Author: sisbell Date: Fri Jan 11 00:13:23 2008 New Revision: 611101 URL: http://svn.apache.org/viewvc?rev=611101&view=rev Log: Now supports compiling compile scope dependencies of a project into the apk package.
Modified: maven/sandbox/trunk/plugins/maven-android/maven-aapt-plugin/src/main/java/org/maven/maven/plugin/aapt/AaptPackagerMojo.java maven/sandbox/trunk/plugins/maven-android/maven-android.iml maven/sandbox/trunk/plugins/maven-android/maven-dx-plugin/src/main/java/org/apache/maven/plugin/android/DxMojo.java Modified: maven/sandbox/trunk/plugins/maven-android/maven-aapt-plugin/src/main/java/org/maven/maven/plugin/aapt/AaptPackagerMojo.java URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/plugins/maven-android/maven-aapt-plugin/src/main/java/org/maven/maven/plugin/aapt/AaptPackagerMojo.java?rev=611101&r1=611100&r2=611101&view=diff ============================================================================== --- maven/sandbox/trunk/plugins/maven-android/maven-aapt-plugin/src/main/java/org/maven/maven/plugin/aapt/AaptPackagerMojo.java (original) +++ maven/sandbox/trunk/plugins/maven-android/maven-aapt-plugin/src/main/java/org/maven/maven/plugin/aapt/AaptPackagerMojo.java Fri Jan 11 00:13:23 2008 @@ -113,6 +113,10 @@ } catch (ExecutionException e) { throw new MojoExecutionException("", e); } + + File dexClassesFile = new File(project.getBasedir(), "target" + File.separator + project.getArtifactId() + "-" + + project.getVersion() + "-classes.dex"); + ZipOutputStream os = null; InputStream is = null; @@ -131,7 +135,7 @@ is.close(); } os.putNextEntry(new ZipEntry("classes.dex")); - is = new FileInputStream(project.getBasedir().getAbsolutePath() + File.separatorChar + "target/classes.dex"); + is = new FileInputStream(dexClassesFile); byte[] buffer = new byte[1024]; int i; while ((i = is.read(buffer)) > 0) { Modified: maven/sandbox/trunk/plugins/maven-android/maven-android.iml URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/plugins/maven-android/maven-android.iml?rev=611101&r1=611100&r2=611101&view=diff ============================================================================== --- maven/sandbox/trunk/plugins/maven-android/maven-android.iml (original) +++ maven/sandbox/trunk/plugins/maven-android/maven-android.iml Fri Jan 11 00:13:23 2008 @@ -5,6 +5,8 @@ <output url="file://$MODULE_DIR$/classes" /> <exclude-output /> <content url="file://$MODULE_DIR$"> + <sourceFolder url="file://$MODULE_DIR$/integration-tests/multimodule/moduleA/src" isTestSource="false" /> + <sourceFolder url="file://$MODULE_DIR$/integration-tests/multimodule/moduleB/src" isTestSource="false" /> <sourceFolder url="file://$MODULE_DIR$/maven-aapt-plugin/src/main/java" isTestSource="false" /> <sourceFolder url="file://$MODULE_DIR$/maven-adb-plugin/src/main/java" isTestSource="false" /> <sourceFolder url="file://$MODULE_DIR$/maven-android-core/src/main/java" isTestSource="false" /> Modified: maven/sandbox/trunk/plugins/maven-android/maven-dx-plugin/src/main/java/org/apache/maven/plugin/android/DxMojo.java URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/plugins/maven-android/maven-dx-plugin/src/main/java/org/apache/maven/plugin/android/DxMojo.java?rev=611101&r1=611100&r2=611101&view=diff ============================================================================== --- maven/sandbox/trunk/plugins/maven-android/maven-dx-plugin/src/main/java/org/apache/maven/plugin/android/DxMojo.java (original) +++ maven/sandbox/trunk/plugins/maven-android/maven-dx-plugin/src/main/java/org/apache/maven/plugin/android/DxMojo.java Fri Jan 11 00:13:23 2008 @@ -26,10 +26,16 @@ import org.apache.maven.project.MavenProjectHelper; import org.apache.maven.android.ExecutionException; import org.apache.maven.android.CommandExecutor; +import org.apache.maven.artifact.Artifact; +import org.codehaus.plexus.util.FileUtils; +import org.codehaus.plexus.util.IOUtil; import java.util.List; import java.util.ArrayList; -import java.io.File; +import java.util.Enumeration; +import java.util.jar.JarFile; +import java.util.jar.JarEntry; +import java.io.*; /** * @author Shane Isbell @@ -57,14 +63,36 @@ CommandExecutor executor = CommandExecutor.Factory.createDefaultCommmandExecutor(); executor.setLogger(this.getLog()); - File outputFile = new File(project.getBasedir(), "target" + File.separator + "classes.dex"); + + + File outputFile = new File(project.getBasedir(), "target" + File.separator + project.getArtifactId() + "-" + + project.getVersion() + "-classes.dex"); File inputFile = new File(project.getBasedir(), "target" + File.separator + project.getArtifactId() + "-" + project.getVersion() + ".jar"); + //Unpackage all dependent and main classes + File outputDirectory = new File(project.getBuild().getDirectory(), "android-classes"); + for (Artifact artifact : (List<Artifact>) project.getCompileArtifacts()) { + if (artifact.getGroupId().equals("android")) { + continue; + } + try { + unjar(new JarFile(artifact.getFile()), outputDirectory); + } catch (IOException e) { + throw new MojoExecutionException("", e); + } + } + + try { + unjar(new JarFile(inputFile), outputDirectory); + } catch (IOException e) { + throw new MojoExecutionException("", e); + } + List<String> commands = new ArrayList<String>(); commands.add("--dex"); commands.add("--output=" + outputFile.getAbsolutePath()); - commands.add(inputFile.getAbsolutePath()); + commands.add(outputDirectory.getAbsolutePath()); getLog().info("dx " + commands.toString()); try { executor.executeCommand("dx", commands, project.getBasedir(), false); @@ -73,5 +101,18 @@ } mavenProjectHelper.attachArtifact(project, "jar", project.getArtifact().getClassifier(), inputFile); + } + + private static void unjar(JarFile jarFile, File outputDirectory) throws IOException { + for (Enumeration en = jarFile.entries(); en.hasMoreElements();) { + JarEntry entry = (JarEntry) en.nextElement(); + File entryFile = new File(outputDirectory, entry.getName()); + if (!entryFile.getParentFile().exists() && !entry.getName().startsWith("META-INF")) { + entryFile.getParentFile().mkdirs(); + } + if (!entry.isDirectory() && entry.getName().endsWith(".class")) { + IOUtil.copy(jarFile.getInputStream(entry), new FileOutputStream(entryFile)); + } + } } }