Permalink
Browse files

Merge pull request #1 from nawroth/master

Fixes to make the dependency:unpack goal happy with the produced jar archives
  • Loading branch information...
simpsonjulian committed Feb 10, 2012
2 parents 51e9941 + 4e79504 commit 46148b66d5f81c1a9c47c31dee03a59fbd41d482
Showing with 78 additions and 109 deletions.
  1. +52 −0 pom.xml
  2. +26 −109 src/main/java/org/neo4j/build/plugins/docs/DocsAssembler.java
View
52 pom.xml
@@ -84,6 +84,10 @@
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.codehaus.plexus</groupId>
+ <artifactId>plexus-archiver</artifactId>
+ </dependency>
</dependencies>
<build>
<plugins>
@@ -422,6 +426,11 @@
<artifactId>maven-plugin-api</artifactId>
<version>3.0.3</version>
</dependency>
+ <dependency>
+ <groupId>org.codehaus.plexus</groupId>
+ <artifactId>plexus-archiver</artifactId>
+ <version>2.1</version>
+ </dependency>
<!-- testing -->
<dependency>
<groupId>junit</groupId>
@@ -533,6 +542,49 @@
</plugins>
</build>
</profile>
+ <profile>
+ <id>enable-docs-plugin--fulldogfooding</id>
+ <activation>
+ <activeByDefault>false</activeByDefault>
+ <property>
+ <name>dogfood2</name>
+ </property>
+ </activation>
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-dependency-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>unpack-docs</id>
+ <phase>package</phase>
+ <goals>
+ <goal>unpack-dependencies</goal>
+ </goals>
+ <configuration>
+ <classifier>docs</classifier>
+ <includeClassifiers>docs</includeClassifiers>
+ <excludeTransitive>true</excludeTransitive>
+ <useSubDirectoryPerArtifact>true</useSubDirectoryPerArtifact>
+ <stripVersion>true</stripVersion>
+ <excludes>META-INF,META-INF/**</excludes>
+ <type>jar</type>
+ <outputDirectory>target/test-unpacking</outputDirectory>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+ <dependencies>
+ <dependency>
+ <artifactId>docs-maven-plugin</artifactId>
+ <groupId>org.neo4j.build.plugins</groupId>
+ <version>${project.version}</version>
+ <classifier>docs</classifier>
+ </dependency>
+ </dependencies>
+ </profile>
<profile>
<id>sonatype-oss-release</id>
<build>
@@ -20,18 +20,12 @@
package org.neo4j.build.plugins.docs;
import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
import java.io.IOException;
import java.io.Reader;
import java.util.ArrayList;
import java.util.Arrays;
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;
import org.apache.maven.model.Resource;
@@ -42,6 +36,10 @@
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.archiver.Archiver;
+import org.codehaus.plexus.archiver.ArchiverException;
+import org.codehaus.plexus.archiver.jar.JarArchiver;
+import org.codehaus.plexus.archiver.util.DefaultFileSet;
import org.codehaus.plexus.util.FileUtils;
final class DocsAssembler
@@ -50,7 +48,6 @@
static final String TYPE = "jar";
- private static final int BUFFER_SIZE = 4096;
private static final String DOCS_DIRNAME = "docs";
private static final List<String> NON_FILTERED_FILE_EXTENSIONS;
@@ -102,7 +99,16 @@ public File doAssembly() throws MojoExecutionException
{
File target = new File( new File( project.getBuild()
.getDirectory() ), "filtered-docs" );
- deleteRecursively( target );
+ try
+ {
+ FileUtils.cleanDirectory( target );
+ }
+ catch ( IOException e )
+ {
+ log.error( e );
+ throw new MojoExecutionException(
+ "Could not remove old filtered files.", e );
+ }
filterResources( dirs, target );
destinationFile = createArchive( Collections.singletonList( target ) );
}
@@ -139,49 +145,28 @@ private File createArchive( final List<File> directories )
+ destFile.getAbsolutePath() );
}
- FileOutputStream fileOut;
- ZipOutputStream zipOut = null;
+ Archiver archiver = new JarArchiver();
+ archiver.setDestFile( destFile );
+
try
{
- fileOut = new FileOutputStream( destFile );
- zipOut = new ZipOutputStream( fileOut );
-
for ( File dir : directories )
{
- int currentBaseDirPathLength = dir.getAbsolutePath()
- .length();
- log.info( "Adding source directory: " + dir );
- zipDirectory( dir, currentBaseDirPathLength, zipOut );
+ DefaultFileSet fileSet = new DefaultFileSet();
+ fileSet.setDirectory( dir );
+ archiver.addFileSet( fileSet );
}
+ archiver.createArchive();
}
- catch ( FileNotFoundException e )
+ catch ( ArchiverException e )
{
log.error( e );
+ throw new MojoExecutionException( "Error building archive.", e );
}
- finally
+ catch ( IOException e )
{
- if ( zipOut != null )
- {
- try
- {
- zipOut.close();
- }
- catch ( ZipException e )
- {
- if ( "ZIP file must have at least one entry".equals( e.getMessage() ) )
- {
- log.warn( "There were no docs to assemble." );
- }
- else
- {
- log.error( e );
- }
- }
- catch ( IOException e )
- {
- log.error( e );
- }
- }
+ log.error( e );
+ throw new MojoExecutionException( "Error building archive.", e );
}
return destFile;
}
@@ -225,53 +210,6 @@ public Reader getReader( final Reader reader )
}
}
- private void zipDirectory( final File dir, int currentBaseDirPathLength, ZipOutputStream zipOut ) throws MojoExecutionException
- {
- byte[] buf = new byte[BUFFER_SIZE];
-
- for ( File file : dir.listFiles() )
- {
- if ( file.isDirectory() )
- {
- zipDirectory( file, currentBaseDirPathLength, zipOut );
- continue;
- }
- FileInputStream inFile = null;
- try
- {
- log.debug( "Adding: " + file.getAbsolutePath() );
- inFile = new FileInputStream( file.getAbsolutePath() );
- zipOut.putNextEntry( new ZipEntry( file.getAbsolutePath()
- .substring( currentBaseDirPathLength ) ) );
- int len;
- while ( ( len = inFile.read( buf ) ) > 0 )
- {
- zipOut.write( buf, 0, len );
- }
- }
- catch ( FileNotFoundException e )
- {
- log.error( e );
- }
- catch ( IOException e )
- {
- log.error( e );
- }
- finally
- {
- try
- {
- zipOut.closeEntry();
- inFile.close();
- }
- catch ( IOException e )
- {
- log.error( e );
- }
- }
- }
- }
-
private List<File> getDirectories( final List<String> sourceDirectories )
throws MojoExecutionException
{
@@ -321,25 +259,4 @@ 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 delete directory. Offending file:" + file );
- }
- }
}

0 comments on commit 46148b6

Please sign in to comment.