Author: brianf Date: Fri Mar 30 20:05:08 2007 New Revision: 524357 URL: http://svn.apache.org/viewvc?view=rev&rev=524357 Log: added site
Added: maven/shared/trunk/maven-enforcer-rule-api/src/site/ maven/shared/trunk/maven-enforcer-rule-api/src/site/apt/ maven/shared/trunk/maven-enforcer-rule-api/src/site/apt/index.apt maven/shared/trunk/maven-enforcer-rule-api/src/site/apt/writing-a-custom-rule.apt maven/shared/trunk/maven-enforcer-rule-api/src/site/site.xml Modified: maven/shared/trunk/maven-enforcer-rule-api/ (props changed) maven/shared/trunk/maven-enforcer-rule-api/pom.xml Propchange: maven/shared/trunk/maven-enforcer-rule-api/ ------------------------------------------------------------------------------ --- svn:ignore (added) +++ svn:ignore Fri Mar 30 20:05:08 2007 @@ -0,0 +1 @@ +target Modified: maven/shared/trunk/maven-enforcer-rule-api/pom.xml URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-enforcer-rule-api/pom.xml?view=diff&rev=524357&r1=524356&r2=524357 ============================================================================== --- maven/shared/trunk/maven-enforcer-rule-api/pom.xml (original) +++ maven/shared/trunk/maven-enforcer-rule-api/pom.xml Fri Mar 30 20:05:08 2007 @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="UTF-8"?> - <!-- +<!-- * 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 @@ -19,41 +19,55 @@ * --> <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> - <groupId>org.apache.maven.shared</groupId> - <artifactId>maven-shared-components</artifactId> - <version>7</version> - </parent> - <groupId>org.apache.maven.shared</groupId> - <artifactId>maven-enforcer-rule-api</artifactId> - <packaging>jar</packaging> - <version>1.0-alpha-1-SNAPSHOT</version> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.apache.maven.shared</groupId> + <artifactId>maven-shared-components</artifactId> + <version>7</version> + </parent> + <groupId>org.apache.maven.shared</groupId> + <artifactId>maven-enforcer-rule-api</artifactId> + <packaging>jar</packaging> + <version>1.0-alpha-1-SNAPSHOT</version> - <name>Maven Enforcer Rule API</name> - <description>This component provides the generic interfaces needed to implement custom -rules for the maven-enforcer-plugin.</description> - <build> - <plugins> - <plugin> - <artifactId>maven-compiler-plugin</artifactId> - <configuration> - <source>1.4</source> - <target>1.4</target> - </configuration> - </plugin> - <plugin> - <groupId>org.codehaus.plexus</groupId> - <artifactId>plexus-maven-plugin</artifactId> - <executions> - <execution> - <goals> - <goal>descriptor</goal> - </goals> - </execution> - </executions> - </plugin> - </plugins> + <name>Maven Enforcer Rule API</name> + <description>This component provides the generic interfaces needed to implement custom rules for the maven-enforcer-plugin.</description> + <issueManagement> + <system>JIRA</system> + <url>http://jira.codehaus.org/browse/MENFORCER</url> + </issueManagement> + <developers> + <developer> + <id>brianf</id> + <name>Brian Fox</name> + <email>[EMAIL PROTECTED]</email> + <roles> + <role>Lead Developer</role> + </roles> + <timezone>5</timezone> + </developer> + </developers> + <build> + <plugins> + <plugin> + <artifactId>maven-compiler-plugin</artifactId> + <configuration> + <source>1.4</source> + <target>1.4</target> + </configuration> + </plugin> + <plugin> + <groupId>org.codehaus.plexus</groupId> + <artifactId>plexus-maven-plugin</artifactId> + <executions> + <execution> + <goals> + <goal>descriptor</goal> + </goals> + </execution> + </executions> + </plugin> + </plugins> <resources> <!-- Include super-pom defined main/resources Removing this section will break the build. @@ -65,34 +79,33 @@ <directory>${basedir}/src/main/resources</directory> </resource> </resources> - </build> - - <dependencies> - <dependency> - <groupId>org.apache.maven</groupId> - <artifactId>maven-project</artifactId> - <version>2.0.5</version> - </dependency> - <dependency> - <groupId>org.apache.maven</groupId> - <artifactId>maven-core</artifactId> - <version>2.0.5</version> - </dependency> - <dependency> - <groupId>org.apache.maven</groupId> - <artifactId>maven-plugin-api</artifactId> - <version>2.0.5</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> + </build> + <dependencies> + <dependency> + <groupId>org.apache.maven</groupId> + <artifactId>maven-project</artifactId> + <version>2.0.5</version> + </dependency> + <dependency> + <groupId>org.apache.maven</groupId> + <artifactId>maven-core</artifactId> + <version>2.0.5</version> + </dependency> + <dependency> + <groupId>org.apache.maven</groupId> + <artifactId>maven-plugin-api</artifactId> + <version>2.0.5</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> Added: maven/shared/trunk/maven-enforcer-rule-api/src/site/apt/index.apt URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-enforcer-rule-api/src/site/apt/index.apt?view=auto&rev=524357 ============================================================================== --- maven/shared/trunk/maven-enforcer-rule-api/src/site/apt/index.apt (added) +++ maven/shared/trunk/maven-enforcer-rule-api/src/site/apt/index.apt Fri Mar 30 20:05:08 2007 @@ -0,0 +1,32 @@ +~~ 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. + + ------ + Introduction + ------ + Brian Fox + ------ + Mar 2007 + ------ + +Maven Enforcer Rule API - Extending The Loving Iron Fist of Maven\x99 + + Custom rules are easy to make with the <<<maven-enforcer-rule-api>>>. These rules can then be invoked with the + {{{http://maven.apache.org/plugins/maven-enforcer-plugin}maven-enforcer-plugin}}. + + See {{{writing-a-custom-rule.html}here}} for instructions on how to make your own rule. + \ No newline at end of file Added: maven/shared/trunk/maven-enforcer-rule-api/src/site/apt/writing-a-custom-rule.apt URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-enforcer-rule-api/src/site/apt/writing-a-custom-rule.apt?view=auto&rev=524357 ============================================================================== --- maven/shared/trunk/maven-enforcer-rule-api/src/site/apt/writing-a-custom-rule.apt (added) +++ maven/shared/trunk/maven-enforcer-rule-api/src/site/apt/writing-a-custom-rule.apt Fri Mar 30 20:05:08 2007 @@ -0,0 +1,225 @@ +~~ 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. + + ------ + Writing a custom rule + ------ + Brian Fox + ------ + Mar 2007 + ------ + +Writing a custom rule + + Custom rules are easy to make with the <<<maven-enforcer-rule-api>>>. These rules can then be invoked with the + {{{http://maven.apache.org/plugins/maven-enforcer-plugin}maven-enforcer-plugin}}. + + [[1]] First make a new jar project starting with the sample pom below: + ++---+ +<?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> + <groupId>your.group</groupId> + <artifactId>custom-rule</artifactId> + <packaging>jar</packaging> + <version>1.0</version> + <name>My Custom Rule</name> + <description>This is my custom rule.</description> + <build> + </build> + <dependencies> + <dependency> + <groupId>org.apache.maven.shared</groupId> + <artifactId>maven-enforcer-rule-api</artifactId> + <version>1.0-alpha-1</version> + </dependency> + <dependency> + <groupId>org.apache.maven</groupId> + <artifactId>maven-project</artifactId> + <version>2.0.5</version> + </dependency> + <dependency> + <groupId>org.apache.maven</groupId> + <artifactId>maven-core</artifactId> + <version>2.0.5</version> + </dependency> + <dependency> + <groupId>org.apache.maven</groupId> + <artifactId>maven-artifact</artifactId> + <version>2.0.5</version> + </dependency> + <dependency> + <groupId>org.apache.maven</groupId> + <artifactId>maven-plugin-api</artifactId> + <version>2.0.5</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> ++---+ + + [[2]] Create your rule class. The rule must implement the {{{apidocs/index.html}EnforcerRule}} interface. + The rule can get access to components and the log via the {{{apidocs/index.html}EnforcerRuleHelper}} interface. + If the rule succeeds, it should just simply return. If the rule fails, it should throw an {{{apidocs/index.html}EnforcerRuleException}} with a descriptive message telling the user why the rule failed. + + Here's a sample class that shows how to access the helper methods and retreive components by class name from the helper: + ++---+ +package org.apache.maven.shared.rule; + +import org.apache.maven.artifact.resolver.ArtifactResolver; +import org.apache.maven.execution.MavenSession; +import org.apache.maven.execution.RuntimeInformation; +import org.apache.maven.plugin.logging.Log; +import org.apache.maven.project.MavenProject; +import org.apache.maven.shared.enforcer.rule.api.EnforcerRule; +import org.apache.maven.shared.enforcer.rule.api.EnforcerRuleException; +import org.apache.maven.shared.enforcer.rule.api.EnforcerRuleHelper; +import org.codehaus.plexus.component.repository.exception.ComponentLookupException; + +/** + * @author <a href="mailto:[EMAIL PROTECTED]">Brian Fox</a> + */ +public class myCustomRule + implements EnforcerRule +{ + /** + * Simple param. This rule will fail if the value is true. + */ + private boolean shouldIfail = false; + + public void execute( EnforcerRuleHelper helper ) + throws EnforcerRuleException + { + Log log = helper.getLog(); + + try + { + // get the various components out of the helper. + MavenProject project = helper.getProject(); + RuntimeInformation rti = helper.getRuntimeInformation(); + MavenSession session = helper.getSession(); + + // retreive any component out of the session directly + ArtifactResolver resolver = (ArtifactResolver) helper.getComponent( ArtifactResolver.class ); + + log.info( "Retrieved Project: " + project ); + log.info( "Retrieved RuntimeInfo: " + rti ); + log.info( "Retrieved Session: " + session ); + log.info( "Retrieved Resolver: " + resolver ); + + if (this.shouldIfail) + { + throw new EnforcerRuleException("Failing because my param said so."); + } + } + catch ( ComponentLookupException e ) + { + throw new EnforcerRuleException("Unable to lookup a component",e); + } + } +} ++---+ + + [[3]] Build and Install or Deploy your custom rule. + + [[4]] Add your custom-rule artifact as a dependency of the <<<maven-enforcer-plugin>>> in your build: + ++---+ +<project> + ... + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-enforcer-plugin</artifactId> + <dependencies> + <dependency> + <groupId>your.group</groupId> + <artifactId>custom-rule</artifactId> + <version>1.0</version> + </dependency> + </dependencies> + ... + </plugin> + </plugins> + </build> + ... +</project> ++---+ + + [[5]] Add your rule to the configuration section of the <<<maven-enforcer-plugin>>>. The name of your class will be the name of the rule, and + you must add an <<<implementation>>> hint that contains the fully qualified class name: + ++---+ +<configuration> + <rules> + <myCustomRule implementation="org.apache.maven.shared.rule.myCustomRule"> + <shouldIfail>true</shouldIfail> + </myCustomRule> + </rules> +</configuration> ++---+ + + [[6]] That's it. The full plugin config may look like this: + ++---+ +<plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-enforcer-plugin</artifactId> + <dependencies> + <dependency> + <groupId>your.group</groupId> + <artifactId>custom-rule</artifactId> + <version>1.0</version> + </dependency> + </dependencies> + <executions> + <execution> + <id>enforce</id> + <configuration> + <rules> + <requireJavaVersion> + <version>[1.3,1.6]</version> + </requireJavaVersion> + <requireMavenVersion> + <version>2.0.6</version> + </requireMavenVersion> + <myCustomRule implementation="org.apache.maven.shared.rule.myCustomRule"> + <shouldIfail>true</shouldIfail> + </myCustomRule> + </rules> + </configuration> + <goals> + <goal>enforce-once</goal> + </goals> + </execution> + </executions> +</plugin> ++---+ \ No newline at end of file Added: maven/shared/trunk/maven-enforcer-rule-api/src/site/site.xml URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-enforcer-rule-api/src/site/site.xml?view=auto&rev=524357 ============================================================================== --- maven/shared/trunk/maven-enforcer-rule-api/src/site/site.xml (added) +++ maven/shared/trunk/maven-enforcer-rule-api/src/site/site.xml Fri Mar 30 20:05:08 2007 @@ -0,0 +1,29 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<!-- + * 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. + * +--> + +<project> + <body> + <menu name="Overview"> + <item name="Introduction" href="index.html"/> + <item name="Writing a custom rule" href="writing-a-custom-rule.html"/> + </menu> + </body> +</project>