use of org.apache.maven.artifact.metadata.ArtifactMetadata in project archiva by apache.
the class LegacyToDefaultConverterTest method testMergeArtifactMetadata.
@Test
public void testMergeArtifactMetadata() throws Exception {
// test artifact level metadata is merged when it already exists on successful conversion
Artifact artifact = createArtifact("test", "newversion-artifact", "1.0.1");
artifactConverter.convert(artifact, targetRepository);
checkSuccess(artifactConverter);
Path artifactFile = Paths.get(targetRepository.getBasedir(), targetRepository.pathOf(artifact));
assertTrue("Check artifact created", Files.exists(artifactFile));
assertTrue("Check artifact matches", FileUtils.contentEquals(artifactFile.toFile(), artifact.getFile()));
artifact = createPomArtifact(artifact);
Path pomFile = Paths.get(targetRepository.getBasedir(), targetRepository.pathOf(artifact));
Path sourcePomFile = Paths.get(sourceRepository.getBasedir(), sourceRepository.pathOf(artifact));
assertTrue("Check POM created", Files.exists(pomFile));
compareFiles(sourcePomFile, pomFile);
ArtifactMetadata artifactMetadata = new ArtifactRepositoryMetadata(artifact);
Path artifactMetadataFile = Paths.get(targetRepository.getBasedir(), targetRepository.pathOfRemoteRepositoryMetadata(artifactMetadata));
assertTrue("Check artifact metadata created", Files.exists(artifactMetadataFile));
Path expectedMetadataFile = getTestFile("src/test/expected-files/newversion-artifact-metadata.xml");
compareFiles(expectedMetadataFile, artifactMetadataFile);
}
use of org.apache.maven.artifact.metadata.ArtifactMetadata in project archiva by apache.
the class LegacyToDefaultConverterTest method testV4PomConvert.
@Test
public void testV4PomConvert() throws Exception {
// test that it is copied as is
Artifact artifact = createArtifact("test", "v4artifact", "1.0.0");
ArtifactMetadata artifactMetadata = new ArtifactRepositoryMetadata(artifact);
Path artifactMetadataFile = Paths.get(targetRepository.getBasedir(), targetRepository.pathOfRemoteRepositoryMetadata(artifactMetadata));
Files.deleteIfExists(artifactMetadataFile);
ArtifactMetadata versionMetadata = new SnapshotArtifactRepositoryMetadata(artifact);
Path versionMetadataFile = Paths.get(targetRepository.getBasedir(), targetRepository.pathOfRemoteRepositoryMetadata(versionMetadata));
Files.deleteIfExists(versionMetadataFile);
Path artifactFile = Paths.get(targetRepository.getBasedir(), targetRepository.pathOf(artifact));
Files.deleteIfExists(artifactFile);
artifactConverter.convert(artifact, targetRepository);
checkSuccess(artifactConverter);
assertTrue("Check artifact created", Files.exists(artifactFile));
assertTrue("Check artifact matches", FileUtils.contentEquals(artifactFile.toFile(), artifact.getFile()));
artifact = createPomArtifact(artifact);
Path pomFile = Paths.get(targetRepository.getBasedir(), targetRepository.pathOf(artifact));
Path sourcePomFile = Paths.get(sourceRepository.getBasedir(), sourceRepository.pathOf(artifact));
assertTrue("Check POM created", Files.exists(pomFile));
compareFiles(sourcePomFile, pomFile);
assertTrue("Check artifact metadata created", Files.exists(artifactMetadataFile));
Path expectedMetadataFile = getTestFile("src/test/expected-files/v4-artifact-metadata.xml");
compareFiles(expectedMetadataFile, artifactMetadataFile);
assertTrue("Check snapshot metadata created", Files.exists(versionMetadataFile));
expectedMetadataFile = getTestFile("src/test/expected-files/v4-version-metadata.xml");
compareFiles(expectedMetadataFile, versionMetadataFile);
}
use of org.apache.maven.artifact.metadata.ArtifactMetadata in project build-info by JFrogDev.
the class BuildInfoRecorder method addPomArtifact.
private void addPomArtifact(Artifact nonPomArtifact, ModuleBuilder module, IncludeExcludePatterns patterns, String deploymentPath, String pomFileName, boolean excludeArtifactsFromBuild) {
for (ArtifactMetadata metadata : nonPomArtifact.getMetadataList()) {
if (metadata instanceof ProjectArtifactMetadata) {
// The pom metadata
ArtifactBuilder artifactBuilder = new ArtifactBuilder(pomFileName).type("pom");
File pomFile = ((ProjectArtifactMetadata) metadata).getFile();
org.jfrog.build.api.Artifact pomArtifact = artifactBuilder.build();
if (pomFile != null && pomFile.isFile()) {
if (excludeArtifactsFromBuild && PatternMatcher.pathConflicts(deploymentPath, patterns)) {
module.addExcludedArtifact(pomArtifact);
} else {
module.addArtifact(pomArtifact);
}
addDeployableArtifact(pomArtifact, pomFile, nonPomArtifact.getGroupId(), nonPomArtifact.getArtifactId(), nonPomArtifact.getVersion(), nonPomArtifact.getClassifier(), "pom");
}
break;
}
}
}
use of org.apache.maven.artifact.metadata.ArtifactMetadata 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());
}
use of org.apache.maven.artifact.metadata.ArtifactMetadata in project maven-plugins by apache.
the class SignAndDeployFileMojo method deploy.
/**
* Deploy an artifact from a particular file.
*
* @param source the file to deploy
* @param artifact the artifact definition
* @param deploymentRepository the repository to deploy to
* @param localRepository the local repository to install into
* @throws ArtifactDeploymentException if an error occurred deploying the artifact
*/
protected void deploy(File source, Artifact artifact, ArtifactRepository deploymentRepository, ArtifactRepository localRepository) throws ArtifactDeploymentException {
int retryFailedDeploymentCount = Math.max(1, Math.min(10, this.retryFailedDeploymentCount));
ArtifactDeploymentException exception = null;
for (int count = 0; count < retryFailedDeploymentCount; count++) {
try {
if (count > 0) {
// CHECKSTYLE_OFF: LineLength
getLog().info("Retrying deployment attempt " + (count + 1) + " of " + retryFailedDeploymentCount);
// CHECKSTYLE_ON: LineLength
}
deployer.deploy(source, artifact, deploymentRepository, localRepository);
for (Object o : artifact.getMetadataList()) {
ArtifactMetadata metadata = (ArtifactMetadata) o;
getLog().info("Metadata[" + metadata.getKey() + "].filename = " + metadata.getRemoteFilename());
}
exception = null;
break;
} catch (ArtifactDeploymentException e) {
if (count + 1 < retryFailedDeploymentCount) {
getLog().warn("Encountered issue during deployment: " + e.getLocalizedMessage());
getLog().debug(e);
}
if (exception == null) {
exception = e;
}
}
}
if (exception != null) {
throw exception;
}
}
Aggregations