Search in sources :

Example 6 with Bundle

use of org.apache.sling.maven.projectsupport.bundlelist.v1_0_0.Bundle in project sling by apache.

the class AbstractUsingBundleListMojo method initBundleList.

private final void initBundleList() throws IOException, XmlPullParserException, MojoExecutionException {
    initArtifactDefinitions();
    if (BundleListUtils.isCurrentArtifact(project, defaultBundleList)) {
        initializedBundleList = readBundleList(bundleListFile);
    } else {
        initializedBundleList = new BundleList();
        if (includeDefaultBundles) {
            Artifact defBndListArtifact = getArtifact(defaultBundleList.getGroupId(), defaultBundleList.getArtifactId(), defaultBundleList.getVersion(), defaultBundleList.getType(), defaultBundleList.getClassifier());
            getLog().info("Using bundle list file from " + defBndListArtifact.getFile().getAbsolutePath());
            initializedBundleList = readBundleList(defBndListArtifact.getFile());
        }
        if (bundleListFile.exists()) {
            initializedBundleList.merge(readBundleList(bundleListFile));
        }
    }
    // add additional bundles
    if (additionalBundles != null) {
        for (ArtifactDefinition def : additionalBundles) {
            initializedBundleList.add(def.toBundleList());
        }
    }
    interpolateProperties(initializedBundleList, project, mavenSession);
    // check for partial bundle lists
    final Set<Artifact> dependencies = project.getDependencyArtifacts();
    for (Artifact artifact : dependencies) {
        if (PARTIAL.equals(artifact.getType())) {
            getLog().info(String.format("Merging partial bundle list %s:%s:%s", artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion()));
            initializedBundleList.merge(readBundleList(artifact.getFile()));
        }
    }
    // handle exclusions
    if (bundleExclusions != null) {
        for (ArtifactDefinition def : bundleExclusions) {
            initializedBundleList.remove(def.toBundleList(), false);
        }
    }
    initBundleList(initializedBundleList);
    interpolateProperties(initializedBundleList, project, mavenSession);
    rewriteBundleList(initializedBundleList);
}
Also used : BundleListUtils.readBundleList(org.apache.sling.maven.projectsupport.BundleListUtils.readBundleList) BundleList(org.apache.sling.maven.projectsupport.bundlelist.v1_0_0.BundleList) Artifact(org.apache.maven.artifact.Artifact)

Example 7 with Bundle

use of org.apache.sling.maven.projectsupport.bundlelist.v1_0_0.Bundle in project sling by apache.

the class CheckBundleListForSnapshotsMojo method executeWithArtifacts.

@Override
protected void executeWithArtifacts() throws MojoExecutionException, MojoFailureException {
    List<Bundle> snapshots = new ArrayList<Bundle>();
    BundleList bundleList = getInitializedBundleList();
    for (StartLevel level : bundleList.getStartLevels()) {
        for (Bundle bundle : level.getBundles()) {
            if (isSnapshot(bundle)) {
                snapshots.add(bundle);
            }
        }
    }
    if (!snapshots.isEmpty()) {
        getLog().error("The following entries in the bundle list file are SNAPSHOTs:");
        for (Bundle bundle : snapshots) {
            getLog().error(String.format("     %s:%s:%s", bundle.getGroupId(), bundle.getArtifactId(), bundle.getVersion()));
        }
        if (failOnSnapshot) {
            throw new MojoFailureException("SNAPSHOTs were found in the bundle list. See log.");
        }
    }
}
Also used : BundleList(org.apache.sling.maven.projectsupport.bundlelist.v1_0_0.BundleList) Bundle(org.apache.sling.maven.projectsupport.bundlelist.v1_0_0.Bundle) ArrayList(java.util.ArrayList) MojoFailureException(org.apache.maven.plugin.MojoFailureException) StartLevel(org.apache.sling.maven.projectsupport.bundlelist.v1_0_0.StartLevel)

Example 8 with Bundle

use of org.apache.sling.maven.projectsupport.bundlelist.v1_0_0.Bundle in project sling by apache.

the class CreateKarafFeatureDescriptorMojo method executeWithArtifacts.

@Override
protected void executeWithArtifacts() throws MojoExecutionException, MojoFailureException {
    Document doc = new Document();
    Element features = new Element("features");
    doc.setRootElement(features);
    features.setAttribute("name", featuresName);
    Element feature = new Element("feature");
    features.addContent(feature);
    feature.setAttribute("name", featureName);
    feature.setAttribute("version", featureVersion);
    BundleList bundleList = getInitializedBundleList();
    for (StartLevel level : bundleList.getStartLevels()) {
        for (Bundle bundle : level.getBundles()) {
            String bundleRef = String.format("mvn:%s/%s/%s", bundle.getGroupId(), bundle.getArtifactId(), bundle.getVersion());
            feature.addContent(new Element("bundle").setText(bundleRef));
        }
    }
    FileOutputStream out = null;
    try {
        out = new FileOutputStream(outputFile);
        new XMLOutputter(Format.getPrettyFormat().setEncoding("UTF-8")).output(doc, out);
        projectHelper.attachArtifact(project, TYPE, CLASSIFIER, outputFile);
    } catch (IOException e) {
        throw new MojoExecutionException("Unable to write features.xml", e);
    } finally {
        if (out != null) {
            try {
                out.close();
            } catch (IOException e) {
            }
        }
    }
}
Also used : XMLOutputter(org.jdom.output.XMLOutputter) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) BundleList(org.apache.sling.maven.projectsupport.bundlelist.v1_0_0.BundleList) Bundle(org.apache.sling.maven.projectsupport.bundlelist.v1_0_0.Bundle) Element(org.jdom.Element) FileOutputStream(java.io.FileOutputStream) StartLevel(org.apache.sling.maven.projectsupport.bundlelist.v1_0_0.StartLevel) IOException(java.io.IOException) Document(org.jdom.Document)

Example 9 with Bundle

use of org.apache.sling.maven.projectsupport.bundlelist.v1_0_0.Bundle in project sling by apache.

the class BundleListContentProvider method handleResourcesRoot.

private Iterator<String> handleResourcesRoot() {
    final Set<String> subDirs = new HashSet<String>();
    subDirs.add(BUNDLE_PATH_PREFIX);
    subDirs.add(CONFIG_PATH_PREFIX);
    subDirs.add("resources/corebundles");
    subDirs.add(INSTALL_PATH_PREFIX);
    // Compute the set of run modes in our bundles
    final Set<String> runModes = new HashSet<String>();
    for (final StartLevel level : getInitializedBundleList().getStartLevels()) {
        for (Bundle bundle : level.getBundles()) {
            final String modes = bundle.getRunModes();
            if (modes != null && modes.length() > 0) {
                for (String m : modes.split(",")) {
                    runModes.add("." + m);
                }
            }
        }
    }
    // Add one install subdir per run mode
    for (String m : runModes) {
        subDirs.add(INSTALL_PATH_PREFIX + m);
    }
    return subDirs.iterator();
}
Also used : Bundle(org.apache.sling.maven.projectsupport.bundlelist.v1_0_0.Bundle) StartLevel(org.apache.sling.maven.projectsupport.bundlelist.v1_0_0.StartLevel) HashSet(java.util.HashSet)

Example 10 with Bundle

use of org.apache.sling.maven.projectsupport.bundlelist.v1_0_0.Bundle in project sling by apache.

the class BundleListContentProvider method addBundles.

private void addBundles(Collection<String> bundles, int startLevel, String runMode) {
    for (final StartLevel level : getInitializedBundleList().getStartLevels()) {
        if (level.getStartLevel() == startLevel) {
            for (final Bundle bundle : level.getBundles()) {
                if (!runModeMatches(bundle, runMode)) {
                    continue;
                }
                final ArtifactDefinition d = new ArtifactDefinition(bundle, startLevel);
                try {
                    final Artifact artifact = getArtifact(d);
                    bundles.add(artifact.getFile().toURI().toURL().toExternalForm());
                } catch (Exception e) {
                    getLog().error("Unable to resolve artifact ", e);
                }
            }
        }
    }
}
Also used : Bundle(org.apache.sling.maven.projectsupport.bundlelist.v1_0_0.Bundle) StartLevel(org.apache.sling.maven.projectsupport.bundlelist.v1_0_0.StartLevel) Artifact(org.apache.maven.artifact.Artifact) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException)

Aggregations

Bundle (org.apache.sling.maven.projectsupport.bundlelist.v1_0_0.Bundle)11 StartLevel (org.apache.sling.maven.projectsupport.bundlelist.v1_0_0.StartLevel)10 BundleList (org.apache.sling.maven.projectsupport.bundlelist.v1_0_0.BundleList)8 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)7 IOException (java.io.IOException)6 ArrayList (java.util.ArrayList)3 Artifact (org.apache.maven.artifact.Artifact)3 MojoFailureException (org.apache.maven.plugin.MojoFailureException)3 FileWriter (java.io.FileWriter)2 HashSet (java.util.HashSet)2 BundleListUtils.readBundleList (org.apache.sling.maven.projectsupport.BundleListUtils.readBundleList)2 ArchiverException (org.codehaus.plexus.archiver.ArchiverException)2 XmlPullParserException (org.codehaus.plexus.util.xml.pull.XmlPullParserException)2 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 MalformedURLException (java.net.MalformedURLException)1 Dependency (org.apache.maven.model.Dependency)1 DefaultMaven2OsgiConverter (org.apache.maven.shared.osgi.DefaultMaven2OsgiConverter)1 Maven2OsgiConverter (org.apache.maven.shared.osgi.Maven2OsgiConverter)1 BundleListXpp3Writer (org.apache.sling.maven.projectsupport.bundlelist.v1_0_0.io.xpp3.BundleListXpp3Writer)1