You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by dk...@apache.org on 2007/01/22 21:17:33 UTC
svn commit: r498781 - in
/maven/sandbox/plugins/maven-remote-resources-plugin: README.txt
src/main/java/org/apache/maven/plugin/resources/remote/ProcessRemoteResourcesMojo.java
Author: dkulp
Date: Mon Jan 22 12:17:32 2007
New Revision: 498781
URL: http://svn.apache.org/viewvc?view=rev&rev=498781
Log:
Preliminary fixes for the following bugs:
MRRESOURCES-2 Support an "append" mode for local resources
MRRESOURCES-3 Plugin does not populate the projects needed for the notices file
MRRESOURCES-4 If not resourceBundles specified (or element miss-spelled) you get a NullPointerException
MRRESOURCES-5 Uses hardcodes src/main/resources for location of overriding resources
Added:
maven/sandbox/plugins/maven-remote-resources-plugin/README.txt (with props)
Modified:
maven/sandbox/plugins/maven-remote-resources-plugin/src/main/java/org/apache/maven/plugin/resources/remote/ProcessRemoteResourcesMojo.java
Added: maven/sandbox/plugins/maven-remote-resources-plugin/README.txt
URL: http://svn.apache.org/viewvc/maven/sandbox/plugins/maven-remote-resources-plugin/README.txt?view=auto&rev=498781
==============================================================================
--- maven/sandbox/plugins/maven-remote-resources-plugin/README.txt (added)
+++ maven/sandbox/plugins/maven-remote-resources-plugin/README.txt Mon Jan 22 12:17:32 2007
@@ -0,0 +1,17 @@
+
+This is in the sandbox to allow fixing some bugs from a non-maven committer.
+
+Currently, it has fixes for the following bugs:
+
+
+Done by Dan Kulp: (dkulp@apache.org)
+MRRESOURCES-2 Support an "append" mode for local resources
+MRRESOURCES-3 Plugin does not populate the projects needed for the notices file
+MRRESOURCES-4 If not resourceBundles specified (or element miss-spelled) you get a NullPointerException
+MRRESOURCES-5 Uses hardcodes src/main/resources for location of overriding resources
+
+Notes:
+MRRESOURCES-3: For this to work for the NOTICE.txt file, you NEED to use a new version of apache-jar-resource-bundle
+ which is also in the sandbox: https://svn.apache.org/repos/asf/maven/sandbox/resources/apache-jar-resource-bundle
+
+
Propchange: maven/sandbox/plugins/maven-remote-resources-plugin/README.txt
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/sandbox/plugins/maven-remote-resources-plugin/README.txt
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: maven/sandbox/plugins/maven-remote-resources-plugin/src/main/java/org/apache/maven/plugin/resources/remote/ProcessRemoteResourcesMojo.java
URL: http://svn.apache.org/viewvc/maven/sandbox/plugins/maven-remote-resources-plugin/src/main/java/org/apache/maven/plugin/resources/remote/ProcessRemoteResourcesMojo.java?view=diff&rev=498781&r1=498780&r2=498781
==============================================================================
--- maven/sandbox/plugins/maven-remote-resources-plugin/src/main/java/org/apache/maven/plugin/resources/remote/ProcessRemoteResourcesMojo.java (original)
+++ maven/sandbox/plugins/maven-remote-resources-plugin/src/main/java/org/apache/maven/plugin/resources/remote/ProcessRemoteResourcesMojo.java Mon Jan 22 12:17:32 2007
@@ -21,12 +21,15 @@
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
+import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.InvalidRepositoryException;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.resources.remote.io.xpp3.RemoteResourcesBundleXpp3Reader;
import org.apache.maven.project.MavenProject;
+import org.apache.maven.project.MavenProjectBuilder;
+import org.apache.maven.project.ProjectBuildingException;
import org.apache.maven.project.ProjectUtils;
import org.apache.maven.shared.downloader.DownloadException;
import org.apache.maven.shared.downloader.DownloadNotFoundException;
@@ -39,10 +42,14 @@
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
import org.codehaus.plexus.velocity.VelocityComponent;
+import java.io.BufferedReader;
+import java.io.BufferedWriter;
import java.io.File;
+import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
+import java.io.PrintWriter;
import java.io.Writer;
import java.net.MalformedURLException;
import java.net.URL;
@@ -52,12 +59,14 @@
import java.util.Date;
import java.util.Enumeration;
import java.util.Iterator;
+import java.util.List;
/**
* Pull down resourceBundles containing remote resources and process the resources contained
* inside the artifact.
*
* @goal process
+ * @requiresDependencyResolution runtime
* @phase generate-resources
*/
public class ProcessRemoteResourcesMojo
@@ -90,14 +99,31 @@
* @parameter expression="${project.build.directory}/maven-shared-archive-resources"
*/
private File outputDirectory;
+
+ /**
+ * The directory containing extra information appended to the generated resources.
+ *
+ * @parameter expression="${basedir}/src/main/appended-resources"
+ */
+ private File appendedResourcesDirectory;
/**
* The resource bundles that will be retrieved and processed.
*
* @parameter
+ * @required
*/
private ArrayList resourceBundles;
-
+
+ /**
+ * The list of resources defined for the project.
+ *
+ * @parameter expression="${project.resources}"
+ * @required
+ */
+ private List resources;
+
+
/**
* Artifact downloader.
*
@@ -130,6 +156,17 @@
* @parameter expression="${session}"
*/
private MavenSession mavenSession;
+
+
+ /**
+ * Artifact factory, needed to create projects from the artifacts.
+ *
+ * @component role="org.apache.maven.project.MavenProjectBuilder"
+ * @required
+ * @readonly
+ */
+ protected MavenProjectBuilder mavenProjectBuilder;
+
public void execute()
throws MojoExecutionException
@@ -141,8 +178,6 @@
RemoteResourcesClassLoader classLoader = new RemoteResourcesClassLoader();
- File standardResourcesDirectory = new File( project.getBasedir(), "src/main/resources" );
-
int bundleCount = 1;
for ( Iterator i = resourceBundles.iterator(); i.hasNext(); )
@@ -216,7 +251,8 @@
VelocityContext context = new VelocityContext();
context.put( "project", project );
-
+ context.put( "projects", getProjects() );
+
String year = new SimpleDateFormat( "yyyy" ).format( new Date() );
context.put( "presentYear", year );
@@ -255,22 +291,31 @@
// Don't overwrite resource that are already being provided.
- File projectResourceFile = new File( standardResourcesDirectory, projectResource );
-
File f = new File( outputDirectory, projectResource );
FileUtils.mkdir( f.getParentFile().getAbsolutePath() );
- if ( projectResourceFile.exists() )
- {
- FileUtils.copyFile( projectResourceFile, f );
- }
- else
+ if ( !copyResourceIfExists(f) )
{
- Writer writer = new FileWriter( f );
+ PrintWriter writer = new PrintWriter( new FileWriter( f ) );
velocity.getEngine().mergeTemplate( bundleResource, context, writer );
+ File appendedResourceFile = new File( appendedResourcesDirectory, projectResource);
+ if ( appendedResourceFile.exists() )
+ {
+ FileReader freader = new FileReader( appendedResourceFile );
+ BufferedReader breader = new BufferedReader( freader );
+
+ String line = breader.readLine();
+
+ while ( line != null )
+ {
+ writer.println( line );
+ line = breader.readLine();
+ }
+ }
+
writer.close();
}
}
@@ -321,5 +366,53 @@
{
throw new MojoExecutionException( "Error creating dot file for archiving instructions.", e );
}
+ }
+
+ protected List getProjects()
+ throws MojoExecutionException
+ {
+ List projects = new ArrayList();
+ for ( Iterator it = project.getArtifacts().iterator() ; it.hasNext() ; )
+ {
+ Artifact artifact = (Artifact) it.next();
+ try {
+ MavenProject p = mavenProjectBuilder.buildFromRepository(artifact,
+ remoteRepositories,
+ localRepository,
+ true);
+ projects.add(p);
+ } catch (ProjectBuildingException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ }
+ return projects;
+ }
+
+ protected boolean copyResourceIfExists(File file)
+ throws IOException
+ {
+ for ( Iterator i = resources.iterator(); i.hasNext(); )
+ {
+ Resource resource = (Resource) i.next();
+ File resourceDirectory = new File( resource.getDirectory() );
+
+ if ( !resourceDirectory.exists() )
+ {
+ continue;
+ }
+ //TODO - really should use the resource includes/excludes and name mapping
+ File source = new File(resourceDirectory, file.getName());
+ if ( source.exists() )
+ {
+ //TODO - should use filters here
+ FileUtils.copyFile(source, file);
+
+ return true;
+ }
+
+ }
+ return false;
}
}