1 /* 2 * Copyright (C) 2008 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package util.build; 18 19 import dxconvext.ClassFileAssembler; 20 21 import java.io.File; 22 import java.io.FileNotFoundException; 23 import java.io.FileOutputStream; 24 import java.io.FileReader; 25 import java.io.OutputStream; 26 import java.io.Reader; 27 28 public class DFHBuildStep extends BuildStep { 29 DFHBuildStep(BuildFile inputFile, BuildFile outputFile)30 public DFHBuildStep(BuildFile inputFile, BuildFile outputFile) { 31 super(inputFile, outputFile); 32 } 33 34 @Override build()35 boolean build() { 36 if (super.build()) { 37 File out_dir = outputFile.fileName.getParentFile(); 38 if (!out_dir.exists() && !out_dir.mkdirs()) { 39 System.err.println("failed to create dir: " 40 + out_dir.getAbsolutePath()); 41 return false; 42 } 43 44 ClassFileAssembler cfAssembler = new ClassFileAssembler(); 45 Reader r; 46 OutputStream os; 47 try { 48 r = new FileReader(inputFile.fileName); 49 os = new FileOutputStream(outputFile.fileName); 50 } catch (FileNotFoundException e) { 51 System.err.println(e); 52 return false; 53 } 54 try { 55 // cfAssembler throws a runtime exception 56 cfAssembler.writeClassFile(r, os, true); 57 } catch (RuntimeException e) { 58 System.err.println("error in DFHBuildStep for inputfile "+inputFile.fileName+", outputfile "+outputFile.fileName); 59 throw e; 60 } 61 62 return true; 63 } 64 return false; 65 } 66 67 @Override equals(Object obj)68 public boolean equals(Object obj) { 69 70 if (super.equals(obj)) { 71 return inputFile.equals(((DFHBuildStep) obj).inputFile) 72 && outputFile.equals(((DFHBuildStep) obj).outputFile); 73 } 74 return false; 75 } 76 77 @Override hashCode()78 public int hashCode() { 79 return (inputFile == null ? 31 : inputFile.hashCode()) 80 ^ (outputFile == null ? 37 : outputFile.hashCode()); 81 } 82 } 83