incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fmesc...@apache.org
Subject svn commit: r734947 - in /incubator/sling/whiteboard/fmeschbe/launchpad: app/src/main/java/ base/src/main/java/org/apache/sling/launchpad/app/ base/src/main/java/org/apache/sling/launchpad/app/Main.java
Date Fri, 16 Jan 2009 09:22:44 GMT
Author: fmeschbe
Date: Fri Jan 16 01:22:44 2009
New Revision: 734947

URL: http://svn.apache.org/viewvc?rev=734947&view=rev
Log:
Move base class to base project

Added:
    incubator/sling/whiteboard/fmeschbe/launchpad/base/src/main/java/org/apache/sling/launchpad/app/
  (props changed)
      - copied from r734790, incubator/sling/whiteboard/fmeschbe/launchpad/app/src/main/java/org/apache/sling/launchpad/app/
Removed:
    incubator/sling/whiteboard/fmeschbe/launchpad/app/src/main/java/
Modified:
    incubator/sling/whiteboard/fmeschbe/launchpad/base/src/main/java/org/apache/sling/launchpad/app/Main.java

Propchange: incubator/sling/whiteboard/fmeschbe/launchpad/base/src/main/java/org/apache/sling/launchpad/app/
------------------------------------------------------------------------------
    svn:mergeinfo = 

Modified: incubator/sling/whiteboard/fmeschbe/launchpad/base/src/main/java/org/apache/sling/launchpad/app/Main.java
URL: http://svn.apache.org/viewvc/incubator/sling/whiteboard/fmeschbe/launchpad/base/src/main/java/org/apache/sling/launchpad/app/Main.java?rev=734947&r1=734790&r2=734947&view=diff
==============================================================================
--- incubator/sling/whiteboard/fmeschbe/launchpad/base/src/main/java/org/apache/sling/launchpad/app/Main.java
(original)
+++ incubator/sling/whiteboard/fmeschbe/launchpad/base/src/main/java/org/apache/sling/launchpad/app/Main.java
Fri Jan 16 01:22:44 2009
@@ -16,11 +16,17 @@
  */
 package org.apache.sling.launchpad.app;
 
+import java.io.BufferedReader;
 import java.io.File;
 import java.io.IOException;
+import java.io.PrintStream;
+import java.io.PrintWriter;
+import java.io.StringReader;
+import java.io.StringWriter;
 import java.net.MalformedURLException;
 import java.net.URL;
 
+import org.apache.sling.launcher.app.Sling;
 import org.apache.sling.launchpad.base.shared.Launcher;
 import org.apache.sling.launchpad.base.shared.Loader;
 import org.apache.sling.launchpad.base.shared.Notifiable;
@@ -61,123 +67,163 @@
  */
 public class Main extends Thread implements Notifiable {
 
-    public static void main(String[] args) {
-        new Main(args);
-    }
-
-    private final String[] commandLineArgs;
-
-    private final String slingHome;
-
-    private Launcher sling;
-
-    private Main(String[] args) {
-
-        // set the thread name
-        super("Sling Terminator");
-
-        // sling.home from the command line or system properties, else default
-        String slingHome = getSlingHome(args);
-        if (slingHome == null) {
-            slingHome = System.getProperty("sling.home");
-        }
-
-        this.commandLineArgs = args;
-        this.slingHome = slingHome;
-        
-        Runtime.getRuntime().addShutdownHook(this);
-
-        // ensure up-to-date launcher jar
-        startSling(getClass().getResource(Loader.DEFAULT_SLING_LAUNCHER_JAR));
-    }
-
-    private void startSling(URL launcherJar) {
-        if (launcherJar != null) {
-            try {
-                Loader.installLauncherJar(launcherJar, slingHome);
-            } catch (IOException ioe) {
-                // TODO:LOG
-            }
-        }
-
-        Object object = Loader.loadLauncher(Loader.DEFAULT_SLING_MAIN,
-            slingHome);
-        if (object instanceof Launcher) {
-            
-            // configure the launcher
-            Launcher sling = (Launcher) object;
-            sling.setNotifiable(this);
-            sling.setCommandLine(commandLineArgs);
-            sling.setSlingHome(slingHome);
-            
-            // launch it
-            if (sling.start()) {
-                this.sling = sling;
-            }
-        }
-    }
-    
-    public void stopped() {
-        /**
-         * This method is called if the framework is stopped from within
-         * by calling stop on the system bundle or if the framework is
-         * stopped because the VM is going down and the shutdown hook
-         * has initated the shutdown
-         * In any case we ensure the reference to the framework is removed
-         * and remove the shutdown hook (but don't care if that fails).
-         */
-        
-        System.out.println("Sling has been stopped");
-        
-        // clear the reference to the framework
-        sling = null;
-        
-        // remove the shutdown hook, the framework has terminated and
-        // we do not need to do anything else
-        try {
-            Runtime.getRuntime().removeShutdownHook(this);
-        } catch (Throwable t) {
-            // don't care for problems removing the hook
-        }
-    }
-
-    public void updated(File updateFile) {
-        if (updateFile == null) {
-        
-            System.out.println("Restarting ....");
-            startSling(null);
-
-        } else {
-
-            System.out.println("Sling has been updated with " + updateFile);
-            try {
-                startSling(updateFile.toURL());
-            } catch (MalformedURLException mue) {
-                // TODO: Shout !
-            } finally {
-                updateFile.delete();
-            }
-            
-        }
-    }
-
-    public void run() {
-        if (sling != null) {
-            sling.stop();
-        }
-    }
-
-    private static String getSlingHome(String[] args) {
-        for (int argc = 0; argc < args.length; argc++) {
-            String arg = args[argc];
-            if (arg.startsWith("-") && arg.length() == 2
-                && arg.charAt(1) == 'c') {
-                argc++;
-                return (argc < args.length) ? args[argc] : null;
-            }
-        }
-
-        return null;
-    }
-
+	public static void main(String[] args) {
+		new Main(args);
+	}
+
+	private final String[] commandLineArgs;
+
+	private final String slingHome;
+
+	private Launcher sling;
+
+	private Main(String[] args) {
+
+		// set the thread name
+		super("Sling Terminator");
+
+		// sling.home from the command line or system properties, else default
+		String slingHome = getSlingHome(args);
+		if (slingHome == null) {
+			slingHome = System.getProperty("sling.home", "sling");
+		}
+		info("Starting Sling in " + slingHome, null);
+
+		this.commandLineArgs = args;
+		this.slingHome = slingHome;
+
+		Runtime.getRuntime().addShutdownHook(this);
+
+		// ensure up-to-date launcher jar
+		startSling(getClass().getResource(Loader.DEFAULT_SLING_LAUNCHER_JAR));
+	}
+
+	private void startSling(URL launcherJar) {
+		if (launcherJar != null) {
+			try {
+				Loader.installLauncherJar(launcherJar, slingHome);
+			} catch (IOException ioe) {
+				error("Failed installing " + launcherJar, ioe);
+			}
+		} else {
+			info("No Launcher JAR to install", null);
+		}
+
+		Object object;
+		try {
+			object = Loader.loadLauncher(Loader.DEFAULT_SLING_MAIN, slingHome);
+		} catch (IllegalArgumentException iae) {
+			error("Failed loading Sling class " + Loader.DEFAULT_SLING_MAIN,
+					iae);
+			return;
+		}
+
+		if (object instanceof Launcher) {
+
+			// configure the launcher
+			Launcher sling = (Launcher) object;
+			sling.setNotifiable(this);
+			sling.setCommandLine(commandLineArgs);
+			sling.setSlingHome(slingHome);
+
+			// launch it
+			if (sling.start()) {
+				this.sling = sling;
+			}
+		}
+	}
+
+	public void stopped() {
+		/**
+		 * This method is called if the framework is stopped from within by
+		 * calling stop on the system bundle or if the framework is stopped
+		 * because the VM is going down and the shutdown hook has initated the
+		 * shutdown In any case we ensure the reference to the framework is
+		 * removed and remove the shutdown hook (but don't care if that fails).
+		 */
+
+		System.out.println("Sling has been stopped");
+
+		// clear the reference to the framework
+		sling = null;
+
+		// remove the shutdown hook, the framework has terminated and
+		// we do not need to do anything else
+		try {
+			Runtime.getRuntime().removeShutdownHook(this);
+		} catch (Throwable t) {
+			// don't care for problems removing the hook
+		}
+	}
+
+	public void updated(File updateFile) {
+		if (updateFile == null) {
+
+			System.out.println("Restarting ....");
+			startSling(null);
+
+		} else {
+
+			System.out.println("Sling has been updated with " + updateFile);
+			try {
+				startSling(updateFile.toURL());
+			} catch (MalformedURLException mue) {
+				// TODO: Shout !
+			} finally {
+				updateFile.delete();
+			}
+
+		}
+	}
+
+	public void run() {
+		if (sling != null) {
+			sling.stop();
+		}
+	}
+
+	private static String getSlingHome(String[] args) {
+		for (int argc = 0; argc < args.length; argc++) {
+			String arg = args[argc];
+			if (arg.startsWith("-") && arg.length() == 2
+					&& arg.charAt(1) == 'c') {
+				argc++;
+				return (argc < args.length) ? args[argc] : null;
+			}
+		}
+
+		return null;
+	}
+
+	private static void info(String message, Throwable t) {
+		log(System.out, "INF: ", message, t);
+	}
+
+	private static void warn(String message, Throwable t) {
+		log(System.out, "WRN: ", message, t);
+	}
+
+	private static void error(String message, Throwable t) {
+		log(System.err, "ERR: ", message, t);
+	}
+
+	private static void log(PrintStream out, String prefix, String message, Throwable t) {
+		out.print(prefix);
+		out.println(message);
+		if (t != null) {
+			StringWriter sw = new StringWriter();
+			PrintWriter pw = new PrintWriter(sw);
+			t.printStackTrace(pw);
+			pw.close();
+			BufferedReader br = new BufferedReader(new StringReader(sw.toString()));
+			String line;
+			try {
+				while ((line = br.readLine()) != null) {
+					out.print(prefix);
+					out.println(line);
+				}
+			} catch (IOException ignore) {
+			}
+		}
+	}
 }



Mime
View raw message