You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by ni...@apache.org on 2009/05/18 17:21:33 UTC
svn commit: r775982 - in /maven/sandbox/trunk/shared/maven-plugin-helper/src:
main/java/org/apache/maven/shared/plugin/classloader/
main/java/org/apache/maven/shared/plugin/scanner/ site/ site/apt/
Author: nicolas
Date: Mon May 18 15:21:30 2009
New Revision: 775982
URL: http://svn.apache.org/viewvc?rev=775982&view=rev
Log:
docs and DirectoryScanner builder
Added:
maven/sandbox/trunk/shared/maven-plugin-helper/src/main/java/org/apache/maven/shared/plugin/scanner/
maven/sandbox/trunk/shared/maven-plugin-helper/src/main/java/org/apache/maven/shared/plugin/scanner/ScannerBuilder.java
maven/sandbox/trunk/shared/maven-plugin-helper/src/site/
maven/sandbox/trunk/shared/maven-plugin-helper/src/site/apt/
maven/sandbox/trunk/shared/maven-plugin-helper/src/site/apt/classloader.apt
maven/sandbox/trunk/shared/maven-plugin-helper/src/site/apt/index.apt
maven/sandbox/trunk/shared/maven-plugin-helper/src/site/apt/javacommand.apt
maven/sandbox/trunk/shared/maven-plugin-helper/src/site/site.xml
Modified:
maven/sandbox/trunk/shared/maven-plugin-helper/src/main/java/org/apache/maven/shared/plugin/classloader/ProjectClassLoaderUtil.java
Modified: maven/sandbox/trunk/shared/maven-plugin-helper/src/main/java/org/apache/maven/shared/plugin/classloader/ProjectClassLoaderUtil.java
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/shared/maven-plugin-helper/src/main/java/org/apache/maven/shared/plugin/classloader/ProjectClassLoaderUtil.java?rev=775982&r1=775981&r2=775982&view=diff
==============================================================================
--- maven/sandbox/trunk/shared/maven-plugin-helper/src/main/java/org/apache/maven/shared/plugin/classloader/ProjectClassLoaderUtil.java (original)
+++ maven/sandbox/trunk/shared/maven-plugin-helper/src/main/java/org/apache/maven/shared/plugin/classloader/ProjectClassLoaderUtil.java Mon May 18 15:21:30 2009
@@ -61,6 +61,7 @@
* Create a ClassLoader for the project with the specified scope, optionnaly including sources, and include the
* specified artifacts (typically from <code>${plugin.artifacts}</code>)
*
+ * @param additionalClassPathArtifacts List&tl;Artifact>
* @throws MalformedURLException
*/
public static ClassLoader buildProjectClassLoaderWithArtifacts( MavenProject project, String scope,
@@ -89,6 +90,7 @@
* Create a ClassLoader for the project with the specified scope, optionnaly including sources, and include the
* specified classpath elements.
*
+ * @param additionalClassPathElements List&tl;String>
* @throws MalformedURLException
*/
public static ClassLoader buildProjectClassLoaderWithElements( MavenProject project, String scope,
Added: maven/sandbox/trunk/shared/maven-plugin-helper/src/main/java/org/apache/maven/shared/plugin/scanner/ScannerBuilder.java
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/shared/maven-plugin-helper/src/main/java/org/apache/maven/shared/plugin/scanner/ScannerBuilder.java?rev=775982&view=auto
==============================================================================
--- maven/sandbox/trunk/shared/maven-plugin-helper/src/main/java/org/apache/maven/shared/plugin/scanner/ScannerBuilder.java (added)
+++ maven/sandbox/trunk/shared/maven-plugin-helper/src/main/java/org/apache/maven/shared/plugin/scanner/ScannerBuilder.java Mon May 18 15:21:30 2009
@@ -0,0 +1,188 @@
+package org.apache.maven.shared.plugin.scanner;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.List;
+
+import org.codehaus.plexus.util.DirectoryScanner;
+
+/*
+ * 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.
+ */
+
+/**
+ * Use the builder pattern to configure and execute a DirectoryScanner. <code>iterateOn*</code> methods allow to iterate
+ * on the scanner result
+ *
+ * @author <a href="mailto:nicolas@apache.org">Nicolas De Loof</a>
+ */
+public class ScannerBuilder
+{
+ private DirectoryScanner scanner;
+
+ private List includes = new ArrayList();
+
+ private List excludes = new ArrayList();
+
+ public ScannerBuilder( File basedir )
+ {
+ scanner = new DirectoryScanner();
+ scanner.setBasedir( basedir );
+ }
+
+ public ScannerBuilder include( String include )
+ {
+ this.includes.add( include );
+ return this;
+ }
+
+ public ScannerBuilder include( String[] includes )
+ {
+ for ( int i = 0; i < includes.length; i++ )
+ {
+ this.includes.add( includes[i] );
+ }
+ return this;
+ }
+
+ public ScannerBuilder exclude( String exclude )
+ {
+ this.excludes.add( exclude );
+ return this;
+ }
+
+ public ScannerBuilder exclude( String[] excludes )
+ {
+ for ( int i = 0; i < excludes.length; i++ )
+ {
+ this.excludes.add( excludes[i] );
+ }
+ return this;
+ }
+
+ public ScannerBuilder scan()
+ {
+ scanner.setIncludes( (String[]) includes.toArray( new String[includes.size()] ) );
+ scanner.setExcludes( (String[]) excludes.toArray( new String[excludes.size()] ) );
+ scanner.scan();
+ return this;
+ }
+
+ public ScannerBuilder addDefaultExcludes()
+ {
+ scanner.addDefaultExcludes();
+ return this;
+ }
+
+ public ScannerBuilder setCaseSensitive( boolean isCaseSensitive )
+ {
+ scanner.setCaseSensitive( isCaseSensitive );
+ return this;
+ }
+
+ public ScannerBuilder setFollowSymlinks( boolean followSymlinks )
+ {
+ scanner.setFollowSymlinks( followSymlinks );
+ return this;
+ }
+
+ /**
+ * @return Iterator&tl;File>
+ */
+ public Iterator iterateOnFiles()
+ {
+ String[] paths = scanner.getIncludedFiles();
+ List files = new ArrayList( paths.length );
+ for ( int i = 0; i < paths.length; i++ )
+ {
+ files.add( new File( scanner.getBasedir(), paths[i] ) );
+ }
+ return files.iterator();
+ }
+
+ /**
+ * @return Iterator&tl;File>
+ */
+ public Iterator iterateOnDirectories()
+ {
+ String[] paths = scanner.getIncludedDirectories();
+ List files = new ArrayList( paths.length );
+ for ( int i = 0; i < paths.length; i++ )
+ {
+ files.add( new File( scanner.getBasedir(), paths[i] ) );
+ }
+ return files.iterator();
+ }
+
+ /**
+ * @return Iterator&tl;String>
+ */
+ public Iterator iterateOnPaths()
+ {
+ String[] paths = scanner.getIncludedFiles();
+ return Arrays.asList( paths ).iterator();
+ }
+
+ public String[] getDeselectedDirectories()
+ {
+ return scanner.getDeselectedDirectories();
+ }
+
+ public String[] getDeselectedFiles()
+ {
+ return scanner.getDeselectedFiles();
+ }
+
+ public String[] getExcludedDirectories()
+ {
+ return scanner.getExcludedDirectories();
+ }
+
+ public String[] getExcludedFiles()
+ {
+ return scanner.getExcludedFiles();
+ }
+
+ public String[] getIncludedDirectories()
+ {
+ return scanner.getIncludedDirectories();
+ }
+
+ public String[] getIncludedFiles()
+ {
+ return scanner.getIncludedFiles();
+ }
+
+ public String[] getNotIncludedDirectories()
+ {
+ return scanner.getNotIncludedDirectories();
+ }
+
+ public String[] getNotIncludedFiles()
+ {
+ return scanner.getNotIncludedFiles();
+ }
+
+ public boolean isEverythingIncluded()
+ {
+ return scanner.isEverythingIncluded();
+ }
+
+}
Added: maven/sandbox/trunk/shared/maven-plugin-helper/src/site/apt/classloader.apt
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/shared/maven-plugin-helper/src/site/apt/classloader.apt?rev=775982&view=auto
==============================================================================
--- maven/sandbox/trunk/shared/maven-plugin-helper/src/site/apt/classloader.apt (added)
+++ maven/sandbox/trunk/shared/maven-plugin-helper/src/site/apt/classloader.apt Mon May 18 15:21:30 2009
@@ -0,0 +1,47 @@
+ ------
+ Managing Project Classloader
+ ------
+ Nicolas De loof
+ ------
+18 May 2009
+ ------
+
+~~ 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.
+
+~~ NOTE: For help with the syntax of this file, see:
+~~ http://maven.apache.org/doxia/references/apt-format.html
+
+
+Managing project classloader
+
+ Many plugins have to lauch a class using a custom classloader that mixes a plugin dependency (the tool) with the
+ project dependencies and classpath elements.
+
+* Usage
+
+ ProjectClassLoaderUtil has static methods to created the required URLClassLoader using the MavenProject. The
+ classpath is built depending on standard Artifact scopes, and may include project source roots.
+
+ Optionnaly, the constructed ClassLoader can include some more artifacts, for example the one obtained from
+ Maven with expression <<<${plugin.artifacts}>>>.
+
+
+
+
+
+
Added: maven/sandbox/trunk/shared/maven-plugin-helper/src/site/apt/index.apt
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/shared/maven-plugin-helper/src/site/apt/index.apt?rev=775982&view=auto
==============================================================================
--- maven/sandbox/trunk/shared/maven-plugin-helper/src/site/apt/index.apt (added)
+++ maven/sandbox/trunk/shared/maven-plugin-helper/src/site/apt/index.apt Mon May 18 15:21:30 2009
@@ -0,0 +1,48 @@
+ ------
+ Introduction
+ ------
+ Nicolas De loof
+ ------
+18 May 2009
+ ------
+
+~~ 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.
+
+~~ NOTE: For help with the syntax of this file, see:
+~~ http://maven.apache.org/doxia/references/apt-format.html
+
+
+Maven Plugin Helper
+
+ Most Maven plugins must address comparable issues : scan a folder for some pattern, manage the executed Maven project
+ classloader to execute some tool, etc. To avoid each plugin to reinvent the wheel and fall into bugs the other ones
+ allready solved, maven-plugin-helper provides some common usage patterns and utility classes.
+
+* Usage
+
+ The following usecases are proposed as reusable set of code:
+
+ * {{{classloader.html}Managing project Classloader}}
+
+ * {{{javacommand.html}Forking a JVM}}
+
+
+
+
+
+
Added: maven/sandbox/trunk/shared/maven-plugin-helper/src/site/apt/javacommand.apt
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/shared/maven-plugin-helper/src/site/apt/javacommand.apt?rev=775982&view=auto
==============================================================================
--- maven/sandbox/trunk/shared/maven-plugin-helper/src/site/apt/javacommand.apt (added)
+++ maven/sandbox/trunk/shared/maven-plugin-helper/src/site/apt/javacommand.apt Mon May 18 15:21:30 2009
@@ -0,0 +1,46 @@
+ ------
+ Running a forked JVM
+ ------
+ Nicolas De loof
+ ------
+18 May 2009
+ ------
+
+~~ 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.
+
+~~ NOTE: For help with the syntax of this file, see:
+~~ http://maven.apache.org/doxia/references/apt-format.html
+
+
+Running a forked JVM
+
+ In many case a plugin cannot run the tool in the same JVM and has to fork a new JVM. Plexus-utils provide
+ the necessary support to run a process, but not dedicated to Maven nor Java.
+
+* Usage
+
+ JavaCommandBuilder uses the builder pattern to help creating a new JVM process and run it. The executed class
+ is configured with a classPath set from project Scope, optionnaly adding some more Artifacts. System properties
+ and environment can be set to tweak the forked JVM. Execution can use a timeout, the builder returning a boolean
+ to indicate normal termination of the forked JVM.
+
+
+
+
+
+
Added: maven/sandbox/trunk/shared/maven-plugin-helper/src/site/site.xml
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/shared/maven-plugin-helper/src/site/site.xml?rev=775982&view=auto
==============================================================================
--- maven/sandbox/trunk/shared/maven-plugin-helper/src/site/site.xml (added)
+++ maven/sandbox/trunk/shared/maven-plugin-helper/src/site/site.xml Mon May 18 15:21:30 2009
@@ -0,0 +1,30 @@
+<?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
+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="Managing classloader" href="classloader.html"/>
+ <item name="Forking a JVM" href="javacommand.html"/>
+ </menu>
+ </body>
+</project>