]> source.dussan.org Git - archiva.git/blob
4587ef7a70b4988d7123d945de82fab6d42bc6e9
[archiva.git] /
1 package org.apache.maven.archiva.indexer.search;
2
3 /*
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
11  *
12  *  http://www.apache.org/licenses/LICENSE-2.0
13  *
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
19  * under the License.
20  */
21
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;
25
26 import java.io.File;
27 import java.util.HashMap;
28 import java.util.Map;
29 import java.util.Map.Entry;
30
31 import junit.framework.AssertionFailedError;
32
33 /**
34  * BytecodeIndexPopulator
35  *
36  * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a>
37  * @version $Id$
38  */
39 public class BytecodeIndexPopulator
40     implements IndexPopulator
41 {
42
43     public Map<String,ArchivaArtifact> getObjectMap()
44     {
45
46         Map<String,ArchivaArtifact> dumps = new HashMap<String,ArchivaArtifact>();
47
48         // archiva-common-1.0.jar.txt
49         dumps.put( "archiva-common",
50                    createArchivaArtifact( "org.apache.maven.archiva", "archiva-common", "1.0", "", "jar" ) );
51
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" ) );
55
56         // daytrader-ear-1.1.ear.txt
57         dumps.put( "daytrader-ear", createArchivaArtifact( "org.apache.geronimo", "daytrader-ear", "1.1", "", "ear" ) );
58
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" ) );
62
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" ) );
66
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" ) );
71
72         // testng-5.1-jdk15.jar.txt
73         dumps.put( "testng", createArchivaArtifact( "org.testng", "testng", "5.1", "jdk15", "jar" ) );
74
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" ) );
78
79         return dumps;
80
81     }
82
83     private ArchivaArtifact createArchivaArtifact( String groupId, String artifactId, String version, String classifier,
84                                                    String type )
85     {
86         ArchivaArtifact artifact = new ArchivaArtifact( groupId, artifactId, version, classifier, type );
87         return artifact;
88     }
89
90     public Map<String, BytecodeRecord> populate( File basedir )
91     {
92         Map<String, BytecodeRecord> records = new HashMap<String, BytecodeRecord>();
93
94         for ( Entry<String, ArchivaArtifact> entry : getObjectMap().entrySet() )
95         {
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 );
101         }
102
103         return records;
104     }
105
106     protected File getDumpFile( File basedir, ArchivaArtifact artifact )
107     {
108         File dumpDir = new File( basedir, "src/test/artifact-dumps" );
109         StringBuffer filename = new StringBuffer();
110
111         filename.append( artifact.getArtifactId() ).append( "-" ).append( artifact.getVersion() );
112
113         if ( artifact.hasClassifier() )
114         {
115             filename.append( "-" ).append( artifact.getClassifier() );
116         }
117
118         filename.append( "." );
119
120         // TODO: use the ArtifactExtensionMapping object
121         if ( "maven-plugin".equals( artifact.getType() ) || "maven-archetype".equals( artifact.getType() ) )
122         {
123             filename.append( "jar" );
124         }
125         else
126         {
127             filename.append( artifact.getType() );
128         }
129         filename.append( ".txt" );
130
131         File dumpFile = new File( dumpDir, filename.toString() );
132
133         if ( !dumpFile.exists() )
134         {
135             throw new AssertionFailedError(
136                 "Dump file " + dumpFile.getAbsolutePath() + " does not exist (should it?)." );
137         }
138
139         return dumpFile;
140     }
141 }