From cfe7fa1cb2d418e01405b7a76063a9ab85704839 Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Tue, 18 Sep 2018 21:17:25 +1000 Subject: [PATCH] Issue #2906 excluded reactor projects with provided scope (#2914) * Issue #2906 excluded reactor projects with provided scope Signed-off-by: olivier lamy * avoid test project within reactors to be in the classpath Signed-off-by: olivier lamy --- .../src/it/it-parent-pom/pom.xml | 1 + .../api/pom.xml | 12 ++++ .../api/src/main/java/test/Api.java | 28 +++++++++ .../invoker.properties | 2 + .../pom.xml | 22 +++++++ .../postbuild.groovy | 21 +++++++ .../web/pom.xml | 58 +++++++++++++++++++ .../web/src/config/jetty.xml | 48 +++++++++++++++ ...sLoadingTestingServletContextListener.java | 49 ++++++++++++++++ .../jetty/maven/plugin/JettyRunMojo.java | 15 +++-- 10 files changed, 248 insertions(+), 8 deletions(-) create mode 100755 jetty-maven-plugin/src/it/jetty-maven-plugin-provided-module-dep/api/pom.xml create mode 100755 jetty-maven-plugin/src/it/jetty-maven-plugin-provided-module-dep/api/src/main/java/test/Api.java create mode 100644 jetty-maven-plugin/src/it/jetty-maven-plugin-provided-module-dep/invoker.properties create mode 100755 jetty-maven-plugin/src/it/jetty-maven-plugin-provided-module-dep/pom.xml create mode 100644 jetty-maven-plugin/src/it/jetty-maven-plugin-provided-module-dep/postbuild.groovy create mode 100755 jetty-maven-plugin/src/it/jetty-maven-plugin-provided-module-dep/web/pom.xml create mode 100644 jetty-maven-plugin/src/it/jetty-maven-plugin-provided-module-dep/web/src/config/jetty.xml create mode 100755 jetty-maven-plugin/src/it/jetty-maven-plugin-provided-module-dep/web/src/main/java/test/ClassLoadingTestingServletContextListener.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 ffffdf384e7..a58f3a3bc4c 100644 --- a/jetty-maven-plugin/src/it/it-parent-pom/pom.xml +++ b/jetty-maven-plugin/src/it/it-parent-pom/pom.xml @@ -10,6 +10,7 @@ @project.version@ + UTF-8 diff --git a/jetty-maven-plugin/src/it/jetty-maven-plugin-provided-module-dep/api/pom.xml b/jetty-maven-plugin/src/it/jetty-maven-plugin-provided-module-dep/api/pom.xml new file mode 100755 index 00000000000..3bd331ee290 --- /dev/null +++ b/jetty-maven-plugin/src/it/jetty-maven-plugin-provided-module-dep/api/pom.xml @@ -0,0 +1,12 @@ + + 4.0.0 + + + test.jetty-maven-plugin-provided-module-dep + parent + 1.0-SNAPSHOT + + api + + diff --git a/jetty-maven-plugin/src/it/jetty-maven-plugin-provided-module-dep/api/src/main/java/test/Api.java b/jetty-maven-plugin/src/it/jetty-maven-plugin-provided-module-dep/api/src/main/java/test/Api.java new file mode 100755 index 00000000000..fc5ad794a23 --- /dev/null +++ b/jetty-maven-plugin/src/it/jetty-maven-plugin-provided-module-dep/api/src/main/java/test/Api.java @@ -0,0 +1,28 @@ +// +// ======================================================================== +// 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; + +public class Api +{ + + public void noOp() + { + } +} \ No newline at end of file diff --git a/jetty-maven-plugin/src/it/jetty-maven-plugin-provided-module-dep/invoker.properties b/jetty-maven-plugin/src/it/jetty-maven-plugin-provided-module-dep/invoker.properties new file mode 100644 index 00000000000..816c3f38def --- /dev/null +++ b/jetty-maven-plugin/src/it/jetty-maven-plugin-provided-module-dep/invoker.properties @@ -0,0 +1,2 @@ +invoker.goals = verify -V -e +#test-compile failsafe:integration-test \ No newline at end of file diff --git a/jetty-maven-plugin/src/it/jetty-maven-plugin-provided-module-dep/pom.xml b/jetty-maven-plugin/src/it/jetty-maven-plugin-provided-module-dep/pom.xml new file mode 100755 index 00000000000..6546cb87f21 --- /dev/null +++ b/jetty-maven-plugin/src/it/jetty-maven-plugin-provided-module-dep/pom.xml @@ -0,0 +1,22 @@ + + 4.0.0 + + + org.eclipse.jetty.its + it-parent-pom + 0.0.1-SNAPSHOT + + + test.jetty-maven-plugin-provided-module-dep + parent + 1.0-SNAPSHOT + pom + + + + api + web + + + diff --git a/jetty-maven-plugin/src/it/jetty-maven-plugin-provided-module-dep/postbuild.groovy b/jetty-maven-plugin/src/it/jetty-maven-plugin-provided-module-dep/postbuild.groovy new file mode 100644 index 00000000000..4c12de49d83 --- /dev/null +++ b/jetty-maven-plugin/src/it/jetty-maven-plugin-provided-module-dep/postbuild.groovy @@ -0,0 +1,21 @@ +/* + * 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( 'ClassNotFoundException') \ No newline at end of file diff --git a/jetty-maven-plugin/src/it/jetty-maven-plugin-provided-module-dep/web/pom.xml b/jetty-maven-plugin/src/it/jetty-maven-plugin-provided-module-dep/web/pom.xml new file mode 100755 index 00000000000..22b6754fa9e --- /dev/null +++ b/jetty-maven-plugin/src/it/jetty-maven-plugin-provided-module-dep/web/pom.xml @@ -0,0 +1,58 @@ + + 4.0.0 + + + test.jetty-maven-plugin-provided-module-dep + parent + 1.0-SNAPSHOT + + web + war + + + + ${project.groupId} + api + ${project.version} + provided + + + javax.servlet + javax.servlet-api + provided + + + + + + + org.apache.maven.plugins + maven-war-plugin + + false + + + + + + + org.eclipse.jetty + jetty-maven-plugin + + + start-jetty + test-compile + + start + + + true + ${basedir}/src/config/jetty.xml + + + + + + + diff --git a/jetty-maven-plugin/src/it/jetty-maven-plugin-provided-module-dep/web/src/config/jetty.xml b/jetty-maven-plugin/src/it/jetty-maven-plugin-provided-module-dep/web/src/config/jetty.xml new file mode 100644 index 00000000000..2a17fe49cd7 --- /dev/null +++ b/jetty-maven-plugin/src/it/jetty-maven-plugin-provided-module-dep/web/src/config/jetty.xml @@ -0,0 +1,48 @@ + + + + + + https + + + + 32768 + 8192 + 8192 + 4096 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 0 + + 30000 + + + + diff --git a/jetty-maven-plugin/src/it/jetty-maven-plugin-provided-module-dep/web/src/main/java/test/ClassLoadingTestingServletContextListener.java b/jetty-maven-plugin/src/it/jetty-maven-plugin-provided-module-dep/web/src/main/java/test/ClassLoadingTestingServletContextListener.java new file mode 100755 index 00000000000..8d22ee0a6e3 --- /dev/null +++ b/jetty-maven-plugin/src/it/jetty-maven-plugin-provided-module-dep/web/src/main/java/test/ClassLoadingTestingServletContextListener.java @@ -0,0 +1,49 @@ +// +// ======================================================================== +// 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 javax.servlet.ServletContextEvent; +import javax.servlet.ServletContextListener; +import javax.servlet.annotation.WebListener; + +@WebListener +public class ClassLoadingTestingServletContextListener + implements ServletContextListener +{ + + @Override + public void contextInitialized( ServletContextEvent sce ) + { + try + { + Api api = new Api(); + } + catch ( java.lang.Exception exception ) + { + exception.printStackTrace(); + } + //System.out.println("Class " + api.getClass().getName() + " is available and loaded by classloader " + api.getClass().getClassLoader().toString() + ". Expected ClassNotFoundException."); + } + + @Override + public void contextDestroyed( ServletContextEvent sce ) + { + } +} \ No newline at end of file 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 feffd9547f3..a29d5beb2fb 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 @@ -532,9 +532,14 @@ public class JettyRunMojo extends AbstractJettyMojo { // 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 param) + + if (Artifact.SCOPE_TEST.equals(artifact.getScope()) && !useTestScope) + continue; //only add dependencies of scope=test if explicitly required + MavenProject mavenProject = getProjectReference( artifact, project ); if (mavenProject != null) { @@ -544,12 +549,6 @@ public class JettyRunMojo extends AbstractJettyMojo continue; } - if (Artifact.SCOPE_PROVIDED.equals(artifact.getScope())) - continue; //never add dependencies of scope=provided to the webapp's classpath (see also param) - - if (Artifact.SCOPE_TEST.equals(artifact.getScope()) && !useTestScope) - continue; //only add dependencies of scope=test if explicitly required - dependencyFiles.add(artifact.getFile()); getLog().debug( "Adding artifact " + artifact.getFile().getName() + " with scope "+artifact.getScope()+" for WEB-INF/lib " ); }