use of org.apache.maven.artifact.factory.ArtifactFactory in project semantic-versioning by jeluard.
the class AbstractEnforcerRule method execute.
@Override
public void execute(final EnforcerRuleHelper helper) throws EnforcerRuleException {
final MavenProject project = getMavenProject(helper);
if (shouldSkipRuleExecution(project)) {
helper.getLog().debug("Skipping non " + AbstractEnforcerRule.JAR_ARTIFACT_TYPE + " or " + BUNDLE_ARTIFACT_TYPE + " artifact.");
return;
}
final Artifact previousArtifact;
final Artifact currentArtifact = validateArtifact(project.getArtifact());
final Version current = Version.parse(currentArtifact.getVersion());
try {
final ArtifactRepository localRepository = (ArtifactRepository) helper.evaluate("${localRepository}");
final String version;
if (this.previousVersion != null) {
version = this.previousVersion;
helper.getLog().info("Version specified as <" + version + ">");
} else {
final ArtifactMetadataSource artifactMetadataSource = (ArtifactMetadataSource) helper.getComponent(ArtifactMetadataSource.class);
final List<ArtifactVersion> availableVersions = getAvailableReleasedVersions(artifactMetadataSource, project, localRepository);
final List<ArtifactVersion> availablePreviousVersions = filterNonPreviousVersions(availableVersions, current);
if (availablePreviousVersions.isEmpty()) {
helper.getLog().warn("No previously released version. Backward compatibility check not performed.");
return;
}
version = availablePreviousVersions.iterator().next().toString();
helper.getLog().info("Version deduced as <" + version + "> (among all availables: " + availablePreviousVersions + ")");
}
final ArtifactFactory artifactFactory = (ArtifactFactory) helper.getComponent(ArtifactFactory.class);
previousArtifact = artifactFactory.createArtifact(project.getGroupId(), project.getArtifactId(), version, null, project.getArtifact().getType());
final ArtifactResolver resolver = (ArtifactResolver) helper.getComponent(ArtifactResolver.class);
resolver.resolve(previousArtifact, project.getRemoteArtifactRepositories(), localRepository);
validateArtifact(previousArtifact);
} catch (Exception e) {
helper.getLog().warn("Exception while accessing artifacts; skipping check.", e);
return;
}
final Version previous = Version.parse(previousArtifact.getVersion());
final File previousJar = previousArtifact.getFile();
final File currentJar = currentArtifact.getFile();
compareJars(helper, previous, previousJar, current, currentJar);
}
use of org.apache.maven.artifact.factory.ArtifactFactory in project intellij-community by JetBrains.
the class Maven30ServerEmbedderImpl method reset.
@Override
public void reset() throws RemoteException {
try {
setConsoleAndIndicator(null, null);
final ArtifactFactory artifactFactory = getComponent(ArtifactFactory.class);
if (artifactFactory instanceof CustomMaven3ArtifactFactory) {
((CustomMaven3ArtifactFactory) artifactFactory).reset();
}
final ArtifactResolver artifactResolver = getComponent(ArtifactResolver.class);
if (artifactResolver instanceof CustomMaven30ArtifactResolver) {
((CustomMaven30ArtifactResolver) artifactResolver).reset();
}
final RepositoryMetadataManager repositoryMetadataManager = getComponent(RepositoryMetadataManager.class);
if (repositoryMetadataManager instanceof CustomMaven3RepositoryMetadataManager) {
((CustomMaven3RepositoryMetadataManager) repositoryMetadataManager).reset();
}
//((CustomWagonManager)getComponent(WagonManager.class)).reset();
} catch (Exception e) {
throw rethrowException(e);
}
}
use of org.apache.maven.artifact.factory.ArtifactFactory in project intellij-community by JetBrains.
the class Maven3ServerEmbedderImpl method reset.
@Override
public void reset() throws RemoteException {
try {
setConsoleAndIndicator(null, null);
final ArtifactFactory artifactFactory = getComponent(ArtifactFactory.class);
if (artifactFactory instanceof CustomMaven3ArtifactFactory) {
((CustomMaven3ArtifactFactory) artifactFactory).reset();
}
final ArtifactResolver artifactResolver = getComponent(ArtifactResolver.class);
if (artifactResolver instanceof CustomMaven3ArtifactResolver) {
((CustomMaven3ArtifactResolver) artifactResolver).reset();
}
final RepositoryMetadataManager repositoryMetadataManager = getComponent(RepositoryMetadataManager.class);
if (repositoryMetadataManager instanceof CustomMaven3RepositoryMetadataManager) {
((CustomMaven3RepositoryMetadataManager) repositoryMetadataManager).reset();
}
//((CustomWagonManager)getComponent(WagonManager.class)).reset();
} catch (Exception e) {
throw rethrowException(e);
}
}
use of org.apache.maven.artifact.factory.ArtifactFactory in project maven-plugins by apache.
the class DependencyTestUtils method getArtifactFactory.
public static ArtifactFactory getArtifactFactory() throws IllegalAccessException {
ArtifactFactory artifactFactory;
ArtifactHandlerManager manager = new DefaultArtifactHandlerManager();
setVariableValueToObject(manager, "artifactHandlers", new HashMap());
artifactFactory = new DefaultArtifactFactory();
setVariableValueToObject(artifactFactory, "artifactHandlerManager", manager);
return artifactFactory;
}
use of org.apache.maven.artifact.factory.ArtifactFactory in project maven-plugins by apache.
the class TestCopyDependenciesMojo2 method testRepositoryLayout.
public void testRepositoryLayout() throws Exception {
String baseVersion = "2.0-SNAPSHOT";
String groupId = "testGroupId";
String artifactId = "expanded-snapshot";
Artifact expandedSnapshot = createExpandedVersionArtifact(baseVersion, groupId, artifactId, "compile", "jar", null);
mojo.getProject().getArtifacts().add(expandedSnapshot);
mojo.getProject().getDependencyArtifacts().add(expandedSnapshot);
Artifact pomExpandedSnapshot = createExpandedVersionArtifact(baseVersion, groupId, artifactId, "compile", "pom", null);
mojo.getProject().getArtifacts().add(pomExpandedSnapshot);
mojo.getProject().getDependencyArtifacts().add(pomExpandedSnapshot);
mojo.useRepositoryLayout = true;
mojo.execute();
ArtifactFactory artifactFactory = lookup(ArtifactFactory.class);
File outputDirectory = mojo.outputDirectory;
ArtifactRepository targetRepository = new MavenArtifactRepository("local", outputDirectory.toURL().toExternalForm(), new DefaultRepositoryLayout(), new ArtifactRepositoryPolicy(), new ArtifactRepositoryPolicy());
Set<Artifact> artifacts = mojo.getProject().getArtifacts();
for (Artifact artifact : artifacts) {
assertArtifactExists(artifact, targetRepository);
if (!artifact.getBaseVersion().equals(artifact.getVersion())) {
Artifact baseArtifact = artifactFactory.createArtifact(artifact.getGroupId(), artifact.getArtifactId(), artifact.getBaseVersion(), artifact.getScope(), artifact.getType());
assertArtifactExists(baseArtifact, targetRepository);
}
}
}
Aggregations