use of org.apache.maven.shared.repository.RepositoryManager 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