Revision: 15015
http://gate.svn.sourceforge.net/gate/?rev=15015&view=rev
Author: valyt
Date: 2012-01-12 14:00:10 +0000 (Thu, 12 Jan 2012)
Log Message:
-----------
New GATE Launcher: sources, build files, shortcut for launch4j.
Modified Paths:
--------------
gate/trunk/build/deploy/launch4j-gate.xml
gate/trunk/build.xml
Added Paths:
-----------
gate/trunk/build/launcher/
gate/trunk/build/launcher/.classpath
gate/trunk/build/launcher/.project
gate/trunk/build/launcher/build.xml
gate/trunk/build/launcher/classes/
gate/trunk/build/launcher/classes/gate/
gate/trunk/build/launcher/classes/gate/Launcher$1.class
gate/trunk/build/launcher/classes/gate/Launcher.class
gate/trunk/build/launcher/src/
gate/trunk/build/launcher/src/gate/
gate/trunk/build/launcher/src/gate/Launcher.java
Modified: gate/trunk/build/deploy/launch4j-gate.xml
===================================================================
--- gate/trunk/build/deploy/launch4j-gate.xml 2012-01-12 13:59:17 UTC (rev
15014)
+++ gate/trunk/build/deploy/launch4j-gate.xml 2012-01-12 14:00:10 UTC (rev
15015)
@@ -2,9 +2,9 @@
<launch4jConfig>
<dontWrapJar>true</dontWrapJar>
<headerType>gui</headerType>
- <jar>lib/ant-launcher.jar</jar>
+ <jar>bin/gateLauncher.jar</jar>
<errTitle></errTitle>
- <cmdLine>run</cmdLine>
+ <cmdLine></cmdLine>
<chdir>.</chdir>
<priority>normal</priority>
<downloadUrl>http://java.sun.com/javase/downloads/</downloadUrl>
Added: gate/trunk/build/launcher/.classpath
===================================================================
--- gate/trunk/build/launcher/.classpath (rev 0)
+++ gate/trunk/build/launcher/.classpath 2012-01-12 14:00:10 UTC (rev
15015)
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="con"
path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+ <classpathentry kind="output" path="classes"/>
+</classpath>
Property changes on: gate/trunk/build/launcher/.classpath
___________________________________________________________________
Added: svn:eol-style
+ native
Added: gate/trunk/build/launcher/.project
===================================================================
--- gate/trunk/build/launcher/.project (rev 0)
+++ gate/trunk/build/launcher/.project 2012-01-12 14:00:10 UTC (rev 15015)
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>GATE-launcher</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
Property changes on: gate/trunk/build/launcher/.project
___________________________________________________________________
Added: svn:eol-style
+ native
Added: gate/trunk/build/launcher/build.xml
===================================================================
--- gate/trunk/build/launcher/build.xml (rev 0)
+++ gate/trunk/build/launcher/build.xml 2012-01-12 14:00:10 UTC (rev 15015)
@@ -0,0 +1,46 @@
+<project name="GATE-launcher" basedir="." default="jar" >
+
+
+ <!-- If gate.home is not set from build.properties or the
+ environment variable GATE_HOME, assume that this
+ plugin is in GATE Developer's plugin directory -->
+ <property name="src.dir" location="src" />
+ <property name="classes.dir" location="classes" />
+ <property name="jar.location" location="../../bin/gateLauncher.jar" />
+
+ <!-- create build directory structure -->
+ <target name="prepare">
+ <mkdir dir="${classes.dir}" />
+ </target>
+
+ <!-- compile the source -->
+ <target name="compile" depends="prepare">
+ <javac srcdir="${src.dir}"
+ destdir="${classes.dir}"
+ debug="true"
+ debuglevel="lines,source"
+ encoding="UTF-8"
+ source="1.6" target="1.6" />
+ </target>
+
+ <!-- create the JAR file -->
+ <target name="jar" depends="compile" >
+ <jar destfile="${jar.location}"
+ update="false"
+ basedir="${classes.dir}">
+ <manifest>
+ <attribute name="Main-Class" value="gate.Launcher" />
+ </manifest>
+ </jar>
+ </target>
+
+ <!-- remove the generated .class files -->
+ <target name="clean.classes" >
+ <delete dir="${classes.dir}" />
+ </target>
+
+ <!-- Clean up - remove .class and .jar files -->
+ <target name="clean" depends="clean.classes" >
+ <delete file="${jar.location}" />
+ </target>
+</project>
Property changes on: gate/trunk/build/launcher/build.xml
___________________________________________________________________
Added: svn:eol-style
+ native
Added: gate/trunk/build/launcher/classes/gate/Launcher$1.class
===================================================================
(Binary files differ)
Property changes on: gate/trunk/build/launcher/classes/gate/Launcher$1.class
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added: gate/trunk/build/launcher/classes/gate/Launcher.class
===================================================================
(Binary files differ)
Property changes on: gate/trunk/build/launcher/classes/gate/Launcher.class
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added: gate/trunk/build/launcher/src/gate/Launcher.java
===================================================================
--- gate/trunk/build/launcher/src/gate/Launcher.java
(rev 0)
+++ gate/trunk/build/launcher/src/gate/Launcher.java 2012-01-12 14:00:10 UTC
(rev 15015)
@@ -0,0 +1,182 @@
+/*
+ * Launcher.java
+ *
+ * Copyright (c) 1995-2010, The University of Sheffield. See the file
+ * COPYRIGHT.txt in the software or at http://gate.ac.uk/gate/COPYRIGHT.txt
+ *
+ * This file is part of GATE (see http://gate.ac.uk/), and is free
+ * software, licenced under the GNU Library General Public License,
+ * Version 2, June 1991 (in the distribution as file licence.html,
+ * and also available at http://gate.ac.uk/gate/licence.html).
+ *
+ * Valentin Tablan, 12 January 2012
+ *
+ * $Id$
+ */
+package gate;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FilenameFilter;
+import java.io.IOException;
+import java.io.InputStream;
+import java.lang.reflect.InvocationTargetException;
+import java.net.MalformedURLException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import javax.swing.filechooser.FileFilter;
+
+
+/**
+ * A simple launcher for GATE. It builds the correct classpath and starts
GATE.
+ */
+public class Launcher {
+
+ public static final String GATE_HOME_PROPERTY_NAME = "gate.home";
+
+ protected static final Pattern PLACEHOLDER =
Pattern.compile("\\$\\{(.*?)\\}");
+
+
+ protected File gateHome;
+
+ protected URLClassLoader classLoader;
+
+ public void startGate(String[] args) throws ClassNotFoundException,
+ SecurityException, NoSuchMethodException, IllegalArgumentException,
+ IllegalAccessException, InvocationTargetException, URISyntaxException,
+ IOException {
+ findGateHome();
+ readSystemProperties();
+ buildClassPath();
+ Thread.currentThread().setContextClassLoader(classLoader);
+ Class.forName("gate.Main", true, classLoader).getDeclaredMethod(
+ "main", new Class[]{String[].class}).invoke(null, new Object[] {args});
+ }
+
+ protected void findGateHome() throws URISyntaxException {
+ String gateHomeStr = System.getProperty(GATE_HOME_PROPERTY_NAME);
+ if(gateHomeStr != null && gateHomeStr.length() > 0) {
+ gateHome = new File(gateHomeStr);
+ }
+ if(gateHome == null || !gateHome.exists()) {
+ URL gateURL = Launcher.class.getClassLoader().getResource(
+ "gate/Launcher.class");
+ if(gateURL.getProtocol().equals("jar")) {
+ // running from gateLauncher.jar
+ String gateURLStr = gateURL.getFile();
+ File gateJarFile = new File(new URI(
+ gateURLStr.substring(0, gateURLStr.indexOf('!'))));
+ gateHome = gateJarFile.getParentFile().getParentFile();
+ } else {
+ throw new RuntimeException("Could not find gateLauncher.jar! " +
+ "How has this launcher been started?");
+ }
+ }
+ }
+
+ protected void buildClassPath() throws MalformedURLException {
+ List<URL> urls = new LinkedList<URL>();
+ File binDir = new File(gateHome, "bin");
+ urls.add(binDir.toURI().toURL());
+ urls.add(new File(binDir, "gate.jar").toURI().toURL());
+ File libDir = new File(gateHome, "lib");
+ FilenameFilter jarFinder = new FilenameFilter() {
+ @Override
+ public boolean accept(File dir, String name) {
+ return name.toLowerCase().endsWith(".jar");
+ }
+ };
+ for(File aJar : libDir.listFiles(jarFinder)) {
+ urls.add(aJar.toURI().toURL());
+ }
+ classLoader = new URLClassLoader(urls.toArray(new URL[urls.size()]),
+ Launcher.class.getClassLoader());
+ }
+
+ protected void readSystemProperties() throws IOException {
+ File buildPropertiesFile = new File(gateHome, "build.properties");
+ if(buildPropertiesFile.canRead()) {
+ Properties buildProperties = new Properties();
+ InputStream in = new FileInputStream(buildPropertiesFile);
+ try {
+ buildProperties.load(in);
+ } finally {
+ in.close();
+ }
+
+
+ String osPrefix = "os." + System.getProperty("os.name") + ".";
+ for(String key : buildProperties.stringPropertyNames()) {
+ if(key.startsWith("run.")) {
+ System.setProperty(key.substring(4), getPropertyValue(key,
+ new HashSet<String>(), buildProperties, System.getProperties()));
+ } else if(key.startsWith(osPrefix)) {
+ System.setProperty(key.substring(osPrefix.length()),
getPropertyValue(key,
+ new HashSet<String>(), buildProperties, System.getProperties()));
+ }
+ }
+ }
+ String gateHomeStr = System.getProperty(GATE_HOME_PROPERTY_NAME);
+ if(gateHomeStr != null && gateHomeStr.length() > 0) {
+ gateHome = new File(gateHomeStr);
+ }
+ }
+
+ protected String getPropertyValue(String key, Set<String> seen,
Properties... context) {
+ String value = null;
+ for(Properties p : context) {
+ value = p.getProperty(key);
+ if(value != null) break;
+ }
+ if(value != null) {
+ Matcher m = PLACEHOLDER.matcher(value);
+ if(m.find()) {
+ m.reset();
+ StringBuffer newValue = new StringBuffer();
+ while(m.find()) {
+ String varName = m.group(1);
+ if(seen.contains(varName)) {
+ throw new RuntimeException("Property " + varName +
+ " is circularly defined.");
+ }
+ seen.add(varName);
+ try {
+ String varValue = getPropertyValue(varName, seen, context);
+ if(varValue == null) {
+ varValue = m.group();
+ }
+ m.appendReplacement(newValue, Matcher.quoteReplacement(varValue));
+ } finally {
+ seen.remove(varName);
+ }
+ }
+ m.appendTail(newValue);
+ value = newValue.toString();
+ }
+ }
+ return value;
+ }
+
+ /**
+ * @param args
+ */
+ public static void main(String[] args) {
+ Launcher launcher = new Launcher();
+ try {
+ launcher.startGate(args);
+ } catch(Exception e) {
+ e.printStackTrace();
+ }
+ }
+}
Property changes on: gate/trunk/build/launcher/src/gate/Launcher.java
___________________________________________________________________
Added: svn:keywords
+ Id
Added: svn:eol-style
+ native
Modified: gate/trunk/build.xml
===================================================================
--- gate/trunk/build.xml 2012-01-12 13:59:17 UTC (rev 15014)
+++ gate/trunk/build.xml 2012-01-12 14:00:10 UTC (rev 15015)
@@ -409,6 +409,8 @@
includes="META-INF/**,gate/**,com/**,hepple/**"/>
<!-- <zipgroupfileset refid="libs"/> -->
</jar>
+ <!-- also build the launcher -->
+ <ant dir="build/launcher" inheritAll="false" target="jar" />
</target>
<!-- Optional target useful for creating jars for embedded apps. It splits
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
RSA(R) Conference 2012
Mar 27 - Feb 2
Save $400 by Jan. 27
Register now!
http://p.sf.net/sfu/rsa-sfdev2dev2
_______________________________________________
GATE-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/gate-cvs