Search in sources :

Example 11 with StartLevel

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

the class BaseBundleList method getOrCreateStartLevel.

private StartLevel getOrCreateStartLevel(int startLevel) {
    for (StartLevel sl : getStartLevels()) {
        if (sl.getStartLevel() == startLevel) {
            return sl;
        }
    }
    StartLevel sl = new StartLevel();
    getStartLevels().add(sl);
    sl.setRawLevel(startLevel);
    return sl;
}
Also used : StartLevel(org.apache.sling.maven.projectsupport.bundlelist.v1_0_0.StartLevel)

Example 12 with StartLevel

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

the class BaseBundleList method add.

/**
     * Merge bundle into a start level using the supplied level if present.
     * @param mergeStartLevel
     * @param newBnd
     */
private void add(StartLevel mergeStartLevel, Bundle newBnd) {
    Bundle current = get(newBnd, false);
    if (current != null) {
        final Maven2OsgiConverter converter = new DefaultMaven2OsgiConverter();
        // compare versions, the highest will be used
        final Version newVersion = new Version(converter.getVersion(newBnd.getVersion()));
        final Version oldVersion = new Version(converter.getVersion(current.getVersion()));
        if (newVersion.compareTo(oldVersion) > 0) {
            current.setVersion(newBnd.getVersion());
        }
    } else {
        StartLevel startLevel = null;
        if (mergeStartLevel == null || newBnd.getStartLevel() != 0) {
            startLevel = getOrCreateStartLevel(newBnd.getStartLevel());
        } else {
            startLevel = getOrCreateStartLevel(mergeStartLevel.getStartLevel());
        }
        startLevel.getBundles().add(newBnd);
    }
}
Also used : Maven2OsgiConverter(org.apache.maven.shared.osgi.Maven2OsgiConverter) DefaultMaven2OsgiConverter(org.apache.maven.shared.osgi.DefaultMaven2OsgiConverter) Version(org.osgi.framework.Version) Bundle(org.apache.sling.maven.projectsupport.bundlelist.v1_0_0.Bundle) StartLevel(org.apache.sling.maven.projectsupport.bundlelist.v1_0_0.StartLevel) DefaultMaven2OsgiConverter(org.apache.maven.shared.osgi.DefaultMaven2OsgiConverter)

Example 13 with StartLevel

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

the class BundleListContentProviderTest method testParsedBundlesCount.

@Test
public void testParsedBundlesCount() {
    int counter = 0;
    for (StartLevel level : bundleList.getStartLevels()) {
        counter += level.getBundles().size();
    }
    assertEquals(BUNDLES_IN_TEST_BUNDLE_LIST, counter);
}
Also used : StartLevel(org.apache.sling.maven.projectsupport.bundlelist.v1_0_0.StartLevel) Test(org.junit.Test)

Example 14 with StartLevel

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

the class CreatePaxRunnerBundleProvisionFileMojo method executeWithArtifacts.

@Override
protected void executeWithArtifacts() throws MojoExecutionException, MojoFailureException {
    FileWriter out = null;
    try {
        out = new FileWriter(outputFile);
        BundleList bundleList = getInitializedBundleList();
        for (StartLevel level : bundleList.getStartLevels()) {
            for (Bundle bundle : level.getBundles()) {
                String line = String.format("mvn:%s/%s/%s@%d\n", bundle.getGroupId(), bundle.getArtifactId(), bundle.getVersion(), level.getStartLevel());
                out.write(line);
            }
        }
        projectHelper.attachArtifact(project, TYPE, CLASSIFIER, outputFile);
    } catch (IOException e) {
        throw new MojoExecutionException("Unable to write " + outputFile.getName(), e);
    } finally {
        if (out != null) {
            try {
                out.close();
            } catch (IOException 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) FileWriter(java.io.FileWriter) StartLevel(org.apache.sling.maven.projectsupport.bundlelist.v1_0_0.StartLevel) IOException(java.io.IOException)

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