Search in sources :

Example 1 with StartLevel

use of org.apache.sling.maven.projectsupport.bundlelist.v1_0_0.StartLevel 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 StartLevel

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

the class BundleListContentProvider method addStartLevelSubdirs.

/** Add one folder per child, using given path as prefix, for start
     *  levels which actually provide bundles for the given run mode.
     */
private void addStartLevelSubdirs(Collection<String> children, String path, String runMode) {
    for (final StartLevel level : getInitializedBundleList().getStartLevels()) {
        final List<String> bundles = new ArrayList<String>();
        addBundles(bundles, level.getStartLevel(), runMode);
        if (!bundles.isEmpty()) {
            int folderLevel = level.getStartLevel();
            if (folderLevel == BOOTSTRAP_DEF_START_LEVEL) {
                folderLevel = ACTUAL_BOOTSTRAP_START_LEVEL;
            }
            children.add(path + "/" + folderLevel);
        }
    }
}
Also used : ArrayList(java.util.ArrayList) StartLevel(org.apache.sling.maven.projectsupport.bundlelist.v1_0_0.StartLevel)

Example 3 with StartLevel

use of org.apache.sling.maven.projectsupport.bundlelist.v1_0_0.StartLevel 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 StartLevel

use of org.apache.sling.maven.projectsupport.bundlelist.v1_0_0.StartLevel 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 StartLevel

use of org.apache.sling.maven.projectsupport.bundlelist.v1_0_0.StartLevel 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

StartLevel (org.apache.sling.maven.projectsupport.bundlelist.v1_0_0.StartLevel)13 Bundle (org.apache.sling.maven.projectsupport.bundlelist.v1_0_0.Bundle)11 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)6 BundleList (org.apache.sling.maven.projectsupport.bundlelist.v1_0_0.BundleList)6 IOException (java.io.IOException)5 ArrayList (java.util.ArrayList)4 HashSet (java.util.HashSet)2 Artifact (org.apache.maven.artifact.Artifact)2 MojoFailureException (org.apache.maven.plugin.MojoFailureException)2 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 FileWriter (java.io.FileWriter)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 ArchiverException (org.codehaus.plexus.archiver.ArchiverException)1 InterpolationException (org.codehaus.plexus.interpolation.InterpolationException)1 Interpolator (org.codehaus.plexus.interpolation.Interpolator)1 StringSearchInterpolator (org.codehaus.plexus.interpolation.StringSearchInterpolator)1