]> source.dussan.org Git - archiva.git/blob
6dcb146a60cefe6bbb714b23e2d039725b557959
[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.hashcodes.HashcodesRecord;
23 import org.apache.maven.archiva.indexer.hashcodes.HashcodesRecordLoader;
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  * HashcodesIndexPopulator 
35  *
36  * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
37  * @version $Id$
38  */
39 public class HashcodesIndexPopulator
40     implements IndexPopulator
41 {
42
43     public Map<String, ArchivaArtifact> getObjectMap()
44     {
45         Map<String, ArchivaArtifact> dumps = new HashMap<String, ArchivaArtifact>();
46
47         // archiva-common-1.0.jar.txt
48         dumps.put( "archiva-common",
49                    createArchivaArtifact( "org.apache.maven.archiva", "archiva-common", "1.0", "", "jar" ) );
50
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" ) );
54
55         // daytrader-ear-1.1.ear.txt
56         dumps.put( "daytrader-ear", createArchivaArtifact( "org.apache.geronimo", "daytrader-ear", "1.1", "", "ear" ) );
57
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" ) );
61
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" ) );
65
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" ) );
70
71         // testng-5.1-jdk15.jar.txt
72         dumps.put( "testng", createArchivaArtifact( "org.testng", "testng", "5.1", "jdk15", "jar" ) );
73
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" ) );
77
78         return dumps;
79     }
80
81     public Map<String, HashcodesRecord> populate( File basedir )
82     {
83         Map<String, HashcodesRecord> records = new HashMap<String, HashcodesRecord>();
84
85         for ( Entry<String, ArchivaArtifact> entry : getObjectMap().entrySet() )
86         {
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 );
92         }
93
94         return records;
95     }
96
97     protected File getDumpFile( File basedir, ArchivaArtifact artifact )
98     {
99         File dumpDir = new File( basedir, "src/test/artifact-dumps" );
100         StringBuffer filename = new StringBuffer();
101
102         filename.append( artifact.getArtifactId() ).append( "-" ).append( artifact.getVersion() );
103
104         if ( artifact.hasClassifier() )
105         {
106             filename.append( "-" ).append( artifact.getClassifier() );
107         }
108
109         filename.append( "." );
110
111         // TODO: use the ArtifactExtensionMapping object
112         if ( "maven-plugin".equals( artifact.getType() ) || "maven-archetype".equals( artifact.getType() ) )
113         {
114             filename.append( "jar" );
115         }
116         else
117         {
118             filename.append( artifact.getType() );
119         }
120         filename.append( ".txt" );
121
122         File dumpFile = new File( dumpDir, filename.toString() );
123
124         if ( !dumpFile.exists() )
125         {
126             throw new AssertionFailedError(
127                 "Dump file " + dumpFile.getAbsolutePath() + " does not exist (should it?)." );
128         }
129
130         return dumpFile;
131     }
132
133     private ArchivaArtifact createArchivaArtifact( String groupId, String artifactId, String version, String classifier,
134                                                    String type )
135     {
136         ArchivaArtifact artifact = new ArchivaArtifact( groupId, artifactId, version, classifier, type );
137         return artifact;
138     }
139 }