use of org.apache.maven.artifact.DependencyResolutionRequiredException 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.artifact.DependencyResolutionRequiredException 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.artifact.DependencyResolutionRequiredException 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.apache.maven.artifact.DependencyResolutionRequiredException in project maven-plugins by apache.
the class AntRunMojo method getPathFromArtifacts.
/**
* @param artifacts {@link Artifact} collection.
* @param antProject {@link Project}
* @return {@link Path}
* @throws DependencyResolutionRequiredException In case of a failure.
*/
private Path getPathFromArtifacts(Collection<Artifact> artifacts, Project antProject) throws DependencyResolutionRequiredException {
if (artifacts == null) {
return new Path(antProject);
}
List<String> list = new ArrayList<String>(artifacts.size());
for (Artifact a : artifacts) {
File file = a.getFile();
if (file == null) {
throw new DependencyResolutionRequiredException(a);
}
list.add(file.getPath());
}
Path p = new Path(antProject);
p.setPath(StringUtils.join(list.iterator(), File.pathSeparator));
return p;
}
use of org.apache.maven.artifact.DependencyResolutionRequiredException in project maven-plugins by apache.
the class AbstractFixJavadocMojo method getProjectClassLoader.
/**
* @return the classLoader for the given project using lazy instantiation.
* @throws MojoExecutionException if any
*/
private ClassLoader getProjectClassLoader() throws MojoExecutionException {
if (projectClassLoader == null) {
List<String> classPath;
try {
classPath = getCompileClasspathElements(project);
} catch (DependencyResolutionRequiredException e) {
throw new MojoExecutionException("DependencyResolutionRequiredException: " + e.getMessage(), e);
}
List<URL> urls = new ArrayList<>(classPath.size());
for (String filename : classPath) {
try {
urls.add(new File(filename).toURL());
} catch (MalformedURLException e) {
throw new MojoExecutionException("MalformedURLException: " + e.getMessage(), e);
}
}
projectClassLoader = new URLClassLoader(urls.toArray(new URL[urls.size()]), null);
}
return projectClassLoader;
}
Aggregations