use maven annotations for jetty plugins #2404 (#2400)

* use maven annotations for jspc mojo

Signed-off-by: olivier lamy <oliver.lamy@gmail.com>

* use maven annotation for jetty-maven-plugin

Signed-off-by: olivier lamy <oliver.lamy@gmail.com>
This commit is contained in:
Olivier Lamy 2018-04-03 17:30:25 +10:00 committed by GitHub
parent 8ec1504279
commit 42d9da56c0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
17 changed files with 260 additions and 340 deletions

View File

@ -27,7 +27,7 @@
<executions>
<execution>
<id>exec-plugin-doc</id>
<phase>generate-sources</phase>
<phase>process-classes</phase>
<goals>
<goal>descriptor</goal>
<goal>helpmojo</goal>
@ -54,6 +54,11 @@
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
</dependency>
<dependency>
<groupId>org.apache.maven.plugin-tools</groupId>
<artifactId>maven-plugin-annotations</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-artifact</artifactId>
@ -123,6 +128,7 @@
<configuration>
<debug>${it.debug}</debug>
<addTestClassPath>true</addTestClassPath>
<timeoutInSeconds>60</timeoutInSeconds>
<projectsDirectory>src/it</projectsDirectory>
<cloneProjectsTo>${project.build.directory}/it</cloneProjectsTo>
<pomIncludes>

View File

@ -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</a> for instructions on using this plugin.
* </p>
* @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 = "</web-app>";
@ -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 &lt;servlet&gt; and
* &lt;servlet-mapping&gt; 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 &lt;/web-app&gt;
* 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<URL> sysUrls = new ArrayList<URL>();
List<URL> 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<webAppUrls.size())
webAppClassPath.append(System.getProperty("path.separator"));
}
@ -385,7 +366,6 @@ public class JspcMojo extends AbstractMojo
}
finally
{
Thread.currentThread().setContextClassLoader(currentClassLoader);
}
}
@ -413,13 +393,8 @@ public class JspcMojo extends AbstractMojo
if(generatedClassesDir.exists() && generatedClassesDir.isDirectory())
{
delete(generatedClassesDir, new FileFilter()
{
@Override
public boolean accept(File f)
{
return f.isDirectory() || f.getName().endsWith(".java");
}
delete(generatedClassesDir, pathname -> {
return pathname.isDirectory() || pathname.getName().endsWith(".java");
});
}
}

View File

@ -201,6 +201,7 @@
<debug>${it.debug}</debug>
<addTestClassPath>true</addTestClassPath>
<projectsDirectory>src/it</projectsDirectory>
<timeoutInSeconds>60</timeoutInSeconds>
<cloneProjectsTo>${project.build.directory}/it</cloneProjectsTo>
<pomIncludes>
<pomInclude>*/pom.xml</pomInclude>

View File

@ -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 &lt;jettyXml&gt; 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 &lt;jettyXml&gt; 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 &lt;jettyXml&gt; 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=&lt;stopPort&gt;
* -DSTOP.KEY=&lt;stopKey&gt; -jar start.jar --stop
*
* @parameter
*
*/
@Parameter
protected int stopPort;
/**
* Key to provide when stopping jetty on executing java -DSTOP.KEY=&lt;stopKey&gt;
* -DSTOP.PORT=&lt;stopPort&gt; -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 &lt;webApp&gt;.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<Artifact> 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<Artifact> 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.
* </p>
* @parameter default-value="false"
*/
@Parameter(defaultValue = "false")
protected boolean nonBlocking = false;
/**
* Per default this goal support only <code>war</code> packaging.
* If your project use an other type please configure it here.
*
* @parameter
*/
@Parameter
protected List<String> supportedPackagings = Collections.singletonList( "war");
@ -361,11 +346,9 @@ public abstract class AbstractJettyMojo extends AbstractMojo
try
{
List<URL> provided = new ArrayList<>();
URL[] urls = null;
for ( Iterator<Artifact> 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 <scope>provided</scope> 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<Artifact> 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"));
}
} );
}
}
}

View File

@ -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;
/**
* <p>
@ -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.
* </p>
*
* @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;

View File

@ -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 <a href="http://www.eclipse.org/jetty/documentation/">http://www.eclipse.org/jetty/documentation</a> 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

View File

@ -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 <a href="http://www.eclipse.org/jetty/documentation/">http://www.eclipse.org/jetty/documentation</a> 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<String,String> env = new HashMap<String,String>();
@Parameter
private Map<String,String> 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<ArtifactRepository> 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;

View File

@ -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;
* <p>
* See <a href="http://www.eclipse.org/jetty/documentation/">http://www.eclipse.org/jetty/documentation</a> 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<Artifact> 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<String,String> env = new HashMap<String,String>();
@Parameter
private Map<String,String> env = new HashMap<>();
/**
* The forked jetty instance
@ -279,7 +270,7 @@ public class JettyRunForkedMojo extends JettyRunMojo
if (tpool != null)
tpool.stop();
List<String> cmd = new ArrayList<String>();
List<String> cmd = new ArrayList<>();
cmd.add(getJavaBin());
if (jvmArgs != null)
@ -398,17 +389,16 @@ public class JettyRunForkedMojo extends JettyRunMojo
if (useProvidedScope)
{
List<String> provided = new ArrayList<String>();
for ( Iterator<Artifact> 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<String> 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<Artifact> 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<Artifact> getExtraJars()
throws Exception
{
Set<Artifact> extraJars = new HashSet<Artifact>();
Set<Artifact> 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

View File

@ -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;
* <p>
* There is a <a href="http://www.eclipse.org/jetty/documentation/current/maven-and-jetty.html">reference guide</a> 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 &lt;testOutputDirectory&gt;
* and the dependencies of &lt;scope&gt;test&lt;scope&gt;
* 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 &lt;webApp&gt;&lt;descriptor&gt; 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 &lt;include&gt; and &lt;exclude&gt; patterns
* for extra targets to periodically scan for changes. Can be used instead of,
* or in conjunction with &lt;scanTargets&gt;.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<File> getDependencyFiles()
{
List<File> dependencyFiles = new ArrayList<>();
for ( Iterator<Artifact> 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<Artifact> matchedWarArtifacts = new HashSet<Artifact>();
List<Overlay> overlays = new ArrayList<Overlay>();
Set<Artifact> matchedWarArtifacts = new HashSet<>();
List<Overlay> 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<Resource> resourceBaseCollection = new ArrayList<Resource>();
List<Resource> resourceBaseCollection = new ArrayList<>();
for (Overlay o:overlays)
{
@ -729,9 +710,8 @@ public class JettyRunMojo extends AbstractJettyMojo
return warArtifacts;
warArtifacts = new ArrayList<>();
for ( Iterator<Artifact> iter = projectArtifacts.iterator(); iter.hasNext(); )
for ( Artifact artifact : projectArtifacts)
{
Artifact artifact = iter.next();
if (artifact.getType().equals("war") || artifact.getType().equals("zip"))
{
try

View File

@ -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.
* </p>
*
*@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;
/**

View File

@ -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.
* </p>
*
* @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;
/**

View File

@ -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.
* </p>
*
* @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
{

View File

@ -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 <b>stopPort</b> and <b>stopKey</b> parameters can be used to
* configure which jetty to stop.
*
* @goal stop
* @description Stops jetty that is configured with &lt;stopKey&gt; and &lt;stopPort&gt;.
* Stops jetty that is configured with &lt;stopKey&gt; and &lt;stopPort&gt;.
*/
@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=&lt;stopKey&gt;
* -DSTOP.PORT=&lt;stopPort&gt; -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)
{

View File

@ -563,7 +563,7 @@ public class JettyWebAppContext extends WebAppContext
if (path != null)
{
TreeSet<String> allPaths = new TreeSet<String>();
TreeSet<String> allPaths = new TreeSet<>();
allPaths.addAll(paths);
//add in the dependency jars as a virtual WEB-INF/lib entry

View File

@ -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

View File

@ -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)

View File

@ -143,13 +143,13 @@ public class OverlayConfig
for (int j=0; list != null && j < list.length;j++)
{
if (includes == null)
includes = new ArrayList<String>();
includes = new ArrayList<>();
includes.add(list[j].getValue());
}
}
if (includes == null && defaultIncludes != null)
{
includes = new ArrayList<String>();
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<String>();
excludes = new ArrayList<>();
excludes.add(list[j].getValue());
}
}
if (excludes == null && defaultExcludes != null)
{
excludes = new ArrayList<String>();
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 : "")+",");