From 2ded823736f8424afb627b67736aec1e253254cd Mon Sep 17 00:00:00 2001 From: Sylwester Lachiewicz Date: Sun, 23 Jun 2019 23:23:45 +0200 Subject: [PATCH 3/5] Remove dependency to TrueZip Credits to: Mat Booth --- indexer-cli/pom.xml | 19 --- indexer-core/pom.xml | 18 --- .../apache/maven/index/ArtifactContext.java | 14 +-- .../creator/JarFileContentsIndexCreator.java | 27 ++--- ...avenArchetypeArtifactInfoIndexCreator.java | 22 +--- .../MavenPluginArtifactInfoIndexCreator.java | 33 +----- .../creator/OsgiArtifactIndexCreator.java | 35 ++---- .../index/util/zip/AbstractZipHandle.java | 44 ------- .../maven/index/util/zip/EntryNameFilter.java | 25 ---- .../index/util/zip/JavaZipFileHandle.java | 110 ----------------- .../index/util/zip/TrueZipZipFileHandle.java | 112 ------------------ .../maven/index/util/zip/ZipFacade.java | 76 ------------ .../maven/index/util/zip/ZipHandle.java | 75 ------------ pom.xml | 32 ----- 14 files changed, 33 insertions(+), 609 deletions(-) delete mode 100644 indexer-core/src/main/java/org/apache/maven/index/util/zip/AbstractZipHandle.java delete mode 100644 indexer-core/src/main/java/org/apache/maven/index/util/zip/EntryNameFilter.java delete mode 100644 indexer-core/src/main/java/org/apache/maven/index/util/zip/JavaZipFileHandle.java delete mode 100644 indexer-core/src/main/java/org/apache/maven/index/util/zip/TrueZipZipFileHandle.java delete mode 100644 indexer-core/src/main/java/org/apache/maven/index/util/zip/ZipFacade.java delete mode 100644 indexer-core/src/main/java/org/apache/maven/index/util/zip/ZipHandle.java diff --git a/indexer-cli/pom.xml b/indexer-cli/pom.xml index 2c478e1..b961d50 100644 --- a/indexer-cli/pom.xml +++ b/indexer-cli/pom.xml @@ -77,16 +77,6 @@ under the License. 1.2 - - - de.schlichtherle.truezip - truezip-file - - - de.schlichtherle.truezip - truezip-driver-zip - - junit @@ -132,15 +122,6 @@ under the License. org.apache.maven.index.cli.NexusIndexerCli - - - org.bouncycastle:* - - META-INF/BCKEY.SF - META-INF/BCKEY.DSA - - - diff --git a/indexer-core/pom.xml b/indexer-core/pom.xml index a441ca7..5b3ea08 100644 --- a/indexer-core/pom.xml +++ b/indexer-core/pom.xml @@ -135,19 +135,6 @@ under the License. true - - - de.schlichtherle.truezip - truezip-file - true - - - - de.schlichtherle.truezip - truezip-driver-zip - true - - junit @@ -229,10 +216,6 @@ under the License. org.tartarus org.apache.maven.index_shaded.lucene - - org.bouncycastle - org.apache.maven.index_shaded.lucene - org.apache.commons.compress org.apache.maven.index_shaded.lucene @@ -253,7 +236,6 @@ under the License. org.apache.maven.archetype:* org.apache.maven.wagon:* org.codehaus.*:* - de.schlichtherle.truezip:* diff --git a/indexer-core/src/main/java/org/apache/maven/index/ArtifactContext.java b/indexer-core/src/main/java/org/apache/maven/index/ArtifactContext.java index 18a5e94..8803654 100644 --- a/indexer-core/src/main/java/org/apache/maven/index/ArtifactContext.java +++ b/indexer-core/src/main/java/org/apache/maven/index/ArtifactContext.java @@ -25,6 +25,8 @@ import java.io.InputStream; import java.nio.file.Files; import java.util.ArrayList; import java.util.List; +import java.util.zip.ZipEntry; +import java.util.zip.ZipFile; import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; @@ -32,8 +34,6 @@ import org.apache.lucene.document.StoredField; import org.apache.maven.index.artifact.Gav; import org.apache.maven.index.context.IndexCreator; import org.apache.maven.index.context.IndexingContext; -import org.apache.maven.index.util.zip.ZipFacade; -import org.apache.maven.index.util.zip.ZipHandle; import org.apache.maven.model.Model; import org.apache.maven.model.io.xpp3.MavenXpp3Reader; import org.codehaus.plexus.util.xml.pull.XmlPullParserException; @@ -103,16 +103,16 @@ public class ArtifactContext // Otherwise, check for pom contained in maven generated artifact else if ( getArtifact() != null && getArtifact().isFile() ) { - File artifact = getArtifact(); - try ( ZipHandle handle = ZipFacade.getZipHandle( artifact ) ) + try ( ZipFile zipFile = new ZipFile( artifact ) ) { - final String embeddedPomPath = "META-INF/maven/" + getGav().getGroupId() + "/" + getGav().getArtifactId() + "/pom.xml"; - if ( handle.hasEntry( embeddedPomPath ) ) + ZipEntry zipEntry = zipFile.getEntry( embeddedPomPath ); + + if ( zipEntry != null ) { - try ( InputStream inputStream = handle.getEntryContent( embeddedPomPath ) ) + try ( InputStream inputStream = zipFile.getInputStream( zipEntry ) ) { return new MavenXpp3Reader().read( inputStream, false ); } diff --git a/indexer-core/src/main/java/org/apache/maven/index/creator/JarFileContentsIndexCreator.java b/indexer-core/src/main/java/org/apache/maven/index/creator/JarFileContentsIndexCreator.java index 7f1c978..cd8cb89 100644 --- a/indexer-core/src/main/java/org/apache/maven/index/creator/JarFileContentsIndexCreator.java +++ b/indexer-core/src/main/java/org/apache/maven/index/creator/JarFileContentsIndexCreator.java @@ -25,7 +25,9 @@ import java.io.File; import java.io.IOException; import java.util.Arrays; import java.util.Collection; -import java.util.List; +import java.util.Enumeration; +import java.util.zip.ZipEntry; +import java.util.zip.ZipFile; import org.apache.lucene.document.Document; import org.apache.maven.index.ArtifactContext; @@ -33,8 +35,6 @@ import org.apache.maven.index.ArtifactInfo; import org.apache.maven.index.IndexerField; import org.apache.maven.index.IndexerFieldVersion; import org.apache.maven.index.MAVEN; -import org.apache.maven.index.util.zip.ZipFacade; -import org.apache.maven.index.util.zip.ZipHandle; import org.codehaus.plexus.util.StringUtils; /** @@ -156,18 +156,16 @@ public class JarFileContentsIndexCreator private void updateArtifactInfo( final ArtifactInfo ai, final File f, final String strippedPrefix ) throws IOException { - ZipHandle handle = null; - try + try ( ZipFile zipFile = new ZipFile( f ) ) { - handle = ZipFacade.getZipHandle( f ); - - final List entries = handle.getEntries(); + final Enumeration entries = zipFile.entries(); final StringBuilder sb = new StringBuilder(); - for ( String name : entries ) + while ( entries.hasMoreElements() ) { + String name = entries.nextElement().getName(); if ( name.endsWith( ".class" ) ) { // TODO verify if class is public or protected @@ -208,17 +206,6 @@ public class JarFileContentsIndexCreator ai.setClassNames( null ); } } - finally - { - try - { - ZipFacade.close( handle ); - } - catch ( Exception e ) - { - getLogger().error( "Could not close jar file properly.", e ); - } - } } @Override diff --git a/indexer-core/src/main/java/org/apache/maven/index/creator/MavenArchetypeArtifactInfoIndexCreator.java b/indexer-core/src/main/java/org/apache/maven/index/creator/MavenArchetypeArtifactInfoIndexCreator.java index bd6c759..cb2b2b7 100644 --- a/indexer-core/src/main/java/org/apache/maven/index/creator/MavenArchetypeArtifactInfoIndexCreator.java +++ b/indexer-core/src/main/java/org/apache/maven/index/creator/MavenArchetypeArtifactInfoIndexCreator.java @@ -22,17 +22,15 @@ package org.apache.maven.index.creator; import javax.inject.Named; import javax.inject.Singleton; import java.io.File; -import java.io.IOException; import java.util.Arrays; import java.util.Collection; import java.util.Collections; +import java.util.zip.ZipFile; import org.apache.lucene.document.Document; import org.apache.maven.index.ArtifactContext; import org.apache.maven.index.ArtifactInfo; import org.apache.maven.index.IndexerField; -import org.apache.maven.index.util.zip.ZipFacade; -import org.apache.maven.index.util.zip.ZipHandle; /** * A Maven Archetype index creator used to detect and correct the artifact packaging to "maven-archetype" if the @@ -85,15 +83,11 @@ public class MavenArchetypeArtifactInfoIndexCreator */ private void checkMavenArchetype( ArtifactInfo ai, File artifact ) { - ZipHandle handle = null; - - try + try ( ZipFile zipFile = new ZipFile( artifact ) ) { - handle = ZipFacade.getZipHandle( artifact ); - for ( String path : ARCHETYPE_XML_LOCATIONS ) { - if ( handle.hasEntry( path ) ) + if ( zipFile.getEntry( path ) != null ) { ai.setPackaging( MAVEN_ARCHETYPE_PACKAGING ); @@ -114,16 +108,6 @@ public class MavenArchetypeArtifactInfoIndexCreator "Failed to parse Maven artifact " + artifact.getAbsolutePath() + " due to " + e.getMessage() ); } } - finally - { - try - { - ZipFacade.close( handle ); - } - catch ( IOException ex ) - { - } - } } public void updateDocument( ArtifactInfo ai, Document doc ) diff --git a/indexer-core/src/main/java/org/apache/maven/index/creator/MavenPluginArtifactInfoIndexCreator.java b/indexer-core/src/main/java/org/apache/maven/index/creator/MavenPluginArtifactInfoIndexCreator.java index 694ad1a..dad2b32 100644 --- a/indexer-core/src/main/java/org/apache/maven/index/creator/MavenPluginArtifactInfoIndexCreator.java +++ b/indexer-core/src/main/java/org/apache/maven/index/creator/MavenPluginArtifactInfoIndexCreator.java @@ -23,12 +23,13 @@ import javax.inject.Named; import javax.inject.Singleton; import java.io.BufferedInputStream; import java.io.File; -import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; +import java.util.zip.ZipEntry; +import java.util.zip.ZipFile; import org.apache.lucene.document.Document; import org.apache.maven.index.ArtifactContext; @@ -36,8 +37,6 @@ import org.apache.maven.index.ArtifactInfo; import org.apache.maven.index.IndexerField; import org.apache.maven.index.IndexerFieldVersion; import org.apache.maven.index.MAVEN; -import org.apache.maven.index.util.zip.ZipFacade; -import org.apache.maven.index.util.zip.ZipHandle; import org.codehaus.plexus.configuration.PlexusConfiguration; import org.codehaus.plexus.configuration.xml.XmlPlexusConfiguration; import org.codehaus.plexus.util.xml.Xpp3DomBuilder; @@ -88,19 +87,13 @@ public class MavenPluginArtifactInfoIndexCreator private void checkMavenPlugin( ArtifactInfo ai, File artifact ) { - ZipHandle handle = null; - - try + try ( ZipFile zipFile = new ZipFile( artifact ) ) { - handle = ZipFacade.getZipHandle( artifact ); - final String pluginDescriptorPath = "META-INF/maven/plugin.xml"; - - if ( handle.hasEntry( pluginDescriptorPath ) ) + ZipEntry zipEntry = zipFile.getEntry( pluginDescriptorPath ); + if ( zipEntry != null ) { - InputStream is = new BufferedInputStream( handle.getEntryContent( pluginDescriptorPath ) ); - - try + try ( InputStream is = new BufferedInputStream( zipFile.getInputStream( zipEntry ) ) ) { // here the reader is closed PlexusConfiguration plexusConfig = @@ -117,10 +110,6 @@ public class MavenPluginArtifactInfoIndexCreator ai.getGoals().add( mojoConfig.getChild( "goal" ).getValue() ); } } - finally - { - is.close(); - } } } catch ( Exception e ) @@ -136,16 +125,6 @@ public class MavenPluginArtifactInfoIndexCreator "Failed to parse Maven artifact " + artifact.getAbsolutePath() + " due to " + e.getMessage() ); } } - finally - { - try - { - ZipFacade.close( handle ); - } - catch ( IOException e ) - { - } - } } public void updateDocument( ArtifactInfo ai, Document doc ) diff --git a/indexer-core/src/main/java/org/apache/maven/index/creator/OsgiArtifactIndexCreator.java b/indexer-core/src/main/java/org/apache/maven/index/creator/OsgiArtifactIndexCreator.java index 559d2da..7394e9e 100644 --- a/indexer-core/src/main/java/org/apache/maven/index/creator/OsgiArtifactIndexCreator.java +++ b/indexer-core/src/main/java/org/apache/maven/index/creator/OsgiArtifactIndexCreator.java @@ -28,8 +28,6 @@ import org.apache.maven.index.ArtifactInfo; import org.apache.maven.index.IndexerField; import org.apache.maven.index.IndexerFieldVersion; import org.apache.maven.index.OSGI; -import org.apache.maven.index.util.zip.ZipFacade; -import org.apache.maven.index.util.zip.ZipHandle; import org.codehaus.plexus.util.StringUtils; import java.io.File; @@ -40,9 +38,11 @@ import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.util.Arrays; import java.util.Collection; -import java.util.List; +import java.util.Enumeration; import java.util.jar.Attributes; import java.util.jar.Manifest; +import java.util.zip.ZipEntry; +import java.util.zip.ZipFile; /** * This indexCreator will index some OSGI metadatas. @@ -419,22 +419,19 @@ public class OsgiArtifactIndexCreator private boolean updateArtifactInfo( ArtifactInfo ai, File f ) throws IOException { - ZipHandle handle = null; - boolean updated = false; - - try + try ( ZipFile zipFile = new ZipFile( f ) ) { - handle = ZipFacade.getZipHandle( f ); - - final List entries = handle.getEntries(); + final Enumeration entries = zipFile.entries(); - for ( String name : entries ) + while ( entries.hasMoreElements() ) { - if ( name.equals( "META-INF/MANIFEST.MF" ) ) + ZipEntry zipEntry = entries.nextElement(); + + if ( zipEntry.getName().equals( "META-INF/MANIFEST.MF" ) ) { - Manifest manifest = new Manifest( handle.getEntryContent( name ) ); + Manifest manifest = new Manifest( zipFile.getInputStream( zipEntry ) ); Attributes mainAttributes = manifest.getMainAttributes(); @@ -596,18 +593,6 @@ public class OsgiArtifactIndexCreator } } } - - } - finally - { - try - { - ZipFacade.close( handle ); - } - catch ( Exception e ) - { - getLogger().error( "Could not close jar file properly.", e ); - } } // only calculate sha256 digest for if we are indexing a bundle. diff --git a/indexer-core/src/main/java/org/apache/maven/index/util/zip/AbstractZipHandle.java b/indexer-core/src/main/java/org/apache/maven/index/util/zip/AbstractZipHandle.java deleted file mode 100644 index 498db6f..0000000 --- a/indexer-core/src/main/java/org/apache/maven/index/util/zip/AbstractZipHandle.java +++ /dev/null @@ -1,44 +0,0 @@ -package org.apache.maven.index.util.zip; - -/* - * 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. - */ - -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; - } -} diff --git a/indexer-core/src/main/java/org/apache/maven/index/util/zip/EntryNameFilter.java b/indexer-core/src/main/java/org/apache/maven/index/util/zip/EntryNameFilter.java deleted file mode 100644 index 48a3935..0000000 --- a/indexer-core/src/main/java/org/apache/maven/index/util/zip/EntryNameFilter.java +++ /dev/null @@ -1,25 +0,0 @@ -package org.apache.maven.index.util.zip; - -/* - * 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. - */ - -public interface EntryNameFilter -{ - boolean accepts( String entryName ); -} diff --git a/indexer-core/src/main/java/org/apache/maven/index/util/zip/JavaZipFileHandle.java b/indexer-core/src/main/java/org/apache/maven/index/util/zip/JavaZipFileHandle.java deleted file mode 100644 index 1a1f74b..0000000 --- a/indexer-core/src/main/java/org/apache/maven/index/util/zip/JavaZipFileHandle.java +++ /dev/null @@ -1,110 +0,0 @@ -package org.apache.maven.index.util.zip; - -/* - * 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. - */ - -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 getEntries() - { - return getEntries( new EntryNameFilter() - { - public boolean accepts( String entryName ) - { - return true; - } - } ); - } - - public List getEntries( EntryNameFilter filter ) - { - ArrayList entries = new ArrayList(); - - Enumeration 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(); - } -} diff --git a/indexer-core/src/main/java/org/apache/maven/index/util/zip/TrueZipZipFileHandle.java b/indexer-core/src/main/java/org/apache/maven/index/util/zip/TrueZipZipFileHandle.java deleted file mode 100644 index 4ca7e8e..0000000 --- a/indexer-core/src/main/java/org/apache/maven/index/util/zip/TrueZipZipFileHandle.java +++ /dev/null @@ -1,112 +0,0 @@ -package org.apache.maven.index.util.zip; - -/* - * 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. - */ - -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 getEntries() - { - return getEntries( new EntryNameFilter() - { - public boolean accepts( String entryName ) - { - return true; - } - } ); - } - - public List getEntries( EntryNameFilter filter ) - { - ArrayList entries = new ArrayList(); - - Enumeration 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(); - } - -} diff --git a/indexer-core/src/main/java/org/apache/maven/index/util/zip/ZipFacade.java b/indexer-core/src/main/java/org/apache/maven/index/util/zip/ZipFacade.java deleted file mode 100644 index 1dcae06..0000000 --- a/indexer-core/src/main/java/org/apache/maven/index/util/zip/ZipFacade.java +++ /dev/null @@ -1,76 +0,0 @@ -package org.apache.maven.index.util.zip; - -/* - * 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. - */ - -import java.io.File; -import java.io.IOException; - -public class ZipFacade -{ - public static final long MEGABYTE = 1048576L; - - public static final long JAVA_ZIPFILE_SIZE_THRESHOLD = Long.getLong( - "org.apache.maven.index.util.zip.ZipFacade.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 static 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:" + targetFile ); - } - - public static void close( ZipHandle handle ) - throws IOException - { - if ( handle != null ) - { - handle.close(); - } - } -} diff --git a/indexer-core/src/main/java/org/apache/maven/index/util/zip/ZipHandle.java b/indexer-core/src/main/java/org/apache/maven/index/util/zip/ZipHandle.java deleted file mode 100644 index c278a68..0000000 --- a/indexer-core/src/main/java/org/apache/maven/index/util/zip/ZipHandle.java +++ /dev/null @@ -1,75 +0,0 @@ -package org.apache.maven.index.util.zip; - -/* - * 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. - */ - -import java.io.Closeable; -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 - extends Closeable -{ - /** - * 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 getEntries(); - - /** - * Returns a list of string, with each string representing a valid path for existing entry in this Zip handle. - * - * @return - */ - List 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; -} diff --git a/pom.xml b/pom.xml index c883e90..6f42633 100644 --- a/pom.xml +++ b/pom.xml @@ -92,7 +92,6 @@ under the License. 5.5.5 3.5.2 1.1.0 - 7.7.10 2.4 2.12 @@ -265,37 +264,6 @@ under the License. ${archetype.version} - - - de.schlichtherle.truezip - truezip-kernel - ${truezip.version} - - - com.google.code.findbugs - annotations - - - - - - de.schlichtherle.truezip - truezip-file - ${truezip.version} - - - - de.schlichtherle.truezip - truezip-driver-zip - ${truezip.version} - - - de.schlichtherle.truezip - truezip-swing - - - - junit -- 2.31.1