Issue #3583 maven plugin do not use testOutputDirectory directory for test dependencies within reactor (#3606)

* Issue #3583 maven plugin do not use testOutputDirectory directory for test dependencies within reactor

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

* use same spaces formatting

Signed-off-by: olivier lamy <oliver.lamy@gmail.com>
This commit is contained in:
Olivier Lamy 2019-05-09 07:00:20 +10:00 committed by GitHub
parent a176c60c5c
commit 45468988ea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 105 additions and 6 deletions

View File

@ -20,6 +20,11 @@
<artifactId>commons-io</artifactId> <artifactId>commons-io</artifactId>
<version>2.6</version> <version>2.6</version>
</dependency> </dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.8.1</version>
</dependency>
<dependency> <dependency>
<groupId>javax.servlet</groupId> <groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId> <artifactId>javax.servlet-api</artifactId>

View File

@ -0,0 +1,45 @@
//
// ========================================================================
// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
//
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
//
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
//
package org.eclipse.jetty.its.jetty_run_mojo_it_test;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
/**
*
*/
@WebServlet("/testhello")
public class HelloTestServlet
extends HttpServlet
{
@Override
protected void doGet( HttpServletRequest req, HttpServletResponse resp )
throws ServletException, IOException
{
String who = req.getParameter( "name" );
resp.getWriter().write( "Hello from test " + (who == null ? "unknown" : who) );
}
}

View File

@ -23,26 +23,44 @@
<groupId>org.eclipse.jetty.its.jetty-run-mojo-it</groupId> <groupId>org.eclipse.jetty.its.jetty-run-mojo-it</groupId>
<artifactId>jetty-simple-base</artifactId> <artifactId>jetty-simple-base</artifactId>
</dependency> </dependency>
<dependency>
<groupId>org.eclipse.jetty.its.jetty-run-mojo-it</groupId>
<artifactId>jetty-simple-base</artifactId>
<scope>test</scope>
<type>test-jar</type>
</dependency>
<dependency> <dependency>
<groupId>org.slf4j</groupId> <groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId> <artifactId>slf4j-simple</artifactId>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.eclipse.jetty</groupId> <groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-servlet</artifactId> <artifactId>jetty-servlet</artifactId>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-client</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<scope>test</scope>
</dependency>
<dependency> <dependency>
<groupId>org.eclipse.jetty</groupId> <groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId> <artifactId>jetty-maven-plugin</artifactId>
<classifier>tests</classifier> <classifier>tests</classifier>
<type>test-jar</type> <type>test-jar</type>
<scope>test</scope> <scope>test</scope>
<exclusions>
<exclusion>
<groupId>*</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.junit.jupiter</groupId> <groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId> <artifactId>junit-jupiter-engine</artifactId>
@ -73,6 +91,7 @@
<jetty.port.file>${jetty.port.file}</jetty.port.file> <jetty.port.file>${jetty.port.file}</jetty.port.file>
<pingServlet>true</pingServlet> <pingServlet>true</pingServlet>
<helloServlet>true</helloServlet> <helloServlet>true</helloServlet>
<helloTestServlet>true</helloTestServlet>
<maven.it.name>${project.groupId}:${project.artifactId}</maven.it.name> <maven.it.name>${project.groupId}:${project.artifactId}</maven.it.name>
</systemPropertyVariables> </systemPropertyVariables>
<dependenciesToScan> <dependenciesToScan>
@ -99,6 +118,7 @@
</systemProperties> </systemProperties>
<nonBlocking>true</nonBlocking> <nonBlocking>true</nonBlocking>
<jettyXml>${basedir}/src/config/jetty.xml</jettyXml> <jettyXml>${basedir}/src/config/jetty.xml</jettyXml>
<useTestScope>true</useTestScope>
</configuration> </configuration>
</execution> </execution>
</executions> </executions>

View File

@ -35,6 +35,13 @@
<artifactId>jetty-simple-base</artifactId> <artifactId>jetty-simple-base</artifactId>
<version>${project.version}</version> <version>${project.version}</version>
</dependency> </dependency>
<dependency>
<groupId>org.eclipse.jetty.its.jetty-run-mojo-it</groupId>
<artifactId>jetty-simple-base</artifactId>
<version>${project.version}</version>
<scope>test</scope>
<type>test-jar</type>
</dependency>
</dependencies> </dependencies>
</dependencyManagement> </dependencyManagement>

View File

@ -41,6 +41,7 @@ import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.util.StringUtils; import org.codehaus.plexus.util.StringUtils;
import org.eclipse.jetty.util.PathWatcher; import org.eclipse.jetty.util.PathWatcher;
import org.eclipse.jetty.util.PathWatcher.PathWatchEvent; import org.eclipse.jetty.util.PathWatcher.PathWatchEvent;
import org.eclipse.jetty.util.StringUtil;
import org.eclipse.jetty.util.resource.Resource; import org.eclipse.jetty.util.resource.Resource;
import org.eclipse.jetty.util.resource.ResourceCollection; import org.eclipse.jetty.util.resource.ResourceCollection;
import org.eclipse.jetty.webapp.WebAppContext; import org.eclipse.jetty.webapp.WebAppContext;
@ -541,16 +542,19 @@ public class JettyRunMojo extends AbstractJettyMojo
continue; //only add dependencies of scope=test if explicitly required continue; //only add dependencies of scope=test if explicitly required
MavenProject mavenProject = getProjectReference( artifact, project ); MavenProject mavenProject = getProjectReference( artifact, project );
if (mavenProject != null) if (mavenProject != null)
{ {
File projectPath = Paths.get(mavenProject.getBuild().getOutputDirectory()).toFile(); File projectPath = "test-jar".equals( artifact.getType() )?
Paths.get( mavenProject.getBuild().getTestOutputDirectory() ).toFile()
: Paths.get( mavenProject.getBuild().getOutputDirectory() ).toFile();
getLog().debug( "Adding project directory " + projectPath.toString() ); getLog().debug( "Adding project directory " + projectPath.toString() );
dependencyFiles.add( projectPath ); dependencyFiles.add( projectPath );
continue; continue;
} }
dependencyFiles.add(artifact.getFile()); dependencyFiles.add(artifact.getFile());
getLog().debug( "Adding artifact " + artifact.getFile().getName() + " with scope "+artifact.getScope()+" for WEB-INF/lib " ); getLog().debug( "Adding artifact " + artifact.getFile().getName() + " with scope "+artifact.getScope()+" for WEB-INF/lib " );
} }
return dependencyFiles; return dependencyFiles;
@ -569,6 +573,16 @@ public class JettyRunMojo extends AbstractJettyMojo
{ {
return mavenProject; return mavenProject;
} }
if("test-jar".equals(artifact.getType()))
{
// getId use type so comparing getId will fail in case of test-jar dependency
if ( StringUtils.equals( mavenProject.getGroupId(), artifact.getGroupId() )
&& StringUtils.equals( mavenProject.getArtifactId(), artifact.getArtifactId() )
&& StringUtils.equals( mavenProject.getVersion(), artifact.getBaseVersion()) )
{
return mavenProject;
}
}
} }
return null; return null;
} }

View File

@ -77,6 +77,14 @@ public class TestGetContent
+ ", response not contentCheck: " + contentCheck + ", response:" + response); + ", response not contentCheck: " + contentCheck + ", response:" + response);
System.out.println( "contentCheck" ); System.out.println( "contentCheck" );
} }
if (Boolean.getBoolean( "helloTestServlet" ))
{
String response = httpClient.GET( "http://localhost:" + port + "/testhello?name=beer" ).getContentAsString();
assertEquals( "Hello from test beer", response.trim(), "it test " + System.getProperty( "maven.it.name" ) );
response = httpClient.GET( "http://localhost:" + port + "/testhello?name=foo" ).getContentAsString();
assertEquals( "Hello from test foo", response.trim(), "it test " + System.getProperty( "maven.it.name" ) );
System.out.println( "helloServlet" );
}
} }
finally finally
{ {