Skip to content

Commit

Permalink
Move maven plugin to the Fray repo and update README (#112)
Browse files Browse the repository at this point in the history
* Simplify README file and move maven-plugin to the fray repo.

* add test method in the Other Testing Framework section.

* Save gradle version in property file.

* Fix circular dependency issue.
  • Loading branch information
aoli-al authored Feb 9, 2025
1 parent 08e4fc8 commit 57830cb
Show file tree
Hide file tree
Showing 12 changed files with 422 additions and 527 deletions.
380 changes: 37 additions & 343 deletions README.md

Large diffs are not rendered by default.

24 changes: 9 additions & 15 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ plugins {
kotlin("jvm") version "2.0.0"
id("maven-publish")
id("com.ncorti.ktfmt.gradle") version "0.17.0"
id("org.jetbrains.dokka") version "1.9.20"
id("org.jreleaser") version "1.16.0"
id("com.gradleup.shadow") version "9.0.0-beta7"
}
Expand Down Expand Up @@ -60,17 +59,16 @@ jreleaser {
}
}


configure(allprojects - rootProject -
project(":instrumentation") - project(":plugins").subprojects - project(":plugins")
- project(":integration-test")) {
project(":instrumentation") -
project(":plugins") -
project(":plugins:gradle") -
project(":plugins:idea") -
project(":integration-test")) {
plugins.apply("maven-publish")
plugins.apply("org.jetbrains.dokka")
afterEvaluate {
tasks.register<Jar>("dokkaJavadocJar") {
dependsOn(tasks.dokkaJavadoc)
from(tasks.dokkaJavadoc.flatMap { it.outputDirectory })
archiveClassifier.set("javadoc")
}

java {
withSourcesJar()
}
Expand Down Expand Up @@ -102,13 +100,9 @@ configure(allprojects - rootProject -
url = "https://github.com/cmu-pasta/fray"
}
}
afterEvaluate {
val shadowJar = tasks.findByName("shadowJar")
if (shadowJar == null) from(components["java"])
else artifact(shadowJar)
}
if (components.findByName("shadow") == null) from(components["java"])
else from(components["shadow"])
if (project.name != "jvmti") {
artifact(tasks["dokkaJavadocJar"])
artifactId = project.base.archivesName.get()
} else {
artifactId = project.base.archivesName.get() + "-$os-$arch"
Expand Down
5 changes: 4 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
kotlin.code.style=official
group=org.pastalab.fray
version=0.2.1
version=0.2.2-SNAPSHOT
org.gradle.jvmargs=-Xmx2g -XX:MaxMetaspaceSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
org.jetbrains.dokka.experimental.gradle.pluginMode=V2Enabled
org.jetbrains.dokka.experimental.gradle.pluginMode.noWarn=true

42 changes: 42 additions & 0 deletions plugins/base/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar

plugins {
kotlin("jvm")
id("com.gradleup.shadow")
}

repositories {
mavenCentral()
}

dependencies {
implementation("org.apache.commons:commons-compress:1.27.1")
testImplementation(platform("org.junit:junit-bom:5.10.0"))
testImplementation("org.junit.jupiter:junit-jupiter")
}

tasks.named<ShadowJar>("shadowJar") {
archiveClassifier.set("")
relocate("org.apache.commons", "org.pastalab.fray.apache.commons")
}

val createVersionProperties by tasks.registering(WriteProperties::class) {
val filePath = sourceSets.main.map {
it.output.resourcesDir!!.resolve("org/pastalab/fray/plugins/base/version.properties")
}
destinationFile = filePath
property("version", project.version.toString())
}

tasks.classes {
dependsOn(createVersionProperties)
}

tasks.jar {
enabled = false
}


tasks.test {
useJUnitPlatform()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package org.pastalab.fray.plugins.base

import java.io.InputStreamReader
import java.nio.charset.StandardCharsets
import java.util.Properties

object FrayVersion {
val version by lazy {
val properties = Properties()
javaClass.getResourceAsStream("/org/pastalab/fray/plugins/base/version.properties")?.let {
properties.load(InputStreamReader(it, StandardCharsets.UTF_8))
}
properties.getProperty("version")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
package org.pastalab.fray.plugins.base

import java.io.BufferedInputStream
import java.io.File
import java.io.FileInputStream
import java.io.FileOutputStream
import java.net.HttpURLConnection
import java.net.URI
import java.util.*
import java.util.zip.ZipInputStream
import org.apache.commons.compress.archivers.tar.TarArchiveInputStream
import org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream

class FrayWorkspaceInitializer(
val jdkPath: File,
val jlinkJar: File,
val jlinkDependencies: Set<File>,
val jvmtiPath: File,
val jvmtiJar: File,
val workDir: String
) {
val jdkVersionPath = File(jdkPath, "fray-version")

fun createInstrumentedJDK(frayVersion: String) {
if (readJDKFrayVersion() != frayVersion) {
jdkPath.deleteRecursively()
val jdk = downloadJDK()
val classPaths = jlinkDependencies.joinToString(":")
val command =
arrayOf(
"$jdk/bin/jlink",
"-J-javaagent:$jlinkJar",
"-J--module-path=$classPaths",
"-J--add-modules=org.pastalab.fray.instrumentation.jdk",
"-J--class-path=$classPaths",
"--output=${jdkPath.absolutePath}",
"--add-modules=ALL-MODULE-PATH",
"--fray-instrumentation",
)
val logFile = File("/tmp/tmp.log")
val process =
ProcessBuilder(*command).redirectOutput(logFile).redirectErrorStream(true).start()
process.waitFor()
jdkVersionPath.createNewFile()
jdkVersionPath.writeText(frayVersion)
}
}

fun createJVMTiRuntime() {
if (!jvmtiPath.exists()) {
jvmtiPath.mkdirs()
unzipFile(jvmtiJar.absolutePath, jvmtiPath.absolutePath)
}
}

private fun downloadJDK(): String {
val osName = System.getProperty("os.name").lowercase()
val downloadUrl = getDownloadUrl(osName)
val fileName = "$workDir/${downloadUrl.substringAfterLast("/")}"
val jdkFolder = File("$workDir/${getJDKFolderName(osName)}")
if (jdkFolder.exists()) {
jdkFolder.deleteRecursively()
}
jdkFolder.mkdirs()
try {
downloadFile(downloadUrl, fileName)
decompressFile(fileName, workDir)
} catch (e: Exception) {
throw RuntimeException("Download failed: ${e.message}", e)
}
return jdkFolder.absolutePath
}

fun downloadFile(fileURL: String, fileName: String) {
println("Downloading $fileURL to $fileName, subsequent downloads will be skipped.")
val url = URI.create(fileURL).toURL()
val connection = url.openConnection() as HttpURLConnection
connection.requestMethod = "GET"

BufferedInputStream(connection.inputStream).use { input ->
FileOutputStream(fileName).use { output ->
val buffer = ByteArray(64 * 1024)
var bytesRead: Int
while (input.read(buffer).also { bytesRead = it } != -1) {
output.write(buffer, 0, bytesRead)
}
}
}
}

fun decompressFile(fileName: String, outputDir: String) {
File(outputDir).mkdir()
when {
fileName.endsWith(".zip") -> unzipFile(fileName, outputDir)
fileName.endsWith(".tar.gz") -> untarGzipFile(fileName, outputDir)
else -> println("Unknown file format, skipping extraction.")
}
}

fun unzipFile(zipFilePath: String, outputDir: String) {
ZipInputStream(FileInputStream(zipFilePath)).use { zip ->
var entry = zip.nextEntry
while (entry != null) {
val filePath = "$outputDir/${entry.name}"
if (!entry.isDirectory) {
FileOutputStream(filePath).use { output -> zip.copyTo(output) }
} else {
File(filePath).mkdirs()
}
zip.closeEntry()
entry = zip.nextEntry
}
}
}

fun untarGzipFile(tarGzFilePath: String, outputDir: String) {
FileInputStream(tarGzFilePath).use { fis ->
GzipCompressorInputStream(fis).use { gzipIn ->
TarArchiveInputStream(gzipIn).use { tarIn ->
var entry = tarIn.nextEntry
while (entry != null) {
val outputFile = File(outputDir, entry.name)
if (entry.isDirectory) {
outputFile.mkdirs()
} else {
outputFile.parentFile.mkdirs()
FileOutputStream(outputFile).use { output -> tarIn.copyTo(output) }
outputFile.setExecutable((entry.mode and 0b001_000_000) != 0, false)
outputFile.setReadable((entry.mode and 0b100_000_000) != 0, false)
outputFile.setWritable((entry.mode and 0b010_000_000) != 0, false)
}
entry = tarIn.nextEntry
}
}
}
}
}

fun getDownloadUrl(osName: String): String {
return when {
osName.contains("win") ->
"https://corretto.aws/downloads/resources/21.0.6.7.1/amazon-corretto-21.0.6.7.1-windows-x64-jdk.zip"
osName.contains("linux") ->
"https://corretto.aws/downloads/resources/21.0.6.7.1/amazon-corretto-21.0.6.7.1-linux-x64.tar.gz"
osName.contains("mac") ->
"https://corretto.aws/downloads/resources/21.0.6.7.1/amazon-corretto-21.0.6.7.1-macosx-aarch64.tar.gz"
else -> throw RuntimeException("Unsupported OS: $osName")
}
}

fun getJDKFolderName(osName: String): String {
return when {
osName.contains("win") -> "jdk21.0.6_7"
osName.contains("linux") -> "amazon-corretto-21.0.6.7.1-linux-x64"
osName.contains("mac") -> "amazon-corretto-21.jdk/Contents/Home"
else -> throw RuntimeException("Unsupported OS: $osName")
}
}

private fun readJDKFrayVersion(): String {
return if (jdkVersionPath.exists()) {
jdkVersionPath.readText()
} else {
""
}
}
}
9 changes: 1 addition & 8 deletions plugins/gradle/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@ plugins {
id("com.gradle.plugin-publish") version "1.2.1"
kotlin("jvm")
id("java")
id("com.gradleup.shadow")
}

dependencies {
implementation("org.apache.commons:commons-compress:1.27.1")
implementation(project(":plugins:base", configuration = "shadow"))
}

repositories {
Expand All @@ -19,12 +18,6 @@ tasks.test {
useJUnitPlatform()
}

tasks.named<ShadowJar>("shadowJar") {
archiveClassifier.set("")
relocate("org.apache.commons", "org.pastalab.fray.apache.commons")
}


gradlePlugin {
website = "https://github.com/cmu-pasta/fray"
vcsUrl = "https://github.com/cmu-pasta/fray"
Expand Down
4 changes: 3 additions & 1 deletion plugins/gradle/src/main/kotlin/FrayExtension.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.pastalab.fray.gradle

import org.pastalab.fray.plugins.base.FrayVersion

open class FrayExtension {
var version = "0.2.1"
var version = FrayVersion.version
}
Loading

0 comments on commit 57830cb

Please sign in to comment.