From 45468988ead838736d4fe2bd86b423df8cbd941e Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Thu, 9 May 2019 07:00:20 +1000 Subject: [PATCH] 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 * use same spaces formatting Signed-off-by: olivier lamy --- .../src/it/it-parent-pom/pom.xml | 5 +++ .../HelloTestServlet.java | 45 +++++++++++++++++++ .../jetty-simple-webapp/pom.xml | 28 ++++++++++-- .../src/it/jetty-run-mojo-it/pom.xml | 7 +++ .../jetty/maven/plugin/JettyRunMojo.java | 18 +++++++- .../jetty/maven/plugin/it/TestGetContent.java | 8 ++++ 6 files changed, 105 insertions(+), 6 deletions(-) create mode 100644 jetty-maven-plugin/src/it/jetty-run-mojo-it/jetty-simple-base/src/test/java/org/eclipse/jetty/its/jetty_run_mojo_it_test/HelloTestServlet.java diff --git a/jetty-maven-plugin/src/it/it-parent-pom/pom.xml b/jetty-maven-plugin/src/it/it-parent-pom/pom.xml index ebae8653539..ba48d496378 100644 --- a/jetty-maven-plugin/src/it/it-parent-pom/pom.xml +++ b/jetty-maven-plugin/src/it/it-parent-pom/pom.xml @@ -20,6 +20,11 @@ commons-io 2.6 + + org.apache.commons + commons-lang3 + 3.8.1 + javax.servlet javax.servlet-api diff --git a/jetty-maven-plugin/src/it/jetty-run-mojo-it/jetty-simple-base/src/test/java/org/eclipse/jetty/its/jetty_run_mojo_it_test/HelloTestServlet.java b/jetty-maven-plugin/src/it/jetty-run-mojo-it/jetty-simple-base/src/test/java/org/eclipse/jetty/its/jetty_run_mojo_it_test/HelloTestServlet.java new file mode 100644 index 00000000000..dbacf9498f3 --- /dev/null +++ b/jetty-maven-plugin/src/it/jetty-run-mojo-it/jetty-simple-base/src/test/java/org/eclipse/jetty/its/jetty_run_mojo_it_test/HelloTestServlet.java @@ -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) ); + } +} diff --git a/jetty-maven-plugin/src/it/jetty-run-mojo-it/jetty-simple-webapp/pom.xml b/jetty-maven-plugin/src/it/jetty-run-mojo-it/jetty-simple-webapp/pom.xml index 099146ad7e0..d0fb927984a 100644 --- a/jetty-maven-plugin/src/it/jetty-run-mojo-it/jetty-simple-webapp/pom.xml +++ b/jetty-maven-plugin/src/it/jetty-run-mojo-it/jetty-simple-webapp/pom.xml @@ -23,26 +23,44 @@ org.eclipse.jetty.its.jetty-run-mojo-it jetty-simple-base - + + org.eclipse.jetty.its.jetty-run-mojo-it + jetty-simple-base + test + test-jar + org.slf4j slf4j-simple - org.eclipse.jetty jetty-servlet provided - + + org.eclipse.jetty + jetty-client + test + + + org.apache.commons + commons-lang3 + test + org.eclipse.jetty jetty-maven-plugin tests test-jar test + + + * + * + + - org.junit.jupiter junit-jupiter-engine @@ -73,6 +91,7 @@ ${jetty.port.file} true true + true ${project.groupId}:${project.artifactId} @@ -99,6 +118,7 @@ true ${basedir}/src/config/jetty.xml + true diff --git a/jetty-maven-plugin/src/it/jetty-run-mojo-it/pom.xml b/jetty-maven-plugin/src/it/jetty-run-mojo-it/pom.xml index 1625960b537..453b36ef875 100644 --- a/jetty-maven-plugin/src/it/jetty-run-mojo-it/pom.xml +++ b/jetty-maven-plugin/src/it/jetty-run-mojo-it/pom.xml @@ -35,6 +35,13 @@ jetty-simple-base ${project.version} + + org.eclipse.jetty.its.jetty-run-mojo-it + jetty-simple-base + ${project.version} + test + test-jar + 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 183d557a1ca..1bfba008d8c 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 @@ -41,6 +41,7 @@ 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.StringUtil; import org.eclipse.jetty.util.resource.Resource; import org.eclipse.jetty.util.resource.ResourceCollection; 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 MavenProject mavenProject = getProjectReference( artifact, project ); + 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() ); dependencyFiles.add( projectPath ); continue; } 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; @@ -569,6 +573,16 @@ public class JettyRunMojo extends AbstractJettyMojo { 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; } diff --git a/jetty-maven-plugin/src/test/java/org/eclipse/jetty/maven/plugin/it/TestGetContent.java b/jetty-maven-plugin/src/test/java/org/eclipse/jetty/maven/plugin/it/TestGetContent.java index 37b2bb1b643..6fffe96d0cc 100644 --- a/jetty-maven-plugin/src/test/java/org/eclipse/jetty/maven/plugin/it/TestGetContent.java +++ b/jetty-maven-plugin/src/test/java/org/eclipse/jetty/maven/plugin/it/TestGetContent.java @@ -77,6 +77,14 @@ public class TestGetContent + ", response not contentCheck: " + contentCheck + ", response:" + response); 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 {