Skip to content
Permalink
Browse files

Pull failOnMissingWebXml up (from WarMojo to AbstractWarMojo). Propag…

…ate failOnMissingWebXml from AbstractWarMojo to WarProjectPackagingTask::handleDeploymentDescriptors and use it to check if it is false when webXml was set, but is not found.
  • Loading branch information
andretadeu authored and rfscholte committed Dec 31, 2018
1 parent 88731b2 commit d98aee4b2c0e58c89f610f4fa1c613861c4cdcd1
@@ -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
@@ -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>
@@ -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" ); %>
@@ -70,6 +70,18 @@
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 void buildWebapp( MavenProject mavenProject, File webapplicationDirectory
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 void buildWebapp( MavenProject mavenProject, File webapplicationDirectory

private boolean useJvmChmod = true;

private final Boolean failOnMissingWebXml;

private final Collection<String> outdatedResources;

/**
@@ -570,13 +584,15 @@ public void buildWebapp( MavenProject mavenProject, File webapplicationDirectory
* @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 void buildWebapp( MavenProject mavenProject, File webapplicationDirectory
webappStructure.getStructure( overlayId );
}
this.useJvmChmod = useJvmChmod;
this.failOnMissingWebXml = failOnMissingWebXml;

if ( !webappDirectory.exists() )
{
@@ -777,6 +794,14 @@ public boolean isUseJvmChmod()
return useJvmChmod;
}

/**
* {@inheritDoc}
*/
public Boolean isFailOnMissingWebXml()
{
return failOnMissingWebXml;
}

@Override
public Collection<String> getOutdatedResources()
{
@@ -115,19 +115,6 @@
@Parameter( defaultValue = "true" )
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.
@@ -215,6 +215,13 @@
*/
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.
@@ -106,7 +106,7 @@ public void performPackaging( WarPackagingContext context )
}
context.getLog().debug( "-- end of dump --" );

handleDeploymentDescriptors( context, webinfDir, metainfDir );
handleDeploymentDescriptors( context, webinfDir, metainfDir, context.isFailOnMissingWebXml() );

handleClassesDirectory( context );

@@ -228,17 +228,20 @@ protected void handleClassesDirectory( WarPackagingContext context )
* @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 @@ protected void handleDeploymentDescriptors( WarPackagingContext context, File we
}
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 )
{

0 comments on commit d98aee4

Please sign in to comment.
You can’t perform that action at this time.