Search in sources :

Example 6 with PatchOperationBuilder

use of org.jboss.as.patching.tool.PatchOperationBuilder in project wildfly-core by wildfly.

the class PatchHandler method createPatchOperationBuilder.

private PatchOperationBuilder createPatchOperationBuilder(ParsedCommandLine args) throws CommandFormatException {
    final String action = this.action.getValue(args, true);
    PatchOperationBuilder builder;
    if (APPLY.equals(action)) {
        final String path = this.path.getValue(args, true);
        final File f = new File(path);
        if (!f.exists()) {
            // i18n is never used for CLI exceptions
            throw new CommandFormatException("Path " + f.getAbsolutePath() + " doesn't exist.");
        }
        if (f.isDirectory()) {
            throw new CommandFormatException(f.getAbsolutePath() + " is a directory.");
        }
        builder = PatchOperationBuilder.Factory.patch(f);
    } else if (ROLLBACK.equals(action)) {
        String resetConfigValue = resetConfiguration.getValue(args, true);
        boolean resetConfig;
        if (Util.TRUE.equalsIgnoreCase(resetConfigValue)) {
            resetConfig = true;
        } else if (Util.FALSE.equalsIgnoreCase(resetConfigValue)) {
            resetConfig = false;
        } else {
            throw new CommandFormatException("Unexpected value for --reset-configuration (only true and false are allowed): " + resetConfigValue);
        }
        final String patchStream = this.patchStream.getValue(args);
        if (patchId.isPresent(args)) {
            final String id = patchId.getValue(args, true);
            final boolean rollbackTo = this.rollbackTo.isPresent(args);
            builder = PatchOperationBuilder.Factory.rollback(patchStream, id, rollbackTo, resetConfig);
        } else {
            builder = PatchOperationBuilder.Factory.rollbackLast(patchStream, resetConfig);
        }
    } else if (INFO.equals(action)) {
        if (streams.isPresent(args)) {
            return PatchOperationBuilder.Factory.streams();
        }
        final String patchStream = this.patchStream.getValue(args);
        final String pId = patchId.getValue(args);
        if (pId == null) {
            builder = PatchOperationBuilder.Factory.info(patchStream);
        } else {
            builder = PatchOperationBuilder.Factory.info(patchStream, pId, verbose.isPresent(args));
        }
        return builder;
    } else if (HISTORY.equals(action)) {
        final String patchStream = this.patchStream.getValue(args);
        builder = PatchOperationBuilder.Factory.history(patchStream, excludeAgedOut.isPresent(args));
        return builder;
    } else {
        throw new CommandFormatException("Unrecognized action '" + action + "'");
    }
    if (overrideModules.isPresent(args)) {
        builder.ignoreModuleChanges();
    }
    if (overrideAll.isPresent(args)) {
        builder.overrideAll();
    }
    if (override.isPresent(args)) {
        final String overrideList = override.getValue(args);
        if (overrideList == null || overrideList.isEmpty()) {
            throw new CommandFormatException(override.getFullName() + " is missing value.");
        }
        for (String path : overrideList.split(",+")) {
            builder.overrideItem(path);
        }
    }
    if (preserve.isPresent(args)) {
        final String preserveList = preserve.getValue(args);
        if (preserveList == null || preserveList.isEmpty()) {
            throw new CommandFormatException(preserve.getFullName() + " is missing value.");
        }
        for (String path : preserveList.split(",+")) {
            builder.preserveItem(path);
        }
    }
    return builder;
}
Also used : CommandFormatException(org.jboss.as.cli.CommandFormatException) PatchOperationBuilder(org.jboss.as.patching.tool.PatchOperationBuilder) ZipFile(java.util.zip.ZipFile) File(java.io.File)

Example 7 with PatchOperationBuilder

use of org.jboss.as.patching.tool.PatchOperationBuilder in project wildfly-core by wildfly.

the class PatchInfo method createPatchOperationBuilder.

@Override
protected PatchOperationBuilder createPatchOperationBuilder(CommandContext ctx) throws CommandException {
    if (streams) {
        return PatchOperationBuilder.Factory.streams();
    }
    PatchOperationBuilder builder;
    final String pId = getPatchId();
    if (pId == null) {
        builder = PatchOperationBuilder.Factory.info(patchStream);
    } else {
        builder = PatchOperationBuilder.Factory.info(patchStream, pId, verbose);
    }
    return builder;
}
Also used : PatchOperationBuilder(org.jboss.as.patching.tool.PatchOperationBuilder)

Example 8 with PatchOperationBuilder

use of org.jboss.as.patching.tool.PatchOperationBuilder in project wildfly-core by wildfly.

the class PatchOverrideCommand method createPatchOperationBuilder.

@Override
protected PatchOperationBuilder createPatchOperationBuilder(CommandContext ctx) throws CommandException {
    PatchOperationBuilder builder = createUnconfiguredOperationBuilder(ctx);
    configureBuilder(builder);
    return builder;
}
Also used : PatchOperationBuilder(org.jboss.as.patching.tool.PatchOperationBuilder)

Aggregations

PatchOperationBuilder (org.jboss.as.patching.tool.PatchOperationBuilder)8 ModelNode (org.jboss.dmr.ModelNode)4 ArrayList (java.util.ArrayList)2 CommandFormatException (org.jboss.as.cli.CommandFormatException)2 PatchOperationTarget (org.jboss.as.patching.tool.PatchOperationTarget)2 File (java.io.File)1 IOException (java.io.IOException)1 ZipException (java.util.zip.ZipException)1 ZipFile (java.util.zip.ZipFile)1 XMLStreamException (javax.xml.stream.XMLStreamException)1 CommandException (org.aesh.command.CommandException)1 OptionValidatorException (org.aesh.command.validator.OptionValidatorException)1 CommandLineException (org.jboss.as.cli.CommandLineException)1 ParsedCommandLine (org.jboss.as.cli.operation.ParsedCommandLine)1 SimpleTable (org.jboss.as.cli.util.SimpleTable)1 PatchingException (org.jboss.as.patching.PatchingException)1