1 package org.apache.maven.archiva.indexer.search;
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.archiva.indexer.hashcodes.HashcodesRecord;
23 import org.apache.maven.archiva.indexer.hashcodes.HashcodesRecordLoader;
24 import org.apache.maven.archiva.model.ArchivaArtifact;
27 import java.util.HashMap;
29 import java.util.Map.Entry;
31 import junit.framework.AssertionFailedError;
34 * HashcodesIndexPopulator
36 * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
39 public class HashcodesIndexPopulator
40 implements IndexPopulator
43 public Map<String, ArchivaArtifact> getObjectMap()
45 Map<String, ArchivaArtifact> dumps = new HashMap<String, ArchivaArtifact>();
47 // archiva-common-1.0.jar.txt
48 dumps.put( "archiva-common",
49 createArchivaArtifact( "org.apache.maven.archiva", "archiva-common", "1.0", "", "jar" ) );
51 // continuum-webapp-1.0.3-SNAPSHOT.war.txt
52 dumps.put( "continuum-webapp", createArchivaArtifact( "org.apache.maven.continuum", "continuum-webapp",
53 "1.0.3-SNAPSHOT", "", "war" ) );
55 // daytrader-ear-1.1.ear.txt
56 dumps.put( "daytrader-ear", createArchivaArtifact( "org.apache.geronimo", "daytrader-ear", "1.1", "", "ear" ) );
58 // maven-archetype-simple-1.0-alpha-4.jar.txt
59 dumps.put( "maven-archetype-simple", createArchivaArtifact( "org.apache.maven", "maven-archetype-simple",
60 "1.0-alpha-4", "", "maven-archetype" ) );
62 // maven-help-plugin-2.0.2-20070119.121239-2.jar.txt
63 dumps.put( "maven-help-plugin", createArchivaArtifact( "org.apache.maven.plugins", "maven-help-plugin",
64 "2.0.2-20070119.121239-2", "", "maven-plugin" ) );
66 // redback-authorization-open-1.0-alpha-1-SNAPSHOT.jar.txt
67 dumps.put( "redback-authorization-open", createArchivaArtifact( "org.codehaus.plexus.redback",
68 "redback-authorization-open",
69 "1.0-alpha-1-SNAPSHOT", "", "jar" ) );
71 // testng-5.1-jdk15.jar.txt
72 dumps.put( "testng", createArchivaArtifact( "org.testng", "testng", "5.1", "jdk15", "jar" ) );
74 // wagon-provider-api-1.0-beta-3-20070209.213958-2.jar.txt
75 dumps.put( "wagon-provider-api", createArchivaArtifact( "org.apache.maven.wagon", "wagon-provider-api",
76 "1.0-beta-3-20070209.213958-2", "", "jar" ) );
81 public Map<String, HashcodesRecord> populate( File basedir )
83 Map<String, HashcodesRecord> records = new HashMap<String, HashcodesRecord>();
85 for ( Entry<String, ArchivaArtifact> entry : getObjectMap().entrySet() )
87 ArchivaArtifact artifact = entry.getValue();
88 File dumpFile = getDumpFile( basedir, artifact );
89 HashcodesRecord record = HashcodesRecordLoader.loadRecord( dumpFile, artifact );
90 record.setRepositoryId( "test-repo" );
91 records.put( entry.getKey(), record );
97 protected File getDumpFile( File basedir, ArchivaArtifact artifact )
99 File dumpDir = new File( basedir, "src/test/artifact-dumps" );
100 StringBuffer filename = new StringBuffer();
102 filename.append( artifact.getArtifactId() ).append( "-" ).append( artifact.getVersion() );
104 if ( artifact.hasClassifier() )
106 filename.append( "-" ).append( artifact.getClassifier() );
109 filename.append( "." );
111 // TODO: use the ArtifactExtensionMapping object
112 if ( "maven-plugin".equals( artifact.getType() ) || "maven-archetype".equals( artifact.getType() ) )
114 filename.append( "jar" );
118 filename.append( artifact.getType() );
120 filename.append( ".txt" );
122 File dumpFile = new File( dumpDir, filename.toString() );
124 if ( !dumpFile.exists() )
126 throw new AssertionFailedError(
127 "Dump file " + dumpFile.getAbsolutePath() + " does not exist (should it?)." );
133 private ArchivaArtifact createArchivaArtifact( String groupId, String artifactId, String version, String classifier,
136 ArchivaArtifact artifact = new ArchivaArtifact( groupId, artifactId, version, classifier, type );