Removing quickstart as the jetty plugin superseeds this

WW-1524


git-svn-id: https://svn.apache.org/repos/asf/struts/struts2/trunk@491065 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Donald J. Brown
2006-12-29 18:03:58 +00:00
parent 42bc64b5af
commit e8d53af627
9 changed files with 0 additions and 1563 deletions
-148
View File
@@ -1,148 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-plugins</artifactId>
<version>2.0.2-SNAPSHOT</version>
</parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-quickstart-plugin</artifactId>
<packaging>jar</packaging>
<name>Struts 2 Quickstart Plugin</name>
<scm>
<connection>scm:svn:http://svn.apache.org/repos/asf/struts/struts2/trunk/plugins/quickstart/</connection>
<developerConnection>scm:svn:https://svn.apache.org/repos/asf/struts/struts2/trunk/plugins/quickstart/</developerConnection>
<url>http://svn.apache.org/viewcvs.cgi/struts/struts2/trunk/plugins/quickstart/</url>
</scm>
<dependencies>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.4</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jsp-api</artifactId>
<version>2.0</version>
<scope>provided</scope>
</dependency>
<!-- Quickstart -->
<dependency>
<groupId>jetty</groupId>
<artifactId>org.mortbay.jetty</artifactId>
<version>5.1.4</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>eclipse</groupId>
<artifactId>jdtcore</artifactId>
<version>3.1.0</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>ant</groupId>
<artifactId>ant</artifactId>
<version>1.6.5</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>tomcat</groupId>
<artifactId>jasper-compiler</artifactId>
<version>5.5.12</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>tomcat</groupId>
<artifactId>jasper-runtime</artifactId>
<version>5.5.12</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>tomcat</groupId>
<artifactId>jasper-compiler-jdt</artifactId>
<version>5.5.12</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>commons-el</groupId>
<artifactId>commons-el</artifactId>
<version>1.0</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>1.0</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.1</version>
<optional>true</optional>
</dependency>
<!-- QuickStart -->
<dependency>
<groupId>xstream</groupId>
<artifactId>xstream</artifactId>
<version>1.1.2</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>commons-digester</groupId>
<artifactId>commons-digester</artifactId>
<version>1.7</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.9</version>
<scope>test</scope>
</dependency>
<!-- Test dependencies -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
<version>3.8.1</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>1.2.8</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-mock</artifactId>
<version>1.2.8</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
@@ -1,244 +0,0 @@
/*
* $Id$
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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 org.apache.struts2;
import java.io.File;
import java.io.FilenameFilter;
import java.lang.reflect.Method;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
/**
* <!-- START SNIPPET: javadoc -->
*
* Struts comes with various related tools included in the struts-core-VERSION.jar file. You can access these
* tools by simply unpacking the Struts distribution and running <b>java -jar struts-core-VERSION.jar</b>.
* Struts will automatically include all jars in the same directory as the struts-core-VERSION.jar file as well as all
* jars in the <i>lib</i> directory. This means you can invoke these tools either from within the standard directory
* structure found in the Struts distribution, or from within your WEB-INF/lib directory.
*
* <p/> You can access the help information for these tools by simply running the jar without any arguments.
*
* <!-- END SNIPPET: javadoc -->
*/
public class Main {
public static void main(String[] args) {
if (args.length == 0) {
System.out.println("Usage:");
System.out.println(" java -jar struts-toolbox.jar [command] (optional command args)");
System.out.println("");
System.out.println("Where [command] is one of the following:");
System.out.println(" quickstart");
System.out.println(" quickstart:xxx");
System.out.println("");
System.out.println("Execute the commands for additional usage instructions.");
System.out.println("Note: the *:xxx commands are just shortcuts for ");
System.out.println(" running the command on a webapp in the apps dir.");
System.out.println(" For example, 'quickstart:sandbox' will start QuickStart");
System.out.println(" automatically for the webapp 'sandbox'.");
return;
}
// check the JDK version
String version = System.getProperty("java.version");
boolean jdk15 = version.indexOf("1.5") != -1;
String javaHome = System.getProperty("java.home");
ArrayList<URL> urls = new ArrayList<URL>();
try {
findJars(new File("lib"), urls);
// use all the jars in the current that aren't the src jar
File wd = new File(".");
File[] jars = wd.listFiles(new FilenameFilter() {
public boolean accept(File dir, String name) {
return name.endsWith(".jar") && name.indexOf("-src.") == -1;
}
});
for (int i = 0; i < jars.length; i++) {
File jar = jars[i];
urls.add(jar.toURL());
}
// ... but there might not be any (ie: we're in development in IDEA), so use this as backup
urls.add(new File(System.getProperty("struts.classes", "build/java")).toURL());
urls.add(new File(System.getProperty("xwork.classes", "../xwork/build/java/")).toURL());
// load tools.jar from JAVA_HOME
File tools = new File(javaHome, "lib/tools.jar");
if (!tools.exists()) {
// hmm, not there, how about java.home?
tools = new File(javaHome, "../lib/tools.jar");
}
if (!tools.exists()) {
// try the OS X common path
tools = new File(javaHome, "../Classes/classes.jar");
}
if (!tools.exists()) {
// try the other OS X common path
tools = new File(javaHome, "../Classes/classes.jar");
}
if (!tools.exists()) {
// did the user specify it by hand?
String prop = System.getProperty("tools");
if (prop != null) {
tools = new File(prop);
}
}
if (!tools.exists()) {
System.out.println("Error: Could not find tools.jar! Please do one of the following: ");
System.out.println("");
System.out.println(" - Use the JDK's JVM (ie: c:\\jdk1.5.0\\bin\\java)");
System.out.println(" - Specify JAVA_HOME to point to your JDK 1.5 home");
System.out.println(" - Specify a direct path to tools.jar via, as shown below:");
System.out.println("");
System.out.println(" java -Dtools=/path/to/tools.jar -jar struts.jar ...");
return;
}
// finally, add the verified tools.jar
urls.add(tools.toURL());
} catch (MalformedURLException e) {
e.printStackTrace();
System.out.println("Could not find URLs -- see stack trace.");
}
String command = args[0];
String[] programArgs = new String[args.length - 1];
System.arraycopy(args, 1, programArgs, 0, programArgs.length);
if (command.startsWith("quickstart:")) {
command = "quickstart";
String name = checkWebAppArgs(args);
programArgs = new String[]{"/" + name,
"apps/" + name + "/src/main/webapp",
"apps/" + name + "/src/main/java",
"apps/" + name + "/src/main/resources"};
}
if (command.startsWith("sitegraph:")) {
command = "sitegraph";
String name = checkWebAppArgs(args);
programArgs = new String[]{"-config", "apps/" + name + "/src/webapp/WEB-INF/classes",
"-views", "apps/" + name + "/src/webapp",
"-output", "."};
}
if ("sitegraph".equals(command)) {
launch("org.apache.struts2.sitegraph.SiteGraph", programArgs, urls);
}
}
private static String checkWebAppArgs(String[] args) {
int colon = args[0].indexOf(':');
String name = null;
try {
name = args[0].substring(colon + 1);
} catch (Exception e) {
//this is OK to skip
}
if (name == null || name.equals("")) {
System.out.println("Error: you must specify the webapp you wish");
System.out.println(" to deploy. The webapp name must be the");
System.out.println(" name of the directory found in apps/.");
System.out.println("");
System.out.println("Example: java -jar struts-core-VERSION.jar quickstart:sandbox");
System.exit(1);
}
return name;
}
private static void launch(String program, String[] programArgs, List<URL> urls) {
Collections.reverse(urls);
URL[] urlArray = urls.toArray(new URL[urls.size()]);
URLClassLoader cl = new MainClassLoader(urlArray);
Thread.currentThread().setContextClassLoader(cl);
try {
Class clazz = cl.loadClass(program);
Method main = clazz.getDeclaredMethod("main", new Class[]{String[].class});
main.invoke(null, new Object[]{programArgs});
} catch (Exception e) {
e.printStackTrace();
}
}
private static void findJars(File file, ArrayList<URL> urls) throws MalformedURLException {
File[] files = file.listFiles();
if (files == null) {
return;
}
for (int i = 0; i < files.length; i++) {
File f = files[i];
if (f.isDirectory()) {
findJars(f, urls);
} else if (f.getName().endsWith(".jar")) {
if (isValid(f.getName())) {
urls.add(f.toURL());
}
}
}
}
private static boolean isValid(String name) {
return !"dom.jar".equals(name);
}
/**
* Reverses the typical order of classloading to defer only to the parent if the current class loader can't be
* found. This is required to allow for the launcher to be embedded within struts.jar (otherwise the dependencies
* wouldn't be found by the system ClassLoader when invoking using "java -jar struts-core-VERSION.jar ...").
*/
public static class MainClassLoader extends URLClassLoader {
public MainClassLoader(URL[] urls) {
super(urls);
}
public Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException {
if (name.startsWith("org.xml.") || name.startsWith("org.w3c.")
|| name.startsWith("java.") || name.startsWith("javax.")
|| name.startsWith("sun.") || name.startsWith("com.sun.")) {
return super.loadClass(name, resolve);
}
ClassLoader parent = getParent();
// First, check if the class has already been loaded
Class c = findLoadedClass(name);
if (c == null) {
try {
c = findClass(name);
} catch (Throwable t) {
// If still not found, only then ask the parent
c = parent.loadClass(name);
}
}
if (resolve) {
resolveClass(c);
}
return c;
}
}
}
@@ -1,372 +0,0 @@
/*
* $Id$
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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 org.apache.struts2.quickstart;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.apache.commons.collections.MultiHashMap;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import com.thoughtworks.xstream.XStream;
/**
* Configuration for the QuickStart program.
*/
public class Configuration implements Serializable {
private static final long serialVersionUID = 9159115401614443449L;
String ideaConfig;
String extendsConfig;
String resolver;
Integer port;
String context;
List libs;
List classDirs;
List sources;
List webDirs;
Map mappings;
List pathPriority;
public String getIdeaConfig() {
return ideaConfig;
}
public void setIdeaConfig(String ideaConfig) {
this.ideaConfig = ideaConfig;
}
public String getExtendsConfig() {
return extendsConfig;
}
public void setExtendsConfig(String extendsConfig) {
this.extendsConfig = extendsConfig;
}
public String getResolver() {
return resolver;
}
public void setResolver(String resolver) {
this.resolver = resolver;
}
public List getLibs() {
return libs;
}
public void setLibs(List libs) {
this.libs = libs;
}
public List getClassDirs() {
return classDirs;
}
public void setClassDirs(List classDirs) {
this.classDirs = classDirs;
}
public List getSources() {
return sources;
}
public void setSources(List sources) {
this.sources = sources;
}
public Map getMappings() {
return mappings;
}
public List getPathPriority() {
return pathPriority;
}
public List getWebDirs() {
return webDirs;
}
public void setWebDirs(List webDirs) {
this.webDirs = webDirs;
}
public Integer getPort() {
return port;
}
public void setPort(Integer port) {
this.port = port;
}
public String getContext() {
return context;
}
public void setContext(String context) {
this.context = context;
}
public void resolveDirs(String wd) {
if (ideaConfig != null) {
String[] paths = ideaConfig.split(",");
for (String path : paths) {
String full = resolveDir(path, wd);
try {
DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document doc = db.parse(full);
NodeList components = doc.getElementsByTagName("root");
List jars = new ArrayList();
for (int i = 0; i < components.getLength(); i++) {
Element e = (Element) components.item(i);
String value = e.getAttribute("url");
if (value != null && value.startsWith("jar://") && value.endsWith(".jar!/")) {
value = value.substring(6, value.length() - 2);
if (value.startsWith("$MODULE_DIR$")) {
value = value.substring(13);
}
jars.add(value);
}
}
if (this.libs != null) {
this.libs.addAll(jars);
} else {
this.libs = jars;
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
resolve(this.libs, wd);
resolve(this.classDirs, wd);
resolve(this.sources, wd);
// now resolve the web dirs
for (Iterator iterator = webDirs.iterator(); iterator.hasNext();) {
Mapping mapping = (Mapping) iterator.next();
String path = mapping.getPath();
String dir = mapping.getDir();
dir = resolveDir(dir, wd);
// if the ${dir}/WEB-INF/classes dir exists and isn't already added to the classDirs, let's do it
// ... but make sure we put it at the front (to obey the class loading behaviors)
File classDir = new File(dir, "WEB-INF/classes");
if (classDir.exists()) {
String fullClassDir = getFullPath(classDir);
if (this.classDirs == null) {
this.classDirs = new ArrayList();
}
if (!classDirs.contains(fullClassDir)) {
classDirs.add(0, fullClassDir);
}
}
if (this.mappings == null) {
this.mappings = new MultiHashMap();
this.pathPriority = new ArrayList();
}
if (!this.pathPriority.contains(path)) {
this.pathPriority.add(path);
}
this.mappings.put(path, dir);
}
}
private void resolve(List list, String wd) {
if (list != null) {
for (int i = 0; i < list.size(); i++) {
String s = (String) list.get(i);
list.set(i, resolveDir(s, wd));
}
}
}
private String resolveDir(String dir, String wd) {
File file = new File(wd, dir);
if (!file.exists() && new File(dir).exists()) {
file = new File(dir);
}
return getFullPath(file);
}
private String getFullPath(File file) {
try {
return file.getCanonicalPath();
} catch (IOException e) {
return file.getAbsolutePath();
}
}
public void resolveExtensions(String wd, XStream xstream) throws FileNotFoundException {
if (extendsConfig != null) {
File config = new File(wd, extendsConfig);
Configuration c = (Configuration) xstream.fromXML(new FileReader(config));
c.resolveDirs(config.getParent());
c.resolveExtensions(config.getParent(), xstream);
// now copy over the props
if (c.getResolver() != null) {
this.resolver = c.getResolver();
}
if (port == null) {
this.port = c.getPort();
}
if (c.getContext() != null) {
this.context = c.getContext();
}
if (c.getLibs() != null) {
if (this.libs != null) {
this.libs.addAll(c.getLibs());
} else {
this.libs = c.getLibs();
}
}
if (c.getClassDirs() != null) {
if (this.classDirs != null) {
this.classDirs.addAll(c.getClassDirs());
} else {
this.classDirs = c.getClassDirs();
}
}
if (c.getSources() != null) {
if (this.sources != null) {
this.sources.addAll(c.getSources());
} else {
this.sources = c.getSources();
}
}
for (Iterator iterator = c.getMappings().entrySet().iterator(); iterator.hasNext();) {
Map.Entry entry = (Map.Entry) iterator.next();
List list = (List) this.mappings.get(entry.getKey());
if (list != null) {
list.addAll((List) entry.getValue());
} else {
this.mappings.put(entry.getKey(), (List) entry.getValue());
}
}
// add only new paths
for (Iterator iterator = c.getPathPriority().iterator(); iterator.hasNext();) {
String path = (String) iterator.next();
if (!this.pathPriority.contains(path)) {
this.pathPriority.add(path);
}
}
}
}
public boolean validate() {
boolean error = false;
if (port == null) {
System.out.println("Port must be greater than 0");
error = true;
}
if (!context.startsWith("/")) {
System.out.println("Context must start with /");
error = true;
}
if (verifyList("Library", libs, false)) {
error = true;
}
if (verifyList("ClassDir", classDirs, false)) {
error = true;
}
if (verifyList("Sources", sources, true)) {
error = true;
}
if (verifyMap("WebApp", mappings)) {
error = true;
}
return error;
}
private boolean verifyMap(String name, Map map) {
boolean error = false;
if (map == null || map.size() == 0) {
System.out.println(name + " must be specified");
return true;
}
for (Iterator iterator = map.entrySet().iterator(); iterator.hasNext();) {
Map.Entry entry = (Map.Entry) iterator.next();
List list = (List) entry.getValue();
verifyList(name, list, false);
}
return error;
}
private boolean verifyList(String name, List list, boolean allowEmpty) {
boolean error = false;
if (!allowEmpty) {
if (list == null || list.size() == 0) {
System.out.println(name + " must be specified");
return true;
}
}
if (list != null) {
for (Iterator iterator = list.iterator(); iterator.hasNext();) {
String s = (String) iterator.next();
if (!new File(s).exists()) {
System.out.println(name + " doesn't exist: " + s);
error = true;
}
}
}
return error;
}
}
@@ -1,68 +0,0 @@
/*
* $Id$
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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 org.apache.struts2.quickstart;
import java.io.File;
import java.util.List;
import java.util.Map;
import org.mortbay.http.SocketListener;
import org.mortbay.jetty.Server;
import org.mortbay.jetty.servlet.WebApplicationContext;
/**
* To start a Jetty server used by the QuickStart application.
*/
public class JettyServer {
/**
* The system property name used to specify a directory of webapps.
*/
public static final String WEBAPPS_DIR_PROPERTY = "webapps.dir";
public static void startServer(int port, String context, List pathPriority, Map paths, String resolver) throws Exception {
try {
Server server = new Server();
SocketListener socketListener = new SocketListener();
socketListener.setPort(port);
server.addListener(socketListener);
WebApplicationContext ctx;
if (resolver == null) {
ctx = new MultiWebApplicationContext(pathPriority, paths);
} else {
ctx = new MultiWebApplicationContext(pathPriority, paths, resolver);
}
ctx.setClassLoader(Thread.currentThread().getContextClassLoader());
ctx.setContextPath(context);
server.addContext(null, ctx);
// Add in extra webapps dir (see WW-1387)
String webappsDir = System.getProperty(WEBAPPS_DIR_PROPERTY);
if (webappsDir != null && new File(webappsDir).exists()) {
server.addWebApplications(webappsDir);
}
server.start();
} catch (Exception e) {
e.printStackTrace();
}
}
}
@@ -1,54 +0,0 @@
/*
* $Id$
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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 org.apache.struts2.quickstart;
/**
* Used for mapping configuration for the QuickStart application.
*
*/
public class Mapping {
String path;
String dir;
public Mapping(String path, String dir) {
this.path = path;
this.dir = dir;
}
public Mapping() {
}
public String getPath() {
return path;
}
public void setPath(String path) {
this.path = path;
}
public String getDir() {
return dir;
}
public void setDir(String dir) {
this.dir = dir;
}
}
@@ -1,99 +0,0 @@
/*
* $Id$
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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 org.apache.struts2.quickstart;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.ArrayList;
/**
* Integration with Jetty.
*
*/
public class MultiDirClassLoader extends URLClassLoader {
private ClassLoader parent;
public MultiDirClassLoader(String[] dirs, String[] cps, ClassLoader parent) throws MalformedURLException {
super(getAllURLs(dirs, cps), parent);
this.parent = parent;
}
public Class loadClass(String name) throws ClassNotFoundException {
Class aClass;
try {
aClass = parent.loadClass(name);
if (aClass != null) {
return aClass;
}
} catch (ClassNotFoundException e) {
// ok, keep trying
}
return super.loadClass(name);
}
public URL getResource(String name) {
URL url = findResource(name);
if (url == null && parent != null) {
url = parent.getResource(name);
}
return url;
}
private static URL[] getAllURLs(String[] dirs, String[] cps) throws MalformedURLException {
ArrayList urls = new ArrayList();
for (int i = 0; i < cps.length; i++) {
String cp = cps[i];
urls.add(new File(cp).toURL());
}
for (int i = 0; i < dirs.length; i++) {
String dir = dirs[i];
File file = new File(dir);
findJars(file, urls);
}
return (URL[]) urls.toArray(new URL[urls.size()]);
}
private static void findJars(File file, ArrayList fileList) throws MalformedURLException {
if (file.isDirectory()) {
File[] files = file.listFiles();
for (int i = 0; i < files.length; i++) {
File f = files[i];
findJars(f, fileList);
}
}
else if (file.getName().endsWith(".jar")) {
// Manually exclude the local license file so that it's possible to run
// clustering.
if (!file.getName().equals("tangosol-license-local.jar")) {
fileList.add(file.toURL());
}
}
}
}
@@ -1,214 +0,0 @@
/*
* $Id$
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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 org.apache.struts2.quickstart;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.mortbay.util.Resource;
/**
*/
public class MultiDirResource extends Resource {
private static final long serialVersionUID = -7571068340424106599L;
MultiWebApplicationContext ctx;
File[] files;
String uri;
public MultiDirResource(MultiWebApplicationContext ctx, String uri, List pathPriority, Map paths) {
this.ctx = ctx;
this.uri = uri;
ArrayList files = new ArrayList();
for (Iterator iterator = pathPriority.iterator(); iterator.hasNext();) {
String path = (String) iterator.next();
List dirs = (List) paths.get(path);
if (uri.startsWith(path) || (uri.equals("") && path.equals("/"))) {
for (Iterator iterator1 = dirs.iterator(); iterator1.hasNext();) {
String s = (String) iterator1.next();
if (uri.startsWith(path)) {
// cut off the path from the start of the URI
files.add(new File(s, uri.substring(path.length())));
} else {
files.add(new File(s, uri));
}
}
}
}
this.files = (File[]) files.toArray(new File[files.size()]);
}
public void release() {
}
public boolean exists() {
for (int i = 0; i < files.length; i++) {
File file = files[i];
if (file.exists()) {
return true;
}
}
return false;
}
public boolean isDirectory() {
for (int i = 0; i < files.length; i++) {
File file = files[i];
if (file.exists()) {
return file.isDirectory();
}
}
return false;
}
public long lastModified() {
for (int i = 0; i < files.length; i++) {
File file = files[i];
if (file.exists()) {
return file.lastModified();
}
}
return 0;
}
public long length() {
for (int i = 0; i < files.length; i++) {
File file = files[i];
if (file.exists()) {
return file.length();
}
}
return 0;
}
public URL getURL() {
for (int i = 0; i < files.length; i++) {
File file = files[i];
if (file.exists()) {
try {
return file.toURL();
} catch (MalformedURLException e) {
e.printStackTrace();
}
}
}
return null;
}
public File getFile() throws IOException {
for (int i = 0; i < files.length; i++) {
File file = files[i];
if (file.exists()) {
return file;
}
}
return null;
}
public String getName() {
for (int i = 0; i < files.length; i++) {
File file = files[i];
if (file.exists()) {
return file.getName();
}
}
return null;
}
public InputStream getInputStream() throws IOException {
for (int i = 0; i < files.length; i++) {
File file = files[i];
if (file.exists()) {
return new FileInputStream(file);
}
}
return null;
}
public OutputStream getOutputStream() throws IOException, SecurityException {
for (int i = 0; i < files.length; i++) {
File file = files[i];
if (file.exists()) {
return new FileOutputStream(file);
}
}
return null;
}
public boolean delete() throws SecurityException {
for (int i = 0; i < files.length; i++) {
File file = files[i];
if (file.exists()) {
return file.delete();
}
}
return false;
}
public boolean renameTo(Resource resource) throws SecurityException {
return false;
}
public String[] list() {
HashSet set = new HashSet();
for (int i = 0; i < files.length; i++) {
File file = files[i];
if (file.exists()) {
String[] files = file.list();
for (int j = 0; j < files.length; j++) {
String s = files[j];
set.add(s);
}
}
}
return (String[]) set.toArray(new String[set.size()]);
}
public Resource addPath(String string) throws IOException, MalformedURLException {
return ctx.newResolver(uri + string);
}
}
@@ -1,161 +0,0 @@
/*
* $Id$
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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 org.apache.struts2.quickstart;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.Constructor;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.List;
import java.util.Map;
import org.mortbay.jetty.servlet.WebApplicationContext;
import org.mortbay.util.FileResource;
import org.mortbay.util.JarResource;
import org.mortbay.util.Resource;
/**
*/
public class MultiWebApplicationContext extends WebApplicationContext {
private static final long serialVersionUID = -4732081314967099271L;
private List pathPriority;
private Map paths;
private Class resolver;
public MultiWebApplicationContext() {
}
public MultiWebApplicationContext(List pathPriority, Map paths) {
super(getFirstRoot(paths));
this.pathPriority = pathPriority;
this.paths = paths;
}
public MultiWebApplicationContext(List pathPriority, Map paths, String resolver) {
super(getFirstRoot(paths));
this.pathPriority = pathPriority;
this.paths = paths;
try {
this.resolver = loadClass(resolver, getClass());
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
private static String getFirstRoot(Map paths) {
return (String) ((List) paths.get("/")).get(0);
}
public Resource getResource(String uriInContext) throws IOException {
if (uriInContext.startsWith("/WEB-INF/lib/")) {
String jar = uriInContext.substring("/WEB-INF/lib/".length());
ClassLoader parent = Thread.currentThread().getContextClassLoader();
while (parent != null) {
if (parent instanceof URLClassLoader) {
URL[] urls = ((URLClassLoader) parent).getURLs();
for (int i = 0; i < urls.length; i++) {
URL url = urls[i];
if (url.toExternalForm().endsWith(jar)) {
return JarResource.newResource(url);
}
}
}
parent = parent.getParent();
}
}
// still haven't found what we're looking for?
// Alright, let's just hack this to work in IDEA
if (uriInContext.equals("/tags")) {
// we do this check to support both "quickstart:showcase" and "quickstart" (using quickstart.xml)
if (new File("../../core/src/main/resources/META-INF/tags.tld").exists()) {
return FileResource.newResource("../../core/src/main/resources/META-INF/tags.tld");
} else {
return FileResource.newResource("src/main/resources/META-INF/tags.tld");
}
}
MultiDirResource resource = newResolver(uriInContext);
if (resource.exists()) {
return resource;
}
String aliasedUri= getResourceAlias(uriInContext);
if (aliasedUri != null) {
return super.getResource(aliasedUri);
}
return resource;
}
public MultiDirResource newResolver(String uriInContext) {
if (resolver == null) {
return new MultiDirResource(this, uriInContext, pathPriority, paths);
} else {
try {
Constructor c = resolver.getDeclaredConstructor(new Class[]{
MultiWebApplicationContext.class,
String.class,
List.class,
Map.class,
});
return (MultiDirResource) c.newInstance(new Object[] {
this,
uriInContext,
pathPriority,
paths,
});
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
}
public Resource getBaseResource() {
return newResolver("");
}
public static Class loadClass(String className, Class callingClass)
throws ClassNotFoundException {
try {
return Thread.currentThread().getContextClassLoader().loadClass(className);
}
catch (ClassNotFoundException e) {
try {
return Class.forName(className);
}
catch (ClassNotFoundException ex) {
try {
return MultiWebApplicationContext.class.getClassLoader().loadClass(className);
}
catch (ClassNotFoundException exc) {
return callingClass.getClassLoader().loadClass(className);
}
}
}
}
}
@@ -1,203 +0,0 @@
/*
* $Id$
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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 org.apache.struts2.quickstart;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
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.Map;
import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.xml.DomDriver;
/**
* The QuickStart main program.
*
*/
public class QuickStart {
public static void main(String[] args) throws FileNotFoundException, MalformedURLException, ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException {
if (args.length != 3 && args.length != 0) {
System.err.println("QuickStart must be either invoked with three arguments or no arguments:");
System.err.println("[contextPath] [webapp] [sources]");
System.err.println("");
System.err.println("Ex: java -jar struts.jar \\");
System.err.println(" quickstart /sandbox sandbox/src/webapp sandbox/src/java");
System.err.println("");
System.err.println("OR");
System.err.println("");
System.err.println("Ex: java -jar struts.jar quickstart");
System.err.println(" Where a 'quickstart.xml' file exists in your working directory");
return;
}
Configuration c;
if (args.length == 0) {
XStream xstream = new XStream(new DomDriver());
xstream.alias("configuration", Configuration.class);
xstream.alias("extendsConfig", String.class);
xstream.alias("port", int.class);
xstream.alias("context", String.class);
xstream.alias("dir", String.class);
xstream.alias("path", String.class);
xstream.alias("webDir", Mapping.class);
File config = new File("quickstart.xml");
if (!config.exists()) {
// uh oh, time to stop
System.err.println("Could not find quickstart.xml!");
System.err.println("Tip: quickstart.xml must exist in your working directory");
System.err.println("");
System.err.println("Alternatively, if you your deployment is simple, try launching");
System.err.println("QuickStart using the simple command line options rather than");
System.err.println("Relying on quickstart.xml existing");
return;
}
c = (Configuration) xstream.fromXML(new FileReader(config));
c.resolveDirs(config.getParent());
c.resolveExtensions(config.getParent(), xstream);
} else {
c = new Configuration();
c.setContext(args[0]);
c.setPort(new Integer(8080));
ArrayList webDirs = new ArrayList();
webDirs.add(new Mapping("/", args[1]));
c.setWebDirs(webDirs);
ArrayList sources = new ArrayList();
sources.add(args[2]);
c.setSources(sources);
ArrayList classDirs = new ArrayList();
classDirs.add(args[1] + "/WEB-INF/classes");
classDirs.add(args[2]);
c.setClassDirs(classDirs);
ArrayList libs = new ArrayList();
libs.add("lib");
c.setLibs(libs);
c.resolveDirs(new File(".").getParent());
}
// validate the configuration
if (c.validate()) {
return;
}
// explain what is being executed
System.out.println("Launching Jetty with the following configuration:");
System.out.println("Jars/Directory of jars:");
for (Iterator iterator = c.getLibs().iterator(); iterator.hasNext();) {
String s = (String) iterator.next();
System.out.println(" " + s);
}
System.out.println("Directories of classes:");
for (Iterator iterator = c.getClassDirs().iterator(); iterator.hasNext();) {
String s = (String) iterator.next();
System.out.println(" " + s);
}
if (c.getSources() != null) {
System.out.println("Sources:");
for (Iterator iterator = c.getSources().iterator(); iterator.hasNext();) {
String s = (String) iterator.next();
System.out.println(" " + s);
}
}
System.out.println("WebApp directories:");
for (Iterator iterator = c.getMappings().entrySet().iterator(); iterator.hasNext();) {
Map.Entry entry = (Map.Entry) iterator.next();
System.out.println(entry.getKey() + " -> " + entry.getValue());
}
// prepare the classloader
List libs = c.getLibs();
List classDirs = c.getClassDirs();
ClassLoader parent = new MultiDirClassLoader((String[]) libs.toArray(new String[libs.size()]),
(String[]) classDirs.toArray(new String[classDirs.size()]),
Thread.currentThread().getContextClassLoader());
if (c.getSources() != null) {
System.out.print("Automatic compiling of classes no longer supported.");
}
URLClassLoader url = new MyURLClassLoader(parent);
Thread.currentThread().setContextClassLoader(url);
Class clazz = url.loadClass("org.apache.struts2.quickstart.JettyServer");
Method method = clazz.getDeclaredMethod("startServer",
new Class[]{int.class, String.class, List.class, Map.class, String.class});
method.invoke(null, new Object[]{c.port, c.getContext(), c.getPathPriority(), c.getMappings(), c.getResolver()});
System.out.println("");
System.out.println("********************************************************");
System.out.println("Quick-started at http://localhost:" + c.getPort() + c.getContext());
System.out.println("You may now edit your Java classes and web files without");
System.out.println(" deploying or restarting.");
System.out.println("********************************************************");
}
static class MyURLClassLoader extends URLClassLoader {
private ClassLoader parent;
public MyURLClassLoader(ClassLoader parent) {
super(new URL[0], parent);
this.parent = parent;
}
public Class loadClass(String name, boolean resolve) throws ClassNotFoundException {
if (name.startsWith("org.xml.") || name.startsWith("org.w3c.")
|| name.startsWith("java.") || name.startsWith("javax.")
|| name.startsWith("sun.") || name.startsWith("com.sun.")) {
return super.loadClass(name, resolve);
}
ClassLoader parent = getParent();
// First, check if the class has already been loaded
Class c = findLoadedClass(name);
if (c == null) {
try {
c = findClass(name);
} catch (Throwable t) {
// If still not found, only then ask the parent
c = parent.loadClass(name);
}
}
if (resolve) {
resolveClass(c);
}
return c;
}
public URL getResource(String name) {
URL url = findResource(name);
if (url == null && parent != null) {
url = parent.getResource(name);
}
return url;
}
}
}