Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Code and dependencies cleanup.

  • Loading branch information...
commit 4582786c590b8ed51031a4920debc143d3f90879 1 parent d2c347d
@nawroth nawroth authored
View
95 pom.xml
@@ -11,20 +11,11 @@
<groupId>org.neo4j.build.plugins</groupId>
<packaging>maven-plugin</packaging>
<version>0.1-SNAPSHOT</version>
- <name>docs Maven Mojo</name>
- <url>http://maven.apache.org</url>
+ <name>Neo4j documentation assembler.</name>
+ <url>components.neo4j.org</url>
+
<dependencies>
<dependency>
- <groupId>org.apache.maven</groupId>
- <artifactId>maven-plugin-api</artifactId>
- <version>3.0.3</version>
- </dependency>
- <dependency>
- <groupId>org.apache.maven</groupId>
- <artifactId>maven-core</artifactId>
- <version>3.0.3</version>
- </dependency>
- <dependency>
<groupId>org.twdata.maven</groupId>
<artifactId>mojo-executor</artifactId>
<version>2.0</version>
@@ -90,5 +81,83 @@
</plugin>
</plugins>
</build>
+ <dependencyManagement>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-core</artifactId>
+ <version>3.0.3</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-settings</artifactId>
+ <version>3.0.3</version>
+ </dependency>
+ <dependency>
+ <groupId>org.codehaus.plexus</groupId>
+ <artifactId>plexus-utils</artifactId>
+ <version>2.0.6</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-model</artifactId>
+ <version>3.0.3</version>
+ </dependency>
+ <dependency>
+ <groupId>org.codehaus.plexus</groupId>
+ <artifactId>plexus-interpolation</artifactId>
+ <version>1.14</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-artifact</artifactId>
+ <version>3.0.3</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-plugin-api</artifactId>
+ <version>3.0.3</version>
+ </dependency>
+ <dependency>
+ <groupId>org.sonatype.aether</groupId>
+ <artifactId>aether-api</artifactId>
+ <version>1.11</version>
+ </dependency>
+ <dependency>
+ <groupId>org.sonatype.sisu</groupId>
+ <artifactId>sisu-inject-plexus</artifactId>
+ <version>2.1.1</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-repository-metadata</artifactId>
+ <version>3.0.3</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-project</artifactId>
+ <version>3.0-alpha-2</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-monitor</artifactId>
+ <version>2.2.1</version>
+ </dependency>
+ <dependency>
+ <groupId>org.codehaus.plexus</groupId>
+ <artifactId>plexus-container-default</artifactId>
+ <version>1.5.5</version>
+ </dependency>
+ <dependency>
+ <groupId>org.codehaus.plexus</groupId>
+ <artifactId>plexus-classworlds</artifactId>
+ <version>2.4</version>
+ </dependency>
+ <dependency>
+ <groupId>org.codehaus.plexus</groupId>
+ <artifactId>plexus-component-annotations</artifactId>
+ <version>1.5.5</version>
+ </dependency>
+ </dependencies>
+ </dependencyManagement>
</project>
-
View
3  src/docs/subdir1/file2.txt
@@ -0,0 +1,3 @@
+content2
+${project.groupId}
+
View
32 src/main/java/org/neo4j/build/plugins/docs/AssembleMojo.java
@@ -21,6 +21,7 @@
import java.util.List;
+import org.apache.maven.execution.MavenSession;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.project.MavenProject;
@@ -39,7 +40,14 @@
*
* @parameter
*/
- private List<String> sourceDirectories;
+ protected List<String> sourceDirectories;
+
+ /**
+ * If filtering should be applied to files.
+ *
+ * @parameter expression="${filter}" default-value="false"
+ */
+ protected boolean filter;
/**
* The maven project.
@@ -47,23 +55,31 @@
* @parameter expression="${project}"
* @readonly
*/
- private MavenProject project;
+ protected MavenProject project;
/**
* @component
*/
- private MavenProjectHelper projectHelper;
+ protected MavenProjectHelper projectHelper;
/**
- * @component
+ *
+ * @component role="org.apache.maven.shared.filtering.MavenResourcesFiltering" role-hint="default"
+ * @required
+ */
+ protected MavenResourcesFiltering resourceFiltering;
+
+ /**
+ * @parameter default-value="${session}"
+ * @readonly
+ * @required
*/
- private MavenResourcesFiltering resourceFiltering;
+ protected MavenSession session;
@Override
public void execute() throws MojoExecutionException
{
- DocsAssembler.assemble( project, getLog(), projectHelper,
- sourceDirectories, resourceFiltering );
+ DocsAssembler.assemble( sourceDirectories, filter, getLog(),
+ session, project, projectHelper, resourceFiltering );
}
}
-
View
100 src/main/java/org/neo4j/build/plugins/docs/DocsAssembler.java
@@ -31,6 +31,7 @@
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
+import org.apache.maven.execution.MavenSession;
import org.apache.maven.model.Resource;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.logging.Log;
@@ -55,58 +56,49 @@
private MavenResourcesFiltering resourceFiltering;
+ private MavenSession session;
+
private Log getLog()
{
return log;
}
- private DocsAssembler( final MavenProject project, final Log log,
- final MavenProjectHelper projectHelper )
+ public DocsAssembler( final MavenProject project, final Log log,
+ final MavenProjectHelper projectHelper,
+ final MavenResourcesFiltering resourceFiltering,
+ MavenSession session )
{
this.project = project;
this.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;
+ this.session = session;
}
- static File assemble( final MavenProject project, final Log log,
- final MavenProjectHelper projectHelper,
- final List<String> sourceDirectories )
+ static File assemble( final List<String> sourceDirectories, final boolean filter,
+ final Log log,
+ MavenSession session, final MavenProject project,
+ final MavenProjectHelper projectHelper, MavenResourcesFiltering resourceFiltering )
throws MojoExecutionException
{
DocsAssembler assembler = new DocsAssembler( project, log,
- projectHelper );
- return assembler.doAssembly( sourceDirectories );
+ projectHelper, resourceFiltering, session );
+ return assembler.doAssembly( sourceDirectories, filter );
}
- 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 )
+ private File doAssembly( final List<String> sourceDirectories,
+ final boolean filter )
throws MojoExecutionException
{
+ getLog().info( "Filtering is: " + ( filter ? "on" : "off" ) );
List<File> dirs = getDirectories( sourceDirectories );
File destFile = null;
- if ( resourceFiltering != null )
+ if ( filter )
{
File target = new File( new File( project.getBuild()
.getDirectory() ), "filtered-docs" );
+ deleteRecursively( target );
filterResources( dirs, target );
destFile = createArchive( Collections.singletonList( target ) );
}
@@ -177,38 +169,37 @@ private void filterResources( final List<File> directories, File targetDir )
int baseDirLength = project.getBasedir()
.getAbsolutePath()
.length() + 1;
- MavenResourcesExecution resourcesExecution = new MavenResourcesExecution();
- resourcesExecution.setEncoding( "UTF-8" );
- resourcesExecution.setMavenProject( project );
- resourcesExecution.setOutputDirectory( targetDir );
- resourcesExecution.setResourcesBaseDirectory( project.getBasedir() );
- 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()
.substring( baseDirLength ) );
- getLog().info( "Adding source directory: " + dir );
resource.setFiltering( true );
+ getLog().info( "Adding source directory: " + dir );
resources.add( resource );
}
- resourcesExecution.setResources( resources );
+
+ MavenResourcesExecution resourcesExecution = new MavenResourcesExecution(
+ resources, targetDir, project, "UTF-8",
+ Collections.<Object>emptyList(),
+ Collections.emptyList(), session );
+ resourcesExecution.setResourcesBaseDirectory( project.getBasedir() );
+ resourcesExecution.addFilterWrapper( new FileUtils.FilterWrapper()
+ {
+ @Override
+ public Reader getReader( final Reader reader )
+ {
+ return reader;
+ }
+ } );
try
{
resourceFiltering.filterResources( resourcesExecution );
}
catch ( MavenFilteringException e )
{
- // TODO Auto-generated catch block
- e.printStackTrace();
+ getLog().error( e );
}
}
@@ -304,4 +295,25 @@ private void addDirectory( final File dir, final List<File> directories )
}
directories.add( dir );
}
+
+ private static void deleteRecursively( File file )
+ {
+ if ( !file.exists() )
+ {
+ return;
+ }
+
+ if ( file.isDirectory() )
+ {
+ for ( File child : file.listFiles() )
+ {
+ deleteRecursively( child );
+ }
+ }
+ if ( !file.delete() )
+ {
+ throw new RuntimeException(
+ "Couldn't empty database. Offending file:" + file );
+ }
+ }
}
View
42 src/main/java/org/neo4j/build/plugins/docs/InstallMojo.java
@@ -31,14 +31,9 @@
import static org.twdata.maven.mojoexecutor.MojoExecutor.version;
import java.io.File;
-import java.util.List;
-import org.apache.maven.execution.MavenSession;
-import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.BuildPluginManager;
import org.apache.maven.plugin.MojoExecutionException;
-import org.apache.maven.project.MavenProject;
-import org.apache.maven.project.MavenProjectHelper;
/**
* Goal which installs docs. Note: requires Maven 3 for plugin management (as it
@@ -48,16 +43,9 @@
* @requiresDirectInvocation
* @requiresDependencyResolution test
*/
-public class InstallMojo extends AbstractMojo
+public class InstallMojo extends AssembleMojo
{
/**
- * Directories to include in the assembly.
- *
- * @parameter
- */
- private List<String> sourceDirectories;
-
- /**
* Test to execute.
*
* @parameter expression="${test}"
@@ -65,28 +53,6 @@
private String test;
/**
- * The maven project.
- *
- * @parameter expression="${project}"
- * @readonly
- */
- private MavenProject project;
-
- /**
- * @component
- */
- private MavenProjectHelper projectHelper;
-
- /**
- * The Maven Session Object
- *
- * @parameter expression="${session}"
- * @required
- * @readonly
- */
- private MavenSession session;
-
- /**
* The Maven PluginManager Object
*
* @component
@@ -117,8 +83,9 @@ private void executeTest() throws MojoExecutionException
private void assembleInstall() throws MojoExecutionException
{
- final File destFile = DocsAssembler.assemble( project, getLog(),
- projectHelper, sourceDirectories );
+ final File destFile = DocsAssembler.assemble( sourceDirectories, filter,
+ getLog(), session, project, projectHelper,
+ resourceFiltering );
final String file = destFile.getAbsolutePath();
final String pomFile = new File( project.getBasedir(), "pom.xml" ).getAbsolutePath();
@@ -143,4 +110,3 @@ private void assembleInstall() throws MojoExecutionException
executionEnvironment( project, session, pluginManager ) );
}
}
-
Please sign in to comment.
Something went wrong with that request. Please try again.