use outputDirectory from reactor projects rather than having to install dependencies first #1623
Signed-off-by: olivier lamy <olamy@webtide.com>
This commit is contained in:
parent
b93f9b319d
commit
20ca6277a8
|
@ -71,6 +71,12 @@
|
||||||
</exclusion>
|
</exclusion>
|
||||||
</exclusions>
|
</exclusions>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.maven.plugin-tools</groupId>
|
||||||
|
<artifactId>maven-plugin-annotations</artifactId>
|
||||||
|
<version>${pluginToolsVersion}</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.eclipse.jetty</groupId>
|
<groupId>org.eclipse.jetty</groupId>
|
||||||
<artifactId>jetty-util</artifactId>
|
<artifactId>jetty-util</artifactId>
|
||||||
|
|
|
@ -341,7 +341,7 @@ public abstract class AbstractJettyMojo extends AbstractMojo
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
List<URL> provided = new ArrayList<URL>();
|
List<URL> provided = new ArrayList<>();
|
||||||
URL[] urls = null;
|
URL[] urls = null;
|
||||||
|
|
||||||
for ( Iterator<Artifact> iter = projectArtifacts.iterator(); iter.hasNext(); )
|
for ( Iterator<Artifact> iter = projectArtifacts.iterator(); iter.hasNext(); )
|
||||||
|
|
|
@ -18,24 +18,29 @@
|
||||||
|
|
||||||
package org.eclipse.jetty.maven.plugin;
|
package org.eclipse.jetty.maven.plugin;
|
||||||
|
|
||||||
|
import org.apache.maven.artifact.Artifact;
|
||||||
|
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.codehaus.plexus.util.StringUtils;
|
||||||
|
import org.eclipse.jetty.util.PathWatcher;
|
||||||
|
import org.eclipse.jetty.util.PathWatcher.PathWatchEvent;
|
||||||
|
import org.eclipse.jetty.util.resource.Resource;
|
||||||
|
import org.eclipse.jetty.webapp.WebAppContext;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
import java.nio.file.Paths;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.apache.maven.artifact.Artifact;
|
|
||||||
import org.apache.maven.plugin.MojoExecutionException;
|
|
||||||
import org.apache.maven.plugin.MojoFailureException;
|
|
||||||
import org.eclipse.jetty.util.PathWatcher;
|
|
||||||
import org.eclipse.jetty.util.PathWatcher.PathWatchEvent;
|
|
||||||
import org.eclipse.jetty.util.resource.Resource;
|
|
||||||
import org.eclipse.jetty.webapp.WebAppContext;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This goal is used in-situ on a Maven project without first requiring that the project
|
* This goal is used in-situ on a Maven project without first requiring that the project
|
||||||
* is assembled into a war, saving time during the development cycle.
|
* is assembled into a war, saving time during the development cycle.
|
||||||
|
@ -155,10 +160,8 @@ public class JettyRunMojo extends AbstractJettyMojo
|
||||||
*/
|
*/
|
||||||
protected List<Artifact> warArtifacts;
|
protected List<Artifact> warArtifacts;
|
||||||
|
|
||||||
|
@Parameter(defaultValue = "${reactorProjects}", readonly = true, required = true)
|
||||||
|
private List<MavenProject> reactorProjects;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see org.eclipse.jetty.maven.plugin.AbstractJettyMojo#execute()
|
* @see org.eclipse.jetty.maven.plugin.AbstractJettyMojo#execute()
|
||||||
|
@ -166,6 +169,10 @@ public class JettyRunMojo extends AbstractJettyMojo
|
||||||
@Override
|
@Override
|
||||||
public void execute() throws MojoExecutionException, MojoFailureException
|
public void execute() throws MojoExecutionException, MojoFailureException
|
||||||
{
|
{
|
||||||
|
if ( !"war".equals( project.getPackaging() ) || skip )
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
warPluginInfo = new WarPluginInfo(project);
|
warPluginInfo = new WarPluginInfo(project);
|
||||||
super.execute();
|
super.execute();
|
||||||
}
|
}
|
||||||
|
@ -274,6 +281,7 @@ public class JettyRunMojo extends AbstractJettyMojo
|
||||||
if (useTestScope && (testClassesDirectory != null))
|
if (useTestScope && (testClassesDirectory != null))
|
||||||
webApp.setTestClasses (testClassesDirectory);
|
webApp.setTestClasses (testClassesDirectory);
|
||||||
|
|
||||||
|
webApp.getClassPathFiles().addAll( getDependencyProjects() );
|
||||||
webApp.setWebInfLib (getDependencyFiles());
|
webApp.setWebInfLib (getDependencyFiles());
|
||||||
|
|
||||||
//get copy of a list of war artifacts
|
//get copy of a list of war artifacts
|
||||||
|
@ -556,18 +564,22 @@ public class JettyRunMojo extends AbstractJettyMojo
|
||||||
/**
|
/**
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
private List<File> getDependencyFiles ()
|
private List<File> getDependencyFiles()
|
||||||
{
|
{
|
||||||
List<File> dependencyFiles = new ArrayList<File>();
|
List<File> dependencyFiles = new ArrayList<File>();
|
||||||
for ( Iterator<Artifact> iter = projectArtifacts.iterator(); iter.hasNext(); )
|
for ( Iterator<Artifact> iter = projectArtifacts.iterator(); iter.hasNext(); )
|
||||||
{
|
{
|
||||||
Artifact artifact = (Artifact) iter.next();
|
Artifact artifact = iter.next();
|
||||||
|
|
||||||
// Include runtime and compile time libraries, and possibly test libs too
|
// Include runtime and compile time libraries, and possibly test libs too
|
||||||
if(artifact.getType().equals("war"))
|
if(artifact.getType().equals("war"))
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if (getProjectReferences( artifact, project )!=null)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (Artifact.SCOPE_PROVIDED.equals(artifact.getScope()))
|
if (Artifact.SCOPE_PROVIDED.equals(artifact.getScope()))
|
||||||
continue; //never add dependencies of scope=provided to the webapp's classpath (see also <useProvidedScope> param)
|
continue; //never add dependencies of scope=provided to the webapp's classpath (see also <useProvidedScope> param)
|
||||||
|
@ -582,6 +594,57 @@ public class JettyRunMojo extends AbstractJettyMojo
|
||||||
return dependencyFiles;
|
return dependencyFiles;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private List<File> getDependencyProjects()
|
||||||
|
{
|
||||||
|
List<File> dependencyFiles = new ArrayList<File>();
|
||||||
|
for ( Iterator<Artifact> iter = projectArtifacts.iterator(); iter.hasNext(); )
|
||||||
|
{
|
||||||
|
Artifact artifact = iter.next();
|
||||||
|
|
||||||
|
// Include runtime and compile time libraries, and possibly test libs too
|
||||||
|
if(artifact.getType().equals("war"))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Artifact.SCOPE_PROVIDED.equals(artifact.getScope()))
|
||||||
|
continue; //never add dependencies of scope=provided to the webapp's classpath (see also <useProvidedScope> param)
|
||||||
|
|
||||||
|
if (Artifact.SCOPE_TEST.equals(artifact.getScope()) && !useTestScope)
|
||||||
|
continue; //only add dependencies of scope=test if explicitly required
|
||||||
|
|
||||||
|
MavenProject mavenProject = getProjectReferences( artifact, project );
|
||||||
|
if (mavenProject != null)
|
||||||
|
{
|
||||||
|
dependencyFiles.add( Paths.get(mavenProject.getBuild().getOutputDirectory()).toFile() );
|
||||||
|
getLog().debug( "Adding project reference " + mavenProject.getBuild().getOutputDirectory()
|
||||||
|
+ " for WEB-INF/classes " );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return dependencyFiles;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private MavenProject getProjectReferences( Artifact artifact, MavenProject project )
|
||||||
|
{
|
||||||
|
if ( project.getProjectReferences() == null || project.getProjectReferences().isEmpty() )
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
Collection<MavenProject> mavenProjects = project.getProjectReferences().values();
|
||||||
|
for ( MavenProject mavenProject : mavenProjects )
|
||||||
|
{
|
||||||
|
if ( StringUtils.equals( mavenProject.getId(), artifact.getId() ) )
|
||||||
|
{
|
||||||
|
return mavenProject;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -95,10 +95,10 @@ public class JettyWebAppContext extends WebAppContext
|
||||||
|
|
||||||
private File _classes = null;
|
private File _classes = null;
|
||||||
private File _testClasses = null;
|
private File _testClasses = null;
|
||||||
private final List<File> _webInfClasses = new ArrayList<File>();
|
private final List<File> _webInfClasses = new ArrayList<>();
|
||||||
private final List<File> _webInfJars = new ArrayList<File>();
|
private final List<File> _webInfJars = new ArrayList<>();
|
||||||
private final Map<String, File> _webInfJarMap = new HashMap<String, File>();
|
private final Map<String, File> _webInfJarMap = new HashMap<String, File>();
|
||||||
private List<File> _classpathFiles; //webInfClasses+testClasses+webInfJars
|
private List<File> _classpathFiles = new ArrayList<>(); //webInfClasses+testClasses+webInfJars
|
||||||
private String _jettyEnvXml;
|
private String _jettyEnvXml;
|
||||||
private List<Overlay> _overlays;
|
private List<Overlay> _overlays;
|
||||||
private Resource _quickStartWebXml;
|
private Resource _quickStartWebXml;
|
||||||
|
@ -411,7 +411,6 @@ public class JettyWebAppContext extends WebAppContext
|
||||||
_webInfClasses.add(_classes);
|
_webInfClasses.add(_classes);
|
||||||
|
|
||||||
// Set up the classpath
|
// Set up the classpath
|
||||||
_classpathFiles = new ArrayList<File>();
|
|
||||||
_classpathFiles.addAll(_webInfClasses);
|
_classpathFiles.addAll(_webInfClasses);
|
||||||
_classpathFiles.addAll(_webInfJars);
|
_classpathFiles.addAll(_webInfJars);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue