• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 com.android.dx.command.dexer.Main;
20 
21 public class DexBuildStep extends BuildStep {
22 
23     private final boolean deleteInputFileAfterBuild;
24 
DexBuildStep(BuildFile inputFile, BuildFile outputFile, boolean deleteInputFileAfterBuild)25     DexBuildStep(BuildFile inputFile, BuildFile outputFile,
26             boolean deleteInputFileAfterBuild) {
27         super(inputFile, outputFile);
28         this.deleteInputFileAfterBuild = deleteInputFileAfterBuild;
29     }
30 
31     @Override
build()32     boolean build() {
33 
34         if (super.build()) {
35             Main.Arguments args = new Main.Arguments();
36 
37             args.jarOutput = true;
38             args.fileNames = new String[] {inputFile.fileName.getAbsolutePath()};
39 
40             args.outName = outputFile.fileName.getAbsolutePath();
41 
42             int result = Main.run(args);
43 
44             if (result == 0) {
45                 if (deleteInputFileAfterBuild) {
46                     inputFile.fileName.delete();
47                 }
48                 return true;
49             } else {
50                 System.err.println("exception while dexing "
51                         + inputFile.fileName.getAbsolutePath() + " to "
52                         + args.outName);
53                 return false;
54             }
55         }
56         return false;
57     }
58 
59     @Override
hashCode()60     public int hashCode() {
61         return inputFile.hashCode() ^ outputFile.hashCode();
62     }
63 
64     @Override
equals(Object obj)65     public boolean equals(Object obj) {
66         if (super.equals(obj)) {
67             DexBuildStep other = (DexBuildStep) obj;
68 
69             return inputFile.equals(other.inputFile)
70                     && outputFile.equals(other.outputFile);
71         }
72         return false;
73     }
74 
75 
76 }
77