You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by cs...@apache.org on 2011/03/30 12:08:07 UTC
svn commit: r1086891 - in /maven/indexer/trunk/indexer-core: ./
src/main/java/org/apache/maven/index/util/
src/main/java/org/apache/maven/index/util/zip/
Author: cstamas
Date: Wed Mar 30 10:08:07 2011
New Revision: 1086891
URL: http://svn.apache.org/viewvc?rev=1086891&view=rev
Log:
Added ZipFacade, ZipHandle and two implementations.
Added:
maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/util/
maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/util/zip/
maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/util/zip/AbstractZipHandle.java (with props)
maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/util/zip/DefaultZipFacade.java (with props)
maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/util/zip/EntryNameFilter.java (with props)
maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/util/zip/JavaZipFileHandle.java (with props)
maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/util/zip/TrueZipZipFileHandle.java (with props)
maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/util/zip/ZipFacade.java (with props)
maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/util/zip/ZipHandle.java (with props)
Modified:
maven/indexer/trunk/indexer-core/pom.xml
Modified: maven/indexer/trunk/indexer-core/pom.xml
URL: http://svn.apache.org/viewvc/maven/indexer/trunk/indexer-core/pom.xml?rev=1086891&r1=1086890&r2=1086891&view=diff
==============================================================================
--- maven/indexer/trunk/indexer-core/pom.xml (original)
+++ maven/indexer/trunk/indexer-core/pom.xml Wed Mar 30 10:08:07 2011
@@ -1,23 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
-<!--
-Licensed to the Apache Software Foundation (ASF) under one
-or more contributor license agreements. See the NOTICE file
-distributed with this work for additional information
-regarding copyright ownership. The ASF licenses this file
-to you under the Apache License, Version 2.0 (the
-"License"); you may not use this file except in compliance
-with the License. You may obtain a copy of the License at
-
-http://www.apache.org/licenses/LICENSE-2.0
-
-Unless required by applicable law or agreed to in writing,
-software distributed under the License is distributed on an
-"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-KIND, either express or implied. See the License for the
-specific language governing permissions and limitations
-under the License.
- -->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+<!-- Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under
+ the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may
+ obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to
+ in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
+ ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under
+ the License. -->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
@@ -36,6 +26,7 @@ under the License.
<aether.version>1.8</aether.version>
<archetype.version>2.0-alpha-4</archetype.version>
<wagon.version>1.0-beta-7</wagon.version>
+ <truezip.version>7.0-rc1</truezip.version>
</properties>
<!-- IMPORTANT! * WHEN YOU CHANGE DEPS MAKE SURE TO UPDATE SHADE CONFIG! * DON'T FORGET OTHERWISE YOU ARE RENDERING CLI
@@ -175,6 +166,20 @@ under the License.
<optional>true</optional>
</dependency>
+ <!-- ZipFacade -->
+ <dependency>
+ <groupId>de.schlichtherle.truezip</groupId>
+ <artifactId>truezip-file</artifactId>
+ <version>${truezip.version}</version>
+ <optional>true</optional>
+ </dependency>
+ <dependency>
+ <groupId>de.schlichtherle.truezip</groupId>
+ <artifactId>truezip-driver-zip</artifactId>
+ <version>${truezip.version}</version>
+ <optional>true</optional>
+ </dependency>
+
<!-- Test -->
<dependency>
<groupId>junit</groupId>
@@ -227,6 +232,7 @@ under the License.
<keepDependenciesWithProvidedScope>true</keepDependenciesWithProvidedScope>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ComponentsXmlResourceTransformer" />
+ <transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" />
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>org.apache.maven.index.cli.NexusIndexerCli</mainClass>
</transformer>
@@ -247,6 +253,10 @@ under the License.
<include>org.sonatype.sisu:sisu-inject-plexus</include>
<include>org.sonatype.sisu:sisu-inject-bean</include>
<include>org.sonatype.sisu:sisu-guice:jar:noaop</include>
+ <include>de.schlichtherle.truezip:truezip-kernel</include>
+ <include>de.schlichtherle.truezip:truezip-file</include>
+ <include>de.schlichtherle.truezip:truezip-driver-zip</include>
+ <include>de.schlichtherle.truezip:truezip-driver-file</include>
</includes>
</artifactSet>
</configuration>
Added: maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/util/zip/AbstractZipHandle.java
URL: http://svn.apache.org/viewvc/maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/util/zip/AbstractZipHandle.java?rev=1086891&view=auto
==============================================================================
--- maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/util/zip/AbstractZipHandle.java (added)
+++ maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/util/zip/AbstractZipHandle.java Wed Mar 30 10:08:07 2011
@@ -0,0 +1,25 @@
+package org.apache.maven.index.util.zip;
+
+import java.io.File;
+
+public abstract class AbstractZipHandle
+ implements ZipHandle
+{
+ private final File targetFile;
+
+ public AbstractZipHandle( final File targetFile )
+ {
+ if ( targetFile == null || !targetFile.isFile() )
+ {
+ throw new IllegalArgumentException(
+ "The targetFile may not be null, and has to point to an existing file (not a directory!)" );
+ }
+
+ this.targetFile = targetFile;
+ }
+
+ public File getTargetFile()
+ {
+ return targetFile;
+ }
+}
Propchange: maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/util/zip/AbstractZipHandle.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/util/zip/AbstractZipHandle.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/util/zip/DefaultZipFacade.java
URL: http://svn.apache.org/viewvc/maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/util/zip/DefaultZipFacade.java?rev=1086891&view=auto
==============================================================================
--- maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/util/zip/DefaultZipFacade.java (added)
+++ maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/util/zip/DefaultZipFacade.java Wed Mar 30 10:08:07 2011
@@ -0,0 +1,52 @@
+package org.apache.maven.index.util.zip;
+
+import java.io.File;
+import java.io.IOException;
+
+import org.codehaus.plexus.component.annotations.Component;
+
+@Component( role = ZipFacade.class )
+public class DefaultZipFacade
+ implements ZipFacade
+{
+ public static final long MEGABYTE = 1048576L;
+
+ public static final long JAVA_ZIPFILE_SIZE_THRESHOLD = Long.getLong(
+ "org.apache.maven.index.util.zip.DefaultZipFacade.javaZipFileSizeThreshold", 100L * MEGABYTE );
+
+ private static final boolean TRUEZIP_AVAILABLE;
+
+ static
+ {
+ Class<?> clazz;
+
+ try
+ {
+ clazz = Class.forName( "de.schlichtherle.truezip.zip.ZipFile" );
+ }
+ catch ( ClassNotFoundException e )
+ {
+ clazz = null;
+ }
+
+ TRUEZIP_AVAILABLE = clazz != null;
+ }
+
+ public ZipHandle getZipHandle( File targetFile )
+ throws IOException
+ {
+ if ( targetFile.isFile() )
+ {
+ if ( TRUEZIP_AVAILABLE && targetFile.length() > JAVA_ZIPFILE_SIZE_THRESHOLD )
+ {
+ return new TrueZipZipFileHandle( targetFile );
+ }
+ else
+ {
+ return new JavaZipFileHandle( targetFile );
+ }
+ }
+
+ throw new IOException( "The targetFile should point to an existing ZIP file!" );
+ }
+}
Propchange: maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/util/zip/DefaultZipFacade.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/util/zip/DefaultZipFacade.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/util/zip/EntryNameFilter.java
URL: http://svn.apache.org/viewvc/maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/util/zip/EntryNameFilter.java?rev=1086891&view=auto
==============================================================================
--- maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/util/zip/EntryNameFilter.java (added)
+++ maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/util/zip/EntryNameFilter.java Wed Mar 30 10:08:07 2011
@@ -0,0 +1,6 @@
+package org.apache.maven.index.util.zip;
+
+public interface EntryNameFilter
+{
+ boolean accepts( String entryName );
+}
Propchange: maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/util/zip/EntryNameFilter.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/util/zip/EntryNameFilter.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/util/zip/JavaZipFileHandle.java
URL: http://svn.apache.org/viewvc/maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/util/zip/JavaZipFileHandle.java?rev=1086891&view=auto
==============================================================================
--- maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/util/zip/JavaZipFileHandle.java (added)
+++ maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/util/zip/JavaZipFileHandle.java Wed Mar 30 10:08:07 2011
@@ -0,0 +1,91 @@
+package org.apache.maven.index.util.zip;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.List;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipFile;
+
+public class JavaZipFileHandle
+ extends AbstractZipHandle
+ implements ZipHandle
+{
+ private final ZipFile zipFile;
+
+ public JavaZipFileHandle( final File targetFile )
+ throws IOException
+ {
+ super( targetFile );
+
+ this.zipFile = new ZipFile( targetFile );
+ }
+
+ protected ZipFile getZipFile()
+ {
+ return zipFile;
+ }
+
+ public boolean hasEntry( String path )
+ throws IOException
+ {
+ return getZipFile().getEntry( path ) != null;
+ }
+
+ public List<String> getEntries()
+ {
+ return getEntries( new EntryNameFilter()
+ {
+ public boolean accepts( String entryName )
+ {
+ return true;
+ }
+ } );
+ }
+
+ public List<String> getEntries( EntryNameFilter filter )
+ {
+ ArrayList<String> entries = new ArrayList<String>();
+
+ Enumeration<? extends ZipEntry> en = getZipFile().entries();
+
+ while ( en.hasMoreElements() )
+ {
+ final ZipEntry e = en.nextElement();
+
+ final String name = e.getName();
+
+ if ( filter != null && !filter.accepts( name ) )
+ {
+ continue;
+ }
+
+ entries.add( name );
+ }
+
+ return entries;
+ }
+
+ public InputStream getEntryContent( String path )
+ throws IOException
+ {
+ ZipEntry entry = getZipFile().getEntry( path );
+
+ if ( entry != null )
+ {
+ return getZipFile().getInputStream( entry );
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ public void close()
+ throws IOException
+ {
+ getZipFile().close();
+ }
+}
Propchange: maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/util/zip/JavaZipFileHandle.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/util/zip/JavaZipFileHandle.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/util/zip/TrueZipZipFileHandle.java
URL: http://svn.apache.org/viewvc/maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/util/zip/TrueZipZipFileHandle.java?rev=1086891&view=auto
==============================================================================
--- maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/util/zip/TrueZipZipFileHandle.java (added)
+++ maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/util/zip/TrueZipZipFileHandle.java Wed Mar 30 10:08:07 2011
@@ -0,0 +1,93 @@
+package org.apache.maven.index.util.zip;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.List;
+
+import de.schlichtherle.truezip.zip.ZipEntry;
+import de.schlichtherle.truezip.zip.ZipFile;
+
+public class TrueZipZipFileHandle
+ extends AbstractZipHandle
+ implements ZipHandle
+{
+ private final ZipFile zipFile;
+
+ public TrueZipZipFileHandle( final File targetFile )
+ throws IOException
+ {
+ super( targetFile );
+
+ this.zipFile = new ZipFile( targetFile );
+ }
+
+ protected ZipFile getZipFile()
+ {
+ return zipFile;
+ }
+
+ public boolean hasEntry( String path )
+ throws IOException
+ {
+ return getZipFile().getEntry( path ) != null;
+ }
+
+ public List<String> getEntries()
+ {
+ return getEntries( new EntryNameFilter()
+ {
+ public boolean accepts( String entryName )
+ {
+ return true;
+ }
+ } );
+ }
+
+ public List<String> getEntries( EntryNameFilter filter )
+ {
+ ArrayList<String> entries = new ArrayList<String>();
+
+ Enumeration<? extends ZipEntry> en = getZipFile().entries();
+
+ while ( en.hasMoreElements() )
+ {
+ final ZipEntry e = en.nextElement();
+
+ final String name = e.getName();
+
+ if ( filter != null && !filter.accepts( name ) )
+ {
+ continue;
+ }
+
+ entries.add( name );
+ }
+
+ return entries;
+ }
+
+ public InputStream getEntryContent( String path )
+ throws IOException
+ {
+ ZipEntry entry = getZipFile().getEntry( path );
+
+ if ( entry != null )
+ {
+ return getZipFile().getInputStream( entry );
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ public void close()
+ throws IOException
+ {
+ getZipFile().close();
+ }
+
+}
Propchange: maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/util/zip/TrueZipZipFileHandle.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/util/zip/TrueZipZipFileHandle.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/util/zip/ZipFacade.java
URL: http://svn.apache.org/viewvc/maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/util/zip/ZipFacade.java?rev=1086891&view=auto
==============================================================================
--- maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/util/zip/ZipFacade.java (added)
+++ maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/util/zip/ZipFacade.java Wed Mar 30 10:08:07 2011
@@ -0,0 +1,10 @@
+package org.apache.maven.index.util.zip;
+
+import java.io.File;
+import java.io.IOException;
+
+public interface ZipFacade
+{
+ ZipHandle getZipHandle( File targetFile )
+ throws IOException;
+}
Propchange: maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/util/zip/ZipFacade.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/util/zip/ZipFacade.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/util/zip/ZipHandle.java
URL: http://svn.apache.org/viewvc/maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/util/zip/ZipHandle.java?rev=1086891&view=auto
==============================================================================
--- maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/util/zip/ZipHandle.java (added)
+++ maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/util/zip/ZipHandle.java Wed Mar 30 10:08:07 2011
@@ -0,0 +1,54 @@
+package org.apache.maven.index.util.zip;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.List;
+
+/**
+ * A very simplistic approach to hide the underlying mech to deal with ZipFiles, suited for use cases happening in Maven
+ * Indexer.
+ *
+ * @author cstamas
+ */
+public interface ZipHandle
+{
+ /**
+ * Returns true if Zip file this handle is pointing to contains an entry at given path.
+ *
+ * @param path
+ * @return
+ */
+ boolean hasEntry( String path )
+ throws IOException;
+
+ /**
+ * Returns a list of string, with each string representing a valid path for existing entry in this Zip handle.
+ *
+ * @return
+ */
+ List<String> getEntries();
+
+ /**
+ * Returns a list of string, with each string representing a valid path for existing entry in this Zip handle.
+ *
+ * @return
+ */
+ List<String> getEntries( EntryNameFilter filter );
+
+ /**
+ * Returns the "payload" (uncompressed) of the entry at given path, or null if no such path exists in the Zip file
+ * this handle points to.
+ *
+ * @param path
+ * @return
+ */
+ InputStream getEntryContent( String path )
+ throws IOException;
+
+ /**
+ * Closes the zip handle (performs resource cleanup). This method should be called when this zip handle is not
+ * needed anymore, and calling it should be obligatory to prevent resource leaks.
+ */
+ void close()
+ throws IOException;
+}
Propchange: maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/util/zip/ZipHandle.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/util/zip/ZipHandle.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision