diff --git a/jetty-core/jetty-maven/pom.xml b/jetty-core/jetty-maven/pom.xml new file mode 100644 index 000000000000..b2aea6afb328 --- /dev/null +++ b/jetty-core/jetty-maven/pom.xml @@ -0,0 +1,122 @@ + + + 4.0.0 + + org.eclipse.jetty + jetty-core + 12.0.9-SNAPSHOT + + jetty-maven + Core :: Maven + + ${project.groupId}.maven + org.eclipse.jetty.maven.* + + + + org.apache.maven.plugin-tools + maven-plugin-tools-api + + + org.codehaus.plexus + plexus-xml + + + org.apache.maven + maven-api-xml + + + org.apache.maven + maven-xml-impl + + + org.apache.maven + maven-xml-meta + + + + + org.eclipse.jetty + jetty-jmx + true + + + org.eclipse.jetty + jetty-security + + + org.eclipse.jetty + jetty-server + + + org.eclipse.jetty + jetty-util + + + org.eclipse.jetty + jetty-xml + + + org.slf4j + slf4j-api + + + org.apache.maven + maven-artifact + provided + + + org.apache.maven + maven-core + provided + + + javax.annotation + javax.annotation-api + + + + + org.apache.maven + maven-model + provided + + + org.apache.maven + maven-plugin-api + provided + + + javax.annotation + javax.annotation-api + + + + + org.awaitility + awaitility + test + + + org.eclipse.jetty + jetty-slf4j-impl + test + + + org.eclipse.jetty.toolchain + jetty-test-helper + test + + + + + + maven-surefire-plugin + + @{argLine} ${jetty.surefire.argLine} + --add-reads org.eclipse.jetty.maven=org.eclipse.jetty.logging + + + + + diff --git a/jetty-core/jetty-maven/src/main/java/org/eclipse/jetty/maven/AbstractForkedChild.java b/jetty-core/jetty-maven/src/main/java/org/eclipse/jetty/maven/AbstractForkedChild.java new file mode 100644 index 000000000000..b76bf0238252 --- /dev/null +++ b/jetty-core/jetty-maven/src/main/java/org/eclipse/jetty/maven/AbstractForkedChild.java @@ -0,0 +1,208 @@ +// +// ======================================================================== +// 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.maven; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Properties; +import java.util.Set; + +import org.eclipse.jetty.util.Scanner; +import org.eclipse.jetty.util.StringUtil; +import org.eclipse.jetty.util.component.ContainerLifeCycle; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * JettyForkedChild + * + * This is the class that is executed when the jetty maven plugin + * forks a process when DeploymentMode=FORKED. + */ +public abstract class AbstractForkedChild extends ContainerLifeCycle +{ + private static final Logger LOG = LoggerFactory.getLogger(AbstractForkedChild.class); + + protected AbstractJettyEmbedder jetty; + protected File tokenFile; // TODO: convert to Path + protected Scanner scanner; + protected File webAppPropsFile; // TODO: convert to Path + protected int scanInterval; + + /** + * @param args arguments that were passed to main + * @throws Exception if unable to configure + */ + public AbstractForkedChild(String[] args) + throws Exception + { + jetty = newJettyEmbedder(); + configure(args); + } + + public AbstractJettyEmbedder getJettyEmbedder() + { + return jetty; + } + + protected abstract AbstractJettyEmbedder newJettyEmbedder(); + + /** + * Based on the args passed to the program, configure jetty. + * + * @param args args that were passed to the program. + * @throws Exception if unable to load webprops + */ + public void configure(String[] args) + throws Exception + { + Map jettyProperties = new HashMap<>(); + + for (int i = 0; i < args.length; i++) + { + //--stop-port + if ("--stop-port".equals(args[i])) + { + jetty.setStopPort(Integer.parseInt(args[++i])); + continue; + } + + //--stop-key + if ("--stop-key".equals(args[i])) + { + jetty.setStopKey(args[++i]); + continue; + } + + //--jettyXml + if ("--jetty-xml".equals(args[i])) + { + List jettyXmls = new ArrayList<>(); + String[] names = StringUtil.csvSplit(args[++i]); + for (int j = 0; names != null && j < names.length; j++) + { + jettyXmls.add(new File(names[j].trim())); + } + jetty.setJettyXmlFiles(jettyXmls); + continue; + } + //--webprops + if ("--webprops".equals(args[i])) + { + webAppPropsFile = new File(args[++i].trim()); + jetty.setWebAppProperties(loadWebAppProps()); + continue; + } + + //--token + if ("--token".equals(args[i])) + { + tokenFile = new File(args[++i].trim()); + continue; + } + + if ("--scanInterval".equals(args[i])) + { + scanInterval = Integer.parseInt(args[++i].trim()); + scanner = new Scanner(); + scanner.setReportExistingFilesOnStartup(false); + scanner.setScanInterval(scanInterval); + scanner.addListener(new Scanner.BulkListener() + { + public void filesChanged(Set changes) + { + if (!Objects.isNull(scanner)) + { + try + { + scanner.stop(); + jetty.redeployWebApp(loadWebAppProps()); + scanner.start(); + } + catch (Exception e) + { + LOG.error("Error reconfiguring/restarting webapp after change in watched files", e); + } + } + } + }); + + if (!Objects.isNull(webAppPropsFile)) + scanner.addFile(webAppPropsFile.toPath()); + continue; + } + + //assume everything else is a jetty property to be passed in + String[] tmp = args[i].trim().split("="); + if (tmp.length == 2) + { + jettyProperties.put(tmp[0], tmp[1]); + } + } + + jetty.setJettyProperties(jettyProperties); + jetty.setExitVm(true); + } + + /** + * Load properties from a file describing the webapp if one is + * present. + * + * @return file contents as properties + * @throws FileNotFoundException if there is a file not found problem + * @throws IOException if there is an IO problem + */ + protected Properties loadWebAppProps() throws FileNotFoundException, IOException + { + Properties props = new Properties(); + if (Objects.nonNull(webAppPropsFile)) + props.load(new FileInputStream(webAppPropsFile)); + return props; + } + + /** + * Start a jetty instance and webapp. This thread will + * wait until jetty exits. + */ + public void doStart() + throws Exception + { + super.doStart(); + + //Start the embedded jetty instance + jetty.start(); + + //touch file to signify start of jetty + Path tokenPath = tokenFile.toPath(); + Files.createFile(tokenPath); + + //Start a watcher on a file that will change if the + //webapp is regenerated; stop the webapp, apply the + //properties and restart it. + if (scanner != null) + scanner.start(); + + //wait for jetty to finish + jetty.join(); + } +} diff --git a/jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/AbstractForker.java b/jetty-core/jetty-maven/src/main/java/org/eclipse/jetty/maven/AbstractForker.java similarity index 99% rename from jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/AbstractForker.java rename to jetty-core/jetty-maven/src/main/java/org/eclipse/jetty/maven/AbstractForker.java index 10ad7784a150..fc7947a62f32 100644 --- a/jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/AbstractForker.java +++ b/jetty-core/jetty-maven/src/main/java/org/eclipse/jetty/maven/AbstractForker.java @@ -11,7 +11,7 @@ // ======================================================================== // -package org.eclipse.jetty.ee9.maven.plugin; +package org.eclipse.jetty.maven; import java.io.File; import java.util.List; diff --git a/jetty-core/jetty-maven/src/main/java/org/eclipse/jetty/maven/AbstractHomeForker.java b/jetty-core/jetty-maven/src/main/java/org/eclipse/jetty/maven/AbstractHomeForker.java new file mode 100644 index 000000000000..1e2ce6a45f32 --- /dev/null +++ b/jetty-core/jetty-maven/src/main/java/org/eclipse/jetty/maven/AbstractHomeForker.java @@ -0,0 +1,428 @@ +// +// ======================================================================== +// 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.maven; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.nio.file.FileAlreadyExistsException; +import java.nio.file.FileSystems; +import java.nio.file.FileVisitOption; +import java.nio.file.FileVisitResult; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.SimpleFileVisitor; +import java.nio.file.attribute.BasicFileAttributes; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.EnumSet; +import java.util.List; +import java.util.Map; + +import org.eclipse.jetty.util.IO; +import org.eclipse.jetty.util.StringUtil; +import org.eclipse.jetty.util.TypeUtil; +import org.eclipse.jetty.util.resource.Resource; +import org.eclipse.jetty.util.resource.ResourceFactory; + +/** + * AbstractHomeForker + * + * Unpacks a jetty-home and configures it with a base that allows it + * to run an unassembled webapp. + */ +public abstract class AbstractHomeForker extends AbstractForker +{ + protected String contextXml; + + /** + * Location of existing jetty home directory + */ + protected File jettyHome; + + /** + * Zip of jetty-home + */ + protected File jettyHomeZip; + + /** + * Location of existing jetty base directory + */ + protected File jettyBase; + + protected File baseDir; + + /** + * Optional list of other modules to + * activate. + */ + protected String[] modules; + + /* + * Optional jetty commands + */ + protected String jettyOptions; + + protected List libExtJarFiles; + protected Path modulesPath; + protected Path etcPath; + protected Path libPath; + protected Path webappPath; + protected Path mavenLibPath; + protected String version; + protected String environment; + + public void setVersion(String version) + { + this.version = version; + } + + public void setJettyOptions(String jettyOptions) + { + this.jettyOptions = jettyOptions; + } + + public String getJettyOptions() + { + return jettyOptions; + } + + public List getLibExtJarFiles() + { + return libExtJarFiles; + } + + public void setLibExtJarFiles(List libExtJarFiles) + { + this.libExtJarFiles = libExtJarFiles; + } + + public File getJettyHome() + { + return jettyHome; + } + + public void setJettyHome(File jettyHome) + { + this.jettyHome = jettyHome; + } + + public File getJettyBase() + { + return jettyBase; + } + + public void setJettyBase(File jettyBase) + { + this.jettyBase = jettyBase; + } + + public String[] getModules() + { + return modules; + } + + public void setModules(String[] modules) + { + this.modules = modules; + } + + public String getContextXmlFile() + { + return contextXml; + } + + public void setContextXml(String contextXml) + { + this.contextXml = contextXml; + } + + public File getJettyHomeZip() + { + return jettyHomeZip; + } + + public void setJettyHomeZip(File jettyHomeZip) + { + this.jettyHomeZip = jettyHomeZip; + } + + public File getBaseDir() + { + return baseDir; + } + + public void setBaseDir(File baseDir) + { + this.baseDir = baseDir; + } + + @Override + protected ProcessBuilder createCommand() + { + List cmd = new ArrayList<>(); + cmd.add("java"); + + //add any args to the jvm + if (StringUtil.isNotBlank(jvmArgs)) + { + Arrays.stream(jvmArgs.split(" ")).filter(a -> StringUtil.isNotBlank(a)).forEach((a) -> cmd.add(a.trim())); + } + + cmd.add("-jar"); + cmd.add(new File(jettyHome, "start.jar").getAbsolutePath()); + + if (systemProperties != null) + { + for (Map.Entry e : systemProperties.entrySet()) + { + cmd.add("-D" + e.getKey() + "=" + e.getValue()); + } + } + + cmd.add("-DSTOP.PORT=" + stopPort); + if (stopKey != null) + cmd.add("-DSTOP.KEY=" + stopKey); + + //set up enabled jetty modules + StringBuilder tmp = new StringBuilder(); + tmp.append("--module="); + tmp.append("server,http," + environment + "-webapp," + environment + "-deploy"); + if (modules != null) + { + for (String m : modules) + { + if (tmp.indexOf(m) < 0) + tmp.append("," + m); + } + } + + if (libExtJarFiles != null && !libExtJarFiles.isEmpty() && tmp.indexOf("ext") < 0) + tmp.append(",ext"); + tmp.append("," + environment + "-maven"); + cmd.add(tmp.toString()); + + //put any other jetty options onto the command line + if (StringUtil.isNotBlank(jettyOptions)) + { + Arrays.stream(jettyOptions.split(" ")).filter(a -> StringUtil.isNotBlank(a)).forEach((a) -> cmd.add(a.trim())); + } + + //put any jetty properties onto the command line + if (jettyProperties != null) + { + for (Map.Entry e : jettyProperties.entrySet()) + { + cmd.add(e.getKey() + "=" + e.getValue()); + } + } + + //existence of this file signals process started + cmd.add("jetty.token.file=" + tokenFile.getAbsolutePath().toString()); + + ProcessBuilder builder = new ProcessBuilder(cmd); + builder.directory(workDir); + + PluginLog.getLog().info("Home process starting"); + + //set up extra environment vars if there are any + if (!env.isEmpty()) + builder.environment().putAll(env); + + if (waitForChild) + builder.inheritIO(); + else + { + builder.redirectOutput(jettyOutputFile); + builder.redirectErrorStream(true); + } + return builder; + } + + @Override + public void doStart() throws Exception + { + //set up a jetty-home + configureJettyHome(); + + if (jettyHome == null || !jettyHome.exists()) + throw new IllegalStateException("No jetty home"); + + //set up a jetty-base + configureJettyBase(); + + //convert the webapp to properties + generateWebAppPropertiesFile(); + + super.doStart(); + } + + protected void redeployWebApp() + throws Exception + { + generateWebAppPropertiesFile(); + webappPath.resolve("maven.xml").toFile().setLastModified(System.currentTimeMillis()); + } + + protected abstract void generateWebAppPropertiesFile() throws Exception; + + /** + * Create or configure a jetty base. + */ + private void configureJettyBase() throws Exception + { + if (jettyBase != null && !jettyBase.exists()) + throw new IllegalStateException(jettyBase.getAbsolutePath() + " does not exist"); + + File targetJettyBase = new File(baseDir, "jetty-base"); + Path targetBasePath = targetJettyBase.toPath(); + if (Files.exists(targetBasePath)) + IO.delete(targetJettyBase); + + targetJettyBase.mkdirs(); + + //jetty-base will be the working directory for the forked command + workDir = targetJettyBase; + + //if there is an existing jetty base, copy parts of it + if (jettyBase != null) + { + Path jettyBasePath = jettyBase.toPath(); + + final File contextXmlFile = (contextXml == null ? null : FileSystems.getDefault().getPath(contextXml).toFile()); + + //copy the existing jetty base + Files.walkFileTree(jettyBasePath, EnumSet.of(FileVisitOption.FOLLOW_LINKS), Integer.MAX_VALUE, + new SimpleFileVisitor() + { + @Override + public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException + { + Path targetDir = targetBasePath.resolve(jettyBasePath.relativize(dir)); + try + { + Files.copy(dir, targetDir); + } + catch (FileAlreadyExistsException e) + { + if (!Files.isDirectory(targetDir)) //ignore attempt to recreate dir + throw e; + } + return FileVisitResult.CONTINUE; + } + + @Override + public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException + { + if (contextXmlFile != null && Files.isSameFile(contextXmlFile.toPath(), file)) + return FileVisitResult.CONTINUE; //skip copying the context xml file + Files.copy(file, targetBasePath.resolve(jettyBasePath.relativize(file))); + return FileVisitResult.CONTINUE; + } + }); + } + + //make the jetty base structure + modulesPath = Files.createDirectories(targetBasePath.resolve("modules")); + etcPath = Files.createDirectories(targetBasePath.resolve("etc")); + libPath = Files.createDirectories(targetBasePath.resolve("lib")); + webappPath = Files.createDirectories(targetBasePath.resolve("webapps")); + mavenLibPath = Files.createDirectories(libPath.resolve(environment + "-maven")); + + //copy in the jetty-${ee}-maven-plugin jar + URI thisJar = TypeUtil.getLocationOfClass(this.getClass()); + if (thisJar == null) + throw new IllegalStateException("Can't find jar for jetty-" + environment + "-maven-plugin"); + + try (InputStream jarStream = thisJar.toURL().openStream(); + FileOutputStream fileStream = new FileOutputStream(mavenLibPath.resolve("jetty-" + environment + "-maven-plugin.jar").toFile())) + { + IO.copy(jarStream, fileStream); + } + + //copy in the jetty-maven.jar for common classes + URI commonJar = TypeUtil.getLocationOfClass(AbstractHomeForker.class); + if (commonJar == null) + throw new IllegalStateException("Can't find jar for jetty-maven common classes"); + try (InputStream jarStream = commonJar.toURL().openStream(); + FileOutputStream fileStream = new FileOutputStream(mavenLibPath.resolve("jetty-maven.jar").toFile())) + { + IO.copy(jarStream, fileStream); + } + + //copy in the maven-${ee}.xml webapp file + String mavenXml = "maven-" + environment + ".xml"; + try (InputStream mavenXmlStream = getClass().getClassLoader().getResourceAsStream(mavenXml); + FileOutputStream fileStream = new FileOutputStream(webappPath.resolve(mavenXml).toFile())) + { + IO.copy(mavenXmlStream, fileStream); + } + + Files.writeString(webappPath.resolve("maven-" + environment + ".properties"), "environment=" + environment); + + //copy in the ${ee}-maven.mod file + String mavenMod = environment + "-maven.mod"; + try (InputStream mavenModStream = getClass().getClassLoader().getResourceAsStream(mavenMod); + FileOutputStream fileStream = new FileOutputStream(modulesPath.resolve(mavenMod).toFile())) + { + IO.copy(mavenModStream, fileStream); + } + + //copy in the jetty-${ee}-maven.xml file + String jettyMavenXml = "jetty-" + environment + "-maven.xml"; + try (InputStream jettyMavenStream = getClass().getClassLoader().getResourceAsStream(jettyMavenXml); + FileOutputStream fileStream = new FileOutputStream(etcPath.resolve(jettyMavenXml).toFile())) + { + IO.copy(jettyMavenStream, fileStream); + } + + //if there were plugin dependencies, copy them into lib/ext + if (libExtJarFiles != null && !libExtJarFiles.isEmpty()) + { + Path libExtPath = Files.createDirectories(libPath.resolve("ext")); + for (File f : libExtJarFiles) + { + try (InputStream jarStream = new FileInputStream(f); + FileOutputStream fileStream = new FileOutputStream(libExtPath.resolve(f.getName()).toFile())) + { + IO.copy(jarStream, fileStream); + } + } + } + } + + private void configureJettyHome() + throws Exception + { + if (jettyHome == null && jettyHomeZip == null) + throw new IllegalStateException("No jettyHome"); + + if (baseDir == null) + throw new IllegalStateException("No baseDir"); + + if (jettyHome == null) + { + try (ResourceFactory.Closeable resourceFactory = ResourceFactory.closeable()) + { + Resource res = resourceFactory.newJarFileResource(jettyHomeZip.toPath().toUri()); + res.copyTo(baseDir.toPath()); + } + //zip will unpack to target/jetty-home- + jettyHome = new File(baseDir, "jetty-home-" + version); + } + } +} diff --git a/jetty-core/jetty-maven/src/main/java/org/eclipse/jetty/maven/AbstractJettyEmbedder.java b/jetty-core/jetty-maven/src/main/java/org/eclipse/jetty/maven/AbstractJettyEmbedder.java new file mode 100644 index 000000000000..aa25e00d0824 --- /dev/null +++ b/jetty-core/jetty-maven/src/main/java/org/eclipse/jetty/maven/AbstractJettyEmbedder.java @@ -0,0 +1,284 @@ +// +// ======================================================================== +// 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.maven; + +import java.io.File; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Properties; + +import org.eclipse.jetty.security.LoginService; +import org.eclipse.jetty.server.RequestLog; +import org.eclipse.jetty.server.Server; +import org.eclipse.jetty.server.ShutdownMonitor; +import org.eclipse.jetty.server.handler.ContextHandler; +import org.eclipse.jetty.util.component.ContainerLifeCycle; + +/** + * AbstractJettyEmbedder + * Starts jetty within the current process. + */ +public abstract class AbstractJettyEmbedder extends ContainerLifeCycle +{ + protected List contextHandlers; + protected List loginServices; + protected RequestLog requestLog; + protected MavenServerConnector httpConnector; + protected Server server; + protected boolean exitVm; + protected boolean stopAtShutdown; + protected List jettyXmlFiles; + protected Map jettyProperties; + protected ShutdownMonitor shutdownMonitor; + protected int stopPort; + protected String stopKey; + protected String contextXml; + protected Properties webAppProperties; + + public List getContextHandlers() + { + return contextHandlers; + } + + public void setContextHandlers(List contextHandlers) + { + if (contextHandlers == null) + this.contextHandlers = null; + else + this.contextHandlers = new ArrayList<>(contextHandlers); + } + + public List getLoginServices() + { + return loginServices; + } + + public void setLoginServices(List loginServices) + { + if (loginServices == null) + this.loginServices = null; + else + this.loginServices = new ArrayList<>(loginServices); + } + + public RequestLog getRequestLog() + { + return requestLog; + } + + public void setRequestLog(RequestLog requestLog) + { + this.requestLog = requestLog; + } + + public MavenServerConnector getHttpConnector() + { + return httpConnector; + } + + public void setHttpConnector(MavenServerConnector httpConnector) + { + this.httpConnector = httpConnector; + } + + public Server getServer() + { + return server; + } + + public void setServer(Server server) + { + this.server = server; + } + + public boolean isExitVm() + { + return exitVm; + } + + public void setExitVm(boolean exitVm) + { + this.exitVm = exitVm; + } + + public boolean isStopAtShutdown() + { + return stopAtShutdown; + } + + public void setStopAtShutdown(boolean stopAtShutdown) + { + this.stopAtShutdown = stopAtShutdown; + } + + public List getJettyXmlFiles() + { + return jettyXmlFiles; + } + + public void setJettyXmlFiles(List jettyXmlFiles) + { + this.jettyXmlFiles = jettyXmlFiles; + } + + public Map getJettyProperties() + { + return jettyProperties; + } + + public void setJettyProperties(Map jettyProperties) + { + this.jettyProperties = jettyProperties; + } + + public ShutdownMonitor getShutdownMonitor() + { + return shutdownMonitor; + } + + public void setShutdownMonitor(ShutdownMonitor shutdownMonitor) + { + this.shutdownMonitor = shutdownMonitor; + } + + 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 void setWebAppProperties(Properties props) + { + if (webAppProperties != null) + webAppProperties.clear(); + + if (props != null) + { + if (webAppProperties == null) + webAppProperties = new Properties(); + + webAppProperties.putAll(props); + } + } + + public String getContextXml() + { + return contextXml; + } + + public void setContextXml(String contextXml) + { + this.contextXml = contextXml; + } + + public void doStart() throws Exception + { + super.doStart(); + + configure(); + configureShutdownMonitor(); + server.start(); + } + + protected abstract void redeployWebApp() throws Exception; + + public void redeployWebApp(Properties webaAppProperties) throws Exception + { + setWebAppProperties(webaAppProperties); + redeployWebApp(); + } + + public abstract void stopWebApp() throws Exception; + + public void join() throws InterruptedException + { + server.join(); + } + + /** + * Configure the server and the webapp + * @throws Exception if there is an unspecified problem + */ + protected void configure() throws Exception + { + configureServer(); + configureWebApp(); + addWebAppToServer(); + } + + protected void configureServer() throws Exception + { + //apply any configs from jetty.xml files first + Server tmp = ServerSupport.applyXmlConfigurations(new Server(), jettyXmlFiles, jettyProperties); + + if (tmp != null) + server = tmp; + + server.setStopAtShutdown(stopAtShutdown); + + //ensure there's a connector + if (httpConnector != null) + httpConnector.setServer(server); + + ServerSupport.configureConnectors(server, httpConnector, jettyProperties); + + //set up handler structure + ServerSupport.configureHandlers(server, contextHandlers, requestLog); + + // set up security realms + ServerSupport.configureLoginServices(server, loginServices); + } + + protected abstract void configureWebApp() throws Exception; + + protected abstract void addWebAppToServer() throws Exception; + + protected void applyWebAppProperties() throws Exception + { + //apply properties to the webapp if there are any + if (contextXml != null) + { + if (webAppProperties == null) + webAppProperties = new Properties(); + + webAppProperties.put("context.xml", contextXml); + } + } + + private void configureShutdownMonitor() + { + if (stopPort > 0 && stopKey != null) + { + ShutdownMonitor monitor = ShutdownMonitor.getInstance(); + monitor.setPort(stopPort); + monitor.setKey(stopKey); + monitor.setExitVm(exitVm); + } + } +} diff --git a/jetty-core/jetty-maven/src/main/java/org/eclipse/jetty/maven/AbstractServerForker.java b/jetty-core/jetty-maven/src/main/java/org/eclipse/jetty/maven/AbstractServerForker.java new file mode 100644 index 000000000000..df8e433eebdc --- /dev/null +++ b/jetty-core/jetty-maven/src/main/java/org/eclipse/jetty/maven/AbstractServerForker.java @@ -0,0 +1,276 @@ +// +// ======================================================================== +// 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.maven; + +import java.io.File; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import org.eclipse.jetty.server.Server; + +/** + * AbstractServerForker + * + * Fork a jetty Server + */ +public abstract class AbstractServerForker extends AbstractForker +{ + protected File forkWebXml; + protected Server server; + protected String containerClassPath; + protected File webAppPropsFile; + protected String contextXml; + protected int scanInterval; + protected String executionClassName; + + /** + * @return the scan + */ + public boolean isScan() + { + return scanInterval > 0; + } + + /** + * Set if true, the forked child will scan for changes at 1 second intervals. + * @param scan if true, the forked child will scan for changes at 1 second intervals + */ + public void setScan(boolean scan) + { + setScanInterval(scan ? 1 : 0); + } + + public int getScanInterval() + { + return scanInterval; + } + + public void setScanInterval(int sec) + { + scanInterval = sec; + } + + public File getWebAppPropsFile() + { + return webAppPropsFile; + } + + public void setWebAppPropsFile(File webAppPropsFile) + { + this.webAppPropsFile = webAppPropsFile; + } + + public File getForkWebXml() + { + return forkWebXml; + } + + public void setForkWebXml(File forkWebXml) + { + this.forkWebXml = forkWebXml; + } + + public String getContextXml() + { + return contextXml; + } + + public void setContextXml(String contextXml) + { + this.contextXml = contextXml; + } + + public String getContainerClassPath() + { + return containerClassPath; + } + + public void setContainerClassPath(String containerClassPath) + { + this.containerClassPath = containerClassPath; + } + + public Server getServer() + { + return server; + } + + public void setServer(Server server) + { + this.server = server; + } + + @Override + public void doStart() + throws Exception + { + generateWebApp(); + super.doStart(); + } + + protected abstract void generateWebApp() throws Exception; + + protected abstract void redeployWebApp() throws Exception; + + public ProcessBuilder createCommand() + { + List cmd = new ArrayList(); + cmd.add(getJavaBin()); + + if (jvmArgs != null) + { + String[] args = jvmArgs.split(" "); + for (int i = 0; args != null && i < args.length; i++) + { + if (args[i] != null && !"".equals(args[i])) + cmd.add(args[i].trim()); + } + } + + if (systemProperties != null) + { + for (Map.Entry e:systemProperties.entrySet()) + { + cmd.add("-D" + e.getKey() + "=" + e.getValue()); + } + } + + if (containerClassPath != null && containerClassPath.length() > 0) + { + cmd.add("-cp"); + cmd.add(containerClassPath); + } + + cmd.add(executionClassName); + + if (stopPort > 0 && stopKey != null) + { + cmd.add("--stop-port"); + cmd.add(Integer.toString(stopPort)); + cmd.add("--stop-key"); + cmd.add(stopKey); + } + if (jettyXmlFiles != null) + { + cmd.add("--jetty-xml"); + StringBuilder tmp = new StringBuilder(); + for (File jettyXml:jettyXmlFiles) + { + if (tmp.length() != 0) + tmp.append(","); + tmp.append(jettyXml.getAbsolutePath()); + } + cmd.add(tmp.toString()); + } + + cmd.add("--webprops"); + cmd.add(webAppPropsFile.getAbsolutePath()); + + cmd.add("--token"); + cmd.add(tokenFile.getAbsolutePath()); + + if (scanInterval > 0) + { + cmd.add("--scanInterval"); + cmd.add(Integer.toString(scanInterval)); + } + + if (jettyProperties != null) + { + for (Map.Entry e:jettyProperties.entrySet()) + { + cmd.add(e.getKey() + "=" + e.getValue()); + } + } + + ProcessBuilder command = new ProcessBuilder(cmd); + command.directory(workDir); + + if (PluginLog.getLog().isDebugEnabled()) + PluginLog.getLog().debug("Forked cli:" + command.command()); + + PluginLog.getLog().info("Forked process starting"); + + //set up extra environment vars if there are any + if (env != null && !env.isEmpty()) + command.environment().putAll(env); + + if (waitForChild) + { + command.inheritIO(); + } + else + { + command.redirectOutput(jettyOutputFile); + command.redirectErrorStream(true); + } + return command; + } + + /** + * Get the location of the java binary. + * @return the location of the java binary + */ + private String getJavaBin() + { + String[] javaexes = new String[]{"java", "java.exe"}; + + File javaHomeDir = new File(System.getProperty("java.home")); + for (String javaexe : javaexes) + { + File javabin = new File(javaHomeDir, fileSeparators("bin/" + javaexe)); + if (javabin.exists() && javabin.isFile()) + { + return javabin.getAbsolutePath(); + } + } + + return "java"; + } + + public static String fileSeparators(String path) + { + StringBuilder ret = new StringBuilder(); + for (char c : path.toCharArray()) + { + if ((c == '/') || (c == '\\')) + { + ret.append(File.separatorChar); + } + else + { + ret.append(c); + } + } + return ret.toString(); + } + + public static String pathSeparators(String path) + { + StringBuilder ret = new StringBuilder(); + for (char c : path.toCharArray()) + { + if ((c == ',') || (c == ':')) + { + ret.append(File.pathSeparatorChar); + } + else + { + ret.append(c); + } + } + return ret.toString(); + } +} diff --git a/jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/ConsoleReader.java b/jetty-core/jetty-maven/src/main/java/org/eclipse/jetty/maven/ConsoleReader.java similarity index 97% rename from jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/ConsoleReader.java rename to jetty-core/jetty-maven/src/main/java/org/eclipse/jetty/maven/ConsoleReader.java index 761eb5461891..9c708e11a999 100644 --- a/jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/ConsoleReader.java +++ b/jetty-core/jetty-maven/src/main/java/org/eclipse/jetty/maven/ConsoleReader.java @@ -11,7 +11,7 @@ // ======================================================================== // -package org.eclipse.jetty.ee9.maven.plugin; +package org.eclipse.jetty.maven; import java.io.Console; import java.util.EventListener; diff --git a/jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/utils/MavenProjectHelper.java b/jetty-core/jetty-maven/src/main/java/org/eclipse/jetty/maven/MavenProjectHelper.java similarity index 97% rename from jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/utils/MavenProjectHelper.java rename to jetty-core/jetty-maven/src/main/java/org/eclipse/jetty/maven/MavenProjectHelper.java index b336f55debdc..54dcc0ad1b66 100644 --- a/jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/utils/MavenProjectHelper.java +++ b/jetty-core/jetty-maven/src/main/java/org/eclipse/jetty/maven/MavenProjectHelper.java @@ -11,7 +11,7 @@ // ======================================================================== // -package org.eclipse.jetty.ee9.maven.plugin.utils; +package org.eclipse.jetty.maven; import java.io.File; import java.nio.file.Path; @@ -35,8 +35,6 @@ import org.eclipse.aether.resolution.ArtifactRequest; import org.eclipse.aether.resolution.ArtifactResolutionException; import org.eclipse.aether.resolution.ArtifactResult; -import org.eclipse.jetty.ee9.maven.plugin.OverlayManager; -import org.eclipse.jetty.ee9.maven.plugin.WarPluginInfo; /** * MavenProjectHelper diff --git a/jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/MavenResource.java b/jetty-core/jetty-maven/src/main/java/org/eclipse/jetty/maven/MavenResource.java similarity index 99% rename from jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/MavenResource.java rename to jetty-core/jetty-maven/src/main/java/org/eclipse/jetty/maven/MavenResource.java index 78d6783cc5a0..42475de50fda 100644 --- a/jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/MavenResource.java +++ b/jetty-core/jetty-maven/src/main/java/org/eclipse/jetty/maven/MavenResource.java @@ -11,7 +11,7 @@ // ======================================================================== // -package org.eclipse.jetty.ee9.maven.plugin; +package org.eclipse.jetty.maven; import java.io.IOException; import java.io.InputStream; diff --git a/jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/MavenServerConnector.java b/jetty-core/jetty-maven/src/main/java/org/eclipse/jetty/maven/MavenServerConnector.java similarity index 99% rename from jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/MavenServerConnector.java rename to jetty-core/jetty-maven/src/main/java/org/eclipse/jetty/maven/MavenServerConnector.java index a44816ef2ce4..d0a482cc9e7c 100644 --- a/jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/MavenServerConnector.java +++ b/jetty-core/jetty-maven/src/main/java/org/eclipse/jetty/maven/MavenServerConnector.java @@ -11,7 +11,7 @@ // ======================================================================== // -package org.eclipse.jetty.ee9.maven.plugin; +package org.eclipse.jetty.maven; import java.util.Collection; import java.util.List; diff --git a/jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/Overlay.java b/jetty-core/jetty-maven/src/main/java/org/eclipse/jetty/maven/Overlay.java similarity index 98% rename from jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/Overlay.java rename to jetty-core/jetty-maven/src/main/java/org/eclipse/jetty/maven/Overlay.java index cb9529783d33..a1b51e3d0e6f 100644 --- a/jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/Overlay.java +++ b/jetty-core/jetty-maven/src/main/java/org/eclipse/jetty/maven/Overlay.java @@ -11,7 +11,7 @@ // ======================================================================== // -package org.eclipse.jetty.ee9.maven.plugin; +package org.eclipse.jetty.maven; import java.io.File; import java.io.IOException; diff --git a/jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/OverlayConfig.java b/jetty-core/jetty-maven/src/main/java/org/eclipse/jetty/maven/OverlayConfig.java similarity index 99% rename from jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/OverlayConfig.java rename to jetty-core/jetty-maven/src/main/java/org/eclipse/jetty/maven/OverlayConfig.java index f31016a69ac7..4bbec73160ba 100644 --- a/jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/OverlayConfig.java +++ b/jetty-core/jetty-maven/src/main/java/org/eclipse/jetty/maven/OverlayConfig.java @@ -11,7 +11,7 @@ // ======================================================================== // -package org.eclipse.jetty.ee9.maven.plugin; +package org.eclipse.jetty.maven; import java.util.ArrayList; import java.util.Arrays; diff --git a/jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/OverlayManager.java b/jetty-core/jetty-maven/src/main/java/org/eclipse/jetty/maven/OverlayManager.java similarity index 77% rename from jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/OverlayManager.java rename to jetty-core/jetty-maven/src/main/java/org/eclipse/jetty/maven/OverlayManager.java index 23cfb3672b46..7c024e0931bf 100644 --- a/jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/OverlayManager.java +++ b/jetty-core/jetty-maven/src/main/java/org/eclipse/jetty/maven/OverlayManager.java @@ -11,7 +11,7 @@ // ======================================================================== // -package org.eclipse.jetty.ee9.maven.plugin; +package org.eclipse.jetty.maven; import java.io.File; import java.io.IOException; @@ -24,7 +24,7 @@ import java.util.Set; import org.apache.maven.artifact.Artifact; -import org.eclipse.jetty.ee9.webapp.WebAppContext; +import org.eclipse.jetty.server.handler.ContextHandler; import org.eclipse.jetty.util.URIUtil; import org.eclipse.jetty.util.resource.MountedPathResource; import org.eclipse.jetty.util.resource.Resource; @@ -45,41 +45,41 @@ public OverlayManager(WarPluginInfo warPlugin) this.warPlugin = warPlugin; } - public void applyOverlays(MavenWebAppContext webApp) + public void applyOverlays(ContextHandler contextHandler, boolean append) throws Exception { List resourceBases = new ArrayList(); - for (Overlay o : getOverlays(webApp)) + for (Overlay o : getOverlays(contextHandler)) { //can refer to the current project in list of overlays for ordering purposes - if (o.getConfig() != null && o.getConfig().isCurrentProject() && webApp.getBaseResource().exists()) + if (o.getConfig() != null && o.getConfig().isCurrentProject() && contextHandler.getBaseResource().exists()) { - resourceBases.add(webApp.getBaseResource()); + resourceBases.add(contextHandler.getBaseResource()); continue; } //add in the selectively unpacked overlay in the correct order to the webapp's resource base - resourceBases.add(unpackOverlay(webApp, o)); + resourceBases.add(unpackOverlay(contextHandler, o)); } - if (!resourceBases.contains(webApp.getBaseResource()) && webApp.getBaseResource().exists()) + if (!resourceBases.contains(contextHandler.getBaseResource()) && contextHandler.getBaseResource().exists()) { - if (webApp.getBaseAppFirst()) - resourceBases.add(0, webApp.getBaseResource()); + if (append) + resourceBases.add(0, contextHandler.getBaseResource()); else - resourceBases.add(webApp.getBaseResource()); + resourceBases.add(contextHandler.getBaseResource()); } - webApp.setBaseResource(ResourceFactory.combine(resourceBases)); + contextHandler.setBaseResource(ResourceFactory.combine(resourceBases)); } /** * Generate an ordered list of overlays */ - protected List getOverlays(WebAppContext webApp) + private List getOverlays(ContextHandler contextHandler) throws Exception { - Objects.requireNonNull(webApp); + Objects.requireNonNull(contextHandler); Set matchedWarArtifacts = new HashSet(); List overlays = new ArrayList(); @@ -104,7 +104,7 @@ protected List getOverlays(WebAppContext webApp) if (a != null) { matchedWarArtifacts.add(a); - Resource resource = webApp.getResourceFactory().newJarFileResource(a.getFile().toPath().toUri()); + Resource resource = ResourceFactory.of(contextHandler).newJarFileResource(a.getFile().toPath().toUri()); SelectiveJarResource r = new SelectiveJarResource(resource); r.setIncludes(config.getIncludes()); r.setExcludes(config.getExcludes()); @@ -118,7 +118,7 @@ protected List getOverlays(WebAppContext webApp) { if (!matchedWarArtifacts.contains(a)) { - Resource resource = webApp.getResourceFactory().newJarFileResource(a.getFile().toPath().toUri()); + Resource resource = ResourceFactory.of(contextHandler).newJarFileResource(a.getFile().toPath().toUri()); Overlay overlay = new Overlay(null, resource); overlays.add(overlay); } @@ -133,10 +133,10 @@ protected List getOverlays(WebAppContext webApp) * @return the location to which it was unpacked * @throws IOException if there is an IO problem */ - protected Resource unpackOverlay(WebAppContext webApp, Overlay overlay) + protected Resource unpackOverlay(ContextHandler contextHandler, Overlay overlay) throws IOException { - Objects.requireNonNull(webApp); + Objects.requireNonNull(contextHandler); Objects.requireNonNull(overlay); if (overlay.getResource() == null) @@ -161,6 +161,6 @@ protected Resource unpackOverlay(WebAppContext webApp, Overlay overlay) overlay.unpackTo(unpackDir); //use top level of unpacked content - return webApp.getResourceFactory().newResource(unpackDir.getCanonicalPath()); + return ResourceFactory.of(contextHandler).newResource(unpackDir.getCanonicalPath()); } } diff --git a/jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/PluginLog.java b/jetty-core/jetty-maven/src/main/java/org/eclipse/jetty/maven/PluginLog.java similarity index 95% rename from jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/PluginLog.java rename to jetty-core/jetty-maven/src/main/java/org/eclipse/jetty/maven/PluginLog.java index 131647b75514..5823846d8bc0 100644 --- a/jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/PluginLog.java +++ b/jetty-core/jetty-maven/src/main/java/org/eclipse/jetty/maven/PluginLog.java @@ -11,7 +11,7 @@ // ======================================================================== // -package org.eclipse.jetty.ee9.maven.plugin; +package org.eclipse.jetty.maven; import org.apache.maven.plugin.logging.Log; diff --git a/jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/ScanPattern.java b/jetty-core/jetty-maven/src/main/java/org/eclipse/jetty/maven/ScanPattern.java similarity index 96% rename from jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/ScanPattern.java rename to jetty-core/jetty-maven/src/main/java/org/eclipse/jetty/maven/ScanPattern.java index 41d0c77be7d0..963222fc2dc8 100644 --- a/jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/ScanPattern.java +++ b/jetty-core/jetty-maven/src/main/java/org/eclipse/jetty/maven/ScanPattern.java @@ -11,7 +11,7 @@ // ======================================================================== // -package org.eclipse.jetty.ee9.maven.plugin; +package org.eclipse.jetty.maven; import java.util.Collections; import java.util.List; diff --git a/jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/ScanTargetPattern.java b/jetty-core/jetty-maven/src/main/java/org/eclipse/jetty/maven/ScanTargetPattern.java similarity index 98% rename from jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/ScanTargetPattern.java rename to jetty-core/jetty-maven/src/main/java/org/eclipse/jetty/maven/ScanTargetPattern.java index 9523ecca5372..5ddcbca2676c 100644 --- a/jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/ScanTargetPattern.java +++ b/jetty-core/jetty-maven/src/main/java/org/eclipse/jetty/maven/ScanTargetPattern.java @@ -11,7 +11,7 @@ // ======================================================================== // -package org.eclipse.jetty.ee9.maven.plugin; +package org.eclipse.jetty.maven; import java.io.File; import java.nio.file.Path; diff --git a/jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/SelectiveJarResource.java b/jetty-core/jetty-maven/src/main/java/org/eclipse/jetty/maven/SelectiveJarResource.java similarity index 99% rename from jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/SelectiveJarResource.java rename to jetty-core/jetty-maven/src/main/java/org/eclipse/jetty/maven/SelectiveJarResource.java index bacf30075355..8e8c44f983e6 100644 --- a/jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/SelectiveJarResource.java +++ b/jetty-core/jetty-maven/src/main/java/org/eclipse/jetty/maven/SelectiveJarResource.java @@ -11,7 +11,7 @@ // ======================================================================== // -package org.eclipse.jetty.ee9.maven.plugin; +package org.eclipse.jetty.maven; import java.io.IOException; import java.io.InputStream; diff --git a/jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/ServerConnectorListener.java b/jetty-core/jetty-maven/src/main/java/org/eclipse/jetty/maven/ServerConnectorListener.java similarity index 98% rename from jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/ServerConnectorListener.java rename to jetty-core/jetty-maven/src/main/java/org/eclipse/jetty/maven/ServerConnectorListener.java index d83562448876..ba2079670aca 100644 --- a/jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/ServerConnectorListener.java +++ b/jetty-core/jetty-maven/src/main/java/org/eclipse/jetty/maven/ServerConnectorListener.java @@ -11,7 +11,7 @@ // ======================================================================== // -package org.eclipse.jetty.ee9.maven.plugin; +package org.eclipse.jetty.maven; import java.io.Writer; import java.nio.file.AtomicMoveNotSupportedException; diff --git a/jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/ServerListener.java b/jetty-core/jetty-maven/src/main/java/org/eclipse/jetty/maven/ServerListener.java similarity index 97% rename from jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/ServerListener.java rename to jetty-core/jetty-maven/src/main/java/org/eclipse/jetty/maven/ServerListener.java index c57663c95e59..f8cf53dd5ce8 100644 --- a/jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/ServerListener.java +++ b/jetty-core/jetty-maven/src/main/java/org/eclipse/jetty/maven/ServerListener.java @@ -11,7 +11,7 @@ // ======================================================================== // -package org.eclipse.jetty.ee9.maven.plugin; +package org.eclipse.jetty.maven; import java.nio.file.Files; import java.nio.file.Path; diff --git a/jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/ServerSupport.java b/jetty-core/jetty-maven/src/main/java/org/eclipse/jetty/maven/ServerSupport.java similarity index 95% rename from jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/ServerSupport.java rename to jetty-core/jetty-maven/src/main/java/org/eclipse/jetty/maven/ServerSupport.java index 079c646ea57b..5dd105b260c5 100644 --- a/jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/ServerSupport.java +++ b/jetty-core/jetty-maven/src/main/java/org/eclipse/jetty/maven/ServerSupport.java @@ -11,7 +11,7 @@ // ======================================================================== // -package org.eclipse.jetty.ee9.maven.plugin; +package org.eclipse.jetty.maven; import java.io.File; import java.util.Enumeration; @@ -19,8 +19,8 @@ import java.util.List; import java.util.Map; -import org.eclipse.jetty.ee9.webapp.Configurations; -import org.eclipse.jetty.ee9.webapp.WebAppContext; +import org.eclipse.jetty.maven.MavenServerConnector; +import org.eclipse.jetty.maven.PluginLog; import org.eclipse.jetty.security.LoginService; import org.eclipse.jetty.server.Connector; import org.eclipse.jetty.server.RequestLog; @@ -37,12 +37,6 @@ */ public class ServerSupport { - - public static void configureDefaultConfigurationClasses(Server server) - { - Configurations.setServerDefault(server); - } - /** * Set up the handler structure to receive a webapp. * Also put in a DefaultHandler so we get a nicer page @@ -144,7 +138,7 @@ public static void configureLoginServices(Server server, List logi * @param webapp the webapp to add * @throws Exception if there is an unspecified problem */ - public static void addWebApplication(Server server, WebAppContext webapp) throws Exception + public static void addWebApplication(Server server, ContextHandler webapp) throws Exception { if (server == null) throw new IllegalArgumentException("Server is null"); diff --git a/jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/WarPluginInfo.java b/jetty-core/jetty-maven/src/main/java/org/eclipse/jetty/maven/WarPluginInfo.java similarity index 99% rename from jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/WarPluginInfo.java rename to jetty-core/jetty-maven/src/main/java/org/eclipse/jetty/maven/WarPluginInfo.java index b028a2e70e34..051a33ca3455 100644 --- a/jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/WarPluginInfo.java +++ b/jetty-core/jetty-maven/src/main/java/org/eclipse/jetty/maven/WarPluginInfo.java @@ -11,7 +11,7 @@ // ======================================================================== // -package org.eclipse.jetty.ee9.maven.plugin; +package org.eclipse.jetty.maven; import java.util.ArrayList; import java.util.Collections; diff --git a/jetty-core/pom.xml b/jetty-core/pom.xml index 97f9ff5401c3..c5f629994c1e 100644 --- a/jetty-core/pom.xml +++ b/jetty-core/pom.xml @@ -28,6 +28,7 @@ jetty-jmx jetty-jndi jetty-keystore + jetty-maven jetty-openid jetty-osgi jetty-plus diff --git a/jetty-ee10/jetty-ee10-maven-plugin/pom.xml b/jetty-ee10/jetty-ee10-maven-plugin/pom.xml index b86cc5b7d503..2d4ed9fe4cb0 100644 --- a/jetty-ee10/jetty-ee10-maven-plugin/pom.xml +++ b/jetty-ee10/jetty-ee10-maven-plugin/pom.xml @@ -81,6 +81,11 @@ jetty-jndi true + + org.eclipse.jetty + jetty-maven + true + org.eclipse.jetty jetty-security diff --git a/jetty-ee10/jetty-ee10-maven-plugin/src/it/jetty-cdi-start-forked/src/main/jetty/jetty.xml b/jetty-ee10/jetty-ee10-maven-plugin/src/it/jetty-cdi-start-forked/src/main/jetty/jetty.xml index e2575774e666..8a8f26b49f4f 100644 --- a/jetty-ee10/jetty-ee10-maven-plugin/src/it/jetty-cdi-start-forked/src/main/jetty/jetty.xml +++ b/jetty-ee10/jetty-ee10-maven-plugin/src/it/jetty-cdi-start-forked/src/main/jetty/jetty.xml @@ -26,7 +26,7 @@ - + diff --git a/jetty-ee10/jetty-ee10-maven-plugin/src/it/jetty-combinedresource-it/src/config/jetty.xml b/jetty-ee10/jetty-ee10-maven-plugin/src/it/jetty-combinedresource-it/src/config/jetty.xml index 445b59619142..343f5e7f99b1 100644 --- a/jetty-ee10/jetty-ee10-maven-plugin/src/it/jetty-combinedresource-it/src/config/jetty.xml +++ b/jetty-ee10/jetty-ee10-maven-plugin/src/it/jetty-combinedresource-it/src/config/jetty.xml @@ -26,7 +26,7 @@ - + diff --git a/jetty-ee10/jetty-ee10-maven-plugin/src/it/jetty-maven-plugin-provided-module-dep/web/src/config/jetty.xml b/jetty-ee10/jetty-ee10-maven-plugin/src/it/jetty-maven-plugin-provided-module-dep/web/src/config/jetty.xml index 0a3a743a2c46..ef0c9bcad939 100644 --- a/jetty-ee10/jetty-ee10-maven-plugin/src/it/jetty-maven-plugin-provided-module-dep/web/src/config/jetty.xml +++ b/jetty-ee10/jetty-ee10-maven-plugin/src/it/jetty-maven-plugin-provided-module-dep/web/src/config/jetty.xml @@ -32,7 +32,7 @@ - + diff --git a/jetty-ee10/jetty-ee10-maven-plugin/src/it/jetty-run-mojo-jar-scan-it/MyWebApp/src/config/jetty.xml b/jetty-ee10/jetty-ee10-maven-plugin/src/it/jetty-run-mojo-jar-scan-it/MyWebApp/src/config/jetty.xml index 657264f32231..58c5b2751216 100644 --- a/jetty-ee10/jetty-ee10-maven-plugin/src/it/jetty-run-mojo-jar-scan-it/MyWebApp/src/config/jetty.xml +++ b/jetty-ee10/jetty-ee10-maven-plugin/src/it/jetty-run-mojo-jar-scan-it/MyWebApp/src/config/jetty.xml @@ -25,7 +25,7 @@ - + diff --git a/jetty-ee10/jetty-ee10-maven-plugin/src/it/jetty-start-distro-mojo-it/jetty-simple-webapp/src/base/etc/test-jetty-ee10.xml b/jetty-ee10/jetty-ee10-maven-plugin/src/it/jetty-start-distro-mojo-it/jetty-simple-webapp/src/base/etc/test-jetty-ee10.xml index 6ba1c7f8e1f1..9857cb546ef7 100644 --- a/jetty-ee10/jetty-ee10-maven-plugin/src/it/jetty-start-distro-mojo-it/jetty-simple-webapp/src/base/etc/test-jetty-ee10.xml +++ b/jetty-ee10/jetty-ee10-maven-plugin/src/it/jetty-start-distro-mojo-it/jetty-simple-webapp/src/base/etc/test-jetty-ee10.xml @@ -5,7 +5,7 @@ - + diff --git a/jetty-ee10/jetty-ee10-maven-plugin/src/it/jetty-start-forked-mojo-it/jetty-simple-webapp/src/config/jetty.xml b/jetty-ee10/jetty-ee10-maven-plugin/src/it/jetty-start-forked-mojo-it/jetty-simple-webapp/src/config/jetty.xml index 445b59619142..343f5e7f99b1 100644 --- a/jetty-ee10/jetty-ee10-maven-plugin/src/it/jetty-start-forked-mojo-it/jetty-simple-webapp/src/config/jetty.xml +++ b/jetty-ee10/jetty-ee10-maven-plugin/src/it/jetty-start-forked-mojo-it/jetty-simple-webapp/src/config/jetty.xml @@ -26,7 +26,7 @@ - + diff --git a/jetty-ee10/jetty-ee10-maven-plugin/src/it/jetty-start-gwt-it/beer-server/src/config/jetty.xml b/jetty-ee10/jetty-ee10-maven-plugin/src/it/jetty-start-gwt-it/beer-server/src/config/jetty.xml index 445b59619142..343f5e7f99b1 100644 --- a/jetty-ee10/jetty-ee10-maven-plugin/src/it/jetty-start-gwt-it/beer-server/src/config/jetty.xml +++ b/jetty-ee10/jetty-ee10-maven-plugin/src/it/jetty-start-gwt-it/beer-server/src/config/jetty.xml @@ -26,7 +26,7 @@ - + diff --git a/jetty-ee10/jetty-ee10-maven-plugin/src/it/jetty-start-mojo-it/jetty-simple-webapp/pom.xml b/jetty-ee10/jetty-ee10-maven-plugin/src/it/jetty-start-mojo-it/jetty-simple-webapp/pom.xml index 94254ab8f283..521f49c0d94e 100644 --- a/jetty-ee10/jetty-ee10-maven-plugin/src/it/jetty-start-mojo-it/jetty-simple-webapp/pom.xml +++ b/jetty-ee10/jetty-ee10-maven-plugin/src/it/jetty-start-mojo-it/jetty-simple-webapp/pom.xml @@ -112,7 +112,7 @@ - + ${basedir}/src/config/login.xml diff --git a/jetty-ee10/jetty-ee10-maven-plugin/src/it/jetty-start-mojo-it/jetty-simple-webapp/src/config/jetty.xml b/jetty-ee10/jetty-ee10-maven-plugin/src/it/jetty-start-mojo-it/jetty-simple-webapp/src/config/jetty.xml index 445b59619142..343f5e7f99b1 100644 --- a/jetty-ee10/jetty-ee10-maven-plugin/src/it/jetty-start-mojo-it/jetty-simple-webapp/src/config/jetty.xml +++ b/jetty-ee10/jetty-ee10-maven-plugin/src/it/jetty-start-mojo-it/jetty-simple-webapp/src/config/jetty.xml @@ -26,7 +26,7 @@ - + diff --git a/jetty-ee10/jetty-ee10-maven-plugin/src/it/jetty-start-mojo-multi-module-single-war-it/webapp-war/src/config/jetty.xml b/jetty-ee10/jetty-ee10-maven-plugin/src/it/jetty-start-mojo-multi-module-single-war-it/webapp-war/src/config/jetty.xml index 445b59619142..343f5e7f99b1 100644 --- a/jetty-ee10/jetty-ee10-maven-plugin/src/it/jetty-start-mojo-multi-module-single-war-it/webapp-war/src/config/jetty.xml +++ b/jetty-ee10/jetty-ee10-maven-plugin/src/it/jetty-start-mojo-multi-module-single-war-it/webapp-war/src/config/jetty.xml @@ -26,7 +26,7 @@ - + diff --git a/jetty-ee10/jetty-ee10-maven-plugin/src/it/jetty-start-overlay-it/jetty-simple-webapp/src/config/jetty.xml b/jetty-ee10/jetty-ee10-maven-plugin/src/it/jetty-start-overlay-it/jetty-simple-webapp/src/config/jetty.xml index 445b59619142..343f5e7f99b1 100644 --- a/jetty-ee10/jetty-ee10-maven-plugin/src/it/jetty-start-overlay-it/jetty-simple-webapp/src/config/jetty.xml +++ b/jetty-ee10/jetty-ee10-maven-plugin/src/it/jetty-start-overlay-it/jetty-simple-webapp/src/config/jetty.xml @@ -26,7 +26,7 @@ - + diff --git a/jetty-ee10/jetty-ee10-maven-plugin/src/it/jetty-start-war-distro-mojo-it/jetty-simple-webapp/src/base/etc/test-jetty-ee10.xml b/jetty-ee10/jetty-ee10-maven-plugin/src/it/jetty-start-war-distro-mojo-it/jetty-simple-webapp/src/base/etc/test-jetty-ee10.xml index 6ba1c7f8e1f1..9857cb546ef7 100644 --- a/jetty-ee10/jetty-ee10-maven-plugin/src/it/jetty-start-war-distro-mojo-it/jetty-simple-webapp/src/base/etc/test-jetty-ee10.xml +++ b/jetty-ee10/jetty-ee10-maven-plugin/src/it/jetty-start-war-distro-mojo-it/jetty-simple-webapp/src/base/etc/test-jetty-ee10.xml @@ -5,7 +5,7 @@ - + diff --git a/jetty-ee10/jetty-ee10-maven-plugin/src/it/jetty-start-war-forked-mojo-it/jetty-simple-webapp/src/config/jetty.xml b/jetty-ee10/jetty-ee10-maven-plugin/src/it/jetty-start-war-forked-mojo-it/jetty-simple-webapp/src/config/jetty.xml index 445b59619142..343f5e7f99b1 100644 --- a/jetty-ee10/jetty-ee10-maven-plugin/src/it/jetty-start-war-forked-mojo-it/jetty-simple-webapp/src/config/jetty.xml +++ b/jetty-ee10/jetty-ee10-maven-plugin/src/it/jetty-start-war-forked-mojo-it/jetty-simple-webapp/src/config/jetty.xml @@ -26,7 +26,7 @@ - + diff --git a/jetty-ee10/jetty-ee10-maven-plugin/src/it/jetty-start-war-mojo-it/src/config/jetty.xml b/jetty-ee10/jetty-ee10-maven-plugin/src/it/jetty-start-war-mojo-it/src/config/jetty.xml index 445b59619142..343f5e7f99b1 100644 --- a/jetty-ee10/jetty-ee10-maven-plugin/src/it/jetty-start-war-mojo-it/src/config/jetty.xml +++ b/jetty-ee10/jetty-ee10-maven-plugin/src/it/jetty-start-war-mojo-it/src/config/jetty.xml @@ -26,7 +26,7 @@ - + diff --git a/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/AbstractForker.java b/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/AbstractForker.java deleted file mode 100644 index 690611f84a71..000000000000 --- a/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/AbstractForker.java +++ /dev/null @@ -1,251 +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.maven.plugin; - -import java.io.File; -import java.util.List; -import java.util.Map; - -import org.eclipse.jetty.util.component.AbstractLifeCycle; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * AbstractForker - * - * Base class for forking jetty. - */ -public abstract class AbstractForker extends AbstractLifeCycle -{ - private static final Logger LOG = LoggerFactory.getLogger(AbstractForker.class); - - protected Map env; - - protected String jvmArgs; - - protected boolean exitVm; - - protected boolean stopAtShutdown; - - protected List jettyXmlFiles; - - protected Map jettyProperties; - - protected int stopPort; - - protected String stopKey; - - protected File jettyOutputFile; - - protected boolean waitForChild; - - protected int maxChildStartChecks = 10; //check up to 10 times for child to start - - protected long maxChildStartCheckMs = 200; //wait 200ms between checks - - protected File tokenFile; - - protected File workDir; - - protected Map systemProperties; - - protected abstract ProcessBuilder createCommand(); - - protected abstract void redeployWebApp() throws Exception; - - public File getWorkDir() - { - return workDir; - } - - public void setWorkDir(File workDir) - { - this.workDir = workDir; - } - - /** - * @return the systemProperties - */ - public Map getSystemProperties() - { - return systemProperties; - } - - /** - * Set the systemProperties to set. - * @param systemProperties the systemProperties to set - */ - public void setSystemProperties(Map systemProperties) - { - this.systemProperties = systemProperties; - } - - public Map getEnv() - { - return env; - } - - public void setEnv(Map env) - { - this.env = env; - } - - public String getJvmArgs() - { - return jvmArgs; - } - - public void setJvmArgs(String jvmArgs) - { - this.jvmArgs = jvmArgs; - } - - public boolean isExitVm() - { - return exitVm; - } - - public void setExitVm(boolean exitVm) - { - this.exitVm = exitVm; - } - - public boolean isStopAtShutdown() - { - return stopAtShutdown; - } - - public void setStopAtShutdown(boolean stopAtShutdown) - { - this.stopAtShutdown = stopAtShutdown; - } - - public List getJettyXmlFiles() - { - return jettyXmlFiles; - } - - public void setJettyXmlFiles(List jettyXmlFiles) - { - this.jettyXmlFiles = jettyXmlFiles; - } - - public Map getJettyProperties() - { - return jettyProperties; - } - - public void setJettyProperties(Map jettyProperties) - { - this.jettyProperties = jettyProperties; - } - - 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 getJettyOutputFile() - { - return jettyOutputFile; - } - - public void setJettyOutputFile(File jettyOutputFile) - { - this.jettyOutputFile = jettyOutputFile; - } - - public boolean isWaitForChild() - { - return waitForChild; - } - - public void setWaitForChild(boolean waitForChild) - { - this.waitForChild = waitForChild; - } - - public int getMaxChildtartChecks() - { - return maxChildStartChecks; - } - - public void setMaxChildStartChecks(int maxChildStartChecks) - { - this.maxChildStartChecks = maxChildStartChecks; - } - - public long getMaxChildStartCheckMs() - { - return maxChildStartCheckMs; - } - - public void setMaxChildStartCheckMs(long maxChildStartCheckMs) - { - this.maxChildStartCheckMs = maxChildStartCheckMs; - } - - public File getTokenFile() - { - return tokenFile; - } - - public void setTokenFile(File tokenFile) - { - this.tokenFile = tokenFile; - } - - public void doStart() - throws Exception - { - super.doStart(); - - //Create the command to fork - ProcessBuilder command = createCommand(); - Process process = command.start(); - - if (waitForChild) - { - //keep executing until the child dies - process.waitFor(); - } - else - { - //just wait until the child has started successfully - int attempts = maxChildStartChecks; - while (!tokenFile.exists() && attempts > 0) - { - Thread.sleep(maxChildStartCheckMs); - --attempts; - } - if (attempts <= 0) - LOG.info("Couldn't verify success of child startup"); - } - } -} diff --git a/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/AbstractUnassembledWebAppMojo.java b/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/AbstractUnassembledWebAppMojo.java index 2d44726d9503..7e5683fd16e5 100644 --- a/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/AbstractUnassembledWebAppMojo.java +++ b/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/AbstractUnassembledWebAppMojo.java @@ -24,6 +24,7 @@ import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.plugins.annotations.Parameter; +import org.eclipse.jetty.maven.ScanPattern; import org.eclipse.jetty.util.resource.Resource; import org.eclipse.jetty.util.resource.Resources; @@ -123,7 +124,7 @@ protected void configureWebApp() throws Exception * * @throws IOException if there is an IO problem */ - protected void configureUnassembledWebApp() throws IOException + protected void configureUnassembledWebApp() throws Exception { //Set up the location of the webapp. //There are 2 parts to this: setWar() and setBaseResource(). On standalone jetty, @@ -208,7 +209,7 @@ protected void configureUnassembledWebApp() throws IOException //process any overlays and the war type artifacts, and //sets up the base resource collection for the webapp - mavenProjectHelper.getOverlayManager().applyOverlays(webApp); + mavenProjectHelper.getOverlayManager().applyOverlays(webApp, webApp.getBaseAppFirst()); getLog().info("web.xml file = " + webApp.getDescriptor()); getLog().info("Webapp directory = " + webAppSourceDirectory.getCanonicalPath()); diff --git a/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/AbstractWebAppMojo.java b/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/AbstractWebAppMojo.java index cbc4b1fb59ff..de3eefc0bbdf 100644 --- a/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/AbstractWebAppMojo.java +++ b/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/AbstractWebAppMojo.java @@ -48,7 +48,10 @@ import org.apache.maven.project.MavenProject; import org.codehaus.plexus.util.StringUtils; import org.eclipse.aether.RepositorySystem; -import org.eclipse.jetty.ee10.maven.plugin.utils.MavenProjectHelper; +import org.eclipse.jetty.maven.MavenProjectHelper; +import org.eclipse.jetty.maven.MavenServerConnector; +import org.eclipse.jetty.maven.PluginLog; +import org.eclipse.jetty.maven.ScanTargetPattern; import org.eclipse.jetty.security.LoginService; import org.eclipse.jetty.server.RequestLog; import org.eclipse.jetty.server.Server; @@ -563,7 +566,7 @@ protected JettyHomeForker newJettyHomeForker() if (jettyHome == null) jetty.setJettyHomeZip(jettyHomeZip != null ? jettyHomeZip : mavenProjectHelper.resolveArtifact(JETTY_HOME_GROUPID, JETTY_HOME_ARTIFACTID, plugin.getVersion(), "zip")); - jetty.version = plugin.getVersion(); + jetty.setVersion(plugin.getVersion()); jetty.setJettyHome(jettyHome); jetty.setJettyBase(jettyBase); jetty.setBaseDir(target); diff --git a/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/ConsoleReader.java b/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/ConsoleReader.java deleted file mode 100644 index 298f434e2e91..000000000000 --- a/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/ConsoleReader.java +++ /dev/null @@ -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.maven.plugin; - -import java.io.Console; -import java.util.EventListener; -import java.util.HashSet; -import java.util.Set; - -/** - * ConsoleReader - * - * Reads lines from the System console and supplies them - * to ConsoleReader.Listeners. - */ -public class ConsoleReader implements Runnable -{ - public interface Listener extends EventListener - { - public void consoleEvent(String line); - } - - public Set listeners = new HashSet<>(); - - public void addListener(ConsoleReader.Listener listener) - { - listeners.add(listener); - } - - public void removeListener(ConsoleReader.Listener listener) - { - listeners.remove(listener); - } - - public void run() - { - Console console = System.console(); - if (console == null) - return; - - String line = ""; - while (true && line != null) - { - line = console.readLine("%nHit to redeploy:%n%n"); - if (line != null) - signalEvent(line); - } - } - - private void signalEvent(String line) - { - for (ConsoleReader.Listener l:listeners) - l.consoleEvent(line); - } -} diff --git a/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/JettyEmbedder.java b/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/JettyEmbedder.java index 95e61c06b5a9..948e556a0ca1 100644 --- a/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/JettyEmbedder.java +++ b/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/JettyEmbedder.java @@ -13,220 +13,40 @@ package org.eclipse.jetty.ee10.maven.plugin; -import java.io.File; import java.nio.file.Files; import java.nio.file.Path; -import java.util.ArrayList; import java.util.List; -import java.util.Map; -import java.util.Properties; import org.eclipse.jetty.ee10.quickstart.QuickStartConfiguration; import org.eclipse.jetty.ee10.quickstart.QuickStartConfiguration.Mode; import org.eclipse.jetty.ee10.servlet.ServletHandler; -import org.eclipse.jetty.security.LoginService; -import org.eclipse.jetty.server.RequestLog; -import org.eclipse.jetty.server.Server; -import org.eclipse.jetty.server.ShutdownMonitor; +import org.eclipse.jetty.ee10.webapp.Configurations; +import org.eclipse.jetty.maven.AbstractJettyEmbedder; +import org.eclipse.jetty.maven.ServerSupport; import org.eclipse.jetty.server.handler.ContextHandler; -import org.eclipse.jetty.util.component.AbstractLifeCycle; /** - * JettyEmbedded + * JettyEmbedder * * Starts jetty within the current process. */ -public class JettyEmbedder extends AbstractLifeCycle +public class JettyEmbedder extends AbstractJettyEmbedder { - protected List contextHandlers; - protected List loginServices; - protected RequestLog requestLog; - protected MavenServerConnector httpConnector; - protected Server server; protected MavenWebAppContext webApp; - protected boolean exitVm; - protected boolean stopAtShutdown; - protected List jettyXmlFiles; - protected Map jettyProperties; - protected ShutdownMonitor shutdownMonitor; - protected int stopPort; - protected String stopKey; - private String contextXml; - private Properties webAppProperties; public List getContextHandlers() { return contextHandlers; } - - public void setContextHandlers(List contextHandlers) - { - if (contextHandlers == null) - this.contextHandlers = null; - else - this.contextHandlers = new ArrayList<>(contextHandlers); - } - - public List getLoginServices() - { - return loginServices; - } - - public void setLoginServices(List loginServices) - { - if (loginServices == null) - this.loginServices = null; - else - this.loginServices = new ArrayList<>(loginServices); - } - - public RequestLog getRequestLog() - { - return requestLog; - } - - public void setRequestLog(RequestLog requestLog) - { - this.requestLog = requestLog; - } - - public MavenServerConnector getHttpConnector() - { - return httpConnector; - } - - public void setHttpConnector(MavenServerConnector httpConnector) - { - this.httpConnector = httpConnector; - } - - public Server getServer() - { - return server; - } - - public void setServer(Server server) - { - this.server = server; - } - - public MavenWebAppContext getWebApp() - { - return webApp; - } - - public boolean isExitVm() - { - return exitVm; - } - - public void setExitVm(boolean exitVm) - { - this.exitVm = exitVm; - } - - public boolean isStopAtShutdown() - { - return stopAtShutdown; - } - - public void setStopAtShutdown(boolean stopAtShutdown) - { - this.stopAtShutdown = stopAtShutdown; - } - - public List getJettyXmlFiles() - { - return jettyXmlFiles; - } - - public void setJettyXmlFiles(List jettyXmlFiles) - { - this.jettyXmlFiles = jettyXmlFiles; - } - - public Map getJettyProperties() - { - return jettyProperties; - } - - public void setJettyProperties(Map jettyProperties) - { - this.jettyProperties = jettyProperties; - } - - public ShutdownMonitor getShutdownMonitor() - { - return shutdownMonitor; - } - - public void setShutdownMonitor(ShutdownMonitor shutdownMonitor) - { - this.shutdownMonitor = shutdownMonitor; - } - - 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 void setWebApp(MavenWebAppContext app) { webApp = app; } - public void setWebAppProperties(Properties props) - { - if (webAppProperties != null) - webAppProperties.clear(); - - if (props != null) - { - if (webAppProperties == null) - webAppProperties = new Properties(); - - webAppProperties.putAll(props); - } - } - - public String getContextXml() - { - return contextXml; - } - - public void setContextXml(String contextXml) - { - this.contextXml = contextXml; - } - - public void doStart() throws Exception - { - super.doStart(); - - configure(); - configureShutdownMonitor(); - server.start(); - } - protected void redeployWebApp() throws Exception { - if (!webApp.isStopped()) - webApp.stop(); + stopWebApp(); //clear the ServletHandler, which may have //remembered "durable" Servlets, Filters, Listeners @@ -239,40 +59,22 @@ protected void redeployWebApp() throws Exception webApp.start(); } - - protected void join() throws InterruptedException + + @Override + public void stopWebApp() throws Exception { - server.join(); + if (webApp != null && !webApp.isStopped()) + webApp.stop(); } /** - * Configure the server and the webapp + * Configure the webapp * @throws Exception if there is an unspecified problem */ - private void configure() throws Exception + public void configureWebApp() throws Exception { - // apply any configs from jetty.xml files first - Server tmp = ServerSupport.applyXmlConfigurations(new Server(), jettyXmlFiles, jettyProperties); - - if (tmp != null) - server = tmp; - - server.setStopAtShutdown(stopAtShutdown); - - //ensure there's a connector - if (httpConnector != null) - httpConnector.setServer(server); - - ServerSupport.configureConnectors(server, httpConnector, jettyProperties); - - //set up handler structure - ServerSupport.configureHandlers(server, contextHandlers, requestLog); - //Set up list of default Configurations to apply to a webapp - ServerSupport.configureDefaultConfigurationClasses(server); - - // set up security realms - ServerSupport.configureLoginServices(server, loginServices); + Configurations.setServerDefault(server); /* Configure the webapp */ if (webApp == null) @@ -286,37 +88,22 @@ private void configure() throws Exception Path qs = webApp.getTempDirectory().toPath().resolve("quickstart-web.xml"); if (Files.exists(qs) && Files.isRegularFile(qs)) { - webApp.setAttribute(QuickStartConfiguration.QUICKSTART_WEB_XML, qs); webApp.addConfiguration(new MavenQuickStartConfiguration()); + webApp.setAttribute(QuickStartConfiguration.QUICKSTART_WEB_XML, qs); webApp.setAttribute(QuickStartConfiguration.MODE, Mode.QUICKSTART); } } - - //add the webapp to the server - ServerSupport.addWebApplication(server, webApp); } - - private void applyWebAppProperties() throws Exception - { - //apply properties to the webapp if there are any - if (contextXml != null) - { - if (webAppProperties == null) - webAppProperties = new Properties(); - webAppProperties.put("context.xml", contextXml); - } - WebAppPropertyConverter.fromProperties(webApp, webAppProperties, server, jettyProperties); + public void applyWebAppProperties() throws Exception + { + super.applyWebAppProperties(); + WebAppPropertyConverter.fromProperties(webApp, webAppProperties, server, jettyProperties); } - - private void configureShutdownMonitor() + + public void addWebAppToServer() throws Exception { - if (stopPort > 0 && stopKey != null) - { - ShutdownMonitor monitor = ShutdownMonitor.getInstance(); - monitor.setPort(stopPort); - monitor.setKey(stopKey); - monitor.setExitVm(exitVm); - } + //add the webapp to the server + ServerSupport.addWebApplication(server, webApp); } } diff --git a/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/JettyForkedChild.java b/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/JettyForkedChild.java index f868ad600ada..7f0c6ba907ae 100644 --- a/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/JettyForkedChild.java +++ b/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/JettyForkedChild.java @@ -26,6 +26,8 @@ import java.util.Properties; import java.util.Set; +import org.eclipse.jetty.maven.AbstractForkedChild; +import org.eclipse.jetty.maven.AbstractJettyEmbedder; import org.eclipse.jetty.util.Scanner; import org.eclipse.jetty.util.StringUtil; import org.eclipse.jetty.util.component.ContainerLifeCycle; @@ -38,174 +40,23 @@ * This is the class that is executed when the jetty maven plugin * forks a process when DeploymentMode=FORKED. */ -public class JettyForkedChild extends ContainerLifeCycle +public class JettyForkedChild extends AbstractForkedChild { private static final Logger LOG = LoggerFactory.getLogger(JettyForkedChild.class); - - protected JettyEmbedder jetty; - protected File tokenFile; // TODO: convert to Path - protected Scanner scanner; - protected File webAppPropsFile; // TODO: convert to Path - protected int scanInterval; /** * @param args arguments that were passed to main * @throws Exception if unable to configure */ - public JettyForkedChild(String[] args) - throws Exception - { - jetty = new JettyEmbedder(); - configure(args); - } - - /** - * Based on the args passed to the program, configure jetty. - * - * @param args args that were passed to the program. - * @throws Exception if unable to load webprops - */ - public void configure(String[] args) - throws Exception - { - Map jettyProperties = new HashMap<>(); - - for (int i = 0; i < args.length; i++) - { - //--stop-port - if ("--stop-port".equals(args[i])) - { - jetty.setStopPort(Integer.parseInt(args[++i])); - continue; - } - - //--stop-key - if ("--stop-key".equals(args[i])) - { - jetty.setStopKey(args[++i]); - continue; - } - - //--jettyXml - if ("--jetty-xml".equals(args[i])) - { - List jettyXmls = new ArrayList<>(); - String[] names = StringUtil.csvSplit(args[++i]); - for (int j = 0; names != null && j < names.length; j++) - { - jettyXmls.add(new File(names[j].trim())); - } - jetty.setJettyXmlFiles(jettyXmls); - continue; - } - //--webprops - if ("--webprops".equals(args[i])) - { - webAppPropsFile = new File(args[++i].trim()); - jetty.setWebAppProperties(loadWebAppProps()); - continue; - } - - //--token - if ("--token".equals(args[i])) - { - tokenFile = new File(args[++i].trim()); - continue; - } - - if ("--scanInterval".equals(args[i])) - { - scanInterval = Integer.parseInt(args[++i].trim()); - scanner = new Scanner(); - scanner.setReportExistingFilesOnStartup(false); - scanner.setScanInterval(scanInterval); - scanner.addListener(new Scanner.BulkListener() - { - public void filesChanged(Set changes) - { - if (!Objects.isNull(scanner)) - { - try - { - scanner.stop(); - if (!Objects.isNull(jetty.getWebApp())) - { - //stop the webapp - jetty.getWebApp().stop(); - //reload the props - jetty.setWebAppProperties(loadWebAppProps()); - jetty.setWebApp(jetty.getWebApp()); - //restart the webapp - jetty.redeployWebApp(); - - //restart the scanner - scanner.start(); - } - } - catch (Exception e) - { - LOG.error("Error reconfiguring/restarting webapp after change in watched files", e); - } - } - } - }); - - if (!Objects.isNull(webAppPropsFile)) - scanner.addFile(webAppPropsFile.toPath()); - continue; - } - - //assume everything else is a jetty property to be passed in - String[] tmp = args[i].trim().split("="); - if (tmp.length == 2) - { - jettyProperties.put(tmp[0], tmp[1]); - } - } - - jetty.setJettyProperties(jettyProperties); - jetty.setExitVm(true); - } - - /** - * Load properties from a file describing the webapp if one is - * present. - * - * @return file contents as properties - * @throws IOException if there is an IO problem - */ - private Properties loadWebAppProps() throws IOException + public JettyForkedChild(String[] args) throws Exception { - Properties props = new Properties(); - if (Objects.nonNull(webAppPropsFile)) - props.load(new FileInputStream(webAppPropsFile)); - return props; + super(args); } - /** - * Start a jetty instance and webapp. This thread will - * wait until jetty exits. - */ - public void doStart() - throws Exception + @Override + protected AbstractJettyEmbedder newJettyEmbedder() { - super.doStart(); - - //Start the embedded jetty instance - jetty.start(); - - //touch file to signify start of jetty - Path tokenPath = tokenFile.toPath(); - Files.createFile(tokenPath); - - //Start a watcher on a file that will change if the - //webapp is regenerated; stop the webapp, apply the - //properties and restart it. - if (scanner != null) - scanner.start(); - - //wait for jetty to finish - jetty.join(); + return new JettyEmbedder(); } public static void main(String[] args) diff --git a/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/JettyForker.java b/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/JettyForker.java index e43637f1a1f2..6fb99d624ce7 100644 --- a/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/JettyForker.java +++ b/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/JettyForker.java @@ -13,94 +13,21 @@ package org.eclipse.jetty.ee10.maven.plugin; -import java.io.File; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - -import org.eclipse.jetty.server.Server; +import org.eclipse.jetty.maven.AbstractServerForker; /** * JettyForker * * Uses quickstart to generate a webapp and forks a process to run it. */ -public class JettyForker extends AbstractForker +public class JettyForker extends AbstractServerForker { - protected File forkWebXml; - protected Server server; protected MavenWebAppContext webApp; - protected String containerClassPath; - protected File webAppPropsFile; - protected String contextXml; - protected int scanInterval; QuickStartGenerator generator; - /** - * @return the scan - */ - public boolean isScan() - { - return scanInterval > 0; - } - - /** - * Set if true, the forked child will scan for changes at 1 second intervals. - * @param scan if true, the forked child will scan for changes at 1 second intervals - */ - public void setScan(boolean scan) - { - setScanInterval(scan ? 1 : 0); - } - - public void setScanInterval(int sec) - { - scanInterval = sec; - } - - public int getScanInterval() - { - return scanInterval; - } - - public File getWebAppPropsFile() - { - return webAppPropsFile; - } - - public void setWebAppPropsFile(File webAppPropsFile) - { - this.webAppPropsFile = webAppPropsFile; - } - - public File getForkWebXml() - { - return forkWebXml; - } - - public void setForkWebXml(File forkWebXml) - { - this.forkWebXml = forkWebXml; - } - - public String getContextXml() - { - return contextXml; - } - - public void setContextXml(String contextXml) - { - this.contextXml = contextXml; - } - - public String getContainerClassPath() - { - return containerClassPath; - } - - public void setContainerClassPath(String containerClassPath) + public JettyForker() { - this.containerClassPath = containerClassPath; + executionClassName = JettyForkedChild.class.getCanonicalName(); } public void setWebApp(MavenWebAppContext app) @@ -108,19 +35,8 @@ public void setWebApp(MavenWebAppContext app) webApp = app; } - public Server getServer() - { - return server; - } - - public void setServer(Server server) - { - this.server = server; - } - @Override - public void doStart() - throws Exception + public void generateWebApp() throws Exception { //Run the webapp to create the quickstart file and properties file generator = new QuickStartGenerator(forkWebXml.toPath(), webApp); @@ -128,8 +44,6 @@ public void doStart() generator.setWebAppProps(webAppPropsFile.toPath()); generator.setServer(server); generator.generate(); - - super.doStart(); } protected void redeployWebApp() @@ -139,154 +53,4 @@ protected void redeployWebApp() //which will redeploy the webapp generator.generate(); } - - public ProcessBuilder createCommand() - { - List cmd = new ArrayList(); - cmd.add(getJavaBin()); - - if (jvmArgs != null) - { - String[] args = jvmArgs.split(" "); - for (int i = 0; args != null && i < args.length; i++) - { - if (args[i] != null && !"".equals(args[i])) - cmd.add(args[i].trim()); - } - } - - if (systemProperties != null) - { - for (Map.Entry e:systemProperties.entrySet()) - { - cmd.add("-D" + e.getKey() + "=" + e.getValue()); - } - } - - if (containerClassPath != null && containerClassPath.length() > 0) - { - cmd.add("-cp"); - cmd.add(containerClassPath); - } - - cmd.add(JettyForkedChild.class.getCanonicalName()); - - if (stopPort > 0 && stopKey != null) - { - cmd.add("--stop-port"); - cmd.add(Integer.toString(stopPort)); - cmd.add("--stop-key"); - cmd.add(stopKey); - } - if (jettyXmlFiles != null) - { - cmd.add("--jetty-xml"); - StringBuilder tmp = new StringBuilder(); - for (File jettyXml:jettyXmlFiles) - { - if (tmp.length() != 0) - tmp.append(","); - tmp.append(jettyXml.getAbsolutePath()); - } - cmd.add(tmp.toString()); - } - - cmd.add("--webprops"); - cmd.add(webAppPropsFile.getAbsolutePath()); - - cmd.add("--token"); - cmd.add(tokenFile.getAbsolutePath()); - - if (scanInterval > 0) - { - cmd.add("--scanInterval"); - cmd.add(Integer.toString(scanInterval)); - } - - if (jettyProperties != null) - { - for (Map.Entry e:jettyProperties.entrySet()) - { - cmd.add(e.getKey() + "=" + e.getValue()); - } - } - - ProcessBuilder command = new ProcessBuilder(cmd); - command.directory(workDir); - - if (PluginLog.getLog().isDebugEnabled()) - PluginLog.getLog().debug("Forked cli:" + command.command()); - - PluginLog.getLog().info("Forked process starting"); - - //set up extra environment vars if there are any - if (env != null && !env.isEmpty()) - command.environment().putAll(env); - - if (waitForChild) - { - command.inheritIO(); - } - else - { - command.redirectOutput(jettyOutputFile); - command.redirectErrorStream(true); - } - return command; - } - - /** - * Get the location of the java binary. - * @return the location of the java binary - */ - private String getJavaBin() - { - String[] javaexes = new String[]{"java", "java.exe"}; - - File javaHomeDir = new File(System.getProperty("java.home")); - for (String javaexe : javaexes) - { - File javabin = new File(javaHomeDir, fileSeparators("bin/" + javaexe)); - if (javabin.exists() && javabin.isFile()) - { - return javabin.getAbsolutePath(); - } - } - - return "java"; - } - - public static String fileSeparators(String path) - { - StringBuilder ret = new StringBuilder(); - for (char c : path.toCharArray()) - { - if ((c == '/') || (c == '\\')) - { - ret.append(File.separatorChar); - } - else - { - ret.append(c); - } - } - return ret.toString(); - } - - public static String pathSeparators(String path) - { - StringBuilder ret = new StringBuilder(); - for (char c : path.toCharArray()) - { - if ((c == ',') || (c == ':')) - { - ret.append(File.pathSeparatorChar); - } - else - { - ret.append(c); - } - } - return ret.toString(); - } } diff --git a/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/JettyHomeForker.java b/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/JettyHomeForker.java index 2d988f8a21b1..7bac2f086b22 100644 --- a/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/JettyHomeForker.java +++ b/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/JettyHomeForker.java @@ -14,30 +14,8 @@ package org.eclipse.jetty.ee10.maven.plugin; import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.net.URI; -import java.nio.file.FileAlreadyExistsException; -import java.nio.file.FileSystems; -import java.nio.file.FileVisitOption; -import java.nio.file.FileVisitResult; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.SimpleFileVisitor; -import java.nio.file.attribute.BasicFileAttributes; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.EnumSet; -import java.util.List; -import java.util.Map; -import org.eclipse.jetty.util.IO; -import org.eclipse.jetty.util.StringUtil; -import org.eclipse.jetty.util.TypeUtil; -import org.eclipse.jetty.util.resource.Resource; -import org.eclipse.jetty.util.resource.ResourceFactory; +import org.eclipse.jetty.maven.AbstractHomeForker; /** * JettyHomeBaseForker @@ -45,121 +23,13 @@ * Unpacks a jetty-home and configures it with a base that allows it * to run an unassembled webapp. */ -public class JettyHomeForker extends AbstractForker +public class JettyHomeForker extends AbstractHomeForker { protected MavenWebAppContext webApp; - protected String contextXml; - - /** - * Location of existing jetty home directory - */ - protected File jettyHome; - - /** - * Zip of jetty-home - */ - protected File jettyHomeZip; - - /** - * Location of existing jetty base directory - */ - protected File jettyBase; - - protected File baseDir; - - /** - * Optional list of other modules to - * activate. - */ - protected String[] modules; - - /* - * Optional jetty commands - */ - protected String jettyOptions; - - protected List libExtJarFiles; - protected Path modulesPath; - protected Path etcPath; - protected Path libPath; - protected Path webappPath; - protected Path mavenLibPath; - protected String version; - - public void setJettyOptions(String jettyOptions) - { - this.jettyOptions = jettyOptions; - } - - public String getJettyOptions() + public JettyHomeForker() { - return jettyOptions; - } - - public List getLibExtJarFiles() - { - return libExtJarFiles; - } - - public void setLibExtJarFiles(List libExtJarFiles) - { - this.libExtJarFiles = libExtJarFiles; - } - - public File getJettyHome() - { - return jettyHome; - } - - public void setJettyHome(File jettyHome) - { - this.jettyHome = jettyHome; - } - - public File getJettyBase() - { - return jettyBase; - } - - public void setJettyBase(File jettyBase) - { - this.jettyBase = jettyBase; - } - - public String[] getModules() - { - return modules; - } - - public void setModules(String[] modules) - { - this.modules = modules; - } - - public String getContextXmlFile() - { - return contextXml; - } - - public void setContextXml(String contextXml) - { - this.contextXml = contextXml; - } - - public File getJettyHomeZip() - { - return jettyHomeZip; - } - - public void setJettyHomeZip(File jettyHomeZip) - { - this.jettyHomeZip = jettyHomeZip; - } - - public MavenWebAppContext getWebApp() - { - return webApp; + environment = "ee10"; } public void setWebApp(MavenWebAppContext webApp) @@ -177,106 +47,6 @@ public void setBaseDir(File baseDir) this.baseDir = baseDir; } - @Override - protected ProcessBuilder createCommand() - { - List cmd = new ArrayList<>(); - cmd.add("java"); - - //add any args to the jvm - if (StringUtil.isNotBlank(jvmArgs)) - { - Arrays.stream(jvmArgs.split(" ")).filter(StringUtil::isNotBlank).forEach((a) -> cmd.add(a.trim())); - } - - cmd.add("-jar"); - cmd.add(new File(jettyHome, "start.jar").getAbsolutePath()); - - if (systemProperties != null) - { - for (Map.Entry e : systemProperties.entrySet()) - { - cmd.add("-D" + e.getKey() + "=" + e.getValue()); - } - } - - cmd.add("-DSTOP.PORT=" + stopPort); - if (stopKey != null) - cmd.add("-DSTOP.KEY=" + stopKey); - - //set up enabled jetty modules - StringBuilder tmp = new StringBuilder(); - tmp.append("--module="); - tmp.append("server,http,ee10-webapp,ee10-deploy"); - if (modules != null) - { - for (String m : modules) - { - if (tmp.indexOf(m) < 0) - tmp.append("," + m); - } - } - - if (libExtJarFiles != null && !libExtJarFiles.isEmpty() && tmp.indexOf("ext") < 0) - tmp.append(",ext"); - tmp.append(",ee10-maven"); - cmd.add(tmp.toString()); - - //put any other jetty options onto the command line - if (StringUtil.isNotBlank(jettyOptions)) - { - Arrays.stream(jettyOptions.split(" ")).filter(StringUtil::isNotBlank).forEach((a) -> cmd.add(a.trim())); - } - - //put any jetty properties onto the command line - if (jettyProperties != null) - { - for (Map.Entry e : jettyProperties.entrySet()) - { - cmd.add(e.getKey() + "=" + e.getValue()); - } - } - - //existence of this file signals process started - cmd.add("jetty.token.file=" + tokenFile.getAbsolutePath().toString()); - - ProcessBuilder builder = new ProcessBuilder(cmd); - builder.directory(workDir); - - PluginLog.getLog().info("Home process starting"); - - //set up extra environment vars if there are any - if (!env.isEmpty()) - builder.environment().putAll(env); - - if (waitForChild) - builder.inheritIO(); - else - { - builder.redirectOutput(jettyOutputFile); - builder.redirectErrorStream(true); - } - return builder; - } - - @Override - public void doStart() throws Exception - { - //set up a jetty-home - configureJettyHome(); - - if (jettyHome == null || !jettyHome.exists()) - throw new IllegalStateException("No jetty home"); - - //set up a jetty-base - configureJettyBase(); - - //convert the webapp to properties - generateWebAppPropertiesFile(); - - super.doStart(); - } - protected void redeployWebApp() throws Exception { @@ -284,142 +54,9 @@ protected void redeployWebApp() webappPath.resolve("maven.xml").toFile().setLastModified(System.currentTimeMillis()); } - private void generateWebAppPropertiesFile() + protected void generateWebAppPropertiesFile() throws Exception { WebAppPropertyConverter.toProperties(webApp, etcPath.resolve("maven.props").toFile(), contextXml); } - - /** - * Create or configure a jetty base. - */ - private void configureJettyBase() throws Exception - { - if (jettyBase != null && !jettyBase.exists()) - throw new IllegalStateException(jettyBase.getAbsolutePath() + " does not exist"); - - File targetJettyBase = new File(baseDir, "jetty-base"); - Path targetBasePath = targetJettyBase.toPath(); - if (Files.exists(targetBasePath)) - IO.delete(targetJettyBase); - - targetJettyBase.mkdirs(); - - //jetty-base will be the working directory for the forked command - workDir = targetJettyBase; - - //if there is an existing jetty base, copy parts of it - if (jettyBase != null) - { - Path jettyBasePath = jettyBase.toPath(); - - final File contextXmlFile = (contextXml == null ? null : FileSystems.getDefault().getPath(contextXml).toFile()); - - //copy the existing jetty base - Files.walkFileTree(jettyBasePath, EnumSet.of(FileVisitOption.FOLLOW_LINKS), Integer.MAX_VALUE, - new SimpleFileVisitor() - { - @Override - public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException - { - Path targetDir = targetBasePath.resolve(jettyBasePath.relativize(dir)); - try - { - Files.copy(dir, targetDir); - } - catch (FileAlreadyExistsException e) - { - if (!Files.isDirectory(targetDir)) //ignore attempt to recreate dir - throw e; - } - return FileVisitResult.CONTINUE; - } - - @Override - public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException - { - if (contextXmlFile != null && Files.isSameFile(contextXmlFile.toPath(), file)) - return FileVisitResult.CONTINUE; //skip copying the context xml file - Files.copy(file, targetBasePath.resolve(jettyBasePath.relativize(file))); - return FileVisitResult.CONTINUE; - } - }); - } - - //make the jetty base structure - modulesPath = Files.createDirectories(targetBasePath.resolve("modules")); - etcPath = Files.createDirectories(targetBasePath.resolve("etc")); - libPath = Files.createDirectories(targetBasePath.resolve("lib")); - webappPath = Files.createDirectories(targetBasePath.resolve("webapps")); - mavenLibPath = Files.createDirectories(libPath.resolve("maven-ee10")); - - //copy in the jetty-maven-plugin jar - URI thisJar = TypeUtil.getLocationOfClass(this.getClass()); - if (thisJar == null) - throw new IllegalStateException("Can't find jar for jetty-ee10-maven-plugin"); - - try (InputStream jarStream = thisJar.toURL().openStream(); - FileOutputStream fileStream = new FileOutputStream(mavenLibPath.resolve("plugin.jar").toFile())) - { - IO.copy(jarStream, fileStream); - } - - // copy in the maven.xml webapp file - try (InputStream mavenXmlStream = getClass().getClassLoader().getResourceAsStream("maven-ee10.xml"); - FileOutputStream fileStream = new FileOutputStream(webappPath.resolve("maven-ee10.xml").toFile())) - { - IO.copy(mavenXmlStream, fileStream); - } - - Files.writeString(webappPath.resolve("maven-ee10.properties"), "environment=ee10"); - - //copy in the maven.mod file - try (InputStream mavenModStream = getClass().getClassLoader().getResourceAsStream("ee10-maven.mod"); - FileOutputStream fileStream = new FileOutputStream(modulesPath.resolve("ee10-maven.mod").toFile())) - { - IO.copy(mavenModStream, fileStream); - } - - //copy in the jetty-maven.xml file - try (InputStream jettyMavenStream = getClass().getClassLoader().getResourceAsStream("jetty-ee10-maven.xml"); - FileOutputStream fileStream = new FileOutputStream(etcPath.resolve("jetty-ee10-maven.xml").toFile())) - { - IO.copy(jettyMavenStream, fileStream); - } - - //if there were plugin dependencies, copy them into lib/ext - if (libExtJarFiles != null && !libExtJarFiles.isEmpty()) - { - Path libExtPath = Files.createDirectories(libPath.resolve("ext")); - for (File f : libExtJarFiles) - { - try (InputStream jarStream = new FileInputStream(f); - FileOutputStream fileStream = new FileOutputStream(libExtPath.resolve(f.getName()).toFile())) - { - IO.copy(jarStream, fileStream); - } - } - } - } - - private void configureJettyHome() - throws Exception - { - if (jettyHome == null && jettyHomeZip == null) - throw new IllegalStateException("No jettyHome"); - - if (baseDir == null) - throw new IllegalStateException("No baseDir"); - - if (jettyHome == null) - { - try (ResourceFactory.Closeable resourceFactory = ResourceFactory.closeable()) - { - Resource res = resourceFactory.newJarFileResource(jettyHomeZip.toPath().toUri()); - res.copyTo(baseDir.toPath()); // TODO: Resource.copyTo() cannot copy dir to dir, only file to file - } - //zip will unpack to target/jetty-home- - jettyHome = new File(baseDir, "jetty-home-" + version); - } - } } diff --git a/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/JettyRunMojo.java b/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/JettyRunMojo.java index 8374459f948b..7ff6e7d8f823 100644 --- a/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/JettyRunMojo.java +++ b/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/JettyRunMojo.java @@ -28,6 +28,7 @@ import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.plugins.annotations.ResolutionScope; import org.eclipse.jetty.ee10.webapp.WebAppContext; +import org.eclipse.jetty.maven.ConsoleReader; import org.eclipse.jetty.util.IncludeExcludeSet; import org.eclipse.jetty.util.Scanner; import org.eclipse.jetty.util.component.LifeCycle; @@ -355,7 +356,7 @@ public void restartWebApp(boolean reconfigure) throws Exception } } - embedder.getWebApp().stop(); + embedder.stopWebApp(); configureWebApp(); embedder.redeployWebApp(); if (scanner != null) diff --git a/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/JettyRunWarMojo.java b/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/JettyRunWarMojo.java index 18f5aa51ef89..a87bc4cdeaa2 100644 --- a/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/JettyRunWarMojo.java +++ b/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/JettyRunWarMojo.java @@ -25,6 +25,7 @@ import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.plugins.annotations.ResolutionScope; +import org.eclipse.jetty.maven.ConsoleReader; import org.eclipse.jetty.util.Scanner; import org.eclipse.jetty.util.StringUtil; @@ -235,7 +236,7 @@ public void restartWebApp(boolean reconfigure) throws Exception warArtifacts = null; configureScanner(); } - embedder.getWebApp().stop(); + embedder.stopWebApp(); configureWebApp(); embedder.redeployWebApp(); scanner.start(); diff --git a/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/MavenResource.java b/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/MavenResource.java deleted file mode 100644 index ab2f6ca7a35f..000000000000 --- a/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/MavenResource.java +++ /dev/null @@ -1,220 +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.maven.plugin; - -import java.io.IOException; -import java.io.InputStream; -import java.net.URI; -import java.nio.file.Path; -import java.time.Instant; -import java.util.Collection; -import java.util.Iterator; -import java.util.List; - -import org.eclipse.jetty.util.resource.Resource; -import org.eclipse.jetty.util.resource.ResourceFactory; - -/** - * MavenResource - * - * A helper class to allow Resources to be used in maven pom.xml configuration by - * providing a no-arg constructor and a setter that accepts a simple string as a - * file location. This class delegates to a real Resource obtained using a - * ResourceFactory. - */ -public class MavenResource extends Resource -{ - private static final ResourceFactory __resourceFactory = ResourceFactory.root(); - private String _resourceString; - private Resource _resource; - - public MavenResource() - { - } - - @Override - public void copyTo(Path destination) throws IOException - { - if (_resource == null) - return; - _resource.copyTo(destination); - } - - @Override - public boolean exists() - { - if (_resource == null) - return false; - return _resource.exists(); - } - - @Override - public Collection getAllResources() - { - if (_resource == null) - return null; - return _resource.getAllResources(); - } - - @Override - public String getFileName() - { - if (_resource == null) - return null; - return _resource.getFileName(); - } - - @Override - public String getName() - { - if (_resource == null) - return null; - return _resource.getName(); - } - - @Override - public Path getPath() - { - if (_resource == null) - return null; - - return _resource.getPath(); - } - - @Override - public URI getRealURI() - { - if (_resource == null) - return null; - return _resource.getRealURI(); - } - - public String getResourceAsString() - { - return _resourceString; - } - - public void setResourceAsString(String resourceString) - { - _resourceString = resourceString; - _resource = __resourceFactory.newResource(_resourceString); - } - - @Override - public URI getURI() - { - if (_resource == null) - return null; - - return _resource.getURI(); - } - - @Override - public boolean isAlias() - { - if (_resource == null) - return false; - return _resource.isAlias(); - } - - @Override - public boolean isContainedIn(Resource container) - { - if (_resource == null) - return false; - return _resource.isContainedIn(container); - } - - @Override - public boolean contains(Resource other) - { - if (_resource == null) - return false; - return _resource.contains(other); - } - - @Override - public Path getPathTo(Resource other) - { - if (_resource == null) - return null; - return _resource.getPathTo(other); - } - - @Override - public boolean isDirectory() - { - if (_resource == null) - return false; - - return _resource.isDirectory(); - } - - @Override - public boolean isReadable() - { - if (_resource == null) - return false; - - return _resource.isReadable(); - } - - @Override - public Iterator iterator() - { - if (_resource == null) - return null; - return _resource.iterator(); - } - - @Override - public Instant lastModified() - { - if (_resource == null) - return null; - return _resource.lastModified(); - } - - @Override - public long length() - { - if (_resource == null) - return -1; - return _resource.length(); - } - - @Override - public List list() - { - if (_resource == null) - return null; - return _resource.list(); - } - - @Override - public InputStream newInputStream() throws IOException - { - if (_resource == null) - return null; - return _resource.newInputStream(); - } - - @Override - public Resource resolve(String subUriPath) - { - if (_resource == null) - return null; - return _resource.resolve(subUriPath); - } -} \ No newline at end of file diff --git a/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/MavenServerConnector.java b/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/MavenServerConnector.java deleted file mode 100644 index 7e3a721cf80e..000000000000 --- a/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/MavenServerConnector.java +++ /dev/null @@ -1,221 +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.maven.plugin; - -import java.util.Collection; -import java.util.List; -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.Executor; - -import org.eclipse.jetty.io.ByteBufferPool; -import org.eclipse.jetty.io.EndPoint; -import org.eclipse.jetty.server.ConnectionFactory; -import org.eclipse.jetty.server.Connector; -import org.eclipse.jetty.server.Server; -import org.eclipse.jetty.server.ServerConnector; -import org.eclipse.jetty.util.annotation.ManagedAttribute; -import org.eclipse.jetty.util.component.ContainerLifeCycle; -import org.eclipse.jetty.util.thread.Scheduler; - -/** - * MavenServerConnector - * - * As the ServerConnector class does not have a no-arg constructor, and moreover requires - * the server instance passed in to all its constructors, it cannot - * be referenced in the pom.xml. This class wraps a ServerConnector, delaying setting the - * server instance. Only a few of the setters from the ServerConnector class are supported. - */ -public class MavenServerConnector extends ContainerLifeCycle implements Connector -{ - public static String PORT_SYSPROPERTY = "jetty.http.port"; - - public static final int DEFAULT_PORT = 8080; - public static final String DEFAULT_PORT_STR = String.valueOf(DEFAULT_PORT); - public static final int DEFAULT_MAX_IDLE_TIME = 30000; - - private Server server; - private volatile ServerConnector delegate; - private String host; - private String name; - private int port; - private long idleTimeout; - - public MavenServerConnector() - { - } - - public void setServer(Server server) - { - this.server = server; - } - - public void setHost(String host) - { - this.host = host; - } - - public String getHost() - { - return this.host; - } - - public void setPort(int port) - { - this.port = port; - } - - public int getPort() - { - return this.port; - } - - public void setName(String name) - { - this.name = name; - } - - public void setIdleTimeout(long idleTimeout) - { - this.idleTimeout = idleTimeout; - } - - @Override - protected void doStart() throws Exception - { - - if (this.server == null) - throw new IllegalStateException("Server not set for MavenServerConnector"); - - this.delegate = new ServerConnector(this.server); - this.delegate.setName(this.name); - this.delegate.setPort(this.port); - this.delegate.setHost(this.host); - this.delegate.setIdleTimeout(idleTimeout); - this.delegate.start(); - - super.doStart(); - } - - @Override - protected void doStop() throws Exception - { - this.delegate.stop(); - super.doStop(); - this.delegate = null; - } - - @Override - public CompletableFuture shutdown() - { - return checkDelegate().shutdown(); - } - - @Override - public boolean isShutdown() - { - return checkDelegate().isShutdown(); - } - - @Override - public Server getServer() - { - return this.server; - } - - @Override - public Executor getExecutor() - { - return checkDelegate().getExecutor(); - } - - @Override - public Scheduler getScheduler() - { - return checkDelegate().getScheduler(); - } - - @Override - public ByteBufferPool getByteBufferPool() - { - return checkDelegate().getByteBufferPool(); - } - - @Override - public ConnectionFactory getConnectionFactory(String nextProtocol) - { - return checkDelegate().getConnectionFactory(nextProtocol); - } - - @Override - public T getConnectionFactory(Class factoryType) - { - return checkDelegate().getConnectionFactory(factoryType); - } - - @Override - public ConnectionFactory getDefaultConnectionFactory() - { - return checkDelegate().getDefaultConnectionFactory(); - } - - @Override - public Collection getConnectionFactories() - { - return checkDelegate().getConnectionFactories(); - } - - @Override - public List getProtocols() - { - return checkDelegate().getProtocols(); - } - - @Override - @ManagedAttribute("maximum time a connection can be idle before being closed (in ms)") - public long getIdleTimeout() - { - return checkDelegate().getIdleTimeout(); - } - - @Override - public Object getTransport() - { - return checkDelegate().getTransport(); - } - - @Override - public Collection getConnectedEndPoints() - { - return checkDelegate().getConnectedEndPoints(); - } - - @Override - public String getName() - { - return this.name; - } - - public int getLocalPort() - { - return this.delegate.getLocalPort(); - } - - private ServerConnector checkDelegate() throws IllegalStateException - { - ServerConnector d = this.delegate; - if (d == null) - throw new IllegalStateException("MavenServerConnector delegate not ready"); - return d; - } -} diff --git a/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/MavenWebAppContext.java b/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/MavenWebAppContext.java index 65939e592025..8f73478cd22e 100644 --- a/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/MavenWebAppContext.java +++ b/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/MavenWebAppContext.java @@ -36,6 +36,7 @@ import org.eclipse.jetty.ee10.webapp.Configurations; import org.eclipse.jetty.ee10.webapp.MetaInfConfiguration; import org.eclipse.jetty.ee10.webapp.WebAppContext; +import org.eclipse.jetty.maven.Overlay; import org.eclipse.jetty.util.FileID; import org.eclipse.jetty.util.StringUtil; import org.eclipse.jetty.util.URIUtil; diff --git a/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/Overlay.java b/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/Overlay.java deleted file mode 100644 index 51b9a6b43575..000000000000 --- a/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/Overlay.java +++ /dev/null @@ -1,103 +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.maven.plugin; - -import java.io.File; -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; -import java.time.Instant; - -import org.eclipse.jetty.util.resource.Resource; - -/** - * Overlay - * - * An Overlay represents overlay information derived from the - * maven-war-plugin. - */ -public class Overlay -{ - private OverlayConfig _config; - private Resource _resource; - - public Overlay(OverlayConfig config, Resource resource) - { - _config = config; - _resource = resource; - } - - public Overlay(OverlayConfig config) - { - _config = config; - } - - public void setResource(Resource r) - { - _resource = r; - } - - public Resource getResource() - { - return _resource; - } - - public OverlayConfig getConfig() - { - return _config; - } - - @Override - public String toString() - { - StringBuilder strbuff = new StringBuilder(); - if (_resource != null) - strbuff.append(_resource); - if (_config != null) - { - strbuff.append(" ["); - strbuff.append(_config); - strbuff.append("]"); - } - return strbuff.toString(); - } - - /** - * Unpack the overlay into the given directory. Only - * unpack if the directory does not exist, or the overlay - * has been modified since the dir was created. - * - * @param dir the directory into which to unpack the overlay - * @throws IOException - */ - public void unpackTo(File dir) throws IOException // TODO: change to Path - { - if (dir == null) - throw new IllegalStateException("No overly unpack directory"); - Path pathDir = dir.toPath(); - // only unpack if the overlay is newer - if (!Files.exists(pathDir)) - { - // create directory - Files.createDirectories(pathDir); - getResource().copyTo(pathDir); - } - else - { - Instant dirLastModified = Files.getLastModifiedTime(pathDir).toInstant(); - if (getResource().lastModified().isAfter(dirLastModified)) - getResource().copyTo(pathDir); - } - } -} diff --git a/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/OverlayConfig.java b/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/OverlayConfig.java deleted file mode 100644 index 26f0342db4f5..000000000000 --- a/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/OverlayConfig.java +++ /dev/null @@ -1,337 +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.maven.plugin; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Iterator; -import java.util.List; - -import org.codehaus.plexus.util.xml.Xpp3Dom; -import org.eclipse.jetty.util.StringUtil; - -/** - * OverlayConfig - * - * The configuration of a war overlay in a pom. Used to help determine which resources - * from a project's dependent war should be included. - */ -public class OverlayConfig -{ - private String targetPath; - private String groupId; - private String artifactId; - private String classifier; - private List includes; - private List excludes; - private boolean skip; - private boolean filtered; - - public OverlayConfig() - { - } - - public OverlayConfig(String fmt, List defaultIncludes, List defaultExcludes) - { - if (fmt == null) - return; - String[] atoms = StringUtil.csvSplit(fmt); - for (int i = 0; i < atoms.length; i++) - { - String s = atoms[i].trim(); - switch (i) - { - case 0: - { - if (!"".equals(s)) - groupId = s; - break; - } - case 1: - { - if (!"".equals(s)) - artifactId = s; - break; - } - case 2: - { - if (!"".equals(s)) - classifier = s; - break; - } - case 3: - { - if (!"".equals(s)) - targetPath = s; - break; - } - case 4: - { - if ("".equals(s)) - skip = false; - else - skip = Boolean.valueOf(s); - break; - } - case 5: - { - if ("".equals(s)) - filtered = false; - else - filtered = Boolean.valueOf(s); - break; - } - case 6: - { - if ("".equals(s)) - break; - String[] incs = s.split(";"); - if (incs.length > 0) - includes = Arrays.asList(incs); - break; - } - case 7: - { - if ("".equals(s)) - break; - String[] exs = s.split(";"); - if (exs.length > 0) - excludes = Arrays.asList(exs); - break; - } - default: - break; - } - } - } - - public OverlayConfig(Xpp3Dom root, List defaultIncludes, List defaultExcludes) - { - Xpp3Dom node = root.getChild("groupId"); - setGroupId(node == null ? null : node.getValue()); - - node = root.getChild("artifactId"); - setArtifactId(node == null ? null : node.getValue()); - - node = root.getChild("classifier"); - setClassifier(node == null ? null : node.getValue()); - - node = root.getChild("targetPath"); - setTargetPath(node == null ? null : node.getValue()); - - node = root.getChild("skip"); - setSkip(node == null ? false : Boolean.valueOf(node.getValue())); - - node = root.getChild("filtered"); - setFiltered(node == null ? false : Boolean.valueOf(node.getValue())); - - node = root.getChild("includes"); - List includes = null; - if (node != null && node.getChildCount() > 0) - { - Xpp3Dom[] list = node.getChildren("include"); - for (int j = 0; list != null && j < list.length; j++) - { - if (includes == null) - includes = new ArrayList<>(); - includes.add(list[j].getValue()); - } - } - if (includes == null && defaultIncludes != null) - { - includes = new ArrayList<>(); - includes.addAll(defaultIncludes); - } - setIncludes(includes); - - node = root.getChild("excludes"); - List excludes = null; - if (node != null && node.getChildCount() > 0) - { - Xpp3Dom[] list = node.getChildren("exclude"); - for (int j = 0; list != null && j < list.length; j++) - { - if (excludes == null) - excludes = new ArrayList<>(); - excludes.add(list[j].getValue()); - } - } - if (excludes == null && defaultExcludes != null) - { - excludes = new ArrayList<>(); - excludes.addAll(defaultExcludes); - } - setExcludes(excludes); - } - - public String getTargetPath() - { - return targetPath; - } - - public void setTargetPath(String targetPath) - { - this.targetPath = targetPath; - } - - public String getGroupId() - { - return groupId; - } - - public void setGroupId(String groupId) - { - this.groupId = groupId; - } - - public String getArtifactId() - { - return artifactId; - } - - public void setArtifactId(String artifactId) - { - this.artifactId = artifactId; - } - - public String getClassifier() - { - return classifier; - } - - public void setClassifier(String classifier) - { - this.classifier = classifier; - } - - public List getIncludes() - { - return includes; - } - - public void setIncludes(List includes) - { - this.includes = includes; - } - - public List getExcludes() - { - return excludes; - } - - public void setExcludes(List excludes) - { - this.excludes = excludes; - } - - public boolean isSkip() - { - return skip; - } - - public void setSkip(boolean skip) - { - this.skip = skip; - } - - public boolean isFiltered() - { - return filtered; - } - - public void setFiltered(boolean filtered) - { - this.filtered = filtered; - } - - public boolean isCurrentProject() - { - if (this.groupId == null && this.artifactId == null) - return true; - return false; - } - - /** - * Check if this overlay configuration matches an Artifact's info - * - * @param gid Artifact groupId - * @param aid Artifact artifactId - * @param cls Artifact classifier - * @return true if matched - */ - public boolean matchesArtifact(String gid, String aid, String cls) - { - if (((getGroupId() == null && gid == null) || (getGroupId() != null && getGroupId().equals(gid))) && - ((getArtifactId() == null && aid == null) || (getArtifactId() != null && getArtifactId().equals(aid))) && - ((getClassifier() == null) || (getClassifier().equals(cls)))) - return true; - - return false; - } - - /** - * Check if this overlay configuration matches an Artifact's info - * - * @param gid the group id - * @param aid the artifact id - * @return true if matched - */ - public boolean matchesArtifact(String gid, String aid) - { - if (((getGroupId() == null && gid == null) || (getGroupId() != null && getGroupId().equals(gid))) && - ((getArtifactId() == null && aid == null) || (getArtifactId() != null && getArtifactId().equals(aid)))) - return true; - - return false; - } - - @Override - public String toString() - { - StringBuilder strbuff = new StringBuilder(); - strbuff.append((groupId != null ? groupId : "") + ","); - strbuff.append((artifactId != null ? artifactId : "") + ","); - strbuff.append((classifier != null ? classifier : "") + ","); - strbuff.append((targetPath != null ? targetPath : "") + ","); - strbuff.append("" + skip + ","); - strbuff.append("" + filtered + ","); - - if (includes != null) - { - Iterator itor = includes.iterator(); - while (itor.hasNext()) - { - strbuff.append(itor.next()); - if (itor.hasNext()) - strbuff.append(";"); - } - } - - strbuff.append(", "); - - if (excludes != null) - { - Iterator itor = excludes.iterator(); - while (itor.hasNext()) - { - strbuff.append(itor.next()); - if (itor.hasNext()) - strbuff.append(";"); - } - } - - return strbuff.toString(); - } -} - diff --git a/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/OverlayManager.java b/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/OverlayManager.java deleted file mode 100644 index 40e353998d09..000000000000 --- a/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/OverlayManager.java +++ /dev/null @@ -1,163 +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.maven.plugin; - -import java.io.File; -import java.io.IOException; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Objects; -import java.util.Set; - -import org.apache.maven.artifact.Artifact; -import org.eclipse.jetty.ee10.webapp.WebAppContext; -import org.eclipse.jetty.util.URIUtil; -import org.eclipse.jetty.util.resource.MountedPathResource; -import org.eclipse.jetty.util.resource.Resource; -import org.eclipse.jetty.util.resource.ResourceFactory; - -/** - * OverlayManager - * - * Mediates information about overlays configured in a war plugin. - * - */ -public class OverlayManager -{ - private WarPluginInfo warPlugin; - - public OverlayManager(WarPluginInfo warPlugin) - { - this.warPlugin = warPlugin; - } - - public void applyOverlays(MavenWebAppContext webApp) throws IOException - { - Objects.requireNonNull(webApp); - List resourceBases = new ArrayList(); - - for (Overlay o : getOverlays(webApp)) - { - //can refer to the current project in list of overlays for ordering purposes - if (o.getConfig() != null && o.getConfig().isCurrentProject() && webApp.getBaseResource().exists()) - { - resourceBases.add(webApp.getBaseResource()); - continue; - } - //add in the selectively unpacked overlay in the correct order to the webapp's resource base - resourceBases.add(unpackOverlay(webApp, o)); - } - - if (!resourceBases.contains(webApp.getBaseResource()) && webApp.getBaseResource().exists()) - { - if (webApp.getBaseAppFirst()) - resourceBases.add(0, webApp.getBaseResource()); - else - resourceBases.add(webApp.getBaseResource()); - } - - webApp.setBaseResource(ResourceFactory.combine(resourceBases)); - } - - /** - * Generate an ordered list of overlays - */ - protected List getOverlays(WebAppContext webApp) - { - Set matchedWarArtifacts = new HashSet(); - List overlays = new ArrayList(); - - //Check all of the overlay configurations - for (OverlayConfig config:warPlugin.getMavenWarOverlayConfigs()) - { - //overlays can be individually skipped - if (config.isSkip()) - continue; - - //an empty overlay refers to the current project - important for ordering - if (config.isCurrentProject()) - { - Overlay overlay = new Overlay(config, null); - overlays.add(overlay); - continue; - } - - //if a war matches an overlay config - Artifact a = warPlugin.getWarArtifact(config.getGroupId(), config.getArtifactId(), config.getClassifier()); - if (a != null) - { - matchedWarArtifacts.add(a); - Resource resource = webApp.getResourceFactory().newJarFileResource(a.getFile().toPath().toUri()); - SelectiveJarResource r = new SelectiveJarResource(resource); - r.setIncludes(config.getIncludes()); - r.setExcludes(config.getExcludes()); - Overlay overlay = new Overlay(config, r); - overlays.add(overlay); - } - } - - //iterate over the left over war artifacts add them - for (Artifact a: warPlugin.getWarArtifacts()) - { - if (!matchedWarArtifacts.contains(a)) - { - Resource resource = webApp.getResourceFactory().newJarFileResource(a.getFile().toPath().toUri()); - Overlay overlay = new Overlay(null, resource); - overlays.add(overlay); - } - } - return overlays; - } - - /** - * Unpack a war overlay. - * - * @param overlay the war overlay to unpack - * @return the location to which it was unpacked - * @throws IOException if there is an IO problem - */ - protected Resource unpackOverlay(WebAppContext webApp, Overlay overlay) - throws IOException - { - Objects.requireNonNull(webApp); - - if (overlay.getResource() == null) - return null; //nothing to unpack - - //Get the name of the overlayed war and unpack it to a dir of the - //same name in the temporary directory. - //We know it is a war because it came from the maven repo - assert overlay.getResource() instanceof MountedPathResource; - - Path p = Paths.get(URIUtil.unwrapContainer(overlay.getResource().getURI())); - String name = p.getName(p.getNameCount() - 1).toString(); - name = name.replace('.', '_'); - - File overlaysDir = new File(warPlugin.getProject().getBuild().getDirectory(), "jetty_overlays"); - File dir = new File(overlaysDir, name); - - //if specified targetPath, unpack to that subdir instead - File unpackDir = dir; - if (overlay.getConfig() != null && overlay.getConfig().getTargetPath() != null) - unpackDir = new File(dir, overlay.getConfig().getTargetPath()); - - overlay.unpackTo(unpackDir); - - //use top level of unpacked content - return webApp.getResourceFactory().newResource(unpackDir.getCanonicalPath()); - } -} diff --git a/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/PluginLog.java b/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/PluginLog.java deleted file mode 100644 index 7adb0007d8d8..000000000000 --- a/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/PluginLog.java +++ /dev/null @@ -1,37 +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.maven.plugin; - -import org.apache.maven.plugin.logging.Log; - -/** - * PluginLog - * - * Convenience class to provide access to the plugin - * Log for non-mojo classes. - */ -public class PluginLog -{ - private static Log log = null; - - public static void setLog(Log l) - { - log = l; - } - - public static Log getLog() - { - return log; - } -} diff --git a/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/QuickStartGenerator.java b/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/QuickStartGenerator.java index 6fde7cf5b363..1b3a712c0bc6 100644 --- a/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/QuickStartGenerator.java +++ b/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/QuickStartGenerator.java @@ -18,6 +18,8 @@ import org.eclipse.jetty.ee10.annotations.AnnotationConfiguration; import org.eclipse.jetty.ee10.quickstart.QuickStartConfiguration; import org.eclipse.jetty.ee10.quickstart.QuickStartConfiguration.Mode; +import org.eclipse.jetty.ee10.webapp.Configurations; +import org.eclipse.jetty.maven.ServerSupport; import org.eclipse.jetty.server.Server; import org.eclipse.jetty.util.thread.QueuedThreadPool; @@ -148,7 +150,7 @@ public void generate() throws Exception //ensure handler structure enabled ServerSupport.configureHandlers(server, null, null); - ServerSupport.configureDefaultConfigurationClasses(server); + Configurations.setServerDefault(server); //if our server has a thread pool associated we can do annotation scanning multithreaded, //otherwise scanning will be single threaded diff --git a/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/ScanPattern.java b/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/ScanPattern.java deleted file mode 100644 index 889ba74f59bc..000000000000 --- a/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/ScanPattern.java +++ /dev/null @@ -1,48 +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.maven.plugin; - -import java.util.Collections; -import java.util.List; - -/** - * ScanPattern - * - * Ant-style pattern of includes and excludes. - */ -public class ScanPattern -{ - private List _includes = Collections.emptyList(); - private List _excludes = Collections.emptyList(); - - public void setIncludes(List includes) - { - _includes = includes; - } - - public void setExcludes(List excludes) - { - _excludes = excludes; - } - - public List getIncludes() - { - return _includes; - } - - public List getExcludes() - { - return _excludes; - } -} diff --git a/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/ScanTargetPattern.java b/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/ScanTargetPattern.java deleted file mode 100644 index 34e42a818915..000000000000 --- a/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/ScanTargetPattern.java +++ /dev/null @@ -1,108 +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.maven.plugin; - -import java.io.File; -import java.nio.file.Path; -import java.nio.file.PathMatcher; -import java.util.Collections; -import java.util.List; - -import org.eclipse.jetty.util.IncludeExcludeSet; - -/** - * ScanTargetPattern - * - * Utility class to provide the ability for the mvn jetty:run - * mojo to be able to specify filesets of extra files to - * regularly scan for changes in order to redeploy the webapp. - * - * For example: - * - * <scanTargetPattern> - * <directory>/some/place</directory> - * <includes> - * <include>some ant pattern here </include> - * <include>some ant pattern here </include> - * </includes> - * <excludes> - * <exclude>some ant pattern here </exclude> - * <exclude>some ant pattern here </exclude> - * </excludes> - * </scanTargetPattern> - */ -public class ScanTargetPattern -{ - private File _directory; - private ScanPattern _pattern; - - /** - * Get the _directory. - * @return the _directory - */ - public File getDirectory() - { - return _directory; - } - - /** - * Set the directory to set. - * @param directory the directory to set - */ - public void setDirectory(File directory) - { - this._directory = directory; - } - - public void setIncludes(List includes) - { - if (_pattern == null) - _pattern = new ScanPattern(); - _pattern.setIncludes(includes); - } - - public void setExcludes(List excludes) - { - if (_pattern == null) - _pattern = new ScanPattern(); - _pattern.setExcludes(excludes); - } - - public List getIncludes() - { - return (_pattern == null ? Collections.emptyList() : _pattern.getIncludes()); - } - - public List getExcludes() - { - return (_pattern == null ? Collections.emptyList() : _pattern.getExcludes()); - } - - public void configureIncludesExcludeSet(IncludeExcludeSet includesExcludes) - { - for (String include:getIncludes()) - { - if (!include.startsWith("glob:")) - include = "glob:" + include; - includesExcludes.include(_directory.toPath().getFileSystem().getPathMatcher(include)); - } - - for (String exclude:getExcludes()) - { - if (!exclude.startsWith("glob:")) - exclude = "glob:" + exclude; - includesExcludes.exclude(_directory.toPath().getFileSystem().getPathMatcher(exclude)); - } - } -} diff --git a/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/SelectiveJarResource.java b/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/SelectiveJarResource.java deleted file mode 100644 index 4a874dada7cb..000000000000 --- a/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/SelectiveJarResource.java +++ /dev/null @@ -1,280 +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.maven.plugin; - -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.net.URI; -import java.net.URL; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.attribute.FileTime; -import java.time.Instant; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; -import java.util.jar.JarEntry; -import java.util.jar.JarInputStream; -import java.util.jar.Manifest; - -import org.codehaus.plexus.util.SelectorUtils; -import org.eclipse.jetty.util.IO; -import org.eclipse.jetty.util.URIUtil; -import org.eclipse.jetty.util.resource.Resource; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * SelectiveJarResource - * - * Selectively copies resources from a jar file based on includes/excludes. - * TODO: investigate if copyTo() can instead have an IncludeExcludeSet as a parameter? - * TODO: or have a smaller ResourceWrapper jetty-core class that can be overridden for specific behavior like in this class - */ -public class SelectiveJarResource extends Resource -{ - private static final Logger LOG = LoggerFactory.getLogger(SelectiveJarResource.class); - - /** - * Default matches every resource. - */ - public static final List DEFAULT_INCLUDES = - Arrays.asList(new String[]{"**"}); - - /** - * Default is to exclude nothing. - */ - public static final List DEFAULT_EXCLUDES = Collections.emptyList(); - - final Resource _delegate; - List _includes = null; - List _excludes = null; - boolean _caseSensitive = false; - - public SelectiveJarResource(Resource resource) - { - _delegate = resource; - } - - public void setCaseSensitive(boolean caseSensitive) - { - _caseSensitive = caseSensitive; - } - - public void setIncludes(List patterns) - { - _includes = patterns; - } - - public void setExcludes(List patterns) - { - _excludes = patterns; - } - - protected boolean isIncluded(String name) - { - for (String include : _includes) - { - if (SelectorUtils.matchPath(include, name, "/", _caseSensitive)) - { - return true; - } - } - return false; - } - - protected boolean isExcluded(String name) - { - for (String exclude : _excludes) - { - if (SelectorUtils.matchPath(exclude, name, "/", _caseSensitive)) - { - return true; - } - } - return false; - } - - @Override - public Path getPath() - { - return _delegate.getPath(); - } - - @Override - public boolean isDirectory() - { - return _delegate.isDirectory(); - } - - @Override - public Instant lastModified() - { - return _delegate.lastModified(); - } - - @Override - public boolean isReadable() - { - return _delegate.isReadable(); - } - - @Override - public boolean isContainedIn(Resource container) - { - return _delegate.isContainedIn(container); - } - - @Override - public boolean contains(Resource other) - { - return _delegate.contains(other); - } - - @Override - public Path getPathTo(Resource other) - { - return _delegate.getPathTo(other); - } - - @Override - public URI getURI() - { - return _delegate.getURI(); - } - - @Override - public String getName() - { - return _delegate.getName(); - } - - @Override - public String getFileName() - { - return _delegate.getFileName(); - } - - @Override - public Resource resolve(String subUriPath) - { - return _delegate.resolve(subUriPath); - } - - @Override - public void copyTo(Path directory) throws IOException - { - if (_includes == null) - _includes = DEFAULT_INCLUDES; - if (_excludes == null) - _excludes = DEFAULT_EXCLUDES; - - //Copy contents of the jar file to the given directory, - //using the includes and excludes patterns to control which - //parts of the jar file are copied - if (!exists()) - return; - - String urlString = this.getURI().toASCIIString().trim(); - int endOfJarUrl = urlString.indexOf("!/"); - int startOfJarUrl = (endOfJarUrl >= 0 ? 4 : 0); - - if (endOfJarUrl < 0) - throw new IOException("Not a valid jar url: " + urlString); - - URL jarFileURL = new URL(urlString.substring(startOfJarUrl, endOfJarUrl)); - - try (InputStream is = jarFileURL.openConnection().getInputStream(); - JarInputStream jin = new JarInputStream(is)) - { - JarEntry entry; - - while ((entry = jin.getNextJarEntry()) != null) - { - String entryName = entry.getName(); - - LOG.debug("Looking at {}", entryName); - // make sure no access out of the root entry is present - if (URIUtil.isNotNormalWithinSelf(entryName)) - { - LOG.info("Invalid entry: {}", entryName); - continue; - } - - Path file = directory.resolve(entryName); - - if (entry.isDirectory()) - { - if (isIncluded(entryName)) - { - if (!isExcluded(entryName)) - { - // Make directory - if (!Files.exists(file)) - Files.createDirectories(file); - } - else - LOG.debug("{} dir is excluded", entryName); - } - else - LOG.debug("{} dir is NOT included", entryName); - } - else - { - //entry is a file, is it included? - if (isIncluded(entryName)) - { - if (!isExcluded(entryName)) - { - // make directory (some jars don't list dirs) - Path dir = file.getParent(); - if (!Files.exists(dir)) - Files.createDirectories(dir); - - // Make file - try (OutputStream fout = Files.newOutputStream(file)) - { - IO.copy(jin, fout); - } - - // touch the file. - if (entry.getTime() >= 0) - Files.setLastModifiedTime(file, FileTime.fromMillis(entry.getTime())); - } - else - LOG.debug("{} file is excluded", entryName); - } - else - LOG.debug("{} file is NOT included", entryName); - } - } - - Manifest manifest = jin.getManifest(); - if (manifest != null) - { - if (isIncluded("META-INF") && !isExcluded("META-INF")) - { - Path metaInf = directory.resolve("META-INF"); - Files.createDirectory(metaInf); - Path f = metaInf.resolve("MANIFEST.MF"); - try (OutputStream fout = Files.newOutputStream(f)) - { - manifest.write(fout); - } - } - } - } - } -} diff --git a/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/ServerConnectorListener.java b/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/ServerConnectorListener.java deleted file mode 100644 index c3c534c7d503..000000000000 --- a/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/ServerConnectorListener.java +++ /dev/null @@ -1,111 +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.maven.plugin; - -import java.io.Writer; -import java.nio.file.AtomicMoveNotSupportedException; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.nio.file.StandardCopyOption; - -import org.eclipse.jetty.server.ServerConnector; -import org.eclipse.jetty.util.component.AbstractLifeCycle.AbstractLifeCycleListener; -import org.eclipse.jetty.util.component.LifeCycle; - -/** - * ServerConnectorListener - * - * This is for test support, where we need jetty to run on a random port, and we need - * a client to be able to find out which port was picked. - */ -public class ServerConnectorListener extends AbstractLifeCycleListener -{ - private String _fileName; - private String _sysPropertyName; - - @Override - public void lifeCycleStarted(LifeCycle event) - { - if (getFileName() != null) - { - try - { - Path tmp = Files.createTempFile("jettyport", ".tmp"); - try (Writer writer = Files.newBufferedWriter(tmp)) - { - writer.write(String.valueOf(((ServerConnector)event).getLocalPort())); - } - - Path path = Paths.get(getFileName()); - Files.deleteIfExists(path); - try - { - Files.move(tmp, path, StandardCopyOption.ATOMIC_MOVE); - } - catch (AtomicMoveNotSupportedException e) // can append on some os (windows).. so try again without the option - { - Files.move(tmp, path); - } - } - catch (Exception e) - { - throw new RuntimeException(e); - } - } - - if (getSysPropertyName() != null) - { - System.setProperty(_sysPropertyName, String.valueOf(((ServerConnector)event).getLocalPort())); - } - super.lifeCycleStarted(event); - } - - /** - * Get the file name. - * @return the file name - */ - public String getFileName() - { - return _fileName; - } - - /** - * Set the file name to set. - * @param name the file name to set - */ - public void setFileName(String name) - { - - _fileName = name; - } - - /** - * Get the sysPropertyName. - * @return the sysPropertyName - */ - public String getSysPropertyName() - { - return _sysPropertyName; - } - - /** - * Set the sysPropertyName to set. - * @param sysPropertyName the sysPropertyName to set - */ - public void setSysPropertyName(String sysPropertyName) - { - _sysPropertyName = sysPropertyName; - } -} diff --git a/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/ServerListener.java b/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/ServerListener.java deleted file mode 100644 index 940c99d606f9..000000000000 --- a/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/ServerListener.java +++ /dev/null @@ -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.maven.plugin; - -import java.nio.file.Files; -import java.nio.file.Path; - -import org.eclipse.jetty.util.component.LifeCycle; - -/** - * ServerListener - * - * Listener to create a file that signals that the startup is completed. - * Used by the JettyRunHome maven goal to determine that the child - * process is started, and that jetty is ready. - */ -public class ServerListener implements LifeCycle.Listener -{ - private String _tokenFile; - - public void setTokenFile(String file) - { - _tokenFile = file; - } - - public String getTokenFile() - { - return _tokenFile; - } - - @Override - public void lifeCycleStarted(LifeCycle event) - { - if (_tokenFile != null) - { - try - { - // Using Path, as we need to reliably create/write a file. - Path path = Path.of(_tokenFile); - Files.createFile(path); - } - catch (Exception e) - { - throw new IllegalStateException(e); - } - } - } -} diff --git a/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/ServerSupport.java b/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/ServerSupport.java deleted file mode 100644 index f648dd6b449c..000000000000 --- a/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/ServerSupport.java +++ /dev/null @@ -1,236 +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.maven.plugin; - -import java.io.File; -import java.util.Enumeration; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.eclipse.jetty.ee10.webapp.Configurations; -import org.eclipse.jetty.ee10.webapp.WebAppContext; -import org.eclipse.jetty.security.LoginService; -import org.eclipse.jetty.server.Connector; -import org.eclipse.jetty.server.RequestLog; -import org.eclipse.jetty.server.Server; -import org.eclipse.jetty.server.handler.ContextHandler; -import org.eclipse.jetty.server.handler.ContextHandlerCollection; -import org.eclipse.jetty.util.resource.ResourceFactory; -import org.eclipse.jetty.xml.XmlConfiguration; - -/** - * ServerSupport - * - * Helps configure the Server instance. - */ -public class ServerSupport -{ - - public static void configureDefaultConfigurationClasses(Server server) - { - Configurations.setServerDefault(server); - } - - /** - * Set up the handler structure to receive a webapp. - * Also put in a DefaultHandler so we get a nicer page - * than a 404 if we hit the root and the webapp's - * context isn't at root. - * - * @param server the server to use - * @param contextHandlers the context handlers to include - * @param requestLog a request log to use - */ - public static void configureHandlers(Server server, List contextHandlers, RequestLog requestLog) - { - if (server == null) - throw new IllegalArgumentException("Server is null"); - - if (requestLog != null) - server.setRequestLog(requestLog); - - ContextHandlerCollection contexts = findContextHandlerCollection(server); - if (contexts == null) - { - contexts = new ContextHandlerCollection(); - server.setHandler(contexts); - } - - if (contextHandlers != null) - { - for (ContextHandler context:contextHandlers) - { - contexts.addHandler(context); - } - } - } - - /** - * Configure at least one connector for the server - * - * @param server the server - * @param connector the connector - * @param properties jetty properties - */ - public static void configureConnectors(Server server, Connector connector, Map properties) - { - if (server == null) - throw new IllegalArgumentException("Server is null"); - - //if a connector is provided, use it - if (connector != null) - { - server.addConnector(connector); - return; - } - - // if the user hasn't configured the connectors in a jetty.xml file so use a default one - Connector[] connectors = server.getConnectors(); - if (connectors == null || connectors.length == 0) - { - //Make a new default connector - MavenServerConnector tmp = new MavenServerConnector(); - //use any jetty.http.port settings provided, trying system properties before jetty properties - String port = System.getProperty(MavenServerConnector.PORT_SYSPROPERTY); - if (port == null) - port = System.getProperty("jetty.port"); - if (port == null) - port = (properties != null ? properties.get(MavenServerConnector.PORT_SYSPROPERTY) : null); - if (port == null) - port = MavenServerConnector.DEFAULT_PORT_STR; - tmp.setPort(Integer.parseInt(port.trim())); - tmp.setServer(server); - server.setConnectors(new Connector[]{tmp}); - } - } - - /** - * Set up any security LoginServices provided. - * - * @param server the server - * @param loginServices the login services - */ - public static void configureLoginServices(Server server, List loginServices) - { - if (server == null) - throw new IllegalArgumentException("Server is null"); - - if (loginServices != null) - { - for (LoginService loginService : loginServices) - { - PluginLog.getLog().debug(loginService.getClass().getName() + ": " + loginService.toString()); - server.addBean(loginService); - } - } - } - - /** - * Add a WebAppContext to a Server - * @param server the server to use - * @param webapp the webapp to add - */ - public static void addWebApplication(Server server, WebAppContext webapp) - { - if (server == null) - throw new IllegalArgumentException("Server is null"); - ContextHandlerCollection contexts = findContextHandlerCollection(server); - if (contexts == null) - throw new IllegalStateException("ContextHandlerCollection is null"); - contexts.addHandler(webapp); - } - - /** - * Locate a ContextHandlerCollection for a Server. - * - * @param server the Server to check. - * @return The ContextHandlerCollection or null if not found. - */ - public static ContextHandlerCollection findContextHandlerCollection(Server server) - { - if (server == null) - return null; - - return server.getDescendant(ContextHandlerCollection.class); - } - - /** - * Apply xml files to server instance. - * - * @param server the server to apply the xml to - * @param files the list of xml files - * @param properties list of jetty properties - * @return the Server implementation, after the xml is applied - * @throws Exception if unable to apply the xml configuration - */ - public static Server applyXmlConfigurations(Server server, List files, Map properties) - throws Exception - { - if (files == null || files.isEmpty()) - return server; - - Map lastMap = new HashMap<>(); - - if (server != null) - lastMap.put("Server", server); - - for (File xmlFile : files) - { - if (PluginLog.getLog() != null) - PluginLog.getLog().info("Configuring Jetty from xml configuration file = " + xmlFile.getCanonicalPath()); - - XmlConfiguration xmlConfiguration = new XmlConfiguration(ResourceFactory.of(server).newResource(xmlFile.toPath())); - - //add in any properties - if (properties != null) - { - for (Map.Entry e : properties.entrySet()) - { - xmlConfiguration.getProperties().put(e.getKey(), e.getValue()); - } - } - - //chain ids from one config file to another - if (lastMap != null) - xmlConfiguration.getIdMap().putAll(lastMap); - - //Set the system properties each time in case the config file set a new one - Enumeration ensysprop = System.getProperties().propertyNames(); - while (ensysprop.hasMoreElements()) - { - String name = (String)ensysprop.nextElement(); - xmlConfiguration.getProperties().put(name, System.getProperty(name)); - } - xmlConfiguration.configure(); - lastMap = xmlConfiguration.getIdMap(); - } - - return (Server)lastMap.get("Server"); - } - - /** - * Apply xml files to server instance. - * - * @param server the Server instance to configure - * @param files the xml configs to apply - * @return the Server after application of configs - * @throws Exception if there is an unspecified problem - */ - public static Server applyXmlConfigurations(Server server, List files) - throws Exception - { - return applyXmlConfigurations(server, files, null); - } -} diff --git a/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/WarPluginInfo.java b/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/WarPluginInfo.java deleted file mode 100644 index 78b566f14e19..000000000000 --- a/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/WarPluginInfo.java +++ /dev/null @@ -1,239 +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.maven.plugin; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Optional; -import java.util.Set; -import java.util.stream.Collectors; - -import org.apache.maven.artifact.Artifact; -import org.apache.maven.model.Plugin; -import org.apache.maven.project.MavenProject; -import org.codehaus.plexus.util.xml.Xpp3Dom; -import org.eclipse.jetty.util.StringUtil; - -/** - * WarPluginInfo - * - * Information about the maven-war-plugin contained in the pom - */ -public class WarPluginInfo -{ - private MavenProject _project; - private Plugin _plugin; - private List _dependentMavenWarIncludes; - private List _dependentMavenWarExcludes; - private List _overlayConfigs; - private Set _warArtifacts; - - public WarPluginInfo(MavenProject project) - { - _project = project; - if (_project.getArtifacts() != null) - { - _warArtifacts = _project.getArtifacts() - .stream() - .filter(a -> "war".equals(a.getType()) || "zip".equals(a.getType())).collect(Collectors.toSet()); - } - else - _warArtifacts = Collections.emptySet(); - } - - /** - * Get the project. - * @return the project - */ - public MavenProject getProject() - { - return _project; - } - - /** - * Get all dependent artifacts that are wars. - * @return all artifacts of type "war" or "zip" - */ - public Set getWarArtifacts() - { - return _warArtifacts; - } - - /** - * Get an artifact of type war that matches the given coordinates. - * @param groupId the groupId to match - * @param artifactId the artifactId to match - * @param classifier the classified to match - * @return the matching Artifact or null if no match - */ - public Artifact getWarArtifact(String groupId, String artifactId, String classifier) - { - Optional o = _warArtifacts.stream() - .filter(a -> match(a, groupId, artifactId, classifier)).findFirst(); - return o.orElse(null); - } - - /** - * Find the maven-war-plugin, if one is configured - * - * @return the plugin - */ - public Plugin getWarPlugin() - { - if (_plugin == null) - { - List plugins = _project.getBuildPlugins(); - if (plugins == null) - return null; - - for (Plugin p : plugins) - { - if ("maven-war-plugin".equals(p.getArtifactId())) - { - _plugin = p; - break; - } - } - } - return _plugin; - } - - /** - * Get value of dependentWarIncludes for maven-war-plugin - * - * @return the list of dependent war includes - */ - public List getDependentMavenWarIncludes() - { - if (_dependentMavenWarIncludes == null) - { - getWarPlugin(); - - if (_plugin == null) - return null; - - Xpp3Dom node = (Xpp3Dom)_plugin.getConfiguration(); - if (node == null) - return null; - - node = node.getChild("dependentWarIncludes"); - if (node == null) - return null; - String val = node.getValue(); - _dependentMavenWarIncludes = StringUtil.csvSplit(null, val, 0, val.length()); - } - return _dependentMavenWarIncludes; - } - - /** - * Get value of dependentWarExcludes for maven-war-plugin - * - * @return the list of dependent war excludes - */ - public List getDependentMavenWarExcludes() - { - if (_dependentMavenWarExcludes == null) - { - getWarPlugin(); - - if (_plugin == null) - return null; - - Xpp3Dom node = (Xpp3Dom)_plugin.getConfiguration(); - if (node == null) - return null; - - node = node.getChild("dependentWarExcludes"); - if (node == null) - return null; - String val = node.getValue(); - _dependentMavenWarExcludes = StringUtil.csvSplit(null, val, 0, val.length()); - } - return _dependentMavenWarExcludes; - } - - /** - * Get config for any overlays that have been declared for the maven-war-plugin. - * - * @return the list of overlay configs - */ - public List getMavenWarOverlayConfigs() - { - if (_overlayConfigs == null) - { - getWarPlugin(); - - if (_plugin == null) - return Collections.emptyList(); - - getDependentMavenWarIncludes(); - getDependentMavenWarExcludes(); - - Xpp3Dom node = (Xpp3Dom)_plugin.getConfiguration(); - if (node == null) - return Collections.emptyList(); - - node = node.getChild("overlays"); - if (node == null) - return Collections.emptyList(); - - Xpp3Dom[] nodes = node.getChildren("overlay"); - if (nodes == null) - return Collections.emptyList(); - - _overlayConfigs = new ArrayList(); - for (int i = 0; i < nodes.length; i++) - { - OverlayConfig overlayConfig = new OverlayConfig(nodes[i], _dependentMavenWarIncludes, _dependentMavenWarExcludes); - _overlayConfigs.add(overlayConfig); - } - } - - return _overlayConfigs; - } - - public boolean match(Artifact a, String gid, String aid, String cls) - { - if (a == null) - return (gid == null && aid == null && cls == null); - - if (((a.getGroupId() == null && gid == null) || (a.getGroupId() != null && a.getGroupId().equals(gid))) && - ((a.getArtifactId() == null && aid == null) || (a.getArtifactId() != null && a.getArtifactId().equals(aid))) && - ((a.getClassifier() == null) || (a.getClassifier().equals(cls)))) - return true; - - return false; - } - - /** - * Check if the given artifact matches the group and artifact coordinates. - * - * @param a the artifact to check - * @param gid the group id - * @param aid the artifact id - * @return true if matched false otherwise - */ - public boolean match(Artifact a, String gid, String aid) - { - if (a == null) - return (gid == null && aid == null); - - if (((a.getGroupId() == null && gid == null) || (a.getGroupId() != null && a.getGroupId().equals(gid))) && - ((a.getArtifactId() == null && aid == null) || (a.getArtifactId() != null && a.getArtifactId().equals(aid)))) - return true; - - return false; - } -} diff --git a/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/utils/MavenProjectHelper.java b/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/utils/MavenProjectHelper.java deleted file mode 100644 index 1f0c7197ea5a..000000000000 --- a/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/utils/MavenProjectHelper.java +++ /dev/null @@ -1,185 +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.maven.plugin.utils; - -import java.io.File; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.Collection; -import java.util.Collections; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.function.Function; -import java.util.stream.Collectors; - -import org.apache.maven.RepositoryUtils; -import org.apache.maven.artifact.Artifact; -import org.apache.maven.artifact.repository.ArtifactRepository; -import org.apache.maven.execution.MavenSession; -import org.apache.maven.project.MavenProject; -import org.eclipse.aether.RepositorySystem; -import org.eclipse.aether.artifact.DefaultArtifact; -import org.eclipse.aether.resolution.ArtifactRequest; -import org.eclipse.aether.resolution.ArtifactResolutionException; -import org.eclipse.aether.resolution.ArtifactResult; -import org.eclipse.jetty.ee10.maven.plugin.OverlayManager; -import org.eclipse.jetty.ee10.maven.plugin.WarPluginInfo; - -/** - * MavenProjectHelper - * - * A class to facilitate interacting with the build time maven environment. - */ -public class MavenProjectHelper -{ - private MavenProject project; - private RepositorySystem repositorySystem; - private List remoteRepositories; - private MavenSession session; - private final Map artifactToReactorProjectMap; - /** - * maven-war-plugin reference - */ - private WarPluginInfo warPluginInfo; - - /** - * Helper for wrangling war overlays - */ - private OverlayManager overlayManager; - - /** - * @param project the project being built - * @param repositorySystem a resolve for artifacts - * @param remoteRepositories repositories from which to resolve artifacts - * @param session the current maven build session - */ - public MavenProjectHelper(MavenProject project, RepositorySystem repositorySystem, List remoteRepositories, MavenSession session) - { - this.project = project; - this.repositorySystem = repositorySystem; - this.remoteRepositories = remoteRepositories; - this.session = session; - //work out which dependent projects are in the reactor - Set mavenProjects = findDependenciesInReactor(project, new HashSet<>()); - artifactToReactorProjectMap = mavenProjects.stream() - .collect(Collectors.toMap(MavenProject::getId, Function.identity())); - artifactToReactorProjectMap.put(project.getArtifact().getId(), project); - warPluginInfo = new WarPluginInfo(project); - overlayManager = new OverlayManager(warPluginInfo); - } - - public MavenProject getProject() - { - return this.project; - } - - public WarPluginInfo getWarPluginInfo() - { - return warPluginInfo; - } - - public OverlayManager getOverlayManager() - { - return overlayManager; - } - - /** - * Gets the maven project represented by the artifact iff it is in - * the reactor. - * - * @param artifact the artifact of the project to get - * @return {@link MavenProject} if artifact is referenced in reactor, otherwise null - */ - public MavenProject getMavenProjectFor(Artifact artifact) - { - if (artifact == null) - return null; - return artifactToReactorProjectMap.get(artifact.getId()); - } - - /** - * Gets path to artifact. - * If the artifact is referenced in the reactor, returns path to ${project.build.outputDirectory}. - * Otherwise, returns path to location in local m2 repo. - * - * Cannot return null - maven will complain about unsatisfied dependency during project build. - * - * @param artifact maven artifact to check - * @return path to artifact - */ - public Path getPathFor(Artifact artifact) - { - Path path = artifact.getFile().toPath(); - MavenProject mavenProject = getMavenProjectFor(artifact); - if (mavenProject != null) - { - if ("test-jar".equals(artifact.getType())) - { - path = Paths.get(mavenProject.getBuild().getTestOutputDirectory()); - } - else - { - path = Paths.get(mavenProject.getBuild().getOutputDirectory()); - } - } - return path; - } - - /** - * Given the coordinates for an artifact, resolve the artifact from the - * remote repositories. - * - * @param groupId the groupId of the artifact to resolve - * @param artifactId the artifactId of the artifact to resolve - * @param version the version of the artifact to resolve - * @param type the type of the artifact to resolve - * @return a File representing the location of the artifact or null if not resolved - */ - public File resolveArtifact(String groupId, String artifactId, String version, String type) - throws ArtifactResolutionException - { - ArtifactRequest request = new ArtifactRequest(); - request.setRepositories(RepositoryUtils.toRepos(remoteRepositories)); - request.setArtifact(new DefaultArtifact(groupId, artifactId, "", type, version)); - ArtifactResult result = repositorySystem.resolveArtifact(session.getRepositorySession(), request); - - if (result.isResolved()) - return result.getArtifact().getFile(); - return null; - } - - /** - * Recursively find projects in the reactor for all dependencies of the given project. - * - * @param project the project for which to find dependencies that are in the reactor - * @param visitedProjects the set of projects already seen - * @return unified set of all related projects in the reactor - */ - private static Set findDependenciesInReactor(MavenProject project, Set visitedProjects) - { - if (visitedProjects.contains(project)) - return Collections.emptySet(); - - visitedProjects.add(project); - Collection refs = project.getProjectReferences().values(); - Set availableProjects = new HashSet<>(refs); - for (MavenProject ref : refs) - { - availableProjects.addAll(findDependenciesInReactor(ref, visitedProjects)); - } - return availableProjects; - } -} diff --git a/jetty-ee10/jetty-ee10-maven-plugin/src/main/resources/ee10-maven.mod b/jetty-ee10/jetty-ee10-maven-plugin/src/main/resources/ee10-maven.mod index 344d4aaaa825..ab4ed52419b7 100644 --- a/jetty-ee10/jetty-ee10-maven-plugin/src/main/resources/ee10-maven.mod +++ b/jetty-ee10/jetty-ee10-maven-plugin/src/main/resources/ee10-maven.mod @@ -12,7 +12,7 @@ ee10-webapp ee10-annotations [lib] -lib/maven-ee10/*.jar +lib/ee10-maven/*.jar [xml] etc/jetty-ee10-maven.xml diff --git a/jetty-ee10/jetty-ee10-maven-plugin/src/main/resources/jetty-ee10-maven.xml b/jetty-ee10/jetty-ee10-maven-plugin/src/main/resources/jetty-ee10-maven.xml index d1ba792557f2..b83be87a6474 100644 --- a/jetty-ee10/jetty-ee10-maven-plugin/src/main/resources/jetty-ee10-maven.xml +++ b/jetty-ee10/jetty-ee10-maven-plugin/src/main/resources/jetty-ee10-maven.xml @@ -4,7 +4,7 @@ - + diff --git a/jetty-ee10/jetty-ee10-maven-plugin/src/test/java/org/eclipse/jetty/ee10/maven/plugin/TestForkedChild.java b/jetty-ee10/jetty-ee10-maven-plugin/src/test/java/org/eclipse/jetty/ee10/maven/plugin/TestForkedChild.java index b2cc8e5f9c85..8e13f6fcb2ed 100644 --- a/jetty-ee10/jetty-ee10-maven-plugin/src/test/java/org/eclipse/jetty/ee10/maven/plugin/TestForkedChild.java +++ b/jetty-ee10/jetty-ee10-maven-plugin/src/test/java/org/eclipse/jetty/ee10/maven/plugin/TestForkedChild.java @@ -88,7 +88,7 @@ public void run() webapp.setBaseResourceAsPath(baseDir.toPath()); WebAppPropertyConverter.toProperties(webapp, webappPropsFile, null); child = new JettyForkedChild(cmd.toArray(new String[0])); - child.jetty.setExitVm(false); //ensure jetty doesn't stop vm for testing + child.getJettyEmbedder().setExitVm(false); //ensure jetty doesn't stop vm for testing child.start(); } catch (Exception e) diff --git a/jetty-ee10/jetty-ee10-maven-plugin/src/test/java/org/eclipse/jetty/ee10/maven/plugin/TestJettyEmbedder.java b/jetty-ee10/jetty-ee10-maven-plugin/src/test/java/org/eclipse/jetty/ee10/maven/plugin/TestJettyEmbedder.java index 7cbd78e1c09a..b5bf18ed1f04 100644 --- a/jetty-ee10/jetty-ee10-maven-plugin/src/test/java/org/eclipse/jetty/ee10/maven/plugin/TestJettyEmbedder.java +++ b/jetty-ee10/jetty-ee10-maven-plugin/src/test/java/org/eclipse/jetty/ee10/maven/plugin/TestJettyEmbedder.java @@ -19,6 +19,8 @@ import java.util.Map; import org.eclipse.jetty.ee10.servlet.ListenerHolder; +import org.eclipse.jetty.maven.MavenServerConnector; +import org.eclipse.jetty.maven.ServerSupport; import org.eclipse.jetty.server.Server; import org.eclipse.jetty.server.handler.ContextHandler; import org.eclipse.jetty.server.handler.ContextHandlerCollection; @@ -119,7 +121,7 @@ public void testJettyEmbedder(WorkDir workDir) assertTrue(contexts.contains(webApp)); //stop the webapp and check durable listener retained - jetty.getWebApp().stop(); + jetty.stopWebApp(); boolean someListener = false; for (ListenerHolder h : webApp.getServletHandler().getListeners()) { diff --git a/jetty-ee10/jetty-ee10-maven-plugin/src/test/java/org/eclipse/jetty/ee10/maven/plugin/TestSelectiveJarResource.java b/jetty-ee10/jetty-ee10-maven-plugin/src/test/java/org/eclipse/jetty/ee10/maven/plugin/TestSelectiveJarResource.java index 2fb56640d908..483eb28668df 100644 --- a/jetty-ee10/jetty-ee10-maven-plugin/src/test/java/org/eclipse/jetty/ee10/maven/plugin/TestSelectiveJarResource.java +++ b/jetty-ee10/jetty-ee10-maven-plugin/src/test/java/org/eclipse/jetty/ee10/maven/plugin/TestSelectiveJarResource.java @@ -18,6 +18,7 @@ import java.util.ArrayList; import java.util.List; +import org.eclipse.jetty.maven.SelectiveJarResource; import org.eclipse.jetty.toolchain.test.MavenTestingUtils; import org.eclipse.jetty.toolchain.test.jupiter.WorkDir; import org.eclipse.jetty.toolchain.test.jupiter.WorkDirExtension; diff --git a/jetty-ee8/jetty-ee8-maven-plugin/pom.xml b/jetty-ee8/jetty-ee8-maven-plugin/pom.xml index fc9eaf2a258c..cf75ae8a06d8 100644 --- a/jetty-ee8/jetty-ee8-maven-plugin/pom.xml +++ b/jetty-ee8/jetty-ee8-maven-plugin/pom.xml @@ -86,6 +86,10 @@ jetty-jndi true + + org.eclipse.jetty + jetty-maven + org.eclipse.jetty jetty-server diff --git a/jetty-ee8/jetty-ee8-maven-plugin/src/it/jetty-cdi-start-forked/src/main/jetty/jetty.xml b/jetty-ee8/jetty-ee8-maven-plugin/src/it/jetty-cdi-start-forked/src/main/jetty/jetty.xml index 5ce14c43a125..8a8f26b49f4f 100644 --- a/jetty-ee8/jetty-ee8-maven-plugin/src/it/jetty-cdi-start-forked/src/main/jetty/jetty.xml +++ b/jetty-ee8/jetty-ee8-maven-plugin/src/it/jetty-cdi-start-forked/src/main/jetty/jetty.xml @@ -26,7 +26,7 @@ - + diff --git a/jetty-ee8/jetty-ee8-maven-plugin/src/it/jetty-maven-plugin-provided-module-dep/web/src/config/jetty.xml b/jetty-ee8/jetty-ee8-maven-plugin/src/it/jetty-maven-plugin-provided-module-dep/web/src/config/jetty.xml index 96f41b96416b..ef0c9bcad939 100644 --- a/jetty-ee8/jetty-ee8-maven-plugin/src/it/jetty-maven-plugin-provided-module-dep/web/src/config/jetty.xml +++ b/jetty-ee8/jetty-ee8-maven-plugin/src/it/jetty-maven-plugin-provided-module-dep/web/src/config/jetty.xml @@ -32,7 +32,7 @@ - + diff --git a/jetty-ee8/jetty-ee8-maven-plugin/src/it/jetty-run-mojo-jar-scan-it/MyWebApp/src/config/jetty.xml b/jetty-ee8/jetty-ee8-maven-plugin/src/it/jetty-run-mojo-jar-scan-it/MyWebApp/src/config/jetty.xml index 0bdfe18d5250..343f5e7f99b1 100644 --- a/jetty-ee8/jetty-ee8-maven-plugin/src/it/jetty-run-mojo-jar-scan-it/MyWebApp/src/config/jetty.xml +++ b/jetty-ee8/jetty-ee8-maven-plugin/src/it/jetty-run-mojo-jar-scan-it/MyWebApp/src/config/jetty.xml @@ -26,7 +26,7 @@ - + diff --git a/jetty-ee8/jetty-ee8-maven-plugin/src/it/jetty-start-distro-mojo-it/jetty-simple-webapp/src/base/etc/test-jetty-ee8.xml b/jetty-ee8/jetty-ee8-maven-plugin/src/it/jetty-start-distro-mojo-it/jetty-simple-webapp/src/base/etc/test-jetty-ee8.xml index 768db9db9267..9857cb546ef7 100644 --- a/jetty-ee8/jetty-ee8-maven-plugin/src/it/jetty-start-distro-mojo-it/jetty-simple-webapp/src/base/etc/test-jetty-ee8.xml +++ b/jetty-ee8/jetty-ee8-maven-plugin/src/it/jetty-start-distro-mojo-it/jetty-simple-webapp/src/base/etc/test-jetty-ee8.xml @@ -5,7 +5,7 @@ - + diff --git a/jetty-ee8/jetty-ee8-maven-plugin/src/it/jetty-start-forked-mojo-it/jetty-simple-webapp/src/config/jetty.xml b/jetty-ee8/jetty-ee8-maven-plugin/src/it/jetty-start-forked-mojo-it/jetty-simple-webapp/src/config/jetty.xml index 0bdfe18d5250..343f5e7f99b1 100644 --- a/jetty-ee8/jetty-ee8-maven-plugin/src/it/jetty-start-forked-mojo-it/jetty-simple-webapp/src/config/jetty.xml +++ b/jetty-ee8/jetty-ee8-maven-plugin/src/it/jetty-start-forked-mojo-it/jetty-simple-webapp/src/config/jetty.xml @@ -26,7 +26,7 @@ - + diff --git a/jetty-ee8/jetty-ee8-maven-plugin/src/it/jetty-start-gwt-it/beer-server/src/config/jetty.xml b/jetty-ee8/jetty-ee8-maven-plugin/src/it/jetty-start-gwt-it/beer-server/src/config/jetty.xml index 0bdfe18d5250..343f5e7f99b1 100644 --- a/jetty-ee8/jetty-ee8-maven-plugin/src/it/jetty-start-gwt-it/beer-server/src/config/jetty.xml +++ b/jetty-ee8/jetty-ee8-maven-plugin/src/it/jetty-start-gwt-it/beer-server/src/config/jetty.xml @@ -26,7 +26,7 @@ - + diff --git a/jetty-ee8/jetty-ee8-maven-plugin/src/it/jetty-start-mojo-it/jetty-simple-webapp/pom.xml b/jetty-ee8/jetty-ee8-maven-plugin/src/it/jetty-start-mojo-it/jetty-simple-webapp/pom.xml index e8e0e40b0056..94439d89a518 100644 --- a/jetty-ee8/jetty-ee8-maven-plugin/src/it/jetty-start-mojo-it/jetty-simple-webapp/pom.xml +++ b/jetty-ee8/jetty-ee8-maven-plugin/src/it/jetty-start-mojo-it/jetty-simple-webapp/pom.xml @@ -140,7 +140,7 @@ - + ${basedir}/src/config/login.xml diff --git a/jetty-ee8/jetty-ee8-maven-plugin/src/it/jetty-start-mojo-it/jetty-simple-webapp/src/config/jetty.xml b/jetty-ee8/jetty-ee8-maven-plugin/src/it/jetty-start-mojo-it/jetty-simple-webapp/src/config/jetty.xml index 0bdfe18d5250..343f5e7f99b1 100644 --- a/jetty-ee8/jetty-ee8-maven-plugin/src/it/jetty-start-mojo-it/jetty-simple-webapp/src/config/jetty.xml +++ b/jetty-ee8/jetty-ee8-maven-plugin/src/it/jetty-start-mojo-it/jetty-simple-webapp/src/config/jetty.xml @@ -26,7 +26,7 @@ - + diff --git a/jetty-ee8/jetty-ee8-maven-plugin/src/it/jetty-start-mojo-multi-module-single-war-it/webapp-war/src/config/jetty.xml b/jetty-ee8/jetty-ee8-maven-plugin/src/it/jetty-start-mojo-multi-module-single-war-it/webapp-war/src/config/jetty.xml index 0bdfe18d5250..343f5e7f99b1 100644 --- a/jetty-ee8/jetty-ee8-maven-plugin/src/it/jetty-start-mojo-multi-module-single-war-it/webapp-war/src/config/jetty.xml +++ b/jetty-ee8/jetty-ee8-maven-plugin/src/it/jetty-start-mojo-multi-module-single-war-it/webapp-war/src/config/jetty.xml @@ -26,7 +26,7 @@ - + diff --git a/jetty-ee8/jetty-ee8-maven-plugin/src/it/jetty-start-war-distro-mojo-it/jetty-simple-webapp/src/base/etc/test-jetty-ee8.xml b/jetty-ee8/jetty-ee8-maven-plugin/src/it/jetty-start-war-distro-mojo-it/jetty-simple-webapp/src/base/etc/test-jetty-ee8.xml index 768db9db9267..9857cb546ef7 100644 --- a/jetty-ee8/jetty-ee8-maven-plugin/src/it/jetty-start-war-distro-mojo-it/jetty-simple-webapp/src/base/etc/test-jetty-ee8.xml +++ b/jetty-ee8/jetty-ee8-maven-plugin/src/it/jetty-start-war-distro-mojo-it/jetty-simple-webapp/src/base/etc/test-jetty-ee8.xml @@ -5,7 +5,7 @@ - + diff --git a/jetty-ee8/jetty-ee8-maven-plugin/src/it/jetty-start-war-forked-mojo-it/jetty-simple-webapp/src/config/jetty.xml b/jetty-ee8/jetty-ee8-maven-plugin/src/it/jetty-start-war-forked-mojo-it/jetty-simple-webapp/src/config/jetty.xml index 0bdfe18d5250..343f5e7f99b1 100644 --- a/jetty-ee8/jetty-ee8-maven-plugin/src/it/jetty-start-war-forked-mojo-it/jetty-simple-webapp/src/config/jetty.xml +++ b/jetty-ee8/jetty-ee8-maven-plugin/src/it/jetty-start-war-forked-mojo-it/jetty-simple-webapp/src/config/jetty.xml @@ -26,7 +26,7 @@ - + diff --git a/jetty-ee8/jetty-ee8-maven-plugin/src/it/jetty-start-war-mojo-it/src/config/jetty.xml b/jetty-ee8/jetty-ee8-maven-plugin/src/it/jetty-start-war-mojo-it/src/config/jetty.xml index 0bdfe18d5250..343f5e7f99b1 100644 --- a/jetty-ee8/jetty-ee8-maven-plugin/src/it/jetty-start-war-mojo-it/src/config/jetty.xml +++ b/jetty-ee8/jetty-ee8-maven-plugin/src/it/jetty-start-war-mojo-it/src/config/jetty.xml @@ -26,7 +26,7 @@ - + diff --git a/jetty-ee8/jetty-ee8-maven-plugin/src/main/resources/ee8-maven.mod b/jetty-ee8/jetty-ee8-maven-plugin/src/main/resources/ee8-maven.mod index e7f649493219..e16db22ed87b 100644 --- a/jetty-ee8/jetty-ee8-maven-plugin/src/main/resources/ee8-maven.mod +++ b/jetty-ee8/jetty-ee8-maven-plugin/src/main/resources/ee8-maven.mod @@ -12,7 +12,7 @@ ee8-webapp ee8-annotations [lib] -lib/maven-ee8/**.jar +lib/ee8-maven/**.jar [xml] etc/jetty-ee8-maven.xml diff --git a/jetty-ee8/jetty-ee8-maven-plugin/src/main/resources/jetty-ee8-maven.xml b/jetty-ee8/jetty-ee8-maven-plugin/src/main/resources/jetty-ee8-maven.xml index eb334cbc683a..b83be87a6474 100644 --- a/jetty-ee8/jetty-ee8-maven-plugin/src/main/resources/jetty-ee8-maven.xml +++ b/jetty-ee8/jetty-ee8-maven-plugin/src/main/resources/jetty-ee8-maven.xml @@ -4,7 +4,7 @@ - + diff --git a/jetty-ee9/jetty-ee9-maven-plugin/pom.xml b/jetty-ee9/jetty-ee9-maven-plugin/pom.xml index 25932a6e5386..c7f54003b097 100644 --- a/jetty-ee9/jetty-ee9-maven-plugin/pom.xml +++ b/jetty-ee9/jetty-ee9-maven-plugin/pom.xml @@ -81,6 +81,11 @@ jetty-jndi true + + org.eclipse.jetty + jetty-maven + true + org.eclipse.jetty jetty-server diff --git a/jetty-ee9/jetty-ee9-maven-plugin/src/it/jetty-cdi-start-forked/src/main/jetty/jetty.xml b/jetty-ee9/jetty-ee9-maven-plugin/src/it/jetty-cdi-start-forked/src/main/jetty/jetty.xml index 1bb69f935a70..8a8f26b49f4f 100644 --- a/jetty-ee9/jetty-ee9-maven-plugin/src/it/jetty-cdi-start-forked/src/main/jetty/jetty.xml +++ b/jetty-ee9/jetty-ee9-maven-plugin/src/it/jetty-cdi-start-forked/src/main/jetty/jetty.xml @@ -26,7 +26,7 @@ - + diff --git a/jetty-ee9/jetty-ee9-maven-plugin/src/it/jetty-combinedresource-it/src/config/jetty.xml b/jetty-ee9/jetty-ee9-maven-plugin/src/it/jetty-combinedresource-it/src/config/jetty.xml index b2e4ff6a33ef..343f5e7f99b1 100644 --- a/jetty-ee9/jetty-ee9-maven-plugin/src/it/jetty-combinedresource-it/src/config/jetty.xml +++ b/jetty-ee9/jetty-ee9-maven-plugin/src/it/jetty-combinedresource-it/src/config/jetty.xml @@ -26,7 +26,7 @@ - + diff --git a/jetty-ee9/jetty-ee9-maven-plugin/src/it/jetty-effective-web-xml-it/webapp-war/src/config/jetty.xml b/jetty-ee9/jetty-ee9-maven-plugin/src/it/jetty-effective-web-xml-it/webapp-war/src/config/jetty.xml index 4e43b5305dfb..343f5e7f99b1 100644 --- a/jetty-ee9/jetty-ee9-maven-plugin/src/it/jetty-effective-web-xml-it/webapp-war/src/config/jetty.xml +++ b/jetty-ee9/jetty-ee9-maven-plugin/src/it/jetty-effective-web-xml-it/webapp-war/src/config/jetty.xml @@ -26,7 +26,7 @@ - + diff --git a/jetty-ee9/jetty-ee9-maven-plugin/src/it/jetty-maven-plugin-provided-module-dep/web/src/config/jetty.xml b/jetty-ee9/jetty-ee9-maven-plugin/src/it/jetty-maven-plugin-provided-module-dep/web/src/config/jetty.xml index 3ab59a4b5cb6..ef0c9bcad939 100644 --- a/jetty-ee9/jetty-ee9-maven-plugin/src/it/jetty-maven-plugin-provided-module-dep/web/src/config/jetty.xml +++ b/jetty-ee9/jetty-ee9-maven-plugin/src/it/jetty-maven-plugin-provided-module-dep/web/src/config/jetty.xml @@ -32,7 +32,7 @@ - + diff --git a/jetty-ee9/jetty-ee9-maven-plugin/src/it/jetty-run-mojo-jar-scan-it/MyWebApp/src/config/jetty.xml b/jetty-ee9/jetty-ee9-maven-plugin/src/it/jetty-run-mojo-jar-scan-it/MyWebApp/src/config/jetty.xml index 72655392a8bd..58c5b2751216 100644 --- a/jetty-ee9/jetty-ee9-maven-plugin/src/it/jetty-run-mojo-jar-scan-it/MyWebApp/src/config/jetty.xml +++ b/jetty-ee9/jetty-ee9-maven-plugin/src/it/jetty-run-mojo-jar-scan-it/MyWebApp/src/config/jetty.xml @@ -25,7 +25,7 @@ - + diff --git a/jetty-ee9/jetty-ee9-maven-plugin/src/it/jetty-start-distro-mojo-it/jetty-simple-webapp/src/base/etc/test-jetty-ee9.xml b/jetty-ee9/jetty-ee9-maven-plugin/src/it/jetty-start-distro-mojo-it/jetty-simple-webapp/src/base/etc/test-jetty-ee9.xml index 07a874e46f09..9857cb546ef7 100644 --- a/jetty-ee9/jetty-ee9-maven-plugin/src/it/jetty-start-distro-mojo-it/jetty-simple-webapp/src/base/etc/test-jetty-ee9.xml +++ b/jetty-ee9/jetty-ee9-maven-plugin/src/it/jetty-start-distro-mojo-it/jetty-simple-webapp/src/base/etc/test-jetty-ee9.xml @@ -5,7 +5,7 @@ - + diff --git a/jetty-ee9/jetty-ee9-maven-plugin/src/it/jetty-start-forked-mojo-it/jetty-simple-webapp/src/config/jetty.xml b/jetty-ee9/jetty-ee9-maven-plugin/src/it/jetty-start-forked-mojo-it/jetty-simple-webapp/src/config/jetty.xml index b2e4ff6a33ef..343f5e7f99b1 100644 --- a/jetty-ee9/jetty-ee9-maven-plugin/src/it/jetty-start-forked-mojo-it/jetty-simple-webapp/src/config/jetty.xml +++ b/jetty-ee9/jetty-ee9-maven-plugin/src/it/jetty-start-forked-mojo-it/jetty-simple-webapp/src/config/jetty.xml @@ -26,7 +26,7 @@ - + diff --git a/jetty-ee9/jetty-ee9-maven-plugin/src/it/jetty-start-gwt-it/beer-server/src/config/jetty.xml b/jetty-ee9/jetty-ee9-maven-plugin/src/it/jetty-start-gwt-it/beer-server/src/config/jetty.xml index b2e4ff6a33ef..343f5e7f99b1 100644 --- a/jetty-ee9/jetty-ee9-maven-plugin/src/it/jetty-start-gwt-it/beer-server/src/config/jetty.xml +++ b/jetty-ee9/jetty-ee9-maven-plugin/src/it/jetty-start-gwt-it/beer-server/src/config/jetty.xml @@ -26,7 +26,7 @@ - + diff --git a/jetty-ee9/jetty-ee9-maven-plugin/src/it/jetty-start-mojo-it/jetty-simple-webapp/pom.xml b/jetty-ee9/jetty-ee9-maven-plugin/src/it/jetty-start-mojo-it/jetty-simple-webapp/pom.xml index aadb236bb245..e5779619b9df 100644 --- a/jetty-ee9/jetty-ee9-maven-plugin/src/it/jetty-start-mojo-it/jetty-simple-webapp/pom.xml +++ b/jetty-ee9/jetty-ee9-maven-plugin/src/it/jetty-start-mojo-it/jetty-simple-webapp/pom.xml @@ -112,7 +112,7 @@ - + ${basedir}/src/config/login.xml diff --git a/jetty-ee9/jetty-ee9-maven-plugin/src/it/jetty-start-mojo-it/jetty-simple-webapp/src/config/jetty.xml b/jetty-ee9/jetty-ee9-maven-plugin/src/it/jetty-start-mojo-it/jetty-simple-webapp/src/config/jetty.xml index b2e4ff6a33ef..343f5e7f99b1 100644 --- a/jetty-ee9/jetty-ee9-maven-plugin/src/it/jetty-start-mojo-it/jetty-simple-webapp/src/config/jetty.xml +++ b/jetty-ee9/jetty-ee9-maven-plugin/src/it/jetty-start-mojo-it/jetty-simple-webapp/src/config/jetty.xml @@ -26,7 +26,7 @@ - + diff --git a/jetty-ee9/jetty-ee9-maven-plugin/src/it/jetty-start-mojo-multi-module-single-war-it/webapp-war/src/config/jetty.xml b/jetty-ee9/jetty-ee9-maven-plugin/src/it/jetty-start-mojo-multi-module-single-war-it/webapp-war/src/config/jetty.xml index b2e4ff6a33ef..343f5e7f99b1 100644 --- a/jetty-ee9/jetty-ee9-maven-plugin/src/it/jetty-start-mojo-multi-module-single-war-it/webapp-war/src/config/jetty.xml +++ b/jetty-ee9/jetty-ee9-maven-plugin/src/it/jetty-start-mojo-multi-module-single-war-it/webapp-war/src/config/jetty.xml @@ -26,7 +26,7 @@ - + diff --git a/jetty-ee9/jetty-ee9-maven-plugin/src/it/jetty-start-overlay-it/jetty-simple-webapp/src/config/jetty.xml b/jetty-ee9/jetty-ee9-maven-plugin/src/it/jetty-start-overlay-it/jetty-simple-webapp/src/config/jetty.xml index b2e4ff6a33ef..343f5e7f99b1 100644 --- a/jetty-ee9/jetty-ee9-maven-plugin/src/it/jetty-start-overlay-it/jetty-simple-webapp/src/config/jetty.xml +++ b/jetty-ee9/jetty-ee9-maven-plugin/src/it/jetty-start-overlay-it/jetty-simple-webapp/src/config/jetty.xml @@ -26,7 +26,7 @@ - + diff --git a/jetty-ee9/jetty-ee9-maven-plugin/src/it/jetty-start-war-distro-mojo-it/jetty-simple-webapp/src/base/etc/test-jetty-ee9.xml b/jetty-ee9/jetty-ee9-maven-plugin/src/it/jetty-start-war-distro-mojo-it/jetty-simple-webapp/src/base/etc/test-jetty-ee9.xml index 07a874e46f09..9857cb546ef7 100644 --- a/jetty-ee9/jetty-ee9-maven-plugin/src/it/jetty-start-war-distro-mojo-it/jetty-simple-webapp/src/base/etc/test-jetty-ee9.xml +++ b/jetty-ee9/jetty-ee9-maven-plugin/src/it/jetty-start-war-distro-mojo-it/jetty-simple-webapp/src/base/etc/test-jetty-ee9.xml @@ -5,7 +5,7 @@ - + diff --git a/jetty-ee9/jetty-ee9-maven-plugin/src/it/jetty-start-war-forked-mojo-it/jetty-simple-webapp/src/config/jetty.xml b/jetty-ee9/jetty-ee9-maven-plugin/src/it/jetty-start-war-forked-mojo-it/jetty-simple-webapp/src/config/jetty.xml index b2e4ff6a33ef..343f5e7f99b1 100644 --- a/jetty-ee9/jetty-ee9-maven-plugin/src/it/jetty-start-war-forked-mojo-it/jetty-simple-webapp/src/config/jetty.xml +++ b/jetty-ee9/jetty-ee9-maven-plugin/src/it/jetty-start-war-forked-mojo-it/jetty-simple-webapp/src/config/jetty.xml @@ -26,7 +26,7 @@ - + diff --git a/jetty-ee9/jetty-ee9-maven-plugin/src/it/jetty-start-war-mojo-it/src/config/jetty.xml b/jetty-ee9/jetty-ee9-maven-plugin/src/it/jetty-start-war-mojo-it/src/config/jetty.xml index b2e4ff6a33ef..343f5e7f99b1 100644 --- a/jetty-ee9/jetty-ee9-maven-plugin/src/it/jetty-start-war-mojo-it/src/config/jetty.xml +++ b/jetty-ee9/jetty-ee9-maven-plugin/src/it/jetty-start-war-mojo-it/src/config/jetty.xml @@ -26,7 +26,7 @@ - + diff --git a/jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/AbstractUnassembledWebAppMojo.java b/jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/AbstractUnassembledWebAppMojo.java index 5185f62397e7..0b23a5a92656 100644 --- a/jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/AbstractUnassembledWebAppMojo.java +++ b/jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/AbstractUnassembledWebAppMojo.java @@ -23,6 +23,9 @@ import org.apache.maven.artifact.Artifact; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugins.annotations.Parameter; +import org.eclipse.jetty.maven.MavenProjectHelper; +import org.eclipse.jetty.maven.Overlay; +import org.eclipse.jetty.maven.ScanPattern; import org.eclipse.jetty.util.resource.Resource; import org.eclipse.jetty.util.resource.ResourceFactory; import org.eclipse.jetty.util.resource.Resources; @@ -198,7 +201,7 @@ protected void configureUnassembledWebApp() throws Exception //process any overlays and the war type artifacts, and //sets up the base resource collection for the webapp - mavenProjectHelper.getOverlayManager().applyOverlays(webApp); + mavenProjectHelper.getOverlayManager().applyOverlays(webApp.getCoreContextHandler(), webApp.getBaseAppFirst()); getLog().info("web.xml file = " + webApp.getDescriptor()); getLog().info("Webapp directory = " + webAppSourceDirectory.getCanonicalPath()); diff --git a/jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/AbstractWebAppMojo.java b/jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/AbstractWebAppMojo.java index bd5ba9fc62d1..eac0c0ce8f7d 100644 --- a/jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/AbstractWebAppMojo.java +++ b/jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/AbstractWebAppMojo.java @@ -47,7 +47,10 @@ import org.apache.maven.project.MavenProject; import org.codehaus.plexus.util.StringUtils; import org.eclipse.aether.RepositorySystem; -import org.eclipse.jetty.ee9.maven.plugin.utils.MavenProjectHelper; +import org.eclipse.jetty.maven.MavenProjectHelper; +import org.eclipse.jetty.maven.MavenServerConnector; +import org.eclipse.jetty.maven.PluginLog; +import org.eclipse.jetty.maven.ScanTargetPattern; import org.eclipse.jetty.security.LoginService; import org.eclipse.jetty.server.RequestLog; import org.eclipse.jetty.server.Server; @@ -562,7 +565,7 @@ protected JettyHomeForker newJettyHomeForker() if (jettyHome == null) jetty.setJettyHomeZip(jettyHomeZip != null ? jettyHomeZip : mavenProjectHelper.resolveArtifact(JETTY_HOME_GROUPID, JETTY_HOME_ARTIFACTID, plugin.getVersion(), "zip")); - jetty.version = plugin.getVersion(); + jetty.setVersion(plugin.getVersion()); jetty.setJettyHome(jettyHome); jetty.setJettyBase(jettyBase); jetty.setBaseDir(target); diff --git a/jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/JettyEmbedder.java b/jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/JettyEmbedder.java index c21aad90725e..5239ec1bb64f 100644 --- a/jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/JettyEmbedder.java +++ b/jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/JettyEmbedder.java @@ -24,6 +24,10 @@ import org.eclipse.jetty.ee9.quickstart.QuickStartConfiguration; import org.eclipse.jetty.ee9.quickstart.QuickStartConfiguration.Mode; import org.eclipse.jetty.ee9.servlet.ServletHandler; +import org.eclipse.jetty.ee9.webapp.Configurations; +import org.eclipse.jetty.maven.AbstractJettyEmbedder; +import org.eclipse.jetty.maven.MavenServerConnector; +import org.eclipse.jetty.maven.ServerSupport; import org.eclipse.jetty.security.LoginService; import org.eclipse.jetty.server.RequestLog; import org.eclipse.jetty.server.Server; @@ -32,201 +36,21 @@ import org.eclipse.jetty.util.component.ContainerLifeCycle; /** - * JettyEmbedded - * + * JettyEmbedder * Starts jetty within the current process. */ -public class JettyEmbedder extends ContainerLifeCycle +public class JettyEmbedder extends AbstractJettyEmbedder { - protected List contextHandlers; - protected List loginServices; - protected RequestLog requestLog; - protected MavenServerConnector httpConnector; - protected Server server; - protected MavenWebAppContext webApp; - protected boolean exitVm; - protected boolean stopAtShutdown; - protected List jettyXmlFiles; - protected Map jettyProperties; - protected ShutdownMonitor shutdownMonitor; - protected int stopPort; - protected String stopKey; - private String contextXml; - private Properties webAppProperties; + private MavenWebAppContext webApp; - public List getContextHandlers() - { - return contextHandlers; - } - - public void setContextHandlers(List contextHandlers) - { - if (contextHandlers == null) - this.contextHandlers = null; - else - this.contextHandlers = new ArrayList<>(contextHandlers); - } - - public List getLoginServices() - { - return loginServices; - } - - public void setLoginServices(List loginServices) - { - if (loginServices == null) - this.loginServices = null; - else - this.loginServices = new ArrayList<>(loginServices); - } - - public RequestLog getRequestLog() - { - return requestLog; - } - - public void setRequestLog(RequestLog requestLog) - { - this.requestLog = requestLog; - } - - public MavenServerConnector getHttpConnector() - { - return httpConnector; - } - - public void setHttpConnector(MavenServerConnector httpConnector) - { - this.httpConnector = httpConnector; - } - - public Server getServer() - { - return server; - } - - public void setServer(Server server) - { - this.server = server; - } - - public MavenWebAppContext getWebApp() - { - return webApp; - } - - public boolean isExitVm() - { - return exitVm; - } - - public void setExitVm(boolean exitVm) - { - this.exitVm = exitVm; - } - - public boolean isStopAtShutdown() - { - return stopAtShutdown; - } - - public void setStopAtShutdown(boolean stopAtShutdown) - { - this.stopAtShutdown = stopAtShutdown; - } - - public List getJettyXmlFiles() - { - return jettyXmlFiles; - } - - public void setJettyXmlFiles(List jettyXmlFiles) - { - this.jettyXmlFiles = jettyXmlFiles; - } - - public Map getJettyProperties() - { - return jettyProperties; - } - - public void setJettyProperties(Map jettyProperties) - { - this.jettyProperties = jettyProperties; - } - - public ShutdownMonitor getShutdownMonitor() - { - return shutdownMonitor; - } - - public void setShutdownMonitor(ShutdownMonitor shutdownMonitor) - { - this.shutdownMonitor = shutdownMonitor; - } - - 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 void setWebApp(MavenWebAppContext app) throws Exception + public void setWebApp(MavenWebAppContext app) { webApp = app; } - - public void setWebAppProperties(Properties props) - { - if (webAppProperties != null) - webAppProperties.clear(); - - if (props != null) - { - if (webAppProperties == null) - webAppProperties = new Properties(); - - webAppProperties.putAll(props); - } - } - - public String getContextXml() - { - return contextXml; - } - public void setContextXml(String contextXml) + public void redeployWebApp() throws Exception { - this.contextXml = contextXml; - } - - public void doStart() throws Exception - { - super.doStart(); - - configure(); - configureShutdownMonitor(); - server.start(); - } - - protected void redeployWebApp() throws Exception - { - if (!webApp.isStopped()) - webApp.stop(); + stopWebApp(); //clear the ServletHandler, which may have //remembered "durable" Servlets, Filters, Listeners @@ -239,40 +63,22 @@ protected void redeployWebApp() throws Exception webApp.start(); } - - protected void join() throws InterruptedException + + @Override + public void stopWebApp() throws Exception { - server.join(); + if (webApp != null && !webApp.isStopped()) + webApp.stop(); } /** - * Configure the server and the webapp + * Configure the webapp * @throws Exception if there is an unspecified problem */ - private void configure() throws Exception + public void configureWebApp() throws Exception { - //apply any configs from jetty.xml files first - Server tmp = ServerSupport.applyXmlConfigurations(new Server(), jettyXmlFiles, jettyProperties); - - if (tmp != null) - server = tmp; - - server.setStopAtShutdown(stopAtShutdown); - - //ensure there's a connector - if (httpConnector != null) - httpConnector.setServer(server); - - ServerSupport.configureConnectors(server, httpConnector, jettyProperties); - - //set up handler structure - ServerSupport.configureHandlers(server, contextHandlers, requestLog); - //Set up list of default Configurations to apply to a webapp - ServerSupport.configureDefaultConfigurationClasses(server); - - // set up security realms - ServerSupport.configureLoginServices(server, loginServices); + Configurations.setServerDefault(server); /* Configure the webapp */ if (webApp == null) @@ -291,32 +97,17 @@ private void configure() throws Exception webApp.setAttribute(QuickStartConfiguration.MODE, Mode.QUICKSTART); } } - - //add the webapp to the server - ServerSupport.addWebApplication(server, webApp); } - private void applyWebAppProperties() throws Exception + public void applyWebAppProperties() throws Exception { - //apply properties to the webapp if there are any - if (contextXml != null) - { - if (webAppProperties == null) - webAppProperties = new Properties(); - - webAppProperties.put("context.xml", contextXml); - } + super.applyWebAppProperties(); WebAppPropertyConverter.fromProperties(webApp, webAppProperties, server, jettyProperties); } - - private void configureShutdownMonitor() + + public void addWebAppToServer() throws Exception { - if (stopPort > 0 && stopKey != null) - { - ShutdownMonitor monitor = ShutdownMonitor.getInstance(); - monitor.setPort(stopPort); - monitor.setKey(stopKey); - monitor.setExitVm(exitVm); - } + //add the webapp to the server + ServerSupport.addWebApplication(server, webApp.getCoreContextHandler()); } } diff --git a/jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/JettyForkedChild.java b/jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/JettyForkedChild.java index ca454c304ca4..ad6a54d83dc5 100644 --- a/jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/JettyForkedChild.java +++ b/jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/JettyForkedChild.java @@ -13,23 +13,8 @@ package org.eclipse.jetty.ee9.maven.plugin; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.Properties; -import java.util.Set; - -import org.eclipse.jetty.util.Scanner; -import org.eclipse.jetty.util.StringUtil; -import org.eclipse.jetty.util.component.ContainerLifeCycle; +import org.eclipse.jetty.maven.AbstractForkedChild; +import org.eclipse.jetty.maven.AbstractJettyEmbedder; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -39,15 +24,9 @@ * This is the class that is executed when the jetty maven plugin * forks a process when DeploymentMode=FORKED. */ -public class JettyForkedChild extends ContainerLifeCycle +public class JettyForkedChild extends AbstractForkedChild { private static final Logger LOG = LoggerFactory.getLogger(JettyForkedChild.class); - - protected JettyEmbedder jetty; - protected File tokenFile; // TODO: convert to Path - protected Scanner scanner; - protected File webAppPropsFile; // TODO: convert to Path - protected int scanInterval; /** * @param args arguments that were passed to main @@ -56,158 +35,13 @@ public class JettyForkedChild extends ContainerLifeCycle public JettyForkedChild(String[] args) throws Exception { - jetty = new JettyEmbedder(); - configure(args); - } - - /** - * Based on the args passed to the program, configure jetty. - * - * @param args args that were passed to the program. - * @throws Exception if unable to load webprops - */ - public void configure(String[] args) - throws Exception - { - Map jettyProperties = new HashMap<>(); - - for (int i = 0; i < args.length; i++) - { - //--stop-port - if ("--stop-port".equals(args[i])) - { - jetty.setStopPort(Integer.parseInt(args[++i])); - continue; - } - - //--stop-key - if ("--stop-key".equals(args[i])) - { - jetty.setStopKey(args[++i]); - continue; - } - - //--jettyXml - if ("--jetty-xml".equals(args[i])) - { - List jettyXmls = new ArrayList<>(); - String[] names = StringUtil.csvSplit(args[++i]); - for (int j = 0; names != null && j < names.length; j++) - { - jettyXmls.add(new File(names[j].trim())); - } - jetty.setJettyXmlFiles(jettyXmls); - continue; - } - //--webprops - if ("--webprops".equals(args[i])) - { - webAppPropsFile = new File(args[++i].trim()); - jetty.setWebAppProperties(loadWebAppProps()); - continue; - } - - //--token - if ("--token".equals(args[i])) - { - tokenFile = new File(args[++i].trim()); - continue; - } - - if ("--scanInterval".equals(args[i])) - { - scanInterval = Integer.parseInt(args[++i].trim()); - scanner = new Scanner(); - scanner.setReportExistingFilesOnStartup(false); - scanner.setScanInterval(scanInterval); - scanner.addListener(new Scanner.BulkListener() - { - public void filesChanged(Set changes) - { - if (!Objects.isNull(scanner)) - { - try - { - scanner.stop(); - if (!Objects.isNull(jetty.getWebApp())) - { - //stop the webapp - jetty.getWebApp().stop(); - //reload the props - jetty.setWebAppProperties(loadWebAppProps()); - jetty.setWebApp(jetty.getWebApp()); - //restart the webapp - jetty.redeployWebApp(); - - //restart the scanner - scanner.start(); - } - } - catch (Exception e) - { - LOG.error("Error reconfiguring/restarting webapp after change in watched files", e); - } - } - } - }); - - if (!Objects.isNull(webAppPropsFile)) - scanner.addFile(webAppPropsFile.toPath()); - continue; - } - - //assume everything else is a jetty property to be passed in - String[] tmp = args[i].trim().split("="); - if (tmp.length == 2) - { - jettyProperties.put(tmp[0], tmp[1]); - } - } - - jetty.setJettyProperties(jettyProperties); - jetty.setExitVm(true); - } - - /** - * Load properties from a file describing the webapp if one is - * present. - * - * @return file contents as properties - * @throws FileNotFoundException if there is a file not found problem - * @throws IOException if there is an IO problem - */ - private Properties loadWebAppProps() throws FileNotFoundException, IOException - { - Properties props = new Properties(); - if (Objects.nonNull(webAppPropsFile)) - props.load(new FileInputStream(webAppPropsFile)); - return props; + super(args); } - /** - * Start a jetty instance and webapp. This thread will - * wait until jetty exits. - */ - public void doStart() - throws Exception + @Override + protected AbstractJettyEmbedder newJettyEmbedder() { - super.doStart(); - - //Start the embedded jetty instance - jetty.start(); - - //touch file to signify start of jetty - Path tokenPath = tokenFile.toPath(); - Files.createFile(tokenPath); - - //Start a watcher on a file that will change if the - //webapp is regenerated; stop the webapp, apply the - //properties and restart it. - if (scanner != null) - scanner.start(); - - //wait for jetty to finish - jetty.join(); + return new JettyEmbedder(); } public static void main(String[] args) diff --git a/jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/JettyForker.java b/jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/JettyForker.java index 4231274bfb35..8c742ec1eb8e 100644 --- a/jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/JettyForker.java +++ b/jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/JettyForker.java @@ -18,108 +18,34 @@ import java.util.List; import java.util.Map; +import org.eclipse.jetty.maven.AbstractForker; +import org.eclipse.jetty.maven.AbstractServerForker; +import org.eclipse.jetty.maven.PluginLog; import org.eclipse.jetty.server.Server; +import org.eclipse.jetty.util.Jetty; /** * JettyForker * * Uses quickstart to generate a webapp and forks a process to run it. */ -public class JettyForker extends AbstractForker +public class JettyForker extends AbstractServerForker { - protected File forkWebXml; - protected Server server; protected MavenWebAppContext webApp; - protected String containerClassPath; - protected File webAppPropsFile; - protected String contextXml; - protected int scanInterval; QuickStartGenerator generator; - /** - * @return the scan - */ - public boolean isScan() + public JettyForker() { - return scanInterval > 0; + executionClassName = JettyForkedChild.class.getCanonicalName(); } - /** - * Set if true, the forked child will scan for changes at 1 second intervals. - * @param scan if true, the forked child will scan for changes at 1 second intervals - */ - public void setScan(boolean scan) + public void setWebApp(MavenWebAppContext webApp) { - setScanInterval(scan ? 1 : 0); - } - - public int getScanInterval() - { - return scanInterval; - } - - public void setScanInterval(int sec) - { - scanInterval = sec; - } - - public File getWebAppPropsFile() - { - return webAppPropsFile; - } - - public void setWebAppPropsFile(File webAppPropsFile) - { - this.webAppPropsFile = webAppPropsFile; - } - - public File getForkWebXml() - { - return forkWebXml; - } - - public void setForkWebXml(File forkWebXml) - { - this.forkWebXml = forkWebXml; - } - - public String getContextXml() - { - return contextXml; - } - - public void setContextXml(String contextXml) - { - this.contextXml = contextXml; - } - - public String getContainerClassPath() - { - return containerClassPath; - } - - public void setContainerClassPath(String containerClassPath) - { - this.containerClassPath = containerClassPath; - } - - public void setWebApp(MavenWebAppContext app) - { - webApp = app; - } - - public Server getServer() - { - return server; - } - - public void setServer(Server server) - { - this.server = server; + this.webApp = webApp; } @Override - public void doStart() + public void generateWebApp() throws Exception { //Run the webapp to create the quickstart file and properties file @@ -128,8 +54,6 @@ public void doStart() generator.setWebAppPropsFile(webAppPropsFile.toPath()); generator.setServer(server); generator.generate(); - - super.doStart(); } protected void redeployWebApp() @@ -139,154 +63,4 @@ protected void redeployWebApp() //which will redeploy the webapp generator.generate(); } - - public ProcessBuilder createCommand() - { - List cmd = new ArrayList(); - cmd.add(getJavaBin()); - - if (jvmArgs != null) - { - String[] args = jvmArgs.split(" "); - for (int i = 0; args != null && i < args.length; i++) - { - if (args[i] != null && !"".equals(args[i])) - cmd.add(args[i].trim()); - } - } - - if (systemProperties != null) - { - for (Map.Entry e:systemProperties.entrySet()) - { - cmd.add("-D" + e.getKey() + "=" + e.getValue()); - } - } - - if (containerClassPath != null && containerClassPath.length() > 0) - { - cmd.add("-cp"); - cmd.add(containerClassPath); - } - - cmd.add(JettyForkedChild.class.getCanonicalName()); - - if (stopPort > 0 && stopKey != null) - { - cmd.add("--stop-port"); - cmd.add(Integer.toString(stopPort)); - cmd.add("--stop-key"); - cmd.add(stopKey); - } - if (jettyXmlFiles != null) - { - cmd.add("--jetty-xml"); - StringBuilder tmp = new StringBuilder(); - for (File jettyXml:jettyXmlFiles) - { - if (tmp.length() != 0) - tmp.append(","); - tmp.append(jettyXml.getAbsolutePath()); - } - cmd.add(tmp.toString()); - } - - cmd.add("--webprops"); - cmd.add(webAppPropsFile.getAbsolutePath()); - - cmd.add("--token"); - cmd.add(tokenFile.getAbsolutePath()); - - if (scanInterval > 0) - { - cmd.add("--scanInterval"); - cmd.add(Integer.toString(scanInterval)); - } - - if (jettyProperties != null) - { - for (Map.Entry e:jettyProperties.entrySet()) - { - cmd.add(e.getKey() + "=" + e.getValue()); - } - } - - ProcessBuilder command = new ProcessBuilder(cmd); - command.directory(workDir); - - if (PluginLog.getLog().isDebugEnabled()) - PluginLog.getLog().debug("Forked cli:" + command.command()); - - PluginLog.getLog().info("Forked process starting"); - - //set up extra environment vars if there are any - if (env != null && !env.isEmpty()) - command.environment().putAll(env); - - if (waitForChild) - { - command.inheritIO(); - } - else - { - command.redirectOutput(jettyOutputFile); - command.redirectErrorStream(true); - } - return command; - } - - /** - * Get the location of the java binary. - * @return the location of the java binary - */ - private String getJavaBin() - { - String[] javaexes = new String[]{"java", "java.exe"}; - - File javaHomeDir = new File(System.getProperty("java.home")); - for (String javaexe : javaexes) - { - File javabin = new File(javaHomeDir, fileSeparators("bin/" + javaexe)); - if (javabin.exists() && javabin.isFile()) - { - return javabin.getAbsolutePath(); - } - } - - return "java"; - } - - public static String fileSeparators(String path) - { - StringBuilder ret = new StringBuilder(); - for (char c : path.toCharArray()) - { - if ((c == '/') || (c == '\\')) - { - ret.append(File.separatorChar); - } - else - { - ret.append(c); - } - } - return ret.toString(); - } - - public static String pathSeparators(String path) - { - StringBuilder ret = new StringBuilder(); - for (char c : path.toCharArray()) - { - if ((c == ',') || (c == ':')) - { - ret.append(File.pathSeparatorChar); - } - else - { - ret.append(c); - } - } - return ret.toString(); - } } diff --git a/jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/JettyHomeForker.java b/jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/JettyHomeForker.java index c92f7be42922..d97acace38d8 100644 --- a/jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/JettyHomeForker.java +++ b/jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/JettyHomeForker.java @@ -13,153 +13,21 @@ package org.eclipse.jetty.ee9.maven.plugin; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.net.URI; -import java.nio.file.FileAlreadyExistsException; -import java.nio.file.FileSystems; -import java.nio.file.FileVisitOption; -import java.nio.file.FileVisitResult; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.SimpleFileVisitor; -import java.nio.file.attribute.BasicFileAttributes; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.EnumSet; -import java.util.List; -import java.util.Map; - -import org.eclipse.jetty.util.IO; -import org.eclipse.jetty.util.StringUtil; -import org.eclipse.jetty.util.TypeUtil; -import org.eclipse.jetty.util.resource.Resource; -import org.eclipse.jetty.util.resource.ResourceFactory; +import org.eclipse.jetty.maven.AbstractHomeForker; /** - * JettyHomeBaseForker + * JettyHomeForker * * Unpacks a jetty-home and configures it with a base that allows it * to run an unassembled webapp. */ -public class JettyHomeForker extends AbstractForker +public class JettyHomeForker extends AbstractHomeForker { protected MavenWebAppContext webApp; - protected String contextXml; - - /** - * Location of existing jetty home directory - */ - protected File jettyHome; - - /** - * Zip of jetty-home - */ - protected File jettyHomeZip; - - /** - * Location of existing jetty base directory - */ - protected File jettyBase; - - protected File baseDir; - - /** - * Optional list of other modules to - * activate. - */ - protected String[] modules; - - /* - * Optional jetty commands - */ - protected String jettyOptions; - - protected List libExtJarFiles; - protected Path modulesPath; - protected Path etcPath; - protected Path libPath; - protected Path webappPath; - protected Path mavenLibPath; - protected String version; - - public void setJettyOptions(String jettyOptions) - { - this.jettyOptions = jettyOptions; - } - - public String getJettyOptions() - { - return jettyOptions; - } - - public List getLibExtJarFiles() - { - return libExtJarFiles; - } - - public void setLibExtJarFiles(List libExtJarFiles) - { - this.libExtJarFiles = libExtJarFiles; - } - - public File getJettyHome() - { - return jettyHome; - } - - public void setJettyHome(File jettyHome) - { - this.jettyHome = jettyHome; - } - - public File getJettyBase() - { - return jettyBase; - } - - public void setJettyBase(File jettyBase) - { - this.jettyBase = jettyBase; - } - - public String[] getModules() - { - return modules; - } - - public void setModules(String[] modules) - { - this.modules = modules; - } - - public String getContextXmlFile() + public JettyHomeForker() { - return contextXml; - } - - public void setContextXml(String contextXml) - { - this.contextXml = contextXml; - } - - public File getJettyHomeZip() - { - return jettyHomeZip; - } - - public void setJettyHomeZip(File jettyHomeZip) - { - this.jettyHomeZip = jettyHomeZip; - } - - public MavenWebAppContext getWebApp() - { - return webApp; + environment = "ee9"; } public void setWebApp(MavenWebAppContext webApp) @@ -167,116 +35,6 @@ public void setWebApp(MavenWebAppContext webApp) this.webApp = webApp; } - public File getBaseDir() - { - return baseDir; - } - - public void setBaseDir(File baseDir) - { - this.baseDir = baseDir; - } - - @Override - protected ProcessBuilder createCommand() - { - List cmd = new ArrayList<>(); - cmd.add("java"); - - //add any args to the jvm - if (StringUtil.isNotBlank(jvmArgs)) - { - Arrays.stream(jvmArgs.split(" ")).filter(a -> StringUtil.isNotBlank(a)).forEach((a) -> cmd.add(a.trim())); - } - - cmd.add("-jar"); - cmd.add(new File(jettyHome, "start.jar").getAbsolutePath()); - - if (systemProperties != null) - { - for (Map.Entry e : systemProperties.entrySet()) - { - cmd.add("-D" + e.getKey() + "=" + e.getValue()); - } - } - - cmd.add("-DSTOP.PORT=" + stopPort); - if (stopKey != null) - cmd.add("-DSTOP.KEY=" + stopKey); - - //set up enabled jetty modules - StringBuilder tmp = new StringBuilder(); - tmp.append("--module="); - tmp.append("server,http,ee9-webapp,ee9-deploy"); - if (modules != null) - { - for (String m : modules) - { - if (tmp.indexOf(m) < 0) - tmp.append("," + m); - } - } - - if (libExtJarFiles != null && !libExtJarFiles.isEmpty() && tmp.indexOf("ext") < 0) - tmp.append(",ext"); - tmp.append(",ee9-maven"); - cmd.add(tmp.toString()); - - //put any other jetty options onto the command line - if (StringUtil.isNotBlank(jettyOptions)) - { - Arrays.stream(jettyOptions.split(" ")).filter(a -> StringUtil.isNotBlank(a)).forEach((a) -> cmd.add(a.trim())); - } - - //put any jetty properties onto the command line - if (jettyProperties != null) - { - for (Map.Entry e : jettyProperties.entrySet()) - { - cmd.add(e.getKey() + "=" + e.getValue()); - } - } - - //existence of this file signals process started - cmd.add("jetty.token.file=" + tokenFile.getAbsolutePath().toString()); - - ProcessBuilder builder = new ProcessBuilder(cmd); - builder.directory(workDir); - - PluginLog.getLog().info("Home process starting"); - - //set up extra environment vars if there are any - if (!env.isEmpty()) - builder.environment().putAll(env); - - if (waitForChild) - builder.inheritIO(); - else - { - builder.redirectOutput(jettyOutputFile); - builder.redirectErrorStream(true); - } - return builder; - } - - @Override - public void doStart() throws Exception - { - //set up a jetty-home - configureJettyHome(); - - if (jettyHome == null || !jettyHome.exists()) - throw new IllegalStateException("No jetty home"); - - //set up a jetty-base - configureJettyBase(); - - //convert the webapp to properties - generateWebAppPropertiesFile(); - - super.doStart(); - } - protected void redeployWebApp() throws Exception { @@ -284,142 +42,9 @@ protected void redeployWebApp() webappPath.resolve("maven.xml").toFile().setLastModified(System.currentTimeMillis()); } - private void generateWebAppPropertiesFile() + protected void generateWebAppPropertiesFile() throws Exception { WebAppPropertyConverter.toProperties(webApp, etcPath.resolve("maven.props").toFile(), contextXml); } - - /** - * Create or configure a jetty base. - */ - private void configureJettyBase() throws Exception - { - if (jettyBase != null && !jettyBase.exists()) - throw new IllegalStateException(jettyBase.getAbsolutePath() + " does not exist"); - - File targetJettyBase = new File(baseDir, "jetty-base"); - Path targetBasePath = targetJettyBase.toPath(); - if (Files.exists(targetBasePath)) - IO.delete(targetJettyBase); - - targetJettyBase.mkdirs(); - - //jetty-base will be the working directory for the forked command - workDir = targetJettyBase; - - //if there is an existing jetty base, copy parts of it - if (jettyBase != null) - { - Path jettyBasePath = jettyBase.toPath(); - - final File contextXmlFile = (contextXml == null ? null : FileSystems.getDefault().getPath(contextXml).toFile()); - - //copy the existing jetty base - Files.walkFileTree(jettyBasePath, EnumSet.of(FileVisitOption.FOLLOW_LINKS), Integer.MAX_VALUE, - new SimpleFileVisitor() - { - @Override - public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException - { - Path targetDir = targetBasePath.resolve(jettyBasePath.relativize(dir)); - try - { - Files.copy(dir, targetDir); - } - catch (FileAlreadyExistsException e) - { - if (!Files.isDirectory(targetDir)) //ignore attempt to recreate dir - throw e; - } - return FileVisitResult.CONTINUE; - } - - @Override - public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException - { - if (contextXmlFile != null && Files.isSameFile(contextXmlFile.toPath(), file)) - return FileVisitResult.CONTINUE; //skip copying the context xml file - Files.copy(file, targetBasePath.resolve(jettyBasePath.relativize(file))); - return FileVisitResult.CONTINUE; - } - }); - } - - //make the jetty base structure - modulesPath = Files.createDirectories(targetBasePath.resolve("modules")); - etcPath = Files.createDirectories(targetBasePath.resolve("etc")); - libPath = Files.createDirectories(targetBasePath.resolve("lib")); - webappPath = Files.createDirectories(targetBasePath.resolve("webapps")); - mavenLibPath = Files.createDirectories(libPath.resolve("maven-ee9")); - - //copy in the jetty-maven-plugin jar - URI thisJar = TypeUtil.getLocationOfClass(this.getClass()); - if (thisJar == null) - throw new IllegalStateException("Can't find jar for jetty-ee9-maven-plugin"); - - try (InputStream jarStream = thisJar.toURL().openStream(); - FileOutputStream fileStream = new FileOutputStream(mavenLibPath.resolve("plugin.jar").toFile())) - { - IO.copy(jarStream, fileStream); - } - - //copy in the maven.xml webapp file - try (InputStream mavenXmlStream = getClass().getClassLoader().getResourceAsStream("maven-ee9.xml"); - FileOutputStream fileStream = new FileOutputStream(webappPath.resolve("maven-ee9.xml").toFile())) - { - IO.copy(mavenXmlStream, fileStream); - } - - Files.writeString(webappPath.resolve("maven-ee9.properties"), "environment=ee9"); - - //copy in the maven.mod file - try (InputStream mavenModStream = getClass().getClassLoader().getResourceAsStream("ee9-maven.mod"); - FileOutputStream fileStream = new FileOutputStream(modulesPath.resolve("ee9-maven.mod").toFile())) - { - IO.copy(mavenModStream, fileStream); - } - - //copy in the jetty-maven.xml file - try (InputStream jettyMavenStream = getClass().getClassLoader().getResourceAsStream("jetty-ee9-maven.xml"); - FileOutputStream fileStream = new FileOutputStream(etcPath.resolve("jetty-ee9-maven.xml").toFile())) - { - IO.copy(jettyMavenStream, fileStream); - } - - //if there were plugin dependencies, copy them into lib/ext - if (libExtJarFiles != null && !libExtJarFiles.isEmpty()) - { - Path libExtPath = Files.createDirectories(libPath.resolve("ext")); - for (File f : libExtJarFiles) - { - try (InputStream jarStream = new FileInputStream(f); - FileOutputStream fileStream = new FileOutputStream(libExtPath.resolve(f.getName()).toFile())) - { - IO.copy(jarStream, fileStream); - } - } - } - } - - private void configureJettyHome() - throws Exception - { - if (jettyHome == null && jettyHomeZip == null) - throw new IllegalStateException("No jettyHome"); - - if (baseDir == null) - throw new IllegalStateException("No baseDir"); - - if (jettyHome == null) - { - try (ResourceFactory.Closeable resourceFactory = ResourceFactory.closeable()) - { - Resource res = resourceFactory.newJarFileResource(jettyHomeZip.toPath().toUri()); - res.copyTo(baseDir.toPath()); - } - //zip will unpack to target/jetty-home- - jettyHome = new File(baseDir, "jetty-home-" + version); - } - } } diff --git a/jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/JettyRunMojo.java b/jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/JettyRunMojo.java index 3cfcba6891a4..be4dcc1201b7 100644 --- a/jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/JettyRunMojo.java +++ b/jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/JettyRunMojo.java @@ -28,6 +28,7 @@ import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.plugins.annotations.ResolutionScope; import org.eclipse.jetty.ee9.webapp.WebAppContext; +import org.eclipse.jetty.maven.ConsoleReader; import org.eclipse.jetty.util.IncludeExcludeSet; import org.eclipse.jetty.util.Scanner; import org.eclipse.jetty.util.component.LifeCycle; @@ -356,7 +357,7 @@ public void restartWebApp(boolean reconfigure) throws Exception } } - embedder.getWebApp().stop(); + embedder.stopWebApp(); configureWebApp(); embedder.redeployWebApp(); if (scanner != null) diff --git a/jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/JettyRunWarMojo.java b/jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/JettyRunWarMojo.java index 11e2b201bf87..74df47acd190 100644 --- a/jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/JettyRunWarMojo.java +++ b/jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/JettyRunWarMojo.java @@ -25,6 +25,7 @@ import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.plugins.annotations.ResolutionScope; +import org.eclipse.jetty.maven.ConsoleReader; import org.eclipse.jetty.util.Scanner; import org.eclipse.jetty.util.StringUtil; @@ -235,7 +236,7 @@ public void restartWebApp(boolean reconfigure) throws Exception warArtifacts = null; configureScanner(); } - embedder.getWebApp().stop(); + embedder.stopWebApp(); configureWebApp(); embedder.redeployWebApp(); scanner.start(); diff --git a/jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/MavenWebAppContext.java b/jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/MavenWebAppContext.java index 0111a9457b15..15a032166160 100644 --- a/jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/MavenWebAppContext.java +++ b/jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/MavenWebAppContext.java @@ -37,6 +37,7 @@ import org.eclipse.jetty.ee9.webapp.Configurations; import org.eclipse.jetty.ee9.webapp.MetaInfConfiguration; import org.eclipse.jetty.ee9.webapp.WebAppContext; +import org.eclipse.jetty.maven.Overlay; import org.eclipse.jetty.util.FileID; import org.eclipse.jetty.util.StringUtil; import org.eclipse.jetty.util.URIUtil; diff --git a/jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/QuickStartGenerator.java b/jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/QuickStartGenerator.java index 9c0fceca0c94..4fd8cdfb3618 100644 --- a/jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/QuickStartGenerator.java +++ b/jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/QuickStartGenerator.java @@ -18,6 +18,8 @@ import org.eclipse.jetty.ee9.annotations.AnnotationConfiguration; import org.eclipse.jetty.ee9.quickstart.QuickStartConfiguration; import org.eclipse.jetty.ee9.quickstart.QuickStartConfiguration.Mode; +import org.eclipse.jetty.ee9.webapp.Configurations; +import org.eclipse.jetty.maven.ServerSupport; import org.eclipse.jetty.server.Server; import org.eclipse.jetty.util.thread.QueuedThreadPool; @@ -152,7 +154,7 @@ public void generate() //ensure handler structure enabled ServerSupport.configureHandlers(server, null, null); - ServerSupport.configureDefaultConfigurationClasses(server); + Configurations.setServerDefault(server); //if our server has a thread pool associated we can do annotation scanning multithreaded, //otherwise scanning will be single threaded @@ -160,7 +162,7 @@ public void generate() tpool = server.getBean(QueuedThreadPool.class); //add webapp to our fake server instance - ServerSupport.addWebApplication(server, webApp); + ServerSupport.addWebApplication(server, webApp.getCoreContextHandler()); //leave everything unpacked for the forked process to use webApp.setPersistTempDirectory(true); diff --git a/jetty-ee9/jetty-ee9-maven-plugin/src/main/resources/ee9-maven.mod b/jetty-ee9/jetty-ee9-maven-plugin/src/main/resources/ee9-maven.mod index b418b19c1d13..4eee3f1211f3 100644 --- a/jetty-ee9/jetty-ee9-maven-plugin/src/main/resources/ee9-maven.mod +++ b/jetty-ee9/jetty-ee9-maven-plugin/src/main/resources/ee9-maven.mod @@ -12,7 +12,7 @@ ee9-webapp ee9-annotations [lib] -lib/maven-ee9/**.jar +lib/ee9-maven/**.jar [xml] etc/jetty-ee9-maven.xml diff --git a/jetty-ee9/jetty-ee9-maven-plugin/src/main/resources/jetty-ee9-maven.xml b/jetty-ee9/jetty-ee9-maven-plugin/src/main/resources/jetty-ee9-maven.xml index 4b7f403ba4a2..b83be87a6474 100644 --- a/jetty-ee9/jetty-ee9-maven-plugin/src/main/resources/jetty-ee9-maven.xml +++ b/jetty-ee9/jetty-ee9-maven-plugin/src/main/resources/jetty-ee9-maven.xml @@ -4,7 +4,7 @@ - + diff --git a/jetty-ee9/jetty-ee9-maven-plugin/src/test/java/org/eclipse/jetty/ee9/maven/plugin/TestForkedChild.java b/jetty-ee9/jetty-ee9-maven-plugin/src/test/java/org/eclipse/jetty/ee9/maven/plugin/TestForkedChild.java index dd26c1c1ed47..55fa53d1beb8 100644 --- a/jetty-ee9/jetty-ee9-maven-plugin/src/test/java/org/eclipse/jetty/ee9/maven/plugin/TestForkedChild.java +++ b/jetty-ee9/jetty-ee9-maven-plugin/src/test/java/org/eclipse/jetty/ee9/maven/plugin/TestForkedChild.java @@ -89,7 +89,7 @@ public void run() webapp.setBaseResourceAsPath(baseDir.toPath()); WebAppPropertyConverter.toProperties(webapp, webappPropsFile, null); child = new JettyForkedChild(cmd.toArray(new String[0])); - child.jetty.setExitVm(false); //ensure jetty doesn't stop vm for testing + child.getJettyEmbedder().setExitVm(false); //ensure jetty doesn't stop vm for testing child.start(); } catch (Exception e) diff --git a/jetty-ee9/jetty-ee9-maven-plugin/src/test/java/org/eclipse/jetty/ee9/maven/plugin/TestJettyEmbedder.java b/jetty-ee9/jetty-ee9-maven-plugin/src/test/java/org/eclipse/jetty/ee9/maven/plugin/TestJettyEmbedder.java index c8ac2df17226..ac4d077ec763 100644 --- a/jetty-ee9/jetty-ee9-maven-plugin/src/test/java/org/eclipse/jetty/ee9/maven/plugin/TestJettyEmbedder.java +++ b/jetty-ee9/jetty-ee9-maven-plugin/src/test/java/org/eclipse/jetty/ee9/maven/plugin/TestJettyEmbedder.java @@ -20,6 +20,8 @@ import java.util.Map; import org.eclipse.jetty.ee9.servlet.ListenerHolder; +import org.eclipse.jetty.maven.MavenServerConnector; +import org.eclipse.jetty.maven.ServerSupport; import org.eclipse.jetty.server.Server; import org.eclipse.jetty.server.handler.ContextHandler; import org.eclipse.jetty.server.handler.ContextHandlerCollection; @@ -121,7 +123,7 @@ public void testJettyEmbedder(WorkDir workDir) assertTrue(contexts.contains(webApp)); //stop the webapp and check durable listener retained - jetty.getWebApp().stop(); + jetty.stopWebApp(); boolean someListener = false; for (ListenerHolder h : webApp.getServletHandler().getListeners()) { diff --git a/jetty-ee9/jetty-ee9-maven-plugin/src/test/java/org/eclipse/jetty/ee9/maven/plugin/TestSelectiveJarResource.java b/jetty-ee9/jetty-ee9-maven-plugin/src/test/java/org/eclipse/jetty/ee9/maven/plugin/TestSelectiveJarResource.java index dba232cc86bc..84538ea0ad73 100644 --- a/jetty-ee9/jetty-ee9-maven-plugin/src/test/java/org/eclipse/jetty/ee9/maven/plugin/TestSelectiveJarResource.java +++ b/jetty-ee9/jetty-ee9-maven-plugin/src/test/java/org/eclipse/jetty/ee9/maven/plugin/TestSelectiveJarResource.java @@ -18,6 +18,7 @@ import java.util.ArrayList; import java.util.List; +import org.eclipse.jetty.maven.SelectiveJarResource; import org.eclipse.jetty.toolchain.test.MavenTestingUtils; import org.eclipse.jetty.toolchain.test.jupiter.WorkDir; import org.eclipse.jetty.toolchain.test.jupiter.WorkDirExtension; diff --git a/pom.xml b/pom.xml index 96daf3e8f11d..7a88efa45336 100644 --- a/pom.xml +++ b/pom.xml @@ -714,6 +714,11 @@ jetty-keystore ${project.version} + + org.eclipse.jetty + jetty-maven + ${project.version} + org.eclipse.jetty jetty-nosql