proguard-maven-plugin suggestion

21 views
Skip to first unread message

velo

unread,
Mar 28, 2009, 10:00:43 AM3/28/09
to pyx4me-users
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

Vlad Skarzhevskyy

unread,
Mar 28, 2009, 7:49:33 PM3/28/09
to pyx4me...@googlegroups.com
Hi Velo
I did the requested change differently.

Now you may specify <injar>classes</injar>
The plugin will detect if this is jar(file) or directory and will
produce different result.
The version 2.0.4-SNAPSHOT will support this.

See the test project:
https://pyx4j.com/svn/pyx4me/pyx4me-tests/proguard-maven-plugin-classes-test
--
Vlad

Marvin Froeder

unread,
Mar 29, 2009, 1:59:07 PM3/29/09
to Vlad Skarzhevskyy, pyx4me...@googlegroups.com
Hey,

What is the address of your snapshots repo?

VELO
Reply all
Reply to author
Forward
0 new messages