use of org.apache.maven.plugins.assembly.archive.ArchiveCreationException in project maven-plugins by apache.
the class ModuleSetAssemblyPhaseTest method testAddModuleArtifact_ShouldThrowExceptionWhenArtifactFileIsNull.
public void testAddModuleArtifact_ShouldThrowExceptionWhenArtifactFileIsNull() throws AssemblyFormattingException, IOException {
final EasyMockSupport mm = new EasyMockSupport();
final ArtifactMock artifactMock = new ArtifactMock(mm, "group", "artifact", "version", "type", false);
artifactMock.setNullFile();
mm.replayAll();
try {
createPhase(new ConsoleLogger(Logger.LEVEL_DEBUG, "test"), null).addModuleArtifact(artifactMock.getArtifact(), null, null, null, null);
fail("Expected ArchiveCreationException since artifact file is null.");
} catch (final ArchiveCreationException e) {
// expected
}
mm.verifyAll();
}
use of org.apache.maven.plugins.assembly.archive.ArchiveCreationException in project maven-plugins by apache.
the class FileItemAssemblyPhase method execute.
/**
* {@inheritDoc}
*/
@Override
public void execute(final Assembly assembly, final Archiver archiver, final AssemblerConfigurationSource configSource) throws ArchiveCreationException, AssemblyFormattingException {
final List<FileItem> fileList = assembly.getFiles();
final File basedir = configSource.getBasedir();
for (final FileItem fileItem : fileList) {
final String sourcePath = fileItem.getSource();
// ensure source file is in absolute path for reactor build to work
File source = new File(sourcePath);
// save the original sourcefile's name, because filtration may
// create a temp file with a different name.
final String sourceName = source.getName();
if (!source.isAbsolute()) {
source = new File(basedir, sourcePath);
}
String destName = fileItem.getDestName();
if (destName == null) {
destName = sourceName;
}
final String outputDirectory1 = fileItem.getOutputDirectory();
AssemblyFormatUtils.warnForPlatformSpecifics(getLogger(), outputDirectory1);
final String outputDirectory = AssemblyFormatUtils.getOutputDirectory(outputDirectory1, configSource.getFinalName(), configSource, AssemblyFormatUtils.moduleProjectInterpolator(configSource.getProject()), AssemblyFormatUtils.artifactProjectInterpolator(null));
String target;
// omit the last char if ends with / or \\
if (outputDirectory.endsWith("/") || outputDirectory.endsWith("\\")) {
target = outputDirectory + destName;
} else if (outputDirectory.length() < 1) {
target = destName;
} else {
target = outputDirectory + "/" + destName;
}
try {
final InputStreamTransformer fileSetTransformers = ReaderFormatter.getFileSetTransformers(configSource, fileItem.isFiltered(), fileItem.getLineEnding());
final PlexusIoResource restoUse = createResource(source, fileSetTransformers);
int mode = TypeConversionUtils.modeToInt(fileItem.getFileMode(), getLogger());
archiver.addResource(restoUse, target, mode);
} catch (final ArchiverException e) {
throw new ArchiveCreationException("Error adding file to archive: " + e.getMessage(), e);
} catch (IOException 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 RepositoryAssemblyPhase method execute.
/**
* {@inheritDoc}
*/
@Override
@SuppressWarnings("ResultOfMethodCallIgnored")
public void execute(final Assembly assembly, final Archiver archiver, final AssemblerConfigurationSource configSource) throws ArchiveCreationException, AssemblyFormattingException, InvalidAssemblerConfigurationException {
final List<Repository> repositoriesList = assembly.getRepositories();
final File tempRoot = configSource.getTemporaryRootDirectory();
for (final Repository repository : repositoriesList) {
final String outputDirectory = AssemblyFormatUtils.getOutputDirectory(repository.getOutputDirectory(), configSource.getFinalName(), configSource, AssemblyFormatUtils.moduleProjectInterpolator(configSource.getProject()), AssemblyFormatUtils.artifactProjectInterpolator(null));
final File repositoryDirectory = new File(tempRoot, outputDirectory);
if (!repositoryDirectory.exists()) {
repositoryDirectory.mkdirs();
}
try {
getLogger().debug("Assembling repository to: " + repositoryDirectory);
repositoryAssembler.buildRemoteRepository(repositoryDirectory, wrap(repository), wrap(configSource));
getLogger().debug("Finished assembling repository to: " + repositoryDirectory);
} catch (final RepositoryAssemblyException e) {
throw new ArchiveCreationException("Failed to assemble repository: " + e.getMessage(), e);
}
final AddDirectoryTask task = new AddDirectoryTask(repositoryDirectory);
final int dirMode = TypeConversionUtils.modeToInt(repository.getDirectoryMode(), getLogger());
if (dirMode != -1) {
task.setDirectoryMode(dirMode);
}
final int fileMode = TypeConversionUtils.modeToInt(repository.getFileMode(), getLogger());
if (fileMode != -1) {
task.setFileMode(fileMode);
}
task.setOutputDirectory(outputDirectory);
task.execute(archiver);
}
}
use of org.apache.maven.plugins.assembly.archive.ArchiveCreationException in project maven-plugins by apache.
the class AddArtifactTask method asFile.
private void asFile(Archiver archiver, AssemblerConfigurationSource configSource, String destDirectory) throws AssemblyFormattingException, ArchiveCreationException {
final String tempMapping = AssemblyFormatUtils.evaluateFileNameMapping(outputFileNameMapping, artifact, configSource.getProject(), moduleArtifact, configSource, AssemblyFormatUtils.moduleProjectInterpolator(moduleProject), AssemblyFormatUtils.artifactProjectInterpolator(project));
final String outputLocation = destDirectory + tempMapping;
try {
final File artifactFile = artifact.getFile();
logger.debug("Adding artifact: " + artifact.getId() + " with file: " + artifactFile + " to assembly location: " + outputLocation + ".");
if (fileMode != -1) {
archiver.addFile(artifactFile, outputLocation, fileMode);
} else {
archiver.addFile(artifactFile, outputLocation);
}
} catch (final ArchiverException e) {
throw new ArchiveCreationException("Error adding file '" + artifact.getId() + "' to archive: " + e.getMessage(), e);
}
}
use of org.apache.maven.plugins.assembly.archive.ArchiveCreationException in project maven-plugins by apache.
the class AddArtifactTask method unpacked.
private void unpacked(Archiver archiver, String destDirectory) throws ArchiveCreationException {
String outputLocation = destDirectory;
if ((outputLocation.length() > 0) && !outputLocation.endsWith("/")) {
outputLocation += "/";
}
String[] includesArray = TypeConversionUtils.toStringArray(includes);
if (includesArray == null) {
includesArray = DEFAULT_INCLUDES_ARRAY;
}
final String[] excludesArray = TypeConversionUtils.toStringArray(excludes);
try {
final File artifactFile = artifact.getFile();
if (artifactFile == null) {
logger.warn("Skipping artifact: " + artifact.getId() + "; it does not have an associated file or directory.");
} else if (artifactFile.isDirectory()) {
logger.debug("Adding artifact directory contents for: " + artifact + " to: " + outputLocation);
DefaultFileSet fs = DefaultFileSet.fileSet(artifactFile);
fs.setIncludes(includesArray);
fs.setExcludes(excludesArray);
fs.setPrefix(outputLocation);
fs.setStreamTransformer(transformer);
archiver.addFileSet(fs);
} else {
logger.debug("Unpacking artifact contents for: " + artifact + " to: " + outputLocation);
logger.debug("includes:\n" + StringUtils.join(includesArray, "\n") + "\n");
logger.debug("excludes:\n" + (excludesArray == null ? "none" : StringUtils.join(excludesArray, "\n")) + "\n");
DefaultArchivedFileSet afs = DefaultArchivedFileSet.archivedFileSet(artifactFile);
afs.setIncludes(includesArray);
afs.setExcludes(excludesArray);
afs.setPrefix(outputLocation);
afs.setStreamTransformer(transformer);
archiver.addArchivedFileSet(afs, encoding);
}
} catch (final ArchiverException e) {
throw new ArchiveCreationException("Error adding file-set for '" + artifact.getId() + "' to archive: " + e.getMessage(), e);
}
}
Aggregations