Search in sources :

Example 11 with Bundle

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

the class BundleListUtils method interpolateProperties.

public static void interpolateProperties(BundleList bundleList, MavenProject project, MavenSession mavenSession) throws MojoExecutionException {
    Interpolator interpolator = createInterpolator(project, mavenSession);
    for (final StartLevel sl : bundleList.getStartLevels()) {
        for (final Bundle bndl : sl.getBundles()) {
            try {
                bndl.setArtifactId(interpolator.interpolate(bndl.getArtifactId()));
                bndl.setGroupId(interpolator.interpolate(bndl.getGroupId()));
                bndl.setVersion(interpolator.interpolate(bndl.getVersion()));
                bndl.setClassifier(interpolator.interpolate(bndl.getClassifier()));
                bndl.setType(interpolator.interpolate(bndl.getType()));
            } catch (InterpolationException e) {
                throw new MojoExecutionException("Unable to interpolate properties for bundle " + bndl.toString(), e);
            }
        }
    }
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) Bundle(org.apache.sling.maven.projectsupport.bundlelist.v1_0_0.Bundle) StartLevel(org.apache.sling.maven.projectsupport.bundlelist.v1_0_0.StartLevel) Interpolator(org.codehaus.plexus.interpolation.Interpolator) StringSearchInterpolator(org.codehaus.plexus.interpolation.StringSearchInterpolator) InterpolationException(org.codehaus.plexus.interpolation.InterpolationException)

Example 12 with Bundle

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

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

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