Search in sources :

Example 96 with MavenProject

use of org.apache.maven.project.MavenProject in project maven-plugins by apache.

the class AbstractFromConfigurationMojo method fillMissingArtifactVersion.

/**
     * Tries to find missing version from dependency list and dependency management. If found, the artifact is updated
     * with the correct version. It will first look for an exact match on artifactId/groupId/classifier/type and if it
     * doesn't find a match, it will try again looking for artifactId and groupId only.
     *
     * @param artifact representing configured file.
     * @throws MojoExecutionException
     */
private void fillMissingArtifactVersion(ArtifactItem artifact) throws MojoExecutionException {
    MavenProject project = getProject();
    List<Dependency> deps = project.getDependencies();
    List<Dependency> depMngt = project.getDependencyManagement() == null ? Collections.<Dependency>emptyList() : project.getDependencyManagement().getDependencies();
    if (!findDependencyVersion(artifact, deps, false) && (project.getDependencyManagement() == null || !findDependencyVersion(artifact, depMngt, false)) && !findDependencyVersion(artifact, deps, true) && (project.getDependencyManagement() == null || !findDependencyVersion(artifact, depMngt, true))) {
        throw new MojoExecutionException("Unable to find artifact version of " + artifact.getGroupId() + ":" + artifact.getArtifactId() + " in either dependency list or in project's dependency management.");
    }
}
Also used : MavenProject(org.apache.maven.project.MavenProject) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) Dependency(org.apache.maven.model.Dependency)

Example 97 with MavenProject

use of org.apache.maven.project.MavenProject in project maven-plugins by apache.

the class CompilerMojoTestCase method getTestCompilerMojo.

private TestCompilerMojo getTestCompilerMojo(CompilerMojo compilerMojo, String pomXml) throws Exception {
    File testPom = new File(getBasedir(), pomXml);
    TestCompilerMojo mojo = (TestCompilerMojo) lookupMojo("testCompile", testPom);
    setVariableValueToObject(mojo, "log", new DebugEnabledLog());
    File buildDir = (File) getVariableValueFromObject(compilerMojo, "buildDirectory");
    File testClassesDir = new File(buildDir, "test-classes");
    setVariableValueToObject(mojo, "outputDirectory", testClassesDir);
    List<String> testClasspathList = new ArrayList<String>();
    Artifact junitArtifact = mock(Artifact.class);
    ArtifactHandler handler = mock(ArtifactHandler.class);
    when(handler.isAddedToClasspath()).thenReturn(true);
    when(junitArtifact.getArtifactHandler()).thenReturn(handler);
    File artifactFile;
    String localRepository = System.getProperty("localRepository");
    if (localRepository != null) {
        artifactFile = new File(localRepository, "junit/junit/3.8.1/junit-3.8.1.jar");
    } else {
        // for IDE
        String junitURI = org.junit.Test.class.getResource("Test.class").toURI().toString();
        junitURI = junitURI.substring("jar:".length(), junitURI.indexOf('!'));
        artifactFile = new File(URI.create(junitURI));
    }
    when(junitArtifact.getFile()).thenReturn(artifactFile);
    testClasspathList.add(artifactFile.getAbsolutePath());
    testClasspathList.add(compilerMojo.getOutputDirectory().getPath());
    String testSourceRoot = testPom.getParent() + "/src/test/java";
    setVariableValueToObject(mojo, "compileSourceRoots", Collections.singletonList(testSourceRoot));
    MavenProject project = getMockMavenProject();
    project.setArtifacts(Collections.singleton(junitArtifact));
    project.getBuild().setOutputDirectory(new File(buildDir, "classes").getAbsolutePath());
    setVariableValueToObject(mojo, "project", project);
    setVariableValueToObject(mojo, "compilePath", Collections.EMPTY_LIST);
    setVariableValueToObject(mojo, "testPath", testClasspathList);
    setVariableValueToObject(mojo, "session", getMockMavenSession());
    setVariableValueToObject(mojo, "mojoExecution", getMockMojoExecution());
    setVariableValueToObject(mojo, "source", source);
    setVariableValueToObject(mojo, "target", target);
    return mojo;
}
Also used : DebugEnabledLog(org.apache.maven.plugin.compiler.stubs.DebugEnabledLog) ArtifactHandler(org.apache.maven.artifact.handler.ArtifactHandler) MavenProject(org.apache.maven.project.MavenProject) ArrayList(java.util.ArrayList) File(java.io.File) Artifact(org.apache.maven.artifact.Artifact)

Example 98 with MavenProject

use of org.apache.maven.project.MavenProject in project maven-plugins by apache.

the class AbstractGpgSigner method getPassphrase.

public String getPassphrase(MavenProject project) throws IOException {
    String pass = null;
    if (project != null) {
        pass = project.getProperties().getProperty("gpg.passphrase");
        if (pass == null) {
            MavenProject prj2 = findReactorProject(project);
            pass = prj2.getProperties().getProperty("gpg.passphrase");
        }
    }
    if (pass == null) {
        pass = readPassword("GPG Passphrase: ");
    }
    if (project != null) {
        findReactorProject(project).getProperties().setProperty("gpg.passphrase", pass);
    }
    return pass;
}
Also used : MavenProject(org.apache.maven.project.MavenProject)

Example 99 with MavenProject

use of org.apache.maven.project.MavenProject in project maven-plugins by apache.

the class AbstractJavadocMojo method getDependenciesLinks.

/**
     * Using Maven, a Javadoc link is given by <code>${project.url}/apidocs</code>.
     *
     * @return the detected Javadoc links using the Maven conventions for all dependencies defined in the current
     *         project or an empty list.
     * @see #detectLinks
     * @see #isValidJavadocLink(String)
     * @since 2.6
     */
private List<String> getDependenciesLinks() {
    if (!detectLinks) {
        return Collections.emptyList();
    }
    getLog().debug("Trying to add links for dependencies...");
    List<String> dependenciesLinks = new ArrayList<String>();
    final Set<Artifact> dependencies = project.getDependencyArtifacts();
    for (Artifact artifact : dependencies) {
        if (artifact.getFile() == null || !artifact.getFile().exists()) {
            continue;
        }
        try {
            MavenProject artifactProject = mavenProjectBuilder.build(artifact, session.getProjectBuildingRequest()).getProject();
            if (StringUtils.isNotEmpty(artifactProject.getUrl())) {
                String url = getJavadocLink(artifactProject);
                if (isValidJavadocLink(url, true)) {
                    getLog().debug("Added Javadoc link: " + url + " for " + artifactProject.getId());
                    dependenciesLinks.add(url);
                }
            }
        } catch (ProjectBuildingException e) {
            logError("ProjectBuildingException for " + artifact.toString() + ": " + e.getMessage(), e);
        }
    }
    return dependenciesLinks;
}
Also used : ProjectBuildingException(org.apache.maven.project.ProjectBuildingException) MavenProject(org.apache.maven.project.MavenProject) ArrayList(java.util.ArrayList) JavadocPathArtifact(org.apache.maven.plugin.javadoc.options.JavadocPathArtifact) Artifact(org.apache.maven.artifact.Artifact) DocletArtifact(org.apache.maven.plugin.javadoc.options.DocletArtifact) BootclasspathArtifact(org.apache.maven.plugin.javadoc.options.BootclasspathArtifact) ResourcesArtifact(org.apache.maven.plugin.javadoc.options.ResourcesArtifact) TagletArtifact(org.apache.maven.plugin.javadoc.options.TagletArtifact)

Example 100 with MavenProject

use of org.apache.maven.project.MavenProject in project maven-plugins by apache.

the class ResourceResolver method resolveDependencyJavadocBundles.

/**
     * @param config {@link SourceResolverConfig}
     * @return list of {@link JavadocBundle}.
     * @throws IOException {@link IOException}
     */
public List<JavadocBundle> resolveDependencyJavadocBundles(final SourceResolverConfig config) throws IOException {
    final List<JavadocBundle> bundles = new ArrayList<JavadocBundle>();
    final Map<String, MavenProject> projectMap = new HashMap<String, MavenProject>();
    if (config.reactorProjects() != null) {
        for (final MavenProject p : config.reactorProjects()) {
            projectMap.put(key(p.getGroupId(), p.getArtifactId()), p);
        }
    }
    final List<Artifact> artifacts = config.project().getTestArtifacts();
    final List<Artifact> forResourceResolution = new ArrayList<Artifact>(artifacts.size());
    for (final Artifact artifact : artifacts) {
        final String key = key(artifact.getGroupId(), artifact.getArtifactId());
        final MavenProject p = projectMap.get(key);
        if (p != null) {
            bundles.addAll(resolveBundleFromProject(config, p, artifact));
        } else {
            forResourceResolution.add(artifact);
        }
    }
    bundles.addAll(resolveBundlesFromArtifacts(config, forResourceResolution));
    return bundles;
}
Also used : MavenProject(org.apache.maven.project.MavenProject) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Artifact(org.apache.maven.artifact.Artifact) DefaultArtifact(org.apache.maven.artifact.DefaultArtifact)

Aggregations

MavenProject (org.apache.maven.project.MavenProject)297 File (java.io.File)138 Artifact (org.apache.maven.artifact.Artifact)66 ArrayList (java.util.ArrayList)64 Model (org.apache.maven.model.Model)57 ConsoleLogger (org.codehaus.plexus.logging.console.ConsoleLogger)36 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)33 IOException (java.io.IOException)29 Assembly (org.apache.maven.plugins.assembly.model.Assembly)28 EasyMockSupport (org.easymock.classextension.EasyMockSupport)27 ArtifactMock (org.apache.maven.plugins.assembly.archive.task.testutils.ArtifactMock)20 Test (org.junit.Test)17 HashMap (java.util.HashMap)16 HashSet (java.util.HashSet)16 MavenSession (org.apache.maven.execution.MavenSession)16 DependencySet (org.apache.maven.plugins.assembly.model.DependencySet)16 ProjectBuildingException (org.apache.maven.project.ProjectBuildingException)16 LinkedHashSet (java.util.LinkedHashSet)15 ArtifactRepository (org.apache.maven.artifact.repository.ArtifactRepository)15 FileSet (org.apache.maven.plugins.assembly.model.FileSet)15