use of org.apache.maven.archiver.MavenArchiver in project maven-plugins by apache.
the class EjbMojo method generateEjbClient.
private File generateEjbClient() throws MojoExecutionException {
File clientJarFile = EjbHelper.getJarFile(outputDirectory, jarName, getClientClassifier());
getLog().info("Building EJB client " + clientJarFile.getPath());
MavenArchiver clientArchiver = new MavenArchiver();
clientArchiver.setArchiver(clientJarArchiver);
clientArchiver.setOutputFile(clientJarFile);
try {
List<String> defaultExcludes = DEFAULT_CLIENT_EXCLUDES_LIST;
List<String> defaultIncludes = DEFAULT_INCLUDES_LIST;
IncludesExcludes ie = new IncludesExcludes(clientIncludes, clientExcludes, defaultIncludes, defaultExcludes);
clientArchiver.getArchiver().addDirectory(sourceDirectory, ie.resultingIncludes(), ie.resultingExcludes());
clientArchiver.createArchive(session, project, archive);
} catch (ArchiverException e) {
throw new MojoExecutionException("There was a problem creating the EJB client archive: " + e.getMessage(), e);
} catch (ManifestException e) {
throw new MojoExecutionException("There was a problem creating the EJB client archive: " + e.getMessage(), e);
} catch (IOException e) {
throw new MojoExecutionException("There was a problem creating the EJB client archive: " + e.getMessage(), e);
} catch (DependencyResolutionRequiredException e) {
throw new MojoExecutionException("There was a problem creating the EJB client archive: " + e.getMessage(), e);
}
return clientJarFile;
}
use of org.apache.maven.archiver.MavenArchiver in project maven-plugins by apache.
the class AcrMojo method execute.
/** {@inheritDoc} */
public void execute() throws MojoExecutionException {
if (getLog().isInfoEnabled()) {
getLog().info("Building JavaEE Application client: " + jarName);
}
File jarFile = getAppClientJarFile(basedir, jarName);
MavenArchiver archiver = new MavenArchiver();
archiver.setArchiver(jarArchiver);
archiver.setOutputFile(jarFile);
try {
String[] mainJarExcludes = DEFAULT_EXCLUDES;
if (excludes != null && !excludes.isEmpty()) {
excludes.add(APP_CLIENT_XML);
mainJarExcludes = excludes.toArray(new String[excludes.size()]);
}
if (outputDirectory.exists()) {
archiver.getArchiver().addDirectory(outputDirectory, DEFAULT_INCLUDES, mainJarExcludes);
} else {
// CHECKSTYLE_OFF: LineLength
getLog().info("JAR will only contain the META-INF/application-client.xml as no content was marked for inclusion");
// CHECKSTYLE_ON: LineLength
}
File deploymentDescriptor = new File(outputDirectory, APP_CLIENT_XML);
if (deploymentDescriptor.exists()) {
if (filterDeploymentDescriptor) {
getLog().debug("Filtering deployment descriptor.");
MavenResourcesExecution mavenResourcesExecution = new MavenResourcesExecution();
mavenResourcesExecution.setEscapeString(escapeString);
List<FilterWrapper> filterWrappers = mavenFileFilter.getDefaultFilterWrappers(project, filters, escapeBackslashesInFilePath, this.session, mavenResourcesExecution);
// Create a temporary file that we can copy-and-filter
File unfilteredDeploymentDescriptor = new File(outputDirectory, APP_CLIENT_XML + ".unfiltered");
FileUtils.copyFile(deploymentDescriptor, unfilteredDeploymentDescriptor);
mavenFileFilter.copyFile(unfilteredDeploymentDescriptor, deploymentDescriptor, true, filterWrappers, getEncoding(unfilteredDeploymentDescriptor));
// Remove the temporary file
FileUtils.forceDelete(unfilteredDeploymentDescriptor);
}
archiver.getArchiver().addFile(deploymentDescriptor, APP_CLIENT_XML);
}
// create archive
archiver.createArchive(session, project, archive);
// CHECKSTYLE_OFF: LineLength
} catch (ArchiverException e) {
throw new MojoExecutionException("There was a problem creating the JavaEE Application Client archive: " + e.getMessage(), e);
} catch (ManifestException e) {
throw new MojoExecutionException("There was a problem reading / creating the manifest for the JavaEE Application Client archive: " + e.getMessage(), e);
} catch (IOException e) {
throw new MojoExecutionException("There was a I/O problem creating the JavaEE Application Client archive: " + e.getMessage(), e);
} catch (DependencyResolutionRequiredException e) {
throw new MojoExecutionException("There was a problem resolving dependencies while creating the JavaEE Application Client archive: " + e.getMessage(), e);
} catch (MavenFilteringException e) {
throw new MojoExecutionException("There was a problem filtering the deployment descriptor: " + e.getMessage(), e);
}
project.getArtifact().setFile(jarFile);
// CHECKSTYLE_ON: LineLength
}
use of org.apache.maven.archiver.MavenArchiver in project maven-plugins by apache.
the class JavadocJar method generateArchive.
// ----------------------------------------------------------------------
// private methods
// ----------------------------------------------------------------------
/**
* Method that creates the jar file
*
* @param javadocFiles 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 {@link ArchiverException}
* @throws IOException {@link IOException}
*/
private File generateArchive(File javadocFiles, String jarFileName) throws ArchiverException, IOException {
File javadocJar = new File(jarOutputDirectory, jarFileName);
if (javadocJar.exists()) {
javadocJar.delete();
}
MavenArchiver archiver = new MavenArchiver();
archiver.setArchiver(jarArchiver);
archiver.setOutputFile(javadocJar);
File contentDirectory = javadocFiles;
if (!contentDirectory.exists()) {
getLog().warn("JAR will be empty - no content was marked for inclusion!");
} else {
archiver.getArchiver().addDirectory(contentDirectory, DEFAULT_INCLUDES, DEFAULT_EXCLUDES);
}
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()));
}
}
if (useDefaultManifestFile && defaultManifestFile.exists() && archive.getManifestFile() == null) {
getLog().info("Adding existing MANIFEST to archive. Found under: " + defaultManifestFile.getPath());
archive.setManifestFile(defaultManifestFile);
}
try {
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 javadocJar;
}
use of org.apache.maven.archiver.MavenArchiver in project maven-plugins by apache.
the class RarMojo method execute.
public void execute() throws MojoExecutionException {
if (skip) {
getLog().info("Skipping rar generation.");
return;
}
// Check if jar file is there and if requested, copy it
try {
if (includeJar) {
File generatedJarFile = new File(outputDirectory, finalName + ".jar");
if (generatedJarFile.exists()) {
getLog().info("Including generated jar file[" + generatedJarFile.getName() + "]");
FileUtils.copyFileToDirectory(generatedJarFile, getBuildDir());
}
}
} catch (IOException e) {
throw new MojoExecutionException("Error copying generated Jar file", e);
}
// Copy dependencies
try {
Set<Artifact> artifacts = project.getArtifacts();
for (Artifact artifact : artifacts) {
ScopeArtifactFilter filter = new ScopeArtifactFilter(Artifact.SCOPE_RUNTIME);
if (!artifact.isOptional() && filter.include(artifact) && artifact.getArtifactHandler().isAddedToClasspath()) {
getLog().info("Copying artifact[" + artifact.getGroupId() + ", " + artifact.getId() + ", " + artifact.getScope() + "]");
FileUtils.copyFileToDirectory(artifact.getFile(), getBuildDir());
}
}
} catch (IOException e) {
throw new MojoExecutionException("Error copying RAR dependencies", e);
}
resourceHandling();
// Include custom manifest if necessary
try {
includeCustomRaXmlFile();
} catch (IOException e) {
throw new MojoExecutionException("Error copying ra.xml file", e);
}
// Check if connector deployment descriptor is there
File ddFile = new File(getBuildDir(), RA_XML_URI);
if (!ddFile.exists() && warnOnMissingRaXml) {
getLog().warn("Connector deployment descriptor: " + ddFile.getAbsolutePath() + " does not exist.");
}
File rarFile = getRarFile(outputDirectory, finalName, classifier);
try {
MavenArchiver archiver = new MavenArchiver();
archiver.setArchiver(jarArchiver);
archiver.setOutputFile(rarFile);
// Include custom manifest if necessary
includeCustomManifestFile();
archiver.getArchiver().addDirectory(getBuildDir());
archiver.createArchive(session, project, archive);
} catch (Exception e) {
throw new MojoExecutionException("Error assembling RAR", e);
}
if (classifier != null) {
projectHelper.attachArtifact(project, "rar", classifier, rarFile);
} else {
project.getArtifact().setFile(rarFile);
}
}
use of org.apache.maven.archiver.MavenArchiver 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.");
}
}
Aggregations