Search in sources :

Example 56 with Profile

use of io.fabric8.maven.core.config.Profile in project fabric8 by jboss-fuse.

the class FabricManager method createProfile.

@Override
// Creates a profile with empty content. Is this meaningful?
@Deprecated
public Map<String, Object> createProfile(String versionId, String profileId) {
    ProfileBuilder builder = ProfileBuilder.Factory.create(versionId, profileId);
    Profile profile = profileService.createProfile(builder.getProfile());
    return getProfile(versionId, profile.getId());
}
Also used : ProfileBuilder(io.fabric8.api.ProfileBuilder) Profile(io.fabric8.api.Profile)

Example 57 with Profile

use of io.fabric8.maven.core.config.Profile in project fabric8 by jboss-fuse.

the class FabricManager method setProfileAttribute.

@Override
public void setProfileAttribute(String versionId, String profileId, String attributeId, String value) {
    Profile profile = profileService.getRequiredProfile(versionId, profileId);
    ProfileBuilder builder = ProfileBuilder.Factory.createFrom(profile);
    builder.addAttribute(attributeId, value);
    profileService.updateProfile(builder.getProfile());
}
Also used : ProfileBuilder(io.fabric8.api.ProfileBuilder) Profile(io.fabric8.api.Profile)

Example 58 with Profile

use of io.fabric8.maven.core.config.Profile in project fabric8 by jboss-fuse.

the class FabricManager method getProfileFeatures.

@Override
public Map<String, Object> getProfileFeatures(String versionId, String profileId) {
    Profile profile = profileService.getVersion(versionId).getRequiredProfile(profileId);
    Profile effectiveProfile = Profiles.getEffectiveProfile(fabricService, profileService.getOverlayProfile(profile));
    Map<String, Boolean> isParentFeature = new HashMap<String, Boolean>();
    for (String feature : profile.getFeatures()) {
        isParentFeature.put(feature, Boolean.FALSE);
    }
    for (String feature : effectiveProfile.getFeatures()) {
        if (isParentFeature.get(feature) == null) {
            isParentFeature.put(feature, Boolean.TRUE);
        }
    }
    Map<String, Object> rc = new HashMap<String, Object>();
    List<Map<String, Object>> featureDefs = new ArrayList<Map<String, Object>>();
    for (Map.Entry<String, Boolean> featureEntry : isParentFeature.entrySet()) {
        Map<String, Object> featureDef = new HashMap<String, Object>();
        featureDef.put("id", featureEntry.getKey());
        featureDef.put("isParentFeature", featureEntry.getValue());
        featureDefs.add(featureDef);
    }
    rc.put("featureDefinitions", featureDefs);
    List<Map<String, Object>> repositoryDefs = new ArrayList<Map<String, Object>>();
    for (String repo : effectiveProfile.getRepositories()) {
        Map<String, Object> repoDef = new HashMap<String, Object>();
        repoDef.put("id", repo);
        Closeable closeable = null;
        try {
            URL url = new URL(repo);
            InputStream os = url.openStream();
            closeable = os;
            InputStream is = new BufferedInputStream(url.openStream());
            closeable = is;
            char[] buffer = new char[8192];
            StringBuilder data = new StringBuilder();
            Reader in = new InputStreamReader(is, "UTF-8");
            closeable = in;
            for (; ; ) {
                int stat = in.read(buffer, 0, buffer.length);
                if (stat < 0) {
                    break;
                }
                data.append(buffer, 0, stat);
            }
            repoDef.put("data", data.toString());
        } catch (Throwable t) {
            repoDef.put("error", t.getMessage());
        } finally {
            try {
                if (closeable != null) {
                    closeable.close();
                }
            } catch (Throwable t) {
            // whatevs, I tried
            }
        }
        repositoryDefs.add(repoDef);
    }
    rc.put("repositoryDefinitions", repositoryDefs);
    return rc;
}
Also used : InputStreamReader(java.io.InputStreamReader) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) BufferedInputStream(java.io.BufferedInputStream) InputStream(java.io.InputStream) Closeable(java.io.Closeable) ArrayList(java.util.ArrayList) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) Profile(io.fabric8.api.Profile) URL(java.net.URL) BufferedInputStream(java.io.BufferedInputStream) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) TreeMap(java.util.TreeMap)

Example 59 with Profile

use of io.fabric8.maven.core.config.Profile in project fabric8 by jboss-fuse.

the class FabricManager method getOverlayProfileProperties.

@Override
public Map<String, String> getOverlayProfileProperties(String versionId, String profileId, String pid) {
    Map<String, String> answer = null;
    Version version = profileService.getVersion(versionId);
    if (version != null) {
        Profile profile = version.getRequiredProfile(profileId);
        if (profile != null) {
            Profile overlayProfile = profileService.getOverlayProfile(profile);
            answer = overlayProfile.getConfiguration(pid);
        }
    }
    return answer;
}
Also used : GitVersion(io.fabric8.api.commands.GitVersion) Version(io.fabric8.api.Version) Profile(io.fabric8.api.Profile)

Example 60 with Profile

use of io.fabric8.maven.core.config.Profile in project fabric8 by jboss-fuse.

the class FabricManager method stringsToProfiles.

protected Profile[] stringsToProfiles(Version version, List<String> names) {
    List<Profile> allProfiles = version.getProfiles();
    List<Profile> profiles = new ArrayList<Profile>();
    if (names == null) {
        return new Profile[0];
    }
    for (String name : names) {
        Profile profile = null;
        for (Profile p : allProfiles) {
            if (name.equals(p.getId())) {
                profile = p;
                break;
            }
        }
        if (profile == null) {
            throw new IllegalArgumentException("Profile " + name + " not found.");
        }
        profiles.add(profile);
    }
    return profiles.toArray(new Profile[profiles.size()]);
}
Also used : ArrayList(java.util.ArrayList) Profile(io.fabric8.api.Profile)

Aggregations

Profile (io.fabric8.api.Profile)125 Version (io.fabric8.api.Version)50 Container (io.fabric8.api.Container)49 ArrayList (java.util.ArrayList)37 ProfileBuilder (io.fabric8.api.ProfileBuilder)34 Test (org.junit.Test)32 FabricService (io.fabric8.api.FabricService)28 HashMap (java.util.HashMap)25 File (java.io.File)24 ProfileService (io.fabric8.api.ProfileService)23 Map (java.util.Map)22 IOException (java.io.IOException)19 ProfileRequirements (io.fabric8.api.ProfileRequirements)13 HashSet (java.util.HashSet)12 GitVersion (io.fabric8.api.commands.GitVersion)11 FabricRequirements (io.fabric8.api.FabricRequirements)10 LinkedList (java.util.LinkedList)9 TreeMap (java.util.TreeMap)9 LockHandle (io.fabric8.api.LockHandle)8 Parser (io.fabric8.maven.util.Parser)8