1 package org.apache.maven.archiva.indexer.record;
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
22 import org.apache.maven.artifact.Artifact;
23 import org.codehaus.plexus.digest.Digester;
26 import java.io.IOException;
27 import java.util.ArrayList;
28 import java.util.Arrays;
29 import java.util.HashSet;
30 import java.util.Iterator;
31 import java.util.List;
35 * An index record type for the minimal index.
37 * @author Edwin Punzalan
38 * @author Brett Porter
39 * @plexus.component role="org.apache.maven.archiva.indexer.record.RepositoryIndexRecordFactory" role-hint="minimal"
41 public class MinimalArtifactIndexRecordFactory
42 extends AbstractArtifactIndexRecordFactory
44 /* List of types to index. */
45 private static final Set INDEXED_TYPES = new HashSet( Arrays.asList( new String[]{"jar", "maven-plugin"} ) );
48 * @plexus.requirement role-hint="sha1"
50 protected Digester sha1Digester;
53 * @plexus.requirement role-hint="md5"
55 protected Digester md5Digester;
57 public RepositoryIndexRecord createRecord( Artifact artifact )
59 MinimalArtifactIndexRecord record = null;
61 File file = artifact.getFile();
62 if ( file != null && INDEXED_TYPES.contains( artifact.getType() ) && file.exists() )
64 String md5 = readChecksum( file, md5Digester );
69 files = readFilesInArchive( file );
71 catch ( IOException e )
73 getLogger().error( "Error reading artifact file, omitting from index: " + e.getMessage() );
78 record = new MinimalArtifactIndexRecord();
79 record.setMd5Checksum( md5 );
80 record.setFilename( artifact.getRepository().pathOf( artifact ) );
81 record.setLastModified( file.lastModified() );
82 record.setSize( file.length() );
83 record.setClasses( getClassesFromFiles( files ) );
89 private List getClassesFromFiles( List files )
91 List classes = new ArrayList();
93 for ( Iterator i = files.iterator(); i.hasNext(); )
95 String name = (String) i.next();
97 if ( isClass( name ) )
99 classes.add( name.substring( 0, name.length() - 6 ).replace( '/', '.' ) );