Search in sources :

Example 1 with Config

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

the class Main method main.

public static void main(String[] args) throws IOException, InterruptedException {
    CliOptions options = new CliOptions();
    CmdLineParser p = new CmdLineParser(options);
    if (args.length == 0) {
        System.out.println("Usage: java -jar war-packager-cli.jar -configPath=mywar.yml [-version=1.0-SNAPSHOT] [-tmpDir=tmp]\n");
        p.printUsage(System.out);
        return;
    }
    try {
        p.parseArgument(args);
    } catch (CmdLineException ex) {
        p.printUsage(System.out);
        throw new IOException("Failed to read command-line arguments", ex);
    }
    final Config cfg;
    if (options.isDemo()) {
        System.out.println("Running build in the demo mode");
        cfg = Config.loadDemoConfig();
    } else {
        final File configPath = options.getConfigPath();
        if (configPath == null) {
            throw new IOException("-configPath or -demo must be defined");
        }
        cfg = Config.loadConfig(configPath);
    }
    // Override Build Settings by CLI arguments
    cfg.buildSettings.setTmpDir(options.getTmpDir());
    cfg.buildSettings.setVersion(options.getVersion());
    final Builder bldr = new Builder(cfg);
    bldr.build();
}
Also used : CmdLineParser(org.kohsuke.args4j.CmdLineParser) Config(io.jenkins.tools.warpackager.lib.config.Config) Builder(io.jenkins.tools.warpackager.lib.impl.Builder) IOException(java.io.IOException) File(java.io.File) CmdLineException(org.kohsuke.args4j.CmdLineException)

Example 2 with Config

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

the class PackageMojo method execute.

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
    if (configFilePath == null) {
        throw new MojoExecutionException("Config file is not defined");
    }
    final Config cfg;
    try {
        cfg = Config.loadConfig(new File(configFilePath));
    } catch (IOException ex) {
        throw new MojoExecutionException("Cannot load configuration from " + configFilePath, ex);
    }
    cfg.buildSettings.setVersion(warVersion);
    if (tmpDir != null) {
        cfg.buildSettings.setTmpDir(new File(tmpDir));
    } else {
        // Use a Maven temporary dir
        // TODO: use step ID
        cfg.buildSettings.setTmpDir(new File(project.getBuild().getDirectory(), "custom-war-packager-maven-plugin"));
    }
    final Builder bldr = new Builder(cfg);
    try {
        bldr.build();
    } catch (Exception ex) {
        throw new MojoExecutionException("Failed to build the custom WAR", ex);
    }
    projectHelper.attachArtifact(project, "war", cfg.getOutputWar());
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) Config(io.jenkins.tools.warpackager.lib.config.Config) Builder(io.jenkins.tools.warpackager.lib.impl.Builder) IOException(java.io.IOException) File(java.io.File) IOException(java.io.IOException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MojoFailureException(org.apache.maven.plugin.MojoFailureException)

Aggregations

Config (io.jenkins.tools.warpackager.lib.config.Config)2 Builder (io.jenkins.tools.warpackager.lib.impl.Builder)2 File (java.io.File)2 IOException (java.io.IOException)2 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)1 MojoFailureException (org.apache.maven.plugin.MojoFailureException)1 CmdLineException (org.kohsuke.args4j.CmdLineException)1 CmdLineParser (org.kohsuke.args4j.CmdLineParser)1