+++ /dev/null
-/*\r
- * Copyright 2011 gitblit.com.\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-package com.gitblit.client;\r
-\r
-import java.awt.Color;\r
-import java.awt.EventQueue;\r
-import java.awt.FontMetrics;\r
-import java.awt.Graphics2D;\r
-import java.awt.SplashScreen;\r
-import java.io.File;\r
-import java.io.FileFilter;\r
-import java.io.IOException;\r
-import java.lang.reflect.Method;\r
-import java.net.URL;\r
-import java.net.URLClassLoader;\r
-import java.text.MessageFormat;\r
-import java.util.ArrayList;\r
-import java.util.Arrays;\r
-import java.util.Collections;\r
-import java.util.List;\r
-\r
-import com.gitblit.Constants;\r
-\r
-/**\r
- * Downloads dependencies and launches Gitblit Manager.\r
- *\r
- * @author James Moger\r
- *\r
- */\r
-public class GitblitManagerLauncher {\r
-\r
- public static final boolean DEBUG = false;\r
-\r
- /**\r
- * Parameters of the method to add an URL to the System classes.\r
- */\r
- private static final Class<?>[] PARAMETERS = new Class[] { URL.class };\r
-\r
- public static void main(String[] args) {\r
- final SplashScreen splash = SplashScreen.getSplashScreen();\r
-\r
- File libFolder = new File("ext");\r
- List<File> jars = findJars(libFolder.getAbsoluteFile());\r
-\r
- // sort the jars by name and then reverse the order so the newer version\r
- // of the library gets loaded in the event that this is an upgrade\r
- Collections.sort(jars);\r
- Collections.reverse(jars);\r
- for (File jar : jars) {\r
- try {\r
- updateSplash(splash, Translation.get("gb.loading") + " " + jar.getName() + "...");\r
- addJarFile(jar);\r
- } catch (IOException e) {\r
-\r
- }\r
- }\r
-\r
- updateSplash(splash, Translation.get("gb.starting") + " Gitblit Manager...");\r
- GitblitManager.main(args);\r
- }\r
-\r
- private static void updateSplash(final SplashScreen splash, final String string) {\r
- if (splash == null) {\r
- return;\r
- }\r
- try {\r
- EventQueue.invokeAndWait(new Runnable() {\r
- @Override\r
- public void run() {\r
- Graphics2D g = splash.createGraphics();\r
- if (g != null) {\r
- // Splash is 320x120\r
- FontMetrics fm = g.getFontMetrics();\r
-\r
- // paint startup status\r
- g.setColor(Color.darkGray);\r
- int h = fm.getHeight() + fm.getMaxDescent();\r
- int x = 5;\r
- int y = 115;\r
- int w = 320 - 2 * x;\r
- g.fillRect(x, y - h, w, h);\r
- g.setColor(Color.lightGray);\r
- g.drawRect(x, y - h, w, h);\r
- g.setColor(Color.WHITE);\r
- int xw = fm.stringWidth(string);\r
- g.drawString(string, x + ((w - xw) / 2), y - 5);\r
-\r
- // paint version\r
- String ver = "v" + Constants.getVersion();\r
- int vw = g.getFontMetrics().stringWidth(ver);\r
- g.drawString(ver, 320 - vw - 5, 34);\r
- g.dispose();\r
- splash.update();\r
- }\r
- }\r
- });\r
- } catch (Throwable t) {\r
- t.printStackTrace();\r
- }\r
- }\r
-\r
- public static List<File> findJars(File folder) {\r
- List<File> jars = new ArrayList<File>();\r
- if (folder.exists()) {\r
- File[] libs = folder.listFiles(new FileFilter() {\r
- @Override\r
- public boolean accept(File file) {\r
- return !file.isDirectory() && file.getName().toLowerCase().endsWith(".jar");\r
- }\r
- });\r
- if (libs != null && libs.length > 0) {\r
- jars.addAll(Arrays.asList(libs));\r
- if (DEBUG) {\r
- for (File jar : jars) {\r
- System.out.println("found " + jar);\r
- }\r
- }\r
- }\r
- }\r
-\r
- return jars;\r
- }\r
-\r
- /**\r
- * Adds a file to the classpath\r
- *\r
- * @param f\r
- * the file to be added\r
- * @throws IOException\r
- */\r
- public static void addJarFile(File f) throws IOException {\r
- if (f.getName().indexOf("-sources") > -1 || f.getName().indexOf("-javadoc") > -1) {\r
- // don't add source or javadoc jars to runtime classpath\r
- return;\r
- }\r
- URL u = f.toURI().toURL();\r
- if (DEBUG) {\r
- System.out.println("load=" + u.toExternalForm());\r
- }\r
- URLClassLoader sysloader = (URLClassLoader) ClassLoader.getSystemClassLoader();\r
- Class<?> sysclass = URLClassLoader.class;\r
- try {\r
- Method method = sysclass.getDeclaredMethod("addURL", PARAMETERS);\r
- method.setAccessible(true);\r
- method.invoke(sysloader, new Object[] { u });\r
- } catch (Throwable t) {\r
- throw new IOException(MessageFormat.format(\r
- "Error, could not add {0} to system classloader", f.getPath()), t);\r
- }\r
- }\r
-\r
-}\r