1 /* 2 * Copyright 2001-2005 The Apache Software Foundation. 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 /* 18 * As per the Apache license requirements, this file has been modified 19 * from its original state. 20 * 21 * Such modifications are Copyright (C) 2010 Ben Gruver, and are released 22 * under the original license 23 */ 24 25 package org.jf; 26 27 import org.apache.maven.plugin.AbstractMojo; 28 import org.apache.maven.plugin.MojoExecutionException; 29 import org.apache.maven.project.MavenProject; 30 import org.jf.smali.main; 31 32 import java.io.File; 33 import java.util.ArrayList; 34 import java.util.List; 35 36 /** 37 * Assembles files in the smali assembly language 38 * 39 * @goal assemble 40 * 41 * @phase compile 42 */ 43 public class SmaliMojo 44 extends AbstractMojo 45 { 46 /** 47 * The maven project. 48 * 49 * @parameter expression="${project}" 50 * @required 51 * @readonly 52 */ 53 private MavenProject project; 54 55 /** 56 * @parameter default-value="${basedir}/src/main/smali" 57 * @required 58 */ 59 private File sourceDirectory; 60 61 /** 62 * @parameter default-value="${project.build.directory}/classes.dex" 63 * @required 64 */ 65 private File outputFile; 66 67 /** 68 * @parameter default-value=null 69 */ 70 private File dumpFile; 71 execute()72 public void execute() 73 throws MojoExecutionException 74 { 75 outputFile.getParentFile().mkdirs(); 76 77 try 78 { 79 List<String> args = new ArrayList<String>(); 80 args.add("-o"); 81 args.add(outputFile.getAbsolutePath()); 82 83 84 if (dumpFile != null) { 85 args.add("-D"); 86 args.add(dumpFile.getAbsolutePath()); 87 } 88 89 args.add(sourceDirectory.getAbsolutePath()); 90 91 main.main(args.toArray(new String[args.size()])); 92 } catch (Exception ex) 93 { 94 throw new MojoExecutionException("oops!", ex); 95 } 96 } 97 } 98