Search in sources :

Example 6 with Profile

use of org.apache.karaf.profile.Profile in project karaf by apache.

the class ProfileServiceImpl method updateProfile.

@Override
@SuppressWarnings("unused")
public void updateProfile(Profile profile) {
    assertNotNull(profile, "profile is null");
    try (LockHandle lock = acquireWriteLock()) {
        final String profileId = profile.getId();
        final Profile lastProfile = getRequiredProfile(profileId);
        createOrUpdateProfile(lastProfile, profile);
    }
}
Also used : LockHandle(org.apache.karaf.profile.LockHandle) Profile(org.apache.karaf.profile.Profile)

Example 7 with Profile

use of org.apache.karaf.profile.Profile in project karaf by apache.

the class Profiles method loadProfiles.

public static Map<String, Profile> loadProfiles(final Path root) throws IOException {
    final Map<String, Profile> profiles = new HashMap<>();
    Files.walkFileTree(root, new SimpleFileVisitor<Path>() {

        ProfileBuilder builder;

        @Override
        public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {
            Path fileName = dir.getFileName();
            if (fileName != null && (fileName.toString().endsWith(PROFILE_FOLDER_SUFFIX) || fileName.toString().endsWith(PROFILE_FOLDER_SUFFIX + "/"))) {
                String profileId = root.relativize(dir).toString();
                if (profileId.endsWith("/")) {
                    profileId = profileId.substring(0, profileId.length() - 1);
                }
                profileId = profileId.replaceAll(root.getFileSystem().getSeparator(), "-");
                profileId = profileId.substring(0, profileId.length() - PROFILE_FOLDER_SUFFIX.length());
                builder = ProfileBuilder.Factory.create(profileId);
            }
            return FileVisitResult.CONTINUE;
        }

        @Override
        public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
            if (exc != null) {
                throw exc;
            }
            if (builder != null) {
                Profile profile = builder.getProfile();
                profiles.put(profile.getId(), profile);
                builder = null;
            }
            return FileVisitResult.CONTINUE;
        }

        @Override
        public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
            if (builder != null) {
                String pid = file.getFileName().toString();
                byte[] data = Files.readAllBytes(file);
                builder.addFileConfiguration(pid, data);
            }
            return FileVisitResult.CONTINUE;
        }
    });
    return profiles;
}
Also used : Path(java.nio.file.Path) HashMap(java.util.HashMap) FileVisitResult(java.nio.file.FileVisitResult) IOException(java.io.IOException) ProfileBuilder(org.apache.karaf.profile.ProfileBuilder) Profile(org.apache.karaf.profile.Profile) BasicFileAttributes(java.nio.file.attribute.BasicFileAttributes)

Example 8 with Profile

use of org.apache.karaf.profile.Profile in project karaf by apache.

the class ProfilesTest method testProfilesOverlayComments.

@Test
public void testProfilesOverlayComments() {
    String pid1 = "# My comment\nfoo = bar\n";
    Profile parent = ProfileBuilder.Factory.create("parent").addFileConfiguration("pid1.cfg", pid1.getBytes()).getProfile();
    Profile profile = ProfileBuilder.Factory.create("test").addConfiguration("pid1", "foo", "bar2").addParent("parent").getProfile();
    Map<String, Profile> profiles = new HashMap<>();
    profiles.put(parent.getId(), parent);
    profiles.put(profile.getId(), profile);
    Profile overlay = Profiles.getOverlay(profile, profiles);
    String outPid1 = new String(overlay.getFileConfiguration("pid1.cfg"));
    assertEquals(String.format("%1$s%n%2$s%n", "# My comment", "foo = bar2"), outPid1);
}
Also used : HashMap(java.util.HashMap) Profile(org.apache.karaf.profile.Profile) Test(org.junit.Test)

Example 9 with Profile

use of org.apache.karaf.profile.Profile in project karaf by apache.

the class ProfileList method execute.

@Override
public Object execute() throws Exception {
    List<String> ids = new ArrayList<>(profileService.getProfiles());
    Collections.sort(ids);
    ShellTable table = new ShellTable();
    table.column("id");
    table.column("parents");
    for (String id : ids) {
        Profile profile = profileService.getProfile(id);
        if (profile != null && (hidden || !profile.isHidden())) {
            String parents = join(" ", profile.getParentIds());
            table.addRow().addContent(id, parents);
        }
    }
    table.print(System.out);
    return null;
}
Also used : ShellTable(org.apache.karaf.shell.support.table.ShellTable) ArrayList(java.util.ArrayList) Profile(org.apache.karaf.profile.Profile)

Example 10 with Profile

use of org.apache.karaf.profile.Profile in project karaf by apache.

the class ProfileServiceImpl method deleteProfile.

@Override
@SuppressWarnings("unused")
public void deleteProfile(String profileId) {
    assertNotNull(profileId, "profileId is null");
    try (LockHandle lock = acquireWriteLock()) {
        final Profile lastProfile = getRequiredProfile(profileId);
        deleteProfileFromCache(lastProfile);
    }
}
Also used : LockHandle(org.apache.karaf.profile.LockHandle) Profile(org.apache.karaf.profile.Profile)

Aggregations

Profile (org.apache.karaf.profile.Profile)20 HashMap (java.util.HashMap)5 ArrayList (java.util.ArrayList)4 Features (org.apache.karaf.features.internal.model.Features)4 Test (org.junit.Test)4 HashSet (java.util.HashSet)3 LinkedHashMap (java.util.LinkedHashMap)3 LinkedHashSet (java.util.LinkedHashSet)3 Map (java.util.Map)3 TreeMap (java.util.TreeMap)3 Properties (org.apache.felix.utils.properties.Properties)3 Downloader (org.apache.karaf.features.internal.download.Downloader)3 Feature (org.apache.karaf.features.internal.model.Feature)3 LockHandle (org.apache.karaf.profile.LockHandle)3 IOException (java.io.IOException)2 Bundle (org.apache.karaf.features.internal.model.Bundle)2 Conditional (org.apache.karaf.features.internal.model.Conditional)2 ConfigFile (org.apache.karaf.features.internal.model.ConfigFile)2 ProfileBuilder (org.apache.karaf.profile.ProfileBuilder)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1