org.codehaus.plexus.archiver.ArchiverException Java Examples

The following examples show how to use org.codehaus.plexus.archiver.ArchiverException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JarMojo.java    From helidon-build-tools with Apache License 2.0 6 votes vote down vote up
/**
 * Generate the archetype JAR file.
 *
 * @param archetypeDir the exploded archetype directory
 * @return created file
 * @throws MojoExecutionException if an error occurs
 */
private File generateArchetypeJar(Path archetypeDir) throws MojoExecutionException {
    File jarFile = new File(outputDirectory, finalName + ".jar");

    MavenArchiver archiver = new MavenArchiver();
    archiver.setCreatedBy("Helidon Archetype Plugin", "io.helidon.build-tools.archetype",
            "helidon-archetype-maven-plugin");
    archiver.setOutputFile(jarFile);
    archiver.setArchiver((JarArchiver) archivers.get("jar"));
    archiver.configureReproducible(outputTimestamp);

    try {
        archiver.getArchiver().addDirectory(archetypeDir.toFile());
        archiver.createArchive(session, project, archive);
    } catch (IOException | DependencyResolutionRequiredException | ArchiverException | ManifestException e) {
        throw new MojoExecutionException("Error assembling archetype jar " + jarFile, e);
    }
    return jarFile;
}
 
Example #2
Source File: JavaFXJLinkMojo.java    From javafx-maven-plugin with Apache License 2.0 5 votes vote down vote up
private File createZipArchiveFromImage() throws MojoExecutionException {
    File imageArchive = new File(builddir, jlinkImageName);
    zipArchiver.addDirectory(imageArchive);

    File resultArchive = new File(builddir, jlinkZipName + ".zip");
    zipArchiver.setDestFile(resultArchive);
    try {
        zipArchiver.createArchive();
    } catch (ArchiverException | IOException e) {
        throw new MojoExecutionException(e.getMessage(), e);
    }
    return resultArchive;
}
 
Example #3
Source File: TarsBuildMojo.java    From TarsJava with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * extract specified artifact. 
 *  
 * @param destination destination folder 
 * @param artifactFile 
 * @throws NoSuchArchiverException 
 * @throws ArchiverException 
 * @throws MojoExecutionException 
 */
private void unArchiveArtifact(final File destination, final File artifactFile) throws MojoExecutionException, IOException {
    try {
        final UnArchiver unArchiver = archiverManager.getUnArchiver(artifactFile);
        unArchiver.setSourceFile(artifactFile);
        unArchiver.setDestDirectory(destination);
        unArchiver.setOverwrite(true);
        unArchiver.extract();
    } catch (final NoSuchArchiverException | ArchiverException e) {
        throw new MojoExecutionException("Unable to unarchive " + artifactFile.getName(), e);
    }
}
 
Example #4
Source File: ArchiveEntryUtils.java    From TarsJava with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public static void chmod(final File file, final int mode, final Log logger, boolean useJvmChmod) throws ArchiverException {
    if (!Os.isFamily(Os.FAMILY_UNIX)) {
        return;
    }

    final String m = Integer.toOctalString(mode & 0xfff);

    if (useJvmChmod && !jvmFilePermAvailable) {
        logger.info("chmod it's not possible where your current jvm");
        useJvmChmod = false;
    }

    if (useJvmChmod && jvmFilePermAvailable) {
        applyPermissionsWithJvm(file, m, logger);
        return;
    }

    try {
        final Commandline commandline = new Commandline();

        commandline.setWorkingDirectory(file.getParentFile().getAbsolutePath());

        if (logger.isDebugEnabled()) {
            logger.debug(file + ": mode " + Integer.toOctalString(mode) + ", chmod " + m);
        }

        commandline.setExecutable("chmod");

        commandline.createArg().setValue(m);

        final String path = file.getAbsolutePath();

        commandline.createArg().setValue(path);

        final CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();

        final CommandLineUtils.StringStreamConsumer stdout = new CommandLineUtils.StringStreamConsumer();

        final int exitCode = CommandLineUtils.executeCommandLine(commandline, stderr, stdout);

        if (exitCode != 0) {
            logger.warn("-------------------------------");
            logger.warn("Standard error:");
            logger.warn("-------------------------------");
            logger.warn(stderr.getOutput());
            logger.warn("-------------------------------");
            logger.warn("Standard output:");
            logger.warn("-------------------------------");
            logger.warn(stdout.getOutput());
            logger.warn("-------------------------------");

            throw new ArchiverException("chmod exit code was: " + exitCode);
        }
    } catch (final CommandLineException e) {
        throw new ArchiverException("Error while executing chmod.", e);
    }

}
 
Example #5
Source File: ArchiveEntryUtils.java    From TarsJava with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public static void chmod(final File file, final int mode, final Log logger) throws ArchiverException {
    chmod(file, mode, logger, Boolean.getBoolean("useJvmChmod") && jvmFilePermAvailable);
}
 
Example #6
Source File: NarMojo.java    From nifi-maven with Apache License 2.0 4 votes vote down vote up
public File createArchive() throws MojoExecutionException {
    final File outputDirectory = projectBuildDirectory;
    File narFile = getNarFile(outputDirectory, finalName, classifier);
    MavenArchiver archiver = new MavenArchiver();
    archiver.setArchiver(jarArchiver);
    archiver.setOutputFile(narFile);
    archive.setForced(forceCreation);

    try {
        File contentDirectory = getClassesDirectory();
        if (contentDirectory.exists()) {
            archiver.getArchiver().addDirectory(contentDirectory, getIncludes(), getExcludes());
        } else {
            getLog().warn("NAR will be empty - no content was marked for inclusion!");
        }

        File extensionDocsFile = getExtensionsDocumentationFile();
        if (extensionDocsFile.exists()) {
            archiver.getArchiver().addFile(extensionDocsFile, "META-INF/docs/" + extensionDocsFile.getName());
        } else {
            getLog().warn("NAR will not contain any Extensions' documentation - no META-INF/" + extensionDocsFile.getName() + " file found!");
        }

        File additionalDetailsDirectory = new File(getExtensionsDocumentationFile().getParentFile(), "additional-details");
        if (additionalDetailsDirectory.exists()) {
            archiver.getArchiver().addDirectory(additionalDetailsDirectory, "META-INF/docs/additional-details/");
        }

        File existingManifest = defaultManifestFile;
        if (useDefaultManifestFile && existingManifest.exists() && archive.getManifestFile() == null) {
            getLog().info("Adding existing MANIFEST to archive. Found under: " + existingManifest.getPath());
            archive.setManifestFile(existingManifest);
        }

        // automatically add the artifact id, group id, and version to the manifest
        archive.addManifestEntry("Nar-Id", narId);
        archive.addManifestEntry("Nar-Group", narGroup);
        archive.addManifestEntry("Nar-Version", narVersion);

        // look for a nar dependency
        NarDependency narDependency = getNarDependency();
        if (narDependency != null) {
            final String narDependencyGroup = notEmpty(this.narDependencyGroup) ? this.narDependencyGroup : narDependency.getGroupId();
            final String narDependencyId = notEmpty(this.narDependencyId) ? this.narDependencyId : narDependency.getArtifactId();
            final String narDependencyVersion = notEmpty(this.narDependencyVersion) ? this.narDependencyVersion : narDependency.getVersion();

            archive.addManifestEntry("Nar-Dependency-Group", narDependencyGroup);
            archive.addManifestEntry("Nar-Dependency-Id", narDependencyId);
            archive.addManifestEntry("Nar-Dependency-Version", narDependencyVersion);
        }

        // add build information when available

        if (notEmpty(buildTag)) {
            archive.addManifestEntry("Build-Tag", buildTag);
        }
        if (notEmpty(buildBranch)) {
            archive.addManifestEntry("Build-Branch", buildBranch);
        }
        if (notEmpty(buildRevision)) {
            archive.addManifestEntry("Build-Revision", buildRevision);
        }

        SimpleDateFormat dateFormat = new SimpleDateFormat(BUILD_TIMESTAMP_FORMAT);
        archive.addManifestEntry("Build-Timestamp", dateFormat.format(new Date()));

        archive.addManifestEntry("Clone-During-Instance-Class-Loading", String.valueOf(cloneDuringInstanceClassLoading));

        archiver.createArchive(session, project, archive);
        return narFile;
    } catch (ArchiverException | MojoExecutionException | ManifestException | IOException | DependencyResolutionRequiredException e) {
        throw new MojoExecutionException("Error assembling NAR", e);
    }
}