Search in sources :

Example 16 with Version

use of io.fabric8.api.Version in project fabric8 by jboss-fuse.

the class ProfileChangeParentsAction method doExecute.

@Override
protected Object doExecute() throws Exception {
    Version version = versionId != null ? profileService.getRequiredVersion(versionId) : fabricService.getRequiredDefaultVersion();
    Profile profile = version.getRequiredProfile(profileId);
    // we can only change parents to existing profiles
    Profile[] parents = FabricCommand.getExistingProfiles(fabricService, version, parentIds);
    ProfileBuilder builder = ProfileBuilder.Factory.createFrom(profile);
    List<String> oldParents = builder.getParents();
    for (Profile parent : parents) {
        builder.addParent(parent.getId());
    }
    // remove old parent profiles
    for (String oldParent : oldParents) {
        if (!parentIds.contains(oldParent)) {
            builder.removeParent(oldParent);
        }
    }
    profileService.updateProfile(builder.getProfile());
    return null;
}
Also used : Version(io.fabric8.api.Version) ProfileBuilder(io.fabric8.api.ProfileBuilder) Profile(io.fabric8.api.Profile)

Example 17 with Version

use of io.fabric8.api.Version in project fabric8 by jboss-fuse.

the class VersionCreateAction method doExecute.

@Override
protected Object doExecute() throws Exception {
    String latestVersion = null;
    ProfileService profileService = fabricService.adapt(ProfileService.class);
    List<String> versions = profileService.getVersions();
    if (versions.size() > 0) {
        latestVersion = versions.get(versions.size() - 1);
    }
    if (versionId == null) {
        IllegalStateAssertion.assertNotNull(latestVersion, "Cannot default the new version name as there are no versions available");
        VersionSequence sequence = new VersionSequence(latestVersion);
        versionId = sequence.next().getName();
    }
    // TODO we maybe want to choose the version which is less than the 'name' if it was specified
    // e.g. if you create a version 1.1 then it should use 1.0 if there is already a 2.0
    String sourceId = null;
    if (parentVersion == null) {
        sourceId = latestVersion;
    } else {
        IllegalStateAssertion.assertTrue(profileService.hasVersion(parentVersion), "Cannot find parent version: " + parentVersion);
        sourceId = parentVersion;
    }
    Version targetVersion;
    if (sourceId != null) {
        Map<String, String> attributes = new HashMap<String, String>(Collections.singletonMap(Version.PARENT, sourceId));
        if (description != null) {
            attributes.put(Version.DESCRIPTION, description);
        }
        targetVersion = profileService.createVersionFrom(sourceId, versionId, attributes);
        System.out.println("Created version: " + versionId + " as copy of: " + sourceId);
    } else {
        VersionBuilder builder = VersionBuilder.Factory.create(versionId);
        if (description != null) {
            builder.addAttribute(Version.DESCRIPTION, description);
        }
        targetVersion = profileService.createVersion(builder.getVersion());
        System.out.println("Create version: " + versionId);
    }
    if (defaultVersion == Boolean.TRUE) {
        fabricService.setDefaultVersionId(targetVersion.getId());
    }
    return null;
}
Also used : ProfileService(io.fabric8.api.ProfileService) Version(io.fabric8.api.Version) HashMap(java.util.HashMap) VersionBuilder(io.fabric8.api.VersionBuilder) VersionSequence(io.fabric8.api.VersionSequence)

Example 18 with Version

use of io.fabric8.api.Version in project fabric8 by jboss-fuse.

the class ProfileEditAction method doExecute.

@Override
protected Object doExecute() throws Exception {
    try {
        FabricValidations.validateProfileName(profileName);
        if (!(delete || remove)) {
            FabricValidations.validatePidProperties(pidProperties);
        }
    } catch (IllegalArgumentException e) {
        // we do not want exception in the server log, so print the error message to the console
        System.out.println(e.getMessage());
        return 1;
    }
    if (delete) {
        set = false;
    }
    Version version = versionId != null ? profileService.getRequiredVersion(versionId) : fabricService.getRequiredDefaultVersion();
    Profile profile = version.getProfile(profileName);
    if (profile != null) {
        editProfile(profile);
    } else {
        System.out.println("Profile " + profileName + " does not exists!");
        return 1;
    }
    return null;
}
Also used : Version(io.fabric8.api.Version) Profile(io.fabric8.api.Profile)

Example 19 with Version

use of io.fabric8.api.Version in project fabric8 by jboss-fuse.

the class ProfileListAction method doExecute.

@Override
protected Object doExecute() throws Exception {
    ProfileService profileService = fabricService.adapt(ProfileService.class);
    Version version = versionId != null ? profileService.getRequiredVersion(versionId) : fabricService.getRequiredDefaultVersion();
    List<Profile> profiles = version.getProfiles();
    profiles = sortProfiles(profiles);
    printProfiles(profileService, profiles, System.out);
    return null;
}
Also used : ProfileService(io.fabric8.api.ProfileService) Version(io.fabric8.api.Version) Profile(io.fabric8.api.Profile)

Example 20 with Version

use of io.fabric8.api.Version in project fabric8 by jboss-fuse.

the class ProfileRefreshAction method doExecute.

@Override
protected Object doExecute() throws Exception {
    ProfileService profileService = fabricService.adapt(ProfileService.class);
    Version version = versionId != null ? profileService.getRequiredVersion(versionId) : fabricService.getRequiredDefaultVersion();
    Profile profile = version.getProfile(profileName);
    if (profile != null) {
        Profiles.refreshProfile(fabricService, profile);
    } else {
        System.out.println("Profile " + profileName + " not found.");
        return 1;
    }
    return null;
}
Also used : ProfileService(io.fabric8.api.ProfileService) Version(io.fabric8.api.Version) Profile(io.fabric8.api.Profile)

Aggregations

Version (io.fabric8.api.Version)74 Profile (io.fabric8.api.Profile)70 File (java.io.File)52 Test (org.junit.Test)46 IOException (java.io.IOException)41 ArrayList (java.util.ArrayList)36 Container (io.fabric8.api.Container)35 HashMap (java.util.HashMap)34 ProfileService (io.fabric8.api.ProfileService)27 Map (java.util.Map)25 Git (org.eclipse.jgit.api.Git)22 FabricService (io.fabric8.api.FabricService)21 Version (org.osgi.framework.Version)21 ProfileBuilder (io.fabric8.api.ProfileBuilder)18 GitVersion (io.fabric8.api.commands.GitVersion)18 PatchException (io.fabric8.patch.management.PatchException)15 HashSet (java.util.HashSet)15 TreeMap (java.util.TreeMap)14 LinkedList (java.util.LinkedList)13 GitPatchRepository (io.fabric8.patch.management.impl.GitPatchRepository)12