1 package org.apache.maven.archiva.indexer.hashcodes;
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.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;
27 import java.io.BufferedReader;
29 import java.io.FileReader;
30 import java.io.IOException;
32 import junit.framework.AssertionFailedError;
35 * HashcodesRecordLoader
37 * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a>
40 public class HashcodesRecordLoader
42 public static HashcodesRecord loadRecord( File dumpFile, ArchivaArtifact artifact )
44 HashcodesRecord record = new HashcodesRecord();
45 record.setArtifact( artifact );
47 FileReader freader = null;
48 BufferedReader reader = null;
52 freader = new FileReader( dumpFile );
53 reader = new BufferedReader( freader );
55 String line = reader.readLine();
56 while ( line != null )
58 if ( line.startsWith( "FILENAME|" ) )
60 String filename = line.substring( "FILENAME|".length() );
61 record.setFilename( filename );
63 else if ( line.startsWith( "SIZE|" ) )
65 String size = line.substring( "SIZE|".length() );
66 record.getArtifact().getModel().setSize( Long.parseLong( size ) );
68 else if ( line.startsWith( "HASH_MD5|" ) )
70 String md5 = line.substring( "HASH_MD5|".length() );
71 record.getArtifact().getModel().setChecksumMD5( md5 );
73 else if ( line.startsWith( "HASH_SHA1|" ) )
75 String sha1 = line.substring( "HASH_SHA1|".length() );
76 record.getArtifact().getModel().setChecksumSHA1( sha1 );
78 else if ( line.startsWith( "HASH_BYTECODE|" ) )
80 String hash = line.substring( "HASH_BYTECODE|".length() );
81 ArchivaArtifactJavaDetails javaDetails = JavaArtifactHelper.getJavaDetails( record.getArtifact() );
82 javaDetails.setChecksumBytecode( hash );
84 else if ( line.startsWith( "JDK|" ) )
86 String jdk = line.substring( "JDK|".length() );
87 ArchivaArtifactJavaDetails javaDetails = JavaArtifactHelper.getJavaDetails( record.getArtifact() );
88 javaDetails.setJdk( jdk );
91 line = reader.readLine();
94 catch ( IOException e )
96 throw new AssertionFailedError( "Unable to load record " + dumpFile + " from disk: " + e.getMessage() );
100 IOUtil.close( reader );
101 IOUtil.close( freader );