|
20 | 20 |
|
21 | 21 | import java.io.BufferedWriter;
|
22 | 22 | import java.io.File;
|
23 |
| -import java.io.FileOutputStream; |
24 | 23 | import java.io.IOException;
|
25 | 24 | import java.io.InputStream;
|
26 | 25 | import java.io.OutputStreamWriter;
|
27 | 26 | import java.io.PrintWriter;
|
28 | 27 | import java.nio.charset.StandardCharsets;
|
| 28 | +import java.nio.file.Files; |
29 | 29 | import java.util.Collections;
|
30 | 30 | import java.util.HashMap;
|
31 | 31 | import java.util.HashSet;
|
@@ -122,89 +122,87 @@ File downloadOrCreateReferenceBuildinfo(
|
122 | 122 | referenceBuildinfo = null;
|
123 | 123 | }
|
124 | 124 |
|
125 |
| - if (referenceBuildinfo == null) { |
126 |
| - // download reference artifacts and guess Java version and OS |
127 |
| - String javaVersion = null; |
128 |
| - String osName = null; |
129 |
| - String currentJavaVersion = null; |
130 |
| - String currentOsName = null; |
131 |
| - Map<Artifact, File> referenceArtifacts = new HashMap<>(); |
132 |
| - for (Artifact artifact : artifacts.keySet()) { |
133 |
| - try { |
134 |
| - // download |
135 |
| - File file = downloadReference(repo, artifact); |
136 |
| - referenceArtifacts.put(artifact, file); |
137 |
| - |
138 |
| - // guess Java version and OS |
139 |
| - if ((javaVersion == null) && JAR_TYPES.contains(artifact.getType())) { |
140 |
| - ReproducibleEnv env = extractEnv(file, artifact); |
141 |
| - if ((env != null) && (env.javaVersion != null)) { |
142 |
| - javaVersion = env.javaVersion; |
143 |
| - osName = env.osName; |
144 |
| - |
145 |
| - ReproducibleEnv currentEnv = extractEnv(artifact.getFile(), artifact); |
146 |
| - currentJavaVersion = currentEnv.javaVersion; |
147 |
| - currentOsName = currentEnv.osName; |
148 |
| - } |
| 125 | + // download reference artifacts and guess Java version and OS |
| 126 | + String javaVersion = null; |
| 127 | + String osName = null; |
| 128 | + String currentJavaVersion = null; |
| 129 | + String currentOsName = null; |
| 130 | + Map<Artifact, File> referenceArtifacts = new HashMap<>(); |
| 131 | + for (Artifact artifact : artifacts.keySet()) { |
| 132 | + try { |
| 133 | + // download |
| 134 | + File file = downloadReference(repo, artifact); |
| 135 | + referenceArtifacts.put(artifact, file); |
| 136 | + |
| 137 | + // guess Java version and OS |
| 138 | + if ((javaVersion == null) && JAR_TYPES.contains(artifact.getType())) { |
| 139 | + ReproducibleEnv env = extractEnv(file, artifact); |
| 140 | + if ((env != null) && (env.javaVersion != null)) { |
| 141 | + javaVersion = env.javaVersion; |
| 142 | + osName = env.osName; |
| 143 | + |
| 144 | + ReproducibleEnv currentEnv = extractEnv(artifact.getFile(), artifact); |
| 145 | + currentJavaVersion = currentEnv.javaVersion; |
| 146 | + currentOsName = currentEnv.osName; |
149 | 147 | }
|
150 |
| - } catch (ArtifactNotFoundException e) { |
151 |
| - log.warn("Reference artifact not found " + artifact); |
152 | 148 | }
|
| 149 | + } catch (ArtifactNotFoundException e) { |
| 150 | + log.warn("Reference artifact not found " + artifact); |
153 | 151 | }
|
| 152 | + } |
154 | 153 |
|
155 |
| - // generate buildinfo from reference artifacts |
156 |
| - referenceBuildinfo = getReference(null, buildinfoFile); |
157 |
| - try (PrintWriter p = new PrintWriter(new BufferedWriter( |
158 |
| - new OutputStreamWriter(new FileOutputStream(referenceBuildinfo), StandardCharsets.UTF_8)))) { |
159 |
| - BuildInfoWriter bi = new BuildInfoWriter(log, p, mono, artifactHandlerManager, rtInformation); |
160 |
| - |
161 |
| - if (javaVersion != null || osName != null) { |
162 |
| - p.println("# effective build environment information"); |
163 |
| - if (javaVersion != null) { |
164 |
| - p.println("java.version=" + javaVersion); |
165 |
| - log.info("Reference build java.version: " + javaVersion); |
166 |
| - if (!javaVersion.equals(currentJavaVersion)) { |
167 |
| - log.error("Current build java.version: " + currentJavaVersion); |
168 |
| - } |
169 |
| - } |
170 |
| - if (osName != null) { |
171 |
| - p.println("os.name=" + osName); |
172 |
| - log.info("Reference build os.name: " + osName); |
173 |
| - |
174 |
| - // check against current line separator |
175 |
| - if (!osName.equals(currentOsName)) { |
176 |
| - log.error("Current build os.name: " + currentOsName); |
177 |
| - } |
178 |
| - String expectedLs = osName.startsWith("Windows") ? "\r\n" : "\n"; |
179 |
| - if (!expectedLs.equals(System.lineSeparator())) { |
180 |
| - log.warn("Current System.lineSeparator() does not match reference build OS"); |
181 |
| - |
182 |
| - String ls = System.getProperty("line.separator"); |
183 |
| - if (!ls.equals(System.lineSeparator())) { |
184 |
| - log.warn("System.lineSeparator() != System.getProperty( \"line.separator\" ): " |
185 |
| - + "too late standard system property update..."); |
186 |
| - } |
187 |
| - } |
| 154 | + // generate buildinfo from reference artifacts |
| 155 | + referenceBuildinfo = getReference(null, buildinfoFile); |
| 156 | + try (PrintWriter p = new PrintWriter(new BufferedWriter( |
| 157 | + new OutputStreamWriter(Files.newOutputStream(referenceBuildinfo.toPath()), StandardCharsets.UTF_8)))) { |
| 158 | + BuildInfoWriter bi = new BuildInfoWriter(log, p, mono, artifactHandlerManager, rtInformation); |
| 159 | + |
| 160 | + if (javaVersion != null || osName != null) { |
| 161 | + p.println("# effective build environment information"); |
| 162 | + if (javaVersion != null) { |
| 163 | + p.println("java.version=" + javaVersion); |
| 164 | + log.info("Reference build java.version: " + javaVersion); |
| 165 | + if (!javaVersion.equals(currentJavaVersion)) { |
| 166 | + log.error("Current build java.version: " + currentJavaVersion); |
188 | 167 | }
|
189 | 168 | }
|
| 169 | + if (osName != null) { |
| 170 | + p.println("os.name=" + osName); |
| 171 | + log.info("Reference build os.name: " + osName); |
190 | 172 |
|
191 |
| - for (Map.Entry<Artifact, String> entry : artifacts.entrySet()) { |
192 |
| - Artifact artifact = entry.getKey(); |
193 |
| - String prefix = entry.getValue(); |
194 |
| - File referenceFile = referenceArtifacts.get(artifact); |
195 |
| - if (referenceFile != null) { |
196 |
| - bi.printFile(prefix, artifact.getGroupId(), referenceFile); |
| 173 | + // check against current line separator |
| 174 | + if (!osName.equals(currentOsName)) { |
| 175 | + log.error("Current build os.name: " + currentOsName); |
| 176 | + } |
| 177 | + String expectedLs = osName.startsWith("Windows") ? "\r\n" : "\n"; |
| 178 | + if (!expectedLs.equals(System.lineSeparator())) { |
| 179 | + log.warn("Current System.lineSeparator() does not match reference build OS"); |
| 180 | + |
| 181 | + String ls = System.getProperty("line.separator"); |
| 182 | + if (!ls.equals(System.lineSeparator())) { |
| 183 | + log.warn("System.lineSeparator() != System.getProperty( \"line.separator\" ): " |
| 184 | + + "too late standard system property update..."); |
| 185 | + } |
197 | 186 | }
|
198 | 187 | }
|
| 188 | + } |
199 | 189 |
|
200 |
| - if (p.checkError()) { |
201 |
| - throw new MojoExecutionException("Write error to " + referenceBuildinfo); |
| 190 | + for (Map.Entry<Artifact, String> entry : artifacts.entrySet()) { |
| 191 | + Artifact artifact = entry.getKey(); |
| 192 | + String prefix = entry.getValue(); |
| 193 | + File referenceFile = referenceArtifacts.get(artifact); |
| 194 | + if (referenceFile != null) { |
| 195 | + bi.printFile(prefix, artifact.getGroupId(), referenceFile); |
202 | 196 | }
|
| 197 | + } |
203 | 198 |
|
204 |
| - log.info("Minimal buildinfo generated from downloaded artifacts: " + referenceBuildinfo); |
205 |
| - } catch (IOException e) { |
206 |
| - throw new MojoExecutionException("Error creating file " + referenceBuildinfo, e); |
| 199 | + if (p.checkError()) { |
| 200 | + throw new MojoExecutionException("Write error to " + referenceBuildinfo); |
207 | 201 | }
|
| 202 | + |
| 203 | + log.info("Minimal buildinfo generated from downloaded artifacts: " + referenceBuildinfo); |
| 204 | + } catch (IOException e) { |
| 205 | + throw new MojoExecutionException("Error creating file " + referenceBuildinfo, e); |
208 | 206 | }
|
209 | 207 |
|
210 | 208 | return referenceBuildinfo;
|
|
0 commit comments