1 package org.apache.maven.archiva.indexer.record;
4 * Copyright 2005-2006 The Apache Software Foundation.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
19 import org.codehaus.plexus.digest.Digester;
20 import org.codehaus.plexus.digest.DigesterException;
21 import org.codehaus.plexus.logging.AbstractLogEnabled;
24 import java.io.IOException;
25 import java.util.ArrayList;
26 import java.util.Enumeration;
27 import java.util.List;
28 import java.util.zip.ZipEntry;
29 import java.util.zip.ZipFile;
32 * Base class for the index record factories.
34 * @author <a href="mailto:brett@apache.org">Brett Porter</a>
36 public abstract class AbstractArtifactIndexRecordFactory
37 extends AbstractLogEnabled
38 implements RepositoryIndexRecordFactory
40 protected String readChecksum( File file, Digester digester )
45 checksum = digester.calc( file ).toLowerCase();
47 catch ( DigesterException e )
49 getLogger().error( "Error getting checksum for artifact file, leaving empty in index: " + e.getMessage() );
55 protected List readFilesInArchive( File file )
58 ZipFile zipFile = new ZipFile( file );
62 files = new ArrayList( zipFile.size() );
64 for ( Enumeration entries = zipFile.entries(); entries.hasMoreElements(); )
66 ZipEntry entry = (ZipEntry) entries.nextElement();
68 files.add( entry.getName() );
73 closeQuietly( zipFile );
78 protected static boolean isClass( String name )
80 // TODO: verify if class is public or protected (this might require the original ZipEntry)
81 return name.endsWith( ".class" ) && name.lastIndexOf( "$" ) < 0;
84 protected static void closeQuietly( ZipFile zipFile )
88 if ( zipFile != null )
93 catch ( IOException e )