@Override
public void addRepository(URI uri) throws Exception {
if (dontAddToStartup) {
getLog().info("Adding feature repository to system: " + uri);
if (featuresCfgFile.exists()) {
Properties properties = new Properties();
InputStream in = new FileInputStream(featuresCfgFile);
try {
properties.load(in);
} finally {
in.close();
}
String existingFeatureRepos = retrieveProperty(properties, FEATURES_REPOSITORIES);
if (!existingFeatureRepos.contains(uri.toString())) {
existingFeatureRepos = existingFeatureRepos + uri.toString();
properties.put(FEATURES_REPOSITORIES, existingFeatureRepos);
}
Features repo = readFeatures(uri);
for (String innerRepository : repo.getRepository()) {
String innerRepositoryPath = dependencyHelper.pathFromMaven(innerRepository);
File innerRepositoryTargetInSystemRepository = new File(system.resolve(innerRepositoryPath));
if (!innerRepositoryTargetInSystemRepository.exists()) {
File innerRepositorySourceFile = dependencyHelper.resolveById(innerRepository, getLog());
innerRepositoryTargetInSystemRepository.getParentFile().mkdirs();
copy(innerRepositorySourceFile, innerRepositoryTargetInSystemRepository);
// add metadata for snapshot
Artifact innerRepositoryArtifact = dependencyHelper.mvnToArtifact(innerRepository);
if (innerRepositoryArtifact.isSnapshot()) {
getLog().debug("Feature repository " + innerRepository + " is a SNAPSHOT, generate the maven-metadata-local.xml file");
File metadataTarget = new File(innerRepositoryTargetInSystemRepository.getParentFile(), "maven-metadata-local.xml");
try {
MavenUtil.generateMavenMetadata(innerRepositoryArtifact, metadataTarget);
} catch (Exception e) {
getLog().warn("Could not create maven-metadata-local.xml", e);
getLog().warn("It means that this SNAPSHOT could be overwritten by an older one present on remote repositories");
}
}
}
}
for (Feature feature : repo.getFeature()) {
featureSet.add(feature);
if (startupFeatures != null && startupFeatures.contains(feature.getName())) {
installFeature(feature, null);
} else if (bootFeatures != null && bootFeatures.contains(feature.getName())) {
localRepoFeatures.add(feature);
missingDependencies.addAll(feature.getDependencies());
String existingBootFeatures = retrieveProperty(properties, FEATURES_BOOT);
if (!existingBootFeatures.contains(feature.getName())) {
existingBootFeatures = existingBootFeatures + feature.getName();
properties.put(FEATURES_BOOT, existingBootFeatures);
}
} else if (installedFeatures != null && installedFeatures.contains(feature.getName())) {
localRepoFeatures.add(feature);
missingDependencies.addAll(feature.getDependencies());
}
}
if (addTransitiveFeatures) {
addMissingDependenciesToRepo();
}
FileOutputStream out = new FileOutputStream(featuresCfgFile);
try {
properties.save(out);
} finally {
out.close();
}
}
} else {