Search in sources :

Example 6 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 7 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)

Example 8 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)

Example 9 with StartLevel

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

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

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