use of org.apache.maven.project.ProjectBuildingRequest in project maven-plugins by apache.
the class DeployMojoTest method testUpdateReleaseParamSetToTrue.
public void testUpdateReleaseParamSetToTrue() 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);
boolean updateReleaseInfo = (Boolean) getVariableValueFromObject(mojo, "updateReleaseInfo");
assertTrue(updateReleaseInfo);
MavenProject project = (MavenProject) getVariableValueFromObject(mojo, "project");
setVariableValueToObject(mojo, "reactorProjects", Collections.singletonList(project));
artifact = (DeployArtifactStub) project.getArtifact();
artifact.setFile(testPom);
ArtifactRepositoryStub repo = getRepoStub(mojo);
repo.setAppendToUrl("basic-deploy-updateReleaseParam");
mojo.execute();
assertTrue(artifact.isRelease());
}
use of org.apache.maven.project.ProjectBuildingRequest in project maven-plugins by apache.
the class DeployMojoTest method testDeployWithAttachedArtifacts.
public void testDeployWithAttachedArtifacts() throws Exception {
File testPom = new File(getBasedir(), "target/test-classes/unit/basic-deploy-with-attached-artifacts/" + "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);
MavenProject project = (MavenProject) getVariableValueFromObject(mojo, "project");
setVariableValueToObject(mojo, "reactorProjects", Collections.singletonList(project));
artifact = (DeployArtifactStub) project.getArtifact();
File file = new File(getBasedir(), "target/test-classes/unit/basic-deploy-with-attached-artifacts/target/" + "deploy-test-file-1.0-SNAPSHOT.jar");
artifact.setFile(file);
ArtifactRepositoryStub repo = getRepoStub(mojo);
repo.setAppendToUrl("basic-deploy-with-attached-artifacts");
mojo.execute();
// check the artifacts in remote repository
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.jar");
expectedFiles.add("maven-deploy-test-1.0-SNAPSHOT.jar.md5");
expectedFiles.add("maven-deploy-test-1.0-SNAPSHOT.jar.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");
expectedFiles.add("attached-artifact-test-0");
expectedFiles.add("1.0-SNAPSHOT");
expectedFiles.add("maven-metadata.xml");
expectedFiles.add("maven-metadata.xml.md5");
expectedFiles.add("maven-metadata.xml.sha1");
expectedFiles.add("attached-artifact-test-0-1.0-SNAPSHOT.jar");
expectedFiles.add("attached-artifact-test-0-1.0-SNAPSHOT.jar.md5");
expectedFiles.add("attached-artifact-test-0-1.0-SNAPSHOT.jar.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-with-attached-artifacts");
File[] files = remoteRepo.listFiles();
for (File file1 : files) {
addFileToList(file1, fileList);
}
assertEquals(expectedFiles.size(), fileList.size());
assertEquals(0, getSizeOfExpectedFiles(fileList, expectedFiles));
}
use of org.apache.maven.project.ProjectBuildingRequest in project maven-plugins by apache.
the class DescribeMojo method isReportGoal.
/**
* Determines if this Mojo should be used as a report or not. This resolves the plugin project along with all of its
* transitive dependencies to determine if the Java class of this goal implements <code>MavenReport</code>.
*
* @param md Mojo descriptor
* @return Whether or not this goal should be used as a report.
*/
private boolean isReportGoal(MojoDescriptor md) {
PluginDescriptor pd = md.getPluginDescriptor();
List<URL> urls = new ArrayList<URL>();
ProjectBuildingRequest pbr = new DefaultProjectBuildingRequest(session.getProjectBuildingRequest());
pbr.setRemoteRepositories(remoteRepositories);
pbr.setResolveDependencies(true);
pbr.setProject(null);
pbr.setValidationLevel(ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL);
try {
Artifact jar = artifactResolver.resolveArtifact(pbr, toArtifactCoordinate(pd, "jar")).getArtifact();
Artifact pom = artifactResolver.resolveArtifact(pbr, toArtifactCoordinate(pd, "pom")).getArtifact();
MavenProject project = projectBuilder.build(pom.getFile(), pbr).getProject();
urls.add(jar.getFile().toURI().toURL());
for (Object artifact : project.getCompileClasspathElements()) {
urls.add(new File((String) artifact).toURI().toURL());
}
ClassLoader classLoader = new URLClassLoader(urls.toArray(new URL[urls.size()]), getClass().getClassLoader());
return MavenReport.class.isAssignableFrom(Class.forName(md.getImplementation(), false, classLoader));
} catch (Exception e) {
getLog().warn("Couldn't identify if this goal is a report goal: " + e.getMessage());
return false;
}
}
use of org.apache.maven.project.ProjectBuildingRequest in project maven-plugins by apache.
the class InstallMojoTest method createMavenSession.
private MavenSession createMavenSession() {
MavenSession session = mock(MavenSession.class);
DefaultRepositorySystemSession repositorySession = new DefaultRepositorySystemSession();
repositorySession.setLocalRepositoryManager(new EnhancedLocalRepositoryManager(new File(LOCAL_REPO)));
ProjectBuildingRequest buildingRequest = new DefaultProjectBuildingRequest();
buildingRequest.setRepositorySession(repositorySession);
when(session.getProjectBuildingRequest()).thenReturn(buildingRequest);
return session;
}
use of org.apache.maven.project.ProjectBuildingRequest in project maven-plugins by apache.
the class InstallMojoTest method testBasicInstallAndCreateChecksumIsTrue.
public void testBasicInstallAndCreateChecksumIsTrue() throws Exception {
File testPom = new File(getBasedir(), "target/test-classes/unit/basic-install-checksum/plugin-config.xml");
AbstractInstallMojo mojo = (AbstractInstallMojo) lookupMojo("install", testPom);
assertNotNull(mojo);
File file = new File(getBasedir(), "target/test-classes/unit/basic-install-checksum/" + "maven-test-jar.jar");
MavenProject project = (MavenProject) getVariableValueFromObject(mojo, "project");
MavenSession mavenSession = createMavenSession();
updateMavenProject(project);
setVariableValueToObject(mojo, "reactorProjects", Collections.singletonList(project));
setVariableValueToObject(mojo, "session", mavenSession);
artifact = (InstallArtifactStub) project.getArtifact();
boolean createChecksum = (Boolean) getVariableValueFromObject(mojo, "createChecksum");
assertTrue(createChecksum);
artifact.setFile(file);
mojo.execute();
ArtifactMetadata metadata = null;
for (Object o : artifact.getMetadataList()) {
metadata = (ArtifactMetadata) o;
if (metadata.getRemoteFilename().endsWith("pom")) {
break;
}
}
RepositoryManager repoManager = (RepositoryManager) getVariableValueFromObject(mojo, "repositoryManager");
ProjectBuildingRequest pbr = mavenSession.getProjectBuildingRequest();
File pom = new File(repoManager.getLocalRepositoryBasedir(pbr), repoManager.getPathForLocalMetadata(pbr, metadata));
assertTrue(pom.exists());
String groupId = dotToSlashReplacer(artifact.getGroupId());
String packaging = project.getPackaging();
String localPath = getBasedir() + "/" + LOCAL_REPO + groupId + "/" + artifact.getArtifactId() + "/" + artifact.getVersion() + "/" + artifact.getArtifactId() + "-" + artifact.getVersion();
// get the actual checksum of the pom
Map<String, Object> csums = ChecksumUtils.calc(pom, Utils.CHECKSUM_ALGORITHMS);
for (Map.Entry<String, Object> csum : csums.entrySet()) {
Object actualPomSum = csum.getValue();
File pomSum = new File(localPath + ".pom." + csum.getKey().toLowerCase().replace("-", ""));
assertTrue(pomSum.exists());
String generatedPomSum = FileUtils.fileRead(pomSum, "UTF-8");
assertEquals(actualPomSum, generatedPomSum);
}
// get the actual checksum of the artifact
csums = ChecksumUtils.calc(file, Utils.CHECKSUM_ALGORITHMS);
for (Map.Entry<String, Object> csum : csums.entrySet()) {
Object actualSum = csum.getValue();
File sum = new File(localPath + "." + packaging + "." + csum.getKey().toLowerCase().replace("-", ""));
assertTrue(sum.exists());
String generatedSum = FileUtils.fileRead(sum, "UTF-8");
assertEquals(actualSum, generatedSum);
}
File installedArtifact = new File(localPath + "." + packaging);
assertTrue(installedArtifact.exists());
assertEquals(9, FileUtils.getFiles(new File(LOCAL_REPO), null, null).size());
}
Aggregations