|
14 | 14 | import java.util.Iterator; |
15 | 15 | import java.util.List; |
16 | 16 | import java.util.Map; |
| 17 | +import java.util.Map.Entry; |
17 | 18 |
|
18 | 19 | import org.eclipse.jgit.lib.ObjectId; |
19 | 20 |
|
@@ -59,18 +60,18 @@ public void createSubmoduleCombinations() throws GitException, IOException { |
59 | 60 | } |
60 | 61 |
|
61 | 62 | // Remove any uninteresting branches |
62 | | - |
63 | | - |
64 | | - |
65 | | - for (IndexEntry entry : moduleBranches.keySet()) { |
66 | | - listener.getLogger().print("Submodule " + entry.getFile() + " branches"); |
67 | | - for (Revision br : moduleBranches.get(entry)) { |
68 | | - listener.getLogger().print(" " + br.toString()); |
69 | 63 |
|
70 | | - } |
71 | | - listener.getLogger().print("\n"); |
| 64 | + |
| 65 | + |
| 66 | + for (Entry<IndexEntry, Collection<Revision>> submodule : moduleBranches |
| 67 | + .entrySet()) { |
| 68 | + listener.getLogger().print( |
| 69 | + "Submodule " + submodule.getKey().getFile() + " branches"); |
| 70 | + for (Revision br : submodule.getValue()) |
| 71 | + listener.getLogger().print(" " + br.toString()); |
| 72 | + listener.getLogger().print('\n'); |
72 | 73 | } |
73 | | - |
| 74 | + |
74 | 75 | // Make all the possible combinations |
75 | 76 | List<Map<IndexEntry, Revision>> combinations = createCombinations(moduleBranches); |
76 | 77 |
|
@@ -110,12 +111,12 @@ public void createSubmoduleCombinations() throws GitException, IOException { |
110 | 111 | int min = Integer.MAX_VALUE; |
111 | 112 |
|
112 | 113 | // But let's see if we can find the most appropriate place to create the branch |
113 | | - for (ObjectId sha : entriesMap.keySet()) { |
114 | | - List<IndexEntry> entries = entriesMap.get(sha); |
115 | | - int value = difference(combination, entries); |
| 114 | + for (Entry<ObjectId, List<IndexEntry>> entry : entriesMap |
| 115 | + .entrySet()) { |
| 116 | + int value = difference(combination, entry.getValue()); |
116 | 117 | if (value > 0 && value < min) { |
117 | 118 | min = value; |
118 | | - sha1 = sha; |
| 119 | + sha1 = entry.getKey(); |
119 | 120 | } |
120 | 121 |
|
121 | 122 | if (min == 1) break; // look no further |
@@ -151,36 +152,40 @@ protected void makeCombination(Map<IndexEntry, Revision> settings) { |
151 | 152 | String name = "combine-" + tid + "-" + (idx++); |
152 | 153 | git.branch(name); |
153 | 154 | git.checkout(name); |
154 | | - |
155 | | - String commit = "Jenkins generated combination of:\n"; |
156 | | - |
157 | | - for (IndexEntry submodule : settings.keySet()) { |
158 | | - Revision branch = settings.get(submodule); |
159 | | - commit += " " + submodule.getFile() + " " + branch.toString() + "\n"; |
| 155 | + |
| 156 | + StringBuilder commit = new StringBuilder( |
| 157 | + "Jenkins generated combination of:\n"); |
| 158 | + |
| 159 | + for (Entry<IndexEntry, Revision> setting : settings.entrySet()) { |
| 160 | + commit.append(' ').append(' '); |
| 161 | + commit.append(setting.getKey().getFile()); |
| 162 | + commit.append(' '); |
| 163 | + commit.append(setting.getValue()); |
| 164 | + commit.append('\n'); |
160 | 165 | } |
161 | | - |
| 166 | + |
162 | 167 | listener.getLogger().print(commit); |
163 | | - |
164 | | - |
165 | | - for (IndexEntry submodule : settings.keySet()) { |
166 | | - Revision branch = settings.get(submodule); |
| 168 | + |
| 169 | + for (Entry<IndexEntry, Revision> setting : settings.entrySet()) { |
| 170 | + IndexEntry submodule = setting.getKey(); |
| 171 | + Revision branch = setting.getValue(); |
167 | 172 | File subdir = new File(workspace, submodule.getFile()); |
168 | | - IGitAPI subGit = new GitAPI(git.getGitExe(), new FilePath(subdir), listener, git.getEnvironment()); |
169 | | - |
| 173 | + IGitAPI subGit = new GitAPI(git.getGitExe(), new FilePath(subdir), |
| 174 | + listener, git.getEnvironment()); |
| 175 | + |
170 | 176 | subGit.checkout(branch.sha1.name()); |
171 | 177 | git.add(submodule.file); |
172 | | - |
173 | 178 | } |
174 | 179 |
|
175 | 180 | try { |
176 | 181 | File f = File.createTempFile("gitcommit", ".txt"); |
177 | 182 | FileOutputStream fos = null; |
178 | 183 | try { |
179 | 184 | fos = new FileOutputStream(f); |
180 | | - fos.write(commit.getBytes()); |
181 | | - } |
182 | | - finally { |
183 | | - fos.close(); |
| 185 | + fos.write(commit.toString().getBytes()); |
| 186 | + } finally { |
| 187 | + if (fos != null) |
| 188 | + fos.close(); |
184 | 189 | } |
185 | 190 | git.commit(f); |
186 | 191 | f.delete(); |
|
0 commit comments