diff --git a/jetty-spdy/spdy-core/pom.xml b/jetty-spdy/spdy-core/pom.xml
index 218da99801d..935c4846da6 100644
--- a/jetty-spdy/spdy-core/pom.xml
+++ b/jetty-spdy/spdy-core/pom.xml
@@ -6,9 +6,9 @@
+ * Allows for a test specific directory, that is a copied jetty-distribution, and then modified for the test specific testing required. + *
+ * Requires that you setup the maven-dependency-plugin appropriately for the base distribution you want to use, along with any other dependencies (wars, libs, + * etc..) that you may need from other maven projects. + *
+ * Maven Dependency Plugin Setup: + * + *
+ * <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"> + * + * <!-- Common Destination Directories --> + * + * <properties> + * <test-wars-dir>${project.build.directory}/test-wars</test-wars-dir> + * <test-libs-dir>${project.build.directory}/test-libs</test-libs-dir> + * <test-distro-dir>${project.build.directory}/test-dist</test-distro-dir> + * </properties> + * + * <build> + * <plugins> + * <plugin> + * <groupId>org.apache.maven.plugins</groupId> + * <artifactId>maven-dependency-plugin</artifactId> + * <version>2.1</version> + * <executions> + * + * <!-- Copy LIB and WAR dependencies into place that JettyDistro can use them --> + * + * <execution> + * <id>test-lib-war-copy</id> + * <phase>process-test-resources</phase> + * <goals> + * <goal>copy</goal> + * </goals> + * <configuration> + * <artifactItems> + * <artifactItem> + * <groupId>org.mortbay.jetty.testwars</groupId> + * <artifactId>test-war-java_util_logging</artifactId> + * <version>7.3.0</version> + * <type>war</type> + * <outputDirectory>${test-wars-dir}</outputDirectory> + * </artifactItem> + * <artifactItem> + * <groupId>org.mortbay.jetty</groupId> + * <artifactId>jetty-aspect-servlet-api-2.5</artifactId> + * <version>7.3.0</version> + * <type>jar</type> + * <outputDirectory>${test-libs-dir}</outputDirectory> + * </artifactItem> + * </artifactItems> + * <overWriteIfNewer>true</overWriteIfNewer> + * <overWrite>true</overWrite> + * <stripVersion>true</stripVersion> + * </configuration> + * </execution> + * + * <!-- Extract Jetty DISTRIBUTION into place that JettyDistro can use it --> + * + * <execution> + * <id>unpack-test-dist</id> + * <phase>process-test-resources</phase> + * <goals> + * <goal>unpack</goal> + * </goals> + * <configuration> + * <artifactItems> + * <artifactItem> + * <groupId>org.eclipse.jetty</groupId> + * <artifactId>jetty-distribution</artifactId> + * <version>7.3.0</version> + * <type>zip</type> + * <overWrite>true</overWrite> + * </artifactItem> + * </artifactItems> + * <outputAbsoluteArtifactFilename>true</outputAbsoluteArtifactFilename> + * <outputDirectory>${test-distro-dir}</outputDirectory> + * <overWriteSnapshots>true</overWriteSnapshots> + * <overWriteIfNewer>true</overWriteIfNewer> + * </configuration> + * </execution> + * </executions> + * </plugin> + * </plugins> + * </build> + * + * </project> + *+ *
+ * If you have a specific configuration you want to setup, you'll want to prepare this configuration in an overlay directory underneath the
+ * src/test/resources/
directory.
+ * Notes:
+ *
target/test-dist
directory into this new testing directory prior to the test specific changes
+ * to the configuration.src/test/resources
will be the name you use in the {@link #overlayConfig(String)} method to provide
+ * replacement configurations for the Jetty Distribution.target/test-libs
directory (created and managed above using the
+ * maven-dependency-plugin
) to copy the lib into the test specific.target/test-wars
directory (created and managed above using the
+ * maven-dependency-plugin
) to copy the WAR into the test specific directory.
+ * Next you'll want to use Junit 4.8+ and the @BeforeClass
and @AfterClass
annotations to setup the JettyDistro
+ * class for setting up your testing configuration.
+ *
+ * Example Test Case using {@link JettyDistro} class + * + *
+ * public class MySampleTest + * { + * private static JettyDistro jetty; + * + * @BeforeClass + * public static void initJetty() throws Exception + * { + * jetty = new JettyDistro(MySampleTest.class); + * + * jetty.copyTestWar("test-war-java_util_logging.war"); + * jetty.copyTestWar("test-war-policy.war"); + * + * jetty.delete("webapps/test.war"); + * jetty.delete("contexts/test.d"); + * jetty.delete("contexts/javadoc.xml"); + * jetty.delete("contexts/test.xml"); + * + * jetty.overlayConfig("no_security"); + * + * jetty.setDebug(true); + * + * jetty.start(); + * } + * + * @AfterClass + * public static void shutdownJetty() throws Exception + * { + * if (jetty != null) + * { + * jetty.stop(); + * } + * } + * + * @Test + * public void testRequest() throws Exception + * { + * SimpleRequest request = new SimpleRequest(jetty.getBaseUri()); + * String path = "/test-war-policy/security/PRACTICAL/testFilsystem"); + * String response = request.getString(path); + * Assert.assertEquals("Success", response); + * } + * } + *+ */ +public class JettyDistro +{ + private String artifactName = "jetty-distribution"; + private long startTime = 60; + private TimeUnit timeUnit = TimeUnit.SECONDS; + + private File jettyHomeDir; + private Process pid; + private URI baseUri; + + private String jmxUrl; + + private boolean _debug = false; + + /** + * Setup the JettyHome as belonging in a testing directory associated with a testing clazz. + * + * @param clazz + * the testing class using this JettyDistro + * @throws IOException + * if unable to copy unpacked distribution into place for the provided testing directory + */ + public JettyDistro(Class> clazz) throws IOException + { + this(clazz,null); + } + + /** + * Setup the JettyHome as belonging in a testing directory associated with a testing clazz. + * + * @param clazz + * the testing class using this JettyDistro + * @param artifact + * name of jetty distribution artifact + * @throws IOException + * if unable to copy unpacked distribution into place for the provided testing directory + */ + public JettyDistro(Class> clazz, String artifact) throws IOException + { + this.jettyHomeDir = MavenTestingUtils.getTargetTestingDir(clazz,"jettyHome"); + if (artifact != null) + { + this.artifactName = artifact; + } + + copyBaseDistro(); + } + + /** + * Setup the JettyHome as belonging to a specific testing method directory + * + * @param testdir + * the testing directory to use as the JettyHome for this JettyDistro + * @throws IOException + * if unable to copy unpacked distribution into place for the provided testing directory + */ + public JettyDistro(TestingDir testdir) throws IOException + { + this.jettyHomeDir = testdir.getDir(); + copyBaseDistro(); + } + + /** + * Setup the JettyHome as belonging to a specific testing method directory + * + * @param testdir + * the testing directory to use as the JettyHome for this JettyDistro + * @param artifact + * name of jetty distribution artifact + * @throws IOException + * if unable to copy unpacked distribution into place for the provided testing directory + */ + public JettyDistro(TestingDir testdir, String artifact) throws IOException + { + this.jettyHomeDir = testdir.getDir(); + if (artifact != null) + { + this.artifactName = artifact; + } + + copyBaseDistro(); + } + + /** + * + * @throws IOException + * if unable to copy unpacked distribution into place for the provided testing directory + */ + private void copyBaseDistro() throws IOException + { + // The outputDirectory for the maven side dependency:unpack goal. + File distroUnpackDir = MavenTestingUtils.getTargetFile("test-dist"); + PathAssert.assertDirExists(artifactName + " dependency:unpack",distroUnpackDir); + + // The actual jetty-distribution-${version} directory is under this directory. + // Lets find it. + File subdirs[] = distroUnpackDir.listFiles(new FileFilter() + { + public boolean accept(File path) + { + if (!path.isDirectory()) + { + return false; + } + + return path.getName().startsWith(artifactName + "-"); + } + }); + + if (subdirs.length == 0) + { + // No jetty-distribution found. + StringBuilder err = new StringBuilder(); + err.append("No target/test-dist/"); + err.append(artifactName); + err.append("-${version} directory found."); + err.append("\n To fix this, run 'mvn process-test-resources' to create the directory."); + throw new IOException(err.toString()); + } + + if (subdirs.length != 1) + { + // Too many jetty-distributions found. + StringBuilder err = new StringBuilder(); + err.append("Too many target/test-dist/"); + err.append(artifactName); + err.append("-${version} directories found."); + for (File dir : subdirs) + { + err.append("\n ").append(dir.getAbsolutePath()); + } + err.append("\n To fix this, run 'mvn clean process-test-resources' to recreate the target/test-dist directory."); + throw new IOException(err.toString()); + } + + File distroSrcDir = subdirs[0]; + FS.ensureEmpty(jettyHomeDir); + System.out.printf("Copying Jetty Distribution: %s%n",distroSrcDir.getAbsolutePath()); + System.out.printf(" To Testing Dir: %s%n",jettyHomeDir.getAbsolutePath()); + IO.copyDir(distroSrcDir,jettyHomeDir); + } + + /** + * Return the $(jetty.home) directory being used for this JettyDistro + * + * @return the jetty.home directory being used + */ + public File getJettyHomeDir() + { + return this.jettyHomeDir; + } + + /** + * Copy a war file from ${project.basedir}/target/test-wars/${testWarFilename} into the ${jetty.home}/webapps/ directory + * + * @param testWarFilename + * the war file to copy (must exist) + * @throws IOException + * if unable to copy the war file. + */ + public void copyTestWar(String testWarFilename) throws IOException + { + File srcWar = MavenTestingUtils.getTargetFile("test-wars/" + testWarFilename); + File destWar = new File(jettyHomeDir,OS.separators("webapps/" + testWarFilename)); + FS.ensureDirExists(destWar.getParentFile()); + IO.copyFile(srcWar,destWar); + } + + /** + * Copy an arbitrary file from
src/test/resources/${resourcePath}
to the testing directory.
+ *
+ * @param resourcePath
+ * the relative path for file content within the src/test/resources
directory.
+ * @param outputPath
+ * the testing directory relative output path for the file output (will result in a file with the outputPath name being created)
+ * @throws IOException
+ * if unable to copy resource file
+ */
+ public void copyResource(String resourcePath, String outputPath) throws IOException
+ {
+ File srcFile = MavenTestingUtils.getTestResourceFile(resourcePath);
+ File destFile = new File(jettyHomeDir,OS.separators(outputPath));
+ FS.ensureDirExists(destFile.getParentFile());
+ IO.copyFile(srcFile,destFile);
+ }
+
+ /**
+ * Copy an arbitrary file from target/test-libs/${libFilename}
to the testing directory.
+ *
+ * @param libFilename
+ * the target/test-libs/${libFilename}
to copy
+ * @param outputPath
+ * the destination testing directory relative output path for the lib. (will result in a file with the outputPath name being created)
+ * @throws IOException
+ * if unable to copy lib
+ */
+ public void copyLib(String libFilename, String outputPath) throws IOException
+ {
+ File srcLib = MavenTestingUtils.getTargetFile("test-libs/" + libFilename);
+ File destLib = new File(jettyHomeDir,OS.separators(outputPath));
+ FS.ensureDirExists(destLib.getParentFile());
+ IO.copyFile(srcLib,destLib);
+ }
+
+ /**
+ * Copy the ${project.basedir}/src/main/config/
tree into the testing directory.
+ *
+ * @throws IOException
+ * if unable to copy the directory tree
+ */
+ public void copyProjectMainConfig() throws IOException
+ {
+ File srcDir = MavenTestingUtils.getProjectDir("src/main/config");
+ IO.copyDir(srcDir,jettyHomeDir);
+ }
+
+ /**
+ * Create a ${jetty.home}/lib/self/${jarFilename}
jar file from the content in the ${project.basedir}/target/classes/
directory.
+ *
+ * @throws IOException
+ * if unable to copy the directory tree
+ */
+ public void createProjectLib(String jarFilename) throws IOException
+ {
+ File srcDir = MavenTestingUtils.getTargetFile("classes");
+ File libSelfDir = new File(jettyHomeDir,OS.separators("lib/self"));
+ FS.ensureDirExists(libSelfDir);
+ File jarFile = new File(libSelfDir,jarFilename);
+ JAR.create(srcDir,jarFile);
+ }
+
+ /**
+ * Unpack an arbitrary config from target/test-configs/${configFilename}
to the testing directory.
+ *
+ * @param configFilename
+ * the target/test-configs/${configFilename}
to copy
+ * @throws IOException
+ * if unable to unpack config file
+ */
+ public void unpackConfig(String configFilename) throws IOException
+ {
+ File srcConfig = MavenTestingUtils.getTargetFile("test-configs/" + configFilename);
+ JAR.unpack(srcConfig,jettyHomeDir);
+ }
+
+ /**
+ * Delete a File or Directory found in the ${jetty.home} directory.
+ *
+ * @param path
+ * the path to delete. (can be a file or directory)
+ */
+ public void delete(String path)
+ {
+ File jettyPath = new File(jettyHomeDir,OS.separators(path));
+ FS.delete(jettyPath);
+ }
+
+ /**
+ * Return the baseUri being used for this Jetty Process Instance.
+ *
+ * @return the base URI for this Jetty Process Instance.
+ */
+ public URI getBaseUri()
+ {
+ return this.baseUri;
+ }
+
+ /**
+ * Return the JMX URL being used for this Jetty Process Instance.
+ *
+ * @return the JMX URL for this Jetty Process Instance.
+ */
+ public String getJmxUrl()
+ {
+ return this.jmxUrl;
+ }
+
+ /**
+ * Take the directory contents from ${project.basedir}/src/test/resources/${testConfigName}/ and copy it over whatever happens to be at ${jetty.home}
+ *
+ * @param testConfigName
+ * the src/test/resources/ directory name to use as the source diretory for the configuration we are interested in.
+ * @throws IOException
+ * if unable to copy directory.
+ */
+ public void overlayConfig(String testConfigName) throws IOException
+ {
+ File srcDir = MavenTestingUtils.getTestResourceDir(testConfigName);
+ IO.copyDir(srcDir,jettyHomeDir);
+ }
+
+ /**
+ * Start the jetty server
+ *
+ * @throws IOException
+ * if unable to start the server.
+ */
+ public void start() throws IOException
+ {
+ List