From f6b200be4c8b90c26886c6cdd5809abac8c4ac15 Mon Sep 17 00:00:00 2001 From: James Moger <james.moger@gitblit.com> Date: Wed, 27 Mar 2013 17:22:08 -0400 Subject: [PATCH] Reorganized to Apache Standard Directory Layout & integrated Moxie --- src/main/java/com/gitblit/client/GitblitManagerLauncher.java | 115 +++++++++++++++++++++++++++++++-------------------------- 1 files changed, 62 insertions(+), 53 deletions(-) diff --git a/src/com/gitblit/Launcher.java b/src/main/java/com/gitblit/client/GitblitManagerLauncher.java similarity index 61% rename from src/com/gitblit/Launcher.java rename to src/main/java/com/gitblit/client/GitblitManagerLauncher.java index a43331b..d0cc839 100644 --- a/src/com/gitblit/Launcher.java +++ b/src/main/java/com/gitblit/client/GitblitManagerLauncher.java @@ -13,35 +13,34 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.gitblit; +package com.gitblit.client; +import java.awt.Color; +import java.awt.EventQueue; +import java.awt.FontMetrics; +import java.awt.Graphics2D; +import java.awt.SplashScreen; import java.io.File; import java.io.FileFilter; import java.io.IOException; import java.lang.reflect.Method; import java.net.URL; import java.net.URLClassLoader; -import java.security.ProtectionDomain; import java.text.MessageFormat; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; -import com.gitblit.build.Build; +import com.gitblit.Constants; /** - * Launch helper class that adds all jars found in the local "lib" & "ext" - * folders and then calls the application main. Using this technique we do not - * have to specify a classpath and we can dynamically add jars to the - * distribution. - * - * This class also downloads all runtime dependencies, if they are not found. + * Downloads dependencies and launches Gitblit Manager. * * @author James Moger * */ -public class Launcher { +public class GitblitManagerLauncher { public static final boolean DEBUG = false; @@ -51,58 +50,67 @@ private static final Class<?>[] PARAMETERS = new Class[] { URL.class }; public static void main(String[] args) { - if (DEBUG) { - System.out.println("jcp=" + System.getProperty("java.class.path")); - ProtectionDomain protectionDomain = Launcher.class.getProtectionDomain(); - System.out.println("launcher=" - + protectionDomain.getCodeSource().getLocation().toExternalForm()); - } - - // download all runtime dependencies - Build.runtime(); - - // Load the JARs in the lib and ext folder - String[] folders = new String[] { "lib", "ext" }; - List<File> jars = new ArrayList<File>(); - for (String folder : folders) { - if (folder == null) { - continue; - } - File libFolder = new File(folder); - if (!libFolder.exists()) { - continue; - } - List<File> found = findJars(libFolder.getAbsoluteFile()); - jars.addAll(found); - } + final SplashScreen splash = SplashScreen.getSplashScreen(); + + File libFolder = new File("ext"); + List<File> jars = findJars(libFolder.getAbsoluteFile()); + // sort the jars by name and then reverse the order so the newer version // of the library gets loaded in the event that this is an upgrade Collections.sort(jars); Collections.reverse(jars); + for (File jar : jars) { + try { + updateSplash(splash, Translation.get("gb.loading") + " " + jar.getName() + "..."); + addJarFile(jar); + } catch (IOException e) { - if (jars.size() == 0) { - for (String folder : folders) { - File libFolder = new File(folder); - // this is a test of adding a comment - // more really interesting things - System.err.println("Failed to find any really cool JARs in " + libFolder.getPath()); - } - System.exit(-1); - } else { - for (File jar : jars) { - try { - jar.canRead(); - addJarFile(jar); - } catch (Throwable t) { - t.printStackTrace(); - } } } - - // Start Server - GitBlitServer.main(args); + + updateSplash(splash, Translation.get("gb.starting") + " Gitblit Manager..."); + GitblitManager.main(args); } + private static void updateSplash(final SplashScreen splash, final String string) { + if (splash == null) { + return; + } + try { + EventQueue.invokeAndWait(new Runnable() { + public void run() { + Graphics2D g = splash.createGraphics(); + if (g != null) { + // Splash is 320x120 + FontMetrics fm = g.getFontMetrics(); + + // paint startup status + g.setColor(Color.darkGray); + int h = fm.getHeight() + fm.getMaxDescent(); + int x = 5; + int y = 115; + int w = 320 - 2 * x; + g.fillRect(x, y - h, w, h); + g.setColor(Color.lightGray); + g.drawRect(x, y - h, w, h); + g.setColor(Color.WHITE); + int xw = fm.stringWidth(string); + g.drawString(string, x + ((w - xw) / 2), y - 5); + + // paint version + String ver = "v" + Constants.getVersion(); + int vw = g.getFontMetrics().stringWidth(ver); + g.drawString(ver, 320 - vw - 5, 34); + g.dispose(); + splash.update(); + } + } + }); + } catch (Throwable t) { + t.printStackTrace(); + } + } + public static List<File> findJars(File folder) { List<File> jars = new ArrayList<File>(); if (folder.exists()) { @@ -152,4 +160,5 @@ "Error, could not add {0} to system classloader", f.getPath()), t); } } + } -- Gitblit v1.9.1