• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2018 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 org.jf.smali.Smali;
20 import org.jf.smali.SmaliOptions;
21 
22 import java.io.File;
23 import java.util.List;
24 
25 /**
26  * BuildStep that invokes the Smali Java API to
27  * assemble test cases written in Smali.
28  */
29 class SmaliBuildStep extends BuildStep {
30 
31     List<String> inputFiles;
32 
SmaliBuildStep(List<String> inputFiles, File outputFile)33     SmaliBuildStep(List<String> inputFiles, File outputFile) {
34         super(outputFile);
35         this.inputFiles = inputFiles;
36     }
37 
38     @Override
build()39     boolean build() {
40         SmaliOptions options = new SmaliOptions();
41         options.verboseErrors = true;
42         options.outputDexFile = outputFile.fileName.getAbsolutePath();
43         try {
44             File destDir = outputFile.folder;
45             if (!destDir.exists()) {
46                 destDir.mkdirs();
47             }
48             return Smali.assemble(options, inputFiles);
49         } catch(Exception e) {
50              if(BuildDalvikSuite.DEBUG)
51                  e.printStackTrace();
52              System.err.println("Exception <" + e.getClass().getName() + ">" + e.getMessage());
53              return false;
54         }
55     }
56 
57     @Override
equals(Object obj)58     public boolean equals(Object obj) {
59         if (super.equals(obj)) {
60             SmaliBuildStep other = (SmaliBuildStep) obj;
61             return inputFiles.equals(other.inputFiles)
62                     && outputFile.equals(other.outputFile);
63         }
64         return false;
65     }
66 
67     @Override
hashCode()68     public int hashCode() {
69         return inputFiles.hashCode() ^ outputFile.hashCode();
70     }
71 }
72