]> source.dussan.org Git - archiva.git/blob
b033569040d931ffab0f7da4f5542074ecc75557
[archiva.git] /
1 package org.apache.maven.archiva.indexer.hashcodes;
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.model.ArchivaArtifact;
23 import org.apache.maven.archiva.model.ArchivaArtifactJavaDetails;
24 import org.apache.maven.archiva.model.platform.JavaArtifactHelper;
25 import org.codehaus.plexus.util.IOUtil;
26
27 import java.io.BufferedReader;
28 import java.io.File;
29 import java.io.FileReader;
30 import java.io.IOException;
31
32 import junit.framework.AssertionFailedError;
33
34 /**
35  * HashcodesRecordLoader 
36  *
37  * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a>
38  * @version $Id$
39  */
40 public class HashcodesRecordLoader
41 {
42     public static HashcodesRecord loadRecord( File dumpFile, ArchivaArtifact artifact )
43     {
44         HashcodesRecord record = new HashcodesRecord();
45         record.setArtifact( artifact );
46
47         FileReader freader = null;
48         BufferedReader reader = null;
49
50         try
51         {
52             freader = new FileReader( dumpFile );
53             reader = new BufferedReader( freader );
54
55             String line = reader.readLine();
56             while ( line != null )
57             {
58                 if ( line.startsWith( "FILENAME|" ) )
59                 {
60                     String filename = line.substring( "FILENAME|".length() );
61                     record.setFilename( filename );
62                 }
63                 else if ( line.startsWith( "SIZE|" ) )
64                 {
65                     String size = line.substring( "SIZE|".length() );
66                     record.getArtifact().getModel().setSize( Long.parseLong( size ) );
67                 }
68                 else if ( line.startsWith( "HASH_MD5|" ) )
69                 {
70                     String md5 = line.substring( "HASH_MD5|".length() );
71                     record.getArtifact().getModel().setChecksumMD5( md5 );
72                 }
73                 else if ( line.startsWith( "HASH_SHA1|" ) )
74                 {
75                     String sha1 = line.substring( "HASH_SHA1|".length() );
76                     record.getArtifact().getModel().setChecksumSHA1( sha1 );
77                 }
78                 else if ( line.startsWith( "HASH_BYTECODE|" ) )
79                 {
80                     String hash = line.substring( "HASH_BYTECODE|".length() );
81                     ArchivaArtifactJavaDetails javaDetails = JavaArtifactHelper.getJavaDetails( record.getArtifact() );
82                     javaDetails.setChecksumBytecode( hash );
83                 }
84                 else if ( line.startsWith( "JDK|" ) )
85                 {
86                     String jdk = line.substring( "JDK|".length() );
87                     ArchivaArtifactJavaDetails javaDetails = JavaArtifactHelper.getJavaDetails( record.getArtifact() );
88                     javaDetails.setJdk( jdk );
89                 }
90
91                 line = reader.readLine();
92             }
93         }
94         catch ( IOException e )
95         {
96             throw new AssertionFailedError( "Unable to load record " + dumpFile + " from disk: " + e.getMessage() );
97         }
98         finally
99         {
100             IOUtil.close( reader );
101             IOUtil.close( freader );
102         }
103
104         return record;
105     }
106 }