Search in sources :

Example 16 with DependencyResolutionRequiredException

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
}
Also used : MavenResourcesExecution(org.apache.maven.shared.filtering.MavenResourcesExecution) DependencyResolutionRequiredException(org.apache.maven.artifact.DependencyResolutionRequiredException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ArchiverException(org.codehaus.plexus.archiver.ArchiverException) MavenFilteringException(org.apache.maven.shared.filtering.MavenFilteringException) MavenArchiver(org.apache.maven.archiver.MavenArchiver) IOException(java.io.IOException) ManifestException(org.codehaus.plexus.archiver.jar.ManifestException) FilterWrapper(org.apache.maven.shared.utils.io.FileUtils.FilterWrapper) File(java.io.File)

Example 17 with DependencyResolutionRequiredException

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;
}
Also used : DependencyResolutionRequiredException(org.apache.maven.artifact.DependencyResolutionRequiredException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ArchiverException(org.codehaus.plexus.archiver.ArchiverException) MavenArchiver(org.apache.maven.archiver.MavenArchiver) IOException(java.io.IOException) ManifestException(org.codehaus.plexus.archiver.jar.ManifestException) File(java.io.File)

Example 18 with DependencyResolutionRequiredException

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);
    }
}
Also used : DependencyResolutionRequiredException(org.apache.maven.artifact.DependencyResolutionRequiredException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ArchiverException(org.codehaus.plexus.archiver.ArchiverException) MavenArchiver(org.apache.maven.archiver.MavenArchiver) IOException(java.io.IOException) ManifestException(org.codehaus.plexus.archiver.jar.ManifestException)

Example 19 with DependencyResolutionRequiredException

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;
}
Also used : Path(org.apache.tools.ant.types.Path) DependencyResolutionRequiredException(org.apache.maven.artifact.DependencyResolutionRequiredException) ArrayList(java.util.ArrayList) File(java.io.File) Artifact(org.apache.maven.artifact.Artifact)

Example 20 with DependencyResolutionRequiredException

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;
}
Also used : MalformedURLException(java.net.MalformedURLException) DependencyResolutionRequiredException(org.apache.maven.artifact.DependencyResolutionRequiredException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) URLClassLoader(java.net.URLClassLoader) ArrayList(java.util.ArrayList) File(java.io.File) URL(java.net.URL)

Aggregations

DependencyResolutionRequiredException (org.apache.maven.artifact.DependencyResolutionRequiredException)37 File (java.io.File)25 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)16 IOException (java.io.IOException)12 ArchiverException (org.codehaus.plexus.archiver.ArchiverException)11 ManifestException (org.codehaus.plexus.archiver.jar.ManifestException)11 MavenArchiver (org.apache.maven.archiver.MavenArchiver)10 MojoFailureException (org.apache.maven.plugin.MojoFailureException)9 ArrayList (java.util.ArrayList)8 MavenProject (org.apache.maven.project.MavenProject)8 MalformedURLException (java.net.MalformedURLException)6 URLClassLoader (java.net.URLClassLoader)6 URL (java.net.URL)5 FileNotFoundException (java.io.FileNotFoundException)3 HashSet (java.util.HashSet)3 Resource (org.apache.maven.model.Resource)3 Path (org.apache.tools.ant.types.Path)3 NamespaceMetaData (io.siddhi.doc.gen.metadata.NamespaceMetaData)2 Path (java.nio.file.Path)2 List (java.util.List)2