Search in sources :

Example 36 with ProjectBuildingRequest

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

the class DeployMojoTest method testDeployIfArtifactFileIsNull.

public void testDeployIfArtifactFileIsNull() throws Exception {
    File testPom = new File(getBasedir(), "target/test-classes/unit/basic-deploy-test/plugin-config.xml");
    DeployMojo mojo = (DeployMojo) lookupMojo("deploy", testPom);
    MockitoAnnotations.initMocks(this);
    ProjectBuildingRequest buildingRequest = mock(ProjectBuildingRequest.class);
    when(session.getProjectBuildingRequest()).thenReturn(buildingRequest);
    setVariableValueToObject(mojo, "session", session);
    assertNotNull(mojo);
    MavenProject project = (MavenProject) getVariableValueFromObject(mojo, "project");
    setVariableValueToObject(mojo, "reactorProjects", Collections.singletonList(project));
    artifact = (DeployArtifactStub) project.getArtifact();
    artifact.setFile(null);
    assertNull(artifact.getFile());
    try {
        mojo.execute();
        fail("Did not throw mojo execution exception");
    } catch (MojoExecutionException e) {
    // expected
    }
}
Also used : ProjectBuildingRequest(org.apache.maven.project.ProjectBuildingRequest) MavenProject(org.apache.maven.project.MavenProject) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) File(java.io.File)

Example 37 with ProjectBuildingRequest

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

the class DeployMojoTest method testBasicDeployWithPackagingAsPom.

public void testBasicDeployWithPackagingAsPom() throws Exception {
    File testPom = new File(getBasedir(), "target/test-classes/unit/basic-deploy-pom/plugin-config.xml");
    mojo = (DeployMojo) lookupMojo("deploy", testPom);
    MockitoAnnotations.initMocks(this);
    assertNotNull(mojo);
    ProjectBuildingRequest buildingRequest = mock(ProjectBuildingRequest.class);
    when(session.getProjectBuildingRequest()).thenReturn(buildingRequest);
    MavenRepositorySystemSession repositorySession = new MavenRepositorySystemSession();
    repositorySession.setLocalRepositoryManager(new SimpleLocalRepositoryManager(LOCAL_REPO));
    when(buildingRequest.getRepositorySession()).thenReturn(repositorySession);
    File pomFile = new File(getBasedir(), "target/test-classes/unit/basic-deploy-pom/target/" + "deploy-test-file-1.0-SNAPSHOT.pom");
    assertTrue(pomFile.exists());
    MavenProject project = (MavenProject) getVariableValueFromObject(mojo, "project");
    setVariableValueToObject(mojo, "reactorProjects", Collections.singletonList(project));
    artifact = (DeployArtifactStub) project.getArtifact();
    artifact.setArtifactHandlerExtension(project.getPackaging());
    artifact.setFile(pomFile);
    ArtifactRepositoryStub repo = getRepoStub(mojo);
    repo.setAppendToUrl("basic-deploy-pom");
    mojo.execute();
    List<String> expectedFiles = new ArrayList<String>();
    List<String> fileList = new ArrayList<String>();
    expectedFiles.add("org");
    expectedFiles.add("apache");
    expectedFiles.add("maven");
    expectedFiles.add("test");
    expectedFiles.add("maven-deploy-test");
    expectedFiles.add("1.0-SNAPSHOT");
    expectedFiles.add("maven-metadata.xml");
    expectedFiles.add("maven-metadata.xml.md5");
    expectedFiles.add("maven-metadata.xml.sha1");
    expectedFiles.add("maven-deploy-test-1.0-SNAPSHOT.pom");
    expectedFiles.add("maven-deploy-test-1.0-SNAPSHOT.pom.md5");
    expectedFiles.add("maven-deploy-test-1.0-SNAPSHOT.pom.sha1");
    // as we are in SNAPSHOT the file is here twice
    expectedFiles.add("maven-metadata.xml");
    expectedFiles.add("maven-metadata.xml.md5");
    expectedFiles.add("maven-metadata.xml.sha1");
    remoteRepo = new File(remoteRepo, "basic-deploy-pom");
    File[] files = remoteRepo.listFiles();
    for (File file : files) {
        addFileToList(file, fileList);
    }
    assertEquals(expectedFiles.size(), fileList.size());
    assertEquals(0, getSizeOfExpectedFiles(fileList, expectedFiles));
}
Also used : ProjectBuildingRequest(org.apache.maven.project.ProjectBuildingRequest) SimpleLocalRepositoryManager(org.sonatype.aether.impl.internal.SimpleLocalRepositoryManager) MavenProject(org.apache.maven.project.MavenProject) ArtifactRepositoryStub(org.apache.maven.plugins.deploy.stubs.ArtifactRepositoryStub) ArrayList(java.util.ArrayList) MavenRepositorySystemSession(org.apache.maven.repository.internal.MavenRepositorySystemSession) File(java.io.File)

Example 38 with ProjectBuildingRequest

use of org.apache.maven.project.ProjectBuildingRequest in project intellij-plugins by JetBrains.

the class Maven method readProject.

// @Nullable return null if cannot read
public MavenProject readProject(final File pomFile, final Logger logger) {
    AtomicNotNullLazyValue<MavenProject> projectRef = projectsCache.get(pomFile);
    if (projectRef == null) {
        AtomicNotNullLazyValue<MavenProject> candidate = projectsCache.putIfAbsent(pomFile, projectRef = new AtomicNotNullLazyValue<MavenProject>() {

            @Override
            protected MavenProject compute() {
                ProjectBuildingRequest projectBuildingRequest = session.getRequest().getProjectBuildingRequest();
                projectBuildingRequest.setResolveDependencies(true);
                projectBuildingRequest.setValidationLevel(ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL);
                projectBuildingRequest.setRepositorySession(session.getRepositorySession());
                projectBuildingRequest.setBuildStartTime(buildStartDate);
                try {
                    return projectBuilder.build(pomFile, projectBuildingRequest).getProject();
                } catch (Throwable e) {
                    logger.error("Cannot read project " + pomFile.getPath(), e);
                    return null;
                }
            }
        });
        if (candidate != null) {
            projectRef = candidate;
        }
    }
    return projectRef.getValue();
}
Also used : ProjectBuildingRequest(org.apache.maven.project.ProjectBuildingRequest) MavenProject(org.apache.maven.project.MavenProject)

Example 39 with ProjectBuildingRequest

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

the class JavadocReportTest method testTagletArtifacts.

/**
     * Method to test the <code>&lt;tagletArtifacts/&gt;</code> parameter.
     *
     * @throws Exception if any
     */
public void testTagletArtifacts() throws Exception {
    File testPom = new File(unit, "tagletArtifacts-test/tagletArtifacts-test-plugin-config.xml");
    JavadocReport mojo = lookupMojo(testPom);
    MavenSession session = spy(newMavenSession(mojo.project));
    ProjectBuildingRequest buildingRequest = mock(ProjectBuildingRequest.class);
    when(buildingRequest.getRemoteRepositories()).thenReturn(mojo.project.getRemoteArtifactRepositories());
    when(session.getProjectBuildingRequest()).thenReturn(buildingRequest);
    MavenRepositorySystemSession repositorySession = new MavenRepositorySystemSession();
    repositorySession.setLocalRepositoryManager(new SimpleLocalRepositoryManager(localRepo));
    when(buildingRequest.getRepositorySession()).thenReturn(repositorySession);
    when(session.getRepositorySession()).thenReturn(repositorySession);
    LegacySupport legacySupport = lookup(LegacySupport.class);
    legacySupport.setSession(session);
    setVariableValueToObject(mojo, "session", session);
    mojo.execute();
    File optionsFile = new File(mojo.getOutputDirectory(), "options");
    assertTrue(optionsFile.exists());
    String options = readFile(optionsFile);
    // count -taglet
    assertEquals(20, StringUtils.countMatches(options, LINE_SEPARATOR + "-taglet" + LINE_SEPARATOR));
    assertTrue(options.contains("org.apache.maven.tools.plugin.javadoc.MojoAggregatorTypeTaglet"));
    assertTrue(options.contains("org.apache.maven.tools.plugin.javadoc.MojoComponentFieldTaglet"));
    assertTrue(options.contains("org.apache.maven.tools.plugin.javadoc.MojoConfiguratorTypeTaglet"));
    assertTrue(options.contains("org.apache.maven.tools.plugin.javadoc.MojoExecuteTypeTaglet"));
    assertTrue(options.contains("org.apache.maven.tools.plugin.javadoc.MojoExecutionStrategyTypeTaglet"));
    assertTrue(options.contains("org.apache.maven.tools.plugin.javadoc.MojoGoalTypeTaglet"));
    assertTrue(options.contains("org.apache.maven.tools.plugin.javadoc.MojoInheritByDefaultTypeTaglet"));
    assertTrue(options.contains("org.apache.maven.tools.plugin.javadoc.MojoInstantiationStrategyTypeTaglet"));
    assertTrue(options.contains("org.apache.maven.tools.plugin.javadoc.MojoParameterFieldTaglet"));
    assertTrue(options.contains("org.apache.maven.tools.plugin.javadoc.MojoPhaseTypeTaglet"));
    assertTrue(options.contains("org.apache.maven.tools.plugin.javadoc.MojoReadOnlyFieldTaglet"));
    assertTrue(options.contains("org.apache.maven.tools.plugin.javadoc.MojoRequiredFieldTaglet"));
    assertTrue(options.contains("org.apache.maven.tools.plugin.javadoc.MojoRequiresDependencyResolutionTypeTaglet"));
    assertTrue(options.contains("org.apache.maven.tools.plugin.javadoc.MojoRequiresDirectInvocationTypeTaglet"));
    assertTrue(options.contains("org.apache.maven.tools.plugin.javadoc.MojoRequiresOnLineTypeTaglet"));
    assertTrue(options.contains("org.apache.maven.tools.plugin.javadoc.MojoRequiresProjectTypeTaglet"));
    assertTrue(options.contains("org.apache.maven.tools.plugin.javadoc.MojoRequiresReportsTypeTaglet"));
    assertTrue(options.contains("org.codehaus.plexus.javadoc.PlexusConfigurationTaglet"));
    assertTrue(options.contains("org.codehaus.plexus.javadoc.PlexusRequirementTaglet"));
    assertTrue(options.contains("org.codehaus.plexus.javadoc.PlexusComponentTaglet"));
}
Also used : MavenSession(org.apache.maven.execution.MavenSession) ProjectBuildingRequest(org.apache.maven.project.ProjectBuildingRequest) SimpleLocalRepositoryManager(org.sonatype.aether.impl.internal.SimpleLocalRepositoryManager) LegacySupport(org.apache.maven.plugin.LegacySupport) MavenRepositorySystemSession(org.apache.maven.repository.internal.MavenRepositorySystemSession) File(java.io.File)

Example 40 with ProjectBuildingRequest

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

the class JavadocReportTest method testDoclets.

/**
     * Method to test the doclet artifact configuration
     *
     * @throws Exception if any
     */
public void testDoclets() throws Exception {
    // ----------------------------------------------------------------------
    // doclet-test: check if the file generated by UmlGraph exists and if
    // doclet path contains the UmlGraph artifact
    // ----------------------------------------------------------------------
    File testPom = new File(unit, "doclet-test/doclet-test-plugin-config.xml");
    JavadocReport mojo = lookupMojo(testPom);
    MavenSession session = spy(newMavenSession(mojo.project));
    ProjectBuildingRequest buildingRequest = mock(ProjectBuildingRequest.class);
    when(buildingRequest.getRemoteRepositories()).thenReturn(mojo.project.getRemoteArtifactRepositories());
    when(session.getProjectBuildingRequest()).thenReturn(buildingRequest);
    MavenRepositorySystemSession repositorySession = new MavenRepositorySystemSession();
    repositorySession.setLocalRepositoryManager(new SimpleLocalRepositoryManager(localRepo));
    when(buildingRequest.getRepositorySession()).thenReturn(repositorySession);
    when(session.getRepositorySession()).thenReturn(repositorySession);
    LegacySupport legacySupport = lookup(LegacySupport.class);
    legacySupport.setSession(session);
    setVariableValueToObject(mojo, "session", session);
    mojo.execute();
    File generatedFile = new File(getBasedir(), "target/test/unit/doclet-test/target/site/apidocs/graph.dot");
    assertTrue(FileUtils.fileExists(generatedFile.getAbsolutePath()));
    File optionsFile = new File(mojo.getOutputDirectory(), "options");
    assertTrue(optionsFile.exists());
    String options = readFile(optionsFile);
    assertTrue(options.contains("/target/local-repo/umlgraph/UMLGraph/2.1/UMLGraph-2.1.jar"));
    // ----------------------------------------------------------------------
    // doclet-path: check if the file generated by UmlGraph exists and if
    // doclet path contains the twice UmlGraph artifacts
    // ----------------------------------------------------------------------
    testPom = new File(unit, "doclet-path-test/doclet-path-test-plugin-config.xml");
    mojo = lookupMojo(testPom);
    setVariableValueToObject(mojo, "session", session);
    mojo.execute();
    generatedFile = new File(getBasedir(), "target/test/unit/doclet-test/target/site/apidocs/graph.dot");
    assertTrue(FileUtils.fileExists(generatedFile.getAbsolutePath()));
    optionsFile = new File(mojo.getOutputDirectory(), "options");
    assertTrue(optionsFile.exists());
    options = readFile(optionsFile);
    assertTrue(options.contains("/target/local-repo/umlgraph/UMLGraph/2.1/UMLGraph-2.1.jar"));
    assertTrue(options.contains("/target/local-repo/umlgraph/UMLGraph-bis/2.1/UMLGraph-bis-2.1.jar"));
}
Also used : MavenSession(org.apache.maven.execution.MavenSession) ProjectBuildingRequest(org.apache.maven.project.ProjectBuildingRequest) SimpleLocalRepositoryManager(org.sonatype.aether.impl.internal.SimpleLocalRepositoryManager) LegacySupport(org.apache.maven.plugin.LegacySupport) MavenRepositorySystemSession(org.apache.maven.repository.internal.MavenRepositorySystemSession) File(java.io.File)

Aggregations

ProjectBuildingRequest (org.apache.maven.project.ProjectBuildingRequest)81 File (java.io.File)40 DefaultProjectBuildingRequest (org.apache.maven.project.DefaultProjectBuildingRequest)37 MavenRepositorySystemSession (org.apache.maven.repository.internal.MavenRepositorySystemSession)28 SimpleLocalRepositoryManager (org.sonatype.aether.impl.internal.SimpleLocalRepositoryManager)28 Artifact (org.apache.maven.artifact.Artifact)25 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)22 MavenProject (org.apache.maven.project.MavenProject)22 MavenSession (org.apache.maven.execution.MavenSession)17 IOException (java.io.IOException)14 LegacySupport (org.apache.maven.plugin.LegacySupport)13 ArtifactResolverException (org.apache.maven.shared.artifact.resolve.ArtifactResolverException)12 ArrayList (java.util.ArrayList)9 ArtifactRepository (org.apache.maven.artifact.repository.ArtifactRepository)8 MavenArtifactRepository (org.apache.maven.artifact.repository.MavenArtifactRepository)8 ArchetypeGenerationRequest (org.apache.maven.archetype.ArchetypeGenerationRequest)7 ArchetypeManager (org.apache.maven.archetype.ArchetypeManager)7 ArchetypeCatalog (org.apache.maven.archetype.catalog.ArchetypeCatalog)7 ProjectBuildingException (org.apache.maven.project.ProjectBuildingException)7 ArtifactResult (org.apache.maven.shared.artifact.resolve.ArtifactResult)7