Search in sources :

Example 1 with Bundle

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

the class DisplayBundleUpdatesMojo method execute.

@SuppressWarnings("unchecked")
public void execute() throws MojoExecutionException, MojoFailureException {
    try {
        BundleList bundleList = readBundleList(bundleListFile);
        Set<Dependency> bundlesAsDependencies = new HashSet<Dependency>();
        for (StartLevel startLevel : bundleList.getStartLevels()) {
            for (Bundle bundle : startLevel.getBundles()) {
                bundlesAsDependencies.add(asDependency(bundle));
            }
        }
        logUpdates(getHelper().lookupDependenciesUpdates(bundlesAsDependencies, false));
    } catch (Exception e) {
        throw new MojoExecutionException("Unable to read bundle list.", e);
    }
}
Also used : 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) StartLevel(org.apache.sling.maven.projectsupport.bundlelist.v1_0_0.StartLevel) Dependency(org.apache.maven.model.Dependency) XmlPullParserException(org.codehaus.plexus.util.xml.pull.XmlPullParserException) IOException(java.io.IOException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MojoFailureException(org.apache.maven.plugin.MojoFailureException) HashSet(java.util.HashSet)

Example 2 with Bundle

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

the class AttachPartialBundleListMojo method execute.

public void execute() throws MojoExecutionException, MojoFailureException {
    final BundleList initializedBundleList;
    if (bundleListFile.exists()) {
        try {
            initializedBundleList = readBundleList(bundleListFile);
        } catch (IOException e) {
            throw new MojoExecutionException("Unable to read bundle list file", e);
        } catch (XmlPullParserException e) {
            throw new MojoExecutionException("Unable to read bundle list file", e);
        }
    } else {
        throw new MojoFailureException(String.format("Bundle list file %s does not exist.", bundleListFile.getAbsolutePath()));
    }
    interpolateProperties(initializedBundleList, this.project, this.mavenSession);
    final BundleListXpp3Writer writer = new BundleListXpp3Writer();
    try {
        this.bundleListOutput.getParentFile().mkdirs();
        writer.write(new FileWriter(bundleListOutput), initializedBundleList);
    } catch (IOException e) {
        throw new MojoExecutionException("Unable to write bundle list", e);
    }
    // if this project is a partial bundle list, it's the main artifact
    if (project.getPackaging().equals(PARTIAL)) {
        project.getArtifact().setFile(bundleListOutput);
    } else {
        // otherwise attach it as an additional artifact
        projectHelper.attachArtifact(project, TYPE, CLASSIFIER, bundleListOutput);
    }
    this.getLog().info("Attaching bundle list configuration");
    try {
        this.attachConfigurations();
    } catch (final IOException ioe) {
        throw new MojoExecutionException("Unable to attach configuration.", ioe);
    } catch (final ArchiverException ioe) {
        throw new MojoExecutionException("Unable to attach configuration.", ioe);
    }
}
Also used : BundleListXpp3Writer(org.apache.sling.maven.projectsupport.bundlelist.v1_0_0.io.xpp3.BundleListXpp3Writer) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) BundleListUtils.readBundleList(org.apache.sling.maven.projectsupport.BundleListUtils.readBundleList) BundleList(org.apache.sling.maven.projectsupport.bundlelist.v1_0_0.BundleList) ArchiverException(org.codehaus.plexus.archiver.ArchiverException) FileWriter(java.io.FileWriter) MojoFailureException(org.apache.maven.plugin.MojoFailureException) XmlPullParserException(org.codehaus.plexus.util.xml.pull.XmlPullParserException) IOException(java.io.IOException)

Example 3 with Bundle

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

the class CreateBundleJarMojo method addBundles.

private void addBundles() throws MojoExecutionException {
    BundleList bundles = getInitializedBundleList();
    for (StartLevel level : bundles.getStartLevels()) {
        for (Bundle bundle : level.getBundles()) {
            Artifact artifact = getArtifact(new ArtifactDefinition(bundle, level.getStartLevel()));
            final String destFileName = getPathForArtifact(level.getStartLevel(), bundle.getRunModes(), artifact.getFile().getName());
            try {
                jarArchiver.addFile(artifact.getFile(), destFileName);
            } catch (ArchiverException e) {
                throw new MojoExecutionException("Unable to add file to bundle jar file: " + artifact.getFile().getAbsolutePath(), e);
            }
        }
    }
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) BundleList(org.apache.sling.maven.projectsupport.bundlelist.v1_0_0.BundleList) ArchiverException(org.codehaus.plexus.archiver.ArchiverException) 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)

Example 4 with Bundle

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

the class SlingPaxOptions method slingBundleList.

public static CompositeOption slingBundleList(String groupId, String artifactId, String version, String type, String classifier) {
    final DefaultCompositeOption result = new DefaultCompositeOption();
    final String paxUrl = new StringBuilder().append("mvn:").append(groupId).append("/").append(artifactId).append("/").append(version == null ? "" : version).append("/").append(type == null ? "" : type).append("/").append(classifier == null ? "" : classifier).toString();
    // TODO BundleList should take an InputStream - for now copy to a tmp file for parsing
    log.info("Getting bundle list {}", paxUrl);
    File tmp = null;
    final Collection<String> testRunModes = getTestRunModes();
    try {
        tmp = dumpMvnUrlToTmpFile(paxUrl);
        final BundleList list = BundleListUtils.readBundleList(tmp);
        int counter = 0;
        int ignored = 0;
        for (StartLevel s : list.getStartLevels()) {
            // Start level < 0 means bootstrap in our bundle lists
            final int startLevel = s.getStartLevel() < 0 ? 1 : s.getStartLevel();
            for (Bundle b : s.getBundles()) {
                if (ignore(b)) {
                    log.info("Bundle ignored due to setIgnoredBundles: {}", b);
                    ignored++;
                    continue;
                }
                counter++;
                // TODO need better fragment detection
                // (but pax exam should really detect that by itself?)
                final List<String> KNOWN_FRAGMENTS = new ArrayList<String>();
                KNOWN_FRAGMENTS.add("org.apache.sling.extensions.webconsolebranding");
                final boolean isFragment = b.getArtifactId().contains("fragment") || KNOWN_FRAGMENTS.contains(b.getArtifactId());
                // Ignore bundles with run modes that do not match ours 
                final String bundleRunModes = b.getRunModes();
                if (bundleRunModes != null && bundleRunModes.length() > 0) {
                    boolean active = false;
                    for (String m : bundleRunModes.split(",")) {
                        if (testRunModes.contains(m)) {
                            active = true;
                            break;
                        }
                    }
                    if (!active) {
                        log.info("Ignoring bundle {} as none of its run modes [{}] are active in this test run {}", new Object[] { b.getArtifactId(), bundleRunModes, testRunModes });
                        continue;
                    }
                }
                if (isFragment) {
                    result.add(mavenBundle(b.getGroupId(), b.getArtifactId(), b.getVersion()).noStart());
                } else if (startLevel == 0) {
                    result.add(mavenBundle(b.getGroupId(), b.getArtifactId(), b.getVersion()));
                } else {
                    result.add(mavenBundle(b.getGroupId(), b.getArtifactId(), b.getVersion()).startLevel(startLevel));
                }
                log.info("Bundle added: {}/{}/{}", new Object[] { b.getGroupId(), b.getArtifactId(), b.getVersion() });
            }
        }
        log.info("Got {} bundles ({} ignored) from {}", new Object[] { counter, ignored, paxUrl });
    } catch (Exception e) {
        throw new RuntimeException("Error getting bundle list " + paxUrl, e);
    } finally {
        if (tmp != null) {
            tmp.delete();
        }
    }
    return result;
}
Also used : BundleList(org.apache.sling.maven.projectsupport.bundlelist.v1_0_0.BundleList) CoreOptions.mavenBundle(org.ops4j.pax.exam.CoreOptions.mavenBundle) Bundle(org.apache.sling.maven.projectsupport.bundlelist.v1_0_0.Bundle) ArrayList(java.util.ArrayList) DefaultCompositeOption(org.ops4j.pax.exam.options.DefaultCompositeOption) IOException(java.io.IOException) StartLevel(org.apache.sling.maven.projectsupport.bundlelist.v1_0_0.StartLevel) File(java.io.File)

Example 5 with Bundle

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

the class ArtifactDefinition method toBundleList.

public List<Bundle> toBundleList() {
    ArrayList<Bundle> bundleList = new ArrayList<Bundle>();
    if (bundles == null) {
        Bundle bnd = new Bundle();
        bnd.setArtifactId(artifactId);
        bnd.setGroupId(groupId);
        bnd.setVersion(version);
        if (type != null) {
            bnd.setType(type);
        }
        bnd.setClassifier(classifier);
        bnd.setStartLevel(startLevel);
        bundleList.add(bnd);
    } else {
        for (ArtifactDefinition bundle : bundles) {
            bundleList.addAll(bundle.toBundleList());
        }
    }
    return bundleList;
}
Also used : Bundle(org.apache.sling.maven.projectsupport.bundlelist.v1_0_0.Bundle) ArrayList(java.util.ArrayList)

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