use of org.apache.maven.plugins.assembly.archive.ArchiveCreationException in project maven-plugins by apache.
the class DefaultDependencyResolver method updateModuleSetResolutionRequirements.
void updateModuleSetResolutionRequirements(AssemblyId assemblyId, ModuleSet set, DependencySet dependencySet, final ResolutionManagementInfo requirements, final AssemblerConfigurationSource configSource) throws DependencyResolutionException {
final ModuleBinaries binaries = set.getBinaries();
if (binaries != null) {
Set<MavenProject> projects;
try {
projects = ModuleSetAssemblyPhase.getModuleProjects(set, configSource, getLogger());
} catch (final ArchiveCreationException e) {
throw new DependencyResolutionException("Error determining project-set for moduleSet with binaries.", e);
}
if (!projects.isEmpty()) {
for (final MavenProject p : projects) {
requirements.enableProjectResolution(p);
if (p.getArtifact() == null) {
// TODO: such a call in MavenMetadataSource too - packaging not really the intention of
// type
final Artifact artifact = resolver.createArtifact(p.getGroupId(), p.getArtifactId(), p.getVersion(), p.getPackaging());
p.setArtifact(artifact);
}
}
}
if (binaries.isIncludeDependencies()) {
updateDependencySetResolutionRequirements(dependencySet, requirements, assemblyId, configSource.getMavenSession().getProjectBuildingRequest(), projects.toArray(new MavenProject[projects.size()]));
}
}
}
use of org.apache.maven.plugins.assembly.archive.ArchiveCreationException in project maven-plugins by apache.
the class AddFileSetsTaskTest method testExecute_ShouldThrowExceptionIfArchiveBasedirProvidedIsNotADirectory.
public void testExecute_ShouldThrowExceptionIfArchiveBasedirProvidedIsNotADirectory() throws AssemblyFormattingException, IOException {
macTask.archiveBaseDir = fileManager.createTempFile();
macTask.expectGetArchiveBaseDirectory();
mockManager.replayAll();
final AddFileSetsTask task = new AddFileSetsTask(new ArrayList<FileSet>());
try {
task.execute(macTask.archiver, macTask.configSource);
fail("Should throw exception due to non-directory archiveBasedir location that was provided.");
} catch (final ArchiveCreationException e) {
// should do this, because it cannot use the provide archiveBasedir.
}
mockManager.verifyAll();
}
use of org.apache.maven.plugins.assembly.archive.ArchiveCreationException in project maven-plugins by apache.
the class AddFileSetsTaskTest method testExecute_ShouldThrowExceptionIfArchiveBasedirProvidedIsNonExistent.
public void testExecute_ShouldThrowExceptionIfArchiveBasedirProvidedIsNonExistent() throws AssemblyFormattingException {
macTask.archiveBaseDir.delete();
macTask.expectGetArchiveBaseDirectory();
mockManager.replayAll();
final AddFileSetsTask task = new AddFileSetsTask(new ArrayList<FileSet>());
try {
task.execute(macTask.archiver, macTask.configSource);
fail("Should throw exception due to non-existent archiveBasedir location that was provided.");
} catch (final ArchiveCreationException e) {
// should do this, because it cannot use the provide archiveBasedir.
}
mockManager.verifyAll();
}
use of org.apache.maven.plugins.assembly.archive.ArchiveCreationException in project maven-plugins by apache.
the class AbstractAssemblyMojo method execute.
/**
* Create the binary distribution.
*
* @throws org.apache.maven.plugin.MojoExecutionException
*/
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
if (skipAssembly) {
getLog().info("Assemblies have been skipped per configuration of the skipAssembly parameter.");
return;
}
// run only at the execution root.
if (runOnlyAtExecutionRoot && !isThisTheExecutionRoot()) {
getLog().info("Skipping the assembly in this project because it's not the Execution Root");
return;
}
List<Assembly> assemblies;
try {
assemblies = assemblyReader.readAssemblies(this);
} catch (final AssemblyReadException e) {
throw new MojoExecutionException("Error reading assemblies: " + e.getMessage(), e);
} catch (final InvalidAssemblerConfigurationException e) {
throw new MojoFailureException(assemblyReader, e.getMessage(), "Mojo configuration is invalid: " + e.getMessage());
}
// TODO: include dependencies marked for distribution under certain formats
// TODO: how, might we plug this into an installer, such as NSIS?
boolean warnedAboutMainProjectArtifact = false;
for (final Assembly assembly : assemblies) {
try {
final String fullName = AssemblyFormatUtils.getDistributionName(assembly, this);
List<String> effectiveFormats = formats;
if (effectiveFormats == null || effectiveFormats.size() == 0) {
effectiveFormats = assembly.getFormats();
}
if (effectiveFormats == null || effectiveFormats.size() == 0) {
throw new MojoFailureException("No formats specified in the execution parameters or the assembly descriptor.");
}
for (final String format : effectiveFormats) {
final File destFile = assemblyArchiver.createArchive(assembly, fullName, format, this, isRecompressZippedFiles(), getMergeManifestMode());
final MavenProject project = getProject();
final String type = project.getArtifact().getType();
if (attach && destFile.isFile()) {
if (isAssemblyIdAppended()) {
projectHelper.attachArtifact(project, format, assembly.getId(), destFile);
} else if (!"pom".equals(type) && format.equals(type)) {
if (!warnedAboutMainProjectArtifact) {
final StringBuilder message = new StringBuilder();
message.append("Configuration option 'appendAssemblyId' is set to false.");
message.append("\nInstead of attaching the assembly file: ").append(destFile);
message.append(", it will become the file for main project artifact.");
message.append("\nNOTE: If multiple descriptors or descriptor-formats are provided " + "for this project, the value of this file will be " + "non-deterministic!");
getLog().warn(message);
warnedAboutMainProjectArtifact = true;
}
final File existingFile = project.getArtifact().getFile();
if ((existingFile != null) && existingFile.exists()) {
getLog().warn("Replacing pre-existing project main-artifact file: " + existingFile + "\nwith assembly file: " + destFile);
}
project.getArtifact().setFile(destFile);
} else {
projectHelper.attachArtifact(project, format, null, destFile);
}
} else if (attach) {
getLog().warn("Assembly file: " + destFile + " is not a regular file (it may be a directory). " + "It cannot be attached to the project build for installation or " + "deployment.");
}
}
} catch (final ArchiveCreationException e) {
throw new MojoExecutionException("Failed to create assembly: " + e.getMessage(), e);
} catch (final AssemblyFormattingException e) {
throw new MojoExecutionException("Failed to create assembly: " + e.getMessage(), e);
} catch (final InvalidAssemblerConfigurationException e) {
throw new MojoFailureException(assembly, "Assembly is incorrectly configured: " + assembly.getId(), "Assembly: " + assembly.getId() + " is not configured correctly: " + e.getMessage());
}
}
}
use of org.apache.maven.plugins.assembly.archive.ArchiveCreationException in project maven-plugins by apache.
the class AddArtifactTask method moveArtifactSomewhereElse.
private File moveArtifactSomewhereElse(AssemblerConfigurationSource configSource) throws ArchiveCreationException {
final File tempRoot = configSource.getTemporaryRootDirectory();
final File tempArtifactFile = new File(tempRoot, artifact.getFile().getName());
logger.warn("Artifact: " + artifact.getId() + " references the same file as the assembly destination file. " + "Moving it to a temporary location for inclusion.");
try {
FileUtils.copyFile(artifact.getFile(), tempArtifactFile);
} catch (final IOException e) {
throw new ArchiveCreationException("Error moving artifact file: '" + artifact.getFile() + "' to temporary location: " + tempArtifactFile + ". Reason: " + e.getMessage(), e);
}
return tempArtifactFile;
}
Aggregations