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);
}
}
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;
}
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);
}
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;
}
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);
}
}
Aggregations