aboutsummaryrefslogtreecommitdiff
path: root/src/eclipseAgent/lombok
diff options
context:
space:
mode:
Diffstat (limited to 'src/eclipseAgent/lombok')
-rw-r--r--src/eclipseAgent/lombok/eclipse/agent/MavenEcjBootstrapApp.java35
-rw-r--r--src/eclipseAgent/lombok/launch/AgentBootstrap.java92
2 files changed, 18 insertions, 109 deletions
diff --git a/src/eclipseAgent/lombok/eclipse/agent/MavenEcjBootstrapApp.java b/src/eclipseAgent/lombok/eclipse/agent/MavenEcjBootstrapApp.java
index d08422be..7f9d4d36 100644
--- a/src/eclipseAgent/lombok/eclipse/agent/MavenEcjBootstrapApp.java
+++ b/src/eclipseAgent/lombok/eclipse/agent/MavenEcjBootstrapApp.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2009-2022 The Project Lombok Authors.
+ * Copyright (C) 2022 The Project Lombok Authors.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -26,7 +26,6 @@ import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.InputStream;
import java.io.PrintStream;
-import java.util.Arrays;
import java.util.List;
import com.zwitserloot.cmdreader.CmdReader;
@@ -45,18 +44,14 @@ public class MavenEcjBootstrapApp extends LombokApp {
@Override public String getAppDescription() {
return "Creates .mvn/jvm.config and .mvn/lombok-bootstrap.jar for\n" +
- "use with the ECJ compiler.";
- }
-
- @Override public List<String> getAppAliases() {
- return Arrays.asList("ecj");
+ "use with the ECJ compiler.";
}
private static class CmdArgs {
@Shorthand("w")
@Description("Overwrite existing files. Defaults to false.")
boolean overwrite = false;
-
+
@Shorthand("o")
@Description("The root of a Maven project. Defaults to the current working directory.")
String output;
@@ -103,7 +98,7 @@ public class MavenEcjBootstrapApp extends LombokApp {
err = e;
}
if (result != 0) {
- System.err.println("Could not create "+mvn.getPath());
+ System.err.println("Could not create " + mvn.getPath());
if (err != null) err.printStackTrace(System.err);
}
return result;
@@ -136,15 +131,21 @@ public class MavenEcjBootstrapApp extends LombokApp {
return 1;
}
try {
- InputStream input = this.getClass().getResourceAsStream("/lombok/eclipse/agent/lombok-bootstrap.jar");
+ InputStream input = MavenEcjBootstrapApp.class.getResourceAsStream("/lombok/launch/mavenEcjBootstrapAgent.jar");
FileOutputStream output = new FileOutputStream(jar);
- byte[] buffer = new byte[4096];
- int length;
- while ((length = input.read(buffer)) > 0) output.write(buffer, 0, length);
- output.flush();
- output.close();
- System.out.println("Successfully created: " + canonical(jar));
- return 0;
+ try {
+ byte[] buffer = new byte[4096];
+ int length;
+ while ((length = input.read(buffer)) > 0) output.write(buffer, 0, length);
+ output.flush();
+ output.close();
+ System.out.println("Successfully created: " + canonical(jar));
+ return 0;
+ } finally {
+ try {
+ output.close();
+ } catch (Exception ignore) {}
+ }
} catch (Exception e) {
System.err.println("Could not create: " + canonical(jar));
e.printStackTrace(System.err);
diff --git a/src/eclipseAgent/lombok/launch/AgentBootstrap.java b/src/eclipseAgent/lombok/launch/AgentBootstrap.java
deleted file mode 100644
index bbd9aa4d..00000000
--- a/src/eclipseAgent/lombok/launch/AgentBootstrap.java
+++ /dev/null
@@ -1,92 +0,0 @@
-/*
- * Copyright (C) 2009-2022 The Project Lombok Authors.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-package lombok.launch;
-
-import java.lang.instrument.ClassFileTransformer;
-import java.lang.instrument.IllegalClassFormatException;
-import java.lang.instrument.Instrumentation;
-import java.net.URL;
-import java.net.URLClassLoader;
-import java.security.ProtectionDomain;
-import java.util.jar.JarFile;
-
-/**
- * This Java agent does not transform bytecode, but acts as a watcher that can figure out when it is appropriate to load
- * Lombok itself within a Maven execution. It relies on several facts:
- * <ul>
- * <li>maven-compiler-plugin contains an AbstractCompilerMojo class that compiler instances extend.
- * <li>Maven loaders are ClassRealms, which extend URLClassLoader.
- * <li>Each plugin dependency in the pom.xml is represented as a file URL on the ClassRealm that points to the artifact.
- * <li>URLs to Maven artifacts contain the group and artifact ids ([...]/groupid/artifactid/ver/artifactid-ver.jar).
- * <li>The Lombok Java agent class is lombok.launch.Agent.
- * </ul>
- * Given all of the above, the transformer simply waits for AbstractCompilerMojo to be loaded, then uses the loader to
- * find the path to the Lombok jar file, and finally loads the Lombok agent using reflection.
- */
-public final class AgentBootstrap
-{
- private static final String MAVEN_COMPILER_TRIGGER_CLASS = "org/apache/maven/plugin/compiler/AbstractCompilerMojo";
- private static final String LOMBOK_URL_IDENTIFIER = "/org/projectlombok/lombok/";
- private static final String LOMBOK_AGENT_CLASS = "lombok.launch.Agent";
- private static final byte[] NOT_TRANSFORMED = null;
-
- private AgentBootstrap()
- {}
-
- /**
- * Invoked when agent is added via -javaagent argument.
- *
- * @param agentArgs
- * arguments
- * @param instrumentation
- * service provider
- */
- public static void premain(final String agentArgs, final Instrumentation instrumentation)
- {
- instrumentation.addTransformer(new ClassFileTransformer() {
- @Override
- public byte[] transform(final ClassLoader loader, final String className, final Class<?> cbr, final ProtectionDomain pd,
- final byte[] cfb)
- throws IllegalClassFormatException
- {
- if (MAVEN_COMPILER_TRIGGER_CLASS.equals(className)) {
- for (final URL url : ((URLClassLoader)loader).getURLs()) {
- if (url.getPath().contains(LOMBOK_URL_IDENTIFIER)) {
- try {
- instrumentation.appendToSystemClassLoaderSearch(new JarFile(url.getPath()));
- AgentBootstrap.class.getClassLoader().loadClass(LOMBOK_AGENT_CLASS)
- .getDeclaredMethod("premain", String.class, Instrumentation.class)
- .invoke(null, agentArgs, instrumentation);
- instrumentation.removeTransformer(this);
- break;
- } catch (final Exception e) {
- //There are no appropriate loggers available at this point in time.
- e.printStackTrace(System.err);
- }
- }
- }
- }
- return NOT_TRANSFORMED;
- }
- });
- }
-}