You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by rf...@apache.org on 2019/11/11 19:11:24 UTC
[maven-war-plugin] 01/01: Pull failOnMissingWebXml up (from WarMojo
to AbstractWarMojo). Propagate failOnMissingWebXml from AbstractWarMojo to
WarProjectPackagingTask::handleDeploymentDescriptors and use it to check if
it is false when webXml was set, but is not found.
This is an automated email from the ASF dual-hosted git repository.
rfscholte pushed a commit to branch MWAR-314
in repository https://gitbox.apache.org/repos/asf/maven-war-plugin.git
commit d98aee4b2c0e58c89f610f4fa1c613861c4cdcd1
Author: Andre Tadeu de Carvalho <an...@gmail.com>
AuthorDate: Mon Dec 31 17:19:14 2018 -0200
Pull failOnMissingWebXml up (from WarMojo to AbstractWarMojo). Propagate failOnMissingWebXml from AbstractWarMojo to WarProjectPackagingTask::handleDeploymentDescriptors and use it to check if it is false when webXml was set, but is not found.
---
src/it/MWAR-314/invoker.properties | 19 +++++++++++
src/it/MWAR-314/pom.xml | 39 ++++++++++++++++++++++
src/it/MWAR-314/src/main/webapp/index.jsp | 20 +++++++++++
.../apache/maven/plugins/war/AbstractWarMojo.java | 29 ++++++++++++++--
.../java/org/apache/maven/plugins/war/WarMojo.java | 13 --------
.../plugins/war/packaging/WarPackagingContext.java | 7 ++++
.../war/packaging/WarProjectPackagingTask.java | 16 ++++++---
7 files changed, 123 insertions(+), 20 deletions(-)
diff --git a/src/it/MWAR-314/invoker.properties b/src/it/MWAR-314/invoker.properties
new file mode 100644
index 0000000..692791c
--- /dev/null
+++ b/src/it/MWAR-314/invoker.properties
@@ -0,0 +1,19 @@
+# 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.
+
+invoker.goals=clean package
+invoker.debug = true
diff --git a/src/it/MWAR-314/pom.xml b/src/it/MWAR-314/pom.xml
new file mode 100644
index 0000000..da9ef17
--- /dev/null
+++ b/src/it/MWAR-314/pom.xml
@@ -0,0 +1,39 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+<!--
+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.
+-->
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>mwar314</groupId>
+ <artifactId>mwar314</artifactId>
+ <version>0.0.1-SNAPSHOT</version>
+ <packaging>war</packaging>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-war-plugin</artifactId>
+ <version>@project.version@</version>
+ <configuration>
+ <failOnMissingWebXml>false</failOnMissingWebXml>
+ <webXml>src/main/webapp/WEB-INF/web.xml</webXml>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
\ No newline at end of file
diff --git a/src/it/MWAR-314/src/main/webapp/index.jsp b/src/it/MWAR-314/src/main/webapp/index.jsp
new file mode 100644
index 0000000..41db44e
--- /dev/null
+++ b/src/it/MWAR-314/src/main/webapp/index.jsp
@@ -0,0 +1,20 @@
+<%--
+ ~ 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.
+ --%>
+
+<% response.sendRedirect( request.getContextPath() + "/groupSummary.action" ); %>
diff --git a/src/main/java/org/apache/maven/plugins/war/AbstractWarMojo.java b/src/main/java/org/apache/maven/plugins/war/AbstractWarMojo.java
index 4721d6b..6108d47 100644
--- a/src/main/java/org/apache/maven/plugins/war/AbstractWarMojo.java
+++ b/src/main/java/org/apache/maven/plugins/war/AbstractWarMojo.java
@@ -70,6 +70,18 @@ public abstract class AbstractWarMojo
private static final String META_INF = "META-INF";
private static final String WEB_INF = "WEB-INF";
+ /**
+ * Whether or not to fail the build if the <code>web.xml</code> file is missing. Set to <code>false</code> if you
+ * want your WAR built without a <code>web.xml</code> file. This may be useful if you are building an overlay that
+ * has no web.xml file.
+ * <p>
+ * Starting with <b>3.1.0</b>, this property defaults to <code>false</code> if the project depends on the Servlet
+ * 3.0 API or newer.
+ *
+ * @since 2.1-alpha-2
+ */
+ @Parameter
+ protected Boolean failOnMissingWebXml;
/**
* The Maven project.
@@ -490,7 +502,7 @@ public abstract class AbstractWarMojo
final WarPackagingContext context =
new DefaultWarPackagingContext( webapplicationDirectory, structure, overlayManager, defaultFilterWrappers,
getNonFilteredFileExtensions(), filteringDeploymentDescriptors,
- this.artifactFactory, resourceEncoding, useJvmChmod );
+ this.artifactFactory, resourceEncoding, useJvmChmod, failOnMissingWebXml );
final List<WarPackagingTask> packagingTasks = getPackagingTasks( overlayManager );
@@ -558,6 +570,8 @@ public abstract class AbstractWarMojo
private boolean useJvmChmod = true;
+ private final Boolean failOnMissingWebXml;
+
private final Collection<String> outdatedResources;
/**
@@ -570,13 +584,15 @@ public abstract class AbstractWarMojo
* @param artifactFactory The artifact factory.
* @param resourceEncoding The resource encoding.
* @param useJvmChmod use Jvm chmod or not.
+ * @param failOnMissingWebXml Flag to check whether we should ignore missing web.xml or not
*/
DefaultWarPackagingContext( final File webappDirectory, final WebappStructure webappStructure,
final OverlayManager overlayManager,
List<FileUtils.FilterWrapper> filterWrappers,
List<String> nonFilteredFileExtensions,
boolean filteringDeploymentDescriptors, ArtifactFactory artifactFactory,
- String resourceEncoding, boolean useJvmChmod )
+ String resourceEncoding, boolean useJvmChmod,
+ final Boolean failOnMissingWebXml )
{
this.webappDirectory = webappDirectory;
this.webappStructure = webappStructure;
@@ -594,6 +610,7 @@ public abstract class AbstractWarMojo
webappStructure.getStructure( overlayId );
}
this.useJvmChmod = useJvmChmod;
+ this.failOnMissingWebXml = failOnMissingWebXml;
if ( !webappDirectory.exists() )
{
@@ -777,6 +794,14 @@ public abstract class AbstractWarMojo
return useJvmChmod;
}
+ /**
+ * {@inheritDoc}
+ */
+ public Boolean isFailOnMissingWebXml()
+ {
+ return failOnMissingWebXml;
+ }
+
@Override
public Collection<String> getOutdatedResources()
{
diff --git a/src/main/java/org/apache/maven/plugins/war/WarMojo.java b/src/main/java/org/apache/maven/plugins/war/WarMojo.java
index 966d903..c7e7620 100644
--- a/src/main/java/org/apache/maven/plugins/war/WarMojo.java
+++ b/src/main/java/org/apache/maven/plugins/war/WarMojo.java
@@ -116,19 +116,6 @@ public class WarMojo
private boolean primaryArtifact;
/**
- * Whether or not to fail the build if the <code>web.xml</code> file is missing. Set to <code>false</code> if you
- * want your WAR built without a <code>web.xml</code> file. This may be useful if you are building an overlay that
- * has no web.xml file.
- * <p>
- * Starting with <b>3.1.0</b>, this property defaults to <code>false</code> if the project depends on the Servlet
- * 3.0 API or newer.
- *
- * @since 2.1-alpha-2
- */
- @Parameter
- private Boolean failOnMissingWebXml;
-
- /**
* Whether classes (that is the content of the WEB-INF/classes directory) should be attached to the project as an
* additional artifact.
* <p>
diff --git a/src/main/java/org/apache/maven/plugins/war/packaging/WarPackagingContext.java b/src/main/java/org/apache/maven/plugins/war/packaging/WarPackagingContext.java
index ee29466..e85cca5 100644
--- a/src/main/java/org/apache/maven/plugins/war/packaging/WarPackagingContext.java
+++ b/src/main/java/org/apache/maven/plugins/war/packaging/WarPackagingContext.java
@@ -216,6 +216,13 @@ public interface WarPackagingContext
boolean isUseJvmChmod();
/**
+ * Returns the flag that switch on/off the missing web.xml validation
+ *
+ * @return failOnMissingWebXml
+ */
+ Boolean isFailOnMissingWebXml();
+
+ /**
* Used to keep track of existing resources and all copied files.
* All others are outdated and should be removed.
* This prevent calling <code>clean</code> when resources are removed.
diff --git a/src/main/java/org/apache/maven/plugins/war/packaging/WarProjectPackagingTask.java b/src/main/java/org/apache/maven/plugins/war/packaging/WarProjectPackagingTask.java
index a1476ec..a01e88b 100644
--- a/src/main/java/org/apache/maven/plugins/war/packaging/WarProjectPackagingTask.java
+++ b/src/main/java/org/apache/maven/plugins/war/packaging/WarProjectPackagingTask.java
@@ -106,7 +106,7 @@ public class WarProjectPackagingTask
}
context.getLog().debug( "-- end of dump --" );
- handleDeploymentDescriptors( context, webinfDir, metainfDir );
+ handleDeploymentDescriptors( context, webinfDir, metainfDir, context.isFailOnMissingWebXml() );
handleClassesDirectory( context );
@@ -228,17 +228,20 @@ public class WarProjectPackagingTask
* @param context the packaging context
* @param webinfDir the web-inf directory
* @param metainfDir the meta-inf directory
- * @throws MojoFailureException if the web.xml is specified but does not exist
+ * @param failOnMissingWebXml if build should fail if web.xml is not found
+ * @throws MojoFailureException if the web.xml is specified but does not exist and failOnMissingWebXml is true
* @throws MojoExecutionException if an error occurred while copying the descriptors
*/
- protected void handleDeploymentDescriptors( WarPackagingContext context, File webinfDir, File metainfDir )
+ protected void handleDeploymentDescriptors( WarPackagingContext context, File webinfDir, File metainfDir,
+ Boolean failOnMissingWebXml )
throws MojoFailureException, MojoExecutionException
{
try
{
if ( webXml != null && StringUtils.isNotEmpty( webXml.getName() ) )
{
- if ( !webXml.exists() )
+ if ( !webXml.exists()
+ && ( failOnMissingWebXml == null || Boolean.TRUE.equals( failOnMissingWebXml ) ) )
{
throw new MojoFailureException( "The specified web.xml file '" + webXml + "' does not exist" );
}
@@ -290,7 +293,10 @@ public class WarProjectPackagingTask
}
catch ( IOException e )
{
- throw new MojoExecutionException( "Failed to copy deployment descriptor", e );
+ if ( failOnMissingWebXml == null || Boolean.TRUE.equals( failOnMissingWebXml ) )
+ {
+ throw new MojoExecutionException( "Failed to copy deployment descriptor", e );
+ }
}
catch ( MavenFilteringException e )
{