Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added generateTemporaryConfigurationFile option #125

Merged
Merged
Changes from 1 commit
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
40 changes: 40 additions & 0 deletions src/main/java/com/github/wvengen/maven/proguard/ProGuardMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
package com.github.wvengen.maven.proguard;

import java.io.File;
import java.io.FileWriter;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
Expand Down Expand Up @@ -132,6 +133,19 @@ public class ProGuardMojo extends AbstractMojo {
*/
private boolean putLibraryJarsInTempDir;

/**
* Create a temporary configuration file
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs a bit more explanation for this feature.
For example: "Use this parameter if your command line arguments become too long and execution fails. If this parameter is true, the arguments are written to a file and the Proguard process reads them from the file instead of the command itself.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Also updated the maven documentation.

*
* @parameter default-value="false"
*/
private boolean generateTemporaryConfigurationFile;

/**
* @parameter expression="${project.build.directory}/generated-proguard.conf"
* @readonly
*/
private File temporaryConfigurationFile;

/**
* Specifies that project compile dependencies should be added as injar.
*
Expand Down Expand Up @@ -693,6 +707,32 @@ public void execute() throws MojoExecutionException, MojoFailureException {
Collections.addAll(args, options);
}


if(generateTemporaryConfigurationFile) {
log.info("building config file");

StringBuilder stringBuilder = new StringBuilder();
for (String arg : args) {
if (arg.startsWith("-")) {
stringBuilder.append("\n");
}else{
stringBuilder.append(" ");
}
stringBuilder.append(arg);
}

try {
FileWriter writer = new FileWriter(temporaryConfigurationFile);
IOUtils.write(stringBuilder.toString(), writer);
writer.close();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Writer needs closing even in case of errors, so this needs to be done in a finally block or with

try(FileWriter write = new FileWriter(temporaryConfigurationFile); ) {

}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I replaced it with a java 1.6 compatible finally.

} catch (IOException e) {
throw new MojoFailureException("cannot write to temporary configuration file " + temporaryConfigurationFile, e);
}
args = new ArrayList<String>();
args.add("-include");
args.add(fileToString(temporaryConfigurationFile));
}

log.info("execute ProGuard " + args.toString());
proguardMain(getProguardJars(this), args, this);

Expand Down