use of org.codehaus.plexus.archiver.ArchiverException in project myfaces-build-tools by apache.
the class WarPackageMojo method execute.
/**
* {@inheritDoc}
*
* @see org.apache.maven.plugin.Mojo#execute()
*/
public void execute() throws MojoExecutionException, MojoFailureException {
super.outputDirectory = new File(webappDirectory, scriptsDirectory);
super.execute();
try {
javascriptArtifactManager.unpack(getProject(), DefaultArtifact.SCOPE_RUNTIME, new File(webappDirectory, scriptsDirectory + "/" + libsDirectory), useArtifactId);
} catch (ArchiverException e) {
throw new MojoExecutionException("Failed to unpack javascript dependencies", e);
}
}
use of org.codehaus.plexus.archiver.ArchiverException in project myfaces-build-tools by apache.
the class AbstractDependencyMojo method unpack.
/**
* Unpacks the archive file.
*
* @param file File to be unpacked.
* @param location Location where to put the unpacked files.
* @param includes Comma separated list of file patterns to include i.e. <code>**/.xml,
* **/*.properties</code>
* @param excludes Comma separated list of file patterns to exclude i.e. <code>**/*.xml,
* **/*.properties</code>
*/
protected void unpack(File file, File location, String includes, String excludes) throws MojoExecutionException {
try {
logUnpack(file, location, includes, excludes);
location.mkdirs();
UnArchiver unArchiver;
unArchiver = archiverManager.getUnArchiver(file);
unArchiver.setSourceFile(file);
unArchiver.setDestDirectory(location);
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);
}
if (this.silent) {
silenceUnarchiver(unArchiver);
}
unArchiver.extract();
} catch (NoSuchArchiverException e) {
throw new MojoExecutionException("Unknown archiver type", e);
} catch (ArchiverException e) {
e.printStackTrace();
throw new MojoExecutionException("Error unpacking file: " + file + " to: " + location + "\r\n" + e.toString(), e);
}
}
use of org.codehaus.plexus.archiver.ArchiverException in project openicf by Evolveum.
the class DocBookResourceMojo method generateArchive.
/**
* Method that creates the jar file
*
* @param docbkxFiles
* the directory where the generated jar file will be put
* @param jarFileName
* the filename of the generated jar file
* @return a File object that contains the generated jar file
* @throws ArchiverException
* if any
* @throws IOException
* if any
*/
private File generateArchive(File docbkxFiles, String jarFileName) throws ArchiverException, IOException {
File docbkxJar = new File(buildDirectory, jarFileName);
if (docbkxJar.exists()) {
docbkxJar.delete();
}
MavenArchiver archiver = new MavenArchiver();
archiver.setArchiver(jarArchiver);
archiver.setOutputFile(docbkxJar);
if (!docbkxFiles.exists()) {
getLog().warn("JAR will be empty - no content was marked for inclusion!");
} else {
archiver.getArchiver().addDirectory(docbkxFiles);
}
List<Resource> resources = project.getBuild().getResources();
for (Resource r : resources) {
if (r.getDirectory().endsWith("maven-shared-archive-resources")) {
archiver.getArchiver().addDirectory(new File(r.getDirectory()));
}
}
try {
archive.setAddMavenDescriptor(false);
archiver.createArchive(session, project, archive);
} catch (ManifestException e) {
throw new ArchiverException("ManifestException: " + e.getMessage(), e);
} catch (DependencyResolutionRequiredException e) {
throw new ArchiverException("DependencyResolutionRequiredException: " + e.getMessage(), e);
}
return docbkxJar;
}
use of org.codehaus.plexus.archiver.ArchiverException in project openicf by Evolveum.
the class DocBookResourceMojo method execute.
public void execute() throws MojoExecutionException, MojoFailureException {
if (skip) {
getLog().info("Skipping DocBook generation");
return;
}
if (!("pom".equalsIgnoreCase(project.getPackaging()))) {
ArtifactHandler artifactHandler = project.getArtifact().getArtifactHandler();
if (!"java".equals(artifactHandler.getLanguage())) {
getLog().info("Not executing DocBook report as the project is not a Java classpath-capable package");
return;
}
}
try {
if (!docbkxDirectory.exists()) {
getLog().info("Not executing DocBook report as the project does not have DocBook source");
return;
}
File rootDirectory = new File(buildDirectory, "openicf-docbkx/" + artifact.getArtifactId() + "-" + artifact.getVersion());
try {
FileUtils.mkdir(rootDirectory.getAbsolutePath());
MavenResourcesExecution mre = new MavenResourcesExecution();
mre.setMavenProject(getMavenProject());
mre.setEscapeWindowsPaths(true);
mre.setMavenSession(session);
mre.setInjectProjectBuildFilters(true);
List<FileUtils.FilterWrapper> filterWrappers = null;
try {
filterWrappers = fileFilter.getDefaultFilterWrappers(mre);
} catch (MavenFilteringException e) {
filterWrappers = Collections.emptyList();
}
if (docbkxDirectory.exists()) {
final List<String> includes = FileUtils.getFileAndDirectoryNames(docbkxDirectory, "**", StringUtils.join(DirectoryScanner.DEFAULTEXCLUDES, ",") + ",**/*.xml", true, false, true, true);
org.apache.commons.io.FileUtils.copyDirectory(docbkxDirectory, rootDirectory, new FileFilter() {
public boolean accept(File pathname) {
return includes.contains(pathname.getPath());
}
});
List<File> files = FileUtils.getFiles(docbkxDirectory, "**/*.xml", null);
for (File file : files) {
try {
fileFilter.copyFile(file, new File(rootDirectory, file.getName()), true, filterWrappers, getSourceEncoding());
} catch (MavenFilteringException e) {
throw new MojoExecutionException(e.getMessage(), e);
}
}
}
File sharedRoot = rootDirectory.getParentFile();
CodeSource src = getClass().getProtectionDomain().getCodeSource();
if (src != null) {
final ZipInputStream zip = new ZipInputStream(src.getLocation().openStream());
ZipEntry entry = null;
while ((entry = zip.getNextEntry()) != null) {
String name = entry.getName();
if (entry.getName().startsWith("shared")) {
File destination = new File(sharedRoot, name);
if (entry.isDirectory()) {
if (!destination.exists()) {
destination.mkdirs();
}
} else {
if (!destination.exists()) {
FileOutputStream output = null;
try {
output = new FileOutputStream(destination);
IOUtil.copy(zip, output);
} finally {
IOUtil.close(output);
}
}
}
}
}
zip.closeEntry();
zip.close();
}
} catch (IOException e) {
throw new MojoExecutionException("Error copy DocBook resources.", e);
}
// Generate Config and Schema DocBook Chapter
CurrentLocale.set(Locale.ENGLISH);
ConnectorDocBuilder generator = new ConnectorDocBuilder(this);
generator.executeReport();
if (attach) {
RemoteResourcesBundle remoteResourcesBundle = new RemoteResourcesBundle();
remoteResourcesBundle.setSourceEncoding(getSourceEncoding());
DirectoryScanner scanner = new DirectoryScanner();
scanner.setBasedir(new File(buildDirectory, "openicf-docbkx/"));
// scanner.setIncludes(new String[] { docFolder + "/**" });
scanner.addDefaultExcludes();
scanner.scan();
List<String> includedFiles = Arrays.asList(scanner.getIncludedFiles());
if (resourcesDirectory.exists()) {
scanner = new DirectoryScanner();
scanner.setBasedir(resourcesDirectory);
if (includes != null && includes.length != 0) {
scanner.setIncludes(includes);
} else {
scanner.setIncludes(DEFAULT_INCLUDES);
}
if (excludes != null && excludes.length != 0) {
scanner.setExcludes(excludes);
}
scanner.addDefaultExcludes();
scanner.scan();
includedFiles.addAll(Arrays.asList(scanner.getIncludedFiles()));
}
for (String resource : includedFiles) {
remoteResourcesBundle.addRemoteResource(StringUtils.replace(resource, '\\', '/'));
}
RemoteResourcesBundleXpp3Writer w = new RemoteResourcesBundleXpp3Writer();
try {
File f = new File(buildDirectory, "openicf-docbkx/" + BundleRemoteResourcesMojo.RESOURCES_MANIFEST);
FileUtils.mkdir(f.getParentFile().getAbsolutePath());
Writer writer = new FileWriter(f);
w.write(writer, remoteResourcesBundle);
} catch (IOException e) {
throw new MojoExecutionException("Error creating remote resources manifest.", e);
}
File outputFile = generateArchive(new File(buildDirectory, "openicf-docbkx/"), finalName + "-docbkx.jar");
projectHelper.attachArtifact(project, "jar", "docbkx", outputFile);
} else {
getLog().info("NOT adding DocBook to attached artifacts list.");
}
} catch (ArchiverException e) {
failOnError("ArchiverException: Error while creating archive", e);
} catch (IOException e) {
failOnError("IOException: Error while creating archive", e);
} catch (RuntimeException e) {
failOnError("RuntimeException: Error while creating archive", e);
}
}
Aggregations