From 8c7c764d7fcc2c6c37db38a3d77f5e6d1c7b87a7 Mon Sep 17 00:00:00 2001 From: Reinier Zwitserloot Date: Fri, 27 Nov 2009 13:54:14 +0100 Subject: SPI-ified the 'app' concept, which lets us create little apps inside lombok.jar proper. Currently used only by 'delombok'. --- src/installer/lombok/installer/Installer.java | 37 ++++++++++++++------------- 1 file changed, 19 insertions(+), 18 deletions(-) (limited to 'src/installer') diff --git a/src/installer/lombok/installer/Installer.java b/src/installer/lombok/installer/Installer.java index d6f1add0..5b023766 100644 --- a/src/installer/lombok/installer/Installer.java +++ b/src/installer/lombok/installer/Installer.java @@ -40,12 +40,11 @@ import java.awt.event.ActionListener; import java.awt.font.TextAttribute; import java.io.File; import java.io.FilenameFilter; +import java.io.IOException; import java.net.URI; import java.util.ArrayList; import java.util.Collections; -import java.util.HashMap; import java.util.List; -import java.util.Map; import java.util.concurrent.atomic.AtomicReference; import javax.swing.Box; @@ -65,6 +64,8 @@ import javax.swing.SwingUtilities; import javax.swing.UIManager; import javax.swing.filechooser.FileFilter; +import lombok.core.LombokApp; +import lombok.core.SpiLoadUtil; import lombok.core.Version; import lombok.installer.EclipseFinder.OS; import lombok.installer.EclipseLocation.InstallException; @@ -96,26 +97,26 @@ public class Installer { private JLabel uninstallPlaceholder; private JButton installButton; - private static final Map APPS; - static { - Map m = new HashMap(); - m.put("delombok", "lombok.delombok.Delombok"); - APPS = Collections.unmodifiableMap(m); - } - public static void main(String[] args) { if (args.length > 0) { - String className = APPS.get(args[0]); - if (className != null) { - String[] newArgs = new String[args.length-1]; - System.arraycopy(args, 1, newArgs, 0, newArgs.length); - try { - Class.forName(className).getMethod("main", String[].class).invoke(newArgs); - } catch (Exception e) { - System.err.println("Lombok bug: Can't find application main class: " + className); + String appName = args[0]; + String[] newArgs = new String[args.length-1]; + System.arraycopy(args, 1, newArgs, 0, newArgs.length); + Iterable services; + try { + services = SpiLoadUtil.findServices(LombokApp.class); + } catch (IOException e) { + System.err.println("Your lombok installation appears to be corrupted! Please let us know by clicking 'report bugs' on projectlombok.org. Include this stack trace:"); + e.printStackTrace(); + System.exit(2); + return; + } + for (LombokApp app : services) { + if (appName.equals(app.getAppName())) { + app.runApp(newArgs); + return; } } - return; } if (args.length > 0 && (args[0].equals("install") || args[0].equals("uninstall"))) { boolean uninstall = args[0].equals("uninstall"); -- cgit