Skip to content

Commit

Permalink
Configuration cleanup, better error handling, enabled dogfooding.
Browse files Browse the repository at this point in the history
  • Loading branch information
nawroth committed Dec 22, 2011
1 parent 3d0e1b6 commit 37458f2
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 26 deletions.
48 changes: 33 additions & 15 deletions pom.xml
Expand Up @@ -47,29 +47,18 @@
</sourceDirectories>
</configuration>
-->
<!--
<configuration>
<executions>
<execution>
<id>assemble-docs</id>
<phase>package</phase>
<goals><goal>assemble</goal></goals>
</execution>
</executions>
</configuration>
-->
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
</plugin>
<plugin>
<artifactId>docs-maven-plugin</artifactId>
<groupId>org.neo4j.build.plugins</groupId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<executions>
Expand Down Expand Up @@ -160,4 +149,33 @@
</dependency>
</dependencies>
</dependencyManagement>

<profiles>
<profile>
<id>enable-dogfooding-plugin</id>
<activation>
<activeByDefault>false</activeByDefault>
<property>
<name>dogfood</name>
</property>
</activation>
<build>
<pluginManagement>
<plugins>
<plugin>
<artifactId>docs-maven-plugin</artifactId>
<groupId>org.neo4j.build.plugins</groupId>
<executions>
<execution>
<id>assemble-docs</id>
<goals><goal>assemble</goal></goals>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>
</profile>
</profiles>

</project>
Expand Up @@ -32,6 +32,7 @@
* Goal which assembles docs.
*
* @goal assemble
* @phase package
*/
public class AssembleMojo extends AbstractMojo
{
Expand Down
41 changes: 30 additions & 11 deletions src/main/java/org/neo4j/build/plugins/docs/DocsAssembler.java
Expand Up @@ -29,6 +29,7 @@
import java.util.Collections;
import java.util.List;
import java.util.zip.ZipEntry;
import java.util.zip.ZipException;
import java.util.zip.ZipOutputStream;

import org.apache.maven.execution.MavenSession;
Expand All @@ -44,11 +45,13 @@

public final class DocsAssembler
{
private static final String TYPE = "jar";
private static final String DOCS_DIRNAME = "docs";

private static final String CLASSIFIER = "docs";

private static final int BUFFER_SIZE = 1024;
private static final String TYPE = "jar";

private static final int BUFFER_SIZE = 4096;

private int currentBaseDirPathLength;

Expand All @@ -62,6 +65,8 @@ public final class DocsAssembler

private MavenSession session;

private ZipOutputStream zipOut;

private Log getLog()
{
return log;
Expand Down Expand Up @@ -132,7 +137,7 @@ private File createArchive( final List<File> directories )
}

FileOutputStream fileOut = null;
ZipOutputStream zipOut = null;
zipOut = null;
try
{
fileOut = new FileOutputStream( destFile );
Expand All @@ -143,7 +148,7 @@ private File createArchive( final List<File> directories )
currentBaseDirPathLength = dir.getAbsolutePath()
.length();
getLog().info( "Adding source directory: " + dir );
zipDirectory( zipOut, dir );
zipDirectory( dir );
}
}
catch ( FileNotFoundException e )
Expand All @@ -158,6 +163,17 @@ private File createArchive( final List<File> directories )
{
zipOut.close();
}
catch ( ZipException e )
{
if ( "ZIP file must have at least one entry".equals( e.getMessage() ) )
{
getLog().warn( "There were no docs to assemble." );
}
else
{
getLog().error( e );
}
}
catch ( IOException e )
{
getLog().error( e );
Expand Down Expand Up @@ -186,8 +202,7 @@ private void filterResources( final List<File> directories, File targetDir )

MavenResourcesExecution resourcesExecution = new MavenResourcesExecution(
resources, targetDir, project, "UTF-8",
Collections.<Object>emptyList(), Collections.emptyList(),
session );
Collections.emptyList(), Collections.emptyList(), session );
resourcesExecution.setResourcesBaseDirectory( project.getBasedir() );
resourcesExecution.addFilterWrapper( new FileUtils.FilterWrapper()
{
Expand All @@ -207,16 +222,15 @@ public Reader getReader( final Reader reader )
}
}

private void zipDirectory( final ZipOutputStream zipOut, final File dir )
throws MojoExecutionException
private void zipDirectory( final File dir ) throws MojoExecutionException
{
byte[] buf = new byte[BUFFER_SIZE];

for ( File file : dir.listFiles() )
{
if ( file.isDirectory() )
{
zipDirectory( zipOut, file );
zipDirectory( file );
continue;
}
FileInputStream inFile = null;
Expand Down Expand Up @@ -265,9 +279,9 @@ private List<File> getDirectories( final List<String> sourceDirectories )
// add default directories
// ./src/docs and ./target/docs
addDirectory( new File( new File( project.getBasedir(), "src" ),
CLASSIFIER ), directories );
DOCS_DIRNAME ), directories );
addDirectory( new File( project.getBuild()
.getDirectory(), CLASSIFIER ), directories );
.getDirectory(), DOCS_DIRNAME ), directories );
}
else
{
Expand All @@ -287,6 +301,11 @@ private void addDirectory( final File dir, final List<File> directories )
getLog().info( "Skipping, does not exist: " + dir );
return;
}
if ( dir.listFiles().length == 0 )
{
getLog().info( "Skipping, is empty: " + dir );
return;
}
if ( !dir.isDirectory() )
{
throw new MojoExecutionException( "Not a directory: "
Expand Down

0 comments on commit 37458f2

Please sign in to comment.