Search in sources :

Example 1 with SimpleManifest

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");
}
Also used : HashMap(java.util.HashMap) SimpleManifest(io.jenkins.tools.warpackager.lib.util.SimpleManifest) GroovyHookInfo(io.jenkins.tools.warpackager.lib.config.GroovyHookInfo) Model(org.apache.maven.model.Model) File(java.io.File) DependencyInfo(io.jenkins.tools.warpackager.lib.config.DependencyInfo)

Aggregations

DependencyInfo (io.jenkins.tools.warpackager.lib.config.DependencyInfo)1 GroovyHookInfo (io.jenkins.tools.warpackager.lib.config.GroovyHookInfo)1 SimpleManifest (io.jenkins.tools.warpackager.lib.util.SimpleManifest)1 File (java.io.File)1 HashMap (java.util.HashMap)1 Model (org.apache.maven.model.Model)1