From e653c9384fe118c596411970eeb049bcec8c21a0 Mon Sep 17 00:00:00 2001 From: luca-vercelli Date: Fri, 17 Sep 2021 14:16:49 +0200 Subject: [PATCH 1/4] moved classes from test to src --- .../core/v1/impl}/loader/ClassPathLoader.java | 2 +- .../core/v1/impl}/loader/DirectoryLoader.java | 2 +- .../jd/core/v1/impl}/loader/NopLoader.java | 2 +- .../jd/core/v1/impl}/loader/ZipLoader.java | 2 +- .../impl}/printer/PlainTextMetaPrinter.java | 2 +- .../v1/impl}/printer/PlainTextPrinter.java | 24 ++++++++++++------- .../jd/core/v1/AnnotationConverterTest.java | 3 ++- src/test/java/org/jd/core/v1/CfrTest.java | 4 ++-- .../jd/core/v1/ClassFileDeserializerTest.java | 2 +- .../org/jd/core/v1/ControlFlowGraphTest.java | 4 ++-- .../jd/core/v1/JarFileToJavaSourceTest.java | 4 ++-- .../org/jd/core/v1/Java9InterfaceTest.java | 6 ++--- .../org/jd/core/v1/JavaAnnotationTest.java | 6 ++--- .../jd/core/v1/JavaAnonymousClassTest.java | 6 ++--- .../java/org/jd/core/v1/JavaArrayTest.java | 6 ++--- .../java/org/jd/core/v1/JavaAssertTest.java | 6 ++--- .../org/jd/core/v1/JavaAutoboxingTest.java | 4 ++-- .../java/org/jd/core/v1/JavaBasicTest.java | 6 ++--- .../java/org/jd/core/v1/JavaEnumTest.java | 6 ++--- .../jd/core/v1/JavaFragmentToTokenTest.java | 5 ++-- .../java/org/jd/core/v1/JavaGenericTest.java | 6 ++--- .../java/org/jd/core/v1/JavaIfElseTest.java | 6 ++--- .../jd/core/v1/JavaInnerOuterClassTest.java | 6 ++--- .../java/org/jd/core/v1/JavaLambdaTest.java | 6 ++--- .../java/org/jd/core/v1/JavaLoopTest.java | 6 ++--- .../jd/core/v1/JavaMethodOverloadingTest.java | 4 ++-- .../core/v1/JavaOperatorPrecedenceTest.java | 4 ++-- .../java/org/jd/core/v1/JavaSwitchTest.java | 6 ++--- .../jd/core/v1/JavaSynchronizedBlockTest.java | 6 ++--- .../core/v1/JavaSyntaxToJavaSourceTest.java | 5 ++-- .../jd/core/v1/JavaTernaryOperatorTest.java | 6 ++--- .../jd/core/v1/JavaTryCatchFinallyTest.java | 6 ++--- .../core/v1/LayoutFragmentProcessorTest.java | 5 ++-- ...ateBindingsForStaticMethodVisitorTest.java | 3 ++- .../org/jd/core/v1/SignatureParserTest.java | 5 ++-- .../java/org/jd/core/v1/TypeMakerTest.java | 4 ++-- .../java/org/jd/core/v1/WriteTokenTest.java | 2 +- 37 files changed, 101 insertions(+), 87 deletions(-) rename src/{test/java/org/jd/core/v1 => main/java/org/jd/core/v1/impl}/loader/ClassPathLoader.java (97%) rename src/{test/java/org/jd/core/v1 => main/java/org/jd/core/v1/impl}/loader/DirectoryLoader.java (97%) rename src/{test/java/org/jd/core/v1 => main/java/org/jd/core/v1/impl}/loader/NopLoader.java (94%) rename src/{test/java/org/jd/core/v1 => main/java/org/jd/core/v1/impl}/loader/ZipLoader.java (98%) rename src/{test/java/org/jd/core/v1 => main/java/org/jd/core/v1/impl}/printer/PlainTextMetaPrinter.java (98%) rename src/{test/java/org/jd/core/v1 => main/java/org/jd/core/v1/impl}/printer/PlainTextPrinter.java (85%) diff --git a/src/test/java/org/jd/core/v1/loader/ClassPathLoader.java b/src/main/java/org/jd/core/v1/impl/loader/ClassPathLoader.java similarity index 97% rename from src/test/java/org/jd/core/v1/loader/ClassPathLoader.java rename to src/main/java/org/jd/core/v1/impl/loader/ClassPathLoader.java index 54c5b063..0dcc6c2d 100644 --- a/src/test/java/org/jd/core/v1/loader/ClassPathLoader.java +++ b/src/main/java/org/jd/core/v1/impl/loader/ClassPathLoader.java @@ -5,7 +5,7 @@ * copy and modify the code freely for non-commercial purposes. */ -package org.jd.core.v1.loader; +package org.jd.core.v1.impl.loader; import org.jd.core.v1.api.loader.Loader; import org.jd.core.v1.api.loader.LoaderException; diff --git a/src/test/java/org/jd/core/v1/loader/DirectoryLoader.java b/src/main/java/org/jd/core/v1/impl/loader/DirectoryLoader.java similarity index 97% rename from src/test/java/org/jd/core/v1/loader/DirectoryLoader.java rename to src/main/java/org/jd/core/v1/impl/loader/DirectoryLoader.java index ae4ccc5e..7961c26f 100644 --- a/src/test/java/org/jd/core/v1/loader/DirectoryLoader.java +++ b/src/main/java/org/jd/core/v1/impl/loader/DirectoryLoader.java @@ -5,7 +5,7 @@ * copy and modify the code freely for non-commercial purposes. */ -package org.jd.core.v1.loader; +package org.jd.core.v1.impl.loader; import org.jd.core.v1.api.loader.Loader; import org.jd.core.v1.api.loader.LoaderException; diff --git a/src/test/java/org/jd/core/v1/loader/NopLoader.java b/src/main/java/org/jd/core/v1/impl/loader/NopLoader.java similarity index 94% rename from src/test/java/org/jd/core/v1/loader/NopLoader.java rename to src/main/java/org/jd/core/v1/impl/loader/NopLoader.java index 2b149947..3b4dc282 100644 --- a/src/test/java/org/jd/core/v1/loader/NopLoader.java +++ b/src/main/java/org/jd/core/v1/impl/loader/NopLoader.java @@ -5,7 +5,7 @@ * copy and modify the code freely for non-commercial purposes. */ -package org.jd.core.v1.loader; +package org.jd.core.v1.impl.loader; import org.jd.core.v1.api.loader.Loader; import org.jd.core.v1.api.loader.LoaderException; diff --git a/src/test/java/org/jd/core/v1/loader/ZipLoader.java b/src/main/java/org/jd/core/v1/impl/loader/ZipLoader.java similarity index 98% rename from src/test/java/org/jd/core/v1/loader/ZipLoader.java rename to src/main/java/org/jd/core/v1/impl/loader/ZipLoader.java index 3b037cff..2379c5cd 100644 --- a/src/test/java/org/jd/core/v1/loader/ZipLoader.java +++ b/src/main/java/org/jd/core/v1/impl/loader/ZipLoader.java @@ -5,7 +5,7 @@ * copy and modify the code freely for non-commercial purposes. */ -package org.jd.core.v1.loader; +package org.jd.core.v1.impl.loader; import org.jd.core.v1.api.loader.Loader; import org.jd.core.v1.api.loader.LoaderException; diff --git a/src/test/java/org/jd/core/v1/printer/PlainTextMetaPrinter.java b/src/main/java/org/jd/core/v1/impl/printer/PlainTextMetaPrinter.java similarity index 98% rename from src/test/java/org/jd/core/v1/printer/PlainTextMetaPrinter.java rename to src/main/java/org/jd/core/v1/impl/printer/PlainTextMetaPrinter.java index fa9d6ae1..f520c1f3 100644 --- a/src/test/java/org/jd/core/v1/printer/PlainTextMetaPrinter.java +++ b/src/main/java/org/jd/core/v1/impl/printer/PlainTextMetaPrinter.java @@ -5,7 +5,7 @@ * copy and modify the code freely for non-commercial purposes. */ -package org.jd.core.v1.printer; +package org.jd.core.v1.impl.printer; public class PlainTextMetaPrinter extends PlainTextPrinter { // --- Printer --- // diff --git a/src/test/java/org/jd/core/v1/printer/PlainTextPrinter.java b/src/main/java/org/jd/core/v1/impl/printer/PlainTextPrinter.java similarity index 85% rename from src/test/java/org/jd/core/v1/printer/PlainTextPrinter.java rename to src/main/java/org/jd/core/v1/impl/printer/PlainTextPrinter.java index d493af24..5dfe13c3 100644 --- a/src/test/java/org/jd/core/v1/printer/PlainTextPrinter.java +++ b/src/main/java/org/jd/core/v1/impl/printer/PlainTextPrinter.java @@ -5,7 +5,7 @@ * copy and modify the code freely for non-commercial purposes. */ -package org.jd.core.v1.printer; +package org.jd.core.v1.impl.printer; import org.jd.core.v1.api.printer.Printer; @@ -19,16 +19,21 @@ public class PlainTextPrinter implements Printer { protected int realLineNumber = 0; protected String format; - protected boolean escapeUnicodeCharacters; + protected boolean escapeUnicodeCharacters = false; + protected boolean showLineNumbers = true; public PlainTextPrinter() { - this.escapeUnicodeCharacters = false; } public PlainTextPrinter(boolean escapeUnicodeCharacters) { this.escapeUnicodeCharacters = escapeUnicodeCharacters; } + public PlainTextPrinter(boolean escapeUnicodeCharacters, boolean showLineNumbers) { + this.escapeUnicodeCharacters = escapeUnicodeCharacters; + this.showLineNumbers = showLineNumbers; + } + public void init() { sb.setLength(0); realLineNumber = 0; @@ -123,10 +128,13 @@ public void startMarker(int type) {} public void endMarker(int type) {} protected void printLineNumber(int lineNumber) { - sb.append("/*"); - sb.append(String.format(format, ++realLineNumber)); - sb.append(':'); - sb.append(String.format(format, lineNumber)); - sb.append(" */ "); + ++realLineNumber; + if (showLineNumbers) { + sb.append("/*"); + sb.append(String.format(format, realLineNumber)); + sb.append(':'); + sb.append(String.format(format, lineNumber)); + sb.append(" */ "); + } } } diff --git a/src/test/java/org/jd/core/v1/AnnotationConverterTest.java b/src/test/java/org/jd/core/v1/AnnotationConverterTest.java index e0c943b4..77e79eb8 100644 --- a/src/test/java/org/jd/core/v1/AnnotationConverterTest.java +++ b/src/test/java/org/jd/core/v1/AnnotationConverterTest.java @@ -8,7 +8,8 @@ package org.jd.core.v1; import junit.framework.TestCase; -import org.jd.core.v1.loader.ZipLoader; + +import org.jd.core.v1.impl.loader.ZipLoader; import org.jd.core.v1.model.classfile.ClassFile; import org.jd.core.v1.model.classfile.attribute.Annotations; import org.jd.core.v1.model.javasyntax.reference.*; diff --git a/src/test/java/org/jd/core/v1/CfrTest.java b/src/test/java/org/jd/core/v1/CfrTest.java index 6140bd2c..45b2af4a 100644 --- a/src/test/java/org/jd/core/v1/CfrTest.java +++ b/src/test/java/org/jd/core/v1/CfrTest.java @@ -12,9 +12,9 @@ import org.jd.core.v1.api.printer.Printer; import org.jd.core.v1.compiler.CompilerUtil; import org.jd.core.v1.compiler.JavaSourceFileObject; -import org.jd.core.v1.loader.ClassPathLoader; +import org.jd.core.v1.impl.loader.ClassPathLoader; +import org.jd.core.v1.impl.printer.PlainTextPrinter; import org.jd.core.v1.model.message.Message; -import org.jd.core.v1.printer.PlainTextPrinter; import org.jd.core.v1.regex.PatternMaker; import org.jd.core.v1.service.converter.classfiletojavasyntax.ClassFileToJavaSyntaxProcessor; import org.jd.core.v1.service.deserializer.classfile.DeserializeClassFileProcessor; diff --git a/src/test/java/org/jd/core/v1/ClassFileDeserializerTest.java b/src/test/java/org/jd/core/v1/ClassFileDeserializerTest.java index c8aa3fcf..b8f93e5b 100644 --- a/src/test/java/org/jd/core/v1/ClassFileDeserializerTest.java +++ b/src/test/java/org/jd/core/v1/ClassFileDeserializerTest.java @@ -11,7 +11,7 @@ import org.jd.core.v1.api.loader.Loader; import org.jd.core.v1.api.loader.LoaderException; -import org.jd.core.v1.loader.ZipLoader; +import org.jd.core.v1.impl.loader.ZipLoader; import org.jd.core.v1.model.classfile.ClassFile; import org.jd.core.v1.model.classfile.Field; import org.jd.core.v1.model.classfile.attribute.Annotations; diff --git a/src/test/java/org/jd/core/v1/ControlFlowGraphTest.java b/src/test/java/org/jd/core/v1/ControlFlowGraphTest.java index 6740b6d2..86dde959 100644 --- a/src/test/java/org/jd/core/v1/ControlFlowGraphTest.java +++ b/src/test/java/org/jd/core/v1/ControlFlowGraphTest.java @@ -9,8 +9,6 @@ import junit.framework.TestCase; import org.jd.core.v1.api.loader.Loader; -import org.jd.core.v1.loader.ClassPathLoader; -import org.jd.core.v1.loader.ZipLoader; import org.jd.core.v1.model.classfile.Method; import org.jd.core.v1.model.javasyntax.CompilationUnit; import org.jd.core.v1.model.javasyntax.declaration.*; @@ -23,6 +21,8 @@ import org.jd.core.v1.service.converter.classfiletojavasyntax.util.*; import org.jd.core.v1.service.deserializer.classfile.DeserializeClassFileProcessor; import org.jd.core.v1.cfg.ControlFlowGraphPlantUMLWriter; +import org.jd.core.v1.impl.loader.ClassPathLoader; +import org.jd.core.v1.impl.loader.ZipLoader; import org.junit.Test; import java.io.FileInputStream; diff --git a/src/test/java/org/jd/core/v1/JarFileToJavaSourceTest.java b/src/test/java/org/jd/core/v1/JarFileToJavaSourceTest.java index 0e76de9c..980cf9e3 100644 --- a/src/test/java/org/jd/core/v1/JarFileToJavaSourceTest.java +++ b/src/test/java/org/jd/core/v1/JarFileToJavaSourceTest.java @@ -10,9 +10,9 @@ import junit.framework.TestCase; import org.jd.core.v1.compiler.CompilerUtil; import org.jd.core.v1.compiler.JavaSourceFileObject; -import org.jd.core.v1.loader.ZipLoader; +import org.jd.core.v1.impl.loader.ZipLoader; +import org.jd.core.v1.impl.printer.PlainTextPrinter; import org.jd.core.v1.model.message.Message; -import org.jd.core.v1.printer.PlainTextPrinter; import org.jd.core.v1.service.converter.classfiletojavasyntax.ClassFileToJavaSyntaxProcessor; import org.jd.core.v1.service.deserializer.classfile.DeserializeClassFileProcessor; import org.jd.core.v1.service.fragmenter.javasyntaxtojavafragment.JavaSyntaxToJavaFragmentProcessor; diff --git a/src/test/java/org/jd/core/v1/Java9InterfaceTest.java b/src/test/java/org/jd/core/v1/Java9InterfaceTest.java index bbfd1766..30b30227 100644 --- a/src/test/java/org/jd/core/v1/Java9InterfaceTest.java +++ b/src/test/java/org/jd/core/v1/Java9InterfaceTest.java @@ -12,10 +12,10 @@ import org.jd.core.v1.api.printer.Printer; import org.jd.core.v1.compiler.CompilerUtil; import org.jd.core.v1.compiler.JavaSourceFileObject; -import org.jd.core.v1.loader.ClassPathLoader; -import org.jd.core.v1.loader.ZipLoader; +import org.jd.core.v1.impl.loader.ClassPathLoader; +import org.jd.core.v1.impl.loader.ZipLoader; +import org.jd.core.v1.impl.printer.PlainTextPrinter; import org.jd.core.v1.model.message.Message; -import org.jd.core.v1.printer.PlainTextPrinter; import org.jd.core.v1.regex.PatternMaker; import org.jd.core.v1.service.converter.classfiletojavasyntax.ClassFileToJavaSyntaxProcessor; import org.jd.core.v1.service.deserializer.classfile.DeserializeClassFileProcessor; diff --git a/src/test/java/org/jd/core/v1/JavaAnnotationTest.java b/src/test/java/org/jd/core/v1/JavaAnnotationTest.java index d2b76ed1..9aaca2d8 100644 --- a/src/test/java/org/jd/core/v1/JavaAnnotationTest.java +++ b/src/test/java/org/jd/core/v1/JavaAnnotationTest.java @@ -12,10 +12,10 @@ import org.jd.core.v1.api.printer.Printer; import org.jd.core.v1.compiler.CompilerUtil; import org.jd.core.v1.compiler.JavaSourceFileObject; -import org.jd.core.v1.loader.ClassPathLoader; -import org.jd.core.v1.loader.ZipLoader; +import org.jd.core.v1.impl.loader.ClassPathLoader; +import org.jd.core.v1.impl.loader.ZipLoader; +import org.jd.core.v1.impl.printer.PlainTextPrinter; import org.jd.core.v1.model.message.Message; -import org.jd.core.v1.printer.PlainTextPrinter; import org.jd.core.v1.regex.PatternMaker; import org.jd.core.v1.service.converter.classfiletojavasyntax.ClassFileToJavaSyntaxProcessor; import org.jd.core.v1.service.deserializer.classfile.DeserializeClassFileProcessor; diff --git a/src/test/java/org/jd/core/v1/JavaAnonymousClassTest.java b/src/test/java/org/jd/core/v1/JavaAnonymousClassTest.java index c6d2a2fa..89ec2393 100644 --- a/src/test/java/org/jd/core/v1/JavaAnonymousClassTest.java +++ b/src/test/java/org/jd/core/v1/JavaAnonymousClassTest.java @@ -12,10 +12,10 @@ import org.jd.core.v1.api.printer.Printer; import org.jd.core.v1.compiler.CompilerUtil; import org.jd.core.v1.compiler.JavaSourceFileObject; -import org.jd.core.v1.loader.ClassPathLoader; -import org.jd.core.v1.loader.ZipLoader; +import org.jd.core.v1.impl.loader.ClassPathLoader; +import org.jd.core.v1.impl.loader.ZipLoader; +import org.jd.core.v1.impl.printer.PlainTextPrinter; import org.jd.core.v1.model.message.Message; -import org.jd.core.v1.printer.PlainTextPrinter; import org.jd.core.v1.regex.PatternMaker; import org.jd.core.v1.service.converter.classfiletojavasyntax.ClassFileToJavaSyntaxProcessor; import org.jd.core.v1.service.deserializer.classfile.DeserializeClassFileProcessor; diff --git a/src/test/java/org/jd/core/v1/JavaArrayTest.java b/src/test/java/org/jd/core/v1/JavaArrayTest.java index 565302da..c6da4b63 100644 --- a/src/test/java/org/jd/core/v1/JavaArrayTest.java +++ b/src/test/java/org/jd/core/v1/JavaArrayTest.java @@ -12,10 +12,10 @@ import org.jd.core.v1.api.printer.Printer; import org.jd.core.v1.compiler.CompilerUtil; import org.jd.core.v1.compiler.JavaSourceFileObject; -import org.jd.core.v1.loader.ClassPathLoader; -import org.jd.core.v1.loader.ZipLoader; +import org.jd.core.v1.impl.loader.ClassPathLoader; +import org.jd.core.v1.impl.loader.ZipLoader; +import org.jd.core.v1.impl.printer.PlainTextPrinter; import org.jd.core.v1.model.message.Message; -import org.jd.core.v1.printer.PlainTextPrinter; import org.jd.core.v1.regex.PatternMaker; import org.jd.core.v1.service.converter.classfiletojavasyntax.ClassFileToJavaSyntaxProcessor; import org.jd.core.v1.service.deserializer.classfile.DeserializeClassFileProcessor; diff --git a/src/test/java/org/jd/core/v1/JavaAssertTest.java b/src/test/java/org/jd/core/v1/JavaAssertTest.java index fbffee1f..49464c06 100644 --- a/src/test/java/org/jd/core/v1/JavaAssertTest.java +++ b/src/test/java/org/jd/core/v1/JavaAssertTest.java @@ -12,10 +12,10 @@ import org.jd.core.v1.api.printer.Printer; import org.jd.core.v1.compiler.CompilerUtil; import org.jd.core.v1.compiler.JavaSourceFileObject; -import org.jd.core.v1.loader.ClassPathLoader; -import org.jd.core.v1.loader.ZipLoader; +import org.jd.core.v1.impl.loader.ClassPathLoader; +import org.jd.core.v1.impl.loader.ZipLoader; +import org.jd.core.v1.impl.printer.PlainTextPrinter; import org.jd.core.v1.model.message.Message; -import org.jd.core.v1.printer.PlainTextPrinter; import org.jd.core.v1.regex.PatternMaker; import org.jd.core.v1.service.converter.classfiletojavasyntax.ClassFileToJavaSyntaxProcessor; import org.jd.core.v1.service.deserializer.classfile.DeserializeClassFileProcessor; diff --git a/src/test/java/org/jd/core/v1/JavaAutoboxingTest.java b/src/test/java/org/jd/core/v1/JavaAutoboxingTest.java index b05ab2db..7bd75584 100644 --- a/src/test/java/org/jd/core/v1/JavaAutoboxingTest.java +++ b/src/test/java/org/jd/core/v1/JavaAutoboxingTest.java @@ -12,9 +12,9 @@ import org.jd.core.v1.api.printer.Printer; import org.jd.core.v1.compiler.CompilerUtil; import org.jd.core.v1.compiler.JavaSourceFileObject; -import org.jd.core.v1.loader.ClassPathLoader; +import org.jd.core.v1.impl.loader.ClassPathLoader; +import org.jd.core.v1.impl.printer.PlainTextPrinter; import org.jd.core.v1.model.message.Message; -import org.jd.core.v1.printer.PlainTextPrinter; import org.jd.core.v1.regex.PatternMaker; import org.jd.core.v1.service.converter.classfiletojavasyntax.ClassFileToJavaSyntaxProcessor; import org.jd.core.v1.service.deserializer.classfile.DeserializeClassFileProcessor; diff --git a/src/test/java/org/jd/core/v1/JavaBasicTest.java b/src/test/java/org/jd/core/v1/JavaBasicTest.java index 6221955b..4e082757 100644 --- a/src/test/java/org/jd/core/v1/JavaBasicTest.java +++ b/src/test/java/org/jd/core/v1/JavaBasicTest.java @@ -12,10 +12,10 @@ import org.jd.core.v1.api.printer.Printer; import org.jd.core.v1.compiler.CompilerUtil; import org.jd.core.v1.compiler.JavaSourceFileObject; -import org.jd.core.v1.loader.ClassPathLoader; -import org.jd.core.v1.loader.ZipLoader; +import org.jd.core.v1.impl.loader.ClassPathLoader; +import org.jd.core.v1.impl.loader.ZipLoader; +import org.jd.core.v1.impl.printer.PlainTextPrinter; import org.jd.core.v1.model.message.Message; -import org.jd.core.v1.printer.PlainTextPrinter; import org.jd.core.v1.service.converter.classfiletojavasyntax.ClassFileToJavaSyntaxProcessor; import org.jd.core.v1.service.deserializer.classfile.DeserializeClassFileProcessor; import org.jd.core.v1.service.fragmenter.javasyntaxtojavafragment.JavaSyntaxToJavaFragmentProcessor; diff --git a/src/test/java/org/jd/core/v1/JavaEnumTest.java b/src/test/java/org/jd/core/v1/JavaEnumTest.java index 24a7b26f..987932e6 100644 --- a/src/test/java/org/jd/core/v1/JavaEnumTest.java +++ b/src/test/java/org/jd/core/v1/JavaEnumTest.java @@ -12,10 +12,10 @@ import org.jd.core.v1.api.printer.Printer; import org.jd.core.v1.compiler.CompilerUtil; import org.jd.core.v1.compiler.JavaSourceFileObject; -import org.jd.core.v1.loader.ClassPathLoader; -import org.jd.core.v1.loader.ZipLoader; +import org.jd.core.v1.impl.loader.ClassPathLoader; +import org.jd.core.v1.impl.loader.ZipLoader; +import org.jd.core.v1.impl.printer.PlainTextPrinter; import org.jd.core.v1.model.message.Message; -import org.jd.core.v1.printer.PlainTextPrinter; import org.jd.core.v1.regex.PatternMaker; import org.jd.core.v1.service.converter.classfiletojavasyntax.ClassFileToJavaSyntaxProcessor; import org.jd.core.v1.service.deserializer.classfile.DeserializeClassFileProcessor; diff --git a/src/test/java/org/jd/core/v1/JavaFragmentToTokenTest.java b/src/test/java/org/jd/core/v1/JavaFragmentToTokenTest.java index ff185694..110969fb 100644 --- a/src/test/java/org/jd/core/v1/JavaFragmentToTokenTest.java +++ b/src/test/java/org/jd/core/v1/JavaFragmentToTokenTest.java @@ -8,12 +8,13 @@ package org.jd.core.v1; import junit.framework.TestCase; + +import org.jd.core.v1.impl.printer.PlainTextMetaPrinter; +import org.jd.core.v1.impl.printer.PlainTextPrinter; import org.jd.core.v1.model.fragment.Fragment; import org.jd.core.v1.model.javafragment.*; import org.jd.core.v1.model.message.Message; import org.jd.core.v1.model.token.*; -import org.jd.core.v1.printer.PlainTextMetaPrinter; -import org.jd.core.v1.printer.PlainTextPrinter; import org.jd.core.v1.service.fragmenter.javasyntaxtojavafragment.util.JavaFragmentFactory; import org.jd.core.v1.service.layouter.LayoutFragmentProcessor; import org.jd.core.v1.service.writer.WriteTokenProcessor; diff --git a/src/test/java/org/jd/core/v1/JavaGenericTest.java b/src/test/java/org/jd/core/v1/JavaGenericTest.java index 75ceb195..0438e2c9 100644 --- a/src/test/java/org/jd/core/v1/JavaGenericTest.java +++ b/src/test/java/org/jd/core/v1/JavaGenericTest.java @@ -12,10 +12,10 @@ import org.jd.core.v1.api.printer.Printer; import org.jd.core.v1.compiler.CompilerUtil; import org.jd.core.v1.compiler.JavaSourceFileObject; -import org.jd.core.v1.loader.ClassPathLoader; -import org.jd.core.v1.loader.ZipLoader; +import org.jd.core.v1.impl.loader.ClassPathLoader; +import org.jd.core.v1.impl.loader.ZipLoader; +import org.jd.core.v1.impl.printer.PlainTextPrinter; import org.jd.core.v1.model.message.Message; -import org.jd.core.v1.printer.PlainTextPrinter; import org.jd.core.v1.regex.PatternMaker; import org.jd.core.v1.service.converter.classfiletojavasyntax.ClassFileToJavaSyntaxProcessor; import org.jd.core.v1.service.deserializer.classfile.DeserializeClassFileProcessor; diff --git a/src/test/java/org/jd/core/v1/JavaIfElseTest.java b/src/test/java/org/jd/core/v1/JavaIfElseTest.java index 9ac28215..dbbbab42 100644 --- a/src/test/java/org/jd/core/v1/JavaIfElseTest.java +++ b/src/test/java/org/jd/core/v1/JavaIfElseTest.java @@ -12,10 +12,10 @@ import org.jd.core.v1.api.printer.Printer; import org.jd.core.v1.compiler.CompilerUtil; import org.jd.core.v1.compiler.JavaSourceFileObject; -import org.jd.core.v1.loader.ClassPathLoader; -import org.jd.core.v1.loader.ZipLoader; +import org.jd.core.v1.impl.loader.ClassPathLoader; +import org.jd.core.v1.impl.loader.ZipLoader; +import org.jd.core.v1.impl.printer.PlainTextPrinter; import org.jd.core.v1.model.message.Message; -import org.jd.core.v1.printer.PlainTextPrinter; import org.jd.core.v1.regex.PatternMaker; import org.jd.core.v1.service.converter.classfiletojavasyntax.ClassFileToJavaSyntaxProcessor; import org.jd.core.v1.service.deserializer.classfile.DeserializeClassFileProcessor; diff --git a/src/test/java/org/jd/core/v1/JavaInnerOuterClassTest.java b/src/test/java/org/jd/core/v1/JavaInnerOuterClassTest.java index eb8905de..bbf7ae5c 100644 --- a/src/test/java/org/jd/core/v1/JavaInnerOuterClassTest.java +++ b/src/test/java/org/jd/core/v1/JavaInnerOuterClassTest.java @@ -12,10 +12,10 @@ import org.jd.core.v1.api.printer.Printer; import org.jd.core.v1.compiler.CompilerUtil; import org.jd.core.v1.compiler.JavaSourceFileObject; -import org.jd.core.v1.loader.ClassPathLoader; -import org.jd.core.v1.loader.ZipLoader; +import org.jd.core.v1.impl.loader.ClassPathLoader; +import org.jd.core.v1.impl.loader.ZipLoader; +import org.jd.core.v1.impl.printer.PlainTextPrinter; import org.jd.core.v1.model.message.Message; -import org.jd.core.v1.printer.PlainTextPrinter; import org.jd.core.v1.regex.PatternMaker; import org.jd.core.v1.service.converter.classfiletojavasyntax.ClassFileToJavaSyntaxProcessor; import org.jd.core.v1.service.deserializer.classfile.DeserializeClassFileProcessor; diff --git a/src/test/java/org/jd/core/v1/JavaLambdaTest.java b/src/test/java/org/jd/core/v1/JavaLambdaTest.java index 52763630..4894569b 100644 --- a/src/test/java/org/jd/core/v1/JavaLambdaTest.java +++ b/src/test/java/org/jd/core/v1/JavaLambdaTest.java @@ -12,10 +12,10 @@ import org.jd.core.v1.api.printer.Printer; import org.jd.core.v1.compiler.CompilerUtil; import org.jd.core.v1.compiler.JavaSourceFileObject; -import org.jd.core.v1.loader.ClassPathLoader; -import org.jd.core.v1.loader.ZipLoader; +import org.jd.core.v1.impl.loader.ClassPathLoader; +import org.jd.core.v1.impl.loader.ZipLoader; +import org.jd.core.v1.impl.printer.PlainTextPrinter; import org.jd.core.v1.model.message.Message; -import org.jd.core.v1.printer.PlainTextPrinter; import org.jd.core.v1.regex.PatternMaker; import org.jd.core.v1.service.converter.classfiletojavasyntax.ClassFileToJavaSyntaxProcessor; import org.jd.core.v1.service.deserializer.classfile.DeserializeClassFileProcessor; diff --git a/src/test/java/org/jd/core/v1/JavaLoopTest.java b/src/test/java/org/jd/core/v1/JavaLoopTest.java index 3409f99f..0db94d14 100644 --- a/src/test/java/org/jd/core/v1/JavaLoopTest.java +++ b/src/test/java/org/jd/core/v1/JavaLoopTest.java @@ -12,10 +12,10 @@ import org.jd.core.v1.api.printer.Printer; import org.jd.core.v1.compiler.CompilerUtil; import org.jd.core.v1.compiler.JavaSourceFileObject; -import org.jd.core.v1.loader.ClassPathLoader; -import org.jd.core.v1.loader.ZipLoader; +import org.jd.core.v1.impl.loader.ClassPathLoader; +import org.jd.core.v1.impl.loader.ZipLoader; +import org.jd.core.v1.impl.printer.PlainTextPrinter; import org.jd.core.v1.model.message.Message; -import org.jd.core.v1.printer.PlainTextPrinter; import org.jd.core.v1.regex.PatternMaker; import org.jd.core.v1.service.converter.classfiletojavasyntax.ClassFileToJavaSyntaxProcessor; import org.jd.core.v1.service.deserializer.classfile.DeserializeClassFileProcessor; diff --git a/src/test/java/org/jd/core/v1/JavaMethodOverloadingTest.java b/src/test/java/org/jd/core/v1/JavaMethodOverloadingTest.java index 59c4aad7..1f51cc40 100644 --- a/src/test/java/org/jd/core/v1/JavaMethodOverloadingTest.java +++ b/src/test/java/org/jd/core/v1/JavaMethodOverloadingTest.java @@ -12,9 +12,9 @@ import org.jd.core.v1.api.printer.Printer; import org.jd.core.v1.compiler.CompilerUtil; import org.jd.core.v1.compiler.JavaSourceFileObject; -import org.jd.core.v1.loader.ClassPathLoader; +import org.jd.core.v1.impl.loader.ClassPathLoader; +import org.jd.core.v1.impl.printer.PlainTextPrinter; import org.jd.core.v1.model.message.Message; -import org.jd.core.v1.printer.PlainTextPrinter; import org.jd.core.v1.regex.PatternMaker; import org.jd.core.v1.service.converter.classfiletojavasyntax.ClassFileToJavaSyntaxProcessor; import org.jd.core.v1.service.deserializer.classfile.DeserializeClassFileProcessor; diff --git a/src/test/java/org/jd/core/v1/JavaOperatorPrecedenceTest.java b/src/test/java/org/jd/core/v1/JavaOperatorPrecedenceTest.java index e0f08ba3..37a05f4f 100644 --- a/src/test/java/org/jd/core/v1/JavaOperatorPrecedenceTest.java +++ b/src/test/java/org/jd/core/v1/JavaOperatorPrecedenceTest.java @@ -12,9 +12,9 @@ import org.jd.core.v1.api.printer.Printer; import org.jd.core.v1.compiler.CompilerUtil; import org.jd.core.v1.compiler.JavaSourceFileObject; -import org.jd.core.v1.loader.ClassPathLoader; +import org.jd.core.v1.impl.loader.ClassPathLoader; +import org.jd.core.v1.impl.printer.PlainTextPrinter; import org.jd.core.v1.model.message.Message; -import org.jd.core.v1.printer.PlainTextPrinter; import org.jd.core.v1.regex.PatternMaker; import org.jd.core.v1.service.converter.classfiletojavasyntax.ClassFileToJavaSyntaxProcessor; import org.jd.core.v1.service.deserializer.classfile.DeserializeClassFileProcessor; diff --git a/src/test/java/org/jd/core/v1/JavaSwitchTest.java b/src/test/java/org/jd/core/v1/JavaSwitchTest.java index f2fa604a..bfc1a4cb 100644 --- a/src/test/java/org/jd/core/v1/JavaSwitchTest.java +++ b/src/test/java/org/jd/core/v1/JavaSwitchTest.java @@ -12,10 +12,10 @@ import org.jd.core.v1.api.printer.Printer; import org.jd.core.v1.compiler.CompilerUtil; import org.jd.core.v1.compiler.JavaSourceFileObject; -import org.jd.core.v1.loader.ClassPathLoader; -import org.jd.core.v1.loader.ZipLoader; +import org.jd.core.v1.impl.loader.ClassPathLoader; +import org.jd.core.v1.impl.loader.ZipLoader; +import org.jd.core.v1.impl.printer.PlainTextPrinter; import org.jd.core.v1.model.message.Message; -import org.jd.core.v1.printer.PlainTextPrinter; import org.jd.core.v1.regex.PatternMaker; import org.jd.core.v1.service.converter.classfiletojavasyntax.ClassFileToJavaSyntaxProcessor; import org.jd.core.v1.service.deserializer.classfile.DeserializeClassFileProcessor; diff --git a/src/test/java/org/jd/core/v1/JavaSynchronizedBlockTest.java b/src/test/java/org/jd/core/v1/JavaSynchronizedBlockTest.java index 52cba281..bee4c0be 100644 --- a/src/test/java/org/jd/core/v1/JavaSynchronizedBlockTest.java +++ b/src/test/java/org/jd/core/v1/JavaSynchronizedBlockTest.java @@ -12,10 +12,10 @@ import org.jd.core.v1.api.printer.Printer; import org.jd.core.v1.compiler.CompilerUtil; import org.jd.core.v1.compiler.JavaSourceFileObject; -import org.jd.core.v1.loader.ClassPathLoader; -import org.jd.core.v1.loader.ZipLoader; +import org.jd.core.v1.impl.loader.ClassPathLoader; +import org.jd.core.v1.impl.loader.ZipLoader; +import org.jd.core.v1.impl.printer.PlainTextPrinter; import org.jd.core.v1.model.message.Message; -import org.jd.core.v1.printer.PlainTextPrinter; import org.jd.core.v1.regex.PatternMaker; import org.jd.core.v1.service.converter.classfiletojavasyntax.ClassFileToJavaSyntaxProcessor; import org.jd.core.v1.service.deserializer.classfile.DeserializeClassFileProcessor; diff --git a/src/test/java/org/jd/core/v1/JavaSyntaxToJavaSourceTest.java b/src/test/java/org/jd/core/v1/JavaSyntaxToJavaSourceTest.java index 0a2d9e1d..1ae5c74f 100644 --- a/src/test/java/org/jd/core/v1/JavaSyntaxToJavaSourceTest.java +++ b/src/test/java/org/jd/core/v1/JavaSyntaxToJavaSourceTest.java @@ -8,7 +8,9 @@ package org.jd.core.v1; import junit.framework.TestCase; -import org.jd.core.v1.loader.NopLoader; + +import org.jd.core.v1.impl.loader.NopLoader; +import org.jd.core.v1.impl.printer.PlainTextMetaPrinter; import org.jd.core.v1.model.javasyntax.CompilationUnit; import org.jd.core.v1.model.javasyntax.declaration.*; import org.jd.core.v1.model.javasyntax.expression.*; @@ -18,7 +20,6 @@ import org.jd.core.v1.model.javasyntax.type.Type; import org.jd.core.v1.model.javasyntax.type.Types; import org.jd.core.v1.model.message.Message; -import org.jd.core.v1.printer.PlainTextMetaPrinter; import org.jd.core.v1.service.fragmenter.javasyntaxtojavafragment.JavaSyntaxToJavaFragmentProcessor; import org.jd.core.v1.service.layouter.LayoutFragmentProcessor; import org.jd.core.v1.service.tokenizer.javafragmenttotoken.JavaFragmentToTokenProcessor; diff --git a/src/test/java/org/jd/core/v1/JavaTernaryOperatorTest.java b/src/test/java/org/jd/core/v1/JavaTernaryOperatorTest.java index 22b0dced..1919de6f 100644 --- a/src/test/java/org/jd/core/v1/JavaTernaryOperatorTest.java +++ b/src/test/java/org/jd/core/v1/JavaTernaryOperatorTest.java @@ -12,10 +12,10 @@ import org.jd.core.v1.api.printer.Printer; import org.jd.core.v1.compiler.CompilerUtil; import org.jd.core.v1.compiler.JavaSourceFileObject; -import org.jd.core.v1.loader.ClassPathLoader; -import org.jd.core.v1.loader.ZipLoader; +import org.jd.core.v1.impl.loader.ClassPathLoader; +import org.jd.core.v1.impl.loader.ZipLoader; +import org.jd.core.v1.impl.printer.PlainTextPrinter; import org.jd.core.v1.model.message.Message; -import org.jd.core.v1.printer.PlainTextPrinter; import org.jd.core.v1.regex.PatternMaker; import org.jd.core.v1.service.converter.classfiletojavasyntax.ClassFileToJavaSyntaxProcessor; import org.jd.core.v1.service.deserializer.classfile.DeserializeClassFileProcessor; diff --git a/src/test/java/org/jd/core/v1/JavaTryCatchFinallyTest.java b/src/test/java/org/jd/core/v1/JavaTryCatchFinallyTest.java index 76130389..1dcd055a 100644 --- a/src/test/java/org/jd/core/v1/JavaTryCatchFinallyTest.java +++ b/src/test/java/org/jd/core/v1/JavaTryCatchFinallyTest.java @@ -12,10 +12,10 @@ import org.jd.core.v1.api.printer.Printer; import org.jd.core.v1.compiler.CompilerUtil; import org.jd.core.v1.compiler.JavaSourceFileObject; -import org.jd.core.v1.loader.ClassPathLoader; -import org.jd.core.v1.loader.ZipLoader; +import org.jd.core.v1.impl.loader.ClassPathLoader; +import org.jd.core.v1.impl.loader.ZipLoader; +import org.jd.core.v1.impl.printer.PlainTextPrinter; import org.jd.core.v1.model.message.Message; -import org.jd.core.v1.printer.PlainTextPrinter; import org.jd.core.v1.regex.PatternMaker; import org.jd.core.v1.service.converter.classfiletojavasyntax.ClassFileToJavaSyntaxProcessor; import org.jd.core.v1.service.deserializer.classfile.DeserializeClassFileProcessor; diff --git a/src/test/java/org/jd/core/v1/LayoutFragmentProcessorTest.java b/src/test/java/org/jd/core/v1/LayoutFragmentProcessorTest.java index ca8bcc05..5af05f53 100644 --- a/src/test/java/org/jd/core/v1/LayoutFragmentProcessorTest.java +++ b/src/test/java/org/jd/core/v1/LayoutFragmentProcessorTest.java @@ -8,9 +8,10 @@ package org.jd.core.v1; import junit.framework.TestCase; -import org.jd.core.v1.loader.ZipLoader; + +import org.jd.core.v1.impl.loader.ZipLoader; +import org.jd.core.v1.impl.printer.PlainTextPrinter; import org.jd.core.v1.model.message.Message; -import org.jd.core.v1.printer.PlainTextPrinter; import org.jd.core.v1.service.converter.classfiletojavasyntax.ClassFileToJavaSyntaxProcessor; import org.jd.core.v1.service.deserializer.classfile.DeserializeClassFileProcessor; import org.jd.core.v1.service.fragmenter.javasyntaxtojavafragment.JavaSyntaxToJavaFragmentProcessor; diff --git a/src/test/java/org/jd/core/v1/PopulateBindingsForStaticMethodVisitorTest.java b/src/test/java/org/jd/core/v1/PopulateBindingsForStaticMethodVisitorTest.java index 15a32766..c3c61a1a 100644 --- a/src/test/java/org/jd/core/v1/PopulateBindingsForStaticMethodVisitorTest.java +++ b/src/test/java/org/jd/core/v1/PopulateBindingsForStaticMethodVisitorTest.java @@ -8,7 +8,8 @@ package org.jd.core.v1; import junit.framework.TestCase; -import org.jd.core.v1.loader.ClassPathLoader; + +import org.jd.core.v1.impl.loader.ClassPathLoader; import org.jd.core.v1.model.javasyntax.type.*; import org.jd.core.v1.service.converter.classfiletojavasyntax.util.TypeMaker; import org.jd.core.v1.service.converter.classfiletojavasyntax.visitor.PopulateBindingsWithTypeArgumentVisitor; diff --git a/src/test/java/org/jd/core/v1/SignatureParserTest.java b/src/test/java/org/jd/core/v1/SignatureParserTest.java index 5d0fbb0d..b32a3501 100644 --- a/src/test/java/org/jd/core/v1/SignatureParserTest.java +++ b/src/test/java/org/jd/core/v1/SignatureParserTest.java @@ -8,8 +8,9 @@ package org.jd.core.v1; import junit.framework.TestCase; -import org.jd.core.v1.loader.ClassPathLoader; -import org.jd.core.v1.loader.ZipLoader; + +import org.jd.core.v1.impl.loader.ClassPathLoader; +import org.jd.core.v1.impl.loader.ZipLoader; import org.jd.core.v1.model.classfile.ClassFile; import org.jd.core.v1.model.javasyntax.type.*; import org.jd.core.v1.model.message.Message; diff --git a/src/test/java/org/jd/core/v1/TypeMakerTest.java b/src/test/java/org/jd/core/v1/TypeMakerTest.java index 55fd0224..02d025f0 100644 --- a/src/test/java/org/jd/core/v1/TypeMakerTest.java +++ b/src/test/java/org/jd/core/v1/TypeMakerTest.java @@ -9,8 +9,8 @@ import junit.framework.TestCase; import org.apache.commons.collections4.iterators.AbstractUntypedIteratorDecorator; -import org.jd.core.v1.loader.ClassPathLoader; -import org.jd.core.v1.loader.ZipLoader; +import org.jd.core.v1.impl.loader.ClassPathLoader; +import org.jd.core.v1.impl.loader.ZipLoader; import org.jd.core.v1.model.javasyntax.type.ObjectType; import org.jd.core.v1.model.javasyntax.type.TypeArguments; import org.jd.core.v1.model.javasyntax.type.WildcardExtendsTypeArgument; diff --git a/src/test/java/org/jd/core/v1/WriteTokenTest.java b/src/test/java/org/jd/core/v1/WriteTokenTest.java index d098a158..832a645e 100644 --- a/src/test/java/org/jd/core/v1/WriteTokenTest.java +++ b/src/test/java/org/jd/core/v1/WriteTokenTest.java @@ -7,9 +7,9 @@ package org.jd.core.v1; +import org.jd.core.v1.impl.printer.PlainTextMetaPrinter; import org.jd.core.v1.model.message.Message; import org.jd.core.v1.model.token.*; -import org.jd.core.v1.printer.PlainTextMetaPrinter; import org.jd.core.v1.service.writer.WriteTokenProcessor; import org.jd.core.v1.util.DefaultList; import org.junit.Assert; From f3a726fea51e9fa2d3d0df9aa9cdd42ac9242a6f Mon Sep 17 00:00:00 2001 From: luca-vercelli Date: Fri, 17 Sep 2021 14:16:57 +0200 Subject: [PATCH 2/4] jd-cli --- src/main/java/org/jd/core/v1/cli/CliMain.java | 216 ++++++++++++++++++ 1 file changed, 216 insertions(+) create mode 100644 src/main/java/org/jd/core/v1/cli/CliMain.java diff --git a/src/main/java/org/jd/core/v1/cli/CliMain.java b/src/main/java/org/jd/core/v1/cli/CliMain.java new file mode 100644 index 00000000..20ae3321 --- /dev/null +++ b/src/main/java/org/jd/core/v1/cli/CliMain.java @@ -0,0 +1,216 @@ +package org.jd.core.v1.cli; + +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLClassLoader; +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; + +import org.jd.core.v1.ClassFileToJavaSourceDecompiler; +import org.jd.core.v1.api.Decompiler; +import org.jd.core.v1.api.loader.Loader; +import org.jd.core.v1.api.printer.Printer; +import org.jd.core.v1.impl.loader.DirectoryLoader; +import org.jd.core.v1.impl.printer.PlainTextPrinter; + +public class CliMain { + + public final static String VERSION = "1.0 2021"; + + public static void usage() { + System.out.println("Usage:"); + System.out.println(" java org.jd.core.v1.cli [-h |-v| [options] ]"); + System.out.println("Decompile all .class files inside given folder."); + System.out.println("Actions:"); + System.out.println(" -h | --help print this help message then exit"); + System.out.println(" -v | --version print version then exit"); + System.out.println("Options:"); + System.out.println(" -d | --dest-folder java files folder (default classes folder)"); + System.out.println(" --override override existing java files"); + System.out.println(" --escape-unicode escape unidoce characters"); + System.out.println(" --no-line-numbers omit line numbers"); + } + + public static void version() { + System.out.println(VERSION); + } + + public static void main(String[] args) { + + if (args.length == 0) { + System.err.println("Missing arguments."); + usage(); + System.exit(1); + } + + if ("-h".equals(args[0]) || "--help".equals(args[0])) { + usage(); + return; + } + if ("-v".equals(args[0]) || "--version".equals(args[0])) { + version(); + return; + } + + int i = 0; // current CLI argument + File srcFolder = null; + File destFolder = null; + boolean override = false; + boolean escapeUnicode = false; + boolean printLineNumbers = true; + + while (i < args.length) { + if ("-d".equals(args[i]) || "--dest-folder".equals(args[i])) { + destFolder = new File(args[++i]); + } else if ("--override".equals(args[i])) { + override = true; + } else if ("--escape-unicode".equals(args[i])) { + escapeUnicode = true; + } else if ("--no-line-numbers".equals(args[i])) { + printLineNumbers = false; + } else if (args[i].startsWith("-")) { + System.err.println("Unknown option: " + args[i]); + usage(); + System.exit(1); + } else if (args.length - i > 1) { + System.err.println("Too many arguments."); + usage(); + System.exit(1); + } else { + srcFolder = new File(args[i]); + } + ++i; + } + if (srcFolder == null || srcFolder.getPath().trim().isEmpty()) { + System.err.println("Missing classes folder."); + usage(); + System.exit(1); + } + if (destFolder == null) { + destFolder = srcFolder; + } + + prepareFolders(srcFolder, destFolder); + + // adding whole folder to classpath should give better decompilation, doesn't + // it? + addToClassPath(srcFolder); + + Loader loader = new DirectoryLoader(srcFolder); + Printer printer = new PlainTextPrinter(escapeUnicode, printLineNumbers); + Decompiler decompiler = new ClassFileToJavaSourceDecompiler(); + List internalNames = listClasses(srcFolder); + for (String internalName : internalNames) { + try { + decompiler.decompile(loader, printer, internalName); + } catch (Exception e) { + System.err.println("Exception while decompiling " + internalName + " : " + e.getMessage()); + continue; + } + try { + writeFile(printer.toString(), destFolder, internalName, override); + } catch (IOException e) { + System.err.println("Exception while writing " + destFolder.getPath() + File.separator + internalName + + " : " + e.getMessage()); + } + } + } + + public static void prepareFolders(File srcFolder, File destFolder) { + if (!srcFolder.exists()) { + System.err.println("Classes folder does not exists."); + System.exit(2); + } + if (!srcFolder.canRead()) { + System.err.println("Classes folder is not readable."); + System.exit(3); + } + if (!srcFolder.isDirectory()) { + System.err.println("Classes folder is not a directory."); + System.exit(4); + } + if (!destFolder.exists()) { + destFolder.mkdirs(); + } else if (!destFolder.isDirectory()) { + System.err.println("Destination folder is not a directory."); + System.exit(5); + } + if (!destFolder.canWrite()) { + System.err.println("Destination folder is not writable."); + System.exit(6); + } + } + + /** + * Add a folder to classpath + * + * @see https://stackoverflow.com/a/7884406/5116356 + */ + @SuppressWarnings("deprecation") + public static void addToClassPath(File folder) { + URL u; + try { + u = folder.toURL(); + } catch (MalformedURLException e) { + throw new RuntimeException(e); // can this happen ?!? + } + URLClassLoader urlClassLoader = (URLClassLoader) ClassLoader.getSystemClassLoader(); + Class urlClass = URLClassLoader.class; + try { + Method method = urlClass.getDeclaredMethod("addURL", new Class[] { URL.class }); + method.setAccessible(true); + method.invoke(urlClassLoader, new Object[] { u }); + } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException + | SecurityException e) { + throw new RuntimeException(e); + } + } + + public static List listClasses(File srcFolder) { + List list = new ArrayList<>(); + listClasses(srcFolder.listFiles(), list); + List ls = list.stream() // + .map(x -> getClassName(srcFolder, x)) // + .collect(Collectors.toList()); + return ls; + } + + public static String getClassName(File srcFolder, File classFile) { + String s = classFile.getPath(); + final int beginIndex = srcFolder.getPath().length(); + final int difflen = ".class".length(); + s = s.substring(beginIndex, s.length() - difflen); + if (s.startsWith("/")) { + s = s.substring(1); + } + return s; + } + + private static void listClasses(File[] files, List result) { + for (File file : files) { + if (file.isDirectory()) { + listClasses(file.listFiles(), result); + } else if (file.getName().endsWith(".class") && !file.getName().contains("$")) { + result.add(file); + } + } + } + + public static void writeFile(String source, File destFolder, String internalName, boolean override) + throws IOException { + File f = new File(destFolder, internalName + ".java"); + if (f.exists() && !override) { + System.err.println("Skipping existing file " + f.getPath()); + return; + } + try (FileWriter fw = new FileWriter(f)) { + fw.write(source); + } + } +} From d626b1a08c1fa39d24bf2f5e4dff25e6dbe36a08 Mon Sep 17 00:00:00 2001 From: luca-vercelli Date: Fri, 17 Sep 2021 14:18:42 +0200 Subject: [PATCH 3/4] doc --- src/main/java/org/jd/core/v1/impl/loader/ClassPathLoader.java | 3 +++ src/main/java/org/jd/core/v1/impl/loader/DirectoryLoader.java | 3 +++ src/main/java/org/jd/core/v1/impl/loader/NopLoader.java | 3 +++ src/main/java/org/jd/core/v1/impl/loader/ZipLoader.java | 4 ++++ .../org/jd/core/v1/impl/printer/PlainTextMetaPrinter.java | 3 +++ .../java/org/jd/core/v1/impl/printer/PlainTextPrinter.java | 4 ++++ 6 files changed, 20 insertions(+) diff --git a/src/main/java/org/jd/core/v1/impl/loader/ClassPathLoader.java b/src/main/java/org/jd/core/v1/impl/loader/ClassPathLoader.java index 0dcc6c2d..fc5cb72e 100644 --- a/src/main/java/org/jd/core/v1/impl/loader/ClassPathLoader.java +++ b/src/main/java/org/jd/core/v1/impl/loader/ClassPathLoader.java @@ -14,6 +14,9 @@ import java.io.IOException; import java.io.InputStream; +/** + * A Loader that loads classes from classpath. + */ public class ClassPathLoader implements Loader { @Override public byte[] load(String internalName) throws LoaderException { diff --git a/src/main/java/org/jd/core/v1/impl/loader/DirectoryLoader.java b/src/main/java/org/jd/core/v1/impl/loader/DirectoryLoader.java index 7961c26f..28f50a25 100644 --- a/src/main/java/org/jd/core/v1/impl/loader/DirectoryLoader.java +++ b/src/main/java/org/jd/core/v1/impl/loader/DirectoryLoader.java @@ -14,6 +14,9 @@ import java.io.File; import java.io.FileInputStream; +/** + * A loader that loads classes from a given filesystem folder. + */ public class DirectoryLoader implements Loader { protected File base; diff --git a/src/main/java/org/jd/core/v1/impl/loader/NopLoader.java b/src/main/java/org/jd/core/v1/impl/loader/NopLoader.java index 3b4dc282..48fbb11d 100644 --- a/src/main/java/org/jd/core/v1/impl/loader/NopLoader.java +++ b/src/main/java/org/jd/core/v1/impl/loader/NopLoader.java @@ -10,6 +10,9 @@ import org.jd.core.v1.api.loader.Loader; import org.jd.core.v1.api.loader.LoaderException; +/** + * A Loader that loads nothing + */ public class NopLoader implements Loader { @Override public byte[] load(String internalName) throws LoaderException { diff --git a/src/main/java/org/jd/core/v1/impl/loader/ZipLoader.java b/src/main/java/org/jd/core/v1/impl/loader/ZipLoader.java index 2379c5cd..b78de6e0 100644 --- a/src/main/java/org/jd/core/v1/impl/loader/ZipLoader.java +++ b/src/main/java/org/jd/core/v1/impl/loader/ZipLoader.java @@ -17,6 +17,10 @@ import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; +/** + * A loader that loads classes from within ZIP archive (e.g. JAR). + * All classes inside zip file are loaded in memory as byte arrays. + */ public class ZipLoader implements Loader { protected HashMap map = new HashMap<>(); diff --git a/src/main/java/org/jd/core/v1/impl/printer/PlainTextMetaPrinter.java b/src/main/java/org/jd/core/v1/impl/printer/PlainTextMetaPrinter.java index f520c1f3..57d244e5 100644 --- a/src/main/java/org/jd/core/v1/impl/printer/PlainTextMetaPrinter.java +++ b/src/main/java/org/jd/core/v1/impl/printer/PlainTextMetaPrinter.java @@ -7,6 +7,9 @@ package org.jd.core.v1.impl.printer; +/** + * A PlainTextPrinter that add some extra meta information to source code. + */ public class PlainTextMetaPrinter extends PlainTextPrinter { // --- Printer --- // public void printStringConstant(String constant, String ownerInternalName) { diff --git a/src/main/java/org/jd/core/v1/impl/printer/PlainTextPrinter.java b/src/main/java/org/jd/core/v1/impl/printer/PlainTextPrinter.java index 5dfe13c3..9e06368b 100644 --- a/src/main/java/org/jd/core/v1/impl/printer/PlainTextPrinter.java +++ b/src/main/java/org/jd/core/v1/impl/printer/PlainTextPrinter.java @@ -10,6 +10,10 @@ import org.jd.core.v1.api.printer.Printer; +/** + * A Printer that stores Java source inside a StringBuilder. Retrieve final + * source code using toString() method. + */ public class PlainTextPrinter implements Printer { protected static final String TAB = " "; protected static final String NEWLINE = "\n"; From 7aee5c0ca8472ae7b0fcd9315f61d97d45d9b777 Mon Sep 17 00:00:00 2001 From: luca-vercelli Date: Sun, 19 Sep 2021 07:42:59 +0200 Subject: [PATCH 4/4] bugfix --- src/main/java/org/jd/core/v1/cli/CliMain.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main/java/org/jd/core/v1/cli/CliMain.java b/src/main/java/org/jd/core/v1/cli/CliMain.java index 20ae3321..0cfa2c7d 100644 --- a/src/main/java/org/jd/core/v1/cli/CliMain.java +++ b/src/main/java/org/jd/core/v1/cli/CliMain.java @@ -96,6 +96,11 @@ public static void main(String[] args) { destFolder = srcFolder; } + main(srcFolder, destFolder, override, escapeUnicode, printLineNumbers); + } + + public static void main(File srcFolder, File destFolder, boolean override, boolean escapeUnicode, + boolean printLineNumbers) { prepareFolders(srcFolder, destFolder); // adding whole folder to classpath should give better decompilation, doesn't @@ -209,6 +214,7 @@ public static void writeFile(String source, File destFolder, String internalName System.err.println("Skipping existing file " + f.getPath()); return; } + f.getParentFile().mkdirs(); try (FileWriter fw = new FileWriter(f)) { fw.write(source); }