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 DefaultAssemblyArchiver method configureArchiver.
private void configureArchiver(final Archiver archiver, final AssemblerConfigurationSource configSource) {
Xpp3Dom config;
try {
config = Xpp3DomBuilder.build(new StringReader(configSource.getArchiverConfig()));
} catch (final XmlPullParserException e) {
throw new ArchiverException("Failed to parse archiver configuration for: " + archiver.getClass().getName(), e);
} catch (final IOException e) {
throw new ArchiverException("Failed to parse archiver configuration for: " + archiver.getClass().getName(), e);
}
getLogger().debug("Configuring archiver: '" + archiver.getClass().getName() + "' -->");
try {
configureComponent(archiver, config, configSource);
} catch (final ComponentConfigurationException e) {
throw new ArchiverException("Failed to configure archiver: " + archiver.getClass().getName(), e);
} catch (final ComponentLookupException e) {
throw new ArchiverException("Failed to lookup configurator for setup of archiver: " + archiver.getClass().getName(), e);
}
getLogger().debug("-- end configuration --");
}
use of org.codehaus.plexus.archiver.ArchiverException in project maven-plugins by apache.
the class DefaultAssemblyArchiver method createArchive.
/**
* {@inheritDoc}
*/
@Override
public File createArchive(final Assembly assembly, final String fullName, final String format, final AssemblerConfigurationSource configSource, boolean recompressZippedFiles, String mergeManifestMode) throws ArchiveCreationException, AssemblyFormattingException, InvalidAssemblerConfigurationException {
validate(assembly);
String filename = fullName;
if (!configSource.isIgnoreDirFormatExtensions() || !format.startsWith("dir")) {
filename += "." + format;
}
AssemblyFileUtils.verifyTempDirectoryAvailability(configSource.getTemporaryRootDirectory());
final File outputDirectory = configSource.getOutputDirectory();
final File destFile = new File(outputDirectory, filename);
try {
final String finalName = configSource.getFinalName();
final String specifiedBasedir = assembly.getBaseDirectory();
String basedir = finalName;
if (specifiedBasedir != null) {
basedir = AssemblyFormatUtils.getOutputDirectory(specifiedBasedir, finalName, configSource, AssemblyFormatUtils.moduleProjectInterpolator(configSource.getProject()), AssemblyFormatUtils.artifactProjectInterpolator(null));
}
final List<ContainerDescriptorHandler> containerHandlers = selectContainerDescriptorHandlers(assembly.getContainerDescriptorHandlers(), configSource);
final Archiver archiver = createArchiver(format, assembly.isIncludeBaseDirectory(), basedir, configSource, containerHandlers, recompressZippedFiles, mergeManifestMode);
archiver.setDestFile(destFile);
for (AssemblyArchiverPhase phase : sortedPhases()) {
phase.execute(assembly, archiver, configSource);
}
archiver.createArchive();
} catch (final ArchiverException e) {
throw new ArchiveCreationException("Error creating assembly archive " + assembly.getId() + ": " + e.getMessage(), e);
} catch (final IOException e) {
throw new ArchiveCreationException("Error creating assembly archive " + assembly.getId() + ": " + e.getMessage(), e);
} catch (final NoSuchArchiverException e) {
throw new ArchiveCreationException("Unable to obtain archiver for extension '" + format + "', for assembly: '" + assembly.getId() + "'", e);
} catch (final DependencyResolutionException e) {
throw new ArchiveCreationException("Unable to resolve dependencies for assembly '" + assembly.getId() + "'", e);
}
return destFile;
}
use of org.codehaus.plexus.archiver.ArchiverException 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);
}
}
}
Aggregations