org.codehaus.plexus.archiver.jar.ManifestException Java Examples

The following examples show how to use org.codehaus.plexus.archiver.jar.ManifestException. 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: PackageMojo.java    From helidon-build-tools with Apache License 2.0 6 votes vote down vote up
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
    if (siteArchiveSkip) {
        getLog().info("processing is skipped.");
        return;
    }
    getLog().info("Assembling site JAR [" + project.getArtifactId() + "]");

    final File jarFile = new File(siteArchiveOutputDirectory, siteArchiveFinalName + ".jar");
    final MavenArchiver mvnArchiver = new MavenArchiver();
    mvnArchiver.setArchiver(jarArchiver);
    mvnArchiver.setOutputFile(jarFile);
    mvnArchiver.getArchiver().addDirectory(siteOutputDirectory, getIncludes(), getExcludes());

    try {
        mvnArchiver.createArchive(session, project, new MavenArchiveConfiguration());
    } catch (ManifestException
            | IOException
            | DependencyResolutionRequiredException ex) {
        throw new MojoExecutionException("Error assembling site archive", ex);
    }

    project.getArtifact().setFile(jarFile);
}
 
Example #2
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 #3
Source File: ManifestCreator.java    From spring-cloud-contract with Apache License 2.0 6 votes vote down vote up
public static Manifest createManifest(MavenProject project) throws ManifestException {
	Manifest manifest = new Manifest();
	Plugin verifierMavenPlugin = findMavenPlugin(project.getBuildPlugins());
	if (verifierMavenPlugin != null) {
		manifest.addConfiguredAttribute(
				new Manifest.Attribute("Spring-Cloud-Contract-Maven-Plugin-Version",
						verifierMavenPlugin.getVersion()));
	}
	if (verifierMavenPlugin != null
			&& !verifierMavenPlugin.getDependencies().isEmpty()) {
		Dependency verifierDependency = findVerifierDependency(
				verifierMavenPlugin.getDependencies());
		if (verifierDependency != null) {
			String verifierVersion = verifierDependency.getVersion();
			manifest.addConfiguredAttribute(new Manifest.Attribute(
					"Spring-Cloud-Contract-Verifier-Version", verifierVersion));
		}
	}
	return manifest;
}
 
Example #4
Source File: WebJarPackager.java    From wisdom with Apache License 2.0 5 votes vote down vote up
private File process() throws IOException, ManifestException {
    getLog().info("Building webjar for " + project.getArtifactId());
    File output = new File(buildDirectory, webjar.getOutputFileName());
    FileUtils.deleteQuietly(output);

    // Compute the set of selected files:
    Collection<File> selected = webjar.getSelectedFiles();
    if (selected.isEmpty()) {
        getLog().warn("No file selected in the webjar - skipping creation");
        return null;
    }
    String root = computeRoot();

    FileUtils.deleteQuietly(output);

    // Web jar are jar file, so use the Plexus Archiver.
    JarArchiver archiver = new JarArchiver();
    archiver.enableLogging(new PlexusLoggerWrapper(getLog()));
    String base = webjar.getFileset().getDirectory();
    for (File file : selected) {
        final String destFileName = root + "/" + file.getAbsolutePath().substring(base.length() + 1);
        getLog().debug(file.getName() + " => " + destFileName);
        archiver.addFile(file, destFileName);
    }

    // Extend the manifest with webjar data - this is not required by the webjar specification
    Manifest manifest = Manifest.getDefaultManifest();
    manifest.getMainSection().addConfiguredAttribute(new Manifest.Attribute("Webjar-Name", webjar.getName()));
    manifest.getMainSection().addConfiguredAttribute(new Manifest.Attribute("Webjar-Version", webjar.getVersion()));
    manifest.getMainSection().addConfiguredAttribute(new Manifest.Attribute("Created-By", "Wisdom Framework " +
            BuildConstants.get("WISDOM_PLUGIN_VERSION")));
    archiver.addConfiguredManifest(manifest);
    archiver.setDestFile(output);
    archiver.createArchive();
    return output;
}
 
Example #5
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);
    }
}