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);
}
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);
}
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;
}
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);
}
}
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));
}
Aggregations