Search in sources :

Example 11 with RunMode

use of org.apache.sling.provisioning.model.RunMode in project sling by apache.

the class FrameworkProperties method getProperties.

public synchronized Map<String, String> getProperties(FeatureFilter filter) {
    if (fprops == null) {
        fprops = new HashMap<String, String>();
        for (Feature f : model.getFeatures()) {
            if (filter != null && filter.ignoreFeature(f)) {
                continue;
            }
            for (RunMode rm : f.getRunModes()) {
                final KeyValueMap<String> settings = rm.getSettings();
                if (settings.size() > 0) {
                    log.info("Using settings from Feature {}, RunMode {} as framework properties", f.getName(), rm.getNames());
                    for (Map.Entry<String, String> e : settings) {
                        log.info("framework property set from provisioning model: {}={}", e.getKey(), e.getValue());
                        fprops.put(e.getKey(), e.getValue());
                    }
                }
            }
        }
    }
    return fprops;
}
Also used : RunMode(org.apache.sling.provisioning.model.RunMode) Feature(org.apache.sling.provisioning.model.Feature) KeyValueMap(org.apache.sling.provisioning.model.KeyValueMap) Map(java.util.Map) HashMap(java.util.HashMap)

Example 12 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)

Example 13 with RunMode

use of org.apache.sling.provisioning.model.RunMode in project sling by apache.

the class ModelPreprocessor method searchSlingstartDependencies.

/**
     * Search for dependent slingstart/slingfeature artifacts and remove them from the effective model.
     * @throws MavenExecutionException
     */
private List<Model> searchSlingstartDependencies(final Environment env, final ProjectInfo info, final Model rawModel, final Model effectiveModel) throws MavenExecutionException {
    // slingstart or slingfeature
    final List<Model> dependencies = new ArrayList<>();
    for (final Feature feature : effectiveModel.getFeatures()) {
        for (final RunMode runMode : feature.getRunModes()) {
            for (final ArtifactGroup group : runMode.getArtifactGroups()) {
                final List<org.apache.sling.provisioning.model.Artifact> removeList = new ArrayList<>();
                for (final org.apache.sling.provisioning.model.Artifact a : group) {
                    if (a.getType().equals(BuildConstants.PACKAGING_SLINGSTART) || a.getType().equals(BuildConstants.PACKAGING_PARTIAL_SYSTEM)) {
                        final Dependency dep = new Dependency();
                        dep.setGroupId(a.getGroupId());
                        dep.setArtifactId(a.getArtifactId());
                        dep.setVersion(a.getVersion());
                        dep.setType(BuildConstants.PACKAGING_PARTIAL_SYSTEM);
                        if (a.getType().equals(BuildConstants.PACKAGING_SLINGSTART)) {
                            dep.setClassifier(BuildConstants.PACKAGING_PARTIAL_SYSTEM);
                        } else {
                            dep.setClassifier(a.getClassifier());
                        }
                        dep.setScope(Artifact.SCOPE_PROVIDED);
                        env.logger.debug("- adding dependency " + ModelUtils.toString(dep));
                        info.project.getDependencies().add(dep);
                        // if it's a project from the current reactor build, we can't resolve it right now
                        final String key = a.getGroupId() + ":" + a.getArtifactId();
                        final ProjectInfo depInfo = env.modelProjects.get(key);
                        if (depInfo != null) {
                            env.logger.debug("Found reactor " + a.getType() + " dependency : " + a);
                            final Model model = addDependencies(env, depInfo);
                            if (model == null) {
                                throw new MavenExecutionException("Recursive model dependency list including project " + info.project, (File) null);
                            }
                            dependencies.add(model);
                            info.includedModels.put(a, depInfo.localModel);
                        } else {
                            env.logger.debug("Found external " + a.getType() + " dependency: " + a);
                            // "external" dependency, we can already resolve it
                            final File modelFile = resolveSlingstartArtifact(env, info.project, dep);
                            FileReader r = null;
                            try {
                                r = new FileReader(modelFile);
                                final Model model = ModelReader.read(r, modelFile.getAbsolutePath());
                                info.includedModels.put(a, model);
                                final Map<Traceable, String> errors = ModelUtility.validate(model);
                                if (errors != null) {
                                    throw new MavenExecutionException("Unable to read model file from " + modelFile + " : " + errors, modelFile);
                                }
                                final Model fullModel = processSlingstartDependencies(env, info, dep, model);
                                dependencies.add(fullModel);
                            } catch (final IOException ioe) {
                                throw new MavenExecutionException("Unable to read model file from " + modelFile, ioe);
                            } finally {
                                try {
                                    if (r != null) {
                                        r.close();
                                    }
                                } catch (final IOException io) {
                                // ignore
                                }
                            }
                        }
                        removeList.add(a);
                    }
                }
                for (final org.apache.sling.provisioning.model.Artifact r : removeList) {
                    group.remove(r);
                    final Feature localModelFeature = rawModel.getFeature(feature.getName());
                    if (localModelFeature != null) {
                        final RunMode localRunMode = localModelFeature.getRunMode(runMode.getNames());
                        if (localRunMode != null) {
                            final ArtifactGroup localAG = localRunMode.getArtifactGroup(group.getStartLevel());
                            if (localAG != null) {
                                localAG.remove(r);
                            }
                        }
                    }
                }
            }
        }
    }
    return dependencies;
}
Also used : ArrayList(java.util.ArrayList) Dependency(org.apache.maven.model.Dependency) IOException(java.io.IOException) Feature(org.apache.sling.provisioning.model.Feature) Artifact(org.apache.maven.artifact.Artifact) DefaultArtifact(org.apache.maven.artifact.DefaultArtifact) MavenExecutionException(org.apache.maven.MavenExecutionException) RunMode(org.apache.sling.provisioning.model.RunMode) Model(org.apache.sling.provisioning.model.Model) FileReader(java.io.FileReader) Traceable(org.apache.sling.provisioning.model.Traceable) ArtifactGroup(org.apache.sling.provisioning.model.ArtifactGroup) File(java.io.File)

Example 14 with RunMode

use of org.apache.sling.provisioning.model.RunMode in project sling by apache.

the class PreparePackageMojo method buildBootstrapFile.

/**
     * Build the bootstrap file for the given packaging run mode
     */
private void buildBootstrapFile(final Model model, final String packageRunMode, final File outputDir) throws MojoExecutionException {
    final StringBuilder sb = new StringBuilder();
    final Feature launchpadFeature = model.getFeature(ModelConstants.FEATURE_LAUNCHPAD);
    if (launchpadFeature != null) {
        final RunMode launchpadRunMode = launchpadFeature.getRunMode();
        if (launchpadRunMode != null) {
            final Configuration c = launchpadRunMode.getConfiguration(ModelConstants.CFG_LAUNCHPAD_BOOTSTRAP);
            if (c != null) {
                sb.append(c.getProperties().get(c.getPid()));
                sb.append('\n');
            }
        }
        final RunMode packageRM = launchpadFeature.getRunMode(new String[] { packageRunMode });
        if (packageRM != null) {
            final Configuration c = packageRM.getConfiguration(ModelConstants.CFG_LAUNCHPAD_BOOTSTRAP);
            if (c != null) {
                sb.append(c.getProperties().get(c.getPid()));
                sb.append('\n');
            }
        }
    }
    if (sb.length() > 0) {
        final File file = new File(outputDir, BOOTSTRAP_FILE);
        getLog().debug(String.format("Creating bootstrap file at %s", file.getPath()));
        try {
            FileUtils.fileWrite(file, sb.toString());
        } catch (final IOException ioe) {
            throw new MojoExecutionException("Unable to write bootstrap file.", ioe);
        }
    }
}
Also used : Configuration(org.apache.sling.provisioning.model.Configuration) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) RunMode(org.apache.sling.provisioning.model.RunMode) IOException(java.io.IOException) Feature(org.apache.sling.provisioning.model.Feature) File(java.io.File)

Example 15 with RunMode

use of org.apache.sling.provisioning.model.RunMode in project sling by apache.

the class PreparePackageMojo method buildSettings.

/**
     * Build the settings for the given packaging run mode
     */
private void buildSettings(final Model model, final String packageRunMode, final File outputDir) throws MojoExecutionException {
    final Properties settings = new Properties();
    final Feature launchpadFeature = model.getFeature(ModelConstants.FEATURE_LAUNCHPAD);
    if (launchpadFeature != null) {
        final RunMode launchpadRunMode = launchpadFeature.getRunMode();
        if (launchpadRunMode != null) {
            for (final Map.Entry<String, String> entry : launchpadRunMode.getSettings()) {
                settings.put(entry.getKey(), deescapeVariablePlaceholders(entry.getValue()));
            }
        }
    }
    final Feature bootFeature = model.getFeature(ModelConstants.FEATURE_BOOT);
    if (bootFeature != null) {
        final RunMode bootRunMode = bootFeature.getRunMode();
        if (bootRunMode != null) {
            for (final Map.Entry<String, String> entry : bootRunMode.getSettings()) {
                settings.put(entry.getKey(), deescapeVariablePlaceholders(entry.getValue()));
            }
        }
    }
    for (final Feature f : model.getFeatures()) {
        final RunMode packageRM = f.getRunMode(new String[] { packageRunMode });
        if (packageRM != null) {
            for (final Map.Entry<String, String> entry : packageRM.getSettings()) {
                settings.put(entry.getKey(), deescapeVariablePlaceholders(entry.getValue()));
            }
        }
    }
    if (settings.size() > 0) {
        final File settingsFile = new File(outputDir, PROPERTIES_FILE);
        getLog().debug(String.format("Creating settings at %s", settingsFile.getPath()));
        FileWriter writer = null;
        try {
            writer = new FileWriter(settingsFile);
            settings.store(writer, null);
        } catch (final IOException ioe) {
            throw new MojoExecutionException("Unable to write properties file.", ioe);
        } finally {
            IOUtils.closeQuietly(writer);
        }
    }
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) RunMode(org.apache.sling.provisioning.model.RunMode) FileWriter(java.io.FileWriter) IOException(java.io.IOException) Properties(java.util.Properties) Feature(org.apache.sling.provisioning.model.Feature) HashMap(java.util.HashMap) Map(java.util.Map) File(java.io.File)

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