/** * @param systemProperties */ public void setSystemProperties(SystemProperties systemProperties) { if (this.systemProperties == null) this.systemProperties = systemProperties; else { for (SystemProperty prop: systemProperties.getSystemProperties()) { this.systemProperties.setSystemProperty(prop); } } }
private void addServlet(JettyWebAppContext webAppContext, ServletHolder servletHolder, String pathSpec) { webAppContext.addServlet(servletHolder, pathSpec); if (ROOT_PATH_SPEC.equals(pathSpec)) { hasRootPathServlet = true; } }
@Override public void startJetty() throws MojoExecutionException { if (httpConnector==null && defaultPort!=0) { httpConnector = new MavenServerConnector(); httpConnector.setPort(defaultPort); } super.startJetty(); }
webApp = new JettyWebAppContext(); String cp = webApp.getContextPath(); if (cp == null || "".equals(cp)) webApp.setContextPath(cp); if (webApp.getTempDirectory() == null) if (!tmp.exists()) tmp.mkdirs(); webApp.setTempDirectory(tmp); getLog().info("Context path = " + webApp.getContextPath()); getLog().info("Tmp directory = "+ (webApp.getTempDirectory()== null? " determined at runtime": webApp.getTempDirectory())); getLog().info("Web defaults = "+(webApp.getDefaultsDescriptor()==null?" jetty default":webApp.getDefaultsDescriptor())); getLog().info("Web overrides = "+(webApp.getOverrideDescriptor()==null?" none":webApp.getOverrideDescriptor()));
getLog().info("restarting "+webApp); getLog().debug("Stopping webapp ..."); webApp.stop(); getLog().debug("Reconfiguring webapp ..."); if (webApp.getDescriptor() != null) scanList.add(new File(webApp.getDescriptor())); if (webApp.getJettyEnvXml() != null) scanList.add(new File(webApp.getJettyEnvXml())); scanList.add(project.getFile()); if (webApp.getTestClasses() != null) scanList.add(webApp.getTestClasses()); if (webApp.getClasses() != null) scanList.add(webApp.getClasses()); scanList.addAll(webApp.getWebInfLib()); scanner.setScanDirs(scanList); webApp.start(); getLog().info("Restart completed at " + new Date().toString());
if (httpConnector.getPort() <= 0) httpConnector.setPort(Integer.parseInt(tmp.trim())); if (httpConnector.getServer() == null) httpConnector.setServer(this.server); this.server.addConnector(httpConnector); httpConnector = new MavenServerConnector(); httpConnector.setPort(Integer.parseInt(tmp.trim())); if (httpConnector.getServer() == null) httpConnector.setServer(this.server); this.server.setConnectors(new Connector[] {httpConnector}); ServerSupport.configureHandlers( this.server, new NCSARequestLog() ServerSupport.addWebApplication( this.server, webApp );
/** * @param file * @throws Exception */ public void setSystemPropertiesFile(File file) throws Exception { this.systemPropertiesFile = file; Properties properties = new Properties(); try (InputStream propFile = new FileInputStream(systemPropertiesFile)) { properties.load(propFile); } if (this.systemProperties == null ) this.systemProperties = new SystemProperties(); for (Enumeration<?> keys = properties.keys(); keys.hasMoreElements(); ) { String key = (String)keys.nextElement(); if ( ! systemProperties.containsSystemProperty(key) ) { SystemProperty prop = new SystemProperty(); prop.setKey(key); prop.setValue(properties.getProperty(key)); this.systemProperties.setSystemProperty(prop); } } }
/** * */ protected void printSystemProperties () { // print out which system properties were set up if (getLog().isDebugEnabled()) { if (systemProperties != null) { Iterator itor = systemProperties.getSystemProperties().iterator(); while (itor.hasNext()) { SystemProperty prop = (SystemProperty)itor.next(); getLog().debug("Property "+prop.getName()+"="+prop.getValue()+" was "+ (prop.isSet() ? "set" : "skipped")); } } } }
private JettyWebAppContext createHandler() throws JettyWrapperException { try { JettyWebAppContext handler = new JettyWebAppContext(); handler.setInitParameter("org.eclipse.jetty.servlet.Default.useFileMappedBuffer", "false"); handler.setBaseResource(new ResourceCollection(baseResources.toArray(new Resource[0]))); getLog().info("Using base resources " + baseResources);
if (webApp == null || webApp.getContextPath() == null) { if (contextPath != null) { getLog().warn("Please use `webApp/contextPath` configuration parameter in place of the deprecated `contextPath` parameter"); if (webApp == null) { try { webApp = new JettyWebAppContext(); } catch (Exception e) { throw new MojoExecutionException("Failed to initialize webApp configuration", e); webApp.setContextPath(contextPath);
/** * @throws Exception */ public void applyJettyXml() throws Exception { if (getJettyXmlFiles() == null) return; ServerSupport.applyXmlConfigurations( this.server, getJettyXmlFiles() ); }
private void addDefaultServlet(JettyWebAppContext webAppContext, StaticResourcesServletConfig config) { ServletHolder servletHolder = new ServletHolder(DefaultServlet.class); servletHolder.setInitParameter("relativeResourceBase", config.getRelativeResourceBase()); servletHolder.setInitParameter("cacheControl", "no-store, no-cache, must-revalidate, max-age=0"); webAppContext.addAliasCheck(new AllowSymLinkAliasChecker()); addServlet(webAppContext, servletHolder, config.getPathSpec()); getLog().info(String.format("Serving static resources: %s -> %s", config.getPathSpec(), config.getRelativeResourceBase())); }
public void configureWebApplication() throws Exception { // Jetty tries to do this in WebAppContext.resolveWebApp but it failed to delete the directory. File t = webApp.getTempDirectory(); if (t==null) t = new File(getProject().getBuild().getDirectory(),"tmp"); File extractedWebAppDir= new File(t, "webapp"); if (isExtractedWebAppDirStale(extractedWebAppDir, webAppFile)) { FileUtils.deleteDirectory(extractedWebAppDir); } super.configureWebApplication(); getWebAppConfig().setWar(webAppFile.getCanonicalPath()); for (Artifact a : (Set<Artifact>) project.getArtifacts()) { if (a.getGroupId().equals("org.jenkins-ci.main") && a.getArtifactId().equals("jenkins-core")) { File coreBasedir = pluginWorkspaceMap.read(a.getId()); if (coreBasedir != null) { String extraCP = new File(coreBasedir, "src/main/resources").toURI() + "," + new File(coreBasedir, "target/classes").toURI(); getLog().info("Will load directly from " + extraCP); getWebAppConfig().setExtraClasspath(extraCP); } } } // cf. https://wiki.jenkins-ci.org/display/JENKINS/Jetty HashLoginService hashLoginService = (new HashLoginService("Jenkins Realm")); hashLoginService.setConfig(System.getProperty("jetty.home", "work") + "/etc/realm.properties"); getWebAppConfig().getSecurityHandler().setLoginService(hashLoginService); }
/** * @see org.apache.maven.plugin.Mojo#execute() */ public void execute() throws MojoExecutionException, MojoFailureException { getLog().info("Configuring Jetty for project: " + this.project.getName()); if (skip) { getLog().info("Skipping Jetty start: jetty.skip==true"); return; } if (isExcluded(execution.getMojoDescriptor().getGoal())) { getLog().info("The goal \""+execution.getMojoDescriptor().getFullGoalName()+ "\" has been made unavailable for this web application by an <excludedGoal> configuration."); return; } configurePluginClasspath(); PluginLog.setLog(getLog()); checkPomConfiguration(); startJetty(); }