Skip to content

Commit 3ec78f8

Browse files
Issue-92: If found library is a directory, copy it as such, not as a file
Also adds some debug log statements.
1 parent b7e3dd0 commit 3ec78f8

File tree

2 files changed

+30
-7
lines changed

2 files changed

+30
-7
lines changed

pom.xml

+6
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,12 @@
9696
<version>2.4</version>
9797
</dependency>
9898

99+
<dependency>
100+
<groupId>commons-io</groupId>
101+
<artifactId>commons-io</artifactId>
102+
<version>2.5</version>
103+
</dependency>
104+
99105
<dependency>
100106
<groupId>junit</groupId>
101107
<artifactId>junit</artifactId>

src/main/java/com/github/wvengen/maven/proguard/ProGuardMojo.java

+24-7
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434
import java.util.Map.Entry;
3535
import java.util.Set;
3636

37+
import org.apache.commons.io.IOUtils;
38+
import org.apache.commons.io.FileUtils;
3739
import org.apache.maven.archiver.MavenArchiveConfiguration;
3840
import org.apache.maven.archiver.MavenArchiver;
3941
import org.apache.maven.artifact.Artifact;
@@ -48,8 +50,6 @@
4850
import org.apache.tools.ant.Project;
4951
import org.apache.tools.ant.taskdefs.Java;
5052
import org.codehaus.plexus.archiver.jar.JarArchiver;
51-
import org.codehaus.plexus.util.FileUtils;
52-
import org.codehaus.plexus.util.IOUtil;
5353

5454
/**
5555
*
@@ -617,22 +617,36 @@ public void execute() throws MojoExecutionException, MojoFailureException {
617617
try{
618618
FileUtils.deleteDirectory(tempLibraryjarsDir);
619619
} catch(IOException ignored){
620-
// NO-OP
620+
throw new MojoFailureException("Deleting failed libraryJars directory", ignored);
621621
}
622622
}
623623
tempLibraryjarsDir.mkdir();
624624
if (!tempLibraryjarsDir.exists()) {
625625
throw new MojoFailureException("Can't create temporary libraryJars directory: " + tempLibraryjarsDir.getAbsolutePath());
626626
}
627+
// Use this subdirectory for all libraries that are files, and not directories themselves
628+
File commonDir = new File(tempLibraryjarsDir, "0");
629+
commonDir.mkdir();
630+
631+
int directoryIndex = 1;
627632
for (File libraryJar : libraryJars) {
628633
try {
629-
FileUtils.copyFileToDirectory(libraryJar, tempLibraryjarsDir);
634+
log.debug("Copying library: " + libraryJar);
635+
if (libraryJar.isFile()) {
636+
FileUtils.copyFileToDirectory(libraryJar, commonDir);
637+
} else {
638+
File subDir = new File(tempLibraryjarsDir, String.valueOf(directoryIndex));
639+
FileUtils.copyDirectory(libraryJar, subDir);
640+
args.add("-libraryjars");
641+
args.add(fileToString(subDir));
642+
}
630643
} catch (IOException e) {
631644
throw new MojoFailureException("Can't copy to temporary libraryJars directory", e);
632645
}
646+
directoryIndex++;
633647
}
634648
args.add("-libraryjars");
635-
args.add(fileToString(tempLibraryjarsDir));
649+
args.add(fileToString(commonDir));
636650
}
637651

638652
File mappingFile = new File(outputDirectory, mappingFileName);
@@ -718,7 +732,7 @@ public void execute() throws MojoExecutionException, MojoFailureException {
718732
applyMappingFile.getParentFile().mkdirs();
719733
FileOutputStream mappingFileOut = new FileOutputStream(applyMappingFile, true);
720734
try {
721-
IOUtil.copy(mappingFileIn, mappingFileOut);
735+
IOUtils.copy(mappingFileIn, mappingFileOut);
722736
} finally {
723737
mappingFileOut.close();
724738
}
@@ -945,9 +959,12 @@ private File getClasspathElement(Artifact artifact, MavenProject mavenProject) t
945959
project = (MavenProject) mavenProject.getProjectReferences().get(refId);
946960
}
947961
if (project != null) {
948-
return new File(project.getBuild().getOutputDirectory());
962+
File file = new File(project.getBuild().getOutputDirectory());
963+
log.debug("Found directory: " + file.getAbsolutePath());
964+
return file;
949965
} else {
950966
File file = artifact.getFile();
967+
log.debug("Found file: " + file.getAbsolutePath());
951968
if ((file == null) || (!file.exists())) {
952969
throw new MojoExecutionException("Dependency Resolution Required " + artifact);
953970
}

0 commit comments

Comments
 (0)