Skip to content

Commit 703d840

Browse files
committed
Fixed incorrect logic on exemption, and some small problems
1 parent 14fa55d commit 703d840

4 files changed

Lines changed: 50 additions & 21 deletions

File tree

dev.skidfuscator.gradle-plugin/build.gradle

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ plugins {
33
id 'com.gradle.plugin-publish' version '0.14.0'
44
}
55

6+
group = 'dev.skidfuscator'
67
version = '0.1'
78

89
gradlePlugin {
@@ -27,6 +28,11 @@ pluginBundle {
2728
}
2829
}
2930

31+
repositories {
32+
mavenCentral()
33+
maven { url 'https://jitpack.io' }
34+
}
35+
3036
dependencies {
3137
compileOnly gradleApi()
3238
compileOnly 'org.codehaus.groovy:groovy-all:3.0.9'

dev.skidfuscator.gradle-plugin/src/main/java/dev/skidfuscator/gradle/SkidfuscatorCompileAction.java

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,27 @@
22

33
import dev.skidfuscator.obfuscator.Skidfuscator;
44
import dev.skidfuscator.obfuscator.SkidfuscatorSession;
5-
import lombok.RequiredArgsConstructor;
65
import org.gradle.api.Action;
76
import org.gradle.api.Task;
8-
import org.gradle.api.tasks.compile.AbstractCompile;
97

10-
@RequiredArgsConstructor
8+
import javax.inject.Inject;
9+
import java.util.List;
10+
1111
public class SkidfuscatorCompileAction implements Action<Task> {
1212

1313
private final SkidfuscatorSession session;
14-
private final String exemptionString;
14+
private final List<String> excludes;
1515

16-
@Override
17-
public void execute(Task task) {
18-
this.handleCompileTask((AbstractCompile) task);
16+
@Inject
17+
public SkidfuscatorCompileAction(SkidfuscatorSession session, List<String> exemptionString) {
18+
this.session = session;
19+
this.excludes = exemptionString;
1920
}
2021

21-
public void handleCompileTask(AbstractCompile compile) {
22+
@Override
23+
public void execute(Task task) {
2224
Skidfuscator skidfuscator = new Skidfuscator(this.session);
23-
if (this.exemptionString != null)
24-
skidfuscator.getExemptAnalysis().add(this.exemptionString);
25+
this.excludes.forEach(exclude -> skidfuscator.getExemptAnalysis().add(exclude));
2526
skidfuscator.run();
2627
}
2728
}
Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
package dev.skidfuscator.gradle;
22

33
import lombok.Getter;
4-
import org.gradle.api.file.RegularFile;
4+
import org.gradle.api.file.RegularFileProperty;
55
import org.gradle.api.model.ObjectFactory;
6+
import org.gradle.api.provider.ListProperty;
67
import org.gradle.api.provider.Property;
78

89
import javax.inject.Inject;
@@ -14,19 +15,35 @@ public class SkidfuscatorExtension {
1415
private final Property<Boolean> notrack;
1516
private final Property<Boolean> fuckit;
1617
private final Property<String> classifier;
17-
private final Property<String> exemptionString;
18-
private final Property<RegularFile> runtime;
19-
private final Property<RegularFile> exemption;
18+
private final ListProperty<String> excludes;
19+
private final RegularFileProperty runtime;
20+
private final RegularFileProperty exemptionFile;
2021

2122
@Inject
2223
public SkidfuscatorExtension(ObjectFactory objectFactory) {
2324
this.phantom = objectFactory.property(Boolean.class).convention(false);
2425
this.notrack = objectFactory.property(Boolean.class).convention(false);
2526
this.fuckit = objectFactory.property(Boolean.class).convention(false);
26-
this.runtime = objectFactory.property(RegularFile.class);
27+
this.runtime = objectFactory.fileProperty();
2728
this.classifier = objectFactory.property(String.class).convention("-obfuscated");
28-
this.exemptionString = objectFactory.property(String.class);
29-
this.exemption = objectFactory.property(RegularFile.class);
29+
this.excludes = objectFactory.listProperty(String.class).empty();
30+
this.exemptionFile = objectFactory.fileProperty();
31+
}
32+
33+
public void exclude(String... exludes) {
34+
this.excludes.addAll(exludes);
35+
}
36+
37+
public void phantom() {
38+
this.phantom.set(true);
39+
}
40+
41+
public void notrack() {
42+
this.notrack.set(true);
43+
}
44+
45+
public void fuckit() {
46+
this.fuckit.set(true);
3047
}
3148

3249
}

dev.skidfuscator.gradle-plugin/src/main/java/dev/skidfuscator/gradle/SkidfuscatorGradlePlugin.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
import java.io.File;
1717
import java.util.ArrayList;
18+
import java.util.Collections;
1819
import java.util.List;
1920

2021
public class SkidfuscatorGradlePlugin implements Plugin<Project> {
@@ -39,7 +40,7 @@ private void handle(Project project, SkidfuscatorExtension extension) {
3940
project.getPlugins().withType(GroovyPlugin.class, plugin -> this.handlePlugin(project, "groovy"));
4041
project.getPlugins().withType(ScalaPlugin.class, plugin -> this.handlePlugin(project, "scala"));
4142
project.getPlugins().withId("org.jetbrains.kotlin.jvm", plugin -> this.handlePlugin(project, "kotlin"));
42-
// compute session and obfuscator right after jar task
43+
// compute session and obfuscate right after jar task
4344
project.getTasks().withType(Jar.class, jar -> {
4445
final String home = System.getProperty("java.home");
4546
final File runtime;
@@ -56,8 +57,8 @@ private void handle(Project project, SkidfuscatorExtension extension) {
5657
);
5758
}
5859

59-
if (extension.getExemption().isPresent()) {
60-
exemption = extension.getExemption().get().getAsFile();;
60+
if (extension.getExemptionFile().isPresent()) {
61+
exemption = extension.getExemptionFile().get().getAsFile();
6162
} else {
6263
exemption = null;
6364
}
@@ -78,7 +79,11 @@ private void handle(Project project, SkidfuscatorExtension extension) {
7879
.libs(this.classpath.toArray(new File[0]))
7980
.build();
8081

81-
SkidfuscatorCompileAction action = project.getObjects().newInstance(SkidfuscatorCompileAction.class, session, extension.getExemptionString().getOrNull());
82+
SkidfuscatorCompileAction action = project.getObjects().newInstance(
83+
SkidfuscatorCompileAction.class,
84+
session,
85+
extension.getExcludes().getOrElse(Collections.emptyList())
86+
);
8287
jar.doLast("skidfuscator", action);
8388
});
8489
}

0 commit comments

Comments
 (0)