use of org.apache.maven.enforcer.rule.api.EnforcerRuleException in project admin-console-beta by connexta.
the class ArtifactSizeEnforcerRule method getArtifactPath.
private String getArtifactPath(EnforcerRuleHelper helper) throws EnforcerRuleException {
String convertedArtifactLocation = artifactLocation;
if (StringUtils.isNotEmpty(convertedArtifactLocation)) {
helper.getLog().info(String.format("Using specified artifactLocation %s", convertedArtifactLocation));
} else {
try {
helper.getLog().info("artifactLocation property not specified. Looking up artifact using maven properties.");
String artifactId = (String) helper.evaluate(PROJECT_ARTIFACT_ID_PROP);
String version = (String) helper.evaluate(PROJECT_VERSION_PROP);
String packaging = getPackaging(helper);
String buildDir = (String) helper.evaluate(PROJECT_BUILD_DIR_PROP);
helper.getLog().debug(String.format(DEFAULT_ARTIFACT_INFO_MSG, artifactId, version, packaging, buildDir));
convertedArtifactLocation = buildDir + File.separator + artifactId + "-" + version + "." + packaging;
helper.getLog().debug(String.format("Complete generated artifact path: %s", convertedArtifactLocation));
} catch (ExpressionEvaluationException e) {
throw new EnforcerRuleException(e.getMessage());
}
}
return convertedArtifactLocation;
}
use of org.apache.maven.enforcer.rule.api.EnforcerRuleException 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.enforcer.rule.api.EnforcerRuleException in project metis-framework by europeana.
the class VocabularyCollectionMavenRule method execute.
@Override
public void execute(EnforcerRuleHelper enforcerRuleHelper) throws EnforcerRuleException {
// Get the environment: the log and the project.
final Log log = enforcerRuleHelper.getLog();
final MavenProject project;
try {
project = enforcerRuleHelper.getComponent(MavenProject.class);
} catch (ComponentLookupException e) {
throw new EnforcerRuleException("Could not retrieve the project properties.", e);
}
// Get the vocabulary directory file
final Path baseDirectory = project.getBasedir().toPath();
final Path vocabularyDirectory = baseDirectory.resolve(vocabularyDirectoryFile);
// Prepare validation
final VocabularyCollectionImporter importer = new VocabularyCollectionImporterFactory().createImporter(baseDirectory, vocabularyDirectory);
final VocabularyCollectionValidatorImpl validator = new VocabularyCollectionValidatorImpl(importer, lenientOnLackOfExamples, lenientOnMappingTestFailures, lenientOnExampleRetrievalFailures);
log.info("");
log.info("Validating vocabulary collection: " + importer.getDirectoryLocation().toString());
// Perform validation
try {
validator.validate(vocabulary -> log.info(" Vocabulary found: " + vocabulary.getName()), log::warn);
} catch (VocabularyImportException e) {
log.error(e.getMessage());
throw new EnforcerRuleException("Vocabulary collection validation failed.", e);
}
// Done
log.info("Finished validating vocabulary collection.");
}
use of org.apache.maven.enforcer.rule.api.EnforcerRuleException in project cloud-opensource-java by GoogleCloudPlatform.
the class LinkageCheckerRule method buildClassPathResult.
private static ClassPathResult buildClassPathResult(DependencyResolutionResult result) throws EnforcerRuleException {
// The root node must have the project's JAR file
DependencyNode root = result.getDependencyGraph();
File rootFile = root.getArtifact().getFile();
if (rootFile == null) {
throw new EnforcerRuleException("The root project artifact is not associated with a file.");
}
List<Dependency> unresolvedDependencies = result.getUnresolvedDependencies();
Set<Artifact> unresolvedArtifacts = unresolvedDependencies.stream().map(Dependency::getArtifact).collect(toImmutableSet());
DependencyGraph dependencyGraph = DependencyGraph.from(root);
AnnotatedClassPath annotatedClassPath = new AnnotatedClassPath();
ImmutableList.Builder<UnresolvableArtifactProblem> problems = ImmutableList.builder();
for (DependencyPath path : dependencyGraph.list()) {
Artifact artifact = path.getLeaf();
if (unresolvedArtifacts.contains(artifact)) {
problems.add(new UnresolvableArtifactProblem(artifact));
} else {
annotatedClassPath.put(new ClassPathEntry(artifact), path);
}
}
return new ClassPathResult(annotatedClassPath, problems.build());
}
use of org.apache.maven.enforcer.rule.api.EnforcerRuleException in project cloud-opensource-java by GoogleCloudPlatform.
the class LinkageCheckerRule method findBomClasspath.
/**
* Builds a class path for {@code bomProject}.
*/
private ClassPathResult findBomClasspath(MavenProject bomProject, RepositorySystemSession repositorySystemSession) throws EnforcerRuleException {
ArtifactTypeRegistry artifactTypeRegistry = repositorySystemSession.getArtifactTypeRegistry();
List<org.apache.maven.model.Dependency> managedDependencies = bomProject.getDependencyManagement().getDependencies();
ImmutableList<Artifact> artifacts = managedDependencies.stream().map(dependency -> RepositoryUtils.toDependency(dependency, artifactTypeRegistry)).map(Dependency::getArtifact).filter(artifact -> !Bom.shouldSkipBomMember(artifact)).collect(toImmutableList());
try {
ClassPathResult result = classPathBuilder.resolve(artifacts, false, DependencyMediation.MAVEN);
ImmutableList<UnresolvableArtifactProblem> artifactProblems = result.getArtifactProblems();
if (!artifactProblems.isEmpty()) {
throw new EnforcerRuleException("Failed to collect dependency: " + artifactProblems);
}
return result;
} catch (InvalidVersionSpecificationException ex) {
throw new EnforcerRuleException("Dependency mediation failed due to invalid version", ex);
}
}
Aggregations