Author: epunzalan
Date: Fri Mar 3 20:55:27 2006
New Revision: 383036
URL: http://svn.apache.org/viewcvs?rev=383036&view=rev
Log:
PR: MIDEA-26
Submitted by: Patrick Lightbody
Patch enabled manual configuration of the Idea libraries in addition to the
libraries generated by the plugin. Also, allowed directory exclusions
configuration, again, in addition to those that are excluded by the plugin by
default (project.build.directory, project.build.outputDirectory,
project.build.testOutputDirectory).
Modified:
maven/plugins/trunk/maven-idea-plugin/src/main/java/org/apache/maven/plugin/idea/AbstractIdeaMojo.java
maven/plugins/trunk/maven-idea-plugin/src/main/java/org/apache/maven/plugin/idea/IdeaModuleMojo.java
maven/plugins/trunk/maven-idea-plugin/src/main/java/org/apache/maven/plugin/idea/IdeaMojo.java
maven/plugins/trunk/maven-idea-plugin/src/main/java/org/apache/maven/plugin/idea/IdeaProjectMojo.java
maven/plugins/trunk/maven-idea-plugin/src/main/java/org/apache/maven/plugin/idea/IdeaWorkspaceMojo.java
maven/plugins/trunk/maven-idea-plugin/src/main/resources/templates/default/project.xml
Modified:
maven/plugins/trunk/maven-idea-plugin/src/main/java/org/apache/maven/plugin/idea/AbstractIdeaMojo.java
URL:
http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-idea-plugin/src/main/java/org/apache/maven/plugin/idea/AbstractIdeaMojo.java?rev=383036&r1=383035&r2=383036&view=diff
==============================================================================
---
maven/plugins/trunk/maven-idea-plugin/src/main/java/org/apache/maven/plugin/idea/AbstractIdeaMojo.java
(original)
+++
maven/plugins/trunk/maven-idea-plugin/src/main/java/org/apache/maven/plugin/idea/AbstractIdeaMojo.java
Fri Mar 3 20:55:27 2006
@@ -37,6 +37,10 @@
import org.codehaus.plexus.util.xml.Xpp3Dom;
import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileReader;
+import java.io.InputStreamReader;
+import java.io.Reader;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
@@ -223,9 +227,11 @@
try
{
- ArtifactResolutionResult result =
artifactResolver.resolveTransitively(
- getProjectArtifacts(), project.getArtifact(),
- managedVersions, localRepo,
project.getRemoteArtifactRepositories(), artifactMetadataSource );
+ ArtifactResolutionResult result =
artifactResolver.resolveTransitively( getProjectArtifacts(),
+
project.getArtifact(),
+
managedVersions, localRepo,
+
project.getRemoteArtifactRepositories(),
+
artifactMetadataSource );
project.setArtifacts( result.getArtifacts() );
}
@@ -244,7 +250,7 @@
{
Set artifacts = new HashSet();
- for( Iterator dependencies = project.getDependencies().iterator();
dependencies.hasNext(); )
+ for ( Iterator dependencies = project.getDependencies().iterator();
dependencies.hasNext(); )
{
Dependency dep = (Dependency) dependencies.next();
@@ -253,7 +259,8 @@
dep.setScope( Artifact.SCOPE_COMPILE );
}
- Artifact artifact = artifactFactory.createArtifact(
dep.getGroupId(), dep.getArtifactId(), dep.getVersion(), dep.getScope(),
dep.getType() );
+ Artifact artifact = artifactFactory.createArtifact(
dep.getGroupId(), dep.getArtifactId(), dep.getVersion(),
+
dep.getScope(), dep.getType() );
artifacts.add( artifact );
}
@@ -304,5 +311,28 @@
}
return log;
+ }
+
+ protected Reader getXmlReader( String file )
+ {
+ File altFile = new File( project.getBasedir(), "src/main/idea/" + file
);
+ if ( altFile.exists() )
+ {
+ try
+ {
+ return new FileReader( altFile );
+ }
+ catch ( FileNotFoundException e )
+ {
+ // this shouldn't happen, since we just verified it exists,
+ // but we'll print the error out in the off change
+ getLog().error( "File not found even though we just verified
it exists. Failing.", e );
+ throw new RuntimeException( e );
+ }
+ }
+ else
+ {
+ return new InputStreamReader( getClass().getResourceAsStream(
"/templates/default/" + file ) );
+ }
}
}
Modified:
maven/plugins/trunk/maven-idea-plugin/src/main/java/org/apache/maven/plugin/idea/IdeaModuleMojo.java
URL:
http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-idea-plugin/src/main/java/org/apache/maven/plugin/idea/IdeaModuleMojo.java?rev=383036&r1=383035&r2=383036&view=diff
==============================================================================
---
maven/plugins/trunk/maven-idea-plugin/src/main/java/org/apache/maven/plugin/idea/IdeaModuleMojo.java
(original)
+++
maven/plugins/trunk/maven-idea-plugin/src/main/java/org/apache/maven/plugin/idea/IdeaModuleMojo.java
Fri Mar 3 20:55:27 2006
@@ -39,7 +39,6 @@
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
-import java.io.InputStreamReader;
import java.io.Reader;
import java.util.ArrayList;
import java.util.Arrays;
@@ -47,6 +46,9 @@
import java.util.Iterator;
import java.util.List;
import java.util.Map;
+import java.util.Set;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
/**
* @author Edwin Punzalan
@@ -116,6 +118,35 @@
private String javadocClassifier;
/**
+ * An optional set of Library objects that allow you to specify a comma
separated list of source dirs, class dirs,
+ * or to indicate that the library should be excluded from the module. For
example:
+ * <p/>
+ * <pre>
+ * <libraries>
+ * <library>
+ * <name>webwork</name>
+ * <sources>file://$webwork$/src/java</sources>
+ * <!--
+ * <classes>...</classes>
+ * <exclude>true</exclude>
+ * -->
+ * </library>
+ * </libraries>
+ * </pre>
+ *
+ * @parameter
+ */
+ private Library[] libraries;
+
+ /**
+ * A comma-separated list of directories that should be excluded. These
directories are in addition to those
+ * already excluded, such as target.
+ *
+ * @parameter
+ */
+ private String exclude;
+
+ /**
* A temporary cache of artifacts that's already been downloaded or
* attempted to be downloaded. This is to refrain from trying to download a
* dependency that we have already tried to download.
@@ -124,11 +155,14 @@
*/
private static Map attemptedDownloads = new HashMap();
+ private Set macros;
+
public void initParam( MavenProject project, ArtifactFactory
artifactFactory, ArtifactRepository localRepo,
ArtifactResolver artifactResolver,
ArtifactMetadataSource artifactMetadataSource, Log log,
boolean overwrite, MavenProject executedProject,
List reactorProjects,
WagonManager wagonManager, boolean linkModules,
boolean useFullNames, boolean useClassifiers,
- String sourceClassifier, String javadocClassifier )
+ String sourceClassifier, String javadocClassifier,
Library[] libraries, Set macros,
+ String exclude )
{
super.initParam( project, artifactFactory, localRepo,
artifactResolver, artifactMetadataSource, log,
overwrite );
@@ -148,6 +182,12 @@
this.sourceClassifier = sourceClassifier;
this.javadocClassifier = javadocClassifier;
+
+ this.libraries = libraries;
+
+ this.macros = macros;
+
+ this.exclude = exclude;
}
/**
@@ -178,7 +218,7 @@
}
else
{
- reader = new InputStreamReader(
getClass().getResourceAsStream( "/templates/default/module.xml" ) );
+ reader = getXmlReader( "module.xml" );
}
Xpp3Dom module;
@@ -252,6 +292,16 @@
filteredExcludes.addAll( getExcludedDirectories( classes,
filteredExcludes, sourceFolders ) );
filteredExcludes.addAll( getExcludedDirectories( testClasses,
filteredExcludes, sourceFolders ) );
+ if ( exclude != null )
+ {
+ String[] dirs = exclude.split( "[,\\s]+" );
+ for ( int i = 0; i < dirs.length; i++ )
+ {
+ File excludedDir = new File( dirs[ i ] );
+ filteredExcludes.add( getExcludedDirectories( excludedDir,
filteredExcludes, sourceFolders ) );
+ }
+ }
+
for ( Iterator i = filteredExcludes.iterator(); i.hasNext(); )
{
addExcludeFolder( content, i.next().toString() );
@@ -264,6 +314,12 @@
{
Artifact a = (Artifact) i.next();
+ Library library = findLibrary( a );
+ if ( library != null && library.isExclude() )
+ {
+ continue;
+ }
+
String moduleName;
if ( useFullNames )
{
@@ -277,9 +333,9 @@
Xpp3Dom dep = null;
Xpp3Dom[] orderEntries = component.getChildren( "orderEntry" );
- for( int idx = 0; idx < orderEntries.length; idx++ )
+ for ( int idx = 0; idx < orderEntries.length; idx++ )
{
- Xpp3Dom orderEntry = orderEntries[ idx ];
+ Xpp3Dom orderEntry = orderEntries[idx];
if ( orderEntry.getAttribute( "type" ).equals( "module" ) )
{
@@ -325,14 +381,46 @@
dep.setAttribute( "name", moduleName );
Xpp3Dom el = createElement( dep, "CLASSES" );
- el = createElement( el, "root" );
- File file = a.getFile();
- el.setAttribute( "url", "jar://" +
file.getAbsolutePath().replace( '\\', '/' ) + "!/" );
+ if ( library != null && library.getSplitClasses().length >
0 )
+ {
+ String[] libraryClasses = library.getSplitClasses();
+ for ( int k = 0; k < libraryClasses.length; k++ )
+ {
+ String classpath = libraryClasses[k];
+ extractMacro( classpath );
+ Xpp3Dom classEl = createElement( el, "root" );
+ classEl.setAttribute( "url", classpath );
+ }
+ }
+ else
+ {
+ el = createElement( el, "root" );
+ File file = a.getFile();
+ el.setAttribute( "url", "jar://" +
file.getAbsolutePath().replace( '\\', '/' ) + "!/" );
+ }
+
+ boolean usedSources = false;
+ if ( library != null && library.getSplitSources().length >
0 )
+ {
+ Xpp3Dom sourcesElement = createElement( dep, "SOURCES"
);
+ usedSources = true;
+ String[] sources = library.getSplitSources();
+ for ( int k = 0; k < sources.length; k++ )
+ {
+ String source = sources[k];
+ extractMacro( source );
+ Xpp3Dom sourceEl = createElement( sourcesElement,
"root" );
+ sourceEl.setAttribute( "url", source );
+ }
+ }
if ( useClassifiers )
{
resolveClassifier( createElement( dep, "JAVADOC" ), a,
javadocClassifier );
- resolveClassifier( createElement( dep, "SOURCES" ), a,
sourceClassifier );
+ if ( !usedSources )
+ {
+ resolveClassifier( createElement( dep, "SOURCES"
), a, sourceClassifier );
+ }
}
}
}
@@ -366,6 +454,37 @@
}
}
+ private void extractMacro( String path )
+ {
+ if ( macros != null )
+ {
+ Pattern p = Pattern.compile( ".*\\$([^\\$]+)\\$.*" );
+ Matcher matcher = p.matcher( path );
+ while ( matcher.find() )
+ {
+ String macro = matcher.group( 1 );
+ macros.add( macro );
+ }
+ }
+ }
+
+ private Library findLibrary( Artifact a )
+ {
+ if ( libraries != null )
+ {
+ for ( int j = 0; j < libraries.length; j++ )
+ {
+ Library library = libraries[j];
+ if ( a.getArtifactId().equals( library.getName() ) )
+ {
+ return library;
+ }
+ }
+ }
+
+ return null;
+ }
+
private List getExcludedDirectories( File target, List excludeList, List
sourceFolders )
{
List foundFolders = new ArrayList();
@@ -383,7 +502,7 @@
String absolutePath = file.getAbsolutePath();
String url = getModuleFileUrl( absolutePath );
- for( Iterator sources = sourceFolders.iterator();
sources.hasNext(); )
+ for ( Iterator sources = sourceFolders.iterator();
sources.hasNext(); )
{
String source = ( (Xpp3Dom) sources.next()
).getAttribute( "url" );
if ( source.equals( url ) )
@@ -394,7 +513,8 @@
else if ( source.indexOf( url ) == 0 )
{
dirs++;
- foundFolders.addAll( getExcludedDirectories( new
File( absolutePath ), excludeList, sourceFolders ) );
+ foundFolders.addAll(
+ getExcludedDirectories( new File( absolutePath
), excludeList, sourceFolders ) );
break;
}
else
Modified:
maven/plugins/trunk/maven-idea-plugin/src/main/java/org/apache/maven/plugin/idea/IdeaMojo.java
URL:
http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-idea-plugin/src/main/java/org/apache/maven/plugin/idea/IdeaMojo.java?rev=383036&r1=383035&r2=383036&view=diff
==============================================================================
---
maven/plugins/trunk/maven-idea-plugin/src/main/java/org/apache/maven/plugin/idea/IdeaMojo.java
(original)
+++
maven/plugins/trunk/maven-idea-plugin/src/main/java/org/apache/maven/plugin/idea/IdeaMojo.java
Fri Mar 3 20:55:27 2006
@@ -20,7 +20,9 @@
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.project.MavenProject;
+import java.util.HashSet;
import java.util.List;
+import java.util.Set;
/**
* Goal for generating IDEA files from a POM.
@@ -109,6 +111,35 @@
private String jdkLevel;
/**
+ * An optional set of Library objects that allow you to specify a comma
separated list of source dirs, class dirs,
+ * or to indicate that the library should be excluded from the module. For
example:
+ * <p/>
+ * <pre>
+ * <libraries>
+ * <library>
+ * <name>webwork</name>
+ * <sources>file://$webwork$/src/java</sources>
+ * <!--
+ * <classes>...</classes>
+ * <exclude>true</exclude>
+ * -->
+ * </library>
+ * </libraries>
+ * </pre>
+ *
+ * @parameter
+ */
+ private Library[] libraries;
+
+ /**
+ * A comma-separated list of directories that should be excluded. These
directories are in addition to those
+ * already excluded, such as target/classes. A common use of this is to
exclude the entire target directory.
+ *
+ * @parameter
+ */
+ private String exclude;
+
+ /**
* Specify the resource pattern in wildcard format, for example
"?*.xml;?*.properties".
* Currently supports 4.x and 5.x.
* The default value is any file without a java extension ("!?*.java").
@@ -142,35 +173,36 @@
throw new MojoExecutionException( "Unable to build project
dependencies.", e );
}
- rewriteModule();
+ Set macros = new HashSet();
+ rewriteModule( macros );
if ( project.isExecutionRoot() )
{
- rewriteProject();
+ rewriteProject( macros );
rewriteWorkspace();
}
}
- private void rewriteModule()
+ private void rewriteModule( Set macros )
throws MojoExecutionException
{
IdeaModuleMojo mojo = new IdeaModuleMojo();
mojo.initParam( project, artifactFactory, localRepo, artifactResolver,
artifactMetadataSource, getLog(),
overwrite, executedProject, reactorProjects,
wagonManager, linkModules, useFullNames,
- useClassifiers, sourceClassifier, javadocClassifier );
+ useClassifiers, sourceClassifier, javadocClassifier,
libraries, macros, exclude );
mojo.execute();
}
- private void rewriteProject()
+ private void rewriteProject( Set macros )
throws MojoExecutionException
{
IdeaProjectMojo mojo = new IdeaProjectMojo();
mojo.initParam( project, artifactFactory, localRepo, artifactResolver,
artifactMetadataSource, getLog(),
- overwrite, jdkName, jdkLevel,
wildcardResourcePatterns, ideaVersion );
+ overwrite, jdkName, jdkLevel,
wildcardResourcePatterns, ideaVersion, macros );
mojo.execute();
}
Modified:
maven/plugins/trunk/maven-idea-plugin/src/main/java/org/apache/maven/plugin/idea/IdeaProjectMojo.java
URL:
http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-idea-plugin/src/main/java/org/apache/maven/plugin/idea/IdeaProjectMojo.java?rev=383036&r1=383035&r2=383036&view=diff
==============================================================================
---
maven/plugins/trunk/maven-idea-plugin/src/main/java/org/apache/maven/plugin/idea/IdeaProjectMojo.java
(original)
+++
maven/plugins/trunk/maven-idea-plugin/src/main/java/org/apache/maven/plugin/idea/IdeaProjectMojo.java
Fri Mar 3 20:55:27 2006
@@ -34,9 +34,9 @@
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
-import java.io.InputStreamReader;
import java.io.Reader;
import java.util.Iterator;
+import java.util.Set;
import java.util.StringTokenizer;
/**
@@ -87,10 +87,12 @@
*/
private String ideaVersion;
+ private Set macros;
+
public void initParam( MavenProject project, ArtifactFactory
artifactFactory, ArtifactRepository localRepo,
ArtifactResolver artifactResolver,
ArtifactMetadataSource artifactMetadataSource, Log log,
boolean overwrite, String jdkName, String jdkLevel,
String wildcardResourcePatterns,
- String ideaVersion )
+ String ideaVersion, Set macros )
{
super.initParam( project, artifactFactory, localRepo,
artifactResolver, artifactMetadataSource, log,
overwrite );
@@ -102,6 +104,8 @@
this.wildcardResourcePatterns = wildcardResourcePatterns;
this.ideaVersion = ideaVersion;
+
+ this.macros = macros;
}
/**
@@ -132,7 +136,7 @@
}
else
{
- reader = new InputStreamReader(
getClass().getResourceAsStream( "/templates/default/project.xml" ) );
+ reader = getXmlReader( "project.xml" );
}
Xpp3Dom module;
@@ -196,6 +200,19 @@
String modulePath =
new File( project.getBasedir(), project.getArtifactId() +
".iml" ).getAbsolutePath();
m.setAttribute( "filepath", "$PROJECT_DIR$/" + toRelative(
project.getBasedir(), modulePath ) );
+ }
+
+ // add any PathMacros we've come across
+ if ( macros != null )
+ {
+ Xpp3Dom usedPathMacros = module.getChildren( "UsedPathMacros"
)[0];
+ removeOldElements( usedPathMacros, "macro" );
+ for ( Iterator iterator = macros.iterator();
iterator.hasNext(); )
+ {
+ String macro = (String) iterator.next();
+ Xpp3Dom macroElement = createElement( usedPathMacros,
"macro" );
+ macroElement.setAttribute( "name", macro );
+ }
}
FileWriter writer = new FileWriter( projectFile );
Modified:
maven/plugins/trunk/maven-idea-plugin/src/main/java/org/apache/maven/plugin/idea/IdeaWorkspaceMojo.java
URL:
http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-idea-plugin/src/main/java/org/apache/maven/plugin/idea/IdeaWorkspaceMojo.java?rev=383036&r1=383035&r2=383036&view=diff
==============================================================================
---
maven/plugins/trunk/maven-idea-plugin/src/main/java/org/apache/maven/plugin/idea/IdeaWorkspaceMojo.java
(original)
+++
maven/plugins/trunk/maven-idea-plugin/src/main/java/org/apache/maven/plugin/idea/IdeaWorkspaceMojo.java
Fri Mar 3 20:55:27 2006
@@ -27,7 +27,6 @@
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
-import java.io.InputStreamReader;
import java.io.Reader;
/**
@@ -73,7 +72,7 @@
}
else
{
- reader = new InputStreamReader(
getClass().getResourceAsStream( "/templates/default/workspace.xml" ) );
+ reader = getXmlReader( "workspace.xml" );
}
module = Xpp3DomBuilder.build( reader );
Modified:
maven/plugins/trunk/maven-idea-plugin/src/main/resources/templates/default/project.xml
URL:
http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-idea-plugin/src/main/resources/templates/default/project.xml?rev=383036&r1=383035&r2=383036&view=diff
==============================================================================
---
maven/plugins/trunk/maven-idea-plugin/src/main/resources/templates/default/project.xml
(original)
+++
maven/plugins/trunk/maven-idea-plugin/src/main/resources/templates/default/project.xml
Fri Mar 3 20:55:27 2006
@@ -97,5 +97,7 @@
<!-- module filepath="$$PROJECT_DIR$$/${pom.artifactId}.iml"/ -->
</modules>
</component>
-
+ <UsedPathMacros>
+ <!--<macro name="cargo"></macro>-->
+ </UsedPathMacros>
</project>