Author: brianf Date: Thu Mar 29 20:38:56 2007 New Revision: 523925 URL: http://svn.apache.org/viewvc?view=rev&rev=523925 Log: site updates
Added: maven/plugins/trunk/maven-enforcer-plugin/src/main/java/org/apache/maven/plugin/enforcer/DisplayOsMojo.java maven/plugins/trunk/maven-enforcer-plugin/src/site/apt/rules/ maven/plugins/trunk/maven-enforcer-plugin/src/site/apt/rules/index.apt maven/plugins/trunk/maven-enforcer-plugin/src/site/apt/rules/requireJavaVersion.apt maven/plugins/trunk/maven-enforcer-plugin/src/site/apt/rules/requireMavenVersion.apt maven/plugins/trunk/maven-enforcer-plugin/src/site/apt/rules/requireOS.apt maven/plugins/trunk/maven-enforcer-plugin/src/site/apt/rules/versionRanges.apt Modified: maven/plugins/trunk/maven-enforcer-plugin/src/main/java/org/apache/maven/plugin/enforcer/AbstractVersionEnforcer.java maven/plugins/trunk/maven-enforcer-plugin/src/main/java/org/apache/maven/plugin/enforcer/EnforceMojo.java maven/plugins/trunk/maven-enforcer-plugin/src/main/java/org/apache/maven/plugin/enforcer/RequireJavaVersion.java maven/plugins/trunk/maven-enforcer-plugin/src/main/java/org/apache/maven/plugin/enforcer/RequireOS.java maven/plugins/trunk/maven-enforcer-plugin/src/site/apt/index.apt maven/plugins/trunk/maven-enforcer-plugin/src/site/apt/usage.apt maven/plugins/trunk/maven-enforcer-plugin/src/site/site.xml maven/plugins/trunk/maven-enforcer-plugin/src/test/java/org/apache/maven/plugin/enforcer/MockPlexusContainer.java maven/plugins/trunk/maven-enforcer-plugin/src/test/java/org/apache/maven/plugin/enforcer/TestMavenVersion.java maven/plugins/trunk/maven-enforcer-plugin/src/test/java/org/apache/maven/plugin/enforcer/TestRequireJavaVersion.java Modified: maven/plugins/trunk/maven-enforcer-plugin/src/main/java/org/apache/maven/plugin/enforcer/AbstractVersionEnforcer.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-enforcer-plugin/src/main/java/org/apache/maven/plugin/enforcer/AbstractVersionEnforcer.java?view=diff&rev=523925&r1=523924&r2=523925 ============================================================================== --- maven/plugins/trunk/maven-enforcer-plugin/src/main/java/org/apache/maven/plugin/enforcer/AbstractVersionEnforcer.java (original) +++ maven/plugins/trunk/maven-enforcer-plugin/src/main/java/org/apache/maven/plugin/enforcer/AbstractVersionEnforcer.java Thu Mar 29 20:38:56 2007 @@ -53,7 +53,7 @@ * @parameter * @required */ - protected String version = null; + public String version = null; /** * Compares the specified version to see if it is allowed by the defined Added: maven/plugins/trunk/maven-enforcer-plugin/src/main/java/org/apache/maven/plugin/enforcer/DisplayOsMojo.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-enforcer-plugin/src/main/java/org/apache/maven/plugin/enforcer/DisplayOsMojo.java?view=auto&rev=523925 ============================================================================== --- maven/plugins/trunk/maven-enforcer-plugin/src/main/java/org/apache/maven/plugin/enforcer/DisplayOsMojo.java (added) +++ maven/plugins/trunk/maven-enforcer-plugin/src/main/java/org/apache/maven/plugin/enforcer/DisplayOsMojo.java Thu Mar 29 20:38:56 2007 @@ -0,0 +1,74 @@ +package org.apache.maven.plugin.enforcer; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import org.apache.commons.lang.SystemUtils; +import org.apache.maven.execution.MavenSession; +import org.apache.maven.execution.RuntimeInformation; +import org.apache.maven.plugin.AbstractMojo; +import org.apache.maven.plugin.MojoExecutionException; +import org.codehaus.plexus.component.repository.exception.ComponentLookupException; + +/** + * This goal displays the current platform information + * + * @goal display-info + * @author <a href="mailto:[EMAIL PROTECTED]">Brian Fox</a> + * @version $Id: EnforceMojo.java 523156 2007-03-28 03:53:54Z brianf $ + */ +public class DisplayOsMojo + extends AbstractMojo +{ + /** + * Maven Session. + * + * @parameter expression="${session}" + * @required + * @readonly + */ + protected MavenSession session; + + /** + * Entry point to the mojo + */ + public void execute() + throws MojoExecutionException + { + try + { + DefaultEnforcementRuleHelper helper = new DefaultEnforcementRuleHelper( session, getLog() ); + RuntimeInformation rti = helper.getRuntimeInformation(); + getLog().info( "Maven Version: " + rti.getApplicationVersion() ); + RequireJavaVersion java = new RequireJavaVersion(); + getLog().info( + "JDK Version: " + SystemUtils.JAVA_VERSION + " normalized as: " + + java.fixJDKVersion( SystemUtils.JAVA_VERSION_TRIMMED ) ); + RequireOS os = new RequireOS(); + os.displayOSInfo( getLog() ); + + } + catch ( ComponentLookupException e ) + { + getLog().warn( "Unable to retreive component." + e.getLocalizedMessage() ); + } + + } + +} Modified: maven/plugins/trunk/maven-enforcer-plugin/src/main/java/org/apache/maven/plugin/enforcer/EnforceMojo.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-enforcer-plugin/src/main/java/org/apache/maven/plugin/enforcer/EnforceMojo.java?view=diff&rev=523925&r1=523924&r2=523925 ============================================================================== --- maven/plugins/trunk/maven-enforcer-plugin/src/main/java/org/apache/maven/plugin/enforcer/EnforceMojo.java (original) +++ maven/plugins/trunk/maven-enforcer-plugin/src/main/java/org/apache/maven/plugin/enforcer/EnforceMojo.java Thu Mar 29 20:38:56 2007 @@ -76,6 +76,7 @@ protected boolean failFast = false; /** + * List of objects that implement the EnforcerRule interface to execute. * @parameter * @required */ Modified: maven/plugins/trunk/maven-enforcer-plugin/src/main/java/org/apache/maven/plugin/enforcer/RequireJavaVersion.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-enforcer-plugin/src/main/java/org/apache/maven/plugin/enforcer/RequireJavaVersion.java?view=diff&rev=523925&r1=523924&r2=523925 ============================================================================== --- maven/plugins/trunk/maven-enforcer-plugin/src/main/java/org/apache/maven/plugin/enforcer/RequireJavaVersion.java (original) +++ maven/plugins/trunk/maven-enforcer-plugin/src/main/java/org/apache/maven/plugin/enforcer/RequireJavaVersion.java Thu Mar 29 20:38:56 2007 @@ -52,8 +52,8 @@ } /** - * Converts a jdk string from 1.5.0-11 to a single 3 digit version like - * 1.5.0 + * Converts a jdk string from 1.5.0-11b12 to a single 3 digit version like + * 1.5.0-11 * * @param theJdkVersion * to be converted. @@ -67,13 +67,22 @@ StringBuffer buffer = new StringBuffer( theJdkVersion.length() ); Iterator iter = tokens.iterator(); - for ( int i = 0; i < tokens.size() && i < 3; i++ ) + for ( int i = 0; i < tokens.size() && i < 4; i++ ) { buffer.append( iter.next() ); - buffer.append( '.' ); + if ( i != 2 ) + { + buffer.append( '.' ); + } + else + { + buffer.append( '-' ); + } + } String version = buffer.toString(); + version = StringUtils.stripEnd( version, "-" ); return StringUtils.stripEnd( version, "." ); } } Modified: maven/plugins/trunk/maven-enforcer-plugin/src/main/java/org/apache/maven/plugin/enforcer/RequireOS.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-enforcer-plugin/src/main/java/org/apache/maven/plugin/enforcer/RequireOS.java?view=diff&rev=523925&r1=523924&r2=523925 ============================================================================== --- maven/plugins/trunk/maven-enforcer-plugin/src/main/java/org/apache/maven/plugin/enforcer/RequireOS.java (original) +++ maven/plugins/trunk/maven-enforcer-plugin/src/main/java/org/apache/maven/plugin/enforcer/RequireOS.java Thu Mar 29 20:38:56 2007 @@ -63,27 +63,27 @@ * <li>os/400</li> * </ul> */ - private String family = null; + public String family = null; /** * Runtime information containing Maven Version. */ - private String name = null; + public String name = null; /** * Runtime information containing Maven Version. */ - private String version = null; + public String version = null; /** * Runtime information containing Maven Version. */ - private String arch = null; + public String arch = null; /** * Display detected OS information. */ - private boolean display = false; + public boolean display = false; private Set validFamilies = null; Modified: maven/plugins/trunk/maven-enforcer-plugin/src/site/apt/index.apt URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-enforcer-plugin/src/site/apt/index.apt?view=diff&rev=523925&r1=523924&r2=523925 ============================================================================== --- maven/plugins/trunk/maven-enforcer-plugin/src/site/apt/index.apt (original) +++ maven/plugins/trunk/maven-enforcer-plugin/src/site/apt/index.apt Thu Mar 29 20:38:56 2007 @@ -29,11 +29,11 @@ * Goals Overview - The Enforcer plugin has several goals: + The Enforcer plugin has two goals: - *{{{enforce-mojo.html}enforcer:enforce}} can check against the Maven and JDK versions + *{{{enforce-mojo.html}enforcer:enforce}} executes rules for each project in a multi-project build. - *{{{os-mojo.html}enforcer:os}} can check the OS. + *{{{enforce-once-mojo.html}enforcer:os}} executes rules once per build. * Usage Added: maven/plugins/trunk/maven-enforcer-plugin/src/site/apt/rules/index.apt URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-enforcer-plugin/src/site/apt/rules/index.apt?view=auto&rev=523925 ============================================================================== --- maven/plugins/trunk/maven-enforcer-plugin/src/site/apt/rules/index.apt (added) +++ maven/plugins/trunk/maven-enforcer-plugin/src/site/apt/rules/index.apt Thu Mar 29 20:38:56 2007 @@ -0,0 +1,34 @@ +~~ Licensed to the Apache Software Foundation (ASF) under one +~~ or more contributor license agreements. See the NOTICE file +~~ distributed with this work for additional information +~~ regarding copyright ownership. The ASF licenses this file +~~ to you under the Apache License, Version 2.0 (the +~~ "License"); you may not use this file except in compliance +~~ with the License. You may obtain a copy of the License at +~~ +~~ http://www.apache.org/licenses/LICENSE-2.0 +~~ +~~ Unless required by applicable law or agreed to in writing, +~~ software distributed under the License is distributed on an +~~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +~~ KIND, either express or implied. See the License for the +~~ specific language governing permissions and limitations +~~ under the License. + + ------ + Standard Rules + ------ + Brian Fox + ------ + Mar 2007 + ------ + +Standard Rules + + The following standard rules ship along with the enforcer plugin: + + * {{{requireMavenVersion.html}requireMavenVersion}} - enforces the Maven version. + + * {{{requireJavaVersion.html}requireJavaVersion}} - enforces the JDK version. + + * {{{requireJavaVersion.html}requireOS}} - enforces the OS / CPU Archictecture. \ No newline at end of file Added: maven/plugins/trunk/maven-enforcer-plugin/src/site/apt/rules/requireJavaVersion.apt URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-enforcer-plugin/src/site/apt/rules/requireJavaVersion.apt?view=auto&rev=523925 ============================================================================== --- maven/plugins/trunk/maven-enforcer-plugin/src/site/apt/rules/requireJavaVersion.apt (added) +++ maven/plugins/trunk/maven-enforcer-plugin/src/site/apt/rules/requireJavaVersion.apt Thu Mar 29 20:38:56 2007 @@ -0,0 +1,89 @@ +~~ Licensed to the Apache Software Foundation (ASF) under one +~~ or more contributor license agreements. See the NOTICE file +~~ distributed with this work for additional information +~~ regarding copyright ownership. The ASF licenses this file +~~ to you under the Apache License, Version 2.0 (the +~~ "License"); you may not use this file except in compliance +~~ with the License. You may obtain a copy of the License at +~~ +~~ http://www.apache.org/licenses/LICENSE-2.0 +~~ +~~ Unless required by applicable law or agreed to in writing, +~~ software distributed under the License is distributed on an +~~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +~~ KIND, either express or implied. See the License for the +~~ specific language governing permissions and limitations +~~ under the License. + + ------ + Require Java Version + ------ + Brian Fox + ------ + Mar 2007 + ------ + +Require Java Version + + This rule enforces certain Java JDK versions. The rule uses the {{{versionRanges.html}Enforcer version range syntax}} to define allowed versions. + + The following parameters are supported by this rule: + + * {{{../apidocs/org/apache/maven/plugin/enforcer/AbstractVersionEnforcer.html#version}version}} - {{{versionRanges.html}range}} of allowed JDKs. + + [] + + The JDK version is retrieved and the following processing occurs before being checked: + + [[1]] Drop all non-numeric characters preceeding the first number. (build 1.5.0_11-b03 becomes 1.5.0_11-b03) + + [[2]] Replace all '_' and '-' with '.' (1.5.0_11-b03 becomes 1.5.0.11.b03) + + [[3]] Split the string on '.' and take the first 3 sections, separated by '.' and add '-' followed by the forth section (1.5.0.11.b03 becomes 1.5.0-11) + + [] + + This preprocessing normalizes various JDK version strings into a standard x.y.z-b version number. Your required range should therefore use the x.y.z-b format for comparison. + There is an easy way to see how your current JDK string will be normalized: + ++---+ + mvn enforcer:display-info + ... + [enforcer:display-info] + Maven Version: 2.0.6 + JDK Version: 1.5.0_11 normalized as: 1.5.0-11 + OS Info: Arch: x86 Family: windows Name: windows xp Version: 5.1 ++---+ + + Sample Plugin Configuration: + ++---+ +<project> + [...] + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-enforcer-plugin</artifactId> + <executions> + <execution> + <id>enforce-java</id> + <goals> + <goal>enforce-once</goal> + </goals> + <configuration> + <rules> + <requireJavaVersion> + <version>1.5.0</version> + </requireJavaVersion> + </rules> + </configuration> + </execution> + </executions> + </plugin> + </plugins> + </build> + [...] +</project> ++---+ + \ No newline at end of file Added: maven/plugins/trunk/maven-enforcer-plugin/src/site/apt/rules/requireMavenVersion.apt URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-enforcer-plugin/src/site/apt/rules/requireMavenVersion.apt?view=auto&rev=523925 ============================================================================== --- maven/plugins/trunk/maven-enforcer-plugin/src/site/apt/rules/requireMavenVersion.apt (added) +++ maven/plugins/trunk/maven-enforcer-plugin/src/site/apt/rules/requireMavenVersion.apt Thu Mar 29 20:38:56 2007 @@ -0,0 +1,66 @@ +~~ Licensed to the Apache Software Foundation (ASF) under one +~~ or more contributor license agreements. See the NOTICE file +~~ distributed with this work for additional information +~~ regarding copyright ownership. The ASF licenses this file +~~ to you under the Apache License, Version 2.0 (the +~~ "License"); you may not use this file except in compliance +~~ with the License. You may obtain a copy of the License at +~~ +~~ http://www.apache.org/licenses/LICENSE-2.0 +~~ +~~ Unless required by applicable law or agreed to in writing, +~~ software distributed under the License is distributed on an +~~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +~~ KIND, either express or implied. See the License for the +~~ specific language governing permissions and limitations +~~ under the License. + + ------ + Require Maven Version + ------ + Brian Fox + ------ + Mar 2007 + ------ + +Require Maven Version + + This rule enforces certain Maven versions. The rule uses the {{{versionRanges.html}Enforcer version range syntax}} to define allowed versions. + + The following parameters are supported by this rule: + + * {{{../apidocs/org/apache/maven/plugin/enforcer/AbstractVersionEnforcer.html#version}version}} - {{{versionRanges.html}range}} of allowed Maven versions. + + [] + + Sample Plugin Configuration: + ++---+ +<project> + [...] + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-enforcer-plugin</artifactId> + <executions> + <execution> + <id>enforce-java</id> + <goals> + <goal>enforce-once</goal> + </goals> + <configuration> + <rules> + <requireMavenVersion> + <version>2.0.6</version> + </requireMavenVersion> + </rules> + </configuration> + </execution> + </executions> + </plugin> + </plugins> + </build> + [...] +</project> ++---+ \ No newline at end of file Added: maven/plugins/trunk/maven-enforcer-plugin/src/site/apt/rules/requireOS.apt URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-enforcer-plugin/src/site/apt/rules/requireOS.apt?view=auto&rev=523925 ============================================================================== --- maven/plugins/trunk/maven-enforcer-plugin/src/site/apt/rules/requireOS.apt (added) +++ maven/plugins/trunk/maven-enforcer-plugin/src/site/apt/rules/requireOS.apt Thu Mar 29 20:38:56 2007 @@ -0,0 +1,140 @@ +~~ Licensed to the Apache Software Foundation (ASF) under one +~~ or more contributor license agreements. See the NOTICE file +~~ distributed with this work for additional information +~~ regarding copyright ownership. The ASF licenses this file +~~ to you under the Apache License, Version 2.0 (the +~~ "License"); you may not use this file except in compliance +~~ with the License. You may obtain a copy of the License at +~~ +~~ http://www.apache.org/licenses/LICENSE-2.0 +~~ +~~ Unless required by applicable law or agreed to in writing, +~~ software distributed under the License is distributed on an +~~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +~~ KIND, either express or implied. See the License for the +~~ specific language governing permissions and limitations +~~ under the License. + + ------ + Require OS Version + ------ + Brian Fox + ------ + Mar 2007 + ------ + +Require OS Version + + This rule can enforce certain values about the Operating System and processor architecture. + The values and code used to determine if an OS is allowed are exactly the same as the OS Profile activation in Maven. + + + The following parameters are supported by this rule: + + * {{{../apidocs/org/apache/maven/plugin/enforcer/RequireOS.html#arch}arch}} - the cpu architecture. + + * {{{../apidocs/org/apache/maven/plugin/enforcer/RequireOS.html#family}family}} - the family of OS. Possible families are: + + * dos + + * mac + + * netware + + * os/2 + + * tandem + + * unix + + * windows + + * win9x + + * z/os + + * os/400 + + [] + + + * {{{../apidocs/org/apache/maven/plugin/enforcer/RequireOS.html#name}name}} - the name of the OS. + + * {{{../apidocs/org/apache/maven/plugin/enforcer/RequireOS.html#version}version}} - the version of the OS. + + * {{{../apidocs/org/apache/maven/plugin/enforcer/RequireOS.html#display}display}} - flag to display the detected OS informatin. + + [] + + + Family is calculated based on testing against the name string retreived from the JDK. The name, arch and version values are retreived from the JDK using the following code: + ++---+ + public static final String OS_NAME = System.getProperty( "os.name" ).toLowerCase( Locale.US ); + + public static final String OS_ARCH = System.getProperty( "os.arch" ).toLowerCase( Locale.US ); + + public static final String OS_VERSION = System.getProperty( "os.version" ).toLowerCase( Locale.US ); ++---+ + + Possible arch, name, and version values can be found here: + + * {{{http://lopica.sourceforge.net/os.html}lopica.sourceforge.net}} + + * {{{http://tolstoy.com/samizdat/sysprops.html}Sysprops}} + + [] + + The various options are considered to be "and'd" together but any number can be specified. + (ie family = windows means windows, but family = windows and arch = x86 means only windows on x86 processors) + + Any parameter may also be used in the negative by prepending a "!" in front of it. For example !dos means everything but dos. (who uses dos anyway?) + + Since the various names, versions and architecture values cannot be listed exhaustively, there is an easy way to display the + information for the current system: + ++---+ + mvn enforcer:display-info + ... + [enforcer:display-info] + Maven Version: 2.0.6 + JDK Version: 1.5.0_11 normalized as: 1.5.0 + OS Info: Arch: x86 Family: windows Name: windows xp Version: 5.1 ++---+ + + Sample Plugin Configuration: + ++---+ +<project> + [...] + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-enforcer-plugin</artifactId> + <executions> + <execution> + <id>enforce-os</id> + <goals> + <goal>os</goal> + </goals> + <configuration> + <rules> + <requireOS> + <name>Windows XP</name> + <family>Windows</family> + <arch>x86</arch> + <version>5.1.2600</version> + </requireOS> + </rules> + <fail>true</fail> + </configuration> + </execution> + </executions> + </plugin> + </plugins> + </build> + [...] +</project> ++---+ + \ No newline at end of file Added: maven/plugins/trunk/maven-enforcer-plugin/src/site/apt/rules/versionRanges.apt URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-enforcer-plugin/src/site/apt/rules/versionRanges.apt?view=auto&rev=523925 ============================================================================== --- maven/plugins/trunk/maven-enforcer-plugin/src/site/apt/rules/versionRanges.apt (added) +++ maven/plugins/trunk/maven-enforcer-plugin/src/site/apt/rules/versionRanges.apt Thu Mar 29 20:38:56 2007 @@ -0,0 +1,54 @@ +~~ Licensed to the Apache Software Foundation (ASF) under one +~~ or more contributor license agreements. See the NOTICE file +~~ distributed with this work for additional information +~~ regarding copyright ownership. The ASF licenses this file +~~ to you under the Apache License, Version 2.0 (the +~~ "License"); you may not use this file except in compliance +~~ with the License. You may obtain a copy of the License at +~~ +~~ http://www.apache.org/licenses/LICENSE-2.0 +~~ +~~ Unless required by applicable law or agreed to in writing, +~~ software distributed under the License is distributed on an +~~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +~~ KIND, either express or implied. See the License for the +~~ specific language governing permissions and limitations +~~ under the License. + + ------ + Version Range Specification + ------ + Brian Fox + ------ + Mar 2007 + ------ + +Version Range Specification + + The {{{requireMavenVersion.html}RequireMavenVersion}} and {{{requireJavaVersion.html}RequireJavaVersion}} rules use the {{{http://docs.codehaus.org/display/MAVEN/Dependency+Mediation+and+Conflict+Resolution#DependencyMediationandConflictResolution-DependencyVersionRanges}standard Maven version range syntax}} with one minor change for ease of use (denoted with *): + + +*----------*--------------+ +| Range | Meaning | +*----------*--------------+ +| 1.0 | x \>\= 1.0 \* The default Maven meaning for 1.0 is everything (,) but with 1.0 recommended. Obviously this doesn't work for enforcing versions here, so it has been redefined as a minimum version. + | +*----------*--------------+ +| (,1.0] | x \<\= 1.0 | +*----------*--------------+ +| (,1.0) | x \< 1.0 | +*----------*--------------+ +| [1.0] | x \=\= 1.0 | +*----------*--------------+ +| [1.0,) | x \>\= 1.0 | +*----------*--------------+ +| (1.0,) | x \> 1.0 | +*----------*--------------+ +| (1.0,2.0)| 1.0 \>\= x \<\= 2.0 | +*----------*--------------+ +| [1.0,2.0]| 1.0 \> x \< 2.0 | +*----------*--------------+ +| (,1.0],[1.2,) |x \<\= 1.0 or x \>\= 1.2. Multiple sets are comma-separated | +*----------*--------------+ +| (,1.1),(1.1,) |x !\= 1.1 | +*----------*--------------+ Modified: maven/plugins/trunk/maven-enforcer-plugin/src/site/apt/usage.apt URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-enforcer-plugin/src/site/apt/usage.apt?view=diff&rev=523925&r1=523924&r2=523925 ============================================================================== --- maven/plugins/trunk/maven-enforcer-plugin/src/site/apt/usage.apt (original) +++ maven/plugins/trunk/maven-enforcer-plugin/src/site/apt/usage.apt Thu Mar 29 20:38:56 2007 @@ -39,58 +39,28 @@ [] -* The <<<enforcer:enforce>>> mojo +* The <<<enforcer:enforce>>> and <<<enforcer:enforce-once>>> mojos - This goal is meant to be bound to a lifecycle phase and configured in your - <<<pom.xml>>>. This goal can enforce a specific range of allowed versions for Maven and the JDK. + These goals are meant to be bound to a lifecycle phase and configured in your + <<<pom.xml>>>. The enforcers execute the configured rules to check for certain constraints. + The available standard rules are described {{{rules/index.html}here}}. Besides the rules to execute, these goals support three options: - The standard Maven version range syntax is supported with one minor change for ease of use (denoted with *): + * {{{enforce-mojo.html#skip}skip}} - a quick way to skip checks via a profile or using -Denforcer.skip=true from the command line. - -*----------*--------------+ -| Range | Meaning | -*----------*--------------+ -| 1.0 | x \>\= 1.0 \* The default maven meaning for 1.0 is everything (,) but with 1.0 recommended. Obviously this doesn't work for enforcing versions here, so it has been redefined as a minimum version. - | -*----------*--------------+ -| (,1.0] | x \<\= 1.0 | -*----------*--------------+ -| (,1.0) | x \< 1.0 | -*----------*--------------+ -| [1.0] | x \=\= 1.0 | -*----------*--------------+ -| [1.0,) | x \>\= 1.0 | -*----------*--------------+ -| (1.0,) | x \> 1.0 | -*----------*--------------+ -| (1.0,2.0)| 1.0 \>\= x \<\= 2.0 | -*----------*--------------+ -| [1.0,2.0]| 1.0 \> x \< 2.0 | -*----------*--------------+ -| (,1.0],[1.2,) |x \<\= 1.0 or x \>\= 1.2. Multiple sets are comma-separated | -*----------*--------------+ -| (,1.1),(1.1,) |x !\= 1.1 | -*----------*--------------+ - - - The JDK version is retrieved and the following processing occurs before being checked: + * {{{enforce-mojo.html#fail}fail}} - if the goal should fail the build when a rule fails. The default is true. If false, the errors will be logged as warnings. - [[1]] Drop all non-numeric characters preceeding the first number. (build 1.5.0_11-b03 becomes 1.5.0_11-b03) - - [[2]] Replace all '_' and '-' with '.' (1.5.0_11-b03 becomes 1.5.0.11.b03) - - [[3]] Split the string on '.' and take the first 3 sections. (1.5.0.11.b03 becomes 1.5.0) - - [] + * {{{enforce-mojo.html#failFast}failFast}} - if the goal should stop checking after the first failure. The default is false. - This preprocessing normalizes various JDK version strings into a standard x.y.z version number. Your required range should therefore use the x.y.z format for comparison. - - To enforce only the Maven version, do not specify a JDK version and vice versa. At least one must be set. + [] - By default, the mojo will fail the build if a check does not succeed. If you would like a warning instead, set <<fail>> to false. + Each rule to be executed should be added to the rules element along with the specific configuration for that rule. + + The <<<enforce>>> goal executes against each project in a multi-project build. The <<<enforce-once>>> goal executes + just once per build. This is most effective for the standard rules because the Maven, Java and OS versions will not change between projects in the same build. + + + Sample Plugin Configuration: - Configure the plugin something like this if you intend to bind it to execute along with your build: - +---+ <project> [...] @@ -103,12 +73,20 @@ <execution> <id>enforce-versions</id> <goals> - <goal>enforce</goal> + <goal>enforce-once</goal> </goals> <configuration> - <mavenVersion>2.0.6</mavenVersion> - <jdkVersion>1.5.0</jdkVersion> - <fail>true</fail> + <rules> + <requireMavenVersion> + <version>2.0.6</version> + </requireMavenVesion> + <requireJavaVersion> + <version>1.5</version> + </requireJavaVersion> + <requireOS> + <family>unix</family> + </requireOS> + </rules> </configuration> </execution> </executions> @@ -119,90 +97,16 @@ </project> +---+ - * The <<<enforcer:os>>> mojo - - This goal can enforce certain values about the Operating System and processor architecture. - The values and code used to determine if an OS is allowed is exactly the same as the OS Profile activation. - - There are several values that can be specified: family, name, version and arch(itecture). Family is calculated based on testing - against the name string retreived from the JDK. The values are retreived from the JDK using the following code: - -+---+ - public static final String OS_NAME = System.getProperty( "os.name" ).toLowerCase( Locale.US ); +* The <<<enforcer:display-info>>> mojo - public static final String OS_ARCH = System.getProperty( "os.arch" ).toLowerCase( Locale.US ); - - public static final String OS_VERSION = System.getProperty( "os.version" ).toLowerCase( Locale.US ); -+---+ - - Possible Family values are: - - * dos - - * mac - - * netware - - * os/2 - - * tandem - - * unix - - * windows - - * win9x - - * z/os - - * os/400 - - [] + This goal is used to determine the current information as detected by the standard rules: - The various options are considered to be "and'd" together but any number can be specified. - (ie family = windows means windows, but family = windows and arch = x86 means only windows on x86 processors) - - Any parameter may also be used in the negative by prepending a "!" in front of it. For example !dos means everything but dos. (who uses dos anyway?) - - Since the various names, versions and architecture values cannot be listed exhaustively, there is an easy way to display the - information for the current system: - +---+ - mvn enforcer:os -Denforcer.os.display=true + mvn enforcer:display-info ... - [enforcer:os] - OS Info: Arch: x86 Family: windows Name: windows xp Version: 5.1 -+---+ - - Sample POM configuration: - -+---+ -<project> - [...] - <build> - <plugins> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-enforcer-plugin</artifactId> - <executions> - <execution> - <id>enforce-os</id> - <goals> - <goal>os</goal> - </goals> - <configuration> - <name>Windows XP</name> - <family>Windows</family> - <arch>x86</arch> - <version>5.1.2600</version> - <fail>true</fail> - </configuration> - </execution> - </executions> - </plugin> - </plugins> - </build> - [...] -</project> + [enforcer:display-info] + Maven Version: 2.0.6 + JDK Version: 1.5.0_11 normalized as: 1.5.0-11 + OS Info: Arch: x86 Family: windows Name: windows xp Version: 5.1 +---+ Modified: maven/plugins/trunk/maven-enforcer-plugin/src/site/site.xml URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-enforcer-plugin/src/site/site.xml?view=diff&rev=523925&r1=523924&r2=523925 ============================================================================== --- maven/plugins/trunk/maven-enforcer-plugin/src/site/site.xml (original) +++ maven/plugins/trunk/maven-enforcer-plugin/src/site/site.xml Thu Mar 29 20:38:56 2007 @@ -27,6 +27,13 @@ <item name="Usage" href="usage.html"/> <item name="FAQ" href="faq.html"/> </menu> + <menu name="Standard Rules"> + <item name="Overview" href="rules/index.html"/> + <item name="RequireJavaVersion" href="rules/requireJavaVersion.html"/> + <item name="RequireMavenVersion" href="rules/requireMavenVersion.html"/> + <item name="RequireOS" href="rules/requireOS.html"/> + <item name="Version Range Specification" href="rules/versionRanges.html"/> + </menu> <menu name="Resources"> <item name="Maven 2.0.x Version Range Syntax" href="http://docs.codehaus.org/display/MAVEN/Dependency+Mediation+and+Conflict+Resolution#DependencyMediationandConflictResolution-DependencyVersionRanges" /> </menu> Modified: maven/plugins/trunk/maven-enforcer-plugin/src/test/java/org/apache/maven/plugin/enforcer/MockPlexusContainer.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-enforcer-plugin/src/test/java/org/apache/maven/plugin/enforcer/MockPlexusContainer.java?view=diff&rev=523925&r1=523924&r2=523925 ============================================================================== --- maven/plugins/trunk/maven-enforcer-plugin/src/test/java/org/apache/maven/plugin/enforcer/MockPlexusContainer.java (original) +++ maven/plugins/trunk/maven-enforcer-plugin/src/test/java/org/apache/maven/plugin/enforcer/MockPlexusContainer.java Thu Mar 29 20:38:56 2007 @@ -55,6 +55,26 @@ /* * (non-Javadoc) * + * @see org.codehaus.plexus.PlexusContainer#lookup(java.lang.String) + */ + public Object lookup( String theComponentKey ) + throws ComponentLookupException + { + if ( theComponentKey.equals( MavenProject.class.getName() ) ) + { + return new MavenProject(); + } + else if ( theComponentKey.equals( RuntimeInformation.class.getName() ) ) + { + return new MockRuntimeInformation(); + } + + return null; + } + + /* + * (non-Javadoc) + * * @see org.codehaus.plexus.PlexusContainer#addComponentDescriptor(org.codehaus.plexus.component.repository.ComponentDescriptor) */ public void addComponentDescriptor( ComponentDescriptor theComponentDescriptor ) @@ -338,26 +358,6 @@ { // TODO Auto-generated method stub return false; - } - - /* - * (non-Javadoc) - * - * @see org.codehaus.plexus.PlexusContainer#lookup(java.lang.String) - */ - public Object lookup( String theComponentKey ) - throws ComponentLookupException - { - if ( theComponentKey.equals( MavenProject.class.getName() ) ) - { - return new MavenProject(); - } - else if ( theComponentKey.equals( RuntimeInformation.class.getName() ) ) - { - return new DefaultRuntimeInformation(); - } - - return null; } /* Modified: maven/plugins/trunk/maven-enforcer-plugin/src/test/java/org/apache/maven/plugin/enforcer/TestMavenVersion.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-enforcer-plugin/src/test/java/org/apache/maven/plugin/enforcer/TestMavenVersion.java?view=diff&rev=523925&r1=523924&r2=523925 ============================================================================== --- maven/plugins/trunk/maven-enforcer-plugin/src/test/java/org/apache/maven/plugin/enforcer/TestMavenVersion.java (original) +++ maven/plugins/trunk/maven-enforcer-plugin/src/test/java/org/apache/maven/plugin/enforcer/TestMavenVersion.java Thu Mar 29 20:38:56 2007 @@ -34,37 +34,34 @@ extends TestCase { public void testRule() - throws EnforcerRuleException -{ - - - String thisVersion = RequireJavaVersion.fixJDKVersion( SystemUtils.JAVA_VERSION_TRIMMED ); + throws EnforcerRuleException + { + + RequireMavenVersion rule = new RequireMavenVersion(); + rule.setVersion( "2.0.5" ); - RequireJavaVersion rule = new RequireJavaVersion(); - rule.setVersion( thisVersion ); + EnforcerRuleHelper helper = new DefaultEnforcementRuleHelper( EnforcerTestUtils.getMavenSession(), + new SystemStreamLog() ); - EnforcerRuleHelper helper = new DefaultEnforcementRuleHelper( EnforcerTestUtils.getMavenSession(), - new SystemStreamLog() ); + // test the singular version + rule.execute( helper ); - // test the singular version - rule.execute( helper ); + // exclude this version + rule.setVersion( "(2.0.5" ); - // exclude this version - rule.setVersion( "(" + thisVersion ); + try + { + rule.execute( helper ); + fail( "Expected an exception." ); + } + catch ( EnforcerRuleException e ) + { + // expected to catch this. + } - try - { + // this shouldn't crash + rule.setVersion( SystemUtils.JAVA_VERSION_TRIMMED ); rule.execute( helper ); - fail( "Expected an exception." ); - } - catch ( EnforcerRuleException e ) - { - // expected to catch this. - } - - //this shouldn't crash - rule.setVersion( SystemUtils.JAVA_VERSION_TRIMMED ); - rule.execute( helper ); -} + } } Modified: maven/plugins/trunk/maven-enforcer-plugin/src/test/java/org/apache/maven/plugin/enforcer/TestRequireJavaVersion.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-enforcer-plugin/src/test/java/org/apache/maven/plugin/enforcer/TestRequireJavaVersion.java?view=diff&rev=523925&r1=523924&r2=523925 ============================================================================== --- maven/plugins/trunk/maven-enforcer-plugin/src/test/java/org/apache/maven/plugin/enforcer/TestRequireJavaVersion.java (original) +++ maven/plugins/trunk/maven-enforcer-plugin/src/test/java/org/apache/maven/plugin/enforcer/TestRequireJavaVersion.java Thu Mar 29 20:38:56 2007 @@ -36,17 +36,17 @@ public void testFixJDKVersion() { // test that we only take the first 3 versions for comparision - assertEquals( "1.5.0", RequireJavaVersion.fixJDKVersion( "1.5.0-11" ) ); + assertEquals( "1.5.0-11", RequireJavaVersion.fixJDKVersion( "1.5.0_11" ) ); assertEquals( "1.5.1", RequireJavaVersion.fixJDKVersion( "1.5.1" ) ); - assertEquals( "1.5.2", RequireJavaVersion.fixJDKVersion( "1.5.2-b11" ) ); - assertEquals( "1.5.3", RequireJavaVersion.fixJDKVersion( "1.5.3_11" ) ); - assertEquals( "1.5.4", RequireJavaVersion.fixJDKVersion( "1.5.4.5_11" ) ); - assertEquals( "1.5.5", RequireJavaVersion.fixJDKVersion( "1.5.5.6_11.2" ) ); + assertEquals( "1.5.2-1", RequireJavaVersion.fixJDKVersion( "1.5.2-1.b11" ) ); + assertEquals( "1.5.3-11", RequireJavaVersion.fixJDKVersion( "1.5.3_11" ) ); + assertEquals( "1.5.4-5", RequireJavaVersion.fixJDKVersion( "1.5.4.5_11" ) ); + assertEquals( "1.5.5-6", RequireJavaVersion.fixJDKVersion( "1.5.5.6_11.2" ) ); // test for non-standard versions - assertEquals( "1.5.0", RequireJavaVersion.fixJDKVersion( "1-5-0-11" ) ); - assertEquals( "1.5.0", RequireJavaVersion.fixJDKVersion( "1-_5-_0-_11" ) ); - assertEquals( "1.5.0", RequireJavaVersion.fixJDKVersion( "1_5_0_11" ) ); + assertEquals( "1.5.0-11", RequireJavaVersion.fixJDKVersion( "1-5-0-11" ) ); + assertEquals( "1.5.0-11", RequireJavaVersion.fixJDKVersion( "1-_5-_0-_11" ) ); + assertEquals( "1.5.0-11", RequireJavaVersion.fixJDKVersion( "1_5_0_11" ) ); } public void testRule()