Search in sources :

Example 26 with ArchiverException

use of org.codehaus.plexus.archiver.ArchiverException in project sling by apache.

the class PreparePackageMojo method pack.

private void pack(File sourceDir, File destination) throws MojoExecutionException {
    getLog().info("Packing " + sourceDir.getPath() + " to\n  " + destination.getPath());
    try {
        destination.getParentFile().mkdirs();
        jarArchiver.setDestFile(destination);
        jarArchiver.addDirectory(sourceDir);
        jarArchiver.setManifest(new File(sourceDir, "META-INF/MANIFEST.MF".replace('/', File.separatorChar)));
        jarArchiver.createArchive();
    } catch (IOException e) {
        throw new MojoExecutionException("Unable to pack " + sourceDir.getPath(), e);
    } catch (ArchiverException e) {
        throw new MojoExecutionException("Unable to pack " + sourceDir.getPath(), e);
    }
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) NoSuchArchiverException(org.codehaus.plexus.archiver.manager.NoSuchArchiverException) ArchiverException(org.codehaus.plexus.archiver.ArchiverException) IOException(java.io.IOException) File(java.io.File)

Example 27 with ArchiverException

use of org.codehaus.plexus.archiver.ArchiverException in project sling by apache.

the class AttachBundleListMojo method executeWithArtifacts.

@Override
protected void executeWithArtifacts() throws MojoExecutionException, MojoFailureException {
    FileWriter fw = null;
    try {
        this.outputFile.getParentFile().mkdirs();
        fw = new FileWriter(outputFile);
        writer.write(fw, getInitializedBundleList());
        projectHelper.attachArtifact(project, AttachPartialBundleListMojo.TYPE, AttachPartialBundleListMojo.CLASSIFIER, outputFile);
    } catch (IOException e) {
        throw new MojoExecutionException("Unable to output effective bundle list", e);
    } finally {
        if (fw != null) {
            try {
                fw.close();
            } catch (IOException e) {
            }
        }
    }
    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 : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ArchiverException(org.codehaus.plexus.archiver.ArchiverException) FileWriter(java.io.FileWriter) IOException(java.io.IOException)

Example 28 with ArchiverException

use of org.codehaus.plexus.archiver.ArchiverException 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 29 with ArchiverException

use of org.codehaus.plexus.archiver.ArchiverException 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)

Example 30 with ArchiverException

use of org.codehaus.plexus.archiver.ArchiverException in project aries by apache.

the class EsaMojo method addDependenciesToArchive.

/**
     * add the dependencies to the archive depending on the configuration of <archiveContent />
     */
private void addDependenciesToArchive() throws MojoExecutionException {
    try {
        Set<Artifact> artifacts = null;
        switch(EsaContent.valueOf(archiveContent)) {
            case none:
                getLog().info("archiveContent=none: subsystem archive will not contain any bundles.");
                break;
            case content:
                // only include the direct dependencies in the archive
                artifacts = project.getDependencyArtifacts();
                break;
            case all:
                // include direct and transitive dependencies in the archive
                artifacts = project.getArtifacts();
                break;
            default:
                throw new MojoExecutionException("Invalid configuration for <archiveContent/>.  Valid values are none, content and all.");
        }
        if (artifacts != null) {
            // Explicitly add self to bundle set (used when pom packaging
            // type != "esa" AND a file is present (no point to add to
            // zip archive without file)
            final Artifact selfArtifact = project.getArtifact();
            if (!"esa".equals(selfArtifact.getType()) && selfArtifact.getFile() != null) {
                getLog().info("Explicitly adding artifact[" + selfArtifact.getGroupId() + ", " + selfArtifact.getId() + ", " + selfArtifact.getScope() + "]");
                artifacts.add(project.getArtifact());
            }
            artifacts = selectArtifactsInCompileOrRuntimeScope(artifacts);
            artifacts = selectNonJarArtifactsAndBundles(artifacts);
            int cnt = 0;
            for (Artifact artifact : artifacts) {
                if (!artifact.isOptional()) /*&& filter.include(artifact)*/
                {
                    getLog().info("Copying artifact[" + artifact.getGroupId() + ", " + artifact.getId() + ", " + artifact.getScope() + "]");
                    zipArchiver.addFile(artifact.getFile(), artifact.getArtifactId() + "-" + artifact.getVersion() + "." + (artifact.getType() == null ? "jar" : artifact.getType()));
                    cnt++;
                }
            }
            getLog().info(String.format("Added %s artifacts to subsystem subsystem archive.", cnt));
        }
    } catch (ArchiverException e) {
        throw new MojoExecutionException("Error copying esa dependencies", e);
    }
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ArchiverException(org.codehaus.plexus.archiver.ArchiverException) Artifact(org.apache.maven.artifact.Artifact)

Aggregations

ArchiverException (org.codehaus.plexus.archiver.ArchiverException)50 File (java.io.File)33 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)25 IOException (java.io.IOException)24 NoSuchArchiverException (org.codehaus.plexus.archiver.manager.NoSuchArchiverException)17 UnArchiver (org.codehaus.plexus.archiver.UnArchiver)9 Artifact (org.apache.maven.artifact.Artifact)8 ManifestException (org.codehaus.plexus.archiver.jar.ManifestException)8 DependencyResolutionRequiredException (org.apache.maven.artifact.DependencyResolutionRequiredException)7 MavenArchiver (org.apache.maven.archiver.MavenArchiver)6 ArchiveCreationException (org.apache.maven.plugins.assembly.archive.ArchiveCreationException)5 ArrayList (java.util.ArrayList)3 MojoFailureException (org.apache.maven.plugin.MojoFailureException)3 Archiver (org.codehaus.plexus.archiver.Archiver)3 JarArchiver (org.codehaus.plexus.archiver.jar.JarArchiver)3 FileInputStream (java.io.FileInputStream)2 FileOutputStream (java.io.FileOutputStream)2 FileWriter (java.io.FileWriter)2 OutputStreamWriter (java.io.OutputStreamWriter)2 PrintWriter (java.io.PrintWriter)2