Search in sources :

Example 21 with DependencyResolutionRequiredException

use of org.apache.maven.artifact.DependencyResolutionRequiredException 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.");
    }
}
Also used : DependencyResolutionRequiredException(org.apache.maven.artifact.DependencyResolutionRequiredException) MavenProject(org.apache.maven.project.MavenProject) 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 22 with DependencyResolutionRequiredException

use of org.apache.maven.artifact.DependencyResolutionRequiredException in project generator by mybatis.

the class MyBatisGeneratorMojo method calculateClassPath.

private void calculateClassPath() throws MojoExecutionException {
    if (includeCompileDependencies || includeAllDependencies) {
        try {
            // add the project compile classpath to the plugin classpath,
            // so that the project dependency classes can be found
            // directly, without adding the classpath to configuration's classPathEntries
            // repeatedly.Examples are JDBC drivers, root classes, root interfaces, etc.
            Set<String> entries = new HashSet<>();
            if (includeCompileDependencies) {
                entries.addAll(project.getCompileClasspathElements());
            }
            if (includeAllDependencies) {
                entries.addAll(project.getTestClasspathElements());
            }
            // remove the output directories (target/classes and target/test-classes)
            // because this mojo runs in the generate-sources phase and
            // those directories have not been created yet (typically)
            entries.remove(project.getBuild().getOutputDirectory());
            entries.remove(project.getBuild().getTestOutputDirectory());
            ClassLoader contextClassLoader = ClassloaderUtility.getCustomClassloader(entries);
            Thread.currentThread().setContextClassLoader(contextClassLoader);
        } catch (DependencyResolutionRequiredException e) {
            throw new MojoExecutionException("Dependency Resolution Required", e);
        }
    }
}
Also used : DependencyResolutionRequiredException(org.apache.maven.artifact.DependencyResolutionRequiredException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) HashSet(java.util.HashSet)

Example 23 with DependencyResolutionRequiredException

use of org.apache.maven.artifact.DependencyResolutionRequiredException in project cuke4duke by cucumber.

the class AbstractJRubyMojo method append.

protected void append(Path classPath, List<?> artifacts) throws DependencyResolutionRequiredException {
    List<String> list = new ArrayList<String>(artifacts.size());
    for (Object elem : artifacts) {
        String path;
        if (elem instanceof Artifact) {
            Artifact a = (Artifact) elem;
            File file = a.getFile();
            if (file == null) {
                throw new DependencyResolutionRequiredException(a);
            }
            path = file.getPath();
        } else {
            path = elem.toString();
        }
        list.add(path);
    }
    Path p = new Path(classPath.getProject());
    p.setPath(StringUtils.join(list.iterator(), File.pathSeparator));
    classPath.append(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 24 with DependencyResolutionRequiredException

use of org.apache.maven.artifact.DependencyResolutionRequiredException in project xtext-xtend by eclipse.

the class XtendCompile method getClassPath.

@SuppressWarnings("deprecation")
protected List<String> getClassPath() {
    Set<String> classPath = Sets.newLinkedHashSet();
    classPath.add(project.getBuild().getSourceDirectory());
    try {
        classPath.addAll(project.getCompileClasspathElements());
    } catch (DependencyResolutionRequiredException e) {
        throw new WrappedException(e);
    }
    addDependencies(classPath, project.getCompileArtifacts());
    classPath.remove(project.getBuild().getOutputDirectory());
    return newArrayList(filter(classPath, FILE_EXISTS));
}
Also used : WrappedException(org.eclipse.emf.common.util.WrappedException) DependencyResolutionRequiredException(org.apache.maven.artifact.DependencyResolutionRequiredException)

Example 25 with DependencyResolutionRequiredException

use of org.apache.maven.artifact.DependencyResolutionRequiredException in project xtext-xtend by eclipse.

the class XtendTestCompile method getTestClassPath.

@SuppressWarnings("deprecation")
protected List<String> getTestClassPath() {
    Set<String> classPath = Sets.newLinkedHashSet();
    classPath.add(project.getBuild().getTestSourceDirectory());
    try {
        classPath.addAll(project.getTestClasspathElements());
    } catch (DependencyResolutionRequiredException e) {
        throw new WrappedException(e);
    }
    addDependencies(classPath, project.getTestArtifacts());
    classPath.remove(project.getBuild().getTestOutputDirectory());
    return newArrayList(filter(classPath, FILE_EXISTS));
}
Also used : WrappedException(org.eclipse.emf.common.util.WrappedException) DependencyResolutionRequiredException(org.apache.maven.artifact.DependencyResolutionRequiredException)

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