Hi,
I'm using proguard-maven-plugin and I made a small change on it that I
wanna to share.
On my application I wanna run the unit tests against the obfuscated
code, to be sure if it will work at runtime. So, I changed proguard-
maven-plugin to allow obfuscation of classes directory (instead of
obfuscating the final jar).
It is a very simple change, but can be very useful to many others.
Patch:
Index: src/main/java/com/pyx4me/maven/proguard/ProGuardMojo.java
===================================================================
--- src/main/java/com/pyx4me/maven/proguard/ProGuardMojo.java
(revision 3204)
+++ src/main/java/com/pyx4me/maven/proguard/ProGuardMojo.java (working
copy)
@@ -42,6 +42,7 @@
import org.apache.tools.ant.Project;
import org.apache.tools.ant.taskdefs.Java;
import org.codehaus.plexus.archiver.jar.JarArchiver;
+import org.codehaus.plexus.util.FileUtils;
/**
*
@@ -247,6 +248,13 @@
* @parameter default-value="proguard.ProGuard"
*/
protected String proguardMainClass = "proguard.ProGuard";
+
+ /**
+ * When true proguard will run against the compiled classes. Not
the package jar.
+ *
+ * @parameter default-value="false"
+ */
+ protected boolean useClassesDir;
private Log log;
@@ -278,7 +286,13 @@
boolean mainIsJar = mavenProject.getPackaging().equals("jar");
boolean mainIsPom = mavenProject.getPackaging().equals("pom");
- File inJarFile = new File(outputDirectory, injar);
+ File inJarFile;
+ if(useClassesDir) {
+ inJarFile = new File(mavenProject.getBuild().getOutputDirectory
());
+ } else {
+ inJarFile = new File(outputDirectory, injar);
+ }
+
if (mainIsJar && (!inJarFile.exists())) {
if (injarNotExistsSkip) {
log.info("Bypass ProGuard processing because \"injar\" dos not
exist");
@@ -317,6 +331,12 @@
throw new MojoFailureException("Can't delete " + outJarFile);
}
}
+ } if (useClassesDir) {
+ sameArtifact = true;
+ File original = new File(outputDirectory, "original-classes");
+ inJarFile.renameTo(original);
+ inJarFile = original;
+ outJarFile = new File(mavenProject.getBuild().getOutputDirectory
());
} else {
sameArtifact = true;
outJarFile = inJarFile.getAbsoluteFile();
VELO