Example usage for java.lang Module.Type Module.Type

List of usage examples for java.lang Module.Type Module.Type

Introduction

In this page you can find the example usage for java.lang Module.Type Module.Type.

Prototype

Module.Type

Source Link

Usage

From source file:nl.toolforge.karma.core.cmd.impl.CreateModuleCommand.java

/**
 * Physical creation of a module in a version control system.
 *//*from ww  w.ja  v  a  2s.c  o  m*/
public void execute() throws CommandException {

    CommandLine commandLine = getCommandLine();

    String locationAlias = commandLine.getOptionValue("l");
    String moduleName = commandLine.getOptionValue("m");
    String comment = commandLine.getOptionValue("c");

    // Part 1 of the transaction is the creation of a Module instance.
    //

    // todo this bit sucks. Since renamed to ModuleDigester, it doesn't make sense anymore.
    ModuleDigester digester = null;
    try {
        digester = new ModuleDigester(moduleName, locationAlias);
    } catch (PatternSyntaxException e) {
        throw new CommandException(CommandException.INVALID_ARGUMENT,
                new Object[] { moduleName, e.getMessage() });
    }

    Module.Type moduleType = new Module.Type();
    try {
        moduleType.setType(commandLine.getOptionValue("t"));
    } catch (IllegalArgumentException e1) {
        throw new CommandException(CommandException.INVALID_ARGUMENT);
    }

    Module module = null;
    try {
        ModuleFactory factory = new ModuleFactory(getWorkingContext());
        module = factory.create(digester, moduleType);
    } catch (LocationException e) {
        throw new CommandException(e.getErrorCode(), e.getMessageArguments());
    }

    SimpleMessage message = new SimpleMessage(getFrontendMessages().getString("message.CREATE_MODULE_STARTED"),
            new Object[] { moduleName, locationAlias });
    commandResponse.addEvent(new MessageEvent(this, message));

    try {

        AuthenticatorKey key = new AuthenticatorKey(getWorkingContext().getName(),
                module.getLocation().getId());
        module.createRemote(Authenticators.getAuthenticator(key), comment);

        // Ensure that only this message is passed back to the client
        //
        message = new SimpleMessage(getFrontendMessages().getString("message.CREATE_MODULE_SUCCESSFULL"),
                new Object[] { moduleName, locationAlias });
        commandResponse.addEvent(new MessageEvent(this, message));

    } catch (VersionControlException e) {
        logger.error(e);
        throw new CommandException(e.getErrorCode(), e.getMessageArguments());
    } catch (AuthenticationException e) {
        logger.error(e);
        throw new CommandException(e.getErrorCode(), e.getMessageArguments());
    }
}