Search in sources :

Example 1 with BundleList

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

the class DisplayBundleUpdatesMojo method readBundleList.

private BundleList readBundleList(File file) throws IOException, XmlPullParserException {
    BundleListXpp3Reader reader = new BundleListXpp3Reader();
    FileInputStream fis = new FileInputStream(file);
    try {
        return reader.read(fis);
    } finally {
        fis.close();
    }
}
Also used : BundleListXpp3Reader(org.apache.sling.maven.projectsupport.bundlelist.v1_0_0.io.xpp3.BundleListXpp3Reader) FileInputStream(java.io.FileInputStream)

Example 2 with BundleList

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

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

the class AttachPartialBundleListMojo method execute.

public void execute() throws MojoExecutionException, MojoFailureException {
    final BundleList initializedBundleList;
    if (bundleListFile.exists()) {
        try {
            initializedBundleList = readBundleList(bundleListFile);
        } catch (IOException e) {
            throw new MojoExecutionException("Unable to read bundle list file", e);
        } catch (XmlPullParserException e) {
            throw new MojoExecutionException("Unable to read bundle list file", e);
        }
    } else {
        throw new MojoFailureException(String.format("Bundle list file %s does not exist.", bundleListFile.getAbsolutePath()));
    }
    interpolateProperties(initializedBundleList, this.project, this.mavenSession);
    final BundleListXpp3Writer writer = new BundleListXpp3Writer();
    try {
        this.bundleListOutput.getParentFile().mkdirs();
        writer.write(new FileWriter(bundleListOutput), initializedBundleList);
    } catch (IOException e) {
        throw new MojoExecutionException("Unable to write bundle list", e);
    }
    // if this project is a partial bundle list, it's the main artifact
    if (project.getPackaging().equals(PARTIAL)) {
        project.getArtifact().setFile(bundleListOutput);
    } else {
        // otherwise attach it as an additional artifact
        projectHelper.attachArtifact(project, TYPE, CLASSIFIER, bundleListOutput);
    }
    this.getLog().info("Attaching bundle list configuration");
    try {
        this.attachConfigurations();
    } catch (final IOException ioe) {
        throw new MojoExecutionException("Unable to attach configuration.", ioe);
    } catch (final ArchiverException ioe) {
        throw new MojoExecutionException("Unable to attach configuration.", ioe);
    }
}
Also used : BundleListXpp3Writer(org.apache.sling.maven.projectsupport.bundlelist.v1_0_0.io.xpp3.BundleListXpp3Writer) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) BundleListUtils.readBundleList(org.apache.sling.maven.projectsupport.BundleListUtils.readBundleList) BundleList(org.apache.sling.maven.projectsupport.bundlelist.v1_0_0.BundleList) ArchiverException(org.codehaus.plexus.archiver.ArchiverException) FileWriter(java.io.FileWriter) MojoFailureException(org.apache.maven.plugin.MojoFailureException) XmlPullParserException(org.codehaus.plexus.util.xml.pull.XmlPullParserException) IOException(java.io.IOException)

Example 4 with BundleList

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

the class BundleListUtils method readBundleList.

public static BundleList readBundleList(File file) throws IOException, XmlPullParserException {
    BundleListXpp3Reader reader = new BundleListXpp3Reader();
    FileInputStream fis = new FileInputStream(file);
    try {
        return reader.read(fis);
    } finally {
        fis.close();
    }
}
Also used : BundleListXpp3Reader(org.apache.sling.maven.projectsupport.bundlelist.v1_0_0.io.xpp3.BundleListXpp3Reader) FileInputStream(java.io.FileInputStream)

Example 5 with BundleList

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

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