-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move maven plugin to the Fray repo and update README (#112)
* 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
Showing
12 changed files
with
422 additions
and
527 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} |
15 changes: 15 additions & 0 deletions
15
plugins/base/src/main/kotlin/org/pastalab/fray/plugins/base/FrayVersion.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
} | ||
} |
167 changes: 167 additions & 0 deletions
167
plugins/base/src/main/kotlin/org/pastalab/fray/plugins/base/FrayWorkspaceInitializer.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { | ||
"" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
Oops, something went wrong.