Search in sources :

Example 11 with BundleList

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

Example 12 with BundleList

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

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

the class BundleListContentProviderTest method parseBundleList.

@BeforeClass
public static void parseBundleList() throws Exception {
    final BundleListXpp3Reader reader = new BundleListXpp3Reader();
    final InputStream is = BundleListContentProviderTest.class.getClassLoader().getResourceAsStream(TEST_BUNDLE_LIST);
    assertNotNull("Expecting " + TEST_BUNDLE_LIST + " to be found", is);
    try {
        bundleList = reader.read(is);
    } finally {
        is.close();
    }
}
Also used : BundleListXpp3Reader(org.apache.sling.maven.projectsupport.bundlelist.v1_0_0.io.xpp3.BundleListXpp3Reader) InputStream(java.io.InputStream) BeforeClass(org.junit.BeforeClass)

Example 14 with BundleList

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

the class BundleListContentProviderTest method setupProvider.

@Before
public void setupProvider() {
    final Log log = Mockito.mock(Log.class);
    final Answer<Void> countWarningAnswers = new Answer<Void>() {

        public Void answer(InvocationOnMock invocation) throws Throwable {
            logWarningsCount++;
            return null;
        }
    };
    Mockito.doAnswer(countWarningAnswers).when(log).warn(Matchers.any(String.class));
    Mockito.doAnswer(countWarningAnswers).when(log).warn(Matchers.any(Throwable.class));
    Mockito.doAnswer(countWarningAnswers).when(log).warn(Matchers.any(String.class), Matchers.any(Throwable.class));
    provider = new BundleListContentProvider(resourceProviderRoot) {

        @Override
        BundleList getInitializedBundleList() {
            return bundleList;
        }

        @Override
        File getConfigDirectory() {
            return configDirectory;
        }

        @Override
        Artifact getArtifact(ArtifactDefinition def) throws MojoExecutionException {
            final Artifact a = Mockito.mock(Artifact.class);
            final String fakeName = new StringBuilder().append("/FAKE_BUNDLE/").append(def.getArtifactId()).append("/").append(def.getStartLevel()).append("/").append(def.getRunModes()).toString();
            Mockito.when(a.getFile()).thenReturn(new File(fakeName));
            return a;
        }

        @Override
        Log getLog() {
            return log;
        }
    };
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) Log(org.apache.maven.plugin.logging.Log) BundleList(org.apache.sling.maven.projectsupport.bundlelist.v1_0_0.BundleList) Artifact(org.apache.maven.artifact.Artifact) Answer(org.mockito.stubbing.Answer) InvocationOnMock(org.mockito.invocation.InvocationOnMock) File(java.io.File) Before(org.junit.Before)

Example 15 with BundleList

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

BundleList (org.apache.sling.maven.projectsupport.bundlelist.v1_0_0.BundleList)10 Bundle (org.apache.sling.maven.projectsupport.bundlelist.v1_0_0.Bundle)9 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)7 StartLevel (org.apache.sling.maven.projectsupport.bundlelist.v1_0_0.StartLevel)7 IOException (java.io.IOException)6 File (java.io.File)3 ArrayList (java.util.ArrayList)3 Artifact (org.apache.maven.artifact.Artifact)3 MojoFailureException (org.apache.maven.plugin.MojoFailureException)3 BundleListXpp3Reader (org.apache.sling.maven.projectsupport.bundlelist.v1_0_0.io.xpp3.BundleListXpp3Reader)3 FileInputStream (java.io.FileInputStream)2 FileWriter (java.io.FileWriter)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 Sets (com.google.common.collect.Sets)1 BufferedReader (java.io.BufferedReader)1 FileOutputStream (java.io.FileOutputStream)1 InputStream (java.io.InputStream)1 Files (java.nio.file.Files)1