use of org.apache.sling.provisioning.model.Feature 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.Feature in project sling by apache.
the class RepoinitTextProvider method extractFromModel.
private String extractFromModel(String sourceInfo, String rawText, String modelSection) throws IOException {
final StringReader reader = new StringReader(rawText);
final Model model = ModelReader.read(reader, sourceInfo);
final StringBuilder sb = new StringBuilder();
if (modelSection == null) {
throw new IllegalStateException("Model section name is null, cannot read model");
}
for (final Feature feature : model.getFeatures()) {
for (final Section section : feature.getAdditionalSections(modelSection)) {
sb.append("# ").append(modelSection).append(" from ").append(feature.getName()).append("\n");
sb.append("# ").append(section.getComment()).append("\n");
sb.append(section.getContents()).append("\n");
}
}
return sb.toString();
}
use of org.apache.sling.provisioning.model.Feature in project sling by apache.
the class IOTest method testAddition.
@Test
public void testAddition() throws Exception {
final Model model = U.readCompleteTestModel(new String[] { "additional.txt" });
final Feature f = model.getFeature("main");
assertNotNull(f);
assertEquals(1, f.getAdditionalSections().size());
assertEquals(1, f.getAdditionalSections("additional").size());
}
use of org.apache.sling.provisioning.model.Feature 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