-
Notifications
You must be signed in to change notification settings - Fork 152
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
lasselindqvist
merged 4 commits into
wvengen:master
from
thargor:generate-temporary-configuration-file
Mar 14, 2021
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
ab49507
added generateTemporaryConfigurationFile option to workaround max arg…
thargor 4cce4a0
ensure temporary config file writer is closed correctly
thargor c0b0e6d
improved documentation of generateTemporaryConfigurationFile
thargor 2f92b19
updated workaround for command line length
thargor File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
|
@@ -132,6 +133,19 @@ public class ProGuardMojo extends AbstractMojo { | |
*/ | ||
private boolean putLibraryJarsInTempDir; | ||
|
||
/** | ||
* Create a temporary configuration file | ||
* | ||
* @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. | ||
* | ||
|
@@ -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(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.