From 28466efa0420e6fa1ce924c12c41132c5b298558 Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Tue, 5 Jun 2018 18:18:42 +1000 Subject: [PATCH] rework maven it test to avoid duplicate class, try to make port file creation atomic (#2607) * use a single instance of the class TestGetContent.java #2600 * make the jetty.port file creation atomic * enforce some tests * ensure we use the correct java home to run invoker plugin, yes this should fail on ci for jdk9+ * use an other maven home for invoker runs * include failsafe-reports from maven invoker plugin Signed-off-by: olivier lamy --- Jenkinsfile | 6 +- jetty-maven-plugin/pom.xml | 18 ++- .../src/it/jetty-cdi-run-forked/pom.xml | 12 ++ .../it/jetty-cdi-run-forked/postbuild.groovy | 11 +- .../src/main/java/test/Greeter.java | 4 +- .../src/test/java/test/TestGetContent.java | 93 -------------- .../src/it/jetty-cdi-run-forked/verify.groovy | 21 ---- .../src/it/jetty-deploy-war-mojo-it/pom.xml | 58 ++++++++- .../postbuild.groovy} | 3 +- .../jetty_run_war_mojo_it/TestGetContent.java | 93 -------------- .../HelloServlet.java | 2 +- .../jetty-simple-webapp/pom.xml | 9 +- .../TestGetContent.java | 93 -------------- .../jetty-run-distro-mojo-it/postbuild.groovy | 10 +- .../it/jetty-run-distro-mojo-it/verify.groovy | 21 ---- .../HelloServlet.java | 2 +- .../jetty-simple-webapp/pom.xml | 16 +-- .../TestGetContent.java | 94 --------------- .../jetty-run-forked-mojo-it/postbuild.groovy | 9 +- .../it/jetty-run-forked-mojo-it/verify.groovy | 21 ---- .../its/jetty_run_mojo_it/HelloServlet.java | 2 +- .../jetty-simple-webapp/pom.xml | 9 +- .../its/jetty_run_mojo_it/TestGetContent.java | 94 --------------- .../postbuild.groovy} | 4 +- .../HelloServlet.java | 2 +- .../jetty-simple-webapp/pom.xml | 13 +- .../TestGetContent.java | 94 --------------- .../postbuild.groovy} | 4 +- .../its/jetty_run_mojo_it/HelloServlet.java | 2 +- .../jetty-simple-webapp/pom.xml | 12 +- .../jetty_run_war_mojo_it/TestGetContent.java | 94 --------------- .../it/jetty-run-war-mojo-it/postbuild.groovy | 23 ++++ .../its/jetty_start_mojo_it/HelloServlet.java | 2 +- .../jetty-simple-webapp/pom.xml | 9 +- .../jetty_start_mojo_it/TestGetContent.java | 94 --------------- .../it/jetty-start-mojo-it/postbuild.groovy | 23 ++++ .../src/it/jetty-start-mojo-it/verify.groovy | 20 ---- .../it/run-mojo-gwt-it/beer-server/pom.xml | 68 ++--------- .../test/java/org/olamy/TestGetContent.java | 92 -------------- .../postbuild.groovy} | 3 +- .../src/it/run-mojo-gwt-it/verify.groovy | 21 ---- .../maven/plugin/ServerConnectorListener.java | 38 +++--- .../jetty/maven/plugin/it/TestGetContent.java | 113 ++++++++++++++++++ 43 files changed, 371 insertions(+), 1061 deletions(-) delete mode 100644 jetty-maven-plugin/src/it/jetty-cdi-run-forked/src/test/java/test/TestGetContent.java delete mode 100644 jetty-maven-plugin/src/it/jetty-cdi-run-forked/verify.groovy rename jetty-maven-plugin/src/it/{jetty-run-mojo-it/verify.groovy => jetty-deploy-war-mojo-it/postbuild.groovy} (85%) delete mode 100644 jetty-maven-plugin/src/it/jetty-deploy-war-mojo-it/src/test/java/org/eclipse/jetty/its/jetty_run_war_mojo_it/TestGetContent.java delete mode 100644 jetty-maven-plugin/src/it/jetty-run-distro-mojo-it/jetty-simple-webapp/src/test/java/org/eclipse/jetty/its/jetty_run_distro_mojo_it/TestGetContent.java delete mode 100644 jetty-maven-plugin/src/it/jetty-run-distro-mojo-it/verify.groovy delete mode 100644 jetty-maven-plugin/src/it/jetty-run-forked-mojo-it/jetty-simple-webapp/src/test/java/org/eclipse/jetty/its/jetty_run_forked_mojo_it/TestGetContent.java delete mode 100644 jetty-maven-plugin/src/it/jetty-run-forked-mojo-it/verify.groovy delete mode 100644 jetty-maven-plugin/src/it/jetty-run-mojo-it/jetty-simple-webapp/src/test/java/org/eclipse/jetty/its/jetty_run_mojo_it/TestGetContent.java rename jetty-maven-plugin/src/it/{jetty-run-war-mojo-it/verify.groovy => jetty-run-mojo-it/postbuild.groovy} (81%) delete mode 100644 jetty-maven-plugin/src/it/jetty-run-war-exploded-mojo-it/jetty-simple-webapp/src/test/java/org/eclipse/jetty/its/jetty_run_war_exploded_mojo_it/TestGetContent.java rename jetty-maven-plugin/src/it/{jetty-deploy-war-mojo-it/verify.groovy => jetty-run-war-exploded-mojo-it/postbuild.groovy} (81%) delete mode 100644 jetty-maven-plugin/src/it/jetty-run-war-mojo-it/jetty-simple-webapp/src/test/java/org/eclipse/jetty/its/jetty_run_war_mojo_it/TestGetContent.java create mode 100644 jetty-maven-plugin/src/it/jetty-run-war-mojo-it/postbuild.groovy delete mode 100644 jetty-maven-plugin/src/it/jetty-start-mojo-it/jetty-simple-webapp/src/test/java/org/eclipse/jetty/its/jetty_start_mojo_it/TestGetContent.java create mode 100644 jetty-maven-plugin/src/it/jetty-start-mojo-it/postbuild.groovy delete mode 100644 jetty-maven-plugin/src/it/jetty-start-mojo-it/verify.groovy delete mode 100644 jetty-maven-plugin/src/it/run-mojo-gwt-it/beer-server/src/test/java/org/olamy/TestGetContent.java rename jetty-maven-plugin/src/it/{jetty-run-war-exploded-mojo-it/verify.groovy => run-mojo-gwt-it/postbuild.groovy} (85%) delete mode 100644 jetty-maven-plugin/src/it/run-mojo-gwt-it/verify.groovy create mode 100644 jetty-maven-plugin/src/test/java/org/eclipse/jetty/maven/plugin/it/TestGetContent.java diff --git a/Jenkinsfile b/Jenkinsfile index a3917bf696e..e74b31f0407 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -16,6 +16,7 @@ def getFullBuild(jdk, os) { node(os) { // System Dependent Locations def mvntool = tool name: 'maven3.5', type: 'hudson.tasks.Maven$MavenInstallation' + def mvntoolInvoker = tool name: 'maven3.5', type: 'hudson.tasks.Maven$MavenInstallation' def jdktool = tool name: "$jdk", type: 'hudson.model.JDK' def mvnName = 'maven3.5' def localRepo = "${env.JENKINS_HOME}/${env.EXECUTOR_NUMBER}" // ".repository" // @@ -89,12 +90,13 @@ def getFullBuild(jdk, os) { jdk: "$jdk", publisherStrategy: 'EXPLICIT', globalMavenSettingsConfig: settingsName, + //options: [invokerPublisher(disabled: false)], mavenLocalRepo: localRepo) { - sh "mvn -V -B install -Dmaven.test.failure.ignore=true -e -Pmongodb -T3" + sh "mvn -V -B install -Dmaven.test.failure.ignore=true -e -Pmongodb -T3 -DmavenHome=${mvntoolInvoker}" } // withMaven doesn't label.. // Report failures in the jenkins UI - junit testResults:'**/target/surefire-reports/TEST-*.xml' + junit testResults:'**/target/surefire-reports/TEST-*.xml,**/target/failsafe-reports/TEST-*.xml' // Collect up the jacoco execution results def jacocoExcludes = // build tools diff --git a/jetty-maven-plugin/pom.xml b/jetty-maven-plugin/pom.xml index eebe394a38a..e853c448cc1 100644 --- a/jetty-maven-plugin/pom.xml +++ b/jetty-maven-plugin/pom.xml @@ -36,12 +36,24 @@ + + org.apache.maven.plugins + maven-jar-plugin + + + + test-jar + + + + org.apache.maven.plugins maven-invoker-plugin integration-test + integration-test install integration-test @@ -50,6 +62,10 @@ + ${java.home} + + ${java.home} + ${it.debug} true src/it @@ -63,7 +79,6 @@ ${jetty.stopKey} ${jetty.stopPort} - ${jetty.runPort} ${surefireVersion} ${skipTests} @@ -85,7 +100,6 @@ jetty.stopPort - jetty.runPort diff --git a/jetty-maven-plugin/src/it/jetty-cdi-run-forked/pom.xml b/jetty-maven-plugin/src/it/jetty-cdi-run-forked/pom.xml index dc9a503e3ff..81770894004 100644 --- a/jetty-maven-plugin/src/it/jetty-cdi-run-forked/pom.xml +++ b/jetty-maven-plugin/src/it/jetty-cdi-run-forked/pom.xml @@ -39,6 +39,14 @@ @project.version@ test + + org.eclipse.jetty + jetty-maven-plugin + @project.version@ + tests + test-jar + test + @@ -59,7 +67,11 @@ ${jetty.port.file} + true + + org.eclipse.jetty:jetty-maven-plugin + diff --git a/jetty-maven-plugin/src/it/jetty-cdi-run-forked/postbuild.groovy b/jetty-maven-plugin/src/it/jetty-cdi-run-forked/postbuild.groovy index 8a524044e2a..7698ebf81a6 100644 --- a/jetty-maven-plugin/src/it/jetty-cdi-run-forked/postbuild.groovy +++ b/jetty-maven-plugin/src/it/jetty-cdi-run-forked/postbuild.groovy @@ -1,6 +1,5 @@ - -System.out.println( "running postbuild.groovy port " + jettyStopPort + ", key:" + jettyStopKey ) +System.out.println( "postbuild.groovy port " + jettyStopPort + ", key:" + jettyStopKey ) int port = Integer.parseInt( jettyStopPort ) @@ -10,4 +9,10 @@ s.setSoLinger(false, 0) OutputStream out=s.getOutputStream() out.write(( jettyStopKey +"\r\nforcestop\r\n").getBytes()) out.flush() -s.close() \ No newline at end of file +s.close() + +File buildLog = new File( basedir, 'build.log' ) +assert buildLog.text.contains( 'Forked process starting' ) +assert buildLog.text.contains( 'Running org.eclipse.jetty.maven.plugin.it.TestGetContent') +assert buildLog.text.contains( 'helloServlet') + diff --git a/jetty-maven-plugin/src/it/jetty-cdi-run-forked/src/main/java/test/Greeter.java b/jetty-maven-plugin/src/it/jetty-cdi-run-forked/src/main/java/test/Greeter.java index 1078b3ff179..c9e9a9ab797 100644 --- a/jetty-maven-plugin/src/it/jetty-cdi-run-forked/src/main/java/test/Greeter.java +++ b/jetty-maven-plugin/src/it/jetty-cdi-run-forked/src/main/java/test/Greeter.java @@ -34,6 +34,8 @@ public class Greeter protected void doGet( final HttpServletRequest req, final HttpServletResponse resp ) throws ServletException, IOException { - resp.getWriter().print( "Hello" ); + String who = req.getParameter( "name" ); + + resp.getWriter().write( "Hello " + (who == null ? "unknown" : who) ); } } diff --git a/jetty-maven-plugin/src/it/jetty-cdi-run-forked/src/test/java/test/TestGetContent.java b/jetty-maven-plugin/src/it/jetty-cdi-run-forked/src/test/java/test/TestGetContent.java deleted file mode 100644 index 6cade703b46..00000000000 --- a/jetty-maven-plugin/src/it/jetty-cdi-run-forked/src/test/java/test/TestGetContent.java +++ /dev/null @@ -1,93 +0,0 @@ -// -// ======================================================================== -// Copyright (c) 1995-2018 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 test; - -import java.io.File; -import java.io.FileReader; -import java.io.LineNumberReader; - -import org.eclipse.jetty.client.HttpClient; -import org.junit.Assert; -import org.junit.Test; - -/** - * - */ -public class TestGetContent -{ - @Test - public void get_ping_response() - throws Exception - { - - int port = getPort(); - Assert.assertTrue(port > 0); - HttpClient httpClient = new HttpClient(); - try - { - httpClient.start(); - - String response = httpClient.GET( "http://localhost:" + port + "/hello?name=beer" ).getContentAsString(); - - Assert.assertEquals( "Hello", response.trim() ); - - response = httpClient.GET( "http://localhost:" + port + "/hello?name=foo" ).getContentAsString(); - - Assert.assertEquals( "Hello", response.trim() ); - } - finally - { - httpClient.stop(); - } - } - - - public int getPort() - throws Exception - { - int attempts = 20; - int port = -1; - String s = System.getProperty("jetty.port.file"); - Assert.assertNotNull(s); - File f = new File(s); - while (true) - { - if (f.exists()) - { - try (FileReader r = new FileReader(f); - LineNumberReader lnr = new LineNumberReader(r); - ) - { - s = lnr.readLine(); - Assert.assertNotNull(s); - port = Integer.parseInt(s.trim()); - } - break; - } - else - { - if (--attempts < 0) - break; - else - Thread.currentThread().sleep(100); - } - } - return port; - } -} diff --git a/jetty-maven-plugin/src/it/jetty-cdi-run-forked/verify.groovy b/jetty-maven-plugin/src/it/jetty-cdi-run-forked/verify.groovy deleted file mode 100644 index b6658aabeec..00000000000 --- a/jetty-maven-plugin/src/it/jetty-cdi-run-forked/verify.groovy +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -File buildLog = new File( basedir, 'build.log' ) -assert buildLog.text.contains( 'Forked process starting' ) -assert buildLog.text.contains( 'Running test.TestGetContent') \ No newline at end of file diff --git a/jetty-maven-plugin/src/it/jetty-deploy-war-mojo-it/pom.xml b/jetty-maven-plugin/src/it/jetty-deploy-war-mojo-it/pom.xml index a76571e21e1..409b362e117 100644 --- a/jetty-maven-plugin/src/it/jetty-deploy-war-mojo-it/pom.xml +++ b/jetty-maven-plugin/src/it/jetty-deploy-war-mojo-it/pom.xml @@ -18,11 +18,12 @@ org.eclipse.jetty - jetty-client + jetty-maven-plugin @project.version@ + tests + test-jar test - junit junit @@ -44,14 +45,34 @@ org.apache.maven.plugins - maven-surefire-plugin + maven-failsafe-plugin @surefireVersion@ - true ${jetty.port.file} + Bean Validation Webapp example + + org.eclipse.jetty:jetty-maven-plugin + + + **/*TestGetContent* + + + + integration-test + + integration-test + + + + verify + + verify + + + org.eclipse.jetty @@ -65,7 +86,6 @@ deploy-war - @jetty.runPort@ pom @@ -115,4 +135,32 @@ + + + jdk9+ + + [1.9,) + + + + + + org.eclipse.jetty + jetty-maven-plugin + @project.version@ + + + javax.xml.bind + jaxb-api + 2.3.0 + + + + + + + + + + diff --git a/jetty-maven-plugin/src/it/jetty-run-mojo-it/verify.groovy b/jetty-maven-plugin/src/it/jetty-deploy-war-mojo-it/postbuild.groovy similarity index 85% rename from jetty-maven-plugin/src/it/jetty-run-mojo-it/verify.groovy rename to jetty-maven-plugin/src/it/jetty-deploy-war-mojo-it/postbuild.groovy index 19583fe2eac..b5f4344c4a6 100644 --- a/jetty-maven-plugin/src/it/jetty-run-mojo-it/verify.groovy +++ b/jetty-maven-plugin/src/it/jetty-deploy-war-mojo-it/postbuild.groovy @@ -18,4 +18,5 @@ */ File buildLog = new File( basedir, 'build.log' ) assert buildLog.text.contains( 'Started Jetty Server' ) -assert buildLog.text.contains( 'org.eclipse.jetty.its.jetty_run_mojo_it.TestGetContent') \ No newline at end of file +assert buildLog.text.contains( 'Running org.eclipse.jetty.maven.plugin.it.TestGetContent') +assert buildLog.text.contains( 'contentCheck') \ No newline at end of file diff --git a/jetty-maven-plugin/src/it/jetty-deploy-war-mojo-it/src/test/java/org/eclipse/jetty/its/jetty_run_war_mojo_it/TestGetContent.java b/jetty-maven-plugin/src/it/jetty-deploy-war-mojo-it/src/test/java/org/eclipse/jetty/its/jetty_run_war_mojo_it/TestGetContent.java deleted file mode 100644 index bc20fef11b7..00000000000 --- a/jetty-maven-plugin/src/it/jetty-deploy-war-mojo-it/src/test/java/org/eclipse/jetty/its/jetty_run_war_mojo_it/TestGetContent.java +++ /dev/null @@ -1,93 +0,0 @@ -// -// ======================================================================== -// Copyright (c) 1995-2018 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_war_mojo_it; - -import java.io.File; -import java.io.FileReader; -import java.io.LineNumberReader; - -import org.eclipse.jetty.client.HttpClient; -import org.junit.Assert; -import org.junit.Test; - -/** - * - */ -public class TestGetContent -{ - @Test - public void get_content() - throws Exception - { - int port = getPort(); - Assert.assertTrue(port > 0); - HttpClient httpClient = new HttpClient(); - try - { - httpClient.start(); - - String response = httpClient.GET( "http://localhost:" + port ).getContentAsString(); - - Assert.assertTrue(response.trim().contains("Bean Validation Webapp example") ); - - response = httpClient.GET( "http://localhost:" + port ).getContentAsString(); - - Assert.assertTrue(response.trim().contains("Bean Validation Webapp example") ); - } - finally - { - httpClient.stop(); - } - } - - public int getPort() - throws Exception - { - int attempts = 20; - int port = -1; - String s = System.getProperty("jetty.port.file"); - Assert.assertNotNull(s); - File f = new File(s); - while (true) - { - if (f.exists()) - { - try (FileReader r = new FileReader(f); - LineNumberReader lnr = new LineNumberReader(r); - ) - { - s = lnr.readLine(); - Assert.assertNotNull(s); - port = Integer.parseInt(s.trim()); - } - break; - } - else - { - if (--attempts < 0) - break; - else - Thread.currentThread().sleep(100); - } - } - return port; - } - -} diff --git a/jetty-maven-plugin/src/it/jetty-run-distro-mojo-it/jetty-simple-base/src/main/java/org/eclipse/jetty/its/jetty_run_distro_mojo_it/HelloServlet.java b/jetty-maven-plugin/src/it/jetty-run-distro-mojo-it/jetty-simple-base/src/main/java/org/eclipse/jetty/its/jetty_run_distro_mojo_it/HelloServlet.java index 73cc3722621..12a508a7e96 100644 --- a/jetty-maven-plugin/src/it/jetty-run-distro-mojo-it/jetty-simple-base/src/main/java/org/eclipse/jetty/its/jetty_run_distro_mojo_it/HelloServlet.java +++ b/jetty-maven-plugin/src/it/jetty-run-distro-mojo-it/jetty-simple-base/src/main/java/org/eclipse/jetty/its/jetty_run_distro_mojo_it/HelloServlet.java @@ -40,6 +40,6 @@ public class HelloServlet { String who = req.getParameter( "name" ); - resp.getWriter().write( "hello " + (who == null ? "unknown" : who) ); + resp.getWriter().write( "Hello " + (who == null ? "unknown" : who) ); } } diff --git a/jetty-maven-plugin/src/it/jetty-run-distro-mojo-it/jetty-simple-webapp/pom.xml b/jetty-maven-plugin/src/it/jetty-run-distro-mojo-it/jetty-simple-webapp/pom.xml index ed07bd37fe6..827f8c9db6f 100644 --- a/jetty-maven-plugin/src/it/jetty-run-distro-mojo-it/jetty-simple-webapp/pom.xml +++ b/jetty-maven-plugin/src/it/jetty-run-distro-mojo-it/jetty-simple-webapp/pom.xml @@ -34,8 +34,10 @@ org.eclipse.jetty - jetty-client + jetty-maven-plugin @project.version@ + tests + test-jar test @@ -69,7 +71,12 @@ ${jetty.port.file} + true + true + + org.eclipse.jetty:jetty-maven-plugin + diff --git a/jetty-maven-plugin/src/it/jetty-run-distro-mojo-it/jetty-simple-webapp/src/test/java/org/eclipse/jetty/its/jetty_run_distro_mojo_it/TestGetContent.java b/jetty-maven-plugin/src/it/jetty-run-distro-mojo-it/jetty-simple-webapp/src/test/java/org/eclipse/jetty/its/jetty_run_distro_mojo_it/TestGetContent.java deleted file mode 100644 index 09cf12de869..00000000000 --- a/jetty-maven-plugin/src/it/jetty-run-distro-mojo-it/jetty-simple-webapp/src/test/java/org/eclipse/jetty/its/jetty_run_distro_mojo_it/TestGetContent.java +++ /dev/null @@ -1,93 +0,0 @@ -// -// ======================================================================== -// Copyright (c) 1995-2018 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_distro_mojo_it; - -import java.io.File; -import java.io.FileReader; -import java.io.LineNumberReader; - -import org.eclipse.jetty.client.HttpClient; -import org.junit.Assert; -import org.junit.Test; - -/** - * - */ -public class TestGetContent -{ - - @Test - public void get_ping_response() - throws Exception - { - int port = getPort(); - Assert.assertTrue(port > 0); - HttpClient httpClient = new HttpClient(); - try - { - httpClient.start(); - - String response = httpClient.GET( "http://localhost:" + port + "/hello?name=beer" ).getContentAsString(); - - Assert.assertEquals( "hello beer", response.trim() ); - - response = httpClient.GET( "http://localhost:" + port + "/ping?name=beer" ).getContentAsString(); - - Assert.assertEquals( "pong beer", response.trim() ); - } - finally - { - httpClient.stop(); - } - } - - public int getPort() - throws Exception - { - int attempts = 20; - int port = -1; - String s = System.getProperty("jetty.port.file"); - Assert.assertNotNull(s); - File f = new File(s); - while (true) - { - if (f.exists()) - { - try (FileReader r = new FileReader(f); - LineNumberReader lnr = new LineNumberReader(r); - ) - { - s = lnr.readLine(); - Assert.assertNotNull(s); - port = Integer.parseInt(s.trim()); - } - break; - } - else - { - if (--attempts < 0) - break; - else - Thread.currentThread().sleep(100); - } - } - return port; - } - -} diff --git a/jetty-maven-plugin/src/it/jetty-run-distro-mojo-it/postbuild.groovy b/jetty-maven-plugin/src/it/jetty-run-distro-mojo-it/postbuild.groovy index 8a524044e2a..a11dfee70e3 100644 --- a/jetty-maven-plugin/src/it/jetty-run-distro-mojo-it/postbuild.groovy +++ b/jetty-maven-plugin/src/it/jetty-run-distro-mojo-it/postbuild.groovy @@ -1,5 +1,4 @@ - System.out.println( "running postbuild.groovy port " + jettyStopPort + ", key:" + jettyStopKey ) int port = Integer.parseInt( jettyStopPort ) @@ -10,4 +9,11 @@ s.setSoLinger(false, 0) OutputStream out=s.getOutputStream() out.write(( jettyStopKey +"\r\nforcestop\r\n").getBytes()) out.flush() -s.close() \ No newline at end of file +s.close() + + +File buildLog = new File( basedir, 'build.log' ) +assert buildLog.text.contains( 'Forking command line' ) +assert buildLog.text.contains( 'Running org.eclipse.jetty.maven.plugin.it.TestGetContent') +assert buildLog.text.contains( 'pingServlet ok') +assert buildLog.text.contains( 'helloServlet') diff --git a/jetty-maven-plugin/src/it/jetty-run-distro-mojo-it/verify.groovy b/jetty-maven-plugin/src/it/jetty-run-distro-mojo-it/verify.groovy deleted file mode 100644 index 8cbf3cc0283..00000000000 --- a/jetty-maven-plugin/src/it/jetty-run-distro-mojo-it/verify.groovy +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -File buildLog = new File( basedir, 'build.log' ) -assert buildLog.text.contains( 'Forking command line' ) -assert buildLog.text.contains( 'org.eclipse.jetty.its.jetty_run_distro_mojo_it.TestGetContent') \ No newline at end of file diff --git a/jetty-maven-plugin/src/it/jetty-run-forked-mojo-it/jetty-simple-base/src/main/java/org/eclipse/jetty/its/jetty_run_forked_mojo_it/HelloServlet.java b/jetty-maven-plugin/src/it/jetty-run-forked-mojo-it/jetty-simple-base/src/main/java/org/eclipse/jetty/its/jetty_run_forked_mojo_it/HelloServlet.java index dfce6cb6947..9d4582a75f6 100644 --- a/jetty-maven-plugin/src/it/jetty-run-forked-mojo-it/jetty-simple-base/src/main/java/org/eclipse/jetty/its/jetty_run_forked_mojo_it/HelloServlet.java +++ b/jetty-maven-plugin/src/it/jetty-run-forked-mojo-it/jetty-simple-base/src/main/java/org/eclipse/jetty/its/jetty_run_forked_mojo_it/HelloServlet.java @@ -40,6 +40,6 @@ public class HelloServlet { String who = req.getParameter( "name" ); - resp.getWriter().write( "hello " + (who == null ? "unknown" : who) ); + resp.getWriter().write( "Hello " + (who == null ? "unknown" : who) ); } } diff --git a/jetty-maven-plugin/src/it/jetty-run-forked-mojo-it/jetty-simple-webapp/pom.xml b/jetty-maven-plugin/src/it/jetty-run-forked-mojo-it/jetty-simple-webapp/pom.xml index 40f2b144fe4..9f97a329e02 100644 --- a/jetty-maven-plugin/src/it/jetty-run-forked-mojo-it/jetty-simple-webapp/pom.xml +++ b/jetty-maven-plugin/src/it/jetty-run-forked-mojo-it/jetty-simple-webapp/pom.xml @@ -32,19 +32,16 @@ provided + org.eclipse.jetty - jetty-client + jetty-maven-plugin @project.version@ + tests + test-jar test - - org.eclipse.jetty.toolchain - jetty-test-helper - 4.2 - test - junit @@ -76,7 +73,12 @@ ${jetty.port.file} + true + true + + org.eclipse.jetty:jetty-maven-plugin + diff --git a/jetty-maven-plugin/src/it/jetty-run-forked-mojo-it/jetty-simple-webapp/src/test/java/org/eclipse/jetty/its/jetty_run_forked_mojo_it/TestGetContent.java b/jetty-maven-plugin/src/it/jetty-run-forked-mojo-it/jetty-simple-webapp/src/test/java/org/eclipse/jetty/its/jetty_run_forked_mojo_it/TestGetContent.java deleted file mode 100644 index a0da6ee489c..00000000000 --- a/jetty-maven-plugin/src/it/jetty-run-forked-mojo-it/jetty-simple-webapp/src/test/java/org/eclipse/jetty/its/jetty_run_forked_mojo_it/TestGetContent.java +++ /dev/null @@ -1,94 +0,0 @@ -// -// ======================================================================== -// Copyright (c) 1995-2018 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_forked_mojo_it; - -import java.io.File; -import java.io.FileReader; -import java.io.LineNumberReader; - -import org.eclipse.jetty.client.HttpClient; -import org.junit.Assert; -import org.junit.Test; - -/** - * - */ -public class TestGetContent - -{ - @Test - public void get_ping_response() - throws Exception - { - - int port = getPort(); - Assert.assertTrue(port > 0); - HttpClient httpClient = new HttpClient(); - try - { - httpClient.start(); - - String response = httpClient.GET( "http://localhost:" + port + "/hello?name=beer" ).getContentAsString(); - - Assert.assertEquals( "hello beer", response.trim() ); - - response = httpClient.GET( "http://localhost:" + port + "/ping?name=beer" ).getContentAsString(); - - Assert.assertEquals( "pong beer", response.trim() ); - } - finally - { - httpClient.stop(); - } - } - - - public int getPort() - throws Exception - { - int attempts = 20; - int port = -1; - String s = System.getProperty("jetty.port.file"); - Assert.assertNotNull(s); - File f = new File(s); - while (true) - { - if (f.exists()) - { - try (FileReader r = new FileReader(f); - LineNumberReader lnr = new LineNumberReader(r); - ) - { - s = lnr.readLine(); - Assert.assertNotNull(s); - port = Integer.parseInt(s.trim()); - } - break; - } - else - { - if (--attempts < 0) - break; - else - Thread.currentThread().sleep(100); - } - } - return port; - } -} diff --git a/jetty-maven-plugin/src/it/jetty-run-forked-mojo-it/postbuild.groovy b/jetty-maven-plugin/src/it/jetty-run-forked-mojo-it/postbuild.groovy index 8a524044e2a..9e717199fb9 100644 --- a/jetty-maven-plugin/src/it/jetty-run-forked-mojo-it/postbuild.groovy +++ b/jetty-maven-plugin/src/it/jetty-run-forked-mojo-it/postbuild.groovy @@ -10,4 +10,11 @@ s.setSoLinger(false, 0) OutputStream out=s.getOutputStream() out.write(( jettyStopKey +"\r\nforcestop\r\n").getBytes()) out.flush() -s.close() \ No newline at end of file +s.close() + + +File buildLog = new File( basedir, 'build.log' ) +assert buildLog.text.contains( 'Forked process starting' ) +assert buildLog.text.contains( 'Running org.eclipse.jetty.maven.plugin.it.TestGetContent') +assert buildLog.text.contains( 'pingServlet ok') +assert buildLog.text.contains( 'helloServlet') \ No newline at end of file diff --git a/jetty-maven-plugin/src/it/jetty-run-forked-mojo-it/verify.groovy b/jetty-maven-plugin/src/it/jetty-run-forked-mojo-it/verify.groovy deleted file mode 100644 index e87b398c6ef..00000000000 --- a/jetty-maven-plugin/src/it/jetty-run-forked-mojo-it/verify.groovy +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -File buildLog = new File( basedir, 'build.log' ) -assert buildLog.text.contains( 'Forked process starting' ) -assert buildLog.text.contains( 'org.eclipse.jetty.its.jetty_run_forked_mojo_it.TestGetContent') \ No newline at end of file diff --git a/jetty-maven-plugin/src/it/jetty-run-mojo-it/jetty-simple-base/src/main/java/org/eclipse/jetty/its/jetty_run_mojo_it/HelloServlet.java b/jetty-maven-plugin/src/it/jetty-run-mojo-it/jetty-simple-base/src/main/java/org/eclipse/jetty/its/jetty_run_mojo_it/HelloServlet.java index 812cf60aa2e..1c093c1675c 100644 --- a/jetty-maven-plugin/src/it/jetty-run-mojo-it/jetty-simple-base/src/main/java/org/eclipse/jetty/its/jetty_run_mojo_it/HelloServlet.java +++ b/jetty-maven-plugin/src/it/jetty-run-mojo-it/jetty-simple-base/src/main/java/org/eclipse/jetty/its/jetty_run_mojo_it/HelloServlet.java @@ -40,6 +40,6 @@ public class HelloServlet { String who = req.getParameter( "name" ); - resp.getWriter().write( "hello " + (who == null ? "unknown" : who) ); + resp.getWriter().write( "Hello " + (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 df71841c32c..6a303b7d4a5 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 @@ -37,8 +37,10 @@ org.eclipse.jetty - jetty-client + jetty-maven-plugin @project.version@ + tests + test-jar test @@ -72,7 +74,12 @@ ${jetty.port.file} + true + true + + org.eclipse.jetty:jetty-maven-plugin + diff --git a/jetty-maven-plugin/src/it/jetty-run-mojo-it/jetty-simple-webapp/src/test/java/org/eclipse/jetty/its/jetty_run_mojo_it/TestGetContent.java b/jetty-maven-plugin/src/it/jetty-run-mojo-it/jetty-simple-webapp/src/test/java/org/eclipse/jetty/its/jetty_run_mojo_it/TestGetContent.java deleted file mode 100644 index 298262cac09..00000000000 --- a/jetty-maven-plugin/src/it/jetty-run-mojo-it/jetty-simple-webapp/src/test/java/org/eclipse/jetty/its/jetty_run_mojo_it/TestGetContent.java +++ /dev/null @@ -1,94 +0,0 @@ -// -// ======================================================================== -// Copyright (c) 1995-2018 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; - -import java.io.File; -import java.io.FileReader; -import java.io.LineNumberReader; - -import org.eclipse.jetty.client.HttpClient; -import org.junit.Assert; -import org.junit.Test; - -/** - * - */ -public class TestGetContent - -{ - @Test - public void get_ping_response() - throws Exception - { - - int port = getPort(); - Assert.assertTrue(port > 0); - HttpClient httpClient = new HttpClient(); - try - { - httpClient.start(); - - String response = httpClient.GET( "http://localhost:" + port + "/hello?name=beer" ).getContentAsString(); - - Assert.assertEquals( "hello beer", response.trim() ); - - response = httpClient.GET( "http://localhost:" + port + "/ping?name=beer" ).getContentAsString(); - - Assert.assertEquals( "pong beer", response.trim() ); - } - finally - { - httpClient.stop(); - } - } - - - public int getPort() - throws Exception - { - int attempts = 20; - int port = -1; - String s = System.getProperty("jetty.port.file"); - Assert.assertNotNull(s); - File f = new File(s); - while (true) - { - if (f.exists()) - { - try (FileReader r = new FileReader(f); - LineNumberReader lnr = new LineNumberReader(r); - ) - { - s = lnr.readLine(); - Assert.assertNotNull(s); - port = Integer.parseInt(s.trim()); - } - break; - } - else - { - if (--attempts < 0) - break; - else - Thread.currentThread().sleep(100); - } - } - return port; - } -} diff --git a/jetty-maven-plugin/src/it/jetty-run-war-mojo-it/verify.groovy b/jetty-maven-plugin/src/it/jetty-run-mojo-it/postbuild.groovy similarity index 81% rename from jetty-maven-plugin/src/it/jetty-run-war-mojo-it/verify.groovy rename to jetty-maven-plugin/src/it/jetty-run-mojo-it/postbuild.groovy index 6e5bbbaa2e0..323b5da5d72 100644 --- a/jetty-maven-plugin/src/it/jetty-run-war-mojo-it/verify.groovy +++ b/jetty-maven-plugin/src/it/jetty-run-mojo-it/postbuild.groovy @@ -18,4 +18,6 @@ */ File buildLog = new File( basedir, 'build.log' ) assert buildLog.text.contains( 'Started Jetty Server' ) -assert buildLog.text.contains( 'org.eclipse.jetty.its.jetty_run_war_mojo_it.TestGetContent') \ No newline at end of file +assert buildLog.text.contains( 'Running org.eclipse.jetty.maven.plugin.it.TestGetContent') +assert buildLog.text.contains( 'pingServlet ok') +assert buildLog.text.contains( 'helloServlet') \ No newline at end of file diff --git a/jetty-maven-plugin/src/it/jetty-run-war-exploded-mojo-it/jetty-simple-base/src/main/java/org/eclipse/jetty/its/jetty_run_war_exploded_mojo_it/HelloServlet.java b/jetty-maven-plugin/src/it/jetty-run-war-exploded-mojo-it/jetty-simple-base/src/main/java/org/eclipse/jetty/its/jetty_run_war_exploded_mojo_it/HelloServlet.java index d8639515858..0ab06680ecf 100644 --- a/jetty-maven-plugin/src/it/jetty-run-war-exploded-mojo-it/jetty-simple-base/src/main/java/org/eclipse/jetty/its/jetty_run_war_exploded_mojo_it/HelloServlet.java +++ b/jetty-maven-plugin/src/it/jetty-run-war-exploded-mojo-it/jetty-simple-base/src/main/java/org/eclipse/jetty/its/jetty_run_war_exploded_mojo_it/HelloServlet.java @@ -40,6 +40,6 @@ public class HelloServlet { String who = req.getParameter( "name" ); - resp.getWriter().write( "hello " + (who == null ? "unknown" : who) ); + resp.getWriter().write( "Hello " + (who == null ? "unknown" : who) ); } } diff --git a/jetty-maven-plugin/src/it/jetty-run-war-exploded-mojo-it/jetty-simple-webapp/pom.xml b/jetty-maven-plugin/src/it/jetty-run-war-exploded-mojo-it/jetty-simple-webapp/pom.xml index 770b3c1b2ba..c358b071e51 100644 --- a/jetty-maven-plugin/src/it/jetty-run-war-exploded-mojo-it/jetty-simple-webapp/pom.xml +++ b/jetty-maven-plugin/src/it/jetty-run-war-exploded-mojo-it/jetty-simple-webapp/pom.xml @@ -31,10 +31,13 @@ provided + org.eclipse.jetty - jetty-client + jetty-maven-plugin @project.version@ + tests + test-jar test @@ -67,9 +70,6 @@ @surefireVersion@ true - - ${jetty.port.file} - @@ -79,7 +79,12 @@ ${jetty.port.file} + true + true + + org.eclipse.jetty:jetty-maven-plugin + **/*TestGetContent* diff --git a/jetty-maven-plugin/src/it/jetty-run-war-exploded-mojo-it/jetty-simple-webapp/src/test/java/org/eclipse/jetty/its/jetty_run_war_exploded_mojo_it/TestGetContent.java b/jetty-maven-plugin/src/it/jetty-run-war-exploded-mojo-it/jetty-simple-webapp/src/test/java/org/eclipse/jetty/its/jetty_run_war_exploded_mojo_it/TestGetContent.java deleted file mode 100644 index 06bfd2c109c..00000000000 --- a/jetty-maven-plugin/src/it/jetty-run-war-exploded-mojo-it/jetty-simple-webapp/src/test/java/org/eclipse/jetty/its/jetty_run_war_exploded_mojo_it/TestGetContent.java +++ /dev/null @@ -1,94 +0,0 @@ -// -// ======================================================================== -// Copyright (c) 1995-2018 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_war_exploded_mojo_it; - -import java.io.File; -import java.io.FileReader; -import java.io.LineNumberReader; - -import org.eclipse.jetty.client.HttpClient; -import org.junit.Assert; -import org.junit.Test; - -/** - * - */ -public class TestGetContent - -{ - @Test - public void get_ping_response() - throws Exception - { - - int port = getPort(); - Assert.assertTrue(port > 0); - HttpClient httpClient = new HttpClient(); - try - { - httpClient.start(); - - String response = httpClient.GET( "http://localhost:" + port + "/hello?name=beer" ).getContentAsString(); - - Assert.assertEquals( "hello beer", response.trim() ); - - response = httpClient.GET( "http://localhost:" + port + "/ping?name=beer" ).getContentAsString(); - - Assert.assertEquals( "pong beer", response.trim() ); - } - finally - { - httpClient.stop(); - } - } - - - public int getPort() - throws Exception - { - int attempts = 20; - int port = -1; - String s = System.getProperty("jetty.port.file"); - Assert.assertNotNull(s); - File f = new File(s); - while (true) - { - if (f.exists()) - { - try (FileReader r = new FileReader(f); - LineNumberReader lnr = new LineNumberReader(r); - ) - { - s = lnr.readLine(); - Assert.assertNotNull(s); - port = Integer.parseInt(s.trim()); - } - break; - } - else - { - if (--attempts < 0) - break; - else - Thread.currentThread().sleep(100); - } - } - return port; - } -} diff --git a/jetty-maven-plugin/src/it/jetty-deploy-war-mojo-it/verify.groovy b/jetty-maven-plugin/src/it/jetty-run-war-exploded-mojo-it/postbuild.groovy similarity index 81% rename from jetty-maven-plugin/src/it/jetty-deploy-war-mojo-it/verify.groovy rename to jetty-maven-plugin/src/it/jetty-run-war-exploded-mojo-it/postbuild.groovy index cf5abbfb416..323b5da5d72 100644 --- a/jetty-maven-plugin/src/it/jetty-deploy-war-mojo-it/verify.groovy +++ b/jetty-maven-plugin/src/it/jetty-run-war-exploded-mojo-it/postbuild.groovy @@ -18,4 +18,6 @@ */ File buildLog = new File( basedir, 'build.log' ) assert buildLog.text.contains( 'Started Jetty Server' ) -assert buildLog.text.contains( 'Running org.eclipse.jetty.its.jetty_run_war_mojo_it.TestGetContent') \ No newline at end of file +assert buildLog.text.contains( 'Running org.eclipse.jetty.maven.plugin.it.TestGetContent') +assert buildLog.text.contains( 'pingServlet ok') +assert buildLog.text.contains( 'helloServlet') \ No newline at end of file diff --git a/jetty-maven-plugin/src/it/jetty-run-war-mojo-it/jetty-simple-base/src/main/java/org/eclipse/jetty/its/jetty_run_mojo_it/HelloServlet.java b/jetty-maven-plugin/src/it/jetty-run-war-mojo-it/jetty-simple-base/src/main/java/org/eclipse/jetty/its/jetty_run_mojo_it/HelloServlet.java index 812cf60aa2e..1c093c1675c 100644 --- a/jetty-maven-plugin/src/it/jetty-run-war-mojo-it/jetty-simple-base/src/main/java/org/eclipse/jetty/its/jetty_run_mojo_it/HelloServlet.java +++ b/jetty-maven-plugin/src/it/jetty-run-war-mojo-it/jetty-simple-base/src/main/java/org/eclipse/jetty/its/jetty_run_mojo_it/HelloServlet.java @@ -40,6 +40,6 @@ public class HelloServlet { String who = req.getParameter( "name" ); - resp.getWriter().write( "hello " + (who == null ? "unknown" : who) ); + resp.getWriter().write( "Hello " + (who == null ? "unknown" : who) ); } } diff --git a/jetty-maven-plugin/src/it/jetty-run-war-mojo-it/jetty-simple-webapp/pom.xml b/jetty-maven-plugin/src/it/jetty-run-war-mojo-it/jetty-simple-webapp/pom.xml index 7ca5716eda8..ca935f11364 100644 --- a/jetty-maven-plugin/src/it/jetty-run-war-mojo-it/jetty-simple-webapp/pom.xml +++ b/jetty-maven-plugin/src/it/jetty-run-war-mojo-it/jetty-simple-webapp/pom.xml @@ -35,8 +35,10 @@ org.eclipse.jetty - jetty-client + jetty-maven-plugin @project.version@ + tests + test-jar test @@ -69,9 +71,6 @@ @surefireVersion@ true - - ${jetty.port.file} - @@ -81,7 +80,12 @@ ${jetty.port.file} + true + true + + org.eclipse.jetty:jetty-maven-plugin + **/*TestGetContent* diff --git a/jetty-maven-plugin/src/it/jetty-run-war-mojo-it/jetty-simple-webapp/src/test/java/org/eclipse/jetty/its/jetty_run_war_mojo_it/TestGetContent.java b/jetty-maven-plugin/src/it/jetty-run-war-mojo-it/jetty-simple-webapp/src/test/java/org/eclipse/jetty/its/jetty_run_war_mojo_it/TestGetContent.java deleted file mode 100644 index 09a9d4abb79..00000000000 --- a/jetty-maven-plugin/src/it/jetty-run-war-mojo-it/jetty-simple-webapp/src/test/java/org/eclipse/jetty/its/jetty_run_war_mojo_it/TestGetContent.java +++ /dev/null @@ -1,94 +0,0 @@ -// -// ======================================================================== -// Copyright (c) 1995-2018 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_war_mojo_it; - -import java.io.File; -import java.io.FileReader; -import java.io.LineNumberReader; - -import org.eclipse.jetty.client.HttpClient; -import org.junit.Assert; -import org.junit.Test; - -/** - * - */ -public class TestGetContent - -{ - @Test - public void get_ping_response() - throws Exception - { - - int port = getPort(); - Assert.assertTrue(port > 0); - HttpClient httpClient = new HttpClient(); - try - { - httpClient.start(); - - String response = httpClient.GET( "http://localhost:" + port + "/hello?name=beer" ).getContentAsString(); - - Assert.assertEquals( "hello beer", response.trim() ); - - response = httpClient.GET( "http://localhost:" + port + "/ping?name=beer" ).getContentAsString(); - - Assert.assertEquals( "pong beer", response.trim() ); - } - finally - { - httpClient.stop(); - } - } - - - public int getPort() - throws Exception - { - int attempts = 20; - int port = -1; - String s = System.getProperty("jetty.port.file"); - Assert.assertNotNull(s); - File f = new File(s); - while (true) - { - if (f.exists()) - { - try (FileReader r = new FileReader(f); - LineNumberReader lnr = new LineNumberReader(r); - ) - { - s = lnr.readLine(); - Assert.assertNotNull(s); - port = Integer.parseInt(s.trim()); - } - break; - } - else - { - if (--attempts < 0) - break; - else - Thread.currentThread().sleep(100); - } - } - return port; - } -} diff --git a/jetty-maven-plugin/src/it/jetty-run-war-mojo-it/postbuild.groovy b/jetty-maven-plugin/src/it/jetty-run-war-mojo-it/postbuild.groovy new file mode 100644 index 00000000000..323b5da5d72 --- /dev/null +++ b/jetty-maven-plugin/src/it/jetty-run-war-mojo-it/postbuild.groovy @@ -0,0 +1,23 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +File buildLog = new File( basedir, 'build.log' ) +assert buildLog.text.contains( 'Started Jetty Server' ) +assert buildLog.text.contains( 'Running org.eclipse.jetty.maven.plugin.it.TestGetContent') +assert buildLog.text.contains( 'pingServlet ok') +assert buildLog.text.contains( 'helloServlet') \ No newline at end of file diff --git a/jetty-maven-plugin/src/it/jetty-start-mojo-it/jetty-simple-base/src/main/java/org/eclipse/jetty/its/jetty_start_mojo_it/HelloServlet.java b/jetty-maven-plugin/src/it/jetty-start-mojo-it/jetty-simple-base/src/main/java/org/eclipse/jetty/its/jetty_start_mojo_it/HelloServlet.java index eb0a54b6fc0..f2457ceea25 100644 --- a/jetty-maven-plugin/src/it/jetty-start-mojo-it/jetty-simple-base/src/main/java/org/eclipse/jetty/its/jetty_start_mojo_it/HelloServlet.java +++ b/jetty-maven-plugin/src/it/jetty-start-mojo-it/jetty-simple-base/src/main/java/org/eclipse/jetty/its/jetty_start_mojo_it/HelloServlet.java @@ -40,6 +40,6 @@ public class HelloServlet { String who = req.getParameter( "name" ); - resp.getWriter().write( "hello " + (who == null ? "unknown" : who) ); + resp.getWriter().write( "Hello " + (who == null ? "unknown" : who) ); } } diff --git a/jetty-maven-plugin/src/it/jetty-start-mojo-it/jetty-simple-webapp/pom.xml b/jetty-maven-plugin/src/it/jetty-start-mojo-it/jetty-simple-webapp/pom.xml index 7c0f1bc1b75..c269c46875b 100644 --- a/jetty-maven-plugin/src/it/jetty-start-mojo-it/jetty-simple-webapp/pom.xml +++ b/jetty-maven-plugin/src/it/jetty-start-mojo-it/jetty-simple-webapp/pom.xml @@ -33,8 +33,10 @@ org.eclipse.jetty - jetty-client + jetty-maven-plugin @project.version@ + tests + test-jar test @@ -68,7 +70,12 @@ ${jetty.port.file} + true + true + + org.eclipse.jetty:jetty-maven-plugin + diff --git a/jetty-maven-plugin/src/it/jetty-start-mojo-it/jetty-simple-webapp/src/test/java/org/eclipse/jetty/its/jetty_start_mojo_it/TestGetContent.java b/jetty-maven-plugin/src/it/jetty-start-mojo-it/jetty-simple-webapp/src/test/java/org/eclipse/jetty/its/jetty_start_mojo_it/TestGetContent.java deleted file mode 100644 index a0da6ee489c..00000000000 --- a/jetty-maven-plugin/src/it/jetty-start-mojo-it/jetty-simple-webapp/src/test/java/org/eclipse/jetty/its/jetty_start_mojo_it/TestGetContent.java +++ /dev/null @@ -1,94 +0,0 @@ -// -// ======================================================================== -// Copyright (c) 1995-2018 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_forked_mojo_it; - -import java.io.File; -import java.io.FileReader; -import java.io.LineNumberReader; - -import org.eclipse.jetty.client.HttpClient; -import org.junit.Assert; -import org.junit.Test; - -/** - * - */ -public class TestGetContent - -{ - @Test - public void get_ping_response() - throws Exception - { - - int port = getPort(); - Assert.assertTrue(port > 0); - HttpClient httpClient = new HttpClient(); - try - { - httpClient.start(); - - String response = httpClient.GET( "http://localhost:" + port + "/hello?name=beer" ).getContentAsString(); - - Assert.assertEquals( "hello beer", response.trim() ); - - response = httpClient.GET( "http://localhost:" + port + "/ping?name=beer" ).getContentAsString(); - - Assert.assertEquals( "pong beer", response.trim() ); - } - finally - { - httpClient.stop(); - } - } - - - public int getPort() - throws Exception - { - int attempts = 20; - int port = -1; - String s = System.getProperty("jetty.port.file"); - Assert.assertNotNull(s); - File f = new File(s); - while (true) - { - if (f.exists()) - { - try (FileReader r = new FileReader(f); - LineNumberReader lnr = new LineNumberReader(r); - ) - { - s = lnr.readLine(); - Assert.assertNotNull(s); - port = Integer.parseInt(s.trim()); - } - break; - } - else - { - if (--attempts < 0) - break; - else - Thread.currentThread().sleep(100); - } - } - return port; - } -} diff --git a/jetty-maven-plugin/src/it/jetty-start-mojo-it/postbuild.groovy b/jetty-maven-plugin/src/it/jetty-start-mojo-it/postbuild.groovy new file mode 100644 index 00000000000..323b5da5d72 --- /dev/null +++ b/jetty-maven-plugin/src/it/jetty-start-mojo-it/postbuild.groovy @@ -0,0 +1,23 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +File buildLog = new File( basedir, 'build.log' ) +assert buildLog.text.contains( 'Started Jetty Server' ) +assert buildLog.text.contains( 'Running org.eclipse.jetty.maven.plugin.it.TestGetContent') +assert buildLog.text.contains( 'pingServlet ok') +assert buildLog.text.contains( 'helloServlet') \ No newline at end of file diff --git a/jetty-maven-plugin/src/it/jetty-start-mojo-it/verify.groovy b/jetty-maven-plugin/src/it/jetty-start-mojo-it/verify.groovy deleted file mode 100644 index 960c599f90c..00000000000 --- a/jetty-maven-plugin/src/it/jetty-start-mojo-it/verify.groovy +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -File buildLog = new File( basedir, 'build.log' ) -assert buildLog.text.contains( 'Started Jetty Server' ) \ No newline at end of file diff --git a/jetty-maven-plugin/src/it/run-mojo-gwt-it/beer-server/pom.xml b/jetty-maven-plugin/src/it/run-mojo-gwt-it/beer-server/pom.xml index ba0ea68de2f..b921256af07 100644 --- a/jetty-maven-plugin/src/it/run-mojo-gwt-it/beer-server/pom.xml +++ b/jetty-maven-plugin/src/it/run-mojo-gwt-it/beer-server/pom.xml @@ -61,6 +61,14 @@ 4.12 test + + org.eclipse.jetty + jetty-maven-plugin + @project.version@ + tests + test-jar + test + @@ -72,7 +80,11 @@ ${jetty.port.file} + Please enter your name + + org.eclipse.jetty:jetty-maven-plugin + @@ -93,10 +105,6 @@ true - 1 - - ${basedir}/../beer-shared/target/classes/ - ${basedir}/src/main/jettyconf/context.xml ${basedir}/src/config/jetty.xml @@ -106,56 +114,4 @@ - - - - env-prod - - true - - - - ${project.groupId} - beer-client - ${project.version} - war - runtime - - - - - env-dev - - - env - dev - - - - - - - org.eclipse.jetty - jetty-maven-plugin - - - - ${basedir}/src/main/webapp - ${basedir}/../target/gwt/launcherDir/ - - - - - - org.apache.tomcat.maven - tomcat7-maven-plugin - - ${basedir}/src/main/tomcatconf/context.xml - - - - - - - diff --git a/jetty-maven-plugin/src/it/run-mojo-gwt-it/beer-server/src/test/java/org/olamy/TestGetContent.java b/jetty-maven-plugin/src/it/run-mojo-gwt-it/beer-server/src/test/java/org/olamy/TestGetContent.java deleted file mode 100644 index 63d2e5d97cd..00000000000 --- a/jetty-maven-plugin/src/it/run-mojo-gwt-it/beer-server/src/test/java/org/olamy/TestGetContent.java +++ /dev/null @@ -1,92 +0,0 @@ -// -// ======================================================================== -// Copyright (c) 1995-2018 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.olamy; - -import org.eclipse.jetty.client.HttpClient; -import org.junit.Assert; -import org.junit.Test; - -import java.io.File; -import java.io.FileReader; -import java.io.LineNumberReader; - -/** - * - */ -public class TestGetContent - -{ - @Test - public void get_root_response() - throws Exception - { - - int port = getPort(); - Assert.assertTrue(port > 0); - HttpClient httpClient = new HttpClient(); - try - { - httpClient.start(); - - String response = httpClient.GET( "http://localhost:" + port ).getContentAsString(); - - System.out.println( "response" + response ); - Assert.assertTrue( response.contains( "Please enter your name" ) ); - - } - finally - { - httpClient.stop(); - } - } - - - public int getPort() - throws Exception - { - int attempts = 20; - int port = -1; - String s = System.getProperty("jetty.port.file"); - Assert.assertNotNull(s); - File f = new File(s); - while (true) - { - if (f.exists()) - { - try (FileReader r = new FileReader(f); - LineNumberReader lnr = new LineNumberReader(r); - ) - { - s = lnr.readLine(); - Assert.assertNotNull(s); - port = Integer.parseInt(s.trim()); - } - break; - } - else - { - if (--attempts < 0) - break; - else - Thread.currentThread().sleep(100); - } - } - return port; - } -} diff --git a/jetty-maven-plugin/src/it/jetty-run-war-exploded-mojo-it/verify.groovy b/jetty-maven-plugin/src/it/run-mojo-gwt-it/postbuild.groovy similarity index 85% rename from jetty-maven-plugin/src/it/jetty-run-war-exploded-mojo-it/verify.groovy rename to jetty-maven-plugin/src/it/run-mojo-gwt-it/postbuild.groovy index 02aa23ef304..b5f4344c4a6 100644 --- a/jetty-maven-plugin/src/it/jetty-run-war-exploded-mojo-it/verify.groovy +++ b/jetty-maven-plugin/src/it/run-mojo-gwt-it/postbuild.groovy @@ -18,4 +18,5 @@ */ File buildLog = new File( basedir, 'build.log' ) assert buildLog.text.contains( 'Started Jetty Server' ) -assert buildLog.text.contains( 'org.eclipse.jetty.its.jetty_run_war_exploded_mojo_it.TestGetContent') \ No newline at end of file +assert buildLog.text.contains( 'Running org.eclipse.jetty.maven.plugin.it.TestGetContent') +assert buildLog.text.contains( 'contentCheck') \ No newline at end of file diff --git a/jetty-maven-plugin/src/it/run-mojo-gwt-it/verify.groovy b/jetty-maven-plugin/src/it/run-mojo-gwt-it/verify.groovy deleted file mode 100644 index 822aaae276a..00000000000 --- a/jetty-maven-plugin/src/it/run-mojo-gwt-it/verify.groovy +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -File buildLog = new File( basedir, 'build.log' ) -assert buildLog.text.contains( 'Started Jetty Server' ) -assert buildLog.text.contains( 'Running org.olamy.TestGetContent') \ No newline at end of file diff --git a/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/ServerConnectorListener.java b/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/ServerConnectorListener.java index 10bd2603a61..76f996d70ff 100644 --- a/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/ServerConnectorListener.java +++ b/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/ServerConnectorListener.java @@ -19,15 +19,17 @@ package org.eclipse.jetty.maven.plugin; -import java.io.File; -import java.io.FileWriter; -import java.nio.file.Files; -import java.nio.file.Path; - import org.eclipse.jetty.server.ServerConnector; import org.eclipse.jetty.util.component.AbstractLifeCycle.AbstractLifeCycleListener; import org.eclipse.jetty.util.component.LifeCycle; +import java.io.Writer; +import java.nio.file.AtomicMoveNotSupportedException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.nio.file.StandardCopyOption; + /** * ServerConnectorListener * @@ -50,20 +52,24 @@ public class ServerConnectorListener extends AbstractLifeCycleListener { if (getFileName() != null) { - File file = new File(getFileName()); try { - Files.deleteIfExists(file.toPath()); - } - catch (Exception e) - { - throw new RuntimeException (e); - } + Path tmp = Files.createTempFile( "jettyport", "tmp " ); + try (Writer writer = Files.newBufferedWriter( tmp )) + { + writer.write( String.valueOf( ( (ServerConnector) event ).getLocalPort() ) ); + } - try (FileWriter writer = new FileWriter(file)) - { - writer.write(String.valueOf(((ServerConnector)event).getLocalPort())); - writer.close(); + Path path = Paths.get(getFileName()); + Files.deleteIfExists(path); + try + { + Files.move( tmp, path, StandardCopyOption.ATOMIC_MOVE ); + } + catch ( AtomicMoveNotSupportedException e ) // can append on some os (windows).. so try again without the option + { + Files.move( tmp, path); + } } catch (Exception e) { 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 new file mode 100644 index 00000000000..56ddfdfe082 --- /dev/null +++ b/jetty-maven-plugin/src/test/java/org/eclipse/jetty/maven/plugin/it/TestGetContent.java @@ -0,0 +1,113 @@ +// +// ======================================================================== +// Copyright (c) 1995-2018 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.maven.plugin.it; + +import org.apache.commons.lang3.StringUtils; +import org.eclipse.jetty.client.HttpClient; +import org.junit.Assert; +import org.junit.Test; + +import java.io.LineNumberReader; +import java.io.Reader; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; + +/** + * + */ +public class TestGetContent +{ + @Test + public void get_content_response() + throws Exception + { + int port = getPort(); + Assert.assertTrue( port > 0 ); + HttpClient httpClient = new HttpClient(); + try + { + httpClient.start(); + + if (Boolean.getBoolean( "helloServlet" )) + { + String response = httpClient.GET( "http://localhost:" + port + "/hello?name=beer" ).getContentAsString(); + Assert.assertEquals( "Hello beer", response.trim() ); + response = httpClient.GET( "http://localhost:" + port + "/hello?name=foo" ).getContentAsString(); + Assert.assertEquals( "Hello foo", response.trim() ); + System.out.println( "helloServlet" ); + } + if (Boolean.getBoolean( "pingServlet" )) + { + System.out.println( "pingServlet ok" ); + String response = httpClient.GET( "http://localhost:" + port + "/ping?name=beer" ).getContentAsString(); + Assert.assertEquals( "pong beer", response.trim() ); + System.out.println( "pingServlet" ); + } + String contentCheck = System.getProperty( "contentCheck" ); + if(StringUtils.isNotBlank( contentCheck ) ) + { + String response = httpClient.GET( "http://localhost:" + port ).getContentAsString(); + Assert.assertTrue( "response not contentCheck: " + contentCheck + ", response:" + response, // + response.contains( contentCheck ) ); + System.out.println( "contentCheck" ); + } + } + finally + { + httpClient.stop(); + } + } + + + public static int getPort() + throws Exception + { + int attempts = 70; + int port = -1; + String s = System.getProperty( "jetty.port.file" ); + Assert.assertNotNull( s ); + Path p = Paths.get( s ); + while ( true ) + { + if ( Files.exists(p) ) + { + try (Reader r = Files.newBufferedReader( p ); LineNumberReader lnr = new LineNumberReader( r );) + { + s = lnr.readLine(); + Assert.assertNotNull( s ); + port = Integer.parseInt( s.trim() ); + } + break; + } + else + { + if ( --attempts < 0 ) + { + break; + } + else + { + Thread.currentThread().sleep( 100 ); + } + } + } + return port; + } +}