Remove jetty-ant (#9382)

This commit is contained in:
Jan Bartel 2023-02-16 13:48:29 +11:00 committed by GitHub
parent b0fa9e20cb
commit dd792b5607
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
88 changed files with 0 additions and 6433 deletions

View File

@ -1,90 +0,0 @@
<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">
<parent>
<groupId>org.eclipse.jetty.ee10</groupId>
<artifactId>jetty-ee10</artifactId>
<version>12.0.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>jetty-ee10-ant</artifactId>
<packaging>jar</packaging>
<name>EE10 :: Ant Plugin</name>
<properties>
<bundle-symbolic-name>${project.groupId}.ant</bundle-symbolic-name>
<jacoco.skip>true</jacoco.skip>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<instructions>
<Require-Capability>
osgi.extender; filter:="(osgi.extender=osgi.serviceloader.registrar)"
</Require-Capability>
<Provide-Capability>
osgi.serviceloader; osgi.serviceloader=org.eclipse.jetty.ee10.webapp.Configuration
</Provide-Capability>
</instructions>
</configuration>
</plugin>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-lib-deps</id>
<phase>process-test-resources</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<includeGroupIds>org.eclipse.jetty</includeGroupIds>
<excludeGroupIds>org.eclipse.jetty.websocket</excludeGroupIds>
<excludeArtifactIds>jetty-start</excludeArtifactIds>
<includeTypes>jar</includeTypes>
<outputDirectory>${project.build.directory}/test-lib</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.eclipse.jetty.toolchain</groupId>
<artifactId>jetty-test-helper</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.ant</groupId>
<artifactId>ant</artifactId>
</dependency>
<dependency>
<groupId>org.apache.ant</groupId>
<artifactId>ant-launcher</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.ee10</groupId>
<artifactId>jetty-ee10-plus</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.ee10</groupId>
<artifactId>jetty-ee10-webapp</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.ee10</groupId>
<artifactId>jetty-ee10-annotations</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-slf4j-impl</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>

View File

@ -1,81 +0,0 @@
//
// ========================================================================
// Copyright (c) 1995 Mort Bay Consulting Pty Ltd and others.
//
// This program and the accompanying materials are made available under the
// terms of the Eclipse Public License v. 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
// which is available at https://www.apache.org/licenses/LICENSE-2.0.
//
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
// ========================================================================
//
package org.eclipse.jetty.ee10.ant;
import java.io.File;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.ArrayList;
import java.util.List;
import org.apache.tools.ant.AntClassLoader;
import org.eclipse.jetty.ee10.webapp.Configuration;
import org.eclipse.jetty.ee10.webapp.MetaInfConfiguration;
import org.eclipse.jetty.ee10.webapp.WebAppContext;
public class AntMetaInfConfiguration extends MetaInfConfiguration
{
@Override
public Class<? extends Configuration> replaces()
{
return MetaInfConfiguration.class;
}
@Override
public void findAndFilterContainerPaths(WebAppContext context) throws Exception
{
// TODO Auto-generated method stub
super.findAndFilterContainerPaths(context);
}
@Override
protected List<URI> getAllContainerJars(final WebAppContext context) throws URISyntaxException
{
List<URI> uris = new ArrayList<>();
if (context.getClassLoader() != null)
{
ClassLoader loader = context.getClassLoader().getParent();
while (loader != null)
{
if (loader instanceof URLClassLoader)
{
URL[] urls = ((URLClassLoader)loader).getURLs();
if (urls != null)
for (URL url : urls)
{
uris.add(new URI(url.toString().replaceAll(" ", "%20")));
}
}
else if (loader instanceof AntClassLoader)
{
AntClassLoader antLoader = (AntClassLoader)loader;
String[] paths = antLoader.getClasspath().split(new String(new char[]{File.pathSeparatorChar}));
if (paths != null)
{
for (String p : paths)
{
File f = new File(p);
uris.add(f.toURI());
}
}
}
loader = loader.getParent();
}
}
return uris;
}
}

View File

@ -1,691 +0,0 @@
//
// ========================================================================
// Copyright (c) 1995-2012 Sabre Holdings and others.
// ------------------------------------------------------------------------
// This program and the accompanying materials are made available under the
// terms of the Eclipse Public License v. 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
// which is available at https://www.apache.org/licenses/LICENSE-2.0.
//
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
// ========================================================================
//
package org.eclipse.jetty.ee10.ant;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.net.URLClassLoader;
import java.security.CodeSource;
import java.security.PermissionCollection;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import java.util.jar.Manifest;
import jakarta.servlet.Servlet;
import org.apache.tools.ant.AntClassLoader;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.types.FileSet;
import org.eclipse.jetty.ee10.ant.types.Attribute;
import org.eclipse.jetty.ee10.ant.types.Attributes;
import org.eclipse.jetty.ee10.ant.types.FileMatchingConfiguration;
import org.eclipse.jetty.ee10.ant.utils.TaskLog;
import org.eclipse.jetty.ee10.plus.webapp.EnvConfiguration;
import org.eclipse.jetty.ee10.servlet.FilterHolder;
import org.eclipse.jetty.ee10.servlet.FilterMapping;
import org.eclipse.jetty.ee10.servlet.ServletHandler;
import org.eclipse.jetty.ee10.servlet.ServletHolder;
import org.eclipse.jetty.ee10.servlet.ServletMapping;
import org.eclipse.jetty.ee10.servlet.Source;
import org.eclipse.jetty.ee10.webapp.MetaInfConfiguration;
import org.eclipse.jetty.ee10.webapp.WebAppClassLoader;
import org.eclipse.jetty.ee10.webapp.WebAppContext;
import org.eclipse.jetty.util.resource.PathResource;
import org.eclipse.jetty.util.resource.Resource;
import org.eclipse.jetty.xml.XmlConfiguration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Extension of WebAppContext to allow configuration via Ant environment.
*/
public class AntWebAppContext extends WebAppContext
{
private static final Logger LOG = LoggerFactory.getLogger(WebAppContext.class);
public static final String DEFAULT_CONTAINER_INCLUDE_JAR_PATTERN =
".*/.*jsp-api-[^/]*\\.jar$|.*/.*jsp-[^/]*\\.jar$|.*/.*taglibs[^/]*\\.jar$|.*/.*jstl[^/]*\\.jar$|.*/.*jsf-impl-[^/]*\\.jar$|.*/.*javax.faces-[^/]*\\.jar$|.*/.*myfaces-impl-[^/]*\\.jar$";
/**
* Location of jetty-env.xml file.
*/
private File jettyEnvXml;
/**
* List of web application libraries.
*/
private List<FileSet> libraries = new ArrayList<>();
/**
* List of web application class directories.
*/
private List<FileSet> classes = new ArrayList<>();
/**
* context xml file to apply to the webapp
*/
private File contextXml;
/**
* List of extra scan targets for this web application.
*/
private FileSet scanTargets;
/**
* context attributes to set
**/
private Attributes attributes;
private Project project;
private List<File> scanFiles;
private FileMatchingConfiguration librariesConfiguration;
public static void dump(ClassLoader loader)
{
while (loader != null)
{
System.err.println(loader);
if (loader instanceof URLClassLoader)
{
URL[] urls = ((URLClassLoader)loader).getURLs();
if (urls != null)
{
for (URL u : urls)
{
System.err.println("\t" + u + "\n");
}
}
}
loader = loader.getParent();
}
}
/**
* AntURLClassLoader
*
* Adapt the AntClassLoader which is not a URLClassLoader - this is needed for
* jsp to be able to search the classpath.
*/
public static class AntURLClassLoader extends URLClassLoader
{
private AntClassLoader antLoader;
public AntURLClassLoader(AntClassLoader antLoader)
{
super(new URL[]{}, antLoader);
this.antLoader = antLoader;
}
@Override
public InputStream getResourceAsStream(String name)
{
return super.getResourceAsStream(name);
}
@Override
public void close() throws IOException
{
super.close();
}
@Override
protected void addURL(URL url)
{
super.addURL(url);
}
@Override
public URL[] getURLs()
{
Set<URL> urls = new HashSet<URL>();
//convert urls from antLoader
String[] paths = antLoader.getClasspath().split(new String(new char[]{File.pathSeparatorChar}));
if (paths != null)
{
for (String p : paths)
{
File f = new File(p);
try
{
urls.add(f.toURI().toURL());
}
catch (Exception e)
{
LOG.trace("IGNORED", e);
}
}
}
//add in any that may have been added to us as a URL directly
URL[] ourURLS = super.getURLs();
if (ourURLS != null)
{
for (URL u : ourURLS)
{
urls.add(u);
}
}
return urls.toArray(new URL[urls.size()]);
}
@Override
protected Class<?> findClass(String name) throws ClassNotFoundException
{
return super.findClass(name);
}
@Override
public URL findResource(String name)
{
return super.findResource(name);
}
@Override
public Enumeration<URL> findResources(String name) throws IOException
{
return super.findResources(name);
}
@Override
protected PermissionCollection getPermissions(CodeSource codesource)
{
return super.getPermissions(codesource);
}
@Override
public Class<?> loadClass(String name) throws ClassNotFoundException
{
return super.loadClass(name);
}
@Override
protected Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException
{
return super.loadClass(name, resolve);
}
@Override
protected Object getClassLoadingLock(String className)
{
return super.getClassLoadingLock(className);
}
@Override
public URL getResource(String name)
{
return super.getResource(name);
}
@Override
public Enumeration<URL> getResources(String name) throws IOException
{
return super.getResources(name);
}
@Override
protected Package definePackage(String name, Manifest man, URL url) throws IllegalArgumentException
{
return super.definePackage(name, man, url);
}
@Override
protected Package definePackage(String name, String specTitle, String specVersion, String specVendor, String implTitle, String implVersion,
String implVendor, URL sealBase) throws IllegalArgumentException
{
return super.definePackage(name, specTitle, specVersion, specVendor, implTitle, implVersion, implVendor, sealBase);
}
@Override
protected Package[] getPackages()
{
return super.getPackages();
}
@Override
protected String findLibrary(String libname)
{
return super.findLibrary(libname);
}
@Override
public void setDefaultAssertionStatus(boolean enabled)
{
super.setDefaultAssertionStatus(enabled);
}
@Override
public void setPackageAssertionStatus(String packageName, boolean enabled)
{
super.setPackageAssertionStatus(packageName, enabled);
}
@Override
public void setClassAssertionStatus(String className, boolean enabled)
{
super.setClassAssertionStatus(className, enabled);
}
@Override
public void clearAssertionStatus()
{
super.clearAssertionStatus();
}
}
/**
* AntServletHolder
*/
public static class AntServletHolder extends ServletHolder
{
public AntServletHolder()
{
super();
}
public AntServletHolder(Class<? extends Servlet> servlet)
{
super(servlet);
}
public AntServletHolder(Servlet servlet)
{
super(servlet);
}
public AntServletHolder(String name, Class<? extends Servlet> servlet)
{
super(name, servlet);
}
public AntServletHolder(String name, Servlet servlet)
{
super(name, servlet);
}
protected String getSystemClassPath(ClassLoader loader) throws Exception
{
StringBuilder classpath = new StringBuilder();
while (loader != null)
{
if (loader instanceof URLClassLoader)
{
URL[] urls = ((URLClassLoader)loader).getURLs();
if (urls != null)
{
for (int i = 0; i < urls.length; i++)
{
Resource resource = Resource.newResource(urls[i]);
File file = resource.getFile();
if (file != null && file.exists())
{
if (classpath.length() > 0)
classpath.append(File.pathSeparatorChar);
classpath.append(file.getAbsolutePath());
}
}
}
}
else if (loader instanceof AntClassLoader)
{
classpath.append(((AntClassLoader)loader).getClasspath());
}
loader = loader.getParent();
}
return classpath.toString();
}
}
/**
* AntServletHandler
*/
public static class AntServletHandler extends ServletHandler
{
@Override
public ServletHolder newServletHolder(Source source)
{
return new AntServletHolder();
}
}
/**
* Default constructor. Takes project as an argument
*
* @param project the project.
* @throws Exception if unable to create webapp context
*/
public AntWebAppContext(Project project) throws Exception
{
super();
this.project = project;
setAttribute(MetaInfConfiguration.CONTAINER_JAR_PATTERN, DEFAULT_CONTAINER_INCLUDE_JAR_PATTERN);
setParentLoaderPriority(true);
addConfiguration(new AntWebInfConfiguration(), new AntWebXmlConfiguration(), new AntMetaInfConfiguration());
}
/**
* Adds a new Ant's attributes tag object if it have not been created yet.
*
* @param atts the attributes
*/
public void addAttributes(Attributes atts)
{
if (this.attributes != null)
{
throw new BuildException("Only one <attributes> tag is allowed!");
}
this.attributes = atts;
}
public void addLib(FileSet lib)
{
libraries.add(lib);
}
public void addClasses(FileSet classes)
{
this.classes.add(classes);
}
@Override
protected ServletHandler newServletHandler()
{
return new AntServletHandler();
}
public void setJettyEnvXml(File jettyEnvXml)
{
this.jettyEnvXml = jettyEnvXml;
TaskLog.log("jetty-env.xml file: = " + (jettyEnvXml == null ? null : jettyEnvXml.getAbsolutePath()));
}
public File getJettyEnvXml()
{
return this.jettyEnvXml;
}
public List<File> getLibraries()
{
return librariesConfiguration.getBaseDirectories();
}
public void addScanTargets(FileSet scanTargets)
{
if (this.scanTargets != null)
{
throw new BuildException("Only one <scanTargets> tag is allowed!");
}
this.scanTargets = scanTargets;
}
public List<File> getScanTargetFiles()
{
if (this.scanTargets == null)
return null;
FileMatchingConfiguration configuration = new FileMatchingConfiguration();
configuration.addDirectoryScanner(scanTargets.getDirectoryScanner(project));
return configuration.getBaseDirectories();
}
public List<File> getScanFiles()
{
if (scanFiles == null)
scanFiles = initScanFiles();
return scanFiles;
}
public boolean isScanned(File file)
{
List<File> files = getScanFiles();
if (files == null || files.isEmpty())
return false;
return files.contains(file);
}
public List<File> initScanFiles()
{
List<File> scanList = new ArrayList<File>();
if (getDescriptor() != null)
{
try (Resource r = Resource.newResource(getDescriptor());)
{
scanList.add(r.getFile());
}
catch (IOException e)
{
throw new BuildException(e);
}
}
if (getJettyEnvXml() != null)
{
try (Resource r = Resource.newResource(getJettyEnvXml());)
{
scanList.add(r.getFile());
}
catch (IOException e)
{
throw new BuildException("Problem configuring scanner for jetty-env.xml", e);
}
}
if (getDefaultsDescriptor() != null)
{
try (Resource r = Resource.newResource(getDefaultsDescriptor());)
{
if (!WebAppContext.WEB_DEFAULTS_XML.equals(getDefaultsDescriptor()))
{
scanList.add(r.getFile());
}
}
catch (IOException e)
{
throw new BuildException("Problem configuring scanner for webdefaults.xml", e);
}
}
if (getOverrideDescriptor() != null)
{
try
{
Resource r = Resource.newResource(getOverrideDescriptor());
scanList.add(r.getFile());
}
catch (IOException e)
{
throw new BuildException("Problem configuring scanner for webdefaults.xml", e);
}
}
//add any extra classpath and libs
List<File> cpFiles = getClassPathFiles();
if (cpFiles != null)
scanList.addAll(cpFiles);
//any extra scan targets
List<File> scanFiles = (List<File>)getScanTargetFiles();
if (scanFiles != null)
scanList.addAll(scanFiles);
return scanList;
}
@Override
public void setWar(String path)
{
super.setWar(path);
try
{
Resource war = Resource.newResource(path);
if (war.exists() && war.isDirectory() && getDescriptor() == null)
{
Resource webXml = war.addPath("WEB-INF/web.xml");
setDescriptor(webXml.toString());
}
}
catch (IOException e)
{
throw new BuildException(e);
}
}
@Override
public void doStart()
{
try
{
TaskLog.logWithTimestamp("Starting web application " + this.getDescriptor());
if (jettyEnvXml != null && jettyEnvXml.exists())
getConfiguration(EnvConfiguration.class).setJettyEnvResource(new PathResource(jettyEnvXml));
ClassLoader parentLoader = this.getClass().getClassLoader();
if (parentLoader instanceof AntClassLoader)
parentLoader = new AntURLClassLoader((AntClassLoader)parentLoader);
setClassLoader(new WebAppClassLoader(parentLoader, this));
if (attributes != null && attributes.getAttributes() != null)
{
for (Attribute a : attributes.getAttributes())
{
setAttribute(a.getName(), a.getValue());
}
}
//apply a context xml file if one was supplied
if (contextXml != null)
{
XmlConfiguration xmlConfiguration = new XmlConfiguration(new PathResource(contextXml));
TaskLog.log("Applying context xml file " + contextXml);
xmlConfiguration.configure(this);
}
super.doStart();
}
catch (Exception e)
{
TaskLog.log(e.toString());
}
}
@Override
public void doStop()
{
try
{
scanFiles = null;
TaskLog.logWithTimestamp("Stopping web application " + this);
Thread.currentThread().sleep(500L);
super.doStop();
// remove all filters and servlets. They will be recreated
// either via application of a context xml file or web.xml or annotation or servlet api.
// Event listeners are reset in ContextHandler.doStop()
getServletHandler().setFilters(new FilterHolder[0]);
getServletHandler().setFilterMappings(new FilterMapping[0]);
getServletHandler().setServlets(new ServletHolder[0]);
getServletHandler().setServletMappings(new ServletMapping[0]);
}
catch (InterruptedException e)
{
TaskLog.log(e.toString());
}
catch (Exception e)
{
TaskLog.log(e.toString());
}
}
/**
* @return a list of classpath files (libraries and class directories).
*/
public List<File> getClassPathFiles()
{
List<File> classPathFiles = new ArrayList<File>();
Iterator<FileSet> classesIterator = classes.iterator();
while (classesIterator.hasNext())
{
FileSet clazz = classesIterator.next();
classPathFiles.add(clazz.getDirectoryScanner(project).getBasedir());
}
Iterator<FileSet> iterator = libraries.iterator();
while (iterator.hasNext())
{
FileSet library = iterator.next();
String[] includedFiles = library.getDirectoryScanner(project).getIncludedFiles();
File baseDir = library.getDirectoryScanner(project).getBasedir();
for (int i = 0; i < includedFiles.length; i++)
{
classPathFiles.add(new File(baseDir, includedFiles[i]));
}
}
return classPathFiles;
}
/**
* @return a <code>FileMatchingConfiguration</code> object describing the
* configuration of all libraries added to this particular web app
* (both classes and libraries).
*/
public FileMatchingConfiguration getLibrariesConfiguration()
{
FileMatchingConfiguration config = new FileMatchingConfiguration();
Iterator<FileSet> classesIterator = classes.iterator();
while (classesIterator.hasNext())
{
FileSet clazz = classesIterator.next();
config.addDirectoryScanner(clazz.getDirectoryScanner(project));
}
Iterator<FileSet> librariesIterator = libraries.iterator();
while (librariesIterator.hasNext())
{
FileSet library = librariesIterator.next();
config.addDirectoryScanner(library.getDirectoryScanner(project));
}
return config;
}
public File getContextXml()
{
return contextXml;
}
public void setContextXml(File contextXml)
{
this.contextXml = contextXml;
}
}

View File

@ -1,59 +0,0 @@
//
// ========================================================================
// Copyright (c) 1995 Mort Bay Consulting Pty Ltd and others.
//
// This program and the accompanying materials are made available under the
// terms of the Eclipse Public License v. 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
// which is available at https://www.apache.org/licenses/LICENSE-2.0.
//
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
// ========================================================================
//
package org.eclipse.jetty.ee10.ant;
import java.io.File;
import java.util.List;
import org.eclipse.jetty.ee10.webapp.Configuration;
import org.eclipse.jetty.ee10.webapp.WebAppClassLoader;
import org.eclipse.jetty.ee10.webapp.WebAppContext;
import org.eclipse.jetty.ee10.webapp.WebInfConfiguration;
import org.eclipse.jetty.ee10.webapp.WebXmlConfiguration;
public class AntWebInfConfiguration extends WebInfConfiguration
{
@Override
public Class<? extends Configuration> replaces()
{
return WebInfConfiguration.class;
}
/**
* Adds classpath files into web application classloader, and
* sets web.xml and base directory for the configured web application.
*
* @see WebXmlConfiguration#configure(WebAppContext)
*/
@Override
public void configure(WebAppContext context) throws Exception
{
if (context instanceof AntWebAppContext)
{
List<File> classPathFiles = ((AntWebAppContext)context).getClassPathFiles();
if (classPathFiles != null)
{
for (File cpFile : classPathFiles)
{
if (cpFile.exists())
{
((WebAppClassLoader)context.getClassLoader()).addClassPath(cpFile.getCanonicalPath());
}
}
}
}
super.configure(context);
}
}

View File

@ -1,64 +0,0 @@
//
// ========================================================================
// Copyright (c) 1995-2012 Sabre Holdings and others.
// ------------------------------------------------------------------------
// This program and the accompanying materials are made available under the
// terms of the Eclipse Public License v. 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
// which is available at https://www.apache.org/licenses/LICENSE-2.0.
//
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
// ========================================================================
//
package org.eclipse.jetty.ee10.ant;
import java.io.File;
import java.util.List;
import org.eclipse.jetty.ee10.webapp.Configuration;
import org.eclipse.jetty.ee10.webapp.WebXmlConfiguration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* This configuration object provides additional way to inject application
* properties into the configured web application. The list of classpath files,
* the application base directory and web.xml file could be specified in this
* way.
*/
public class AntWebXmlConfiguration extends WebXmlConfiguration
{
private static final Logger LOG = LoggerFactory.getLogger(WebXmlConfiguration.class);
/**
* List of classpath files.
*/
private List classPathFiles;
/**
* Web application root directory.
*/
private File webAppBaseDir;
public AntWebXmlConfiguration()
{
super();
}
@Override
public Class<? extends Configuration> replaces()
{
return WebXmlConfiguration.class;
}
public void setClassPathFiles(List classPathFiles)
{
this.classPathFiles = classPathFiles;
}
public void setWebAppBaseDir(File webAppBaseDir)
{
this.webAppBaseDir = webAppBaseDir;
}
}

View File

@ -1,310 +0,0 @@
//
// ========================================================================
// Copyright (c) 1995-2012 Sabre Holdings and others.
// ------------------------------------------------------------------------
// This program and the accompanying materials are made available under the
// terms of the Eclipse Public License v. 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
// which is available at https://www.apache.org/licenses/LICENSE-2.0.
//
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
// ========================================================================
//
package org.eclipse.jetty.ee10.ant;
import java.io.File;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Task;
import org.apache.tools.ant.taskdefs.Property;
import org.eclipse.jetty.ee10.ant.types.Connector;
import org.eclipse.jetty.ee10.ant.types.Connectors;
import org.eclipse.jetty.ee10.ant.types.ContextHandlers;
import org.eclipse.jetty.ee10.ant.types.LoginServices;
import org.eclipse.jetty.ee10.ant.types.SystemProperties;
import org.eclipse.jetty.ee10.ant.utils.TaskLog;
import org.eclipse.jetty.ee10.servlet.security.LoginService;
import org.eclipse.jetty.ee10.webapp.WebAppContext;
import org.eclipse.jetty.server.RequestLog;
/**
* Ant task for running a Jetty server.
*/
public class JettyRunTask extends Task
{
private int scanIntervalSeconds;
/**
* Temporary files directory.
*/
private File tempDirectory;
/**
* List of web applications to be deployed.
*/
private List<AntWebAppContext> webapps = new ArrayList<>();
/**
* Location of jetty.xml file.
*/
private File jettyXml;
/**
* List of server connectors.
*/
private Connectors connectors = null;
/**
* Server request logger object.
*/
private RequestLog requestLog;
/**
* List of login services.
*/
private LoginServices loginServices;
/**
* List of system properties to be set.
*/
private SystemProperties systemProperties;
/**
* List of other contexts to deploy
*/
private ContextHandlers contextHandlers;
/**
* Port Jetty will use for the default connector
*/
private int jettyPort = 8080;
private int stopPort;
private String stopKey;
private boolean daemon;
public JettyRunTask()
{
TaskLog.setTask(this);
}
/**
* Creates a new <code>WebApp</code> Ant object.
*
* @param webapp the webapp context
*/
public void addWebApp(AntWebAppContext webapp)
{
webapps.add(webapp);
}
/**
* Adds a new Ant's connector tag object if it have not been created yet.
*
* @param connectors the connectors
*/
public void addConnectors(Connectors connectors)
{
if (this.connectors != null)
throw new BuildException("Only one <connectors> tag is allowed!");
this.connectors = connectors;
}
public void addLoginServices(LoginServices services)
{
if (this.loginServices != null)
throw new BuildException("Only one <loginServices> tag is allowed!");
this.loginServices = services;
}
public void addSystemProperties(SystemProperties systemProperties)
{
if (this.systemProperties != null)
throw new BuildException("Only one <systemProperties> tag is allowed!");
this.systemProperties = systemProperties;
}
public void addContextHandlers(ContextHandlers handlers)
{
if (this.contextHandlers != null)
throw new BuildException("Only one <contextHandlers> tag is allowed!");
this.contextHandlers = handlers;
}
public File getTempDirectory()
{
return tempDirectory;
}
public void setTempDirectory(File tempDirectory)
{
this.tempDirectory = tempDirectory;
}
public File getJettyXml()
{
return jettyXml;
}
public void setJettyXml(File jettyXml)
{
this.jettyXml = jettyXml;
}
public void setRequestLog(String className)
{
try
{
this.requestLog = (RequestLog)Class.forName(className).getDeclaredConstructor().newInstance();
}
catch (ClassNotFoundException e)
{
throw new BuildException("Unknown request logger class: " + className);
}
catch (Exception e)
{
throw new BuildException("Request logger instantiation exception: " + e);
}
}
public String getRequestLog()
{
if (requestLog != null)
{
return requestLog.getClass().getName();
}
return "";
}
/**
* Sets the port Jetty uses for the default connector.
*
* @param jettyPort The port Jetty will use for the default connector
*/
public void setJettyPort(final int jettyPort)
{
this.jettyPort = jettyPort;
}
/**
* Executes this Ant task. The build flow is being stopped until Jetty
* server stops.
*
* @throws BuildException if unable to build
*/
@Override
public void execute() throws BuildException
{
TaskLog.log("Configuring Jetty for project: " + getProject().getName());
setSystemProperties();
List<Connector> connectorsList = null;
if (connectors != null)
connectorsList = connectors.getConnectors();
else
connectorsList = new Connectors(jettyPort, 30000).getDefaultConnectors();
List<LoginService> loginServicesList = (loginServices != null ? loginServices.getLoginServices() : new ArrayList<LoginService>());
ServerProxyImpl server = new ServerProxyImpl();
server.setConnectors(connectorsList);
server.setLoginServices(loginServicesList);
server.setRequestLog(requestLog);
server.setJettyXml(jettyXml);
server.setDaemon(daemon);
server.setStopPort(stopPort);
server.setStopKey(stopKey);
server.setContextHandlers(contextHandlers);
server.setTempDirectory(tempDirectory);
server.setScanIntervalSecs(scanIntervalSeconds);
try
{
for (WebAppContext webapp : webapps)
{
server.addWebApplication((AntWebAppContext)webapp);
}
}
catch (Exception e)
{
throw new BuildException(e);
}
server.start();
}
public int getStopPort()
{
return stopPort;
}
public void setStopPort(int stopPort)
{
this.stopPort = stopPort;
TaskLog.log("stopPort=" + stopPort);
}
public String getStopKey()
{
return stopKey;
}
public void setStopKey(String stopKey)
{
this.stopKey = stopKey;
TaskLog.log("stopKey=" + stopKey);
}
/**
* @return the daemon
*/
public boolean isDaemon()
{
return daemon;
}
/**
* @param daemon the daemon to set
*/
public void setDaemon(boolean daemon)
{
this.daemon = daemon;
TaskLog.log("Daemon=" + daemon);
}
public int getScanIntervalSeconds()
{
return scanIntervalSeconds;
}
public void setScanIntervalSeconds(int secs)
{
scanIntervalSeconds = secs;
TaskLog.log("scanIntervalSecs=" + secs);
}
/**
* Sets the system properties.
*/
private void setSystemProperties()
{
if (systemProperties != null)
{
Iterator propertiesIterator = systemProperties.getSystemProperties().iterator();
while (propertiesIterator.hasNext())
{
Property property = ((Property)propertiesIterator.next());
SystemProperties.setIfNotSetAlready(property);
}
}
}
}

View File

@ -1,114 +0,0 @@
//
// ========================================================================
// Copyright (c) 1995 Mort Bay Consulting Pty Ltd and others.
//
// This program and the accompanying materials are made available under the
// terms of the Eclipse Public License v. 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
// which is available at https://www.apache.org/licenses/LICENSE-2.0.
//
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
// ========================================================================
//
package org.eclipse.jetty.ee10.ant;
import java.io.InputStreamReader;
import java.io.LineNumberReader;
import java.io.OutputStream;
import java.net.ConnectException;
import java.net.InetAddress;
import java.net.Socket;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Task;
import org.eclipse.jetty.ee10.ant.utils.TaskLog;
/**
* JettyStopTask
*/
public class JettyStopTask extends Task
{
private int stopPort;
private String stopKey;
private int stopWait;
/**
*
*/
public JettyStopTask()
{
TaskLog.setTask(this);
}
@Override
public void execute() throws BuildException
{
try
{
Socket s = new Socket(InetAddress.getByName("127.0.0.1"), stopPort);
if (stopWait > 0)
s.setSoTimeout(stopWait * 1000);
try
{
OutputStream out = s.getOutputStream();
out.write((stopKey + "\r\nstop\r\n").getBytes());
out.flush();
if (stopWait > 0)
{
TaskLog.log("Waiting" + (stopWait > 0 ? (" " + stopWait + "sec") : "") + " for jetty to stop");
LineNumberReader lin = new LineNumberReader(new InputStreamReader(s.getInputStream()));
String response = lin.readLine();
if ("Stopped".equals(response))
System.err.println("Stopped");
}
}
finally
{
s.close();
}
}
catch (ConnectException e)
{
TaskLog.log("Jetty not running!");
}
catch (Exception e)
{
TaskLog.log(e.getMessage());
}
}
public int getStopPort()
{
return stopPort;
}
public void setStopPort(int stopPort)
{
this.stopPort = stopPort;
}
public String getStopKey()
{
return stopKey;
}
public void setStopKey(String stopKey)
{
this.stopKey = stopKey;
}
public int getStopWait()
{
return stopWait;
}
public void setStopWait(int stopWait)
{
this.stopWait = stopWait;
}
}

View File

@ -1,491 +0,0 @@
//
// ========================================================================
// Copyright (c) 1995-2012 Sabre Holdings and others.
// ------------------------------------------------------------------------
// This program and the accompanying materials are made available under the
// terms of the Eclipse Public License v. 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
// which is available at https://www.apache.org/licenses/LICENSE-2.0.
//
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
// ========================================================================
//
package org.eclipse.jetty.ee10.ant;
import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import org.eclipse.jetty.ee10.ant.types.Connector;
import org.eclipse.jetty.ee10.ant.types.ContextHandlers;
import org.eclipse.jetty.ee10.ant.utils.ServerProxy;
import org.eclipse.jetty.ee10.ant.utils.TaskLog;
import org.eclipse.jetty.ee10.servlet.security.LoginService;
import org.eclipse.jetty.server.Handler;
import org.eclipse.jetty.server.RequestLog;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.ServerConnector;
import org.eclipse.jetty.server.ShutdownMonitor;
import org.eclipse.jetty.server.handler.ContextHandler;
import org.eclipse.jetty.server.handler.ContextHandlerCollection;
import org.eclipse.jetty.server.handler.DefaultHandler;
import org.eclipse.jetty.util.Scanner;
import org.eclipse.jetty.util.resource.PathResource;
import org.eclipse.jetty.util.resource.Resource;
import org.eclipse.jetty.xml.XmlConfiguration;
import org.xml.sax.SAXException;
/**
* A proxy class for interaction with Jetty server object. Used to have some
* level of abstraction over standard Jetty classes.
*/
public class ServerProxyImpl implements ServerProxy
{
/**
* Proxied Jetty server object.
*/
private Server server;
/**
* Temporary files directory.
*/
private File tempDirectory;
/**
* Collection of context handlers (web application contexts).
*/
private ContextHandlerCollection contexts;
/**
* Location of jetty.xml file.
*/
private File jettyXml;
/**
* List of connectors.
*/
private List<Connector> connectors;
/**
* Request logger.
*/
private RequestLog requestLog;
/**
* User realms.
*/
private List<LoginService> loginServices;
/**
* List of added web applications.
*/
private List<AntWebAppContext> webApplications = new ArrayList<AntWebAppContext>();
/**
* other contexts to deploy
*/
private ContextHandlers contextHandlers;
/**
* scan interval for changed files
*/
private int scanIntervalSecs;
/**
* port to listen for stop command
*/
private int stopPort;
/**
* security key for stop command
*/
private String stopKey;
/**
* wait for all jetty threads to exit or continue
*/
private boolean daemon;
private boolean configured = false;
/**
* WebAppScannerListener
*
* Handle notifications that files we are interested in have changed
* during execution.
*/
public static class WebAppScannerListener implements Scanner.BulkListener
{
AntWebAppContext awc;
public WebAppScannerListener(AntWebAppContext awc)
{
this.awc = awc;
}
@Override
public void filesChanged(Set<String> changedFileNames)
{
boolean isScanned = false;
try
{
Iterator<String> itor = changedFileNames.iterator();
while (!isScanned && itor.hasNext())
{
isScanned = awc.isScanned(Resource.newResource(itor.next()).getFile());
}
if (isScanned)
{
awc.stop();
awc.start();
}
}
catch (Exception e)
{
TaskLog.log(e.getMessage());
}
}
}
/**
* Default constructor. Creates a new Jetty server with a standard connector
* listening on a given port.
*/
public ServerProxyImpl()
{
server = new Server();
server.setStopAtShutdown(true);
}
@Override
public void addWebApplication(AntWebAppContext webApp)
{
webApplications.add(webApp);
}
public int getStopPort()
{
return stopPort;
}
public void setStopPort(int stopPort)
{
this.stopPort = stopPort;
}
public String getStopKey()
{
return stopKey;
}
public void setStopKey(String stopKey)
{
this.stopKey = stopKey;
}
public File getJettyXml()
{
return jettyXml;
}
public void setJettyXml(File jettyXml)
{
this.jettyXml = jettyXml;
}
public List<Connector> getConnectors()
{
return connectors;
}
public void setConnectors(List<Connector> connectors)
{
this.connectors = connectors;
}
public RequestLog getRequestLog()
{
return requestLog;
}
public void setRequestLog(RequestLog requestLog)
{
this.requestLog = requestLog;
}
public List<LoginService> getLoginServices()
{
return loginServices;
}
public void setLoginServices(List<LoginService> loginServices)
{
this.loginServices = loginServices;
}
public List<AntWebAppContext> getWebApplications()
{
return webApplications;
}
public void setWebApplications(List<AntWebAppContext> webApplications)
{
this.webApplications = webApplications;
}
public File getTempDirectory()
{
return tempDirectory;
}
public void setTempDirectory(File tempDirectory)
{
this.tempDirectory = tempDirectory;
}
@Override
public void start()
{
try
{
configure();
configureWebApps();
server.start();
System.setProperty("jetty.ant.server.port", "" + ((ServerConnector)server.getConnectors()[0]).getLocalPort());
String host = ((ServerConnector)server.getConnectors()[0]).getHost();
if (host == null)
{
System.setProperty("jetty.ant.server.host", "localhost");
}
else
{
System.setProperty("jetty.ant.server.host", host);
}
startScanners();
TaskLog.log("Jetty AntTask Started");
if (!daemon)
server.join();
}
catch (InterruptedException e)
{
new RuntimeException(e);
}
catch (Exception e)
{
e.printStackTrace();
new RuntimeException(e);
}
}
@Override
public Object getProxiedObject()
{
return server;
}
/**
* @return the daemon
*/
public boolean isDaemon()
{
return daemon;
}
/**
* @param daemon the daemon to set
*/
public void setDaemon(boolean daemon)
{
this.daemon = daemon;
}
/**
* @return the contextHandlers
*/
public ContextHandlers getContextHandlers()
{
return contextHandlers;
}
/**
* @param contextHandlers the contextHandlers to set
*/
public void setContextHandlers(ContextHandlers contextHandlers)
{
this.contextHandlers = contextHandlers;
}
public int getScanIntervalSecs()
{
return scanIntervalSecs;
}
public void setScanIntervalSecs(int scanIntervalSecs)
{
this.scanIntervalSecs = scanIntervalSecs;
}
/**
* Configures Jetty server before adding any web applications to it.
*/
private void configure()
{
if (configured)
return;
configured = true;
if (stopPort > 0 && stopKey != null)
{
ShutdownMonitor monitor = ShutdownMonitor.getInstance();
monitor.setPort(stopPort);
monitor.setKey(stopKey);
monitor.setExitVm(false);
}
if (tempDirectory != null && !tempDirectory.exists())
tempDirectory.mkdirs();
// Applies external configuration via jetty.xml
applyJettyXml();
// Configures connectors for this server instance.
if (connectors != null)
{
for (Connector c : connectors)
{
ServerConnector jc = new ServerConnector(server);
jc.setPort(c.getPort());
jc.setIdleTimeout(c.getMaxIdleTime());
server.addConnector(jc);
}
}
// Configures login services
if (loginServices != null)
{
for (LoginService ls : loginServices)
{
server.addBean(ls);
}
}
// Does not cache resources, to prevent Windows from locking files
Resource.setDefaultUseCaches(false);
// Set default server handlers
configureHandlers();
}
/**
*
*/
private void configureHandlers()
{
if (requestLog != null)
server.setRequestLog(requestLog);
contexts = server.getDescendant(ContextHandlerCollection.class);
if (contexts == null)
{
contexts = new ContextHandlerCollection();
Handler.Collection handlers = server.getDescendant(Handler.Collection.class);
if (handlers == null)
server.setHandler(new Handler.Collection(contexts, new DefaultHandler()));
else
handlers.addHandler(contexts);
}
//if there are any extra contexts to deploy
if (contextHandlers != null && contextHandlers.getContextHandlers() != null)
{
for (ContextHandler c : contextHandlers.getContextHandlers())
{
contexts.addHandler(c);
}
}
}
/**
* Applies jetty.xml configuration to the Jetty server instance.
*/
private void applyJettyXml()
{
if (jettyXml != null && jettyXml.exists())
{
TaskLog.log("Configuring jetty from xml configuration file = " + jettyXml.getAbsolutePath());
XmlConfiguration configuration;
try
{
configuration = new XmlConfiguration(new PathResource(jettyXml));
configuration.configure(server);
}
catch (MalformedURLException e)
{
throw new RuntimeException(e);
}
catch (SAXException e)
{
throw new RuntimeException(e);
}
catch (IOException e)
{
throw new RuntimeException(e);
}
catch (Exception e)
{
throw new RuntimeException(e);
}
}
}
/**
* Starts web applications' scanners.
*/
private void startScanners() throws Exception
{
for (AntWebAppContext awc : webApplications)
{
if (scanIntervalSecs <= 0)
return;
TaskLog.log("Web application '" + awc + "': starting scanner at interval of " + scanIntervalSecs + " seconds.");
Scanner.Listener changeListener = new WebAppScannerListener(awc);
Scanner scanner = new Scanner();
scanner.setScanInterval(scanIntervalSecs);
scanner.addListener(changeListener);
scanner.setScanDirs(awc.getScanFiles());
scanner.setReportExistingFilesOnStartup(false);
scanner.start();
}
}
/**
*
*/
private void configureWebApps()
{
for (AntWebAppContext awc : webApplications)
{
awc.setAttribute(AntWebAppContext.BASETEMPDIR, tempDirectory);
if (contexts != null)
contexts.addHandler(awc);
}
}
}

View File

@ -1,18 +0,0 @@
//
// ========================================================================
// Copyright (c) 1995 Mort Bay Consulting Pty Ltd and others.
//
// This program and the accompanying materials are made available under the
// terms of the Eclipse Public License v. 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
// which is available at https://www.apache.org/licenses/LICENSE-2.0.
//
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
// ========================================================================
//
/**
* Jetty Ant : Ant Tasks and Configuration
*/
package org.eclipse.jetty.ee10.ant;

View File

@ -1,42 +0,0 @@
//
// ========================================================================
// Copyright (c) 1995 Mort Bay Consulting Pty Ltd and others.
//
// This program and the accompanying materials are made available under the
// terms of the Eclipse Public License v. 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
// which is available at https://www.apache.org/licenses/LICENSE-2.0.
//
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
// ========================================================================
//
package org.eclipse.jetty.ee10.ant.types;
public class Attribute
{
String name;
String value;
public void setName(String name)
{
this.name = name;
}
public void setValue(String value)
{
this.value = value;
}
public String getName()
{
return name;
}
public String getValue()
{
return value;
}
}

View File

@ -1,33 +0,0 @@
//
// ========================================================================
// Copyright (c) 1995 Mort Bay Consulting Pty Ltd and others.
//
// This program and the accompanying materials are made available under the
// terms of the Eclipse Public License v. 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
// which is available at https://www.apache.org/licenses/LICENSE-2.0.
//
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
// ========================================================================
//
package org.eclipse.jetty.ee10.ant.types;
import java.util.ArrayList;
import java.util.List;
public class Attributes
{
List<Attribute> _attributes = new ArrayList<Attribute>();
public void addAttribute(Attribute attr)
{
_attributes.add(attr);
}
public List<Attribute> getAttributes()
{
return _attributes;
}
}

View File

@ -1,54 +0,0 @@
//
// ========================================================================
// Copyright (c) 1995 Mort Bay Consulting Pty Ltd and others.
//
// This program and the accompanying materials are made available under the
// terms of the Eclipse Public License v. 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
// which is available at https://www.apache.org/licenses/LICENSE-2.0.
//
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
// ========================================================================
//
package org.eclipse.jetty.ee10.ant.types;
/**
* Connector
*/
public class Connector
{
private int port;
private int maxIdleTime;
public Connector()
{
}
public Connector(int port, int maxIdleTime)
{
this.port = port;
this.maxIdleTime = maxIdleTime;
}
public int getPort()
{
return port;
}
public void setPort(int port)
{
this.port = port;
}
public int getMaxIdleTime()
{
return maxIdleTime;
}
public void setMaxIdleTime(int maxIdleTime)
{
this.maxIdleTime = maxIdleTime;
}
}

View File

@ -1,76 +0,0 @@
//
// ========================================================================
// Copyright (c) 1995-2012 Sabre Holdings and others.
// ------------------------------------------------------------------------
// This program and the accompanying materials are made available under the
// terms of the Eclipse Public License v. 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
// which is available at https://www.apache.org/licenses/LICENSE-2.0.
//
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
// ========================================================================
//
package org.eclipse.jetty.ee10.ant.types;
import java.util.ArrayList;
import java.util.List;
/**
* Specifies a jetty configuration <code>&lt;connectors/&gt;</code> element for Ant build file.
*/
public class Connectors
{
private List<Connector> connectors = new ArrayList<Connector>();
private List<Connector> defaultConnectors = new ArrayList<Connector>();
/**
* Default constructor.
*/
public Connectors()
{
this(8080, 30000);
}
/**
* Constructor.
*
* @param port The port that the default connector will listen on
* @param maxIdleTime The maximum idle time for the default connector
*/
public Connectors(int port, int maxIdleTime)
{
defaultConnectors.add(new Connector(port, maxIdleTime));
}
/**
* Adds a connector to the list of connectors to deploy.
*
* @param connector A connector to add to the list
*/
public void add(Connector connector)
{
connectors.add(connector);
}
/**
* Returns the list of known connectors to deploy.
*
* @return The list of known connectors
*/
public List<Connector> getConnectors()
{
return connectors;
}
/**
* Gets the default list of connectors to deploy when no connectors
* were explicitly added to the list.
*
* @return The list of default connectors
*/
public List<Connector> getDefaultConnectors()
{
return defaultConnectors;
}
}

View File

@ -1,37 +0,0 @@
//
// ========================================================================
// Copyright (c) 1995-2012 Sabre Holdings and others.
// ------------------------------------------------------------------------
// This program and the accompanying materials are made available under the
// terms of the Eclipse Public License v. 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
// which is available at https://www.apache.org/licenses/LICENSE-2.0.
//
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
// ========================================================================
//
package org.eclipse.jetty.ee10.ant.types;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.jetty.server.handler.ContextHandler;
/**
* Specifies <code>&lt;contextHandlers/&gt;</code> element in web app configuration.
*/
public class ContextHandlers
{
private List<ContextHandler> contextHandlers = new ArrayList<ContextHandler>();
public void add(ContextHandler handler)
{
contextHandlers.add(handler);
}
public List<ContextHandler> getContextHandlers()
{
return contextHandlers;
}
}

View File

@ -1,91 +0,0 @@
//
// ========================================================================
// Copyright (c) 1995-2012 Sabre Holdings and others.
// ------------------------------------------------------------------------
// This program and the accompanying materials are made available under the
// terms of the Eclipse Public License v. 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
// which is available at https://www.apache.org/licenses/LICENSE-2.0.
//
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
// ========================================================================
//
package org.eclipse.jetty.ee10.ant.types;
import java.io.File;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.apache.tools.ant.DirectoryScanner;
/**
* Describes set of files matched by <code>&lt;fileset/&gt;</code> elements in ant configuration
* file. It is used to group application classes, libraries, and scannedTargets
* elements.
*/
public class FileMatchingConfiguration
{
private List<DirectoryScanner> directoryScanners;
public FileMatchingConfiguration()
{
this.directoryScanners = new ArrayList<>();
}
/**
* @param directoryScanner new directory scanner retrieved from the
* <code>&lt;fileset/&gt;</code> element.
*/
public void addDirectoryScanner(DirectoryScanner directoryScanner)
{
this.directoryScanners.add(directoryScanner);
}
/**
* @return a list of base directories denoted by a list of directory
* scanners.
*/
public List<File> getBaseDirectories()
{
List<File> baseDirs = new ArrayList<>();
Iterator<DirectoryScanner> scanners = directoryScanners.iterator();
while (scanners.hasNext())
{
DirectoryScanner scanner = (DirectoryScanner)scanners.next();
baseDirs.add(scanner.getBasedir());
}
return baseDirs;
}
/**
* Checks if passed file is scanned by any of the directory scanners.
*
* @param pathToFile a fully qualified path to tested file.
* @return true if so, false otherwise.
*/
public boolean isIncluded(String pathToFile)
{
Iterator<DirectoryScanner> scanners = directoryScanners.iterator();
while (scanners.hasNext())
{
DirectoryScanner scanner = (DirectoryScanner)scanners.next();
scanner.scan();
String[] includedFiles = scanner.getIncludedFiles();
for (int i = 0; i < includedFiles.length; i++)
{
File includedFile = new File(scanner.getBasedir(), includedFiles[i]);
if (pathToFile.equalsIgnoreCase(includedFile.getAbsolutePath()))
{
return true;
}
}
}
return false;
}
}

View File

@ -1,37 +0,0 @@
//
// ========================================================================
// Copyright (c) 1995-2012 Sabre Holdings and others.
// ------------------------------------------------------------------------
// This program and the accompanying materials are made available under the
// terms of the Eclipse Public License v. 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
// which is available at https://www.apache.org/licenses/LICENSE-2.0.
//
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
// ========================================================================
//
package org.eclipse.jetty.ee10.ant.types;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.jetty.ee10.servlet.security.LoginService;
/**
* Specifies a jetty configuration &lt;loginServices/&gt; element for Ant build file.
*/
public class LoginServices
{
private List<LoginService> loginServices = new ArrayList<LoginService>();
public void add(LoginService service)
{
loginServices.add(service);
}
public List<LoginService> getLoginServices()
{
return loginServices;
}
}

View File

@ -1,59 +0,0 @@
//
// ========================================================================
// Copyright (c) 1995-2012 Sabre Holdings and others.
// ------------------------------------------------------------------------
// This program and the accompanying materials are made available under the
// terms of the Eclipse Public License v. 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
// which is available at https://www.apache.org/licenses/LICENSE-2.0.
//
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
// ========================================================================
//
package org.eclipse.jetty.ee10.ant.types;
import java.util.ArrayList;
import java.util.List;
import org.apache.tools.ant.taskdefs.Property;
import org.eclipse.jetty.ee10.ant.utils.TaskLog;
/**
* SystemProperties
* <p>
* Ant &lt;systemProperties/&gt; tag definition.
*/
public class SystemProperties
{
private List systemProperties = new ArrayList();
public List getSystemProperties()
{
return systemProperties;
}
public void addSystemProperty(Property property)
{
systemProperties.add(property);
}
/**
* Set a System.property with this value if it is not already set.
*
* @param property the property to test
* @return true if property has been set
*/
public static boolean setIfNotSetAlready(Property property)
{
if (System.getProperty(property.getName()) == null)
{
System.setProperty(property.getName(), (property.getValue() == null ? "" : property.getValue()));
TaskLog.log("Setting property '" + property.getName() + "' to value '" + property.getValue() + "'");
return true;
}
return false;
}
}

View File

@ -1,18 +0,0 @@
//
// ========================================================================
// Copyright (c) 1995 Mort Bay Consulting Pty Ltd and others.
//
// This program and the accompanying materials are made available under the
// terms of the Eclipse Public License v. 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
// which is available at https://www.apache.org/licenses/LICENSE-2.0.
//
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
// ========================================================================
//
/**
* Jetty Ant : Ant Wrappers of Jetty Internals
*/
package org.eclipse.jetty.ee10.ant.types;

View File

@ -1,34 +0,0 @@
//
// ========================================================================
// Copyright (c) 1995-2012 Sabre Holdings and others.
// ------------------------------------------------------------------------
// This program and the accompanying materials are made available under the
// terms of the Eclipse Public License v. 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
// which is available at https://www.apache.org/licenses/LICENSE-2.0.
//
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
// ========================================================================
//
package org.eclipse.jetty.ee10.ant.utils;
import org.eclipse.jetty.ee10.ant.AntWebAppContext;
public interface ServerProxy
{
/**
* Adds a new web application to this server.
*
* @param awc a AntWebAppContext object.
*/
public void addWebApplication(AntWebAppContext awc);
/**
* Starts this server.
*/
public void start();
public Object getProxiedObject();
}

View File

@ -1,52 +0,0 @@
//
// ========================================================================
// Copyright (c) 1995-2012 Sabre Holdings and others.
// ------------------------------------------------------------------------
// This program and the accompanying materials are made available under the
// terms of the Eclipse Public License v. 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
// which is available at https://www.apache.org/licenses/LICENSE-2.0.
//
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
// ========================================================================
//
package org.eclipse.jetty.ee10.ant.utils;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.apache.tools.ant.Task;
/**
* Provides logging functionality for classes without access to the Ant project
* variable.
*/
public class TaskLog
{
private static Task task;
private static final SimpleDateFormat format = new SimpleDateFormat(
"yyyy-MM-dd HH:mm:ss.SSS");
public static void setTask(Task task)
{
TaskLog.task = task;
}
public static void log(String message)
{
task.log(message);
}
public static void logWithTimestamp(String message)
{
String date;
synchronized (format)
{
date = format.format(new Date());
}
task.log(date + ": " + message);
}
}

View File

@ -1,18 +0,0 @@
//
// ========================================================================
// Copyright (c) 1995 Mort Bay Consulting Pty Ltd and others.
//
// This program and the accompanying materials are made available under the
// terms of the Eclipse Public License v. 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
// which is available at https://www.apache.org/licenses/LICENSE-2.0.
//
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
// ========================================================================
//
/**
* Jetty Ant : Utility Classes
*/
package org.eclipse.jetty.ee10.ant.utils;

View File

@ -1,2 +0,0 @@
org.eclipse.jetty.ee10.ant.AntWebInfConfiguration
org.eclipse.jetty.ee10.ant.AntWebXmlConfiguration

View File

@ -1,2 +0,0 @@
jetty.run=org.eclipse.jetty.ee10.ant.JettyRunTask
jetty.stop=org.eclipse.jetty.ee10.ant.JettyStopTask

View File

@ -1,39 +0,0 @@
<!-- =======================================================================================-->
<!-- Build file for running the test-jetty-webapp from the jetty distro. -->
<!-- -->
<!-- You will need to have a full jetty-home available unpacked on your local file -->
<!-- system. We will refer to the top level directory of this distribution as $JETTY_HOME. -->
<!-- -->
<!-- To use: -->
<!-- * mkdir test-jetty-ant -->
<!-- * cp this file to test-jetty-ant -->
<!-- * cd test-jetty-ant; mkdir jetty-lib; mkdir jetty-temp -->
<!-- * copy all jars from $JETTY_HOME/lib and all subdirs flatly into ./jetty-lib -->
<!-- * copy the jetty-ant jar into ./jetty-lib -->
<!-- * copy the test.war from $JETTY_HOME/webapps.demo dir -->
<!-- -->
<!-- To run: -->
<!-- ant jetty.run -->
<!-- =======================================================================================-->
<project name="Jetty-Ant integration test" basedir=".">
<path id="jetty.plugin.classpath">
<fileset dir="jetty-lib" includes="*.jar"/>
</path>
<taskdef classpathref="jetty.plugin.classpath" resource="tasks.properties" loaderref="jetty.loader" />
<typedef name="hashLoginService" classname="org.eclipse.jetty.security.HashLoginService"
classpathref="jetty.plugin.classpath" loaderref="jetty.loader" />
<target name="jetty.run">
<jetty.run tempDirectory="jetty-temp">
<loginServices>
<hashLoginService name="Test Realm" config="realm.properties"/>
</loginServices>
<webApp war="test.war" contextpath="/test" >
<attributes>
<attribute name="org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern" value=".*/jetty-jakarta-servlet-api-[^/]*\.jar$"/>
</attributes>
</webApp>
</jetty.run>
</target>
</project>

View File

@ -1,289 +0,0 @@
//
// ========================================================================
// Copyright (c) 1995 Mort Bay Consulting Pty Ltd and others.
//
// This program and the accompanying materials are made available under the
// terms of the Eclipse Public License v. 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
// which is available at https://www.apache.org/licenses/LICENSE-2.0.
//
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
// ========================================================================
//
package org.eclipse.jetty.ee10.ant;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PipedInputStream;
import java.io.PipedOutputStream;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.tools.ant.DefaultLogger;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.ProjectHelper;
import org.eclipse.jetty.toolchain.test.IO;
import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
public class AntBuild
{
private Thread _process;
private String _ant;
private int _port;
private String _host;
public AntBuild(String ant)
{
_ant = ant;
}
private class AntBuildProcess implements Runnable
{
List<String[]> connList;
@Override
public void run()
{
File buildFile = new File(_ant);
Project antProject = new Project();
try
{
antProject.setBaseDir(MavenTestingUtils.getBaseDir());
antProject.setUserProperty("ant.file", buildFile.getAbsolutePath());
DefaultLogger logger = new DefaultLogger();
ConsoleParser parser = new ConsoleParser();
//connList = parser.newPattern(".*([0-9]+\\.[0-9]*\\.[0-9]*\\.[0-9]*):([0-9]*)",1);
connList = parser.newPattern("Jetty AntTask Started", 1);
PipedOutputStream pos = new PipedOutputStream();
PipedInputStream pis = new PipedInputStream(pos);
PipedOutputStream pose = new PipedOutputStream();
PipedInputStream pise = new PipedInputStream(pose);
startPump("STDOUT", parser, pis);
startPump("STDERR", parser, pise);
logger.setErrorPrintStream(new PrintStream(pos));
logger.setOutputPrintStream(new PrintStream(pose));
logger.setMessageOutputLevel(Project.MSG_VERBOSE);
antProject.addBuildListener(logger);
antProject.fireBuildStarted();
antProject.init();
ProjectHelper helper = ProjectHelper.getProjectHelper();
antProject.addReference("ant.projectHelper", helper);
helper.parse(antProject, buildFile);
antProject.executeTarget("jetty.run");
parser.waitForDone(10000, TimeUnit.MILLISECONDS);
}
catch (Exception e)
{
antProject.fireBuildFinished(e);
}
}
public void waitForStarted() throws Exception
{
while (connList == null || connList.isEmpty())
{
Thread.sleep(10);
}
}
}
public void start() throws Exception
{
System.out.println("Starting Ant Build ...");
AntBuildProcess abp = new AntBuildProcess();
_process = new Thread(abp);
_process.start();
abp.waitForStarted();
// once this has returned we should have the connection info we need
//_host = abp.getConnectionList().get(0)[0];
//_port = Integer.parseInt(abp.getConnectionList().get(0)[1]);
}
public int getJettyPort()
{
return Integer.parseInt(System.getProperty("jetty.ant.server.port"));
}
public String getJettyHost()
{
return System.getProperty("jetty.ant.server.host");
}
/**
* Stop the jetty server
*/
public void stop()
{
System.out.println("Stopping Ant Build ...");
_process.interrupt();
}
private static class ConsoleParser
{
private List<ConsolePattern> patterns = new ArrayList<ConsolePattern>();
private CountDownLatch latch;
private int count;
public List<String[]> newPattern(String exp, int cnt)
{
ConsolePattern pat = new ConsolePattern(exp, cnt);
patterns.add(pat);
count += cnt;
return pat.getMatches();
}
public void parse(String line)
{
for (ConsolePattern pat : patterns)
{
Matcher mat = pat.getMatcher(line);
if (mat.find())
{
int num = 0;
int count = mat.groupCount();
String[] match = new String[count];
while (num++ < count)
{
match[num - 1] = mat.group(num);
}
pat.getMatches().add(match);
if (pat.getCount() > 0)
{
getLatch().countDown();
}
}
}
}
public void waitForDone(long timeout, TimeUnit unit) throws InterruptedException
{
getLatch().await(timeout, unit);
}
private CountDownLatch getLatch()
{
synchronized (this)
{
if (latch == null)
{
latch = new CountDownLatch(count);
}
}
return latch;
}
}
private static class ConsolePattern
{
private Pattern pattern;
private List<String[]> matches;
private int count;
ConsolePattern(String exp, int cnt)
{
pattern = Pattern.compile(exp);
matches = new ArrayList<String[]>();
count = cnt;
}
public Matcher getMatcher(String line)
{
return pattern.matcher(line);
}
public List<String[]> getMatches()
{
return matches;
}
public int getCount()
{
return count;
}
}
private void startPump(String mode, ConsoleParser parser, InputStream inputStream)
{
ConsoleStreamer pump = new ConsoleStreamer(mode, inputStream);
pump.setParser(parser);
Thread thread = new Thread(pump, "ConsoleStreamer/" + mode);
thread.start();
}
/**
* Simple streamer for the console output from a Process
*/
private static class ConsoleStreamer implements Runnable
{
private String mode;
private BufferedReader reader;
private ConsoleParser parser;
public ConsoleStreamer(String mode, InputStream is)
{
this.mode = mode;
this.reader = new BufferedReader(new InputStreamReader(is));
}
public void setParser(ConsoleParser connector)
{
this.parser = connector;
}
@Override
public void run()
{
String line;
//System.out.printf("ConsoleStreamer/%s initiated%n",mode);
try
{
while ((line = reader.readLine()) != (null))
{
if (parser != null)
{
parser.parse(line);
}
System.out.println("[" + mode + "] " + line);
}
}
catch (IOException ignore)
{
/* ignore */
}
finally
{
IO.close(reader);
}
//System.out.printf("ConsoleStreamer/%s finished%n",mode);
}
}
}

View File

@ -1,66 +0,0 @@
//
// ========================================================================
// Copyright (c) 1995 Mort Bay Consulting Pty Ltd and others.
//
// This program and the accompanying materials are made available under the
// terms of the Eclipse Public License v. 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
// which is available at https://www.apache.org/licenses/LICENSE-2.0.
//
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
// ========================================================================
//
package org.eclipse.jetty.ee10.ant;
import java.net.HttpURLConnection;
import java.net.URI;
import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
public class JettyAntTaskTest
{
@Test
public void testConnectorTask() throws Exception
{
AntBuild build = new AntBuild(MavenTestingUtils.getTestResourceFile("connector-test.xml").getAbsolutePath());
build.start();
URI uri = new URI("http://" + build.getJettyHost() + ":" + build.getJettyPort());
HttpURLConnection connection = (HttpURLConnection)uri.toURL().openConnection();
connection.connect();
assertThat("response code is 404", connection.getResponseCode(), is(404));
build.stop();
}
@Disabled //TODO
@Test
public void testWebApp() throws Exception
{
AntBuild build = new AntBuild(MavenTestingUtils.getTestResourceFile("webapp-test.xml").getAbsolutePath());
build.start();
URI uri = new URI("http://" + build.getJettyHost() + ":" + build.getJettyPort() + "/");
HttpURLConnection connection = (HttpURLConnection)uri.toURL().openConnection();
connection.connect();
assertThat("response code is 200", connection.getResponseCode(), is(200));
System.err.println("Stop build!");
build.stop();
}
}

View File

@ -1,19 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<project name="Jetty-Ant integration test" basedir=".">
<path id="jetty.plugin.classpath">
<fileset dir="target/test-lib" includes="*.jar"/>
</path>
<taskdef classpathref="jetty.plugin.classpath" resource="tasks.properties" loaderref="jetty.loader" />
<typedef name="connector" classname="org.eclipse.jetty.ee10.ant.types.Connector"
classpathref="jetty.plugin.classpath" loaderref="jetty.loader" />
<target name="jetty.run">
<jetty.run>
<connectors>
<connector port="0"/>
</connectors>
</jetty.run>
</target>
</project>

View File

@ -1,28 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE taglib
PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN"
"http://java.sun.com/dtd/web-jsptaglibrary_1_2.dtd">
<taglib>
<tlib-version>1.0</tlib-version>
<jsp-version>1.2</jsp-version>
<short-name>acme</short-name>
<uri>http://www.acme.com/taglib</uri>
<description>taglib example</description>
<listener>
<listener-class>com.acme.TagListener</listener-class>
</listener>
<tag>
<name>date</name>
<tag-class>com.acme.DateTag</tag-class>
<body-content>TAGDEPENDENT</body-content>
<description>Display Date</description>
<attribute>
<name>tz</name>
<required>false</required>
</attribute>
</tag>
</taglib>

View File

@ -1,35 +0,0 @@
<?xml version="1.0" encoding="UTF-8" ?>
<taglib xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee web-jsptaglibrary_2_0.xsd"
version="2.0">
<description>Acme JSP2 tags</description>
<tlib-version>1.0</tlib-version>
<short-name>acme2</short-name>
<uri>http://www.acme.com/taglib2</uri>
<tag>
<description>Simple Date formatting</description>
<name>date2</name>
<tag-class>com.acme.Date2Tag</tag-class>
<body-content>scriptless</body-content>
<variable>
<description>Day of the Month</description>
<name-given>day</name-given>
</variable>
<variable>
<description>Month of the Year</description>
<name-given>month</name-given>
</variable>
<variable>
<description>Year</description>
<name-given>year</name-given>
</variable>
<attribute>
<name>format</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>
</taglib>

View File

@ -1,17 +0,0 @@
<%--
- Copyright (c) 2002 The Apache Software Foundation. All rights
- reserved.
--%>
<%@ attribute name="color" %>
<%@ attribute name="bgcolor" %>
<%@ attribute name="title" %>
<table border="1" bgcolor="${color}">
<tr>
<td><b>${title}</b></td>
</tr>
<tr>
<td bgcolor="${bgcolor}">
<jsp:doBody/>
</td>
</tr>
</table>

View File

@ -1,28 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<web-app
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5">
<display-name>Test WebApp</display-name>
<context-param>
<param-name>org.eclipse.jetty.server.context.ManagedAttributes</param-name>
<param-value>QoSFilter,TransparentProxy.ThreadPool,TransparentProxy.HttpClient</param-value>
</context-param>
<servlet>
<servlet-name>foo.jsp</servlet-name>
<jsp-file>/jsp/foo/foo.jsp</jsp-file>
</servlet>
<servlet-mapping>
<servlet-name>foo.jsp</servlet-name>
<url-pattern>/jsp/foo/</url-pattern>
</servlet-mapping>
</web-app>

View File

@ -1,5 +0,0 @@
<html>
<body>
<h1>INDEX!</h1>
</body>
</html>

View File

@ -1,15 +0,0 @@
<html>
<%@ page session="true"%>
<body>
<jsp:useBean id='counter' scope='session' class='com.acme.Counter' type="com.acme.Counter" />
<h1>JSP1.2 Beans: 1</h1>
Counter accessed <jsp:getProperty name="counter" property="count"/> times.<br/>
Counter last accessed by <jsp:getProperty name="counter" property="last"/><br/>
<jsp:setProperty name="counter" property="last" value="<%= request.getRequestURI()%>"/>
<a href="bean2.jsp">Goto bean2.jsp</a>
</body>
</html>

View File

@ -1,15 +0,0 @@
<html>
<%@ page session="true"%>
<body>
<jsp:useBean id='counter' scope='session' class='com.acme.Counter' type="com.acme.Counter" />
<h1>JSP1.2 Beans: 2</h1>
Counter accessed <jsp:getProperty name="counter" property="count"/> times.<br/>
Counter last accessed by <jsp:getProperty name="counter" property="last"/><br/>
<jsp:setProperty name="counter" property="last" value="<%= request.getRequestURI()%>"/>
<a href="bean1.jsp">Goto bean1.jsp</a>
</body>
</html>

View File

@ -1,23 +0,0 @@
<html><head>
<%@ page import="java.util.Enumeration" %>
</head><body>
<h1>JSP Dump</h1>
<table border="1">
<tr><th>Request URI:</th><td><%= request.getRequestURI() %></td></tr>
<tr><th>ServletPath:</th><td><%= request.getServletPath() %></td></tr>
<tr><th>PathInfo:</th><td><%= request.getPathInfo() %></td></tr>
<%
Enumeration e =request.getParameterNames();
while(e.hasMoreElements())
{
String name = (String)e.nextElement();
%>
<tr>
<th>getParameter("<%= name %>")</th>
<td><%= request.getParameter(name) %></td></tr>
<% } %>
</table>
</body></html>

View File

@ -1,23 +0,0 @@
<html>
<h1>JSP2.0 Expressions</h1>
<table border="1">
<tr><th>Expression</th><th>Result</th></tr>
<tr>
<td>\${param["A"]}</td>
<td>${param["A"]}&nbsp;</td>
</tr><tr>
<td>\${header["host"]}</td>
<td>${header["host"]}</td>
</tr><tr>
<td>\${header["user-agent"]}</td>
<td>${header["user-agent"]}</td>
</tr><tr>
<td>\${1+1}</td>
<td>${1+1}</td>
</tr><tr>
<td>\${param["A"] * 2}</td>
<td>${param["A"] * 2}&nbsp;</td>
</tr>
</table>
</html>

View File

@ -1,15 +0,0 @@
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
</head>
<body>
<h1>FOO Example</h1>
<hr>
<p>A trivial FOO example
<hr>
<c:forEach var="i" begin="1" end="10" step="1">
<c:out value="${i}" />
<br />
</c:forEach>
</body>
</html>

View File

@ -1,20 +0,0 @@
<html>
<body>
<h1>JSP Examples</h1>
<ul>
<li><a href="dump.jsp">JSP 1.2 embedded java</a><br/>
<li><a href="bean1.jsp">JSP 1.2 Bean demo</a><br/>
<li><a href="tag.jsp">JSP 1.2 BodyTag demo</a><br/>
<li><a href="tag2.jsp">JSP 2.0 SimpleTag demo</a><br/>
<li><a href="tagfile.jsp">JSP 2.0 Tag File demo</a><br/>
<li><a href="expr.jsp?A=1">JSP 2.0 Tag Expression</a><br/>
<li><a href="jstl.jsp">JSTL Expression</a><br/>
<li><a href="foo/">Mapping to &lt;jsp-file&gt;</a><br/>
</ul>
<a href="/">Main Menu</a>
</body>
</html>

View File

@ -1,15 +0,0 @@
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
</head>
<body>
<h1>JSTL Example</h1>
<hr>
<p>A trivial jstl example
<hr>
<c:forEach var="i" begin="1" end="10" step="1">
<c:out value="${i}" />
<br />
</c:forEach>
</body>
</html>

View File

@ -1,16 +0,0 @@
<html>
<body>
<%@ taglib uri="http://www.acme.com/taglib" prefix="acme" %>
<small>&lt;acme:date tz="GMT"&gt;EEE, dd/MMM/yyyy HH:mm:ss ZZZ&lt;/acme:date&gt;
==&gt;</small>
<acme:date tz="GMT">EEE, dd/MMM/yyyy HH:mm:ss ZZZ</acme:date>
<br/>
<small>&lt;acme:date tz="EST"&gt;EEE, dd-MMM-yyyy HH:mm:ss ZZZ&lt;/acme:date&gt;
==&gt;</small>
<acme:date tz="EST">EEE, dd-MMM-yyyy HH:mm:ss ZZZ</acme:date>
<br/>
</body>
</html>

View File

@ -1,19 +0,0 @@
<html>
<body>
<%@ taglib uri="http://www.acme.com/taglib2" prefix="acme" %>
<acme:date2 format="long">
On ${day} of ${month} in the year ${year}
</acme:date2>
<br/>
<acme:date2 format="short">
${day} - ${month} - ${year}
</acme:date2>
<br/>
</body>
</html>

View File

@ -1,37 +0,0 @@
<%@ taglib prefix="acme" tagdir="/WEB-INF/tags" %>
<html>
<head>
</head>
<body>
<h1>JSP 2.0 Tag File Example</h1>
<hr>
<p>Panel tag created from JSP fragment file in WEB-INF/tags
<hr>
<table border="0">
<tr valign="top">
<td>
<acme:panel color="#ff8080" bgcolor="#ffc0c0" title="Panel 1">
First panel.<br/>
</acme:panel>
</td>
<td>
<acme:panel color="#80ff80" bgcolor="#c0ffc0" title="Panel 2">
Second panel.<br/>
Second panel.<br/>
Second panel.<br/>
Second panel.<br/>
</acme:panel>
</td>
<td>
<acme:panel color="#8080ff" bgcolor="#c0c0ff" title="Panel 3">
Third panel.<br/>
<acme:panel color="#ff80ff" bgcolor="#ffc0ff" title="Inner">
A panel in a panel.
</acme:panel>
Third panel.<br/>
</acme:panel>
</td>
</tr>
</table>
</body>
</html>

View File

@ -1,17 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<project name="Jetty-Ant integration test" basedir="." >
<path id="jetty.plugin.classpath">
<fileset dir="target/test-lib" includes="*.jar"/>
</path>
<taskdef classpathref="jetty.plugin.classpath" resource="tasks.properties" loaderref="jetty.loader" />
<typedef name="webapp" classname="org.eclipse.jetty.ee10.ant.AntWebAppContext"
classpathref="jetty.plugin.classpath" loaderref="jetty.loader" />
<target name="jetty.run">
<jetty.run daemon="true" scanIntervalSeconds="10" jettyPort="0">
<webapp war="${basedir}/src/test/resources/foo" contextpath="/" />
</jetty.run>
</target>
</project>

View File

@ -45,8 +45,6 @@
<module>jetty-ee10-apache-jsp</module>
<module>jetty-ee10-glassfish-jstl</module>
<module>jetty-ee10-annotations</module>
<!-- TODO -->
<!-- module>jetty-ee10-ant</module -->
<module>jetty-ee10-cdi</module>
<module>jetty-ee10-jaas</module>
<module>jetty-ee10-jaspi</module>

View File

@ -1,94 +0,0 @@
<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">
<parent>
<groupId>org.eclipse.jetty.ee9</groupId>
<artifactId>jetty-ee9</artifactId>
<version>12.0.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>jetty-ee9-ant</artifactId>
<packaging>jar</packaging>
<name>EE9 :: Ant Plugin</name>
<properties>
<bundle-symbolic-name>${project.groupId}.ant</bundle-symbolic-name>
<jacoco.skip>true</jacoco.skip>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<instructions>
<Require-Capability>
osgi.extender; filter:="(osgi.extender=osgi.serviceloader.registrar)"
</Require-Capability>
<Provide-Capability>
osgi.serviceloader; osgi.serviceloader=org.eclipse.jetty.ee9.webapp.Configuration
</Provide-Capability>
</instructions>
</configuration>
</plugin>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-lib-deps</id>
<phase>process-test-resources</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<includeGroupIds>org.eclipse.jetty</includeGroupIds>
<excludeGroupIds>org.eclipse.jetty.orbit,org.eclipse.jetty.websocket</excludeGroupIds>
<excludeArtifactIds>jetty-start</excludeArtifactIds>
<includeTypes>jar</includeTypes>
<outputDirectory>${project.build.directory}/test-lib</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.eclipse.jetty.toolchain</groupId>
<artifactId>jetty-test-helper</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.ant</groupId>
<artifactId>ant</artifactId>
</dependency>
<dependency>
<groupId>org.apache.ant</groupId>
<artifactId>ant-launcher</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.ee9</groupId>
<artifactId>jetty-ee9-security</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.ee9</groupId>
<artifactId>jetty-ee9-plus</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.ee9</groupId>
<artifactId>jetty-ee9-webapp</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.ee9</groupId>
<artifactId>jetty-ee9-annotations</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-slf4j-impl</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>

View File

@ -1,81 +0,0 @@
//
// ========================================================================
// Copyright (c) 1995 Mort Bay Consulting Pty Ltd and others.
//
// This program and the accompanying materials are made available under the
// terms of the Eclipse Public License v. 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
// which is available at https://www.apache.org/licenses/LICENSE-2.0.
//
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
// ========================================================================
//
package org.eclipse.jetty.ee9.ant;
import java.io.File;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.ArrayList;
import java.util.List;
import org.apache.tools.ant.AntClassLoader;
import org.eclipse.jetty.ee9.webapp.Configuration;
import org.eclipse.jetty.ee9.webapp.MetaInfConfiguration;
import org.eclipse.jetty.ee9.webapp.WebAppContext;
public class AntMetaInfConfiguration extends MetaInfConfiguration
{
@Override
public Class<? extends Configuration> replaces()
{
return MetaInfConfiguration.class;
}
@Override
public void findAndFilterContainerPaths(WebAppContext context) throws Exception
{
// TODO Auto-generated method stub
super.findAndFilterContainerPaths(context);
}
@Override
protected List<URI> getAllContainerJars(final WebAppContext context) throws URISyntaxException
{
List<URI> uris = new ArrayList<>();
if (context.getClassLoader() != null)
{
ClassLoader loader = context.getClassLoader().getParent();
while (loader != null)
{
if (loader instanceof URLClassLoader)
{
URL[] urls = ((URLClassLoader)loader).getURLs();
if (urls != null)
for (URL url : urls)
{
uris.add(new URI(url.toString().replaceAll(" ", "%20")));
}
}
else if (loader instanceof AntClassLoader)
{
AntClassLoader antLoader = (AntClassLoader)loader;
String[] paths = antLoader.getClasspath().split(new String(new char[]{File.pathSeparatorChar}));
if (paths != null)
{
for (String p : paths)
{
File f = new File(p);
uris.add(f.toURI());
}
}
}
loader = loader.getParent();
}
}
return uris;
}
}

View File

@ -1,691 +0,0 @@
//
// ========================================================================
// Copyright (c) 1995-2012 Sabre Holdings and others.
// ------------------------------------------------------------------------
// This program and the accompanying materials are made available under the
// terms of the Eclipse Public License v. 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
// which is available at https://www.apache.org/licenses/LICENSE-2.0.
//
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
// ========================================================================
//
package org.eclipse.jetty.ee9.ant;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.net.URLClassLoader;
import java.security.CodeSource;
import java.security.PermissionCollection;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import java.util.jar.Manifest;
import jakarta.servlet.Servlet;
import org.apache.tools.ant.AntClassLoader;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.types.FileSet;
import org.eclipse.jetty.ee9.ant.types.Attribute;
import org.eclipse.jetty.ee9.ant.types.Attributes;
import org.eclipse.jetty.ee9.ant.types.FileMatchingConfiguration;
import org.eclipse.jetty.ee9.ant.utils.TaskLog;
import org.eclipse.jetty.ee9.plus.webapp.EnvConfiguration;
import org.eclipse.jetty.ee9.servlet.FilterHolder;
import org.eclipse.jetty.ee9.servlet.FilterMapping;
import org.eclipse.jetty.ee9.servlet.ServletHandler;
import org.eclipse.jetty.ee9.servlet.ServletHolder;
import org.eclipse.jetty.ee9.servlet.ServletMapping;
import org.eclipse.jetty.ee9.servlet.Source;
import org.eclipse.jetty.ee9.webapp.MetaInfConfiguration;
import org.eclipse.jetty.ee9.webapp.WebAppClassLoader;
import org.eclipse.jetty.ee9.webapp.WebAppContext;
import org.eclipse.jetty.util.resource.PathResource;
import org.eclipse.jetty.util.resource.Resource;
import org.eclipse.jetty.xml.XmlConfiguration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Extension of WebAppContext to allow configuration via Ant environment.
*/
public class AntWebAppContext extends WebAppContext
{
private static final Logger LOG = LoggerFactory.getLogger(WebAppContext.class);
public static final String DEFAULT_CONTAINER_INCLUDE_JAR_PATTERN =
".*/.*jsp-api-[^/]*\\.jar$|.*/.*jsp-[^/]*\\.jar$|.*/.*taglibs[^/]*\\.jar$|.*/.*jstl[^/]*\\.jar$|.*/.*jsf-impl-[^/]*\\.jar$|.*/.*javax.faces-[^/]*\\.jar$|.*/.*myfaces-impl-[^/]*\\.jar$";
/**
* Location of jetty-env.xml file.
*/
private File jettyEnvXml;
/**
* List of web application libraries.
*/
private List<FileSet> libraries = new ArrayList<>();
/**
* List of web application class directories.
*/
private List<FileSet> classes = new ArrayList<>();
/**
* context xml file to apply to the webapp
*/
private File contextXml;
/**
* List of extra scan targets for this web application.
*/
private FileSet scanTargets;
/**
* context attributes to set
**/
private Attributes attributes;
private Project project;
private List<File> scanFiles;
private FileMatchingConfiguration librariesConfiguration;
public static void dump(ClassLoader loader)
{
while (loader != null)
{
System.err.println(loader);
if (loader instanceof URLClassLoader)
{
URL[] urls = ((URLClassLoader)loader).getURLs();
if (urls != null)
{
for (URL u : urls)
{
System.err.println("\t" + u + "\n");
}
}
}
loader = loader.getParent();
}
}
/**
* AntURLClassLoader
*
* Adapt the AntClassLoader which is not a URLClassLoader - this is needed for
* jsp to be able to search the classpath.
*/
public static class AntURLClassLoader extends URLClassLoader
{
private AntClassLoader antLoader;
public AntURLClassLoader(AntClassLoader antLoader)
{
super(new URL[]{}, antLoader);
this.antLoader = antLoader;
}
@Override
public InputStream getResourceAsStream(String name)
{
return super.getResourceAsStream(name);
}
@Override
public void close() throws IOException
{
super.close();
}
@Override
protected void addURL(URL url)
{
super.addURL(url);
}
@Override
public URL[] getURLs()
{
Set<URL> urls = new HashSet<URL>();
//convert urls from antLoader
String[] paths = antLoader.getClasspath().split(new String(new char[]{File.pathSeparatorChar}));
if (paths != null)
{
for (String p : paths)
{
File f = new File(p);
try
{
urls.add(f.toURI().toURL());
}
catch (Exception e)
{
LOG.trace("IGNORED", e);
}
}
}
//add in any that may have been added to us as a URL directly
URL[] ourURLS = super.getURLs();
if (ourURLS != null)
{
for (URL u : ourURLS)
{
urls.add(u);
}
}
return urls.toArray(new URL[urls.size()]);
}
@Override
protected Class<?> findClass(String name) throws ClassNotFoundException
{
return super.findClass(name);
}
@Override
public URL findResource(String name)
{
return super.findResource(name);
}
@Override
public Enumeration<URL> findResources(String name) throws IOException
{
return super.findResources(name);
}
@Override
protected PermissionCollection getPermissions(CodeSource codesource)
{
return super.getPermissions(codesource);
}
@Override
public Class<?> loadClass(String name) throws ClassNotFoundException
{
return super.loadClass(name);
}
@Override
protected Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException
{
return super.loadClass(name, resolve);
}
@Override
protected Object getClassLoadingLock(String className)
{
return super.getClassLoadingLock(className);
}
@Override
public URL getResource(String name)
{
return super.getResource(name);
}
@Override
public Enumeration<URL> getResources(String name) throws IOException
{
return super.getResources(name);
}
@Override
protected Package definePackage(String name, Manifest man, URL url) throws IllegalArgumentException
{
return super.definePackage(name, man, url);
}
@Override
protected Package definePackage(String name, String specTitle, String specVersion, String specVendor, String implTitle, String implVersion,
String implVendor, URL sealBase) throws IllegalArgumentException
{
return super.definePackage(name, specTitle, specVersion, specVendor, implTitle, implVersion, implVendor, sealBase);
}
@Override
protected Package[] getPackages()
{
return super.getPackages();
}
@Override
protected String findLibrary(String libname)
{
return super.findLibrary(libname);
}
@Override
public void setDefaultAssertionStatus(boolean enabled)
{
super.setDefaultAssertionStatus(enabled);
}
@Override
public void setPackageAssertionStatus(String packageName, boolean enabled)
{
super.setPackageAssertionStatus(packageName, enabled);
}
@Override
public void setClassAssertionStatus(String className, boolean enabled)
{
super.setClassAssertionStatus(className, enabled);
}
@Override
public void clearAssertionStatus()
{
super.clearAssertionStatus();
}
}
/**
* AntServletHolder
*/
public static class AntServletHolder extends ServletHolder
{
public AntServletHolder()
{
super();
}
public AntServletHolder(Class<? extends Servlet> servlet)
{
super(servlet);
}
public AntServletHolder(Servlet servlet)
{
super(servlet);
}
public AntServletHolder(String name, Class<? extends Servlet> servlet)
{
super(name, servlet);
}
public AntServletHolder(String name, Servlet servlet)
{
super(name, servlet);
}
protected String getSystemClassPath(ClassLoader loader) throws Exception
{
StringBuilder classpath = new StringBuilder();
while (loader != null)
{
if (loader instanceof URLClassLoader)
{
URL[] urls = ((URLClassLoader)loader).getURLs();
if (urls != null)
{
for (int i = 0; i < urls.length; i++)
{
Resource resource = Resource.newResource(urls[i]);
File file = resource.getFile();
if (file != null && file.exists())
{
if (classpath.length() > 0)
classpath.append(File.pathSeparatorChar);
classpath.append(file.getAbsolutePath());
}
}
}
}
else if (loader instanceof AntClassLoader)
{
classpath.append(((AntClassLoader)loader).getClasspath());
}
loader = loader.getParent();
}
return classpath.toString();
}
}
/**
* AntServletHandler
*/
public static class AntServletHandler extends ServletHandler
{
@Override
public ServletHolder newServletHolder(Source source)
{
return new AntServletHolder();
}
}
/**
* Default constructor. Takes project as an argument
*
* @param project the project.
* @throws Exception if unable to create webapp context
*/
public AntWebAppContext(Project project) throws Exception
{
super();
this.project = project;
setAttribute(MetaInfConfiguration.CONTAINER_JAR_PATTERN, DEFAULT_CONTAINER_INCLUDE_JAR_PATTERN);
setParentLoaderPriority(true);
addConfiguration(new AntWebInfConfiguration(), new AntWebXmlConfiguration(), new AntMetaInfConfiguration());
}
/**
* Adds a new Ant's attributes tag object if it have not been created yet.
*
* @param atts the attributes
*/
public void addAttributes(Attributes atts)
{
if (this.attributes != null)
{
throw new BuildException("Only one <attributes> tag is allowed!");
}
this.attributes = atts;
}
public void addLib(FileSet lib)
{
libraries.add(lib);
}
public void addClasses(FileSet classes)
{
this.classes.add(classes);
}
@Override
protected ServletHandler newServletHandler()
{
return new AntServletHandler();
}
public void setJettyEnvXml(File jettyEnvXml)
{
this.jettyEnvXml = jettyEnvXml;
TaskLog.log("jetty-env.xml file: = " + (jettyEnvXml == null ? null : jettyEnvXml.getAbsolutePath()));
}
public File getJettyEnvXml()
{
return this.jettyEnvXml;
}
public List<File> getLibraries()
{
return librariesConfiguration.getBaseDirectories();
}
public void addScanTargets(FileSet scanTargets)
{
if (this.scanTargets != null)
{
throw new BuildException("Only one <scanTargets> tag is allowed!");
}
this.scanTargets = scanTargets;
}
public List<File> getScanTargetFiles()
{
if (this.scanTargets == null)
return null;
FileMatchingConfiguration configuration = new FileMatchingConfiguration();
configuration.addDirectoryScanner(scanTargets.getDirectoryScanner(project));
return configuration.getBaseDirectories();
}
public List<File> getScanFiles()
{
if (scanFiles == null)
scanFiles = initScanFiles();
return scanFiles;
}
public boolean isScanned(File file)
{
List<File> files = getScanFiles();
if (files == null || files.isEmpty())
return false;
return files.contains(file);
}
public List<File> initScanFiles()
{
List<File> scanList = new ArrayList<File>();
if (getDescriptor() != null)
{
try (Resource r = Resource.newResource(getDescriptor());)
{
scanList.add(r.getFile());
}
catch (IOException e)
{
throw new BuildException(e);
}
}
if (getJettyEnvXml() != null)
{
try (Resource r = Resource.newResource(getJettyEnvXml());)
{
scanList.add(r.getFile());
}
catch (IOException e)
{
throw new BuildException("Problem configuring scanner for jetty-env.xml", e);
}
}
if (getDefaultsDescriptor() != null)
{
try (Resource r = Resource.newResource(getDefaultsDescriptor());)
{
if (!WebAppContext.WEB_DEFAULTS_XML.equals(getDefaultsDescriptor()))
{
scanList.add(r.getFile());
}
}
catch (IOException e)
{
throw new BuildException("Problem configuring scanner for webdefaults.xml", e);
}
}
if (getOverrideDescriptor() != null)
{
try
{
Resource r = Resource.newResource(getOverrideDescriptor());
scanList.add(r.getFile());
}
catch (IOException e)
{
throw new BuildException("Problem configuring scanner for webdefaults.xml", e);
}
}
//add any extra classpath and libs
List<File> cpFiles = getClassPathFiles();
if (cpFiles != null)
scanList.addAll(cpFiles);
//any extra scan targets
List<File> scanFiles = (List<File>)getScanTargetFiles();
if (scanFiles != null)
scanList.addAll(scanFiles);
return scanList;
}
@Override
public void setWar(String path)
{
super.setWar(path);
try
{
Resource war = Resource.newResource(path);
if (war.exists() && war.isDirectory() && getDescriptor() == null)
{
Resource webXml = war.addPath("WEB-INF/web.xml");
setDescriptor(webXml.toString());
}
}
catch (IOException e)
{
throw new BuildException(e);
}
}
@Override
public void doStart()
{
try
{
TaskLog.logWithTimestamp("Starting web application " + this.getDescriptor());
if (jettyEnvXml != null && jettyEnvXml.exists())
getConfiguration(EnvConfiguration.class).setJettyEnvResource(new PathResource(jettyEnvXml));
ClassLoader parentLoader = this.getClass().getClassLoader();
if (parentLoader instanceof AntClassLoader)
parentLoader = new AntURLClassLoader((AntClassLoader)parentLoader);
setClassLoader(new WebAppClassLoader(parentLoader, this));
if (attributes != null && attributes.getAttributes() != null)
{
for (Attribute a : attributes.getAttributes())
{
setAttribute(a.getName(), a.getValue());
}
}
//apply a context xml file if one was supplied
if (contextXml != null)
{
XmlConfiguration xmlConfiguration = new XmlConfiguration(new PathResource(contextXml));
TaskLog.log("Applying context xml file " + contextXml);
xmlConfiguration.configure(this);
}
super.doStart();
}
catch (Exception e)
{
TaskLog.log(e.toString());
}
}
@Override
public void doStop()
{
try
{
scanFiles = null;
TaskLog.logWithTimestamp("Stopping web application " + this);
Thread.currentThread().sleep(500L);
super.doStop();
// remove all filters and servlets. They will be recreated
// either via application of a context xml file or web.xml or annotation or servlet api.
// Event listeners are reset in ContextHandler.doStop()
getServletHandler().setFilters(new FilterHolder[0]);
getServletHandler().setFilterMappings(new FilterMapping[0]);
getServletHandler().setServlets(new ServletHolder[0]);
getServletHandler().setServletMappings(new ServletMapping[0]);
}
catch (InterruptedException e)
{
TaskLog.log(e.toString());
}
catch (Exception e)
{
TaskLog.log(e.toString());
}
}
/**
* @return a list of classpath files (libraries and class directories).
*/
public List<File> getClassPathFiles()
{
List<File> classPathFiles = new ArrayList<File>();
Iterator<FileSet> classesIterator = classes.iterator();
while (classesIterator.hasNext())
{
FileSet clazz = classesIterator.next();
classPathFiles.add(clazz.getDirectoryScanner(project).getBasedir());
}
Iterator<FileSet> iterator = libraries.iterator();
while (iterator.hasNext())
{
FileSet library = iterator.next();
String[] includedFiles = library.getDirectoryScanner(project).getIncludedFiles();
File baseDir = library.getDirectoryScanner(project).getBasedir();
for (int i = 0; i < includedFiles.length; i++)
{
classPathFiles.add(new File(baseDir, includedFiles[i]));
}
}
return classPathFiles;
}
/**
* @return a <code>FileMatchingConfiguration</code> object describing the
* configuration of all libraries added to this particular web app
* (both classes and libraries).
*/
public FileMatchingConfiguration getLibrariesConfiguration()
{
FileMatchingConfiguration config = new FileMatchingConfiguration();
Iterator<FileSet> classesIterator = classes.iterator();
while (classesIterator.hasNext())
{
FileSet clazz = classesIterator.next();
config.addDirectoryScanner(clazz.getDirectoryScanner(project));
}
Iterator<FileSet> librariesIterator = libraries.iterator();
while (librariesIterator.hasNext())
{
FileSet library = librariesIterator.next();
config.addDirectoryScanner(library.getDirectoryScanner(project));
}
return config;
}
public File getContextXml()
{
return contextXml;
}
public void setContextXml(File contextXml)
{
this.contextXml = contextXml;
}
}

View File

@ -1,59 +0,0 @@
//
// ========================================================================
// Copyright (c) 1995 Mort Bay Consulting Pty Ltd and others.
//
// This program and the accompanying materials are made available under the
// terms of the Eclipse Public License v. 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
// which is available at https://www.apache.org/licenses/LICENSE-2.0.
//
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
// ========================================================================
//
package org.eclipse.jetty.ee9.ant;
import java.io.File;
import java.util.List;
import org.eclipse.jetty.ee9.webapp.Configuration;
import org.eclipse.jetty.ee9.webapp.WebAppClassLoader;
import org.eclipse.jetty.ee9.webapp.WebAppContext;
import org.eclipse.jetty.ee9.webapp.WebInfConfiguration;
import org.eclipse.jetty.ee9.webapp.WebXmlConfiguration;
public class AntWebInfConfiguration extends WebInfConfiguration
{
@Override
public Class<? extends Configuration> replaces()
{
return WebInfConfiguration.class;
}
/**
* Adds classpath files into web application classloader, and
* sets web.xml and base directory for the configured web application.
*
* @see WebXmlConfiguration#configure(WebAppContext)
*/
@Override
public void configure(WebAppContext context) throws Exception
{
if (context instanceof AntWebAppContext)
{
List<File> classPathFiles = ((AntWebAppContext)context).getClassPathFiles();
if (classPathFiles != null)
{
for (File cpFile : classPathFiles)
{
if (cpFile.exists())
{
((WebAppClassLoader)context.getClassLoader()).addClassPath(cpFile.getCanonicalPath());
}
}
}
}
super.configure(context);
}
}

View File

@ -1,64 +0,0 @@
//
// ========================================================================
// Copyright (c) 1995-2012 Sabre Holdings and others.
// ------------------------------------------------------------------------
// This program and the accompanying materials are made available under the
// terms of the Eclipse Public License v. 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
// which is available at https://www.apache.org/licenses/LICENSE-2.0.
//
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
// ========================================================================
//
package org.eclipse.jetty.ee9.ant;
import java.io.File;
import java.util.List;
import org.eclipse.jetty.ee9.webapp.Configuration;
import org.eclipse.jetty.ee9.webapp.WebXmlConfiguration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* This configuration object provides additional way to inject application
* properties into the configured web application. The list of classpath files,
* the application base directory and web.xml file could be specified in this
* way.
*/
public class AntWebXmlConfiguration extends WebXmlConfiguration
{
private static final Logger LOG = LoggerFactory.getLogger(WebXmlConfiguration.class);
/**
* List of classpath files.
*/
private List classPathFiles;
/**
* Web application root directory.
*/
private File webAppBaseDir;
public AntWebXmlConfiguration()
{
super();
}
@Override
public Class<? extends Configuration> replaces()
{
return WebXmlConfiguration.class;
}
public void setClassPathFiles(List classPathFiles)
{
this.classPathFiles = classPathFiles;
}
public void setWebAppBaseDir(File webAppBaseDir)
{
this.webAppBaseDir = webAppBaseDir;
}
}

View File

@ -1,310 +0,0 @@
//
// ========================================================================
// Copyright (c) 1995-2012 Sabre Holdings and others.
// ------------------------------------------------------------------------
// This program and the accompanying materials are made available under the
// terms of the Eclipse Public License v. 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
// which is available at https://www.apache.org/licenses/LICENSE-2.0.
//
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
// ========================================================================
//
package org.eclipse.jetty.ee9.ant;
import java.io.File;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Task;
import org.apache.tools.ant.taskdefs.Property;
import org.eclipse.jetty.ee9.ant.types.Connector;
import org.eclipse.jetty.ee9.ant.types.Connectors;
import org.eclipse.jetty.ee9.ant.types.ContextHandlers;
import org.eclipse.jetty.ee9.ant.types.LoginServices;
import org.eclipse.jetty.ee9.ant.types.SystemProperties;
import org.eclipse.jetty.ee9.ant.utils.TaskLog;
import org.eclipse.jetty.ee9.security.LoginService;
import org.eclipse.jetty.ee9.webapp.WebAppContext;
import org.eclipse.jetty.server.RequestLog;
/**
* Ant task for running a Jetty server.
*/
public class JettyRunTask extends Task
{
private int scanIntervalSeconds;
/**
* Temporary files directory.
*/
private File tempDirectory;
/**
* List of web applications to be deployed.
*/
private List<AntWebAppContext> webapps = new ArrayList<>();
/**
* Location of jetty.xml file.
*/
private File jettyXml;
/**
* List of server connectors.
*/
private Connectors connectors = null;
/**
* Server request logger object.
*/
private RequestLog requestLog;
/**
* List of login services.
*/
private LoginServices loginServices;
/**
* List of system properties to be set.
*/
private SystemProperties systemProperties;
/**
* List of other contexts to deploy
*/
private ContextHandlers contextHandlers;
/**
* Port Jetty will use for the default connector
*/
private int jettyPort = 8080;
private int stopPort;
private String stopKey;
private boolean daemon;
public JettyRunTask()
{
TaskLog.setTask(this);
}
/**
* Creates a new <code>WebApp</code> Ant object.
*
* @param webapp the webapp context
*/
public void addWebApp(AntWebAppContext webapp)
{
webapps.add(webapp);
}
/**
* Adds a new Ant's connector tag object if it have not been created yet.
*
* @param connectors the connectors
*/
public void addConnectors(Connectors connectors)
{
if (this.connectors != null)
throw new BuildException("Only one <connectors> tag is allowed!");
this.connectors = connectors;
}
public void addLoginServices(LoginServices services)
{
if (this.loginServices != null)
throw new BuildException("Only one <loginServices> tag is allowed!");
this.loginServices = services;
}
public void addSystemProperties(SystemProperties systemProperties)
{
if (this.systemProperties != null)
throw new BuildException("Only one <systemProperties> tag is allowed!");
this.systemProperties = systemProperties;
}
public void addContextHandlers(ContextHandlers handlers)
{
if (this.contextHandlers != null)
throw new BuildException("Only one <contextHandlers> tag is allowed!");
this.contextHandlers = handlers;
}
public File getTempDirectory()
{
return tempDirectory;
}
public void setTempDirectory(File tempDirectory)
{
this.tempDirectory = tempDirectory;
}
public File getJettyXml()
{
return jettyXml;
}
public void setJettyXml(File jettyXml)
{
this.jettyXml = jettyXml;
}
public void setRequestLog(String className)
{
try
{
this.requestLog = (RequestLog)Class.forName(className).getDeclaredConstructor().newInstance();
}
catch (ClassNotFoundException e)
{
throw new BuildException("Unknown request logger class: " + className);
}
catch (Exception e)
{
throw new BuildException("Request logger instantiation exception: " + e);
}
}
public String getRequestLog()
{
if (requestLog != null)
{
return requestLog.getClass().getName();
}
return "";
}
/**
* Sets the port Jetty uses for the default connector.
*
* @param jettyPort The port Jetty will use for the default connector
*/
public void setJettyPort(final int jettyPort)
{
this.jettyPort = jettyPort;
}
/**
* Executes this Ant task. The build flow is being stopped until Jetty
* server stops.
*
* @throws BuildException if unable to build
*/
@Override
public void execute() throws BuildException
{
TaskLog.log("Configuring Jetty for project: " + getProject().getName());
setSystemProperties();
List<Connector> connectorsList = null;
if (connectors != null)
connectorsList = connectors.getConnectors();
else
connectorsList = new Connectors(jettyPort, 30000).getDefaultConnectors();
List<LoginService> loginServicesList = (loginServices != null ? loginServices.getLoginServices() : new ArrayList<LoginService>());
ServerProxyImpl server = new ServerProxyImpl();
server.setConnectors(connectorsList);
server.setLoginServices(loginServicesList);
server.setRequestLog(requestLog);
server.setJettyXml(jettyXml);
server.setDaemon(daemon);
server.setStopPort(stopPort);
server.setStopKey(stopKey);
server.setContextHandlers(contextHandlers);
server.setTempDirectory(tempDirectory);
server.setScanIntervalSecs(scanIntervalSeconds);
try
{
for (WebAppContext webapp : webapps)
{
server.addWebApplication((AntWebAppContext)webapp);
}
}
catch (Exception e)
{
throw new BuildException(e);
}
server.start();
}
public int getStopPort()
{
return stopPort;
}
public void setStopPort(int stopPort)
{
this.stopPort = stopPort;
TaskLog.log("stopPort=" + stopPort);
}
public String getStopKey()
{
return stopKey;
}
public void setStopKey(String stopKey)
{
this.stopKey = stopKey;
TaskLog.log("stopKey=" + stopKey);
}
/**
* @return the daemon
*/
public boolean isDaemon()
{
return daemon;
}
/**
* @param daemon the daemon to set
*/
public void setDaemon(boolean daemon)
{
this.daemon = daemon;
TaskLog.log("Daemon=" + daemon);
}
public int getScanIntervalSeconds()
{
return scanIntervalSeconds;
}
public void setScanIntervalSeconds(int secs)
{
scanIntervalSeconds = secs;
TaskLog.log("scanIntervalSecs=" + secs);
}
/**
* Sets the system properties.
*/
private void setSystemProperties()
{
if (systemProperties != null)
{
Iterator propertiesIterator = systemProperties.getSystemProperties().iterator();
while (propertiesIterator.hasNext())
{
Property property = ((Property)propertiesIterator.next());
SystemProperties.setIfNotSetAlready(property);
}
}
}
}

View File

@ -1,114 +0,0 @@
//
// ========================================================================
// Copyright (c) 1995 Mort Bay Consulting Pty Ltd and others.
//
// This program and the accompanying materials are made available under the
// terms of the Eclipse Public License v. 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
// which is available at https://www.apache.org/licenses/LICENSE-2.0.
//
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
// ========================================================================
//
package org.eclipse.jetty.ee9.ant;
import java.io.InputStreamReader;
import java.io.LineNumberReader;
import java.io.OutputStream;
import java.net.ConnectException;
import java.net.InetAddress;
import java.net.Socket;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Task;
import org.eclipse.jetty.ee9.ant.utils.TaskLog;
/**
* JettyStopTask
*/
public class JettyStopTask extends Task
{
private int stopPort;
private String stopKey;
private int stopWait;
/**
*
*/
public JettyStopTask()
{
TaskLog.setTask(this);
}
@Override
public void execute() throws BuildException
{
try
{
Socket s = new Socket(InetAddress.getByName("127.0.0.1"), stopPort);
if (stopWait > 0)
s.setSoTimeout(stopWait * 1000);
try
{
OutputStream out = s.getOutputStream();
out.write((stopKey + "\r\nstop\r\n").getBytes());
out.flush();
if (stopWait > 0)
{
TaskLog.log("Waiting" + (stopWait > 0 ? (" " + stopWait + "sec") : "") + " for jetty to stop");
LineNumberReader lin = new LineNumberReader(new InputStreamReader(s.getInputStream()));
String response = lin.readLine();
if ("Stopped".equals(response))
System.err.println("Stopped");
}
}
finally
{
s.close();
}
}
catch (ConnectException e)
{
TaskLog.log("Jetty not running!");
}
catch (Exception e)
{
TaskLog.log(e.getMessage());
}
}
public int getStopPort()
{
return stopPort;
}
public void setStopPort(int stopPort)
{
this.stopPort = stopPort;
}
public String getStopKey()
{
return stopKey;
}
public void setStopKey(String stopKey)
{
this.stopKey = stopKey;
}
public int getStopWait()
{
return stopWait;
}
public void setStopWait(int stopWait)
{
this.stopWait = stopWait;
}
}

View File

@ -1,491 +0,0 @@
//
// ========================================================================
// Copyright (c) 1995-2012 Sabre Holdings and others.
// ------------------------------------------------------------------------
// This program and the accompanying materials are made available under the
// terms of the Eclipse Public License v. 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
// which is available at https://www.apache.org/licenses/LICENSE-2.0.
//
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
// ========================================================================
//
package org.eclipse.jetty.ee9.ant;
import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import org.eclipse.jetty.ee9.ant.types.Connector;
import org.eclipse.jetty.ee9.ant.types.ContextHandlers;
import org.eclipse.jetty.ee9.ant.utils.ServerProxy;
import org.eclipse.jetty.ee9.ant.utils.TaskLog;
import org.eclipse.jetty.ee9.security.LoginService;
import org.eclipse.jetty.server.RequestLog;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.ServerConnector;
import org.eclipse.jetty.server.ShutdownMonitor;
import org.eclipse.jetty.server.handler.ContextHandler;
import org.eclipse.jetty.server.handler.ContextHandlerCollection;
import org.eclipse.jetty.server.handler.DefaultHandler;
import org.eclipse.jetty.server.handler.HandlerCollection;
import org.eclipse.jetty.util.Scanner;
import org.eclipse.jetty.util.resource.PathResource;
import org.eclipse.jetty.util.resource.Resource;
import org.eclipse.jetty.xml.XmlConfiguration;
import org.xml.sax.SAXException;
/**
* A proxy class for interaction with Jetty server object. Used to have some
* level of abstraction over standard Jetty classes.
*/
public class ServerProxyImpl implements ServerProxy
{
/**
* Proxied Jetty server object.
*/
private Server server;
/**
* Temporary files directory.
*/
private File tempDirectory;
/**
* Collection of context handlers (web application contexts).
*/
private ContextHandlerCollection contexts;
/**
* Location of jetty.xml file.
*/
private File jettyXml;
/**
* List of connectors.
*/
private List<Connector> connectors;
/**
* Request logger.
*/
private RequestLog requestLog;
/**
* User realms.
*/
private List<LoginService> loginServices;
/**
* List of added web applications.
*/
private List<AntWebAppContext> webApplications = new ArrayList<AntWebAppContext>();
/**
* other contexts to deploy
*/
private ContextHandlers contextHandlers;
/**
* scan interval for changed files
*/
private int scanIntervalSecs;
/**
* port to listen for stop command
*/
private int stopPort;
/**
* security key for stop command
*/
private String stopKey;
/**
* wait for all jetty threads to exit or continue
*/
private boolean daemon;
private boolean configured = false;
/**
* WebAppScannerListener
*
* Handle notifications that files we are interested in have changed
* during execution.
*/
public static class WebAppScannerListener implements Scanner.BulkListener
{
AntWebAppContext awc;
public WebAppScannerListener(AntWebAppContext awc)
{
this.awc = awc;
}
@Override
public void filesChanged(Set<String> changedFileNames)
{
boolean isScanned = false;
try
{
Iterator<String> itor = changedFileNames.iterator();
while (!isScanned && itor.hasNext())
{
isScanned = awc.isScanned(Resource.newResource(itor.next()).getFile());
}
if (isScanned)
{
awc.stop();
awc.start();
}
}
catch (Exception e)
{
TaskLog.log(e.getMessage());
}
}
}
/**
* Default constructor. Creates a new Jetty server with a standard connector
* listening on a given port.
*/
public ServerProxyImpl()
{
server = new Server();
server.setStopAtShutdown(true);
}
@Override
public void addWebApplication(AntWebAppContext webApp)
{
webApplications.add(webApp);
}
public int getStopPort()
{
return stopPort;
}
public void setStopPort(int stopPort)
{
this.stopPort = stopPort;
}
public String getStopKey()
{
return stopKey;
}
public void setStopKey(String stopKey)
{
this.stopKey = stopKey;
}
public File getJettyXml()
{
return jettyXml;
}
public void setJettyXml(File jettyXml)
{
this.jettyXml = jettyXml;
}
public List<Connector> getConnectors()
{
return connectors;
}
public void setConnectors(List<Connector> connectors)
{
this.connectors = connectors;
}
public RequestLog getRequestLog()
{
return requestLog;
}
public void setRequestLog(RequestLog requestLog)
{
this.requestLog = requestLog;
}
public List<LoginService> getLoginServices()
{
return loginServices;
}
public void setLoginServices(List<LoginService> loginServices)
{
this.loginServices = loginServices;
}
public List<AntWebAppContext> getWebApplications()
{
return webApplications;
}
public void setWebApplications(List<AntWebAppContext> webApplications)
{
this.webApplications = webApplications;
}
public File getTempDirectory()
{
return tempDirectory;
}
public void setTempDirectory(File tempDirectory)
{
this.tempDirectory = tempDirectory;
}
@Override
public void start()
{
try
{
configure();
configureWebApps();
server.start();
System.setProperty("jetty.ant.server.port", "" + ((ServerConnector)server.getConnectors()[0]).getLocalPort());
String host = ((ServerConnector)server.getConnectors()[0]).getHost();
if (host == null)
{
System.setProperty("jetty.ant.server.host", "localhost");
}
else
{
System.setProperty("jetty.ant.server.host", host);
}
startScanners();
TaskLog.log("Jetty AntTask Started");
if (!daemon)
server.join();
}
catch (InterruptedException e)
{
new RuntimeException(e);
}
catch (Exception e)
{
e.printStackTrace();
new RuntimeException(e);
}
}
@Override
public Object getProxiedObject()
{
return server;
}
/**
* @return the daemon
*/
public boolean isDaemon()
{
return daemon;
}
/**
* @param daemon the daemon to set
*/
public void setDaemon(boolean daemon)
{
this.daemon = daemon;
}
/**
* @return the contextHandlers
*/
public ContextHandlers getContextHandlers()
{
return contextHandlers;
}
/**
* @param contextHandlers the contextHandlers to set
*/
public void setContextHandlers(ContextHandlers contextHandlers)
{
this.contextHandlers = contextHandlers;
}
public int getScanIntervalSecs()
{
return scanIntervalSecs;
}
public void setScanIntervalSecs(int scanIntervalSecs)
{
this.scanIntervalSecs = scanIntervalSecs;
}
/**
* Configures Jetty server before adding any web applications to it.
*/
private void configure()
{
if (configured)
return;
configured = true;
if (stopPort > 0 && stopKey != null)
{
ShutdownMonitor monitor = ShutdownMonitor.getInstance();
monitor.setPort(stopPort);
monitor.setKey(stopKey);
monitor.setExitVm(false);
}
if (tempDirectory != null && !tempDirectory.exists())
tempDirectory.mkdirs();
// Applies external configuration via jetty.xml
applyJettyXml();
// Configures connectors for this server instance.
if (connectors != null)
{
for (Connector c : connectors)
{
ServerConnector jc = new ServerConnector(server);
jc.setPort(c.getPort());
jc.setIdleTimeout(c.getMaxIdleTime());
server.addConnector(jc);
}
}
// Configures login services
if (loginServices != null)
{
for (LoginService ls : loginServices)
{
server.addBean(ls);
}
}
// Does not cache resources, to prevent Windows from locking files
Resource.setDefaultUseCaches(false);
// Set default server handlers
configureHandlers();
}
/**
*
*/
private void configureHandlers()
{
if (requestLog != null)
server.setRequestLog(requestLog);
contexts = server.getChildHandlerByClass(ContextHandlerCollection.class);
if (contexts == null)
{
contexts = new ContextHandlerCollection();
HandlerCollection handlers = server.getChildHandlerByClass(HandlerCollection.class);
if (handlers == null)
server.setHandler(contexts);
else
handlers.addHandler(contexts);
}
//if there are any extra contexts to deploy
if (contextHandlers != null && contextHandlers.getContextHandlers() != null)
{
for (ContextHandler c : contextHandlers.getContextHandlers())
{
contexts.addHandler(c);
}
}
}
/**
* Applies jetty.xml configuration to the Jetty server instance.
*/
private void applyJettyXml()
{
if (jettyXml != null && jettyXml.exists())
{
TaskLog.log("Configuring jetty from xml configuration file = " + jettyXml.getAbsolutePath());
XmlConfiguration configuration;
try
{
configuration = new XmlConfiguration(new PathResource(jettyXml));
configuration.configure(server);
}
catch (MalformedURLException e)
{
throw new RuntimeException(e);
}
catch (SAXException e)
{
throw new RuntimeException(e);
}
catch (IOException e)
{
throw new RuntimeException(e);
}
catch (Exception e)
{
throw new RuntimeException(e);
}
}
}
/**
* Starts web applications' scanners.
*/
private void startScanners() throws Exception
{
for (AntWebAppContext awc : webApplications)
{
if (scanIntervalSecs <= 0)
return;
TaskLog.log("Web application '" + awc + "': starting scanner at interval of " + scanIntervalSecs + " seconds.");
Scanner.Listener changeListener = new WebAppScannerListener(awc);
Scanner scanner = new Scanner();
scanner.setScanInterval(scanIntervalSecs);
scanner.addListener(changeListener);
scanner.setScanDirs(awc.getScanFiles());
scanner.setReportExistingFilesOnStartup(false);
scanner.start();
}
}
/**
*
*/
private void configureWebApps()
{
for (AntWebAppContext awc : webApplications)
{
awc.setAttribute(AntWebAppContext.BASETEMPDIR, tempDirectory);
if (contexts != null)
contexts.addHandler(awc);
}
}
}

View File

@ -1,18 +0,0 @@
//
// ========================================================================
// Copyright (c) 1995 Mort Bay Consulting Pty Ltd and others.
//
// This program and the accompanying materials are made available under the
// terms of the Eclipse Public License v. 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
// which is available at https://www.apache.org/licenses/LICENSE-2.0.
//
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
// ========================================================================
//
/**
* Jetty Ant : Ant Tasks and Configuration
*/
package org.eclipse.jetty.ee9.ant;

View File

@ -1,42 +0,0 @@
//
// ========================================================================
// Copyright (c) 1995 Mort Bay Consulting Pty Ltd and others.
//
// This program and the accompanying materials are made available under the
// terms of the Eclipse Public License v. 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
// which is available at https://www.apache.org/licenses/LICENSE-2.0.
//
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
// ========================================================================
//
package org.eclipse.jetty.ee9.ant.types;
public class Attribute
{
String name;
String value;
public void setName(String name)
{
this.name = name;
}
public void setValue(String value)
{
this.value = value;
}
public String getName()
{
return name;
}
public String getValue()
{
return value;
}
}

View File

@ -1,33 +0,0 @@
//
// ========================================================================
// Copyright (c) 1995 Mort Bay Consulting Pty Ltd and others.
//
// This program and the accompanying materials are made available under the
// terms of the Eclipse Public License v. 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
// which is available at https://www.apache.org/licenses/LICENSE-2.0.
//
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
// ========================================================================
//
package org.eclipse.jetty.ee9.ant.types;
import java.util.ArrayList;
import java.util.List;
public class Attributes
{
List<Attribute> _attributes = new ArrayList<Attribute>();
public void addAttribute(Attribute attr)
{
_attributes.add(attr);
}
public List<Attribute> getAttributes()
{
return _attributes;
}
}

View File

@ -1,54 +0,0 @@
//
// ========================================================================
// Copyright (c) 1995 Mort Bay Consulting Pty Ltd and others.
//
// This program and the accompanying materials are made available under the
// terms of the Eclipse Public License v. 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
// which is available at https://www.apache.org/licenses/LICENSE-2.0.
//
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
// ========================================================================
//
package org.eclipse.jetty.ee9.ant.types;
/**
* Connector
*/
public class Connector
{
private int port;
private int maxIdleTime;
public Connector()
{
}
public Connector(int port, int maxIdleTime)
{
this.port = port;
this.maxIdleTime = maxIdleTime;
}
public int getPort()
{
return port;
}
public void setPort(int port)
{
this.port = port;
}
public int getMaxIdleTime()
{
return maxIdleTime;
}
public void setMaxIdleTime(int maxIdleTime)
{
this.maxIdleTime = maxIdleTime;
}
}

View File

@ -1,76 +0,0 @@
//
// ========================================================================
// Copyright (c) 1995-2012 Sabre Holdings and others.
// ------------------------------------------------------------------------
// This program and the accompanying materials are made available under the
// terms of the Eclipse Public License v. 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
// which is available at https://www.apache.org/licenses/LICENSE-2.0.
//
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
// ========================================================================
//
package org.eclipse.jetty.ee9.ant.types;
import java.util.ArrayList;
import java.util.List;
/**
* Specifies a jetty configuration <code>&lt;connectors/&gt;</code> element for Ant build file.
*/
public class Connectors
{
private List<Connector> connectors = new ArrayList<Connector>();
private List<Connector> defaultConnectors = new ArrayList<Connector>();
/**
* Default constructor.
*/
public Connectors()
{
this(8080, 30000);
}
/**
* Constructor.
*
* @param port The port that the default connector will listen on
* @param maxIdleTime The maximum idle time for the default connector
*/
public Connectors(int port, int maxIdleTime)
{
defaultConnectors.add(new Connector(port, maxIdleTime));
}
/**
* Adds a connector to the list of connectors to deploy.
*
* @param connector A connector to add to the list
*/
public void add(Connector connector)
{
connectors.add(connector);
}
/**
* Returns the list of known connectors to deploy.
*
* @return The list of known connectors
*/
public List<Connector> getConnectors()
{
return connectors;
}
/**
* Gets the default list of connectors to deploy when no connectors
* were explicitly added to the list.
*
* @return The list of default connectors
*/
public List<Connector> getDefaultConnectors()
{
return defaultConnectors;
}
}

View File

@ -1,37 +0,0 @@
//
// ========================================================================
// Copyright (c) 1995-2012 Sabre Holdings and others.
// ------------------------------------------------------------------------
// This program and the accompanying materials are made available under the
// terms of the Eclipse Public License v. 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
// which is available at https://www.apache.org/licenses/LICENSE-2.0.
//
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
// ========================================================================
//
package org.eclipse.jetty.ee9.ant.types;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.jetty.server.handler.ContextHandler;
/**
* Specifies <code>&lt;contextHandlers/&gt;</code> element in web app configuration.
*/
public class ContextHandlers
{
private List<ContextHandler> contextHandlers = new ArrayList<ContextHandler>();
public void add(ContextHandler handler)
{
contextHandlers.add(handler);
}
public List<ContextHandler> getContextHandlers()
{
return contextHandlers;
}
}

View File

@ -1,91 +0,0 @@
//
// ========================================================================
// Copyright (c) 1995-2012 Sabre Holdings and others.
// ------------------------------------------------------------------------
// This program and the accompanying materials are made available under the
// terms of the Eclipse Public License v. 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
// which is available at https://www.apache.org/licenses/LICENSE-2.0.
//
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
// ========================================================================
//
package org.eclipse.jetty.ee9.ant.types;
import java.io.File;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.apache.tools.ant.DirectoryScanner;
/**
* Describes set of files matched by <code>&lt;fileset/&gt;</code> elements in ant configuration
* file. It is used to group application classes, libraries, and scannedTargets
* elements.
*/
public class FileMatchingConfiguration
{
private List<DirectoryScanner> directoryScanners;
public FileMatchingConfiguration()
{
this.directoryScanners = new ArrayList<>();
}
/**
* @param directoryScanner new directory scanner retrieved from the
* <code>&lt;fileset/&gt;</code> element.
*/
public void addDirectoryScanner(DirectoryScanner directoryScanner)
{
this.directoryScanners.add(directoryScanner);
}
/**
* @return a list of base directories denoted by a list of directory
* scanners.
*/
public List<File> getBaseDirectories()
{
List<File> baseDirs = new ArrayList<>();
Iterator<DirectoryScanner> scanners = directoryScanners.iterator();
while (scanners.hasNext())
{
DirectoryScanner scanner = (DirectoryScanner)scanners.next();
baseDirs.add(scanner.getBasedir());
}
return baseDirs;
}
/**
* Checks if passed file is scanned by any of the directory scanners.
*
* @param pathToFile a fully qualified path to tested file.
* @return true if so, false otherwise.
*/
public boolean isIncluded(String pathToFile)
{
Iterator<DirectoryScanner> scanners = directoryScanners.iterator();
while (scanners.hasNext())
{
DirectoryScanner scanner = (DirectoryScanner)scanners.next();
scanner.scan();
String[] includedFiles = scanner.getIncludedFiles();
for (int i = 0; i < includedFiles.length; i++)
{
File includedFile = new File(scanner.getBasedir(), includedFiles[i]);
if (pathToFile.equalsIgnoreCase(includedFile.getAbsolutePath()))
{
return true;
}
}
}
return false;
}
}

View File

@ -1,37 +0,0 @@
//
// ========================================================================
// Copyright (c) 1995-2012 Sabre Holdings and others.
// ------------------------------------------------------------------------
// This program and the accompanying materials are made available under the
// terms of the Eclipse Public License v. 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
// which is available at https://www.apache.org/licenses/LICENSE-2.0.
//
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
// ========================================================================
//
package org.eclipse.jetty.ee9.ant.types;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.jetty.ee9.security.LoginService;
/**
* Specifies a jetty configuration &lt;loginServices/&gt; element for Ant build file.
*/
public class LoginServices
{
private List<LoginService> loginServices = new ArrayList<LoginService>();
public void add(LoginService service)
{
loginServices.add(service);
}
public List<LoginService> getLoginServices()
{
return loginServices;
}
}

View File

@ -1,59 +0,0 @@
//
// ========================================================================
// Copyright (c) 1995-2012 Sabre Holdings and others.
// ------------------------------------------------------------------------
// This program and the accompanying materials are made available under the
// terms of the Eclipse Public License v. 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
// which is available at https://www.apache.org/licenses/LICENSE-2.0.
//
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
// ========================================================================
//
package org.eclipse.jetty.ee9.ant.types;
import java.util.ArrayList;
import java.util.List;
import org.apache.tools.ant.taskdefs.Property;
import org.eclipse.jetty.ee9.ant.utils.TaskLog;
/**
* SystemProperties
* <p>
* Ant &lt;systemProperties/&gt; tag definition.
*/
public class SystemProperties
{
private List systemProperties = new ArrayList();
public List getSystemProperties()
{
return systemProperties;
}
public void addSystemProperty(Property property)
{
systemProperties.add(property);
}
/**
* Set a System.property with this value if it is not already set.
*
* @param property the property to test
* @return true if property has been set
*/
public static boolean setIfNotSetAlready(Property property)
{
if (System.getProperty(property.getName()) == null)
{
System.setProperty(property.getName(), (property.getValue() == null ? "" : property.getValue()));
TaskLog.log("Setting property '" + property.getName() + "' to value '" + property.getValue() + "'");
return true;
}
return false;
}
}

View File

@ -1,18 +0,0 @@
//
// ========================================================================
// Copyright (c) 1995 Mort Bay Consulting Pty Ltd and others.
//
// This program and the accompanying materials are made available under the
// terms of the Eclipse Public License v. 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
// which is available at https://www.apache.org/licenses/LICENSE-2.0.
//
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
// ========================================================================
//
/**
* Jetty Ant : Ant Wrappers of Jetty Internals
*/
package org.eclipse.jetty.ee9.ant.types;

View File

@ -1,34 +0,0 @@
//
// ========================================================================
// Copyright (c) 1995-2012 Sabre Holdings and others.
// ------------------------------------------------------------------------
// This program and the accompanying materials are made available under the
// terms of the Eclipse Public License v. 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
// which is available at https://www.apache.org/licenses/LICENSE-2.0.
//
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
// ========================================================================
//
package org.eclipse.jetty.ee9.ant.utils;
import org.eclipse.jetty.ee9.ant.AntWebAppContext;
public interface ServerProxy
{
/**
* Adds a new web application to this server.
*
* @param awc a AntWebAppContext object.
*/
public void addWebApplication(AntWebAppContext awc);
/**
* Starts this server.
*/
public void start();
public Object getProxiedObject();
}

View File

@ -1,52 +0,0 @@
//
// ========================================================================
// Copyright (c) 1995-2012 Sabre Holdings and others.
// ------------------------------------------------------------------------
// This program and the accompanying materials are made available under the
// terms of the Eclipse Public License v. 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
// which is available at https://www.apache.org/licenses/LICENSE-2.0.
//
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
// ========================================================================
//
package org.eclipse.jetty.ee9.ant.utils;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.apache.tools.ant.Task;
/**
* Provides logging functionality for classes without access to the Ant project
* variable.
*/
public class TaskLog
{
private static Task task;
private static final SimpleDateFormat format = new SimpleDateFormat(
"yyyy-MM-dd HH:mm:ss.SSS");
public static void setTask(Task task)
{
TaskLog.task = task;
}
public static void log(String message)
{
task.log(message);
}
public static void logWithTimestamp(String message)
{
String date;
synchronized (format)
{
date = format.format(new Date());
}
task.log(date + ": " + message);
}
}

View File

@ -1,18 +0,0 @@
//
// ========================================================================
// Copyright (c) 1995 Mort Bay Consulting Pty Ltd and others.
//
// This program and the accompanying materials are made available under the
// terms of the Eclipse Public License v. 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
// which is available at https://www.apache.org/licenses/LICENSE-2.0.
//
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
// ========================================================================
//
/**
* Jetty Ant : Utility Classes
*/
package org.eclipse.jetty.ee9.ant.utils;

View File

@ -1,2 +0,0 @@
org.eclipse.jetty.ee9.ant.AntWebInfConfiguration
org.eclipse.jetty.ee9.ant.AntWebXmlConfiguration

View File

@ -1,2 +0,0 @@
jetty.run=org.eclipse.jetty.ee9.ant.JettyRunTask
jetty.stop=org.eclipse.jetty.ee9.ant.JettyStopTask

View File

@ -1,39 +0,0 @@
<!-- =======================================================================================-->
<!-- Build file for running the test-jetty-webapp from the jetty distro. -->
<!-- -->
<!-- You will need to have a full jetty-home available unpacked on your local file -->
<!-- system. We will refer to the top level directory of this distribution as $JETTY_HOME. -->
<!-- -->
<!-- To use: -->
<!-- * mkdir test-jetty-ant -->
<!-- * cp this file to test-jetty-ant -->
<!-- * cd test-jetty-ant; mkdir jetty-lib; mkdir jetty-temp -->
<!-- * copy all jars from $JETTY_HOME/lib and all subdirs flatly into ./jetty-lib -->
<!-- * copy the jetty-ant jar into ./jetty-lib -->
<!-- * copy the test.war from $JETTY_HOME/webapps.demo dir -->
<!-- -->
<!-- To run: -->
<!-- ant jetty.run -->
<!-- =======================================================================================-->
<project name="Jetty-Ant integration test" basedir=".">
<path id="jetty.plugin.classpath">
<fileset dir="jetty-lib" includes="*.jar"/>
</path>
<taskdef classpathref="jetty.plugin.classpath" resource="tasks.properties" loaderref="jetty.loader" />
<typedef name="hashLoginService" classname="org.eclipse.jetty.security.HashLoginService"
classpathref="jetty.plugin.classpath" loaderref="jetty.loader" />
<target name="jetty.run">
<jetty.run tempDirectory="jetty-temp">
<loginServices>
<hashLoginService name="Test Realm" config="realm.properties"/>
</loginServices>
<webApp war="test.war" contextpath="/test" >
<attributes>
<attribute name="org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern" value=".*/jetty-jakarta-servlet-api-[^/]*\.jar$"/>
</attributes>
</webApp>
</jetty.run>
</target>
</project>

View File

@ -1,289 +0,0 @@
//
// ========================================================================
// Copyright (c) 1995 Mort Bay Consulting Pty Ltd and others.
//
// This program and the accompanying materials are made available under the
// terms of the Eclipse Public License v. 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
// which is available at https://www.apache.org/licenses/LICENSE-2.0.
//
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
// ========================================================================
//
package org.eclipse.jetty.ee9.ant;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PipedInputStream;
import java.io.PipedOutputStream;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.tools.ant.DefaultLogger;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.ProjectHelper;
import org.eclipse.jetty.toolchain.test.IO;
import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
public class AntBuild
{
private Thread _process;
private String _ant;
private int _port;
private String _host;
public AntBuild(String ant)
{
_ant = ant;
}
private class AntBuildProcess implements Runnable
{
List<String[]> connList;
@Override
public void run()
{
File buildFile = new File(_ant);
Project antProject = new Project();
try
{
antProject.setBaseDir(MavenTestingUtils.getBaseDir());
antProject.setUserProperty("ant.file", buildFile.getAbsolutePath());
DefaultLogger logger = new DefaultLogger();
ConsoleParser parser = new ConsoleParser();
//connList = parser.newPattern(".*([0-9]+\\.[0-9]*\\.[0-9]*\\.[0-9]*):([0-9]*)",1);
connList = parser.newPattern("Jetty AntTask Started", 1);
PipedOutputStream pos = new PipedOutputStream();
PipedInputStream pis = new PipedInputStream(pos);
PipedOutputStream pose = new PipedOutputStream();
PipedInputStream pise = new PipedInputStream(pose);
startPump("STDOUT", parser, pis);
startPump("STDERR", parser, pise);
logger.setErrorPrintStream(new PrintStream(pos));
logger.setOutputPrintStream(new PrintStream(pose));
logger.setMessageOutputLevel(Project.MSG_VERBOSE);
antProject.addBuildListener(logger);
antProject.fireBuildStarted();
antProject.init();
ProjectHelper helper = ProjectHelper.getProjectHelper();
antProject.addReference("ant.projectHelper", helper);
helper.parse(antProject, buildFile);
antProject.executeTarget("jetty.run");
parser.waitForDone(10000, TimeUnit.MILLISECONDS);
}
catch (Exception e)
{
antProject.fireBuildFinished(e);
}
}
public void waitForStarted() throws Exception
{
while (connList == null || connList.isEmpty())
{
Thread.sleep(10);
}
}
}
public void start() throws Exception
{
System.out.println("Starting Ant Build ...");
AntBuildProcess abp = new AntBuildProcess();
_process = new Thread(abp);
_process.start();
abp.waitForStarted();
// once this has returned we should have the connection info we need
//_host = abp.getConnectionList().get(0)[0];
//_port = Integer.parseInt(abp.getConnectionList().get(0)[1]);
}
public int getJettyPort()
{
return Integer.parseInt(System.getProperty("jetty.ant.server.port"));
}
public String getJettyHost()
{
return System.getProperty("jetty.ant.server.host");
}
/**
* Stop the jetty server
*/
public void stop()
{
System.out.println("Stopping Ant Build ...");
_process.interrupt();
}
private static class ConsoleParser
{
private List<ConsolePattern> patterns = new ArrayList<ConsolePattern>();
private CountDownLatch latch;
private int count;
public List<String[]> newPattern(String exp, int cnt)
{
ConsolePattern pat = new ConsolePattern(exp, cnt);
patterns.add(pat);
count += cnt;
return pat.getMatches();
}
public void parse(String line)
{
for (ConsolePattern pat : patterns)
{
Matcher mat = pat.getMatcher(line);
if (mat.find())
{
int num = 0;
int count = mat.groupCount();
String[] match = new String[count];
while (num++ < count)
{
match[num - 1] = mat.group(num);
}
pat.getMatches().add(match);
if (pat.getCount() > 0)
{
getLatch().countDown();
}
}
}
}
public void waitForDone(long timeout, TimeUnit unit) throws InterruptedException
{
getLatch().await(timeout, unit);
}
private CountDownLatch getLatch()
{
synchronized (this)
{
if (latch == null)
{
latch = new CountDownLatch(count);
}
}
return latch;
}
}
private static class ConsolePattern
{
private Pattern pattern;
private List<String[]> matches;
private int count;
ConsolePattern(String exp, int cnt)
{
pattern = Pattern.compile(exp);
matches = new ArrayList<String[]>();
count = cnt;
}
public Matcher getMatcher(String line)
{
return pattern.matcher(line);
}
public List<String[]> getMatches()
{
return matches;
}
public int getCount()
{
return count;
}
}
private void startPump(String mode, ConsoleParser parser, InputStream inputStream)
{
ConsoleStreamer pump = new ConsoleStreamer(mode, inputStream);
pump.setParser(parser);
Thread thread = new Thread(pump, "ConsoleStreamer/" + mode);
thread.start();
}
/**
* Simple streamer for the console output from a Process
*/
private static class ConsoleStreamer implements Runnable
{
private String mode;
private BufferedReader reader;
private ConsoleParser parser;
public ConsoleStreamer(String mode, InputStream is)
{
this.mode = mode;
this.reader = new BufferedReader(new InputStreamReader(is));
}
public void setParser(ConsoleParser connector)
{
this.parser = connector;
}
@Override
public void run()
{
String line;
//System.out.printf("ConsoleStreamer/%s initiated%n",mode);
try
{
while ((line = reader.readLine()) != (null))
{
if (parser != null)
{
parser.parse(line);
}
System.out.println("[" + mode + "] " + line);
}
}
catch (IOException ignore)
{
/* ignore */
}
finally
{
IO.close(reader);
}
//System.out.printf("ConsoleStreamer/%s finished%n",mode);
}
}
}

View File

@ -1,64 +0,0 @@
//
// ========================================================================
// Copyright (c) 1995 Mort Bay Consulting Pty Ltd and others.
//
// This program and the accompanying materials are made available under the
// terms of the Eclipse Public License v. 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
// which is available at https://www.apache.org/licenses/LICENSE-2.0.
//
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
// ========================================================================
//
package org.eclipse.jetty.ee9.ant;
import java.net.HttpURLConnection;
import java.net.URI;
import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
import org.junit.jupiter.api.Test;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
public class JettyAntTaskTest
{
@Test
public void testConnectorTask() throws Exception
{
AntBuild build = new AntBuild(MavenTestingUtils.getTestResourceFile("connector-test.xml").getAbsolutePath());
build.start();
URI uri = new URI("http://" + build.getJettyHost() + ":" + build.getJettyPort());
HttpURLConnection connection = (HttpURLConnection)uri.toURL().openConnection();
connection.connect();
assertThat("response code is 404", connection.getResponseCode(), is(404));
build.stop();
}
@Test
public void testWebApp() throws Exception
{
AntBuild build = new AntBuild(MavenTestingUtils.getTestResourceFile("webapp-test.xml").getAbsolutePath());
build.start();
URI uri = new URI("http://" + build.getJettyHost() + ":" + build.getJettyPort() + "/");
HttpURLConnection connection = (HttpURLConnection)uri.toURL().openConnection();
connection.connect();
assertThat("response code is 200", connection.getResponseCode(), is(200));
System.err.println("Stop build!");
build.stop();
}
}

View File

@ -1,19 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<project name="Jetty-Ant integration test" basedir=".">
<path id="jetty.plugin.classpath">
<fileset dir="target/test-lib" includes="*.jar"/>
</path>
<taskdef classpathref="jetty.plugin.classpath" resource="tasks.properties" loaderref="jetty.loader" />
<typedef name="connector" classname="org.eclipse.jetty.ee9.ant.types.Connector"
classpathref="jetty.plugin.classpath" loaderref="jetty.loader" />
<target name="jetty.run">
<jetty.run>
<connectors>
<connector port="0"/>
</connectors>
</jetty.run>
</target>
</project>

View File

@ -1,28 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE taglib
PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN"
"http://java.sun.com/dtd/web-jsptaglibrary_1_2.dtd">
<taglib>
<tlib-version>1.0</tlib-version>
<jsp-version>1.2</jsp-version>
<short-name>acme</short-name>
<uri>http://www.acme.com/taglib</uri>
<description>taglib example</description>
<listener>
<listener-class>com.acme.TagListener</listener-class>
</listener>
<tag>
<name>date</name>
<tag-class>com.acme.DateTag</tag-class>
<body-content>TAGDEPENDENT</body-content>
<description>Display Date</description>
<attribute>
<name>tz</name>
<required>false</required>
</attribute>
</tag>
</taglib>

View File

@ -1,35 +0,0 @@
<?xml version="1.0" encoding="UTF-8" ?>
<taglib xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee web-jsptaglibrary_2_0.xsd"
version="2.0">
<description>Acme JSP2 tags</description>
<tlib-version>1.0</tlib-version>
<short-name>acme2</short-name>
<uri>http://www.acme.com/taglib2</uri>
<tag>
<description>Simple Date formatting</description>
<name>date2</name>
<tag-class>com.acme.Date2Tag</tag-class>
<body-content>scriptless</body-content>
<variable>
<description>Day of the Month</description>
<name-given>day</name-given>
</variable>
<variable>
<description>Month of the Year</description>
<name-given>month</name-given>
</variable>
<variable>
<description>Year</description>
<name-given>year</name-given>
</variable>
<attribute>
<name>format</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>
</taglib>

View File

@ -1,17 +0,0 @@
<%--
- Copyright (c) 2002 The Apache Software Foundation. All rights
- reserved.
--%>
<%@ attribute name="color" %>
<%@ attribute name="bgcolor" %>
<%@ attribute name="title" %>
<table border="1" bgcolor="${color}">
<tr>
<td><b>${title}</b></td>
</tr>
<tr>
<td bgcolor="${bgcolor}">
<jsp:doBody/>
</td>
</tr>
</table>

View File

@ -1,28 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<web-app
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5">
<display-name>Test WebApp</display-name>
<context-param>
<param-name>org.eclipse.jetty.server.context.ManagedAttributes</param-name>
<param-value>QoSFilter,TransparentProxy.ThreadPool,TransparentProxy.HttpClient</param-value>
</context-param>
<servlet>
<servlet-name>foo.jsp</servlet-name>
<jsp-file>/jsp/foo/foo.jsp</jsp-file>
</servlet>
<servlet-mapping>
<servlet-name>foo.jsp</servlet-name>
<url-pattern>/jsp/foo/</url-pattern>
</servlet-mapping>
</web-app>

View File

@ -1,5 +0,0 @@
<html>
<body>
<h1>INDEX!</h1>
</body>
</html>

View File

@ -1,15 +0,0 @@
<html>
<%@ page session="true"%>
<body>
<jsp:useBean id='counter' scope='session' class='com.acme.Counter' type="com.acme.Counter" />
<h1>JSP1.2 Beans: 1</h1>
Counter accessed <jsp:getProperty name="counter" property="count"/> times.<br/>
Counter last accessed by <jsp:getProperty name="counter" property="last"/><br/>
<jsp:setProperty name="counter" property="last" value="<%= request.getRequestURI()%>"/>
<a href="bean2.jsp">Goto bean2.jsp</a>
</body>
</html>

View File

@ -1,15 +0,0 @@
<html>
<%@ page session="true"%>
<body>
<jsp:useBean id='counter' scope='session' class='com.acme.Counter' type="com.acme.Counter" />
<h1>JSP1.2 Beans: 2</h1>
Counter accessed <jsp:getProperty name="counter" property="count"/> times.<br/>
Counter last accessed by <jsp:getProperty name="counter" property="last"/><br/>
<jsp:setProperty name="counter" property="last" value="<%= request.getRequestURI()%>"/>
<a href="bean1.jsp">Goto bean1.jsp</a>
</body>
</html>

View File

@ -1,23 +0,0 @@
<html><head>
<%@ page import="java.util.Enumeration" %>
</head><body>
<h1>JSP Dump</h1>
<table border="1">
<tr><th>Request URI:</th><td><%= request.getRequestURI() %></td></tr>
<tr><th>ServletPath:</th><td><%= request.getServletPath() %></td></tr>
<tr><th>PathInfo:</th><td><%= request.getPathInfo() %></td></tr>
<%
Enumeration e =request.getParameterNames();
while(e.hasMoreElements())
{
String name = (String)e.nextElement();
%>
<tr>
<th>getParameter("<%= name %>")</th>
<td><%= request.getParameter(name) %></td></tr>
<% } %>
</table>
</body></html>

View File

@ -1,23 +0,0 @@
<html>
<h1>JSP2.0 Expressions</h1>
<table border="1">
<tr><th>Expression</th><th>Result</th></tr>
<tr>
<td>\${param["A"]}</td>
<td>${param["A"]}&nbsp;</td>
</tr><tr>
<td>\${header["host"]}</td>
<td>${header["host"]}</td>
</tr><tr>
<td>\${header["user-agent"]}</td>
<td>${header["user-agent"]}</td>
</tr><tr>
<td>\${1+1}</td>
<td>${1+1}</td>
</tr><tr>
<td>\${param["A"] * 2}</td>
<td>${param["A"] * 2}&nbsp;</td>
</tr>
</table>
</html>

View File

@ -1,15 +0,0 @@
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
</head>
<body>
<h1>FOO Example</h1>
<hr>
<p>A trivial FOO example
<hr>
<c:forEach var="i" begin="1" end="10" step="1">
<c:out value="${i}" />
<br />
</c:forEach>
</body>
</html>

View File

@ -1,20 +0,0 @@
<html>
<body>
<h1>JSP Examples</h1>
<ul>
<li><a href="dump.jsp">JSP 1.2 embedded java</a><br/>
<li><a href="bean1.jsp">JSP 1.2 Bean demo</a><br/>
<li><a href="tag.jsp">JSP 1.2 BodyTag demo</a><br/>
<li><a href="tag2.jsp">JSP 2.0 SimpleTag demo</a><br/>
<li><a href="tagfile.jsp">JSP 2.0 Tag File demo</a><br/>
<li><a href="expr.jsp?A=1">JSP 2.0 Tag Expression</a><br/>
<li><a href="jstl.jsp">JSTL Expression</a><br/>
<li><a href="foo/">Mapping to &lt;jsp-file&gt;</a><br/>
</ul>
<a href="/">Main Menu</a>
</body>
</html>

View File

@ -1,15 +0,0 @@
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
</head>
<body>
<h1>JSTL Example</h1>
<hr>
<p>A trivial jstl example
<hr>
<c:forEach var="i" begin="1" end="10" step="1">
<c:out value="${i}" />
<br />
</c:forEach>
</body>
</html>

View File

@ -1,16 +0,0 @@
<html>
<body>
<%@ taglib uri="http://www.acme.com/taglib" prefix="acme" %>
<small>&lt;acme:date tz="GMT"&gt;EEE, dd/MMM/yyyy HH:mm:ss ZZZ&lt;/acme:date&gt;
==&gt;</small>
<acme:date tz="GMT">EEE, dd/MMM/yyyy HH:mm:ss ZZZ</acme:date>
<br/>
<small>&lt;acme:date tz="EST"&gt;EEE, dd-MMM-yyyy HH:mm:ss ZZZ&lt;/acme:date&gt;
==&gt;</small>
<acme:date tz="EST">EEE, dd-MMM-yyyy HH:mm:ss ZZZ</acme:date>
<br/>
</body>
</html>

View File

@ -1,19 +0,0 @@
<html>
<body>
<%@ taglib uri="http://www.acme.com/taglib2" prefix="acme" %>
<acme:date2 format="long">
On ${day} of ${month} in the year ${year}
</acme:date2>
<br/>
<acme:date2 format="short">
${day} - ${month} - ${year}
</acme:date2>
<br/>
</body>
</html>

View File

@ -1,37 +0,0 @@
<%@ taglib prefix="acme" tagdir="/WEB-INF/tags" %>
<html>
<head>
</head>
<body>
<h1>JSP 2.0 Tag File Example</h1>
<hr>
<p>Panel tag created from JSP fragment file in WEB-INF/tags
<hr>
<table border="0">
<tr valign="top">
<td>
<acme:panel color="#ff8080" bgcolor="#ffc0c0" title="Panel 1">
First panel.<br/>
</acme:panel>
</td>
<td>
<acme:panel color="#80ff80" bgcolor="#c0ffc0" title="Panel 2">
Second panel.<br/>
Second panel.<br/>
Second panel.<br/>
Second panel.<br/>
</acme:panel>
</td>
<td>
<acme:panel color="#8080ff" bgcolor="#c0c0ff" title="Panel 3">
Third panel.<br/>
<acme:panel color="#ff80ff" bgcolor="#ffc0ff" title="Inner">
A panel in a panel.
</acme:panel>
Third panel.<br/>
</acme:panel>
</td>
</tr>
</table>
</body>
</html>

View File

@ -1,17 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<project name="Jetty-Ant integration test" basedir="." >
<path id="jetty.plugin.classpath">
<fileset dir="target/test-lib" includes="*.jar"/>
</path>
<taskdef classpathref="jetty.plugin.classpath" resource="tasks.properties" loaderref="jetty.loader" />
<typedef name="webapp" classname="org.eclipse.jetty.ee9.ant.AntWebAppContext"
classpathref="jetty.plugin.classpath" loaderref="jetty.loader" />
<target name="jetty.run">
<jetty.run daemon="true" scanIntervalSeconds="10" jettyPort="0">
<webapp war="${basedir}/src/test/resources/foo" contextpath="/" />
</jetty.run>
</target>
</project>

View File

@ -54,7 +54,6 @@
<module>jetty-ee9-apache-jsp</module>
<module>jetty-ee9-glassfish-jstl</module>
<module>jetty-ee9-annotations</module>
<!-- <module>jetty-ee9-ant</module>-->
<module>jetty-ee9-cdi</module>
<module>jetty-ee9-jaas</module>
<module>jetty-ee9-jaspi</module>