1 package org.apache.maven.archiva.indexer.bytecode;
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 junit.framework.AssertionFailedError;
23 import org.apache.maven.archiva.model.ArchivaArtifact;
24 import org.apache.maven.archiva.model.ArchivaArtifactJavaDetails;
25 import org.apache.maven.archiva.model.platform.JavaArtifactHelper;
26 import org.codehaus.plexus.util.IOUtil;
28 import java.io.BufferedReader;
30 import java.io.FileReader;
31 import java.io.IOException;
32 import java.util.ArrayList;
35 * BytecodeRecordLoader - Utility method for loading dump files into BytecordRecords.
37 * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a>
40 public class BytecodeRecordLoader
42 // private static Map cache = new HashMap();
44 public static BytecodeRecord loadRecord( File dumpFile, ArchivaArtifact artifact )
46 BytecodeRecord record;
47 // record = (BytecodeRecord) cache.get( artifact );
48 // if ( record != null )
53 record = new BytecodeRecord();
54 record.setArtifact( artifact );
56 record.setClasses( new ArrayList() );
57 record.setMethods( new ArrayList() );
58 record.setFiles( new ArrayList() );
60 FileReader freader = null;
61 BufferedReader reader = null;
65 freader = new FileReader( dumpFile );
66 reader = new BufferedReader( freader );
68 String line = reader.readLine();
69 while ( line != null )
71 if ( line.startsWith( "FILENAME|" ) )
73 String filename = line.substring( "FILENAME|".length() );
74 record.setFilename( filename );
76 else if ( line.startsWith( "SIZE|" ) )
78 String size = line.substring( "SIZE|".length() );
79 record.getArtifact().getModel().setSize( Long.parseLong( size ) );
81 else if ( line.startsWith( "HASH_MD5|" ) )
83 String md5 = line.substring( "HASH_MD5|".length() );
84 record.getArtifact().getModel().setChecksumMD5( md5 );
86 else if ( line.startsWith( "HASH_SHA1|" ) )
88 String sha1 = line.substring( "HASH_SHA1|".length() );
89 record.getArtifact().getModel().setChecksumSHA1( sha1 );
91 else if ( line.startsWith( "HASH_BYTECODE|" ) )
93 String hash = line.substring( "HASH_BYTECODE|".length() );
94 ArchivaArtifactJavaDetails javaDetails = JavaArtifactHelper.getJavaDetails( record.getArtifact() );
95 javaDetails.setChecksumBytecode( hash );
97 else if ( line.startsWith( "JDK|" ) )
99 String jdk = line.substring( "JDK|".length() );
100 ArchivaArtifactJavaDetails javaDetails = JavaArtifactHelper.getJavaDetails( record.getArtifact() );
101 javaDetails.setJdk( jdk );
103 else if ( line.startsWith( "CLASS|" ) )
105 String classname = line.substring( "CLASS|".length() );
106 record.getClasses().add( classname );
108 else if ( line.startsWith( "METHOD|" ) )
110 String methodName = line.substring( "METHOD|".length() );
111 record.getMethods().add( methodName );
113 else if ( line.startsWith( "FILE|" ) )
115 String fileentry = line.substring( "FILE|".length() );
116 record.getFiles().add( fileentry );
119 line = reader.readLine();
122 catch ( IOException e )
124 throw new AssertionFailedError( "Unable to load record " + dumpFile + " from disk: " + e.getMessage() );
128 IOUtil.close( reader );
129 IOUtil.close( freader );
132 // cache.put( artifact, record );