Package org.sonatype.gshell.command

Examples of org.sonatype.gshell.command.IO


        return this;
    }

    public Object execute(final CommandContext context) throws Exception {
        assert context != null;
        IO io = context.getIo();
        Variables vars = context.getVariables();

        io.println("Creating archetype from: {}", pomFile.getAbsoluteFile()); // TODO: i18n

        MavenProject project = buildProject(context);
        log.debug("Built project: {}", project);

        log.debug("Configuring");
        ArchetypeCreationConfigurator configurator = plexus.lookup(ArchetypeCreationConfigurator.class);
        Properties config = configurator.configureArchetypeCreation(project, !batch, props, null, languages);

        RepositorySystem rsys = plexus.lookup(RepositorySystem.class);

        ArchetypeCreationRequest request = new ArchetypeCreationRequest()
            .setProject(project)
            .setProperties(config)
            .setLanguages(languages)
            .setFilteredExtensions(filteredExtensions)
            .setPreserveCData(preserveCDATA)
            .setKeepParent(keepParent)
            .setPartialArchetype(partial)
            .setLocalRepository(rsys.createDefaultLocalRepository())
            .setPackageName(packageName);

        if (registryFile == null) {
            File dir = vars.get(SHELL_USER_HOME, File.class);
            registryFile = new File(dir, ".m2/archetype.xml");
        }
        request.setArchetypeRegistryFile(registryFile);

        if (outputDirectory != null) {
            request.setOutputDirectory(outputDirectory);
        }
        else {
            // HACK: Default dir is not rooted
            System.setProperty("user.dir", vars.get(SHELL_USER_DIR, File.class).getAbsolutePath());
        }

        log.debug("Creating archetype");
        ArchetypeManager archetypeManager = plexus.lookup(ArchetypeManager.class);
        ArchetypeCreationResult result = archetypeManager.createArchetypeFromProject(request);

        if (result.getCause() != null) {
            throw result.getCause();
        }

        // HACK: Prompter has some issues, so add a newline
        io.out.println();

        io.println("Archetype created in: {}", request.getOutputDirectory().getAbsolutePath()); // TODO: i18n

        return Result.SUCCESS;
    }
View Full Code Here


        this.plexus = plexus;
    }

    public Object execute(final CommandContext context) throws Exception {
        assert context != null;
        IO io = context.getIo();
        Variables vars = context.getVariables();

        RepositorySystem rsys = plexus.lookup(RepositorySystem.class);
        ArchetypeGenerationRequest request = new ArchetypeGenerationRequest()
            .setLocalRepository(rsys.createDefaultLocalRepository())
            .setRemoteArtifactRepositories(Collections.singletonList(rsys.createDefaultRemoteRepository()));

        if (outputDirectory == null) {
            outputDirectory = new File(vars.get(SHELL_USER_DIR, String.class));
        }
        request.setOutputDirectory(outputDirectory.getAbsolutePath());

        if (archetypeId != null) {
            String[] items = archetypeId.split(":", 3);
            if (items.length != 3) {
                io.error("Invalid archetype id: {}", archetypeId); // TODO: i18n
                return Result.FAILURE;
            }

            request.setArchetypeGroupId(items[0])
                .setArchetypeArtifactId(items[1])
View Full Code Here

    @Override
    protected Object execute(final CommandContext context, final NexusClient client) throws Exception {
        assert context != null;
        assert client != null;
        IO io = context.getIo();

        //
        // TODO: Prompt for server/instance/username/password if not given, or --interactive is configured,
        //       need to bring back the prompt helper components from gshell 1.x
        //

        log.debug("Opening");

        client.open(server, instance);
   
        if (username != null) {
            log.debug("Logging in");

            AuthenticationLoginResource detail = client.login(username, password);
            AuthenticationClientPermissions perms = detail.getClientPermissions();

            if (perms.isLoggedIn()) {
                // TODO: Add colors

                io.println("User: {}", perms.getLoggedInUsername()); // TODO: i18n
                io.println("Source: {}", perms.getLoggedInUserSource()); // TODO: i18n

                // TODO: Add more details
            }
            else {
                io.error("Authentication failed"); // TODO: i18n
                return Result.FAILURE;
            }
        }

        // Try to fetch something before we bind into context
        StatusResource status = client.ext(BasicClient.class).status();

        context.getVariables().set(NexusClient.class, client);

        io.println("Connected to: {} ({} v{})", status.getBaseUrl(), status.getAppName(), status.getApiVersion()); // TODO: i18n

        return client;
    }
View Full Code Here

   
    @Override
    protected Object execute(final CommandContext context, final NexusClient client) throws Exception {
        assert context != null;
        assert client != null;
        IO io = context.getIo();

        MultivaluedMap<String,String> params = new MultivaluedMapImpl<String,String>();

        if (query != null) {
            params.putSingle("q", query);
        }
        if (groupId != null) {
            params.putSingle("g", groupId);
        }
        if (artifactId != null) {
            params.putSingle("a", artifactId);
        }
        if (version != null) {
            params.putSingle("v", version);
        }

        if (params.isEmpty()) {
            io.error("Missing search criteria");
            return Result.FAILURE;
        }

        SearchResponse response = client.ext(BasicClient.class).search(params);

        // TODO: Need to return better results, and handle errors
       
        io.println("Total count: {}", response.getTotalCount());
        io.println("From: {}", response.getFrom());
        io.println("Count: {}", response.getCount());
        io.println("Too many results: {}", response.isTooManyResults());

        List<NexusArtifact> results = response.getData();
        if (!results.isEmpty()) {
            log.info("Results:");
            for (NexusArtifact artifact : results) {
View Full Code Here

    @Override
    protected Object execute(final CommandContext context, final NexusClient client) throws Exception {
        assert context != null;
        assert client != null;
        IO io = context.getIo();

        //
        // TODO: Fetch the current details, and use them as defaults
        //
       
        UserResource user = new UserResource();

        // Prompt for any missing details
        PromptReader prompt = promptProvider.get();

        user.setUserId(userId);
       
        // TODO: i18n all of this

        // TODO: Add color

        if (name == null) {
            name = prompt.readLine("User name: ");
        }
        user.setName(name);

        if (email == null) {
            email = prompt.readLine("User email: ");
        }
        user.setEmail(email);

        if (active == null) {
            String tmp = prompt.readLine("User active: ");
            active = Boolean.parseBoolean(tmp);
        }
        if (active) {
            user.setStatus("active");
        }
        else {
            user.setStatus("disabled");
        }

        if (userManaged == null) {
            String tmp = prompt.readLine("User managed: ");
            userManaged = Boolean.parseBoolean(tmp);
        }
        user.setUserManaged(userManaged);

        if (roles == null) {
            roles = new ArrayList<String>();

            String tmp;
            while ((tmp = prompt.readLine("User role: ")) != null && tmp.trim().length() != 0) {
                roles.add(tmp);
            }

        }
        user.getRoles().addAll(roles);

        //
        // TODO: Verify input if interactive
        //

        // Create the user
        user = client.ext(UserClient.class).update(user);

        io.println("Updated user: {}", user.getResourceURI());

        return user;
    }
View Full Code Here

{
    @Override
    protected Object execute(final CommandContext context, final NexusClient client) throws Exception {
        assert context != null;
        assert client != null;
        IO io = context.getIo();

        List<RepositoryListResource> repos = client.ext(RepositoryClient.class).list();

        for (RepositoryListResource repo : repos) {
            // TODO: Add color

            io.println("ID: {}", repo.getId()); // TODO: i18n
            io.println("Name: {}", repo.getName());

            // TODO: More details
        }

        return repos;
View Full Code Here

{
    @Override
    protected Object execute(final CommandContext context, final NexusClient client) throws Exception {
        assert context != null;
        assert client != null;
        IO io = context.getIo();

        StatusResource status = client.ext(BasicClient.class).status();

        // TODO: Add colors

        io.println("App Name: {}", status.getAppName()); // TODO: i18n
        io.println("Version: {}", status.getVersion()); // TODO: i18n
        io.println("State: {}", status.getState());

        // TODO: Add more details

        return status;
    }
View Full Code Here

    @Override
    protected Object execute(final CommandContext context, final NexusClient client) throws Exception {
        assert context != null;
        assert client != null;
        IO io = context.getIo();

        UserResource user = new UserResource();

        // Prompt for any missing details
        PromptReader prompt = promptProvider.get();

        // TODO: i18n all of this

        // TODO: Add color
       
        if (userId == null) {
            userId = prompt.readLine("User ID: ");
        }
        user.setUserId(userId);

        if (name == null) {
            name = prompt.readLine("User name: ");
        }
        user.setName(name);

        if (email == null) {
            email = prompt.readLine("User email: ");
        }
        user.setEmail(email);

        if (active == null) {
            String tmp = prompt.readLine("User active: ");
            active = Boolean.parseBoolean(tmp);
        }
        if (active) {
            user.setStatus("active");
        }
        else {
            user.setStatus("disabled");
        }

        if (userManaged == null) {
            String tmp = prompt.readLine("User managed: ");
            userManaged = Boolean.parseBoolean(tmp);
        }
        user.setUserManaged(userManaged);

        if (roles == null) {
            roles = new ArrayList<String>();

            String tmp;
            while ((tmp = prompt.readLine("User role: ")) != null && tmp.trim().length() != 0) {
                roles.add(tmp);
            }

        }
        user.getRoles().addAll(roles);

        if (password == null) {
            password = prompt.readPassword("User password: ");
        }
        user.setPassword(password);

        //
        // TODO: Verify input if interactive
        //
       
        // Create the user
        user = client.ext(UserClient.class).create(user);

        io.println("Created user: {}", user.getResourceURI());

        return user;
    }
View Full Code Here

   
    @Override
    protected Object execute(final CommandContext context, final NexusClient client) throws Exception {
        assert context != null;
        assert client != null;
        IO io = context.getIo();

        String content = client.ext(M2SettingsClient.class).fetch(templateId);

        File target = file;
        if (file == null) {
            if (settings != null) {
                target = new File(new File(System.getProperty("user.home")), ".m2/settings.xml");
            }
        }

        if (target == null) {
            io.out.println(content);
            return Result.SUCCESS;
        }

        log.debug("Target file: {}", target);

        if (backup && target.exists()) {
            String backupString = new SimpleDateFormat(backupFormat).format(new Date());

            File b = new File(target.getParentFile(), target.getName() + "." + backupString);

            log.debug("Backing up old settings to: {}", b.getAbsolutePath());

            if (!target.renameTo(b)) {
                io.error("Cannot rename existing settings to backup file.\nExisting file: {}\nBackup file: {}",
                    target.getAbsolutePath(), b.getAbsolutePath());
                return Result.FAILURE;
            }

            log.info("Existing settings backed up to: {}", b.getAbsolutePath());
        }

        PrintWriter writer = new PrintWriter(new BufferedWriter(new FileWriter(target)));
        try {
            writer.print(content);
        }
        finally {
            Closer.close(writer);
        }

        io.println("Wrote settings to: {}", target.getAbsolutePath());

        return target;
    }
View Full Code Here

{
    @Override
    protected Object execute(final CommandContext context, final NexusClient client) throws Exception {
        assert context != null;
        assert client != null;
        IO io = context.getIo();

        List<UserResource> users = client.ext(UserClient.class).list();
        if (!users.isEmpty()) {
            io.println("Users:");
            for (UserResource user : users) {
                io.println("  @|bold {}|@: {}", user.getUserId(), user.getName());
            }
        }

        return users;
    }
View Full Code Here

TOP

Related Classes of org.sonatype.gshell.command.IO

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.