Permalink
Browse files

Merge pull request #2 from yetanotherx/yamlConfig

Multiple fixes
  • Loading branch information...
2 parents 26d74b1 + f7aa2da commit f567c6020e59f231335d1d4229c5d83d54e9fd78 @lahwran committed Dec 19, 2011
@@ -93,7 +93,7 @@ public void execute() throws MojoExecutionException {
}
for( RenameFile renameFile : renameFiles ) {
- for(Rename rename:renameFile.getRenames()) {
+ for(Rename rename:renameFile.getRenames(this)) {
if (rename.getDynamic()) {
dynamiclist.add(rename);
} else {
@@ -126,8 +126,10 @@ public void execute() throws MojoExecutionException {
String rename = (String) renamermap.get(e.getKey());
File in = e.getValue();
File out = in;
- if(rename != null)
+ if(rename != null) {
out = new File(classdir, rename+".class");
+ out.getParentFile().mkdirs();
+ }
getLog().info("Processing "+e.getKey()+(rename != null ? " -> "+rename : ""));
if(!in.exists())
{
@@ -136,16 +138,24 @@ public void execute() throws MojoExecutionException {
}
try
{
- ClassFile processing = new ClassFile(new DataInputStream(new FileInputStream(in)));
+ FileInputStream fileInputStream = new FileInputStream(in);
+ DataInputStream dataInputStream = new DataInputStream(fileInputStream);
+ ClassFile processing = new ClassFile(dataInputStream);
processing.renameClass(renamermap);
if(rename != null && out.exists())
{
getLog().warn(in.getAbsolutePath()+" would overwrite " + out.getAbsolutePath() +" ********************");
continue;
}
in.delete();
- out.getParentFile().mkdirs();
- processing.write(new DataOutputStream(new FileOutputStream(out)));
+ FileOutputStream fileOutputStream = new FileOutputStream(out);
+ DataOutputStream dataOutputStream = new DataOutputStream(fileOutputStream);
+ processing.write(dataOutputStream);
+
+ fileInputStream.close();
+ dataInputStream.close();
+ fileOutputStream.close();
+ dataOutputStream.close();
}
catch (IOException e1)
{
@@ -93,7 +93,7 @@ public void execute() throws MojoExecutionException {
}
for( RenameFile renameFile : renameFiles ) {
- for(Rename rename:renameFile.getRenames()) {
+ for(Rename rename:renameFile.getRenames(this)) {
if (rename.getDynamic()) {
dynamiclist.add(rename);
} else {
@@ -124,8 +124,11 @@ public void execute() throws MojoExecutionException {
String rename = (String) renamermap.get(e.getKey());
File in = e.getValue();
File out = in;
- if(rename != null)
+ if(rename != null) {
out = new File(classdir, rename+".class");
+ out.getParentFile().mkdirs();
+ }
+
getLog().info("Processing "+e.getKey()+(rename != null ? " -> "+rename : ""));
if(!in.exists())
{
@@ -134,15 +137,24 @@ public void execute() throws MojoExecutionException {
}
try
{
- ClassFile processing = new ClassFile(new DataInputStream(new FileInputStream(in)));
+ FileInputStream fileInputStream = new FileInputStream(in);
+ DataInputStream dataInputStream = new DataInputStream(fileInputStream);
+ ClassFile processing = new ClassFile(dataInputStream);
processing.renameClass(renamermap);
if(rename != null && out.exists())
{
getLog().warn(in.getAbsolutePath()+" would overwrite " + out.getAbsolutePath() +" ********************");
continue;
}
in.delete();
- processing.write(new DataOutputStream(new FileOutputStream(out)));
+ FileOutputStream fileOutputStream = new FileOutputStream(out);
+ DataOutputStream dataOutputStream = new DataOutputStream(fileOutputStream);
+ processing.write(dataOutputStream);
+
+ fileInputStream.close();
+ dataInputStream.close();
+ fileOutputStream.close();
+ dataOutputStream.close();
}
catch (IOException e1)
{
@@ -66,7 +66,7 @@ public static String expand(Matcher matcher, String format) {
escaped = false;
} else if (c >= 49 && c <= 57) { //numeric
if (num == null) {
- num = new StringBuilder(c);
+ num = new StringBuilder(String.valueOf(c));
} else {
num.append(c);
}
@@ -85,6 +85,13 @@ public static String expand(Matcher matcher, String format) {
output.append(c);
}
}
+
+ //In case a replacement was the end of the line
+ if (num != null) {
+ output.append(matcher.group(Integer.parseInt(num.toString())));
+ num = null;
+ }
+
return output.toString();
}
@@ -8,6 +8,7 @@
import java.util.List;
import net.lahwran.package_renamer.config.Configuration;
import net.lahwran.package_renamer.config.ConfigurationNode;
+import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
/**
@@ -32,13 +33,14 @@
*/
public String file;
- public Rename[] getRenames() throws MojoExecutionException {
+ public Rename[] getRenames(AbstractMojo mojo) throws MojoExecutionException {
File configFile = new File(this.file);
if (!configFile.exists()) {
throw new MojoExecutionException("Obfuscation file could not be read: " + configFile.getAbsolutePath());
}
+ mojo.getLog().info("Reading obfuscation values from " + configFile.getAbsolutePath());
Configuration conf = new Configuration(configFile);
conf.load();

0 comments on commit f567c60

Please sign in to comment.