Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright 2005-2014 Red Hat, Inc. Red Hat licenses this file to you under the Apache License, version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
package io.fabric8.commands;
import  org.apache.felix.gogo.commands.Argument;
import  org.apache.felix.gogo.commands.Command;
import  org.apache.karaf.shell.console.AbstractAction;
@Command(name = ., scope = ., description = .)
public class VersionInfoAction extends AbstractAction {
    static final String FORMAT = "%-30s %s";
    @Argument(index = 0, name = "version", description = "The version name.", required = false, multiValued = false)
    private String versionName;
    private final FabricService fabricService;
    private final RuntimeProperties runtimeProperties;
    VersionInfoAction(FabricService fabricServiceRuntimeProperties runtimeProperties) {
        this. = fabricService;
        this. = runtimeProperties;
    }
    @Override
    protected Object doExecute() throws Exception {
        if (!versionExists()) {
            ..println("Container " +  + " does not exists!");
            return null;
        }
        Version version = .getVersion();
        String description = version.getAttributes().get(.);
        StringBuilder sbContainers = new StringBuilder("");
        for (String c : .getDataStore().getContainers()) {
            if (version.getId().equals(.getContainer(c).getVersion().getId())) {
                sbContainers.append(c);
                sbContainers.append(", ");
            }
        }
        String containers = sbContainers.toString();
        if (containers.endsWith(", ")) {
            containers = containers.substring(0, containers.lastIndexOf(", "));
        }
        boolean defaultVersion = version.getId().equals(.getDefaultVersion().getId());
        Profile[] profiles = CommandUtils.sortProfiles(version.getProfiles());
        StringBuilder sbProfiles = new StringBuilder("");
        for (int i = 0; i < profiles.lengthi++) {
            if (i != 0) {
                sbProfiles.append(", ");
            }
            sbProfiles.append(profiles[i].getId());
        }
        ..println(String.format("Name:"version.getId()));
        ..println(String.format("Description:", (description != null ? description : "")));
        ..println(String.format("Default Version:"defaultVersion));
        ..println(String.format("Containers:"containers));
        ..println(String.format("Profiles:"sbProfiles.toString()));
        return null;
    }
    private boolean versionExists(String versionName) {
        Version[] versions = .getVersions();
        for (Version v : versions) {
            if (versionName.equals(v.getId())) {
                return true;
            }
        }
        return false;
    }
New to GrepCode? Check out our FAQ X