Skip to content

Commit

Permalink
Install ByteBuddy agent once per JVM (#74)
Browse files Browse the repository at this point in the history
Move bytebuddy agent installation to a static block so
that the installation only happens once per JVM.

This ensures that the plugin works well with BUCK(and likewise) build
systems where multiple javac compilation task is started parallely in
the same JVM. Without this the JVM crashes undeterministically.

This will also work well in gradle build system where once javac task
runs per JVM
  • Loading branch information
raviagarwal7 authored Jun 18, 2021
1 parent 16f76a3 commit 42089a4
Showing 1 changed file with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,12 @@
import net.bytebuddy.pool.TypePool;
import net.bytebuddy.utility.JavaModule;

import java.lang.instrument.Instrumentation;
import java.util.*;

import static net.bytebuddy.matcher.ElementMatchers.*;

public class JabelCompilerPlugin implements Plugin {

@Override
public void init(JavacTask task, String... args) {
static {
Map<String, AsmVisitorWrapper> visitors = new HashMap<String, AsmVisitorWrapper>() {{
// Disable the preview feature check
AsmVisitorWrapper checkSourceLevelAdvice = Advice.to(CheckSourceLevelAdvice.class)
Expand Down Expand Up @@ -118,7 +115,10 @@ public void init(JavacTask task, String... args) {
Collections.emptySet(),
Collections.emptyMap()
);
}

@Override
public void init(JavacTask task, String... args) {
Context context = ((JavacTaskImpl) task).getContext();
JavacMessages.instance(context).add(locale -> new ResourceBundle() {
@Override
Expand Down

0 comments on commit 42089a4

Please sign in to comment.