Search in sources :

Example 96 with ArchiverException

use of org.codehaus.plexus.archiver.ArchiverException in project myfaces-build-tools by apache.

the class WarPackageMojo method execute.

/**
 * {@inheritDoc}
 *
 * @see org.apache.maven.plugin.Mojo#execute()
 */
public void execute() throws MojoExecutionException, MojoFailureException {
    super.outputDirectory = new File(webappDirectory, scriptsDirectory);
    super.execute();
    try {
        javascriptArtifactManager.unpack(getProject(), DefaultArtifact.SCOPE_RUNTIME, new File(webappDirectory, scriptsDirectory + "/" + libsDirectory), useArtifactId);
    } catch (ArchiverException e) {
        throw new MojoExecutionException("Failed to unpack javascript dependencies", e);
    }
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ArchiverException(org.codehaus.plexus.archiver.ArchiverException) File(java.io.File)

Example 97 with ArchiverException

use of org.codehaus.plexus.archiver.ArchiverException in project myfaces-build-tools by apache.

the class AbstractDependencyMojo method unpack.

/**
 * Unpacks the archive file.
 *
 * @param file File to be unpacked.
 * @param location Location where to put the unpacked files.
 * @param includes Comma separated list of file patterns to include i.e. <code>**&#47;.xml,
 *            **&#47;*.properties</code>
 * @param excludes Comma separated list of file patterns to exclude i.e. <code>**&#47;*.xml,
 *            **&#47;*.properties</code>
 */
protected void unpack(File file, File location, String includes, String excludes) throws MojoExecutionException {
    try {
        logUnpack(file, location, includes, excludes);
        location.mkdirs();
        UnArchiver unArchiver;
        unArchiver = archiverManager.getUnArchiver(file);
        unArchiver.setSourceFile(file);
        unArchiver.setDestDirectory(location);
        if (StringUtils.isNotEmpty(excludes) || StringUtils.isNotEmpty(includes)) {
            // Create the selectors that will filter
            // based on include/exclude parameters
            // MDEP-47
            IncludeExcludeFileSelector[] selectors = new IncludeExcludeFileSelector[] { new IncludeExcludeFileSelector() };
            if (StringUtils.isNotEmpty(excludes)) {
                selectors[0].setExcludes(excludes.split(","));
            }
            if (StringUtils.isNotEmpty(includes)) {
                selectors[0].setIncludes(includes.split(","));
            }
            unArchiver.setFileSelectors(selectors);
        }
        if (this.silent) {
            silenceUnarchiver(unArchiver);
        }
        unArchiver.extract();
    } catch (NoSuchArchiverException e) {
        throw new MojoExecutionException("Unknown archiver type", e);
    } catch (ArchiverException e) {
        e.printStackTrace();
        throw new MojoExecutionException("Error unpacking file: " + file + " to: " + location + "\r\n" + e.toString(), e);
    }
}
Also used : IncludeExcludeFileSelector(org.codehaus.plexus.components.io.fileselectors.IncludeExcludeFileSelector) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) NoSuchArchiverException(org.codehaus.plexus.archiver.manager.NoSuchArchiverException) ArchiverException(org.codehaus.plexus.archiver.ArchiverException) UnArchiver(org.codehaus.plexus.archiver.UnArchiver) NoSuchArchiverException(org.codehaus.plexus.archiver.manager.NoSuchArchiverException)

Example 98 with ArchiverException

use of org.codehaus.plexus.archiver.ArchiverException in project openicf by Evolveum.

the class DocBookResourceMojo method generateArchive.

/**
 * Method that creates the jar file
 *
 * @param docbkxFiles
 *            the directory where the generated jar file will be put
 * @param jarFileName
 *            the filename of the generated jar file
 * @return a File object that contains the generated jar file
 * @throws ArchiverException
 *             if any
 * @throws IOException
 *             if any
 */
private File generateArchive(File docbkxFiles, String jarFileName) throws ArchiverException, IOException {
    File docbkxJar = new File(buildDirectory, jarFileName);
    if (docbkxJar.exists()) {
        docbkxJar.delete();
    }
    MavenArchiver archiver = new MavenArchiver();
    archiver.setArchiver(jarArchiver);
    archiver.setOutputFile(docbkxJar);
    if (!docbkxFiles.exists()) {
        getLog().warn("JAR will be empty - no content was marked for inclusion!");
    } else {
        archiver.getArchiver().addDirectory(docbkxFiles);
    }
    List<Resource> resources = project.getBuild().getResources();
    for (Resource r : resources) {
        if (r.getDirectory().endsWith("maven-shared-archive-resources")) {
            archiver.getArchiver().addDirectory(new File(r.getDirectory()));
        }
    }
    try {
        archive.setAddMavenDescriptor(false);
        archiver.createArchive(session, project, archive);
    } catch (ManifestException e) {
        throw new ArchiverException("ManifestException: " + e.getMessage(), e);
    } catch (DependencyResolutionRequiredException e) {
        throw new ArchiverException("DependencyResolutionRequiredException: " + e.getMessage(), e);
    }
    return docbkxJar;
}
Also used : DependencyResolutionRequiredException(org.apache.maven.artifact.DependencyResolutionRequiredException) ArchiverException(org.codehaus.plexus.archiver.ArchiverException) Resource(org.apache.maven.model.Resource) MavenArchiver(org.apache.maven.archiver.MavenArchiver) ManifestException(org.codehaus.plexus.archiver.jar.ManifestException) File(java.io.File)

Example 99 with ArchiverException

use of org.codehaus.plexus.archiver.ArchiverException in project openicf by Evolveum.

the class DocBookResourceMojo method execute.

public void execute() throws MojoExecutionException, MojoFailureException {
    if (skip) {
        getLog().info("Skipping DocBook generation");
        return;
    }
    if (!("pom".equalsIgnoreCase(project.getPackaging()))) {
        ArtifactHandler artifactHandler = project.getArtifact().getArtifactHandler();
        if (!"java".equals(artifactHandler.getLanguage())) {
            getLog().info("Not executing DocBook report as the project is not a Java classpath-capable package");
            return;
        }
    }
    try {
        if (!docbkxDirectory.exists()) {
            getLog().info("Not executing DocBook report as the project does not have DocBook source");
            return;
        }
        File rootDirectory = new File(buildDirectory, "openicf-docbkx/" + artifact.getArtifactId() + "-" + artifact.getVersion());
        try {
            FileUtils.mkdir(rootDirectory.getAbsolutePath());
            MavenResourcesExecution mre = new MavenResourcesExecution();
            mre.setMavenProject(getMavenProject());
            mre.setEscapeWindowsPaths(true);
            mre.setMavenSession(session);
            mre.setInjectProjectBuildFilters(true);
            List<FileUtils.FilterWrapper> filterWrappers = null;
            try {
                filterWrappers = fileFilter.getDefaultFilterWrappers(mre);
            } catch (MavenFilteringException e) {
                filterWrappers = Collections.emptyList();
            }
            if (docbkxDirectory.exists()) {
                final List<String> includes = FileUtils.getFileAndDirectoryNames(docbkxDirectory, "**", StringUtils.join(DirectoryScanner.DEFAULTEXCLUDES, ",") + ",**/*.xml", true, false, true, true);
                org.apache.commons.io.FileUtils.copyDirectory(docbkxDirectory, rootDirectory, new FileFilter() {

                    public boolean accept(File pathname) {
                        return includes.contains(pathname.getPath());
                    }
                });
                List<File> files = FileUtils.getFiles(docbkxDirectory, "**/*.xml", null);
                for (File file : files) {
                    try {
                        fileFilter.copyFile(file, new File(rootDirectory, file.getName()), true, filterWrappers, getSourceEncoding());
                    } catch (MavenFilteringException e) {
                        throw new MojoExecutionException(e.getMessage(), e);
                    }
                }
            }
            File sharedRoot = rootDirectory.getParentFile();
            CodeSource src = getClass().getProtectionDomain().getCodeSource();
            if (src != null) {
                final ZipInputStream zip = new ZipInputStream(src.getLocation().openStream());
                ZipEntry entry = null;
                while ((entry = zip.getNextEntry()) != null) {
                    String name = entry.getName();
                    if (entry.getName().startsWith("shared")) {
                        File destination = new File(sharedRoot, name);
                        if (entry.isDirectory()) {
                            if (!destination.exists()) {
                                destination.mkdirs();
                            }
                        } else {
                            if (!destination.exists()) {
                                FileOutputStream output = null;
                                try {
                                    output = new FileOutputStream(destination);
                                    IOUtil.copy(zip, output);
                                } finally {
                                    IOUtil.close(output);
                                }
                            }
                        }
                    }
                }
                zip.closeEntry();
                zip.close();
            }
        } catch (IOException e) {
            throw new MojoExecutionException("Error copy DocBook resources.", e);
        }
        // Generate Config and Schema DocBook Chapter
        CurrentLocale.set(Locale.ENGLISH);
        ConnectorDocBuilder generator = new ConnectorDocBuilder(this);
        generator.executeReport();
        if (attach) {
            RemoteResourcesBundle remoteResourcesBundle = new RemoteResourcesBundle();
            remoteResourcesBundle.setSourceEncoding(getSourceEncoding());
            DirectoryScanner scanner = new DirectoryScanner();
            scanner.setBasedir(new File(buildDirectory, "openicf-docbkx/"));
            // scanner.setIncludes(new String[] { docFolder + "/**" });
            scanner.addDefaultExcludes();
            scanner.scan();
            List<String> includedFiles = Arrays.asList(scanner.getIncludedFiles());
            if (resourcesDirectory.exists()) {
                scanner = new DirectoryScanner();
                scanner.setBasedir(resourcesDirectory);
                if (includes != null && includes.length != 0) {
                    scanner.setIncludes(includes);
                } else {
                    scanner.setIncludes(DEFAULT_INCLUDES);
                }
                if (excludes != null && excludes.length != 0) {
                    scanner.setExcludes(excludes);
                }
                scanner.addDefaultExcludes();
                scanner.scan();
                includedFiles.addAll(Arrays.asList(scanner.getIncludedFiles()));
            }
            for (String resource : includedFiles) {
                remoteResourcesBundle.addRemoteResource(StringUtils.replace(resource, '\\', '/'));
            }
            RemoteResourcesBundleXpp3Writer w = new RemoteResourcesBundleXpp3Writer();
            try {
                File f = new File(buildDirectory, "openicf-docbkx/" + BundleRemoteResourcesMojo.RESOURCES_MANIFEST);
                FileUtils.mkdir(f.getParentFile().getAbsolutePath());
                Writer writer = new FileWriter(f);
                w.write(writer, remoteResourcesBundle);
            } catch (IOException e) {
                throw new MojoExecutionException("Error creating remote resources manifest.", e);
            }
            File outputFile = generateArchive(new File(buildDirectory, "openicf-docbkx/"), finalName + "-docbkx.jar");
            projectHelper.attachArtifact(project, "jar", "docbkx", outputFile);
        } else {
            getLog().info("NOT adding DocBook to attached artifacts list.");
        }
    } catch (ArchiverException e) {
        failOnError("ArchiverException: Error while creating archive", e);
    } catch (IOException e) {
        failOnError("IOException: Error while creating archive", e);
    } catch (RuntimeException e) {
        failOnError("RuntimeException: Error while creating archive", e);
    }
}
Also used : MavenResourcesExecution(org.apache.maven.shared.filtering.MavenResourcesExecution) RemoteResourcesBundleXpp3Writer(org.apache.maven.plugin.resources.remote.io.xpp3.RemoteResourcesBundleXpp3Writer) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ArchiverException(org.codehaus.plexus.archiver.ArchiverException) MavenFilteringException(org.apache.maven.shared.filtering.MavenFilteringException) ZipEntry(java.util.zip.ZipEntry) FileWriter(java.io.FileWriter) IOException(java.io.IOException) CodeSource(java.security.CodeSource) RemoteResourcesBundle(org.apache.maven.plugin.resources.remote.RemoteResourcesBundle) ZipInputStream(java.util.zip.ZipInputStream) ArtifactHandler(org.apache.maven.artifact.handler.ArtifactHandler) FileOutputStream(java.io.FileOutputStream) DirectoryScanner(org.codehaus.plexus.util.DirectoryScanner) MavenFileFilter(org.apache.maven.shared.filtering.MavenFileFilter) FileFilter(java.io.FileFilter) File(java.io.File) RemoteResourcesBundleXpp3Writer(org.apache.maven.plugin.resources.remote.io.xpp3.RemoteResourcesBundleXpp3Writer) Writer(java.io.Writer) FileWriter(java.io.FileWriter)

Aggregations

ArchiverException (org.codehaus.plexus.archiver.ArchiverException)99 File (java.io.File)69 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)54 IOException (java.io.IOException)48 NoSuchArchiverException (org.codehaus.plexus.archiver.manager.NoSuchArchiverException)28 UnArchiver (org.codehaus.plexus.archiver.UnArchiver)18 ManifestException (org.codehaus.plexus.archiver.jar.ManifestException)15 MavenArchiver (org.apache.maven.archiver.MavenArchiver)14 Artifact (org.apache.maven.artifact.Artifact)14 DependencyResolutionRequiredException (org.apache.maven.artifact.DependencyResolutionRequiredException)14 Archiver (org.codehaus.plexus.archiver.Archiver)8 Resource (org.apache.maven.model.Resource)7 IncludeExcludeFileSelector (org.codehaus.plexus.components.io.fileselectors.IncludeExcludeFileSelector)7 MojoFailureException (org.apache.maven.plugin.MojoFailureException)6 DefaultFileSet (org.codehaus.plexus.archiver.util.DefaultFileSet)6 ArrayList (java.util.ArrayList)5 ArchiveCreationException (org.apache.maven.plugins.assembly.archive.ArchiveCreationException)5 MavenProject (org.apache.maven.project.MavenProject)5 FileInputStream (java.io.FileInputStream)4 FileWriter (java.io.FileWriter)4