use of org.codehaus.plexus.archiver.jar.ManifestException in project maven-plugins by apache.
the class AbstractSourceJarMojo method packageSources.
/**
* @param theProjects {@link MavenProject}
* @throws MojoExecutionException in case of an error.
*/
protected void packageSources(List<MavenProject> theProjects) throws MojoExecutionException {
if (project.getArtifact().getClassifier() != null) {
getLog().warn("NOT adding sources to artifacts with classifier as Maven only supports one classifier " + "per artifact. Current artifact [" + project.getArtifact().getId() + "] has a [" + project.getArtifact().getClassifier() + "] classifier.");
return;
}
MavenArchiver archiver = createArchiver();
for (MavenProject pItem : theProjects) {
MavenProject subProject = getProject(pItem);
if ("pom".equals(subProject.getPackaging())) {
continue;
}
archiveProjectContent(subProject, archiver.getArchiver());
}
if (archiver.getArchiver().getResources().hasNext() || forceCreation) {
if (useDefaultManifestFile && defaultManifestFile.exists() && archive.getManifestFile() == null) {
getLog().info("Adding existing MANIFEST to archive. Found under: " + defaultManifestFile.getPath());
archive.setManifestFile(defaultManifestFile);
}
File outputFile = new File(outputDirectory, finalName + "-" + getClassifier() + getExtension());
try {
archiver.setOutputFile(outputFile);
archive.setForced(forceCreation);
archiver.createArchive(session, project, archive);
} catch (IOException e) {
throw new MojoExecutionException("Error creating source archive: " + e.getMessage(), e);
} catch (ArchiverException e) {
throw new MojoExecutionException("Error creating source archive: " + e.getMessage(), e);
} catch (DependencyResolutionRequiredException e) {
throw new MojoExecutionException("Error creating source archive: " + e.getMessage(), e);
} catch (ManifestException e) {
throw new MojoExecutionException("Error creating source archive: " + e.getMessage(), e);
}
if (attach) {
projectHelper.attachArtifact(project, getType(), getClassifier(), outputFile);
} else {
getLog().info("NOT adding java-sources to attached artifacts list.");
}
} else {
getLog().info("No sources in project. Archive not created.");
}
}
use of org.codehaus.plexus.archiver.jar.ManifestException in project maven-plugins by apache.
the class ClassesPackager method packageClasses.
/**
* Package the classes
*
* @param classesDirectory the classes directory
* @param targetFile the target file
* @param jarArchiver the jar archiver to use
* @param session the current session
* @param project the related project
* @param archiveConfiguration the archive configuration to use
* @throws MojoExecutionException if an error occurred while creating the archive
*/
public void packageClasses(File classesDirectory, File targetFile, JarArchiver jarArchiver, MavenSession session, MavenProject project, MavenArchiveConfiguration archiveConfiguration) throws MojoExecutionException {
try {
final MavenArchiver archiver = new MavenArchiver();
archiver.setArchiver(jarArchiver);
archiver.setOutputFile(targetFile);
archiver.getArchiver().addDirectory(classesDirectory);
archiver.createArchive(session, project, archiveConfiguration);
} catch (ArchiverException e) {
throw new MojoExecutionException("Could not create classes archive", e);
} catch (ManifestException e) {
throw new MojoExecutionException("Could not create classes archive", e);
} catch (IOException e) {
throw new MojoExecutionException("Could not create classes archive", e);
} catch (DependencyResolutionRequiredException e) {
throw new MojoExecutionException("Could not create classes archive", e);
}
}
use of org.codehaus.plexus.archiver.jar.ManifestException in project sling by apache.
the class JarArchiverHelper method createManifest.
/**
* Create a manifest
*/
private void createManifest(final java.util.jar.Manifest manifest) throws MojoExecutionException {
// create a new manifest
final Manifest outManifest = new Manifest();
try {
boolean hasMain = false;
// copy entries from existing manifest
if (manifest != null) {
final Map<Object, Object> attrs = manifest.getMainAttributes();
for (final Map.Entry<Object, Object> entry : attrs.entrySet()) {
final String key = entry.getKey().toString();
if (!BuildConstants.ATTRS_EXCLUDES.contains(key)) {
final Attribute a = new Attribute(key, entry.getValue().toString());
outManifest.addConfiguredAttribute(a);
}
if (key.equals(BuildConstants.ATTR_MAIN_CLASS)) {
hasMain = true;
}
}
}
outManifest.addConfiguredAttribute(new Attribute(BuildConstants.ATTR_IMPLEMENTATION_BUILD, project.getVersion()));
outManifest.addConfiguredAttribute(new Attribute(BuildConstants.ATTR_IMPLEMENTATION_VERSION, project.getVersion()));
String organizationName = project.getOrganization() != null ? project.getOrganization().getName() : null;
if (organizationName != null) {
outManifest.addConfiguredAttribute(new Attribute(BuildConstants.ATTR_IMPLEMENTATION_VENDOR, organizationName));
outManifest.addConfiguredAttribute(new Attribute(BuildConstants.ATTR_CREATED_BY, organizationName));
outManifest.addConfiguredAttribute(new Attribute(BuildConstants.ATTR_BUILT_BY, organizationName));
outManifest.addConfiguredAttribute(new Attribute(BuildConstants.ATTR_SPECIFICATION_VENDOR, organizationName));
}
outManifest.addConfiguredAttribute(new Attribute(BuildConstants.ATTR_IMPLEMENTATION_VENDOR_ID, project.getGroupId()));
outManifest.addConfiguredAttribute(new Attribute(BuildConstants.ATTR_IMPLEMENTATION_TITLE, project.getName()));
outManifest.addConfiguredAttribute(new Attribute(BuildConstants.ATTR_SPECIFICATION_TITLE, project.getName()));
outManifest.addConfiguredAttribute(new Attribute(BuildConstants.ATTR_SPECIFICATION_VERSION, project.getVersion()));
if (archiver.getDestFile().getName().endsWith(".jar") && !hasMain) {
outManifest.addConfiguredAttribute(new Attribute(BuildConstants.ATTR_MAIN_CLASS, BuildConstants.ATTR_VALUE_MAIN_CLASS));
}
archiver.addConfiguredManifest(outManifest);
} catch (final ManifestException e) {
throw new MojoExecutionException("Unable to create manifest for " + this.archiver.getDestFile(), e);
}
}
use of org.codehaus.plexus.archiver.jar.ManifestException in project maven-plugins by apache.
the class ManifestCreationFinalizer method finalizeArchiveCreation.
@Override
public void finalizeArchiveCreation(final Archiver archiver) {
if (archiveConfiguration != null) {
try {
Manifest manifest;
final File manifestFile = archiveConfiguration.getManifestFile();
if (manifestFile != null) {
Reader manifestFileReader = null;
try {
manifestFileReader = new InputStreamReader(new FileInputStream(manifestFile), "UTF-8");
manifest = new Manifest(manifestFileReader);
manifestFileReader.close();
manifestFileReader = null;
} catch (final FileNotFoundException e) {
throw new ArchiverException("Manifest not found: " + e.getMessage(), e);
} catch (final IOException e) {
throw new ArchiverException("Error processing manifest: " + e.getMessage(), e);
} finally {
IOUtil.close(manifestFileReader);
}
} else {
manifest = mavenArchiver.getManifest(session, project, archiveConfiguration);
}
if ((manifest != null) && (archiver instanceof JarArchiver)) {
final JarArchiver jarArchiver = (JarArchiver) archiver;
jarArchiver.addConfiguredManifest(manifest);
}
} catch (final ManifestException e) {
throw new ArchiverException("Error creating manifest: " + e.getMessage(), e);
} catch (final DependencyResolutionRequiredException e) {
throw new ArchiverException("Dependencies were not resolved: " + e.getMessage(), e);
}
}
}
use of org.codehaus.plexus.archiver.jar.ManifestException in project maven-plugins by apache.
the class EjbMojo method generateEjb.
private File generateEjb() throws MojoExecutionException {
File jarFile = EjbHelper.getJarFile(outputDirectory, jarName, getClassifier());
getLog().info("Building EJB " + jarName + " with EJB version " + ejbVersion);
MavenArchiver archiver = new MavenArchiver();
archiver.setArchiver(jarArchiver);
archiver.setOutputFile(jarFile);
File deploymentDescriptor = new File(sourceDirectory, ejbJar);
checkEJBVersionCompliance(deploymentDescriptor);
try {
List<String> defaultExcludes = Lists.newArrayList(ejbJar, "**/package.html");
List<String> defaultIncludes = DEFAULT_INCLUDES_LIST;
IncludesExcludes ie = new IncludesExcludes(Collections.<String>emptyList(), excludes, defaultIncludes, defaultExcludes);
archiver.getArchiver().addDirectory(sourceDirectory, ie.resultingIncludes(), ie.resultingExcludes());
// FIXME: We should be able to filter more than just the deployment descriptor?
if (deploymentDescriptor.exists()) {
// EJB-34 Filter ejb-jar.xml
if (filterDeploymentDescriptor) {
filterDeploymentDescriptor(deploymentDescriptor);
}
archiver.getArchiver().addFile(deploymentDescriptor, ejbJar);
}
// create archive
archiver.createArchive(session, project, archive);
} catch (ArchiverException e) {
throw new MojoExecutionException("There was a problem creating the EJB archive: " + e.getMessage(), e);
} catch (ManifestException e) {
throw new MojoExecutionException("There was a problem creating the EJB archive: " + e.getMessage(), e);
} catch (IOException e) {
throw new MojoExecutionException("There was a problem creating the EJB archive: " + e.getMessage(), e);
} catch (DependencyResolutionRequiredException e) {
throw new MojoExecutionException("There was a problem creating the EJB archive: " + e.getMessage(), e);
} catch (MavenFilteringException e) {
throw new MojoExecutionException("There was a problem filtering the deployment descriptor: " + e.getMessage(), e);
}
return jarFile;
}
Aggregations