maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r521753 - in /maven/plugins/trunk/maven-remote-resources-plugin/src/main/java/org/apache/maven/plugin/resources/remote: BundleRemoteResourcesMojo.java ProcessRemoteResourcesMojo.java
Date Fri, 23 Mar 2007 15:02:07 GMT
Author: dkulp
Date: Fri Mar 23 08:02:06 2007
New Revision: 521753

URL: http://svn.apache.org/viewvc?view=rev&rev=521753
Log:
[MRRESOURCES-19,MRRESOURCES-20,MRRESOURCES-18] Updates to Bundle mojo to allow better filtering.
 Non-velocity resources support.

Modified:
    maven/plugins/trunk/maven-remote-resources-plugin/src/main/java/org/apache/maven/plugin/resources/remote/BundleRemoteResourcesMojo.java
    maven/plugins/trunk/maven-remote-resources-plugin/src/main/java/org/apache/maven/plugin/resources/remote/ProcessRemoteResourcesMojo.java

Modified: maven/plugins/trunk/maven-remote-resources-plugin/src/main/java/org/apache/maven/plugin/resources/remote/BundleRemoteResourcesMojo.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-remote-resources-plugin/src/main/java/org/apache/maven/plugin/resources/remote/BundleRemoteResourcesMojo.java?view=diff&rev=521753&r1=521752&r2=521753
==============================================================================
--- maven/plugins/trunk/maven-remote-resources-plugin/src/main/java/org/apache/maven/plugin/resources/remote/BundleRemoteResourcesMojo.java
(original)
+++ maven/plugins/trunk/maven-remote-resources-plugin/src/main/java/org/apache/maven/plugin/resources/remote/BundleRemoteResourcesMojo.java
Fri Mar 23 08:02:06 2007
@@ -22,9 +22,11 @@
 import org.apache.maven.plugin.AbstractMojo;
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.plugin.resources.remote.io.xpp3.RemoteResourcesBundleXpp3Writer;
+import org.codehaus.plexus.util.DirectoryScanner;
 import org.codehaus.plexus.util.FileUtils;
 import org.codehaus.plexus.util.StringUtils;
 
+import java.util.Arrays;
 import java.util.List;
 import java.util.Iterator;
 import java.io.File;
@@ -43,6 +45,12 @@
     extends AbstractMojo
 {
     public static final String RESOURCES_MANIFEST = "META-INF/maven/remote-resources.xml";
+    
+    private static String[] DEFAULT_INCLUDES = new String [] {
+                                                              "**/*.txt",
+                                                              "**/*.vm",
+                                                   };
+
 
     /**
      * The directory which contains the resources you want packaged up in this resource bundle.
@@ -57,7 +65,24 @@
      * @parameter expression="${project.build.outputDirectory}"
      */
     private File outputDirectory;
+    
+    
+    /**
+     * A list of files to include. Can contain ant-style wildcards and double wildcards.
+     * The default includes are 
+     * <code>**&#47;*.txt   **&#47;*.vm</code>
+     * 
+     * @parameter
+     */
+    private String[] includes;
 
+    /**
+     * A list of files to exclude. Can contain ant-style wildcards and double wildcards.
 
+     *
+     * @parameter
+     */
+    private String[] excludes;
+    
     public void execute()
         throws MojoExecutionException
     {
@@ -71,22 +96,36 @@
 
         RemoteResourcesBundle remoteResourcesBundle = new RemoteResourcesBundle();
 
-        try
-        {
-            List resources = FileUtils.getFileNames( resourcesDirectory, "**/*.txt,**/*.vm",
"**/.svn/**", false );
+        DirectoryScanner scanner = new DirectoryScanner();
 
-            for ( Iterator i = resources.iterator(); i.hasNext(); )
-            {
-                String resource = (String) i.next();
+        scanner.setBasedir( resourcesDirectory );
+        if ( includes != null && includes.length != 0 )
+        {
+            scanner.setIncludes( includes );
+        }
+        else
+        {
+            scanner.setIncludes( DEFAULT_INCLUDES );
+        }
 
-                remoteResourcesBundle.addRemoteResource( StringUtils.replace( resource, '\\',
'/' ) );
-            }
+        if ( excludes != null && excludes.length != 0 )
+        {
+            scanner.setExcludes( excludes );
         }
-        catch ( IOException e )
+
+        scanner.addDefaultExcludes();
+        scanner.scan();
+
+        List includedFiles = Arrays.asList( scanner.getIncludedFiles() );
+
+        for ( Iterator i = includedFiles.iterator(); i.hasNext(); )
         {
-            throw new MojoExecutionException( "Error scanning resources.", e );
+            String resource = (String) i.next();
+
+            remoteResourcesBundle.addRemoteResource( StringUtils.replace( resource, '\\',
'/' ) );
         }
 
+        
         RemoteResourcesBundleXpp3Writer w = new RemoteResourcesBundleXpp3Writer();
 
         try

Modified: maven/plugins/trunk/maven-remote-resources-plugin/src/main/java/org/apache/maven/plugin/resources/remote/ProcessRemoteResourcesMojo.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-remote-resources-plugin/src/main/java/org/apache/maven/plugin/resources/remote/ProcessRemoteResourcesMojo.java?view=diff&rev=521753&r1=521752&r2=521753
==============================================================================
--- maven/plugins/trunk/maven-remote-resources-plugin/src/main/java/org/apache/maven/plugin/resources/remote/ProcessRemoteResourcesMojo.java
(original)
+++ maven/plugins/trunk/maven-remote-resources-plugin/src/main/java/org/apache/maven/plugin/resources/remote/ProcessRemoteResourcesMojo.java
Fri Mar 23 08:02:06 2007
@@ -22,6 +22,7 @@
 import org.apache.maven.artifact.factory.ArtifactFactory;
 import org.apache.maven.artifact.repository.ArtifactRepository;
 import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
+import org.apache.maven.artifact.versioning.VersionRange;
 import org.apache.maven.artifact.Artifact;
 import org.apache.maven.artifact.InvalidRepositoryException;
 import org.apache.maven.execution.MavenSession;
@@ -194,9 +195,13 @@
     public void execute()
         throws MojoExecutionException
     {
-        if ( StringUtils.isEmpty( project.getInceptionYear() ) )
+        String inceptionYear = project.getInceptionYear();
+        String year = new SimpleDateFormat( "yyyy" ).format( new Date() );
+        
+        if ( StringUtils.isEmpty( inceptionYear ) )
         {
-            throw new MojoExecutionException( "You must specify an inceptionYear." );
+            getLog().info("inceptionYear not specified, defaulting to " + year);
+            inceptionYear = year;
         }
 
         RemoteResourcesClassLoader classLoader = new RemoteResourcesClassLoader();
@@ -277,8 +282,6 @@
         context.put( "project", project );
         context.put( "projects", getProjects() );
         
-        String year = new SimpleDateFormat( "yyyy" ).format( new Date() );
-
         context.put( "presentYear", year );
 
         if ( project.getInceptionYear().equals( year ) )
@@ -317,10 +320,11 @@
     
                         String projectResource = bundleResource;
     
-    
+                        boolean doVelocity = false;
                         if ( projectResource.endsWith( ".vm" ) )
                         {
                             projectResource = projectResource.substring( 0, projectResource.length()
- 3 );
+                            doVelocity = true;
                         }
     
                         // Don't overwrite resource that are already being provided.
@@ -331,30 +335,40 @@
     
                         if ( !copyResourceIfExists( f, projectResource ) )
                         {
-                            PrintWriter writer = new PrintWriter( new FileWriter( f ) );
-    
-                            try 
+                            if ( doVelocity) 
                             {
-                                velocity.getEngine().mergeTemplate( bundleResource, context,
writer );
-    
-                                File appendedResourceFile = new File( appendedResourcesDirectory,
projectResource );
-                                if ( appendedResourceFile.exists() ) 
+                                PrintWriter writer = new PrintWriter( new FileWriter( f )
);
+                                try 
                                 {
-                                    FileReader freader = new FileReader( appendedResourceFile
);
-                                    BufferedReader breader = new BufferedReader( freader
);
-                                    
-                                    String line = breader.readLine();
-                           
-                                    while ( line != null )
+                                    velocity.getEngine().mergeTemplate( bundleResource, context,
writer );
+        
+                                    File appendedResourceFile = new File( appendedResourcesDirectory,
projectResource );
+                                    if ( appendedResourceFile.exists() ) 
                                     {
-                                        writer.println( line );
-                                        line = breader.readLine();
+                                        FileReader freader = new FileReader( appendedResourceFile
);
+                                        BufferedReader breader = new BufferedReader( freader
);
+                                        
+                                        String line = breader.readLine();
+                               
+                                        while ( line != null )
+                                        {
+                                            writer.println( line );
+                                            line = breader.readLine();
+                                        }
                                     }
                                 }
+                                finally
+                                {
+                                    writer.close();
+                                }
                             }
-                            finally
+                            else
                             {
-                                writer.close();
+                                URL resUrl = classLoader.getResource( bundleResource );
+                                if ( resUrl != null )
+                                {
+                                    FileUtils.copyURLToFile( resUrl, f );
+                                }
                             }
                         }
                     }
@@ -424,17 +438,16 @@
             {
                 if ( artifact.isSnapshot() )
                 {
+                    VersionRange rng = VersionRange.createFromVersion(artifact.getBaseVersion());
                     artifact = artifactFactory.createDependencyArtifact( artifact.getGroupId(),
                                                                          artifact.getArtifactId(),
-                                                                         artifact.getVersionRange(),
+                                                                         rng,
                                                                          artifact.getType(),
                                                                          artifact.getClassifier(),
                                                                          artifact.getScope(),
                                                                          null,
                                                                          artifact.isOptional()
);
-                    artifact.setVersion( artifact.getBaseVersion() );
                 }
-                
                 getLog().debug("Building project for " + artifact);
                 MavenProject p = mavenProjectBuilder.buildFromRepository( artifact,
                                                         remoteRepositories,



Mime
View raw message