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.apache.maven.artifact.Artifact;
20 import org.codehaus.plexus.digest.Digester;
23 import java.io.IOException;
24 import java.util.ArrayList;
25 import java.util.Arrays;
26 import java.util.HashSet;
27 import java.util.Iterator;
28 import java.util.List;
32 * An index record type for the minimal index.
34 * @author Edwin Punzalan
35 * @author Brett Porter
36 * @plexus.component role="org.apache.maven.archiva.indexer.record.RepositoryIndexRecordFactory" role-hint="minimal"
38 public class MinimalArtifactIndexRecordFactory
39 extends AbstractArtifactIndexRecordFactory
41 /* List of types to index. */
42 private static final Set INDEXED_TYPES = new HashSet( Arrays.asList( new String[]{"jar", "maven-plugin"} ) );
45 * @plexus.requirement role-hint="sha1"
47 protected Digester sha1Digester;
50 * @plexus.requirement role-hint="md5"
52 protected Digester md5Digester;
54 public RepositoryIndexRecord createRecord( Artifact artifact )
56 MinimalArtifactIndexRecord record = null;
58 File file = artifact.getFile();
59 if ( file != null && INDEXED_TYPES.contains( artifact.getType() ) && file.exists() )
61 String md5 = readChecksum( file, md5Digester );
66 files = readFilesInArchive( file );
68 catch ( IOException e )
70 getLogger().error( "Error reading artifact file, omitting from index: " + e.getMessage() );
75 record = new MinimalArtifactIndexRecord();
76 record.setMd5Checksum( md5 );
77 record.setFilename( artifact.getRepository().pathOf( artifact ) );
78 record.setLastModified( file.lastModified() );
79 record.setSize( file.length() );
80 record.setClasses( getClassesFromFiles( files ) );
86 private List getClassesFromFiles( List files )
88 List classes = new ArrayList();
90 for ( Iterator i = files.iterator(); i.hasNext(); )
92 String name = (String) i.next();
94 if ( isClass( name ) )
96 classes.add( name.substring( 0, name.length() - 6 ).replace( '/', '.' ) );