Author: hboutemy Date: Thu Nov 6 23:18:33 2014 New Revision: 1637265 URL: http://svn.apache.org/r1637265 Log: created a sample plugin using the custom toolchain
Added: maven/plugins/trunk/maven-toolchains-plugin/src/it/custom-toolchain-plugin/ - copied from r1636475, maven/plugins/trunk/maven-toolchains-plugin/src/it/custom-toolchain/ maven/plugins/trunk/maven-toolchains-plugin/src/it/custom-toolchain-plugin/src/main/java/org/apache/maven/plugins/toolchains/its/custom/CustomMojo.java (with props) maven/plugins/trunk/maven-toolchains-plugin/src/it/custom-toolchain-plugin/src/main/java/org/apache/maven/plugins/toolchains/its/custom/CustomToolchainFactory.java - copied, changed from r1636790, maven/plugins/trunk/maven-toolchains-plugin/src/it/custom-toolchain/src/main/java/org/apache/maven/plugins/toolchains/its/custom/CustomToolchainFactory.java maven/plugins/trunk/maven-toolchains-plugin/src/it/use-custom-toolchain/opt/ maven/plugins/trunk/maven-toolchains-plugin/src/it/use-custom-toolchain/opt/custom/ maven/plugins/trunk/maven-toolchains-plugin/src/it/use-custom-toolchain/opt/custom/1.5/ maven/plugins/trunk/maven-toolchains-plugin/src/it/use-custom-toolchain/opt/custom/1.5/bin/ maven/plugins/trunk/maven-toolchains-plugin/src/it/use-custom-toolchain/opt/custom/1.5/bin/tool maven/plugins/trunk/maven-toolchains-plugin/src/it/use-custom-toolchain/opt/custom/1.5/bin/tool.exe (with props) maven/plugins/trunk/maven-toolchains-plugin/src/it/use-custom-toolchain/opt/custom/2.0/ maven/plugins/trunk/maven-toolchains-plugin/src/it/use-custom-toolchain/opt/custom/2.0/bin/ maven/plugins/trunk/maven-toolchains-plugin/src/it/use-custom-toolchain/opt/custom/2.0/bin/tool maven/plugins/trunk/maven-toolchains-plugin/src/it/use-custom-toolchain/opt/custom/2.0/bin/tool.exe (with props) maven/plugins/trunk/maven-toolchains-plugin/src/it/use-custom-toolchain/verify.groovy (with props) Removed: maven/plugins/trunk/maven-toolchains-plugin/src/it/custom-toolchain/ maven/plugins/trunk/maven-toolchains-plugin/src/it/custom-toolchain-plugin/src/main/java/org/apache/maven/plugins/toolchains/its/custom/DefaultCustomToolchainFactory.java Modified: maven/plugins/trunk/maven-toolchains-plugin/src/it/custom-toolchain-plugin/pom.xml maven/plugins/trunk/maven-toolchains-plugin/src/it/custom-toolchain-plugin/src/main/java/org/apache/maven/plugins/toolchains/its/custom/DefaultCustomToolchain.java maven/plugins/trunk/maven-toolchains-plugin/src/it/toolchains.xml maven/plugins/trunk/maven-toolchains-plugin/src/it/use-custom-toolchain/invoker.properties maven/plugins/trunk/maven-toolchains-plugin/src/it/use-custom-toolchain/pom.xml Modified: maven/plugins/trunk/maven-toolchains-plugin/src/it/custom-toolchain-plugin/pom.xml URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-toolchains-plugin/src/it/custom-toolchain-plugin/pom.xml?rev=1637265&r1=1636475&r2=1637265&view=diff ============================================================================== --- maven/plugins/trunk/maven-toolchains-plugin/src/it/custom-toolchain-plugin/pom.xml (original) +++ maven/plugins/trunk/maven-toolchains-plugin/src/it/custom-toolchain-plugin/pom.xml Thu Nov 6 23:18:33 2014 @@ -24,21 +24,48 @@ under the License. <modelVersion>4.0.0</modelVersion> <groupId>org.apache.maven.plugins.toolchains.its</groupId> - <artifactId>custom-toolchain</artifactId> + <artifactId>custom-toolchain-plugin</artifactId> <version>1.0-SNAPSHOT</version> - <packaging>jar</packaging> + <packaging>maven-plugin</packaging> - <name>maven-toolchains-plugin IT: demo toolchain</name> + <name>maven-toolchains-plugin IT: custom toolchain + plugin using it</name> <description> - Demo to show how to write a custom toolchain type + Demo to show how to write a custom toolchain type, a plugin using this custom toolchain, + to later write a project that uses the toolchain and plugin. </description> <dependencies> + <!-- toolchains API --> <dependency> <groupId>org.apache.maven</groupId> <artifactId>maven-core</artifactId> <version>3.0.5</version> </dependency> + <dependency> + <groupId>org.codehaus.plexus</groupId> + <artifactId>plexus-component-annotations</artifactId> + <version>1.5.5</version> + <scope>provided</scope> + </dependency> + + <!-- plugin API and plugin-tools --> + <dependency> + <groupId>org.apache.maven</groupId> + <artifactId>maven-plugin-api</artifactId> + <version>3.0.5</version> + </dependency> + <dependency> + <groupId>org.apache.maven.plugin-tools</groupId> + <artifactId>maven-plugin-annotations</artifactId> + <version>3.3</version> + <scope>provided</scope> + </dependency> + + <dependency> + <groupId>org.codehaus.plexus</groupId> + <artifactId>plexus-utils</artifactId> + <version>3.0.15</version> + </dependency> </dependencies> <build> @@ -59,6 +86,26 @@ under the License. </execution> </executions> </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-plugin-plugin</artifactId> + <version>3.3</version> + <executions> + <execution> + <id>default-descriptor</id> + <phase>process-classes</phase> + </execution> + <execution> + <id>generated-helpmojo</id> + <goals> + <goal>helpmojo</goal> + </goals> + <configuration><!-- TODO: remove when upgrading plugin-tools to 3.4: see MPLUGIN-238 --> + <skipErrorNoDescriptorsFound>true</skipErrorNoDescriptorsFound> + </configuration> + </execution> + </executions> + </plugin> </plugins> </build> </project> Added: maven/plugins/trunk/maven-toolchains-plugin/src/it/custom-toolchain-plugin/src/main/java/org/apache/maven/plugins/toolchains/its/custom/CustomMojo.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-toolchains-plugin/src/it/custom-toolchain-plugin/src/main/java/org/apache/maven/plugins/toolchains/its/custom/CustomMojo.java?rev=1637265&view=auto ============================================================================== --- maven/plugins/trunk/maven-toolchains-plugin/src/it/custom-toolchain-plugin/src/main/java/org/apache/maven/plugins/toolchains/its/custom/CustomMojo.java (added) +++ maven/plugins/trunk/maven-toolchains-plugin/src/it/custom-toolchain-plugin/src/main/java/org/apache/maven/plugins/toolchains/its/custom/CustomMojo.java Thu Nov 6 23:18:33 2014 @@ -0,0 +1,64 @@ +package org.apache.maven.plugins.toolchains.its.custom; + +/* + * 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.maven.execution.MavenSession; +import org.apache.maven.plugin.AbstractMojo; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugins.annotations.Component; +import org.apache.maven.plugins.annotations.Mojo; +import org.apache.maven.plugins.annotations.Parameter; +import org.apache.maven.toolchain.ToolchainManager; + +/** + * A sample Mojo that uses the custom toolchain. + * + * @author Hervé Boutemy + */ +@Mojo( name = "tool" ) +public class CustomMojo + extends AbstractMojo +{ + + @Component + private ToolchainManager toolchainManager; + + @Parameter( defaultValue = "${session}", required = true, readonly = true ) + private MavenSession session; + + public void execute() + throws MojoExecutionException + { + // get the custom toolchain + CustomToolchain toolchain = (CustomToolchain) toolchainManager.getToolchainFromBuildContext( "custom", session ); + + if ( toolchain == null ) + { + throw new MojoExecutionException( "Could not find 'custom' toolchain: please check maven-toolchains-plugin configuration." ); + } + + getLog().info( "Found 'custom' toolchain in build context." ); + + // get a tool from the toolchain + String path = toolchain.findTool( "tool" ); + + getLog().info( "Found expected tool named 'tool' at following location: " + path ); + } +} \ No newline at end of file Propchange: maven/plugins/trunk/maven-toolchains-plugin/src/it/custom-toolchain-plugin/src/main/java/org/apache/maven/plugins/toolchains/its/custom/CustomMojo.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: maven/plugins/trunk/maven-toolchains-plugin/src/it/custom-toolchain-plugin/src/main/java/org/apache/maven/plugins/toolchains/its/custom/CustomMojo.java ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision Propchange: maven/plugins/trunk/maven-toolchains-plugin/src/it/custom-toolchain-plugin/src/main/java/org/apache/maven/plugins/toolchains/its/custom/CustomMojo.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Copied: maven/plugins/trunk/maven-toolchains-plugin/src/it/custom-toolchain-plugin/src/main/java/org/apache/maven/plugins/toolchains/its/custom/CustomToolchainFactory.java (from r1636790, maven/plugins/trunk/maven-toolchains-plugin/src/it/custom-toolchain/src/main/java/org/apache/maven/plugins/toolchains/its/custom/CustomToolchainFactory.java) URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-toolchains-plugin/src/it/custom-toolchain-plugin/src/main/java/org/apache/maven/plugins/toolchains/its/custom/CustomToolchainFactory.java?p2=maven/plugins/trunk/maven-toolchains-plugin/src/it/custom-toolchain-plugin/src/main/java/org/apache/maven/plugins/toolchains/its/custom/CustomToolchainFactory.java&p1=maven/plugins/trunk/maven-toolchains-plugin/src/it/custom-toolchain/src/main/java/org/apache/maven/plugins/toolchains/its/custom/CustomToolchainFactory.java&r1=1636790&r2=1637265&rev=1637265&view=diff ============================================================================== --- maven/plugins/trunk/maven-toolchains-plugin/src/it/custom-toolchain/src/main/java/org/apache/maven/plugins/toolchains/its/custom/CustomToolchainFactory.java (original) +++ maven/plugins/trunk/maven-toolchains-plugin/src/it/custom-toolchain-plugin/src/main/java/org/apache/maven/plugins/toolchains/its/custom/CustomToolchainFactory.java Thu Nov 6 23:18:33 2014 @@ -97,17 +97,13 @@ public class CustomToolchainFactory + DefaultCustomToolchain.KEY_TOOLHOME + " configuration element." ); } - File normal = new File( FileUtils.normalize( toolHome ) ); - if ( normal.exists() ) - { - customToolchain.setToolHome( FileUtils.normalize( toolHome ) ); - } - else + toolHome = FileUtils.normalize( toolHome ); + customToolchain.setToolHome( toolHome ); + + if ( !new File( toolHome ).exists() ) { - // for this IT, don't really check the toolHome directory exists... - // throw new MisconfiguredToolchainException( "Non-existing tool home configuration at " - // + normal.getAbsolutePath() ); - customToolchain.setToolHome( FileUtils.normalize( toolHome ) ); + throw new MisconfiguredToolchainException( "Non-existing tool home configuration at " + + new File( toolHome ).getAbsolutePath() ); } return customToolchain; Modified: maven/plugins/trunk/maven-toolchains-plugin/src/it/custom-toolchain-plugin/src/main/java/org/apache/maven/plugins/toolchains/its/custom/DefaultCustomToolchain.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-toolchains-plugin/src/it/custom-toolchain-plugin/src/main/java/org/apache/maven/plugins/toolchains/its/custom/DefaultCustomToolchain.java?rev=1637265&r1=1636475&r2=1637265&view=diff ============================================================================== --- maven/plugins/trunk/maven-toolchains-plugin/src/it/custom-toolchain-plugin/src/main/java/org/apache/maven/plugins/toolchains/its/custom/DefaultCustomToolchain.java (original) +++ maven/plugins/trunk/maven-toolchains-plugin/src/it/custom-toolchain-plugin/src/main/java/org/apache/maven/plugins/toolchains/its/custom/DefaultCustomToolchain.java Thu Nov 6 23:18:33 2014 @@ -61,25 +61,30 @@ public class DefaultCustomToolchain public String findTool( String toolName ) { - File toRet = findTool( toolName, new File( FileUtils.normalize( getToolHome() ) ) ); - if ( toRet != null ) + File tool = findTool( toolName, new File( getToolHome() ) ); + + if ( tool != null ) { - return toRet.getAbsolutePath(); + return tool.getAbsolutePath(); } + return null; } private static File findTool( String toolName, File installFolder ) { File bin = new File( installFolder, "bin" ); //NOI18N + if ( bin.exists() ) { File tool = new File( bin, toolName + ( Os.isFamily( "windows" ) ? ".exe" : "" ) ); // NOI18N + if ( tool.exists() ) { return tool; } } + return null; } } \ No newline at end of file Modified: maven/plugins/trunk/maven-toolchains-plugin/src/it/toolchains.xml URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-toolchains-plugin/src/it/toolchains.xml?rev=1637265&r1=1637264&r2=1637265&view=diff ============================================================================== --- maven/plugins/trunk/maven-toolchains-plugin/src/it/toolchains.xml (original) +++ maven/plugins/trunk/maven-toolchains-plugin/src/it/toolchains.xml Thu Nov 6 23:18:33 2014 @@ -28,7 +28,7 @@ under the License. <name>demo</name> </provides> <configuration> - <toolHome>/opt/custom/1.5</toolHome> + <toolHome>opt/custom/1.5</toolHome> </configuration> </toolchain> <toolchain> @@ -38,7 +38,7 @@ under the License. <name>demo-2</name> </provides> <configuration> - <toolHome>/opt/custom/2.0</toolHome> + <toolHome>opt/custom/2.0</toolHome> </configuration> </toolchain> </toolchains> \ No newline at end of file Modified: maven/plugins/trunk/maven-toolchains-plugin/src/it/use-custom-toolchain/invoker.properties URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-toolchains-plugin/src/it/use-custom-toolchain/invoker.properties?rev=1637265&r1=1637264&r2=1637265&view=diff ============================================================================== --- maven/plugins/trunk/maven-toolchains-plugin/src/it/use-custom-toolchain/invoker.properties (original) +++ maven/plugins/trunk/maven-toolchains-plugin/src/it/use-custom-toolchain/invoker.properties Thu Nov 6 23:18:33 2014 @@ -15,5 +15,5 @@ # specific language governing permissions and limitations # under the License. -invoker.goals = --toolchains ../../../src/it/toolchains.xml validate +invoker.goals = --toolchains ../../../src/it/toolchains.xml compile invoker.maven.version = 3.0+ Added: maven/plugins/trunk/maven-toolchains-plugin/src/it/use-custom-toolchain/opt/custom/1.5/bin/tool URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-toolchains-plugin/src/it/use-custom-toolchain/opt/custom/1.5/bin/tool?rev=1637265&view=auto ============================================================================== --- maven/plugins/trunk/maven-toolchains-plugin/src/it/use-custom-toolchain/opt/custom/1.5/bin/tool (added) +++ maven/plugins/trunk/maven-toolchains-plugin/src/it/use-custom-toolchain/opt/custom/1.5/bin/tool Thu Nov 6 23:18:33 2014 @@ -0,0 +1,16 @@ +# 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. Added: maven/plugins/trunk/maven-toolchains-plugin/src/it/use-custom-toolchain/opt/custom/1.5/bin/tool.exe URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-toolchains-plugin/src/it/use-custom-toolchain/opt/custom/1.5/bin/tool.exe?rev=1637265&view=auto ============================================================================== Binary file - no diff available. Propchange: maven/plugins/trunk/maven-toolchains-plugin/src/it/use-custom-toolchain/opt/custom/1.5/bin/tool.exe ------------------------------------------------------------------------------ svn:mime-type = application/octet-stream Added: maven/plugins/trunk/maven-toolchains-plugin/src/it/use-custom-toolchain/opt/custom/2.0/bin/tool URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-toolchains-plugin/src/it/use-custom-toolchain/opt/custom/2.0/bin/tool?rev=1637265&view=auto ============================================================================== --- maven/plugins/trunk/maven-toolchains-plugin/src/it/use-custom-toolchain/opt/custom/2.0/bin/tool (added) +++ maven/plugins/trunk/maven-toolchains-plugin/src/it/use-custom-toolchain/opt/custom/2.0/bin/tool Thu Nov 6 23:18:33 2014 @@ -0,0 +1,16 @@ +# 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. Added: maven/plugins/trunk/maven-toolchains-plugin/src/it/use-custom-toolchain/opt/custom/2.0/bin/tool.exe URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-toolchains-plugin/src/it/use-custom-toolchain/opt/custom/2.0/bin/tool.exe?rev=1637265&view=auto ============================================================================== Binary file - no diff available. Propchange: maven/plugins/trunk/maven-toolchains-plugin/src/it/use-custom-toolchain/opt/custom/2.0/bin/tool.exe ------------------------------------------------------------------------------ svn:mime-type = application/octet-stream Modified: maven/plugins/trunk/maven-toolchains-plugin/src/it/use-custom-toolchain/pom.xml URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-toolchains-plugin/src/it/use-custom-toolchain/pom.xml?rev=1637265&r1=1637264&r2=1637265&view=diff ============================================================================== --- maven/plugins/trunk/maven-toolchains-plugin/src/it/use-custom-toolchain/pom.xml (original) +++ maven/plugins/trunk/maven-toolchains-plugin/src/it/use-custom-toolchain/pom.xml Thu Nov 6 23:18:33 2014 @@ -34,13 +34,6 @@ under the License. </description> <build> - <extensions> - <extension> - <groupId>org.apache.maven.plugins.toolchains.its</groupId> - <artifactId>custom-toolchain</artifactId> - <version>1.0-SNAPSHOT</version> - </extension> - </extensions> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> @@ -61,6 +54,20 @@ under the License. </toolchains> </configuration> </plugin> + <plugin> + <groupId>org.apache.maven.plugins.toolchains.its</groupId> + <artifactId>custom-toolchain-plugin</artifactId> + <version>1.0-SNAPSHOT</version> + <extensions>true</extensions><!-- to share the custom toolchain with maven-toolchains-plugin --> + <executions> + <execution> + <phase>compile</phase> + <goals> + <goal>tool</goal> + </goals> + </execution> + </executions> + </plugin> </plugins> </build> </project> Added: maven/plugins/trunk/maven-toolchains-plugin/src/it/use-custom-toolchain/verify.groovy URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-toolchains-plugin/src/it/use-custom-toolchain/verify.groovy?rev=1637265&view=auto ============================================================================== --- maven/plugins/trunk/maven-toolchains-plugin/src/it/use-custom-toolchain/verify.groovy (added) +++ maven/plugins/trunk/maven-toolchains-plugin/src/it/use-custom-toolchain/verify.groovy Thu Nov 6 23:18:33 2014 @@ -0,0 +1,22 @@ +/* + * 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. + */ + +content = new File( basedir, 'build.log' ).text + +assert content.indexOf( "Found expected tool named 'tool' at following location:" ) > 0 Propchange: maven/plugins/trunk/maven-toolchains-plugin/src/it/use-custom-toolchain/verify.groovy ------------------------------------------------------------------------------ svn:eol-style = native Propchange: maven/plugins/trunk/maven-toolchains-plugin/src/it/use-custom-toolchain/verify.groovy ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision