if (!startupPropertiesFile.getParentFile().exists()) {
startupPropertiesFile.getParentFile().mkdirs();
}
}
FeaturesService featuresService = new OfflineFeaturesService();
Collection<Artifact> dependencies = project.getDependencyArtifacts();
StringBuilder buf = new StringBuilder();
for (Artifact artifact : dependencies) {
dontAddToStartup = "runtime".equals(artifact.getScope());
if ("kar".equals(artifact.getType()) && acceptScope(artifact)) {
File file = artifact.getFile();
try {
Kar kar = new Kar(file.toURI());
kar.extract(new File(system.getPath()), new File(workDirectory));
for (URI repoUri : kar.getFeatureRepos()) {
featuresService.removeRepository(repoUri);
featuresService.addRepository(repoUri);
}
} catch (Exception e) {
throw new RuntimeException("Could not install kar: " + artifact.toString() + "\n", e);
//buf.append("Could not install kar: ").append(artifact.toString()).append("\n");
//buf.append(e.getMessage()).append("\n\n");
}
}
if ("features".equals(artifact.getClassifier()) && acceptScope(artifact)) {
String uri = this.dependencyHelper.artifactToMvn(artifact);
File source = artifact.getFile();
DefaultRepositoryLayout layout = new DefaultRepositoryLayout();
//remove timestamp version
artifact = factory.createArtifactWithClassifier(artifact.getGroupId(), artifact.getArtifactId(), artifact.getBaseVersion(), artifact.getType(), artifact.getClassifier());
File target = new File(system.resolve(layout.pathOf(artifact)));
if (!target.exists()) {
target.getParentFile().mkdirs();
try {
copy(source, target);
} catch (RuntimeException e) {
getLog().error("Could not copy features " + uri + " from source file " + source, e);
}
// for snapshot, generate the repository metadata in order to avoid override of snapshot from remote repositories
if (artifact.isSnapshot()) {
getLog().debug("Feature " + uri + " is a SNAPSHOT, generate the maven-metadata-local.xml file");
File metadataTarget = new File(target.getParentFile(), "maven-metadata-local.xml");
try {
MavenUtil.generateMavenMetadata(artifact, 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");
}
}
}
try {
featuresService.addRepository(URI.create(uri));
} catch (Exception e) {
buf.append("Could not install feature: ").append(artifact.toString()).append("\n");
buf.append(e.getMessage()).append("\n\n");
}
}