Skip to content

Commit ef83db9

Browse files
git init
0 parents  commit ef83db9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+3795
-0
lines changed

.gitattributes

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#
2+
# https://help.github.com/articles/dealing-with-line-endings/
3+
#
4+
# These are explicitly windows files and should use crlf
5+
*.bat text eol=crlf
6+

.gitignore

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Ignore Gradle project-specific cache directory
2+
.gradle
3+
bin
4+
5+
# Ignore Gradle build output directory
6+
build

.vscode/launch.json

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"type": "java",
9+
"name": "attach",
10+
"request": "attach",
11+
"hostName": "localhost",
12+
"port": 10001
13+
},
14+
]
15+
}

.vscode/settings.json

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"java.configuration.updateBuildConfiguration": "automatic"
3+
}

app/build.gradle.kts

+100
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
/*
2+
* This file was generated by the Gradle 'init' task.
3+
*
4+
* This generated file contains a sample Java application project to get you started.
5+
* For more details take a look at the 'Building Java & JVM projects' chapter in the Gradle
6+
* User Manual available at https://docs.gradle.org/7.3/userguide/building_java_projects.html
7+
*/
8+
9+
tasks.register("hello") {
10+
doLast {
11+
println("hello 1")
12+
}
13+
}
14+
15+
tasks.register("hello2") {
16+
dependsOn("hello")
17+
doLast {
18+
println("hello 2")
19+
}
20+
}
21+
22+
plugins {
23+
// Apply the application plugin to add support for building a CLI application in Java.
24+
application
25+
}
26+
27+
repositories {
28+
// Use Maven Central for resolving dependencies.
29+
mavenCentral()
30+
}
31+
32+
dependencies {
33+
// Use JUnit Jupiter for testing.
34+
testImplementation("org.junit.jupiter:junit-jupiter:5.7.2")
35+
36+
// This dependency is used by the application.
37+
implementation("com.google.guava:guava:30.1.1-jre")
38+
implementation("org.ow2.asm:asm:9.3")
39+
implementation("org.ow2.asm:asm-util:9.3")
40+
implementation(project(":luceedebug"))
41+
}
42+
43+
application {
44+
// Define the main class for the application.
45+
mainClass.set("asm.use.App")
46+
}
47+
48+
tasks.named<Test>("test") {
49+
// Use JUnit Platform for unit tests.
50+
useJUnitPlatform()
51+
}
52+
53+
// sourceSets {
54+
// main {
55+
// java.srcDir("src/main/java")
56+
// }
57+
// }
58+
59+
60+
tasks.register("buildTestSource1") {
61+
dependsOn("classes")
62+
doLast {
63+
javaexec {
64+
mainClass.set("asm.use.App")
65+
// classpath = sourceSets["main"].runtimeClasspath
66+
classpath(sourceSets["main"].runtimeClasspath)
67+
}
68+
}
69+
}
70+
71+
tasks.register("runTestDriver1") {
72+
dependsOn("classes")
73+
doLast {
74+
javaexec {
75+
mainClass.set("asm.use.TestDriver1")
76+
// classpath = sourceSets["main"].runtimeClasspath
77+
classpath(sourceSets["main"].runtimeClasspath)
78+
}
79+
}
80+
}
81+
82+
tasks.register("buildAgentJar") {
83+
84+
}
85+
86+
tasks.register("runInstrumenter") {
87+
dependsOn("classes")
88+
doLast {
89+
javaexec {
90+
jvmArgs = mutableListOf(
91+
"-javaagent:" + File(rootProject.projectDir.getAbsolutePath() + "/luceedebug/build/libs/luceedebug.jar").getAbsolutePath()
92+
)
93+
//classpath += FileCollection("lel/")
94+
mainClass.set("asm.use.InstrumenterDriver")
95+
// classpath = sourceSets["main"].runtimeClasspath
96+
classpath(sourceSets["main"].runtimeClasspath)
97+
// classpath += files(File(rootProject.projectDir.getAbsolutePath() + "/luceedebug/build/libs").getAbsolutePath())
98+
}
99+
}
100+
}

app/src/main/java/asm/use/App.java

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/*
2+
* This Java source file was generated by the Gradle 'init' task.
3+
*/
4+
package asm.use;
5+
6+
import java.io.File;
7+
import java.io.FileInputStream;
8+
import java.io.FileOutputStream;
9+
import java.io.PrintWriter;
10+
import java.nio.file.Paths;
11+
import org.objectweb.asm.ClassReader;
12+
import org.objectweb.asm.ClassVisitor;
13+
import org.objectweb.asm.ClassWriter;
14+
import org.objectweb.asm.Opcodes;
15+
import org.objectweb.asm.util.TraceClassVisitor;
16+
17+
public class App {
18+
static String relPathToSource = "build/classes/java/main/asm/use/WillHaveSourceFileNameTransformed.class";
19+
static String relPathToTarget = "build/classes/java/main/asm/use/MockCfFile.class";
20+
21+
public String getGreeting() {
22+
System.out.println(ClassReader.class);
23+
return "Hello World! (oye) lel";
24+
}
25+
26+
static byte[] readSource() throws Throwable {
27+
String absPathToSource = Paths.get(relPathToSource).toAbsolutePath().toString();
28+
File source = new File(absPathToSource);
29+
byte[] result = new byte[(int)source.length()];
30+
FileInputStream fis = new FileInputStream(source);
31+
int bs = fis.read(result);
32+
System.out.println("Read " + bs + " bytes");
33+
fis.close();
34+
return result;
35+
}
36+
37+
static void writeTarget(byte[] bytes) throws Throwable {
38+
String absPathToTarget = Paths.get(relPathToTarget).toAbsolutePath().toString();
39+
File target = new File(absPathToTarget);
40+
System.out.println(target);
41+
42+
if (target.exists()) {
43+
target.delete();
44+
target.createNewFile();
45+
}
46+
47+
FileOutputStream fos = new FileOutputStream(target);
48+
fos.write(bytes);
49+
fos.close();
50+
}
51+
52+
public static void main(String[] args) throws Throwable {
53+
byte[] source = readSource();
54+
55+
ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS);
56+
57+
ClassVisitor visitor = new ClassVisitor(Opcodes.ASM9, cw) {
58+
@Override
59+
public void visitSource(String source, String debug) {
60+
super.visitSource("/some/abs/project/path/Foo.cfc", null);
61+
}
62+
};
63+
64+
ClassReader reader = new ClassReader(source);
65+
66+
reader.accept(visitor, 0);
67+
68+
byte[] transformed = cw.toByteArray();
69+
70+
writeTarget(transformed);
71+
72+
System.out.println("OK?");
73+
}
74+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package asm.use;
2+
import luceedebug.*;
3+
4+
public class InstrumenterDriver {
5+
public static void main(String[] args) throws Throwable {
6+
System.out.println("Instrumenter main");
7+
ThisShouldGetInstrumented.doTheThing(Thread.currentThread());
8+
System.out.println("Instrumented int: " + ThisIsCalledByInstrumentedCode.thread_to_pageContext_map.get(Thread.currentThread()));
9+
}
10+
}
+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* This Java source file was generated by the Gradle 'init' task.
3+
*/
4+
package asm.use;
5+
6+
public class TestDriver1 {
7+
public static void main(String[] args) {
8+
WillHaveSourceFileNameTransformed v = new WillHaveSourceFileNameTransformed();
9+
System.out.println(v.bar());
10+
}
11+
12+
public int foo() {
13+
int i = 0;
14+
int j = 1;
15+
int k = 2;
16+
System.out.println(i);
17+
System.out.println(j);
18+
System.out.println(k);
19+
return i + j + k;
20+
}
21+
22+
public String bar() {
23+
return "bar -> foo -> " + foo();
24+
}
25+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package asm.use;
2+
3+
public class ThisShouldGetInstrumented {
4+
public static void doTheThing(Object o) {
5+
System.out.println("doTheThing(Object o) called");
6+
doTheOtherThing(o);
7+
}
8+
9+
public static void doTheOtherThing(Object o) {
10+
System.out.println("doTheOtherThing(Object o) called");
11+
}
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* This Java source file was generated by the Gradle 'init' task.
3+
*/
4+
package asm.use;
5+
6+
public class WillHaveSourceFileNameTransformed {
7+
public static void main(String[] args) {
8+
System.out.println("This is a stub java file, which should have had it's class file's source file set to .cfc after build.");
9+
}
10+
11+
public int foo() {
12+
int i = 0;
13+
int j = 1;
14+
int k = 2;
15+
System.out.println(i);
16+
System.out.println(j);
17+
System.out.println(k);
18+
return i + j + k;
19+
}
20+
21+
public String bar() {
22+
return "bar -> foo -> " + foo();
23+
}
24+
}
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/*
2+
* This Java source file was generated by the Gradle 'init' task.
3+
*/
4+
package asm.use;
5+
6+
import org.junit.jupiter.api.Test;
7+
import static org.junit.jupiter.api.Assertions.*;
8+
9+
class AppTest {
10+
@Test void appHasAGreeting() {
11+
App classUnderTest = new App();
12+
assertNotNull(classUnderTest.getGreeting(), "app should have a greeting");
13+
}
14+
}

gradle/wrapper/gradle-wrapper.jar

58.1 KB
Binary file not shown.
+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
distributionBase=GRADLE_USER_HOME
2+
distributionPath=wrapper/dists
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3-bin.zip
4+
zipStoreBase=GRADLE_USER_HOME
5+
zipStorePath=wrapper/dists

0 commit comments

Comments
 (0)