aboutsummaryrefslogtreecommitdiffstats
path: root/enforcer-rule
diff options
context:
space:
mode:
authorJulien Eluard <[email protected]>2010-11-15 23:49:56 +0100
committerJulien Eluard <[email protected]>2010-11-15 23:49:56 +0100
commit5d31c40323d980fc394ee8caf505241e74bd37e5 (patch)
tree8db563eb98d29c53bf03da84a377ab475ccaa2fd /enforcer-rule
parentfc1d06d8226763e6c702865affc879b8a43afb80 (diff)
Fixed bug in compatibility checking.
Diffstat (limited to 'enforcer-rule')
-rw-r--r--enforcer-rule/src/main/java/org/semver/enforcer/CheckVersionRule.java37
1 files changed, 23 insertions, 14 deletions
diff --git a/enforcer-rule/src/main/java/org/semver/enforcer/CheckVersionRule.java b/enforcer-rule/src/main/java/org/semver/enforcer/CheckVersionRule.java
index 77409e4..f167dfe 100644
--- a/enforcer-rule/src/main/java/org/semver/enforcer/CheckVersionRule.java
+++ b/enforcer-rule/src/main/java/org/semver/enforcer/CheckVersionRule.java
@@ -19,15 +19,16 @@
package org.semver.enforcer;
import java.io.File;
+import java.io.IOException;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
+
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.resolver.ArtifactResolver;
-
import org.apache.maven.enforcer.rule.api.EnforcerRule;
import org.apache.maven.enforcer.rule.api.EnforcerRuleException;
import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper;
@@ -74,30 +75,38 @@ public final class CheckVersionRule implements EnforcerRule {
@Override
public void execute(final EnforcerRuleHelper helper) throws EnforcerRuleException {
+ final Artifact previousArtifact;
+ final Artifact currentArtifact;
try {
final MavenProject project = (MavenProject) helper.evaluate("${project}");
final ArtifactFactory artifactFactory = (ArtifactFactory) helper.getComponent(ArtifactFactory.class);
- final Artifact previousArtifact = artifactFactory.createArtifact(project.getGroupId(), project.getArtifactId(), this.previousVersion, null, "jar");
+ previousArtifact = artifactFactory.createArtifact(project.getGroupId(), project.getArtifactId(), this.previousVersion, null, "jar");
final ArtifactResolver resolver = (ArtifactResolver) helper.getComponent(ArtifactResolver.class );
final ArtifactRepository localRepository = (ArtifactRepository) helper.evaluate("${localRepository}");
resolver.resolve(previousArtifact, project.getRemoteArtifactRepositories(), localRepository);
- final Artifact currentArtifact = project.getArtifact();
+ currentArtifact = project.getArtifact();
validateArtifact(previousArtifact);
validateArtifact(currentArtifact);
-
- final Version previous = Version.parse(previousArtifact.getVersion());
- final File previousJar = previousArtifact.getFile();
- final Version current = Version.parse(currentArtifact.getVersion());
- final File currentJar = currentArtifact.getFile();
- final Checker.CompatibilityType compatibilityType = new Checker().check(previousJar, currentJar, extractFilters(this.includes), extractFilters(this.excludes));
- final boolean compatible = Checker.isTypeCompatible(compatibilityType, previous.delta(current));
- if (!compatible) {
- throw new EnforcerRuleException("Current codebase incompatible with version <"+current+">. Version should be at least <"+Checker.inferNextVersion(previous, compatibilityType)+">.");
- }
} catch (Exception e) {
- throw new EnforcerRuleException("Exception while executing rule", e);
+ throw new EnforcerRuleException("Exception while accessing artifacts: "+e.toString(), e);
+ }
+
+ final Version previous = Version.parse(previousArtifact.getVersion());
+ final File previousJar = previousArtifact.getFile();
+ final Version current = Version.parse(currentArtifact.getVersion());
+ final File currentJar = currentArtifact.getFile();
+ final Checker.CompatibilityType compatibilityType;
+ try {
+ compatibilityType = new Checker().check(previousJar, currentJar, extractFilters(this.includes), extractFilters(this.excludes));
+ } catch (IOException e) {
+ throw new EnforcerRuleException("Exception while checking compatibility: "+e.toString(), e);
+ }
+ final boolean compatible = Checker.isTypeCompatible(compatibilityType, previous.delta(current));
+ if (!compatible) {
+ throw new EnforcerRuleException("Current codebase incompatible with version <"+current+">. Version should be at least <"+Checker.inferNextVersion(previous, compatibilityType)+">.");
}
+
}
/**