From 42d9da56c0292467074789bd557b803f1adc7269 Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Tue, 3 Apr 2018 17:30:25 +1000 Subject: [PATCH] use maven annotations for jetty plugins #2404 (#2400) * use maven annotations for jspc mojo Signed-off-by: olivier lamy * use maven annotation for jetty-maven-plugin Signed-off-by: olivier lamy --- jetty-jspc-maven-plugin/pom.xml | 8 +- .../eclipse/jetty/jspc/plugin/JspcMojo.java | 93 +++++-------- jetty-maven-plugin/pom.xml | 1 + .../jetty/maven/plugin/AbstractJettyMojo.java | 124 +++++++----------- .../jetty/maven/plugin/JettyDeployWar.java | 16 ++- .../maven/plugin/JettyEffectiveWebXml.java | 25 ++-- .../jetty/maven/plugin/JettyRunDistro.java | 72 +++++----- .../maven/plugin/JettyRunForkedMojo.java | 96 ++++++-------- .../jetty/maven/plugin/JettyRunMojo.java | 80 +++++------ .../maven/plugin/JettyRunWarExplodedMojo.java | 17 ++- .../jetty/maven/plugin/JettyRunWarMojo.java | 18 +-- .../jetty/maven/plugin/JettyStartMojo.java | 11 +- .../jetty/maven/plugin/JettyStopMojo.java | 20 ++- .../maven/plugin/JettyWebAppContext.java | 2 +- .../plugin/MavenQuickStartConfiguration.java | 5 +- .../eclipse/jetty/maven/plugin/Overlay.java | 2 +- .../jetty/maven/plugin/OverlayConfig.java | 10 +- 17 files changed, 260 insertions(+), 340 deletions(-) diff --git a/jetty-jspc-maven-plugin/pom.xml b/jetty-jspc-maven-plugin/pom.xml index e8121302752..5b645583706 100644 --- a/jetty-jspc-maven-plugin/pom.xml +++ b/jetty-jspc-maven-plugin/pom.xml @@ -27,7 +27,7 @@ exec-plugin-doc - generate-sources + process-classes descriptor helpmojo @@ -54,6 +54,11 @@ org.apache.maven maven-plugin-api + + org.apache.maven.plugin-tools + maven-plugin-annotations + provided + org.apache.maven maven-artifact @@ -123,6 +128,7 @@ ${it.debug} true + 60 src/it ${project.build.directory}/it diff --git a/jetty-jspc-maven-plugin/src/main/java/org/eclipse/jetty/jspc/plugin/JspcMojo.java b/jetty-jspc-maven-plugin/src/main/java/org/eclipse/jetty/jspc/plugin/JspcMojo.java index 4e5937c11f5..34c75bd66ee 100644 --- a/jetty-jspc-maven-plugin/src/main/java/org/eclipse/jetty/jspc/plugin/JspcMojo.java +++ b/jetty-jspc-maven-plugin/src/main/java/org/eclipse/jetty/jspc/plugin/JspcMojo.java @@ -42,6 +42,11 @@ import org.apache.maven.artifact.Artifact; import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; +import org.apache.maven.plugins.annotations.Component; +import org.apache.maven.plugins.annotations.LifecyclePhase; +import org.apache.maven.plugins.annotations.Mojo; +import org.apache.maven.plugins.annotations.Parameter; +import org.apache.maven.plugins.annotations.ResolutionScope; import org.apache.maven.project.MavenProject; import org.apache.tomcat.JarScanner; import org.apache.tomcat.util.scan.StandardJarScanner; @@ -64,11 +69,9 @@ import org.eclipse.jetty.util.resource.Resource; * href="https://www.eclipse.org/jetty/documentation/current/jetty-jspc-maven-plugin.html">Usage * Guide for instructions on using this plugin. *

- * @goal jspc - * @phase process-classes - * @requiresDependencyResolution compile+runtime - * @description Runs jspc compiler to produce .java and .class files + * Runs jspc compiler to produce .java and .class files */ +@Mojo( name = "jspc", defaultPhase = LifecyclePhase.PROCESS_CLASSES, requiresDependencyResolution = ResolutionScope.COMPILE_PLUS_RUNTIME) public class JspcMojo extends AbstractMojo { public static final String END_OF_WEBAPP = ""; @@ -124,46 +127,39 @@ public class JspcMojo extends AbstractMojo * Use WITH CAUTION as you may wind up with duplicate jars/classes. * * @since jetty-7.6.3 - * @parameter default-value="false" */ + @Parameter(defaultValue = "false") private boolean useProvidedScope; /** * The artifacts for the project. * * @since jetty-7.6.3 - * @parameter default-value="${project.artifacts}" - * @readonly */ + @Parameter(defaultValue = "${project.artifacts}", readonly = true) private Set projectArtifacts; /** * The maven project. - * - * @parameter default-value="${project}" - * @required - * @readonly */ + @Parameter(defaultValue = "${project}", readonly = true , required = true) private MavenProject project; /** * The artifacts for the plugin itself. - * - * @parameter default-value="${plugin.artifacts}" - * @readonly */ + @Parameter(defaultValue = "${plugin.artifacts}", readonly = true) private List pluginArtifacts; /** * File into which to generate the <servlet> and * <servlet-mapping> tags for the compiled jsps - * - * @parameter default-value="${basedir}/target/webfrag.xml" */ + @Parameter(defaultValue = "${basedir}/target/webfrag.xml") private String webXmlFragment; /** @@ -172,103 +168,89 @@ public class JspcMojo extends AbstractMojo * will NOT be preserved during the insertion. Can be left blank, in which * case the generated fragment is inserted just before the </web-app> * line - * - * @parameter */ + @Parameter private String insertionMarker; /** * Merge the generated fragment file with the web.xml from * webAppSourceDirectory. The merged file will go into the same directory as * the webXmlFragment. - * - * @parameter default-value="true" */ + @Parameter(defaultValue = "true") private boolean mergeFragment; /** * The destination directory into which to put the compiled jsps. - * - * @parameter default-value="${project.build.outputDirectory}" */ + @Parameter(defaultValue = "${project.build.outputDirectory}") private String generatedClasses; /** * Controls whether or not .java files generated during compilation will be * preserved. - * - * @parameter default-value="false" */ + @Parameter(defaultValue = "false") private boolean keepSources; - /** * Root directory for all html/jsp etc files - * - * @parameter default-value="${basedir}/src/main/webapp" - * */ + @Parameter(defaultValue = "${basedir}/src/main/webapp") private String webAppSourceDirectory; - - - + /** * Location of web.xml. Defaults to src/main/webapp/web.xml. - * @parameter default-value="${basedir}/src/main/webapp/WEB-INF/web.xml" */ + @Parameter(defaultValue = "${basedir}/src/main/webapp/WEB-INF/web.xml") private String webXml; /** * The comma separated list of patterns for file extensions to be processed. By default * will include all .jsp and .jspx files. - * - * @parameter default-value="**\/*.jsp, **\/*.jspx" */ + @Parameter(defaultValue = "**\\/*.jsp, **\\/*.jspx") private String includes; /** * The comma separated list of file name patters to exclude from compilation. - * - * @parameter default_value="**\/.svn\/**"; */ + @Parameter(defaultValue = "**\\/.svn\\/**") private String excludes; /** * The location of the compiled classes for the webapp - * - * @parameter default-value="${project.build.outputDirectory}" */ + @Parameter(defaultValue = "${project.build.outputDirectory}") private File classesDirectory; /** * Patterns of jars on the system path that contain tlds. Use | to separate each pattern. - * - * @parameter default-value=".*taglibs[^/]*\.jar|.*jstl[^/]*\.jar$ */ + @Parameter(defaultValue = ".*taglibs[^/]*\\.jar|.*jstl[^/]*\\.jar$") private String tldJarNamePatterns; /** * Source version - if not set defaults to jsp default (currently 1.7) - * @parameter */ + @Parameter private String sourceVersion; /** * Target version - if not set defaults to jsp default (currently 1.7) - * @parameter */ + @Parameter private String targetVersion; /** * * The JspC instance being used to compile the jsps. - * - * @parameter */ + @Parameter private JettyJspC jspc; @@ -276,9 +258,8 @@ public class JspcMojo extends AbstractMojo * Whether dirs on the classpath should be scanned as well as jars. * True by default. This allows for scanning for tlds of dependent projects that * are in the reactor as unassembled jars. - * - * @parameter default-value=true */ + @Parameter(defaultValue = "true") private boolean scanAllDirectories; @@ -326,13 +307,13 @@ public class JspcMojo extends AbstractMojo //Make a classloader so provided jars will be on the classpath - List sysUrls = new ArrayList(); + List sysUrls = new ArrayList<>(); sysUrls.addAll(providedJars); - URLClassLoader sysClassLoader = new URLClassLoader((URL[])sysUrls.toArray(new URL[0]), currentClassLoader); + URLClassLoader sysClassLoader = new URLClassLoader(sysUrls.toArray(new URL[0]), currentClassLoader); //make a classloader with the webapp classpath - URLClassLoader webAppClassLoader = new URLClassLoader((URL[]) webAppUrls.toArray(new URL[0]), sysClassLoader); - StringBuffer webAppClassPath = new StringBuffer(); + URLClassLoader webAppClassLoader = new URLClassLoader(webAppUrls.toArray(new URL[0]), sysClassLoader); + StringBuilder webAppClassPath = new StringBuilder(); for (int i = 0; i < webAppUrls.size(); i++) { @@ -340,7 +321,7 @@ public class JspcMojo extends AbstractMojo getLog().debug("webappclassloader contains: " + webAppUrls.get(i)); webAppClassPath.append(new File(webAppUrls.get(i).toURI()).getCanonicalPath()); if (getLog().isDebugEnabled()) - getLog().debug("added to classpath: " + ((URL) webAppUrls.get(i)).getFile()); + getLog().debug("added to classpath: " + (webAppUrls.get(i)).getFile()); if (i+1 { + return pathname.isDirectory() || pathname.getName().endsWith(".java"); }); } } diff --git a/jetty-maven-plugin/pom.xml b/jetty-maven-plugin/pom.xml index 7e06a8e5de5..f2df4664702 100644 --- a/jetty-maven-plugin/pom.xml +++ b/jetty-maven-plugin/pom.xml @@ -201,6 +201,7 @@ ${it.debug} true src/it + 60 ${project.build.directory}/it */pom.xml diff --git a/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/AbstractJettyMojo.java b/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/AbstractJettyMojo.java index 0e63f0493d0..026f18dafe1 100644 --- a/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/AbstractJettyMojo.java +++ b/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/AbstractJettyMojo.java @@ -37,8 +37,10 @@ import java.util.Set; import org.apache.maven.artifact.Artifact; import org.apache.maven.plugin.AbstractMojo; +import org.apache.maven.plugin.MojoExecution; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; +import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.project.MavenProject; import org.eclipse.jetty.security.LoginService; import org.eclipse.jetty.server.RequestLog; @@ -62,16 +64,16 @@ public abstract class AbstractJettyMojo extends AbstractMojo * Use WITH CAUTION as you may wind up with duplicate jars/classes. * * @since jetty-7.5.2 - * @parameter default-value="false" */ + @Parameter(defaultValue = "false") protected boolean useProvidedScope; /** * List of goals that are NOT to be used * * @since jetty-7.5.2 - * @parameter */ + @Parameter protected String[] excludedGoals; /** @@ -79,9 +81,8 @@ public abstract class AbstractJettyMojo extends AbstractMojo * the <jettyXml> element to specify external jetty xml config file. * Optional. * - * - * @parameter */ + @Parameter protected ContextHandler[] contextHandlers; /** @@ -89,9 +90,8 @@ public abstract class AbstractJettyMojo extends AbstractMojo * the <jettyXml> element to specify external jetty xml config file. * Optional. * - * - * @parameter */ + @Parameter protected LoginService[] loginServices; /** @@ -99,9 +99,8 @@ public abstract class AbstractJettyMojo extends AbstractMojo * Consider using instead the <jettyXml> element to specify external jetty xml config file. * Optional. * - * - * @parameter */ + @Parameter protected RequestLog requestLog; /** @@ -110,8 +109,8 @@ public abstract class AbstractJettyMojo extends AbstractMojo * flexible method of configuration, rather than using the (deprecated) individual * parameters like "tmpDirectory", "contextPath" etc. * - * @parameter alias="webAppConfig" */ + @Parameter(alias = "webAppConfig") protected JettyWebAppContext webApp; /** @@ -119,9 +118,8 @@ public abstract class AbstractJettyMojo extends AbstractMojo * and restart the context if necessary. Ignored if reload * is enabled. Disabled by default. * - * @parameter property="jetty.scanIntervalSeconds" default-value="0" - * @required */ + @Parameter(property = "jetty.scanIntervalSeconds", defaultValue = "0", required = true) protected int scanIntervalSeconds; /** @@ -129,9 +127,9 @@ public abstract class AbstractJettyMojo extends AbstractMojo * * if 'manual' then the context can be reloaded by a linefeed in the console * if 'automatic' then traditional reloading on changed files is enabled. - * - * @parameter property="jetty.reload" default-value="automatic" + * */ + @Parameter(property = "jetty.reload", defaultValue = "automatic") protected String reload; @@ -142,8 +140,8 @@ public abstract class AbstractJettyMojo extends AbstractMojo * that have been set on the command line, by the JVM, or directly * in the POM via systemProperties. Optional. * - * @parameter property="jetty.systemPropertiesFile" */ + @Parameter(property = "jetty.systemPropertiesFile") protected File systemPropertiesFile; @@ -153,111 +151,99 @@ public abstract class AbstractJettyMojo extends AbstractMojo * that have been set on the command line or by the JVM. They WILL * override System properties that have been set via systemPropertiesFile. * Optional. - * @parameter */ + @Parameter protected SystemProperties systemProperties; /** * Comma separated list of a jetty xml configuration files whose contents * will be applied before any plugin configuration. Optional. - * - * - * @parameter alias="jettyConfig" + * */ + @Parameter(alias="jettyConfig") protected String jettyXml; /** * Port to listen to stop jetty on executing -DSTOP.PORT=<stopPort> * -DSTOP.KEY=<stopKey> -jar start.jar --stop - * - * @parameter + * */ + @Parameter protected int stopPort; /** * Key to provide when stopping jetty on executing java -DSTOP.KEY=<stopKey> * -DSTOP.PORT=<stopPort> -jar start.jar --stop - * - * @parameter + * */ + @Parameter protected String stopKey; /** * Use the dump() facility of jetty to print out the server configuration to logging - * - * @parameter property="dumponStart" default-value="false" + * */ + @Parameter( property="dumponStart", defaultValue="false") protected boolean dumpOnStart; /** * Skip this mojo execution. - * - * @parameter property="jetty.skip" default-value="false" */ + @Parameter(property="jetty.skip", defaultValue="false") protected boolean skip; /** * Location of a context xml configuration file whose contents * will be applied to the webapp AFTER anything in <webApp>.Optional. - * - * - * @parameter alias="webAppXml" + * */ + @Parameter(alias="webAppXml") protected String contextXml; /** * The maven project. * - * @parameter default-value="${project}" - * @readonly */ + @Parameter(defaultValue="${project}", readonly = true) protected MavenProject project; /** * The artifacts for the project. - * - * @parameter default-value="${project.artifacts}" - * @readonly + * */ - protected Set projectArtifacts; + @Parameter(defaultValue="${project.artifacts}", readonly = true) + protected Set projectArtifacts; - /** - * @parameter default-value="${mojoExecution}" - * @readonly - */ - protected org.apache.maven.plugin.MojoExecution execution; - + @Parameter(defaultValue="${mojoExecution}", readonly = true) + protected MojoExecution execution; /** * The artifacts for the plugin itself. - * - * @parameter default-value="${plugin.artifacts}" - * @readonly + * */ - protected List pluginArtifacts; - - + @Parameter(defaultValue="${plugin.artifacts}", readonly = true) + protected List pluginArtifacts; /** * A ServerConnector to use. - * - * @parameter + * */ + @Parameter protected MavenServerConnector httpConnector; /** * A wrapper for the Server object - * @parameter */ + @Parameter protected Server server; @@ -266,8 +252,7 @@ public abstract class AbstractJettyMojo extends AbstractMojo */ protected PathWatcher scanner; - - + /** * A scanner to check ENTER hits on the console */ @@ -286,16 +271,16 @@ public abstract class AbstractJettyMojo extends AbstractMojo * If true, the server will not block the execution of subsequent code. This * is the behaviour of the jetty:start and default behaviour of the jetty:deploy goals. *

- * @parameter default-value="false" */ + @Parameter(defaultValue = "false") protected boolean nonBlocking = false; /** * Per default this goal support only war packaging. * If your project use an other type please configure it here. * - * @parameter */ + @Parameter protected List supportedPackagings = Collections.singletonList( "war"); @@ -361,11 +346,9 @@ public abstract class AbstractJettyMojo extends AbstractMojo try { List provided = new ArrayList<>(); - URL[] urls = null; - - for ( Iterator iter = projectArtifacts.iterator(); iter.hasNext(); ) + + for ( Artifact artifact : projectArtifacts) { - Artifact artifact = iter.next(); if (Artifact.SCOPE_PROVIDED.equals(artifact.getScope()) && !isPluginArtifact(artifact)) { provided.add(artifact.getFile().toURI().toURL()); @@ -375,8 +358,7 @@ public abstract class AbstractJettyMojo extends AbstractMojo if (!provided.isEmpty()) { - urls = new URL[provided.size()]; - provided.toArray(urls); + URL[] urls = provided.stream().toArray(URL[]::new); URLClassLoader loader = new URLClassLoader(urls, getClass().getClassLoader()); Thread.currentThread().setContextClassLoader(loader); getLog().info("Plugin classpath augmented with provided dependencies: "+Arrays.toString(urls)); @@ -394,23 +376,22 @@ public abstract class AbstractJettyMojo extends AbstractMojo if (pluginArtifacts == null || pluginArtifacts.isEmpty()) return false; - boolean isPluginArtifact = false; - for (Iterator iter = pluginArtifacts.iterator(); iter.hasNext() && !isPluginArtifact; ) + for (Artifact pluginArtifact : pluginArtifacts ) { - Artifact pluginArtifact = iter.next(); if (getLog().isDebugEnabled()) { getLog().debug("Checking "+pluginArtifact);} - if (pluginArtifact.getGroupId().equals(artifact.getGroupId()) && pluginArtifact.getArtifactId().equals(artifact.getArtifactId())) - isPluginArtifact = true; + if (pluginArtifact.getGroupId().equals(artifact.getGroupId()) // + && pluginArtifact.getArtifactId().equals(artifact.getArtifactId())) + return true; } - return isPluginArtifact; + return false; } public void finishConfigurationBeforeStart() throws Exception { - HandlerCollection contexts = (HandlerCollection)server.getChildHandlerByClass(ContextHandlerCollection.class); + HandlerCollection contexts = server.getChildHandlerByClass(ContextHandlerCollection.class); if (contexts==null) - contexts = (HandlerCollection)server.getChildHandlerByClass(HandlerCollection.class); + contexts = server.getChildHandlerByClass(HandlerCollection.class); for (int i=0; (this.contextHandlers != null) && (i < this.contextHandlers.length); i++) { @@ -648,12 +629,9 @@ public abstract class AbstractJettyMojo extends AbstractMojo { if (systemProperties != null) { - Iterator itor = systemProperties.getSystemProperties().iterator(); - while (itor.hasNext()) - { - SystemProperty prop = (SystemProperty)itor.next(); + systemProperties.getSystemProperties().stream().forEach( prop -> { getLog().debug("Property "+prop.getName()+"="+prop.getValue()+" was "+ (prop.isSet() ? "set" : "skipped")); - } + } ); } } } diff --git a/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/JettyDeployWar.java b/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/JettyDeployWar.java index 4dbfc9dbd87..8477b175edc 100644 --- a/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/JettyDeployWar.java +++ b/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/JettyDeployWar.java @@ -20,6 +20,11 @@ package org.eclipse.jetty.maven.plugin; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; +import org.apache.maven.plugins.annotations.Execute; +import org.apache.maven.plugins.annotations.LifecyclePhase; +import org.apache.maven.plugins.annotations.Mojo; +import org.apache.maven.plugins.annotations.Parameter; +import org.apache.maven.plugins.annotations.ResolutionScope; /** *

@@ -36,13 +41,11 @@ import org.apache.maven.plugin.MojoFailureException; * This goal is useful e.g. for launching a web app in Jetty as a target for unit-tested * HTTP client components. *

- * - * @goal deploy-war - * @requiresDependencyResolution runtime - * @execute phase="validate" - * @description Deploy a pre-assembled war + * Deploy a pre-assembled war * */ +@Mojo( name = "deploy-war", requiresDependencyResolution = ResolutionScope.RUNTIME) +@Execute(phase = LifecyclePhase.VALIDATE) public class JettyDeployWar extends JettyRunWarMojo { @@ -52,9 +55,8 @@ public class JettyDeployWar extends JettyRunWarMojo * plugin will block further execution and you will need to use * cntrl-c to stop it. * - * - * @parameter default-value="true" */ + @Parameter(defaultValue = "true") protected boolean daemon = true; diff --git a/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/JettyEffectiveWebXml.java b/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/JettyEffectiveWebXml.java index e00aa76cd29..8208290abea 100644 --- a/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/JettyEffectiveWebXml.java +++ b/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/JettyEffectiveWebXml.java @@ -24,6 +24,11 @@ import java.io.IOException; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; +import org.apache.maven.plugins.annotations.Execute; +import org.apache.maven.plugins.annotations.LifecyclePhase; +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.annotations.AnnotationConfiguration; import org.eclipse.jetty.util.IO; import org.eclipse.jetty.util.resource.Resource; @@ -37,31 +42,25 @@ import org.eclipse.jetty.util.thread.QueuedThreadPool; * * See http://www.eclipse.org/jetty/documentation for more information on this and other jetty plugins. * - * @goal effective-web-xml - * @requiresDependencyResolution test - * @execute phase="test-compile" - * @description Runs jetty on the unassembled webapp to generate the effective web.xml + * Runs jetty on the unassembled webapp to generate the effective web.xml */ +@Mojo( name = "effective-web-xml", requiresDependencyResolution = ResolutionScope.TEST) +@Execute(phase = LifecyclePhase.TEST_COMPILE) public class JettyEffectiveWebXml extends JettyRunMojo { /** * The target directory - * - * @parameter default-value="${project.build.directory}" - * @required - * @readonly */ + @Parameter(defaultValue = "${project.build.directory}", readonly = true, required = true) protected File target; /** * The name of the file to generate into * - * @parameter */ + @Parameter protected File effectiveWebXml; - - - + protected boolean deleteOnExit = true; @@ -79,9 +78,7 @@ public class JettyEffectiveWebXml extends JettyRunMojo public void startJetty() throws MojoExecutionException { //Only do enough setup to be able to produce a quickstart-web.xml file - - QueuedThreadPool tpool = null; try diff --git a/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/JettyRunDistro.java b/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/JettyRunDistro.java index ed8f3dcec86..1fd6ecb727d 100644 --- a/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/JettyRunDistro.java +++ b/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/JettyRunDistro.java @@ -48,6 +48,12 @@ import org.apache.maven.model.Dependency; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.plugin.descriptor.PluginDescriptor; +import org.apache.maven.plugins.annotations.Component; +import org.apache.maven.plugins.annotations.Execute; +import org.apache.maven.plugins.annotations.LifecyclePhase; +import org.apache.maven.plugins.annotations.Mojo; +import org.apache.maven.plugins.annotations.Parameter; +import org.apache.maven.plugins.annotations.ResolutionScope; import org.apache.maven.project.DefaultProjectBuildingRequest; import org.apache.maven.project.ProjectBuildingRequest; import org.apache.maven.shared.artifact.DefaultArtifactCoordinate; @@ -76,12 +82,11 @@ import org.eclipse.jetty.util.resource.Resource; * * See http://www.eclipse.org/jetty/documentation for more information on this and other jetty plugins. * - * @goal run-distro - * @requiresDependencyResolution test - * @execute phase="test-compile" - * @description Runs unassembled webapp in a locally installed jetty distro + * Runs unassembled webapp in a locally installed jetty distro * */ +@Mojo( name = "run-distro", requiresDependencyResolution = ResolutionScope.TEST) +@Execute(phase = LifecyclePhase.TEST_COMPILE) public class JettyRunDistro extends JettyRunMojo { @@ -91,112 +96,99 @@ public class JettyRunDistro extends JettyRunMojo /** * This plugin - * - * @parameter default-value="${plugin}" - * @readonly - * @required */ + @Parameter(defaultValue = "${plugin}", required = true, readonly = true) protected PluginDescriptor plugin; /** * The target directory - * - * @parameter default-value="${project.build.directory}" - * @required - * @readonly */ + @Parameter(defaultValue = "${project.build.directory}", readonly = true, required = true) protected File target; /** * Optional jetty.home dir - * @parameter + * */ + @Parameter private File jettyHome; /** * Optional jetty.base dir - * @parameter + * */ + @Parameter private File jettyBase; /** * Optional list of other modules to * activate. - * @parameter */ + @Parameter private String[] modules; /** * Arbitrary jvm args to pass to the forked process - * @parameter property="jetty.jvmArgs" + * */ + @Parameter(property = "jetty.jvmArgs") private String jvmArgs; /** * Extra environment variables to be passed to the forked process - * - * @parameter + * */ - private Map env = new HashMap(); + @Parameter + private Map env = new HashMap<>(); /** * Optional list of jetty properties to put on the command line - * @parameter + * */ + @Parameter private String[] jettyProperties; - /** - * @parameter default-value="${session}" - * @required - * @readonly - */ + @Parameter(defaultValue = "${session}", required = true, readonly = true) private MavenSession session; /** * The project's remote repositories to use for the resolution. * - * @parameter default-value="${project.remoteArtifactRepositories}" - * @required - * @readonly */ + @Parameter(defaultValue="${project.remoteArtifactRepositories}", required = true, readonly = true) private List remoteRepositories; - /** - * @component - */ + @Component private ArtifactResolver artifactResolver; - - /** - * @parameter default-value="${plugin.version}" - * @readonly - */ + + @Parameter( defaultValue="${plugin.version}", readonly = true) private String pluginVersion; /** * Whether to wait for the child to finish or not. - * @parameter default-value="true" + * */ + @Parameter(defaultValue="true") private boolean waitForChild; /** * Max number of times to try checking if the * child has started successfully. * - * @parameter default-value="10" */ + @Parameter(defaultValue="10") private int maxChildChecks; /** * Millisecs to wait between each * check to see if the child started successfully. - * - * @parameter default-value="100" */ + @Parameter(defaultValue="100") private long maxChildCheckInterval; private File targetBase; diff --git a/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/JettyRunForkedMojo.java b/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/JettyRunForkedMojo.java index 8ac761be0a6..e0df458fdf9 100644 --- a/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/JettyRunForkedMojo.java +++ b/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/JettyRunForkedMojo.java @@ -37,6 +37,11 @@ import org.apache.maven.model.Dependency; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.plugin.descriptor.PluginDescriptor; +import org.apache.maven.plugins.annotations.Execute; +import org.apache.maven.plugins.annotations.LifecyclePhase; +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.annotations.AnnotationConfiguration; import org.eclipse.jetty.server.Server; import org.eclipse.jetty.util.resource.Resource; @@ -59,87 +64,73 @@ import org.eclipse.jetty.util.thread.QueuedThreadPool; *

* See http://www.eclipse.org/jetty/documentation for more information on this and other jetty plugins. * - * @goal run-forked - * @requiresDependencyResolution test - * @execute phase="test-compile" - * @description Runs Jetty in forked JVM on an unassembled webapp + * Runs Jetty in forked JVM on an unassembled webapp * */ +@Mojo( name = "run-forked", requiresDependencyResolution = ResolutionScope.TEST) +@Execute(phase = LifecyclePhase.TEST_COMPILE) public class JettyRunForkedMojo extends JettyRunMojo { /** * The target directory - * - * @parameter default-value="${project.build.directory}" - * @required - * @readonly */ + @Parameter(defaultValue="${project.build.directory}", readonly = true, required = true) protected File target; /** * The file into which to generate the quickstart web xml for the forked process to use - * - * @parameter default-value="${project.build.directory}/fork-web.xml" + * */ + @Parameter(defaultValue="${project.build.directory}/fork-web.xml") protected File forkWebXml; /** * Arbitrary jvm args to pass to the forked process - * @parameter property="jetty.jvmArgs" + * */ + @Parameter(property="jetty.jvmArgs") private String jvmArgs; /** * Optional list of jetty properties to put on the command line - * @parameter + * */ + @Parameter private String[] jettyProperties; - - /** - * @parameter default-value="${plugin.artifacts}" - * @readonly - */ - private List pluginArtifacts; - - - /** - * @parameter default-value="${plugin}" - * @readonly - */ + @Parameter(defaultValue="${plugin.artifacts}",readonly = true) + private List pluginArtifacts; + + @Parameter(defaultValue="${plugin}", readonly = true) private PluginDescriptor plugin; - - - /** - * @parameter default-value="true" - */ + + @Parameter(defaultValue="true") private boolean waitForChild; /** * Max number of times to try checking if the * child has started successfully. - * - * @parameter alias="maxStartupLines" default-value="50" + * */ + @Parameter(alias="maxStartupLines", defaultValue="50") private int maxChildChecks; /** * Millisecs to wait between each * check to see if the child started successfully. - * - * @parameter default-value="100" */ + @Parameter(defaultValue="100") private long maxChildCheckInterval; /** * Extra environment variables to be passed to the forked process * - * @parameter */ - private Map env = new HashMap(); + @Parameter + private Map env = new HashMap<>(); /** * The forked jetty instance @@ -279,7 +270,7 @@ public class JettyRunForkedMojo extends JettyRunMojo if (tpool != null) tpool.stop(); - List cmd = new ArrayList(); + List cmd = new ArrayList<>(); cmd.add(getJavaBin()); if (jvmArgs != null) @@ -398,17 +389,16 @@ public class JettyRunForkedMojo extends JettyRunMojo if (useProvidedScope) { - List provided = new ArrayList(); - for ( Iterator iter = project.getArtifacts().iterator(); iter.hasNext(); ) - { - Artifact artifact = iter.next(); - if (Artifact.SCOPE_PROVIDED.equals(artifact.getScope()) && !isPluginArtifact(artifact)) - { - provided.add(artifact.getFile().getAbsolutePath()); - if (getLog().isDebugEnabled()) { getLog().debug("Adding provided artifact: "+artifact);} - } + List provided = new ArrayList<>(); + for ( Artifact artifact : project.getArtifacts()) + { + if (Artifact.SCOPE_PROVIDED.equals(artifact.getScope()) && !isPluginArtifact(artifact)) + { + provided.add(artifact.getFile().getAbsolutePath()); + if (getLog().isDebugEnabled()) { getLog().debug("Adding provided artifact: "+artifact);} } - return provided; + } + return provided; } else @@ -438,22 +428,20 @@ public class JettyRunForkedMojo extends JettyRunMojo if (pluginArtifacts == null || pluginArtifacts.isEmpty()) return false; - boolean isPluginArtifact = false; - for (Iterator iter = pluginArtifacts.iterator(); iter.hasNext() && !isPluginArtifact; ) + for (Artifact pluginArtifact : pluginArtifacts) { - Artifact pluginArtifact = iter.next(); if (getLog().isDebugEnabled()) { getLog().debug("Checking "+pluginArtifact);} if (pluginArtifact.getGroupId().equals(artifact.getGroupId()) && pluginArtifact.getArtifactId().equals(artifact.getArtifactId())) - isPluginArtifact = true; + return true; } - return isPluginArtifact; + return false; } private Set getExtraJars() throws Exception { - Set extraJars = new HashSet(); + Set extraJars = new HashSet<>(); List l = pluginArtifacts; @@ -461,6 +449,7 @@ public class JettyRunForkedMojo extends JettyRunMojo if (l != null) { + Iterator itor = l.iterator(); while (itor.hasNext() && pluginArtifact == null) { @@ -478,9 +467,8 @@ public class JettyRunForkedMojo extends JettyRunMojo public String getContainerClassPath() throws Exception { StringBuilder classPath = new StringBuilder(); - for (Object obj : pluginArtifacts) + for (Artifact artifact : pluginArtifacts) { - Artifact artifact = (Artifact) obj; if ("jar".equals(artifact.getType())) { //ignore slf4j from inside maven diff --git a/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/JettyRunMojo.java b/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/JettyRunMojo.java index 2ff73a17772..f686a0456dc 100644 --- a/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/JettyRunMojo.java +++ b/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/JettyRunMojo.java @@ -34,7 +34,11 @@ import java.util.Set; import org.apache.maven.artifact.Artifact; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; +import org.apache.maven.plugins.annotations.Execute; +import org.apache.maven.plugins.annotations.LifecyclePhase; +import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.plugins.annotations.Parameter; +import org.apache.maven.plugins.annotations.ResolutionScope; import org.apache.maven.project.MavenProject; import org.codehaus.plexus.util.StringUtils; import org.eclipse.jetty.util.PathWatcher; @@ -61,11 +65,10 @@ import org.eclipse.jetty.webapp.WebAppContext; *

* There is a reference guide to the configuration parameters for this plugin. * - * @goal run - * @requiresDependencyResolution test - * @execute phase="test-compile" - * @description Runs jetty directly from a maven project + * Runs jetty directly from a maven project */ +@Mojo( name = "run", requiresDependencyResolution = ResolutionScope.TEST) +@Execute(phase = LifecyclePhase.TEST_COMPILE) public class JettyRunMojo extends AbstractJettyMojo { public static final String DEFAULT_WEBAPP_SRC = "src"+File.separator+"main"+File.separator+"webapp"; @@ -77,69 +80,61 @@ public class JettyRunMojo extends AbstractJettyMojo * If true, the <testOutputDirectory> * and the dependencies of <scope>test<scope> * will be put first on the runtime classpath. - * - * @parameter alias="useTestClasspath" default-value="false" + * */ + @Parameter(alias="useTestClasspath", defaultValue="false") protected boolean useTestScope; /** * The default location of the web.xml file. Will be used * if <webApp><descriptor> is not set. - * - * @parameter default-value="${maven.war.webxml}" - * @readonly + * */ + @Parameter(defaultValue="${maven.war.webxml}", readonly = true) protected String webXml; /** * The directory containing generated classes. * - * @parameter default-value="${project.build.outputDirectory}" - * @required - * */ + @Parameter(defaultValue="${project.build.outputDirectory}", required = true) protected File classesDirectory; /** * An optional pattern for includes/excludes of classes in the classesDirectory - * @parameter + * */ + @Parameter protected ScanPattern scanClassesPattern; - - - - + /** * The directory containing generated test classes. - * - * @parameter default-value="${project.build.testOutputDirectory}" - * @required + * */ + @Parameter(defaultValue="${project.build.testOutputDirectory}", required = true) protected File testClassesDirectory; /** * An optional pattern for includes/excludes of classes in the testClassesDirectory - * @parameter + * */ + @Parameter protected ScanPattern scanTestClassesPattern; - - - + /** * Root directory for all html/jsp etc files * - * @parameter default-value="${maven.war.src}" - * */ + @Parameter(defaultValue="${maven.war.src}") protected File webAppSourceDirectory; /** * List of files or directories to additionally periodically scan for changes. Optional. - * @parameter */ + @Parameter protected File[] scanTargets; @@ -147,8 +142,9 @@ public class JettyRunMojo extends AbstractJettyMojo * List of directories with ant-style <include> and <exclude> patterns * for extra targets to periodically scan for changes. Can be used instead of, * or in conjunction with <scanTargets>.Optional. - * @parameter + * */ + @Parameter protected ScanTargetPattern[] scanTargetPatterns; @@ -336,20 +332,7 @@ public class JettyRunMojo extends AbstractJettyMojo getLog().info( "web.xml file = "+webApp.getDescriptor()); getLog().info("Webapp directory = " + webAppSourceDirectory.getCanonicalPath()); } - - private static File toFile(Resource resource) - { - try - { - return resource.getFile(); - } - catch ( IOException e ) - { - throw new RuntimeException( e.getMessage(), e ); - } - } - /** * @see org.eclipse.jetty.maven.plugin.AbstractJettyMojo#configureScanner() */ @@ -366,7 +349,7 @@ public class JettyRunMojo extends AbstractJettyMojo throw new MojoExecutionException("Error forming scan list", e); } - scanner.addListener(new PathWatcher.EventListListener() + scanner.addListener( new PathWatcher.EventListListener() { @Override @@ -549,10 +532,8 @@ public class JettyRunMojo extends AbstractJettyMojo private List getDependencyFiles() { List dependencyFiles = new ArrayList<>(); - for ( Iterator iter = projectArtifacts.iterator(); iter.hasNext(); ) + for ( Artifact artifact : projectArtifacts) { - Artifact artifact = iter.next(); - // Include runtime and compile time libraries, and possibly test libs too if(artifact.getType().equals("war")) { @@ -604,8 +585,8 @@ public class JettyRunMojo extends AbstractJettyMojo throws Exception { //get copy of a list of war artifacts - Set matchedWarArtifacts = new HashSet(); - List overlays = new ArrayList(); + Set matchedWarArtifacts = new HashSet<>(); + List overlays = new ArrayList<>(); for (OverlayConfig config:warPluginInfo.getMavenWarOverlayConfigs()) { //overlays can be individually skipped @@ -652,7 +633,7 @@ public class JettyRunMojo extends AbstractJettyMojo if (overlays == null || overlays.isEmpty()) return; - List resourceBaseCollection = new ArrayList(); + List resourceBaseCollection = new ArrayList<>(); for (Overlay o:overlays) { @@ -729,9 +710,8 @@ public class JettyRunMojo extends AbstractJettyMojo return warArtifacts; warArtifacts = new ArrayList<>(); - for ( Iterator iter = projectArtifacts.iterator(); iter.hasNext(); ) + for ( Artifact artifact : projectArtifacts) { - Artifact artifact = iter.next(); if (artifact.getType().equals("war") || artifact.getType().equals("zip")) { try diff --git a/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/JettyRunWarExplodedMojo.java b/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/JettyRunWarExplodedMojo.java index bf3bed32f95..2e6b37b580b 100644 --- a/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/JettyRunWarExplodedMojo.java +++ b/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/JettyRunWarExplodedMojo.java @@ -24,6 +24,11 @@ import java.util.List; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; +import org.apache.maven.plugins.annotations.Execute; +import org.apache.maven.plugins.annotations.LifecyclePhase; +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.util.PathWatcher; import org.eclipse.jetty.util.PathWatcher.PathWatchEvent; @@ -40,22 +45,16 @@ import org.eclipse.jetty.util.PathWatcher.PathWatchEvent; * You may also specify the location of a jetty.xml file whose contents will be applied before any plugin configuration. * This can be used, for example, to deploy a static webapp that is not part of your maven build. *

- * - *@goal run-exploded - *@requiresDependencyResolution compile+runtime - *@execute phase=package */ +@Mojo( name = "run-exploded", requiresDependencyResolution = ResolutionScope.COMPILE_PLUS_RUNTIME) +@Execute(phase = LifecyclePhase.PACKAGE) public class JettyRunWarExplodedMojo extends AbstractJettyMojo { - - /** * The location of the war file. - * - * @parameter default-value="${project.build.directory}/${project.build.finalName}" - * @required */ + @Parameter(defaultValue="${project.build.directory}/${project.build.finalName}", required = true) private File war; /** diff --git a/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/JettyRunWarMojo.java b/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/JettyRunWarMojo.java index 30227435e71..fd79deedd98 100644 --- a/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/JettyRunWarMojo.java +++ b/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/JettyRunWarMojo.java @@ -24,6 +24,11 @@ import java.util.List; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; +import org.apache.maven.plugins.annotations.Execute; +import org.apache.maven.plugins.annotations.LifecyclePhase; +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.util.PathWatcher; import org.eclipse.jetty.util.PathWatcher.PathWatchEvent; @@ -39,21 +44,18 @@ import org.eclipse.jetty.util.PathWatcher.PathWatchEvent; * You may also specify the location of a jetty.xml file whose contents will be applied before any plugin configuration. * This can be used, for example, to deploy a static webapp that is not part of your maven build. *

- * - * @goal run-war - * @requiresDependencyResolution compile+runtime - * @execute phase="package" - * @description Runs jetty on a war file - * + * Runs jetty on a war file */ +@Mojo( name = "run-war", requiresDependencyResolution = ResolutionScope.COMPILE_PLUS_RUNTIME) +@Execute(phase = LifecyclePhase.PACKAGE) public class JettyRunWarMojo extends AbstractJettyMojo { /** * The location of the war file. - * @parameter default-value="${project.build.directory}/${project.build.finalName}.war" - * @required + * */ + @Parameter(defaultValue="${project.build.directory}/${project.build.finalName}.war", required = true) private File war; /** diff --git a/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/JettyStartMojo.java b/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/JettyStartMojo.java index bb4c6943678..70fe508dace 100644 --- a/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/JettyStartMojo.java +++ b/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/JettyStartMojo.java @@ -20,6 +20,10 @@ package org.eclipse.jetty.maven.plugin; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; +import org.apache.maven.plugins.annotations.Execute; +import org.apache.maven.plugins.annotations.LifecyclePhase; +import org.apache.maven.plugins.annotations.Mojo; +import org.apache.maven.plugins.annotations.ResolutionScope; /** @@ -33,11 +37,10 @@ import org.apache.maven.plugin.MojoFailureException; * the webapp already exist. *

* - * @goal start - * @requiresDependencyResolution test - * @execute phase="validate" - * @description Runs jetty directly from a maven project from a binding to an execution in your pom + * Runs jetty directly from a maven project from a binding to an execution in your pom */ +@Mojo( name = "start", requiresDependencyResolution = ResolutionScope.TEST) +@Execute(phase = LifecyclePhase.VALIDATE) public class JettyStartMojo extends JettyRunMojo { diff --git a/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/JettyStopMojo.java b/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/JettyStopMojo.java index 68027601464..241fbadd657 100644 --- a/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/JettyStopMojo.java +++ b/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/JettyStopMojo.java @@ -28,6 +28,8 @@ import java.net.Socket; import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; +import org.apache.maven.plugins.annotations.Mojo; +import org.apache.maven.plugins.annotations.Parameter; /** * This goal stops a running instance of jetty. @@ -35,32 +37,29 @@ import org.apache.maven.plugin.MojoFailureException; * The stopPort and stopKey parameters can be used to * configure which jetty to stop. * - * @goal stop - * @description Stops jetty that is configured with <stopKey> and <stopPort>. + * Stops jetty that is configured with <stopKey> and <stopPort>. */ - +@Mojo( name = "stop") public class JettyStopMojo extends AbstractMojo { /** * Port to listen to stop jetty on sending stop command - * @parameter - * @required */ + @Parameter(required = true) protected int stopPort; /** * Key to provide when stopping jetty on executing java -DSTOP.KEY=<stopKey> * -DSTOP.PORT=<stopPort> -jar start.jar --stop - * @parameter - * @required */ + @Parameter(required = true) protected String stopKey; /** * Max time in seconds that the plugin will wait for confirmation that jetty has stopped. - * @parameter */ + @Parameter protected int stopWait; @@ -78,9 +77,9 @@ public class JettyStopMojo extends AbstractMojo //also stops depends whether or not it was started with ShutdownMonitor.exitVm=true String command = "forcestop"; - try + try(Socket s=new Socket(InetAddress.getByName("127.0.0.1"),stopPort);) { - Socket s=new Socket(InetAddress.getByName("127.0.0.1"),stopPort); + s.setSoLinger(false, 0); OutputStream out=s.getOutputStream(); @@ -105,7 +104,6 @@ public class JettyStopMojo extends AbstractMojo } } } - s.close(); } catch (ConnectException e) { diff --git a/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/JettyWebAppContext.java b/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/JettyWebAppContext.java index 1ee4ca4d5a8..92982799df8 100644 --- a/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/JettyWebAppContext.java +++ b/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/JettyWebAppContext.java @@ -563,7 +563,7 @@ public class JettyWebAppContext extends WebAppContext if (path != null) { - TreeSet allPaths = new TreeSet(); + TreeSet allPaths = new TreeSet<>(); allPaths.addAll(paths); //add in the dependency jars as a virtual WEB-INF/lib entry diff --git a/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/MavenQuickStartConfiguration.java b/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/MavenQuickStartConfiguration.java index 714e427092b..f7533e33b5d 100644 --- a/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/MavenQuickStartConfiguration.java +++ b/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/MavenQuickStartConfiguration.java @@ -68,9 +68,8 @@ public class MavenQuickStartConfiguration extends QuickStartConfiguration if (jwac.getClassPathFiles() != null) { if (LOG.isDebugEnabled()) LOG.debug("Setting up classpath ..."); - Iterator itor = jwac.getClassPathFiles().iterator(); - while (itor.hasNext()) - ((WebAppClassLoader)context.getClassLoader()).addClassPath(((File)itor.next()).getCanonicalPath()); + for(File classPathFile:jwac.getClassPathFiles()) + ((WebAppClassLoader)context.getClassLoader()).addClassPath(classPathFile.getCanonicalPath()); } //Set up the quickstart environment for the context diff --git a/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/Overlay.java b/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/Overlay.java index eefe8289b89..e507d4f04e9 100644 --- a/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/Overlay.java +++ b/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/Overlay.java @@ -61,7 +61,7 @@ public class Overlay @Override public String toString() { - StringBuffer strbuff = new StringBuffer(); + StringBuilder strbuff = new StringBuilder(); if (_resource != null) strbuff.append(_resource); if (_config != null) diff --git a/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/OverlayConfig.java b/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/OverlayConfig.java index d3426f47b8c..bdc11cc9fd6 100644 --- a/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/OverlayConfig.java +++ b/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/OverlayConfig.java @@ -143,13 +143,13 @@ public class OverlayConfig for (int j=0; list != null && j < list.length;j++) { if (includes == null) - includes = new ArrayList(); + includes = new ArrayList<>(); includes.add(list[j].getValue()); } } if (includes == null && defaultIncludes != null) { - includes = new ArrayList(); + includes = new ArrayList<>(); includes.addAll(defaultIncludes); } setIncludes(includes); @@ -163,13 +163,13 @@ public class OverlayConfig for (int j=0; list != null && j < list.length;j++) { if (excludes == null) - excludes = new ArrayList(); + excludes = new ArrayList<>(); excludes.add(list[j].getValue()); } } if (excludes == null && defaultExcludes != null) { - excludes = new ArrayList(); + excludes = new ArrayList<>(); excludes.addAll(defaultExcludes); } setExcludes(excludes); @@ -300,7 +300,7 @@ public class OverlayConfig @Override public String toString() { - StringBuffer strbuff = new StringBuffer(); + StringBuilder strbuff = new StringBuilder(); strbuff.append((groupId != null ? groupId : "")+","); strbuff.append((artifactId != null ? artifactId : "")+","); strbuff.append((classifier != null ? classifier : "")+",");