use of io.jenkins.tools.warpackager.lib.util.SimpleManifest in project custom-war-packager by jenkinsci.
the class Builder method build.
public void build() throws IOException, InterruptedException {
// Cleanup the temporary directory
final File tmpDir = config.buildSettings.getTmpDir();
if (tmpDir.exists()) {
LOGGER.log(Level.INFO, "Cleaning up the temporary directory {0}", tmpDir);
FileUtils.deleteDirectory(tmpDir);
}
Files.createDirectories(buildRoot.toPath());
// Build core and plugins
buildIfNeeded(config.war, "war");
if (config.plugins != null) {
for (DependencyInfo plugin : config.plugins) {
buildIfNeeded(plugin, "hpi");
}
}
// Prepare library patches
if (config.libPatches != null) {
for (DependencyInfo library : config.libPatches) {
buildIfNeeded(library, "jar");
}
}
// Prepare Groovy Hooks
Map<String, File> hooks = new HashMap<>();
if (config.groovyHooks != null) {
for (GroovyHookInfo hook : config.groovyHooks) {
hooks.put(hook.id, checkoutIfNeeded(hook.id, hook.source));
}
}
// Generate POM
File warBuildDir = new File(tmpDir, "prebuild");
Files.createDirectories(warBuildDir.toPath());
MavenHPICustomWARPOMGenerator gen = new MavenHPICustomWARPOMGenerator(config, "-prebuild");
Model model = gen.generatePOM(versionOverrides);
gen.writePOM(model, warBuildDir);
// Build WAR using Maven HPI plugin
processFor(warBuildDir, "mvn", "clean", "package");
// Add System properties
File srcWar = new File(warBuildDir, "target/" + config.bundle.artifactId + "-prebuild.war");
File explodedWar = new File(warBuildDir, "exploded-war");
// Patch WAR
new JenkinsWarPatcher(config, srcWar, explodedWar).removeMetaInf().addSystemProperties(config.systemProperties).replaceLibs(versionOverrides).excludeLibs().addHooks(hooks);
File warOutputDir = new File(tmpDir, "output");
SimpleManifest manifest = SimpleManifest.parseFile(srcWar);
MavenWARPackagePOMGenerator finalWar = new MavenWARPackagePOMGenerator(config, explodedWar);
finalWar.writePOM(finalWar.generatePOM(manifest.getMain()), warOutputDir);
processFor(warOutputDir, "mvn", "clean", "package");
// TODO: Support custom output destinations
// File dstWar = new File(warBuildDir, "target/" + config.bundle.artifactId + ".war");
}
Aggregations