public ContainerConfiguration set(TestatooProperties property, String value) { notNull(property, "Property name"); switch (property) { case CONTEXT: return context(value); case PORT: return port(Integer.parseInt(value)); case SERVER_CLASSPATH: return serverClassPath(value); case WEBAPP_CLASSPATH: return webappClassPath(value); case WEBAPP_ROOT: return webappRoot(value); } return this; }
@Override public Container get() { return containerConfiguration.buildContainer(containerClass); } };
@Override public ContainerBuilder set(String property, String value) { containerConfiguration.set(property, value); return this; }
private ContainerConfiguration() { port(DEFAULT_PORT); context(DEFAULT_CONTEXT_PATH); webappRoot(DEFAULT_WEBAPP_ROOT); }
public static ContainerConfiguration from(Properties settings) { return new ContainerConfiguration().add(settings); }
public ContainerConfiguration webappClassPath(String webappClassPath) { notNull(webappClassPath, "Webapp classpath"); return webappClassPath(toUrl(webappClassPath)); }
@Test public void test_toString() throws Exception { System.out.println(ContainerConfiguration.create() .port(9999) .webappRoot("../core/src/test/webapp") .context("superApp")); System.out.println(ContainerConfiguration.create() .port(9999) .webappRoot("../core/src/test/webapp") .context("superApp") .buildContainer(TestatooContainer.JETTY)); }
protected Server buildServer() { if (settings().hasServerClassPath()) { tryEnhanceContextClassloaderWithClasspath(settings().serverClassPath()); if (settings().has(PROPERTY_JETTY_CONF)) { try { XmlConfiguration configuration = new XmlConfiguration(new File(settings().get(PROPERTY_JETTY_CONF)).toURI().toURL()); configuration.configure(jetty); } catch (Exception e) { settings().port(jetty.getConnectors()[0].getPort()); if (settings().has(PROPERTY_TRACE)) { RequestLogHandler requestLogHandler = new RequestLogHandler(); NCSARequestLog requestLog = new NCSARequestLog(); if (settings().has(PROPERTY_JETTY_ENV)) { try { XmlConfiguration configuration = new XmlConfiguration(new File(settings().get(PROPERTY_JETTY_ENV)).toURI().toURL()); configuration.configure(webapp); } catch (Exception e) { throw new RuntimeException("An error has been detected in the Environnement configuration file you provided: " + e.getClass().getSimpleName() + " - " + e.getMessage(), e); } else if (settings().hasWebappClassPath()) { URL[] cp = settings().webappClassPath(); StringBuilder sb = new StringBuilder(); for (URL url : cp) {
public ContainerConfiguration serverClassPath(String serverClassPath) { notNull(serverClassPath, "Server classpath"); return serverClassPath(toUrl(serverClassPath)); }
public ContainerConfiguration serverClassPath(File... paths) { notNull(paths, "Server classpath"); List<URL> urls = new ArrayList<URL>(paths.length); for (File path : paths) urls.add(pathAsURL(path.getAbsolutePath())); return serverClassPath(urls.toArray(new URL[urls.size()])); }
public ContainerConfiguration webappClassPath(File... paths) { notNull(paths, "Webapp classpath"); List<URL> urls = new ArrayList<URL>(paths.length); for (File path : paths) urls.add(pathAsURL(path.getAbsolutePath())); return webappClassPath(urls.toArray(new URL[urls.size()])); }
public static void main(String... args) throws Exception { CommandLineParser parser = new GnuParser(); CommandLine line = parser.parse(options, args); if (line.hasOption("help") || !line.hasOption(CONTAINER.getName())) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(ContainerRunner.class.getSimpleName(), options); return; } // Set default values // And override by system properties. This way, we can start ContainerRunner with specific options such as -DjettyConf=.. -DjettyEnv=... ContainerConfiguration settings = ContainerConfiguration.from(System.getProperties()); // Then parse command line for (Option option : line.getOptions()) { settings.set(TestatooProperties.from(option.getOpt()), line.getOptionValue(option.getOpt())); } Container container = settings.buildContainer(line.getOptionValue(CONTAINER.getName())); container.start(); } }
@Override public ContainerBuilder port(int port) { containerConfiguration.port(port); return this; }
@Override public ContainerBuilder serverClassPath(URL... locations) { containerConfiguration.serverClassPath(locations); return this; }
@Override public ContainerBuilder webappClassPath(URL... locations) { containerConfiguration.webappClassPath(locations); return this; }
@Override public ContainerBuilder webappRoot(File webappRoot) { containerConfiguration.webappRoot(webappRoot); return this; }
public ContainerConfiguration webappRoot(String webappRoot) { notNull(webappRoot, "Webapp root"); return webappRoot(new File(webappRoot)); }
@Override public ContainerBuilder context(String contextPath) { containerConfiguration.context(contextPath); return this; }
public String get(String property) { if (has(property)) return properties.getProperty(property); throw new IllegalArgumentException("No property has been defined for [" + property + "]"); }
public String getProperty(String property) { return settings().get(property); }