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.commons.io.FileUtils;
23 import org.apache.maven.archiva.indexer.filecontent.FileContentRecord;
24 import org.apache.maven.archiva.model.ArchivaArtifact;
27 import java.io.IOException;
28 import java.util.HashMap;
31 import junit.framework.AssertionFailedError;
34 * FileContentIndexPopulator
38 public class FileContentIndexPopulator
39 implements IndexPopulator
41 public Map<String, ArchivaArtifact> getObjectMap()
46 public Map<String, FileContentRecord> populate( File basedir )
48 Map<String, FileContentRecord> map = new HashMap<String, FileContentRecord>();
50 File repoDir = new File( basedir, "src/test/managed-repository" );
52 String prefix = "org/apache/maven/archiva/record/";
54 map.put( "parent-pom-1", createFileContentRecord( repoDir, prefix + "parent-pom/1/parent-pom-1.pom" ) );
55 map.put( "child-pom-1.0-SNAPSHOT", createFileContentRecord( repoDir, prefix
56 + "test-child-pom/1.0-SNAPSHOT/test-child-pom-1.0-20060728.121314-1.pom" ) );
57 map.put( "test-archetype-1.0", createFileContentRecord( repoDir, prefix
58 + "test-archetype/1.0/test-archetype-1.0.pom" ) );
59 map.put( "test-jar-and-pom-1.0-alpha-1", createFileContentRecord( repoDir, prefix
60 + "test-jar-and-pom/1.0-alpha-1/test-jar-and-pom-1.0-alpha-1.pom" ) );
61 map.put( "test-plugin-1.0", createFileContentRecord( repoDir, prefix + "test-plugin/1.0/test-plugin-1.0.pom" ) );
62 map.put( "test-pom-1.0", createFileContentRecord( repoDir, prefix + "test-pom/1.0/test-pom-1.0.pom" ) );
63 map.put( "test-skin-1.0", createFileContentRecord( repoDir, prefix + "test-skin/1.0/test-skin-1.0.pom" ) );
68 private FileContentRecord createFileContentRecord( File repoDir, String path )
70 File pathToFile = new File( repoDir, path );
72 if ( !pathToFile.exists() )
74 throw new AssertionFailedError( "Can't find test file: " + pathToFile.getAbsolutePath() );
77 FileContentRecord record = new FileContentRecord();
78 record.setRepositoryId( "test-repo" );
79 record.setFilename( path );
83 record.setContents( FileUtils.readFileToString( pathToFile, null ) );
85 catch ( IOException e )
88 throw new AssertionFailedError( "Can't load test file contents: " + pathToFile.getAbsolutePath() );