use of org.codehaus.plexus.archiver.ArchiverException in project maven-plugins by apache.
the class ResourcesBundleMojo method doExecute.
/**
* Assemble a new {@link org.apache.maven.plugin.javadoc.options.JavadocOptions JavadocOptions} instance that
* contains the configuration options in this
* mojo, which are a subset of those provided in derivatives of the {@link AbstractJavadocMojo}
* class (most of the javadoc mojos, in other words). Then, bundle the contents of the
* <code>javadocDirectory</code> along with the assembled JavadocOptions instance (serialized to
* META-INF/maven/javadoc-options.xml) into a project attachment for installation/deployment.
*
* {@inheritDoc}
* @see org.apache.maven.plugin.Mojo#execute()
*/
public void doExecute() throws MojoExecutionException, MojoFailureException {
try {
buildJavadocOptions();
} catch (IOException e) {
throw new MojoExecutionException("Failed to generate javadoc-options file: " + e.getMessage(), e);
}
Archiver archiver;
try {
archiver = archiverManager.getArchiver("jar");
} catch (NoSuchArchiverException e) {
throw new MojoExecutionException("Failed to retrieve jar archiver component from manager.", e);
}
File optionsFile = getJavadocOptionsFile();
File bundleFile = new File(getProject().getBuild().getDirectory(), finalName + "-" + getAttachmentClassifier() + ".jar");
try {
archiver.addFile(optionsFile, BUNDLE_OPTIONS_PATH);
File javadocDir = getJavadocDirectory();
if (javadocDir.exists() && javadocDir.isDirectory()) {
archiver.addDirectory(javadocDir, RESOURCES_DIR_PATH + "/");
}
archiver.setDestFile(bundleFile);
archiver.createArchive();
} catch (ArchiverException e) {
throw new MojoExecutionException("Failed to assemble javadoc-resources bundle archive. Reason: " + e.getMessage(), e);
} catch (IOException e) {
throw new MojoExecutionException("Failed to assemble javadoc-resources bundle archive. Reason: " + e.getMessage(), e);
}
projectHelper.attachArtifact(getProject(), bundleFile, getAttachmentClassifier());
}
use of org.codehaus.plexus.archiver.ArchiverException in project aries by apache.
the class EbaMojo method execute.
public void execute() throws MojoExecutionException {
getLog().debug(" ======= EbaMojo settings =======");
getLog().debug("ebaSourceDirectory[" + ebaSourceDirectory + "]");
getLog().debug("manifestFile[" + manifestFile + "]");
getLog().debug("applicationManifestFile[" + applicationManifestFile + "]");
getLog().debug("workDirectory[" + workDirectory + "]");
getLog().debug("outputDirectory[" + outputDirectory + "]");
getLog().debug("finalName[" + finalName + "]");
getLog().debug("generateManifest[" + generateManifest + "]");
if (archiveContent == null) {
archiveContent = new String("applicationContent");
}
getLog().debug("archiveContent[" + archiveContent + "]");
getLog().info("archiveContent[" + archiveContent + "]");
zipArchiver.setIncludeEmptyDirs(includeEmptyDirs);
zipArchiver.setCompress(true);
zipArchiver.setForced(forceCreation);
// Check if jar file is there and if requested, copy it
try {
if (includeJar.booleanValue()) {
File generatedJarFile = new File(outputDirectory, finalName + ".jar");
if (generatedJarFile.exists()) {
getLog().info("Including generated jar file[" + generatedJarFile.getName() + "]");
zipArchiver.addFile(generatedJarFile, finalName + ".jar");
}
}
} catch (ArchiverException e) {
throw new MojoExecutionException("Error adding generated Jar file", e);
}
// Copy dependencies
try {
Set<Artifact> artifacts = null;
if (useTransitiveDependencies || "all".equals(archiveContent)) {
// to the same compatible value or is the default).
if ("none".equals(archiveContent)) {
throw new MojoExecutionException("<useTransitiveDependencies/> and <archiveContent/> incompatibly configured. <useTransitiveDependencies/> is deprecated in favor of <archiveContent/>.");
} else {
artifacts = project.getArtifacts();
}
} else {
// check that archiveContent is compatible
if ("applicationContent".equals(archiveContent)) {
artifacts = project.getDependencyArtifacts();
} else {
// the only remaining options should be applicationContent="none"
getLog().info("archiveContent=none: application arvhive will not contain any bundles.");
}
}
if (artifacts != null) {
for (Artifact artifact : artifacts) {
ScopeArtifactFilter filter = new ScopeArtifactFilter(Artifact.SCOPE_RUNTIME);
if (!artifact.isOptional() && filter.include(artifact)) {
getLog().info("Copying artifact[" + artifact.getGroupId() + ", " + artifact.getId() + ", " + artifact.getScope() + "]");
zipArchiver.addFile(artifact.getFile(), artifact.getArtifactId() + "-" + artifact.getVersion() + "." + (artifact.getType() == null ? "jar" : artifact.getType()));
}
}
}
} catch (ArchiverException e) {
throw new MojoExecutionException("Error copying EBA dependencies", e);
}
// Copy source files
try {
File ebaSourceDir = ebaSourceDirectory;
if (ebaSourceDir.exists()) {
getLog().info("Copy eba resources to " + getBuildDir().getAbsolutePath());
DirectoryScanner scanner = new DirectoryScanner();
scanner.setBasedir(ebaSourceDir.getAbsolutePath());
scanner.setIncludes(DEFAULT_INCLUDES);
scanner.addDefaultExcludes();
scanner.scan();
String[] dirs = scanner.getIncludedDirectories();
for (int j = 0; j < dirs.length; j++) {
new File(getBuildDir(), dirs[j]).mkdirs();
}
String[] files = scanner.getIncludedFiles();
for (int j = 0; j < files.length; j++) {
File targetFile = new File(getBuildDir(), files[j]);
targetFile.getParentFile().mkdirs();
File file = new File(ebaSourceDir, files[j]);
FileUtils.copyFileToDirectory(file, targetFile.getParentFile());
}
}
} catch (Exception e) {
throw new MojoExecutionException("Error copying EBA resources", e);
}
// Include custom manifest if necessary
try {
if (!generateManifest) {
includeCustomApplicationManifestFile();
}
} catch (IOException e) {
throw new MojoExecutionException("Error copying APPLICATION.MF file", e);
}
// Generate application manifest if requested
if (generateManifest) {
String fileName = new String(getBuildDir() + "/" + APPLICATION_MF_URI);
File appMfFile = new File(fileName);
try {
// Delete any old manifest
if (appMfFile.exists()) {
FileUtils.fileDelete(fileName);
}
appMfFile.getParentFile().mkdirs();
if (appMfFile.createNewFile()) {
writeApplicationManifest(fileName);
}
} catch (java.io.IOException e) {
throw new MojoExecutionException("Error generating APPLICATION.MF file: " + fileName, e);
}
}
// Check if connector deployment descriptor is there
File ddFile = new File(getBuildDir(), APPLICATION_MF_URI);
if (!ddFile.exists()) {
getLog().warn("Application manifest: " + ddFile.getAbsolutePath() + " does not exist.");
}
try {
if (addMavenDescriptor) {
if (project.getArtifact().isSnapshot()) {
project.setVersion(project.getArtifact().getVersion());
}
String groupId = project.getGroupId();
String artifactId = project.getArtifactId();
zipArchiver.addFile(project.getFile(), "META-INF/maven/" + groupId + "/" + artifactId + "/pom.xml");
PomPropertiesUtil pomPropertiesUtil = new PomPropertiesUtil();
File dir = new File(project.getBuild().getDirectory(), "maven-zip-plugin");
File pomPropertiesFile = new File(dir, "pom.properties");
pomPropertiesUtil.createPomProperties(project, zipArchiver, pomPropertiesFile, forceCreation);
}
File ebaFile = new File(outputDirectory, finalName + ".eba");
zipArchiver.setDestFile(ebaFile);
File buildDir = getBuildDir();
if (buildDir.isDirectory()) {
zipArchiver.addDirectory(buildDir);
}
//include legal files if any
File sharedResourcesDir = new File(sharedResources);
if (sharedResourcesDir.isDirectory()) {
zipArchiver.addDirectory(sharedResourcesDir);
}
zipArchiver.createArchive();
project.getArtifact().setFile(ebaFile);
} catch (Exception e) {
throw new MojoExecutionException("Error assembling eba", e);
}
}
use of org.codehaus.plexus.archiver.ArchiverException in project aries by apache.
the class EsaMojo method addDependenciesToArchive.
/**
* add the dependencies to the archive depending on the configuration of <archiveContent />
*/
private void addDependenciesToArchive() throws MojoExecutionException {
try {
Set<Artifact> artifacts = null;
switch(EsaContent.valueOf(archiveContent)) {
case none:
getLog().info("archiveContent=none: subsystem archive will not contain any bundles.");
break;
case content:
// only include the direct dependencies in the archive
artifacts = project.getDependencyArtifacts();
break;
case all:
// include direct and transitive dependencies in the archive
artifacts = project.getArtifacts();
break;
default:
throw new MojoExecutionException("Invalid configuration for <archiveContent/>. Valid values are none, content and all.");
}
if (artifacts != null) {
// Explicitly add self to bundle set (used when pom packaging
// type != "esa" AND a file is present (no point to add to
// zip archive without file)
final Artifact selfArtifact = project.getArtifact();
if (!"esa".equals(selfArtifact.getType()) && selfArtifact.getFile() != null) {
getLog().info("Explicitly adding artifact[" + selfArtifact.getGroupId() + ", " + selfArtifact.getId() + ", " + selfArtifact.getScope() + "]");
artifacts.add(project.getArtifact());
}
artifacts = selectArtifactsInCompileOrRuntimeScope(artifacts);
artifacts = selectNonJarArtifactsAndBundles(artifacts);
int cnt = 0;
for (Artifact artifact : artifacts) {
if (!artifact.isOptional()) /*&& filter.include(artifact)*/
{
getLog().info("Copying artifact[" + artifact.getGroupId() + ", " + artifact.getId() + ", " + artifact.getScope() + "]");
zipArchiver.addFile(artifact.getFile(), artifact.getArtifactId() + "-" + artifact.getVersion() + "." + (artifact.getType() == null ? "jar" : artifact.getType()));
cnt++;
}
}
getLog().info(String.format("Added %s artifacts to subsystem subsystem archive.", cnt));
}
} catch (ArchiverException e) {
throw new MojoExecutionException("Error copying esa dependencies", e);
}
}
use of org.codehaus.plexus.archiver.ArchiverException in project maven-plugins by apache.
the class AssemblyFileUtilsTest method testUnpack_ShouldSetSourceAndDestinationAndCallExtract.
public void testUnpack_ShouldSetSourceAndDestinationAndCallExtract() throws IOException, ArchiveExpansionException, NoSuchArchiverException {
EasyMockSupport mockManager = new EasyMockSupport();
File source = fileManager.createTempFile();
File destDir = fileManager.createTempDir();
UnArchiver unarchiver = mockManager.createMock(UnArchiver.class);
ArchiverManager archiverManager = mockManager.createMock(ArchiverManager.class);
try {
expect(archiverManager.getUnArchiver(source)).andReturn(unarchiver);
} catch (NoSuchArchiverException e) {
fail("Should never happen.");
}
unarchiver.setSourceFile(source);
unarchiver.setDestDirectory(destDir);
try {
unarchiver.extract();
} catch (ArchiverException e) {
fail("Should never happen.");
}
mockManager.replayAll();
AssemblyFileUtils.unpack(source, destDir, archiverManager);
mockManager.verifyAll();
}
use of org.codehaus.plexus.archiver.ArchiverException 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