SmaliMojo.java revision 3e4c1193cf631b36e3d8ea42f2c3a3d70237b0f7
1package org.jf; 2 3/* 4 5 * Copyright 2001-2005 The Apache Software Foundation. 6 * 7 * Licensed under the Apache License, Version 2.0 (the "License"); 8 * you may not use this file except in compliance with the License. 9 * You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, software 14 * distributed under the License is distributed on an "AS IS" BASIS, 15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 * See the License for the specific language governing permissions and 17 * limitations under the License. 18 */ 19 20import org.apache.maven.plugin.AbstractMojo; 21import org.apache.maven.plugin.MojoExecutionException; 22import org.apache.maven.project.MavenProject; 23import org.jf.smali.main; 24 25import java.io.File; 26import java.util.ArrayList; 27import java.util.List; 28 29/** 30 * Assembles files in the smali assembly language 31 * 32 * @goal assemble 33 * 34 * @phase compile 35 */ 36public class SmaliMojo 37 extends AbstractMojo 38{ 39 /** 40 * The maven project. 41 * 42 * @parameter expression="${project}" 43 * @required 44 * @readonly 45 */ 46 private MavenProject project; 47 48 /** 49 * @parameter default-value="${basedir}/src/main/smali" 50 * @required 51 */ 52 private File sourceDirectory; 53 54 /** 55 * @parameter default-value="${project.build.directory}/classes.dex" 56 * @required 57 */ 58 private File outputFile; 59 60 /** 61 * @parameter default-value=null 62 */ 63 private File dumpFile; 64 65 public void execute() 66 throws MojoExecutionException 67 { 68 outputFile.getParentFile().mkdirs(); 69 70 try 71 { 72 List<String> args = new ArrayList<String>(); 73 args.add("-o"); 74 args.add(outputFile.getAbsolutePath()); 75 76 77 if (dumpFile != null) { 78 args.add("-D"); 79 args.add(dumpFile.getAbsolutePath()); 80 } 81 82 args.add(sourceDirectory.getAbsolutePath()); 83 84 main.main(args.toArray(new String[args.size()])); 85 } catch (Exception ex) 86 { 87 throw new MojoExecutionException("oops!", ex); 88 } 89 } 90} 91