use of org.codehaus.plexus.archiver.ArchiverException in project maven-plugins by apache.
the class AbstractSourceJarMojo method packageSources.
/**
* @param theProjects {@link MavenProject}
* @throws MojoExecutionException in case of an error.
*/
protected void packageSources(List<MavenProject> theProjects) throws MojoExecutionException {
if (project.getArtifact().getClassifier() != null) {
getLog().warn("NOT adding sources to artifacts with classifier as Maven only supports one classifier " + "per artifact. Current artifact [" + project.getArtifact().getId() + "] has a [" + project.getArtifact().getClassifier() + "] classifier.");
return;
}
MavenArchiver archiver = createArchiver();
for (MavenProject pItem : theProjects) {
MavenProject subProject = getProject(pItem);
if ("pom".equals(subProject.getPackaging())) {
continue;
}
archiveProjectContent(subProject, archiver.getArchiver());
}
if (archiver.getArchiver().getResources().hasNext() || forceCreation) {
if (useDefaultManifestFile && defaultManifestFile.exists() && archive.getManifestFile() == null) {
getLog().info("Adding existing MANIFEST to archive. Found under: " + defaultManifestFile.getPath());
archive.setManifestFile(defaultManifestFile);
}
File outputFile = new File(outputDirectory, finalName + "-" + getClassifier() + getExtension());
try {
archiver.setOutputFile(outputFile);
archive.setForced(forceCreation);
archiver.createArchive(session, project, archive);
} catch (IOException e) {
throw new MojoExecutionException("Error creating source archive: " + e.getMessage(), e);
} catch (ArchiverException e) {
throw new MojoExecutionException("Error creating source archive: " + e.getMessage(), e);
} catch (DependencyResolutionRequiredException e) {
throw new MojoExecutionException("Error creating source archive: " + e.getMessage(), e);
} catch (ManifestException e) {
throw new MojoExecutionException("Error creating source archive: " + e.getMessage(), e);
}
if (attach) {
projectHelper.attachArtifact(project, getType(), getClassifier(), outputFile);
} else {
getLog().info("NOT adding java-sources to attached artifacts list.");
}
} else {
getLog().info("No sources in project. Archive not created.");
}
}
use of org.codehaus.plexus.archiver.ArchiverException in project maven-plugins by apache.
the class AbstractWarPackagingTask method copyFile.
/**
* Copy file from source to destination. The directories up to <code>destination</code> will be created if they
* don't already exist. if the <code>onlyIfModified</code> flag is <tt>false</tt>, <code>destination</code> will be
* overwritten if it already exists. If the flag is <tt>true</tt> destination will be overwritten if it's not up to
* date.
*
* @param context the packaging context
* @param source an existing non-directory <code>File</code> to copy bytes from
* @param destination a non-directory <code>File</code> to write bytes to (possibly overwriting).
* @param targetFilename the relative path of the file from the webapp root directory
* @param onlyIfModified if true, copy the file only if the source has changed, always copy otherwise
* @return true if the file has been copied/updated, false otherwise
* @throws IOException if <code>source</code> does not exist, <code>destination</code> cannot be written to, or an
* IO error occurs during copying
*/
protected boolean copyFile(WarPackagingContext context, File source, File destination, String targetFilename, boolean onlyIfModified) throws IOException {
if (onlyIfModified && destination.lastModified() >= source.lastModified()) {
context.getLog().debug(" * " + targetFilename + " is up to date.");
return false;
} else {
if (source.isDirectory()) {
context.getLog().warn(" + " + targetFilename + " is packaged from the source folder");
try {
JarArchiver archiver = context.getJarArchiver();
archiver.addDirectory(source);
archiver.setDestFile(destination);
archiver.createArchive();
} catch (ArchiverException e) {
String msg = "Failed to create " + targetFilename;
context.getLog().error(msg, e);
IOException ioe = new IOException(msg);
ioe.initCause(e);
throw ioe;
}
} else {
FileUtils.copyFile(source.getCanonicalFile(), destination);
// preserve timestamp
destination.setLastModified(source.lastModified());
context.getLog().debug(" + " + targetFilename + " has been copied.");
}
return true;
}
}
use of org.codehaus.plexus.archiver.ArchiverException in project maven-plugins by apache.
the class ClassesPackager method packageClasses.
/**
* Package the classes
*
* @param classesDirectory the classes directory
* @param targetFile the target file
* @param jarArchiver the jar archiver to use
* @param session the current session
* @param project the related project
* @param archiveConfiguration the archive configuration to use
* @throws MojoExecutionException if an error occurred while creating the archive
*/
public void packageClasses(File classesDirectory, File targetFile, JarArchiver jarArchiver, MavenSession session, MavenProject project, MavenArchiveConfiguration archiveConfiguration) throws MojoExecutionException {
try {
final MavenArchiver archiver = new MavenArchiver();
archiver.setArchiver(jarArchiver);
archiver.setOutputFile(targetFile);
archiver.getArchiver().addDirectory(classesDirectory);
archiver.createArchive(session, project, archiveConfiguration);
} catch (ArchiverException e) {
throw new MojoExecutionException("Could not create classes archive", e);
} catch (ManifestException e) {
throw new MojoExecutionException("Could not create classes archive", e);
} catch (IOException e) {
throw new MojoExecutionException("Could not create classes archive", e);
} catch (DependencyResolutionRequiredException e) {
throw new MojoExecutionException("Could not create classes archive", e);
}
}
use of org.codehaus.plexus.archiver.ArchiverException in project maven-plugins by apache.
the class AbstractWarPackagingTask method doUnpack.
/**
* Unpacks the specified file to the specified directory.
*
* @param context the packaging context
* @param file the file to unpack
* @param unpackDirectory the directory to use for th unpacked file
* @throws MojoExecutionException if an error occurred while unpacking the file
*/
protected void doUnpack(WarPackagingContext context, File file, File unpackDirectory) throws MojoExecutionException {
String archiveExt = FileUtils.getExtension(file.getAbsolutePath()).toLowerCase();
try {
UnArchiver unArchiver = context.getArchiverManager().getUnArchiver(archiveExt);
unArchiver.setSourceFile(file);
unArchiver.setUseJvmChmod(context.isUseJvmChmod());
unArchiver.setDestDirectory(unpackDirectory);
unArchiver.setOverwrite(true);
unArchiver.extract();
} catch (ArchiverException e) {
throw new MojoExecutionException("Error unpacking file [" + file.getAbsolutePath() + "]" + " to [" + unpackDirectory.getAbsolutePath() + "]", e);
} catch (NoSuchArchiverException e) {
context.getLog().warn("Skip unpacking dependency file [" + file.getAbsolutePath() + " with unknown extension [" + archiveExt + "]");
}
}
use of org.codehaus.plexus.archiver.ArchiverException in project midpoint by Evolveum.
the class SchemaDistMojo method unpack.
private void unpack(ArtifactItem artifactItem, File destDir) throws MojoExecutionException {
Artifact artifact = artifactItem.getArtifact();
File file = artifact.getFile();
if (file == null) {
throw new MojoExecutionException("No file for artifact " + artifact);
}
if (file.isDirectory()) {
try {
FileUtils.copyDirectory(file, destDir);
} catch (IOException e) {
throw new MojoExecutionException("Error copying directory " + file + " to " + destDir + ": " + e.getMessage(), e);
}
} else {
try {
UnArchiver unArchiver = archiverManager.getUnArchiver(artifact.getType());
unArchiver.setSourceFile(file);
unArchiver.setDestDirectory(destDir);
if (StringUtils.isNotEmpty(excludes) || StringUtils.isNotEmpty(includes)) {
// Create the selectors that will filter
// based on include/exclude parameters
// MDEP-47
IncludeExcludeFileSelector[] selectors = new IncludeExcludeFileSelector[] { new IncludeExcludeFileSelector() };
if (StringUtils.isNotEmpty(excludes)) {
selectors[0].setExcludes(excludes.split(","));
}
if (StringUtils.isNotEmpty(includes)) {
selectors[0].setIncludes(includes.split(","));
}
unArchiver.setFileSelectors(selectors);
}
unArchiver.extract();
} catch (ArchiverException | NoSuchArchiverException e) {
throw new MojoExecutionException("Error unpacking file: " + file + " to: " + destDir + "\r\n" + e.toString(), e);
}
}
}
Aggregations