Search in sources :

Example 16 with RunMode

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);
                }
            }
        }
    }
}
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 RunMode

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;
}
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

RunMode (org.apache.sling.provisioning.model.RunMode)17 Feature (org.apache.sling.provisioning.model.Feature)15 ArtifactGroup (org.apache.sling.provisioning.model.ArtifactGroup)11 File (java.io.File)9 IOException (java.io.IOException)8 HashMap (java.util.HashMap)6 Artifact (org.apache.maven.artifact.Artifact)6 Map (java.util.Map)5 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)5 Artifact (org.apache.sling.provisioning.model.Artifact)5 Configuration (org.apache.sling.provisioning.model.Configuration)5 Traceable (org.apache.sling.provisioning.model.Traceable)4 ArrayList (java.util.ArrayList)3 Manifest (java.util.jar.Manifest)3 MavenExecutionException (org.apache.maven.MavenExecutionException)3 Model (org.apache.sling.provisioning.model.Model)3 FileOutputStream (java.io.FileOutputStream)2 FileWriter (java.io.FileWriter)2 InputStream (java.io.InputStream)2 StringReader (java.io.StringReader)2