Search in sources :

Example 16 with Feature

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);
                }
            }
        }
    }
}
Also used : RunMode(org.apache.sling.provisioning.model.RunMode) Dependency(org.apache.maven.model.Dependency) Feature(org.apache.sling.provisioning.model.Feature) ArtifactGroup(org.apache.sling.provisioning.model.ArtifactGroup)

Example 17 with Feature

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();
}
Also used : StringReader(java.io.StringReader) Model(org.apache.sling.provisioning.model.Model) Feature(org.apache.sling.provisioning.model.Feature) Section(org.apache.sling.provisioning.model.Section)

Example 18 with Feature

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());
}
Also used : Model(org.apache.sling.provisioning.model.Model) Feature(org.apache.sling.provisioning.model.Feature) Test(org.junit.Test)

Example 19 with Feature

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;
}
Also used : MalformedURLException(java.net.MalformedURLException) RunMode(org.apache.sling.provisioning.model.RunMode) ArrayList(java.util.ArrayList) Feature(org.apache.sling.provisioning.model.Feature) ArtifactGroup(org.apache.sling.provisioning.model.ArtifactGroup) URL(java.net.URL) Artifact(org.apache.sling.provisioning.model.Artifact)

Aggregations

Feature (org.apache.sling.provisioning.model.Feature)19 RunMode (org.apache.sling.provisioning.model.RunMode)15 File (java.io.File)9 IOException (java.io.IOException)9 ArtifactGroup (org.apache.sling.provisioning.model.ArtifactGroup)9 Model (org.apache.sling.provisioning.model.Model)7 Artifact (org.apache.sling.provisioning.model.Artifact)6 Traceable (org.apache.sling.provisioning.model.Traceable)6 HashMap (java.util.HashMap)5 Configuration (org.apache.sling.provisioning.model.Configuration)5 Map (java.util.Map)4 MavenExecutionException (org.apache.maven.MavenExecutionException)4 Artifact (org.apache.maven.artifact.Artifact)4 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)4 InputStream (java.io.InputStream)3 StringReader (java.io.StringReader)3 ArrayList (java.util.ArrayList)3 Section (org.apache.sling.provisioning.model.Section)3 FileWriter (java.io.FileWriter)2 Reader (java.io.Reader)2