Skip to content

Commit

Permalink
Apply Spotless for buildSrc and build script
Browse files Browse the repository at this point in the history
Signed-off-by: utzcoz <[email protected]>
  • Loading branch information
utzcoz committed Nov 10, 2023
1 parent 739194f commit 64c2d96
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 35 deletions.
15 changes: 15 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,21 @@ allprojects {
}

apply plugin: 'idea'
apply plugin: "com.diffplug.spotless"

// Apply Spotless for buildSrc and build scripts
spotless {
java {
target("buildSrc/**/*.java")
googleJavaFormat("1.17.0")
}
groovy {
target("buildSrc/**/*.groovy")
}
groovyGradle {
target('*.gradle', "**/*.gradle")
}
}

project.ext.configAnnotationProcessing = []
project.afterEvaluate {
Expand Down
5 changes: 5 additions & 0 deletions buildSrc/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,8 @@ dependencies {
implementation libs.asm.tree
implementation libs.android.gradle
}

java {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}
70 changes: 35 additions & 35 deletions buildSrc/src/main/groovy/org/robolectric/gradle/AarDepsPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@
import org.gradle.api.tasks.compile.JavaCompile;
import org.jetbrains.annotations.NotNull;

/**
* Resolve aar dependencies into jars for non-Android projects.
*/
/** Resolve aar dependencies into jars for non-Android projects. */
public class AarDepsPlugin implements Plugin<Project> {
@Override
public void apply(Project project) {
Expand Down Expand Up @@ -57,16 +55,18 @@ public void apply(Project project) {
.all(
// the following Action<Task needs to remain an anonymous subclass or gradle's
// incremental compile breaks (run `gradlew -i classes` twice to see impact):
t -> t.doFirst(new Action<Task>() {
@Override
public void execute(Task task) {
List<File> aarFiles = AarDepsPlugin.this.findAarFiles(t.getClasspath());
if (!aarFiles.isEmpty()) {
throw new IllegalStateException(
"AARs on classpath: " + Joiner.on("\n ").join(aarFiles));
}
}
}));
t ->
t.doFirst(
new Action<Task>() {
@Override
public void execute(Task task) {
List<File> aarFiles = AarDepsPlugin.this.findAarFiles(t.getClasspath());
if (!aarFiles.isEmpty()) {
throw new IllegalStateException(
"AARs on classpath: " + Joiner.on("\n ").join(aarFiles));
}
}
}));
}

private List<File> findAarFiles(FileCollection files) {
Expand All @@ -79,36 +79,36 @@ private List<File> findAarFiles(FileCollection files) {
return bad;
}

public static abstract class ClassesJarExtractor extends ExtractAarTransform {
public abstract static class ClassesJarExtractor extends ExtractAarTransform {
@Inject
public ClassesJarExtractor() {
}
public ClassesJarExtractor() {}

@Override
public void transform(@NotNull TransformOutputs outputs) {
AtomicReference<File> classesJarFile = new AtomicReference<>();
AtomicReference<File> outJarFile = new AtomicReference<>();
super.transform(new TransformOutputs() {
// This is the one that ExtractAarTransform calls.
@Override
public File dir(Object o) {
// ExtractAarTransform needs a place to extract the AAR. We don't really need to
// register this as an output, but it'd be tricky to avoid it.
File dir = outputs.dir(o);
super.transform(
new TransformOutputs() {
// This is the one that ExtractAarTransform calls.
@Override
public File dir(Object o) {
// ExtractAarTransform needs a place to extract the AAR. We don't really need to
// register this as an output, but it'd be tricky to avoid it.
File dir = outputs.dir(o);

// Also, register our jar file. Its name needs to be quasi-unique or
// IntelliJ Gradle/Android plugins get confused.
classesJarFile.set(new File(new File(dir, "jars"), "classes.jar"));
outJarFile.set(new File(new File(dir, "jars"), o + ".jar"));
outputs.file(o + "/jars/" + o + ".jar");
return outputs.dir(o);
}
// Also, register our jar file. Its name needs to be quasi-unique or
// IntelliJ Gradle/Android plugins get confused.
classesJarFile.set(new File(new File(dir, "jars"), "classes.jar"));
outJarFile.set(new File(new File(dir, "jars"), o + ".jar"));
outputs.file(o + "/jars/" + o + ".jar");
return outputs.dir(o);
}

@Override
public File file(Object o) {
throw new IllegalStateException("shouldn't be called");
}
});
@Override
public File file(Object o) {
throw new IllegalStateException("shouldn't be called");
}
});

classesJarFile.get().renameTo(outJarFile.get());
}
Expand Down

0 comments on commit 64c2d96

Please sign in to comment.