Index: main/build.xml =================================================================== RCS file: /cvsroot/cruisecontrol/cruisecontrol/main/build.xml,v retrieving revision 1.91 diff -u -r1.91 build.xml --- main/build.xml 21 Jun 2005 02:35:57 -0000 1.91 +++ main/build.xml 11 Jul 2005 21:50:05 -0000 @@ -301,10 +301,19 @@ - - + + + + + + + + + + + Index: main/manifest.mf =================================================================== RCS file: main/manifest.mf diff -N main/manifest.mf --- main/manifest.mf 3 Nov 2004 00:11:00 -0000 1.9 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,22 +0,0 @@ -Manifest-Version: 1.2 -Class-Path: - ../lib/activation.jar - ../lib/comm.jar - ../lib/commons-net-1.1.0.jar - ../lib/jakarta-oro-2.0.3.jar - ../lib/jdom.jar - ../lib/log4j.jar - ../lib/mail.jar - ../lib/mx4j-tools.jar - ../lib/mx4j-remote.jar - ../lib/mx4j.jar - ../lib/smack.jar - ../lib/starteam-sdk.jar - ../lib/STComm.jar - ../lib/x10.jar - ../lib/xalan.jar - ../lib/xerces.jar - ../lib/ant/ant.jar - ../lib/ant/ant-launcher.jar -Main-Class: CruiseControl - Index: main/bin/cruisecontrol.bat =================================================================== RCS file: /cvsroot/cruisecontrol/cruisecontrol/main/bin/cruisecontrol.bat,v retrieving revision 1.14 diff -u -r1.14 cruisecontrol.bat --- main/bin/cruisecontrol.bat 16 Oct 2004 22:51:08 -0000 1.14 +++ main/bin/cruisecontrol.bat 11 Jul 2005 21:50:05 -0000 @@ -52,25 +52,19 @@ if not defined CCDIR set CCDIR=%DEFAULT_CCDIR% set DEFAULT_CCDIR= -:setClassPath -set CRUISE_PATH= - :checkJava if not defined JAVA_HOME goto noJavaHome -set CRUISE_PATH=%JAVA_HOME%\lib\tools.jar goto setCruise :noJavaHome -echo Warning: You have not set the JAVA_HOME environment variable. Any tasks relying on the tools.jar file (such as ) will not work properly. +echo Warning: You have not set the JAVA_HOME environment variable. Any tasks relying on the tools.jar file (such as ) may not work properly. :setCruise - set LIBDIR=%CCDIR%\lib set DISTDIR=%CCDIR%\dist -set CRUISE_PATH=%CRUISE_PATH%;%DISTDIR%\cruisecontrol.jar;%LIBDIR%\log4j.jar;%LIBDIR%\jdom.jar;%LIBDIR%\ant\ant.jar;%LIBDIR%\ant\ant-launcher.jar;%LIBDIR%\xerces.jar;%LIBDIR%\xalan.jar;%LIBDIR%\jakarta-oro-2.0.3.jar;%LIBDIR%\mail.jar;%LIBDIR%\junit.jar;%LIBDIR%\activation.jar;%LIBDIR%\commons-net-1.1.0.jar;%LIBDIR%\starteam-sdk.jar;%LIBDIR%\mx4j.jar;%LIBDIR%\mx4j-tools.jar;%LIBDIR%\mx4j-remote.jar;%LIBDIR%\smack.jar;%LIBDIR%\comm.jar;%LIBDIR%\x10.jar;. - -set EXEC="%JAVA_HOME%\bin\java" -cp "%CRUISE_PATH%" -Djavax.management.builder.initial=mx4j.server.MX4JMBeanServerBuilder CruiseControl %* +set EXEC="%JAVA_HOME%\bin\java" -Djavax.management.builder.initial=mx4j.server.MX4JMBeanServerBuilder -Dcc.library.dir=%LIBDIR% -Dcc.dist.dir=%DISTDIR% -jar %DISTDIR%\cruisecontrol-launcher.jar %* echo %EXEC% +echo. %EXEC% Index: main/bin/cruisecontrol.sh =================================================================== RCS file: /cvsroot/cruisecontrol/cruisecontrol/main/bin/cruisecontrol.sh,v retrieving revision 1.15 diff -u -r1.15 cruisecontrol.sh --- main/bin/cruisecontrol.sh 24 Apr 2005 15:26:49 -0000 1.15 +++ main/bin/cruisecontrol.sh 11 Jul 2005 21:50:05 -0000 @@ -66,17 +66,11 @@ cd $saveddir echo Using Cruise Control at $CCDIR fi + LIBDIR=$CCDIR/lib DISTDIR=$CCDIR/dist -CRUISE_PATH=$JAVA_HOME/lib/tools.jar:$DISTDIR/cruisecontrol.jar:$LIBDIR/log4j.jar:$LIBDIR/jdom.jar:$LIBDIR/ant/ant.jar:$LIBDIR/ant/ant-launcher.jar:$LIBDIR/xerces.jar:$LIBDIR/xalan.jar:$LIBDIR/jakarta-oro-2.0.3.jar:$LIBDIR/mail.jar:$LIBDIR/junit.jar:$LIBDIR/activation.jar:$LIBDIR/commons-net-1.1.0.jar:$LIBDIR/starteam-sdk.jar:$LIBDIR/mx4j.jar:$LIBDIR/mx4j-tools.jar:$LIBDIR/mx4j-remote.jar:$LIBDIR/smack.jar:. - -# convert the existing path to unix -if [ `uname | grep -n CYGWIN` ]; then - CRUISE_PATH=`cygpath --path --windows "$CRUISE_PATH"` -fi - -EXEC="$JAVA_HOME/bin/java -cp $CRUISE_PATH -Djavax.management.builder.initial=mx4j.server.MX4JMBeanServerBuilder CruiseControl $@" +EXEC="$JAVA_HOME/bin/java -Djavax.management.builder.initial=mx4j.server.MX4JMBeanServerBuilder -Dcc.library.dir=$LIBDIR -Dcc.dist.dir=$DISTDIR -jar $DISTDIR/cruisecontrol-launcher.jar $@" echo $EXEC $EXEC Index: main/src/CruiseControl.java =================================================================== RCS file: /cvsroot/cruisecontrol/cruisecontrol/main/src/CruiseControl.java,v retrieving revision 1.23 diff -u -r1.23 CruiseControl.java --- main/src/CruiseControl.java 9 Sep 2004 00:19:38 -0000 1.23 +++ main/src/CruiseControl.java 11 Jul 2005 21:50:06 -0000 @@ -46,6 +46,8 @@ * @author alden almagro * @author Paul Julius * @author Jason Yip + * + * @deprecated Use the Launcher class instead. */ public final class CruiseControl { Index: main/src/net/sourceforge/cruisecontrol/Main.java =================================================================== RCS file: /cvsroot/cruisecontrol/cruisecontrol/main/src/net/sourceforge/cruisecontrol/Main.java,v retrieving revision 1.39 diff -u -r1.39 Main.java --- main/src/net/sourceforge/cruisecontrol/Main.java 14 Mar 2005 22:47:36 -0000 1.39 +++ main/src/net/sourceforge/cruisecontrol/Main.java 11 Jul 2005 21:50:06 -0000 @@ -41,6 +41,7 @@ import java.util.Properties; import net.sourceforge.cruisecontrol.jmx.CruiseControlControllerAgent; +import net.sourceforge.cruisecontrol.launch.CCMain; import net.sourceforge.cruisecontrol.util.threadpool.ThreadQueueProperties; import org.apache.log4j.Level; @@ -52,18 +53,26 @@ * @author alden almagro, ThoughtWorks, Inc. 2002 * @author Jason Yip */ -public final class Main { +public final class Main implements CCMain { private static final Logger LOG = Logger.getLogger(Main.class); public static final int NOT_FOUND = -1; - private Main() { } - + /** + * Commandline entry point into the application. + * + * @deprecated Use the Launcher class instead + */ + public static void main(String[] args) { + Main cruise = new Main(); + cruise.start(args); + } + /** * Print the version, configure the project with serialized build info * and/or arguments and start the project build process. */ - public static void main(String[] args) { + public void start(String[] args) { printVersion(); if (printUsage(args)) { usage(); Index: main/src/net/sourceforge/cruisecontrol/util/OSEnvironment.java =================================================================== RCS file: /cvsroot/cruisecontrol/cruisecontrol/main/src/net/sourceforge/cruisecontrol/util/OSEnvironment.java,v retrieving revision 1.3 diff -u -r1.3 OSEnvironment.java --- main/src/net/sourceforge/cruisecontrol/util/OSEnvironment.java 2 Jun 2005 16:32:07 -0000 1.3 +++ main/src/net/sourceforge/cruisecontrol/util/OSEnvironment.java 11 Jul 2005 21:50:09 -0000 @@ -139,7 +139,7 @@ command = "command.com /c set"; } else if ( (os.indexOf("nt") > -1) - || (os.indexOf("windows 200") > -1) + || (os.indexOf("windows 20") > -1) || (os.indexOf("windows xp") > -1) || (os.indexOf("os/2") > -1)) { command = "cmd.exe /c set"; Index: main/src/net/sourceforge/cruisecontrol/launch/CCMain.java =================================================================== RCS file: main/src/net/sourceforge/cruisecontrol/launch/CCMain.java diff -N main/src/net/sourceforge/cruisecontrol/launch/CCMain.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ main/src/net/sourceforge/cruisecontrol/launch/CCMain.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,67 @@ +/******************************************************************************** + * CruiseControl, a Continuous Integration Toolkit + * Copyright (c) 2001, ThoughtWorks, Inc. + * 651 W Washington Ave. Suite 600 + * Chicago, IL 60661 USA + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * + Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * + Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * + Neither the name of ThoughtWorks, Inc., CruiseControl, nor the + * names of its contributors may be used to endorse or promote + * products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + ********************************************************************************/ + /* + * Copyright 2003-2005 The Apache Software Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + package net.sourceforge.cruisecontrol.launch; + + /** + * Interface used to bridge to the actual Main class without any + * messy reflection + */ + public interface CCMain { + /** + * Start CruiseControl + * + * @param args Command line arguments to be handled directly by + * CruiseControl (passed through the launcher without processing) + */ + public void start(String[] args); +} Index: main/src/net/sourceforge/cruisecontrol/launch/LaunchException.java =================================================================== RCS file: main/src/net/sourceforge/cruisecontrol/launch/LaunchException.java diff -N main/src/net/sourceforge/cruisecontrol/launch/LaunchException.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ main/src/net/sourceforge/cruisecontrol/launch/LaunchException.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,35 @@ +/* + * Copyright 2003-2004 The Apache Software Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package net.sourceforge.cruisecontrol.launch; + +/** + * Signals an error condition during launching + */ +public class LaunchException extends Exception { + + /** + * Constructs an exception with the given descriptive message. + * + * @param message A description of or information about the exception. + * Should not be null. + */ + public LaunchException(String message) { + super(message); + } + +} Index: main/src/net/sourceforge/cruisecontrol/launch/Launcher.java =================================================================== RCS file: main/src/net/sourceforge/cruisecontrol/launch/Launcher.java diff -N main/src/net/sourceforge/cruisecontrol/launch/Launcher.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ main/src/net/sourceforge/cruisecontrol/launch/Launcher.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,293 @@ +/******************************************************************************** + * CruiseControl, a Continuous Integration Toolkit + * Copyright (c) 2001, ThoughtWorks, Inc. + * 651 W Washington Ave. Suite 600 + * Chicago, IL 60661 USA + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * + Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * + Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * + Neither the name of ThoughtWorks, Inc., CruiseControl, nor the + * names of its contributors may be used to endorse or promote + * products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + ********************************************************************************/ +/* + * Copyright 2003-2005 The Apache Software Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +package net.sourceforge.cruisecontrol.launch; + +import java.io.File; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLClassLoader; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.StringTokenizer; + +import net.sourceforge.cruisecontrol.launch.util.Locator; + +/** + * Provides the means to launch CruiseControl with the appropriate classpath. + * This code is based heavily on (some parts taken directly from) the Apache + * Ant project. + * + * @author file: URI. + * + *

Will be an absolute path if the given URI is absolute.

+ * + *

Swallows '%' that are not followed by two characters, + * doesn't deal with non-ASCII characters.

+ * + * @param uri the URI designating a file in the local filesystem. + * @return the local file system path for the file. + * @since Ant 1.6 + */ + public static String fromURI(String uri) { + URL url = null; + try { + url = new URL(uri); + } catch (MalformedURLException emYouEarlEx) { + // Ignore malformed exception + } + if (url == null || !("file".equals(url.getProtocol()))) { + throw new IllegalArgumentException("Can only handle valid file: URIs"); + } + StringBuffer buf = new StringBuffer(url.getHost()); + if (buf.length() > 0) { + buf.insert(0, File.separatorChar).insert(0, File.separatorChar); + } + String file = url.getFile(); + int queryPos = file.indexOf('?'); + buf.append((queryPos < 0) ? file : file.substring(0, queryPos)); + + uri = buf.toString().replace('/', File.separatorChar); + + if (File.pathSeparatorChar == ';' && uri.startsWith("\\") && uri.length() > 2 + && Character.isLetter(uri.charAt(1)) && uri.lastIndexOf(':') > -1) { + uri = uri.substring(1); + } + String path = decodeUri(uri); + return path; + } + + /** + * Decodes an Uri with % characters. + * @param uri String with the uri possibly containing % characters. + * @return The decoded Uri + */ + private static String decodeUri(String uri) { + if (uri.indexOf('%') == -1) { + return uri; + } + StringBuffer sb = new StringBuffer(); + CharacterIterator iter = new StringCharacterIterator(uri); + for (char c = iter.first(); c != CharacterIterator.DONE; + c = iter.next()) { + if (c == '%') { + char c1 = iter.next(); + if (c1 != CharacterIterator.DONE) { + int i1 = Character.digit(c1, 16); + char c2 = iter.next(); + if (c2 != CharacterIterator.DONE) { + int i2 = Character.digit(c2, 16); + sb.append((char) ((i1 << 4) + i2)); + } + } + } else { + sb.append(c); + } + } + String path = sb.toString(); + return path; + } + + /** + * Get the File necessary to load the Sun compiler tools. If the classes + * are available to this class, then no additional URL is required and + * null is returned. This may be because the classes are explicitly in the + * class path or provided by the JVM directly. + * + * @return the tools jar as a File if required, null otherwise. + */ + public static File getToolsJar() { + // firstly check if the tools jar is already in the classpath + boolean toolsJarAvailable = false; + try { + // just check whether this throws an exception + Class.forName("com.sun.tools.javac.Main"); + toolsJarAvailable = true; + } catch (Exception e) { + try { + Class.forName("sun.tools.javac.Main"); + toolsJarAvailable = true; + } catch (Exception e2) { + // ignore + } + } + if (toolsJarAvailable) { + return null; + } + // couldn't find compiler - try to find tools.jar + // based on java.home setting + String javaHome = System.getProperty("java.home"); + if (javaHome.toLowerCase(Locale.US).endsWith("jre")) { + javaHome = javaHome.substring(0, javaHome.length() - 4); + } + File toolsJar = new File(javaHome + "/lib/tools.jar"); + if (!toolsJar.exists()) { + System.out.println("Unable to locate tools.jar. " + + "Expected to find it in " + toolsJar.getPath()); + return null; + } + return toolsJar; + } + + /** + * Get an array of URLs representing all of the jar files in the + * given location. If the location is a file, it is returned as the only + * element of the array. If the location is a directory, it is scanned for + * jar files. + * + * @param location the location to scan for Jars. + * + * @return an array of URLs for all jars in the given location. + * + * @exception MalformedURLException if the URLs for the jars cannot be + * formed. + */ + public static URL[] getLocationURLs(File location) + throws MalformedURLException { + return getLocationURLs(location, new String[]{".jar"}); + } + + /** + * Get an array of URLs representing all of the files of a given set of + * extensions in the given location. If the location is a file, it is + * returned as the only element of the array. If the location is a + * directory, it is scanned for matching files. + * + * @param location + * the location to scan for files. + * @param extensions + * an array of extension that are to match in the directory + * search. + * + * @return an array of URLs of matching files. + * @exception MalformedURLException + * if the URLs for the files cannot be formed. + */ + public static URL[] getLocationURLs(File location, + final String[] extensions) + throws MalformedURLException { + + URL[] urls = new URL[0]; + + if (!location.exists()) { + return urls; + } + if (!location.isDirectory()) { + urls = new URL[1]; + String path = location.getPath(); + for (int i = 0; i < extensions.length; ++i) { + if (path.toLowerCase().endsWith(extensions[i])) { + urls[0] = location.toURL(); + break; + } + } + return urls; + } + File[] matches = location.listFiles( + new FilenameFilter() { + public boolean accept(File dir, String name) { + for (int i = 0; i < extensions.length; ++i) { + if (name.toLowerCase().endsWith(extensions[i])) { + return true; + } + } + return false; + } + }); + urls = new URL[matches.length]; + for (int i = 0; i < matches.length; ++i) { + urls[i] = matches[i].toURL(); + } + return urls; + } +} +