Examples of IO


Examples of org.sonatype.gshell.command.IO

   
    @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

Examples of org.sonatype.gshell.command.IO

    @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

Examples of org.sonatype.gshell.command.IO

{
    @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

Examples of org.sonatype.gshell.command.IO

{
    @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

Examples of org.sonatype.gshell.command.IO

    @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

Examples of org.sonatype.gshell.command.IO

   
    @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

Examples of org.sonatype.gshell.command.IO

{
    @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

Examples of org.sonatype.gshell.command.IO

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

        client.ext(UserClient.class).delete(userId);

        io.println("Deleted user: {}", userId);

        return Result.SUCCESS;
    }
View Full Code Here

Examples of org.sonatype.gshell.command.IO

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

        UserResource user = client.ext(UserClient.class).fetch(userId);
        io.println("@|bold {}|@: {}", user.getUserId(), user.getName());

        return user;
    }
View Full Code Here

Examples of org.sonatype.gshell.command.IO

        this.plexus = plexus;
    }

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

        // HACK: Put all props into System, the security muck needs it
        if (props != null) {
            System.getProperties().putAll(props);
        }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.