Permalink
Browse files

Started trying out filtering.

  • Loading branch information...
1 parent 18f2cf4 commit e5aca2d1778a98b940ae8bf4fa9f6e3aa1b85b96 @nawroth nawroth committed Nov 28, 2011
View
@@ -33,6 +33,16 @@
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.apache.maven.shared</groupId>
+ <artifactId>maven-filtering</artifactId>
+ <version>1.0</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-assembly-plugin</artifactId>
+ <version>2.2.1</version>
+ </dependency>
</dependencies>
<build>
<pluginManagement>
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -25,6 +25,7 @@
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.MavenProjectHelper;
+import org.apache.maven.shared.filtering.MavenResourcesFiltering;
/**
* Goal which assembles docs.
@@ -53,11 +54,16 @@
*/
private MavenProjectHelper projectHelper;
+ /**
+ * @component
+ */
+ private MavenResourcesFiltering resourceFiltering;
+
@Override
public void execute() throws MojoExecutionException
{
DocsAssembler.assemble( project, getLog(), projectHelper,
- sourceDirectories );
+ sourceDirectories, resourceFiltering );
}
}
@@ -24,15 +24,21 @@
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
+import java.io.Reader;
import java.util.ArrayList;
import java.util.List;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
+import org.apache.maven.model.Resource;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.logging.Log;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.MavenProjectHelper;
+import org.apache.maven.shared.filtering.MavenFilteringException;
+import org.apache.maven.shared.filtering.MavenResourcesExecution;
+import org.apache.maven.shared.filtering.MavenResourcesFiltering;
+import org.codehaus.plexus.util.FileUtils;
public final class DocsAssembler
{
@@ -46,6 +52,8 @@
private final MavenProjectHelper projectHelper;
+ private MavenResourcesFiltering resourceFiltering;
+
private Log getLog()
{
return log;
@@ -59,6 +67,14 @@ private DocsAssembler( final MavenProject project, final Log log,
this.projectHelper = projectHelper;
}
+ public DocsAssembler( final MavenProject project, final Log log,
+ final MavenProjectHelper projectHelper,
+ final MavenResourcesFiltering resourceFiltering )
+ {
+ this( project, log, projectHelper );
+ this.resourceFiltering = resourceFiltering;
+ }
+
static File assemble( final MavenProject project, final Log log,
final MavenProjectHelper projectHelper,
final List<String> sourceDirectories )
@@ -69,10 +85,28 @@ static File assemble( final MavenProject project, final Log log,
return assembler.doAssembly( sourceDirectories );
}
+ static File assemble( final MavenProject project, final Log log,
+ final MavenProjectHelper projectHelper,
+ final List<String> sourceDirectories,
+ final MavenResourcesFiltering resourceFiltering )
+ throws MojoExecutionException
+ {
+ DocsAssembler assembler = new DocsAssembler( project, log,
+ projectHelper, resourceFiltering );
+ return assembler.doAssembly( sourceDirectories );
+ }
+
private File doAssembly( final List<String> sourceDirectories )
throws MojoExecutionException
{
- File destFile = createArchive( getDirectories( sourceDirectories ) );
+ List<File> dirs = getDirectories( sourceDirectories );
+
+ if ( resourceFiltering != null )
+ {
+ filterResources( dirs );
+ // TODO in this case, the filter target is the only one to zip.
+ }
+ File destFile = createArchive( dirs );
projectHelper.attachArtifact( project, "jar", "docs", destFile );
@@ -130,6 +164,43 @@ private File createArchive( final List<File> directories )
return destFile;
}
+ private void filterResources( final List<File> directories )
+ {
+ System.out.println( "lets filter resources ..." );
+ MavenResourcesExecution resourcesExecution = new MavenResourcesExecution();
+ resourcesExecution.setEncoding( "UTF-8" );
+ resourcesExecution.setMavenProject( project );
+ resourcesExecution.setOutputDirectory( new File( "target/gendocs" ) );
+ resourcesExecution.setResourcesBaseDirectory( new File( "target/x" ) );
+ resourcesExecution.addFilterWrapper( new FileUtils.FilterWrapper()
+ {
+ @Override
+ public Reader getReader( final Reader reader )
+ {
+ return reader;
+ }
+ } );
+ List<Resource> resources = new ArrayList<Resource>();
+ for ( File dir : directories )
+ {
+ Resource resource = new Resource();
+ resource.setDirectory( dir.getAbsolutePath() );
+ resource.setTargetPath( "target" );
+ resource.setFiltering( true );
+ resources.add( resource );
+ }
+ resourcesExecution.setResources( resources );
+ try
+ {
+ resourceFiltering.filterResources( resourcesExecution );
+ }
+ catch ( MavenFilteringException e )
+ {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
private void zipDirectory( final ZipOutputStream zipOut, final File dir )
throws MojoExecutionException
{
@@ -223,4 +294,3 @@ private void addDirectory( final File dir, final List<File> directories )
directories.add( dir );
}
}
-

0 comments on commit e5aca2d

Please sign in to comment.