org.codehaus.plexus.archiver.jar.JarArchiver Java Examples
The following examples show how to use
org.codehaus.plexus.archiver.jar.JarArchiver.
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 |
/** * 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: AssembleTestBundleMojo.java From vespa with Apache License 2.0 | 6 votes |
@Override public void execute() throws MojoExecutionException { Artifacts.ArtifactSet artifacts = Artifacts.getArtifacts(project, true, testProvidedArtifacts); JarArchiver archiver = new JarArchiver(); addDirectory(archiver, Paths.get(project.getBuild().getOutputDirectory())); addDirectory(archiver, Paths.get(project.getBuild().getTestOutputDirectory())); addArtifacts(archiver, artifacts.getJarArtifactsToInclude()); Path archiveFile = archiveFile(project); createArchive(archiver, archiveFile, manifestFile(project)); project.getArtifact().setFile(archiveFile.toFile()); }
Example #3
Source File: AssembleContainerPluginMojo.java From vespa with Apache License 2.0 | 5 votes |
@Override public void execute() throws MojoExecutionException { Map<Dependencies, String> jarSuffixes = new EnumMap<Dependencies, String>(Dependencies.class); if (useCommonAssemblyIds) { jarSuffixes.put(Dependencies.WITHOUT, ".jar"); jarSuffixes.put(Dependencies.WITH, "-jar-with-dependencies.jar"); } else { jarSuffixes.put(Dependencies.WITHOUT, "-without-dependencies.jar"); jarSuffixes.put(Dependencies.WITH, "-deploy.jar"); } Map<Dependencies, File> jarFiles = new EnumMap<Dependencies, File>(Dependencies.class); jarSuffixes.forEach((dep, suffix) -> { jarFiles.put(dep, jarFileInBuildDirectory(build().getFinalName(), suffix)); }); Path manifestFile = Paths.get(build().getOutputDirectory(), JarFile.MANIFEST_NAME); JarArchiver jarWithoutDependencies = new JarArchiver(); addDirectory(jarWithoutDependencies, Paths.get(build().getOutputDirectory())); createArchive(jarWithoutDependencies, jarFiles.get(Dependencies.WITHOUT).toPath(), manifestFile); project.getArtifact().setFile(jarFiles.get(Dependencies.WITHOUT)); JarArchiver jarWithDependencies = new JarArchiver(); addDirectory(jarWithDependencies, Paths.get(build().getOutputDirectory())); addArtifacts(jarWithDependencies, Artifacts.getArtifactsToInclude(project)); createArchive(jarWithDependencies, jarFiles.get(Dependencies.WITH).toPath(), manifestFile); if (attachBundleArtifact) { projectHelper.attachArtifact(project, project.getArtifact().getType(), bundleClassifierName, jarFiles.get(Dependencies.WITH)); } }
Example #4
Source File: AbstractAssembleBundleMojo.java From vespa with Apache License 2.0 | 5 votes |
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: AbstractAssembleBundleMojo.java From vespa with Apache License 2.0 | 5 votes |
void addArtifacts(JarArchiver jarArchiver, Collection<Artifact> artifacts) { for (Artifact artifact : artifacts) { if ("jar".equals(artifact.getType())) { jarArchiver.addFile(artifact.getFile(), "dependencies/" + artifact.getFile().getName()); copyConfigDefinitions(artifact.getFile(), jarArchiver); } else { getLog().warn("Unknown artifact type " + artifact.getType()); } } }
Example #6
Source File: AbstractAssembleBundleMojo.java From vespa with Apache License 2.0 | 5 votes |
private void copyConfigDefinitions(File file, JarArchiver jarArchiver) { JarFiles.withJarFile(file, jarFile -> { for (Enumeration<JarEntry> entries = jarFile.entries(); entries.hasMoreElements();) { JarEntry entry = entries.nextElement(); String name = entry.getName(); if (name.startsWith("configdefinitions/") && name.endsWith(".def")) { copyConfigDefinition(jarFile, entry, jarArchiver); } } return null; }); }
Example #7
Source File: AbstractAssembleBundleMojo.java From vespa with Apache License 2.0 | 5 votes |
private void copyConfigDefinition(JarFile jarFile, ZipEntry entry, JarArchiver jarArchiver) { JarFiles.withInputStream(jarFile, entry, input -> { String defPath = entry.getName().replace("/", File.separator); File destinationFile = new File(project.getBuild().getOutputDirectory(), defPath); destinationFile.getParentFile().mkdirs(); Files.withFileOutputStream(destinationFile, output -> { output.getChannel().transferFrom(Channels.newChannel(input), 0, Long.MAX_VALUE); return null; }); jarArchiver.addFile(destinationFile, entry.getName()); return null; }); }
Example #8
Source File: WebJarPackager.java From wisdom with Apache License 2.0 | 5 votes |
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 #9
Source File: AbstractAssembleBundleMojo.java From vespa with Apache License 2.0 | 4 votes |
void addDirectory(JarArchiver jarArchiver, Path directory) { if (java.nio.file.Files.isDirectory(directory)) { jarArchiver.addDirectory(directory.toFile()); } }