Skip to content

Commit

Permalink
[MWAR-441] add outdatedCheckPath=/ to cover everything in the web app
Browse files Browse the repository at this point in the history
  • Loading branch information
scottkurz authored and hboutemy committed May 9, 2021
1 parent a77ff81 commit 17e71f8
Show file tree
Hide file tree
Showing 6 changed files with 185 additions and 3 deletions.
20 changes: 20 additions & 0 deletions src/it/MWAR-441/invoker.properties
@@ -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.

invoker.goals.1=package
invoker.goals.2=groovy:execute
invoker.goals.3=package
87 changes: 87 additions & 0 deletions src/it/MWAR-441/pom.xml
@@ -0,0 +1,87 @@
<?xml version="1.0" encoding="UTF-8"?>

<!--
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.
-->

<project>
<modelVersion>4.0.0</modelVersion>

<groupId>org.apache.maven.its.war</groupId>
<artifactId>mwar427</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>@project.version@</version>
<configuration>
<archiveClasses>true</archiveClasses>
<outdatedCheckPath>/</outdatedCheckPath>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.gmaven</groupId>
<artifactId>groovy-maven-plugin</artifactId>
<version>2.0</version>
<configuration>
<source>
def fileToModify = new File(project.basedir, 'pom.xml')
processFileInplace(fileToModify) { text ->
text.replaceAll(/1.4.6/,'1.4.5')
}
def processFileInplace(file, Closure processText) {
file.write(processText(file.text))
}
new File('src/main/webapp/root.html').renameTo 'src/main/webapp/index.html'
</source>
</configuration>
<dependencies>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>2.4.21</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>

<dependencies>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-utils</artifactId>
<version>1.4.6</version>
</dependency>
</dependencies>

</project>
16 changes: 16 additions & 0 deletions src/it/MWAR-441/src/main/resources/resource.txt
@@ -0,0 +1,16 @@
# 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.
23 changes: 23 additions & 0 deletions src/it/MWAR-441/src/main/webapp/root.html
@@ -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.
-->
<html>
<body>
Hello World
</body>
</html>
26 changes: 26 additions & 0 deletions src/it/MWAR-441/verify.groovy
@@ -0,0 +1,26 @@
/*
* 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.
*/

def warFile = new java.util.jar.JarFile( new File(basedir,"target/mwar427-1.0-SNAPSHOT.war"), false)
assert warFile.getEntry('WEB-INF/lib/plexus-utils-1.4.5.jar') != null
assert warFile.getEntry('WEB-INF/lib/mwar427-1.0-SNAPSHOT.jar') != null
assert warFile.getEntry('index.html') != null

assert warFile.getEntry('WEB-INF/lib/plexus-utils-1.4.6.jar') == null
assert warFile.getEntry('root.html') == null // after MWAR-441, this path is also removed as outdated (with the '/' config in the pom).
16 changes: 13 additions & 3 deletions src/main/java/org/apache/maven/plugins/war/AbstractWarMojo.java
Expand Up @@ -365,6 +365,9 @@ public abstract class AbstractWarMojo
/**
* Path prefix for resources that will be checked against outdated content.
*
* Starting with <b>3.3.2</b>, if a value of "/" is specified the entire
* webappDirectory will be checked, i.e. the "/" signifies "root".
*
* @since 3.3.1
*/
@Parameter( defaultValue = "WEB-INF/lib/" )
Expand Down Expand Up @@ -650,7 +653,10 @@ else if ( getWarSourceDirectory().toPath().equals( webappDirectory.toPath() ) )
{
if ( '\\' == File.separatorChar )
{
outdatedCheckPath = outdatedCheckPath.replace( '/', '\\' );
if ( ! checkAllPathsForOutdated() )
{
outdatedCheckPath = outdatedCheckPath.replace( '/', '\\' );
}
}
Files.walkFileTree( webappDirectory.toPath(), new SimpleFileVisitor<Path>()
{
Expand All @@ -660,9 +666,8 @@ public FileVisitResult visitFile( Path file, BasicFileAttributes attrs )
{
if ( file.toFile().lastModified() < session.getStartTime().getTime() )
{
// resource older than session build start
String path = webappDirectory.toPath().relativize( file ).toString();
if ( path.startsWith( outdatedCheckPath ) )
if ( checkAllPathsForOutdated() || path.startsWith( outdatedCheckPath ) )
{
outdatedResources.add( path );
}
Expand All @@ -679,6 +684,11 @@ public FileVisitResult visitFile( Path file, BasicFileAttributes attrs )
this.outputTimestamp = outputTimestamp;
}

protected boolean checkAllPathsForOutdated()
{
return outdatedCheckPath.equals( "/" );
}

@Override
public MavenProject getProject()
{
Expand Down

0 comments on commit 17e71f8

Please sign in to comment.