184 "-q", "--whatprovides", file.toString()) |
185 "-q", "--whatprovides", file.toString()) |
185 .saveOutput(true).executeExpectSuccess().getOutput().stream(); |
186 .saveOutput(true).executeExpectSuccess().getOutput().stream(); |
186 }); |
187 }); |
187 } |
188 } |
188 |
189 |
|
190 @Override |
|
191 protected List<ConfigException> verifyOutputBundle( |
|
192 Map<String, ? super Object> params, Path packageBundle) { |
|
193 List<ConfigException> errors = new ArrayList<>(); |
|
194 |
|
195 String specFileName = specFile(params).getFileName().toString(); |
|
196 |
|
197 try { |
|
198 List<PackageProperty> properties = List.of( |
|
199 new PackageProperty("Name", PACKAGE_NAME.fetchFrom(params), |
|
200 "APPLICATION_PACKAGE", specFileName), |
|
201 new PackageProperty("Version", VERSION.fetchFrom(params), |
|
202 "APPLICATION_VERSION", specFileName), |
|
203 new PackageProperty("Release", RELEASE.fetchFrom(params), |
|
204 "APPLICATION_RELEASE", specFileName), |
|
205 new PackageProperty("Arch", rpmArch(), null, specFileName)); |
|
206 |
|
207 List<String> actualValues = Executor.of(TOOL_RPM, "-qp", "--queryformat", |
|
208 properties.stream().map(entry -> String.format("%%{%s}", |
|
209 entry.name)).collect(Collectors.joining("\\n")), |
|
210 packageBundle.toString()).saveOutput(true).executeExpectSuccess().getOutput(); |
|
211 |
|
212 Iterator<String> actualValuesIt = actualValues.iterator(); |
|
213 properties.forEach(property -> errors.add(property.verifyValue( |
|
214 actualValuesIt.next()))); |
|
215 } catch (IOException ex) { |
|
216 // Ignore error as it is not critical. Just report it. |
|
217 Log.verbose(ex); |
|
218 } |
|
219 |
|
220 return errors; |
|
221 } |
|
222 |
|
223 private String rpmArch() throws IOException { |
|
224 if (rpmArch == null) { |
|
225 rpmArch = Executor.of(TOOL_RPMBUILD, "--eval=%{_target_cpu}").saveOutput( |
|
226 true).executeExpectSuccess().getOutput().get(0); |
|
227 } |
|
228 return rpmArch; |
|
229 } |
|
230 |
189 private Path specFile(Map<String, ? super Object> params) { |
231 private Path specFile(Map<String, ? super Object> params) { |
190 return TEMP_ROOT.fetchFrom(params).toPath().resolve(Path.of("SPECS", |
232 return TEMP_ROOT.fetchFrom(params).toPath().resolve(Path.of("SPECS", |
191 PACKAGE_NAME.fetchFrom(params) + ".spec")); |
233 PACKAGE_NAME.fetchFrom(params) + ".spec")); |
192 } |
234 } |
193 |
235 |
194 private File buildRPM(Map<String, ? super Object> params, |
236 private Path buildRPM(Map<String, ? super Object> params, |
195 File outdir) throws IOException { |
237 Path outdir) throws IOException { |
|
238 |
|
239 Path rpmFile = outdir.toAbsolutePath().resolve(String.format( |
|
240 "%s-%s-%s.%s.rpm", PACKAGE_NAME.fetchFrom(params), |
|
241 VERSION.fetchFrom(params), RELEASE.fetchFrom(params), rpmArch())); |
|
242 |
196 Log.verbose(MessageFormat.format(I18N.getString( |
243 Log.verbose(MessageFormat.format(I18N.getString( |
197 "message.outputting-bundle-location"), |
244 "message.outputting-bundle-location"), |
198 outdir.getAbsolutePath())); |
245 rpmFile.getParent())); |
199 |
246 |
200 PlatformPackage thePackage = createMetaPackage(params); |
247 PlatformPackage thePackage = createMetaPackage(params); |
201 |
248 |
202 //run rpmbuild |
249 //run rpmbuild |
203 Executor.of( |
250 Executor.of( |
204 TOOL_RPMBUILD, |
251 TOOL_RPMBUILD, |
205 "-bb", specFile(params).toAbsolutePath().toString(), |
252 "-bb", specFile(params).toAbsolutePath().toString(), |
206 "--define", String.format("%%_sourcedir %s", |
253 "--define", String.format("%%_sourcedir %s", |
207 thePackage.sourceRoot()), |
254 thePackage.sourceRoot()), |
208 // save result to output dir |
255 // save result to output dir |
209 "--define", String.format("%%_rpmdir %s", |
256 "--define", String.format("%%_rpmdir %s", rpmFile.getParent()), |
210 outdir.getAbsolutePath()), |
|
211 // do not use other system directories to build as current user |
257 // do not use other system directories to build as current user |
212 "--define", String.format("%%_topdir %s", |
258 "--define", String.format("%%_topdir %s", |
213 TEMP_ROOT.fetchFrom(params).toPath().toAbsolutePath()) |
259 TEMP_ROOT.fetchFrom(params).toPath().toAbsolutePath()), |
|
260 "--define", String.format("%%_rpmfilename %s", rpmFile.getFileName()) |
214 ).executeExpectSuccess(); |
261 ).executeExpectSuccess(); |
215 |
262 |
216 Log.verbose(MessageFormat.format( |
263 Log.verbose(MessageFormat.format( |
217 I18N.getString("message.output-bundle-location"), |
264 I18N.getString("message.output-bundle-location"), |
218 outdir.getAbsolutePath())); |
265 rpmFile.getParent())); |
219 |
266 |
220 // presume the result is the ".rpm" file with the newest modified time |
267 return rpmFile; |
221 // not the best solution, but it is the most reliable |
|
222 File result = null; |
|
223 long lastModified = 0; |
|
224 File[] list = outdir.listFiles(); |
|
225 if (list != null) { |
|
226 for (File f : list) { |
|
227 if (f.getName().endsWith(".rpm") && |
|
228 f.lastModified() > lastModified) { |
|
229 result = f; |
|
230 lastModified = f.lastModified(); |
|
231 } |
|
232 } |
|
233 } |
|
234 |
|
235 return result; |
|
236 } |
268 } |
237 |
269 |
238 @Override |
270 @Override |
239 public String getName() { |
271 public String getName() { |
240 return I18N.getString("rpm.bundler.name"); |
272 return I18N.getString("rpm.bundler.name"); |