Skip to content

Commit

Permalink
Introduce ide-provisioning-api and load implementation via custom cla…
Browse files Browse the repository at this point in the history
…ssloader
  • Loading branch information
asodja committed Mar 22, 2024
1 parent 1d2a84d commit 6677ebb
Show file tree
Hide file tree
Showing 10 changed files with 83 additions and 7 deletions.
19 changes: 19 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ description = "A tool to profile and benchmark Gradle builds"

val gradleRuntime by configurations.creating
val profilerPlugins by configurations.creating
val ideImplementation by configurations.creating

dependencies {
implementation(libs.toolingApi)
Expand All @@ -42,6 +43,7 @@ dependencies {
because("To write JSON output")
}
implementation(project(":client-protocol"))
implementation(project(":ide-provisioning-api"))


gradleRuntime(gradleApi())
Expand All @@ -52,6 +54,7 @@ dependencies {
profilerPlugins(project(":studio-agent"))
profilerPlugins(project(":heap-dump"))
profilerPlugins(project(":studio-plugin"))
ideImplementation(project(":ide-provisioning"))

runtimeOnly("org.slf4j:slf4j-simple:1.7.10")
testImplementation(libs.bundles.testDependencies)
Expand Down Expand Up @@ -87,13 +90,29 @@ val generateHtmlReportJavaScript = tasks.register<NpxTask>("generateHtmlReportJa
args.addAll(source.absolutePath, "--outfile", output.get().asFile.absolutePath)
}

val listIdeProvisioningDependencies = tasks.register("listIdeProvisioningDependencies") {
val input = ideImplementation.minus(gradleRuntime)
val output = project.layout.buildDirectory.file("ide-provisioning/ide-provisioning.txt")
inputs.files(input)
outputs.file(output)
doLast {
output.get().asFile.writeText(input.joinToString("\n") { it.name })
}
}

tasks.processResources {
into("META-INF/jars") {
from(profilerPlugins.minus(gradleRuntime)) {
// Removing the version from the JARs here, since they are referenced by name in production code.
rename("""(.*)-\d\.\d.*\.jar""", "${'$'}1.jar")
}
}
into("META-INF/jars") {
from(ideImplementation.minus(gradleRuntime))
}
into("META-INF/classpath") {
from(listIdeProvisioningDependencies)
}
from(generateHtmlReportJavaScript)
}

Expand Down
7 changes: 7 additions & 0 deletions buildSrc/src/main/kotlin/profiler.java-library.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ repositories {
}
}
mavenCentral()
maven {
url = uri("https://www.jetbrains.com/intellij-repository/releases")
}
maven {
url = uri("https://cache-redirector.jetbrains.com/intellij-dependencies")
}

}

java {
Expand Down
1 change: 1 addition & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ include("client-protocol")
include("instrumentation-support")
include("studio-agent")
include("studio-plugin")
include("ide-provisioning-api")
include("ide-provisioning")

rootProject.children.forEach {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,18 @@
import org.gradle.profiler.GeneratedInitScript;
import org.gradle.profiler.GradleArgsCalculator;

import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.UncheckedIOException;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;
import java.util.List;
import java.util.stream.Collectors;

/**
* Represents some instrumentation that uses Gradle APIs and that is injected by gradle-profiler.
Expand Down Expand Up @@ -56,4 +61,20 @@ public static File unpackPlugin(String jarName) {
throw UncheckedException.throwAsUncheckedException(e);
}
}

public static URL[] getClasspath(String classPathName) {
List<String> classpathJars = readLines("/META-INF/classpath/" + classPathName + ".txt");
return classpathJars.stream()
.map(jar -> GradleInstrumentation.class.getResource("/META-INF/jars/" + jar))
.toArray(URL[]::new);
}

private static List<String> readLines(String resourcePath) {
try (BufferedReader reader = new BufferedReader(new InputStreamReader(GradleInstrumentation.class.getResourceAsStream(resourcePath)))) {
return reader.lines()
.collect(Collectors.toList());
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,16 @@

import org.gradle.profiler.BuildAction;
import org.gradle.profiler.GradleClient;
import org.gradle.profiler.ide.RunIde;
import org.gradle.profiler.instrument.GradleInstrumentation;
import org.gradle.profiler.result.BuildActionResult;
import org.gradle.profiler.studio.StudioGradleClient;

import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.Arrays;
import java.util.List;
import java.util.ServiceLoader;

/**
* A mock-up of Android studio sync.
Expand Down
13 changes: 13 additions & 0 deletions subprojects/ide-provisioning-api/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
plugins {
id("profiler.embedded-library")
id("profiler.publication")
}

description = "Api for IDE provisioning capabilities for Gradle profiler"


java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(8))
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package org.gradle.profiler.ide;

public interface RunIde {
void run();
}
7 changes: 1 addition & 6 deletions subprojects/ide-provisioning/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,23 +1,18 @@
plugins {
id("profiler.embedded-library")
id("profiler.publication")
kotlin("jvm") version "1.9.22"
}

description = "IDE provisioning capabilities for Gradle profiler"

repositories {
maven { url = uri("https://www.jetbrains.com/intellij-repository/releases") }
maven { url = uri("https://cache-redirector.jetbrains.com/intellij-dependencies") }
}

java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(17))
}
}

dependencies {
implementation(project(":ide-provisioning-api"))
implementation(libs.ideStarter) {
exclude(group = "io.ktor")
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package org.gradle.profiler.ide;

public class RunIdeImpl implements RunIde {
@Override
public void run() {
System.out.println("Running IDE");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
org.gradle.profiler.ide.RunIdeImpl

0 comments on commit 6677ebb

Please sign in to comment.