Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
</properties>


<groupId>com.github.wvengen</groupId>
<groupId>net.astah.maven.plugin</groupId>
<artifactId>proguard-maven-plugin</artifactId>
<name>proguard-maven-plugin</name>
<version>2.5.1</version>
<version>2.5.2</version>
<packaging>maven-plugin</packaging>

<description>Maven 3 Plugin for ProGuard</description>
Expand Down Expand Up @@ -103,7 +103,7 @@
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-archiver</artifactId>
<version>2.4</version>
<version>3.5.2</version>
</dependency>

<dependency>
Expand Down
47 changes: 37 additions & 10 deletions src/main/java/com/github/wvengen/maven/proguard/ProGuardMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,8 @@ public void execute() throws MojoExecutionException, MojoFailureException {
inJarFile = baseFile;
}

boolean outJarArchive = isArchive(outJarFile);

ArrayList<String> args = new ArrayList<String>();
ArrayList<File> libraryJars = new ArrayList<File>();

Expand Down Expand Up @@ -528,25 +530,31 @@ public void execute() throws MojoExecutionException, MojoFailureException {

for (Entry<Artifact, Inclusion> entry : injars.entrySet()) {
log.info("--- ADD injars:" + entry.getKey().getArtifactId());
File file = getClasspathElement(entry.getKey(), mavenProject);
File file = getClasspathElement(entry.getKey(), mavenProject, !outJarArchive);
inPath.add(file.toString());
StringBuilder filter = new StringBuilder(fileToString(file));
filter.append("(!META-INF/MANIFEST.MF");
int start = filter.length();
if (outJarArchive) {
filter.append("(!META-INF/MANIFEST.MF");
}
if (!addMavenDescriptor) {
filter.append(",");
filter.append(filter.length() > start ? "," : "(");
filter.append("!META-INF/maven/**");
}
if (entry.getValue().filter != null) {
filter.append(",").append(entry.getValue().filter);
filter.append(filter.length() > start ? "," : "(");
filter.append(entry.getValue().filter);
}
if (filter.length() > start) {
filter.append(")");
}
filter.append(")");
args.add("-injars");
args.add(filter.toString());
}

for (Entry<Artifact, Inclusion> entry : libraryjars.entrySet()) {
log.info("--- ADD libraryjars:" + entry.getKey().getArtifactId());
File file = getClasspathElement(entry.getKey(), mavenProject);
File file = getClasspathElement(entry.getKey(), mavenProject, false);
hasInclusionLibrary = true;
inPath.add(file.toString());
if (putLibraryJarsInTempDir) {
Expand Down Expand Up @@ -590,7 +598,7 @@ public void execute() throws MojoExecutionException, MojoFailureException {
if (isExclusion(artifact)) {
continue;
}
File file = getClasspathElement(artifact, mavenProject);
File file = getClasspathElement(artifact, mavenProject, includeDependencyInjar && !outJarArchive);

if (inPath.contains(file.toString())) {
log.debug("--- ignore library since one in injar:" + artifact.getArtifactId());
Expand Down Expand Up @@ -766,7 +774,7 @@ public void execute() throws MojoExecutionException, MojoFailureException {
jarArchiver.addArchivedFileSet(baseFile);
for (Entry<Artifact, Inclusion> entry : libraryjars.entrySet()) {
File file;
file = getClasspathElement(entry.getKey(), mavenProject);
file = getClasspathElement(entry.getKey(), mavenProject, false);
if (file.isDirectory()) {
getLog().info("merge project: " + entry.getKey() + " " + file);
jarArchiver.addDirectory(file);
Expand Down Expand Up @@ -1062,6 +1070,25 @@ private boolean deleteFileOrDirectory(File path) throws MojoFailureException {
}
}

private boolean isArchive(File path) {
String name = path.getName();
int separator = name.lastIndexOf('.');
if (separator > 0) {
// https://www.guardsquare.com/en/products/proguard/manual/usage#classpath
String extension = name.substring(separator + 1).toLowerCase();
if (extension.equals("apk")
|| extension.equals("jar")
|| extension.equals("aar")
|| extension.equals("war")
|| extension.equals("ear")
|| extension.equals("jmod")
|| extension.equals("zip")) {
return true;
}
}
return false;
}

private Set<Artifact> getDependencies(final Inclusion inc, MavenProject mavenProject)
throws MojoExecutionException {
@SuppressWarnings("unchecked")
Expand Down Expand Up @@ -1090,8 +1117,8 @@ private boolean isExclusion(Artifact artifact) {
return false;
}

private File getClasspathElement(Artifact artifact, MavenProject mavenProject) throws MojoExecutionException {
if (artifact.getClassifier() != null) {
private File getClasspathElement(Artifact artifact, MavenProject mavenProject, boolean preferFile) throws MojoExecutionException {
if (artifact.getClassifier() != null || (preferFile && artifact.getFile().exists())) {
return artifact.getFile();
}
String refId = artifact.getGroupId() + ":" + artifact.getArtifactId() + ":" + artifact.getVersion();
Expand Down