use of org.apache.sling.provisioning.model.RunMode in project sling by apache.
the class ModelPreprocessor method addDependenciesFromModel.
/**
* Add all dependencies from the model
* @param env The environment
* @param info The project info
* @param scope The scope which the new dependencies should have
* @throws MavenExecutionException
*/
private void addDependenciesFromModel(final Environment env, final ProjectInfo info, final String scope) throws MavenExecutionException {
if (info.project.getPackaging().equals(BuildConstants.PACKAGING_SLINGSTART)) {
// add base artifact if defined in current model
final org.apache.sling.provisioning.model.Artifact baseArtifact = ModelUtils.findBaseArtifact(info.model);
final String[] classifiers = new String[] { null, BuildConstants.CLASSIFIER_APP, BuildConstants.CLASSIFIER_WEBAPP };
for (final String c : classifiers) {
final Dependency dep = new Dependency();
dep.setGroupId(baseArtifact.getGroupId());
dep.setArtifactId(baseArtifact.getArtifactId());
dep.setVersion(baseArtifact.getVersion());
dep.setType(baseArtifact.getType());
dep.setClassifier(c);
if (BuildConstants.CLASSIFIER_WEBAPP.equals(c)) {
dep.setType(BuildConstants.TYPE_WAR);
}
dep.setScope(scope);
info.project.getDependencies().add(dep);
env.logger.debug("- adding base dependency " + ModelUtils.toString(dep));
}
}
for (final Feature feature : info.model.getFeatures()) {
// skip launchpad feature
if (feature.getName().equals(ModelConstants.FEATURE_LAUNCHPAD)) {
continue;
}
for (final RunMode runMode : feature.getRunModes()) {
for (final ArtifactGroup group : runMode.getArtifactGroups()) {
for (final org.apache.sling.provisioning.model.Artifact a : group) {
if (a.getGroupId().equals(info.project.getGroupId()) && a.getArtifactId().equals(info.project.getArtifactId()) && a.getVersion().equals(info.project.getVersion())) {
// skip artifact from the same project
env.logger.debug("- skipping dependency " + a.toMvnUrl());
continue;
}
final Dependency dep = new Dependency();
dep.setGroupId(a.getGroupId());
dep.setArtifactId(a.getArtifactId());
dep.setVersion(a.getVersion());
dep.setType(a.getType());
dep.setClassifier(a.getClassifier());
dep.setScope(scope);
env.logger.debug("- adding dependency " + ModelUtils.toString(dep));
info.project.getDependencies().add(dep);
}
}
}
}
}
use of org.apache.sling.provisioning.model.RunMode in project sling by apache.
the class Launcher method getClasspathURLs.
/** Convert a Model feature to a set of URLs meant to setup
* an URLClassLoader.
*/
List<URL> getClasspathURLs(Model m, String featureName) throws MalformedURLException {
final List<URL> result = new ArrayList<URL>();
// Add all URLs from the special feature to our classpath
final Feature f = m.getFeature(featureName);
if (f == null) {
log.warn("No {} feature found in provisioning model, nothing to add to our classpath", featureName);
} else {
for (RunMode rm : f.getRunModes()) {
for (ArtifactGroup g : rm.getArtifactGroups()) {
for (Artifact a : g) {
final String url = MavenResolver.mvnUrl(a);
try {
result.add(new URL(url));
} catch (MalformedURLException e) {
final MalformedURLException up = new MalformedURLException("Invalid URL [" + url + "]");
up.initCause(e);
throw up;
}
}
}
}
}
return result;
}
Aggregations