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.bytecode.BytecodeRecord;
23 import org.apache.maven.archiva.indexer.bytecode.BytecodeRecordLoader;
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 * BytecodeIndexPopulator
36 * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a>
39 public class BytecodeIndexPopulator
40 implements IndexPopulator
43 public Map<String,ArchivaArtifact> getObjectMap()
46 Map<String,ArchivaArtifact> dumps = new HashMap<String,ArchivaArtifact>();
48 // archiva-common-1.0.jar.txt
49 dumps.put( "archiva-common",
50 createArchivaArtifact( "org.apache.maven.archiva", "archiva-common", "1.0", "", "jar" ) );
52 // continuum-webapp-1.0.3-SNAPSHOT.war.txt
53 dumps.put( "continuum-webapp", createArchivaArtifact( "org.apache.maven.continuum", "continuum-webapp",
54 "1.0.3-SNAPSHOT", "", "war" ) );
56 // daytrader-ear-1.1.ear.txt
57 dumps.put( "daytrader-ear", createArchivaArtifact( "org.apache.geronimo", "daytrader-ear", "1.1", "", "ear" ) );
59 // maven-archetype-simple-1.0-alpha-4.jar.txt
60 dumps.put( "maven-archetype-simple", createArchivaArtifact( "org.apache.maven", "maven-archetype-simple",
61 "1.0-alpha-4", "", "maven-archetype" ) );
63 // maven-help-plugin-2.0.2-20070119.121239-2.jar.txt
64 dumps.put( "maven-help-plugin", createArchivaArtifact( "org.apache.maven.plugins", "maven-help-plugin",
65 "2.0.2-20070119.121239-2", "", "maven-plugin" ) );
67 // redback-authorization-open-1.0-alpha-1-SNAPSHOT.jar.txt
68 dumps.put( "redback-authorization-open", createArchivaArtifact( "org.codehaus.plexus.redback",
69 "redback-authorization-open",
70 "1.0-alpha-1-SNAPSHOT", "", "jar" ) );
72 // testng-5.1-jdk15.jar.txt
73 dumps.put( "testng", createArchivaArtifact( "org.testng", "testng", "5.1", "jdk15", "jar" ) );
75 // wagon-provider-api-1.0-beta-3-20070209.213958-2.jar.txt
76 dumps.put( "wagon-provider-api", createArchivaArtifact( "org.apache.maven.wagon", "wagon-provider-api",
77 "1.0-beta-3-20070209.213958-2", "", "jar" ) );
83 private ArchivaArtifact createArchivaArtifact( String groupId, String artifactId, String version, String classifier,
86 ArchivaArtifact artifact = new ArchivaArtifact( groupId, artifactId, version, classifier, type );
90 public Map<String, BytecodeRecord> populate( File basedir )
92 Map<String, BytecodeRecord> records = new HashMap<String, BytecodeRecord>();
94 for ( Entry<String, ArchivaArtifact> entry : getObjectMap().entrySet() )
96 ArchivaArtifact artifact = entry.getValue();
97 File dumpFile = getDumpFile( basedir, artifact );
98 BytecodeRecord record = BytecodeRecordLoader.loadRecord( dumpFile, artifact );
99 record.setRepositoryId( "test-repo" );
100 records.put( entry.getKey(), record );
106 protected File getDumpFile( File basedir, ArchivaArtifact artifact )
108 File dumpDir = new File( basedir, "src/test/artifact-dumps" );
109 StringBuffer filename = new StringBuffer();
111 filename.append( artifact.getArtifactId() ).append( "-" ).append( artifact.getVersion() );
113 if ( artifact.hasClassifier() )
115 filename.append( "-" ).append( artifact.getClassifier() );
118 filename.append( "." );
120 // TODO: use the ArtifactExtensionMapping object
121 if ( "maven-plugin".equals( artifact.getType() ) || "maven-archetype".equals( artifact.getType() ) )
123 filename.append( "jar" );
127 filename.append( artifact.getType() );
129 filename.append( ".txt" );
131 File dumpFile = new File( dumpDir, filename.toString() );
133 if ( !dumpFile.exists() )
135 throw new AssertionFailedError(
136 "Dump file " + dumpFile.getAbsolutePath() + " does not exist (should it?)." );