org.apache.maven.archiver.MavenArchiver Java Examples

The following examples show how to use org.apache.maven.archiver.MavenArchiver. 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: AbstractDockerMojo.java    From dockerfile-maven with Apache License 2.0 6 votes vote down vote up
@Nonnull
protected File buildDockerInfoJar(@Nonnull Log log) throws MojoExecutionException {
  final File jarFile = getJarFile(buildDirectory, finalName, classifier);

  final MavenArchiver archiver = new MavenArchiver();
  archiver.setArchiver(jarArchiver);
  archiver.setOutputFile(jarFile);

  archive.setForced(forceCreation);

  if (dockerInfoDirectory.exists()) {
    final String prefix = getMetaSubdir();
    archiver.getArchiver().addDirectory(dockerInfoDirectory, prefix);
  } else {
    log.warn("Docker info directory not created - Docker info JAR will be empty");
  }

  try {
    archiver.createArchive(session, project, archive);
  } catch (Exception e) {
    throw new MojoExecutionException("Could not build Docker info JAR", e);
  }

  return jarFile;
}
 
Example #4
Source File: AbstractAssembleBundleMojo.java    From vespa with Apache License 2.0 5 votes vote down vote up
void createArchive(JarArchiver jarArchiver, Path jarFile, Path manifestFile) throws MojoExecutionException {
    archiveConfiguration.setForced(true); // force recreating the archive
    archiveConfiguration.setManifestFile(manifestFile.toFile());
    MavenArchiver mavenArchiver = new MavenArchiver();
    mavenArchiver.setArchiver(jarArchiver);
    mavenArchiver.setOutputFile(jarFile.toFile());
    try {
        mavenArchiver.createArchive(session, project, archiveConfiguration);
    } catch (Exception e) {
        throw new MojoExecutionException("Error creating archive " + jarFile.toFile().getName(), e);
    }
}
 
Example #5
Source File: JarMojo.java    From opoopress with Apache License 2.0 5 votes vote down vote up
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
    String[] includes = {"**/*"};
    String[] excludes = {"**/Thumbs.db", "src/**", "target/**", ".config.rb.cache"};

    File outputFile = new File(buildDirectory, finalName + "-" + classifier + ".jar");
    File jarFile = new File(buildDirectory, finalName + ".jar");
    File targetPluginsDir = new File(buildDirectory, "plugins");

    try{
        MavenArchiver archiver = new MavenArchiver();
        archiver.setArchiver(jarArchiver);
        archiver.setOutputFile(outputFile);

        archiver.getArchiver().addDirectory(basedir, includes, excludes);

        if(outputDirectory.exists() && jarFile.exists()){
            if(!targetPluginsDir.exists()){
                targetPluginsDir.mkdirs();
            }
            FileUtils.copyFileToDirectory(jarFile, targetPluginsDir);
        }else{
            getLog().warn("No theme classes add to theme package.");
        }

        if(targetPluginsDir.exists()){
            archiver.getArchiver().addDirectory(buildDirectory, new String[]{"plugins/**"}, null);
        }

        archiver.createArchive(project, archive);
    } catch (Exception e) {
        throw new MojoExecutionException("build archiver error: " + e.getMessage(), e);
    }

    if(attach){
        projectHelper.attachArtifact(project, "jar", classifier, outputFile);
    }
}
 
Example #6
Source File: BaratineMojo.java    From baratine with GNU General Public License v2.0 4 votes vote down vote up
public File createBar()
  throws MojoExecutionException
{
  File bar = getBarFile();

  MavenArchiver archiver = new MavenArchiver();

  archiver.setArchiver(this.archiver);

  archiver.setOutputFile(bar);

  try {
    File web = getWebDirectory();

    if (web.exists())
      this.archiver.addDirectory(web, this.web);

    File contentDirectory = getClassesDirectory();

    this.archiver.addDirectory(contentDirectory,
                               "classes/",
                               getIncludes(),
                               getExcludes());

    String baratineMetaName = "META-INF"
                              + File.separatorChar
                              + "baratine";

    File baratineMeta = new File(contentDirectory, baratineMetaName);

    if (baratineMeta.exists())
      this.archiver.addDirectory(baratineMeta,
                                 baratineMetaName
                                 + File.separatorChar);

    for (Object x : project.getArtifacts()) {
      Artifact artifact = (Artifact) x;

      final String type = artifact.getType();

      if ("js".equals(type)) {
        addJs(artifact);
      }
      else if ("jar".equals(type)) {
        addJar(artifact);
      }
      else {
        getLog().info("skipping artifact "
                      + artifact.getId()
                      + ':'
                      + artifact.getArtifactId()
                      + ':'
                      + artifact.getSelectedVersion()
                      + ':' + artifact.getType());
      }

    }

    archiver.createArchive(session, project, archive);

    return bar;
  } catch (Exception e) {
    throw new MojoExecutionException("Error assembling bar", e);
  }
}
 
Example #7
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);
    }
}