diff options
author | Jesse McConnell | 2009-07-02 17:45:19 +0000 |
---|---|---|
committer | Jesse McConnell | 2009-07-02 17:45:19 +0000 |
commit | 7c2393ec7ac01059adc80a50a4729a3abc4f264f (patch) | |
tree | ec07066f5fe91c58bee071028ecb3b842939b4a4 | |
parent | 2070804c8437c106a7a34802f478c9f625a537ec (diff) | |
download | org.eclipse.jetty.toolchain-7c2393ec7ac01059adc80a50a4729a3abc4f264f.tar.gz org.eclipse.jetty.toolchain-7c2393ec7ac01059adc80a50a4729a3abc4f264f.tar.xz org.eclipse.jetty.toolchain-7c2393ec7ac01059adc80a50a4729a3abc4f264f.zip |
[Bug 282309] enforcer rule
-rw-r--r-- | jetty-enforcer-rules/pom.xml | 58 | ||||
-rw-r--r-- | jetty-enforcer-rules/src/main/java/org/eclipse/jetty/toolchain/enforcer/rules/VersionRule.java | 89 |
2 files changed, 147 insertions, 0 deletions
diff --git a/jetty-enforcer-rules/pom.xml b/jetty-enforcer-rules/pom.xml new file mode 100644 index 0000000..67c6b7d --- /dev/null +++ b/jetty-enforcer-rules/pom.xml @@ -0,0 +1,58 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <artifactId>jetty-toolchain</artifactId> + <groupId>org.eclipse.jetty.toolchain</groupId> + <version>1.1</version> + </parent> + <artifactId>jetty-enforcer-rules</artifactId> + <packaging>jar</packaging> + <version>1.0-SNAPSHOT</version> + <name>Jetty Toolchain :: Enforcer Rules</name> + <properties> + <api.version>1.0-beta-1</api.version> + <maven.version>2.0.9</maven.version> + </properties> + <build> + </build> + <dependencies> + <dependency> + <groupId>org.apache.maven.enforcer</groupId> + <artifactId>enforcer-api</artifactId> + <version>${api.version}</version> + </dependency> + <dependency> + <groupId>org.apache.maven</groupId> + <artifactId>maven-project</artifactId> + <version>${maven.version}</version> + </dependency> + <dependency> + <groupId>org.apache.maven</groupId> + <artifactId>maven-core</artifactId> + <version>${maven.version}</version> + </dependency> + <dependency> + <groupId>org.apache.maven</groupId> + <artifactId>maven-artifact</artifactId> + <version>${maven.version}</version> + </dependency> + <dependency> + <groupId>org.apache.maven</groupId> + <artifactId>maven-plugin-api</artifactId> + <version>${maven.version}</version> + </dependency> + <dependency> + <groupId>org.codehaus.plexus</groupId> + <artifactId>plexus-container-default</artifactId> + <version>1.0-alpha-9</version> + </dependency> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>3.8.1</version> + <scope>test</scope> + </dependency> + </dependencies> +</project> + diff --git a/jetty-enforcer-rules/src/main/java/org/eclipse/jetty/toolchain/enforcer/rules/VersionRule.java b/jetty-enforcer-rules/src/main/java/org/eclipse/jetty/toolchain/enforcer/rules/VersionRule.java new file mode 100644 index 0000000..633e1c7 --- /dev/null +++ b/jetty-enforcer-rules/src/main/java/org/eclipse/jetty/toolchain/enforcer/rules/VersionRule.java @@ -0,0 +1,89 @@ +package org.eclipse.jetty.toolchain.enforcer.rules; + +import java.io.IOException; + +import org.apache.maven.enforcer.rule.api.EnforcerRule; +import org.apache.maven.enforcer.rule.api.EnforcerRuleException; +import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper; +import org.apache.maven.plugin.logging.Log; +import org.apache.maven.project.MavenProject; +import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException; +import org.codehaus.plexus.component.repository.exception.ComponentLookupException; +import org.codehaus.plexus.util.FileUtils; + +//======================================================================== +//Copyright (c) Webtide LLC +//------------------------------------------------------------------------ +//All rights reserved. This program and the accompanying materials +//are made available under the terms of the Eclipse Public License v1.0 +//and Apache License v2.0 which accompanies this distribution. +// +//The Eclipse Public License is available at +//http://www.eclipse.org/legal/epl-v10.html +// +//The Apache License v2.0 is available at +//http://www.apache.org/licenses/LICENSE-2.0.txt +// +//You may elect to redistribute this code under either of these licenses. +//======================================================================== + +public class VersionRule implements EnforcerRule +{ + + /** + * Simple param. This rule will fail if the value is true. + */ + private boolean shouldIfail = false; + + public void execute( EnforcerRuleHelper helper ) + throws EnforcerRuleException + { + try + { + String artifactId = (String) helper.evaluate( "${project.artifactId}" ); + String version = (String) helper.evaluate( "${project.version}" ); + + if ( "jetty-project".equals( artifactId ) && !version.contains( "SNAPSHOT" ) ) + { + String versionTxt = FileUtils.fileRead( "VERSION.txt" ); + + if ( versionTxt.contains( "SNAPSHOT" ) ) + { + shouldIfail = true; + } + } + + + if ( this.shouldIfail ) + { + throw new EnforcerRuleException( "When version is a non-snapshot, VERSION.txt should not have a SNAPSHOT version in it." ); + } + } + catch ( ExpressionEvaluationException e ) + { + throw new EnforcerRuleException( "Unable to lookup an expression " + e.getLocalizedMessage(), e ); + } + catch ( IOException e ) + { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + } + + public String getCacheId() + { + return "" + shouldIfail; + } + + public boolean isCacheable() + { + return true; + } + + public boolean isResultValid( EnforcerRule arg0 ) + { + return true; + } + +}
\ No newline at end of file |