@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
@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
/** * Writes given {@link Profile} under a path specified as <code>root</code>. Directory name to store a profile is * derived from {@link Profile#getId()} * @param root * @param profile * @throws IOException */ public static void writeProfile(Path root, Profile profile) throws IOException { Path path = root.resolve(profile.getId().replace("-", root.getFileSystem().getSeparator()) + PROFILE_FOLDER_SUFFIX); Files.createDirectories(path); for (Map.Entry<String, byte[]> entry : profile.getFileConfigurations().entrySet()) { Files.write(path.resolve(entry.getKey()), entry.getValue(), StandardOpenOption.CREATE_NEW); } }
/** * Writes given {@link Profile} under a path specified as <code>root</code>. Directory name to store a profile is * derived from {@link Profile#getId()} * @param root * @param profile * @throws IOException */ public static void writeProfile(Path root, Profile profile) throws IOException { Path path = root.resolve(profile.getId().replaceAll("-", root.getFileSystem().getSeparator()) + PROFILE_FOLDER_SUFFIX); Files.createDirectories(path); for (Map.Entry<String, byte[]> entry : profile.getFileConfigurations().entrySet()) { Files.write(path.resolve(entry.getKey()), entry.getValue(), StandardOpenOption.CREATE_NEW); } }
/** * Adds or remove the specified feature repositories to the specified profile. */ private void handleFeatureRepositories(ProfileBuilder builder, String[] repositories, Profile profile) { Map<String, Object> conf = getConfigurationFromBuilder(builder, Profile.INTERNAL_PID); for (String repositoryURI : repositories) { if (set) { System.out.println("Adding feature repository:" + repositoryURI + " to profile:" + profile.getId()); } else if (delete) { System.out.println("Deleting feature repository:" + repositoryURI + " from profile:" + profile.getId()); } updateConfig(conf, ProfileConstants.REPOSITORY_PREFIX + repositoryURI.replace('/', '_'), repositoryURI, set, delete); } builder.addConfiguration(Profile.INTERNAL_PID, conf); }
/** * Adds or remove the specified features to the specified profile. */ private void handleFeatures(ProfileBuilder builder, String[] features, Profile profile) { Map<String, Object> conf = getConfigurationFromBuilder(builder, Profile.INTERNAL_PID); for (String feature : features) { if (delete) { System.out.println("Deleting feature:" + feature + " from profile:" + profile.getId()); } else { System.out.println("Adding feature:" + feature + " to profile:" + profile.getId()); } updateConfig(conf, ProfileConstants.FEATURE_PREFIX + feature.replace('/', '_'), feature, set, delete); builder.addConfiguration(Profile.INTERNAL_PID, conf); } }
/** * Adds or remove the specified feature repositories to the specified profile. */ private void handleFeatureRepositories(ProfileBuilder builder, String[] repositories, Profile profile) { Map<String, Object> conf = getConfigurationFromBuilder(builder, Profile.INTERNAL_PID); for (String repositoryURI : repositories) { if (set) { System.out.println("Adding feature repository:" + repositoryURI + " to profile:" + profile.getId()); } else if (delete) { System.out.println("Deleting feature repository:" + repositoryURI + " from profile:" + profile.getId()); } updateConfig(conf, ProfileConstants.REPOSITORY_PREFIX + repositoryURI.replace('/', '_'), repositoryURI, set, delete); } builder.addConfiguration(Profile.INTERNAL_PID, conf); }
/** * Adds or remove the specified features to the specified profile. */ private void handleFeatures(ProfileBuilder builder, String[] features, Profile profile) { Map<String, Object> conf = getConfigurationFromBuilder(builder, Profile.INTERNAL_PID); for (String feature : features) { if (delete) { System.out.println("Deleting feature:" + feature + " from profile:" + profile.getId()); } else { System.out.println("Adding feature:" + feature + " to profile:" + profile.getId()); } updateConfig(conf, ProfileConstants.FEATURE_PREFIX + feature.replace('/', '_'), feature, set, delete); builder.addConfiguration(Profile.INTERNAL_PID, conf); } }
/** * Adds or remove the specified overrides to the specified profile. * @param overrides The array of overrides. * @param profile The target profile. */ private void handleOverrides(ProfileBuilder builder, String[] overrides, Profile profile) { Map<String, Object> conf = getConfigurationFromBuilder(builder, Profile.INTERNAL_PID); for (String override : overrides) { if (set) { System.out.println("Adding override:" + override + " to profile:" + profile.getId()); } else if (delete) { System.out.println("Deleting override:" + override + " from profile:" + profile.getId()); } updateConfig(conf, ProfileConstants.OVERRIDE_PREFIX + override.replace('/', '_'), override, set, delete); } builder.addConfiguration(Profile.INTERNAL_PID, conf); }
/** * Adds or remove the specified bundles to the specified profile. * @param bundles The array of bundles. * @param profile The target profile. */ private void handleBundles(ProfileBuilder builder, String[] bundles, Profile profile) { Map<String, Object> conf = getConfigurationFromBuilder(builder, Profile.INTERNAL_PID); for (String bundle : bundles) { if (set) { System.out.println("Adding bundle:" + bundle + " to profile:" + profile.getId()); } else if (delete) { System.out.println("Deleting bundle:" + bundle + " from profile:" + profile.getId()); } updateConfig(conf, ProfileConstants.BUNDLE_PREFIX + bundle.replace('/', '_'), bundle, set, delete); } builder.addConfiguration(Profile.INTERNAL_PID, conf); }
/** * Adds or remove the specified overrides to the specified profile. * @param overrides The array of overrides. * @param profile The target profile. */ private void handleOverrides(ProfileBuilder builder, String[] overrides, Profile profile) { Map<String, Object> conf = getConfigurationFromBuilder(builder, Profile.INTERNAL_PID); for (String override : overrides) { if (set) { System.out.println("Adding override:" + override + " to profile:" + profile.getId()); } else if (delete) { System.out.println("Deleting override:" + override + " from profile:" + profile.getId()); } updateConfig(conf, ProfileConstants.OVERRIDE_PREFIX + override.replace('/', '_'), override, set, delete); } builder.addConfiguration(Profile.INTERNAL_PID, conf); }
/** * Adds or remove the specified bundles to the specified profile. * @param bundles The array of bundles. * @param profile The target profile. */ private void handleBundles(ProfileBuilder builder, String[] bundles, Profile profile) { Map<String, Object> conf = getConfigurationFromBuilder(builder, Profile.INTERNAL_PID); for (String bundle : bundles) { if (set) { System.out.println("Adding bundle:" + bundle + " to profile:" + profile.getId()); } else if (delete) { System.out.println("Deleting bundle:" + bundle + " from profile:" + profile.getId()); } updateConfig(conf, ProfileConstants.BUNDLE_PREFIX + bundle.replace('/', '_'), bundle, set, delete); } builder.addConfiguration(Profile.INTERNAL_PID, conf); }
/** * Adds or remove the specified libraries to the specified profile. * @param libs The array of libs. * @param profile The target profile. * @param libType The type of lib. Used just for the command output. * @param libPrefix The prefix of the lib. */ private void handleLibraries(ProfileBuilder builder, String[] libs, Profile profile, String libType, String libPrefix) { Map<String, Object> conf = getConfigurationFromBuilder(builder, Profile.INTERNAL_PID); for (String lib : libs) { if (set) { System.out.println("Adding "+libType+":" + lib + " to profile:" + profile.getId()); } else if (delete) { System.out.println("Deleting "+libType+":" + lib + " from profile:" + profile.getId()); } updateConfig(conf, libPrefix + lib.replace('/', '_'), lib, set, delete); } builder.addConfiguration(Profile.INTERNAL_PID, conf); }
@Override public ProfileBuilder from(Profile profile) { profileId = profile.getId(); setFileConfigurations(profile.getFileConfigurations()); return this; }
@Override public ProfileBuilder from(Profile profile) { profileId = profile.getId(); setFileConfigurations(profile.getFileConfigurations()); return this; }
protected void createOrUpdateProfile(Profile lastProfile, Profile profile) { if (lastProfile != null) { deleteProfileFromCache(lastProfile); } try { loadCache(); for (String parentId : profile.getParentIds()) { if (!cache.containsKey(parentId)) { throw new IllegalStateException("Parent profile " + parentId + " does not exist"); } } Profiles.writeProfile(profilesDirectory, profile); if (cache != null) { cache.put(profile.getId(), profile); } } catch (IOException e) { throw new IllegalStateException("Error writing profiles", e); } }
@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); } }
@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); } }
@Override @SuppressWarnings("unused") public void createProfile(Profile profile) { assertNotNull(profile, "profile is null"); try (LockHandle lock = acquireWriteLock()) { String profileId = profile.getId(); assertFalse(hasProfile(profileId), "Profile already exists: " + profileId); createOrUpdateProfile(null, profile); } }
@Override @SuppressWarnings("unused") public void createProfile(Profile profile) { assertNotNull(profile, "profile is null"); try (LockHandle lock = acquireWriteLock()) { String profileId = profile.getId(); assertFalse(hasProfile(profileId), "Profile already exists: " + profileId); createOrUpdateProfile(null, profile); } }