use of org.apache.maven.plugins.assembly.archive.ArchiveCreationException in project maven-plugins by apache.
the class AddDependencySetsTask method addNonArchiveDependency.
private void addNonArchiveDependency(final Artifact depArtifact, final MavenProject depProject, final DependencySet dependencySet, final Archiver archiver, final AssemblerConfigurationSource configSource) throws AssemblyFormattingException, ArchiveCreationException {
final File source = depArtifact.getFile();
String outputDirectory = dependencySet.getOutputDirectory();
FixedStringSearchInterpolator moduleProjectInterpolator = AssemblyFormatUtils.moduleProjectInterpolator(moduleProject);
FixedStringSearchInterpolator artifactProjectInterpolator = AssemblyFormatUtils.artifactProjectInterpolator(depProject);
outputDirectory = AssemblyFormatUtils.getOutputDirectory(outputDirectory, depProject.getBuild().getFinalName(), configSource, moduleProjectInterpolator, artifactProjectInterpolator);
final String destName = AssemblyFormatUtils.evaluateFileNameMapping(dependencySet.getOutputFileNameMapping(), depArtifact, configSource.getProject(), moduleArtifact, configSource, moduleProjectInterpolator, artifactProjectInterpolator);
String target;
// omit the last char if ends with / or \\
if (outputDirectory.endsWith("/") || outputDirectory.endsWith("\\")) {
target = outputDirectory + destName;
} else {
target = outputDirectory + "/" + destName;
}
try {
final int mode = TypeConversionUtils.modeToInt(dependencySet.getFileMode(), logger);
if (mode > -1) {
archiver.addFile(source, target, mode);
} else {
archiver.addFile(source, target);
}
} catch (final ArchiverException e) {
throw new ArchiveCreationException("Error adding file to archive: " + e.getMessage(), e);
}
}
use of org.apache.maven.plugins.assembly.archive.ArchiveCreationException in project maven-plugins by apache.
the class AddDirectoryTask method execute.
public void execute(final Archiver archiver) throws ArchiveCreationException {
if (".".equals(outputDirectory)) {
outputDirectory = "";
} else if ("..".equals(outputDirectory)) {
throw new ArchiveCreationException("Cannot add source directory: " + directory + " to archive-path: " + outputDirectory + ". All paths must be within the archive root directory.");
}
final int oldDirMode = archiver.getOverrideDirectoryMode();
final int oldFileMode = archiver.getOverrideFileMode();
boolean fileModeSet = false;
boolean dirModeSet = false;
try {
if (directoryMode != -1) {
archiver.setDirectoryMode(directoryMode);
dirModeSet = true;
}
if (fileMode != -1) {
archiver.setFileMode(fileMode);
fileModeSet = true;
}
if (directory.exists()) {
List<String> directoryExcludes;
if (excludes != null && !excludes.isEmpty()) {
directoryExcludes = new ArrayList<String>(excludes);
} else {
directoryExcludes = new ArrayList<String>();
}
try {
String[] includesArray = null;
if (includes != null && !includes.isEmpty()) {
includesArray = new String[includes.size()];
int i = 0;
for (String include : includes) {
includesArray[i++] = normalize(include);
}
}
// this one is guaranteed to be non-null by code above.
final String[] excludesArray = new String[directoryExcludes.size()];
int i = 0;
for (String directoryExclude : directoryExcludes) {
excludesArray[i++] = normalize(directoryExclude);
}
final DefaultFileSet fs = new DefaultFileSet();
fs.setUsingDefaultExcludes(useDefaultExcludes);
fs.setPrefix(outputDirectory);
fs.setDirectory(directory);
fs.setIncludes(includesArray);
fs.setExcludes(excludesArray);
if (transformer != null) {
fs.setStreamTransformer(transformer);
}
archiver.addFileSet(fs);
} catch (final ArchiverException e) {
throw new ArchiveCreationException("Error adding directory to archive: " + e.getMessage(), e);
}
}
} finally {
if (dirModeSet) {
archiver.setDirectoryMode(oldDirMode);
}
if (fileModeSet) {
archiver.setFileMode(oldFileMode);
}
}
}
use of org.apache.maven.plugins.assembly.archive.ArchiveCreationException in project maven-plugins by apache.
the class ModuleSetAssemblyPhase method getModuleProjects.
@Nonnull
public static Set<MavenProject> getModuleProjects(final ModuleSet moduleSet, final AssemblerConfigurationSource configSource, final Logger logger) throws ArchiveCreationException {
MavenProject project = configSource.getProject();
Set<MavenProject> moduleProjects = null;
if (moduleSet.isUseAllReactorProjects()) {
if (!moduleSet.isIncludeSubModules()) {
moduleProjects = new LinkedHashSet<MavenProject>(configSource.getReactorProjects());
}
project = configSource.getReactorProjects().get(0);
}
if (moduleProjects == null) {
try {
moduleProjects = ProjectUtils.getProjectModules(project, configSource.getReactorProjects(), moduleSet.isIncludeSubModules(), logger);
} catch (final IOException e) {
throw new ArchiveCreationException("Error retrieving module-set for project: " + project.getId() + ": " + e.getMessage(), e);
}
}
return FilterUtils.filterProjects(moduleProjects, moduleSet.getIncludes(), moduleSet.getExcludes(), true, logger);
}
use of org.apache.maven.plugins.assembly.archive.ArchiveCreationException in project maven-plugins by apache.
the class ModuleSetAssemblyPhase method addModuleArtifact.
void addModuleArtifact(final Artifact artifact, final MavenProject project, final Archiver archiver, final AssemblerConfigurationSource configSource, final ModuleBinaries binaries) throws ArchiveCreationException, AssemblyFormattingException {
if (artifact.getFile() == null) {
throw new ArchiveCreationException("Artifact: " + artifact.getId() + " (included by module) does not have an artifact with a file. " + "Please ensure the package phase is run before the assembly is generated.");
}
final AddArtifactTask task = new AddArtifactTask(artifact, getLogger(), null);
task.setFileNameMapping(binaries.getOutputFileNameMapping());
task.setOutputDirectory(binaries.getOutputDirectory());
task.setProject(project);
task.setModuleProject(project);
task.setModuleArtifact(artifact);
final int dirMode = TypeConversionUtils.modeToInt(binaries.getDirectoryMode(), getLogger());
if (dirMode != -1) {
task.setDirectoryMode(dirMode);
}
final int fileMode = TypeConversionUtils.modeToInt(binaries.getFileMode(), getLogger());
if (fileMode != -1) {
task.setFileMode(fileMode);
}
task.setUnpack(binaries.isUnpack());
if (binaries.isUnpack() && binaries.getUnpackOptions() != null) {
task.setIncludes(binaries.getUnpackOptions().getIncludes());
task.setExcludes(binaries.getUnpackOptions().getExcludes());
}
task.execute(archiver, configSource);
}
Aggregations