Search in sources :

Example 41 with MavenProject

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

the class DependencyFilesetsTask method execute.

/** {@inheritDoc} */
public void execute() {
    if (this.getProject().getReference(mavenProjectId) == null) {
        throw new BuildException("Maven project reference not found: " + mavenProjectId);
    }
    MavenProject mavenProject = (MavenProject) this.getProject().getReference("maven.project");
    // Add filesets for depenedency artifacts
    Set<Artifact> depArtifacts = filterArtifacts(mavenProject.getArtifacts());
    FileSet dependenciesFileSet = new FileSet();
    dependenciesFileSet.setProject(getProject());
    ArtifactRepository localRepository = (ArtifactRepository) getProject().getReference("maven.local.repository");
    dependenciesFileSet.setDir(new File(localRepository.getBasedir()));
    for (Artifact artifact : depArtifacts) {
        String relativeArtifactPath = localRepository.pathOf(artifact);
        dependenciesFileSet.createInclude().setName(relativeArtifactPath);
        String fileSetName = getPrefix() + artifact.getDependencyConflictId();
        FileSet singleArtifactFileSet = new FileSet();
        singleArtifactFileSet.setProject(getProject());
        singleArtifactFileSet.setFile(artifact.getFile());
        getProject().addReference(fileSetName, singleArtifactFileSet);
    }
    getProject().addReference((getPrefix() + projectDependenciesId), dependenciesFileSet);
}
Also used : MavenProject(org.apache.maven.project.MavenProject) FileSet(org.apache.tools.ant.types.FileSet) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository) BuildException(org.apache.tools.ant.BuildException) File(java.io.File) Artifact(org.apache.maven.artifact.Artifact)

Example 42 with MavenProject

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

the class JiraUnicodeTestCase method testUnicodeReport.

public void testUnicodeReport() throws Exception {
    File pom = new File(getBasedir(), "/src/test/unit/jira-plugin-config.xml");
    assertNotNull(pom);
    assertTrue(pom.exists());
    JiraMojo mojo = (JiraMojo) lookupMojo("jira-report", pom);
    MavenProject project = new JiraUnicodeTestProjectStub();
    MavenSession session = newMavenSession(project);
    DefaultRepositorySystemSession repoSession = (DefaultRepositorySystemSession) session.getRepositorySession();
    repoSession.setLocalRepositoryManager(new SimpleLocalRepositoryManager("target/local-repo"));
    setVariableValueToObject(mojo, "project", project);
    setVariableValueToObject(mojo, "mavenSession", session);
    InputStream testJiraXmlStream = JiraUnicodeTestCase.class.getResourceAsStream("unicode-jira-results.xml");
    String jiraXml = null;
    try {
        jiraXml = IOUtils.toString(testJiraXmlStream, "utf-8");
    } finally {
        testJiraXmlStream.close();
    }
    MockJiraDownloader mockDownloader = new MockJiraDownloader();
    mockDownloader.setJiraXml(jiraXml);
    mojo.setMockDownloader(mockDownloader);
    File outputDir = new File("target/jira-test-output");
    outputDir.mkdirs();
    mojo.setReportOutputDirectory(outputDir);
    mojo.execute();
    String reportHtml = FileUtils.readFileToString(new File(outputDir, "jira-report.html"), "utf-8");
    int turtleIndex = reportHtml.indexOf(TEST_TURTLES);
    assertTrue(turtleIndex >= 0);
}
Also used : MavenSession(org.apache.maven.execution.MavenSession) SimpleLocalRepositoryManager(org.sonatype.aether.impl.internal.SimpleLocalRepositoryManager) MavenProject(org.apache.maven.project.MavenProject) DefaultRepositorySystemSession(org.sonatype.aether.util.DefaultRepositorySystemSession) InputStream(java.io.InputStream) JiraMojo(org.apache.maven.plugins.jira.JiraMojo) File(java.io.File)

Example 43 with MavenProject

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

the class AbstractCheckDocumentationMojo method buildErrorMessages.

private String buildErrorMessages(Map<MavenProject, DocumentationReporter> reporters) {
    String messages = "";
    StringBuilder buffer = new StringBuilder();
    for (Map.Entry<MavenProject, DocumentationReporter> entry : reporters.entrySet()) {
        MavenProject project = entry.getKey();
        DocumentationReporter reporter = entry.getValue();
        if (!reporter.getMessages().isEmpty()) {
            buffer.append("\no ").append(project.getName());
            buffer.append(" (");
            final int numberOfErrors = reporter.getMessagesByType(DocumentationReport.TYPE_ERROR).size();
            buffer.append(numberOfErrors).append(" error").append(numberOfErrors == 1 ? "" : "s");
            buffer.append(", ");
            final int numberOfWarnings = reporter.getMessagesByType(DocumentationReport.TYPE_WARN).size();
            buffer.append(numberOfWarnings).append(" warning").append(numberOfWarnings == 1 ? "" : "s");
            buffer.append(")");
            buffer.append("\n");
            for (String error : reporter.getMessages()) {
                buffer.append("  ").append(error).append("\n");
            }
        }
    }
    if (buffer.length() > 0) {
        messages = "The following documentation problems were found:\n" + buffer.toString();
    }
    return messages;
}
Also used : MavenProject(org.apache.maven.project.MavenProject) DocumentationReporter(org.apache.maven.plugin.docck.reports.DocumentationReporter) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 44 with MavenProject

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

the class AbstractCheckDocumentationMojo method execute.

public void execute() throws MojoExecutionException, MojoFailureException {
    setupProxy();
    if (output != null) {
        getLog().info("Writing documentation check results to: " + output);
    }
    Map<MavenProject, DocumentationReporter> reporters = new LinkedHashMap<MavenProject, DocumentationReporter>();
    boolean hasErrors = false;
    for (MavenProject project : reactorProjects) {
        if (approveProjectPackaging(project.getPackaging())) {
            getLog().info("Checking project: " + project.getName());
            DocumentationReporter reporter = new DocumentationReporter();
            checkProject(project, reporter);
            if (!hasErrors && reporter.hasErrors()) {
                hasErrors = true;
            }
            reporters.put(project, reporter);
        } else {
            getLog().info("Skipping unsupported project: " + project.getName());
        }
    }
    String messages;
    messages = buildErrorMessages(reporters);
    if (!hasErrors) {
        messages += "No documentation errors were found.";
    }
    try {
        writeMessages(messages, hasErrors);
    } catch (IOException e) {
        throw new MojoExecutionException("Error writing results to output file: " + output);
    }
    if (hasErrors) {
        String logLocation;
        if (output == null) {
            logLocation = "Please see the console output above for more information.";
        } else {
            logLocation = "Please see \'" + output + "\' for more information.";
        }
        throw new MojoFailureException("Documentation problems were found. " + logLocation);
    }
}
Also used : MavenProject(org.apache.maven.project.MavenProject) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) DocumentationReporter(org.apache.maven.plugin.docck.reports.DocumentationReporter) MojoFailureException(org.apache.maven.plugin.MojoFailureException) IOException(java.io.IOException) LinkedHashMap(java.util.LinkedHashMap)

Example 45 with MavenProject

use of org.apache.maven.project.MavenProject 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)

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