Search in sources :

Example 1 with GroovyHookInfo

use of io.jenkins.tools.warpackager.lib.config.GroovyHookInfo in project custom-war-packager by jenkinsci.

the class JenkinsWarPatcher method addHooks.

public JenkinsWarPatcher addHooks(@Nonnull Map<String, File> hooks) throws IOException {
    for (Map.Entry<String, File> hookSrc : hooks.entrySet()) {
        final String hookId = hookSrc.getKey();
        GroovyHookInfo hook = config.getHookById(hookId);
        if (hook == null) {
            throw new IOException("Cannot find metadata for the hook with ID=" + hookId);
        }
        addHook(hook, hookSrc.getValue());
    }
    return this;
}
Also used : GroovyHookInfo(io.jenkins.tools.warpackager.lib.config.GroovyHookInfo) IOException(java.io.IOException) Map(java.util.Map) ZipFile(java.util.zip.ZipFile) File(java.io.File)

Example 2 with GroovyHookInfo

use of io.jenkins.tools.warpackager.lib.config.GroovyHookInfo 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

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