Search in sources :

Example 1 with EnforcerRuleException

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;
}
Also used : ExpressionEvaluationException(org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException) EnforcerRuleException(org.apache.maven.enforcer.rule.api.EnforcerRuleException)

Example 2 with EnforcerRuleException

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);
}
Also used : DefaultArtifactVersion(org.apache.maven.artifact.versioning.DefaultArtifactVersion) ArtifactVersion(org.apache.maven.artifact.versioning.ArtifactVersion) ArtifactFactory(org.apache.maven.artifact.factory.ArtifactFactory) MavenProject(org.apache.maven.project.MavenProject) DefaultArtifactVersion(org.apache.maven.artifact.versioning.DefaultArtifactVersion) Version(org.semver.Version) ArtifactVersion(org.apache.maven.artifact.versioning.ArtifactVersion) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository) ArtifactMetadataSource(org.apache.maven.artifact.metadata.ArtifactMetadataSource) File(java.io.File) Artifact(org.apache.maven.artifact.Artifact) ArtifactResolver(org.apache.maven.artifact.resolver.ArtifactResolver) ExpressionEvaluationException(org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException) IOException(java.io.IOException) EnforcerRuleException(org.apache.maven.enforcer.rule.api.EnforcerRuleException) ArtifactMetadataRetrievalException(org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException)

Example 3 with EnforcerRuleException

use of org.apache.maven.enforcer.rule.api.EnforcerRuleException in project jersey by jersey.

the class FilePatternDoesNotExistRule method execute.

public void execute(EnforcerRuleHelper helper) throws EnforcerRuleException {
    if (files == null) {
        return;
    }
    for (File file : files) {
        final String filePath = file.getPath();
        final String prefix = filePath.substring(0, filePath.indexOf("*"));
        final String dirName = prefix.substring(0, prefix.lastIndexOf(File.separator));
        final String fileItselfPattern = filePath.substring(dirName.length() + 1);
        final File dir = new File(dirName);
        if (!dir.isDirectory()) {
            continue;
        }
        final Set<File> matchedFiles = new TreeSet<>();
        for (File matchedFile : dir.listFiles((FileFilter) new WildcardFileFilter(fileItselfPattern))) {
            matchedFiles.add(matchedFile);
        }
        if (!matchedFiles.isEmpty()) {
            throw new EnforcerRuleException("Files found! " + Arrays.toString(matchedFiles.toArray()));
        }
    }
}
Also used : TreeSet(java.util.TreeSet) EnforcerRuleException(org.apache.maven.enforcer.rule.api.EnforcerRuleException) File(java.io.File) WildcardFileFilter(org.apache.commons.io.filefilter.WildcardFileFilter)

Example 4 with EnforcerRuleException

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;
}
Also used : ExpressionEvaluationException(org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException) EnforcerRuleException(org.apache.maven.enforcer.rule.api.EnforcerRuleException)

Example 5 with EnforcerRuleException

use of org.apache.maven.enforcer.rule.api.EnforcerRuleException in project semantic-versioning by jeluard.

the class RequireBackwardCompatibility method enforce.

@Override
protected void enforce(final EnforcerRuleHelper helper, final Delta delta, final Version previous, final Version current) throws EnforcerRuleException {
    if (this.compatibilityType == null) {
        throw new IllegalArgumentException("A value for compatibilityType attribute must be provided.");
    }
    final Delta.CompatibilityType expectedCompatibilityType;
    try {
        expectedCompatibilityType = Delta.CompatibilityType.valueOf(this.compatibilityType);
    } catch (IllegalStateException e) {
        throw new EnforcerRuleException("Compatibility type value must be one of " + Delta.CompatibilityType.values());
    }
    final Delta.CompatibilityType detectedCompatibilityType = delta.computeCompatibilityType();
    if (this.strictChecking) {
        if (detectedCompatibilityType != expectedCompatibilityType) {
            fail(delta, "Current codebase is not strictly backward compatible (" + this.compatibilityType + ") with version <" + previous + ">. Compatibility type has been detected as <" + detectedCompatibilityType + ">");
        }
    } else {
        if (expectedCompatibilityType == Delta.CompatibilityType.NON_BACKWARD_COMPATIBLE) {
            helper.getLog().warn("Rule will never fail as compatibility type " + Delta.CompatibilityType.NON_BACKWARD_COMPATIBLE + " is used with non-strict checking.");
        }
        if (detectedCompatibilityType.compareTo(expectedCompatibilityType) > 0) {
            fail(delta, "Current codebase is not backward compatible (" + this.compatibilityType + ") with version <" + previous + ">. Compatibility type has been detected as <" + detectedCompatibilityType + ">");
        }
    }
}
Also used : Delta(org.semver.Delta) EnforcerRuleException(org.apache.maven.enforcer.rule.api.EnforcerRuleException)

Aggregations

EnforcerRuleException (org.apache.maven.enforcer.rule.api.EnforcerRuleException)6 ExpressionEvaluationException (org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException)3 File (java.io.File)2 IOException (java.io.IOException)2 Delta (org.semver.Delta)2 TreeSet (java.util.TreeSet)1 WildcardFileFilter (org.apache.commons.io.filefilter.WildcardFileFilter)1 Artifact (org.apache.maven.artifact.Artifact)1 ArtifactFactory (org.apache.maven.artifact.factory.ArtifactFactory)1 ArtifactMetadataRetrievalException (org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException)1 ArtifactMetadataSource (org.apache.maven.artifact.metadata.ArtifactMetadataSource)1 ArtifactRepository (org.apache.maven.artifact.repository.ArtifactRepository)1 ArtifactResolver (org.apache.maven.artifact.resolver.ArtifactResolver)1 ArtifactVersion (org.apache.maven.artifact.versioning.ArtifactVersion)1 DefaultArtifactVersion (org.apache.maven.artifact.versioning.DefaultArtifactVersion)1 MavenProject (org.apache.maven.project.MavenProject)1 DiffCriteria (org.osjava.jardiff.DiffCriteria)1 PublicDiffCriteria (org.osjava.jardiff.PublicDiffCriteria)1 SimpleDiffCriteria (org.osjava.jardiff.SimpleDiffCriteria)1 Comparer (org.semver.Comparer)1