Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
keyescgm
jadx
提交
6016b902
J
jadx
项目概览
keyescgm
/
jadx
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
J
jadx
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
6016b902
编写于
2月 26, 2022
作者:
S
Skylot
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
test: fix usage of Eclipse compiler
上级
5852da1e
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
61 addition
and
21 deletion
+61
-21
build.gradle
build.gradle
+0
-1
jadx-core/build.gradle
jadx-core/build.gradle
+2
-1
jadx-core/src/test/java/jadx/tests/api/IntegrationTest.java
jadx-core/src/test/java/jadx/tests/api/IntegrationTest.java
+5
-4
jadx-core/src/test/java/jadx/tests/api/compiler/EclipseCompilerUtils.java
...st/java/jadx/tests/api/compiler/EclipseCompilerUtils.java
+18
-0
jadx-core/src/test/java/jadx/tests/api/compiler/TestCompiler.java
...e/src/test/java/jadx/tests/api/compiler/TestCompiler.java
+16
-13
jadx-core/src/test/java/jadx/tests/api/extensions/profiles/JadxTestProfilesExtension.java
...ts/api/extensions/profiles/JadxTestProfilesExtension.java
+8
-1
jadx-core/src/test/java/jadx/tests/api/extensions/profiles/TestProfile.java
.../java/jadx/tests/api/extensions/profiles/TestProfile.java
+12
-1
未找到文件。
build.gradle
浏览文件 @
6016b902
...
...
@@ -38,7 +38,6 @@ allprojects {
testImplementation
'org.junit.jupiter:junit-jupiter-api:5.8.2'
testRuntimeOnly
'org.junit.jupiter:junit-jupiter-engine:5.8.2'
testImplementation
'org.eclipse.jdt.core.compiler:ecj:4.6.1'
testCompileOnly
'org.jetbrains:annotations:23.0.0'
}
...
...
jadx-core/build.gradle
浏览文件 @
6016b902
...
...
@@ -20,7 +20,8 @@ dependencies {
testRuntimeOnly
(
project
(
':jadx-plugins:jadx-java-input'
))
testRuntimeOnly
(
project
(
':jadx-plugins:jadx-raung-input'
))
testImplementation
(
'tools.profiler:async-profiler:1.8.3'
)
testImplementation
'org.eclipse.jdt:ecj:3.28.0'
testImplementation
'tools.profiler:async-profiler:1.8.3'
}
test
{
...
...
jadx-core/src/test/java/jadx/tests/api/IntegrationTest.java
浏览文件 @
6016b902
...
...
@@ -65,7 +65,6 @@ import static org.hamcrest.Matchers.not;
import
static
org
.
hamcrest
.
Matchers
.
notNullValue
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertFalse
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertNotNull
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertTrue
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
fail
;
public
abstract
class
IntegrationTest
extends
TestUtils
{
...
...
@@ -436,9 +435,10 @@ public abstract class IntegrationTest extends TestUtils {
return
;
}
try
{
// TODO: eclipse uses files or compilation units providers added in Java 9
compilerOptions
.
setUseEclipseCompiler
(
false
);
decompiledCompiler
=
new
TestCompiler
(
compilerOptions
);
boolean
result
=
decompiledCompiler
.
compileNodes
(
clsList
);
assertTrue
(
result
,
"Compilation failed"
);
decompiledCompiler
.
compileNodes
(
clsList
);
System
.
out
.
println
(
"Compilation: PASSED"
);
}
catch
(
Exception
e
)
{
fail
(
e
);
...
...
@@ -514,7 +514,8 @@ public abstract class IntegrationTest extends TestUtils {
this
.
compilerOptions
.
setIncludeDebugInfo
(
false
);
}
protected
void
useEclipseCompiler
()
{
public
void
useEclipseCompiler
()
{
Assumptions
.
assumeTrue
(
JavaUtils
.
checkJavaVersion
(
11
),
"eclipse compiler library using Java 11"
);
this
.
compilerOptions
.
setUseEclipseCompiler
(
true
);
}
...
...
jadx-core/src/test/java/jadx/tests/api/compiler/EclipseCompilerUtils.java
0 → 100644
浏览文件 @
6016b902
package
jadx.tests.api.compiler
;
import
javax.tools.JavaCompiler
;
public
class
EclipseCompilerUtils
{
public
static
JavaCompiler
newInstance
()
{
if
(!
JavaUtils
.
checkJavaVersion
(
11
))
{
throw
new
IllegalArgumentException
(
"Eclipse compiler build with Java 11"
);
}
try
{
Class
<?>
ecjCls
=
Class
.
forName
(
"org.eclipse.jdt.internal.compiler.tool.EclipseCompiler"
);
return
(
JavaCompiler
)
ecjCls
.
getConstructor
().
newInstance
();
}
catch
(
Exception
e
)
{
throw
new
RuntimeException
(
"Failed to init Eclipse compiler"
,
e
);
}
}
}
jadx-core/src/test/java/jadx/tests/api/compiler/TestCompiler.java
浏览文件 @
6016b902
...
...
@@ -3,20 +3,22 @@ package jadx.tests.api.compiler;
import
java.io.Closeable
;
import
java.io.File
;
import
java.io.IOException
;
import
java.io.PrintWriter
;
import
java.io.Writer
;
import
java.lang.reflect.Method
;
import
java.nio.file.Files
;
import
java.nio.file.Path
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.Collections
;
import
java.util.List
;
import
java.util.Locale
;
import
javax.tools.DiagnosticListener
;
import
javax.tools.JavaCompiler
;
import
javax.tools.JavaCompiler.CompilationTask
;
import
javax.tools.JavaFileObject
;
import
javax.tools.ToolProvider
;
import
org.eclipse.jdt.internal.compiler.tool.EclipseCompiler
;
import
org.jetbrains.annotations.NotNull
;
import
jadx.core.dex.nodes.ClassNode
;
...
...
@@ -38,7 +40,7 @@ public class TestCompiler implements Closeable {
+
"current: "
+
JavaUtils
.
JAVA_VERSION_INT
+
", required: "
+
javaVersion
);
}
if
(
options
.
isUseEclipseCompiler
())
{
compiler
=
new
EclipseCompiler
();
compiler
=
EclipseCompilerUtils
.
newInstance
();
}
else
{
compiler
=
ToolProvider
.
getSystemJavaCompiler
();
if
(
compiler
==
null
)
{
...
...
@@ -49,11 +51,7 @@ public class TestCompiler implements Closeable {
}
public
List
<
File
>
compileFiles
(
List
<
File
>
sourceFiles
,
Path
outTmp
)
throws
IOException
{
List
<
JavaFileObject
>
jfObjects
=
fileManager
.
getJavaFileObjectsFromFiles
(
sourceFiles
);
boolean
success
=
compile
(
jfObjects
);
if
(!
success
)
{
return
Collections
.
emptyList
();
}
compile
(
fileManager
.
getJavaFileObjectsFromFiles
(
sourceFiles
));
List
<
File
>
files
=
new
ArrayList
<>();
for
(
JavaClassObject
classObject
:
fileManager
.
getClassLoader
().
getClassObjects
())
{
Path
path
=
outTmp
.
resolve
(
classObject
.
getName
().
replace
(
'.'
,
'/'
)
+
".class"
);
...
...
@@ -64,15 +62,15 @@ public class TestCompiler implements Closeable {
return
files
;
}
public
boolean
compileNodes
(
List
<
ClassNode
>
clsNodeList
)
{
public
void
compileNodes
(
List
<
ClassNode
>
clsNodeList
)
{
List
<
JavaFileObject
>
jfObjects
=
new
ArrayList
<>(
clsNodeList
.
size
());
for
(
ClassNode
clsNode
:
clsNodeList
)
{
jfObjects
.
add
(
new
StringJavaFileObject
(
clsNode
.
getFullName
(),
clsNode
.
getCode
().
getCodeStr
()));
}
return
compile
(
jfObjects
);
compile
(
jfObjects
);
}
private
boolean
compile
(
List
<
JavaFileObject
>
jfObjects
)
{
private
void
compile
(
List
<
JavaFileObject
>
jfObjects
)
{
List
<
String
>
arguments
=
new
ArrayList
<>();
arguments
.
add
(
options
.
isIncludeDebugInfo
()
?
"-g"
:
"-g:none"
);
int
javaVersion
=
options
.
getJavaVersion
();
...
...
@@ -83,8 +81,13 @@ public class TestCompiler implements Closeable {
arguments
.
add
(
javaVerStr
);
arguments
.
addAll
(
options
.
getArguments
());
CompilationTask
compilerTask
=
compiler
.
getTask
(
null
,
fileManager
,
null
,
arguments
,
null
,
jfObjects
);
return
Boolean
.
TRUE
.
equals
(
compilerTask
.
call
());
DiagnosticListener
<?
super
JavaFileObject
>
diagnostic
=
diagObj
->
System
.
out
.
println
(
"Compiler diagnostic: "
+
diagObj
.
getMessage
(
Locale
.
ROOT
));
Writer
out
=
new
PrintWriter
(
System
.
out
);
CompilationTask
compilerTask
=
compiler
.
getTask
(
out
,
fileManager
,
diagnostic
,
arguments
,
null
,
jfObjects
);
if
(
Boolean
.
FALSE
.
equals
(
compilerTask
.
call
()))
{
throw
new
RuntimeException
(
"Compilation failed"
);
}
}
private
ClassLoader
getClassLoader
()
{
...
...
jadx-core/src/test/java/jadx/tests/api/extensions/profiles/JadxTestProfilesExtension.java
浏览文件 @
6016b902
...
...
@@ -2,6 +2,7 @@ package jadx.tests.api.extensions.profiles;
import
java.lang.reflect.Method
;
import
java.util.Collections
;
import
java.util.EnumSet
;
import
java.util.List
;
import
java.util.stream.Stream
;
...
...
@@ -35,7 +36,13 @@ public class JadxTestProfilesExtension implements TestTemplateInvocationContextP
Preconditions
.
condition
(!
testAnnAdded
,
"@Test annotation should be removed"
);
TestWithProfiles
profilesAnn
=
AnnotationUtils
.
findAnnotation
(
testMethod
,
TestWithProfiles
.
class
).
get
();
return
Stream
.
of
(
profilesAnn
.
value
())
EnumSet
<
TestProfile
>
profilesSet
=
EnumSet
.
noneOf
(
TestProfile
.
class
);
Collections
.
addAll
(
profilesSet
,
profilesAnn
.
value
());
if
(
profilesSet
.
contains
(
TestProfile
.
ALL
))
{
Collections
.
addAll
(
profilesSet
,
TestProfile
.
values
());
}
profilesSet
.
remove
(
TestProfile
.
ALL
);
return
profilesSet
.
stream
()
.
sorted
()
.
map
(
RunWithProfile:
:
new
);
}
...
...
jadx-core/src/test/java/jadx/tests/api/extensions/profiles/TestProfile.java
浏览文件 @
6016b902
...
...
@@ -20,7 +20,18 @@ public enum TestProfile implements Consumer<IntegrationTest> {
JAVA11
(
"java-11"
,
test
->
{
test
.
useTargetJavaVersion
(
11
);
test
.
useJavaInput
();
});
}),
ECJ_DX_J8
(
"ecj-dx-j8"
,
test
->
{
test
.
useEclipseCompiler
();
test
.
useTargetJavaVersion
(
8
);
test
.
useDexInput
();
}),
ECJ_J8
(
"ecj-j8"
,
test
->
{
test
.
useEclipseCompiler
();
test
.
useTargetJavaVersion
(
8
);
test
.
useJavaInput
();
}),
ALL
(
"all"
,
null
);
private
final
String
description
;
private
final
Consumer
<
IntegrationTest
>
setup
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录