diff --git a/Java-base/maven-war-plugin/Dockerfile b/Java-base/maven-war-plugin/Dockerfile new file mode 100644 index 000000000..e208c4890 --- /dev/null +++ b/Java-base/maven-war-plugin/Dockerfile @@ -0,0 +1,28 @@ +FROM ubuntu:22.04 + +RUN export DEBIAN_FRONTEND=noninteractive \ + && apt-get update \ + && apt-get install -y software-properties-common \ + && add-apt-repository ppa:deadsnakes/ppa \ + && apt-get update \ + && apt-get install -y \ + build-essential \ + git \ + vim \ + jq \ + && apt-get autoremove -y && apt-get clean -y && rm -rf /var/lib/apt/list/* + +RUN apt-get -y install sudo \ + openjdk-8-jdk \ + maven + +RUN bash -c "echo 2 | update-alternatives --config java" + +COPY src /workspace +WORKDIR /workspace + +RUN mvn install -V -B -Denforcer.skip=true -Dcheckstyle.skip=true -Dcobertura.skip=true -Drat.skip=true -Dlicense.skip=true -Dfindbugs.skip=true -Dgpg.skip=true -Dskip.npm=true -Dskip.gulp=true -Dskip.bower=true -Drat.numUnapprovedLicenses=100 -DskipTests=true -DskipITs=true -Dtest=None -DfailIfNoTests=false + +RUN mvn test -V -B -Denforcer.skip=true -Dcheckstyle.skip=true -Dcobertura.skip=true -Drat.skip=true -Dlicense.skip=true -Dfindbugs.skip=true -Dgpg.skip=true -Dskip.npm=true -Dskip.gulp=true -Dskip.bower=true -Drat.numUnapprovedLicenses=100 + +ENV TZ=Asia/Seoul diff --git a/Java-base/maven-war-plugin/src/Jenkinsfile b/Java-base/maven-war-plugin/src/Jenkinsfile new file mode 100644 index 000000000..e9f05f7d9 --- /dev/null +++ b/Java-base/maven-war-plugin/src/Jenkinsfile @@ -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. + */ + +asfMavenTlpPlgnBuild() diff --git a/Java-base/maven-war-plugin/src/README.md b/Java-base/maven-war-plugin/src/README.md new file mode 100644 index 000000000..19bf10233 --- /dev/null +++ b/Java-base/maven-war-plugin/src/README.md @@ -0,0 +1,99 @@ + +Contributing to [Apache Maven WAR Plugin](https://maven.apache.org/plugins/maven-war-plugin/) +====================== + +[![ASF Jira](https://img.shields.io/endpoint?url=https%3A%2F%2Fmaven.apache.org%2Fbadges%2Fasf_jira-MWAR.json)][jira] +[![Apache License, Version 2.0, January 2004](https://img.shields.io/github/license/apache/maven.svg?label=License)][license] +[![Maven Central](https://img.shields.io/maven-central/v/org.apache.maven.plugins/maven-war-plugin.svg?label=Maven%20Central)](https://search.maven.org/artifact/org.apache.maven.plugins/maven-war-plugin) +[![Jenkins Status](https://img.shields.io/jenkins/s/https/builds.apache.org/job/maven-box/job/maven-war-plugin/job/master.svg?)][build] +[![Jenkins tests](https://img.shields.io/jenkins/t/https/builds.apache.org/job/maven-box/job/maven-war-plugin/job/master.svg?)][test-results] + + +You have found a bug or you have an idea for a cool new feature? Contributing +code is a great way to give something back to the open source community. Before +you dig right into the code, there are a few guidelines that we need +contributors to follow so that we can have a chance of keeping on top of +things. + +Getting Started +--------------- + ++ Make sure you have a [JIRA account](https://issues.apache.org/jira/). ++ Make sure you have a [GitHub account](https://github.com/signup/free). ++ If you're planning to implement a new feature, it makes sense to discuss your changes + on the [dev list][ml-list] first. + This way you can make sure you're not wasting your time on something that isn't + considered to be in Apache Maven's scope. ++ Submit a ticket for your issue, assuming one does not already exist. + + Clearly describe the issue, including steps to reproduce when it is a bug. + + Make sure you fill in the earliest version that you know has the issue. ++ Fork the repository on GitHub. + +Making and Submitting Changes +-------------- + +We accept Pull Requests via GitHub. The [developer mailing list][ml-list] is the +main channel of communication for contributors. +There are some guidelines which will make applying PRs easier for us: ++ Create a topic branch from where you want to base your work (this is usually the master branch). + Push your changes to a topic branch in your fork of the repository. ++ Make commits of logical units. ++ Respect the original code style: by using the same [codestyle][code-style], + patches should only highlight the actual difference, not being disturbed by any formatting issues: + + Only use spaces for indentation. + + Create minimal diffs - disable on save actions like reformat source code or organize imports. + If you feel the source code should be reformatted, create a separate PR for this change. + + Check for unnecessary whitespace with `git diff --check` before committing. ++ Make sure your commit messages are in the proper format. Your commit message should contain the key of the JIRA issue. +``` +[MWAR-XXX] - Subject of the JIRA Ticket + Optional supplemental description. +``` ++ Make sure you have added the necessary tests (JUnit/IT) for your changes. ++ Run all the tests with `mvn -Prun-its verify` to assure nothing else was accidentally broken. ++ Submit a pull request to the repository in the Apache organization. ++ Update your JIRA ticket and include a link to the pull request in the ticket. + +If you plan to contribute on a regular basis, please consider filing a [contributor license agreement][cla]. + +Making Trivial Changes +---------------------- + +For changes of a trivial nature to comments and documentation, it is not always +necessary to create a new ticket in JIRA. In this case, it is appropriate to +start the first line of a commit with '(doc)' instead of a ticket number. + +Additional Resources +-------------------- + ++ [Contributing patches](https://maven.apache.org/guides/development/guide-maven-development.html#Creating_and_submitting_a_patch) ++ [Apache Maven WAR JIRA project page][jira] ++ [Contributor License Agreement][cla] ++ [General GitHub documentation](https://help.github.com/) ++ [GitHub pull request documentation](https://help.github.com/send-pull-requests/) ++ [Apache Maven Twitter Account](https://twitter.com/ASFMavenProject) ++ #Maven IRC channel on freenode.org + +[jira]: https://issues.apache.org/jira/projects/MWAR/ +[license]: https://www.apache.org/licenses/LICENSE-2.0 +[ml-list]: https://maven.apache.org/mailing-lists.html +[code-style]: https://maven.apache.org/developers/conventions/code.html +[cla]: https://www.apache.org/licenses/#clas +[maven-wiki]: https://cwiki.apache.org/confluence/display/MAVEN/Index +[test-results]: https://builds.apache.org/job/maven-box/job/maven-war-plugin/job/master/lastCompletedBuild/testReport/ +[build]: https://builds.apache.org/job/maven-box/job/maven-war-plugin/job/master/ diff --git a/Java-base/maven-war-plugin/src/deploySite.sh b/Java-base/maven-war-plugin/src/deploySite.sh new file mode 100755 index 000000000..f6c265d75 --- /dev/null +++ b/Java-base/maven-war-plugin/src/deploySite.sh @@ -0,0 +1,23 @@ +#!/bin/sh + +# +# 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. +# + +mvn -Preporting site site:stage $@ +mvn scm-publish:publish-scm $@ diff --git a/Java-base/maven-war-plugin/src/pom.xml b/Java-base/maven-war-plugin/src/pom.xml new file mode 100644 index 000000000..7256fb4ac --- /dev/null +++ b/Java-base/maven-war-plugin/src/pom.xml @@ -0,0 +1,263 @@ + + + + + + 4.0.0 + + + maven-plugins + org.apache.maven.plugins + 34 + + + + maven-war-plugin + 3.3.1-SNAPSHOT + maven-plugin + + Apache Maven WAR Plugin + Builds a Web Application Archive (WAR) file from the project output and its dependencies. + + + ${mavenVersion} + + + + scm:git:https://gitbox.apache.org/repos/asf/maven-war-plugin.git + scm:git:https://gitbox.apache.org/repos/asf/maven-war-plugin.git + https://github.com/apache/maven-war-plugin/tree/${project.scm.tag} + HEAD + + + JIRA + https://issues.apache.org/jira/browse/MWAR + + + Jenkins + https://builds.apache.org/job/maven-box/job/maven-war-plugin/ + + + + apache.website + scm:svn:https://svn.apache.org/repos/asf/maven/website/components/${maven.site.path} + + + + + 3.5.0 + 3.1.1 + 3.0 + 7 + 2020-06-06T06:50:15Z + + + + + Auke Schrijnen + + + Ludwig Magnusson + + + Hayarobi Park + + + Enrico Olivelli + + + + + + org.apache.maven + maven-plugin-api + ${mavenVersion} + + + org.apache.maven + maven-core + ${mavenVersion} + + + org.apache.maven + maven-archiver + ${mavenArchiverVersion} + + + org.apache.maven.plugin-tools + maven-plugin-annotations + provided + + + commons-io + commons-io + 2.6 + + + org.codehaus.plexus + plexus-archiver + 4.2.2 + + + org.codehaus.plexus + plexus-interpolation + 1.26 + + + + org.codehaus.plexus + plexus-utils + 3.3.0 + + + + org.apache.maven.shared + maven-filtering + ${mavenFilteringVersion} + + + + org.apache.maven.shared + maven-mapping + 3.0.0 + + + + org.apache.maven + maven-compat + ${mavenVersion} + test + + + junit + junit + 4.13 + test + + + + org.apache.maven.plugin-testing + maven-plugin-testing-harness + 2.1 + test + + + + + + + src/main/resources-filtered + true + + + + + + org.apache.maven.plugins + maven-enforcer-plugin + + + enforce-bytecode-version + + enforce + + + + + ${maven.compiler.target} + + + true + + + + + + org.apache.rat + apache-rat-plugin + + + + src/it/MWAR-167/src/main/resources/MANIFEST.MF + + + + + + + + org.apache.maven.plugins + maven-surefire-plugin + + + ${project.build.directory} + ${project.build.outputDirectory} + + + + + + + + + run-its + + + + org.apache.maven.plugins + maven-invoker-plugin + + + clean + package + + src/it + verify + prebuild + ${project.build.directory}/local-repo + src/it/settings.xml + ${project.build.directory}/it + + + + install + pre-integration-tests + + install + + + + javax.servlet:servlet-api:2.4:jar + javax.servlet:javax.servlet-api:3.0.1:jar + org.apache.struts:struts-core:1.3.9:jar + org.codehaus.plexus:plexus-utils:1.4.7:jar:sources + + + + + + + + + + + diff --git a/Java-base/maven-war-plugin/src/src/it/MWAR-128/pom.xml b/Java-base/maven-war-plugin/src/src/it/MWAR-128/pom.xml new file mode 100644 index 000000000..cb2bfc482 --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/it/MWAR-128/pom.xml @@ -0,0 +1,38 @@ + + + + 4.0.0 + testwar + MWAR-128 + war + 1.0-SNAPSHOT + + + + + maven-war-plugin + @project.version@ + + true + + + + + diff --git a/Java-base/maven-war-plugin/src/src/it/MWAR-128/prebuild.groovy b/Java-base/maven-war-plugin/src/src/it/MWAR-128/prebuild.groovy new file mode 100644 index 000000000..f0f6e037d --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/it/MWAR-128/prebuild.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. + */ + +def dir = new File( basedir, "src/main/webapp/WEB-INF/logs" ) +dir.mkdirs() +return true; + diff --git a/Java-base/maven-war-plugin/src/src/it/MWAR-128/src/main/webapp/WEB-INF/web.xml b/Java-base/maven-war-plugin/src/src/it/MWAR-128/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 000000000..468ed7856 --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/it/MWAR-128/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,18 @@ + diff --git a/Java-base/maven-war-plugin/src/src/it/MWAR-128/verify.groovy b/Java-base/maven-war-plugin/src/src/it/MWAR-128/verify.groovy new file mode 100644 index 000000000..9a8843c2f --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/it/MWAR-128/verify.groovy @@ -0,0 +1,22 @@ +/* + * 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/MWAR-128-1.0-SNAPSHOT.war" ), false ); +assert warFile.getEntry( 'WEB-INF/logs' ) != null + diff --git a/Java-base/maven-war-plugin/src/src/it/MWAR-129/invoker.properties b/Java-base/maven-war-plugin/src/src/it/MWAR-129/invoker.properties new file mode 100644 index 000000000..7e6fbfd9f --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/it/MWAR-129/invoker.properties @@ -0,0 +1,18 @@ +# 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 war:exploded diff --git a/Java-base/maven-war-plugin/src/src/it/MWAR-129/pom.xml b/Java-base/maven-war-plugin/src/src/it/MWAR-129/pom.xml new file mode 100644 index 000000000..279a8489d --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/it/MWAR-129/pom.xml @@ -0,0 +1,121 @@ + + + + 4.0.0 + testwar + MWAR-129 + war + 1.0-SNAPSHOT + MWAR-129 Maven Webapp + http://maven.apache.org + + + junit + junit + 3.8.1 + test + + + + package + + + true + src/main/resources + + + src/main/java + + **/*.xml + + + + + + src/test/resources + + + src/main/webapp + + **/*.xml + + + + src/test/webapp + + **/*.xml + + + + ${project.artifactId} + + + maven-war-plugin + + + @pom.version@ + + src/main/webapp + + + true + src/main/webapp + . + + param.jsp + + + + + + + + + + profile1 + + + profile1 + + + + profile1 + + + profile1.css + + + + profile2 + + true + + profile2 + + + + profile2 + + + profile2.css + + + + diff --git a/Java-base/maven-war-plugin/src/src/it/MWAR-129/src/main/webapp/WEB-INF/web.xml b/Java-base/maven-war-plugin/src/src/it/MWAR-129/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 000000000..6a8fa709e --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/it/MWAR-129/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,24 @@ + + + + Archetype Created Web Application + diff --git a/Java-base/maven-war-plugin/src/src/it/MWAR-129/src/main/webapp/index.jsp b/Java-base/maven-war-plugin/src/src/it/MWAR-129/src/main/webapp/index.jsp new file mode 100755 index 000000000..9c9f33459 --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/it/MWAR-129/src/main/webapp/index.jsp @@ -0,0 +1,23 @@ + + + +

Hello World!

+ + diff --git a/Java-base/maven-war-plugin/src/src/it/MWAR-129/src/main/webapp/param.jsp b/Java-base/maven-war-plugin/src/src/it/MWAR-129/src/main/webapp/param.jsp new file mode 100755 index 000000000..6be3a1be0 --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/it/MWAR-129/src/main/webapp/param.jsp @@ -0,0 +1,27 @@ + + + + + + + + + + \ No newline at end of file diff --git a/Java-base/maven-war-plugin/src/src/it/MWAR-129/verify.bsh b/Java-base/maven-war-plugin/src/src/it/MWAR-129/verify.bsh new file mode 100644 index 000000000..7b85cd782 --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/it/MWAR-129/verify.bsh @@ -0,0 +1,66 @@ + +/* + * 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. + */ + +import java.io.*; +import org.codehaus.plexus.util.*; + +boolean result = true; + +try +{ + File target = new File( basedir, "target" ); + if ( !target.exists() || !target.isDirectory() ) + { + System.err.println( "target file is missing or not a directory." ); + return false; + } + + File webappDirectory = new File( target, "profile2" ); + if ( !webappDirectory.exists() || !webappDirectory.isDirectory() ) + { + System.err.println( "webappDirectory is missing or not a directory." ); + return false; + } + + File param = new File( webappDirectory, "param.jsp" ); + if ( !param.exists() || param.isDirectory() ) + { + System.err.println( "param.jsp file is missing or a directory." ); + return false; + } + System.out.println( " before reading param " ); + String paramContent = FileUtils.fileRead( param ); + + + int indexOf = paramContent.indexOf( "" ); + if ( indexOf < 0 ) + { + System.err.println( "param.jsp not contains " ); + return false; + } + +} +catch( Throwable e ) +{ + e.printStackTrace(); + result = false; +} + +return result; diff --git a/Java-base/maven-war-plugin/src/src/it/MWAR-131/invoker.properties b/Java-base/maven-war-plugin/src/src/it/MWAR-131/invoker.properties new file mode 100644 index 000000000..f93d074f8 --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/it/MWAR-131/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 install +invoker.maven.version=2.0.9+ \ No newline at end of file diff --git a/Java-base/maven-war-plugin/src/src/it/MWAR-131/mwar131-test/pom.xml b/Java-base/maven-war-plugin/src/src/it/MWAR-131/mwar131-test/pom.xml new file mode 100644 index 000000000..b1b1d0559 --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/it/MWAR-131/mwar131-test/pom.xml @@ -0,0 +1,50 @@ + + + + + mwar131 + com.example + 1.0-SNAPSHOT + + 4.0.0 + mwar131-test + Maven Quick Start Archetype + + + Example project that expects the attached jar from mwar131-webapp to be on the compile and test classpath. + + + 1.0-SNAPSHOT + http://maven.apache.org + + + junit + junit + 3.8.1 + test + + + com.example + mwar131-webapp + 1.0-SNAPSHOT + classes + + + \ No newline at end of file diff --git a/Java-base/maven-war-plugin/src/src/it/MWAR-131/mwar131-test/src/main/java/com/example/App.java b/Java-base/maven-war-plugin/src/src/it/MWAR-131/mwar131-test/src/main/java/com/example/App.java new file mode 100644 index 000000000..d5290dfd6 --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/it/MWAR-131/mwar131-test/src/main/java/com/example/App.java @@ -0,0 +1,32 @@ +package com.example; + +/* + * 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. + */ + +/** + * Hello world! + * + */ +public class App +{ + public static void main( String[] args ) + { + System.out.println( "Hello World is " + Util.isPresent() ); + } +} diff --git a/Java-base/maven-war-plugin/src/src/it/MWAR-131/mwar131-test/src/test/java/com/example/AppTest.java b/Java-base/maven-war-plugin/src/src/it/MWAR-131/mwar131-test/src/test/java/com/example/AppTest.java new file mode 100644 index 000000000..0c3fbb1cd --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/it/MWAR-131/mwar131-test/src/test/java/com/example/AppTest.java @@ -0,0 +1,62 @@ +package com.example; + +/* + * 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. + */ + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +/** + * Unit test for simple App. + */ +public class AppTest + extends TestCase +{ + /** + * Create the test case + * + * @param testName name of the test case + */ + public AppTest( String testName ) + { + super( testName ); + } + + /** + * @return the suite of tests being tested + */ + public static Test suite() + { + return new TestSuite( AppTest.class ); + } + + /** + * Rigourous Test :-) + */ + public void testApp() + { + assertTrue( true ); + } + + public void testUtil() + { + assertTrue( Util.isPresent() ); + } +} diff --git a/Java-base/maven-war-plugin/src/src/it/MWAR-131/mwar131-webapp/pom.xml b/Java-base/maven-war-plugin/src/src/it/MWAR-131/mwar131-webapp/pom.xml new file mode 100644 index 000000000..ee5ac62f5 --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/it/MWAR-131/mwar131-webapp/pom.xml @@ -0,0 +1,59 @@ + + + 4.0.0 + + com.example + mwar131 + 1.0-SNAPSHOT + + mwar131-webapp + war + MWAR-131 Webapp + + Web application with classes that get installed as an + attached artifact with a classifier (mwar131-webapp-1.0-SNAPSHOT-classes.jar) + + http://maven.apache.org + + + junit + junit + 3.8.1 + test + + + org.apache.struts + struts-core + 1.3.9 + + + + mwar131-webapp + + + maven-war-plugin + + true + + + + + diff --git a/Java-base/maven-war-plugin/src/src/it/MWAR-131/mwar131-webapp/src/main/java/com/example/Util.java b/Java-base/maven-war-plugin/src/src/it/MWAR-131/mwar131-webapp/src/main/java/com/example/Util.java new file mode 100644 index 000000000..b97118786 --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/it/MWAR-131/mwar131-webapp/src/main/java/com/example/Util.java @@ -0,0 +1,28 @@ +package com.example; + +/* + * 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. + */ + +public class Util +{ + public static boolean isPresent() + { + return true; + } +} diff --git a/Java-base/maven-war-plugin/src/src/it/MWAR-131/mwar131-webapp/src/main/webapp/WEB-INF/web.xml b/Java-base/maven-war-plugin/src/src/it/MWAR-131/mwar131-webapp/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 000000000..ef9d13e76 --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/it/MWAR-131/mwar131-webapp/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,25 @@ + + + + + Archetype Created Web Application + diff --git a/Java-base/maven-war-plugin/src/src/it/MWAR-131/mwar131-webapp/src/main/webapp/index.jsp b/Java-base/maven-war-plugin/src/src/it/MWAR-131/mwar131-webapp/src/main/webapp/index.jsp new file mode 100644 index 000000000..9c9f33459 --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/it/MWAR-131/mwar131-webapp/src/main/webapp/index.jsp @@ -0,0 +1,23 @@ + + + +

Hello World!

+ + diff --git a/Java-base/maven-war-plugin/src/src/it/MWAR-131/mwar131-webapp2/pom.xml b/Java-base/maven-war-plugin/src/src/it/MWAR-131/mwar131-webapp2/pom.xml new file mode 100644 index 000000000..0125a0bd2 --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/it/MWAR-131/mwar131-webapp2/pom.xml @@ -0,0 +1,55 @@ + + + + + mwar131 + com.example + 1.0-SNAPSHOT + + 4.0.0 + mwar131-webapp2 + war + Maven Webapp Archetype + + + Webapp that declares the attached jar from mwar131-webapp as a dependency, which should show up in WEB-INF/lib + along with its transitive dependencies. + + + 1.0-SNAPSHOT + http://maven.apache.org + + ${project.artifactId} + + + + junit + junit + 3.8.1 + test + + + com.example + mwar131-webapp + 1.0-SNAPSHOT + classes + + + \ No newline at end of file diff --git a/Java-base/maven-war-plugin/src/src/it/MWAR-131/mwar131-webapp2/src/main/webapp/WEB-INF/web.xml b/Java-base/maven-war-plugin/src/src/it/MWAR-131/mwar131-webapp2/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 000000000..ef9d13e76 --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/it/MWAR-131/mwar131-webapp2/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,25 @@ + + + + + Archetype Created Web Application + diff --git a/Java-base/maven-war-plugin/src/src/it/MWAR-131/mwar131-webapp2/src/main/webapp/index.jsp b/Java-base/maven-war-plugin/src/src/it/MWAR-131/mwar131-webapp2/src/main/webapp/index.jsp new file mode 100644 index 000000000..9c9f33459 --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/it/MWAR-131/mwar131-webapp2/src/main/webapp/index.jsp @@ -0,0 +1,23 @@ + + + +

Hello World!

+ + diff --git a/Java-base/maven-war-plugin/src/src/it/MWAR-131/pom.xml b/Java-base/maven-war-plugin/src/src/it/MWAR-131/pom.xml new file mode 100644 index 000000000..cc2bbca4a --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/it/MWAR-131/pom.xml @@ -0,0 +1,41 @@ + + + + 4.0.0 + com.example + mwar131 + pom + 1.0-SNAPSHOT + MWAR-131 Integration Test + http://maven.apache.org + + + + maven-war-plugin + @pom.version@ + + + + + mwar131-webapp + mwar131-test + mwar131-webapp2 + + \ No newline at end of file diff --git a/Java-base/maven-war-plugin/src/src/it/MWAR-131/verify.bsh b/Java-base/maven-war-plugin/src/src/it/MWAR-131/verify.bsh new file mode 100644 index 000000000..ca9fe0a5d --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/it/MWAR-131/verify.bsh @@ -0,0 +1,77 @@ + +/* + * 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. + */ + +import java.io.*; +import org.codehaus.plexus.util.*; + +boolean result = true; + +try +{ + + // Make sure the -classes jar from the first webapp is installed into the local repo + File localRepoClassesJar = new File( basedir, + "../../../target/local-repo/com/example/mwar131-webapp/1.0-SNAPSHOT/mwar131-webapp-1.0-SNAPSHOT-classes.jar"); + + if ( !localRepoClassesJar.exists() || localRepoClassesJar.isDirectory() ) + { + System.err.println( "The -classes jar file is missing or is a directory." ); + return false; + } + + // Make sure the -classes jar is included in WEB-INF/lib of the second webapp + File classesJar = new File( basedir, + "mwar131-webapp2/target/mwar131-webapp2/WEB-INF/lib/mwar131-webapp-1.0-SNAPSHOT-classes.jar"); + + if ( !classesJar.exists() || classesJar.isDirectory() ) + { + System.err.println( "The -classes jar file is missing or is a directory." ); + return false; + } + + // Make sure dependencies of the -classes jar are included in WEB-INF/lib of the second webapp + File strutsJar = new File( basedir, + "mwar131-webapp2/target/mwar131-webapp2/WEB-INF/lib/struts-core-1.3.9.jar"); + + if ( !strutsJar.exists() || strutsJar.isDirectory() ) + { + System.err.println( "The Struts 1.3.9 jar file is missing or is a directory." ); + return false; + } + + // Make sure transitive dependencies of the -classes jar are included in WEB-INF/lib of the second webapp + File digesterJar = new File( basedir, + "mwar131-webapp2/target/mwar131-webapp2/WEB-INF/lib/commons-digester-1.8.jar"); + + if ( !digesterJar.exists() || digesterJar.isDirectory() ) + { + System.err.println( "The Commons Digester 1.8 jar file is missing or is a directory." ); + return false; + } + +} +catch( Throwable e ) +{ + e.printStackTrace(); + result = false; +} + +return result; + diff --git a/Java-base/maven-war-plugin/src/src/it/MWAR-133/invoker.properties b/Java-base/maven-war-plugin/src/src/it/MWAR-133/invoker.properties new file mode 100644 index 000000000..7e6fbfd9f --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/it/MWAR-133/invoker.properties @@ -0,0 +1,18 @@ +# 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 war:exploded diff --git a/Java-base/maven-war-plugin/src/src/it/MWAR-133/pom.xml b/Java-base/maven-war-plugin/src/src/it/MWAR-133/pom.xml new file mode 100644 index 000000000..99248bc3b --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/it/MWAR-133/pom.xml @@ -0,0 +1,58 @@ + + + + 4.0.0 + testwar + MWAR-133 + war + 1.0-SNAPSHOT + MWAR-133 Maven Webapp + MWAR-133 it + + + + + src/main/resources + true + + + + + maven-war-plugin + @pom.version@ + + + + src/main/webresources + true + + + + + + + + + org.codehaus.plexus + plexus-utils + 1.4.6 + + + diff --git a/Java-base/maven-war-plugin/src/src/it/MWAR-133/src/main/webapp/WEB-INF/web.xml b/Java-base/maven-war-plugin/src/src/it/MWAR-133/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 000000000..6a8fa709e --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/it/MWAR-133/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,24 @@ + + + + Archetype Created Web Application + diff --git a/Java-base/maven-war-plugin/src/src/it/MWAR-133/src/main/webresources/filtered.properties b/Java-base/maven-war-plugin/src/src/it/MWAR-133/src/main/webresources/filtered.properties new file mode 100644 index 000000000..d60a845f6 --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/it/MWAR-133/src/main/webresources/filtered.properties @@ -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. + +# +# Not Replaced with the pom version +# +app.version=${node.version} \ No newline at end of file diff --git a/Java-base/maven-war-plugin/src/src/it/MWAR-133/verify.bsh b/Java-base/maven-war-plugin/src/src/it/MWAR-133/verify.bsh new file mode 100644 index 000000000..88989630b --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/it/MWAR-133/verify.bsh @@ -0,0 +1,66 @@ + +/* + * 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. + */ + +import java.io.*; +import org.codehaus.plexus.util.*; + +boolean result = true; + +try +{ + File target = new File( basedir, "target" ); + if ( !target.exists() || !target.isDirectory() ) + { + System.err.println( "target file is missing or not a directory." ); + return false; + } + + File webappDirectory = new File( target, "MWAR-133-1.0-SNAPSHOT" ); + if ( !webappDirectory.exists() || !webappDirectory.isDirectory() ) + { + System.err.println( "webappDirectory is missing or not a directory." ); + return false; + } + + File filtered = new File( webappDirectory, "filtered.properties" ); + if ( !filtered.exists() || filtered.isDirectory() ) + { + System.err.println( "filtered.properties file is missing or a directory." ); + return false; + } + System.out.println( " before reading filtered.properties" ); + String paramContent = FileUtils.fileRead( filtered ); + + + int indexOf = paramContent.indexOf( "app.version=${node.version}" ); + if ( indexOf < 0 ) + { + System.err.println( "filtered.properties was not filtered with the value of ${node.version}" ); + return false; + } + +} +catch( Throwable e ) +{ + e.printStackTrace(); + result = false; +} + +return result; diff --git a/Java-base/maven-war-plugin/src/src/it/MWAR-139/pom.xml b/Java-base/maven-war-plugin/src/src/it/MWAR-139/pom.xml new file mode 100644 index 000000000..a51346a8d --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/it/MWAR-139/pom.xml @@ -0,0 +1,48 @@ + + + + 4.0.0 + testwar + MWAR-139 + war + 1.0-SNAPSHOT + MWAR-139 Maven Webapp + http://maven.apache.org + + + + maven-war-plugin + @pom.version@ + + src/main/webapp + + + src/main/webresources + true + + + + + + + + diff --git a/Java-base/maven-war-plugin/src/src/it/MWAR-139/src/main/webapp/WEB-INF/web.xml b/Java-base/maven-war-plugin/src/src/it/MWAR-139/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 000000000..6a8fa709e --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/it/MWAR-139/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,24 @@ + + + + Archetype Created Web Application + diff --git a/Java-base/maven-war-plugin/src/src/it/MWAR-139/src/main/webresources/filterme.xml b/Java-base/maven-war-plugin/src/src/it/MWAR-139/src/main/webresources/filterme.xml new file mode 100644 index 000000000..2365ca4c7 --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/it/MWAR-139/src/main/webresources/filterme.xml @@ -0,0 +1,23 @@ + + + ${foo.url} + hallo @@ hallo + start-${}-end + diff --git a/Java-base/maven-war-plugin/src/src/it/MWAR-139/verify.bsh b/Java-base/maven-war-plugin/src/src/it/MWAR-139/verify.bsh new file mode 100644 index 000000000..390c0be32 --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/it/MWAR-139/verify.bsh @@ -0,0 +1,72 @@ + +/* + * 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. + */ + +import java.io.*; +import org.codehaus.plexus.util.*; + +boolean result = true; + +try +{ + File target = new File( basedir, "target" ); + if ( !target.exists() || !target.isDirectory() ) + { + System.err.println( "target file is missing or not a directory." ); + return false; + } + + File webappDirectory = new File( target, "MWAR-139-1.0-SNAPSHOT" ); + if ( !webappDirectory.exists() || !webappDirectory.isDirectory() ) + { + System.err.println( "webappDirectory is missing or not a directory." ); + return false; + } + + File param = new File( webappDirectory, "filterme.xml" ); + if ( !param.exists() || param.isDirectory() ) + { + System.err.println( "filterme.xml file is missing or a directory." ); + return false; + } + + String paramContent = FileUtils.fileRead( param ); + + int indexOf = paramContent.indexOf( "hallo @@ hallo" ); + if ( indexOf < 0 ) + { + System.err.println( "filterme.xml does not contains hallo @@ hallo" ); + return false; + } + + indexOf = paramContent.indexOf( "start-${}-end" ); + if ( indexOf < 0 ) + { + System.err.println( "filterme.xml does not contains start-${}-end" ); + return false; + } + +} +catch( Throwable e ) +{ + e.printStackTrace(); + result = false; +} + +return result; diff --git a/Java-base/maven-war-plugin/src/src/it/MWAR-143/invoker.properties b/Java-base/maven-war-plugin/src/src/it/MWAR-143/invoker.properties new file mode 100644 index 000000000..3376b9e49 --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/it/MWAR-143/invoker.properties @@ -0,0 +1,18 @@ +# 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 install diff --git a/Java-base/maven-war-plugin/src/src/it/MWAR-143/pom.xml b/Java-base/maven-war-plugin/src/src/it/MWAR-143/pom.xml new file mode 100644 index 000000000..c975e36d8 --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/it/MWAR-143/pom.xml @@ -0,0 +1,58 @@ + + + + 4.0.0 + debug.war + MWAR-143 + pom + 1.0-SNAPSHOT + MWAR-143 Maven Webapp + http://maven.apache.org + + + + + maven-war-plugin + @pom.version@ + + + jpg + + + + + + + + war-common + war-filter-overlay + + + + + debug.war + common-overlay + 1.0-SNAPSHOT + + + + diff --git a/Java-base/maven-war-plugin/src/src/it/MWAR-143/verify.bsh b/Java-base/maven-war-plugin/src/src/it/MWAR-143/verify.bsh new file mode 100644 index 000000000..45ed59e2f --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/it/MWAR-143/verify.bsh @@ -0,0 +1,124 @@ + +/* + * 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. + */ + +import java.io.*; +import org.codehaus.plexus.util.*; + +boolean result = true; + +filesAreIdentical( File expected, File current ) + throws IOException +{ + if ( expected.length() != current.length() ) + { + return false; + } + FileInputStream expectedIn = new FileInputStream( expected ); + FileInputStream currentIn = new FileInputStream( current ); + try + { + byte[] expectedBuffer = IOUtil.toByteArray( expectedIn ); + + byte[] currentBuffer = IOUtil.toByteArray( currentIn ); + if ( expectedBuffer.length != currentBuffer.length ) + { + return false; + } + for ( int i = 0,size = expectedBuffer.length; i + + + 4.0.0 + + debug.war + MWAR-143 + 1.0-SNAPSHOT + + common-overlay + war + + + + + org.apache.maven.plugins + maven-war-plugin + + + + properties + + + + + src/main/images + true + + + + + + + diff --git a/Java-base/maven-war-plugin/src/src/it/MWAR-143/war-common/src/main/images/duke-beer.jpg b/Java-base/maven-war-plugin/src/src/it/MWAR-143/war-common/src/main/images/duke-beer.jpg new file mode 100755 index 000000000..8b43aa065 Binary files /dev/null and b/Java-base/maven-war-plugin/src/src/it/MWAR-143/war-common/src/main/images/duke-beer.jpg differ diff --git a/Java-base/maven-war-plugin/src/src/it/MWAR-143/war-common/src/main/resources/filter.properties b/Java-base/maven-war-plugin/src/src/it/MWAR-143/war-common/src/main/resources/filter.properties new file mode 100644 index 000000000..624f14f21 --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/it/MWAR-143/war-common/src/main/resources/filter.properties @@ -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. + +title.main=Prototype ${pom.name} +title.version=version ${pom.version} + +debug.test = ${my.filter.value} diff --git a/Java-base/maven-war-plugin/src/src/it/MWAR-143/war-common/src/main/webapp/WEB-INF/web.xml b/Java-base/maven-war-plugin/src/src/it/MWAR-143/war-common/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 000000000..357cf72ca --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/it/MWAR-143/war-common/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,25 @@ + + + + + diff --git a/Java-base/maven-war-plugin/src/src/it/MWAR-143/war-filter-overlay/pom.xml b/Java-base/maven-war-plugin/src/src/it/MWAR-143/war-filter-overlay/pom.xml new file mode 100644 index 000000000..062fb1b80 --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/it/MWAR-143/war-filter-overlay/pom.xml @@ -0,0 +1,65 @@ + + + + 4.0.0 + + debug.war + MWAR-143 + 1.0-SNAPSHOT + + custom-manifest + war + + + + + debug.war + common-overlay + 1.0-SNAPSHOT + war + runtime + + + + + + + org.apache.maven.plugins + maven-war-plugin + + + + debug.war + common-overlay + + true + + + + + + + + + hello world ! + + + diff --git a/Java-base/maven-war-plugin/src/src/it/MWAR-143/war-filter-overlay/src/main/webapp/WEB-INF/web.xml b/Java-base/maven-war-plugin/src/src/it/MWAR-143/war-filter-overlay/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 000000000..fc6e240ce --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/it/MWAR-143/war-filter-overlay/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,26 @@ + + + + + + diff --git a/Java-base/maven-war-plugin/src/src/it/MWAR-167/invoker.properties b/Java-base/maven-war-plugin/src/src/it/MWAR-167/invoker.properties new file mode 100644 index 000000000..7e6fbfd9f --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/it/MWAR-167/invoker.properties @@ -0,0 +1,18 @@ +# 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 war:exploded diff --git a/Java-base/maven-war-plugin/src/src/it/MWAR-167/pom.xml b/Java-base/maven-war-plugin/src/src/it/MWAR-167/pom.xml new file mode 100644 index 000000000..174386f45 --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/it/MWAR-167/pom.xml @@ -0,0 +1,49 @@ + + + + 4.0.0 + testwar + MWAR-167 + war + 1.0-SNAPSHOT + MWAR-167 Maven Webapp + http://maven.apache.org + + + junit + junit + 3.8.1 + test + + + + + + maven-war-plugin + @project.version@ + + + src/main/resources/MANIFEST.MF + + + + + + diff --git a/Java-base/maven-war-plugin/src/src/it/MWAR-167/src/main/resources/MANIFEST.MF b/Java-base/maven-war-plugin/src/src/it/MWAR-167/src/main/resources/MANIFEST.MF new file mode 100644 index 000000000..285550382 --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/it/MWAR-167/src/main/resources/MANIFEST.MF @@ -0,0 +1,5 @@ +Manifest-Version: 1.0 +Bundle-Name: Dummy Bundle +Bundle-SymbolicName: dummy.bundle +Bundle-ManifestVersion: 2 +Bundle-Version: 1.0.0.SNAPSHOT \ No newline at end of file diff --git a/Java-base/maven-war-plugin/src/src/it/MWAR-167/verify.bsh b/Java-base/maven-war-plugin/src/src/it/MWAR-167/verify.bsh new file mode 100644 index 000000000..fa82b4309 --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/it/MWAR-167/verify.bsh @@ -0,0 +1,74 @@ + +/* + * 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. + */ + +import java.io.*; +import org.codehaus.plexus.util.*; + +boolean result = true; + +try +{ + File manifest = new File( basedir, "target/MWAR-167-1.0-SNAPSHOT/META-INF/MANIFEST.MF" ); + if ( !manifest.exists() || !manifest.isFile() ) + { + System.err.println( "Manifest is missing!"); + return false; + } + + + FileInputStream fis = new FileInputStream ( manifest ); + String manifestContent = IOUtil.toString ( fis ); + + int indexOf = manifestContent.indexOf("Manifest-Version: 1.0" ); + if ( indexOf < 0) + { + System.err.println( "Manifest-Version header not found" ); + return false; + } + + indexOf = manifestContent.indexOf("Bundle-Name: Dummy Bundle" ); + if ( indexOf < 0) + { + System.err.println( "Bundle-Name header not found" ); + return false; + } + + indexOf = manifestContent.indexOf("Bundle-SymbolicName: dummy.bundle" ); + if ( indexOf < 0) + { + System.err.println( "Bundle-SymbolicName: 2" ); + return false; + } + + indexOf = manifestContent.indexOf("Bundle-Version: 1.0.0.SNAPSHOT" ); + if ( indexOf < 0) + { + System.err.println( "Bundle-Version header not found" ); + return false; + } + +} +catch( Throwable e ) +{ + e.printStackTrace(); + result = false; +} + +return result; diff --git a/Java-base/maven-war-plugin/src/src/it/MWAR-240/invoker.properties b/Java-base/maven-war-plugin/src/src/it/MWAR-240/invoker.properties new file mode 100644 index 000000000..c743aa4f3 --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/it/MWAR-240/invoker.properties @@ -0,0 +1,18 @@ +# 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 diff --git a/Java-base/maven-war-plugin/src/src/it/MWAR-240/pom.xml b/Java-base/maven-war-plugin/src/src/it/MWAR-240/pom.xml new file mode 100644 index 000000000..5ac2c0d99 --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/it/MWAR-240/pom.xml @@ -0,0 +1,43 @@ + + + + 4.0.0 + test + mwar-240-test-case + 1.0 + MWAR-240 Test case + war + Test project for reproducing an issue with classes packaging: https://issues.apache.org/jira/browse/MWAR-240 + + + + maven-war-plugin + @pom.version@ + + false + true + true + + + + + \ No newline at end of file diff --git a/Java-base/maven-war-plugin/src/src/it/MWAR-240/src/main/java/org/apache/maven/plugin/war/it/Dummy.java b/Java-base/maven-war-plugin/src/src/it/MWAR-240/src/main/java/org/apache/maven/plugin/war/it/Dummy.java new file mode 100644 index 000000000..e980d3552 --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/it/MWAR-240/src/main/java/org/apache/maven/plugin/war/it/Dummy.java @@ -0,0 +1,29 @@ +/* + * 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. + */ + +package org.apache.maven.plugin.war.it; + +/** + * A dummy class to show the problem with classes packaging. + * + * @author Sergiy Shyrkov + */ +public class Dummy { + +} diff --git a/Java-base/maven-war-plugin/src/src/it/MWAR-240/verify.bsh b/Java-base/maven-war-plugin/src/src/it/MWAR-240/verify.bsh new file mode 100644 index 000000000..fec4b9d43 --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/it/MWAR-240/verify.bsh @@ -0,0 +1,59 @@ + +/* + * 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. + */ + +import java.io.*; +import java.util.*; +import java.util.jar.*; +import java.util.regex.*; + +try +{ + File jarFile = new File( basedir, "target/mwar-240-test-case-1.0-classes.jar" ); + System.out.println( "Checking for existence of " + jarFile ); + if ( !jarFile.isFile() ) + { + System.out.println( "FAILURE!" ); + return false; + } + + JarFile jar = new JarFile( jarFile ); + + String[] includedEntries = { + "org/apache/maven/plugin/war/it/Dummy.class", + }; + for ( String included : includedEntries ) + { + System.out.println( "Checking for existence of " + included ); + if ( jar.getEntry( included ) == null ) + { + System.out.println( "FAILURE!" ); + return false; + } + } + + jar.close(); +} +catch( Throwable t ) +{ + t.printStackTrace(); + return false; +} + +return true; diff --git a/Java-base/maven-war-plugin/src/src/it/MWAR-306/pom.xml b/Java-base/maven-war-plugin/src/src/it/MWAR-306/pom.xml new file mode 100644 index 000000000..facc3b537 --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/it/MWAR-306/pom.xml @@ -0,0 +1,45 @@ + + + + 4.0.0 + foo.bar + MWAR-306 + 0.0.1-SNAPSHOT + war + + + + @project.groupId@ + @project.artifactId@ + @project.version@ + + false + + + src/main/webapp + true + + + + + + + diff --git a/Java-base/maven-war-plugin/src/src/it/MWAR-306/src/main/webapp/index.html b/Java-base/maven-war-plugin/src/src/it/MWAR-306/src/main/webapp/index.html new file mode 100644 index 000000000..873f9bdaf --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/it/MWAR-306/src/main/webapp/index.html @@ -0,0 +1,26 @@ + + + + +${project.artifactId} + +${project.artifactId} @ ${project.version} +${project.name} + diff --git a/Java-base/maven-war-plugin/src/src/it/MWAR-306/verify.groovy b/Java-base/maven-war-plugin/src/src/it/MWAR-306/verify.groovy new file mode 100644 index 000000000..ba74120d9 --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/it/MWAR-306/verify.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. + */ + +def indexHtml = new File(basedir, 'target/MWAR-306-0.0.1-SNAPSHOT/index.html'); +assert indexHtml.exists() + +assert indexHtml.text.contains('MWAR-306 @ 0.0.1-SNAPSHOT') diff --git a/Java-base/maven-war-plugin/src/src/it/MWAR-311/pom.xml b/Java-base/maven-war-plugin/src/src/it/MWAR-311/pom.xml new file mode 100644 index 000000000..820173b11 --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/it/MWAR-311/pom.xml @@ -0,0 +1,64 @@ + + + + 4.0.0 + com.ecbrodie + MWAR-311 + 0.0.1-SNAPSHOT + Maven War Plugin Bug + Filtering of properties files (as a web resource) broken in maven-war-plugin version 2.4. + war + + + UTF-8 + foo foo + + + + + src/main/resources/default.properties + + + + src/main/resources + true + + + + + @project.groupId@ + @project.artifactId@ + @project.version@ + + + + src/main/resources + true + + **/app.properties + + + + true + + + + + diff --git a/Java-base/maven-war-plugin/src/src/it/MWAR-311/src/main/resources/app.properties b/Java-base/maven-war-plugin/src/src/it/MWAR-311/src/main/resources/app.properties new file mode 100644 index 000000000..057e159b7 --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/it/MWAR-311/src/main/resources/app.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. +my.maven.property=${my.maven.property} +prop.a=${prop.a} +prop.b=${prop.b} diff --git a/Java-base/maven-war-plugin/src/src/it/MWAR-311/src/main/resources/default.properties b/Java-base/maven-war-plugin/src/src/it/MWAR-311/src/main/resources/default.properties new file mode 100644 index 000000000..b16902f2c --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/it/MWAR-311/src/main/resources/default.properties @@ -0,0 +1,18 @@ +# 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. +prop.a=AAA +prop.b=BBB diff --git a/Java-base/maven-war-plugin/src/src/it/MWAR-311/src/main/webapp/WEB-INF/web.xml b/Java-base/maven-war-plugin/src/src/it/MWAR-311/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 000000000..b457706f5 --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/it/MWAR-311/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,24 @@ + + + + diff --git a/Java-base/maven-war-plugin/src/src/it/MWAR-311/verify.groovy b/Java-base/maven-war-plugin/src/src/it/MWAR-311/verify.groovy new file mode 100644 index 000000000..77599894f --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/it/MWAR-311/verify.groovy @@ -0,0 +1,25 @@ +/* + * 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 propertiesFile = new File(basedir, 'target/MWAR-311-0.0.1-SNAPSHOT/app.properties'); +assert propertiesFile.exists() + +assert propertiesFile.text.contains('my.maven.property=foo foo'); +assert propertiesFile.text.contains('prop.a=AAA'); +assert propertiesFile.text.contains('prop.b=BBB'); diff --git a/Java-base/maven-war-plugin/src/src/it/MWAR-314/invoker.properties b/Java-base/maven-war-plugin/src/src/it/MWAR-314/invoker.properties new file mode 100644 index 000000000..692791cf1 --- /dev/null +++ b/Java-base/maven-war-plugin/src/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/Java-base/maven-war-plugin/src/src/it/MWAR-314/pom.xml b/Java-base/maven-war-plugin/src/src/it/MWAR-314/pom.xml new file mode 100644 index 000000000..da9ef170c --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/it/MWAR-314/pom.xml @@ -0,0 +1,39 @@ + + + 4.0.0 + mwar314 + mwar314 + 0.0.1-SNAPSHOT + war + + + + org.apache.maven.plugins + maven-war-plugin + @project.version@ + + false + src/main/webapp/WEB-INF/web.xml + + + + + \ No newline at end of file diff --git a/Java-base/maven-war-plugin/src/src/it/MWAR-314/src/main/webapp/index.jsp b/Java-base/maven-war-plugin/src/src/it/MWAR-314/src/main/webapp/index.jsp new file mode 100644 index 000000000..41db44eef --- /dev/null +++ b/Java-base/maven-war-plugin/src/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/Java-base/maven-war-plugin/src/src/it/MWAR-326/invoker.properties b/Java-base/maven-war-plugin/src/src/it/MWAR-326/invoker.properties new file mode 100644 index 000000000..5e07ba581 --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/it/MWAR-326/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.description = This test only checks if using extensions works without any issue. +invoker.goals = clean package diff --git a/Java-base/maven-war-plugin/src/src/it/MWAR-326/pom.xml b/Java-base/maven-war-plugin/src/src/it/MWAR-326/pom.xml new file mode 100755 index 000000000..37f123963 --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/it/MWAR-326/pom.xml @@ -0,0 +1,46 @@ + + + + + 4.0.0 + org.apache.maven.plugins + maven-war-plugin-test-mwar-326 + 1.0-SNAPSHOT + war + Maven Integration Test :: MWAR-326 + MWAR-326 integration test + + + + false + org.apache.maven.plugins + maven-war-plugin + @project.version@ + true + + false + + + + + diff --git a/Java-base/maven-war-plugin/src/src/it/MWAR-326/src/main/java/A.java b/Java-base/maven-war-plugin/src/src/it/MWAR-326/src/main/java/A.java new file mode 100755 index 000000000..474b0a65b --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/it/MWAR-326/src/main/java/A.java @@ -0,0 +1,25 @@ + +/* + * 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. + */ + +public class A { + public static void main(String[] args) { + + } +} diff --git a/Java-base/maven-war-plugin/src/src/it/MWAR-326/verify.bsh b/Java-base/maven-war-plugin/src/src/it/MWAR-326/verify.bsh new file mode 100644 index 000000000..c0a4425de --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/it/MWAR-326/verify.bsh @@ -0,0 +1,52 @@ + +/* + * 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. + */ + +import java.io.*; +import java.util.*; +import java.util.jar.*; +import org.codehaus.plexus.util.*; + +boolean result = true; + +try +{ + File target = new File( basedir, "target" ); + if ( !target.exists() || !target.isDirectory() ) + { + System.err.println( "target file is missing or not a directory." ); + return false; + } + + File artifact = new File( target, "maven-war-plugin-test-mwar-326-1.0-SNAPSHOT.war" ); + if ( !artifact.exists() ) + { + System.err.println( "default artifact should exist." ); + return false; + } + + return true; +} +catch( Throwable e ) +{ + e.printStackTrace(); + return false; +} + +return false; diff --git a/Java-base/maven-war-plugin/src/src/it/MWAR-350/pom.xml b/Java-base/maven-war-plugin/src/src/it/MWAR-350/pom.xml new file mode 100644 index 000000000..6ef40f407 --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/it/MWAR-350/pom.xml @@ -0,0 +1,69 @@ + + + + + + 4.0.0 + + org.apache.maven.its.war + maven-it-mwar350 + 1.0 + war + + Maven Integration Test :: MWAR-350 + Test to skip WAR generation + + + UTF-8 + + + + + javax.servlet + servlet-api + 2.4 + provided + + + commons-logging + commons-logging + 1.0.3 + + + junit + junit + 3.8.2 + test + + + + + + + org.apache.maven.plugins + maven-war-plugin + @project.version@ + + true + + + + + diff --git a/Java-base/maven-war-plugin/src/src/it/MWAR-350/src/main/java/org/apache/maven/it0016/Person.java b/Java-base/maven-war-plugin/src/src/it/MWAR-350/src/main/java/org/apache/maven/it0016/Person.java new file mode 100644 index 000000000..4a287e77c --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/it/MWAR-350/src/main/java/org/apache/maven/it0016/Person.java @@ -0,0 +1,35 @@ +package org.apache.maven.it0016; + +/* + * 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. + */ + +public class Person +{ + private String name; + + public void setName( String name ) + { + this.name = name; + } + + public String getName() + { + return name; + } +} diff --git a/Java-base/maven-war-plugin/src/src/it/MWAR-350/src/main/webapp/WEB-INF/web.xml b/Java-base/maven-war-plugin/src/src/it/MWAR-350/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 000000000..c1af95de8 --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/it/MWAR-350/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,23 @@ + + + + + + diff --git a/Java-base/maven-war-plugin/src/src/it/MWAR-350/src/main/webapp/index.html b/Java-base/maven-war-plugin/src/src/it/MWAR-350/src/main/webapp/index.html new file mode 100644 index 000000000..8e81e877d --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/it/MWAR-350/src/main/webapp/index.html @@ -0,0 +1,23 @@ + + + + Hello World + + diff --git a/Java-base/maven-war-plugin/src/src/it/MWAR-350/verify.bsh b/Java-base/maven-war-plugin/src/src/it/MWAR-350/verify.bsh new file mode 100644 index 000000000..9e5c87990 --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/it/MWAR-350/verify.bsh @@ -0,0 +1,51 @@ +/* + * 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. + */ + +import java.io.*; +import java.util.*; +import java.util.jar.*; +import java.util.regex.*; + +try +{ + File explodedDir = new File( basedir, "target/maven-it-mwar350-1.0" ); + System.out.println( "Checking for existence of exploded directory " + explodedDir ); + if ( explodedDir.isDirectory() ) + { + System.out.println( "FAILURE! The directory " + explodedDir + " does exist." ); + return false; + } + + + File warFile = new File( basedir, "target/maven-it-mwar350-1.0.war" ); + System.out.println( "Checking for existence of " + warFile ); + if ( warFile.isFile() ) + { + System.out.println( "FAILURE! The generated file should have not be there." ); + return false; + } + +} +catch( Throwable t ) +{ + t.printStackTrace(); + return false; +} + +return true; diff --git a/Java-base/maven-war-plugin/src/src/it/MWAR-352_custom-webXml/pom.xml b/Java-base/maven-war-plugin/src/src/it/MWAR-352_custom-webXml/pom.xml new file mode 100644 index 000000000..12905e211 --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/it/MWAR-352_custom-webXml/pom.xml @@ -0,0 +1,46 @@ + + + + + + 4.0.0 + + org.apache.maven.plugins.war.its + mwar-352 + 1.0-SNAPSHOT + war + + + UTF-8 + + + + + + org.apache.maven.plugins + maven-war-plugin + @project.version@ + + src/main/webconfig/release/web.xml + + + + + diff --git a/Java-base/maven-war-plugin/src/src/it/MWAR-352_custom-webXml/src/main/webapp/WEB-INF/web.xml b/Java-base/maven-war-plugin/src/src/it/MWAR-352_custom-webXml/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 000000000..d8f4f21de --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/it/MWAR-352_custom-webXml/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,22 @@ + + + + + diff --git a/Java-base/maven-war-plugin/src/src/it/MWAR-352_custom-webXml/src/main/webconfig/release/web.xml b/Java-base/maven-war-plugin/src/src/it/MWAR-352_custom-webXml/src/main/webconfig/release/web.xml new file mode 100644 index 000000000..a7b8744cf --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/it/MWAR-352_custom-webXml/src/main/webconfig/release/web.xml @@ -0,0 +1,22 @@ + + + + + diff --git a/Java-base/maven-war-plugin/src/src/it/MWAR-352_custom-webXml/verify.groovy b/Java-base/maven-war-plugin/src/src/it/MWAR-352_custom-webXml/verify.groovy new file mode 100644 index 000000000..753bf8465 --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/it/MWAR-352_custom-webXml/verify.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. + */ + +def warFile = new java.util.jar.JarFile( new File(basedir,"target/mwar-352-1.0-SNAPSHOT.war"), false) +def webXml = warFile.getEntry('WEB-INF/web.xml') +assert webXml != null +assert warFile.getInputStream( webXml).text.contains('from src/main/webconfig/release/web.xml') diff --git a/Java-base/maven-war-plugin/src/src/it/MWAR-371/custom/pom.xml b/Java-base/maven-war-plugin/src/src/it/MWAR-371/custom/pom.xml new file mode 100644 index 000000000..b2aa1976a --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/it/MWAR-371/custom/pom.xml @@ -0,0 +1,65 @@ + + + + 4.0.0 + + mwar371 + mwar371 + 1.0-SNAPSHOT + + custom + war + + + mwar371 + generic + 1.0-SNAPSHOT + war + + + + + + + maven-war-plugin + + + + src/main/custom + + a1.txt + + x/ + + + src/main/custom + + a2.txt + + x + + + + + + + + \ No newline at end of file diff --git a/Java-base/maven-war-plugin/src/src/it/MWAR-371/custom/src/main/custom/a1.txt b/Java-base/maven-war-plugin/src/src/it/MWAR-371/custom/src/main/custom/a1.txt new file mode 100644 index 000000000..7fe810a0c --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/it/MWAR-371/custom/src/main/custom/a1.txt @@ -0,0 +1,18 @@ +# 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. + +i'm custom \ No newline at end of file diff --git a/Java-base/maven-war-plugin/src/src/it/MWAR-371/custom/src/main/custom/a2.txt b/Java-base/maven-war-plugin/src/src/it/MWAR-371/custom/src/main/custom/a2.txt new file mode 100644 index 000000000..7fe810a0c --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/it/MWAR-371/custom/src/main/custom/a2.txt @@ -0,0 +1,18 @@ +# 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. + +i'm custom \ No newline at end of file diff --git a/Java-base/maven-war-plugin/src/src/it/MWAR-371/generic/pom.xml b/Java-base/maven-war-plugin/src/src/it/MWAR-371/generic/pom.xml new file mode 100644 index 000000000..beeef48a2 --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/it/MWAR-371/generic/pom.xml @@ -0,0 +1,29 @@ + + + + 4.0.0 + + mwar371 + mwar371 + 1.0-SNAPSHOT + + generic + war + \ No newline at end of file diff --git a/Java-base/maven-war-plugin/src/src/it/MWAR-371/generic/src/main/webapp/x/a1.txt b/Java-base/maven-war-plugin/src/src/it/MWAR-371/generic/src/main/webapp/x/a1.txt new file mode 100644 index 000000000..fc4dee13c --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/it/MWAR-371/generic/src/main/webapp/x/a1.txt @@ -0,0 +1,18 @@ +# 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. + +I'm generic \ No newline at end of file diff --git a/Java-base/maven-war-plugin/src/src/it/MWAR-371/generic/src/main/webapp/x/a2.txt b/Java-base/maven-war-plugin/src/src/it/MWAR-371/generic/src/main/webapp/x/a2.txt new file mode 100644 index 000000000..fc4dee13c --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/it/MWAR-371/generic/src/main/webapp/x/a2.txt @@ -0,0 +1,18 @@ +# 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. + +I'm generic \ No newline at end of file diff --git a/Java-base/maven-war-plugin/src/src/it/MWAR-371/generic/src/main/webapp/x/a3.txt b/Java-base/maven-war-plugin/src/src/it/MWAR-371/generic/src/main/webapp/x/a3.txt new file mode 100644 index 000000000..fc4dee13c --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/it/MWAR-371/generic/src/main/webapp/x/a3.txt @@ -0,0 +1,18 @@ +# 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. + +I'm generic \ No newline at end of file diff --git a/Java-base/maven-war-plugin/src/src/it/MWAR-371/pom.xml b/Java-base/maven-war-plugin/src/src/it/MWAR-371/pom.xml new file mode 100644 index 000000000..1f72884fb --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/it/MWAR-371/pom.xml @@ -0,0 +1,51 @@ + + + + 4.0.0 + mwar371 + mwar371 + 1.0-SNAPSHOT + pom + Maven Integration Test :: MWAR-371 + MWAR-371 integration test + + + UTF-8 + + + + generic + custom + + + + + + maven-war-plugin + @project.version@ + + false + + + + + + \ No newline at end of file diff --git a/Java-base/maven-war-plugin/src/src/it/MWAR-371/verify.groovy b/Java-base/maven-war-plugin/src/src/it/MWAR-371/verify.groovy new file mode 100644 index 000000000..e66bcd5ec --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/it/MWAR-371/verify.groovy @@ -0,0 +1,74 @@ +/* + * 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. + */ + +boolean checkFile( String fileName, String artifact, String module ) +{ + def customA1 = new File( basedir, "${artifact}/target/${artifact}-1.0-SNAPSHOT/x/${fileName}" ) + if ( ! customA1.exists() ) + { + System.err.println( "${artifact}/target/${artifact}-1.0-SNAPSHOT/x/${fileName} does not exist." ) + return false + } + if ( ! customA1.text.contains( module ) ) + { + System.err.println( "${artifact}/target/${artifact}-1.0-SNAPSHOT/x/${fileName} is not ${module}." ) + return false + } + return true +} + +boolean checkFile( String fileName, String module ) +{ + return checkFile( fileName, module, module ) +} + +try { + if ( ! checkFile( "a1.txt", "custom" ) ) + { + return false + } + if ( ! checkFile( "a2.txt", "custom" ) ) + { + return false + } + if ( ! checkFile( "a3.txt", "custom", "generic" ) ) + { + return false + } + if ( ! checkFile( "a1.txt", "generic" ) ) + { + return false + } + if ( ! checkFile( "a2.txt", "generic" ) ) + { + return false + } + if ( ! checkFile( "a3.txt", "generic" ) ) + { + return false + } +} +catch ( Throwable e ) +{ + e.printStackTrace() + return false +} + +return true + diff --git a/Java-base/maven-war-plugin/src/src/it/MWAR-396_no-servlet30/invoker.properties b/Java-base/maven-war-plugin/src/src/it/MWAR-396_no-servlet30/invoker.properties new file mode 100644 index 000000000..f2a7dfb44 --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/it/MWAR-396_no-servlet30/invoker.properties @@ -0,0 +1,18 @@ +# 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.buildResult = failure diff --git a/Java-base/maven-war-plugin/src/src/it/MWAR-396_no-servlet30/pom.xml b/Java-base/maven-war-plugin/src/src/it/MWAR-396_no-servlet30/pom.xml new file mode 100644 index 000000000..5fa6d853f --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/it/MWAR-396_no-servlet30/pom.xml @@ -0,0 +1,66 @@ + + + + + + 4.0.0 + + org.apache.maven.its.war + maven-it-mwar396 + 1.0 + war + + Maven Integration Test :: MWAR-396 + Test that a web.xml is required when project does not depend on Servlet 3.0 or newer + + + UTF-8 + + + + + javax.servlet + servlet-api + 2.4 + provided + + + commons-logging + commons-logging + 1.0.3 + + + junit + junit + 3.8.2 + test + + + + + + + org.apache.maven.plugins + maven-war-plugin + @project.version@ + + + + diff --git a/Java-base/maven-war-plugin/src/src/it/MWAR-396_servlet30/pom.xml b/Java-base/maven-war-plugin/src/src/it/MWAR-396_servlet30/pom.xml new file mode 100644 index 000000000..2244d1599 --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/it/MWAR-396_servlet30/pom.xml @@ -0,0 +1,66 @@ + + + + + + 4.0.0 + + org.apache.maven.its.war + maven-it-mwar396_servlet30 + 1.0 + war + + Maven Integration Test :: MWAR-396 + Test that no web.xml is required when project depends on Servlet 3.0 or newer + + + UTF-8 + + + + + javax.servlet + javax.servlet-api + 3.0.1 + provided + + + commons-logging + commons-logging + 1.0.3 + + + junit + junit + 3.8.2 + test + + + + + + + org.apache.maven.plugins + maven-war-plugin + @project.version@ + + + + diff --git a/Java-base/maven-war-plugin/src/src/it/MWAR-396_servlet30/verify.bsh b/Java-base/maven-war-plugin/src/src/it/MWAR-396_servlet30/verify.bsh new file mode 100644 index 000000000..402a3ca27 --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/it/MWAR-396_servlet30/verify.bsh @@ -0,0 +1,49 @@ +/* + * 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. + */ + +import java.io.*; +import java.util.*; +import java.util.jar.*; +import java.util.regex.*; + +try +{ + File explodedDir = new File( basedir, "target/maven-it-mwar396_servlet30-1.0" ); + System.out.println( "Checking for existence of exploded directory " + explodedDir ); + if ( !explodedDir.exists() ) + { + System.out.println( "FAILURE! The directory " + explodedDir + " does not exist." ); + return false; + } + + File webInfFile = new File( explodedDir, "WEB-INF/web.xml" ); + if ( webInfFile.exists() ) + { + System.err.println( "FAILURE! The file web.xml should not be present." ); + return false; + } + +} +catch( Throwable t ) +{ + t.printStackTrace(); + return false; +} + +return true; diff --git a/Java-base/maven-war-plugin/src/src/it/MWAR-427_update-without-clean/invoker.properties b/Java-base/maven-war-plugin/src/src/it/MWAR-427_update-without-clean/invoker.properties new file mode 100644 index 000000000..ea3a6224b --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/it/MWAR-427_update-without-clean/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 diff --git a/Java-base/maven-war-plugin/src/src/it/MWAR-427_update-without-clean/pom.xml b/Java-base/maven-war-plugin/src/src/it/MWAR-427_update-without-clean/pom.xml new file mode 100644 index 000000000..a0d714624 --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/it/MWAR-427_update-without-clean/pom.xml @@ -0,0 +1,79 @@ + + + + + + 4.0.0 + + org.apache.maven.its.war + mwar427 + 1.0-SNAPSHOT + war + + + UTF-8 + + + + + + org.apache.maven.plugins + maven-war-plugin + @project.version@ + + true + + + + org.codehaus.gmaven + groovy-maven-plugin + 2.0 + + + 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' + + + + + + + + + javax.servlet + javax.servlet-api + 3.0.1 + provided + + + org.codehaus.plexus + plexus-utils + 1.4.6 + + + + diff --git a/Java-base/maven-war-plugin/src/src/it/MWAR-427_update-without-clean/src/main/resources/resource.txt b/Java-base/maven-war-plugin/src/src/it/MWAR-427_update-without-clean/src/main/resources/resource.txt new file mode 100644 index 000000000..13a83393a --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/it/MWAR-427_update-without-clean/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. diff --git a/Java-base/maven-war-plugin/src/src/it/MWAR-427_update-without-clean/src/main/webapp/index.html b/Java-base/maven-war-plugin/src/src/it/MWAR-427_update-without-clean/src/main/webapp/index.html new file mode 100644 index 000000000..8809bcf35 --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/it/MWAR-427_update-without-clean/src/main/webapp/index.html @@ -0,0 +1,23 @@ + + + + Hello World + + \ No newline at end of file diff --git a/Java-base/maven-war-plugin/src/src/it/MWAR-427_update-without-clean/verify.groovy b/Java-base/maven-war-plugin/src/src/it/MWAR-427_update-without-clean/verify.groovy new file mode 100644 index 000000000..5fdf4744d --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/it/MWAR-427_update-without-clean/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 \ No newline at end of file diff --git a/Java-base/maven-war-plugin/src/src/it/MWAR-430_jakarta-servlet/invoker.properties b/Java-base/maven-war-plugin/src/src/it/MWAR-430_jakarta-servlet/invoker.properties new file mode 100644 index 000000000..9695a95b5 --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/it/MWAR-430_jakarta-servlet/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.java.version = 1.8+ + diff --git a/Java-base/maven-war-plugin/src/src/it/MWAR-430_jakarta-servlet/pom.xml b/Java-base/maven-war-plugin/src/src/it/MWAR-430_jakarta-servlet/pom.xml new file mode 100644 index 000000000..8f773b1cb --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/it/MWAR-430_jakarta-servlet/pom.xml @@ -0,0 +1,66 @@ + + + + + + 4.0.0 + + org.apache.maven.its.war + maven-it-mwar-430 + 1.0 + war + + Maven Integration Test :: MWAR-430 + Test that no web.xml is required when project depends on Jakarta Servlet 5.0 or newer + + + UTF-8 + + + + + jakarta.servlet + jakarta.servlet-api + 5.0.0-M1 + provided + + + commons-logging + commons-logging + 1.0.3 + + + junit + junit + 3.8.2 + test + + + + + + + org.apache.maven.plugins + maven-war-plugin + @project.version@ + + + + diff --git a/Java-base/maven-war-plugin/src/src/it/MWAR-430_jakarta-servlet/verify.bsh b/Java-base/maven-war-plugin/src/src/it/MWAR-430_jakarta-servlet/verify.bsh new file mode 100644 index 000000000..3c7e8b5e1 --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/it/MWAR-430_jakarta-servlet/verify.bsh @@ -0,0 +1,49 @@ +/* + * 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. + */ + +import java.io.*; +import java.util.*; +import java.util.jar.*; +import java.util.regex.*; + +try +{ + File explodedDir = new File( basedir, "target/maven-it-mwar-430-1.0" ); + System.out.println( "Checking for existence of exploded directory " + explodedDir ); + if ( !explodedDir.exists() ) + { + System.out.println( "FAILURE! The directory " + explodedDir + " does not exist." ); + return false; + } + + File webInfFile = new File( explodedDir, "WEB-INF/web.xml" ); + if ( webInfFile.exists() ) + { + System.err.println( "FAILURE! The file web.xml should not be present." ); + return false; + } + +} +catch( Throwable t ) +{ + t.printStackTrace(); + return false; +} + +return true; diff --git a/Java-base/maven-war-plugin/src/src/it/MWAR-62/invoker.properties b/Java-base/maven-war-plugin/src/src/it/MWAR-62/invoker.properties new file mode 100644 index 000000000..7e6fbfd9f --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/it/MWAR-62/invoker.properties @@ -0,0 +1,18 @@ +# 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 war:exploded diff --git a/Java-base/maven-war-plugin/src/src/it/MWAR-62/pom.xml b/Java-base/maven-war-plugin/src/src/it/MWAR-62/pom.xml new file mode 100644 index 000000000..9c97e29bf --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/it/MWAR-62/pom.xml @@ -0,0 +1,50 @@ + + + + 4.0.0 + testwar + MWAR-62 + war + 1.0-SNAPSHOT + MWAR-62 Maven Webapp + http://maven.apache.org + + + junit + junit + 3.8.1 + test + + + + + + maven-war-plugin + + @pom.version@ + + ${project.build.directory}/webAppDirectory + src/main/webapp + **/*dev.properties,**/*test.properties + + + + + diff --git a/Java-base/maven-war-plugin/src/src/it/MWAR-62/src/main/webapp/dev.properties b/Java-base/maven-war-plugin/src/src/it/MWAR-62/src/main/webapp/dev.properties new file mode 100644 index 000000000..eb7ffe692 --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/it/MWAR-62/src/main/webapp/dev.properties @@ -0,0 +1,18 @@ +# 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. + +foo dev \ No newline at end of file diff --git a/Java-base/maven-war-plugin/src/src/it/MWAR-62/src/main/webapp/test.properties b/Java-base/maven-war-plugin/src/src/it/MWAR-62/src/main/webapp/test.properties new file mode 100644 index 000000000..eb7ffe692 --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/it/MWAR-62/src/main/webapp/test.properties @@ -0,0 +1,18 @@ +# 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. + +foo dev \ No newline at end of file diff --git a/Java-base/maven-war-plugin/src/src/it/MWAR-62/src/main/webapp/web.xml b/Java-base/maven-war-plugin/src/src/it/MWAR-62/src/main/webapp/web.xml new file mode 100644 index 000000000..6a8fa709e --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/it/MWAR-62/src/main/webapp/web.xml @@ -0,0 +1,24 @@ + + + + Archetype Created Web Application + diff --git a/Java-base/maven-war-plugin/src/src/it/MWAR-62/verify.bsh b/Java-base/maven-war-plugin/src/src/it/MWAR-62/verify.bsh new file mode 100644 index 000000000..0eeb6d9b1 --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/it/MWAR-62/verify.bsh @@ -0,0 +1,61 @@ + +/* + * 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. + */ + +import java.io.*; +import org.codehaus.plexus.util.*; + +boolean result = true; + +try +{ + File target = new File( basedir, "target" ); + if ( !target.exists() || !target.isDirectory() ) + { + System.err.println( "target file is missing or not a directory." ); + return false; + } + File webAppDirectory = new File( target, "webAppDirectory" ); + if ( !webAppDirectory.exists() || !webAppDirectory.isDirectory() ) + { + System.err.println( "webAppDirectory is missing or a not directory." ); + return false; + } + File devProperties = new File( webAppDirectory, "dev.properties" ); + if ( devProperties.exists() ) + { + System.err.println( "dev.properties has not been excluded." ); + return false; + } + + File testProperties = new File( webAppDirectory, "test.properties" ); + if ( testProperties.exists() ) + { + System.err.println( "test.properties has not been excluded." ); + return false; + } + +} +catch( Throwable e ) +{ + e.printStackTrace(); + result = false; +} + +return result; diff --git a/Java-base/maven-war-plugin/src/src/it/MWAR-96/pom.xml b/Java-base/maven-war-plugin/src/src/it/MWAR-96/pom.xml new file mode 100644 index 000000000..3a303a5e8 --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/it/MWAR-96/pom.xml @@ -0,0 +1,51 @@ + + + + 4.0.0 + testwar + MWAR-96 + war + 1.0-SNAPSHOT + MWAR-96 MWAR-144 Tests + http://maven.apache.org + + + + maven-war-plugin + @pom.version@ + + src/main/webapp + + src/main/filters/filter.properties + + + + true + src/main/webapp + + index.jsp + + + + + + + + diff --git a/Java-base/maven-war-plugin/src/src/it/MWAR-96/src/main/filters/filter.properties b/Java-base/maven-war-plugin/src/src/it/MWAR-96/src/main/filters/filter.properties new file mode 100644 index 000000000..0b24f47c7 --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/it/MWAR-96/src/main/filters/filter.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. +# */ +warPluginFilterConfigurationProperty=okitworks \ No newline at end of file diff --git a/Java-base/maven-war-plugin/src/src/it/MWAR-96/src/main/webapp/WEB-INF/web.xml b/Java-base/maven-war-plugin/src/src/it/MWAR-96/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 000000000..6a8fa709e --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/it/MWAR-96/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,24 @@ + + + + Archetype Created Web Application + diff --git a/Java-base/maven-war-plugin/src/src/it/MWAR-96/src/main/webapp/index.jsp b/Java-base/maven-war-plugin/src/src/it/MWAR-96/src/main/webapp/index.jsp new file mode 100755 index 000000000..2321faffc --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/it/MWAR-96/src/main/webapp/index.jsp @@ -0,0 +1,22 @@ + +java versionjava version : ${java.version} +Project${pom.name} +Version${pom.version} +custom filter${warPluginFilterConfigurationProperty} \ No newline at end of file diff --git a/Java-base/maven-war-plugin/src/src/it/MWAR-96/verify.bsh b/Java-base/maven-war-plugin/src/src/it/MWAR-96/verify.bsh new file mode 100644 index 000000000..18a6258eb --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/it/MWAR-96/verify.bsh @@ -0,0 +1,74 @@ + +/* + * 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. + */ + +import java.io.*; +import org.codehaus.plexus.util.*; + +boolean result = true; + +try +{ + File target = new File( basedir, "target" ); + if ( !target.exists() || !target.isDirectory() ) + { + System.err.println( "target file is missing or not a directory." ); + return false; + } + + File webappDirectory = new File( target, "MWAR-96-1.0-SNAPSHOT" ); + if ( !webappDirectory.exists() || !webappDirectory.isDirectory() ) + { + System.err.println( "webappDirectory is missing or not a directory." ); + return false; + } + + File param = new File( webappDirectory, "index.jsp" ); + if ( !param.exists() || param.isDirectory() ) + { + System.err.println( "index.jsp file is missing or a directory." ); + return false; + } + String paramContent = FileUtils.fileRead( param ); + + String javaVersion = System.getProperty( "java.version" ); + int indexOf = paramContent.indexOf( "java version : " + javaVersion + "" ); + if ( indexOf < 0 ) + { + paramContent = paramContent.substring( paramContent.indexOf( "java version : " ) ); + System.err.println( "index.jsp not contains java version : " + javaVersion + " but " + + paramContent.substring( 0, paramContent.indexOf( "" ) + 5 ) ); + return false; + } + + indexOf = paramContent.indexOf("okitworks" ); + if ( indexOf < 0 ) + { + System.err.println( "index.jsp not contains okitworks" ); + return false; + } + +} +catch( Throwable e ) +{ + e.printStackTrace(); + result = false; +} + +return result; diff --git a/Java-base/maven-war-plugin/src/src/it/archiveClasses/pom.xml b/Java-base/maven-war-plugin/src/src/it/archiveClasses/pom.xml new file mode 100644 index 000000000..a7c516631 --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/it/archiveClasses/pom.xml @@ -0,0 +1,70 @@ + + + + + + 4.0.0 + + org.apache.maven.its.mwar-45 + maven-it-mwar-45 + 1.0 + war + + Maven Integration Test :: MWAR-45 + Test a WAR generation with archiveClasses=true + + + UTF-8 + 2020-06-06T06:50:15Z + + + + + javax.servlet + servlet-api + 2.4 + provided + + + commons-logging + commons-logging + 1.0.3 + + + junit + junit + 3.8.2 + test + + + + + + + org.apache.maven.plugins + maven-war-plugin + @project.version@ + + true + + + + + diff --git a/Java-base/maven-war-plugin/src/src/it/archiveClasses/src/main/java/org/apache/maven/it0016/Person.java b/Java-base/maven-war-plugin/src/src/it/archiveClasses/src/main/java/org/apache/maven/it0016/Person.java new file mode 100644 index 000000000..4a287e77c --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/it/archiveClasses/src/main/java/org/apache/maven/it0016/Person.java @@ -0,0 +1,35 @@ +package org.apache.maven.it0016; + +/* + * 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. + */ + +public class Person +{ + private String name; + + public void setName( String name ) + { + this.name = name; + } + + public String getName() + { + return name; + } +} diff --git a/Java-base/maven-war-plugin/src/src/it/archiveClasses/src/main/webapp/WEB-INF/web.xml b/Java-base/maven-war-plugin/src/src/it/archiveClasses/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 000000000..c1af95de8 --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/it/archiveClasses/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,23 @@ + + + + + + diff --git a/Java-base/maven-war-plugin/src/src/it/archiveClasses/src/main/webapp/index.html b/Java-base/maven-war-plugin/src/src/it/archiveClasses/src/main/webapp/index.html new file mode 100644 index 000000000..8e81e877d --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/it/archiveClasses/src/main/webapp/index.html @@ -0,0 +1,23 @@ + + + + Hello World + + diff --git a/Java-base/maven-war-plugin/src/src/it/archiveClasses/verify.bsh b/Java-base/maven-war-plugin/src/src/it/archiveClasses/verify.bsh new file mode 100644 index 000000000..9b3da7509 --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/it/archiveClasses/verify.bsh @@ -0,0 +1,99 @@ +/* + * 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. + */ + +import java.io.*; +import java.util.*; +import java.util.jar.*; +import java.util.regex.*; + +try +{ + File explodedDir = new File( basedir, "target/maven-it-mwar-45-1.0" ); + System.out.println( "Checking for existence of exploded directory " + explodedDir ); + if ( !explodedDir.isDirectory() ) + { + System.out.println( "FAILURE!" ); + return false; + } + + String[] expectedPaths = { + "index.html", + "WEB-INF/lib/commons-logging-1.0.3.jar", + "WEB-INF/lib/maven-it-mwar-45-1.0.jar", + }; + for ( String path : expectedPaths ) + { + File file = new File( explodedDir, path ); + System.out.println( "Checking for existence of " + file ); + if ( !file.exists() ) + { + System.out.println( "FAILURE!" ); + return false; + } + } + + String[] unexpectedPaths = { + "WEB-INF/classes/org/apache/maven/it0016/Person.class", + "WEB-INF/lib/servlet-api-2.4.jar", + }; + for ( String path : unexpectedPaths ) + { + File file = new File( explodedDir, path ); + System.out.println( "Checking for absence of " + file ); + if ( file.exists() ) + { + System.out.println( "FAILURE!" ); + return false; + } + } + + File warFile = new File( basedir, "target/maven-it-mwar-45-1.0.war" ); + System.out.println( "Checking for existence of " + warFile ); + if ( !warFile.isFile() ) + { + System.out.println( "FAILURE!" ); + return false; + } + + JarFile war = new JarFile( warFile ); + + String[] includedEntries = { + "index.html", + "WEB-INF/lib/maven-it-mwar-45-1.0.jar", + "WEB-INF/lib/commons-logging-1.0.3.jar", + }; + for ( String included : includedEntries ) + { + System.out.println( "Checking for existence of " + included ); + if ( war.getEntry( included ) == null ) + { + System.out.println( "FAILURE!" ); + return false; + } + } + + war.close(); +} +catch( Throwable t ) +{ + t.printStackTrace(); + return false; +} + +return true; diff --git a/Java-base/maven-war-plugin/src/src/it/default/pom.xml b/Java-base/maven-war-plugin/src/src/it/default/pom.xml new file mode 100644 index 000000000..10554a86b --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/it/default/pom.xml @@ -0,0 +1,66 @@ + + + + + + 4.0.0 + + org.apache.maven.its.it0016 + maven-it-it0016 + 1.0 + war + + Maven Integration Test :: it0016 + Test a WAR generation + + + UTF-8 + + + + + javax.servlet + servlet-api + 2.4 + provided + + + commons-logging + commons-logging + 1.0.3 + + + junit + junit + 3.8.2 + test + + + + + + + org.apache.maven.plugins + maven-war-plugin + @project.version@ + + + + diff --git a/Java-base/maven-war-plugin/src/src/it/default/src/main/java/org/apache/maven/it0016/Person.java b/Java-base/maven-war-plugin/src/src/it/default/src/main/java/org/apache/maven/it0016/Person.java new file mode 100644 index 000000000..4a287e77c --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/it/default/src/main/java/org/apache/maven/it0016/Person.java @@ -0,0 +1,35 @@ +package org.apache.maven.it0016; + +/* + * 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. + */ + +public class Person +{ + private String name; + + public void setName( String name ) + { + this.name = name; + } + + public String getName() + { + return name; + } +} diff --git a/Java-base/maven-war-plugin/src/src/it/default/src/main/webapp/WEB-INF/web.xml b/Java-base/maven-war-plugin/src/src/it/default/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 000000000..c1af95de8 --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/it/default/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,23 @@ + + + + + + diff --git a/Java-base/maven-war-plugin/src/src/it/default/src/main/webapp/index.html b/Java-base/maven-war-plugin/src/src/it/default/src/main/webapp/index.html new file mode 100644 index 000000000..8e81e877d --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/it/default/src/main/webapp/index.html @@ -0,0 +1,23 @@ + + + + Hello World + + diff --git a/Java-base/maven-war-plugin/src/src/it/default/verify.bsh b/Java-base/maven-war-plugin/src/src/it/default/verify.bsh new file mode 100644 index 000000000..af15a8196 --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/it/default/verify.bsh @@ -0,0 +1,97 @@ +/* + * 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. + */ + +import java.io.*; +import java.util.*; +import java.util.jar.*; +import java.util.regex.*; + +try +{ + File explodedDir = new File( basedir, "target/maven-it-it0016-1.0" ); + System.out.println( "Checking for existence of exploded directory " + explodedDir ); + if ( !explodedDir.isDirectory() ) + { + System.out.println( "FAILURE!" ); + return false; + } + + String[] expectedPaths = { + "index.html", + "WEB-INF/classes/org/apache/maven/it0016/Person.class", + "WEB-INF/lib/commons-logging-1.0.3.jar", + }; + for ( String path : expectedPaths ) + { + File file = new File( explodedDir, path ); + System.out.println( "Checking for existence of " + file ); + if ( !file.exists() ) + { + System.out.println( "FAILURE!" ); + return false; + } + } + + String[] unexpectedPaths = { + "WEB-INF/lib/servlet-api-2.4.jar", + }; + for ( String path : unexpectedPaths ) + { + File file = new File( explodedDir, path ); + System.out.println( "Checking for absence of " + file ); + if ( file.exists() ) + { + System.out.println( "FAILURE!" ); + return false; + } + } + + File warFile = new File( basedir, "target/maven-it-it0016-1.0.war" ); + System.out.println( "Checking for existence of " + warFile ); + if ( !warFile.isFile() ) + { + System.out.println( "FAILURE!" ); + return false; + } + + JarFile war = new JarFile( warFile ); + + String[] includedEntries = { + "WEB-INF/classes/org/apache/maven/it0016/Person.class", + "WEB-INF/lib/commons-logging-1.0.3.jar", + }; + for ( String included : includedEntries ) + { + System.out.println( "Checking for existence of " + included ); + if ( war.getEntry( included ) == null ) + { + System.out.println( "FAILURE!" ); + return false; + } + } + + war.close(); +} +catch( Throwable t ) +{ + t.printStackTrace(); + return false; +} + +return true; diff --git a/Java-base/maven-war-plugin/src/src/it/manifest-content/pom.xml b/Java-base/maven-war-plugin/src/src/it/manifest-content/pom.xml new file mode 100644 index 000000000..bcfa76d0b --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/it/manifest-content/pom.xml @@ -0,0 +1,50 @@ + + + + 4.0.0 + test + manifest-content + war + 1.0-SNAPSHOT + Maven War Manifest Content Test + + war plugin it + + + + + maven-war-plugin + @pom.version@ + + false + + true + + true + true + + + + + + + \ No newline at end of file diff --git a/Java-base/maven-war-plugin/src/src/it/manifest-content/src/main/webapp/index.jsp b/Java-base/maven-war-plugin/src/src/it/manifest-content/src/main/webapp/index.jsp new file mode 100644 index 000000000..41db44eef --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/it/manifest-content/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/Java-base/maven-war-plugin/src/src/it/manifest-content/verify.bsh b/Java-base/maven-war-plugin/src/src/it/manifest-content/verify.bsh new file mode 100644 index 000000000..8980a6f86 --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/it/manifest-content/verify.bsh @@ -0,0 +1,96 @@ + +/* + * 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. + */ + +import java.io.*; +import java.util.*; +import java.util.jar.*; +import org.codehaus.plexus.util.*; + +boolean result = true; + +try +{ + File target = new File( basedir, "target" ); + if ( !target.exists() || !target.isDirectory() ) + { + System.err.println( "target file is missing or not a directory." ); + return false; + } + + File artifact = new File( target, "manifest-content-1.0-SNAPSHOT.war" ); + if ( !artifact.exists() || artifact.isDirectory() ) + { + System.err.println( "artifact file is missing or a directory." ); + return false; + } + + JarFile jar = new JarFile( artifact ); + + Attributes manifest = jar.getManifest().getMainAttributes(); + + if ( !"Maven War Manifest Content Test".equals( manifest.get( Attributes.Name.SPECIFICATION_TITLE ) ) ) + { + System.err.println( "Incorrect '" + Attributes.Name.SPECIFICATION_TITLE.toString() + "' manifest entry: " + + manifest.get( Attributes.Name.SPECIFICATION_TITLE ) ); + return false; + } + + if ( !"1.0".equals( manifest.get( Attributes.Name.SPECIFICATION_VERSION ) ) ) + { + System.err.println( "Incorrect '" + Attributes.Name.SPECIFICATION_VERSION.toString() + "' manifest entry: " + + manifest.get( Attributes.Name.SPECIFICATION_VERSION ) ); + return false; + } + + if ( !"war plugin it".equals( manifest.get( Attributes.Name.SPECIFICATION_VENDOR ) ) ) + { + System.err.println( "Incorrect '" + Attributes.Name.SPECIFICATION_VENDOR.toString() + "' manifest entry: " + + manifest.get( Attributes.Name.SPECIFICATION_VENDOR ) ); + return false; + } + + if ( !"Maven War Manifest Content Test".equals( manifest.get( Attributes.Name.IMPLEMENTATION_TITLE ) ) ) + { + System.err.println( "Incorrect '" + Attributes.Name.IMPLEMENTATION_TITLE.toString() + "' manifest entry: " + + manifest.get( Attributes.Name.IMPLEMENTATION_TITLE ) ); + return false; + } + + if ( !"1.0-SNAPSHOT".equals( manifest.get( Attributes.Name.IMPLEMENTATION_VERSION ) ) ) + { + System.err.println( "Incorrect '" + Attributes.Name.IMPLEMENTATION_VERSION.toString() + "' manifest entry: " + + manifest.get( Attributes.Name.IMPLEMENTATION_VERSION ) ); + return false; + } + + if ( !"war plugin it".equals( manifest.get( Attributes.Name.IMPLEMENTATION_VENDOR ) ) ) + { + System.err.println( "Incorrect '" + Attributes.Name.IMPLEMENTATION_VENDOR.toString() + "' manifest entry: " + + manifest.get( Attributes.Name.IMPLEMENTATION_VENDOR ) ); + return false; + } +} +catch( Throwable e ) +{ + e.printStackTrace(); + result = false; +} + +return result; diff --git a/Java-base/maven-war-plugin/src/src/it/overlay-excludes/invoker.properties b/Java-base/maven-war-plugin/src/src/it/overlay-excludes/invoker.properties new file mode 100644 index 000000000..3376b9e49 --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/it/overlay-excludes/invoker.properties @@ -0,0 +1,18 @@ +# 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 install diff --git a/Java-base/maven-war-plugin/src/src/it/overlay-excludes/pom.xml b/Java-base/maven-war-plugin/src/src/it/overlay-excludes/pom.xml new file mode 100644 index 000000000..63c55d499 --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/it/overlay-excludes/pom.xml @@ -0,0 +1,44 @@ + + + + 4.0.0 + debug.war + overlay-excludes + pom + 1.0-SNAPSHOT + test of overlay with exclusions + http://maven.apache.org + + war-overlay + war-exclude-overlay + + + + + + maven-war-plugin + @pom.version@ + + + + + diff --git a/Java-base/maven-war-plugin/src/src/it/overlay-excludes/verify.bsh b/Java-base/maven-war-plugin/src/src/it/overlay-excludes/verify.bsh new file mode 100644 index 000000000..0ba9a0b50 --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/it/overlay-excludes/verify.bsh @@ -0,0 +1,31 @@ + +/* + * 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. + */ + +import java.io.*; +import org.codehaus.plexus.util.*; + + + File testFile = new File( basedir, "war-exclude-overlay/target/war-exclude-overlay-1.0-SNAPSHOT/lib/js/something/else.js"); + if ( testFile.exists() ) + { + System.err.println( "exclude didn't exclude." ); + return false; + } + diff --git a/Java-base/maven-war-plugin/src/src/it/overlay-excludes/war-exclude-overlay/pom.xml b/Java-base/maven-war-plugin/src/src/it/overlay-excludes/war-exclude-overlay/pom.xml new file mode 100644 index 000000000..c735de79a --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/it/overlay-excludes/war-exclude-overlay/pom.xml @@ -0,0 +1,61 @@ + + + + 4.0.0 + + debug.war + overlay-excludes + 1.0-SNAPSHOT + + war-exclude-overlay + war + + + + + debug.war + war-overlay + 1.0-SNAPSHOT + war + runtime + + + + + + + org.apache.maven.plugins + maven-war-plugin + + + + debug.war + war-overlay + + lib/js/** + + + + + + + + diff --git a/Java-base/maven-war-plugin/src/src/it/overlay-excludes/war-exclude-overlay/src/main/webapp/WEB-INF/web.xml b/Java-base/maven-war-plugin/src/src/it/overlay-excludes/war-exclude-overlay/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 000000000..fc6e240ce --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/it/overlay-excludes/war-exclude-overlay/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,26 @@ + + + + + + diff --git a/Java-base/maven-war-plugin/src/src/it/overlay-excludes/war-overlay/pom.xml b/Java-base/maven-war-plugin/src/src/it/overlay-excludes/war-overlay/pom.xml new file mode 100644 index 000000000..80f19956a --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/it/overlay-excludes/war-overlay/pom.xml @@ -0,0 +1,30 @@ + + + + 4.0.0 + + debug.war + overlay-excludes + 1.0-SNAPSHOT + + war-overlay + war + diff --git a/Java-base/maven-war-plugin/src/src/it/overlay-excludes/war-overlay/src/main/webapp/WEB-INF/web.xml b/Java-base/maven-war-plugin/src/src/it/overlay-excludes/war-overlay/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 000000000..357cf72ca --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/it/overlay-excludes/war-overlay/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,25 @@ + + + + + diff --git a/Java-base/maven-war-plugin/src/src/it/overlay-excludes/war-overlay/src/main/webapp/lib/js/something/else.js b/Java-base/maven-war-plugin/src/src/it/overlay-excludes/war-overlay/src/main/webapp/lib/js/something/else.js new file mode 100644 index 000000000..b7bb67336 --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/it/overlay-excludes/war-overlay/src/main/webapp/lib/js/something/else.js @@ -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. + */ + +/* a javascript file, sort of */ diff --git a/Java-base/maven-war-plugin/src/src/it/overlay-keeps-contextxml/invoker.properties b/Java-base/maven-war-plugin/src/src/it/overlay-keeps-contextxml/invoker.properties new file mode 100644 index 000000000..3376b9e49 --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/it/overlay-keeps-contextxml/invoker.properties @@ -0,0 +1,18 @@ +# 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 install diff --git a/Java-base/maven-war-plugin/src/src/it/overlay-keeps-contextxml/pom.xml b/Java-base/maven-war-plugin/src/src/it/overlay-keeps-contextxml/pom.xml new file mode 100644 index 000000000..ade7a13a3 --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/it/overlay-keeps-contextxml/pom.xml @@ -0,0 +1,44 @@ + + + + 4.0.0 + debug.war + overlay-keeps-contextxml + pom + 1.0-SNAPSHOT + test that default overlay keeps META-INF/context.xml + http://maven.apache.org + + war1-with-contextxml + war2-result + + + + + + maven-war-plugin + @pom.version@ + + + + + diff --git a/Java-base/maven-war-plugin/src/src/it/overlay-keeps-contextxml/verify.bsh b/Java-base/maven-war-plugin/src/src/it/overlay-keeps-contextxml/verify.bsh new file mode 100644 index 000000000..f0c99d7ba --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/it/overlay-keeps-contextxml/verify.bsh @@ -0,0 +1,31 @@ + +/* + * 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. + */ + +import java.io.*; +import org.codehaus.plexus.util.*; + + + File testFile = new File( basedir, "war2-result/target/war2-result-1.0-SNAPSHOT/META-INF/context.xml"); + if ( !testFile.exists() ) + { + System.err.println( "war1 META-INF/context.xml lost in overlay process" ); + return false; + } + diff --git a/Java-base/maven-war-plugin/src/src/it/overlay-keeps-contextxml/war1-with-contextxml/pom.xml b/Java-base/maven-war-plugin/src/src/it/overlay-keeps-contextxml/war1-with-contextxml/pom.xml new file mode 100644 index 000000000..cfa52bf19 --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/it/overlay-keeps-contextxml/war1-with-contextxml/pom.xml @@ -0,0 +1,31 @@ + + + + 4.0.0 + + debug.war + overlay-keeps-contextxml + 1.0-SNAPSHOT + + war1-with-contextxml + war + + diff --git a/Java-base/maven-war-plugin/src/src/it/overlay-keeps-contextxml/war1-with-contextxml/src/main/webapp/META-INF/context.xml b/Java-base/maven-war-plugin/src/src/it/overlay-keeps-contextxml/war1-with-contextxml/src/main/webapp/META-INF/context.xml new file mode 100644 index 000000000..b14753a76 --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/it/overlay-keeps-contextxml/war1-with-contextxml/src/main/webapp/META-INF/context.xml @@ -0,0 +1,19 @@ + + diff --git a/Java-base/maven-war-plugin/src/src/it/overlay-keeps-contextxml/war1-with-contextxml/src/main/webapp/WEB-INF/web.xml b/Java-base/maven-war-plugin/src/src/it/overlay-keeps-contextxml/war1-with-contextxml/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 000000000..c873e8a02 --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/it/overlay-keeps-contextxml/war1-with-contextxml/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,25 @@ + + + + + diff --git a/Java-base/maven-war-plugin/src/src/it/overlay-keeps-contextxml/war2-result/pom.xml b/Java-base/maven-war-plugin/src/src/it/overlay-keeps-contextxml/war2-result/pom.xml new file mode 100644 index 000000000..3656cf311 --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/it/overlay-keeps-contextxml/war2-result/pom.xml @@ -0,0 +1,40 @@ + + + + 4.0.0 + + debug.war + overlay-keeps-contextxml + 1.0-SNAPSHOT + + war2-result + war + + + + debug.war + war1-with-contextxml + 1.0-SNAPSHOT + war + runtime + + + diff --git a/Java-base/maven-war-plugin/src/src/it/overlay-keeps-contextxml/war2-result/src/main/webapp/WEB-INF/web.xml b/Java-base/maven-war-plugin/src/src/it/overlay-keeps-contextxml/war2-result/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 000000000..c873e8a02 --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/it/overlay-keeps-contextxml/war2-result/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,25 @@ + + + + + diff --git a/Java-base/maven-war-plugin/src/src/it/scoped-dependency-same-artifact/invoker.properties b/Java-base/maven-war-plugin/src/src/it/scoped-dependency-same-artifact/invoker.properties new file mode 100644 index 000000000..c743aa4f3 --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/it/scoped-dependency-same-artifact/invoker.properties @@ -0,0 +1,18 @@ +# 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 diff --git a/Java-base/maven-war-plugin/src/src/it/scoped-dependency-same-artifact/pom.xml b/Java-base/maven-war-plugin/src/src/it/scoped-dependency-same-artifact/pom.xml new file mode 100644 index 000000000..8c882baac --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/it/scoped-dependency-same-artifact/pom.xml @@ -0,0 +1,53 @@ + + + + 4.0.0 + test + scope-depdency-same-artifact + war + 1.0-SNAPSHOT + Maven Simple War Project Test + + + + maven-war-plugin + @pom.version@ + + + + + + + + + org.codehaus.plexus + plexus-utils + 1.4.7 + + + org.codehaus.plexus + plexus-utils + sources + 1.4.7 + + + \ No newline at end of file diff --git a/Java-base/maven-war-plugin/src/src/it/scoped-dependency-same-artifact/src/main/webapp/WEB-INF/web.xml b/Java-base/maven-war-plugin/src/src/it/scoped-dependency-same-artifact/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 000000000..873dd4794 --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/it/scoped-dependency-same-artifact/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,29 @@ + + + + + + + Maven Simple War Project Test + + + diff --git a/Java-base/maven-war-plugin/src/src/it/scoped-dependency-same-artifact/src/main/webapp/index.jsp b/Java-base/maven-war-plugin/src/src/it/scoped-dependency-same-artifact/src/main/webapp/index.jsp new file mode 100644 index 000000000..41db44eef --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/it/scoped-dependency-same-artifact/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/Java-base/maven-war-plugin/src/src/it/scoped-dependency-same-artifact/verify.bsh b/Java-base/maven-war-plugin/src/src/it/scoped-dependency-same-artifact/verify.bsh new file mode 100644 index 000000000..057d78828 --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/it/scoped-dependency-same-artifact/verify.bsh @@ -0,0 +1,88 @@ + +/* + * 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. + */ + +import java.io.*; + +boolean result = true; + +try +{ + File target = new File( basedir, "target" ); + if ( !target.exists() || !target.isDirectory() ) + { + System.err.println( "target file is missing or a directory." ); + return false; + } + + File webappDirectory = new File( target, "scope-depdency-same-artifact-1.0-SNAPSHOT" ); + if ( !webappDirectory.exists() || !webappDirectory.isDirectory() ) + { + System.err.println( "webappDirectory is missing or not a directory." ); + return false; + } + + File webInfFile = new File( webappDirectory, "WEB-INF/web.xml" ); + if ( !webInfFile.exists() || webInfFile.isDirectory() ) + { + System.err.println( "webInfFile is missing or a directory." ); + return false; + } + + File indexJsp = new File( webappDirectory, "index.jsp" ); + if ( !indexJsp.exists() || indexJsp.isDirectory() ) + { + System.err.println( "indexJsp is missing or a directory." ); + return false; + } + + File warFile = new File( target, "scope-depdency-same-artifact-1.0-SNAPSHOT.war" ); + if ( !warFile.exists() || warFile.isDirectory() ) + { + System.err.println( "warFile is missing or a directory." ); + return false; + } + + File libDir = new File( webappDirectory, "WEB-INF/lib" ); + if ( !libDir.exists() || !libDir.isDirectory() ) + { + System.err.println( "WEB-INF/lib is missing or not a directory." ); + return false; + } + + File plexusUtilsDependency = new File( libDir, "plexus-utils-1.4.7.jar" ); + if ( !plexusUtilsDependency.exists() || plexusUtilsDependency.isDirectory() ) + { + System.err.println( "plexus-utils-1.4.7.jar is missing or a directory." ); + return false; + } + File plexusUtilsSourceDependency = new File( libDir, "plexus-utils-1.4.7-sources.jar" ); + if ( !plexusUtilsSourceDependency.exists() || plexusUtilsSourceDependency.isDirectory() ) + { + System.err.println( "plexus-utils-1.4.7-sources.jar is missing or a directory." ); + return false; + } +} +catch( IOException e ) +{ + e.printStackTrace(); + result = false; +} + +return result; diff --git a/Java-base/maven-war-plugin/src/src/it/settings.xml b/Java-base/maven-war-plugin/src/src/it/settings.xml new file mode 100644 index 000000000..c8f77f0b7 --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/it/settings.xml @@ -0,0 +1,55 @@ + + + + + + + + it-repo + + true + + + + local.central + @localRepositoryUrl@ + + true + + + true + + + + + + local.central + @localRepositoryUrl@ + + true + + + true + + + + + + diff --git a/Java-base/maven-war-plugin/src/src/it/simple-war-no-webxml/invoker.properties b/Java-base/maven-war-plugin/src/src/it/simple-war-no-webxml/invoker.properties new file mode 100644 index 000000000..692791cf1 --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/it/simple-war-no-webxml/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/Java-base/maven-war-plugin/src/src/it/simple-war-no-webxml/pom.xml b/Java-base/maven-war-plugin/src/src/it/simple-war-no-webxml/pom.xml new file mode 100644 index 000000000..31cc0568f --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/it/simple-war-no-webxml/pom.xml @@ -0,0 +1,47 @@ + + + + 4.0.0 + test + simple-war-no-webxml + war + 1.0-SNAPSHOT + Maven Simple War Project Test + + + + maven-war-plugin + @pom.version@ + + false + + + + + + + org.codehaus.plexus + plexus-utils + 1.4.6 + + + \ No newline at end of file diff --git a/Java-base/maven-war-plugin/src/src/it/simple-war-no-webxml/src/main/webapp/index.jsp b/Java-base/maven-war-plugin/src/src/it/simple-war-no-webxml/src/main/webapp/index.jsp new file mode 100644 index 000000000..41db44eef --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/it/simple-war-no-webxml/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/Java-base/maven-war-plugin/src/src/it/simple-war-no-webxml/verify.bsh b/Java-base/maven-war-plugin/src/src/it/simple-war-no-webxml/verify.bsh new file mode 100644 index 000000000..b163bbe86 --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/it/simple-war-no-webxml/verify.bsh @@ -0,0 +1,82 @@ + +/* + * 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. + */ + +import java.io.*; + +boolean result = true; + +try +{ + File target = new File( basedir, "target" ); + if ( !target.exists() || !target.isDirectory() ) + { + System.err.println( "target file is missing or a directory." ); + return false; + } + + File webappDirectory = new File( target, "simple-war-no-webxml-1.0-SNAPSHOT" ); + if ( !webappDirectory.exists() || !webappDirectory.isDirectory() ) + { + System.err.println( "webappDirectory is missing or not a directory." ); + return false; + } + + File webInfFile = new File( webappDirectory, "WEB-INF/web.xml" ); + if ( webInfFile.exists()) + { + System.err.println( "web.xml should not be there." ); + return false; + } + + File indexJsp = new File( webappDirectory, "index.jsp" ); + if ( !indexJsp.exists() || indexJsp.isDirectory() ) + { + System.err.println( "indexJsp is missing or a directory." ); + return false; + } + + File warFile = new File( target, "simple-war-no-webxml-1.0-SNAPSHOT.war" ); + if ( !warFile.exists() || warFile.isDirectory() ) + { + System.err.println( "warFile is missing or a directory." ); + return false; + } + + File libDir = new File( webappDirectory, "WEB-INF/lib" ); + if ( !libDir.exists() || !libDir.isDirectory() ) + { + System.err.println( "WEB-INF/lib is missing or not a directory." ); + return false; + } + + File plexusUtilsDependency = new File( libDir, "plexus-utils-1.4.6.jar" ); + if ( !plexusUtilsDependency.exists() || plexusUtilsDependency.isDirectory() ) + { + System.err.println( "plexus-utils-1.4.6.jar is missing or a directory." ); + return false; + } +} +catch( IOException e ) +{ + e.printStackTrace(); + result = false; +} + +return result; diff --git a/Java-base/maven-war-plugin/src/src/it/simple-war-project/invoker.properties b/Java-base/maven-war-plugin/src/src/it/simple-war-project/invoker.properties new file mode 100644 index 000000000..c743aa4f3 --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/it/simple-war-project/invoker.properties @@ -0,0 +1,18 @@ +# 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 diff --git a/Java-base/maven-war-plugin/src/src/it/simple-war-project/pom.xml b/Java-base/maven-war-plugin/src/src/it/simple-war-project/pom.xml new file mode 100644 index 000000000..a70c4e8a6 --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/it/simple-war-project/pom.xml @@ -0,0 +1,54 @@ + + + + 4.0.0 + test + simple-war-project + war + 1.0-SNAPSHOT + Maven Simple War Project Test + maven test it + + + 2020-05-01T12:12:12Z + + + + + + maven-war-plugin + @pom.version@ + + + true + + + + + + + + org.codehaus.plexus + plexus-utils + 1.4.6 + + + \ No newline at end of file diff --git a/Java-base/maven-war-plugin/src/src/it/simple-war-project/src/main/webapp/WEB-INF/web.xml b/Java-base/maven-war-plugin/src/src/it/simple-war-project/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 000000000..488bc9739 --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/it/simple-war-project/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,29 @@ + + + + + + + ${pom.description} + + + diff --git a/Java-base/maven-war-plugin/src/src/it/simple-war-project/src/main/webapp/index.jsp b/Java-base/maven-war-plugin/src/src/it/simple-war-project/src/main/webapp/index.jsp new file mode 100755 index 000000000..4e817f7e9 --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/it/simple-war-project/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/Java-base/maven-war-plugin/src/src/it/simple-war-project/verify.bsh b/Java-base/maven-war-plugin/src/src/it/simple-war-project/verify.bsh new file mode 100644 index 000000000..7dc3d728a --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/it/simple-war-project/verify.bsh @@ -0,0 +1,96 @@ + +/* + * 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. + */ + +import java.io.*; + +import org.codehaus.plexus.util.*; + +boolean result = true; + +try +{ + File target = new File( basedir, "target" ); + if ( !target.exists() || !target.isDirectory() ) + { + System.err.println( "target file is missing or a directory." ); + return false; + } + + File webappDirectory = new File( target, "simple-war-project-1.0-SNAPSHOT" ); + if ( !webappDirectory.exists() || !webappDirectory.isDirectory() ) + { + System.err.println( "webappDirectory is missing or not a directory." ); + return false; + } + + File webInfFile = new File( webappDirectory, "WEB-INF/web.xml" ); + if ( !webInfFile.exists() || webInfFile.isDirectory() ) + { + System.err.println( "webInfFile is missing or a directory." ); + return false; + } + + + + String paramContent = FileUtils.fileRead( webInfFile, "UTF-8" ); + + + int indexOf = paramContent.indexOf( "maven test it" ); + if ( indexOf < 0 ) + { + System.err.println( "web.xml not contains maven test it" ); + return false; + } + + File indexJsp = new File( webappDirectory, "index.jsp" ); + if ( !indexJsp.exists() || indexJsp.isDirectory() ) + { + System.err.println( "indexJsp is missing or a directory." ); + return false; + } + + File warFile = new File( target, "simple-war-project-1.0-SNAPSHOT.war" ); + if ( !warFile.exists() || warFile.isDirectory() ) + { + System.err.println( "warFile is missing or a directory." ); + return false; + } + + File libDir = new File( webappDirectory, "WEB-INF/lib" ); + if ( !libDir.exists() || !libDir.isDirectory() ) + { + System.err.println( "WEB-INF/lib is missing or not a directory." ); + return false; + } + + File plexusUtilsDependency = new File( libDir, "plexus-utils-1.4.6.jar" ); + if ( !plexusUtilsDependency.exists() || plexusUtilsDependency.isDirectory() ) + { + System.err.println( "plexus-utils-1.4.6.jar is missing or a directory." ); + return false; + } +} +catch( IOException e ) +{ + e.printStackTrace(); + result = false; +} + +return result; diff --git a/Java-base/maven-war-plugin/src/src/it/web-resources-filtering-delimiter/parent/pom.xml b/Java-base/maven-war-plugin/src/src/it/web-resources-filtering-delimiter/parent/pom.xml new file mode 100644 index 000000000..cee6b8395 --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/it/web-resources-filtering-delimiter/parent/pom.xml @@ -0,0 +1,62 @@ + + + + + 4.0.0 + + Company Parent + Parent that handles dependencyManagement + + com.edb.finance.example + example-parent + 1.0.0-SNAPSHOT + pom + 2008 + + + + 1 + Valeriy Molyakov + valeriy.molyakov@infopulse.com.ua + EDB Business Partner + http://www.edb.com + + developer + + +2 + + + + + + sample.website + ${website.url}/${project.name} + + + + + + jdbc:oracle:thin:@localhost:1521:orcl + scp://www.yourcompany.com/www/docs/project + + + diff --git a/Java-base/maven-war-plugin/src/src/it/web-resources-filtering-delimiter/pom.xml b/Java-base/maven-war-plugin/src/src/it/web-resources-filtering-delimiter/pom.xml new file mode 100644 index 000000000..84391162f --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/it/web-resources-filtering-delimiter/pom.xml @@ -0,0 +1,44 @@ + + + + 4.0.0 + + + com.edb.finance.example + example-parent + 1.0.0-SNAPSHOT + parent/pom.xml + + + + example + pom + + Example Maven Multi-module project For Filtering with Delimiters + http://maven.apache.org + + + parent + web + + + + diff --git a/Java-base/maven-war-plugin/src/src/it/web-resources-filtering-delimiter/verify.bsh b/Java-base/maven-war-plugin/src/src/it/web-resources-filtering-delimiter/verify.bsh new file mode 100644 index 000000000..dd86ecd4b --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/it/web-resources-filtering-delimiter/verify.bsh @@ -0,0 +1,108 @@ + +/* + * 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. + */ + +import java.io.*; + +import org.codehaus.plexus.util.*; + +boolean result = true; + +try +{ + // Load and check jetty-env.xml + + File target = new File( basedir, "web/target/example-web/WEB-INF" ); + if ( !target.exists() || !target.isDirectory() ) + { + System.err.println( "web/target/example-web/WEB-INF is missing or is not a directory." ); + return false; + } + + File jettyEnv = new File( target, "jetty-env.xml" ); + if ( !jettyEnv.exists() || jettyEnv.isDirectory() ) + { + System.err.println( "jetty-env.xml is missing or is a directory." ); + return false; + } + + + FileInputStream fis = new FileInputStream ( jettyEnv ); + String paramContent = IOUtil.toString ( fis, "UTF-8" ); + + System.out.println( "content='" + paramContent + "'" ); + + + int indexOf = paramContent.indexOf( "Characters that should be encoded in UTF-8: åäö" ); + if ( indexOf < 0 ) + { + System.err.println( "Non-ascii characters changed encoding during filtering" ); + return false; + } + + indexOf = paramContent.indexOf( "jdbc:oracle:thin:@localhost:1521:orcl" ); + if ( indexOf < 0 ) + { + System.err.println( "jdbc.url not filtered correctly" ); + return false; + } + + indexOf = paramContent.indexOf( "@@jdbc.password@@" ); + if ( indexOf < 0 ) + { + System.err.println( "jdbc.password has been filtered" ); + return false; + } + + // Load and check my.properties + + target = new File( basedir, "web/target/example-web/WEB-INF/classes" ); + if ( !target.exists() || !target.isDirectory() ) + { + System.err.println( "web/target/example-web/WEB-INF/classes is missing or is not a directory." ); + return false; + } + + File myProperties = new File( target, "my.properties" ); + if ( !myProperties.exists() || myProperties.isDirectory() ) + { + System.err.println( "my.properties is missing or is a directory." ); + return false; + } + + Properties properties = new Properties(); + FileInputStream fis = new FileInputStream( myProperties ); + properties.load( fis ); + fis.close(); + + String property = properties.get( "my.property" ); + System.out.println( "my.property='" + property + "'" ); + if ( !"Characters that should be encoded in ISO-8859-1: åäö".equals( property ) ) + { + System.err.println( "Non-ascii characters has wrong encoding after filtering" ); + return false; + } +} +catch( IOException e ) +{ + e.printStackTrace(); + result = false; +} + +return result; diff --git a/Java-base/maven-war-plugin/src/src/it/web-resources-filtering-delimiter/web/pom.xml b/Java-base/maven-war-plugin/src/src/it/web-resources-filtering-delimiter/web/pom.xml new file mode 100644 index 000000000..531d27909 --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/it/web-resources-filtering-delimiter/web/pom.xml @@ -0,0 +1,72 @@ + + + + 4.0.0 + + + com.edb.finance.example + example-parent + 1.0.0-SNAPSHOT + ../parent/pom.xml + + + + example-web + war + + example-web Maven Webapp + http://maven.apache.org + + + + junit + junit + 3.8.1 + test + + + + + example-web + + + org.apache.maven.plugins + maven-war-plugin + @pom.version@ + + \ + true + + + ${basedir}/src/main/webresources + true + + + ISO-8859-1 + + @@*@@ + + false + + + + + diff --git a/Java-base/maven-war-plugin/src/src/it/web-resources-filtering-delimiter/web/src/main/webapp/WEB-INF/web.xml b/Java-base/maven-war-plugin/src/src/it/web-resources-filtering-delimiter/web/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 000000000..36c5645fb --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/it/web-resources-filtering-delimiter/web/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,26 @@ + + + + + + Archetype Created Web Application + diff --git a/Java-base/maven-war-plugin/src/src/it/web-resources-filtering-delimiter/web/src/main/webapp/index.jsp b/Java-base/maven-war-plugin/src/src/it/web-resources-filtering-delimiter/web/src/main/webapp/index.jsp new file mode 100755 index 000000000..1f294feb8 --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/it/web-resources-filtering-delimiter/web/src/main/webapp/index.jsp @@ -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. + */ + + +

Hello World!

+ + diff --git a/Java-base/maven-war-plugin/src/src/it/web-resources-filtering-delimiter/web/src/main/webresources/WEB-INF/classes/my.properties b/Java-base/maven-war-plugin/src/src/it/web-resources-filtering-delimiter/web/src/main/webresources/WEB-INF/classes/my.properties new file mode 100644 index 000000000..d07696737 --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/it/web-resources-filtering-delimiter/web/src/main/webresources/WEB-INF/classes/my.properties @@ -0,0 +1,18 @@ +# 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. + +my.property=Characters that should be encoded in ISO-8859-1: åäö \ No newline at end of file diff --git a/Java-base/maven-war-plugin/src/src/it/web-resources-filtering-delimiter/web/src/main/webresources/WEB-INF/jetty-env.xml b/Java-base/maven-war-plugin/src/src/it/web-resources-filtering-delimiter/web/src/main/webresources/WEB-INF/jetty-env.xml new file mode 100644 index 000000000..68ffb6646 --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/it/web-resources-filtering-delimiter/web/src/main/webresources/WEB-INF/jetty-env.xml @@ -0,0 +1,40 @@ + + + + + + + jdbc/EventdialogDS + + + @@jdbc.url@@ + @@jdbc.user@@ + \@@jdbc.password@@ + + + + diff --git a/Java-base/maven-war-plugin/src/src/it/web-resources-filtering/parent/pom.xml b/Java-base/maven-war-plugin/src/src/it/web-resources-filtering/parent/pom.xml new file mode 100644 index 000000000..cee6b8395 --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/it/web-resources-filtering/parent/pom.xml @@ -0,0 +1,62 @@ + + + + + 4.0.0 + + Company Parent + Parent that handles dependencyManagement + + com.edb.finance.example + example-parent + 1.0.0-SNAPSHOT + pom + 2008 + + + + 1 + Valeriy Molyakov + valeriy.molyakov@infopulse.com.ua + EDB Business Partner + http://www.edb.com + + developer + + +2 + + + + + + sample.website + ${website.url}/${project.name} + + + + + + jdbc:oracle:thin:@localhost:1521:orcl + scp://www.yourcompany.com/www/docs/project + + + diff --git a/Java-base/maven-war-plugin/src/src/it/web-resources-filtering/pom.xml b/Java-base/maven-war-plugin/src/src/it/web-resources-filtering/pom.xml new file mode 100644 index 000000000..8412bae76 --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/it/web-resources-filtering/pom.xml @@ -0,0 +1,44 @@ + + + + 4.0.0 + + + com.edb.finance.example + example-parent + 1.0.0-SNAPSHOT + parent/pom.xml + + + + example + pom + + Example Maven Multi-module project + http://maven.apache.org + + + parent + web + + + + diff --git a/Java-base/maven-war-plugin/src/src/it/web-resources-filtering/verify.bsh b/Java-base/maven-war-plugin/src/src/it/web-resources-filtering/verify.bsh new file mode 100644 index 000000000..6ea7d17be --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/it/web-resources-filtering/verify.bsh @@ -0,0 +1,115 @@ + +/* + * 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. + */ + +import java.io.*; + +import org.codehaus.plexus.util.*; + +boolean result = true; + +try +{ + // Load and check jetty-env.xml + + File target = new File( basedir, "web/target/example-web/WEB-INF" ); + if ( !target.exists() || !target.isDirectory() ) + { + System.err.println( "web/target/example-web/WEB-INF is missing or is not a directory." ); + return false; + } + + File jettyEnv = new File( target, "jetty-env.xml" ); + if ( !jettyEnv.exists() || jettyEnv.isDirectory() ) + { + System.err.println( "jetty-env.xml is missing or is a directory." ); + return false; + } + + + FileInputStream fis = new FileInputStream ( jettyEnv ); + String paramContent = IOUtil.toString ( fis, "UTF-8" ); + + System.out.println( "content='" + paramContent + "'" ); + + + int indexOf = paramContent.indexOf( "Characters that should be encoded in UTF-8: åäö" ); + if ( indexOf < 0 ) + { + System.err.println( "Non-ascii characters changed encoding during filtering" ); + return false; + } + + indexOf = paramContent.indexOf( "Author id: 1" ); + if ( indexOf < 0 ) + { + System.err.println( "project.developers[0].id not filtered correctly" ); + return false; + } + + indexOf = paramContent.indexOf( "jdbc:oracle:thin:@localhost:1521:orcl" ); + if ( indexOf < 0 ) + { + System.err.println( "jdbc.url not filtered correctly" ); + return false; + } + + indexOf = paramContent.indexOf( "${jdbc.password}" ); + if ( indexOf < 0 ) + { + System.err.println( "jdbc.password has been filtered" ); + return false; + } + + // Load and check my.properties + + target = new File( basedir, "web/target/example-web/WEB-INF/classes" ); + if ( !target.exists() || !target.isDirectory() ) + { + System.err.println( "web/target/example-web/WEB-INF/classes is missing or is not a directory." ); + return false; + } + + File myProperties = new File( target, "my.properties" ); + if ( !myProperties.exists() || myProperties.isDirectory() ) + { + System.err.println( "my.properties is missing or is a directory." ); + return false; + } + + Properties properties = new Properties(); + FileInputStream fis = new FileInputStream( myProperties ); + properties.load( fis ); + fis.close(); + + String property = properties.get( "my.property" ); + System.out.println( "my.property='" + property + "'" ); + if ( !"Characters that should be encoded in ISO-8859-1: åäö".equals( property ) ) + { + System.err.println( "Non-ascii characters has wrong encoding after filtering" ); + return false; + } +} +catch( IOException e ) +{ + e.printStackTrace(); + result = false; +} + +return result; diff --git a/Java-base/maven-war-plugin/src/src/it/web-resources-filtering/web/pom.xml b/Java-base/maven-war-plugin/src/src/it/web-resources-filtering/web/pom.xml new file mode 100644 index 000000000..071888abc --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/it/web-resources-filtering/web/pom.xml @@ -0,0 +1,68 @@ + + + + 4.0.0 + + + com.edb.finance.example + example-parent + 1.0.0-SNAPSHOT + ../parent/pom.xml + + + + example-web + war + + example-web Maven Webapp + http://maven.apache.org + + + + junit + junit + 3.8.1 + test + + + + + example-web + + + org.apache.maven.plugins + maven-war-plugin + @pom.version@ + + \ + true + + + ${basedir}/src/main/webresources + true + + + ISO-8859-1 + + + + + diff --git a/Java-base/maven-war-plugin/src/src/it/web-resources-filtering/web/src/main/webapp/WEB-INF/web.xml b/Java-base/maven-war-plugin/src/src/it/web-resources-filtering/web/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 000000000..36c5645fb --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/it/web-resources-filtering/web/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,26 @@ + + + + + + Archetype Created Web Application + diff --git a/Java-base/maven-war-plugin/src/src/it/web-resources-filtering/web/src/main/webapp/index.jsp b/Java-base/maven-war-plugin/src/src/it/web-resources-filtering/web/src/main/webapp/index.jsp new file mode 100755 index 000000000..1f294feb8 --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/it/web-resources-filtering/web/src/main/webapp/index.jsp @@ -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. + */ + + +

Hello World!

+ + diff --git a/Java-base/maven-war-plugin/src/src/it/web-resources-filtering/web/src/main/webresources/WEB-INF/classes/my.properties b/Java-base/maven-war-plugin/src/src/it/web-resources-filtering/web/src/main/webresources/WEB-INF/classes/my.properties new file mode 100644 index 000000000..d07696737 --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/it/web-resources-filtering/web/src/main/webresources/WEB-INF/classes/my.properties @@ -0,0 +1,18 @@ +# 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. + +my.property=Characters that should be encoded in ISO-8859-1: åäö \ No newline at end of file diff --git a/Java-base/maven-war-plugin/src/src/it/web-resources-filtering/web/src/main/webresources/WEB-INF/jetty-env.xml b/Java-base/maven-war-plugin/src/src/it/web-resources-filtering/web/src/main/webresources/WEB-INF/jetty-env.xml new file mode 100644 index 000000000..20d9ebd86 --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/it/web-resources-filtering/web/src/main/webresources/WEB-INF/jetty-env.xml @@ -0,0 +1,44 @@ + + + + + + + + jdbc/EventdialogDS + + + ${jdbc.url} + ${jdbc.user} + \${jdbc.password} + + + + diff --git a/Java-base/maven-war-plugin/src/src/main/java/org/apache/maven/plugins/war/AbstractWarMojo.java b/Java-base/maven-war-plugin/src/src/main/java/org/apache/maven/plugins/war/AbstractWarMojo.java new file mode 100644 index 000000000..5595124ca --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/main/java/org/apache/maven/plugins/war/AbstractWarMojo.java @@ -0,0 +1,1152 @@ +package org.apache.maven.plugins.war; + +/* + * 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. + */ + +import java.io.File; +import java.io.IOException; +import java.nio.file.FileVisitResult; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.SimpleFileVisitor; +import java.nio.file.attribute.BasicFileAttributes; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.LinkedHashSet; +import java.util.List; + +import org.apache.maven.archiver.MavenArchiveConfiguration; +import org.apache.maven.artifact.factory.ArtifactFactory; +import org.apache.maven.execution.MavenSession; +import org.apache.maven.model.Resource; +import org.apache.maven.plugin.AbstractMojo; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.MojoFailureException; +import org.apache.maven.plugin.logging.Log; +import org.apache.maven.plugins.annotations.Component; +import org.apache.maven.plugins.annotations.Parameter; +import org.apache.maven.plugins.war.overlay.OverlayManager; +import org.apache.maven.plugins.war.packaging.CopyUserManifestTask; +import org.apache.maven.plugins.war.packaging.OverlayPackagingTask; +import org.apache.maven.plugins.war.packaging.WarPackagingContext; +import org.apache.maven.plugins.war.packaging.WarPackagingTask; +import org.apache.maven.plugins.war.packaging.WarProjectPackagingTask; +import org.apache.maven.plugins.war.util.WebappStructure; +import org.apache.maven.project.MavenProject; +import org.apache.maven.shared.filtering.MavenFileFilter; +import org.apache.maven.shared.filtering.MavenFilteringException; +import org.apache.maven.shared.filtering.MavenResourcesExecution; +import org.apache.maven.shared.filtering.MavenResourcesFiltering; +import org.apache.maven.shared.utils.StringUtils; +import org.apache.maven.shared.utils.io.FileUtils; +import org.codehaus.plexus.archiver.Archiver; +import org.codehaus.plexus.archiver.jar.JarArchiver; +import org.codehaus.plexus.archiver.manager.ArchiverManager; + +/** + * Contains common jobs for WAR mojos. + */ +public abstract class AbstractWarMojo + extends AbstractMojo +{ + 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 web.xml file is missing. Set to false if you + * want your WAR built without a web.xml file. This may be useful if you are building an overlay that + * has no web.xml file. + *

+ * Starting with 3.1.0, this property defaults to false if the project depends on the Servlet + * 3.0 API or newer. + * + * @since 2.1-alpha-2 + */ + @Parameter + protected Boolean failOnMissingWebXml; + + /** + * The Maven project. + */ + @Parameter( defaultValue = "${project}", readonly = true, required = true ) + private MavenProject project; + + /** + * The directory containing compiled classes. + */ + @Parameter( defaultValue = "${project.build.outputDirectory}", required = true, readonly = true ) + private File classesDirectory; + + /** + * Whether a JAR file will be created for the classes in the webapp. Using this optional configuration parameter + * will make the compiled classes to be archived into a JAR file in /WEB-INF/lib/ and the classes + * directory will then be excluded from the webapp /WEB-INF/classes/. + * + * @since 2.0.1 + */ + @Parameter( defaultValue = "false" ) + private boolean archiveClasses; + + /** + * The encoding to use when copying filtered web resources. + * + * @since 2.3 + */ + @Parameter( defaultValue = "${project.build.sourceEncoding}" ) + private String resourceEncoding; + + /** + * The JAR archiver needed for archiving the classes directory into a JAR file under WEB-INF/lib. + */ + @Component( role = Archiver.class, hint = "jar" ) + private JarArchiver jarArchiver; + + /** + * The directory where the webapp is built. + */ + @Parameter( defaultValue = "${project.build.directory}/${project.build.finalName}", required = true ) + private File webappDirectory; + + /** + * Single directory for extra files to include in the WAR. This is where you place your JSP files. + */ + @Parameter( defaultValue = "${basedir}/src/main/webapp", required = true ) + private File warSourceDirectory; + + /** + * The list of webResources we want to transfer. + */ + @Parameter + private Resource[] webResources; + + /** + * Filters (property files) to include during the interpolation of the pom.xml. + */ + @Parameter + private List filters; + + /** + *

+ * Set of delimiters for expressions to filter within the resources. These delimiters are specified in the form + * 'beginToken*endToken'. If no '*' is given, the delimiter is assumed to be the same for start and end. + *

+ *

+ * So, the default filtering delimiters might be specified as: + *

+ * + *
+     * <delimiters>
+     *   <delimiter>${*}</delimiter>
+     *   <delimiter>@</delimiter>
+     * </delimiters>
+     * 
+ *

+ * Since the '@' delimiter is the same on both ends, we don't need to specify '@*@' (though we can). + *

+ * + * @since 3.0.0 + */ + @Parameter + private LinkedHashSet delimiters; + + /** + * Use default delimiters in addition to custom delimiters, if any. + * + * @since 3.0.0 + */ + @Parameter( defaultValue = "true" ) + private boolean useDefaultDelimiters; + + /** + * The path to the web.xml file to use. + */ + @Parameter + private File webXml; + + /** + * The path to a configuration file for the servlet container. Note that the file name may be different for + * different servlet containers. Apache Tomcat uses a configuration file named context.xml. The file will be copied + * to the META-INF directory. + */ + @Parameter + private File containerConfigXML; + + /** + * Directory to unpack dependent WARs into if needed. + */ + @Parameter( defaultValue = "${project.build.directory}/war/work", required = true ) + private File workDirectory; + + /** + * The file name mapping to use when copying libraries and TLDs. If no file mapping is set (default) the files are + * copied with their standard names. + * + * @since 2.1-alpha-1 + */ + @Parameter + private String outputFileNameMapping; + + /** + */ + @Component( role = ArtifactFactory.class ) + private ArtifactFactory artifactFactory; + + /** + * To look up Archiver/UnArchiver implementations. + */ + @Component( role = ArchiverManager.class ) + private ArchiverManager archiverManager; + + /** + */ + @Component( role = MavenFileFilter.class, hint = "default" ) + private MavenFileFilter mavenFileFilter; + + /** + */ + @Component( role = MavenResourcesFiltering.class, hint = "default" ) + private MavenResourcesFiltering mavenResourcesFiltering; + + /** + * The comma separated list of tokens to include when copying the content of the warSourceDirectory. + */ + @Parameter( defaultValue = "**" ) + private String warSourceIncludes; + + /** + * The comma separated list of tokens to exclude when copying the content of the warSourceDirectory. + */ + @Parameter + private String warSourceExcludes; + + /** + * The comma separated list of tokens to include when doing a WAR overlay. Default is + * {@link org.apache.maven.plugins.war.Overlay#DEFAULT_INCLUDES} + * + */ + @Parameter + private String dependentWarIncludes = StringUtils.join( Overlay.DEFAULT_INCLUDES, "," ); + + /** + * The comma separated list of tokens to exclude when doing a WAR overlay. Default is + * {@link org.apache.maven.plugins.war.Overlay#DEFAULT_EXCLUDES} + * + */ + @Parameter + private String dependentWarExcludes = StringUtils.join( Overlay.DEFAULT_EXCLUDES, "," ); + + /** + * The overlays to apply. Each <overlay> element may contain: + *
    + *
  • id (defaults to currentBuild)
  • + *
  • groupId (if this and artifactId are null, then the current project is treated as its own overlay)
  • + *
  • artifactId (see above)
  • + *
  • classifier
  • + *
  • type
  • + *
  • includes (a list of string patterns)
  • + *
  • excludes (a list of string patterns)
  • + *
  • filtered (defaults to false)
  • + *
  • skip (defaults to false)
  • + *
  • targetPath (defaults to root of webapp structure)
  • + *
+ * + * @since 2.1-alpha-1 + */ + @Parameter + private List overlays = new ArrayList<>(); + + /** + * A list of file extensions that should not be filtered. Will be used when filtering webResources and + * overlays. + * + * @since 2.1-alpha-2 + */ + @Parameter + private List nonFilteredFileExtensions; + + /** + * @since 2.1-alpha-2 + */ + @Parameter( defaultValue = "${session}", readonly = true, required = true ) + private MavenSession session; + + /** + * To filter deployment descriptors. Disabled by default. + * + * @since 2.1-alpha-2 + */ + @Parameter( defaultValue = "false" ) + private boolean filteringDeploymentDescriptors; + + /** + * To escape interpolated values with Windows path c:\foo\bar will be replaced with + * c:\\foo\\bar. + * + * @since 2.1-alpha-2 + */ + @Parameter( defaultValue = "false" ) + private boolean escapedBackslashesInFilePath; + + /** + * Expression preceded with this String won't be interpolated. \${foo} will be replaced with + * ${foo}. + * + * @since 2.1-beta-1 + */ + @Parameter + protected String escapeString; + + /** + * Indicates if zip archives (jar,zip etc) being added to the war should be compressed again. Compressing again can + * result in smaller archive size, but gives noticeably longer execution time. + * + * @since 2.3 + */ + @Parameter( defaultValue = "true" ) + private boolean recompressZippedFiles; + + /** + * @since 2.4 + */ + @Parameter( defaultValue = "false" ) + private boolean includeEmptyDirectories; + + /** + * Stop searching endToken at the end of line + * + * @since 2.4 + */ + @Parameter( defaultValue = "false" ) + private boolean supportMultiLineFiltering; + + /** + * use jvmChmod rather that cli chmod and forking process + * + * @since 2.4 + */ + @Parameter( defaultValue = "true" ) + private boolean useJvmChmod; + + /** + * The archive configuration to use. See Maven + * Archiver Reference. + */ + @Parameter + private MavenArchiveConfiguration archive = new MavenArchiveConfiguration(); + + /** + * Timestamp for reproducible output archive entries, either formatted as ISO 8601 + * yyyy-MM-dd'T'HH:mm:ssXXX or as an int representing seconds since the epoch (like + * SOURCE_DATE_EPOCH). + * + * @since 3.3.0 + */ + @Parameter( defaultValue = "${project.build.outputTimestamp}" ) + protected String outputTimestamp; + + private final Overlay currentProjectOverlay = Overlay.createInstance(); + + /** + * @return The current overlay. + */ + public Overlay getCurrentProjectOverlay() + { + return currentProjectOverlay; + } + + /** + * Returns a string array of the excludes to be used when copying the content of the WAR source directory. + * + * @return an array of tokens to exclude + */ + protected String[] getExcludes() + { + List excludeList = new ArrayList<>(); + if ( StringUtils.isNotEmpty( warSourceExcludes ) ) + { + excludeList.addAll( Arrays.asList( StringUtils.split( warSourceExcludes, "," ) ) ); + } + + // if webXML is specified, omit the one in the source directory + if ( webXml != null && StringUtils.isNotEmpty( webXml.getName() ) ) + { + excludeList.add( "**/" + WEB_INF + "/web.xml" ); + } + + // if contextXML is specified, omit the one in the source directory + if ( containerConfigXML != null && StringUtils.isNotEmpty( containerConfigXML.getName() ) ) + { + excludeList.add( "**/" + META_INF + "/" + containerConfigXML.getName() ); + } + + return excludeList.toArray( new String[excludeList.size()] ); + } + + /** + * Returns a string array of the includes to be used when assembling/copying the WAR. + * + * @return an array of tokens to include + */ + protected String[] getIncludes() + { + return StringUtils.split( StringUtils.defaultString( warSourceIncludes ), "," ); + } + + /** + * Returns a string array of the excludes to be used when adding dependent WAR as an overlay onto this WAR. + * + * @return an array of tokens to exclude + */ + protected String[] getDependentWarExcludes() + { + return StringUtils.split( StringUtils.defaultString( dependentWarExcludes ), "," ); + } + + /** + * Returns a string array of the includes to be used when adding dependent WARs as an overlay onto this WAR. + * + * @return an array of tokens to include + */ + protected String[] getDependentWarIncludes() + { + return StringUtils.split( StringUtils.defaultString( dependentWarIncludes ), "," ); + } + + /** + * @param webapplicationDirectory The web application directory. + * @throws MojoExecutionException In case of failure. + * @throws MojoFailureException In case of failure. + */ + public void buildExplodedWebapp( File webapplicationDirectory ) + throws MojoExecutionException, MojoFailureException + { + webapplicationDirectory.mkdirs(); + + try + { + buildWebapp( project, webapplicationDirectory ); + } + catch ( IOException e ) + { + throw new MojoExecutionException( "Could not build webapp", e ); + } + } + + /** + * Builds the webapp for the specified project with the new packaging task thingy. + * Classes, libraries and tld files are copied to the webappDirectory during this phase. + * + * @param mavenProject the maven project + * @param webapplicationDirectory the target directory + * @throws MojoExecutionException if an error occurred while packaging the webapp + * @throws MojoFailureException if an unexpected error occurred while packaging the webapp + * @throws IOException if an error occurred while copying the files + */ + public void buildWebapp( MavenProject mavenProject, File webapplicationDirectory ) + throws MojoExecutionException, MojoFailureException, IOException + { + + WebappStructure structure = new WebappStructure( mavenProject.getDependencies() ); + + // CHECKSTYLE_OFF: LineLength + final long startTime = System.currentTimeMillis(); + getLog().info( "Assembling webapp [" + mavenProject.getArtifactId() + "] in [" + webapplicationDirectory + "]" ); + + final OverlayManager overlayManager = + new OverlayManager( overlays, mavenProject, getDependentWarIncludes(), getDependentWarExcludes(), + currentProjectOverlay ); + // CHECKSTYLE_ON: LineLength + List defaultFilterWrappers; + try + { + MavenResourcesExecution mavenResourcesExecution = new MavenResourcesExecution(); + mavenResourcesExecution.setEscapeString( escapeString ); + mavenResourcesExecution.setSupportMultiLineFiltering( supportMultiLineFiltering ); + mavenResourcesExecution.setMavenProject( mavenProject ); + + // if these are NOT set, just use the defaults, which are '${*}' and '@'. + mavenResourcesExecution.setDelimiters( delimiters, useDefaultDelimiters ); + + if ( nonFilteredFileExtensions != null ) + { + mavenResourcesExecution.setNonFilteredFileExtensions( nonFilteredFileExtensions ); + } + + if ( filters == null ) + { + filters = getProject().getBuild().getFilters(); + } + mavenResourcesExecution.setFilters( filters ); + mavenResourcesExecution.setEscapedBackslashesInFilePath( escapedBackslashesInFilePath ); + mavenResourcesExecution.setMavenSession( this.session ); + mavenResourcesExecution.setEscapeString( this.escapeString ); + mavenResourcesExecution.setSupportMultiLineFiltering( supportMultiLineFiltering ); + + defaultFilterWrappers = mavenFileFilter.getDefaultFilterWrappers( mavenResourcesExecution ); + + } + catch ( MavenFilteringException e ) + { + getLog().error( "fail to build filtering wrappers " + e.getMessage() ); + throw new MojoExecutionException( e.getMessage(), e ); + } + + final WarPackagingContext context = + new DefaultWarPackagingContext( webapplicationDirectory, structure, overlayManager, defaultFilterWrappers, + getNonFilteredFileExtensions(), filteringDeploymentDescriptors, + this.artifactFactory, resourceEncoding, useJvmChmod, failOnMissingWebXml, + outputTimestamp ); + + final List packagingTasks = getPackagingTasks( overlayManager ); + + for ( WarPackagingTask warPackagingTask : packagingTasks ) + { + warPackagingTask.performPackaging( context ); + } + + getLog().debug( "Webapp assembled in [" + ( System.currentTimeMillis() - startTime ) + " msecs]" ); + + } + + /** + * Returns a List of the {@link org.apache.maven.plugins.war.packaging.WarPackagingTask} + * instances to invoke to perform the packaging. + * + * @param overlayManager the overlay manager + * @return the list of packaging tasks + * @throws MojoExecutionException if the packaging tasks could not be built + */ + private List getPackagingTasks( OverlayManager overlayManager ) + throws MojoExecutionException + { + final List packagingTasks = new ArrayList<>(); + + packagingTasks.add( new CopyUserManifestTask() ); + + final List resolvedOverlays = overlayManager.getOverlays(); + for ( Overlay overlay : resolvedOverlays ) + { + if ( overlay.isCurrentProject() ) + { + packagingTasks.add( new WarProjectPackagingTask( webResources, webXml, containerConfigXML, + currentProjectOverlay ) ); + } + else + { + packagingTasks.add( new OverlayPackagingTask( overlay, currentProjectOverlay ) ); + } + } + return packagingTasks; + } + + /** + * WarPackagingContext default implementation + */ + private class DefaultWarPackagingContext + implements WarPackagingContext + { + private final ArtifactFactory artifactFactory; + + private final String resourceEncoding; + + private final WebappStructure webappStructure; + + private final File webappDirectory; + + private final OverlayManager overlayManager; + + private final List filterWrappers; + + private List nonFilteredFileExtensions; + + private boolean filteringDeploymentDescriptors; + + private boolean useJvmChmod; + + private final Boolean failOnMissingWebXml; + + private final Collection outdatedResources; + + private final String outputTimestamp; + + /** + * @param webappDirectory The web application directory. + * @param webappStructure The web app structure. + * @param overlayManager The overlay manager. + * @param filterWrappers The filter wrappers + * @param nonFilteredFileExtensions The non filtered file extensions. + * @param filteringDeploymentDescriptors The filtering deployment descriptors. + * @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 + * @param outputTimestamp the output timestamp for reproducible archive creation + */ + DefaultWarPackagingContext( final File webappDirectory, final WebappStructure webappStructure, + final OverlayManager overlayManager, + List filterWrappers, + List nonFilteredFileExtensions, + boolean filteringDeploymentDescriptors, ArtifactFactory artifactFactory, + String resourceEncoding, boolean useJvmChmod, + final Boolean failOnMissingWebXml, String outputTimestamp ) + { + this.webappDirectory = webappDirectory; + this.webappStructure = webappStructure; + this.overlayManager = overlayManager; + this.filterWrappers = filterWrappers; + this.artifactFactory = artifactFactory; + this.filteringDeploymentDescriptors = filteringDeploymentDescriptors; + this.nonFilteredFileExtensions = + nonFilteredFileExtensions == null ? Collections.emptyList() : nonFilteredFileExtensions; + this.resourceEncoding = resourceEncoding; + // This is kinda stupid but if we loop over the current overlays and we request the path structure + // it will register it. This will avoid wrong warning messages in a later phase + for ( String overlayId : overlayManager.getOverlayIds() ) + { + webappStructure.getStructure( overlayId ); + } + this.useJvmChmod = useJvmChmod; + this.failOnMissingWebXml = failOnMissingWebXml; + + if ( !webappDirectory.exists() ) + { + outdatedResources = Collections.emptyList(); + } + else if ( getWarSourceDirectory().toPath().equals( webappDirectory.toPath() ) ) + { + getLog().info( "Can't detect outdated resources when running inplace goal" ); + outdatedResources = Collections.emptyList(); + } + else + { + outdatedResources = new ArrayList<>(); + try + { + Files.walkFileTree( webappDirectory.toPath(), new SimpleFileVisitor() + { + @Override + public FileVisitResult visitFile( Path file, BasicFileAttributes attrs ) + throws IOException + { + outdatedResources.add( webappDirectory.toPath().relativize( file ).toString() ); + return super.visitFile( file, attrs ); + } + } ); + } + catch ( IOException e ) + { + getLog().warn( "Can't detect outdated resources", e ); + } + } + this.outputTimestamp = outputTimestamp; + } + + @Override + public MavenProject getProject() + { + return project; + } + + @Override + public File getWebappDirectory() + { + return webappDirectory; + } + + @Override + public File getClassesDirectory() + { + return classesDirectory; + } + + @Override + public Log getLog() + { + return AbstractWarMojo.this.getLog(); + } + + @Override + public String getOutputFileNameMapping() + { + return outputFileNameMapping; + } + + @Override + public File getWebappSourceDirectory() + { + return warSourceDirectory; + } + + @Override + public String[] getWebappSourceIncludes() + { + return getIncludes(); + } + + @Override + public String[] getWebappSourceExcludes() + { + return getExcludes(); + } + + @Override + public boolean isWebappSourceIncludeEmptyDirectories() + { + return includeEmptyDirectories; + } + + @Override + public boolean archiveClasses() + { + return archiveClasses; + } + + @Override + public File getOverlaysWorkDirectory() + { + return workDirectory; + } + + @Override + public ArchiverManager getArchiverManager() + { + return archiverManager; + } + + @Override + public MavenArchiveConfiguration getArchive() + { + return archive; + } + + @Override + public JarArchiver getJarArchiver() + { + return jarArchiver; + } + + @Override + public List getFilters() + { + return filters; + } + + @Override + public WebappStructure getWebappStructure() + { + return webappStructure; + } + + @Override + public List getOwnerIds() + { + return overlayManager.getOverlayIds(); + } + + @Override + public MavenFileFilter getMavenFileFilter() + { + return mavenFileFilter; + } + + @Override + public List getFilterWrappers() + { + return filterWrappers; + } + + @Override + public boolean isNonFilteredExtension( String fileName ) + { + return !mavenResourcesFiltering.filteredFileExtension( fileName, nonFilteredFileExtensions ); + } + + @Override + public boolean isFilteringDeploymentDescriptors() + { + return filteringDeploymentDescriptors; + } + + @Override + public ArtifactFactory getArtifactFactory() + { + return this.artifactFactory; + } + + @Override + public MavenSession getSession() + { + return session; + } + + @Override + public String getResourceEncoding() + { + return resourceEncoding; + } + + @Override + public boolean isUseJvmChmod() + { + return useJvmChmod; + } + + @Override + public Boolean isFailOnMissingWebXml() + { + return failOnMissingWebXml; + } + + @Override + public void addResource( String resource ) + { + outdatedResources.remove( resource.replace( '/', File.separatorChar ) ); + } + + @Override + public void deleteOutdatedResources() + { + for ( String resource : outdatedResources ) + { + getLog().info( "deleting outdated resource " + resource ); + new File( getWebappDirectory(), resource ).delete(); + } + } + + @Override + public String getOutputTimestamp() + { + return outputTimestamp; + } + } + + /** + * @return The Maven Project. + */ + public MavenProject getProject() + { + return project; + } + + /** + * @param project The project to be set. + */ + public void setProject( MavenProject project ) + { + this.project = project; + } + + /** + * @return the classes directory. + */ + public File getClassesDirectory() + { + return classesDirectory; + } + + /** + * @param classesDirectory The classes directory to be set. + */ + public void setClassesDirectory( File classesDirectory ) + { + this.classesDirectory = classesDirectory; + } + + /** + * @return {@link #webappDirectory} + */ + public File getWebappDirectory() + { + return webappDirectory; + } + + /** + * @param webappDirectory The web application directory. + */ + public void setWebappDirectory( File webappDirectory ) + { + this.webappDirectory = webappDirectory; + } + + /** + * @return {@link #warSourceDirectory} + */ + public File getWarSourceDirectory() + { + return warSourceDirectory; + } + + /** + * @param warSourceDirectory {@link #warSourceDirectory} + */ + public void setWarSourceDirectory( File warSourceDirectory ) + { + this.warSourceDirectory = warSourceDirectory; + } + + /** + * @return The {@link #webXml} + */ + public File getWebXml() + { + return webXml; + } + + /** + * @param webXml The {@link #webXml} + */ + public void setWebXml( File webXml ) + { + this.webXml = webXml; + } + + /** + * @return {@link #containerConfigXML} + */ + public File getContainerConfigXML() + { + return containerConfigXML; + } + + /** + * @param containerConfigXML {@link #containerConfigXML} + */ + public void setContainerConfigXML( File containerConfigXML ) + { + this.containerConfigXML = containerConfigXML; + } + + /** + * @return {@link #outputFileNameMapping} + */ + public String getOutputFileNameMapping() + { + return outputFileNameMapping; + } + + /** + * @param outputFileNameMapping {@link #outputFileNameMapping} + */ + public void setOutputFileNameMapping( String outputFileNameMapping ) + { + this.outputFileNameMapping = outputFileNameMapping; + } + + /** + * @return {@link #overlays} + */ + public List getOverlays() + { + return overlays; + } + + /** + * @param overlays {@link #overlays} + */ + public void setOverlays( List overlays ) + { + this.overlays = overlays; + } + + /** + * @param overlay add {@link #overlays}. + */ + public void addOverlay( Overlay overlay ) + { + overlays.add( overlay ); + } + + /** + * @return {@link #archiveClasses} + */ + public boolean isArchiveClasses() + { + return archiveClasses; + } + + /** + * @param archiveClasses {@link #archiveClasses} + */ + public void setArchiveClasses( boolean archiveClasses ) + { + this.archiveClasses = archiveClasses; + } + + /** + * @return {@link JarArchiver} + */ + public JarArchiver getJarArchiver() + { + return jarArchiver; + } + + /** + * @param jarArchiver {@link JarArchiver} + */ + public void setJarArchiver( JarArchiver jarArchiver ) + { + this.jarArchiver = jarArchiver; + } + + /** + * @return {@link #webResources}. + */ + public Resource[] getWebResources() + { + return webResources; + } + + /** + * @param webResources {@link #webResources}. + */ + public void setWebResources( Resource[] webResources ) + { + this.webResources = webResources; + } + + /** + * @return {@link #filters} + */ + public List getFilters() + { + return filters; + } + + /** + * @param filters {@link #filters} + */ + public void setFilters( List filters ) + { + this.filters = filters; + } + + /** + * @return {@link #workDirectory} + */ + public File getWorkDirectory() + { + return workDirectory; + } + + /** + * @param workDirectory {@link #workDirectory} + */ + public void setWorkDirectory( File workDirectory ) + { + this.workDirectory = workDirectory; + } + + /** + * @return {@link #warSourceIncludes} + */ + public String getWarSourceIncludes() + { + return warSourceIncludes; + } + + /** + * @param warSourceIncludes {@link #warSourceIncludes} + */ + public void setWarSourceIncludes( String warSourceIncludes ) + { + this.warSourceIncludes = warSourceIncludes; + } + + /** + * @return {@link #warSourceExcludes} + */ + public String getWarSourceExcludes() + { + return warSourceExcludes; + } + + /** + * @param warSourceExcludes {@link #warSourceExcludes} + */ + public void setWarSourceExcludes( String warSourceExcludes ) + { + this.warSourceExcludes = warSourceExcludes; + } + + /** + * @return {@link #archive} + */ + public MavenArchiveConfiguration getArchive() + { + return archive; + } + + /** + * @return {@link #nonFilteredFileExtensions} + */ + public List getNonFilteredFileExtensions() + { + return nonFilteredFileExtensions; + } + + /** + * @param nonFilteredFileExtensions {@link #nonFilteredFileExtensions} + */ + public void setNonFilteredFileExtensions( List nonFilteredFileExtensions ) + { + this.nonFilteredFileExtensions = nonFilteredFileExtensions; + } + + /** + * @return {@link #artifactFactory} + */ + public ArtifactFactory getArtifactFactory() + { + return this.artifactFactory; + } + + /** + * @param artifactFactory {@link #artifactFactory} + */ + public void setArtifactFactory( ArtifactFactory artifactFactory ) + { + this.artifactFactory = artifactFactory; + } + + /** + * @return {@link #session} + */ + protected MavenSession getSession() + { + return this.session; + } + + /** + * @return {@link #recompressZippedFiles} + */ + protected boolean isRecompressZippedFiles() + { + return recompressZippedFiles; + } + + /** + * @return {@link #includeEmptyDirectories} + */ + protected boolean isIncludeEmptyDirectories() + { + return includeEmptyDirectories; + } +} diff --git a/Java-base/maven-war-plugin/src/src/main/java/org/apache/maven/plugins/war/Overlay.java b/Java-base/maven-war-plugin/src/src/main/java/org/apache/maven/plugins/war/Overlay.java new file mode 100644 index 000000000..c42f1c793 --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/main/java/org/apache/maven/plugins/war/Overlay.java @@ -0,0 +1,384 @@ +package org.apache.maven.plugins.war; + +/* + * 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. + */ + +import org.apache.maven.artifact.Artifact; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +/** + *

+ * An overlay is a skeleton WAR added to another WAR project in order to inject a functionality, resources or any other + * shared component.

+ * + *

Note that a particular WAR dependency can be added multiple times as an overlay with different includes/excludes + * filter; this allows building a fine grained overwriting policy.

+ * + *

The current project can also be described as an overlay and can not be specified twice. An overlay with no groupId + * and no artifactId represents the current project.

+ * + * @author Stephane Nicoll + */ +public class Overlay +{ + + /** + * The list of default includes. + */ + public static final String[] DEFAULT_INCLUDES = new String[] { "**/**" }; + + /** + * The list of default excludes. + */ + public static final String[] DEFAULT_EXCLUDES = new String[] { "META-INF/MANIFEST.MF" }; + + private String id; + + private String groupId; + + private String artifactId; + + private String classifier = null; + + private String[] includes = DEFAULT_INCLUDES; + + private String[] excludes = DEFAULT_EXCLUDES; + + private boolean filtered = false; + + private boolean skip = false; + + private Artifact artifact; + + private String targetPath; + + /** default overlay type is war */ + private String type = "war"; + + /** + * Create instance. + */ + public Overlay() + { + super(); + } + + /** + * @param groupId {@link #groupId} + * @param artifactId {@link #artifactId} + */ + public Overlay( String groupId, String artifactId ) + { + this(); + this.groupId = groupId; + this.artifactId = artifactId; + } + + /** + * Specify whether this overlay represents the current project or not. + * + * @return true if the overlay represents the current project, false otherwise + */ + public boolean isCurrentProject() + { + return ( groupId == null && artifactId == null ); + } + + /** + * @return {@link Overlay} instance. + */ + public static Overlay createInstance() + { + Overlay overlay = new Overlay(); + overlay.setId( "currentBuild" ); + return overlay; + } + + // Getters and Setters + + /** + * @return The id. + */ + public String getId() + { + if ( id == null ) + { + final StringBuilder sb = new StringBuilder(); + sb.append( getGroupId() ).append( ":" ).append( getArtifactId() ); + if ( getClassifier() != null ) + { + sb.append( ":" ).append( getClassifier() ); + } + id = sb.toString(); + } + return id; + } + + /** + * @param id The id. + */ + public void setId( String id ) + { + this.id = id; + } + + /** + * @return {@link #groupId} + */ + public String getGroupId() + { + return groupId; + } + + /** + * @param groupId {@link #groupId} + */ + public void setGroupId( String groupId ) + { + this.groupId = groupId; + } + + /** + * @return {@link #artifactId} + */ + public String getArtifactId() + { + return artifactId; + } + + /** + * @param artifactId {@link #artifactId} + */ + public void setArtifactId( String artifactId ) + { + this.artifactId = artifactId; + } + + /** + * @return {@link #classifier} + */ + public String getClassifier() + { + return classifier; + } + + /** + * @param classifier {@link #classifier} + */ + public void setClassifier( String classifier ) + { + this.classifier = classifier; + } + + /** + * @return {@link #includes} + */ + public String[] getIncludes() + { + return includes; + } + + /** + * @param includes {@link #includes} + */ + public void setIncludes( String includes ) + { + this.includes = parse( includes ); + } + + /** + * @param includes {@link #includes} + */ + public void setIncludes( String[] includes ) + { + this.includes = includes; + } + + /** + * @return {@link #excludes} + */ + public String[] getExcludes() + { + return excludes; + } + + /** + * @param excludes {@link #excludes} + */ + public void setExcludes( String excludes ) + { + this.excludes = parse( excludes ); + } + + /** + * @param excludes {@link #excludes} + */ + public void setExcludes( String[] excludes ) + { + this.excludes = excludes; + } + + /** + * @return {@link #filtered} + */ + public boolean isFiltered() + { + return filtered; + } + + /** + * @param filtered {@link #filtered} + */ + public void setFiltered( boolean filtered ) + { + this.filtered = filtered; + } + + /** + * @return {@link #skip} + */ + public boolean shouldSkip() + { + return skip; + } + + /** + * @param skip {@link #skip} + */ + public void setSkip( boolean skip ) + { + this.skip = skip; + } + + /** + * @return {@link #artifact} + */ + public Artifact getArtifact() + { + return artifact; + } + + /** + * @param artifact {@link #artifact} + */ + public void setArtifact( Artifact artifact ) + { + this.artifact = artifact; + } + + /** + * @return {@link #targetPath} + */ + public String getTargetPath() + { + return targetPath; + } + + /** + * @param targetPath {@link #targetPath} + */ + public void setTargetPath( String targetPath ) + { + this.targetPath = targetPath; + } + + /** + * @return {@link #type} + */ + public String getType() + { + return type; + } + + /** + * @param type {@link #type} + */ + public void setType( String type ) + { + this.type = type; + } + + @Override + public String toString() + { + return " id " + getId(); + } + + @Override + public boolean equals( Object o ) + { + if ( this == o ) + { + return true; + } + if ( o == null || getClass() != o.getClass() ) + { + return false; + } + + Overlay overlay = (Overlay) o; + + if ( excludes != null ? !Arrays.equals( excludes, overlay.excludes ) : overlay.excludes != null ) + { + return false; + } + if ( getId() != null ? !getId().equals( overlay.getId() ) : overlay.getId() != null ) + { + return false; + } + if ( includes != null ? !Arrays.equals( includes, overlay.includes ) : overlay.includes != null ) + { + return false; + } + + return true; + } + + @Override + public int hashCode() + { + int result; + result = ( getId() != null ? getId().hashCode() : 0 ); + result = 31 * result + ( includes != null ? includes.hashCode() : 0 ); + result = 31 * result + ( excludes != null ? excludes.hashCode() : 0 ); + return result; + } + + private String[] parse( String s ) + { + final List result = new ArrayList<>(); + if ( s == null ) + { + return result.toArray( new String[result.size()] ); + } + else + { + String[] tokens = s.split( "," ); + for ( String token : tokens ) + { + result.add( token.trim() ); + } + return result.toArray( new String[result.size()] ); + } + } + +} diff --git a/Java-base/maven-war-plugin/src/src/main/java/org/apache/maven/plugins/war/WarExplodedMojo.java b/Java-base/maven-war-plugin/src/src/main/java/org/apache/maven/plugins/war/WarExplodedMojo.java new file mode 100644 index 000000000..1327068ce --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/main/java/org/apache/maven/plugins/war/WarExplodedMojo.java @@ -0,0 +1,46 @@ +package org.apache.maven.plugins.war; + +/* + * 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. + */ + +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.MojoFailureException; +import org.apache.maven.plugins.annotations.LifecyclePhase; +import org.apache.maven.plugins.annotations.Mojo; +import org.apache.maven.plugins.annotations.ResolutionScope; + +/** + * Create an exploded webapp in a specified directory. + * + */ +@Mojo( name = "exploded", defaultPhase = LifecyclePhase.PACKAGE, threadSafe = true, + requiresDependencyResolution = ResolutionScope.RUNTIME ) +public class WarExplodedMojo + extends AbstractWarMojo +{ + @Override + public void execute() + throws MojoExecutionException, MojoFailureException + { + getLog().info( "Exploding webapp" ); + + buildExplodedWebapp( getWebappDirectory() ); + } + +} diff --git a/Java-base/maven-war-plugin/src/src/main/java/org/apache/maven/plugins/war/WarInPlaceMojo.java b/Java-base/maven-war-plugin/src/src/main/java/org/apache/maven/plugins/war/WarInPlaceMojo.java new file mode 100644 index 000000000..9cfe02c64 --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/main/java/org/apache/maven/plugins/war/WarInPlaceMojo.java @@ -0,0 +1,43 @@ +package org.apache.maven.plugins.war; + +/* + * 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. + */ + +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.MojoFailureException; +import org.apache.maven.plugins.annotations.Mojo; +import org.apache.maven.plugins.annotations.ResolutionScope; + +/** + * Generate the webapp in the WAR source directory. + * + */ +@Mojo( name = "inplace", requiresDependencyResolution = ResolutionScope.RUNTIME, threadSafe = true ) +public class WarInPlaceMojo + extends AbstractWarMojo +{ + @Override + public void execute() + throws MojoExecutionException, MojoFailureException + { + getLog().info( "Generating webapp in source directory [" + getWarSourceDirectory() + "]" ); + + buildExplodedWebapp( getWarSourceDirectory() ); + } +} \ No newline at end of file diff --git a/Java-base/maven-war-plugin/src/src/main/java/org/apache/maven/plugins/war/WarMojo.java b/Java-base/maven-war-plugin/src/src/main/java/org/apache/maven/plugins/war/WarMojo.java new file mode 100644 index 000000000..e30c57151 --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/main/java/org/apache/maven/plugins/war/WarMojo.java @@ -0,0 +1,574 @@ +package org.apache.maven.plugins.war; + +/* + * 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. + */ + +import java.io.File; +import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLClassLoader; +import java.util.Arrays; +import java.util.List; + +import org.apache.maven.archiver.MavenArchiver; +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.DependencyResolutionRequiredException; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.MojoFailureException; +import org.apache.maven.plugins.annotations.Component; +import org.apache.maven.plugins.annotations.LifecyclePhase; +import org.apache.maven.plugins.annotations.Mojo; +import org.apache.maven.plugins.annotations.Parameter; +import org.apache.maven.plugins.annotations.ResolutionScope; +import org.apache.maven.plugins.war.util.ClassesPackager; +import org.apache.maven.project.MavenProjectHelper; +import org.codehaus.plexus.archiver.Archiver; +import org.codehaus.plexus.archiver.ArchiverException; +import org.codehaus.plexus.archiver.jar.ManifestException; +import org.codehaus.plexus.archiver.war.WarArchiver; +import org.codehaus.plexus.util.FileUtils; +import org.codehaus.plexus.util.StringUtils; + +/** + * Build a WAR file. + * + * @author Emmanuel Venisse + */ +@Mojo( name = "war", defaultPhase = LifecyclePhase.PACKAGE, threadSafe = true, + requiresDependencyResolution = ResolutionScope.COMPILE_PLUS_RUNTIME ) +public class WarMojo + extends AbstractWarMojo +{ + /** + * The directory for the generated WAR. + */ + @Parameter( defaultValue = "${project.build.directory}", required = true ) + private String outputDirectory; + + /** + * The name of the generated WAR. + */ + @Parameter( defaultValue = "${project.build.finalName}", required = true, readonly = true ) + private String warName; + + /** + * Classifier to add to the generated WAR. If given, the artifact will be an attachment instead. The classifier will + * not be applied to the JAR file of the project - only to the WAR file. + */ + @Parameter + private String classifier; + + /** + * The comma separated list of tokens to exclude from the WAR before packaging. This option may be used to implement + * the skinny WAR use case. Note that you can use the Java Regular Expressions engine to include and exclude + * specific pattern using the expression %regex[]. Hint: read the about (?!Pattern). + * + * @since 2.1-alpha-2 + */ + @Parameter + private String packagingExcludes; + + /** + * The comma separated list of tokens to include in the WAR before packaging. By default everything is included. + * This option may be used to implement the skinny WAR use case. Note that you can use the Java Regular Expressions + * engine to include and exclude specific pattern using the expression %regex[]. + * + * @since 2.1-beta-1 + */ + @Parameter + private String packagingIncludes; + + /** + * The WAR archiver. + */ + @Component( role = Archiver.class, hint = "war" ) + private WarArchiver warArchiver; + + /** + */ + @Component + private MavenProjectHelper projectHelper; + + /** + * Whether this is the main artifact being built. Set to false if you don't want to install or deploy + * it to the local repository instead of the default one in an execution. + */ + @Parameter( defaultValue = "true" ) + private boolean primaryArtifact; + + /** + * Whether classes (that is the content of the WEB-INF/classes directory) should be attached to the project as an + * additional artifact. + *

+ * By default the classifier for the additional artifact is 'classes'. You can change it with the + * someclassifier]]> parameter. + *

+ *

+ * If this parameter true, another project can depend on the classes by writing something like: + * + *

+     * 
+     *   myGroup
+     *   myArtifact
+     *   myVersion
+     *   classes
+     * ]]>
+     * 
+ *

+ * + * @since 2.1-alpha-2 + */ + @Parameter( defaultValue = "false" ) + private boolean attachClasses; + + /** + * The classifier to use for the attached classes artifact. + * + * @since 2.1-alpha-2 + */ + @Parameter( defaultValue = "classes" ) + private String classesClassifier; + + /** + * You can skip the execution of the plugin if you need to. Its use is NOT RECOMMENDED, but quite convenient on + * occasion. + * + * @since 3.0.0 + */ + @Parameter( property = "maven.war.skip", defaultValue = "false" ) + private boolean skip; + + // ---------------------------------------------------------------------- + // Implementation + // ---------------------------------------------------------------------- + + /** + * Executes the WarMojo on the current project. + * + * @throws MojoExecutionException if an error occurred while building the webapp + * @throws MojoFailureException if an error. + */ + @Override + public void execute() + throws MojoExecutionException, MojoFailureException + { + + if ( isSkip() ) + { + getLog().info( "Skipping the execution." ); + return; + } + + File warFile = getTargetWarFile(); + + try + { + performPackaging( warFile ); + } + catch ( DependencyResolutionRequiredException | ArchiverException e ) + { + throw new MojoExecutionException( "Error assembling WAR: " + e.getMessage(), e ); + } + catch ( ManifestException | IOException e ) + { + throw new MojoExecutionException( "Error assembling WAR", e ); + } + } + + /** + * Generates the webapp according to the mode attribute. + * + * @param warFile the target WAR file + * @throws IOException if an error occurred while copying files + * @throws ArchiverException if the archive could not be created + * @throws ManifestException if the manifest could not be created + * @throws DependencyResolutionRequiredException if an error occurred while resolving the dependencies + * @throws MojoExecutionException if the execution failed + * @throws MojoFailureException if a fatal exception occurred + */ + private void performPackaging( File warFile ) + throws IOException, ManifestException, DependencyResolutionRequiredException, MojoExecutionException, + MojoFailureException + { + getLog().info( "Packaging webapp" ); + + buildExplodedWebapp( getWebappDirectory() ); + + MavenArchiver archiver = new MavenArchiver(); + + archiver.setArchiver( warArchiver ); + + archiver.setCreatedBy( "Maven WAR Plugin", "org.apache.maven.plugins", "maven-war-plugin" ); + + archiver.setOutputFile( warFile ); + + // configure for Reproducible Builds based on outputTimestamp value + archiver.configureReproducible( outputTimestamp ); + + getLog().debug( "Excluding " + Arrays.asList( getPackagingExcludes() ) + + " from the generated webapp archive." ); + getLog().debug( "Including " + Arrays.asList( getPackagingIncludes() ) + " in the generated webapp archive." ); + + warArchiver.addDirectory( getWebappDirectory(), getPackagingIncludes(), getPackagingExcludes() ); + + final File webXmlFile = new File( getWebappDirectory(), "WEB-INF/web.xml" ); + if ( webXmlFile.exists() ) + { + warArchiver.setWebxml( webXmlFile ); + } + + warArchiver.setRecompressAddedZips( isRecompressZippedFiles() ); + + warArchiver.setIncludeEmptyDirs( isIncludeEmptyDirectories() ); + + if ( Boolean.FALSE.equals( failOnMissingWebXml ) + || ( failOnMissingWebXml == null && isProjectUsingAtLeastServlet30() ) ) + { + getLog().debug( "Build won't fail if web.xml file is missing." ); + warArchiver.setExpectWebXml( false ); + } + + // create archive + archiver.createArchive( getSession(), getProject(), getArchive() ); + + // create the classes to be attached if necessary + if ( isAttachClasses() ) + { + if ( isArchiveClasses() && getJarArchiver().getDestFile() != null ) + { + // special handling in case of archived classes: MWAR-240 + File targetClassesFile = getTargetClassesFile(); + FileUtils.copyFile( getJarArchiver().getDestFile(), targetClassesFile ); + projectHelper.attachArtifact( getProject(), "jar", getClassesClassifier(), targetClassesFile ); + } + else + { + ClassesPackager packager = new ClassesPackager(); + final File classesDirectory = packager.getClassesDirectory( getWebappDirectory() ); + if ( classesDirectory.exists() ) + { + getLog().info( "Packaging classes" ); + packager.packageClasses( classesDirectory, getTargetClassesFile(), getJarArchiver(), getSession(), + getProject(), getArchive(), outputTimestamp ); + projectHelper.attachArtifact( getProject(), "jar", getClassesClassifier(), getTargetClassesFile() ); + } + } + } + + if ( this.classifier != null ) + { + projectHelper.attachArtifact( getProject(), "war", this.classifier, warFile ); + } + else + { + Artifact artifact = getProject().getArtifact(); + if ( primaryArtifact ) + { + artifact.setFile( warFile ); + } + else if ( artifact.getFile() == null || artifact.getFile().isDirectory() ) + { + artifact.setFile( warFile ); + } + } + } + + /** + * Determines if the current Maven project being built uses the Servlet 3.0 API (JSR 315) + * or Jakarta Servlet API. + * If it does then the web.xml file can be omitted. + *

+ * This is done by checking if the interface javax.servlet.annotation.WebServlet + * or jakarta.servlet.annotation.WebServlet is in the compile-time + * dependencies (which includes provided dependencies) of the Maven project. + * + * @return true if the project being built depends on Servlet 3.0 API or Jakarta Servlet API, + * false otherwise. + * @throws DependencyResolutionRequiredException if the compile elements can't be resolved. + * @throws MalformedURLException if the path to a dependency file can't be transformed to a URL. + */ + private boolean isProjectUsingAtLeastServlet30() + throws DependencyResolutionRequiredException, MalformedURLException + { + List classpathElements = getProject().getCompileClasspathElements(); + URL[] urls = new URL[classpathElements.size()]; + for ( int i = 0; i < urls.length; i++ ) + { + urls[i] = new File( classpathElements.get( i ) ).toURI().toURL(); + } + ClassLoader loader = new URLClassLoader( urls, Thread.currentThread().getContextClassLoader() ); + + return hasWebServletAnnotationClassInClasspath( loader ); + } + + private static boolean hasWebServletAnnotationClassInClasspath( ClassLoader loader ) + { + return hasClassInClasspath( loader, "javax.servlet.annotation.WebServlet" ) + || hasClassInClasspath( loader, "jakarta.servlet.annotation.WebServlet" ); + } + + private static boolean hasClassInClasspath( ClassLoader loader, String clazz ) + { + try + { + Class.forName( clazz, false, loader ); + return true; + } + catch ( ClassNotFoundException e ) + { + return false; + } + } + + /** + * @param basedir The basedir + * @param finalName The finalName + * @param classifier The classifier. + * @param type The type. + * @return {@link File} + */ + protected static File getTargetFile( File basedir, String finalName, String classifier, String type ) + { + if ( classifier == null ) + { + classifier = ""; + } + else if ( classifier.trim().length() > 0 && !classifier.startsWith( "-" ) ) + { + classifier = "-" + classifier; + } + + return new File( basedir, finalName + classifier + "." + type ); + } + + /** + * @return The war {@link File} + */ + protected File getTargetWarFile() + { + return getTargetFile( new File( getOutputDirectory() ), getWarName(), getClassifier(), "war" ); + + } + + /** + * @return The target class {@link File} + */ + protected File getTargetClassesFile() + { + return getTargetFile( new File( getOutputDirectory() ), getWarName(), getClassesClassifier(), "jar" ); + } + + // Getters and Setters + + /** + * @return {@link #classifier} + */ + public String getClassifier() + { + return classifier; + } + + /** + * @param classifier {@link #classifier} + */ + public void setClassifier( String classifier ) + { + this.classifier = classifier; + } + + /** + * @return The package excludes. + */ + public String[] getPackagingExcludes() + { + if ( StringUtils.isEmpty( packagingExcludes ) ) + { + return new String[0]; + } + else + { + return StringUtils.split( packagingExcludes, "," ); + } + } + + /** + * @param packagingExcludes {@link #packagingExcludes} + */ + public void setPackagingExcludes( String packagingExcludes ) + { + this.packagingExcludes = packagingExcludes; + } + + /** + * @return The packaging includes. + */ + public String[] getPackagingIncludes() + { + if ( StringUtils.isEmpty( packagingIncludes ) ) + { + return new String[] { "**" }; + } + else + { + return StringUtils.split( packagingIncludes, "," ); + } + } + + /** + * @param packagingIncludes {@link #packagingIncludes} + */ + public void setPackagingIncludes( String packagingIncludes ) + { + this.packagingIncludes = packagingIncludes; + } + + /** + * @return {@link #outputDirectory} + */ + public String getOutputDirectory() + { + return outputDirectory; + } + + /** + * @param outputDirectory {@link #outputDirectory} + */ + public void setOutputDirectory( String outputDirectory ) + { + this.outputDirectory = outputDirectory; + } + + /** + * @return {@link #warName} + */ + public String getWarName() + { + return warName; + } + + /** + * @param warName {@link #warName} + */ + public void setWarName( String warName ) + { + this.warName = warName; + } + + /** + * @return {@link #warArchiver} + */ + public WarArchiver getWarArchiver() + { + return warArchiver; + } + + /** + * @param warArchiver {@link #warArchiver} + */ + public void setWarArchiver( WarArchiver warArchiver ) + { + this.warArchiver = warArchiver; + } + + /** + * @return {@link #projectHelper} + */ + public MavenProjectHelper getProjectHelper() + { + return projectHelper; + } + + /** + * @param projectHelper {@link #projectHelper} + */ + public void setProjectHelper( MavenProjectHelper projectHelper ) + { + this.projectHelper = projectHelper; + } + + /** + * @return {@link #primaryArtifact} + */ + public boolean isPrimaryArtifact() + { + return primaryArtifact; + } + + /** + * @param primaryArtifact {@link #primaryArtifact} + */ + public void setPrimaryArtifact( boolean primaryArtifact ) + { + this.primaryArtifact = primaryArtifact; + } + + /** + * @return {@link #attachClasses} + */ + public boolean isAttachClasses() + { + return attachClasses; + } + + /** + * @param attachClasses {@link #attachClasses} + */ + public void setAttachClasses( boolean attachClasses ) + { + this.attachClasses = attachClasses; + } + + /** + * @return {@link #classesClassifier} + */ + public String getClassesClassifier() + { + return classesClassifier; + } + + /** + * @param classesClassifier {@link #classesClassifier} + */ + public void setClassesClassifier( String classesClassifier ) + { + this.classesClassifier = classesClassifier; + } + + /** + * @return {@link #failOnMissingWebXml} + */ + public boolean isFailOnMissingWebXml() + { + return failOnMissingWebXml; + } + + /** + * @param failOnMissingWebXml {@link #failOnMissingWebXml} + */ + public void setFailOnMissingWebXml( boolean failOnMissingWebXml ) + { + this.failOnMissingWebXml = failOnMissingWebXml; + } + + public boolean isSkip() + { + return skip; + } +} diff --git a/Java-base/maven-war-plugin/src/src/main/java/org/apache/maven/plugins/war/overlay/DefaultOverlay.java b/Java-base/maven-war-plugin/src/src/main/java/org/apache/maven/plugins/war/overlay/DefaultOverlay.java new file mode 100644 index 000000000..831a53a19 --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/main/java/org/apache/maven/plugins/war/overlay/DefaultOverlay.java @@ -0,0 +1,62 @@ +package org.apache.maven.plugins.war.overlay; + +/* + * 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. + */ + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.plugins.war.Overlay; + +/** + * A default overlay implementation based on an {@link Artifact}. + * + * @author Stephane Nicoll + */ +public class DefaultOverlay + extends Overlay +{ + + /** + * Creates an overlay for the specified artifact. + * + * @param a the artifact + */ + public DefaultOverlay( Artifact a ) + { + super(); + setGroupId( a.getGroupId() ); + setArtifactId( a.getArtifactId() ); + setClassifier( a.getClassifier() ); + setArtifact( a ); + setType( a.getType() ); + } + + /** + * Creates an overlay for the specified artifact. + * + * @param a the artifact + * @param includes the includes to use + * @param excludes the excludes to use + */ + public DefaultOverlay( Artifact a, String[] includes, String[] excludes ) + { + this( a ); + setIncludes( includes ); + setExcludes( excludes ); + } +} diff --git a/Java-base/maven-war-plugin/src/src/main/java/org/apache/maven/plugins/war/overlay/InvalidOverlayConfigurationException.java b/Java-base/maven-war-plugin/src/src/main/java/org/apache/maven/plugins/war/overlay/InvalidOverlayConfigurationException.java new file mode 100644 index 000000000..3470ef57c --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/main/java/org/apache/maven/plugins/war/overlay/InvalidOverlayConfigurationException.java @@ -0,0 +1,54 @@ +package org.apache.maven.plugins.war.overlay; + +/* + * 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. + */ + +import org.apache.maven.plugin.MojoExecutionException; + +/** + * Thrown if the overlay configuration is invalid. + * + * @author Stephane Nicoll + */ +public class InvalidOverlayConfigurationException + extends MojoExecutionException +{ + + /** + * + */ + private static final long serialVersionUID = -9048144470408031414L; + + /** + * @param string Set the message of the exception. + */ + public InvalidOverlayConfigurationException( String string ) + { + super( string ); + } + + /** + * @param string Set the message of the exception. + * @param throwable {@link Throwable} + */ + public InvalidOverlayConfigurationException( String string, Throwable throwable ) + { + super( string, throwable ); + } +} diff --git a/Java-base/maven-war-plugin/src/src/main/java/org/apache/maven/plugins/war/overlay/OverlayManager.java b/Java-base/maven-war-plugin/src/src/main/java/org/apache/maven/plugins/war/overlay/OverlayManager.java new file mode 100644 index 000000000..cf83d5e29 --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/main/java/org/apache/maven/plugins/war/overlay/OverlayManager.java @@ -0,0 +1,253 @@ +package org.apache.maven.plugins.war.overlay; + +/* + * 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. + */ + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.ListIterator; +import java.util.Objects; +import java.util.Set; + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter; +import org.apache.maven.plugins.war.Overlay; +import org.apache.maven.project.MavenProject; + +/** + * Manages the overlays. + * + * @author Stephane Nicoll + */ +public class OverlayManager +{ + private final List overlays; + + private final MavenProject project; + + private final List artifactsOverlays; + + /** + * Creates a manager with the specified overlays. + * + * Note that the list is potentially updated by the manager so a new list is created based on the overlays. + * + * @param overlays the overlays + * @param project the maven project + * @param defaultIncludes the default includes to use + * @param defaultExcludes the default excludes to use + * @param currentProjectOverlay the overlay for the current project + * @throws InvalidOverlayConfigurationException if the config is invalid + */ + public OverlayManager( List overlays, MavenProject project, String[] defaultIncludes, + String[] defaultExcludes, Overlay currentProjectOverlay ) + throws InvalidOverlayConfigurationException + { + this.overlays = new ArrayList<>(); + if ( overlays != null ) + { + this.overlays.addAll( overlays ); + } + this.project = project; + + this.artifactsOverlays = getOverlaysAsArtifacts(); + + // Initialize + initialize( defaultIncludes, defaultExcludes, currentProjectOverlay ); + + } + + /** + * Returns the resolved overlays. + * + * @return the overlays + */ + public List getOverlays() + { + return overlays; + } + + /** + * Returns the id of the resolved overlays. + * + * @return the overlay ids + */ + public List getOverlayIds() + { + final List result = new ArrayList<>(); + for ( Overlay overlay : overlays ) + { + result.add( overlay.getId() ); + } + return result; + + } + + /** + * Initializes the manager and validates the overlays configuration. + * + * @param defaultIncludes the default includes to use + * @param defaultExcludes the default excludes to use + * @param currentProjectOverlay the overlay for the current project + * @throws InvalidOverlayConfigurationException if the configuration is invalid + */ + void initialize( String[] defaultIncludes, String[] defaultExcludes, Overlay currentProjectOverlay ) + throws InvalidOverlayConfigurationException + { + + // Build the list of configured artifacts and makes sure that each overlay + // refer to a valid artifact + final List configuredWarArtifacts = new ArrayList<>(); + final ListIterator it = overlays.listIterator(); + while ( it.hasNext() ) + { + Overlay overlay = it.next(); + if ( overlay == null ) + { + throw new InvalidOverlayConfigurationException( "overlay could not be null." ); + } + // If it's the current project, return the project instance + if ( overlay.isCurrentProject() ) + { + overlay = currentProjectOverlay; + it.set( overlay ); + } + // default includes/excludes - only if the overlay uses the default settings + if ( Arrays.equals( Overlay.DEFAULT_INCLUDES, overlay.getIncludes() ) + && Arrays.equals( Overlay.DEFAULT_EXCLUDES, overlay.getExcludes() ) ) + { + overlay.setIncludes( defaultIncludes ); + overlay.setExcludes( defaultExcludes ); + } + + final Artifact artifact = getAssociatedArtifact( overlay ); + if ( artifact != null ) + { + configuredWarArtifacts.add( artifact ); + overlay.setArtifact( artifact ); + } + } + + // Build the list of missing overlays + for ( Artifact artifact : artifactsOverlays ) + { + if ( !configuredWarArtifacts.contains( artifact ) ) + { + // Add a default overlay for the given artifact which will be applied after + // the ones that have been configured + overlays.add( new DefaultOverlay( artifact, defaultIncludes, defaultExcludes ) ); + } + } + + // Final validation, make sure that the current project is in there. Otherwise add it first + for ( Overlay overlay : overlays ) + { + if ( overlay.equals( currentProjectOverlay ) ) + { + return; + } + } + overlays.add( 0, currentProjectOverlay ); + } + + /** + * Returns the Artifact associated to the specified overlay. + * + * If the overlay defines the current project, null is returned. If no artifact could not be found for the + * overlay a InvalidOverlayConfigurationException is thrown. + * + * @param overlay an overlay + * @return the artifact associated to the overlay + * @throws org.apache.maven.plugins.war.overlay.InvalidOverlayConfigurationException if the overlay does not have an + * associated artifact + */ + Artifact getAssociatedArtifact( final Overlay overlay ) + throws InvalidOverlayConfigurationException + { + if ( overlay.isCurrentProject() ) + { + return null; + } + + for ( Artifact artifact : artifactsOverlays ) + { + // Handle classifier dependencies properly (clash management) + if ( compareOverlayWithArtifact( overlay, artifact ) ) + { + return artifact; + } + } + + // maybe its a project dependencies zip or an other type + Set projectArtifacts = this.project.getDependencyArtifacts(); + if ( projectArtifacts != null ) + { + for ( Artifact artifact : projectArtifacts ) + { + if ( compareOverlayWithArtifact( overlay, artifact ) ) + { + return artifact; + } + } + } + // CHECKSTYLE_OFF: LineLength + throw new InvalidOverlayConfigurationException( "overlay [" + overlay + "] is not a dependency of the project." ); + // CHECKSTYLE_ON: LineLength + + } + + /** + * Compare groupId && artifactId && type && classifier. + * + * @param overlay the overlay + * @param artifact the artifact + * @return boolean true if equals + */ + private boolean compareOverlayWithArtifact( Overlay overlay, Artifact artifact ) + { + return ( Objects.equals( overlay.getGroupId(), artifact.getGroupId() ) + && Objects.equals( overlay.getArtifactId(), artifact.getArtifactId() ) + && Objects.equals( overlay.getType(), artifact.getType() ) + // MWAR-241 Make sure to treat null and "" as equal when comparing the classifier + && Objects.equals( Objects.toString( overlay.getClassifier() ), + Objects.toString( artifact.getClassifier() ) ) ); + } + + /** + * Returns a list of WAR {@link org.apache.maven.artifact.Artifact} describing the overlays of the current project. + * + * @return the overlays as artifacts objects + */ + private List getOverlaysAsArtifacts() + { + ScopeArtifactFilter filter = new ScopeArtifactFilter( Artifact.SCOPE_RUNTIME ); + final Set artifacts = project.getArtifacts(); + + final List result = new ArrayList<>(); + for ( Artifact artifact : artifacts ) + { + if ( !artifact.isOptional() && filter.include( artifact ) && ( "war".equals( artifact.getType() ) ) ) + { + result.add( artifact ); + } + } + return result; + } +} diff --git a/Java-base/maven-war-plugin/src/src/main/java/org/apache/maven/plugins/war/packaging/AbstractWarPackagingTask.java b/Java-base/maven-war-plugin/src/src/main/java/org/apache/maven/plugins/war/packaging/AbstractWarPackagingTask.java new file mode 100644 index 000000000..e230f6cf6 --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/main/java/org/apache/maven/plugins/war/packaging/AbstractWarPackagingTask.java @@ -0,0 +1,492 @@ +package org.apache.maven.plugins.war.packaging; + +/* + * 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. + */ + +import java.io.File; +import java.io.IOException; + +import org.apache.commons.io.input.XmlStreamReader; +import org.apache.maven.artifact.Artifact; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugins.war.util.PathSet; +import org.apache.maven.plugins.war.util.WebappStructure; +import org.apache.maven.shared.filtering.MavenFilteringException; +import org.apache.maven.shared.mapping.MappingUtils; +import org.codehaus.plexus.archiver.ArchiverException; +import org.codehaus.plexus.archiver.UnArchiver; +import org.codehaus.plexus.archiver.jar.JarArchiver; +import org.codehaus.plexus.archiver.manager.NoSuchArchiverException; +import org.codehaus.plexus.interpolation.InterpolationException; +import org.codehaus.plexus.util.DirectoryScanner; +import org.codehaus.plexus.util.FileUtils; + +/** + * @author Stephane Nicoll + */ +public abstract class AbstractWarPackagingTask + implements WarPackagingTask +{ + /** + * The default list of includes. + */ + public static final String[] DEFAULT_INCLUDES = { "**/**" }; + + /** + * The {@code WEB-INF} path. + */ + public static final String WEB_INF_PATH = "WEB-INF"; + + /** + * The {@code META-INF} path. + */ + public static final String META_INF_PATH = "META-INF"; + + /** + * The {@code classes} path. + */ + public static final String CLASSES_PATH = "WEB-INF/classes/"; + + /** + * The {@code lib} path. + */ + public static final String LIB_PATH = "WEB-INF/lib/"; + + /** + * Copies the files if possible with an optional target prefix. + * + * Copy uses a first-win strategy: files that have already been copied by previous tasks are ignored. This method + * makes sure to update the list of protected files which gives the list of files that have already been copied. + * + * If the structure of the source directory is not the same as the root of the webapp, use the targetPrefix + * parameter to specify in which particular directory the files should be copied. Use null to copy the + * files with the same structure + * + * @param sourceId the source id + * @param context the context to use + * @param sourceBaseDir the base directory from which the sourceFilesSet will be copied + * @param sourceFilesSet the files to be copied + * @param targetPrefix the prefix to add to the target file name + * @param filtered filter or not. + * @throws IOException if an error occurred while copying the files + * @throws MojoExecutionException if an error occurs. + */ + protected void copyFiles( String sourceId, WarPackagingContext context, File sourceBaseDir, PathSet sourceFilesSet, + String targetPrefix, boolean filtered ) + throws IOException, MojoExecutionException + { + for ( String fileToCopyName : sourceFilesSet.paths() ) + { + final File sourceFile = new File( sourceBaseDir, fileToCopyName ); + + String destinationFileName; + if ( targetPrefix == null ) + { + destinationFileName = fileToCopyName; + } + else + { + destinationFileName = targetPrefix + fileToCopyName; + } + + if ( filtered && !context.isNonFilteredExtension( sourceFile.getName() ) ) + { + copyFilteredFile( sourceId, context, sourceFile, destinationFileName ); + } + else + { + copyFile( sourceId, context, sourceFile, destinationFileName ); + } + } + } + + /** + * Copies the files if possible as is. + * + * Copy uses a first-win strategy: files that have already been copied by previous tasks are ignored. This method + * makes sure to update the list of protected files which gives the list of files that have already been copied. + * + * @param sourceId the source id + * @param context the context to use + * @param sourceBaseDir the base directory from which the sourceFilesSet will be copied + * @param sourceFilesSet the files to be copied + * @param filtered filter or not. + * @throws IOException if an error occurred while copying the files + * @throws MojoExecutionException break the build. + */ + protected void copyFiles( String sourceId, WarPackagingContext context, File sourceBaseDir, PathSet sourceFilesSet, + boolean filtered ) + throws IOException, MojoExecutionException + { + copyFiles( sourceId, context, sourceBaseDir, sourceFilesSet, null, filtered ); + } + + /** + * Copy the specified file if the target location has not yet already been used. + * + * The targetFileName is the relative path according to the root of the generated web application. + * + * @param sourceId the source id + * @param context the context to use + * @param file the file to copy + * @param targetFilename the relative path according to the root of the webapp + * @throws IOException if an error occurred while copying + */ + // CHECKSTYLE_OFF: LineLength + protected void copyFile( String sourceId, final WarPackagingContext context, final File file, String targetFilename ) + throws IOException + // CHECKSTYLE_ON: LineLength + { + final File targetFile = new File( context.getWebappDirectory(), targetFilename ); + + if ( file.isFile() ) + { + context.getWebappStructure().registerFile( sourceId, targetFilename, + new WebappStructure.RegistrationCallback() + { + public void registered( String ownerId, String targetFilename ) + throws IOException + { + copyFile( context, file, targetFile, targetFilename, + false ); + } + + public void alreadyRegistered( String ownerId, + String targetFilename ) + throws IOException + { + copyFile( context, file, targetFile, targetFilename, + true ); + } + + public void refused( String ownerId, String targetFilename, + String actualOwnerId ) + throws IOException + { + context.getLog().debug( " - " + + targetFilename + + " wasn't copied because it has " + + "already been packaged for overlay [" + + actualOwnerId + "]." ); + } + + public void superseded( String ownerId, + String targetFilename, + String deprecatedOwnerId ) + throws IOException + { + context.getLog().info( "File [" + + targetFilename + + "] belonged to overlay [" + + deprecatedOwnerId + + "] so it will be overwritten." ); + copyFile( context, file, targetFile, targetFilename, + false ); + } + + public void supersededUnknownOwner( String ownerId, + String targetFilename, + String unknownOwnerId ) + throws IOException + { + // CHECKSTYLE_OFF: LineLength + context.getLog().warn( "File [" + + targetFilename + + "] belonged to overlay [" + + unknownOwnerId + + "] which does not exist anymore in the current project. It is recommended to invoke " + + "clean if the dependencies of the project changed." ); + // CHECKSTYLE_ON: LineLength + copyFile( context, file, targetFile, targetFilename, + false ); + } + } ); + } + else if ( !targetFile.exists() && !targetFile.mkdirs() ) + { + context.getLog().info( "Failed to create directory " + targetFile.getAbsolutePath() ); + } + } + + /** + * Copy the specified file if the target location has not yet already been used and filter its content with the + * configured filter properties. + * + * The targetFileName is the relative path according to the root of the generated web application. + * + * @param sourceId the source id + * @param context the context to use + * @param file the file to copy + * @param targetFilename the relative path according to the root of the webapp + * @return true if the file has been copied, false otherwise + * @throws IOException if an error occurred while copying + * @throws MojoExecutionException if an error occurred while retrieving the filter properties + */ + protected boolean copyFilteredFile( String sourceId, final WarPackagingContext context, File file, + String targetFilename ) + throws IOException, MojoExecutionException + { + context.addResource( targetFilename ); + + if ( context.getWebappStructure().registerFile( sourceId, targetFilename ) ) + { + final File targetFile = new File( context.getWebappDirectory(), targetFilename ); + final String encoding; + try + { + if ( isXmlFile( file ) ) + { + // For xml-files we extract the encoding from the files + encoding = getEncoding( file ); + } + else + { + // For all others we use the configured encoding + encoding = context.getResourceEncoding(); + } + // fix for MWAR-36, ensures that the parent dir are created first + targetFile.getParentFile().mkdirs(); + + context.getMavenFileFilter().copyFile( file, targetFile, true, context.getFilterWrappers(), encoding ); + } + catch ( MavenFilteringException e ) + { + throw new MojoExecutionException( e.getMessage(), e ); + } + // CHECKSTYLE_OFF: LineLength + // Add the file to the protected list + context.getLog().debug( " + " + targetFilename + " has been copied (filtered encoding='" + encoding + "')." ); + // CHECKSTYLE_ON: LineLength + return true; + } + else + { + context.getLog().debug( " - " + targetFilename + + " wasn't copied because it has already been packaged (filtered)." ); + return false; + } + } + + /** + * Unpacks the specified file to the specified directory. + * + * @param context the packaging context + * @param file the file to unpack + * @param unpackDirectory the directory to use for th unpacked file + * @throws MojoExecutionException if an error occurred while unpacking the file + */ + protected void doUnpack( WarPackagingContext context, File file, File unpackDirectory ) + throws MojoExecutionException + { + String archiveExt = FileUtils.getExtension( file.getAbsolutePath() ).toLowerCase(); + + try + { + UnArchiver unArchiver = context.getArchiverManager().getUnArchiver( archiveExt ); + unArchiver.setSourceFile( file ); + unArchiver.setDestDirectory( unpackDirectory ); + unArchiver.setOverwrite( true ); + unArchiver.extract(); + } + catch ( ArchiverException e ) + { + throw new MojoExecutionException( "Error unpacking file [" + file.getAbsolutePath() + "]" + " to [" + + unpackDirectory.getAbsolutePath() + "]", e ); + } + catch ( NoSuchArchiverException e ) + { + context.getLog().warn( "Skip unpacking dependency file [" + file.getAbsolutePath() + + " with unknown extension [" + archiveExt + "]" ); + } + } + + /** + * Copy file from source to destination. The directories up to destination will be created if they + * don't already exist. if the onlyIfModified flag is false, destination will be + * overwritten if it already exists. If the flag is true destination will be overwritten if it's not up to + * date. + * + * @param context the packaging context + * @param source an existing non-directory File to copy bytes from + * @param destination a non-directory File to write bytes to (possibly overwriting). + * @param targetFilename the relative path of the file from the webapp root directory + * @param onlyIfModified if true, copy the file only if the source has changed, always copy otherwise + * @return true if the file has been copied/updated, false otherwise + * @throws IOException if source does not exist, destination cannot be written to, or an + * IO error occurs during copying + */ + protected boolean copyFile( WarPackagingContext context, File source, File destination, String targetFilename, + boolean onlyIfModified ) + throws IOException + { + context.addResource( targetFilename ); + + if ( onlyIfModified && destination.lastModified() >= source.lastModified() ) + { + context.getLog().debug( " * " + targetFilename + " is up to date." ); + return false; + } + else + { + if ( source.isDirectory() ) + { + context.getLog().warn( " + " + targetFilename + " is packaged from the source folder" ); + + try + { + JarArchiver archiver = context.getJarArchiver(); + archiver.addDirectory( source ); + archiver.setDestFile( destination ); + archiver.createArchive(); + } + catch ( ArchiverException e ) + { + String msg = "Failed to create " + targetFilename; + context.getLog().error( msg, e ); + IOException ioe = new IOException( msg ); + ioe.initCause( e ); + throw ioe; + } + } + else + { + FileUtils.copyFile( source.getCanonicalFile(), destination ); + // preserve timestamp + destination.setLastModified( source.lastModified() ); + context.getLog().debug( " + " + targetFilename + " has been copied." ); + } + return true; + } + } + + /** + * Get the encoding from an XML-file. + * + * @param webXml the XML-file + * @return The encoding of the XML-file, or UTF-8 if it's not specified in the file + * @throws java.io.IOException if an error occurred while reading the file + */ + protected String getEncoding( File webXml ) + throws IOException + { + try ( XmlStreamReader xmlReader = new XmlStreamReader( webXml ) ) + { + return xmlReader.getEncoding(); + } + } + + /** + * Returns the file to copy. If the includes are null or empty, the default includes are used. + * + * @param baseDir the base directory to start from + * @param includes the includes + * @param excludes the excludes + * @return the files to copy + */ + protected PathSet getFilesToIncludes( File baseDir, String[] includes, String[] excludes ) + { + return getFilesToIncludes( baseDir, includes, excludes, false ); + } + + /** + * Returns the file to copy. If the includes are null or empty, the default includes are used. + * + * @param baseDir the base directory to start from + * @param includes the includes + * @param excludes the excludes + * @param includeDirectories include directories yes or not. + * @return the files to copy + */ + // CHECKSTYLE_OFF: LineLength + protected PathSet getFilesToIncludes( File baseDir, String[] includes, String[] excludes, boolean includeDirectories ) + // CHECKSTYLE_ON: LineLength + { + final DirectoryScanner scanner = new DirectoryScanner(); + scanner.setBasedir( baseDir ); + + if ( excludes != null ) + { + scanner.setExcludes( excludes ); + } + scanner.addDefaultExcludes(); + + if ( includes != null && includes.length > 0 ) + { + scanner.setIncludes( includes ); + } + else + { + scanner.setIncludes( DEFAULT_INCLUDES ); + } + + scanner.scan(); + + PathSet pathSet = new PathSet( scanner.getIncludedFiles() ); + + if ( includeDirectories ) + { + pathSet.addAll( scanner.getIncludedDirectories() ); + } + + return pathSet; + } + + /** + * Returns the final name of the specified artifact. + * + * If the outputFileNameMapping is set, it is used, otherwise the standard naming scheme is used. + * + * @param context the packaging context + * @param artifact the artifact + * @return the converted filename of the artifact + * @throws InterpolationException in case of interpolation problem. + */ + protected String getArtifactFinalName( WarPackagingContext context, Artifact artifact ) + throws InterpolationException + { + if ( context.getOutputFileNameMapping() != null ) + { + return MappingUtils.evaluateFileNameMapping( context.getOutputFileNameMapping(), artifact ); + } + + String classifier = artifact.getClassifier(); + if ( ( classifier != null ) && !( "".equals( classifier.trim() ) ) ) + { + return MappingUtils.evaluateFileNameMapping( MappingUtils.DEFAULT_FILE_NAME_MAPPING_CLASSIFIER, artifact ); + } + else + { + return MappingUtils.evaluateFileNameMapping( MappingUtils.DEFAULT_FILE_NAME_MAPPING, artifact ); + } + + } + + /** + * Returns true if the File-object is a file (not a directory) that is not + * null and has a file name that ends in ".xml". + * + * @param file The file to check + * @return true if the file is an xml-file, otherwise false + * @since 2.3 + */ + private boolean isXmlFile( File file ) + { + return file != null && file.isFile() && file.getName().endsWith( ".xml" ); + } +} diff --git a/Java-base/maven-war-plugin/src/src/main/java/org/apache/maven/plugins/war/packaging/ArtifactsPackagingTask.java b/Java-base/maven-war-plugin/src/src/main/java/org/apache/maven/plugins/war/packaging/ArtifactsPackagingTask.java new file mode 100644 index 000000000..2fa484d6d --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/main/java/org/apache/maven/plugins/war/packaging/ArtifactsPackagingTask.java @@ -0,0 +1,187 @@ +package org.apache.maven.plugins.war.packaging; + +/* + * 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. + */ + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.Set; + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugins.war.Overlay; +import org.codehaus.plexus.interpolation.InterpolationException; + +/** + * Handles the artifacts that needs to be packaged in the web application. + * + * @author Stephane Nicoll + */ +public class ArtifactsPackagingTask + extends AbstractWarPackagingTask +{ + + /** + * The {@code tld} path. + */ + public static final String TLD_PATH = "WEB-INF/tld/"; + + /** + * The {@code services} path. + */ + public static final String SERVICES_PATH = "WEB-INF/services/"; + + /** + * The {@code modules} path. + */ + public static final String MODULES_PATH = "WEB-INF/modules/"; + + /** + * The {@code extensions} path. + */ + public static final String EXTENSIONS_PATH = "WEB-INF/extensions/"; + + private final Set artifacts; + + private final String id; + + /** + * @param artifacts {@link #artifacts} + * @param currentProjectOverlay {@link #id} + */ + public ArtifactsPackagingTask( Set artifacts, Overlay currentProjectOverlay ) + { + this.artifacts = artifacts; + this.id = currentProjectOverlay.getId(); + } + + @Override + public void performPackaging( WarPackagingContext context ) + throws MojoExecutionException + { + try + { + final ScopeArtifactFilter filter = new ScopeArtifactFilter( Artifact.SCOPE_RUNTIME ); + final List duplicates = findDuplicates( context, artifacts ); + + for ( Artifact artifact : artifacts ) + { + String targetFileName = getArtifactFinalName( context, artifact ); + + context.getLog().debug( "Processing: " + targetFileName ); + + if ( duplicates.contains( targetFileName ) ) + { + context.getLog().debug( "Duplicate found: " + targetFileName ); + targetFileName = artifact.getGroupId() + "-" + targetFileName; + context.getLog().debug( "Renamed to: " + targetFileName ); + } + context.getWebappStructure().registerTargetFileName( artifact, targetFileName ); + + if ( !artifact.isOptional() && filter.include( artifact ) ) + { + try + { + String type = artifact.getType(); + if ( "tld".equals( type ) ) + { + copyFile( id, context, artifact.getFile(), TLD_PATH + targetFileName ); + } + else if ( "aar".equals( type ) ) + { + copyFile( id, context, artifact.getFile(), SERVICES_PATH + targetFileName ); + } + else if ( "mar".equals( type ) ) + { + copyFile( id, context, artifact.getFile(), MODULES_PATH + targetFileName ); + } + else if ( "xar".equals( type ) ) + { + copyFile( id, context, artifact.getFile(), EXTENSIONS_PATH + targetFileName ); + } + else if ( "jar".equals( type ) || "ejb".equals( type ) || "ejb-client".equals( type ) + || "test-jar".equals( type ) || "bundle".equals( type ) ) + { + copyFile( id, context, artifact.getFile(), LIB_PATH + targetFileName ); + } + else if ( "par".equals( type ) ) + { + targetFileName = targetFileName.substring( 0, targetFileName.lastIndexOf( '.' ) ) + ".jar"; + copyFile( id, context, artifact.getFile(), LIB_PATH + targetFileName ); + } + else if ( "war".equals( type ) ) + { + // Nothing to do here, it is an overlay and it's already handled + context.getLog().debug( "war artifacts are handled as overlays, ignoring [" + artifact + + "]" ); + } + else if ( "zip".equals( type ) ) + { + // Nothing to do here, it is an overlay and it's already handled + context.getLog().debug( "zip artifacts are handled as overlays, ignoring [" + artifact + + "]" ); + } + else + { + context.getLog().debug( "Artifact of type [" + type + "] is not supported, ignoring [" + + artifact + "]" ); + } + } + catch ( IOException e ) + { + throw new MojoExecutionException( "Failed to copy file for artifact [" + artifact + "]", e ); + } + } + } + } + catch ( InterpolationException e ) + { + throw new MojoExecutionException( e.getMessage(), e ); + } + } + + /** + * Searches a set of artifacts for duplicate filenames and returns a list of duplicates. + * + * @param context the packaging context + * @param artifacts set of artifacts + * @return List of duplicated artifacts as bundling file names + */ + private List findDuplicates( WarPackagingContext context, Set artifacts ) + throws InterpolationException + { + List duplicates = new ArrayList<>(); + List identifiers = new ArrayList<>(); + for ( Artifact artifact : artifacts ) + { + String candidate = getArtifactFinalName( context, artifact ); + if ( identifiers.contains( candidate ) ) + { + duplicates.add( candidate ); + } + else + { + identifiers.add( candidate ); + } + } + return duplicates; + } +} diff --git a/Java-base/maven-war-plugin/src/src/main/java/org/apache/maven/plugins/war/packaging/ClassesPackagingTask.java b/Java-base/maven-war-plugin/src/src/main/java/org/apache/maven/plugins/war/packaging/ClassesPackagingTask.java new file mode 100644 index 000000000..ea136a695 --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/main/java/org/apache/maven/plugins/war/packaging/ClassesPackagingTask.java @@ -0,0 +1,128 @@ +package org.apache.maven.plugins.war.packaging; + +/* + * 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. + */ + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.factory.ArtifactFactory; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugins.war.Overlay; +import org.apache.maven.plugins.war.util.ClassesPackager; +import org.apache.maven.plugins.war.util.PathSet; +import org.apache.maven.project.MavenProject; +import org.codehaus.plexus.interpolation.InterpolationException; + +import java.io.File; +import java.io.IOException; + +/** + * Handles the classes directory that needs to be packaged in the web application. + * + * Based on the {@link WarPackagingContext#archiveClasses()} flag, the resources are either copied into to + * WEB-INF/classes directory or archived in a jar within the WEB-INF/lib directory. + * + * @author Stephane Nicoll + */ +public class ClassesPackagingTask + extends AbstractWarPackagingTask +{ + private final Overlay currentProjectOverlay; + + /** + * @param currentProjectOverlay {@link #currentProjectOverlay} + */ + public ClassesPackagingTask( Overlay currentProjectOverlay ) + { + this.currentProjectOverlay = currentProjectOverlay; + } + + @Override + public void performPackaging( WarPackagingContext context ) + throws MojoExecutionException + { + final File webappClassesDirectory = new File( context.getWebappDirectory(), CLASSES_PATH ); + if ( !webappClassesDirectory.exists() ) + { + webappClassesDirectory.mkdirs(); + } + + if ( context.getClassesDirectory().exists() && !context.getClassesDirectory().equals( webappClassesDirectory ) ) + { + if ( context.archiveClasses() ) + { + generateJarArchive( context ); + } + else + { + final PathSet sources = getFilesToIncludes( context.getClassesDirectory(), null, null ); + try + { + copyFiles( currentProjectOverlay.getId(), context, context.getClassesDirectory(), sources, + CLASSES_PATH, false ); + } + catch ( IOException e ) + { + throw new MojoExecutionException( "Could not copy webapp classes [" + + context.getClassesDirectory().getAbsolutePath() + "]", e ); + } + } + } + } + + /** + * @param context The warPackingContext. + * @throws MojoExecutionException In case of an error. + */ + protected void generateJarArchive( WarPackagingContext context ) + throws MojoExecutionException + { + MavenProject project = context.getProject(); + ArtifactFactory factory = context.getArtifactFactory(); + Artifact artifact = + factory.createBuildArtifact( project.getGroupId(), project.getArtifactId(), project.getVersion(), "jar" ); + String archiveName; + try + { + archiveName = getArtifactFinalName( context, artifact ); + } + catch ( InterpolationException e ) + { + throw new MojoExecutionException( "Could not get the final name of the artifact [" + artifact.getGroupId() + + ":" + artifact.getArtifactId() + ":" + artifact.getVersion() + "]", e ); + } + final String targetFilename = LIB_PATH + archiveName; + + if ( context.getWebappStructure().registerFile( currentProjectOverlay.getId(), targetFilename ) ) + { + context.addResource( targetFilename ); + + final File libDirectory = new File( context.getWebappDirectory(), LIB_PATH ); + final File jarFile = new File( libDirectory, archiveName ); + final ClassesPackager packager = new ClassesPackager(); + packager.packageClasses( context.getClassesDirectory(), jarFile, context.getJarArchiver(), + context.getSession(), project, context.getArchive(), + context.getOutputTimestamp() ); + } + else + { + context.getLog().warn( "Could not generate archive classes file [" + targetFilename + + "] has already been copied." ); + } + } +} diff --git a/Java-base/maven-war-plugin/src/src/main/java/org/apache/maven/plugins/war/packaging/CopyUserManifestTask.java b/Java-base/maven-war-plugin/src/src/main/java/org/apache/maven/plugins/war/packaging/CopyUserManifestTask.java new file mode 100644 index 000000000..217c18a2d --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/main/java/org/apache/maven/plugins/war/packaging/CopyUserManifestTask.java @@ -0,0 +1,77 @@ +package org.apache.maven.plugins.war.packaging; + +/* + * 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. + */ + +import java.io.File; +import java.io.IOException; + +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.MojoFailureException; +import org.apache.maven.plugin.logging.Log; +import org.apache.maven.plugin.logging.SystemStreamLog; + +/** + * @author Haikal Saadh + * + */ +public class CopyUserManifestTask + extends AbstractWarPackagingTask +{ + + /** Instance logger */ + private Log log; + + public Log getLog() + { + if ( log == null ) + { + log = new SystemStreamLog(); + } + return log; + } + + public void setLog( Log log ) + { + this.log = log; + } + + public void performPackaging( WarPackagingContext context ) + throws MojoExecutionException, MojoFailureException + { + File userManifest = context.getArchive().getManifestFile(); + if ( userManifest != null ) + { + + try + { + getLog().info( "Copying manifest..." ); + File metainfDir = new File( context.getWebappDirectory(), META_INF_PATH ); + copyFile( context, userManifest, new File( metainfDir, "MANIFEST.MF" ), "META-INF/MANIFEST.MF", true ); + + } + catch ( IOException e ) + { + throw new MojoExecutionException( "Error copying user manifest", e ); + } + } + + } + +} diff --git a/Java-base/maven-war-plugin/src/src/main/java/org/apache/maven/plugins/war/packaging/OverlayPackagingTask.java b/Java-base/maven-war-plugin/src/src/main/java/org/apache/maven/plugins/war/packaging/OverlayPackagingTask.java new file mode 100644 index 000000000..df7f2b400 --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/main/java/org/apache/maven/plugins/war/packaging/OverlayPackagingTask.java @@ -0,0 +1,157 @@ +package org.apache.maven.plugins.war.packaging; + +/* + * 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. + */ + +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugins.war.Overlay; +import org.apache.maven.plugins.war.util.PathSet; +import org.codehaus.plexus.util.FileUtils; + +import java.io.File; +import java.io.IOException; + +/** + * Handles an overlay. + * + * @author Stephane Nicoll + */ +public class OverlayPackagingTask + extends AbstractWarPackagingTask +{ + private final Overlay overlay; + + /** + * @param overlay {@link #overlay} + * @param currentProjectOverlay current overlay. + */ + public OverlayPackagingTask( Overlay overlay, Overlay currentProjectOverlay ) + { + if ( overlay == null ) + { + throw new NullPointerException( "overlay could not be null." ); + } + if ( overlay.equals( currentProjectOverlay ) ) + { + throw new IllegalStateException( "Could not handle the current project with this task." ); + } + this.overlay = overlay; + } + + @Override + public void performPackaging( WarPackagingContext context ) + throws MojoExecutionException + { + context.getLog().debug( "OverlayPackagingTask performPackaging overlay.getTargetPath() " + + overlay.getTargetPath() ); + if ( overlay.shouldSkip() ) + { + context.getLog().info( "Skipping overlay [" + overlay + "]" ); + } + else + { + try + { + context.getLog().info( "Processing overlay [" + overlay + "]" ); + + // Step1: Extract if necessary + final File tmpDir = unpackOverlay( context, overlay ); + + // Step2: setup + final PathSet includes = getFilesToIncludes( tmpDir, overlay.getIncludes(), overlay.getExcludes() ); + + // Copy + if ( null == overlay.getTargetPath() ) + { + copyFiles( overlay.getId(), context, tmpDir, includes, overlay.isFiltered() ); + } + else + { + // overlay.getTargetPath() must ended with / + // if not we add it + String targetPath = overlay.getTargetPath(); + if ( !targetPath.endsWith( "/" ) ) + { + targetPath = targetPath + "/"; + } + copyFiles( overlay.getId(), context, tmpDir, includes, targetPath, overlay.isFiltered() ); + } + } + catch ( IOException e ) + { + throw new MojoExecutionException( "Failed to copy file for overlay [" + overlay + "]", e ); + } + } + } + + /** + * Unpacks the specified overlay. + * + * Makes sure to skip the unpack process if the overlay has already been unpacked. + * + * @param context the packaging context + * @param overlay the overlay + * @return the directory containing the unpacked overlay + * @throws MojoExecutionException if an error occurred while unpacking the overlay + */ + protected File unpackOverlay( WarPackagingContext context, Overlay overlay ) + throws MojoExecutionException + { + final File tmpDir = getOverlayTempDirectory( context, overlay ); + + // TODO: not sure it's good, we should reuse the markers of the dependency plugin + if ( FileUtils.sizeOfDirectory( tmpDir ) == 0 + || overlay.getArtifact().getFile().lastModified() > tmpDir.lastModified() ) + { + doUnpack( context, overlay.getArtifact().getFile(), tmpDir ); + } + else + { + context.getLog().debug( "Overlay [" + overlay + "] was already unpacked" ); + } + return tmpDir; + } + + /** + * Returns the directory to use to unpack the specified overlay. + * + * @param context the packaging context + * @param overlay the overlay + * @return the temp directory for the overlay + */ + protected File getOverlayTempDirectory( WarPackagingContext context, Overlay overlay ) + { + final File groupIdDir = new File( context.getOverlaysWorkDirectory(), overlay.getGroupId() ); + if ( !groupIdDir.exists() ) + { + groupIdDir.mkdir(); + } + String directoryName = overlay.getArtifactId(); + if ( overlay.getClassifier() != null ) + { + directoryName = directoryName + "-" + overlay.getClassifier(); + } + final File result = new File( groupIdDir, directoryName ); + if ( !result.exists() ) + { + result.mkdirs(); + } + return result; + } +} diff --git a/Java-base/maven-war-plugin/src/src/main/java/org/apache/maven/plugins/war/packaging/WarPackagingContext.java b/Java-base/maven-war-plugin/src/src/main/java/org/apache/maven/plugins/war/packaging/WarPackagingContext.java new file mode 100644 index 000000000..29336a234 --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/main/java/org/apache/maven/plugins/war/packaging/WarPackagingContext.java @@ -0,0 +1,253 @@ +package org.apache.maven.plugins.war.packaging; + +/* + * 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. + */ + +import java.io.File; +import java.util.List; + +import org.apache.maven.archiver.MavenArchiveConfiguration; +import org.apache.maven.artifact.factory.ArtifactFactory; +import org.apache.maven.execution.MavenSession; +import org.apache.maven.plugin.logging.Log; +import org.apache.maven.plugins.war.util.WebappStructure; +import org.apache.maven.project.MavenProject; +import org.apache.maven.shared.filtering.MavenFileFilter; +import org.apache.maven.shared.utils.io.FileUtils.FilterWrapper; +import org.codehaus.plexus.archiver.jar.JarArchiver; +import org.codehaus.plexus.archiver.manager.ArchiverManager; + +/** + * The packaging context. + * + * @author Stephane Nicoll + */ +public interface WarPackagingContext +{ + /** + * Returns the maven project. + * + * @return the project + */ + MavenProject getProject(); + + /** + * Returns the webapp directory. Packaging tasks should use this directory to generate the webapp. + * + * @return the webapp directory + */ + File getWebappDirectory(); + + /** + * Returns the main webapp source directory. + * + * @return the webapp source directory + */ + File getWebappSourceDirectory(); + + /** + * Returns the webapp source includes. + * + * @return the webapp source includes + */ + String[] getWebappSourceIncludes(); + + /** + * Returns {@code true} if empty directories should be includes, otherwise {@code false} + * + * @return {@code true} if empty directories should be includes, otherwise {@code false} + */ + boolean isWebappSourceIncludeEmptyDirectories(); + + /** + * Returns the webapp source excludes. + * + * @return the webapp source excludes + */ + String[] getWebappSourceExcludes(); + + /** + * Returns the directory holding generated classes. + * + * @return the classes directory + */ + File getClassesDirectory(); + + /** + * Specify whether the classes resources should be archived in the WEB-INF/lib of the generated web app. + * + * @return true if the classes should be archived, false otherwise + */ + boolean archiveClasses(); + + /** + * Returns the logger to use to output logging event. + * + * @return the logger + */ + Log getLog(); + + /** + * Returns the directory to unpack dependent WARs into if needed. + * + * @return the overlays work directory + */ + File getOverlaysWorkDirectory(); + + /** + * Returns the archiver manager to use. + * + * @return the archiver manager + */ + ArchiverManager getArchiverManager(); + + /** + * The maven archive configuration to use. + * + * @return the maven archive configuration + */ + MavenArchiveConfiguration getArchive(); + + /** + * Returns the Jar archiver needed for archiving classes directory into jar file under WEB-INF/lib. + * + * @return the jar archiver to user + */ + JarArchiver getJarArchiver(); + + /** + * Returns the output file name mapping to use, if any. Returns null if no file name mapping is set. + * + * @return the output file name mapping or null + */ + String getOutputFileNameMapping(); + + /** + * Returns the list of filter files to use. + * + * @return a list of filter files + */ + List getFilters(); + + /** + * Returns the {@link WebappStructure}. + * + * @return the webapp structure + */ + WebappStructure getWebappStructure(); + + /** + * Returns the list of registered overlays for this session. + * + * @return the list of registered overlays, including the current project + */ + List getOwnerIds(); + + /** + * Returns the {@link MavenFileFilter} instance to use. + * + * @return the maven file filter to use + * @since 2.1-alpha-2 + */ + MavenFileFilter getMavenFileFilter(); + + /** + * @return {@link List} of {@link FilterWrapper} + * @since 2.1-alpha-2 + */ + List getFilterWrappers(); + + /** + * Specify if the given fileName belongs to the list of extensions that must not be filtered + * + * @param fileName the name of file + * @return true if it should not be filtered, false otherwise + * @since 2.1-alpha-2 + */ + boolean isNonFilteredExtension( String fileName ); + + /** + * @return filtering deployment descriptor. + */ + boolean isFilteringDeploymentDescriptors(); + + /** + * @return {@link ArtifactFactory} + */ + ArtifactFactory getArtifactFactory(); + + /** + * Returns the Maven session. + * + * @return the Maven session + * @since 2.2 + */ + MavenSession getSession(); + + /** + * Returns the encoding to use for resources. + * + * @return the resource encoding + * @since 2.3 + */ + String getResourceEncoding(); + + /** + * @return to use jvmChmod rather than forking chmod cli + * @since 2.4 + */ + boolean isUseJvmChmod(); + + /** + * Returns the flag that switch on/off the missing web.xml validation + * + * @return failOnMissingWebXml + */ + Boolean isFailOnMissingWebXml(); + + /** + * Add a live resource to the war. + * Used to keep track of existing resources and all copied files. + * All others are outdated and will be removed. + * This prevent calling mvn clean when resources are removed. + * + * @param resource the resource that is to me marked as not outdated + * @since 3.3.0 + * @see #deleteOutdatedResources() + */ + void addResource( String resource ); + + /** + * Delete outdated resources, ie resources that are found in the war but that were not added by the current + * packaging process, then are supposed to be content from a previous run. + * This prevent calling mvn clean when resources are removed. + * + * @since 3.3.0 + * @see #addResource + */ + void deleteOutdatedResources(); + + /** + * Output timestamp for reproducible archive creation. + * + * @return the output timestamp (may be null) + * @since 3.3.0 + */ + String getOutputTimestamp(); +} diff --git a/Java-base/maven-war-plugin/src/src/main/java/org/apache/maven/plugins/war/packaging/WarPackagingTask.java b/Java-base/maven-war-plugin/src/src/main/java/org/apache/maven/plugins/war/packaging/WarPackagingTask.java new file mode 100644 index 000000000..4260e1deb --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/main/java/org/apache/maven/plugins/war/packaging/WarPackagingTask.java @@ -0,0 +1,45 @@ +package org.apache.maven.plugins.war.packaging; + +/* + * 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. + */ + +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.MojoFailureException; + +/** + * The base packaging task. + * + * @author Stephane Nicoll + */ +public interface WarPackagingTask +{ + + /** + * Performs the packaging for the specified task. + * + * The task is responsible to update the packaging context, namely with the files that have been copied. + * + * @param context the packaging context + * @throws MojoExecutionException if an error occurred + * @throws MojoFailureException if the project configuration is invalid + */ + void performPackaging( WarPackagingContext context ) + throws MojoExecutionException, MojoFailureException; + +} diff --git a/Java-base/maven-war-plugin/src/src/main/java/org/apache/maven/plugins/war/packaging/WarProjectPackagingTask.java b/Java-base/maven-war-plugin/src/src/main/java/org/apache/maven/plugins/war/packaging/WarProjectPackagingTask.java new file mode 100644 index 000000000..599370629 --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/main/java/org/apache/maven/plugins/war/packaging/WarProjectPackagingTask.java @@ -0,0 +1,381 @@ +package org.apache.maven.plugins.war.packaging; + +/* + * 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. + */ + +import java.io.File; +import java.io.IOException; +import java.util.Objects; + +import org.apache.maven.model.Resource; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.MojoFailureException; +import org.apache.maven.plugins.war.Overlay; +import org.apache.maven.plugins.war.util.PathSet; +import org.apache.maven.shared.filtering.MavenFilteringException; +import org.codehaus.plexus.util.DirectoryScanner; +import org.codehaus.plexus.util.StringUtils; + +/** + * Handles the project own resources, that is: + *

    + *
  • The list of web resources, if any
  • + *
  • The content of the webapp directory if it exists
  • + *
  • The custom deployment descriptor(s), if any
  • + *
  • The content of the classes directory if it exists
  • + *
  • The dependencies of the project
  • + *
+ * + * @author Stephane Nicoll + */ +public class WarProjectPackagingTask + extends AbstractWarPackagingTask +{ + private final Resource[] webResources; + + private final File webXml; + + private final File containerConfigXML; + + private final String id; + + private Overlay currentProjectOverlay; + + /** + * @param webResources {@link #webResources} + * @param webXml {@link #webXml} + * @param containerConfigXml {@link #containerConfigXML} + * @param currentProjectOverlay {@link #currentProjectOverlay} + */ + public WarProjectPackagingTask( Resource[] webResources, File webXml, File containerConfigXml, + Overlay currentProjectOverlay ) + { + if ( webResources != null ) + { + this.webResources = webResources; + } + else + { + this.webResources = new Resource[0]; + } + this.webXml = webXml; + this.containerConfigXML = containerConfigXml; + this.currentProjectOverlay = currentProjectOverlay; + this.id = currentProjectOverlay.getId(); + } + + @Override + public void performPackaging( WarPackagingContext context ) + throws MojoExecutionException, MojoFailureException + { + context.getLog().info( "Processing war project" ); + + // Prepare the INF directories + File webinfDir = new File( context.getWebappDirectory(), WEB_INF_PATH ); + webinfDir.mkdirs(); + File metainfDir = new File( context.getWebappDirectory(), META_INF_PATH ); + metainfDir.mkdirs(); + + handleWebResources( context ); + + handleWebAppSourceDirectory( context ); + + // Debug mode: dump the path set for the current build + PathSet pathSet = context.getWebappStructure().getStructure( "currentBuild" ); + context.getLog().debug( "Dump of the current build pathSet content -->" ); + for ( String path : pathSet ) + { + context.getLog().debug( path ); + } + context.getLog().debug( "-- end of dump --" ); + + handleDeploymentDescriptors( context, webinfDir, metainfDir, context.isFailOnMissingWebXml() ); + + handleClassesDirectory( context ); + + handleArtifacts( context ); + + if ( !context.getWebappDirectory().mkdirs() ) + { + context.deleteOutdatedResources(); + } + } + + /** + * Handles the web resources. + * + * @param context the packaging context + * @throws MojoExecutionException if a resource could not be copied + */ + protected void handleWebResources( WarPackagingContext context ) + throws MojoExecutionException + { + for ( Resource resource : webResources ) + { + + // MWAR-246 + if ( resource.getDirectory() == null ) + { + throw new MojoExecutionException( "The tag is missing from the tag." ); + } + + if ( !( new File( resource.getDirectory() ) ).isAbsolute() ) + { + resource.setDirectory( context.getProject().getBasedir() + File.separator + resource.getDirectory() ); + } + + // Make sure that the resource directory is not the same as the webappDirectory + if ( !resource.getDirectory().equals( context.getWebappDirectory().getPath() ) ) + { + + try + { + copyResources( context, resource ); + } + catch ( IOException e ) + { + throw new MojoExecutionException( "Could not copy resource [" + resource.getDirectory() + "]", e ); + } + } + } + } + + /** + * Handles the webapp sources. + * + * @param context the packaging context + * @throws MojoExecutionException if the sources could not be copied + */ + protected void handleWebAppSourceDirectory( WarPackagingContext context ) + throws MojoExecutionException + { + // CHECKSTYLE_OFF: LineLength + if ( !context.getWebappSourceDirectory().exists() ) + { + context.getLog().debug( "webapp sources directory does not exist - skipping." ); + } + else if ( !context.getWebappSourceDirectory().getAbsolutePath().equals( context.getWebappDirectory().getPath() ) ) + { + context.getLog().info( "Copying webapp resources [" + context.getWebappSourceDirectory() + "]" ); + final PathSet sources = + getFilesToIncludes( context.getWebappSourceDirectory(), context.getWebappSourceIncludes(), + context.getWebappSourceExcludes(), context.isWebappSourceIncludeEmptyDirectories() ); + + try + { + copyFiles( id, context, context.getWebappSourceDirectory(), sources, false ); + } + catch ( IOException e ) + { + throw new MojoExecutionException( "Could not copy webapp sources [" + + context.getWebappDirectory().getAbsolutePath() + "]", e ); + } + } + // CHECKSTYLE_ON: LineLength + } + + /** + * Handles the webapp artifacts. + * + * @param context the packaging context + * @throws MojoExecutionException if the artifacts could not be packaged + */ + protected void handleArtifacts( WarPackagingContext context ) + throws MojoExecutionException + { + ArtifactsPackagingTask task = + new ArtifactsPackagingTask( context.getProject().getArtifacts(), currentProjectOverlay ); + task.performPackaging( context ); + } + + /** + * Handles the webapp classes. + * + * @param context the packaging context + * @throws MojoExecutionException if the classes could not be packaged + */ + protected void handleClassesDirectory( WarPackagingContext context ) + throws MojoExecutionException + { + ClassesPackagingTask task = new ClassesPackagingTask( currentProjectOverlay ); + task.performPackaging( context ); + } + + /** + * Handles the deployment descriptors, if specified. Note that the behavior here is slightly different since the + * customized entry always win, even if an overlay has already packaged a web.xml previously. + * + * @param context the packaging context + * @param webinfDir the web-inf directory + * @param metainfDir the meta-inf directory + * @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, + Boolean failOnMissingWebXml ) + throws MojoFailureException, MojoExecutionException + { + try + { + if ( webXml != null && StringUtils.isNotEmpty( webXml.getName() ) ) + { + if ( !webXml.exists() + && ( failOnMissingWebXml == null || Boolean.TRUE.equals( failOnMissingWebXml ) ) ) + { + throw new MojoFailureException( "The specified web.xml file '" + webXml + "' does not exist" ); + } + + // Making sure that it won't get overlayed + context.getWebappStructure().registerFileForced( id, WEB_INF_PATH + "/web.xml" ); + + if ( context.isFilteringDeploymentDescriptors() ) + { + context.getMavenFileFilter().copyFile( webXml, new File( webinfDir, "web.xml" ), true, + context.getFilterWrappers(), getEncoding( webXml ) ); + } + else + { + copyFile( context, webXml, new File( webinfDir, "web.xml" ), "WEB-INF/web.xml", true ); + } + } + else + { + // the webXml can be the default one + File defaultWebXml = new File( context.getWebappSourceDirectory(), WEB_INF_PATH + "/web.xml" ); + // if exists we can filter it + if ( defaultWebXml.exists() && context.isFilteringDeploymentDescriptors() ) + { + context.getWebappStructure().registerFile( id, WEB_INF_PATH + "/web.xml" ); + context.getMavenFileFilter().copyFile( defaultWebXml, new File( webinfDir, "web.xml" ), true, + context.getFilterWrappers(), getEncoding( defaultWebXml ) ); + } + } + + if ( containerConfigXML != null && StringUtils.isNotEmpty( containerConfigXML.getName() ) ) + { + String xmlFileName = containerConfigXML.getName(); + + context.getWebappStructure().registerFileForced( id, META_INF_PATH + "/" + xmlFileName ); + + if ( context.isFilteringDeploymentDescriptors() ) + { + context.getMavenFileFilter().copyFile( containerConfigXML, new File( metainfDir, xmlFileName ), + true, context.getFilterWrappers(), + getEncoding( containerConfigXML ) ); + } + else + { + copyFile( context, containerConfigXML, new File( metainfDir, xmlFileName ), "META-INF/" + + xmlFileName, true ); + } + } + } + catch ( IOException e ) + { + if ( failOnMissingWebXml == null || Boolean.TRUE.equals( failOnMissingWebXml ) ) + { + throw new MojoExecutionException( "Failed to copy deployment descriptor", e ); + } + } + catch ( MavenFilteringException e ) + { + throw new MojoExecutionException( "Failed to copy deployment descriptor", e ); + } + } + + /** + * Copies webapp webResources from the specified directory. + * + * @param context the WAR packaging context to use + * @param resource the resource to copy + * @throws IOException if an error occurred while copying the resources + * @throws MojoExecutionException if an error occurred while retrieving the filter properties + */ + public void copyResources( WarPackagingContext context, Resource resource ) + throws IOException, MojoExecutionException + { + if ( !context.getWebappDirectory().exists() ) + { + context.getLog().warn( "Not copying webapp webResources [" + resource.getDirectory() + + "]: webapp directory [" + context.getWebappDirectory().getAbsolutePath() + + "] does not exist!" ); + } + + context.getLog().info( "Copying webapp webResources [" + resource.getDirectory() + "] to [" + + context.getWebappDirectory().getAbsolutePath() + "]" ); + String[] fileNames = getFilesToCopy( resource ); + for ( String fileName : fileNames ) + { + String targetFileName = fileName; + if ( resource.getTargetPath() != null ) + { + // TODO make sure this thing is 100% safe + // MWAR-129 if targetPath is only a dot . or ./ + // and the Resource is in a part of the warSourceDirectory the file from sources will override this + // that's we don't have to add the targetPath yep not nice but works + if ( !Objects.equals( ".", resource.getTargetPath() ) + && !Objects.equals( "./", resource.getTargetPath() ) ) + { + targetFileName = resource.getTargetPath() + File.separator + targetFileName; + } + } + if ( resource.isFiltering() && !context.isNonFilteredExtension( fileName ) ) + { + copyFilteredFile( id, context, new File( resource.getDirectory(), fileName ), targetFileName ); + } + else + { + copyFile( id, context, new File( resource.getDirectory(), fileName ), targetFileName ); + } + } + } + + /** + * Returns a list of filenames that should be copied over to the destination directory. + * + * @param resource the resource to be scanned + * @return the array of filenames, relative to the sourceDir + */ + private String[] getFilesToCopy( Resource resource ) + { + // CHECKSTYLE_OFF: LineLength + DirectoryScanner scanner = new DirectoryScanner(); + scanner.setBasedir( resource.getDirectory() ); + if ( resource.getIncludes() != null && !resource.getIncludes().isEmpty() ) + { + scanner.setIncludes( resource.getIncludes().toArray( new String[resource.getIncludes().size()] ) ); + } + else + { + scanner.setIncludes( DEFAULT_INCLUDES ); + } + if ( resource.getExcludes() != null && !resource.getExcludes().isEmpty() ) + { + scanner.setExcludes( resource.getExcludes().toArray( new String[resource.getExcludes().size()] ) ); + } + + scanner.addDefaultExcludes(); + + scanner.scan(); + + return scanner.getIncludedFiles(); + // CHECKSTYLE_ON: LineLength + } +} diff --git a/Java-base/maven-war-plugin/src/src/main/java/org/apache/maven/plugins/war/util/ClassesPackager.java b/Java-base/maven-war-plugin/src/src/main/java/org/apache/maven/plugins/war/util/ClassesPackager.java new file mode 100644 index 000000000..2b14617cf --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/main/java/org/apache/maven/plugins/war/util/ClassesPackager.java @@ -0,0 +1,88 @@ +package org.apache.maven.plugins.war.util; + +/* + * 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. + */ + +import org.apache.maven.archiver.MavenArchiveConfiguration; +import org.apache.maven.archiver.MavenArchiver; +import org.apache.maven.artifact.DependencyResolutionRequiredException; +import org.apache.maven.execution.MavenSession; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugins.war.packaging.AbstractWarPackagingTask; +import org.apache.maven.project.MavenProject; +import org.codehaus.plexus.archiver.ArchiverException; +import org.codehaus.plexus.archiver.jar.JarArchiver; +import org.codehaus.plexus.archiver.jar.ManifestException; + +import java.io.File; +import java.io.IOException; + +/** + * Packages the content of the classes directory. + * + * @author Stephane Nicoll + */ +public class ClassesPackager +{ + + /** + * Package the classes + * + * @param classesDirectory the classes directory + * @param targetFile the target file + * @param jarArchiver the jar archiver to use + * @param session the current session + * @param project the related project + * @param archiveConfiguration the archive configuration to use + * @param outputTimestamp the output timestamp for reproducibility + * @throws MojoExecutionException if an error occurred while creating the archive + */ + public void packageClasses( File classesDirectory, File targetFile, JarArchiver jarArchiver, MavenSession session, + MavenProject project, MavenArchiveConfiguration archiveConfiguration, + String outputTimestamp ) + throws MojoExecutionException + { + + try + { + final MavenArchiver archiver = new MavenArchiver(); + archiver.setArchiver( jarArchiver ); + archiver.setOutputFile( targetFile ); + archiver.setCreatedBy( "Maven WAR Plugin", "org.apache.maven.plugins", "maven-war-plugin" ); + archiver.configureReproducible( outputTimestamp ); + archiver.getArchiver().addDirectory( classesDirectory ); + archiver.createArchive( session, project, archiveConfiguration ); + } + catch ( ArchiverException | ManifestException | IOException | DependencyResolutionRequiredException e ) + { + throw new MojoExecutionException( "Could not create classes archive", e ); + } + } + + /** + * Returns the classes directory from the specified webapp directory. + * + * @param webappDirectory the webapp directory + * @return the classes directory of the specified webapp directory + */ + public File getClassesDirectory( File webappDirectory ) + { + return new File( webappDirectory, AbstractWarPackagingTask.CLASSES_PATH ); + } +} diff --git a/Java-base/maven-war-plugin/src/src/main/java/org/apache/maven/plugins/war/util/DependencyInfo.java b/Java-base/maven-war-plugin/src/src/main/java/org/apache/maven/plugins/war/util/DependencyInfo.java new file mode 100644 index 000000000..f38ab060a --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/main/java/org/apache/maven/plugins/war/util/DependencyInfo.java @@ -0,0 +1,103 @@ +package org.apache.maven.plugins.war.util; + +/* + * 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. + */ + +import java.util.Objects; + +import org.apache.maven.model.Dependency; + +/** + * Holds a dependency and packaging information. + * + * @author Stephane Nicoll + */ +public class DependencyInfo +{ + + private final Dependency dependency; + + private String targetFileName; + + /** + * Creates a new instance. + * + * @param dependency the dependency + */ + public DependencyInfo( Dependency dependency ) + { + this.dependency = dependency; + } + + /** + * Returns the dependency. + * + * @return the dependency + */ + public Dependency getDependency() + { + return dependency; + } + + /** + * Returns the target filename of the dependency. If no target file name is associated, returns null. + * + * @return the target file name or null + */ + public String getTargetFileName() + { + return targetFileName; + } + + /** + * Sets the target file name. + * + * @param targetFileName the target file name + */ + public void setTargetFileName( String targetFileName ) + { + this.targetFileName = targetFileName; + } + + @Override + public boolean equals( Object o ) + { + if ( this == o ) + { + return true; + } + if ( o == null || getClass() != o.getClass() ) + { + return false; + } + + DependencyInfo that = (DependencyInfo) o; + + return Objects.equals( dependency, that.dependency ); + } + + @Override + public int hashCode() + { + int result; + result = ( dependency != null ? dependency.hashCode() : 0 ); + result = 31 * result + ( targetFileName != null ? targetFileName.hashCode() : 0 ); + return result; + } +} diff --git a/Java-base/maven-war-plugin/src/src/main/java/org/apache/maven/plugins/war/util/PathSet.java b/Java-base/maven-war-plugin/src/src/main/java/org/apache/maven/plugins/war/util/PathSet.java new file mode 100644 index 000000000..23da7b377 --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/main/java/org/apache/maven/plugins/war/util/PathSet.java @@ -0,0 +1,264 @@ +package org.apache.maven.plugins.war.util; + +/* + * 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. + */ + +import org.codehaus.plexus.util.DirectoryScanner; + +import java.io.File; +import java.util.Collection; +import java.util.HashSet; +import java.util.Iterator; +import java.util.LinkedHashSet; +import java.util.Set; + +/** + * Set of file's paths. + * + * The class extends functionality of a "normal" set of strings by a process of the paths normalization. All paths are + * converted to unix form (slashes) and they don't start with starting /. + * + * @author Piotr Tabor + */ + +public class PathSet + implements Iterable +{ + private static final String SEPARATOR = "/"; + private static final char SEPARATOR_CHAR = SEPARATOR.charAt( 0 ); + /** + * Set of normalized paths + */ + private Set pathsSet = new LinkedHashSet<>(); + + static String normalizeSubPath( String path ) + { + if ( path.isEmpty() ) + { + return path; + } + String cleanPath = path.replaceAll( "[\\\\]+", SEPARATOR ) + .replaceAll( "[/]+" , SEPARATOR ); + cleanPath = cleanPath.charAt( 0 ) == SEPARATOR_CHAR ? cleanPath.substring( 1 ) : cleanPath; + if ( cleanPath.isEmpty() ) + { + return cleanPath; + } + if ( cleanPath.charAt( cleanPath.length() - 1 ) == SEPARATOR_CHAR ) + { + return cleanPath.substring( 0, cleanPath.length() - 1 ); + } + return cleanPath; + } + + /*-------------------- Business interface ------------------------------*/ + + /** + * Creates an empty paths set + */ + public PathSet() + { + /* Empty default constructor */ + } + + /** + * Creates paths set and normalizate and adds all 'paths'. The source 'paths' will not be changed + * + * @param paths to be added + */ + public PathSet( Collection paths ) + { + addAll( paths ); + } + + /** + * Creates paths set and normalizate and adds all 'paths'. The source 'paths' will not be changed + * + * @param paths to be added + */ + public PathSet( String[] paths ) + { + addAll( paths ); + } + + /** + * Normalizes and adds given path to the set. + * + * @param path to be added + */ + public void add( String path ) + { + pathsSet.add( normalizeSubPath( path ) ); + } + + /** + * Normalizes and adds given paths (collection of strings) to the set. The source collection will not be changed + * + * @param paths - collection of strings to be added + * @param prefix added to all given paths + */ + public void addAll( Collection paths, String prefix ) + { + for ( String val : paths ) + { + add( prefix + SEPARATOR + val ); + } + } + + /** + * Normalizes and adds given paths to the set. The source collection will not be changed + * + * @param paths to be added + * @param prefix added to all given paths + */ + public void addAll( String[] paths, String prefix ) + { + for ( String val : paths ) + { + add( prefix + SEPARATOR + val ); + } + } + + /** + * Adds given paths to the set. The source collection will not be changed + * + * @param paths to be added + * @param prefix added to all given paths + */ + public void addAll( PathSet paths, String prefix ) + { + for ( String path : paths ) + { + add( prefix + SEPARATOR + path ); + } + } + + /** + * Normalizes and adds given paths (collection of strings) to the set. The source collection will not be changed + * + * @param paths - collection of strings to be added + */ + public void addAll( Collection paths ) + { + addAll( paths, "" ); + } + + /** + * Normalizes and adds given paths to the set. The source collection will not be changed + * + * @param paths to be added + */ + public void addAll( String[] paths ) + { + addAll( paths, "" ); + } + + /** + * Adds given paths to the set. The source collection will not be changed + * + * @param paths to be added + */ + public void addAll( PathSet paths ) + { + addAll( paths, "" ); + } + + /** + * Checks if the set constains given path. The path is normalized before check. + * + * @param path we are looking for in the set. + * @return information if the set constains the path. + */ + public boolean contains( String path ) + { + return pathsSet.contains( normalizeSubPath( path ) ); + } + + /** + * Removes the specified path if it exists. + * + * @param path the path to remove + * @return true if the path was removed, false if it did not existed + */ + boolean remove( String path ) + { + return pathsSet.remove( normalizeSubPath( path ) ); + } + + /** + * Returns iterator of normalized paths (strings) + * + * @return iterator of normalized paths (strings) + */ + @Override + public Iterator iterator() + { + return pathsSet.iterator(); + } + + /** + * @return {@link #pathsSet} + */ + public Collection paths() + { + return pathsSet; + } + + /** + * Adds given prefix to all paths in the set. + * + * The prefix should be ended by '/'. The generated paths are normalized. + * + * @param prefix to be added to all items + */ + public void addPrefix( String prefix ) + { + final Set newSet = new HashSet<>(); + for ( String path : pathsSet ) + { + newSet.add( normalizeSubPath( prefix + path ) ); + } + pathsSet = newSet; + } + + /** + * Returns count of the paths in the set + * + * @return count of the paths in the set + */ + public int size() + { + return pathsSet.size(); + } + + /** + * Adds to the set all files in the given directory + * + * @param directory that will be searched for file's paths to add + * @param prefix to be added to all found files + */ + public void addAllFilesInDirectory( File directory, String prefix ) + { + DirectoryScanner scanner = new DirectoryScanner(); + scanner.setBasedir( directory ); + scanner.scan(); + addAll( scanner.getIncludedFiles(), prefix ); + } + +} diff --git a/Java-base/maven-war-plugin/src/src/main/java/org/apache/maven/plugins/war/util/WarUtils.java b/Java-base/maven-war-plugin/src/src/main/java/org/apache/maven/plugins/war/util/WarUtils.java new file mode 100644 index 000000000..19dbb7980 --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/main/java/org/apache/maven/plugins/war/util/WarUtils.java @@ -0,0 +1,105 @@ +package org.apache.maven.plugins.war.util; + +/* + * 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. + */ + +import java.util.Objects; + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.model.Dependency; +import org.apache.maven.project.MavenProject; + +/** + * @author Stephane Nicoll + */ +public class WarUtils +{ + + /** + * @param project {@link MavenProject} + * @param dependency {@link Dependency} + * @return {@link Artifact} + */ + public static Artifact getArtifact( MavenProject project, Dependency dependency ) + { + for ( Artifact artifact : project.getArtifacts() ) + { + if ( artifact.getGroupId().equals( dependency.getGroupId() ) + && artifact.getArtifactId().equals( dependency.getArtifactId() ) + && artifact.getType().equals( dependency.getType() ) ) + { + if ( artifact.getClassifier() == null && dependency.getClassifier() == null ) + { + return artifact; + } + else if ( dependency.getClassifier() != null + && dependency.getClassifier().equals( artifact.getClassifier() ) ) + { + return artifact; + } + } + } + return null; + } + + /** + * @param artifact {@link Artifact} + * @param dependency {@link Dependency} + * @return is related or not. + */ + public static boolean isRelated( Artifact artifact, Dependency dependency ) + { + if ( artifact == null || dependency == null ) + { + return false; + } + + if ( !Objects.equals( artifact.getGroupId(), dependency.getGroupId() ) ) + { + return false; + } + if ( !Objects.equals( artifact.getArtifactId(), dependency.getArtifactId() ) ) + { + return false; + } + if ( Objects.equals( artifact.getVersion(), dependency.getVersion() ) ) + { + return false; + } + if ( Objects.equals( artifact.getType(), dependency.getType() ) ) + { + return false; + } + if ( Objects.equals( artifact.getClassifier(), dependency.getClassifier() ) ) + { + return false; + } + if ( Objects.equals( artifact.getScope(), dependency.getScope() ) ) + { + return false; + } + if ( artifact.isOptional() != dependency.isOptional() ) + { + return false; + } + + return true; + } + +} diff --git a/Java-base/maven-war-plugin/src/src/main/java/org/apache/maven/plugins/war/util/WebappStructure.java b/Java-base/maven-war-plugin/src/src/main/java/org/apache/maven/plugins/war/util/WebappStructure.java new file mode 100644 index 000000000..9d116508a --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/main/java/org/apache/maven/plugins/war/util/WebappStructure.java @@ -0,0 +1,391 @@ +package org.apache.maven.plugins.war.util; + +/* + * 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. + */ + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.model.Dependency; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; + +/** + * Represents the structure of a web application composed of multiple overlays. Each overlay is registered within this + * structure with the set of files it holds. + * + * Note that this structure is persisted to disk at each invocation to store which owner holds which path (file). + * + * @author Stephane Nicoll + */ +public class WebappStructure +{ + + private Map registeredFiles; + + private List dependenciesInfo; + + private transient PathSet allFiles = new PathSet(); + + /** + * Creates a new empty instance. + * + * @param dependencies the dependencies of the project + */ + public WebappStructure( List dependencies ) + { + this.dependenciesInfo = createDependenciesInfoList( dependencies ); + this.registeredFiles = new HashMap<>(); + } + + /** + * Returns the list of {@link DependencyInfo} for the project. + * + * @return the dependencies information of the project + */ + public List getDependenciesInfo() + { + return dependenciesInfo; + } + + /** + * Returns the dependencies of the project. + * + * @return the dependencies of the project + */ + public List getDependencies() + { + final List result = new ArrayList<>(); + if ( dependenciesInfo == null ) + { + return result; + } + for ( DependencyInfo dependencyInfo : dependenciesInfo ) + { + result.add( dependencyInfo.getDependency() ); + } + return result; + } + + /** + * Specify if the specified path is registered or not. + * + * @param path the relative path from the webapp root directory + * @return true if the path is registered, false otherwise + */ + public boolean isRegistered( String path ) + { + return getFullStructure().contains( path ); + + } + + /** + * Registers the specified path for the specified owner. Returns true if the path is not already + * registered, false otherwise. + * + * @param id the owner of the path + * @param path the relative path from the webapp root directory + * @return true if the file was registered successfully + */ + public boolean registerFile( String id, String path ) + { + if ( !isRegistered( path ) ) + { + doRegister( id, path ); + return true; + } + else + { + return false; + } + } + + /** + * Forces the registration of the specified path for the specified owner. If the file is not registered yet, a + * simple registration is performed. If the file already exists, the owner changes to the specified one. + *

+ * Beware that the semantic of the return boolean is different than the one from + * {@link #registerFile(String, String)}; returns true if an owner replacement was made and false + * if the file was simply registered for the first time.

+ * + * @param id the owner of the path + * @param path the relative path from the webapp root directory + * @return false if the file did not exist, true if the owner was replaced + */ + public boolean registerFileForced( String id, String path ) + { + if ( !isRegistered( path ) ) + { + doRegister( id, path ); + return false; + } + else + { + // Force the switch to the new owner + getStructure( getOwner( path ) ).remove( path ); + getStructure( id ).add( path ); + return true; + } + + } + + /** + * Registers the specified path for the specified owner. Invokes the callback with the result of the + * registration. + * + * @param id the owner of the path + * @param path the relative path from the webapp root directory + * @param callback the callback to invoke with the result of the registration + * @throws IOException if the callback invocation throws an IOException + */ + public void registerFile( String id, String path, RegistrationCallback callback ) + throws IOException + { + + // If the file is already in the current structure, rejects it with the current owner + if ( isRegistered( path ) ) + { + callback.refused( id, path, getOwner( path ) ); + } + else + { + doRegister( id, path ); + // This is a new file + if ( getOwner( path ) == null ) + { + callback.registered( id, path ); + + } // The file already belonged to this owner + else if ( getOwner( path ).equals( id ) ) + { + callback.alreadyRegistered( id, path ); + } // The file belongs to another owner and it's known currently + else if ( getOwners().contains( getOwner( path ) ) ) + { + callback.superseded( id, path, getOwner( path ) ); + } // The file belongs to another owner and it's unknown + else + { + callback.supersededUnknownOwner( id, path, getOwner( path ) ); + } + } + } + + /** + * Returns the owner of the specified path. If the file is not registered, returns null + * + * @param path the relative path from the webapp root directory + * @return the owner or null. + */ + public String getOwner( String path ) + { + if ( !isRegistered( path ) ) + { + return null; + } + else + { + for ( final String owner : registeredFiles.keySet() ) + { + final PathSet structure = getStructure( owner ); + if ( structure.contains( path ) ) + { + return owner; + } + + } + throw new IllegalStateException( "Should not happen, path [" + path + + "] is flagged as being registered but was not found." ); + } + + } + + /** + * Returns the owners. + * + * @return the list of owners + */ + public Set getOwners() + { + return registeredFiles.keySet(); + } + + /** + * Returns all paths that have been registered so far. + * + * @return all registered path + */ + public PathSet getFullStructure() + { + return allFiles; + } + + /** + * Returns the list of registered files for the specified owner. + * + * @param id the owner + * @return the list of files registered for that owner + */ + public PathSet getStructure( String id ) + { + PathSet pathSet = registeredFiles.get( id ); + if ( pathSet == null ) + { + pathSet = new PathSet(); + registeredFiles.put( id, pathSet ); + } + return pathSet; + } + + + + /** + * Registers the target file name for the specified artifact. + * + * @param artifact the artifact + * @param targetFileName the target file name + */ + public void registerTargetFileName( Artifact artifact, String targetFileName ) + { + if ( dependenciesInfo != null ) + { + for ( DependencyInfo dependencyInfo : dependenciesInfo ) + { + if ( WarUtils.isRelated( artifact, dependencyInfo.getDependency() ) ) + { + dependencyInfo.setTargetFileName( targetFileName ); + } + } + } + } + + // Private helpers + + private void doRegister( String id, String path ) + { + getFullStructure().add( path ); + getStructure( id ).add( path ); + } + + private List createDependenciesInfoList( List dependencies ) + { + if ( dependencies == null ) + { + return Collections.emptyList(); + } + final List result = new ArrayList<>(); + for ( Dependency dependency : dependencies ) + { + result.add( new DependencyInfo( dependency ) ); + } + return result; + } + + private Object readResolve() + { + // the full structure should be resolved so let's rebuild it + this.allFiles = new PathSet(); + for ( PathSet pathSet : registeredFiles.values() ) + { + this.allFiles.addAll( pathSet ); + } + return this; + } + + /** + * Callback interface to handle events related to filepath registration in the webapp. + */ + public interface RegistrationCallback + { + + /** + * Called if the targetFilename for the specified ownerId has been registered successfully. + * + * This means that the targetFilename was unknown and has been registered successfully. + * + * @param ownerId the ownerId + * @param targetFilename the relative path according to the root of the webapp + * @throws IOException if an error occurred while handling this event + */ + void registered( String ownerId, String targetFilename ) + throws IOException; + + /** + * Called if the targetFilename for the specified ownerId has already been registered. + * + * This means that the targetFilename was known and belongs to the specified owner. + * + * @param ownerId the ownerId + * @param targetFilename the relative path according to the root of the webapp + * @throws IOException if an error occurred while handling this event + */ + void alreadyRegistered( String ownerId, String targetFilename ) + throws IOException; + + /** + *

+ * Called if the registration of the targetFilename for the specified ownerId has been refused + * since the path already belongs to the actualOwnerId. + *

+ * This means that the targetFilename was known and does not belong to the specified owner. + * + * @param ownerId the ownerId + * @param targetFilename the relative path according to the root of the webapp + * @param actualOwnerId the actual owner + * @throws IOException if an error occurred while handling this event + */ + void refused( String ownerId, String targetFilename, String actualOwnerId ) + throws IOException; + + /** + * Called if the targetFilename for the specified ownerId has been registered successfully by + * superseding a deprecatedOwnerId, that is the previous owner of the file. + * + * This means that the targetFilename was known but for another owner. This usually happens after a + * project's configuration change. As a result, the file has been registered successfully to the new owner. + * + * @param ownerId the ownerId + * @param targetFilename the relative path according to the root of the webapp + * @param deprecatedOwnerId the previous owner that does not exist anymore + * @throws IOException if an error occurred while handling this event + */ + void superseded( String ownerId, String targetFilename, String deprecatedOwnerId ) + throws IOException; + + /** + * Called if the targetFilename for the specified ownerId has been registered successfully by + * superseding a unknownOwnerId, that is an owner that does not exist anymore in the current project. + * + * This means that the targetFilename was known but for an owner that does not exist anymore. Hence the + * file has been registered successfully to the new owner. + * + * @param ownerId the ownerId + * @param targetFilename the relative path according to the root of the webapp + * @param unknownOwnerId the previous owner that does not exist anymore + * @throws IOException if an error occurred while handling this event + */ + void supersededUnknownOwner( String ownerId, String targetFilename, String unknownOwnerId ) + throws IOException; + } + +} diff --git a/Java-base/maven-war-plugin/src/src/main/resources-filtered/META-INF/plexus/components.xml b/Java-base/maven-war-plugin/src/src/main/resources-filtered/META-INF/plexus/components.xml new file mode 100644 index 000000000..85adcb528 --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/main/resources-filtered/META-INF/plexus/components.xml @@ -0,0 +1,89 @@ + + + + + + + + + org.apache.maven.artifact.handler.ArtifactHandler + war + org.apache.maven.artifact.handler.DefaultArtifactHandler + + war + true + java + false + + + + + + + org.apache.maven.lifecycle.mapping.LifecycleMapping + war + org.apache.maven.lifecycle.mapping.DefaultLifecycleMapping + + + + default + + + + org.apache.maven.plugins:maven-resources-plugin:3.0.2:resources + + + org.apache.maven.plugins:maven-compiler-plugin:3.7.0:compile + + + org.apache.maven.plugins:maven-resources-plugin:3.0.2:testResources + + + org.apache.maven.plugins:maven-compiler-plugin:3.7.0:testCompile + + + org.apache.maven.plugins:maven-surefire-plugin:2.19.1:test + + + org.apache.maven.plugins:maven-war-plugin:${project.version}:war + + + org.apache.maven.plugins:maven-install-plugin:2.5.2:install + + + org.apache.maven.plugins:maven-deploy-plugin:2.8.2:deploy + + + + + + + + + + diff --git a/Java-base/maven-war-plugin/src/src/site/apt/examples/adding-filtering-webresources.apt.vm b/Java-base/maven-war-plugin/src/src/site/apt/examples/adding-filtering-webresources.apt.vm new file mode 100644 index 000000000..56f97baeb --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/site/apt/examples/adding-filtering-webresources.apt.vm @@ -0,0 +1,407 @@ + ------ + Adding and Filtering External Web Resources + ------ + Pete Marvin King + Dennis Lundberg + ------ + 2012-09-28 + ------ + +~~ 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. + +~~ NOTE: For help with the syntax of this file, see: +~~ http://maven.apache.org/doxia/references/apt-format.html + +Adding and Filtering External Web Resources + + The default resource directory for all Maven projects is <<>> which + will end up in <<>> and in <<>> in the WAR. The directory + structure will be preserved in the process. + + The WAR Plugin is also capable of including resources not found in the default resource + directory through the <<>> parameter. + +*Adding web resources + ++-------+ + + ... + + + + org.apache.maven.plugins + maven-war-plugin + ${project.version} + + + + + resource2 + + + + + + + ... + ++-------+ + + Using our sample project in the {{{../usage.html}usage section}} with an added external resource, like this: + +---------- + . + |-- pom.xml + |-- resource2 + | |-- external-resource.jpg + | `-- image2 + | `-- external-resource2.jpg + `-- src + `-- main + |-- java + | `-- com + | `-- example + | `-- projects + | `-- SampleAction.java + |-- resources + | `-- images + | `-- sampleimage.jpg + `-- webapp + |-- WEB-INF + | `-- web.xml + |-- index.jsp + `-- jsp + `-- websource.jsp +---------- + + would end up in the WAR as: + +---------- +documentedproject-1.0-SNAPSHOT.war + |-- META-INF + | |-- MANIFEST.MF + | `-- maven + | `-- com.example.projects + | `-- documentedproject + | |-- pom.properties + | `-- pom.xml + |-- WEB-INF + | |-- classes + | | |-- com + | | | `-- example + | | | `-- projects + | | | `-- SampleAction.class + | | `-- images + | | `-- sampleimage.jpg + | `-- web.xml + |-- external-resource.jpg + |-- image2 + | `-- external-resource2.jpg + |-- index.jsp + `-- jsp + `-- websource.jsp +---------- + + <<>> and <<>> are copied to the root of the WAR, preserving the + directory structure. + +*Configuring web Resources + + <<>> is a list of resources. All options of resource are supported. + + A web resource + + * can have includes/excludes + + * can be filtered + + * is not limited to the default destination - the root of the WAR + +**Includes/Excludes + + To include all jpgs in the WAR we can add the following to our POM configuration from above: + ++----------+ + ... + + + + + resource2 + + + **/*.jpg + + + + + ... ++----------+ + + To exclude the <<>> directory from the WAR add this: + ++----------+ + ... + + + + + resource2 + + + **/image2 + + + + + ... ++----------+ + + Be careful when mixing includes and excludes, excludes will have a higher priority. + Includes can not override excludes if a resource matches both. + + Having this configuration will exclude all jpgs from the WAR: + ++----------+ + ... + + + + + resource2/ + + + image2/*.jpg + + + + **/*.jpg + + + + + ... ++----------+ + + Here's another example of how to specify include and exclude patterns: + ++----------+ + ... + + + + + resource2 + + + **/pattern1 + *pattern2 + + + + *pattern3/pattern3 + pattern4/pattern4 + + + + + ... ++----------+ + +**Filtering + + Using our example above, we can also configure filters for our resources. + We will add a hypothetical <<>> directory to our project: + +---------- + . + |-- configurations + | |-- config.cfg + | `-- properties + | `-- config.prop + |-- pom.xml + |-- resource2 + | |-- external-resource.jpg + | `-- image2 + | `-- external-resource2.jpg + `-- src + `-- main + |-- java + | `-- com + | `-- example + | `-- projects + | `-- SampleAction.java + |-- resources + | `-- images + | `-- sampleimage.jpg + `-- webapp + |-- WEB-INF + | `-- web.xml + |-- index.jsp + `-- jsp + `-- websource.jsp +---------- + + To prevent corrupting your binary files when filtering is enabled, you can configure a list of file extensions that + will not be filtered. + ++----------+ + ... + + + + + properties/config.prop + + + + pdf + + + + resource2 + + false + + + configurations + + true + + **/properties + + + + + ... ++----------+ + +*** <<>> + ++----------+ +interpolated_property=some_config_value ++----------+ + +*** <<>> + ++----------+ + + ${interpolated_property} + ++----------+ + + The resulting WAR would be: + +---------- +documentedproject-1.0-SNAPSHOT.war + |-- META-INF + | |-- MANIFEST.MF + | `-- maven + | `-- com.example.projects + | `-- documentedproject + | |-- pom.properties + | `-- pom.xml + |-- WEB-INF + | |-- classes + | | |-- com + | | | `-- example + | | | `-- projects + | | | `-- SampleAction.class + | | `-- images + | | `-- sampleimage.jpg + | `-- web.xml + |-- config.cfg + |-- external-resource.jpg + |-- image2 + | `-- external-resource2.jpg + |-- index.jsp + `-- jsp + `-- websource.jsp +---------- + + and the content of <<>> would be: + ++----------+ + + some_config_value + ++----------+ + + <> In versions 2.2 and earlier of this plugin the platform encoding was + used when filtering resources. Depending on what that encoding was you could + end up with scrambled characters after filtering. Starting with version 2.3 + this plugin respects the property <<>> when + filtering resources. One notable exception to this is that <<<.xml>>> files + are filtered using the encoding specified inside the xml-file itself. + + +**Overriding the default destination directory + + By default web resources are copied to the root of the WAR, as shown in the previous example. + To override the default destination directory, specify the target path. + ++----------+ + ... + + + + ... + + + configurations + + WEB-INF + + true + + **/properties + + + + + ... ++----------+ + + Using the sample project the resulting WAR would look like this: + +---------- +documentedproject-1.0-SNAPSHOT.war + |-- META-INF + | |-- MANIFEST.MF + | `-- maven + | `-- com.example.projects + | `-- documentedproject + | |-- pom.properties + | `-- pom.xml + |-- WEB-INF + | |-- classes + | | |-- com + | | | `-- example + | | | `-- projects + | | | `-- SampleAction.class + | | `-- images + | | `-- sampleimage.jpg + | |-- config.cfg + | `-- web.xml + |-- external-resource.jpg + |-- image2 + | `-- external-resource2.jpg + |-- index.jsp + `-- jsp + `-- websource.jsp +---------- diff --git a/Java-base/maven-war-plugin/src/src/site/apt/examples/file-name-mapping.apt b/Java-base/maven-war-plugin/src/src/site/apt/examples/file-name-mapping.apt new file mode 100644 index 000000000..0e96b41b2 --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/site/apt/examples/file-name-mapping.apt @@ -0,0 +1,60 @@ + ------ + Using File Name Mapping + ------ + Stephane Nicoll + Dennis Lundberg + ------ + 2010-05-24 + +~~ 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. + +~~ NOTE: For help with the syntax of this file, see: +~~ http://maven.apache.org/doxia/references/apt-format.html + +Using File Name Mapping + + It might be necessary to customize the file name of libraries and TLDs. By default, those resources are stored + using the following pattern: + ++----- +@{artifactId}@-@{version}@.@{extension}@ ++----- + + If the artifact has a classifier the default pattern is of course: + ++----- +@{artifactId}@-@{version}@-@{classifier}@.@{extension}@ ++----- + + The <<>> parameter allows you to give a custom pattern. Each token defined in the + pattern will be replaced with a value from the current artifact. You can use any property of Artifact and + ArtifactHandler as a token. There is also a special token named <<>> that can be used, since 2.1. + It will add the string "-yourclassifier" if and only if the artifact has a classifier. + + For instance, to store the libraries and TLDs without version numbers or classifiers, use the following pattern: + ++----- +@{artifactId}@.@{extension}@ ++----- + + To store the libraries and TLDs without version numbers but with classifiers + (if they exist), use the following pattern: + ++----- +@{artifactId}@@{dashClassifier?}@.@{extension}@ ++----- diff --git a/Java-base/maven-war-plugin/src/src/site/apt/examples/including-excluding-files-from-war.apt.vm b/Java-base/maven-war-plugin/src/src/site/apt/examples/including-excluding-files-from-war.apt.vm new file mode 100644 index 000000000..74a4e71da --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/site/apt/examples/including-excluding-files-from-war.apt.vm @@ -0,0 +1,94 @@ + ------ + Including and Excluding Files From the WAR + ------ + Dennis Lundberg + ------ + 2011-11-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. + +~~ NOTE: For help with the syntax of this file, see: +~~ http://maven.apache.org/doxia/references/apt-format.html + +Including and Excluding Files From the WAR + + + It is possible to include or exclude certain files from the WAR file, by using + the <<<\>>> and <<<\>>> configuration + parameters. They each take a comma-separated list of Ant file set patterns. + You can use wildcards such as <<<**>>> to indicate multiple directories and + <<<*>>> to indicate an optional part of a file or directory name. + + Here is an example where we exclude all JAR files from <<>>: + ++-----------------+ + + ... + + + + maven-war-plugin + ${project.version} + + WEB-INF/lib/*.jar + + + + + ... + ++-----------------+ + + Sometimes even such wildcards are not enough. In these cases you can use + regular expressions with the <<<%regex[]>>> syntax. Here is a real life use + case in which this is used. In this example we want to exclude any + commons-logging and log4j JARs, but we do not want to exclude the + log4j-over-slf4j JAR. So we want to exclude <<.jar>>> but + keep the <<.jar>>>. + ++-----------------+ + + ... + + + + maven-war-plugin + ${project.version} + + + + WEB-INF/lib/commons-logging-*.jar, + %regex[WEB-INF/lib/log4j-(?!over-slf4j).*.jar] + + + + + + ... + ++-----------------+ + + If you have more real life examples of using regular expressions, we'd like to + know about them. Please file an issue in + {{{../issue-tracking.html}our issue tracker}} with your configuration, so we + can expand this page. diff --git a/Java-base/maven-war-plugin/src/src/site/apt/examples/rapid-testing-jetty6-plugin.apt b/Java-base/maven-war-plugin/src/src/site/apt/examples/rapid-testing-jetty6-plugin.apt new file mode 100644 index 000000000..a500a933b --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/site/apt/examples/rapid-testing-jetty6-plugin.apt @@ -0,0 +1,75 @@ + ------ + Rapid Testing Using the Jetty Plugin + ------ + Pete Marvin King + ------ + 2008-08-03 + ------ + +~~ 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. + +~~ NOTE: For help with the syntax of this file, see: +~~ http://maven.apache.org/doxia/references/apt-format.html + +Rapid Testing Using the Jetty Plugin + + Normally, testing a web application involves compiling Java sources, creating a WAR and + deploying it to a web container. + + Using the Jetty Plugin enables you to quickly test your web application by skipping + the last two steps. By default the Jetty Plugin scans <<>> for + any changes in your Java sources and <<>> for changes to your web sources. + The Jetty Plugin will automatically reload the modified classes and web sources. + + To use the Jetty Plugin just add the following in your <<>>: + ++-----------------+ + + ... + + + + org.mortbay.jetty + maven-jetty-plugin + 6.1.10 + + 10 + + + 8080 + 60000 + + + + + ... + + + ... + ++-----------------+ + + Then start Jetty: + +----------------- + mvn jetty:run +----------------- + + The command will block with Jetty listening on port 8080. + + Check the {{{http://docs.codehaus.org/display/JETTY/Maven+Jetty+Plugin}Jetty Plugin documentation}} for more details. diff --git a/Java-base/maven-war-plugin/src/src/site/apt/examples/skinny-wars.apt.vm b/Java-base/maven-war-plugin/src/src/site/apt/examples/skinny-wars.apt.vm new file mode 100644 index 000000000..f530dbdde --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/site/apt/examples/skinny-wars.apt.vm @@ -0,0 +1,112 @@ + ------ + Creating Skinny WARs + ------ + Mike Perham + Karl-Heinz Marbaise + ------ + 2014-10-01 + ------ + +~~ 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. + +~~ NOTE: For help with the syntax of this file, see: +~~ http://maven.apache.org/doxia/references/apt-format.html + +Creating Skinny WARs + + In a typical J2EE environment, a WAR is packaged within an EAR for deployment. The + WAR can contain all its dependent JARs in <<>> but then the EAR can quickly grow + very large if there are multiple WARs, due to the presence of duplicate JARs. Instead + the J2EE specification allows WARs to reference external JARs packaged within the EAR + via the <<>> setting in their <<>>. + + The Maven EAR Plugin has direct support for creating skinny wars which simply + means to {{{http://maven.apache.org/plugins/maven-ear-plugin/examples/skinny-wars.html}configure the maven-ear-plugin}} + accordingly. + + You need to change the EAR project's <<>> to package those dependent JARs in the EAR. + Notice that we package everything into a <<>> directory within the EAR. This is + just my own personal preference to distinguish between J2EE modules (which will + be packaged in the root of the EAR) and Java libraries (which are packaged in <<>>). + ++-----------------+ + + ... + + + + maven-ear-plugin + 2.9.1 + + lib/ + true + + + + + ... + ++-----------------+ + + Now the painful part. Your EAR project's <<>> needs to list every dependency that the WAR has. + This is because Maven assumes fat WARs and does not include transitive dependencies + of WARs within the EAR. + ++-----------------+ + + .... + + + com.acme + shared-jar + 1.0.0 + + + com.acme + war1 + 1.0.0 + war + + + com.acme + war2 + 1.0.0 + war + + + ... + ++-----------------+ + + Your EAR will contain something like this: + +----------------- + . + |-- META-INF + | `-- application.xml + |-- lib + | `-- shared-jar-1.0.0.jar + |-- war1-1.0.0.war + `-- war2-1.0.0.war +----------------- + + +* Alternatives + + Our users have submitted alternatives to the above recipe on + {{{http://docs.codehaus.org/display/MAVENUSER/Solving+the+Skinny+Wars+problem}the Wiki}}. diff --git a/Java-base/maven-war-plugin/src/src/site/apt/examples/war-manifest-guide.apt.vm b/Java-base/maven-war-plugin/src/src/site/apt/examples/war-manifest-guide.apt.vm new file mode 100644 index 000000000..a3aadb302 --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/site/apt/examples/war-manifest-guide.apt.vm @@ -0,0 +1,102 @@ + ------ + WAR Manifest Customization + ------ + Pete Marvin King + ------ + 2008-08-03 + ------ + +~~ 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. + +~~ NOTE: For help with the syntax of this file, see: +~~ http://maven.apache.org/doxia/references/apt-format.html + +WAR Manifest Customization + + The manifest can be customized by configuring the WAR Plugin's archiver. For full information on the different + configuration options available check the documentation for + {{{http://maven.apache.org/shared/maven-archiver/index.html}Maven Archiver}}. + + +*Generating a manifest classpath + + Generating a manifest classpath for a WAR is similar to for a JAR, but there are a couple of slight differences since + you normally don't want a JAR in both the manifest classpath and the <<>> directory. Customize the WAR + Plugin's archiver: + ++--------------------+ + + ... + + + + org.apache.maven.plugins + maven-war-plugin + ${project.version} + + + + true + + + + + ... + + + ... + ++--------------------+ + + Now, you can control which dependencies are included in <<>> and in the manifest classpath by following + these examples. Maven will follow the transitive dependency tree until it gets to artifacts scoped as "provided". + + <> No way is shown how to include a dependency in <<>> but not in the manifest classpath. + ++--------------------+ + + ... + + + org.foo + bar-jar1 + ${pom.version} + true + + + + org.foo + bar-jar2 + ${pom.version} + + + + org.foo + bar-jar3 + ${pom.version} + provided + + + ... + + ... + ++--------------------+ + + Check the {{{http://maven.apache.org/guides/mini/guide-manifest.html}Guide to Working with Manifests}} for more + examples. diff --git a/Java-base/maven-war-plugin/src/src/site/apt/index.apt.vm b/Java-base/maven-war-plugin/src/src/site/apt/index.apt.vm new file mode 100644 index 000000000..edcc5c5c5 --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/site/apt/index.apt.vm @@ -0,0 +1,98 @@ + ------ + Introduction + ------ + Pete Marvin King + ------ + 2013-07-22 + ------ + +~~ 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. + +~~ NOTE: For help with the syntax of this file, see: +~~ http://maven.apache.org/doxia/references/apt-format.html + +${project.name} + + The WAR Plugin is responsible for collecting all artifact dependencies, classes + and resources of the web application and packaging them into a web application + archive. + +* Goals Overview + + * {{{./war-mojo.html}war:war}} is the default goal invoked during the + <<>> phase for projects with a packaging type of <<>>. + It builds a WAR file. + + * {{{./exploded-mojo.html}war:exploded}} is generally used to speed up + testing during the developement phase by creating an exploded webapp + in a specified directory. + + * {{{./inplace-mojo.html}war:inplace}} another variation of <<>> + where the webapp is instead generated in the web application source directory, + which is <<>> by default. + + [] + +* Usage + + General instructions on how to use the WAR Plugin can be found on the + {{{./usage.html}usage page}}. Some more specific use cases are described in the + examples given below. To share common resources across multiple web applications, + see the documentation about using {{{./overlays.html}overlays}}. + + In case you still have questions regarding the plugin's usage, please have a look at the + {{{./faq.html}FAQ}} and feel free to contact the {{{./mailing-lists.html}user mailing list}}. + The posts to the mailing list are archived and could already contain the answer to your + question as part of an older thread. Hence, it is also worth browsing/searching + the {{{./mailing-lists.html}mail archive}}. + + If you feel like the plugin is missing a feature or has a defect, you can fill a + feature request or bug report in our {{{./issue-management.html}issue tracker}}. + When creating a new issue, please provide a comprehensive description of your + concern. Especially for fixing bugs it is crucial that the developers can + reproduce your problem. For this reason, entire debug logs, POMs or most + preferably little demo projects attached to the issue are very much appreciated. + Of course, patches are welcome, too. Contributors can check out the project from + our {{{./scm.html}source repository}} and will find supplementary + information in the + {{{/guides/development/guide-helping.html}guide to helping with Maven}}. + +* Examples + + To provide you with better understanding on some usages of the Maven WAR Plugin, + you can take a look into the following examples: + + * {{{./examples/adding-filtering-webresources.html}Adding and Filtering External Web Resources}} + + * {{{./examples/war-manifest-guide.html}WAR Manifest Customization}} + + * {{{./examples/rapid-testing-jetty6-plugin.html}Rapid Testing the Jetty Plugin}} + + * {{{./examples/skinny-wars.html}Creating Skinny WARs}} + + * {{{./examples/including-excluding-files-from-war.html}Including and Excluding Files From the WAR}} + + * {{{./examples/file-name-mapping.html}Using File Name Mapping}} + + [] + +* Related links + + * {{{/guides/mini/guide-archive-configuration.html}Exclusion of Maven Descriptors}} + + [] diff --git a/Java-base/maven-war-plugin/src/src/site/apt/overlays.apt.vm b/Java-base/maven-war-plugin/src/src/site/apt/overlays.apt.vm new file mode 100644 index 000000000..741a80e59 --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/site/apt/overlays.apt.vm @@ -0,0 +1,393 @@ + ------ + Overlays + ------ + Pete Marvin King + Stephane Nicoll + Dennis Lundberg + ------ + 2010-08-14 + +~~ 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. + +~~ NOTE: For help with the syntax of this file, see: +~~ http://maven.apache.org/doxia/references/apt-format.html + +Overlays + + Overlays are used to share common resources across multiple web applications. + The dependencies of a WAR project are collected in <<>>, except for WAR + artifacts which are overlayed on the WAR project itself. + + +* Overlays at a glance + + To demonstrate, given this structure for the project <<>>: + +----------------- + |-- pom.xml + `-- src + `-- main + |-- java + | `-- com + | `-- example + | `-- projects + | `-- SampleAction.java + |-- resources + | |-- images + | | `-- sampleimage.jpg + | `-- sampleresource + `-- webapp + |-- WEB-INF + | `-- web.xml + |-- index.jsp + `-- jsp + `-- websource.jsp +----------------- + + The project depends on another WAR artifact, <<>>, + which is declared as a dependency in the project's <<>>: + ++-----------------+ + + ... + + + com.example.projects + documentedprojectdependency + 1.0-SNAPSHOT + war + runtime + + ... + + ... + ++-----------------+ + + The structure for the <<>> WAR file looks like this: + +----------------- +documentedprojectdependency-1.0-SNAPSHOT.war + |-- META-INF + | |-- MANIFEST.MF + | `-- maven + | `-- com.example.projects + | `-- documentedprojectdependency + | |-- pom.properties + | `-- pom.xml + |-- WEB-INF + | |-- classes + | | |-- com + | | | `-- example + | | | `-- projects + | | | `-- SampleActionDependency.class + | | `-- images + | | `-- sampleimage-dependency.jpg + | `-- web.xml + `-- index-dependency.jsp +----------------- + + The resulting WAR would end up like this: + +----------------- + |-- META-INF + | |-- MANIFEST.MF + | `-- maven + | `-- com.example.projects + | `-- documentedproject + | |-- pom.properties + | `-- pom.xml + |-- WEB-INF + | |-- classes + | | |-- com + | | | `-- example + | | | `-- projects + | | | |-- SampleAction.class + | | | `-- SampleActionDependency.class + | | `-- images + | | |-- sampleimage-dependency.jpg + | | `-- sampleimage.jpg + | `-- web.xml + |-- index-dependency.jsp + |-- index.jsp + `-- jsp + `-- websource.jsp +----------------- + + The <<>> file above comes from <<>>. + + +* Overlay types + + The WAR Plugin handles both <> and <> artifacts as overlays. However, for backward compatibility reasons, zip + overlays are handled only if they are defined explicitly in the plugin's configuration. + + +* Configuring Overlays + + In previous versions of the WAR Plugin, no configuration was necessary. This is still the + case if you are happy with the default settings. However, if you need more control, read on! + + The <<<\<{overlay}\>>>> element can have the following child elements: + + * <> - the id of the overlay. If none is provided, the WAR Plugin will + generate one. + + * <> - the groupId of the overlay artifact you want to configure. + + * <> - the artifactId of the overlay artifact you want to + configure. + + * <> - the type of the overlay artifact you want to + configure. Default value is: <<>>. + + * <> - the classifier of the overlay artifact you want to + configure if multiple artifacts matches the groupId/artifactId. + + * <> - the files to include. By default, all files are included. + + * <> - the files to exclude. By default, the <<>> file + is excluded. + + * <> - the target relative path in the webapp structure, which is only + available for overlays of type <<>>. By default, the content of the overlay is added in the root + structure of the webapp. + + * <> - set to <<>> to skip this overlay. Default value is: <<>>. + + * <> - whether to apply filtering to this overlay. Default value is <<>>. + + [] + + For instance, to exclude the <<>> of our + <<>> <<>> overlay above: + ++-----------------+ + + ... + + + + org.apache.maven.plugins + maven-war-plugin + ${project.version} + + + + com.example.projects + documentedprojectdependency + + WEB-INF/classes/images/sampleimage-dependency.jpg + + + + + + + + ... + ++-----------------+ + + +* Overlays packaging + + Overlays are applied with a first-win strategy (hence if a file has been copied by + one overlay, it won't be copied by another). Overlays are applied in the order in which + they are defined in the <<<\>>> configuration. If no configuration is provided, + the order in which the dependencies are defined in the POM is used (warning: this is not + deterministic, especially if you have overlays as transitive dependencies). In case of + a mixed situation (e.g. configured overlays and non-configured overlays), non-configured + overlays are applied after configured overlays. + + By default, the source of the project (a.k.a the current build) is added first (e.g. + before any overlay is applied). The current build is defined as a special overlay + with no <<>>, <<>>. If overlays need to be applied first, simply + configure the current build after those overlays. + + For instance, if <<>> from the <<>> group is a dependency + of the project and needs to be applied before the project's own source, do as follows: + + ++-----------------+ + + ... + + + + org.apache.maven.plugins + maven-war-plugin + ${project.version} + + + + com.example.projects + my-webapp + + + + + + + + + + ... + ++-----------------+ + + <> In the scenario above, any other WAR dependency will be applied after the current build + since they have not been configured in the <<<\>>> element. + + To perform an even more fine grained overwriting policy, overlays can be packaged multiple times + with different includes/excludes. For instance if the <<>> file of the + overlay <<>> <> be set in the webapp but other files can be controlled the + regular way, define two overlay configurations for <<>>: + ++-----------------+ + + ... + + + + org.apache.maven.plugins + maven-war-plugin + ${project.version} + + + + my-webapp-index.jsp + com.example.projects + my-webapp + + index.jsp + + + + + + + + + + my-webapp + com.example.projects + my-webapp + + + + + + + ... + ++-----------------+ + + +* Overlay global settings + + The following settings can be specified globally and modify the way all overlays are applied. + + * <> - sets the default includes to apply to all overlays. Any overlay that + has no specific <<>> element will inherit this setting by default. + ++-----------------+ + + ... + + + org.apache.maven.plugins + maven-war-plugin + ${project.version} + + **/IncludeME,**/images + + + + ... + ++-----------------+ + + * <> - sets the default excludes to apply to all overlays. Any overlay that + has no specific <<>> element will inherit this setting by default. + ++-----------------+ + + ... + + + org.apache.maven.plugins + maven-war-plugin + ${project.version} + + WEB-INF/web.xml,index.* + + + + ... + ++-----------------+ + + * <> - sets the directory where overlays will be temporarily extracted. + ++-----------------+ + + ... + + + org.apache.maven.plugins + maven-war-plugin + ${project.version} + + + /tmp/extract_here + + + + ... + ++-----------------+ + +* Zip dependencies with overlays + + To use a <> dependency as an overlay you have to configure it explicitly in the plugin's configuration. For + instance to inject the content of a zip overlay in the <<>> directory of the webapp, do as follows: + ++-----------------+ + + ... + + + org.apache.maven.plugins + maven-war-plugin + ${project.version} + + + + zipGroupId + zipArtifactId + zip + scripts + + + + + + ... + ++-----------------+ diff --git a/Java-base/maven-war-plugin/src/src/site/apt/usage.apt.vm b/Java-base/maven-war-plugin/src/src/site/apt/usage.apt.vm new file mode 100644 index 000000000..3e3b1cc0d --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/site/apt/usage.apt.vm @@ -0,0 +1,229 @@ + ------ + Usage + ------ + Pete Marvin King + ------ + 2010-08-15 + ------ + +~~ 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. + +~~ NOTE: For help with the syntax of this file, see: +~~ http://maven.apache.org/doxia/references/apt-format.html + +Usage + + There are 4 ways to use the WAR Plugin: + + * using the <<>> phase with the project package type as <<>> + + * invocation of the <<>> goal + + * invocation of the <<>> goal + + * invocation of the <<>> goal + + [] + + <> When using the <<>> goals it is assumed that the <<>> phase is already done. + The WAR Plugin is not responsible for compiling the java sources or copying the resources. + + To handle archiving this version of Maven WAR Plugin uses + {{{http://maven.apache.org/shared/maven-archiver/index.html}Maven Archiver}} ${mavenArchiverVersion}. + + To handle filtering this version of Maven WAR Plugin uses + {{{http://maven.apache.org/shared/maven-filtering/index.html}Maven Filtering}} ${mavenFilteringVersion}. + + +*Using the <<>> phase with the project package type as war / invocation of the <<>> goal + + This is the normal way of using the WAR Plugin. + To illustrate, here's the <<>> for our project: + ++----------+ + + ... + com.example.projects + documentedproject + war + 1.0-SNAPSHOT + Documented Project + http://example.com + ... + ++----------+ + + The project's structure looks like this: + +---------- + |-- pom.xml + `-- src + `-- main + |-- java + | `-- com + | `-- example + | `-- projects + | `-- SampleAction.java + |-- resources + | `-- images + | `-- sampleimage.jpg + `-- webapp + |-- WEB-INF + | `-- web.xml + |-- index.jsp + `-- jsp + `-- websource.jsp +---------- + + Invoking + +---------- +mvn package +---------- + + or + +---------- +mvn compile war:war +---------- + + will generate the WAR file <<>>. Here are the contents of that WAR file: + +---------- +documentedproject-1.0-SNAPSHOT.war + |-- META-INF + | |-- MANIFEST.MF + | `-- maven + | `-- com.example.projects + | `-- documentedproject + | |-- pom.properties + | `-- pom.xml + |-- WEB-INF + | |-- classes + | | |-- com + | | | `-- example + | | | `-- projects + | | | `-- SampleAction.class + | | `-- images + | | `-- sampleimage.jpg + | `-- web.xml + |-- index.jsp + `-- jsp + `-- websource.jsp +---------- + +*Invocation of <<>> goal + + To speed up testing during the developement phase, <<>> can be used to generate the WAR in exploded + form. + Use the same project as above and invoke: + +---------- +mvn compile war:exploded +---------- + + This will generate an exploded version of the WAR in <<>>. + The contents of that directory looks like this: + +---------- + documentedproject-1.0-SNAPSHOT + |-- META-INF + |-- WEB-INF + | |-- classes + | | |-- com + | | | `-- example + | | | `-- projects + | | | `-- SampleAction.class + | | `-- images + | | `-- sampleimage.jpg + | `-- web.xml + |-- index.jsp + `-- jsp + `-- websource.jsp +---------- + + The default directory for the exploded WAR is <<>>>. The <<>> is usually in the form + of <<<\-\>>>. + This default directory can be overridden by specifying the <<>> parameter. + ++-------+ + + ... + + + + org.apache.maven.plugins + maven-war-plugin + ${project.version} + + /sample/servlet/container/deploy/directory + + + + + ... + ++-------+ + +*Invocation of <<>> goal + + Another variation of <<>> is <<>>. With <<>> the exploded WAR is created + in the webapp source, which defaults to <<>>. + Use our sample project above, and invoke: + +---------- +mvn compile war:inplace +---------- + + This will result in: + +---------- + |-- pom.xml + |-- src + | `-- main + | |-- java + | | `-- com + | | `-- example + | | `-- projects + | | `-- SampleAction.java + | |-- resources + | | `-- images + | | `-- sampleimage.jpg + | `-- webapp + | |-- META-INF + | |-- WEB-INF + | | |-- classes + | | | |-- com + | | | | `-- example + | | | | `-- projects + | | | | `-- SampleAction.class + | | | `-- images + | | | `-- sampleimage.jpg + | | `-- web.xml + | |-- index.jsp + | `-- jsp + | `-- websource.jsp + `-- target + `-- classes + |-- com + | `-- example + | `-- projects + | `-- SampleAction.class + `-- images + `-- sampleimage.jpg +---------- diff --git a/Java-base/maven-war-plugin/src/src/site/fml/faq.fml.vm b/Java-base/maven-war-plugin/src/src/site/fml/faq.fml.vm new file mode 100644 index 000000000..19fc6f81c --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/site/fml/faq.fml.vm @@ -0,0 +1,141 @@ + + + + + + + + + How is filtering done in the WAR plugin? + +

To enable filtering of web.xml you must configure the WAR Plugin like this: + + maven-war-plugin + ${project.version} + + true + + +]]> +

+

Examples can be found here.

+
+
+ + How does the classifier of dependency artifacts affect my WAR project? + +

When used, the copy of the dependency artifact in your project will have the classifier appended to its + filename. This can be used to differentiate duplicate artifacts.

+
+
+ + How do I exclude transitive dependencies from my project? + +

Give it a "provided" scope.

+
+
+ + What's the difference between using dependentWarExclude and provided scope? + +

dependentWarExclude is used in overlays for excluding dependent + WAR files from the assembled webapp.

+
+
+ + How do I exclude files in my web resources? + +

Use the <webResources> / <exclude> parameter to identify the tokens to exclude.

+

For more information refer to Adding and Filtering + External Web Resources.

+
+
+ + How do I exclude files when doing overlays? + +

Use the dependentWarExcludes parameter to identify the tokens to exclude.

+
+
+ + Where can I find the documentation for the plugin's configuration? + +

+ For each goal, you can use the documentation from the plugin site. +

+

+ If you need a specific version, generate it using mvn site:site or use: + +]]> +

+
+
+ + How do I create a JAR containing the classes in my webapp? + +

If you would simply like to package the classes and resources as a JAR in WEB-INF/lib + rather than as loose files under WEB-INF/classes, use the following configuration:

+

+ + maven-war-plugin + ${project.version} + + true + + +]]> +

+

If you need to re-use this JAR in another project, the recommended approach is to move the classes to a + separate module that builds a JAR, and then declare a dependency on that JAR from your webapp as well as from + any other projects that need it.

+

If you can't move the classes to another project, you can deploy the classes and resources included in + your webapp as an "attached" artifact, with a classifier, by using the following configuration:

+

+ + ... + mywebapp + 1.0-SNAPSHOT + ... + + + + maven-war-plugin + ${project.version} + + true + + + + + ... + +]]> +

+

This will result in two artifacts being deployed: mywebapp-1.0-SNAPSHOT.war + and mywebapp-1.0-SNAPSHOT-classes.jar.

+
+
+
+
\ No newline at end of file diff --git a/Java-base/maven-war-plugin/src/src/site/resources/download.cgi b/Java-base/maven-war-plugin/src/src/site/resources/download.cgi new file mode 100644 index 000000000..1b178d2e6 --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/site/resources/download.cgi @@ -0,0 +1,22 @@ +#!/bin/sh +# +# 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. +# +# Just call the standard mirrors.cgi script. It will use download.html +# as the input template. +exec /www/www.apache.org/dyn/mirrors/mirrors.cgi $* \ No newline at end of file diff --git a/Java-base/maven-war-plugin/src/src/site/site.xml b/Java-base/maven-war-plugin/src/src/site/site.xml new file mode 100644 index 000000000..2f81f26ca --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/site/site.xml @@ -0,0 +1,48 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Java-base/maven-war-plugin/src/src/site/xdoc/download.xml.vm b/Java-base/maven-war-plugin/src/src/site/xdoc/download.xml.vm new file mode 100644 index 000000000..3f710359a --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/site/xdoc/download.xml.vm @@ -0,0 +1,126 @@ + + + + + + + Download ${project.name} Source + + +
+ +

${project.name} ${project.version} is distributed in source format. Use a source archive if you intend to build + ${project.name} yourself. Otherwise, simply use the ready-made binary artifacts from central repository.

+ +

You will be prompted for a mirror - if the file is not found on yours, please be patient, as it may take 24 + hours to reach all mirrors.

+ +

In order to guard against corrupted downloads/installations, it is highly recommended to + verify the signature + of the release bundles against the public KEYS used by the Apache Maven + developers.

+ +

${project.name} is distributed under the Apache License, version 2.0.

+ +

We strongly encourage our users to configure a Maven repository mirror closer to their location, please read How to Use Mirrors for Repositories.

+ + + + +

+ [if-any logo] + + logo + + [end] + The currently selected mirror is + [preferred]. + If you encounter a problem with this mirror, + please select another mirror. + If all mirrors are failing, there are + backup + mirrors + (at the end of the mirrors list) that should be available. +

+ +
+ Other mirrors: + + +
+ +

+ You may also consult the + complete list of + mirrors. +

+ + + + + +

This is the current stable version of ${project.name}.

+ + + + + + + + + + + + + + + + + + +
LinkChecksumSignature
${project.name} ${project.version} (Source zip)maven/plugins/${project.artifactId}-${project.version}-source-release.zipmaven/plugins/${project.artifactId}-${project.version}-source-release.zip.sha512maven/plugins/${project.artifactId}-${project.version}-source-release.zip.asc
+
+ + + +

Older non-recommended releases can be found on our archive site.

+ +
+
+ +
+ diff --git a/Java-base/maven-war-plugin/src/src/test/java/org/apache/maven/plugins/war/AbstractWarExplodedMojoTest.java b/Java-base/maven-war-plugin/src/src/test/java/org/apache/maven/plugins/war/AbstractWarExplodedMojoTest.java new file mode 100644 index 000000000..d7c897aa0 --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/test/java/org/apache/maven/plugins/war/AbstractWarExplodedMojoTest.java @@ -0,0 +1,303 @@ +package org.apache.maven.plugins.war; + +/* + * 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. + */ + +import org.apache.maven.plugin.testing.stubs.ArtifactStub; +import org.apache.maven.plugins.war.stub.MavenProjectArtifactsStub; +import org.codehaus.plexus.util.FileUtils; + +import java.io.File; +import java.io.FileFilter; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.LinkedList; +import java.util.List; + +/** + * @author Stephane Nicoll + */ +public abstract class AbstractWarExplodedMojoTest + extends AbstractWarMojoTest +{ + + protected WarExplodedMojo mojo; + + public void setUp() + throws Exception + { + super.setUp(); + mojo = (WarExplodedMojo) lookupMojo( "exploded", getPomFile() ); + } + + /** + * Returns the pom configuration to use. + * + * @return the pom configuration + */ + protected abstract File getPomFile(); + + /** + * Returns the test directory to use. + * + * @return the test directory + */ + protected abstract File getTestDirectory(); + + /** + * Configures the exploded mojo for the specified test. + * + * If the sourceFiles parameter is null, sample JSPs are created by default. + * + * @param testId the id of the test + * @param artifactStubs the dependencies (may be null) + * @param sourceFiles the source files to create (may be null) + * @return the webapp directory + * @throws Exception if an error occurs while configuring the mojo + */ + protected File setUpMojo( final String testId, ArtifactStub[] artifactStubs, String[] sourceFiles ) + throws Exception + { + final MavenProjectArtifactsStub project = new MavenProjectArtifactsStub(); + final File webAppDirectory = new File( getTestDirectory(), testId ); + + // Create the webapp sources + File webAppSource; + if ( sourceFiles == null ) + { + webAppSource = createWebAppSource( testId ); + } + else + { + webAppSource = createWebAppSource( testId, false ); + for ( String sourceFile : sourceFiles ) + { + File sample = new File( webAppSource, sourceFile ); + createFile( sample ); + + } + + } + + final File classesDir = createClassesDir( testId, true ); + final File workDirectory = new File( getTestDirectory(), "/war/work-" + testId ); + createDir( workDirectory ); + + if ( artifactStubs != null ) + { + for ( ArtifactStub artifactStub : artifactStubs ) + { + project.addArtifact( artifactStub ); + } + } + + configureMojo( mojo, new LinkedList(), classesDir, webAppSource, webAppDirectory, project ); + setVariableValueToObject( mojo, "workDirectory", workDirectory ); + + return webAppDirectory; + } + + /** + * Configures the exploded mojo for the specified test. + * + * @param testId the id of the test + * @param artifactStubs the dependencies (may be null) + * @return the webapp directory + * @throws Exception if an error occurs while configuring the mojo + */ + protected File setUpMojo( final String testId, ArtifactStub[] artifactStubs ) + throws Exception + { + return setUpMojo( testId, artifactStubs, null ); + } + + /** + * Cleans up a directory. + * + * @param directory the directory to remove + * @throws IOException if an error occurred while removing the directory + */ + protected void cleanDirectory( File directory ) + throws IOException + { + if ( directory != null && directory.isDirectory() && directory.exists() ) + { + FileUtils.deleteDirectory( directory ); + } + } + + /** + * Asserts the default content of the war based on the specified webapp directory. + * + * @param webAppDirectory the webapp directory + * @return a list of File objects that have been asserted + */ + protected List assertDefaultContent( File webAppDirectory ) + { + // Validate content of the webapp + File expectedWebSourceFile = new File( webAppDirectory, "pansit.jsp" ); + File expectedWebSource2File = new File( webAppDirectory, "org/web/app/last-exile.jsp" ); + + assertTrue( "source file not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists() ); + assertTrue( "source file not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists() ); + + final List content = new ArrayList<>(); + content.add( expectedWebSourceFile ); + content.add( expectedWebSource2File ); + + return content; + } + + /** + * Asserts the web.xml file of the war based on the specified webapp directory. + * + * @param webAppDirectory the webapp directory + * @return a list with the web.xml File object + */ + protected List assertWebXml( File webAppDirectory ) + { + File expectedWEBXMLFile = new File( webAppDirectory, "WEB-INF/web.xml" ); + assertTrue( "web xml not found: " + expectedWEBXMLFile.toString(), expectedWEBXMLFile.exists() ); + + final List content = new ArrayList<>(); + content.add( expectedWEBXMLFile ); + + return content; + } + + /** + * Asserts custom content of the war based on the specified webapp directory. + * + * @param webAppDirectory the webapp directory + * @param filePaths an array of file paths relative to the webapp directory + * @param customMessage a custom message if an assertion fails + * @return a list of File objects that have been inspected + */ + protected List assertCustomContent( File webAppDirectory, String[] filePaths, String customMessage ) + { + final List content = new ArrayList<>(); + for ( String filePath : filePaths ) + { + final File expectedFile = new File( webAppDirectory, filePath ); + if ( customMessage != null ) + { + assertTrue( customMessage + " - " + expectedFile.toString(), expectedFile.exists() ); + } + else + { + assertTrue( "source file not found: " + expectedFile.toString(), expectedFile.exists() ); + } + content.add( expectedFile ); + } + return content; + } + + /** + * Asserts that the webapp contains only the specified files. + * + * @param webAppDirectory the webapp directory + * @param expectedFiles the expected files + * @param filter an optional filter to ignore some resources + */ + protected void assertWebAppContent( File webAppDirectory, List expectedFiles, FileFilter filter ) + { + final List webAppContent = new ArrayList<>(); + if ( filter != null ) + { + buildFilesList( webAppDirectory, filter, webAppContent ); + } + else + { + buildFilesList( webAppDirectory, new FileFilterImpl( webAppDirectory, null ), webAppContent ); + } + + // Now we have the files, sort them. + Collections.sort( expectedFiles ); + Collections.sort( webAppContent ); + assertEquals( "Invalid webapp content, expected " + expectedFiles.size() + "file(s) " + expectedFiles + + " but got " + webAppContent.size() + " file(s) " + webAppContent, expectedFiles, webAppContent ); + } + + /** + * Builds the list of files and directories from the specified dir. + * + * Note that the filter is not used the usual way. If the filter does not accept the current file, it's not added + * but yet the subdirectories are added if any. + * + * @param dir the base directory + * @param filter the filter + * @param content the current content, updated recursively + */ + private void buildFilesList( final File dir, FileFilter filter, final List content ) + { + final File[] files = dir.listFiles(); + + for ( File file : files ) + { + // Add the file if the filter is ok with it + if ( filter.accept( file ) ) + { + content.add( file ); + } + + // Even if the file is not accepted and is a directory, add it + if ( file.isDirectory() ) + { + buildFilesList( file, filter, content ); + } + + } + } + + class FileFilterImpl + implements FileFilter + { + + private final List rejectedFilePaths; + + private final int webAppDirIndex; + + public FileFilterImpl( File webAppDirectory, String[] rejectedFilePaths ) + { + if ( rejectedFilePaths != null ) + { + this.rejectedFilePaths = Arrays.asList( rejectedFilePaths ); + } + else + { + this.rejectedFilePaths = new ArrayList<>(); + } + this.webAppDirIndex = webAppDirectory.getAbsolutePath().length() + 1; + } + + public boolean accept( File file ) + { + String effectiveRelativePath = buildRelativePath( file ); + return !( rejectedFilePaths.contains( effectiveRelativePath ) || file.isDirectory() ); + } + + private String buildRelativePath( File f ) + { + return f.getAbsolutePath().substring( webAppDirIndex ); + } + } + +} diff --git a/Java-base/maven-war-plugin/src/src/test/java/org/apache/maven/plugins/war/AbstractWarMojoTest.java b/Java-base/maven-war-plugin/src/src/test/java/org/apache/maven/plugins/war/AbstractWarMojoTest.java new file mode 100644 index 000000000..87344ad26 --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/test/java/org/apache/maven/plugins/war/AbstractWarMojoTest.java @@ -0,0 +1,332 @@ +package org.apache.maven.plugins.war; + +/* + * 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. + */ + +import java.io.File; +import java.io.IOException; +import java.util.List; + +import org.apache.maven.execution.DefaultMavenExecutionRequest; +import org.apache.maven.execution.MavenExecutionRequest; +import org.apache.maven.execution.MavenSession; +import org.apache.maven.plugin.testing.AbstractMojoTestCase; +import org.apache.maven.plugin.testing.stubs.ArtifactStub; +import org.apache.maven.plugins.war.AbstractWarMojo; +import org.apache.maven.plugins.war.stub.MavenProjectBasicStub; +import org.apache.maven.plugins.war.stub.WarOverlayStub; +import org.apache.maven.shared.filtering.MavenFileFilter; +import org.codehaus.plexus.PlexusContainer; +import org.codehaus.plexus.archiver.Archiver; +import org.codehaus.plexus.archiver.ArchiverException; +import org.codehaus.plexus.archiver.jar.JarArchiver; +import org.codehaus.plexus.util.FileUtils; +import org.sonatype.aether.RepositorySystemSession; + +public abstract class AbstractWarMojoTest + extends AbstractMojoTestCase +{ + + protected static final File OVERLAYS_TEMP_DIR = new File( getBasedir(), "target/test-overlays/" ); + + protected static final File OVERLAYS_ROOT_DIR = new File( getBasedir(), "target/test-classes/overlays/" ); + + protected static final String MANIFEST_PATH = "META-INF" + File.separator + "MANIFEST.MF"; + + protected abstract File getTestDirectory() + throws Exception; + + /** + * initialize required parameters + * + * @param mojo The mojo to be tested. + * @param filters The list of filters. + * @param classesDir The classes directory. + * @param webAppSource The webAppSource. + * @param webAppDir The webAppDir folder. + * @param project The Maven project. + * @throws Exception in case of errors + */ + protected void configureMojo( AbstractWarMojo mojo, List filters, File classesDir, File webAppSource, + File webAppDir, MavenProjectBasicStub project ) + throws Exception + { + setVariableValueToObject( mojo, "filters", filters ); + setVariableValueToObject( mojo, "mavenFileFilter", lookup( MavenFileFilter.class.getName() ) ); + setVariableValueToObject( mojo, "useJvmChmod", Boolean.TRUE ); + + MavenExecutionRequest request = new DefaultMavenExecutionRequest(); + request.setSystemProperties( System.getProperties() ); + + MavenSession mavenSession = + new MavenSession( (PlexusContainer) null, (RepositorySystemSession) null, request, null ); + setVariableValueToObject( mojo, "session", mavenSession ); + mojo.setClassesDirectory( classesDir ); + mojo.setWarSourceDirectory( webAppSource ); + mojo.setWebappDirectory( webAppDir ); + mojo.setProject( project ); + } + + /** + * create an isolated xml dir + * + * @param id The id. + * @param xmlFiles array of xml files. + * @return The created file. + * @throws Exception in case of errors. + */ + protected File createXMLConfigDir( String id, String[] xmlFiles ) + throws Exception + { + File xmlConfigDir = new File( getTestDirectory(), "/" + id + "-test-data/xml-config" ); + File XMLFile; + + createDir( xmlConfigDir ); + + if ( xmlFiles != null ) + { + for ( String o : xmlFiles ) + { + XMLFile = new File( xmlConfigDir, o ); + createFile( XMLFile ); + } + } + + return xmlConfigDir; + } + + /** + * Returns the webapp source directory for the specified id. + * + * @param id the id of the test + * @return the source directory for that test + * @throws Exception if an exception occurs + */ + protected File getWebAppSource( String id ) + throws Exception + { + return new File( getTestDirectory(), "/" + id + "-test-data/source" ); + } + + /** + * create an isolated web source with a sample jsp file + * + * @param id The id. + * @param createSamples Create example files yes or no. + * @return The created file. + * @throws Exception in case of errors. + */ + protected File createWebAppSource( String id, boolean createSamples ) + throws Exception + { + File webAppSource = getWebAppSource( id ); + if ( createSamples ) + { + File simpleJSP = new File( webAppSource, "pansit.jsp" ); + File jspFile = new File( webAppSource, "org/web/app/last-exile.jsp" ); + + createFile( simpleJSP ); + createFile( jspFile ); + } + return webAppSource; + } + + protected File createWebAppSource( String id ) + throws Exception + { + return createWebAppSource( id, true ); + } + + /** + * create a class directory with or without a sample class + * + * @param id The id. + * @param empty true to create a class files false otherwise. + * @return The created class file. + * @throws Exception in case of errors. + */ + protected File createClassesDir( String id, boolean empty ) + throws Exception + { + File classesDir = new File( getTestDirectory() + "/" + id + "-test-data/classes/" ); + + createDir( classesDir ); + + if ( !empty ) + { + createFile( new File( classesDir + "/sample-servlet.class" ) ); + } + + return classesDir; + } + + protected void createDir( File dir ) + { + if ( !dir.exists() ) + { + assertTrue( "can not create test dir: " + dir.toString(), dir.mkdirs() ); + } + } + + protected void createFile( File testFile, String body ) + throws Exception + { + createDir( testFile.getParentFile() ); + FileUtils.fileWrite( testFile.toString(), body ); + + assertTrue( "could not create file: " + testFile, testFile.exists() ); + } + + protected void createFile( File testFile ) + throws Exception + { + createFile( testFile, testFile.toString() ); + } + + /** + * Generates test war. + * Generates war with such a structure: + *
    + *
  • jsp + *
      + *
    • d + *
        + *
      • a.jsp
      • + *
      • b.jsp
      • + *
      • c.jsp
      • + *
      + *
    • + *
    • a.jsp
    • + *
    • b.jsp
    • + *
    • c.jsp
    • + *
    + *
  • + *
  • WEB-INF + *
      + *
    • classes + *
        + *
      • a.class
      • + *
      • b.class
      • + *
      • c.class
      • + *
      + *
    • + *
    • lib + *
        + *
      • a.jar
      • + *
      • b.jar
      • + *
      • c.jar
      • + *
      + *
    • + *
    • web.xml
    • + *
    + *
  • + *
+ * Each of the files will contain: id+'-'+path + * + * @param id the id of the overlay containing the full structure + * @return the war file + * @throws Exception if an error occurs + */ + protected File generateFullOverlayWar( String id ) + throws Exception + { + final File destFile = new File( OVERLAYS_TEMP_DIR, id + ".war" ); + if ( destFile.exists() ) + { + return destFile; + } + + // Archive was not yet created for that id so let's create it + final File rootDir = new File( OVERLAYS_ROOT_DIR, id ); + rootDir.mkdirs(); + String[] filePaths = new String[] { "jsp/d/a.jsp", "jsp/d/b.jsp", "jsp/d/c.jsp", "jsp/a.jsp", "jsp/b.jsp", + "jsp/c.jsp", "WEB-INF/classes/a.class", "WEB-INF/classes/b.class", "WEB-INF/classes/c.class", + "WEB-INF/lib/a.jar", "WEB-INF/lib/b.jar", "WEB-INF/lib/c.jar", "WEB-INF/web.xml" }; + + for ( String filePath : filePaths ) + { + createFile( new File( rootDir, filePath ), id + "-" + filePath ); + } + + createArchive( rootDir, destFile ); + return destFile; + } + + // Overlay utilities + + /** + * Builds a test overlay. + * + * @param id the id of the overlay (see test/resources/overlays) + * @return a test war artifact with the content of the given test overlay + */ + protected ArtifactStub buildWarOverlayStub( String id ) + { + // Create war file + final File destFile = new File( OVERLAYS_TEMP_DIR, id + ".war" ); + if ( !destFile.exists() ) + { + createArchive( new File( OVERLAYS_ROOT_DIR, id ), destFile ); + } + + return new WarOverlayStub( getBasedir(), id, destFile ); + } + + protected File getOverlayFile( String id, String filePath ) + { + final File overlayDir = new File( OVERLAYS_ROOT_DIR, id ); + final File file = new File( overlayDir, filePath ); + + // Make sure the file exists + assertTrue( "Overlay file " + filePath + " does not exist for overlay " + id + " at " + file.getAbsolutePath(), + file.exists() ); + return file; + + } + + protected void createArchive( final File directory, final File destinationFile ) + { + try + { + // WarArchiver archiver = new WarArchiver(); + + Archiver archiver = new JarArchiver(); + + archiver.setDestFile( destinationFile ); + archiver.addDirectory( directory ); + + // archiver.setWebxml( new File(directory, "WEB-INF/web.xml")); + + // create archive + archiver.createArchive(); + + } + catch ( ArchiverException e ) + { + e.printStackTrace(); + fail( "Failed to create overlay archive " + e.getMessage() ); + } + catch ( IOException e ) + { + e.printStackTrace(); + fail( "Unexpected exception " + e.getMessage() ); + } + } + +} \ No newline at end of file diff --git a/Java-base/maven-war-plugin/src/src/test/java/org/apache/maven/plugins/war/WarExplodedMojoFilteringTest.java b/Java-base/maven-war-plugin/src/src/test/java/org/apache/maven/plugins/war/WarExplodedMojoFilteringTest.java new file mode 100644 index 000000000..9997f4d68 --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/test/java/org/apache/maven/plugins/war/WarExplodedMojoFilteringTest.java @@ -0,0 +1,209 @@ +package org.apache.maven.plugins.war; + +/* + * 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. + */ + +import java.io.BufferedReader; +import java.io.File; +import java.io.StringReader; +import java.util.LinkedList; +import java.util.List; + +import org.apache.maven.plugins.war.stub.MavenProjectBasicStub; +import org.apache.maven.plugins.war.stub.ResourceStub; +import org.codehaus.plexus.util.FileUtils; + +/** + * @author Olivier Lamy + * @since 21 juil. 2008 + */ +public class WarExplodedMojoFilteringTest + extends AbstractWarExplodedMojoTest +{ + + protected File getPomFile() + { + return new File( getBasedir(), "/target/test-classes/unit/warexplodedmojo/plugin-config.xml" ); + } + + protected File getTestDirectory() + { + return new File( getBasedir(), "target/test-classes/unit/warexplodedmojo/test-dir" ); + } + + /** + * @throws Exception in case of an error. + */ + public void testExplodedWar_WithResourceFiltering() + throws Exception + { + // setup test data + String testId = "ExplodedWar_WithResourceFiltering"; + MavenProjectBasicStub project = new MavenProjectBasicStub(); + File webAppDirectory = new File( getTestDirectory(), testId ); + File webAppSource = createWebAppSource( testId ); + File classesDir = createClassesDir( testId, false ); + File webAppResource = new File( getTestDirectory(), testId + "-test-data/resources" ); + File sampleResource = new File( webAppResource, "custom-setting.cfg" ); + File sampleResourceWDir = new File( webAppResource, "custom-config/custom-setting.cfg" ); + List filterList = new LinkedList<>(); + ResourceStub[] resources = new ResourceStub[] { new ResourceStub() }; + + createFile( sampleResource ); + createFile( sampleResourceWDir ); + + String ls = System.getProperty( "line.separator" ); + final String comment = "# this is comment created by author@somewhere@"; + // prepare web resources + String content = comment + ls; + content += "system_key_1=${user.dir}" + ls; + content += "system_key_2=@user.dir@" + ls; + content += "project_key_1=${is_this_simple}" + ls; + content += "project_key_2=@is_this_simple@" + ls; + content += "project_name_1=${project.name}" + ls; + content += "project_name_2=@project.name@" + ls; + content += "system_property_1=${system.property}" + ls; + content += "system_property_2=@system.property@" + ls; + FileUtils.fileWrite( sampleResourceWDir.getAbsolutePath(), content ); + FileUtils.fileWrite( sampleResource.getAbsolutePath(), content ); + + System.setProperty( "system.property", "system-property-value" ); + + // configure mojo + project.addProperty( "is_this_simple", "i_think_so" ); + resources[0].setDirectory( webAppResource.getAbsolutePath() ); + resources[0].setFiltering( true ); + this.configureMojo( mojo, filterList, classesDir, webAppSource, webAppDirectory, project ); + setVariableValueToObject( mojo, "webResources", resources ); + mojo.execute(); + + // validate operation + File expectedWebSourceFile = new File( webAppDirectory, "pansit.jsp" ); + File expectedWebSource2File = new File( webAppDirectory, "org/web/app/last-exile.jsp" ); + File expectedResourceFile = new File( webAppDirectory, "custom-setting.cfg" ); + File expectedResourceWDirFile = new File( webAppDirectory, "custom-config/custom-setting.cfg" ); + + assertTrue( "source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists() ); + assertTrue( "source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists() ); + assertTrue( "resource file not found:" + expectedResourceFile.toString(), expectedResourceFile.exists() ); + assertTrue( "resource file with dir not found:" + expectedResourceWDirFile.toString(), + expectedResourceWDirFile.exists() ); + + // validate filtered file + content = FileUtils.fileRead( expectedResourceWDirFile ); + BufferedReader reader = new BufferedReader( new StringReader( content ) ); + + assertEquals( "error in filtering using System Properties", comment, reader.readLine() ); + + String line = reader.readLine(); + System.out.println( " line " + line ); + System.out.println( " need " + System.getProperty( "user.dir" ) ); + assertEquals( "error in filtering using System properties", "system_key_1=" + System.getProperty( "user.dir" ), + line ); + line = reader.readLine(); + System.out.println( " line " + line ); + assertEquals( "error in filtering using System properties", "system_key_2=" + System.getProperty( "user.dir" ), + line ); + + assertEquals( "error in filtering using project properties", "project_key_1=i_think_so", reader.readLine() ); + assertEquals( "error in filtering using project properties", "project_key_2=i_think_so", reader.readLine() ); + + assertEquals( "error in filtering using project properties", "project_name_1=Test Project ", reader.readLine() ); + assertEquals( "error in filtering using project properties", "project_name_2=Test Project ", reader.readLine() ); + + assertEquals( "error in filtering using System properties", "system_property_1=system-property-value", + reader.readLine() ); + assertEquals( "error in filtering using System properties", "system_property_2=system-property-value", + reader.readLine() ); + + // update property, and generate again + System.setProperty( "system.property", "new-system-property-value" ); + this.configureMojo( mojo, filterList, classesDir, webAppSource, webAppDirectory, project ); + + mojo.execute(); + + // validate filtered file + content = FileUtils.fileRead( expectedResourceWDirFile ); + reader = new BufferedReader( new StringReader( content ) ); + + assertEquals( "error in filtering using System Properties", comment, reader.readLine() ); + + assertEquals( "error in filtering using System properties", "system_key_1=" + System.getProperty( "user.dir" ), + reader.readLine() ); + assertEquals( "error in filtering using System properties", "system_key_2=" + System.getProperty( "user.dir" ), + reader.readLine() ); + + assertEquals( "error in filtering using project properties", "project_key_1=i_think_so", reader.readLine() ); + assertEquals( "error in filtering using project properties", "project_key_2=i_think_so", reader.readLine() ); + + assertEquals( "error in filtering using project properties", "project_name_1=Test Project ", reader.readLine() ); + assertEquals( "error in filtering using project properties", "project_name_2=Test Project ", reader.readLine() ); + + assertEquals( "error in filtering using System properties", "system_property_1=new-system-property-value", + reader.readLine() ); + assertEquals( "error in filtering using System properties", "system_property_2=new-system-property-value", + reader.readLine() ); + + // update property, and generate again + File filterFile = new File( getTestDirectory(), testId + "-test-data/filters/filter.properties" ); + createFile( filterFile ); + filterList.add( filterFile.getAbsolutePath() ); + content += "resource_key_1=${resource_value_1}\n"; + content += "resource_key_2=@resource_value_2@\n" + content; + FileUtils.fileWrite( sampleResourceWDir.getAbsolutePath(), content ); + FileUtils.fileWrite( sampleResource.getAbsolutePath(), content ); + String filterContent = "resource_value_1=this_is_filtered\n"; + filterContent += "resource_value_2=this_is_filtered"; + FileUtils.fileWrite( filterFile.getAbsolutePath(), filterContent ); + + mojo.execute(); + + // validate filtered file + content = FileUtils.fileRead( expectedResourceWDirFile ); + reader = new BufferedReader( new StringReader( content ) ); + + assertEquals( "error in filtering using System Properties", comment, reader.readLine() ); + + assertEquals( "error in filtering using System properties", "system_key_1=" + System.getProperty( "user.dir" ), + reader.readLine() ); + assertEquals( "error in filtering using System properties", "system_key_2=" + System.getProperty( "user.dir" ), + reader.readLine() ); + + assertEquals( "error in filtering using project properties", "project_key_1=i_think_so", reader.readLine() ); + assertEquals( "error in filtering using project properties", "project_key_2=i_think_so", reader.readLine() ); + + assertEquals( "error in filtering using project properties", "project_name_1=Test Project ", reader.readLine() ); + assertEquals( "error in filtering using project properties", "project_name_2=Test Project ", reader.readLine() ); + + assertEquals( "error in filtering using System properties", "system_property_1=new-system-property-value", + reader.readLine() ); + assertEquals( "error in filtering using System properties", "system_property_2=new-system-property-value", + reader.readLine() ); + + assertEquals( "error in filtering using filter files", "resource_key_1=this_is_filtered", reader.readLine() ); + assertEquals( "error in filtering using filter files", "resource_key_2=this_is_filtered", reader.readLine() ); + + // house keeping + expectedWebSourceFile.delete(); + expectedWebSource2File.delete(); + expectedResourceFile.delete(); + expectedResourceWDirFile.delete(); + } + +} diff --git a/Java-base/maven-war-plugin/src/src/test/java/org/apache/maven/plugins/war/WarExplodedMojoTest.java b/Java-base/maven-war-plugin/src/src/test/java/org/apache/maven/plugins/war/WarExplodedMojoTest.java new file mode 100644 index 000000000..22ff280de --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/test/java/org/apache/maven/plugins/war/WarExplodedMojoTest.java @@ -0,0 +1,1055 @@ +package org.apache.maven.plugins.war; + +/* + * 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. + */ + +import static org.junit.Assert.assertNotEquals; + +import org.apache.maven.artifact.handler.ArtifactHandler; +import org.apache.maven.plugin.testing.stubs.ArtifactStub; +import org.apache.maven.plugins.war.stub.AarArtifactStub; +import org.apache.maven.plugins.war.stub.EJBArtifactStub; +import org.apache.maven.plugins.war.stub.EJBArtifactStubWithClassifier; +import org.apache.maven.plugins.war.stub.EJBClientArtifactStub; +import org.apache.maven.plugins.war.stub.IncludeExcludeWarArtifactStub; +import org.apache.maven.plugins.war.stub.JarArtifactStub; +import org.apache.maven.plugins.war.stub.MarArtifactStub; +import org.apache.maven.plugins.war.stub.MavenProjectArtifactsStub; +import org.apache.maven.plugins.war.stub.MavenProjectBasicStub; +import org.apache.maven.plugins.war.stub.PARArtifactStub; +import org.apache.maven.plugins.war.stub.ResourceStub; +import org.apache.maven.plugins.war.stub.TLDArtifactStub; +import org.apache.maven.plugins.war.stub.WarArtifactStub; +import org.apache.maven.plugins.war.stub.XarArtifactStub; +import org.codehaus.plexus.util.FileUtils; + +import java.io.File; +import java.text.SimpleDateFormat; +import java.util.LinkedList; +import java.util.Locale; + +public class WarExplodedMojoTest + extends AbstractWarExplodedMojoTest +{ + + protected File getPomFile() + { + return new File( getBasedir(), "/target/test-classes/unit/warexplodedmojo/plugin-config.xml" ); + } + + protected File getTestDirectory() + { + return new File( getBasedir(), "target/test-classes/unit/warexplodedmojo/test-dir" ); + } + + /** + * @throws Exception in case of an error. + */ + public void testSimpleExplodedWar() + throws Exception + { + // setup test data + String testId = "SimpleExplodedWar"; + MavenProjectBasicStub project = new MavenProjectBasicStub(); + File webAppSource = createWebAppSource( testId ); + File classesDir = createClassesDir( testId, false ); + File webAppResource = new File( getTestDirectory(), testId + "-resources" ); + File webAppDirectory = new File( getTestDirectory(), testId ); + File sampleResource = new File( webAppResource, "pix/panis_na.jpg" ); + ResourceStub[] resources = new ResourceStub[] { new ResourceStub() }; + + createFile( sampleResource ); + + assertTrue( "sampeResource not found", sampleResource.exists() ); + + // configure mojo + resources[0].setDirectory( webAppResource.getAbsolutePath() ); + this.configureMojo( mojo, new LinkedList(), classesDir, webAppSource, webAppDirectory, project ); + setVariableValueToObject( mojo, "webResources", resources ); + mojo.execute(); + + // validate operation + File expectedWebSourceFile = new File( webAppDirectory, "pansit.jsp" ); + File expectedWebSource2File = new File( webAppDirectory, "org/web/app/last-exile.jsp" ); + File expectedWebResourceFile = new File( webAppDirectory, "pix/panis_na.jpg" ); + File expectedWEBINFDir = new File( webAppDirectory, "WEB-INF" ); + File expectedMETAINFDir = new File( webAppDirectory, "META-INF" ); + + assertTrue( "source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists() ); + assertTrue( "source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists() ); + assertTrue( "resources doesn't exist: " + expectedWebResourceFile, expectedWebResourceFile.exists() ); + assertTrue( "WEB-INF not found", expectedWEBINFDir.exists() ); + assertTrue( "META-INF not found", expectedMETAINFDir.exists() ); + + // house keeping + expectedWebSourceFile.delete(); + expectedWebSource2File.delete(); + expectedWebResourceFile.delete(); + } + + /** + * @throws Exception in case of an error. + */ + public void testSimpleExplodedWarWTargetPath() + throws Exception + { + // setup test data + String testId = "SimpleExplodedWar"; + MavenProjectBasicStub project = new MavenProjectBasicStub(); + File webAppSource = createWebAppSource( testId ); + File classesDir = createClassesDir( testId, false ); + File webAppResource = new File( getTestDirectory(), "resources" ); + File webAppDirectory = new File( getTestDirectory(), testId ); + File sampleResource = new File( webAppResource, "pix/panis_na.jpg" ); + ResourceStub[] resources = new ResourceStub[] { new ResourceStub() }; + + createFile( sampleResource ); + + // configure mojo + resources[0].setDirectory( webAppResource.getAbsolutePath() ); + resources[0].setTargetPath( "targetPath" ); + this.configureMojo( mojo, new LinkedList(), classesDir, webAppSource, webAppDirectory, project ); + setVariableValueToObject( mojo, "webResources", resources ); + mojo.execute(); + + // validate operation + File expectedWebSourceFile = new File( webAppDirectory, "pansit.jsp" ); + File expectedWebSource2File = new File( webAppDirectory, "org/web/app/last-exile.jsp" ); + File expectedWebResourceFile = new File( webAppDirectory, "targetPath/pix/panis_na.jpg" ); + File expectedWEBINFDir = new File( webAppDirectory, "WEB-INF" ); + File expectedMETAINFDir = new File( webAppDirectory, "META-INF" ); + + assertTrue( "source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists() ); + assertTrue( "source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists() ); + assertTrue( "resources doesn't exist: " + expectedWebResourceFile, expectedWebResourceFile.exists() ); + assertTrue( "WEB-INF not found", expectedWEBINFDir.exists() ); + assertTrue( "META-INF not found", expectedMETAINFDir.exists() ); + + // house keeping + expectedWebSourceFile.delete(); + expectedWebSource2File.delete(); + expectedWebResourceFile.delete(); + } + + /** + * @throws Exception in case of an error. + */ + public void testExplodedWar_WithCustomWebXML() + throws Exception + { + // setup test data + String testId = "ExplodedWar_WithCustomWebXML"; + MavenProjectBasicStub project = new MavenProjectBasicStub(); + File webAppSource = createWebAppSource( testId ); + File classesDir = createClassesDir( testId, true ); + File xmlSource = createXMLConfigDir( testId, new String[] { "web.xml" } ); + File webAppDirectory = new File( getTestDirectory(), testId ); + + // configure mojo + this.configureMojo( mojo, new LinkedList(), classesDir, webAppSource, webAppDirectory, project ); + mojo.setWebXml( new File( xmlSource, "web.xml" ) ); + mojo.execute(); + + // validate operation + File expectedWebSourceFile = new File( webAppDirectory, "pansit.jsp" ); + File expectedWebSource2File = new File( webAppDirectory, "org/web/app/last-exile.jsp" ); + File expectedWEBXMLFile = new File( webAppDirectory, "WEB-INF/web.xml" ); + File expectedMETAINFDir = new File( webAppDirectory, "META-INF" ); + + assertTrue( "source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists() ); + assertTrue( "source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists() ); + assertTrue( "WEB XML not found: " + expectedWEBXMLFile.toString(), expectedWEBXMLFile.exists() ); + assertTrue( "META-INF not found", expectedMETAINFDir.exists() ); + assertEquals( "WEB XML not correct", mojo.getWebXml().toString(), FileUtils.fileRead( expectedWEBXMLFile ) ); + + // house keeping + expectedWebSourceFile.delete(); + expectedWebSource2File.delete(); + expectedWEBXMLFile.delete(); + expectedMETAINFDir.delete(); + } + + /** + * @throws Exception in case of an error. + */ + public void testExplodedWar_WithContainerConfigXML() + throws Exception + { + // setup test data + String testId = "ExplodedWar_WithContainerConfigXML"; + MavenProjectBasicStub project = new MavenProjectBasicStub(); + File classesDir = createClassesDir( testId, true ); + File webAppSource = createWebAppSource( testId ); + File xmlSource = createXMLConfigDir( testId, new String[] { "config.xml" } ); + File webAppDirectory = new File( getTestDirectory(), testId ); + + // configure mojo + this.configureMojo( mojo, new LinkedList(), classesDir, webAppSource, webAppDirectory, project ); + mojo.setContainerConfigXML( new File( xmlSource, "config.xml" ) ); + mojo.execute(); + + // validate operation + File expectedWebSourceFile = new File( webAppDirectory, "pansit.jsp" ); + File expectedWebSource2File = new File( webAppDirectory, "org/web/app/last-exile.jsp" ); + File expectedContainerConfigXMLFile = new File( webAppDirectory, "META-INF/config.xml" ); + File expectedWEBINFDir = new File( webAppDirectory, "WEB-INF" ); + + assertTrue( "source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists() ); + assertTrue( "source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists() ); + assertTrue( "WEB-INF not found", expectedWEBINFDir.exists() ); + assertTrue( "Container Config XML not found:" + expectedContainerConfigXMLFile.toString(), + expectedContainerConfigXMLFile.exists() ); + + // house keeping + expectedWebSourceFile.delete(); + expectedWebSource2File.delete(); + expectedContainerConfigXMLFile.delete(); + expectedWEBINFDir.delete(); + } + + /** + * @throws Exception in case of an error. + */ + public void testExplodedWar_WithSimpleExternalWARFile() + throws Exception + { + // setup test data + MavenProjectArtifactsStub project = new MavenProjectArtifactsStub(); + WarArtifactStub warArtifact = new WarArtifactStub( getBasedir() ); + + String testId = "ExplodedWar_WithSimpleExternalWARFile"; + File webAppDirectory = new File( getTestDirectory(), testId ); + File webAppSource = createWebAppSource( testId ); + File classesDir = createClassesDir( testId, true ); + File workDirectory = new File( getTestDirectory(), "/war/work-" + testId ); + File simpleWarFile = warArtifact.getFile(); + + assertTrue( "simple war not found: " + simpleWarFile.toString(), simpleWarFile.exists() ); + + createDir( workDirectory ); + + // configure mojo + project.addArtifact( warArtifact ); + this.configureMojo( mojo, new LinkedList(), classesDir, webAppSource, webAppDirectory, project ); + setVariableValueToObject( mojo, "workDirectory", workDirectory ); + mojo.execute(); + + // validate operation - META-INF is automatically excluded so remove the file from the list + File expectedWebSourceFile = new File( webAppDirectory, "pansit.jsp" ); + File expectedWebSource2File = new File( webAppDirectory, "org/web/app/last-exile.jsp" ); + File expectedWEBXMLFile = new File( webAppDirectory, "WEB-INF/web.xml" ); + File expectedWARFile = new File( webAppDirectory, "/org/sample/company/test.jsp" ); + + assertTrue( "source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists() ); + assertTrue( "source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists() ); + // check simple.war in the unit test dir under resources to verify the list of files + assertTrue( "web xml not found: " + expectedWEBXMLFile.toString(), expectedWEBXMLFile.exists() ); + assertTrue( "war file not found: " + expectedWARFile.toString(), expectedWARFile.exists() ); + + // house keeping + expectedWebSourceFile.delete(); + expectedWebSource2File.delete(); + expectedWEBXMLFile.delete(); + expectedWARFile.delete(); + } + + /** + * Merge a dependent WAR when a file in the war source directory overrides one found in the WAR. + * @throws Exception in case of an error. + */ + public void testExplodedWarMergeWarLocalFileOverride() + throws Exception + { + // setup test data + MavenProjectArtifactsStub project = new MavenProjectArtifactsStub(); + WarArtifactStub warArtifact = new WarArtifactStub( getBasedir() ); + + String testId = "testExplodedWarMergeWarLocalFileOverride"; + File webAppDirectory = new File( getTestDirectory(), testId ); + File webAppSource = getWebAppSource( testId ); + File simpleJSP = new File( webAppSource, "org/sample/company/test.jsp" ); + createFile( simpleJSP ); + + File workDirectory = new File( getTestDirectory(), "/war/work-" + testId ); + createDir( workDirectory ); + + File classesDir = createClassesDir( testId, true ); + + // configure mojo + project.addArtifact( warArtifact ); + this.configureMojo( mojo, new LinkedList(), classesDir, webAppSource, webAppDirectory, project ); + setVariableValueToObject( mojo, "workDirectory", workDirectory ); + mojo.execute(); + + // validate operation + File expectedFile = new File( webAppDirectory, "/org/sample/company/test.jsp" ); + + assertTrue( "file not found: " + expectedFile.toString(), expectedFile.exists() ); + assertEquals( "file incorrect", simpleJSP.toString(), FileUtils.fileRead( expectedFile ) ); + + // check when the merged war file is newer - so set an old time on the local file + long time = new SimpleDateFormat( "yyyy-MM-dd", Locale.US ).parse( "2005-1-1" ).getTime(); + simpleJSP.setLastModified( time ); + expectedFile.setLastModified( time ); + + project.addArtifact( warArtifact ); + this.configureMojo( mojo, new LinkedList(), classesDir, webAppSource, webAppDirectory, project ); + setVariableValueToObject( mojo, "workDirectory", workDirectory ); + mojo.execute(); + + assertTrue( "file not found: " + expectedFile.toString(), expectedFile.exists() ); + assertEquals( "file incorrect", simpleJSP.toString(), FileUtils.fileRead( expectedFile ) ); + + // house keeping + expectedFile.delete(); + } + + // The last modified thingy behavior is not applicable anymore. This is the only test that + // has been removed. + // /** + // * Merge a dependent WAR that gets updated since the last run. + // */ + // public void testExplodedWarMergeWarUpdated() + // throws Exception + // { + // // setup test data + // MavenProjectArtifactsStub project = new MavenProjectArtifactsStub(); + // WarArtifactStub warArtifact = new WarArtifactStub( getBasedir() ); + // + // String testId = "testExplodedWarMergeWarUpdated"; + // File webAppDirectory = new File( getTestDirectory(), testId ); + // FileUtils.deleteDirectory( webAppDirectory ); + // + // File webAppSource = getWebAppSource( testId ); + // + // File workDirectory = new File( getTestDirectory(), "/war/work-" + testId ); + // createDir( workDirectory ); + // + // File classesDir = createClassesDir( testId, true ); + // + // // configure mojo + // project.addArtifact( warArtifact ); + // this.configureMojo( mojo, new LinkedList(), classesDir, webAppSource, webAppDirectory, project ); + // setVariableValueToObject( mojo, "workDirectory", workDirectory ); + // mojo.execute(); + // + // // validate operation + // File expectedFile = new File( webAppDirectory, "/org/sample/company/test.jsp" ); + // + // assertTrue( "file not found: " + expectedFile.toString(), expectedFile.exists() ); + // assertEquals( "file incorrect", "", FileUtils.fileRead( expectedFile ) ); + // + // // update file, so the local one is older + // warArtifact.setFile( new File( warArtifact.getFile().getParentFile(), "simple-updated.war" ) ); + // + // mojo.execute(); + // + // assertTrue( "file not found: " + expectedFile.toString(), expectedFile.exists() ); + // assertEquals( "file incorrect", "updated\n", FileUtils.fileRead( expectedFile ) ); + // + // // update file, so the local one is newer + // warArtifact.setFile( new File( warArtifact.getFile().getParentFile(), "simple.war" ) ); + // + // mojo.execute(); + // + // assertTrue( "file not found: " + expectedFile.toString(), expectedFile.exists() ); + // assertEquals( "file incorrect", "updated\n", FileUtils.fileRead( expectedFile ) ); + // + // // house keeping + // expectedFile.delete(); + // } + + /** + * @throws Exception in case of an error. + */ + public void testExplodedWar_WithEJB() + throws Exception + { + // setup test data + String testId = "ExplodedWar_WithEJB"; + MavenProjectArtifactsStub project = new MavenProjectArtifactsStub(); + File webAppDirectory = new File( getTestDirectory(), testId ); + File webAppSource = createWebAppSource( testId ); + File classesDir = createClassesDir( testId, true ); + EJBArtifactStub ejbArtifact = new EJBArtifactStub( getBasedir() ); + File ejbFile = ejbArtifact.getFile(); + + assertTrue( "ejb jar not found: " + ejbFile.toString(), ejbFile.exists() ); + + // configure mojo + project.addArtifact( ejbArtifact ); + this.configureMojo( mojo, new LinkedList(), classesDir, webAppSource, webAppDirectory, project ); + mojo.execute(); + + // validate operation + File expectedWebSourceFile = new File( webAppDirectory, "pansit.jsp" ); + File expectedWebSource2File = new File( webAppDirectory, "org/web/app/last-exile.jsp" ); + // final name form is -. + File expectedEJBArtifact = new File( webAppDirectory, "WEB-INF/lib/ejbartifact-0.0-Test.jar" ); + // File expectedEJBArtifact = new File( webAppDirectory, "WEB-INF/lib/ejbartifact-0.0-Test.jar" ); + + assertTrue( "source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists() ); + assertTrue( "source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists() ); + assertTrue( "ejb artifact not found: " + expectedEJBArtifact.toString(), expectedEJBArtifact.exists() ); + + // house keeping + expectedWebSourceFile.delete(); + expectedWebSource2File.delete(); + expectedEJBArtifact.delete(); + } + + public void testExplodedWarWithJar() + throws Exception + { + // setup test data + String testId = "ExplodedWarWithJar"; + MavenProjectArtifactsStub project = new MavenProjectArtifactsStub(); + File webAppDirectory = new File( getTestDirectory(), testId ); + File webAppSource = createWebAppSource( testId ); + File classesDir = createClassesDir( testId, true ); + ArtifactHandler artifactHandler = (ArtifactHandler) lookup( ArtifactHandler.ROLE, "jar" ); + ArtifactStub jarArtifact = new JarArtifactStub( getBasedir(), artifactHandler ); + File jarFile = jarArtifact.getFile(); + + assertTrue( "jar not found: " + jarFile.toString(), jarFile.exists() ); + + // configure mojo + project.addArtifact( jarArtifact ); + this.configureMojo( mojo, new LinkedList(), classesDir, webAppSource, webAppDirectory, project ); + mojo.execute(); + + // validate operation + File expectedWebSourceFile = new File( webAppDirectory, "pansit.jsp" ); + File expectedWebSource2File = new File( webAppDirectory, "org/web/app/last-exile.jsp" ); + // final name form is -. + File expectedJarArtifact = new File( webAppDirectory, "WEB-INF/lib/jarartifact-0.0-Test.jar" ); + + assertTrue( "source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists() ); + assertTrue( "source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists() ); + assertTrue( "jar artifact not found: " + expectedJarArtifact.toString(), expectedJarArtifact.exists() ); + + // house keeping + expectedWebSourceFile.delete(); + expectedWebSource2File.delete(); + expectedJarArtifact.delete(); + } + + /** + * @throws Exception in case of an error. + */ + public void testExplodedWar_WithEJBClient() + throws Exception + { + // setup test data + String testId = "ExplodedWar_WithEJB"; + MavenProjectArtifactsStub project = new MavenProjectArtifactsStub(); + File webAppDirectory = new File( getTestDirectory(), testId ); + File webAppSource = createWebAppSource( testId ); + File classesDir = createClassesDir( testId, true ); + EJBClientArtifactStub ejbArtifact = new EJBClientArtifactStub( getBasedir() ); + File ejbFile = ejbArtifact.getFile(); + + assertTrue( "ejb jar not found: " + ejbFile.toString(), ejbFile.exists() ); + + // configure mojo + project.addArtifact( ejbArtifact ); + this.configureMojo( mojo, new LinkedList(), classesDir, webAppSource, webAppDirectory, project ); + mojo.execute(); + + // validate operation + File expectedWebSourceFile = new File( webAppDirectory, "pansit.jsp" ); + File expectedWebSource2File = new File( webAppDirectory, "org/web/app/last-exile.jsp" ); + // final name form is -. + File expectedEJBArtifact = new File( webAppDirectory, "WEB-INF/lib/ejbclientartifact-0.0-Test-client.jar" ); + + assertTrue( "source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists() ); + assertTrue( "source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists() ); + assertTrue( "ejb artifact not found: " + expectedEJBArtifact.toString(), expectedEJBArtifact.exists() ); + + // house keeping + expectedWebSourceFile.delete(); + expectedWebSource2File.delete(); + expectedEJBArtifact.delete(); + } + + /** + * @throws Exception in case of an error. + */ + public void testExplodedWar_WithTLD() + throws Exception + { + // setup test data + String testId = "ExplodedWar_WithTLD"; + MavenProjectArtifactsStub project = new MavenProjectArtifactsStub(); + File webAppDirectory = new File( getTestDirectory(), testId ); + File webAppSource = createWebAppSource( testId ); + File classesDir = createClassesDir( testId, true ); + TLDArtifactStub tldArtifact = new TLDArtifactStub( getBasedir() ); + File tldFile = tldArtifact.getFile(); + + assertTrue( "tld jar not found: " + tldFile.getAbsolutePath(), tldFile.exists() ); + + // configure mojo + project.addArtifact( tldArtifact ); + this.configureMojo( mojo, new LinkedList(), classesDir, webAppSource, webAppDirectory, project ); + mojo.execute(); + + // validate operation + File expectedWebSourceFile = new File( webAppDirectory, "pansit.jsp" ); + File expectedWebSource2File = new File( webAppDirectory, "org/web/app/last-exile.jsp" ); + // final name form is -. + File expectedTLDArtifact = new File( webAppDirectory, "WEB-INF/tld/tldartifact-0.0-Test.tld" ); + + assertTrue( "source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists() ); + assertTrue( "source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists() ); + assertTrue( "tld artifact not found: " + expectedTLDArtifact.toString(), expectedTLDArtifact.exists() ); + + // house keeping + expectedWebSourceFile.delete(); + expectedWebSource2File.delete(); + expectedTLDArtifact.delete(); + } + + /** + * @throws Exception in case of an error. + */ + public void testExplodedWar_WithPAR() + throws Exception + { + // setup test data + String testId = "ExplodedWar_WithPAR"; + MavenProjectArtifactsStub project = new MavenProjectArtifactsStub(); + File webAppDirectory = new File( getTestDirectory(), testId ); + File webAppSource = createWebAppSource( testId ); + File classesDir = createClassesDir( testId, true ); + PARArtifactStub parartifact = new PARArtifactStub( getBasedir() ); + File parFile = parartifact.getFile(); + + assertTrue( "par not found: " + parFile.getAbsolutePath(), parFile.exists() ); + + // configure mojo + project.addArtifact( parartifact ); + this.configureMojo( mojo, new LinkedList(), classesDir, webAppSource, webAppDirectory, project ); + mojo.execute(); + + // validate operation + File expectedWebSourceFile = new File( webAppDirectory, "pansit.jsp" ); + File expectedWebSource2File = new File( webAppDirectory, "org/web/app/last-exile.jsp" ); + // final name form is -. + File expectedPARArtifact = new File( webAppDirectory, "WEB-INF/lib/parartifact-0.0-Test.jar" ); + + assertTrue( "source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists() ); + assertTrue( "source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists() ); + assertTrue( "par artifact not found: " + expectedPARArtifact.toString(), expectedPARArtifact.exists() ); + + // house keeping + expectedWebSourceFile.delete(); + expectedWebSource2File.delete(); + expectedPARArtifact.delete(); + } + + /** + * @throws Exception in case of an error. + */ + public void testExplodedWarWithAar() + throws Exception + { + // setup test data + String testId = "ExplodedWarWithAar"; + MavenProjectArtifactsStub project = new MavenProjectArtifactsStub(); + File webAppDirectory = new File( getTestDirectory(), testId ); + File webAppSource = createWebAppSource( testId ); + File classesDir = createClassesDir( testId, true ); + // Fake here since the aar artifact handler does not exist: no biggie + ArtifactHandler artifactHandler = (ArtifactHandler) lookup( ArtifactHandler.ROLE, "jar" ); + ArtifactStub aarArtifact = new AarArtifactStub( getBasedir(), artifactHandler ); + File aarFile = aarArtifact.getFile(); + + assertTrue( "jar not found: " + aarFile.toString(), aarFile.exists() ); + + // configure mojo + project.addArtifact( aarArtifact ); + this.configureMojo( mojo, new LinkedList(), classesDir, webAppSource, webAppDirectory, project ); + mojo.execute(); + + // validate operation + File expectedWebSourceFile = new File( webAppDirectory, "pansit.jsp" ); + File expectedWebSource2File = new File( webAppDirectory, "org/web/app/last-exile.jsp" ); + // final name form is -. + File expectedJarArtifact = new File( webAppDirectory, "WEB-INF/services/aarartifact-0.0-Test.jar" ); + + assertTrue( "source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists() ); + assertTrue( "source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists() ); + assertTrue( "jar artifact not found: " + expectedJarArtifact.toString(), expectedJarArtifact.exists() ); + + // house keeping + expectedWebSourceFile.delete(); + expectedWebSource2File.delete(); + expectedJarArtifact.delete(); + } + + /** + * @throws Exception in case of an error. + */ + public void testExplodedWarWithMar() + throws Exception + { + // setup test data + String testId = "ExplodedWarWithMar"; + MavenProjectArtifactsStub project = new MavenProjectArtifactsStub(); + File webAppDirectory = new File( getTestDirectory(), testId ); + File webAppSource = createWebAppSource( testId ); + File classesDir = createClassesDir( testId, true ); + // Fake here since the mar artifact handler does not exist: no biggie + ArtifactHandler artifactHandler = (ArtifactHandler) lookup( ArtifactHandler.ROLE, "jar" ); + ArtifactStub marArtifact = new MarArtifactStub( getBasedir(), artifactHandler ); + File marFile = marArtifact.getFile(); + + assertTrue( "jar not found: " + marFile.toString(), marFile.exists() ); + + // configure mojo + project.addArtifact( marArtifact ); + this.configureMojo( mojo, new LinkedList(), classesDir, webAppSource, webAppDirectory, project ); + mojo.execute(); + + // validate operation + File expectedWebSourceFile = new File( webAppDirectory, "pansit.jsp" ); + File expectedWebSource2File = new File( webAppDirectory, "org/web/app/last-exile.jsp" ); + // final name form is -. + File expectedJarArtifact = new File( webAppDirectory, "WEB-INF/modules/marartifact-0.0-Test.jar" ); + + assertTrue( "source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists() ); + assertTrue( "source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists() ); + assertTrue( "jar artifact not found: " + expectedJarArtifact.toString(), expectedJarArtifact.exists() ); + + // house keeping + expectedWebSourceFile.delete(); + expectedWebSource2File.delete(); + expectedJarArtifact.delete(); + } + + /** + * @throws Exception in case of an error. + */ + public void testExplodedWarWithXar() + throws Exception + { + // setup test data + String testId = "ExplodedWarWithXar"; + MavenProjectArtifactsStub project = new MavenProjectArtifactsStub(); + File webAppDirectory = new File( getTestDirectory(), testId ); + File webAppSource = createWebAppSource( testId ); + File classesDir = createClassesDir( testId, true ); + // Fake here since the xar artifact handler does not exist: no biggie + ArtifactHandler artifactHandler = (ArtifactHandler) lookup( ArtifactHandler.ROLE, "jar" ); + ArtifactStub xarArtifact = new XarArtifactStub( getBasedir(), artifactHandler ); + File xarFile = xarArtifact.getFile(); + + assertTrue( "jar not found: " + xarFile.toString(), xarFile.exists() ); + + // configure mojo + project.addArtifact( xarArtifact ); + this.configureMojo( mojo, new LinkedList(), classesDir, webAppSource, webAppDirectory, project ); + mojo.execute(); + + // validate operation + File expectedWebSourceFile = new File( webAppDirectory, "pansit.jsp" ); + File expectedWebSource2File = new File( webAppDirectory, "org/web/app/last-exile.jsp" ); + // final name form is -. + File expectedJarArtifact = new File( webAppDirectory, "WEB-INF/extensions/xarartifact-0.0-Test.jar" ); + + assertTrue( "source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists() ); + assertTrue( "source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists() ); + assertTrue( "jar artifact not found: " + expectedJarArtifact.toString(), expectedJarArtifact.exists() ); + + // house keeping + expectedWebSourceFile.delete(); + expectedWebSource2File.delete(); + expectedJarArtifact.delete(); + } + + /** + * @throws Exception in case of an error. + */ + public void testExplodedWar_WithDuplicateDependencies() + throws Exception + { + // setup test data + String testId = "ExplodedWar_WithDuplicateDependencies"; + MavenProjectArtifactsStub project = new MavenProjectArtifactsStub(); + File webAppDirectory = new File( getTestDirectory(), testId ); + File webAppSource = createWebAppSource( testId ); + File classesDir = createClassesDir( testId, true ); + EJBArtifactStub ejbArtifact = new EJBArtifactStub( getBasedir() ); + EJBArtifactStub ejbArtifactDup = new EJBArtifactStub( getBasedir() ); + File ejbFile = ejbArtifact.getFile(); + + // ejbArtifact has a hard coded file, only one assert is needed + assertTrue( "ejb not found: " + ejbFile.getAbsolutePath(), ejbFile.exists() ); + + // configure mojo + ejbArtifact.setGroupId( "org.sample.ejb" ); + ejbArtifactDup.setGroupId( "org.dup.ejb" ); + project.addArtifact( ejbArtifact ); + project.addArtifact( ejbArtifactDup ); + this.configureMojo( mojo, new LinkedList(), classesDir, webAppSource, webAppDirectory, project ); + mojo.execute(); + + // validate operation + File expectedWebSourceFile = new File( webAppDirectory, "pansit.jsp" ); + File expectedWebSource2File = new File( webAppDirectory, "org/web/app/last-exile.jsp" ); + // final name form is -. + File expectedEJBArtifact = new File( webAppDirectory, "WEB-INF/lib/org.sample.ejb-ejbartifact-0.0-Test.jar" ); + File expectedEJBDupArtifact = new File( webAppDirectory, "WEB-INF/lib/org.dup.ejb-ejbartifact-0.0-Test.jar" ); + + assertTrue( "source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists() ); + assertTrue( "source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists() ); + assertTrue( "ejb artifact not found: " + expectedEJBArtifact.toString(), expectedEJBArtifact.exists() ); + assertTrue( "ejb dup artifact not found: " + expectedEJBDupArtifact.toString(), expectedEJBDupArtifact.exists() ); + + // house keeping + expectedWebSourceFile.delete(); + expectedWebSource2File.delete(); + expectedEJBArtifact.delete(); + expectedEJBDupArtifact.delete(); + } + + /** + * @throws Exception in case of an error. + */ + public void testExplodedWar_DuplicateWithClassifier() + throws Exception + { + // setup test data + String testId = "ExplodedWar_DuplicateWithClassifier"; + MavenProjectArtifactsStub project = new MavenProjectArtifactsStub(); + File webAppDirectory = new File( getTestDirectory(), testId ); + File webAppSource = createWebAppSource( testId ); + File classesDir = createClassesDir( testId, true ); + EJBArtifactStub ejbArtifact = new EJBArtifactStub( getBasedir() ); + EJBArtifactStubWithClassifier ejbArtifactDup = new EJBArtifactStubWithClassifier( getBasedir() ); + + File ejbFile = ejbArtifact.getFile(); + + // ejbArtifact has a hard coded file, only one assert is needed + assertTrue( "ejb not found: " + ejbFile.getAbsolutePath(), ejbFile.exists() ); + + // configure mojo + + ejbArtifact.setGroupId( "org.sample.ejb" ); + ejbArtifactDup.setGroupId( "org.sample.ejb" ); + + ejbArtifactDup.setClassifier( "classifier" ); + + project.addArtifact( ejbArtifact ); + project.addArtifact( ejbArtifactDup ); + + this.configureMojo( mojo, new LinkedList(), classesDir, webAppSource, webAppDirectory, project ); + mojo.execute(); + + // validate operation + File expectedWebSourceFile = new File( webAppDirectory, "pansit.jsp" ); + File expectedWebSource2File = new File( webAppDirectory, "org/web/app/last-exile.jsp" ); + // final name form is -. + File expectedEJBArtifact = new File( webAppDirectory, "WEB-INF/lib/ejbartifact-0.0-Test.jar" ); + File expectedEJBDupArtifact = new File( webAppDirectory, "WEB-INF/lib/ejbartifact-0.0-Test-classifier.jar" ); + + assertTrue( "source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists() ); + assertTrue( "source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists() ); + assertTrue( "ejb artifact not found: " + expectedEJBArtifact.toString(), expectedEJBArtifact.exists() ); + assertTrue( "ejb dup artifact not found: " + expectedEJBDupArtifact.toString(), expectedEJBDupArtifact.exists() ); + + // house keeping + expectedWebSourceFile.delete(); + expectedWebSource2File.delete(); + expectedEJBArtifact.delete(); + expectedEJBDupArtifact.delete(); + } + + /** + * @throws Exception in case of an error. + */ + public void testExplodedWar_WithClasses() + throws Exception + { + // setup test data + String testId = "ExplodedWar_WithClasses"; + MavenProjectBasicStub project = new MavenProjectBasicStub(); + File webAppDirectory = new File( getTestDirectory(), testId ); + File webAppSource = createWebAppSource( testId ); + File classesDir = createClassesDir( testId, false ); + + // configure mojo + this.configureMojo( mojo, new LinkedList(), classesDir, webAppSource, webAppDirectory, project ); + mojo.execute(); + + // validate operation + File expectedWebSourceFile = new File( webAppDirectory, "pansit.jsp" ); + File expectedWebSource2File = new File( webAppDirectory, "org/web/app/last-exile.jsp" ); + // final name form is -. + File expectedClass = new File( webAppDirectory, "WEB-INF/classes/sample-servlet.class" ); + + assertTrue( "source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists() ); + assertTrue( "source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists() ); + assertTrue( "classes not found: " + expectedClass.toString(), expectedClass.exists() ); + + // house keeping + expectedWebSourceFile.delete(); + expectedWebSource2File.delete(); + expectedClass.delete(); + } + + /** + * @throws Exception in case of an error. + */ + public void testExplodedWar_WithSourceIncludeExclude() + throws Exception + { + // setup test data + String testId = "ExplodedWar_WithSourceIncludeExclude"; + MavenProjectBasicStub project = new MavenProjectBasicStub(); + File webAppSource = createWebAppSource( testId ); + File classesDir = createClassesDir( testId, true ); + File webAppDirectory = new File( getTestDirectory(), testId ); + + // configure mojo + this.configureMojo( mojo, new LinkedList(), classesDir, webAppSource, webAppDirectory, project ); + setVariableValueToObject( mojo, "warSourceIncludes", "**/*sit.jsp" ); + setVariableValueToObject( mojo, "warSourceExcludes", "**/last*.*" ); + mojo.execute(); + + // validate operation + File expectedWebSourceFile = new File( webAppDirectory, "pansit.jsp" ); + File expectedWebSource2File = new File( webAppDirectory, "org/web/app/last-exile.jsp" ); + File expectedWEBXMLDir = new File( webAppDirectory, "WEB-INF" ); + File expectedMETAINFDir = new File( webAppDirectory, "META-INF" ); + + assertTrue( "source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists() ); + assertFalse( "source files found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists() ); + assertTrue( "WEB XML not found: " + expectedWEBXMLDir.toString(), expectedWEBXMLDir.exists() ); + assertTrue( "META-INF not found", expectedMETAINFDir.exists() ); + + // house keeping + expectedWebSourceFile.delete(); + expectedWebSource2File.delete(); + expectedWEBXMLDir.delete(); + expectedMETAINFDir.delete(); + } + + /** + * @throws Exception in case of an error. + */ + public void testExplodedWar_WithWarDependencyIncludeExclude() + throws Exception + { + // setup test data + String testId = "ExplodedWar_WithWarDependencyIncludeExclude"; + MavenProjectArtifactsStub project = new MavenProjectArtifactsStub(); + IncludeExcludeWarArtifactStub includeexcludeWarArtifact = new IncludeExcludeWarArtifactStub( getBasedir() ); + File webAppDirectory = new File( getTestDirectory(), testId ); + File webAppSource = createWebAppSource( testId ); + File classesDir = createClassesDir( testId, true ); + File workDirectory = new File( getTestDirectory(), "/war/work-" + testId ); + File includeExcludeWarFile = includeexcludeWarArtifact.getFile(); + + assertTrue( "war not found: " + includeExcludeWarFile.toString(), includeExcludeWarFile.exists() ); + + createDir( workDirectory ); + + // configure mojo + project.addArtifact( includeexcludeWarArtifact ); + this.configureMojo( mojo, new LinkedList(), classesDir, webAppSource, webAppDirectory, project ); + setVariableValueToObject( mojo, "dependentWarIncludes", "**/*Include.jsp,**/*.xml" ); + setVariableValueToObject( mojo, "dependentWarExcludes", "**/*Exclude*,**/MANIFEST.MF" ); + setVariableValueToObject( mojo, "workDirectory", workDirectory ); + mojo.execute(); + + // validate operation + File expectedWebSourceFile = new File( webAppDirectory, "pansit.jsp" ); + File expectedWebSource2File = new File( webAppDirectory, "org/web/app/last-exile.jsp" ); + File expectedManifestFile = new File( webAppDirectory, "META-INF/MANIFEST.MF" ); + File expectedWEBXMLFile = new File( webAppDirectory, "WEB-INF/web.xml" ); + File expectedIncludedWARFile = new File( webAppDirectory, "/org/sample/company/testInclude.jsp" ); + File expectedExcludedWarfile = new File( webAppDirectory, "/org/sample/companyExclude/test.jsp" ); + + assertTrue( "source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists() ); + assertTrue( "source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists() ); + // check include-exclude.war in the unit test dir under resources to verify the list of files + assertTrue( "web xml not found: " + expectedWEBXMLFile.toString(), expectedWEBXMLFile.exists() ); + assertFalse( "manifest file found: " + expectedManifestFile.toString(), expectedManifestFile.exists() ); + assertTrue( "war file not found: " + expectedIncludedWARFile.toString(), expectedIncludedWARFile.exists() ); + assertFalse( "war file not found: " + expectedExcludedWarfile.toString(), expectedExcludedWarfile.exists() ); + + // house keeping + expectedWebSourceFile.delete(); + expectedWebSource2File.delete(); + expectedManifestFile.delete(); + expectedWEBXMLFile.delete(); + expectedIncludedWARFile.delete(); + expectedExcludedWarfile.delete(); + } + + /** + * @throws Exception in case of an error. + */ + public void testExplodedWarWithSourceModificationCheck() + throws Exception + { + // setup test data + String testId = "ExplodedWarWithSourceModificationCheck"; + MavenProjectBasicStub project = new MavenProjectBasicStub(); + File webAppSource = createWebAppSource( testId ); + File classesDir = createClassesDir( testId, false ); + File webAppDirectory = new File( getTestDirectory(), testId ); + + // configure mojo + this.configureMojo( mojo, new LinkedList(), classesDir, webAppSource, webAppDirectory, project ); + + // destination file is already created manually containing an "error" string + // source is newer than the destination file + mojo.execute(); + + // validate operation + + File expectedWEBINFDir = new File( webAppDirectory, "WEB-INF" ); + File expectedMETAINFDir = new File( webAppDirectory, "META-INF" ); + File expectedWebSourceFile = new File( webAppDirectory, "pansit.jsp" ); + File expectedWebSource2File = new File( webAppDirectory, "org/web/app/last-exile.jsp" ); + + assertTrue( "source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists() ); + assertTrue( "source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists() ); + assertTrue( "WEB-INF not found", expectedWEBINFDir.exists() ); + assertTrue( "META-INF not found", expectedMETAINFDir.exists() ); + + // 1st phase destination is older than source + // destination starts with a value of error replaced with a blank source + assertNotEquals( "source files not updated with new copy: " + expectedWebSourceFile.toString(), + "error", FileUtils.fileRead( expectedWebSourceFile ) ); + + // TODO: uncomment when lastModified problem is resolved + // FileWriter writer = new FileWriter(expectedWebSourceFile); + // + // // 2nd phase destination is newer than source + // // destination should not be replaced with an blank source + // writer.write("newdata"); + // mojo.execute(); + // reader = new FileReader(expectedWebSourceFile); + // reader.read(data); + // assertTrue("source file updated with old copy: " + // +expectedWebSourceFile.toString(),String.valueOf(data).equals("newdata") ); } + + // house keeping + expectedWEBINFDir.delete(); + expectedMETAINFDir.delete(); + expectedWebSourceFile.delete(); + expectedWebSource2File.delete(); + } + + /** + * @throws Exception in case of an error. + */ + public void testExplodedWarWithOutputFileNameMapping() + throws Exception + { + // setup test data + String testId = "ExplodedWarWithFileNameMapping"; + MavenProjectArtifactsStub project = new MavenProjectArtifactsStub(); + File webAppDirectory = new File( getTestDirectory(), testId ); + File webAppSource = createWebAppSource( testId ); + File classesDir = createClassesDir( testId, true ); + ArtifactHandler artifactHandler = (ArtifactHandler) lookup( ArtifactHandler.ROLE, "jar" ); + ArtifactStub jarArtifact = new JarArtifactStub( getBasedir(), artifactHandler ); + File jarFile = jarArtifact.getFile(); + + assertTrue( "jar not found: " + jarFile.toString(), jarFile.exists() ); + + // configure mojo + project.addArtifact( jarArtifact ); + mojo.setOutputFileNameMapping( "@{artifactId}@.@{extension}@" ); + this.configureMojo( mojo, new LinkedList(), classesDir, webAppSource, webAppDirectory, project ); + mojo.execute(); + + // validate operation + File expectedWebSourceFile = new File( webAppDirectory, "pansit.jsp" ); + File expectedWebSource2File = new File( webAppDirectory, "org/web/app/last-exile.jsp" ); + // final name form is -. + File expectedJarArtifact = new File( webAppDirectory, "WEB-INF/lib/jarartifact.jar" ); + + assertTrue( "source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists() ); + assertTrue( "source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists() ); + assertTrue( "jar artifact not found: " + expectedJarArtifact.toString(), expectedJarArtifact.exists() ); + + // house keeping + expectedWebSourceFile.delete(); + expectedWebSource2File.delete(); + expectedJarArtifact.delete(); + } + + /** + * @throws Exception in case of an error. + */ + public void testExplodedWarWithOutputFileNameMappingAndDuplicateDependencies() + throws Exception + { + // setup test data + String testId = "ExplodedWarWithFileNameMappingAndDuplicateDependencies"; + MavenProjectArtifactsStub project = new MavenProjectArtifactsStub(); + File webAppDirectory = new File( getTestDirectory(), testId ); + File webAppSource = createWebAppSource( testId ); + File classesDir = createClassesDir( testId, true ); + EJBArtifactStub ejbArtifact = new EJBArtifactStub( getBasedir() ); + EJBArtifactStub ejbArtifactDup = new EJBArtifactStub( getBasedir() ); + File ejbFile = ejbArtifact.getFile(); + + // ejbArtifact has a hard coded file, only one assert is needed + assertTrue( "ejb not found: " + ejbFile.getAbsolutePath(), ejbFile.exists() ); + + // configure mojo + ejbArtifact.setGroupId( "org.sample.ejb" ); + ejbArtifactDup.setGroupId( "org.dup.ejb" ); + project.addArtifact( ejbArtifact ); + project.addArtifact( ejbArtifactDup ); + mojo.setOutputFileNameMapping( "@{artifactId}@.@{extension}@" ); + this.configureMojo( mojo, new LinkedList(), classesDir, webAppSource, webAppDirectory, project ); + mojo.execute(); + + // validate operation + File expectedWebSourceFile = new File( webAppDirectory, "pansit.jsp" ); + File expectedWebSource2File = new File( webAppDirectory, "org/web/app/last-exile.jsp" ); + // final name form is -. + File expectedEJBArtifact = new File( webAppDirectory, "WEB-INF/lib/org.sample.ejb-ejbartifact.jar" ); + File expectedEJBDupArtifact = new File( webAppDirectory, "WEB-INF/lib/org.dup.ejb-ejbartifact.jar" ); + + assertTrue( "source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists() ); + assertTrue( "source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists() ); + assertTrue( "ejb artifact not found: " + expectedEJBArtifact.toString(), expectedEJBArtifact.exists() ); + assertTrue( "ejb dup artifact not found: " + expectedEJBDupArtifact.toString(), expectedEJBDupArtifact.exists() ); + + // house keeping + expectedWebSourceFile.delete(); + expectedWebSource2File.delete(); + expectedEJBArtifact.delete(); + expectedEJBDupArtifact.delete(); + } + + /* --------------------- 2.1 Overlay tests ----------------------------------- */ + + /*---------------------------*/ + +} diff --git a/Java-base/maven-war-plugin/src/src/test/java/org/apache/maven/plugins/war/WarInPlaceMojoTest.java b/Java-base/maven-war-plugin/src/src/test/java/org/apache/maven/plugins/war/WarInPlaceMojoTest.java new file mode 100644 index 000000000..d93433ccd --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/test/java/org/apache/maven/plugins/war/WarInPlaceMojoTest.java @@ -0,0 +1,90 @@ +package org.apache.maven.plugins.war; + +/* + * 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. + */ + +import org.apache.maven.plugins.war.stub.MavenProjectBasicStub; +import org.apache.maven.plugins.war.stub.ResourceStub; + +import java.io.File; +import java.util.LinkedList; + +public class WarInPlaceMojoTest + extends AbstractWarMojoTest +{ + protected static final String pomFilePath = getBasedir() + + "/target/test-classes/unit/warexplodedinplacemojo/plugin-config.xml"; + + protected File getTestDirectory() + throws Exception + { + return new File( getBasedir(), "target/test-classes/unit/warexplodedinplacemojo/test-dir" ); + } + + private WarInPlaceMojo mojo; + + public void setUp() + throws Exception + { + super.setUp(); + + mojo = (WarInPlaceMojo) lookupMojo( "inplace", pomFilePath ); + assertNotNull( mojo ); + } + + public void testEnvironment() + throws Exception + { + // see setUp + } + + public void testSimpleExplodedInplaceWar() + throws Exception + { + // setup test data + String testId = "SimpleExplodedInplaceWar"; + MavenProjectBasicStub project = new MavenProjectBasicStub(); + File webAppSource = createWebAppSource( testId ); + File classesDir = createClassesDir( testId, true ); + File webAppResource = new File( getTestDirectory(), "resources" ); + File sampleResource = new File( webAppResource, "pix/panis_na.jpg" ); + ResourceStub[] resources = new ResourceStub[] { new ResourceStub() }; + + createFile( sampleResource ); + + // configure mojo + resources[0].setDirectory( webAppResource.getAbsolutePath() ); + this.configureMojo( mojo, new LinkedList(), classesDir, webAppSource, null, project ); + setVariableValueToObject( mojo, "webResources", resources ); + mojo.execute(); + + // validate operation + File expectedWebSourceFile = new File( webAppSource, "pansit.jsp" ); + File expectedWebSource2File = new File( webAppSource, "org/web/app/last-exile.jsp" ); + File expectedWebResourceFile = new File( webAppSource, "pix/panis_na.jpg" ); + File expectedWEBINFDir = new File( webAppSource, "WEB-INF" ); + File expectedMETAINFDir = new File( webAppSource, "META-INF" ); + + assertTrue( "source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists() ); + assertTrue( "source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists() ); + assertTrue( "resources doesn't exist: " + expectedWebResourceFile, expectedWebResourceFile.exists() ); + assertTrue( "WEB-INF not found", expectedWEBINFDir.exists() ); + assertTrue( "META-INF not found", expectedMETAINFDir.exists() ); + } +} diff --git a/Java-base/maven-war-plugin/src/src/test/java/org/apache/maven/plugins/war/WarMojoTest.java b/Java-base/maven-war-plugin/src/src/test/java/org/apache/maven/plugins/war/WarMojoTest.java new file mode 100644 index 000000000..7a313ec25 --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/test/java/org/apache/maven/plugins/war/WarMojoTest.java @@ -0,0 +1,535 @@ +package org.apache.maven.plugins.war; + +/* + * 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. + */ + +import java.io.File; +import java.io.IOException; +import java.util.Enumeration; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.Map; +import java.util.jar.JarEntry; +import java.util.jar.JarFile; + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.handler.ArtifactHandler; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugins.war.stub.JarArtifactStub; +import org.apache.maven.plugins.war.stub.MavenProject4CopyConstructor; +import org.apache.maven.plugins.war.stub.MavenProjectArtifactsStub; +import org.apache.maven.plugins.war.stub.ProjectHelperStub; +import org.apache.maven.plugins.war.stub.WarArtifact4CCStub; +import org.codehaus.plexus.util.IOUtil; + +/** + * comprehensive test on buildExplodedWebApp is done on WarExplodedMojoTest + */ +public class WarMojoTest + extends AbstractWarMojoTest +{ + WarMojo mojo; + + private static File pomFile = new File( getBasedir(), + "target/test-classes/unit/warmojotest/plugin-config-primary-artifact.xml" ); + + protected File getTestDirectory() + { + return new File( getBasedir(), "target/test-classes/unit/warmojotest" ); + } + + public void setUp() + throws Exception + { + super.setUp(); + mojo = (WarMojo) lookupMojo( "war", pomFile ); + } + + public void testEnvironment() + throws Exception + { + // see setup + } + + public void testSimpleWar() + throws Exception + { + String testId = "SimpleWar"; + MavenProject4CopyConstructor project = new MavenProject4CopyConstructor(); + String outputDir = getTestDirectory().getAbsolutePath() + "/" + testId + "-output"; + File webAppDirectory = new File( getTestDirectory(), testId ); + WarArtifact4CCStub warArtifact = new WarArtifact4CCStub( getBasedir() ); + String warName = "simple"; + File webAppSource = createWebAppSource( testId ); + File classesDir = createClassesDir( testId, true ); + File xmlSource = createXMLConfigDir( testId, new String[] { "web.xml" } ); + + project.setArtifact( warArtifact ); + this.configureMojo( mojo, new LinkedList(), classesDir, webAppSource, webAppDirectory, project ); + setVariableValueToObject( mojo, "outputDirectory", outputDir ); + setVariableValueToObject( mojo, "warName", warName ); + mojo.setWebXml( new File( xmlSource, "web.xml" ) ); + + mojo.execute(); + + // validate jar file + File expectedJarFile = new File( outputDir, "simple.war" ); + assertJarContent( expectedJarFile, new String[] { "META-INF/MANIFEST.MF", "WEB-INF/web.xml", "pansit.jsp", + "org/web/app/last-exile.jsp", "META-INF/maven/org.apache.maven.plugin.test/maven-war-plugin-test/pom.xml", + "META-INF/maven/org.apache.maven.plugin.test/maven-war-plugin-test/pom.properties" }, new String[] { null, + mojo.getWebXml().toString(), null, null, null, null } ); + } + + public void testSimpleWarPackagingExcludeWithIncludesRegEx() + throws Exception + { + String testId = "SimpleWarPackagingExcludeWithIncludesRegEx"; + MavenProject4CopyConstructor project = new MavenProject4CopyConstructor(); + String outputDir = getTestDirectory().getAbsolutePath() + "/" + testId + "-output"; + File webAppDirectory = new File( getTestDirectory(), testId ); + WarArtifact4CCStub warArtifact = new WarArtifact4CCStub( getBasedir() ); + String warName = "simple"; + File webAppSource = createWebAppSource( testId ); + File classesDir = createClassesDir( testId, true ); + File xmlSource = createXMLConfigDir( testId, new String[] { "web.xml" } ); + + project.setArtifact( warArtifact ); + this.configureMojo( mojo, new LinkedList(), classesDir, webAppSource, webAppDirectory, project ); + setVariableValueToObject( mojo, "outputDirectory", outputDir ); + setVariableValueToObject( mojo, "warName", warName ); + mojo.setWebXml( new File( xmlSource, "web.xml" ) ); + setVariableValueToObject( mojo, "packagingIncludes", "%regex[(.(?!exile))+]" ); +// setVariableValueToObject( mojo, "packagingIncludes", "%regex" ); + + mojo.execute(); + + // validate jar file + File expectedJarFile = new File( outputDir, "simple.war" ); + assertJarContent( expectedJarFile, new String[] { "META-INF/MANIFEST.MF", "WEB-INF/web.xml", "pansit.jsp", + "META-INF/maven/org.apache.maven.plugin.test/maven-war-plugin-test/pom.xml", + "META-INF/maven/org.apache.maven.plugin.test/maven-war-plugin-test/pom.properties" }, new String[] { null, + mojo.getWebXml().toString(), null, null, null, }, new String[] { "org/web/app/last-exile.jsp" } ); + } + + public void testClassifier() + throws Exception + { + String testId = "Classifier"; + MavenProject4CopyConstructor project = new MavenProject4CopyConstructor(); + String outputDir = getTestDirectory().getAbsolutePath() + "/" + testId + "-output"; + File webAppDirectory = new File( getTestDirectory(), testId ); + WarArtifact4CCStub warArtifact = new WarArtifact4CCStub( getBasedir() ); + ProjectHelperStub projectHelper = new ProjectHelperStub(); + String warName = "simple"; + File webAppSource = createWebAppSource( testId ); + File classesDir = createClassesDir( testId, true ); + File xmlSource = createXMLConfigDir( testId, new String[] { "web.xml" } ); + + project.setArtifact( warArtifact ); + this.configureMojo( mojo, new LinkedList(), classesDir, webAppSource, webAppDirectory, project ); + setVariableValueToObject( mojo, "projectHelper", projectHelper ); + setVariableValueToObject( mojo, "classifier", "test-classifier" ); + setVariableValueToObject( mojo, "outputDirectory", outputDir ); + setVariableValueToObject( mojo, "warName", warName ); + mojo.setWebXml( new File( xmlSource, "web.xml" ) ); + + mojo.execute(); + + // validate jar file + File expectedJarFile = new File( outputDir, "simple-test-classifier.war" ); + assertJarContent( expectedJarFile, new String[] { "META-INF/MANIFEST.MF", "WEB-INF/web.xml", "pansit.jsp", + "org/web/app/last-exile.jsp", "META-INF/maven/org.apache.maven.plugin.test/maven-war-plugin-test/pom.xml", + "META-INF/maven/org.apache.maven.plugin.test/maven-war-plugin-test/pom.properties" }, new String[] { null, + mojo.getWebXml().toString(), null, null, null, null } ); + } + + public void testPrimaryArtifact() + throws Exception + { + String testId = "PrimaryArtifact"; + MavenProject4CopyConstructor project = new MavenProject4CopyConstructor(); + String outputDir = getTestDirectory().getAbsolutePath() + "/" + testId + "-output"; + File webAppDirectory = new File( getTestDirectory(), testId ); + WarArtifact4CCStub warArtifact = new WarArtifact4CCStub( getBasedir() ); + ProjectHelperStub projectHelper = new ProjectHelperStub(); + String warName = "simple"; + File webAppSource = createWebAppSource( testId ); + File classesDir = createClassesDir( testId, true ); + File xmlSource = createXMLConfigDir( testId, new String[] { "web.xml" } ); + + warArtifact.setFile( new File( "error.war" ) ); + project.setArtifact( warArtifact ); + this.configureMojo( mojo, new LinkedList(), classesDir, webAppSource, webAppDirectory, project ); + setVariableValueToObject( mojo, "projectHelper", projectHelper ); + setVariableValueToObject( mojo, "outputDirectory", outputDir ); + setVariableValueToObject( mojo, "warName", warName ); + mojo.setWebXml( new File( xmlSource, "web.xml" ) ); + + mojo.execute(); + + // validate jar file + File expectedJarFile = new File( outputDir, "simple.war" ); + assertJarContent( expectedJarFile, new String[] { "META-INF/MANIFEST.MF", "WEB-INF/web.xml", "pansit.jsp", + "org/web/app/last-exile.jsp", "META-INF/maven/org.apache.maven.plugin.test/maven-war-plugin-test/pom.xml", + "META-INF/maven/org.apache.maven.plugin.test/maven-war-plugin-test/pom.properties" }, new String[] { null, + mojo.getWebXml().toString(), null, null, null, null } ); + } + + public void testNotPrimaryArtifact() + throws Exception + { + // use a different pom + File pom = new File( getBasedir(), "target/test-classes/unit/warmojotest/not-primary-artifact.xml" ); + mojo = (WarMojo) lookupMojo( "war", pom ); + + String testId = "NotPrimaryArtifact"; + MavenProject4CopyConstructor project = new MavenProject4CopyConstructor(); + String outputDir = getTestDirectory().getAbsolutePath() + "/" + testId + "-output"; + File webAppDirectory = new File( getTestDirectory(), testId ); + WarArtifact4CCStub warArtifact = new WarArtifact4CCStub( getBasedir() ); + ProjectHelperStub projectHelper = new ProjectHelperStub(); + String warName = "simple"; + File webAppSource = createWebAppSource( testId ); + File classesDir = createClassesDir( testId, true ); + File xmlSource = createXMLConfigDir( testId, new String[] { "web.xml" } ); + + warArtifact.setFile( new File( "error.war" ) ); + project.setArtifact( warArtifact ); + this.configureMojo( mojo, new LinkedList(), classesDir, webAppSource, webAppDirectory, project ); + setVariableValueToObject( mojo, "projectHelper", projectHelper ); + setVariableValueToObject( mojo, "outputDirectory", outputDir ); + setVariableValueToObject( mojo, "warName", warName ); + mojo.setWebXml( new File( xmlSource, "web.xml" ) ); + + mojo.execute(); + + // validate jar file + File expectedJarFile = new File( outputDir, "simple.war" ); + assertJarContent( expectedJarFile, new String[] { "META-INF/MANIFEST.MF", "WEB-INF/web.xml", "pansit.jsp", + "org/web/app/last-exile.jsp", "META-INF/maven/org.apache.maven.plugin.test/maven-war-plugin-test/pom.xml", + "META-INF/maven/org.apache.maven.plugin.test/maven-war-plugin-test/pom.properties" }, new String[] { null, + mojo.getWebXml().toString(), null, null, null, null } ); + } + + public void testMetaInfContent() + throws Exception + { + String testId = "SimpleWarWithMetaInfContent"; + MavenProject4CopyConstructor project = new MavenProject4CopyConstructor(); + String outputDir = getTestDirectory().getAbsolutePath() + "/" + testId + "-output"; + File webAppDirectory = new File( getTestDirectory(), testId ); + WarArtifact4CCStub warArtifact = new WarArtifact4CCStub( getBasedir() ); + String warName = "simple"; + File webAppSource = createWebAppSource( testId ); + File classesDir = createClassesDir( testId, true ); + File xmlSource = createXMLConfigDir( testId, new String[] { "web.xml" } ); + + // Create the sample config.xml + final File configFile = new File( webAppSource, "META-INF/config.xml" ); + createFile( configFile, "" ); + + project.setArtifact( warArtifact ); + this.configureMojo( mojo, new LinkedList(), classesDir, webAppSource, webAppDirectory, project ); + setVariableValueToObject( mojo, "outputDirectory", outputDir ); + setVariableValueToObject( mojo, "warName", warName ); + mojo.setWebXml( new File( xmlSource, "web.xml" ) ); + + mojo.execute(); + + // validate jar file + File expectedJarFile = new File( outputDir, "simple.war" ); + assertJarContent( expectedJarFile, new String[] { "META-INF/MANIFEST.MF", "META-INF/config.xml", + "WEB-INF/web.xml", "pansit.jsp", "org/web/app/last-exile.jsp", + "META-INF/maven/org.apache.maven.plugin.test/maven-war-plugin-test/pom.xml", + "META-INF/maven/org.apache.maven.plugin.test/maven-war-plugin-test/pom.properties" }, new String[] { null, null, + mojo.getWebXml().toString(), null, null, null, null } ); + } + + public void testMetaInfContentWithContainerConfig() + throws Exception + { + String testId = "SimpleWarWithContainerConfig"; + MavenProject4CopyConstructor project = new MavenProject4CopyConstructor(); + String outputDir = getTestDirectory().getAbsolutePath() + "/" + testId + "-output"; + File webAppDirectory = new File( getTestDirectory(), testId ); + WarArtifact4CCStub warArtifact = new WarArtifact4CCStub( getBasedir() ); + String warName = "simple"; + File webAppSource = createWebAppSource( testId ); + File classesDir = createClassesDir( testId, true ); + File xmlSource = createXMLConfigDir( testId, new String[] { "web.xml" } ); + + // Create the sample config.xml + final File configFile = new File( webAppSource, "META-INF/config.xml" ); + createFile( configFile, "" ); + + project.setArtifact( warArtifact ); + this.configureMojo( mojo, new LinkedList(), classesDir, webAppSource, webAppDirectory, project ); + setVariableValueToObject( mojo, "outputDirectory", outputDir ); + setVariableValueToObject( mojo, "warName", warName ); + mojo.setWebXml( new File( xmlSource, "web.xml" ) ); + mojo.setContainerConfigXML( configFile ); + + mojo.execute(); + + // validate jar file + File expectedJarFile = new File( outputDir, "simple.war" ); + assertJarContent( expectedJarFile, new String[] { "META-INF/MANIFEST.MF", "META-INF/config.xml", + "WEB-INF/web.xml", "pansit.jsp", "org/web/app/last-exile.jsp", + "META-INF/maven/org.apache.maven.plugin.test/maven-war-plugin-test/pom.xml", + "META-INF/maven/org.apache.maven.plugin.test/maven-war-plugin-test/pom.properties" }, new String[] { null, null, + mojo.getWebXml().toString(), null, null, null, null } ); + } + + public void testFailOnMissingWebXmlFalse() + throws Exception + { + + String testId = "SimpleWarMissingWebXmlFalse"; + MavenProject4CopyConstructor project = new MavenProject4CopyConstructor(); + String outputDir = getTestDirectory().getAbsolutePath() + "/" + testId + "-output"; + File webAppDirectory = new File( getTestDirectory(), testId ); + WarArtifact4CCStub warArtifact = new WarArtifact4CCStub( getBasedir() ); + String warName = "simple"; + File webAppSource = createWebAppSource( testId ); + File classesDir = createClassesDir( testId, true ); + + project.setArtifact( warArtifact ); + this.configureMojo( mojo, new LinkedList(), classesDir, webAppSource, webAppDirectory, project ); + setVariableValueToObject( mojo, "outputDirectory", outputDir ); + setVariableValueToObject( mojo, "warName", warName ); + mojo.setFailOnMissingWebXml( false ); + mojo.execute(); + + // validate jar file + File expectedJarFile = new File( outputDir, "simple.war" ); + final Map jarContent = + assertJarContent( expectedJarFile, new String[] { "META-INF/MANIFEST.MF", "pansit.jsp", + "org/web/app/last-exile.jsp", "META-INF/maven/org.apache.maven.plugin.test/maven-war-plugin-test/pom.xml", + "META-INF/maven/org.apache.maven.plugin.test/maven-war-plugin-test/pom.properties" }, new String[] { null, null, + null, null, null } ); + + assertFalse( "web.xml should be missing", jarContent.containsKey( "WEB-INF/web.xml" ) ); + } + + public void testFailOnMissingWebXmlTrue() + throws Exception + { + + String testId = "SimpleWarMissingWebXmlTrue"; + MavenProject4CopyConstructor project = new MavenProject4CopyConstructor(); + String outputDir = getTestDirectory().getAbsolutePath() + "/" + testId + "-output"; + File webAppDirectory = new File( getTestDirectory(), testId ); + WarArtifact4CCStub warArtifact = new WarArtifact4CCStub( getBasedir() ); + String warName = "simple"; + File webAppSource = createWebAppSource( testId ); + File classesDir = createClassesDir( testId, true ); + + project.setArtifact( warArtifact ); + this.configureMojo( mojo, new LinkedList(), classesDir, webAppSource, webAppDirectory, project ); + setVariableValueToObject( mojo, "outputDirectory", outputDir ); + setVariableValueToObject( mojo, "warName", warName ); + mojo.setFailOnMissingWebXml( true ); + + try + { + mojo.execute(); + fail( "Building of the war isn't possible because web.xml is missing" ); + } + catch ( MojoExecutionException e ) + { + // expected behaviour + } + } + + public void testFailOnMissingWebXmlNotSpecifiedAndServlet30Used() + throws Exception + { + String testId = "SimpleWarUnderServlet30"; + MavenProjectArtifactsStub project = new MavenProjectArtifactsStub(); + String outputDir = getTestDirectory().getAbsolutePath() + "/" + testId + "-output"; + File webAppDirectory = new File( getTestDirectory(), testId ); + WarArtifact4CCStub warArtifact = new WarArtifact4CCStub( getBasedir() ); + String warName = "simple"; + File webAppSource = createWebAppSource( testId ); + File classesDir = createClassesDir( testId, true ); + + final ArtifactHandler artifactHandler = (ArtifactHandler) lookup( ArtifactHandler.ROLE, "jar" ); + JarArtifactStub jarArtifactStub = new JarArtifactStub( getBasedir(), artifactHandler ); + jarArtifactStub.setFile( new File( getBasedir(), + "/target/test-classes/unit/sample_wars/javax.servlet-api-3.0.1.jar" ) ); + jarArtifactStub.setScope( Artifact.SCOPE_PROVIDED ); + project.addArtifact( jarArtifactStub ); + + project.setArtifact( warArtifact ); + project.setFile( warArtifact.getFile() ); + this.configureMojo( mojo, new LinkedList(), classesDir, webAppSource, webAppDirectory, project ); + setVariableValueToObject( mojo, "outputDirectory", outputDir ); + setVariableValueToObject( mojo, "warName", warName ); + + mojo.execute(); + + // validate war file + File expectedWarFile = new File( outputDir, "simple.war" ); + final Map jarContent = + assertJarContent( expectedWarFile, + new String[] { "META-INF/MANIFEST.MF", "pansit.jsp", "org/web/app/last-exile.jsp", + "META-INF/maven/org.apache.maven.plugin.test/maven-war-plugin-test/pom.xml", + "META-INF/maven/org.apache.maven.plugin.test/maven-war-plugin-test/pom.properties" }, + new String[] { null, null, null, null, null } ); + + assertFalse( "web.xml should be missing", jarContent.containsKey( "WEB-INF/web.xml" ) ); + } + + public void testFailOnMissingWebXmlNotSpecifiedAndServlet30NotUsed() + throws Exception + { + String testId = "SimpleWarNotUnderServlet30"; + MavenProjectArtifactsStub project = new MavenProjectArtifactsStub(); + String outputDir = getTestDirectory().getAbsolutePath() + "/" + testId + "-output"; + File webAppDirectory = new File( getTestDirectory(), testId ); + WarArtifact4CCStub warArtifact = new WarArtifact4CCStub( getBasedir() ); + String warName = "simple"; + File webAppSource = createWebAppSource( testId ); + File classesDir = createClassesDir( testId, true ); + + project.setArtifact( warArtifact ); + project.setFile( warArtifact.getFile() ); + this.configureMojo( mojo, new LinkedList(), classesDir, webAppSource, webAppDirectory, project ); + setVariableValueToObject( mojo, "outputDirectory", outputDir ); + setVariableValueToObject( mojo, "warName", warName ); + + try + { + mojo.execute(); + fail( "Building of the war isn't possible because no 'failOnMissingWebXml' policy was set and the project " + + "does not depend on Servlet 3.0" ); + } + catch ( MojoExecutionException e ) + { + // expected behaviour + } + } + + public void testAttachClasses() + throws Exception + { + String testId = "AttachClasses"; + MavenProject4CopyConstructor project = new MavenProject4CopyConstructor(); + String outputDir = getTestDirectory().getAbsolutePath() + "/" + testId + "-output"; + File webAppDirectory = new File( getTestDirectory(), testId ); + WarArtifact4CCStub warArtifact = new WarArtifact4CCStub( getBasedir() ); + String warName = "simple"; + File webAppSource = createWebAppSource( testId ); + File classesDir = createClassesDir( testId, false ); + File xmlSource = createXMLConfigDir( testId, new String[] { "web.xml" } ); + + project.setArtifact( warArtifact ); + this.configureMojo( mojo, new LinkedList(), classesDir, webAppSource, webAppDirectory, project ); + setVariableValueToObject( mojo, "outputDirectory", outputDir ); + setVariableValueToObject( mojo, "warName", warName ); + mojo.setWebXml( new File( xmlSource, "web.xml" ) ); + mojo.setAttachClasses( true ); + mojo.setClassesClassifier( "classes" ); + + mojo.execute(); + + // validate jar file + File expectedJarFile = new File( outputDir, "simple-classes.jar" ); + assertJarContent( expectedJarFile, new String[] { "META-INF/MANIFEST.MF", "sample-servlet.class" }, + new String[] { null, null } ); + } + + public void testAttachClassesWithCustomClassifier() + throws Exception + { + String testId = "AttachClassesCustomClassifier"; + MavenProject4CopyConstructor project = new MavenProject4CopyConstructor(); + String outputDir = getTestDirectory().getAbsolutePath() + "/" + testId + "-output"; + File webAppDirectory = new File( getTestDirectory(), testId ); + WarArtifact4CCStub warArtifact = new WarArtifact4CCStub( getBasedir() ); + String warName = "simple"; + File webAppSource = createWebAppSource( testId ); + File classesDir = createClassesDir( testId, false ); + File xmlSource = createXMLConfigDir( testId, new String[] { "web.xml" } ); + + project.setArtifact( warArtifact ); + this.configureMojo( mojo, new LinkedList(), classesDir, webAppSource, webAppDirectory, project ); + setVariableValueToObject( mojo, "outputDirectory", outputDir ); + setVariableValueToObject( mojo, "warName", warName ); + mojo.setWebXml( new File( xmlSource, "web.xml" ) ); + mojo.setAttachClasses( true ); + mojo.setClassesClassifier( "mystuff" ); + + mojo.execute(); + + // validate jar file + File expectedJarFile = new File( outputDir, "simple-mystuff.jar" ); + assertJarContent( expectedJarFile, new String[] { "META-INF/MANIFEST.MF", "sample-servlet.class" }, + new String[] { null, null } ); + } + + protected Map assertJarContent( final File expectedJarFile, final String[] files, + final String[] filesContent ) + throws IOException + { + return assertJarContent( expectedJarFile, files, filesContent, null ); + } + + protected Map assertJarContent( final File expectedJarFile, final String[] files, + final String[] filesContent, final String[] mustNotBeInJar ) + throws IOException + { + // Sanity check + assertEquals( "Could not test, files and filesContent length does not match", files.length, filesContent.length ); + + assertTrue( "war file not created: " + expectedJarFile.toString(), expectedJarFile.exists() ); + final Map jarContent = new HashMap<>(); + try ( JarFile jarFile = new JarFile( expectedJarFile ) ) { + Enumeration enumeration = jarFile.entries(); + while ( enumeration.hasMoreElements() ) + { + JarEntry entry = enumeration.nextElement(); + Object previousValue = jarContent.put( entry.getName(), entry ); + assertNull( "Duplicate Entry in Jar File: " + entry.getName(), previousValue ); + } + + for ( int i = 0; i < files.length; i++ ) + { + String file = files[i]; + + assertTrue( "File[" + file + "] not found in archive", jarContent.containsKey( file ) ); + if ( filesContent[i] != null ) + { + assertEquals( "Content of file[" + file + "] does not match", filesContent[i], + IOUtil.toString( jarFile.getInputStream( jarContent.get( file ) ) ) ); + } + } + if ( mustNotBeInJar != null ) + { + for ( String file : mustNotBeInJar ) + { + assertFalse( "File[" + file + "] found in archive", jarContent.containsKey( file ) ); + + } + } + return jarContent; + } + } + +} diff --git a/Java-base/maven-war-plugin/src/src/test/java/org/apache/maven/plugins/war/WarOverlaysTest.java b/Java-base/maven-war-plugin/src/src/test/java/org/apache/maven/plugins/war/WarOverlaysTest.java new file mode 100644 index 000000000..557357417 --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/test/java/org/apache/maven/plugins/war/WarOverlaysTest.java @@ -0,0 +1,494 @@ +package org.apache.maven.plugins.war; + +/* + * 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. + */ + +import org.apache.maven.plugin.testing.stubs.ArtifactStub; +import org.apache.maven.plugins.war.overlay.DefaultOverlay; +import org.codehaus.plexus.util.FileUtils; + +import java.io.File; +import java.io.FileFilter; +import java.io.IOException; +import java.util.ArrayList; +import java.util.LinkedList; +import java.util.List; + +/** + * @author Stephane Nicoll + */ +public class WarOverlaysTest + extends AbstractWarExplodedMojoTest +{ + + private static File pomFile = new File( getBasedir(), "target/test-classes/unit/waroverlays/default.xml" ); + + public void setUp() + throws Exception + { + super.setUp(); + generateFullOverlayWar( "overlay-full-1" ); + generateFullOverlayWar( "overlay-full-2" ); + generateFullOverlayWar( "overlay-full-3" ); + } + + protected File getPomFile() + { + return pomFile; + } + + protected File getTestDirectory() + { + return new File( getBasedir(), "target/test-classes/unit/waroverlays" ); + } + + public void testEnvironment() + throws Exception + { + // see setup + } + + public void testNoOverlay() + throws Exception + { + // setup test data + final String testId = "no-overlay"; + final File xmlSource = createXMLConfigDir( testId, new String[] { "web.xml" } ); + + final File webAppDirectory = setUpMojo( testId, null ); + try + { + mojo.setWebXml( new File( xmlSource, "web.xml" ) ); + mojo.execute(); + + // Validate content of the webapp + assertDefaultContent( webAppDirectory ); + assertWebXml( webAppDirectory ); + } + finally + { + cleanDirectory( webAppDirectory ); + } + } + + public void testDefaultOverlay() + throws Exception + { + // setup test data + final String testId = "default-overlay"; + + // Add an overlay + final ArtifactStub overlay = buildWarOverlayStub( "overlay-one" ); + + final File webAppDirectory = setUpMojo( testId, new ArtifactStub[] { overlay } ); + final List assertedFiles = new ArrayList<>(); + try + { + mojo.execute(); + assertedFiles.addAll( assertDefaultContent( webAppDirectory ) ); + assertedFiles.addAll( assertWebXml( webAppDirectory ) ); + assertedFiles.addAll( assertCustomContent( webAppDirectory, new String[] { "index.jsp", "login.jsp" }, + "overlay file not found" ) ); + + // index and login come from overlay1 + assertOverlayedFile( webAppDirectory, "overlay-one", "index.jsp" ); + assertOverlayedFile( webAppDirectory, "overlay-one", "login.jsp" ); + + // Ok now check that there is no more files/directories + final FileFilter filter = new FileFilterImpl( webAppDirectory, new String[] { MANIFEST_PATH } ); + assertWebAppContent( webAppDirectory, assertedFiles, filter ); + } + finally + { + cleanDirectory( webAppDirectory ); + } + } + + public void testDefaultOverlays() + throws Exception + { + // setup test data + final String testId = "default-overlays"; + + // Add an overlay + final ArtifactStub overlay = buildWarOverlayStub( "overlay-one" ); + final ArtifactStub overlay2 = buildWarOverlayStub( "overlay-two" ); + + final File webAppDirectory = setUpMojo( testId, new ArtifactStub[] { overlay, overlay2 } ); + final List assertedFiles = new ArrayList<>(); + try + { + mojo.execute(); + assertedFiles.addAll( assertDefaultContent( webAppDirectory ) ); + assertedFiles.addAll( assertWebXml( webAppDirectory ) ); + assertedFiles.addAll( assertCustomContent( webAppDirectory, new String[] { "index.jsp", "login.jsp", + "admin.jsp" }, "overlay file not found" ) ); + + // index and login come from overlay1 + assertOverlayedFile( webAppDirectory, "overlay-one", "index.jsp" ); + assertOverlayedFile( webAppDirectory, "overlay-one", "login.jsp" ); + + // admin comes from overlay2 + // index and login comes from overlay1 + assertOverlayedFile( webAppDirectory, "overlay-two", "admin.jsp" ); + + // Ok now check that there is no more files/directories + final FileFilter filter = new FileFilterImpl( webAppDirectory, new String[] { MANIFEST_PATH } ); + assertWebAppContent( webAppDirectory, assertedFiles, filter ); + } + finally + { + cleanDirectory( webAppDirectory ); + } + } + + /** + * Merge a dependent WAR when a file in the war source directory overrides one found in the WAR. + * + * It also tests completeness of the resulting war as well as the proper order of dependencies. + * + * @throws Exception if any error occurs + */ + public void testScenarioOneWithDefaulSettings() + throws Exception + { + // setup test data + final String testId = "scenario-one-default-settings"; + + // Add an overlay + final ArtifactStub overlay1 = buildWarOverlayStub( "overlay-full-1" ); + final ArtifactStub overlay2 = buildWarOverlayStub( "overlay-full-2" ); + final ArtifactStub overlay3 = buildWarOverlayStub( "overlay-full-3" ); + + final File webAppDirectory = + setUpMojo( testId, new ArtifactStub[] { overlay1, overlay2, overlay3 }, new String[] { + "org/sample/company/test.jsp", "jsp/b.jsp" } ); + + assertScenariOne( testId, webAppDirectory ); + } + + /** + * Tests that specifying the overlay explicitely has the same behavior as the default (i.e. order, etc). + * + * The default project is not specified in this case so it is processed first by default + * + * @throws Exception if an error occurs + */ + public void testScenarioOneWithOverlaySettings() + throws Exception + { + // setup test data + final String testId = "scenario-one-overlay-settings"; + + // Add an overlay + final ArtifactStub overlay1 = buildWarOverlayStub( "overlay-full-1" ); + final ArtifactStub overlay2 = buildWarOverlayStub( "overlay-full-2" ); + final ArtifactStub overlay3 = buildWarOverlayStub( "overlay-full-3" ); + + final File webAppDirectory = + setUpMojo( testId, new ArtifactStub[] { overlay1, overlay2, overlay3 }, new String[] { + "org/sample/company/test.jsp", "jsp/b.jsp" } ); + + // Add the tags + final List overlays = new ArrayList<>(); + overlays.add( new DefaultOverlay( overlay1 ) ); + overlays.add( new DefaultOverlay( overlay2 ) ); + overlays.add( new DefaultOverlay( overlay3 ) ); + mojo.setOverlays( overlays ); + + // current project ignored. Should be on top of the list + assertScenariOne( testId, webAppDirectory ); + } + + /** + * Tests that specifying the overlay explicitely has the same behavior as the default (i.e. order, etc). + * + * The default project is explicitely specified so this should match the default. + * + * @throws Exception if an error occurs + */ + public void testScenarioOneWithFullSettings() + throws Exception + { + // setup test data + final String testId = "scenario-one-full-settings"; + + // Add an overlay + final ArtifactStub overlay1 = buildWarOverlayStub( "overlay-full-1" ); + final ArtifactStub overlay2 = buildWarOverlayStub( "overlay-full-2" ); + final ArtifactStub overlay3 = buildWarOverlayStub( "overlay-full-3" ); + + final File webAppDirectory = + setUpMojo( testId, new ArtifactStub[] { overlay1, overlay2, overlay3 }, new String[] { + "org/sample/company/test.jsp", "jsp/b.jsp" } ); + + // Add the tags + final List overlays = new ArrayList<>(); + + // Add the default project explicitely + overlays.add( mojo.getCurrentProjectOverlay() ); + + // Other overlays + overlays.add( new DefaultOverlay( overlay1 ) ); + overlays.add( new DefaultOverlay( overlay2 ) ); + overlays.add( new DefaultOverlay( overlay3 ) ); + mojo.setOverlays( overlays ); + + // current project ignored. Should be on top of the list + assertScenariOne( testId, webAppDirectory ); + } + + /** + * Runs the mojo and asserts a scenerio with 3 overlays and no includes/excludes settings. + * + * @param testId thie id of the test + * @param webAppDirectory the webapp directory + * @throws Exception if an exception occurs + */ + private void assertScenariOne( String testId, File webAppDirectory ) + throws Exception + { + final List assertedFiles = new ArrayList<>(); + try + { + mojo.execute(); + assertedFiles.addAll( assertWebXml( webAppDirectory ) ); + assertedFiles.addAll( assertCustomContent( webAppDirectory, new String[] { "jsp/a.jsp", "jsp/b.jsp", + "jsp/c.jsp", "jsp/d/a.jsp", "jsp/d/b.jsp", "jsp/d/c.jsp", "org/sample/company/test.jsp", + "WEB-INF/classes/a.class", "WEB-INF/classes/b.class", "WEB-INF/classes/c.class", "WEB-INF/lib/a.jar", + "WEB-INF/lib/b.jar", "WEB-INF/lib/c.jar" }, "overlay file not found" ) ); + + // Those files should come from the source webapp without any config + assertDefaultFileContent( testId, webAppDirectory, "jsp/b.jsp" ); + assertDefaultFileContent( testId, webAppDirectory, "org/sample/company/test.jsp" ); + + // Everything else comes from overlay1 (order of addition in the dependencies) + assertOverlayedFile( webAppDirectory, "overlay-full-1", "jsp/a.jsp" ); + assertOverlayedFile( webAppDirectory, "overlay-full-1", "jsp/c.jsp" ); + assertOverlayedFile( webAppDirectory, "overlay-full-1", "jsp/d/a.jsp" ); + assertOverlayedFile( webAppDirectory, "overlay-full-1", "jsp/d/b.jsp" ); + assertOverlayedFile( webAppDirectory, "overlay-full-1", "jsp/d/c.jsp" ); + assertOverlayedFile( webAppDirectory, "overlay-full-1", "WEB-INF/web.xml" ); + assertOverlayedFile( webAppDirectory, "overlay-full-1", "WEB-INF/classes/a.class" ); + assertOverlayedFile( webAppDirectory, "overlay-full-1", "WEB-INF/classes/b.class" ); + assertOverlayedFile( webAppDirectory, "overlay-full-1", "WEB-INF/classes/c.class" ); + assertOverlayedFile( webAppDirectory, "overlay-full-1", "WEB-INF/lib/a.jar" ); + assertOverlayedFile( webAppDirectory, "overlay-full-1", "WEB-INF/lib/b.jar" ); + assertOverlayedFile( webAppDirectory, "overlay-full-1", "WEB-INF/lib/c.jar" ); + + // Ok now check that there is no more files/directories + final FileFilter filter = new FileFilterImpl( webAppDirectory, new String[] { MANIFEST_PATH } ); + assertWebAppContent( webAppDirectory, assertedFiles, filter ); + } + finally + { + cleanDirectory( webAppDirectory ); + } + } + + public void testOverlaysIncludesExcludesWithMultipleDefinitions() + throws Exception + { + // setup test data + final String testId = "overlays-includes-excludes-multiple-defs"; + + // Add an overlay + final ArtifactStub overlay1 = buildWarOverlayStub( "overlay-full-1" ); + final ArtifactStub overlay2 = buildWarOverlayStub( "overlay-full-2" ); + final ArtifactStub overlay3 = buildWarOverlayStub( "overlay-full-3" ); + + final File webAppDirectory = + setUpMojo( testId, new ArtifactStub[] { overlay1, overlay2, overlay3 }, new String[] { + "org/sample/company/test.jsp", "jsp/b.jsp" } ); + + Overlay over1 = new DefaultOverlay( overlay3 ); + over1.setExcludes( "**/a.*,**/c.*,**/*.xml" ); + + Overlay over2 = new DefaultOverlay( overlay1 ); + over2.setIncludes( "jsp/d/*" ); + over2.setExcludes( "jsp/d/a.jsp" ); + + Overlay over3 = new DefaultOverlay( overlay3 ); + over3.setIncludes( "**/*.jsp" ); + + Overlay over4 = new DefaultOverlay( overlay2 ); + + mojo.setOverlays( new LinkedList() ); + mojo.addOverlay( over1 ); + mojo.addOverlay( over2 ); + mojo.addOverlay( over3 ); + mojo.addOverlay( mojo.getCurrentProjectOverlay() ); + mojo.addOverlay( over4 ); + + final List assertedFiles = new ArrayList<>(); + try + { + mojo.execute(); + assertedFiles.addAll( assertWebXml( webAppDirectory ) ); + assertedFiles.addAll( assertCustomContent( webAppDirectory, new String[] { "jsp/a.jsp", "jsp/b.jsp", + "jsp/c.jsp", "jsp/d/a.jsp", "jsp/d/b.jsp", "jsp/d/c.jsp", "org/sample/company/test.jsp", + "WEB-INF/classes/a.class", "WEB-INF/classes/b.class", "WEB-INF/classes/c.class", "WEB-INF/lib/a.jar", + "WEB-INF/lib/b.jar", "WEB-INF/lib/c.jar" }, "overlay file not found" ) ); + + assertOverlayedFile( webAppDirectory, "overlay-full-3", "jsp/a.jsp" ); + assertOverlayedFile( webAppDirectory, "overlay-full-3", "jsp/b.jsp" ); + assertOverlayedFile( webAppDirectory, "overlay-full-3", "jsp/c.jsp" ); + assertOverlayedFile( webAppDirectory, "overlay-full-3", "jsp/d/a.jsp" ); + assertOverlayedFile( webAppDirectory, "overlay-full-3", "jsp/d/b.jsp" ); + assertOverlayedFile( webAppDirectory, "overlay-full-1", "jsp/d/c.jsp" ); + assertDefaultFileContent( testId, webAppDirectory, "org/sample/company/test.jsp" ); + assertOverlayedFile( webAppDirectory, "overlay-full-2", "WEB-INF/web.xml" ); + assertOverlayedFile( webAppDirectory, "overlay-full-2", "WEB-INF/classes/a.class" ); + assertOverlayedFile( webAppDirectory, "overlay-full-3", "WEB-INF/classes/b.class" ); + assertOverlayedFile( webAppDirectory, "overlay-full-2", "WEB-INF/classes/c.class" ); + assertOverlayedFile( webAppDirectory, "overlay-full-2", "WEB-INF/lib/a.jar" ); + assertOverlayedFile( webAppDirectory, "overlay-full-3", "WEB-INF/lib/b.jar" ); + assertOverlayedFile( webAppDirectory, "overlay-full-2", "WEB-INF/lib/c.jar" ); + + // Ok now check that there is no more files/directories + final FileFilter filter = new FileFilterImpl( webAppDirectory, new String[] { MANIFEST_PATH } ); + assertWebAppContent( webAppDirectory, assertedFiles, filter ); + } + finally + { + cleanDirectory( webAppDirectory ); + } + } + + public void testOverlaysIncludesExcludesWithMultipleDefinitions2() + throws Exception + { + // setup test data + final String testId = "overlays-includes-excludes-multiple-defs2"; + + // Add an overlay + final ArtifactStub overlay1 = buildWarOverlayStub( "overlay-full-1" ); + final ArtifactStub overlay2 = buildWarOverlayStub( "overlay-full-2" ); + final ArtifactStub overlay3 = buildWarOverlayStub( "overlay-full-3" ); + + final File webAppDirectory = + setUpMojo( testId, new ArtifactStub[] { overlay1, overlay2, overlay3 }, new String[] { + "org/sample/company/test.jsp", "jsp/b.jsp" } ); + + Overlay over1 = new DefaultOverlay( overlay3 ); + over1.setExcludes( "**/a.*,**/c.*,**/*.xml,jsp/b.jsp" ); + + Overlay over2 = new DefaultOverlay( overlay1 ); + over2.setIncludes( "jsp/d/*" ); + over2.setExcludes( "jsp/d/a.jsp" ); + + Overlay over3 = new DefaultOverlay( overlay3 ); + over3.setIncludes( "**/*.jsp" ); + over3.setExcludes( "jsp/b.jsp" ); + + Overlay over4 = new DefaultOverlay( overlay2 ); + + mojo.setOverlays( new LinkedList() ); + mojo.addOverlay( over1 ); + mojo.addOverlay( over2 ); + mojo.addOverlay( over3 ); + mojo.addOverlay( mojo.getCurrentProjectOverlay() ); + mojo.addOverlay( over4 ); + + final List assertedFiles = new ArrayList<>(); + try + { + mojo.execute(); + assertedFiles.addAll( assertWebXml( webAppDirectory ) ); + assertedFiles.addAll( assertCustomContent( webAppDirectory, new String[] { "jsp/a.jsp", "jsp/b.jsp", + "jsp/c.jsp", "jsp/d/a.jsp", "jsp/d/b.jsp", "jsp/d/c.jsp", "org/sample/company/test.jsp", + "WEB-INF/classes/a.class", "WEB-INF/classes/b.class", "WEB-INF/classes/c.class", "WEB-INF/lib/a.jar", + "WEB-INF/lib/b.jar", "WEB-INF/lib/c.jar" }, "overlay file not found" ) ); + + assertOverlayedFile( webAppDirectory, "overlay-full-3", "jsp/a.jsp" ); + assertDefaultFileContent( testId, webAppDirectory, "jsp/b.jsp" ); + assertOverlayedFile( webAppDirectory, "overlay-full-3", "jsp/c.jsp" ); + assertOverlayedFile( webAppDirectory, "overlay-full-3", "jsp/d/a.jsp" ); + assertOverlayedFile( webAppDirectory, "overlay-full-3", "jsp/d/b.jsp" ); + assertOverlayedFile( webAppDirectory, "overlay-full-1", "jsp/d/c.jsp" ); + assertDefaultFileContent( testId, webAppDirectory, "org/sample/company/test.jsp" ); + assertOverlayedFile( webAppDirectory, "overlay-full-2", "WEB-INF/web.xml" ); + assertOverlayedFile( webAppDirectory, "overlay-full-2", "WEB-INF/classes/a.class" ); + assertOverlayedFile( webAppDirectory, "overlay-full-3", "WEB-INF/classes/b.class" ); + assertOverlayedFile( webAppDirectory, "overlay-full-2", "WEB-INF/classes/c.class" ); + assertOverlayedFile( webAppDirectory, "overlay-full-2", "WEB-INF/lib/a.jar" ); + assertOverlayedFile( webAppDirectory, "overlay-full-3", "WEB-INF/lib/b.jar" ); + assertOverlayedFile( webAppDirectory, "overlay-full-2", "WEB-INF/lib/c.jar" ); + + // Ok now check that there is no more files/directories + final FileFilter filter = new FileFilterImpl( webAppDirectory, new String[] { MANIFEST_PATH } ); + assertWebAppContent( webAppDirectory, assertedFiles, filter ); + } + finally + { + cleanDirectory( webAppDirectory ); + } + + } + + // Helpers + + /** + * Asserts that the content of an overlayed file is correct. + * + * Note that the filePath is relative to both the webapp directory and the overlayed directory, defined by + * the overlayId. + * + * @param webAppDirectory the webapp directory + * @param overlayId the id of the overlay + * @param filePath the relative path + * @throws IOException if an error occurred while reading the files + */ + protected void assertOverlayedFile( File webAppDirectory, String overlayId, String filePath ) + throws IOException + { + final File webAppFile = new File( webAppDirectory, filePath ); + final File overlayFile = getOverlayFile( overlayId, filePath ); + assertEquals( "Wrong content for overlayed file " + filePath, FileUtils.fileRead( overlayFile ), + FileUtils.fileRead( webAppFile ) ); + + } + + /** + * Asserts that the content of an overlayed file is correct. + * + * Note that the filePath is relative to both the webapp directory and the overlayed directory, defined by + * the overlayId. + * + * @param testId te id of the test + * @param webAppDirectory the webapp directory + * @param filePath the relative path + * @throws IOException if an error occurred while reading the files + */ + protected void assertDefaultFileContent( String testId, File webAppDirectory, String filePath ) + throws Exception + { + final File webAppFile = new File( webAppDirectory, filePath ); + final File sourceFile = new File( getWebAppSource( testId ), filePath ); + final String expectedContent = sourceFile.toString(); + assertEquals( "Wrong content for file " + filePath, expectedContent, FileUtils.fileRead( webAppFile ) ); + + } + + protected ArtifactStub generateSimpleWarArtifactStub( String id ) + throws Exception + { + return buildWarOverlayStub( id ); + } +} \ No newline at end of file diff --git a/Java-base/maven-war-plugin/src/src/test/java/org/apache/maven/plugins/war/WarZipTest.java b/Java-base/maven-war-plugin/src/src/test/java/org/apache/maven/plugins/war/WarZipTest.java new file mode 100644 index 000000000..88f665533 --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/test/java/org/apache/maven/plugins/war/WarZipTest.java @@ -0,0 +1,182 @@ +package org.apache.maven.plugins.war; + +/* + * 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. + */ + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.handler.ArtifactHandler; +import org.apache.maven.plugins.war.overlay.DefaultOverlay; +import org.apache.maven.plugins.war.stub.MavenZipProject; +import org.apache.maven.plugins.war.stub.WarArtifactStub; +import org.apache.maven.plugins.war.stub.ZipArtifactStub; +import org.codehaus.plexus.util.FileUtils; + +import java.io.File; +import java.util.LinkedList; + +/** + * @author Olivier Lamy + * @since 7 Oct 07 + */ +public class WarZipTest + extends AbstractWarMojoTest +{ + WarMojo mojo; + + private static File pomFile = new File( getBasedir(), "src/test/resources/unit/warziptest/war-with-zip.xml" ); + + protected File getTestDirectory() + { + return new File( getBasedir(), "target/test-classes/unit/warziptest" ); + } + + public void setUp() + throws Exception + { + super.setUp(); + mojo = (WarMojo) lookupMojo( "war", pomFile ); + } + + private Artifact buildZipArtifact() + throws Exception + { + ArtifactHandler artifactHandler = (ArtifactHandler) lookup( ArtifactHandler.ROLE, "jar" ); + File zipFile = new File( getTestDirectory(), "foobar.zip" ); + return new ZipArtifactStub( "src/test/resources/unit/warziptest", artifactHandler, zipFile ); + } + + private File configureMojo( String testId ) + throws Exception + { + MavenZipProject project = new MavenZipProject(); + String outputDir = getTestDirectory().getAbsolutePath() + File.separatorChar + testId + "-output"; + // clean up + File outputDirFile = new File( outputDir ); + if ( outputDirFile.exists() ) + { + FileUtils.deleteDirectory( outputDirFile ); + } + File webAppDirectory = new File( getTestDirectory(), testId ); + WarArtifactStub warArtifact = new WarArtifactStub( getBasedir() ); + String warName = "simple"; + File webAppSource = createWebAppSource( testId ); + File classesDir = createClassesDir( testId, true ); + File xmlSource = createXMLConfigDir( testId, new String[] { "web.xml" } ); + project.setArtifact( warArtifact ); + + this.configureMojo( mojo, new LinkedList(), classesDir, webAppSource, webAppDirectory, project ); + setVariableValueToObject( mojo, "outputDirectory", outputDir ); + setVariableValueToObject( mojo, "warName", warName ); + setVariableValueToObject( mojo, "workDirectory", new File( getTestDirectory(), "work" ) ); + mojo.setWebXml( new File( xmlSource, "web.xml" ) ); + + project.getArtifacts().add( buildZipArtifact() ); + + return webAppDirectory; + } + + public void testOneZipWithNoSkip() + throws Exception + { + File webAppDirectory = configureMojo( "one-zip" ); + + Overlay overlay = new DefaultOverlay( buildZipArtifact() ); + // overlay.setSkip( false ); + overlay.setType( "zip" ); + mojo.addOverlay( overlay ); + mojo.execute(); + + File foo = new File( webAppDirectory, "foo.txt" ); + assertTrue( "foo.txt not exists", foo.exists() ); + assertTrue( "foo.txt not a file", foo.isFile() ); + + File barDirectory = new File( webAppDirectory, "bar" ); + assertTrue( "bar directory not exists", barDirectory.exists() ); + assertTrue( "bar not a directory", barDirectory.isDirectory() ); + + File bar = new File( barDirectory, "bar.txt" ); + assertTrue( "bar/bar.txt not exists", bar.exists() ); + assertTrue( "bar/bar.txt not a file", bar.isFile() ); + } + + public void testOneZipWithTargetPathOverlay() + throws Exception + { + File webAppDirectory = configureMojo( "one-zip-overlay-targetPath" ); + + Overlay overlay = new DefaultOverlay( buildZipArtifact() ); + overlay.setSkip( false ); + overlay.setType( "zip" ); + overlay.setTargetPath( "overridePath" ); + mojo.addOverlay( overlay ); + + mojo.execute(); + + File foo = new File( webAppDirectory.getPath() + File.separatorChar + "overridePath", "foo.txt" ); + assertTrue( "foo.txt not exists", foo.exists() ); + assertTrue( "foo.txt not a file", foo.isFile() ); + + File barDirectory = new File( webAppDirectory.getPath() + File.separatorChar + "overridePath", "bar" ); + assertTrue( "bar directory not exists", barDirectory.exists() ); + assertTrue( "bar not a directory", barDirectory.isDirectory() ); + + File bar = new File( barDirectory, "bar.txt" ); + assertTrue( "bar/bar.txt not exists", bar.exists() ); + assertTrue( "bar/bar.txt not a file", bar.isFile() ); + } + + public void testOneZipDefaultSkip() + throws Exception + { + File webAppDirectory = configureMojo( "one-zip-overlay-skip" ); + + mojo.execute(); + + assertZipContentNotHere( webAppDirectory ); + } + + public void testOneZipWithForceSkip() + throws Exception + { + File webAppDirectory = configureMojo( "one-zip-overlay-skip" ); + Overlay overlay = new DefaultOverlay( buildZipArtifact() ); + overlay.setSkip( true ); + overlay.setType( "zip" ); + mojo.addOverlay( overlay ); + + mojo.execute(); + assertZipContentNotHere( webAppDirectory ); + + } + + protected void assertZipContentNotHere( File webAppDirectory ) + { + File foo = new File( webAppDirectory.getPath() + File.separatorChar + "overridePath", "foo.txt" ); + assertFalse( "foo.txt exists", foo.exists() ); + assertFalse( "foo.txt a file", foo.isFile() ); + + File barDirectory = new File( webAppDirectory.getPath() + File.separatorChar + "overridePath", "bar" ); + assertFalse( "bar directory exists", barDirectory.exists() ); + assertFalse( "bar is a directory", barDirectory.isDirectory() ); + + File bar = new File( barDirectory, "bar.txt" ); + assertFalse( "bar/bar.txt exists", bar.exists() ); + assertFalse( "bar/bar.txt is a file", bar.isFile() ); + } +} diff --git a/Java-base/maven-war-plugin/src/src/test/java/org/apache/maven/plugins/war/overlay/OverlayManagerTest.java b/Java-base/maven-war-plugin/src/src/test/java/org/apache/maven/plugins/war/overlay/OverlayManagerTest.java new file mode 100644 index 000000000..59ed9e0c7 --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/test/java/org/apache/maven/plugins/war/overlay/OverlayManagerTest.java @@ -0,0 +1,226 @@ +package org.apache.maven.plugins.war.overlay; + +/* + * 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. + */ + +import static org.apache.maven.plugins.war.Overlay.DEFAULT_INCLUDES; +import static org.apache.maven.plugins.war.Overlay.DEFAULT_EXCLUDES; + +import org.apache.maven.plugin.testing.stubs.ArtifactStub; +import org.apache.maven.plugins.war.Overlay; +import org.apache.maven.plugins.war.stub.MavenProjectArtifactsStub; +import org.apache.maven.plugins.war.stub.WarArtifactStub; +import org.codehaus.plexus.PlexusTestCase; + +import java.util.ArrayList; +import java.util.List; + +/** + * @author Stephane Nicoll + */ +public class OverlayManagerTest + extends PlexusTestCase +{ + + + public void testEmptyProject() + throws Exception + { + final MavenProjectArtifactsStub project = new MavenProjectArtifactsStub(); + final List overlays = new ArrayList<>(); + try + { + final Overlay currentProjectOverlay = Overlay.createInstance(); + OverlayManager manager = new OverlayManager( overlays, project, DEFAULT_INCLUDES, DEFAULT_EXCLUDES, + currentProjectOverlay ); + assertNotNull( manager.getOverlays() ); + assertEquals( 1, manager.getOverlays().size() ); + assertEquals( currentProjectOverlay, manager.getOverlays().get( 0 ) ); + } + catch ( InvalidOverlayConfigurationException e ) + { + e.printStackTrace(); + fail( "Should not have failed to validate a valid overly config " + e.getMessage() ); + } + } + + public void testAutodetectSimpleOverlay( Overlay currentProjectOverlay ) + throws Exception + { + + final MavenProjectArtifactsStub project = new MavenProjectArtifactsStub(); + final ArtifactStub first = newWarArtifact( "test", "test-webapp" ); + project.addArtifact( first ); + + final List overlays = new ArrayList<>(); + + try + { + final Overlay overlay = currentProjectOverlay; + OverlayManager manager = new OverlayManager( overlays, project, DEFAULT_INCLUDES, DEFAULT_EXCLUDES, + overlay ); + assertNotNull( manager.getOverlays() ); + assertEquals( 2, manager.getOverlays().size() ); + assertEquals( overlay, manager.getOverlays().get( 0 ) ); + assertEquals( new DefaultOverlay( first ), manager.getOverlays().get( 1 ) ); + } + catch ( InvalidOverlayConfigurationException e ) + { + e.printStackTrace(); + fail( "Should not have failed to validate a valid overlay config " + e.getMessage() ); + } + } + + public void testSimpleOverlay() + throws Exception + { + + final MavenProjectArtifactsStub project = new MavenProjectArtifactsStub(); + final ArtifactStub first = newWarArtifact( "test", "test-webapp" ); + project.addArtifact( first ); + + final List overlays = new ArrayList<>(); + overlays.add( new DefaultOverlay( first ) ); + + try + { + final Overlay currentProjectOverlay = Overlay.createInstance(); + OverlayManager manager = new OverlayManager( overlays, project, DEFAULT_INCLUDES, DEFAULT_EXCLUDES, + currentProjectOverlay ); + assertNotNull( manager.getOverlays() ); + assertEquals( 2, manager.getOverlays().size() ); + assertEquals( Overlay.createInstance(), manager.getOverlays().get( 0 ) ); + assertEquals( overlays.get( 0 ), manager.getOverlays().get( 1 ) ); + } + catch ( InvalidOverlayConfigurationException e ) + { + e.printStackTrace(); + fail( "Should not have failed to validate a valid overlay config " + e.getMessage() ); + } + } + + public void testUnknownOverlay() + throws Exception + { + + final MavenProjectArtifactsStub project = new MavenProjectArtifactsStub(); + final ArtifactStub first = newWarArtifact( "test", "test-webapp" ); + project.addArtifact( first ); + + final List overlays = new ArrayList<>(); + overlays.add( new Overlay( "test", "test-webapp-2" ) ); + + try + { + final Overlay currentProjectOverlay = Overlay.createInstance(); + new OverlayManager( overlays, project, DEFAULT_INCLUDES, DEFAULT_EXCLUDES, currentProjectOverlay ); + fail( "Should have failed to validate an unknown overlay" ); + } + catch ( InvalidOverlayConfigurationException e ) + { + // OK + } + } + + public void testCustomCurrentProject() + throws Exception + { + + final MavenProjectArtifactsStub project = new MavenProjectArtifactsStub(); + final ArtifactStub first = newWarArtifact( "test", "test-webapp" ); + final ArtifactStub second = newWarArtifact( "test", "test-webapp-2" ); + project.addArtifact( first ); + project.addArtifact( second ); + + final List overlays = new ArrayList<>(); + overlays.add( new DefaultOverlay( first ) ); + final Overlay currentProjectOverlay = Overlay.createInstance(); + overlays.add( currentProjectOverlay ); + + try + { + OverlayManager manager = new OverlayManager( overlays, project, DEFAULT_INCLUDES, DEFAULT_EXCLUDES, + currentProjectOverlay ); + assertNotNull( manager.getOverlays() ); + assertEquals( 3, manager.getOverlays().size() ); + assertEquals( overlays.get( 0 ), manager.getOverlays().get( 0 ) ); + assertEquals( currentProjectOverlay, manager.getOverlays().get( 1 ) ); + assertEquals( new DefaultOverlay( second ), manager.getOverlays().get( 2 ) ); + + } + catch ( InvalidOverlayConfigurationException e ) + { + e.printStackTrace(); + fail( "Should not have failed to validate a valid overlay config " + e.getMessage() ); + } + } + + public void testOverlaysWithSameArtifactAndGroupId() + throws Exception + { + + final MavenProjectArtifactsStub project = new MavenProjectArtifactsStub(); + final ArtifactStub first = newWarArtifact( "test", "test-webapp" ); + final ArtifactStub second = newWarArtifact( "test", "test-webapp", "my-classifier" ); + + project.addArtifact( first ); + project.addArtifact( second ); + + final List overlays = new ArrayList<>(); + overlays.add( new DefaultOverlay( first ) ); + overlays.add( new DefaultOverlay( second ) ); + + try + { + final Overlay currentProjectOverlay = Overlay.createInstance(); + OverlayManager manager = new OverlayManager( overlays, project, DEFAULT_INCLUDES, DEFAULT_EXCLUDES, + currentProjectOverlay ); + assertNotNull( manager.getOverlays() ); + assertEquals( 3, manager.getOverlays().size() ); + assertEquals( currentProjectOverlay, manager.getOverlays().get( 0 ) ); + assertEquals( overlays.get( 0 ), manager.getOverlays().get( 1 ) ); + assertEquals( overlays.get( 1 ), manager.getOverlays().get( 2 ) ); + + } + catch ( InvalidOverlayConfigurationException e ) + { + e.printStackTrace(); + fail( "Should not have failed to validate a valid overlay config " + e.getMessage() ); + } + } + + + protected ArtifactStub newWarArtifact( String groupId, String artifactId, String classifier ) + { + final WarArtifactStub a = new WarArtifactStub( getBasedir() ); + a.setGroupId( groupId ); + a.setArtifactId( artifactId ); + if ( classifier != null ) + { + a.setClassifier( classifier ); + } + return a; + } + + protected ArtifactStub newWarArtifact( String groupId, String artifactId ) + { + return newWarArtifact( groupId, artifactId, null ); + + } +} diff --git a/Java-base/maven-war-plugin/src/src/test/java/org/apache/maven/plugins/war/stub/AarArtifactStub.java b/Java-base/maven-war-plugin/src/src/test/java/org/apache/maven/plugins/war/stub/AarArtifactStub.java new file mode 100644 index 000000000..db5004964 --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/test/java/org/apache/maven/plugins/war/stub/AarArtifactStub.java @@ -0,0 +1,79 @@ +package org.apache.maven.plugins.war.stub; + +/* + * 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. + */ + + +import org.apache.maven.artifact.handler.ArtifactHandler; + +import java.io.File; + +/** + * @author Stephane Nicoll + */ +public class AarArtifactStub + extends AbstractArtifactStub +{ + protected String groupId; + + private ArtifactHandler artifactHandler; + + public AarArtifactStub( String basedir, ArtifactHandler artifactHandler ) + { + super( basedir ); + this.artifactHandler = artifactHandler; + } + + public void setGroupId( String id ) + { + groupId = id; + } + + public String getGroupId() + { + if ( groupId != null ) + { + return groupId; + } + else + { + return "org.sample.aar"; + } + } + + public String getType() + { + return "aar"; + } + + public String getArtifactId() + { + return "aarartifact"; + } + + public File getFile() + { + return new File( basedir, "/target/test-classes/unit/sample_wars/simple.aar" ); + } + + public ArtifactHandler getArtifactHandler() + { + return artifactHandler; + } +} diff --git a/Java-base/maven-war-plugin/src/src/test/java/org/apache/maven/plugins/war/stub/AbstractArtifactStub.java b/Java-base/maven-war-plugin/src/src/test/java/org/apache/maven/plugins/war/stub/AbstractArtifactStub.java new file mode 100644 index 000000000..de6890ead --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/test/java/org/apache/maven/plugins/war/stub/AbstractArtifactStub.java @@ -0,0 +1,166 @@ +package org.apache.maven.plugins.war.stub; + +/* + * 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. + */ + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.handler.ArtifactHandler; +import org.apache.maven.artifact.handler.DefaultArtifactHandler; +import org.apache.maven.artifact.versioning.VersionRange; +import org.apache.maven.plugin.testing.stubs.ArtifactStub; + +public abstract class AbstractArtifactStub + extends ArtifactStub +{ + protected String basedir; + + public AbstractArtifactStub( String _basedir ) + { + basedir = _basedir; + } + + public String getVersion() + { + return "0.0-Test"; + } + + @Override + public String getBaseVersion() + { + return getVersion(); + } + + public String getScope() + { + return Artifact.SCOPE_RUNTIME; + } + + public VersionRange getVersionRange() + { + return VersionRange.createFromVersion( getVersion()); + } + + public boolean isOptional() + { + return false; + } + + public ArtifactHandler getArtifactHandler() + { + return new DefaultArtifactHandler( getType() ); + } + + /* + * TODO: Copied from org/apache/maven/artifact/DefaultArtifact.java; Consider merging... + */ + public int compareTo( Artifact a ) + { + /* -- We need to support groupId=null (it is missing in DefaultArtifact.java) */ + int result; + if ( a.getGroupId() != null ) + { + result = getGroupId().compareTo( a.getGroupId() ); + } + else + { + result = ( getGroupId() == null ? 0 : -1 ); + } + /* -- */ + + if ( result == 0 ) + { + result = getArtifactId().compareTo( a.getArtifactId() ); + if ( result == 0 ) + { + result = getType().compareTo( a.getType() ); + if ( result == 0 ) + { + if ( getClassifier() == null ) + { + if ( a.getClassifier() != null ) + { + result = 1; + } + } + else + { + if ( a.getClassifier() != null ) + { + result = getClassifier().compareTo( a.getClassifier() ); + } + else + { + result = -1; + } + } + if ( result == 0 ) + { + // We don't consider the version range in the comparison, just the resolved version + result = getVersion().compareTo( a.getVersion() ); + } + } + } + } + return result; + } + + /* + * TODO: Copied from org/apache/maven/artifact/DefaultArtifact.java; Consider merging... + */ + public boolean equals( Object o ) + { + if ( o == this ) + { + return true; + } + + if ( !( o instanceof Artifact ) ) + { + return false; + } + + Artifact a = (Artifact) o; + + /* -- We need to support groupId=null (it is missing in DefaultArtifact.java) */ + if ( a.getGroupId() == null ? ( getGroupId() != null ) : a.getGroupId().equals( getGroupId() ) ) + { + return false; + } + else if ( !a.getArtifactId().equals( getArtifactId() ) ) + { + return false; + } + else if ( !a.getVersion().equals( getVersion() ) ) + { + return false; + } + else if ( !a.getType().equals( getType() ) ) + { + return false; + } + else if ( a.getClassifier() == null ? getClassifier() != null : !a.getClassifier().equals( getClassifier() ) ) + { + return false; + } + + // We don't consider the version range in the comparison, just the resolved version + + return true; + } +} diff --git a/Java-base/maven-war-plugin/src/src/test/java/org/apache/maven/plugins/war/stub/EJBArtifactStub.java b/Java-base/maven-war-plugin/src/src/test/java/org/apache/maven/plugins/war/stub/EJBArtifactStub.java new file mode 100644 index 000000000..7383715bd --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/test/java/org/apache/maven/plugins/war/stub/EJBArtifactStub.java @@ -0,0 +1,79 @@ +package org.apache.maven.plugins.war.stub; + +/* + * 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. + */ + +import org.apache.maven.artifact.handler.ArtifactHandler; +import org.apache.maven.artifact.handler.DefaultArtifactHandler; + +import java.io.File; + +public class EJBArtifactStub + extends AbstractArtifactStub +{ + protected String groupId; + + public EJBArtifactStub( String _basedir ) + { + super( _basedir ); + } + + public void setGroupId( String id ) + { + groupId = id; + } + + public String getGroupId() + { + if ( groupId != null ) + { + return groupId; + } + else + { + return "org.sample.ejb"; + } + } + + public String getType() + { + return "ejb"; + } + + public String getArtifactId() + { + return "ejbartifact"; + } + + public File getFile() + { + return new File( basedir, "/target/test-classes/unit/sample_wars/ejb.jar" ); + } + + public ArtifactHandler getArtifactHandler() + { + return new DefaultArtifactHandler() + { + public String getExtension() + { + return "jar"; + } + }; + } +} diff --git a/Java-base/maven-war-plugin/src/src/test/java/org/apache/maven/plugins/war/stub/EJBArtifactStubWithClassifier.java b/Java-base/maven-war-plugin/src/src/test/java/org/apache/maven/plugins/war/stub/EJBArtifactStubWithClassifier.java new file mode 100644 index 000000000..35869c5e2 --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/test/java/org/apache/maven/plugins/war/stub/EJBArtifactStubWithClassifier.java @@ -0,0 +1,90 @@ +package org.apache.maven.plugins.war.stub; + +/* + * 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. + */ + +import org.apache.maven.artifact.handler.ArtifactHandler; +import org.apache.maven.artifact.handler.DefaultArtifactHandler; + +import java.io.File; + +public class EJBArtifactStubWithClassifier + extends AbstractArtifactStub +{ + protected String groupId; + protected String classifier; + + public EJBArtifactStubWithClassifier( String _basedir ) + { + super( _basedir ); + } + + public void setGroupId( String id ) + { + groupId = id; + } + + public String getGroupId() + { + if ( groupId != null ) + { + return groupId; + } + else + { + return "org.sample.ejb"; + } + } + + public String getType() + { + return "ejb"; + } + + public String getArtifactId() + { + return "ejbartifact"; + } + + public void setClassifier( String classifier ) + { + this.classifier = classifier; + } + + public String getClassifier() + { + return classifier; + } + + public File getFile() + { + return new File( basedir, "/target/test-classes/unit/sample_wars/ejb.jar" ); + } + + public ArtifactHandler getArtifactHandler() + { + return new DefaultArtifactHandler() + { + public String getExtension() + { + return "jar"; + } + }; + } +} diff --git a/Java-base/maven-war-plugin/src/src/test/java/org/apache/maven/plugins/war/stub/EJBClientArtifactStub.java b/Java-base/maven-war-plugin/src/src/test/java/org/apache/maven/plugins/war/stub/EJBClientArtifactStub.java new file mode 100644 index 000000000..7e978967b --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/test/java/org/apache/maven/plugins/war/stub/EJBClientArtifactStub.java @@ -0,0 +1,84 @@ +package org.apache.maven.plugins.war.stub; + +/* + * 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. + */ + +import org.apache.maven.artifact.handler.ArtifactHandler; +import org.apache.maven.artifact.handler.DefaultArtifactHandler; + +import java.io.File; + +public class EJBClientArtifactStub + extends AbstractArtifactStub +{ + protected String groupId; + + public EJBClientArtifactStub( String _basedir ) + { + super( _basedir ); + } + + public void setGroupId( String id ) + { + groupId = id; + } + + public String getGroupId() + { + if ( groupId != null ) + { + return groupId; + } + else + { + return "org.sample.ejb"; + } + } + + public String getType() + { + return "ejb-client"; + } + + public String getClassifier() + { + return "client"; + } + + public String getArtifactId() + { + return "ejbclientartifact"; + } + + public File getFile() + { + return new File( basedir, "/target/test-classes/unit/sample_wars/ejbclient.jar" ); + } + + public ArtifactHandler getArtifactHandler() + { + return new DefaultArtifactHandler() + { + public String getExtension() + { + return "jar"; + } + }; + } +} diff --git a/Java-base/maven-war-plugin/src/src/test/java/org/apache/maven/plugins/war/stub/IncludeExcludeWarArtifactStub.java b/Java-base/maven-war-plugin/src/src/test/java/org/apache/maven/plugins/war/stub/IncludeExcludeWarArtifactStub.java new file mode 100644 index 000000000..9f879b3c4 --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/test/java/org/apache/maven/plugins/war/stub/IncludeExcludeWarArtifactStub.java @@ -0,0 +1,42 @@ +package org.apache.maven.plugins.war.stub; + +/* + * 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. + */ + +import java.io.File; + +public class IncludeExcludeWarArtifactStub + extends WarArtifactStub +{ + public IncludeExcludeWarArtifactStub( String id ) + { + super( id ); + setGroupId( "wartests" ); + } + + public String getArtifactId() + { + return "war-include-exclude"; + } + + public File getFile() + { + return new File( basedir, "/target/test-classes/unit/sample_wars/include-exclude.war" ); + } +} diff --git a/Java-base/maven-war-plugin/src/src/test/java/org/apache/maven/plugins/war/stub/JarArtifactStub.java b/Java-base/maven-war-plugin/src/src/test/java/org/apache/maven/plugins/war/stub/JarArtifactStub.java new file mode 100644 index 000000000..4b0899516 --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/test/java/org/apache/maven/plugins/war/stub/JarArtifactStub.java @@ -0,0 +1,151 @@ +package org.apache.maven.plugins.war.stub; + +/* + * 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. + */ + +import org.apache.maven.artifact.handler.ArtifactHandler; + +import java.io.File; + +public class JarArtifactStub + extends AbstractArtifactStub +{ + + protected String groupId; + + protected String artifactId; + + protected String version; + + protected boolean optional = false; + + protected String scope; + + private File file; + + private ArtifactHandler artifactHandler; + + public JarArtifactStub( String basedir, ArtifactHandler artifactHandler ) + { + super( basedir ); + this.artifactHandler = artifactHandler; + } + + public void setGroupId( String id ) + { + groupId = id; + } + + public String getGroupId() + { + if ( groupId != null ) + { + return groupId; + } + else + { + return "org.sample.jar"; + } + } + + public String getType() + { + return "jar"; + } + + public void setArtifactId( String artifactId ) + { + this.artifactId = artifactId; + } + + public String getArtifactId() + { + if ( artifactId != null ) + { + return artifactId; + } + else + { + return "jarartifact"; + } + } + + public String getVersion() + { + if ( version != null ) + { + return version; + } + else + { + return super.getVersion(); + } + } + + public void setVersion( String version ) + { + this.version = version; + } + + public boolean isOptional() + { + return optional; + } + + public void setOptional( boolean optional ) + { + this.optional = optional; + } + + public String getScope() + { + if ( scope != null ) + { + return scope; + } + else + { + return super.getScope(); + } + } + + public void setScope( String scope ) + { + this.scope = scope; + } + + public File getFile() + { + if ( file == null ) + { + return new File( basedir, "/target/test-classes/unit/sample_wars/simple.jar" ); + } + return file; + } + + public void setFile( File file ) + { + this.file = file; + } + + public ArtifactHandler getArtifactHandler() + { + return artifactHandler; + } +} diff --git a/Java-base/maven-war-plugin/src/src/test/java/org/apache/maven/plugins/war/stub/MarArtifactStub.java b/Java-base/maven-war-plugin/src/src/test/java/org/apache/maven/plugins/war/stub/MarArtifactStub.java new file mode 100644 index 000000000..e26655749 --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/test/java/org/apache/maven/plugins/war/stub/MarArtifactStub.java @@ -0,0 +1,78 @@ +/* + * 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. + */ +package org.apache.maven.plugins.war.stub; + +import org.apache.maven.artifact.handler.ArtifactHandler; + +import java.io.File; + +/** + * @author Stephane Nicoll + */ +public class MarArtifactStub + extends AbstractArtifactStub +{ + protected String groupId; + + private ArtifactHandler artifactHandler; + + public MarArtifactStub( String basedir, ArtifactHandler artifactHandler ) + { + super( basedir ); + this.artifactHandler = artifactHandler; + } + + public void setGroupId( String id ) + { + groupId = id; + } + + public String getGroupId() + { + if ( groupId != null ) + { + return groupId; + } + else + { + return "org.sample.mar"; + } + } + + public String getType() + { + return "mar"; + } + + public String getArtifactId() + { + return "marartifact"; + } + + public File getFile() + { + return new File( basedir, "/target/test-classes/unit/sample_wars/simple.mar" ); + } + + public ArtifactHandler getArtifactHandler() + { + return artifactHandler; + } +} + diff --git a/Java-base/maven-war-plugin/src/src/test/java/org/apache/maven/plugins/war/stub/MavenProject4CopyConstructor.java b/Java-base/maven-war-plugin/src/src/test/java/org/apache/maven/plugins/war/stub/MavenProject4CopyConstructor.java new file mode 100644 index 000000000..e9a58ab12 --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/test/java/org/apache/maven/plugins/war/stub/MavenProject4CopyConstructor.java @@ -0,0 +1,64 @@ +package org.apache.maven.plugins.war.stub; + +/* + * 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. + */ + +import java.io.File; +import java.util.HashSet; +import java.util.LinkedList; +import java.util.List; + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.model.Profile; +import org.apache.maven.project.MavenProject; + +public class MavenProject4CopyConstructor + extends MavenProjectBasicStub +{ + protected ModelStub model; + + public MavenProject4CopyConstructor() + throws Exception + { + initializeParentFields(); + } + + public List getAttachedArtifacts() + { + return new LinkedList<>(); + } + + // to prevent the MavenProject copy constructor from blowing up + private void initializeParentFields() + { + // the pom should be located in the isolated dummy root + super.setFile( new File( getBasedir(), "pom.xml" ) ); + super.setDependencyArtifacts( new HashSet() ); + super.setArtifacts( new HashSet() ); + super.setExtensionArtifacts( new HashSet() ); + super.setRemoteArtifactRepositories( new LinkedList() ); + super.setPluginArtifactRepositories( new LinkedList() ); + super.setCollectedProjects( new LinkedList() ); + super.setActiveProfiles( new LinkedList() ); + super.setOriginalModel( null ); + super.setExecutionProject( this ); + super.setBuild( getBuild() ); + } +} diff --git a/Java-base/maven-war-plugin/src/src/test/java/org/apache/maven/plugins/war/stub/MavenProjectArtifactsStub.java b/Java-base/maven-war-plugin/src/src/test/java/org/apache/maven/plugins/war/stub/MavenProjectArtifactsStub.java new file mode 100644 index 000000000..a8e21192c --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/test/java/org/apache/maven/plugins/war/stub/MavenProjectArtifactsStub.java @@ -0,0 +1,85 @@ +package org.apache.maven.plugins.war.stub; + +/* + * 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. + */ + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.model.Dependency; +import org.apache.maven.plugin.testing.stubs.ArtifactStub; + +import java.util.ArrayList; +import java.util.List; +import java.util.Set; +import java.util.TreeSet; + +public class MavenProjectArtifactsStub + extends MavenProjectBasicStub +{ + TreeSet artifacts; + + public MavenProjectArtifactsStub() + throws Exception + { + artifacts = new TreeSet<>(); + } + + public void addArtifact( ArtifactStub stub ) + { + artifacts.add( stub ); + } + + public Set getArtifacts() + { + return artifacts; + } + + public List getDependencies() + { + if ( getArtifacts() == null ) + { + return new ArrayList<>(); + } + final List dependencies = new ArrayList<>(); + for ( Artifact a : getArtifacts() ) + { + Dependency dependency = new Dependency(); + dependency.setArtifactId( a.getArtifactId() ); + dependency.setGroupId( a.getGroupId() ); + dependency.setVersion( a.getVersion() ); + dependency.setScope( a.getScope() ); + dependency.setType( a.getType() ); + dependency.setClassifier( a.getClassifier() ); + dependencies.add( dependency ); + + } + return dependencies; + } + + public List getRuntimeClasspathElements() + { + List artifacts = new ArrayList<>(); + + artifacts.add( + "src/test/resources/unit/manifest/manifest-with-classpath/sample-artifacts/maven-artifact1-1.0-SNAPSHOT.jar" ); + artifacts.add( + "src/test/resources/unit/manifest/manifest-with-classpath/sample-artifacts/maven-artifact2-1.0-SNAPSHOT.jar" ); + + return artifacts; + } +} diff --git a/Java-base/maven-war-plugin/src/src/test/java/org/apache/maven/plugins/war/stub/MavenProjectBasicStub.java b/Java-base/maven-war-plugin/src/src/test/java/org/apache/maven/plugins/war/stub/MavenProjectBasicStub.java new file mode 100644 index 000000000..7b2ac3007 --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/test/java/org/apache/maven/plugins/war/stub/MavenProjectBasicStub.java @@ -0,0 +1,130 @@ +package org.apache.maven.plugins.war.stub; + +/* + * 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. + */ + +import java.io.File; +import java.util.HashSet; +import java.util.Properties; +import java.util.Set; + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.model.Build; +import org.apache.maven.model.Organization; +import org.apache.maven.project.MavenProject; + +/** + * Stub + */ +public class MavenProjectBasicStub + extends MavenProject +{ + protected String testRootDir; + + protected Properties properties; + + public MavenProjectBasicStub() + throws Exception + { + super( new ModelStub() ); + properties = new Properties(); + } + + public Set getArtifacts() + { + return new HashSet<>(); + } + + public String getName() + { + return "Test Project "; + } + + public File getBasedir() + { + // create an isolated environment + // see setupTestEnvironment for details + //return new File( testRootDir ); + return null; + } + + public String getGroupId() + { + return "org.apache.maven.plugin.test"; + } + + public String getArtifactId() + { + return "maven-war-plugin-test"; + } + + public String getPackaging() + { + return "jar"; + } + + public String getVersion() + { + return "0.0-Test"; + } + + public void addProperty( String key, String value ) + { + properties.put( key, value ); + } + + public Properties getProperties() + { + return properties; + } + + public String getDescription() + { + return "Test Description"; + } + + public Organization getOrganization() + { + return new Organization() + { + public String getName() + { + return "Test Name"; + } + }; + } + + @Override + public Build getBuild() + { + Build build = super.getBuild(); + + build.setDirectory( System.getProperty( "project.build.directory" ) ); + build.setOutputDirectory( System.getProperty( "project.build.outputDirectory" ) ); + + return build; + } + + @Override + public MavenProject clone() + { + return this; + } + +} diff --git a/Java-base/maven-war-plugin/src/src/test/java/org/apache/maven/plugins/war/stub/MavenZipProject.java b/Java-base/maven-war-plugin/src/src/test/java/org/apache/maven/plugins/war/stub/MavenZipProject.java new file mode 100644 index 000000000..c2ff17006 --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/test/java/org/apache/maven/plugins/war/stub/MavenZipProject.java @@ -0,0 +1,58 @@ +package org.apache.maven.plugins.war.stub; + +/* + * 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. + */ + +import java.util.HashSet; +import java.util.Set; + +import org.apache.maven.artifact.Artifact; + +/** + * @author Olivier Lamy + * @since 9 juin 07 + */ +public class MavenZipProject + extends MavenProject4CopyConstructor +{ + private Set artifacts; + + public MavenZipProject() + throws Exception + { + super(); + this.artifacts = new HashSet<>(); + } + + public Set getArtifacts() + { + return this.artifacts; + } + + public Set getDependencyArtifacts() + { + return this.artifacts; + } + + public void addArtifact( Artifact artifact ) + { + this.artifacts.add( artifact ); + } + +} diff --git a/Java-base/maven-war-plugin/src/src/test/java/org/apache/maven/plugins/war/stub/ModelStub.java b/Java-base/maven-war-plugin/src/src/test/java/org/apache/maven/plugins/war/stub/ModelStub.java new file mode 100644 index 000000000..e15b8b2c9 --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/test/java/org/apache/maven/plugins/war/stub/ModelStub.java @@ -0,0 +1,100 @@ +package org.apache.maven.plugins.war.stub; + +/* + * 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. + */ + +import java.util.LinkedList; +import java.util.List; +import java.util.Properties; + +import org.apache.maven.model.Model; +import org.apache.maven.model.Parent; +import org.apache.maven.model.Profile; + +/** + * Stub + */ +public class ModelStub + extends Model +{ + /** + * + */ + private static final long serialVersionUID = 7802402157311376304L; + + public ModelStub() + { + + } + + public String getVersion() + { + return "0.0-TEST"; + } + + public String getModelVersion() + { + return "0.0-TEST"; + } + + public String getName() + { + return "Test Model"; + } + + public String getGroupId() + { + return "org.apache.maven.test"; + } + + public String getPackaging() + { + return "jar"; + } + + public Parent getParent() + { + return new Parent(); + } + + public String getArtifactId() + { + return "maven-test-plugin"; + } + + public Properties getProperties() + { + return new Properties(); + } + + public List getPackages() + { + return new LinkedList(); + } + + public List getProfiles() + { + return new LinkedList<>(); + } + + public List getModules() + { + return new LinkedList<>(); + } +} diff --git a/Java-base/maven-war-plugin/src/src/test/java/org/apache/maven/plugins/war/stub/PARArtifactStub.java b/Java-base/maven-war-plugin/src/src/test/java/org/apache/maven/plugins/war/stub/PARArtifactStub.java new file mode 100644 index 000000000..588b22e26 --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/test/java/org/apache/maven/plugins/war/stub/PARArtifactStub.java @@ -0,0 +1,46 @@ +package org.apache.maven.plugins.war.stub; + +/* + * 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. + */ + +import java.io.File; + +public class PARArtifactStub + extends AbstractArtifactStub +{ + public PARArtifactStub( String _basedir ) + { + super( _basedir ); + } + + public String getType() + { + return "par"; + } + + public String getArtifactId() + { + return "parartifact"; + } + + public File getFile() + { + return new File( basedir, "/target/test-classes/unit/sample_wars/sample.par" ); + } +} diff --git a/Java-base/maven-war-plugin/src/src/test/java/org/apache/maven/plugins/war/stub/ProjectHelperStub.java b/Java-base/maven-war-plugin/src/src/test/java/org/apache/maven/plugins/war/stub/ProjectHelperStub.java new file mode 100644 index 000000000..9fe114f99 --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/test/java/org/apache/maven/plugins/war/stub/ProjectHelperStub.java @@ -0,0 +1,81 @@ +package org.apache.maven.plugins.war.stub; + +/* + * 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. + */ + +import java.io.File; +import java.util.List; + +import org.apache.maven.project.MavenProject; +import org.apache.maven.project.MavenProjectHelper; + +public class ProjectHelperStub + implements MavenProjectHelper +{ + File artifactFile; + + String artifactType; + + String artifactClassifier; + + public File getArtifactFile() + { + return artifactFile; + } + + public String getArtifactType() + { + return artifactType; + } + + public String getArtifactClassifier() + { + return artifactClassifier; + } + + public void attachArtifact( MavenProject project, File artifactFile, String artifactClassifier ) + { + + } + + public void attachArtifact( MavenProject project, String artifactType, File artifactFile ) + { + + } + + public void attachArtifact( MavenProject project, String _artifactType, String _artifactClassifier, + File _artifactFile ) + { + artifactType = _artifactType; + artifactClassifier = _artifactClassifier; + artifactFile = _artifactFile; + } + + @SuppressWarnings( "rawtypes" ) + public void addResource( MavenProject project, String resourceDirectory, List includes, List excludes ) + { + + } + + @SuppressWarnings( "rawtypes" ) + public void addTestResource( MavenProject project, String resourceDirectory, List includes, List excludes ) + { + + } +} diff --git a/Java-base/maven-war-plugin/src/src/test/java/org/apache/maven/plugins/war/stub/ResourceStub.java b/Java-base/maven-war-plugin/src/src/test/java/org/apache/maven/plugins/war/stub/ResourceStub.java new file mode 100644 index 000000000..dbe22b0b5 --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/test/java/org/apache/maven/plugins/war/stub/ResourceStub.java @@ -0,0 +1,57 @@ +package org.apache.maven.plugins.war.stub; + +/* + * 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. + */ + +import java.util.ArrayList; +import java.util.List; + +import org.apache.maven.model.Resource; + +public class ResourceStub + extends Resource +{ + /** + * + */ + private static final long serialVersionUID = 7685068931840967662L; + + private String directory; + + public List getIncludes() + { + return new ArrayList<>(); + } + + public List getExcludes() + { + return new ArrayList<>(); + } + + public void setDirectory( String _directory ) + { + directory = _directory; + } + + public String getDirectory() + { + return directory; + } + +} diff --git a/Java-base/maven-war-plugin/src/src/test/java/org/apache/maven/plugins/war/stub/TLDArtifactStub.java b/Java-base/maven-war-plugin/src/src/test/java/org/apache/maven/plugins/war/stub/TLDArtifactStub.java new file mode 100644 index 000000000..bd2c2fd6d --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/test/java/org/apache/maven/plugins/war/stub/TLDArtifactStub.java @@ -0,0 +1,46 @@ +package org.apache.maven.plugins.war.stub; + +/* + * 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. + */ + +import java.io.File; + +public class TLDArtifactStub + extends AbstractArtifactStub +{ + public TLDArtifactStub( String _basedir ) + { + super( _basedir ); + } + + public String getType() + { + return "tld"; + } + + public String getArtifactId() + { + return "tldartifact"; + } + + public File getFile() + { + return new File( basedir, "/target/test-classes/unit/sample_wars/tld.jar" ); + } +} diff --git a/Java-base/maven-war-plugin/src/src/test/java/org/apache/maven/plugins/war/stub/WarArtifact4CCStub.java b/Java-base/maven-war-plugin/src/src/test/java/org/apache/maven/plugins/war/stub/WarArtifact4CCStub.java new file mode 100644 index 000000000..c2b05b29e --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/test/java/org/apache/maven/plugins/war/stub/WarArtifact4CCStub.java @@ -0,0 +1,57 @@ +package org.apache.maven.plugins.war.stub; + +/* + * 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. + */ + +import org.apache.maven.artifact.handler.ArtifactHandler; +import org.apache.maven.artifact.handler.DefaultArtifactHandler; +import org.apache.maven.artifact.versioning.VersionRange; + +/** + * stub for copy constructor + * to prevent the copy constructor from blowing up + */ +public class WarArtifact4CCStub + extends WarArtifactStub +{ + public WarArtifact4CCStub( String basedir ) + { + super( basedir ); + } + + public VersionRange getVersionRange() + { + return VersionRange.createFromVersion( getVersion() ); + } + + public String getGroupId() + { + return "org.maven.plugin.test"; + } + + public String getClassifier() + { + return "testclassifier"; + } + + public ArtifactHandler getArtifactHandler() + { + return new DefaultArtifactHandler(); + } +} diff --git a/Java-base/maven-war-plugin/src/src/test/java/org/apache/maven/plugins/war/stub/WarArtifactStub.java b/Java-base/maven-war-plugin/src/src/test/java/org/apache/maven/plugins/war/stub/WarArtifactStub.java new file mode 100644 index 000000000..9b4c63ead --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/test/java/org/apache/maven/plugins/war/stub/WarArtifactStub.java @@ -0,0 +1,115 @@ +package org.apache.maven.plugins.war.stub; + +/* + * 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. + */ + +import java.io.File; + +/** + * Stub + */ +public class WarArtifactStub + extends AbstractArtifactStub +{ + + private String groupId; + + private String artifactId; + + private String classifier; + + private File file; + + public WarArtifactStub( String _basedir ) + { + super( _basedir ); + } + + public String getType() + { + return "war"; + } + + public String getArtifactId() + { + if ( artifactId == null ) + { + return "simple"; + } + else + { + return artifactId; + } + } + + public void setArtifactId( String _artifactId ) + { + artifactId = _artifactId; + } + + + public String getGroupId() + { + if ( groupId == null ) + { + return "wartests"; + } + else + { + return groupId; + } + } + + public void setGroupId( String groupId ) + { + this.groupId = groupId; + } + + public File getFile() + { + if ( file == null ) + { + return new File( basedir, "/target/test-classes/unit/sample_wars/simple.war" ); + } + else + { + return file; + } + } + + public void setFile( File _file ) + { + file = _file; + } + + public String getClassifier() + { + return classifier; + } + + public void setClassifier( String classifier ) + { + this.classifier = classifier; + } + + public boolean hasClassifier() + { + return classifier != null; + } +} diff --git a/Java-base/maven-war-plugin/src/src/test/java/org/apache/maven/plugins/war/stub/WarOverlayStub.java b/Java-base/maven-war-plugin/src/src/test/java/org/apache/maven/plugins/war/stub/WarOverlayStub.java new file mode 100644 index 000000000..892f9791e --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/test/java/org/apache/maven/plugins/war/stub/WarOverlayStub.java @@ -0,0 +1,76 @@ +package org.apache.maven.plugins.war.stub; + +/* + * 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. + */ + +import java.io.File; + +/** + * @author Stephane Nicoll + */ +public class WarOverlayStub + extends AbstractArtifactStub +{ + + + private final String artifactId; + + private File file; + + public WarOverlayStub( String _basedir, String artifactId, File warFile ) + { + super( _basedir ); + if ( artifactId == null ) + { + throw new NullPointerException( "Id could not be null." ); + } + if ( warFile == null ) + { + throw new NullPointerException( "warFile could not be null." ); + + } + else if ( !warFile.exists() ) + { + throw new IllegalStateException( "warFile[" + file.getAbsolutePath() + "] should exist." ); + } + this.artifactId = artifactId; + this.file = warFile; + } + + public String getType() + { + return "war"; + } + + public String getArtifactId() + { + return artifactId; + } + + public String getGroupId() + { + return "wartests"; + } + + public File getFile() + { + return file; + } + +} diff --git a/Java-base/maven-war-plugin/src/src/test/java/org/apache/maven/plugins/war/stub/XarArtifactStub.java b/Java-base/maven-war-plugin/src/src/test/java/org/apache/maven/plugins/war/stub/XarArtifactStub.java new file mode 100644 index 000000000..92e195f28 --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/test/java/org/apache/maven/plugins/war/stub/XarArtifactStub.java @@ -0,0 +1,79 @@ +package org.apache.maven.plugins.war.stub; + +/* + * 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. + */ + + +import org.apache.maven.artifact.handler.ArtifactHandler; + +import java.io.File; + +/** + * @author Auke Schrijnen + */ +public class XarArtifactStub + extends AbstractArtifactStub +{ + protected String groupId; + + private ArtifactHandler artifactHandler; + + public XarArtifactStub( String basedir, ArtifactHandler artifactHandler ) + { + super( basedir ); + this.artifactHandler = artifactHandler; + } + + public void setGroupId( String id ) + { + groupId = id; + } + + public String getGroupId() + { + if ( groupId != null ) + { + return groupId; + } + else + { + return "org.sample.xar"; + } + } + + public String getType() + { + return "xar"; + } + + public String getArtifactId() + { + return "xarartifact"; + } + + public File getFile() + { + return new File( basedir, "/target/test-classes/unit/sample_wars/simple.xar" ); + } + + public ArtifactHandler getArtifactHandler() + { + return artifactHandler; + } +} diff --git a/Java-base/maven-war-plugin/src/src/test/java/org/apache/maven/plugins/war/stub/ZipArtifactStub.java b/Java-base/maven-war-plugin/src/src/test/java/org/apache/maven/plugins/war/stub/ZipArtifactStub.java new file mode 100644 index 000000000..50c01d98a --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/test/java/org/apache/maven/plugins/war/stub/ZipArtifactStub.java @@ -0,0 +1,89 @@ +package org.apache.maven.plugins.war.stub; + +/* + * 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. + */ + +import java.io.File; + +import org.apache.maven.artifact.handler.ArtifactHandler; + +/** + * @author Olivier Lamy + * @since 8 juin 07 + */ +public class ZipArtifactStub + extends AbstractArtifactStub +{ + private File zip; + + public ZipArtifactStub( String basedir, ArtifactHandler artifactHandler, File zipFile ) + { + super( basedir ); + super.setArtifactHandler( artifactHandler ); + this.zip = zipFile; + } + + + public String getId() + { + return null; + } + + public ArtifactHandler getArtifactHandler() + { + return super.getArtifactHandler(); + } + + public String getScope() + { + return super.getScope(); + } + + public String getVersion() + { + return "1.0"; + } + + public boolean isOptional() + { + return super.isOptional(); + } + + public File getFile() + { + return this.zip; + } + + public String getType() + { + return "zip"; + } + + + public String getArtifactId() + { + return "zipId"; + } + + public String getGroupId() + { + return "zipGroupId"; + } + +} diff --git a/Java-base/maven-war-plugin/src/src/test/java/org/apache/maven/plugins/war/util/PathSetTest.java b/Java-base/maven-war-plugin/src/src/test/java/org/apache/maven/plugins/war/util/PathSetTest.java new file mode 100644 index 000000000..6375109ef --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/test/java/org/apache/maven/plugins/war/util/PathSetTest.java @@ -0,0 +1,257 @@ +package org.apache.maven.plugins.war.util; + +/* + * 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. + */ + +import junit.framework.TestCase; + +import org.apache.maven.plugins.war.util.PathSet; +import org.codehaus.plexus.util.StringUtils; + +import java.io.File; +import java.io.IOException; +import java.util.HashSet; +import java.util.Iterator; +import java.util.Set; + +public class PathSetTest + extends TestCase +{ + + /* --------------- Normalization tests --------------*/ + + /** + * Test method for 'org.apache.maven.plugin.war.PathSet.normalizeSubPath(String)' + */ + public void testNormalizeSubPath() + { + assertEquals( "Normalized path error", "", PathSet.normalizeSubPath( "" ) ); + assertEquals( "Normalized path error", "", PathSet.normalizeSubPath( "/" ) ); + assertEquals( "Normalized path error", "", PathSet.normalizeSubPath( "////" ) ); + assertEquals( "Normalized path error", "", PathSet.normalizeSubPath( "\\" ) ); + assertEquals( "Normalized path error", "", PathSet.normalizeSubPath( "\\\\\\\\" ) ); + + assertEquals( "Normalized path error", "abc", PathSet.normalizeSubPath( "abc" ) ); + assertEquals( "Normalized path error", "abc", PathSet.normalizeSubPath( "/abc" ) ); + assertEquals( "Normalized path error", "abc", PathSet.normalizeSubPath( "////abc" ) ); + assertEquals( "Normalized path error", "abc", PathSet.normalizeSubPath( "\\abc" ) ); + assertEquals( "Normalized path error", "abc", PathSet.normalizeSubPath( "\\\\\\\\abc" ) ); + + assertEquals( "Normalized path error", "abc/def/xyz", PathSet.normalizeSubPath( "abc/def\\xyz\\" ) ); + assertEquals( "Normalized path error", "abc/def/xyz", PathSet.normalizeSubPath( "/abc/def/xyz/" ) ); + assertEquals( "Normalized path error", "abc/def/xyz", PathSet.normalizeSubPath( "////abc/def/xyz/" ) ); + assertEquals( "Normalized path error", "abc/def/xyz", PathSet.normalizeSubPath( "\\abc/def/xyz/" ) ); + assertEquals( "Normalized path error", "abc/def/xyz", + PathSet.normalizeSubPath( "\\\\\\\\abc/def/xyz/" ) ); + // MWAR-371 + assertEquals( "Normalized path error", "abc/def/ghi", + PathSet.normalizeSubPath( "///abc/////def////ghi//" ) ); + } + + /* -------------- Operations tests ------------------*/ + + /** + * Test method for: + *
    + *
  • org.apache.maven.plugin.war.PathSet.PathSet()
  • + *
  • org.apache.maven.plugin.war.PathSet.size()
  • + *
  • org.apache.maven.plugin.war.PathSet.add()
  • + *
  • org.apache.maven.plugin.war.PathSet.addAll()
  • + *
  • org.apache.maven.plugin.war.PathSet.iterate()
  • + *
  • org.apache.maven.plugin.war.PathSet.contains()
  • + *
  • org.apache.maven.plugin.war.PathSet.addPrefix(String)
  • + *
+ */ + public void testPathsSetBasic() + { + PathSet ps = new PathSet(); + assertEquals( "Unexpected PathSet size", ps.size(), 0 ); + Iterator iter = ps.iterator(); + assertNotNull( "Iterator is null", iter ); + assertFalse( "Can iterate on empty set", iter.hasNext() ); + + ps.add( "abc" ); + assertEquals( "Unexpected PathSet size", ps.size(), 1 ); + ps.add( "abc" ); + assertEquals( "Unexpected PathSet size", ps.size(), 1 ); + ps.add( "xyz/abc" ); + assertEquals( "Unexpected PathSet size", ps.size(), 2 ); + ps.add( "///abc" ); + assertEquals( "Unexpected PathSet size", ps.size(), 2 ); + ps.add( "///xyz\\abc" ); + assertEquals( "Unexpected PathSet size", ps.size(), 2 ); + + ps.addAll( ps ); + assertEquals( "Unexpected PathSet size", ps.size(), 2 ); + + int i = 0; + for (String pathstr : ps) { + i++; + assertTrue(ps.contains(pathstr)); + assertTrue(ps.contains("/" + pathstr)); + assertTrue(ps.contains("/" + StringUtils.replace(pathstr, '/', '\\'))); + assertFalse(ps.contains("/" + StringUtils.replace(pathstr, '/', '\\') + "/a")); + assertFalse(ps.contains("/a/" + StringUtils.replace(pathstr, '/', '\\'))); + } + assertEquals( "Wrong count of iterations", 2, i ); + + ps.addPrefix( "/ab/c/" ); + i = 0; + for (String pathstr : ps) { + i++; + assertTrue(pathstr.startsWith("ab/c/")); + assertFalse(pathstr.startsWith("ab/c//")); + assertTrue(ps.contains(pathstr)); + assertTrue(ps.contains("/" + pathstr)); + assertTrue(ps.contains("/" + StringUtils.replace(pathstr, '/', '\\'))); + assertFalse(ps.contains("/" + StringUtils.replace(pathstr, '/', '\\') + "/a")); + assertFalse(ps.contains("/ab/" + StringUtils.replace(pathstr, '/', '\\'))); + } + assertEquals( "Wrong count of iterations", 2, i ); + } + + /** + * Test method for: + *
    + *
  • org.apache.maven.plugin.war.PathSet.PathSet(Collection)
  • + *
  • org.apache.maven.plugin.war.PathSet.PathSet(String[])
  • + *
  • org.apache.maven.plugin.war.PathSet.Add
  • + *
  • org.apache.maven.plugin.war.PathSet.AddAll(String[],String)
  • + *
  • org.apache.maven.plugin.war.PathSet.AddAll(Collection,String)
  • + *
+ */ + public void testPathsSetAddAlls() + { + Set s1set = new HashSet<>(); + s1set.add( "/a/b" ); + s1set.add( "a/b/c" ); + s1set.add( "a\\b/c" ); + s1set.add( "//1//2\3a" ); + + String[] s2ar = new String[]{"/a/b", "a2/b2/c2", "a2\\b2/c2", "//21//22\23a"}; + + PathSet ps1 = new PathSet( s1set ); + assertEquals( "Unexpected PathSet size", 3, ps1.size() ); + + PathSet ps2 = new PathSet( s2ar ); + assertEquals( "Unexpected PathSet size", 3, ps2.size() ); + + ps1.addAll( s2ar ); + assertEquals( "Unexpected PathSet size", 5, ps1.size() ); + + ps2.addAll( s1set ); + assertEquals( "Unexpected PathSet size", 5, ps2.size() ); + + for (String str : ps1) { + assertTrue(str, ps2.contains(str)); + assertTrue(ps2.contains("/" + str)); + assertTrue(ps1.contains(str)); + assertTrue(ps1.contains("/" + str)); + } + + for (String str : ps2) { + assertTrue(ps1.contains(str)); + assertTrue(ps1.contains("/" + str)); + assertTrue(ps2.contains(str)); + assertTrue(ps2.contains("/" + str)); + } + + ps1.addAll( s2ar, "/pref/" ); + assertEquals( "Unexpected PathSet size", 8, ps1.size() ); + + ps2.addAll( s2ar, "/pref/" ); + assertEquals( "Unexpected PathSet size", 8, ps2.size() ); + + for (String str : ps1) { + assertTrue(str, ps2.contains(str)); + assertTrue(ps2.contains("/" + str)); + assertTrue(ps1.contains(str)); + assertTrue(ps1.contains("/" + str)); + } + + for (String str : ps2) { + assertTrue(ps1.contains(str)); + assertTrue(ps1.contains("/" + str)); + assertTrue(ps2.contains(str)); + assertTrue(ps2.contains("/" + str)); + } + + PathSet ps3 = new PathSet(); + ps3.addAll(new String[]{ "a/b/c" }, "d"); + assertTrue( "Unexpected PathSet path", ps3.contains( "d/a/b/c" ) ); + } + + /** + * Test method for 'org.apache.maven.plugin.war.PathSet.addAllFilesInDirectory(File, String)' + * + * @throws IOException if an io error occurred + */ + public void testAddAllFilesInDirectory() + throws IOException + { + PathSet ps = new PathSet(); + + /* Preparing directory structure*/ + File testDir = new File( "target/testAddAllFilesInDirectory" ); + testDir.mkdirs(); + + File f1 = new File( testDir, "f1" ); + f1.createNewFile(); + File f2 = new File( testDir, "f2" ); + f2.createNewFile(); + + File d1 = new File( testDir, "d1" ); + File d1d2 = new File( testDir, "d1/d2" ); + d1d2.mkdirs(); + File d1d2f1 = new File( d1d2, "f1" ); + d1d2f1.createNewFile(); + File d1d2f2 = new File( d1d2, "f2" ); + d1d2f2.createNewFile(); + + ps.addAllFilesInDirectory( new File( "target/testAddAllFilesInDirectory" ), "123/" ); + assertEquals( "Unexpected PathSet size", 4, ps.size() ); + + /*No changes after adding duplicates*/ + ps.addAllFilesInDirectory( new File( "target/testAddAllFilesInDirectory" ), "123/" ); + assertEquals( "Unexpected PathSet size", 4, ps.size() ); + + /*Cleanup*/ + + f1.delete(); + f2.delete(); + + /*No changes after adding a subset of files*/ + ps.addAllFilesInDirectory( new File( "target/testAddAllFilesInDirectory" ), "123/" ); + assertEquals( "Unexpected PathSet size", 4, ps.size() ); + + d1d2f1.delete(); + d1d2f2.delete(); + d1d2.delete(); + d1.delete(); + testDir.delete(); + + assertTrue( ps.contains( "123/f1" ) ); + assertTrue( ps.contains( "/123/f1" ) ); + assertTrue( ps.contains( "123\\f1" ) ); + assertTrue( ps.contains( "123\\f2" ) ); + assertTrue( ps.contains( "\\123/d1\\d2/f1" ) ); + assertTrue( ps.contains( "123\\d1/d2\\f2" ) ); + assertFalse( ps.contains( "123\\f3" ) ); + } +} diff --git a/Java-base/maven-war-plugin/src/src/test/java/org/apache/maven/plugins/war/util/WebappStructureTest.java b/Java-base/maven-war-plugin/src/src/test/java/org/apache/maven/plugins/war/util/WebappStructureTest.java new file mode 100644 index 000000000..0e135de23 --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/test/java/org/apache/maven/plugins/war/util/WebappStructureTest.java @@ -0,0 +1,114 @@ +package org.apache.maven.plugins.war.util; + +/* + * 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. + */ + +import junit.framework.TestCase; +import org.apache.maven.artifact.Artifact; +import org.apache.maven.model.Dependency; +import org.apache.maven.plugins.war.util.WebappStructure; + +import java.util.ArrayList; + +/** + * @author Stephane Nicoll + */ +public class WebappStructureTest + extends TestCase +{ + public void testUnknownFileNotAvailable() + { + final WebappStructure structure = new WebappStructure( new ArrayList() ); + assertFalse( structure.isRegistered( "/foo/bar.txt" ) ); + } + + public void testRegisterSamePathTwice() + { + final WebappStructure structure = new WebappStructure( new ArrayList() ); + structure.registerFile( "overlay1", "WEB-INF/web.xml" ); + assertFalse( structure.registerFile( "currentBuild", "WEB-INF/web.xml" ) ); + } + + public void testRegisterForced() + { + final String path = "WEB-INF/web.xml"; + final WebappStructure structure = new WebappStructure( new ArrayList() ); + assertFalse("New file should return false", + structure.registerFileForced( "overlay1", path )); + assertEquals( "overlay1", structure.getOwner( path ) ); + } + + public void testRegisterSamePathTwiceForced() + { + final String path = "WEB-INF/web.xml"; + final WebappStructure structure = new WebappStructure( new ArrayList() ); + structure.registerFile( "overlay1", path ); + assertEquals( "overlay1", structure.getOwner( path ) ); + assertTrue("owner replacement should have returned true", + structure.registerFileForced( "currentBuild", path )); + assertEquals("currentBuild", structure.getOwner( path )); + } + + + protected Dependency createDependency( String groupId, String artifactId, String version, String type, String scope, + String classifier ) + { + final Dependency dep = new Dependency(); + dep.setGroupId( groupId ); + dep.setArtifactId( artifactId ); + dep.setVersion( version ); + if ( type == null ) + { + dep.setType( "jar" ); + } + else + { + dep.setType( type ); + } + if ( scope != null ) + { + dep.setScope( scope ); + } + else + { + dep.setScope( Artifact.SCOPE_COMPILE ); + } + if ( classifier != null ) + { + dep.setClassifier( classifier ); + } + return dep; + } + + protected Dependency createDependency( String groupId, String artifactId, String version, String type, + String scope ) + { + return createDependency( groupId, artifactId, version, type, scope, null ); + } + + protected Dependency createDependency( String groupId, String artifactId, String version, String type ) + { + return createDependency( groupId, artifactId, version, type, null ); + } + + protected Dependency createDependency( String groupId, String artifactId, String version ) + { + return createDependency( groupId, artifactId, version, null ); + } +} diff --git a/Java-base/maven-war-plugin/src/src/test/resources/overlays/overlay-one/WEB-INF/web.xml b/Java-base/maven-war-plugin/src/src/test/resources/overlays/overlay-one/WEB-INF/web.xml new file mode 100644 index 000000000..c39450400 --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/test/resources/overlays/overlay-one/WEB-INF/web.xml @@ -0,0 +1,21 @@ + + + Sample one overlay + diff --git a/Java-base/maven-war-plugin/src/src/test/resources/overlays/overlay-one/index.jsp b/Java-base/maven-war-plugin/src/src/test/resources/overlays/overlay-one/index.jsp new file mode 100644 index 000000000..8846f183a --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/test/resources/overlays/overlay-one/index.jsp @@ -0,0 +1,25 @@ + + + +

+ Hello World, this is overlay-one! +

+ + \ No newline at end of file diff --git a/Java-base/maven-war-plugin/src/src/test/resources/overlays/overlay-one/login.jsp b/Java-base/maven-war-plugin/src/src/test/resources/overlays/overlay-one/login.jsp new file mode 100644 index 000000000..96199c36e --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/test/resources/overlays/overlay-one/login.jsp @@ -0,0 +1,21 @@ + + + + \ No newline at end of file diff --git a/Java-base/maven-war-plugin/src/src/test/resources/overlays/overlay-two/WEB-INF/web.xml b/Java-base/maven-war-plugin/src/src/test/resources/overlays/overlay-two/WEB-INF/web.xml new file mode 100644 index 000000000..139f2c579 --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/test/resources/overlays/overlay-two/WEB-INF/web.xml @@ -0,0 +1,21 @@ + + + Sample two overlay + diff --git a/Java-base/maven-war-plugin/src/src/test/resources/overlays/overlay-two/admin.jsp b/Java-base/maven-war-plugin/src/src/test/resources/overlays/overlay-two/admin.jsp new file mode 100644 index 000000000..96199c36e --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/test/resources/overlays/overlay-two/admin.jsp @@ -0,0 +1,21 @@ + + + + \ No newline at end of file diff --git a/Java-base/maven-war-plugin/src/src/test/resources/overlays/overlay-two/index.jsp b/Java-base/maven-war-plugin/src/src/test/resources/overlays/overlay-two/index.jsp new file mode 100644 index 000000000..d0fe77df5 --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/test/resources/overlays/overlay-two/index.jsp @@ -0,0 +1,25 @@ + + + +

+ Hello World, this is overlay-two! +

+ + \ No newline at end of file diff --git a/Java-base/maven-war-plugin/src/src/test/resources/unit/sample_wars/ejb.jar b/Java-base/maven-war-plugin/src/src/test/resources/unit/sample_wars/ejb.jar new file mode 100644 index 000000000..5ad4bcf96 Binary files /dev/null and b/Java-base/maven-war-plugin/src/src/test/resources/unit/sample_wars/ejb.jar differ diff --git a/Java-base/maven-war-plugin/src/src/test/resources/unit/sample_wars/ejbclient.jar b/Java-base/maven-war-plugin/src/src/test/resources/unit/sample_wars/ejbclient.jar new file mode 100644 index 000000000..5ad4bcf96 Binary files /dev/null and b/Java-base/maven-war-plugin/src/src/test/resources/unit/sample_wars/ejbclient.jar differ diff --git a/Java-base/maven-war-plugin/src/src/test/resources/unit/sample_wars/include-exclude.war b/Java-base/maven-war-plugin/src/src/test/resources/unit/sample_wars/include-exclude.war new file mode 100644 index 000000000..4f580db08 Binary files /dev/null and b/Java-base/maven-war-plugin/src/src/test/resources/unit/sample_wars/include-exclude.war differ diff --git a/Java-base/maven-war-plugin/src/src/test/resources/unit/sample_wars/javax.servlet-api-3.0.1.jar b/Java-base/maven-war-plugin/src/src/test/resources/unit/sample_wars/javax.servlet-api-3.0.1.jar new file mode 100644 index 000000000..4e2edcc9d Binary files /dev/null and b/Java-base/maven-war-plugin/src/src/test/resources/unit/sample_wars/javax.servlet-api-3.0.1.jar differ diff --git a/Java-base/maven-war-plugin/src/src/test/resources/unit/sample_wars/sample.par b/Java-base/maven-war-plugin/src/src/test/resources/unit/sample_wars/sample.par new file mode 100644 index 000000000..e69de29bb diff --git a/Java-base/maven-war-plugin/src/src/test/resources/unit/sample_wars/simple-updated.war b/Java-base/maven-war-plugin/src/src/test/resources/unit/sample_wars/simple-updated.war new file mode 100644 index 000000000..58a5b76b2 Binary files /dev/null and b/Java-base/maven-war-plugin/src/src/test/resources/unit/sample_wars/simple-updated.war differ diff --git a/Java-base/maven-war-plugin/src/src/test/resources/unit/sample_wars/simple.aar b/Java-base/maven-war-plugin/src/src/test/resources/unit/sample_wars/simple.aar new file mode 100644 index 000000000..79681e07a Binary files /dev/null and b/Java-base/maven-war-plugin/src/src/test/resources/unit/sample_wars/simple.aar differ diff --git a/Java-base/maven-war-plugin/src/src/test/resources/unit/sample_wars/simple.jar b/Java-base/maven-war-plugin/src/src/test/resources/unit/sample_wars/simple.jar new file mode 100644 index 000000000..79681e07a Binary files /dev/null and b/Java-base/maven-war-plugin/src/src/test/resources/unit/sample_wars/simple.jar differ diff --git a/Java-base/maven-war-plugin/src/src/test/resources/unit/sample_wars/simple.mar b/Java-base/maven-war-plugin/src/src/test/resources/unit/sample_wars/simple.mar new file mode 100644 index 000000000..e69de29bb diff --git a/Java-base/maven-war-plugin/src/src/test/resources/unit/sample_wars/simple.war b/Java-base/maven-war-plugin/src/src/test/resources/unit/sample_wars/simple.war new file mode 100644 index 000000000..79681e07a Binary files /dev/null and b/Java-base/maven-war-plugin/src/src/test/resources/unit/sample_wars/simple.war differ diff --git a/Java-base/maven-war-plugin/src/src/test/resources/unit/sample_wars/simple.xar b/Java-base/maven-war-plugin/src/src/test/resources/unit/sample_wars/simple.xar new file mode 100644 index 000000000..e69de29bb diff --git a/Java-base/maven-war-plugin/src/src/test/resources/unit/sample_wars/tld.jar b/Java-base/maven-war-plugin/src/src/test/resources/unit/sample_wars/tld.jar new file mode 100644 index 000000000..e69de29bb diff --git a/Java-base/maven-war-plugin/src/src/test/resources/unit/warexplodedinplacemojo/plugin-config.xml b/Java-base/maven-war-plugin/src/src/test/resources/unit/warexplodedinplacemojo/plugin-config.xml new file mode 100644 index 000000000..f5a51e6cd --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/test/resources/unit/warexplodedinplacemojo/plugin-config.xml @@ -0,0 +1,31 @@ + + + + war-plugin-test + + + + maven-war-plugin + + + + + + diff --git a/Java-base/maven-war-plugin/src/src/test/resources/unit/warexplodedmojo/plugin-config.xml b/Java-base/maven-war-plugin/src/src/test/resources/unit/warexplodedmojo/plugin-config.xml new file mode 100644 index 000000000..f5a51e6cd --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/test/resources/unit/warexplodedmojo/plugin-config.xml @@ -0,0 +1,31 @@ + + + + war-plugin-test + + + + maven-war-plugin + + + + + + diff --git a/Java-base/maven-war-plugin/src/src/test/resources/unit/warmojotest/not-primary-artifact.xml b/Java-base/maven-war-plugin/src/src/test/resources/unit/warmojotest/not-primary-artifact.xml new file mode 100644 index 000000000..902e78b33 --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/test/resources/unit/warmojotest/not-primary-artifact.xml @@ -0,0 +1,32 @@ + + + + war-plugin-test + + + + maven-war-plugin + + false + + + + + diff --git a/Java-base/maven-war-plugin/src/src/test/resources/unit/warmojotest/plugin-config-primary-artifact.xml b/Java-base/maven-war-plugin/src/src/test/resources/unit/warmojotest/plugin-config-primary-artifact.xml new file mode 100644 index 000000000..684d0c79b --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/test/resources/unit/warmojotest/plugin-config-primary-artifact.xml @@ -0,0 +1,32 @@ + + + + war-plugin-test + + + + maven-war-plugin + + true + + + + + diff --git a/Java-base/maven-war-plugin/src/src/test/resources/unit/waroverlays/default.xml b/Java-base/maven-war-plugin/src/src/test/resources/unit/waroverlays/default.xml new file mode 100644 index 000000000..de295beaf --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/test/resources/unit/waroverlays/default.xml @@ -0,0 +1,32 @@ + + + + war-plugin-test + + + + maven-war-plugin + + + + + + + diff --git a/Java-base/maven-war-plugin/src/src/test/resources/unit/warziptest/foobar.zip b/Java-base/maven-war-plugin/src/src/test/resources/unit/warziptest/foobar.zip new file mode 100755 index 000000000..e1eb8480c Binary files /dev/null and b/Java-base/maven-war-plugin/src/src/test/resources/unit/warziptest/foobar.zip differ diff --git a/Java-base/maven-war-plugin/src/src/test/resources/unit/warziptest/war-with-zip.xml b/Java-base/maven-war-plugin/src/src/test/resources/unit/warziptest/war-with-zip.xml new file mode 100644 index 000000000..9a3d425c8 --- /dev/null +++ b/Java-base/maven-war-plugin/src/src/test/resources/unit/warziptest/war-with-zip.xml @@ -0,0 +1,31 @@ + + + + war-with-one-zip + + + + maven-war-plugin + + + + + + diff --git a/Java/maven-war-plugin-AbstractArtifactStub_103/Dockerfile b/Java/maven-war-plugin-AbstractArtifactStub_103/Dockerfile new file mode 100644 index 000000000..34955205a --- /dev/null +++ b/Java/maven-war-plugin-AbstractArtifactStub_103/Dockerfile @@ -0,0 +1,18 @@ +FROM ghcr.io/kupl/starlab-benchmarks/java-base:maven-war-plugin + +ENV TZ=Asia/Seoul + +COPY ./metadata.json . +COPY ./npe.json . +COPY ./buggy.java /tmp/buggy.java +RUN export BUGGY_PATH=$(cat metadata.json | jq -r ".npe.filepath") \ + && export BUGGY_LINE=$(cat metadata.json | jq -r ".npe.line") \ + && export BUGGY_MTHD=$(cat metadata.json | jq -r ".npe.npe_method") \ + && mv /tmp/buggy.java $BUGGY_PATH \ + && echo "[{\"filepath\": \"$BUGGY_PATH\", \"line\": $BUGGY_LINE, \"method_name\": \"$BUGGY_MTHD\"}]" | jq . > traces.json + +RUN git init . && git add -A + +RUN $(cat metadata.json | jq -r ".buildCommand") + +RUN $(cat metadata.json | jq -r ".testCommand"); if [ $? -eq 0 ]; then exit 1; fi diff --git a/Java/maven-war-plugin-AbstractArtifactStub_103/buggy.java b/Java/maven-war-plugin-AbstractArtifactStub_103/buggy.java new file mode 100644 index 000000000..6163fae79 --- /dev/null +++ b/Java/maven-war-plugin-AbstractArtifactStub_103/buggy.java @@ -0,0 +1,147 @@ +package org.apache.maven.plugins.war.stub; + +/* + * 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. + */ + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.handler.ArtifactHandler; +import org.apache.maven.artifact.handler.DefaultArtifactHandler; +import org.apache.maven.artifact.versioning.VersionRange; +import org.apache.maven.plugin.testing.stubs.ArtifactStub; + +public abstract class AbstractArtifactStub + extends ArtifactStub +{ + protected String basedir; + + public AbstractArtifactStub( String _basedir ) + { + basedir = _basedir; + } + + public String getVersion() + { + return "0.0-Test"; + } + + @Override + public String getBaseVersion() + { + return getVersion(); + } + + public String getScope() + { + return Artifact.SCOPE_RUNTIME; + } + + public VersionRange getVersionRange() + { + return VersionRange.createFromVersion( getVersion()); + } + + public boolean isOptional() + { + return false; + } + + public ArtifactHandler getArtifactHandler() + { + return new DefaultArtifactHandler( getType() ); + } + + /* + * TODO: Copied from org/apache/maven/artifact/DefaultArtifact.java; Consider merging... + */ +/* TODO: Copied from org/apache/maven/artifact/DefaultArtifact.java; Consider merging... */ +public int compareTo(org.apache.maven.artifact.Artifact a) { + /* -- We need to support groupId=null (it is missing in DefaultArtifact.java) */ + int result; + if (a.getGroupId() != null) { + result = getGroupId().compareTo(a.getGroupId()); + } else { + result = (getGroupId() == null) ? 0 : -1; + } + /* -- */ + if (result == 0) { + result = getArtifactId().compareTo(a.getArtifactId()); + if (result == 0) { + result = getType().compareTo(a.getType()); + if (result == 0) { + { + { + result = /* NPEX_NULL_EXP */ + getClassifier().compareTo(/* NPEX_NULL_EXP */ + a.getClassifier()); + } + } + if (result == 0) { + // We don't consider the version range in the comparison, just the resolved version + result = getVersion().compareTo(a.getVersion()); + } + } + } + } + return result; +} + + /* + * TODO: Copied from org/apache/maven/artifact/DefaultArtifact.java; Consider merging... + */ + public boolean equals( Object o ) + { + if ( o == this ) + { + return true; + } + + if ( !( o instanceof Artifact ) ) + { + return false; + } + + Artifact a = (Artifact) o; + + /* -- We need to support groupId=null (it is missing in DefaultArtifact.java) */ + if ( a.getGroupId() == null ? ( getGroupId() != null ) : a.getGroupId().equals( getGroupId() ) ) + { + return false; + } + else if ( !a.getArtifactId().equals( getArtifactId() ) ) + { + return false; + } + else if ( !a.getVersion().equals( getVersion() ) ) + { + return false; + } + else if ( !a.getType().equals( getType() ) ) + { + return false; + } + else if ( a.getClassifier() == null ? getClassifier() != null : !a.getClassifier().equals( getClassifier() ) ) + { + return false; + } + + // We don't consider the version range in the comparison, just the resolved version + + return true; + } +} diff --git a/Java/maven-war-plugin-AbstractArtifactStub_103/metadata.json b/Java/maven-war-plugin-AbstractArtifactStub_103/metadata.json new file mode 100644 index 000000000..b68d55db7 --- /dev/null +++ b/Java/maven-war-plugin-AbstractArtifactStub_103/metadata.json @@ -0,0 +1,21 @@ +{ + "language": "java", + "id": "maven-war-plugin-AbstractArtifactStub_103", + "buggyPath": ".", + "referencePath": null, + "buildCommand": "mvn package -V -B -Denforcer.skip=true -Dcheckstyle.skip=true -Dcobertura.skip=true -Drat.skip=true -Dlicense.skip=true -Dfindbugs.skip=true -Dgpg.skip=true -Dskip.npm=true -Dskip.gulp=true -Dskip.bower=true -Drat.numUnapprovedLicenses=100 -DskipTests=true -DskipITs=true -Dtest=None -DfailIfNoTests=false", + "testCommand": "mvn test -V -B -Denforcer.skip=true -Dcheckstyle.skip=true -Dcobertura.skip=true -Drat.skip=true -Dlicense.skip=true -Dfindbugs.skip=true -Dgpg.skip=true -Dskip.npm=true -Dskip.gulp=true -Dskip.bower=true -Drat.numUnapprovedLicenses=100", + "categories": [ + "safety", + "npe" + ], + "npe": { + "filepath": "src/test/java/org/apache/maven/plugins/war/stub/AbstractArtifactStub.java", + "line": 91, + "npe_method": "compareTo", + "deref_field": "getClassifier", + "npe_class": "AbstractArtifactStub", + "repo": "maven-war-plugin", + "bug_id": "AbstractArtifactStub_103" + } +} diff --git a/Java/maven-war-plugin-AbstractArtifactStub_103/npe.json b/Java/maven-war-plugin-AbstractArtifactStub_103/npe.json new file mode 100644 index 000000000..02cda04e0 --- /dev/null +++ b/Java/maven-war-plugin-AbstractArtifactStub_103/npe.json @@ -0,0 +1,7 @@ +{ + "filepath": "src/test/java/org/apache/maven/plugins/war/stub/AbstractArtifactStub.java", + "line": 91, + "npe_method": "compareTo", + "deref_field": "getClassifier", + "npe_class": "AbstractArtifactStub" +} \ No newline at end of file diff --git a/Java/maven-war-plugin-AbstractArtifactStub_76/Dockerfile b/Java/maven-war-plugin-AbstractArtifactStub_76/Dockerfile new file mode 100644 index 000000000..34955205a --- /dev/null +++ b/Java/maven-war-plugin-AbstractArtifactStub_76/Dockerfile @@ -0,0 +1,18 @@ +FROM ghcr.io/kupl/starlab-benchmarks/java-base:maven-war-plugin + +ENV TZ=Asia/Seoul + +COPY ./metadata.json . +COPY ./npe.json . +COPY ./buggy.java /tmp/buggy.java +RUN export BUGGY_PATH=$(cat metadata.json | jq -r ".npe.filepath") \ + && export BUGGY_LINE=$(cat metadata.json | jq -r ".npe.line") \ + && export BUGGY_MTHD=$(cat metadata.json | jq -r ".npe.npe_method") \ + && mv /tmp/buggy.java $BUGGY_PATH \ + && echo "[{\"filepath\": \"$BUGGY_PATH\", \"line\": $BUGGY_LINE, \"method_name\": \"$BUGGY_MTHD\"}]" | jq . > traces.json + +RUN git init . && git add -A + +RUN $(cat metadata.json | jq -r ".buildCommand") + +RUN $(cat metadata.json | jq -r ".testCommand"); if [ $? -eq 0 ]; then exit 1; fi diff --git a/Java/maven-war-plugin-AbstractArtifactStub_76/buggy.java b/Java/maven-war-plugin-AbstractArtifactStub_76/buggy.java new file mode 100644 index 000000000..314b71093 --- /dev/null +++ b/Java/maven-war-plugin-AbstractArtifactStub_76/buggy.java @@ -0,0 +1,148 @@ +package org.apache.maven.plugins.war.stub; + +/* + * 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. + */ + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.handler.ArtifactHandler; +import org.apache.maven.artifact.handler.DefaultArtifactHandler; +import org.apache.maven.artifact.versioning.VersionRange; +import org.apache.maven.plugin.testing.stubs.ArtifactStub; + +public abstract class AbstractArtifactStub + extends ArtifactStub +{ + protected String basedir; + + public AbstractArtifactStub( String _basedir ) + { + basedir = _basedir; + } + + public String getVersion() + { + return "0.0-Test"; + } + + @Override + public String getBaseVersion() + { + return getVersion(); + } + + public String getScope() + { + return Artifact.SCOPE_RUNTIME; + } + + public VersionRange getVersionRange() + { + return VersionRange.createFromVersion( getVersion()); + } + + public boolean isOptional() + { + return false; + } + + public ArtifactHandler getArtifactHandler() + { + return new DefaultArtifactHandler( getType() ); + } + + /* + * TODO: Copied from org/apache/maven/artifact/DefaultArtifact.java; Consider merging... + */ +/* TODO: Copied from org/apache/maven/artifact/DefaultArtifact.java; Consider merging... */ +public int compareTo(org.apache.maven.artifact.Artifact a) { + /* -- We need to support groupId=null (it is missing in DefaultArtifact.java) */ + int result; + { + result = getGroupId().compareTo(/* NPEX_NULL_EXP */ + a.getGroupId()); + } + /* -- */ + if (result == 0) { + result = getArtifactId().compareTo(a.getArtifactId()); + if (result == 0) { + result = getType().compareTo(a.getType()); + if (result == 0) { + if (getClassifier() == null) { + if (a.getClassifier() != null) { + result = 1; + } + } else if (a.getClassifier() != null) { + result = getClassifier().compareTo(a.getClassifier()); + } else { + result = -1; + } + if (result == 0) { + // We don't consider the version range in the comparison, just the resolved version + result = getVersion().compareTo(a.getVersion()); + } + } + } + } + return result; +} + + /* + * TODO: Copied from org/apache/maven/artifact/DefaultArtifact.java; Consider merging... + */ + public boolean equals( Object o ) + { + if ( o == this ) + { + return true; + } + + if ( !( o instanceof Artifact ) ) + { + return false; + } + + Artifact a = (Artifact) o; + + /* -- We need to support groupId=null (it is missing in DefaultArtifact.java) */ + if ( a.getGroupId() == null ? ( getGroupId() != null ) : a.getGroupId().equals( getGroupId() ) ) + { + return false; + } + else if ( !a.getArtifactId().equals( getArtifactId() ) ) + { + return false; + } + else if ( !a.getVersion().equals( getVersion() ) ) + { + return false; + } + else if ( !a.getType().equals( getType() ) ) + { + return false; + } + else if ( a.getClassifier() == null ? getClassifier() != null : !a.getClassifier().equals( getClassifier() ) ) + { + return false; + } + + // We don't consider the version range in the comparison, just the resolved version + + return true; + } +} diff --git a/Java/maven-war-plugin-AbstractArtifactStub_76/metadata.json b/Java/maven-war-plugin-AbstractArtifactStub_76/metadata.json new file mode 100644 index 000000000..42e10b7b6 --- /dev/null +++ b/Java/maven-war-plugin-AbstractArtifactStub_76/metadata.json @@ -0,0 +1,21 @@ +{ + "language": "java", + "id": "maven-war-plugin-AbstractArtifactStub_76", + "buggyPath": ".", + "referencePath": null, + "buildCommand": "mvn package -V -B -Denforcer.skip=true -Dcheckstyle.skip=true -Dcobertura.skip=true -Drat.skip=true -Dlicense.skip=true -Dfindbugs.skip=true -Dgpg.skip=true -Dskip.npm=true -Dskip.gulp=true -Dskip.bower=true -Drat.numUnapprovedLicenses=100 -DskipTests=true -DskipITs=true -Dtest=None -DfailIfNoTests=false", + "testCommand": "mvn test -V -B -Denforcer.skip=true -Dcheckstyle.skip=true -Dcobertura.skip=true -Drat.skip=true -Dlicense.skip=true -Dfindbugs.skip=true -Dgpg.skip=true -Dskip.npm=true -Dskip.gulp=true -Dskip.bower=true -Drat.numUnapprovedLicenses=100", + "categories": [ + "safety", + "npe" + ], + "npe": { + "filepath": "src/test/java/org/apache/maven/plugins/war/stub/AbstractArtifactStub.java", + "line": 78, + "npe_method": "compareTo", + "deref_field": "getGroupId", + "npe_class": "AbstractArtifactStub", + "repo": "maven-war-plugin", + "bug_id": "AbstractArtifactStub_76" + } +} diff --git a/Java/maven-war-plugin-AbstractArtifactStub_76/npe.json b/Java/maven-war-plugin-AbstractArtifactStub_76/npe.json new file mode 100644 index 000000000..b338e3e39 --- /dev/null +++ b/Java/maven-war-plugin-AbstractArtifactStub_76/npe.json @@ -0,0 +1,7 @@ +{ + "filepath": "src/test/java/org/apache/maven/plugins/war/stub/AbstractArtifactStub.java", + "line": 78, + "npe_method": "compareTo", + "deref_field": "getGroupId", + "npe_class": "AbstractArtifactStub" +} \ No newline at end of file diff --git a/Java/maven-war-plugin-AbstractWarExplodedMojoTest_104/Dockerfile b/Java/maven-war-plugin-AbstractWarExplodedMojoTest_104/Dockerfile new file mode 100644 index 000000000..34955205a --- /dev/null +++ b/Java/maven-war-plugin-AbstractWarExplodedMojoTest_104/Dockerfile @@ -0,0 +1,18 @@ +FROM ghcr.io/kupl/starlab-benchmarks/java-base:maven-war-plugin + +ENV TZ=Asia/Seoul + +COPY ./metadata.json . +COPY ./npe.json . +COPY ./buggy.java /tmp/buggy.java +RUN export BUGGY_PATH=$(cat metadata.json | jq -r ".npe.filepath") \ + && export BUGGY_LINE=$(cat metadata.json | jq -r ".npe.line") \ + && export BUGGY_MTHD=$(cat metadata.json | jq -r ".npe.npe_method") \ + && mv /tmp/buggy.java $BUGGY_PATH \ + && echo "[{\"filepath\": \"$BUGGY_PATH\", \"line\": $BUGGY_LINE, \"method_name\": \"$BUGGY_MTHD\"}]" | jq . > traces.json + +RUN git init . && git add -A + +RUN $(cat metadata.json | jq -r ".buildCommand") + +RUN $(cat metadata.json | jq -r ".testCommand"); if [ $? -eq 0 ]; then exit 1; fi diff --git a/Java/maven-war-plugin-AbstractWarExplodedMojoTest_104/buggy.java b/Java/maven-war-plugin-AbstractWarExplodedMojoTest_104/buggy.java new file mode 100644 index 000000000..90dc65e98 --- /dev/null +++ b/Java/maven-war-plugin-AbstractWarExplodedMojoTest_104/buggy.java @@ -0,0 +1,304 @@ +package org.apache.maven.plugins.war; + +/* + * 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. + */ + +import org.apache.maven.plugin.testing.stubs.ArtifactStub; +import org.apache.maven.plugins.war.stub.MavenProjectArtifactsStub; +import org.codehaus.plexus.util.FileUtils; + +import java.io.File; +import java.io.FileFilter; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.LinkedList; +import java.util.List; + +/** + * @author Stephane Nicoll + */ +public abstract class AbstractWarExplodedMojoTest + extends AbstractWarMojoTest +{ + + protected WarExplodedMojo mojo; + + public void setUp() + throws Exception + { + super.setUp(); + mojo = (WarExplodedMojo) lookupMojo( "exploded", getPomFile() ); + } + + /** + * Returns the pom configuration to use. + * + * @return the pom configuration + */ + protected abstract File getPomFile(); + + /** + * Returns the test directory to use. + * + * @return the test directory + */ + protected abstract File getTestDirectory(); + + /** + * Configures the exploded mojo for the specified test. + * + * If the sourceFiles parameter is null, sample JSPs are created by default. + * + * @param testId the id of the test + * @param artifactStubs the dependencies (may be null) + * @param sourceFiles the source files to create (may be null) + * @return the webapp directory + * @throws Exception if an error occurs while configuring the mojo + */ +/** + * Configures the exploded mojo for the specified test. + * + * If the sourceFiles parameter is null, sample JSPs are created by default. + * + * @param testId + * the id of the test + * @param artifactStubs + * the dependencies (may be null) + * @param sourceFiles + * the source files to create (may be null) + * @return the webapp directory + * @throws Exception + * if an error occurs while configuring the mojo + */ +protected java.io.File setUpMojo(final java.lang.String testId, org.apache.maven.plugin.testing.stubs.ArtifactStub[] artifactStubs, java.lang.String[] sourceFiles) throws java.lang.Exception { + final org.apache.maven.plugins.war.stub.MavenProjectArtifactsStub project = new org.apache.maven.plugins.war.stub.MavenProjectArtifactsStub(); + final java.io.File webAppDirectory = new java.io.File(getTestDirectory(), testId); + // Create the webapp sources + java.io.File webAppSource; + if (sourceFiles == null) { + webAppSource = createWebAppSource(testId); + } else { + webAppSource = createWebAppSource(testId, false); + for (java.lang.String sourceFile : sourceFiles) { + java.io.File sample = new java.io.File(webAppSource, sourceFile); + createFile(sample); + } + } + final java.io.File classesDir = createClassesDir(testId, true); + final java.io.File workDirectory = new java.io.File(getTestDirectory(), "/war/work-" + testId); + createDir(workDirectory); + { + for (org.apache.maven.plugin.testing.stubs.ArtifactStub artifactStub : /* NPEX_NULL_EXP */ + artifactStubs) { + project.addArtifact(artifactStub); + } + } + configureMojo(mojo, new java.util.LinkedList(), classesDir, webAppSource, webAppDirectory, project); + setVariableValueToObject(mojo, "workDirectory", workDirectory); + return webAppDirectory; +} + + /** + * Configures the exploded mojo for the specified test. + * + * @param testId the id of the test + * @param artifactStubs the dependencies (may be null) + * @return the webapp directory + * @throws Exception if an error occurs while configuring the mojo + */ + protected File setUpMojo( final String testId, ArtifactStub[] artifactStubs ) + throws Exception + { + return setUpMojo( testId, artifactStubs, null ); + } + + /** + * Cleans up a directory. + * + * @param directory the directory to remove + * @throws IOException if an error occurred while removing the directory + */ + protected void cleanDirectory( File directory ) + throws IOException + { + if ( directory != null && directory.isDirectory() && directory.exists() ) + { + FileUtils.deleteDirectory( directory ); + } + } + + /** + * Asserts the default content of the war based on the specified webapp directory. + * + * @param webAppDirectory the webapp directory + * @return a list of File objects that have been asserted + */ + protected List assertDefaultContent( File webAppDirectory ) + { + // Validate content of the webapp + File expectedWebSourceFile = new File( webAppDirectory, "pansit.jsp" ); + File expectedWebSource2File = new File( webAppDirectory, "org/web/app/last-exile.jsp" ); + + assertTrue( "source file not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists() ); + assertTrue( "source file not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists() ); + + final List content = new ArrayList<>(); + content.add( expectedWebSourceFile ); + content.add( expectedWebSource2File ); + + return content; + } + + /** + * Asserts the web.xml file of the war based on the specified webapp directory. + * + * @param webAppDirectory the webapp directory + * @return a list with the web.xml File object + */ + protected List assertWebXml( File webAppDirectory ) + { + File expectedWEBXMLFile = new File( webAppDirectory, "WEB-INF/web.xml" ); + assertTrue( "web xml not found: " + expectedWEBXMLFile.toString(), expectedWEBXMLFile.exists() ); + + final List content = new ArrayList<>(); + content.add( expectedWEBXMLFile ); + + return content; + } + + /** + * Asserts custom content of the war based on the specified webapp directory. + * + * @param webAppDirectory the webapp directory + * @param filePaths an array of file paths relative to the webapp directory + * @param customMessage a custom message if an assertion fails + * @return a list of File objects that have been inspected + */ + protected List assertCustomContent( File webAppDirectory, String[] filePaths, String customMessage ) + { + final List content = new ArrayList<>(); + for ( String filePath : filePaths ) + { + final File expectedFile = new File( webAppDirectory, filePath ); + if ( customMessage != null ) + { + assertTrue( customMessage + " - " + expectedFile.toString(), expectedFile.exists() ); + } + else + { + assertTrue( "source file not found: " + expectedFile.toString(), expectedFile.exists() ); + } + content.add( expectedFile ); + } + return content; + } + + /** + * Asserts that the webapp contains only the specified files. + * + * @param webAppDirectory the webapp directory + * @param expectedFiles the expected files + * @param filter an optional filter to ignore some resources + */ + protected void assertWebAppContent( File webAppDirectory, List expectedFiles, FileFilter filter ) + { + final List webAppContent = new ArrayList<>(); + if ( filter != null ) + { + buildFilesList( webAppDirectory, filter, webAppContent ); + } + else + { + buildFilesList( webAppDirectory, new FileFilterImpl( webAppDirectory, null ), webAppContent ); + } + + // Now we have the files, sort them. + Collections.sort( expectedFiles ); + Collections.sort( webAppContent ); + assertEquals( "Invalid webapp content, expected " + expectedFiles.size() + "file(s) " + expectedFiles + + " but got " + webAppContent.size() + " file(s) " + webAppContent, expectedFiles, webAppContent ); + } + + /** + * Builds the list of files and directories from the specified dir. + * + * Note that the filter is not used the usual way. If the filter does not accept the current file, it's not added + * but yet the subdirectories are added if any. + * + * @param dir the base directory + * @param filter the filter + * @param content the current content, updated recursively + */ + private void buildFilesList( final File dir, FileFilter filter, final List content ) + { + final File[] files = dir.listFiles(); + + for ( File file : files ) + { + // Add the file if the filter is ok with it + if ( filter.accept( file ) ) + { + content.add( file ); + } + + // Even if the file is not accepted and is a directory, add it + if ( file.isDirectory() ) + { + buildFilesList( file, filter, content ); + } + + } + } + + class FileFilterImpl + implements FileFilter + { + + private final List rejectedFilePaths; + + private final int webAppDirIndex; + + public FileFilterImpl( File webAppDirectory, String[] rejectedFilePaths ) + { + if ( rejectedFilePaths != null ) + { + this.rejectedFilePaths = Arrays.asList( rejectedFilePaths ); + } + else + { + this.rejectedFilePaths = new ArrayList<>(); + } + this.webAppDirIndex = webAppDirectory.getAbsolutePath().length() + 1; + } + + public boolean accept( File file ) + { + String effectiveRelativePath = buildRelativePath( file ); + return !( rejectedFilePaths.contains( effectiveRelativePath ) || file.isDirectory() ); + } + + private String buildRelativePath( File f ) + { + return f.getAbsolutePath().substring( webAppDirIndex ); + } + } + +} diff --git a/Java/maven-war-plugin-AbstractWarExplodedMojoTest_104/metadata.json b/Java/maven-war-plugin-AbstractWarExplodedMojoTest_104/metadata.json new file mode 100644 index 000000000..c9aac8575 --- /dev/null +++ b/Java/maven-war-plugin-AbstractWarExplodedMojoTest_104/metadata.json @@ -0,0 +1,21 @@ +{ + "language": "java", + "id": "maven-war-plugin-AbstractWarExplodedMojoTest_104", + "buggyPath": ".", + "referencePath": null, + "buildCommand": "mvn package -V -B -Denforcer.skip=true -Dcheckstyle.skip=true -Dcobertura.skip=true -Drat.skip=true -Dlicense.skip=true -Dfindbugs.skip=true -Dgpg.skip=true -Dskip.npm=true -Dskip.gulp=true -Dskip.bower=true -Drat.numUnapprovedLicenses=100 -DskipTests=true -DskipITs=true -Dtest=None -DfailIfNoTests=false", + "testCommand": "mvn test -V -B -Denforcer.skip=true -Dcheckstyle.skip=true -Dcobertura.skip=true -Drat.skip=true -Dlicense.skip=true -Dfindbugs.skip=true -Dgpg.skip=true -Dskip.npm=true -Dskip.gulp=true -Dskip.bower=true -Drat.numUnapprovedLicenses=100", + "categories": [ + "safety", + "npe" + ], + "npe": { + "filepath": "src/test/java/org/apache/maven/plugins/war/AbstractWarExplodedMojoTest.java", + "line": 110, + "npe_method": "setUpMojo", + "deref_field": "artifactStubs", + "npe_class": "AbstractWarExplodedMojoTest", + "repo": "maven-war-plugin", + "bug_id": "AbstractWarExplodedMojoTest_104" + } +} diff --git a/Java/maven-war-plugin-AbstractWarExplodedMojoTest_104/npe.json b/Java/maven-war-plugin-AbstractWarExplodedMojoTest_104/npe.json new file mode 100644 index 000000000..a413444cb --- /dev/null +++ b/Java/maven-war-plugin-AbstractWarExplodedMojoTest_104/npe.json @@ -0,0 +1,7 @@ +{ + "filepath": "src/test/java/org/apache/maven/plugins/war/AbstractWarExplodedMojoTest.java", + "line": 110, + "npe_method": "setUpMojo", + "deref_field": "artifactStubs", + "npe_class": "AbstractWarExplodedMojoTest" +} \ No newline at end of file diff --git a/Java/maven-war-plugin-AbstractWarExplodedMojoTest_84/Dockerfile b/Java/maven-war-plugin-AbstractWarExplodedMojoTest_84/Dockerfile new file mode 100644 index 000000000..34955205a --- /dev/null +++ b/Java/maven-war-plugin-AbstractWarExplodedMojoTest_84/Dockerfile @@ -0,0 +1,18 @@ +FROM ghcr.io/kupl/starlab-benchmarks/java-base:maven-war-plugin + +ENV TZ=Asia/Seoul + +COPY ./metadata.json . +COPY ./npe.json . +COPY ./buggy.java /tmp/buggy.java +RUN export BUGGY_PATH=$(cat metadata.json | jq -r ".npe.filepath") \ + && export BUGGY_LINE=$(cat metadata.json | jq -r ".npe.line") \ + && export BUGGY_MTHD=$(cat metadata.json | jq -r ".npe.npe_method") \ + && mv /tmp/buggy.java $BUGGY_PATH \ + && echo "[{\"filepath\": \"$BUGGY_PATH\", \"line\": $BUGGY_LINE, \"method_name\": \"$BUGGY_MTHD\"}]" | jq . > traces.json + +RUN git init . && git add -A + +RUN $(cat metadata.json | jq -r ".buildCommand") + +RUN $(cat metadata.json | jq -r ".testCommand"); if [ $? -eq 0 ]; then exit 1; fi diff --git a/Java/maven-war-plugin-AbstractWarExplodedMojoTest_84/buggy.java b/Java/maven-war-plugin-AbstractWarExplodedMojoTest_84/buggy.java new file mode 100644 index 000000000..12a483f54 --- /dev/null +++ b/Java/maven-war-plugin-AbstractWarExplodedMojoTest_84/buggy.java @@ -0,0 +1,302 @@ +package org.apache.maven.plugins.war; + +/* + * 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. + */ + +import org.apache.maven.plugin.testing.stubs.ArtifactStub; +import org.apache.maven.plugins.war.stub.MavenProjectArtifactsStub; +import org.codehaus.plexus.util.FileUtils; + +import java.io.File; +import java.io.FileFilter; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.LinkedList; +import java.util.List; + +/** + * @author Stephane Nicoll + */ +public abstract class AbstractWarExplodedMojoTest + extends AbstractWarMojoTest +{ + + protected WarExplodedMojo mojo; + + public void setUp() + throws Exception + { + super.setUp(); + mojo = (WarExplodedMojo) lookupMojo( "exploded", getPomFile() ); + } + + /** + * Returns the pom configuration to use. + * + * @return the pom configuration + */ + protected abstract File getPomFile(); + + /** + * Returns the test directory to use. + * + * @return the test directory + */ + protected abstract File getTestDirectory(); + + /** + * Configures the exploded mojo for the specified test. + * + * If the sourceFiles parameter is null, sample JSPs are created by default. + * + * @param testId the id of the test + * @param artifactStubs the dependencies (may be null) + * @param sourceFiles the source files to create (may be null) + * @return the webapp directory + * @throws Exception if an error occurs while configuring the mojo + */ +/** + * Configures the exploded mojo for the specified test. + * + * If the sourceFiles parameter is null, sample JSPs are created by default. + * + * @param testId + * the id of the test + * @param artifactStubs + * the dependencies (may be null) + * @param sourceFiles + * the source files to create (may be null) + * @return the webapp directory + * @throws Exception + * if an error occurs while configuring the mojo + */ +protected java.io.File setUpMojo(final java.lang.String testId, org.apache.maven.plugin.testing.stubs.ArtifactStub[] artifactStubs, java.lang.String[] sourceFiles) throws java.lang.Exception { + final org.apache.maven.plugins.war.stub.MavenProjectArtifactsStub project = new org.apache.maven.plugins.war.stub.MavenProjectArtifactsStub(); + final java.io.File webAppDirectory = new java.io.File(getTestDirectory(), testId); + // Create the webapp sources + java.io.File webAppSource; + { + webAppSource = createWebAppSource(testId, false); + for (java.lang.String sourceFile : /* NPEX_NULL_EXP */ + sourceFiles) { + java.io.File sample = new java.io.File(webAppSource, sourceFile); + createFile(sample); + } + } + final java.io.File classesDir = createClassesDir(testId, true); + final java.io.File workDirectory = new java.io.File(getTestDirectory(), "/war/work-" + testId); + createDir(workDirectory); + if (artifactStubs != null) { + for (org.apache.maven.plugin.testing.stubs.ArtifactStub artifactStub : artifactStubs) { + project.addArtifact(artifactStub); + } + } + configureMojo(mojo, new java.util.LinkedList(), classesDir, webAppSource, webAppDirectory, project); + setVariableValueToObject(mojo, "workDirectory", workDirectory); + return webAppDirectory; +} + + /** + * Configures the exploded mojo for the specified test. + * + * @param testId the id of the test + * @param artifactStubs the dependencies (may be null) + * @return the webapp directory + * @throws Exception if an error occurs while configuring the mojo + */ + protected File setUpMojo( final String testId, ArtifactStub[] artifactStubs ) + throws Exception + { + return setUpMojo( testId, artifactStubs, null ); + } + + /** + * Cleans up a directory. + * + * @param directory the directory to remove + * @throws IOException if an error occurred while removing the directory + */ + protected void cleanDirectory( File directory ) + throws IOException + { + if ( directory != null && directory.isDirectory() && directory.exists() ) + { + FileUtils.deleteDirectory( directory ); + } + } + + /** + * Asserts the default content of the war based on the specified webapp directory. + * + * @param webAppDirectory the webapp directory + * @return a list of File objects that have been asserted + */ + protected List assertDefaultContent( File webAppDirectory ) + { + // Validate content of the webapp + File expectedWebSourceFile = new File( webAppDirectory, "pansit.jsp" ); + File expectedWebSource2File = new File( webAppDirectory, "org/web/app/last-exile.jsp" ); + + assertTrue( "source file not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists() ); + assertTrue( "source file not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists() ); + + final List content = new ArrayList<>(); + content.add( expectedWebSourceFile ); + content.add( expectedWebSource2File ); + + return content; + } + + /** + * Asserts the web.xml file of the war based on the specified webapp directory. + * + * @param webAppDirectory the webapp directory + * @return a list with the web.xml File object + */ + protected List assertWebXml( File webAppDirectory ) + { + File expectedWEBXMLFile = new File( webAppDirectory, "WEB-INF/web.xml" ); + assertTrue( "web xml not found: " + expectedWEBXMLFile.toString(), expectedWEBXMLFile.exists() ); + + final List content = new ArrayList<>(); + content.add( expectedWEBXMLFile ); + + return content; + } + + /** + * Asserts custom content of the war based on the specified webapp directory. + * + * @param webAppDirectory the webapp directory + * @param filePaths an array of file paths relative to the webapp directory + * @param customMessage a custom message if an assertion fails + * @return a list of File objects that have been inspected + */ + protected List assertCustomContent( File webAppDirectory, String[] filePaths, String customMessage ) + { + final List content = new ArrayList<>(); + for ( String filePath : filePaths ) + { + final File expectedFile = new File( webAppDirectory, filePath ); + if ( customMessage != null ) + { + assertTrue( customMessage + " - " + expectedFile.toString(), expectedFile.exists() ); + } + else + { + assertTrue( "source file not found: " + expectedFile.toString(), expectedFile.exists() ); + } + content.add( expectedFile ); + } + return content; + } + + /** + * Asserts that the webapp contains only the specified files. + * + * @param webAppDirectory the webapp directory + * @param expectedFiles the expected files + * @param filter an optional filter to ignore some resources + */ + protected void assertWebAppContent( File webAppDirectory, List expectedFiles, FileFilter filter ) + { + final List webAppContent = new ArrayList<>(); + if ( filter != null ) + { + buildFilesList( webAppDirectory, filter, webAppContent ); + } + else + { + buildFilesList( webAppDirectory, new FileFilterImpl( webAppDirectory, null ), webAppContent ); + } + + // Now we have the files, sort them. + Collections.sort( expectedFiles ); + Collections.sort( webAppContent ); + assertEquals( "Invalid webapp content, expected " + expectedFiles.size() + "file(s) " + expectedFiles + + " but got " + webAppContent.size() + " file(s) " + webAppContent, expectedFiles, webAppContent ); + } + + /** + * Builds the list of files and directories from the specified dir. + * + * Note that the filter is not used the usual way. If the filter does not accept the current file, it's not added + * but yet the subdirectories are added if any. + * + * @param dir the base directory + * @param filter the filter + * @param content the current content, updated recursively + */ + private void buildFilesList( final File dir, FileFilter filter, final List content ) + { + final File[] files = dir.listFiles(); + + for ( File file : files ) + { + // Add the file if the filter is ok with it + if ( filter.accept( file ) ) + { + content.add( file ); + } + + // Even if the file is not accepted and is a directory, add it + if ( file.isDirectory() ) + { + buildFilesList( file, filter, content ); + } + + } + } + + class FileFilterImpl + implements FileFilter + { + + private final List rejectedFilePaths; + + private final int webAppDirIndex; + + public FileFilterImpl( File webAppDirectory, String[] rejectedFilePaths ) + { + if ( rejectedFilePaths != null ) + { + this.rejectedFilePaths = Arrays.asList( rejectedFilePaths ); + } + else + { + this.rejectedFilePaths = new ArrayList<>(); + } + this.webAppDirIndex = webAppDirectory.getAbsolutePath().length() + 1; + } + + public boolean accept( File file ) + { + String effectiveRelativePath = buildRelativePath( file ); + return !( rejectedFilePaths.contains( effectiveRelativePath ) || file.isDirectory() ); + } + + private String buildRelativePath( File f ) + { + return f.getAbsolutePath().substring( webAppDirIndex ); + } + } + +} diff --git a/Java/maven-war-plugin-AbstractWarExplodedMojoTest_84/metadata.json b/Java/maven-war-plugin-AbstractWarExplodedMojoTest_84/metadata.json new file mode 100644 index 000000000..af40fb8f2 --- /dev/null +++ b/Java/maven-war-plugin-AbstractWarExplodedMojoTest_84/metadata.json @@ -0,0 +1,21 @@ +{ + "language": "java", + "id": "maven-war-plugin-AbstractWarExplodedMojoTest_84", + "buggyPath": ".", + "referencePath": null, + "buildCommand": "mvn package -V -B -Denforcer.skip=true -Dcheckstyle.skip=true -Dcobertura.skip=true -Drat.skip=true -Dlicense.skip=true -Dfindbugs.skip=true -Dgpg.skip=true -Dskip.npm=true -Dskip.gulp=true -Dskip.bower=true -Drat.numUnapprovedLicenses=100 -DskipTests=true -DskipITs=true -Dtest=None -DfailIfNoTests=false", + "testCommand": "mvn test -V -B -Denforcer.skip=true -Dcheckstyle.skip=true -Dcobertura.skip=true -Drat.skip=true -Dlicense.skip=true -Dfindbugs.skip=true -Dgpg.skip=true -Dskip.npm=true -Dskip.gulp=true -Dskip.bower=true -Drat.numUnapprovedLicenses=100", + "categories": [ + "safety", + "npe" + ], + "npe": { + "filepath": "src/test/java/org/apache/maven/plugins/war/AbstractWarExplodedMojoTest.java", + "line": 99, + "npe_method": "setUpMojo", + "deref_field": "sourceFiles", + "npe_class": "AbstractWarExplodedMojoTest", + "repo": "maven-war-plugin", + "bug_id": "AbstractWarExplodedMojoTest_84" + } +} diff --git a/Java/maven-war-plugin-AbstractWarExplodedMojoTest_84/npe.json b/Java/maven-war-plugin-AbstractWarExplodedMojoTest_84/npe.json new file mode 100644 index 000000000..f1b3686da --- /dev/null +++ b/Java/maven-war-plugin-AbstractWarExplodedMojoTest_84/npe.json @@ -0,0 +1,7 @@ +{ + "filepath": "src/test/java/org/apache/maven/plugins/war/AbstractWarExplodedMojoTest.java", + "line": 99, + "npe_method": "setUpMojo", + "deref_field": "sourceFiles", + "npe_class": "AbstractWarExplodedMojoTest" +} \ No newline at end of file diff --git a/Java/maven-war-plugin-AbstractWarPackagingTask_99/Dockerfile b/Java/maven-war-plugin-AbstractWarPackagingTask_99/Dockerfile new file mode 100644 index 000000000..34955205a --- /dev/null +++ b/Java/maven-war-plugin-AbstractWarPackagingTask_99/Dockerfile @@ -0,0 +1,18 @@ +FROM ghcr.io/kupl/starlab-benchmarks/java-base:maven-war-plugin + +ENV TZ=Asia/Seoul + +COPY ./metadata.json . +COPY ./npe.json . +COPY ./buggy.java /tmp/buggy.java +RUN export BUGGY_PATH=$(cat metadata.json | jq -r ".npe.filepath") \ + && export BUGGY_LINE=$(cat metadata.json | jq -r ".npe.line") \ + && export BUGGY_MTHD=$(cat metadata.json | jq -r ".npe.npe_method") \ + && mv /tmp/buggy.java $BUGGY_PATH \ + && echo "[{\"filepath\": \"$BUGGY_PATH\", \"line\": $BUGGY_LINE, \"method_name\": \"$BUGGY_MTHD\"}]" | jq . > traces.json + +RUN git init . && git add -A + +RUN $(cat metadata.json | jq -r ".buildCommand") + +RUN $(cat metadata.json | jq -r ".testCommand"); if [ $? -eq 0 ]; then exit 1; fi diff --git a/Java/maven-war-plugin-AbstractWarPackagingTask_99/buggy.java b/Java/maven-war-plugin-AbstractWarPackagingTask_99/buggy.java new file mode 100644 index 000000000..b1d0f3bab --- /dev/null +++ b/Java/maven-war-plugin-AbstractWarPackagingTask_99/buggy.java @@ -0,0 +1,506 @@ +package org.apache.maven.plugins.war.packaging; + +/* + * 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. + */ + +import java.io.File; +import java.io.IOException; + +import org.apache.commons.io.input.XmlStreamReader; +import org.apache.maven.artifact.Artifact; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugins.war.util.PathSet; +import org.apache.maven.plugins.war.util.WebappStructure; +import org.apache.maven.shared.filtering.MavenFilteringException; +import org.apache.maven.shared.mapping.MappingUtils; +import org.codehaus.plexus.archiver.ArchiverException; +import org.codehaus.plexus.archiver.UnArchiver; +import org.codehaus.plexus.archiver.jar.JarArchiver; +import org.codehaus.plexus.archiver.manager.NoSuchArchiverException; +import org.codehaus.plexus.interpolation.InterpolationException; +import org.codehaus.plexus.util.DirectoryScanner; +import org.codehaus.plexus.util.FileUtils; + +/** + * @author Stephane Nicoll + */ +public abstract class AbstractWarPackagingTask + implements WarPackagingTask +{ + /** + * The default list of includes. + */ + public static final String[] DEFAULT_INCLUDES = { "**/**" }; + + /** + * The {@code WEB-INF} path. + */ + public static final String WEB_INF_PATH = "WEB-INF"; + + /** + * The {@code META-INF} path. + */ + public static final String META_INF_PATH = "META-INF"; + + /** + * The {@code classes} path. + */ + public static final String CLASSES_PATH = "WEB-INF/classes/"; + + /** + * The {@code lib} path. + */ + public static final String LIB_PATH = "WEB-INF/lib/"; + + /** + * Copies the files if possible with an optional target prefix. + * + * Copy uses a first-win strategy: files that have already been copied by previous tasks are ignored. This method + * makes sure to update the list of protected files which gives the list of files that have already been copied. + * + * If the structure of the source directory is not the same as the root of the webapp, use the targetPrefix + * parameter to specify in which particular directory the files should be copied. Use null to copy the + * files with the same structure + * + * @param sourceId the source id + * @param context the context to use + * @param sourceBaseDir the base directory from which the sourceFilesSet will be copied + * @param sourceFilesSet the files to be copied + * @param targetPrefix the prefix to add to the target file name + * @param filtered filter or not. + * @throws IOException if an error occurred while copying the files + * @throws MojoExecutionException if an error occurs. + */ +/** + * Copies the files if possible with an optional target prefix. + * + * Copy uses a first-win strategy: files that have already been copied by previous tasks are ignored. This method + * makes sure to update the list of protected files which gives the list of files that have already been copied. + * + * If the structure of the source directory is not the same as the root of the webapp, use the targetPrefix + * parameter to specify in which particular directory the files should be copied. Use null to copy the + * files with the same structure + * + * @param sourceId + * the source id + * @param context + * the context to use + * @param sourceBaseDir + * the base directory from which the sourceFilesSet will be copied + * @param sourceFilesSet + * the files to be copied + * @param targetPrefix + * the prefix to add to the target file name + * @param filtered + * filter or not. + * @throws IOException + * if an error occurred while copying the files + * @throws MojoExecutionException + * if an error occurs. + */ +protected void copyFiles(java.lang.String sourceId, org.apache.maven.plugins.war.packaging.WarPackagingContext context, java.io.File sourceBaseDir, org.apache.maven.plugins.war.util.PathSet sourceFilesSet, java.lang.String targetPrefix, boolean filtered) throws java.io.IOException, org.apache.maven.plugin.MojoExecutionException { + for (java.lang.String fileToCopyName : sourceFilesSet.paths()) { + final java.io.File sourceFile = new java.io.File(sourceBaseDir, fileToCopyName); + java.lang.String destinationFileName; + { + destinationFileName = /* NPEX_NULL_EXP */ + targetPrefix + fileToCopyName; + } + if (filtered && (!context.isNonFilteredExtension(sourceFile.getName()))) { + copyFilteredFile(sourceId, context, sourceFile, destinationFileName); + } else { + copyFile(sourceId, context, sourceFile, destinationFileName); + } + } +} + + /** + * Copies the files if possible as is. + * + * Copy uses a first-win strategy: files that have already been copied by previous tasks are ignored. This method + * makes sure to update the list of protected files which gives the list of files that have already been copied. + * + * @param sourceId the source id + * @param context the context to use + * @param sourceBaseDir the base directory from which the sourceFilesSet will be copied + * @param sourceFilesSet the files to be copied + * @param filtered filter or not. + * @throws IOException if an error occurred while copying the files + * @throws MojoExecutionException break the build. + */ + protected void copyFiles( String sourceId, WarPackagingContext context, File sourceBaseDir, PathSet sourceFilesSet, + boolean filtered ) + throws IOException, MojoExecutionException + { + copyFiles( sourceId, context, sourceBaseDir, sourceFilesSet, null, filtered ); + } + + /** + * Copy the specified file if the target location has not yet already been used. + * + * The targetFileName is the relative path according to the root of the generated web application. + * + * @param sourceId the source id + * @param context the context to use + * @param file the file to copy + * @param targetFilename the relative path according to the root of the webapp + * @throws IOException if an error occurred while copying + */ + // CHECKSTYLE_OFF: LineLength + protected void copyFile( String sourceId, final WarPackagingContext context, final File file, String targetFilename ) + throws IOException + // CHECKSTYLE_ON: LineLength + { + final File targetFile = new File( context.getWebappDirectory(), targetFilename ); + + if ( file.isFile() ) + { + context.getWebappStructure().registerFile( sourceId, targetFilename, + new WebappStructure.RegistrationCallback() + { + public void registered( String ownerId, String targetFilename ) + throws IOException + { + copyFile( context, file, targetFile, targetFilename, + false ); + } + + public void alreadyRegistered( String ownerId, + String targetFilename ) + throws IOException + { + copyFile( context, file, targetFile, targetFilename, + true ); + } + + public void refused( String ownerId, String targetFilename, + String actualOwnerId ) + throws IOException + { + context.getLog().debug( " - " + + targetFilename + + " wasn't copied because it has " + + "already been packaged for overlay [" + + actualOwnerId + "]." ); + } + + public void superseded( String ownerId, + String targetFilename, + String deprecatedOwnerId ) + throws IOException + { + context.getLog().info( "File [" + + targetFilename + + "] belonged to overlay [" + + deprecatedOwnerId + + "] so it will be overwritten." ); + copyFile( context, file, targetFile, targetFilename, + false ); + } + + public void supersededUnknownOwner( String ownerId, + String targetFilename, + String unknownOwnerId ) + throws IOException + { + // CHECKSTYLE_OFF: LineLength + context.getLog().warn( "File [" + + targetFilename + + "] belonged to overlay [" + + unknownOwnerId + + "] which does not exist anymore in the current project. It is recommended to invoke " + + "clean if the dependencies of the project changed." ); + // CHECKSTYLE_ON: LineLength + copyFile( context, file, targetFile, targetFilename, + false ); + } + } ); + } + else if ( !targetFile.exists() && !targetFile.mkdirs() ) + { + context.getLog().info( "Failed to create directory " + targetFile.getAbsolutePath() ); + } + } + + /** + * Copy the specified file if the target location has not yet already been used and filter its content with the + * configured filter properties. + * + * The targetFileName is the relative path according to the root of the generated web application. + * + * @param sourceId the source id + * @param context the context to use + * @param file the file to copy + * @param targetFilename the relative path according to the root of the webapp + * @return true if the file has been copied, false otherwise + * @throws IOException if an error occurred while copying + * @throws MojoExecutionException if an error occurred while retrieving the filter properties + */ + protected boolean copyFilteredFile( String sourceId, final WarPackagingContext context, File file, + String targetFilename ) + throws IOException, MojoExecutionException + { + context.addResource( targetFilename ); + + if ( context.getWebappStructure().registerFile( sourceId, targetFilename ) ) + { + final File targetFile = new File( context.getWebappDirectory(), targetFilename ); + final String encoding; + try + { + if ( isXmlFile( file ) ) + { + // For xml-files we extract the encoding from the files + encoding = getEncoding( file ); + } + else + { + // For all others we use the configured encoding + encoding = context.getResourceEncoding(); + } + // fix for MWAR-36, ensures that the parent dir are created first + targetFile.getParentFile().mkdirs(); + + context.getMavenFileFilter().copyFile( file, targetFile, true, context.getFilterWrappers(), encoding ); + } + catch ( MavenFilteringException e ) + { + throw new MojoExecutionException( e.getMessage(), e ); + } + // CHECKSTYLE_OFF: LineLength + // Add the file to the protected list + context.getLog().debug( " + " + targetFilename + " has been copied (filtered encoding='" + encoding + "')." ); + // CHECKSTYLE_ON: LineLength + return true; + } + else + { + context.getLog().debug( " - " + targetFilename + + " wasn't copied because it has already been packaged (filtered)." ); + return false; + } + } + + /** + * Unpacks the specified file to the specified directory. + * + * @param context the packaging context + * @param file the file to unpack + * @param unpackDirectory the directory to use for th unpacked file + * @throws MojoExecutionException if an error occurred while unpacking the file + */ + protected void doUnpack( WarPackagingContext context, File file, File unpackDirectory ) + throws MojoExecutionException + { + String archiveExt = FileUtils.getExtension( file.getAbsolutePath() ).toLowerCase(); + + try + { + UnArchiver unArchiver = context.getArchiverManager().getUnArchiver( archiveExt ); + unArchiver.setSourceFile( file ); + unArchiver.setDestDirectory( unpackDirectory ); + unArchiver.setOverwrite( true ); + unArchiver.extract(); + } + catch ( ArchiverException e ) + { + throw new MojoExecutionException( "Error unpacking file [" + file.getAbsolutePath() + "]" + " to [" + + unpackDirectory.getAbsolutePath() + "]", e ); + } + catch ( NoSuchArchiverException e ) + { + context.getLog().warn( "Skip unpacking dependency file [" + file.getAbsolutePath() + + " with unknown extension [" + archiveExt + "]" ); + } + } + + /** + * Copy file from source to destination. The directories up to destination will be created if they + * don't already exist. if the onlyIfModified flag is false, destination will be + * overwritten if it already exists. If the flag is true destination will be overwritten if it's not up to + * date. + * + * @param context the packaging context + * @param source an existing non-directory File to copy bytes from + * @param destination a non-directory File to write bytes to (possibly overwriting). + * @param targetFilename the relative path of the file from the webapp root directory + * @param onlyIfModified if true, copy the file only if the source has changed, always copy otherwise + * @return true if the file has been copied/updated, false otherwise + * @throws IOException if source does not exist, destination cannot be written to, or an + * IO error occurs during copying + */ + protected boolean copyFile( WarPackagingContext context, File source, File destination, String targetFilename, + boolean onlyIfModified ) + throws IOException + { + context.addResource( targetFilename ); + + if ( onlyIfModified && destination.lastModified() >= source.lastModified() ) + { + context.getLog().debug( " * " + targetFilename + " is up to date." ); + return false; + } + else + { + if ( source.isDirectory() ) + { + context.getLog().warn( " + " + targetFilename + " is packaged from the source folder" ); + + try + { + JarArchiver archiver = context.getJarArchiver(); + archiver.addDirectory( source ); + archiver.setDestFile( destination ); + archiver.createArchive(); + } + catch ( ArchiverException e ) + { + String msg = "Failed to create " + targetFilename; + context.getLog().error( msg, e ); + IOException ioe = new IOException( msg ); + ioe.initCause( e ); + throw ioe; + } + } + else + { + FileUtils.copyFile( source.getCanonicalFile(), destination ); + // preserve timestamp + destination.setLastModified( source.lastModified() ); + context.getLog().debug( " + " + targetFilename + " has been copied." ); + } + return true; + } + } + + /** + * Get the encoding from an XML-file. + * + * @param webXml the XML-file + * @return The encoding of the XML-file, or UTF-8 if it's not specified in the file + * @throws java.io.IOException if an error occurred while reading the file + */ + protected String getEncoding( File webXml ) + throws IOException + { + try ( XmlStreamReader xmlReader = new XmlStreamReader( webXml ) ) + { + return xmlReader.getEncoding(); + } + } + + /** + * Returns the file to copy. If the includes are null or empty, the default includes are used. + * + * @param baseDir the base directory to start from + * @param includes the includes + * @param excludes the excludes + * @return the files to copy + */ + protected PathSet getFilesToIncludes( File baseDir, String[] includes, String[] excludes ) + { + return getFilesToIncludes( baseDir, includes, excludes, false ); + } + + /** + * Returns the file to copy. If the includes are null or empty, the default includes are used. + * + * @param baseDir the base directory to start from + * @param includes the includes + * @param excludes the excludes + * @param includeDirectories include directories yes or not. + * @return the files to copy + */ + // CHECKSTYLE_OFF: LineLength + protected PathSet getFilesToIncludes( File baseDir, String[] includes, String[] excludes, boolean includeDirectories ) + // CHECKSTYLE_ON: LineLength + { + final DirectoryScanner scanner = new DirectoryScanner(); + scanner.setBasedir( baseDir ); + + if ( excludes != null ) + { + scanner.setExcludes( excludes ); + } + scanner.addDefaultExcludes(); + + if ( includes != null && includes.length > 0 ) + { + scanner.setIncludes( includes ); + } + else + { + scanner.setIncludes( DEFAULT_INCLUDES ); + } + + scanner.scan(); + + PathSet pathSet = new PathSet( scanner.getIncludedFiles() ); + + if ( includeDirectories ) + { + pathSet.addAll( scanner.getIncludedDirectories() ); + } + + return pathSet; + } + + /** + * Returns the final name of the specified artifact. + * + * If the outputFileNameMapping is set, it is used, otherwise the standard naming scheme is used. + * + * @param context the packaging context + * @param artifact the artifact + * @return the converted filename of the artifact + * @throws InterpolationException in case of interpolation problem. + */ + protected String getArtifactFinalName( WarPackagingContext context, Artifact artifact ) + throws InterpolationException + { + if ( context.getOutputFileNameMapping() != null ) + { + return MappingUtils.evaluateFileNameMapping( context.getOutputFileNameMapping(), artifact ); + } + + String classifier = artifact.getClassifier(); + if ( ( classifier != null ) && !( "".equals( classifier.trim() ) ) ) + { + return MappingUtils.evaluateFileNameMapping( MappingUtils.DEFAULT_FILE_NAME_MAPPING_CLASSIFIER, artifact ); + } + else + { + return MappingUtils.evaluateFileNameMapping( MappingUtils.DEFAULT_FILE_NAME_MAPPING, artifact ); + } + + } + + /** + * Returns true if the File-object is a file (not a directory) that is not + * null and has a file name that ends in ".xml". + * + * @param file The file to check + * @return true if the file is an xml-file, otherwise false + * @since 2.3 + */ + private boolean isXmlFile( File file ) + { + return file != null && file.isFile() && file.getName().endsWith( ".xml" ); + } +} diff --git a/Java/maven-war-plugin-AbstractWarPackagingTask_99/metadata.json b/Java/maven-war-plugin-AbstractWarPackagingTask_99/metadata.json new file mode 100644 index 000000000..57f0b37ab --- /dev/null +++ b/Java/maven-war-plugin-AbstractWarPackagingTask_99/metadata.json @@ -0,0 +1,21 @@ +{ + "language": "java", + "id": "maven-war-plugin-AbstractWarPackagingTask_99", + "buggyPath": ".", + "referencePath": null, + "buildCommand": "mvn package -V -B -Denforcer.skip=true -Dcheckstyle.skip=true -Dcobertura.skip=true -Drat.skip=true -Dlicense.skip=true -Dfindbugs.skip=true -Dgpg.skip=true -Dskip.npm=true -Dskip.gulp=true -Dskip.bower=true -Drat.numUnapprovedLicenses=100 -DskipTests=true -DskipITs=true -Dtest=None -DfailIfNoTests=false", + "testCommand": "mvn test -V -B -Denforcer.skip=true -Dcheckstyle.skip=true -Dcobertura.skip=true -Drat.skip=true -Dlicense.skip=true -Dfindbugs.skip=true -Dgpg.skip=true -Dskip.npm=true -Dskip.gulp=true -Dskip.bower=true -Drat.numUnapprovedLicenses=100", + "categories": [ + "safety", + "npe" + ], + "npe": { + "filepath": "src/main/java/org/apache/maven/plugins/war/packaging/AbstractWarPackagingTask.java", + "line": 123, + "npe_method": "copyFiles", + "deref_field": "targetPrefix", + "npe_class": "AbstractWarPackagingTask", + "repo": "maven-war-plugin", + "bug_id": "AbstractWarPackagingTask_99" + } +} diff --git a/Java/maven-war-plugin-AbstractWarPackagingTask_99/npe.json b/Java/maven-war-plugin-AbstractWarPackagingTask_99/npe.json new file mode 100644 index 000000000..cdcca5246 --- /dev/null +++ b/Java/maven-war-plugin-AbstractWarPackagingTask_99/npe.json @@ -0,0 +1,7 @@ +{ + "filepath": "src/main/java/org/apache/maven/plugins/war/packaging/AbstractWarPackagingTask.java", + "line": 123, + "npe_method": "copyFiles", + "deref_field": "targetPrefix", + "npe_class": "AbstractWarPackagingTask" +} \ No newline at end of file diff --git a/Java/maven-war-plugin-CopyUserManifestTask_59/Dockerfile b/Java/maven-war-plugin-CopyUserManifestTask_59/Dockerfile new file mode 100644 index 000000000..34955205a --- /dev/null +++ b/Java/maven-war-plugin-CopyUserManifestTask_59/Dockerfile @@ -0,0 +1,18 @@ +FROM ghcr.io/kupl/starlab-benchmarks/java-base:maven-war-plugin + +ENV TZ=Asia/Seoul + +COPY ./metadata.json . +COPY ./npe.json . +COPY ./buggy.java /tmp/buggy.java +RUN export BUGGY_PATH=$(cat metadata.json | jq -r ".npe.filepath") \ + && export BUGGY_LINE=$(cat metadata.json | jq -r ".npe.line") \ + && export BUGGY_MTHD=$(cat metadata.json | jq -r ".npe.npe_method") \ + && mv /tmp/buggy.java $BUGGY_PATH \ + && echo "[{\"filepath\": \"$BUGGY_PATH\", \"line\": $BUGGY_LINE, \"method_name\": \"$BUGGY_MTHD\"}]" | jq . > traces.json + +RUN git init . && git add -A + +RUN $(cat metadata.json | jq -r ".buildCommand") + +RUN $(cat metadata.json | jq -r ".testCommand"); if [ $? -eq 0 ]; then exit 1; fi diff --git a/Java/maven-war-plugin-CopyUserManifestTask_59/buggy.java b/Java/maven-war-plugin-CopyUserManifestTask_59/buggy.java new file mode 100644 index 000000000..35832211c --- /dev/null +++ b/Java/maven-war-plugin-CopyUserManifestTask_59/buggy.java @@ -0,0 +1,69 @@ +package org.apache.maven.plugins.war.packaging; + +/* + * 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. + */ + +import java.io.File; +import java.io.IOException; + +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.MojoFailureException; +import org.apache.maven.plugin.logging.Log; +import org.apache.maven.plugin.logging.SystemStreamLog; + +/** + * @author Haikal Saadh + * + */ +public class CopyUserManifestTask + extends AbstractWarPackagingTask +{ + + /** Instance logger */ + private Log log; + + public Log getLog() + { + if ( log == null ) + { + log = new SystemStreamLog(); + } + return log; + } + + public void setLog( Log log ) + { + this.log = log; + } + +public void performPackaging(org.apache.maven.plugins.war.packaging.WarPackagingContext context) throws org.apache.maven.plugin.MojoExecutionException, org.apache.maven.plugin.MojoFailureException { + java.io.File userManifest = context.getArchive().getManifestFile(); + { + try { + getLog().info("Copying manifest..."); + java.io.File metainfDir = new java.io.File(context.getWebappDirectory(), org.apache.maven.plugins.war.packaging.AbstractWarPackagingTask.META_INF_PATH); + copyFile(context, /* NPEX_NULL_EXP */ + userManifest, new java.io.File(metainfDir, "MANIFEST.MF"), "META-INF/MANIFEST.MF", true); + } catch (java.io.IOException e) { + throw new org.apache.maven.plugin.MojoExecutionException("Error copying user manifest", e); + } + } +} + +} diff --git a/Java/maven-war-plugin-CopyUserManifestTask_59/metadata.json b/Java/maven-war-plugin-CopyUserManifestTask_59/metadata.json new file mode 100644 index 000000000..76d37b651 --- /dev/null +++ b/Java/maven-war-plugin-CopyUserManifestTask_59/metadata.json @@ -0,0 +1,21 @@ +{ + "language": "java", + "id": "maven-war-plugin-CopyUserManifestTask_59", + "buggyPath": ".", + "referencePath": null, + "buildCommand": "mvn package -V -B -Denforcer.skip=true -Dcheckstyle.skip=true -Dcobertura.skip=true -Drat.skip=true -Dlicense.skip=true -Dfindbugs.skip=true -Dgpg.skip=true -Dskip.npm=true -Dskip.gulp=true -Dskip.bower=true -Drat.numUnapprovedLicenses=100 -DskipTests=true -DskipITs=true -Dtest=None -DfailIfNoTests=false", + "testCommand": "mvn test -V -B -Denforcer.skip=true -Dcheckstyle.skip=true -Dcobertura.skip=true -Drat.skip=true -Dlicense.skip=true -Dfindbugs.skip=true -Dgpg.skip=true -Dskip.npm=true -Dskip.gulp=true -Dskip.bower=true -Drat.numUnapprovedLicenses=100", + "categories": [ + "safety", + "npe" + ], + "npe": { + "filepath": "src/main/java/org/apache/maven/plugins/war/packaging/CopyUserManifestTask.java", + "line": 62, + "npe_method": "performPackaging", + "deref_field": "userManifest", + "npe_class": "CopyUserManifestTask", + "repo": "maven-war-plugin", + "bug_id": "CopyUserManifestTask_59" + } +} diff --git a/Java/maven-war-plugin-CopyUserManifestTask_59/npe.json b/Java/maven-war-plugin-CopyUserManifestTask_59/npe.json new file mode 100644 index 000000000..644004bce --- /dev/null +++ b/Java/maven-war-plugin-CopyUserManifestTask_59/npe.json @@ -0,0 +1,7 @@ +{ + "filepath": "src/main/java/org/apache/maven/plugins/war/packaging/CopyUserManifestTask.java", + "line": 62, + "npe_method": "performPackaging", + "deref_field": "userManifest", + "npe_class": "CopyUserManifestTask" +} \ No newline at end of file diff --git a/Java/maven-war-plugin-JarArtifactStub_135/Dockerfile b/Java/maven-war-plugin-JarArtifactStub_135/Dockerfile new file mode 100644 index 000000000..34955205a --- /dev/null +++ b/Java/maven-war-plugin-JarArtifactStub_135/Dockerfile @@ -0,0 +1,18 @@ +FROM ghcr.io/kupl/starlab-benchmarks/java-base:maven-war-plugin + +ENV TZ=Asia/Seoul + +COPY ./metadata.json . +COPY ./npe.json . +COPY ./buggy.java /tmp/buggy.java +RUN export BUGGY_PATH=$(cat metadata.json | jq -r ".npe.filepath") \ + && export BUGGY_LINE=$(cat metadata.json | jq -r ".npe.line") \ + && export BUGGY_MTHD=$(cat metadata.json | jq -r ".npe.npe_method") \ + && mv /tmp/buggy.java $BUGGY_PATH \ + && echo "[{\"filepath\": \"$BUGGY_PATH\", \"line\": $BUGGY_LINE, \"method_name\": \"$BUGGY_MTHD\"}]" | jq . > traces.json + +RUN git init . && git add -A + +RUN $(cat metadata.json | jq -r ".buildCommand") + +RUN $(cat metadata.json | jq -r ".testCommand"); if [ $? -eq 0 ]; then exit 1; fi diff --git a/Java/maven-war-plugin-JarArtifactStub_135/buggy.java b/Java/maven-war-plugin-JarArtifactStub_135/buggy.java new file mode 100644 index 000000000..399bb7196 --- /dev/null +++ b/Java/maven-war-plugin-JarArtifactStub_135/buggy.java @@ -0,0 +1,149 @@ +package org.apache.maven.plugins.war.stub; + +/* + * 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. + */ + +import org.apache.maven.artifact.handler.ArtifactHandler; + +import java.io.File; + +public class JarArtifactStub + extends AbstractArtifactStub +{ + + protected String groupId; + + protected String artifactId; + + protected String version; + + protected boolean optional = false; + + protected String scope; + + private File file; + + private ArtifactHandler artifactHandler; + + public JarArtifactStub( String basedir, ArtifactHandler artifactHandler ) + { + super( basedir ); + this.artifactHandler = artifactHandler; + } + + public void setGroupId( String id ) + { + groupId = id; + } + + public String getGroupId() + { + if ( groupId != null ) + { + return groupId; + } + else + { + return "org.sample.jar"; + } + } + + public String getType() + { + return "jar"; + } + + public void setArtifactId( String artifactId ) + { + this.artifactId = artifactId; + } + + public String getArtifactId() + { + if ( artifactId != null ) + { + return artifactId; + } + else + { + return "jarartifact"; + } + } + + public String getVersion() + { + if ( version != null ) + { + return version; + } + else + { + return super.getVersion(); + } + } + + public void setVersion( String version ) + { + this.version = version; + } + + public boolean isOptional() + { + return optional; + } + + public void setOptional( boolean optional ) + { + this.optional = optional; + } + + public String getScope() + { + if ( scope != null ) + { + return scope; + } + else + { + return super.getScope(); + } + } + + public void setScope( String scope ) + { + this.scope = scope; + } + +public java.io.File getFile() { + { + return /* NPEX_NULL_EXP */ + file; + } +} + + public void setFile( File file ) + { + this.file = file; + } + + public ArtifactHandler getArtifactHandler() + { + return artifactHandler; + } +} diff --git a/Java/maven-war-plugin-JarArtifactStub_135/metadata.json b/Java/maven-war-plugin-JarArtifactStub_135/metadata.json new file mode 100644 index 000000000..de8c9059c --- /dev/null +++ b/Java/maven-war-plugin-JarArtifactStub_135/metadata.json @@ -0,0 +1,21 @@ +{ + "language": "java", + "id": "maven-war-plugin-JarArtifactStub_135", + "buggyPath": ".", + "referencePath": null, + "buildCommand": "mvn package -V -B -Denforcer.skip=true -Dcheckstyle.skip=true -Dcobertura.skip=true -Drat.skip=true -Dlicense.skip=true -Dfindbugs.skip=true -Dgpg.skip=true -Dskip.npm=true -Dskip.gulp=true -Dskip.bower=true -Drat.numUnapprovedLicenses=100 -DskipTests=true -DskipITs=true -Dtest=None -DfailIfNoTests=false", + "testCommand": "mvn test -V -B -Denforcer.skip=true -Dcheckstyle.skip=true -Dcobertura.skip=true -Drat.skip=true -Dlicense.skip=true -Dfindbugs.skip=true -Dgpg.skip=true -Dskip.npm=true -Dskip.gulp=true -Dskip.bower=true -Drat.numUnapprovedLicenses=100", + "categories": [ + "safety", + "npe" + ], + "npe": { + "filepath": "src/test/java/org/apache/maven/plugins/war/stub/JarArtifactStub.java", + "line": 136, + "npe_method": "getFile", + "deref_field": "file", + "npe_class": "JarArtifactStub", + "repo": "maven-war-plugin", + "bug_id": "JarArtifactStub_135" + } +} diff --git a/Java/maven-war-plugin-JarArtifactStub_135/npe.json b/Java/maven-war-plugin-JarArtifactStub_135/npe.json new file mode 100644 index 000000000..39921ad3a --- /dev/null +++ b/Java/maven-war-plugin-JarArtifactStub_135/npe.json @@ -0,0 +1,7 @@ +{ + "filepath": "src/test/java/org/apache/maven/plugins/war/stub/JarArtifactStub.java", + "line": 136, + "npe_method": "getFile", + "deref_field": "file", + "npe_class": "JarArtifactStub" +} \ No newline at end of file diff --git a/Java/maven-war-plugin-JarArtifactStub_79/Dockerfile b/Java/maven-war-plugin-JarArtifactStub_79/Dockerfile new file mode 100644 index 000000000..34955205a --- /dev/null +++ b/Java/maven-war-plugin-JarArtifactStub_79/Dockerfile @@ -0,0 +1,18 @@ +FROM ghcr.io/kupl/starlab-benchmarks/java-base:maven-war-plugin + +ENV TZ=Asia/Seoul + +COPY ./metadata.json . +COPY ./npe.json . +COPY ./buggy.java /tmp/buggy.java +RUN export BUGGY_PATH=$(cat metadata.json | jq -r ".npe.filepath") \ + && export BUGGY_LINE=$(cat metadata.json | jq -r ".npe.line") \ + && export BUGGY_MTHD=$(cat metadata.json | jq -r ".npe.npe_method") \ + && mv /tmp/buggy.java $BUGGY_PATH \ + && echo "[{\"filepath\": \"$BUGGY_PATH\", \"line\": $BUGGY_LINE, \"method_name\": \"$BUGGY_MTHD\"}]" | jq . > traces.json + +RUN git init . && git add -A + +RUN $(cat metadata.json | jq -r ".buildCommand") + +RUN $(cat metadata.json | jq -r ".testCommand"); if [ $? -eq 0 ]; then exit 1; fi diff --git a/Java/maven-war-plugin-JarArtifactStub_79/buggy.java b/Java/maven-war-plugin-JarArtifactStub_79/buggy.java new file mode 100644 index 000000000..4b4301a60 --- /dev/null +++ b/Java/maven-war-plugin-JarArtifactStub_79/buggy.java @@ -0,0 +1,146 @@ +package org.apache.maven.plugins.war.stub; + +/* + * 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. + */ + +import org.apache.maven.artifact.handler.ArtifactHandler; + +import java.io.File; + +public class JarArtifactStub + extends AbstractArtifactStub +{ + + protected String groupId; + + protected String artifactId; + + protected String version; + + protected boolean optional = false; + + protected String scope; + + private File file; + + private ArtifactHandler artifactHandler; + + public JarArtifactStub( String basedir, ArtifactHandler artifactHandler ) + { + super( basedir ); + this.artifactHandler = artifactHandler; + } + + public void setGroupId( String id ) + { + groupId = id; + } + + public String getGroupId() + { + if ( groupId != null ) + { + return groupId; + } + else + { + return "org.sample.jar"; + } + } + + public String getType() + { + return "jar"; + } + + public void setArtifactId( String artifactId ) + { + this.artifactId = artifactId; + } + +public java.lang.String getArtifactId() { + { + return /* NPEX_NULL_EXP */ + artifactId; + } +} + + public String getVersion() + { + if ( version != null ) + { + return version; + } + else + { + return super.getVersion(); + } + } + + public void setVersion( String version ) + { + this.version = version; + } + + public boolean isOptional() + { + return optional; + } + + public void setOptional( boolean optional ) + { + this.optional = optional; + } + + public String getScope() + { + if ( scope != null ) + { + return scope; + } + else + { + return super.getScope(); + } + } + + public void setScope( String scope ) + { + this.scope = scope; + } + + public File getFile() + { + if ( file == null ) + { + return new File( basedir, "/target/test-classes/unit/sample_wars/simple.jar" ); + } + return file; + } + + public void setFile( File file ) + { + this.file = file; + } + + public ArtifactHandler getArtifactHandler() + { + return artifactHandler; + } +} diff --git a/Java/maven-war-plugin-JarArtifactStub_79/metadata.json b/Java/maven-war-plugin-JarArtifactStub_79/metadata.json new file mode 100644 index 000000000..6d554e08a --- /dev/null +++ b/Java/maven-war-plugin-JarArtifactStub_79/metadata.json @@ -0,0 +1,21 @@ +{ + "language": "java", + "id": "maven-war-plugin-JarArtifactStub_79", + "buggyPath": ".", + "referencePath": null, + "buildCommand": "mvn package -V -B -Denforcer.skip=true -Dcheckstyle.skip=true -Dcobertura.skip=true -Drat.skip=true -Dlicense.skip=true -Dfindbugs.skip=true -Dgpg.skip=true -Dskip.npm=true -Dskip.gulp=true -Dskip.bower=true -Drat.numUnapprovedLicenses=100 -DskipTests=true -DskipITs=true -Dtest=None -DfailIfNoTests=false", + "testCommand": "mvn test -V -B -Denforcer.skip=true -Dcheckstyle.skip=true -Dcobertura.skip=true -Drat.skip=true -Dlicense.skip=true -Dfindbugs.skip=true -Dgpg.skip=true -Dskip.npm=true -Dskip.gulp=true -Dskip.bower=true -Drat.numUnapprovedLicenses=100", + "categories": [ + "safety", + "npe" + ], + "npe": { + "filepath": "src/test/java/org/apache/maven/plugins/war/stub/JarArtifactStub.java", + "line": 80, + "npe_method": "getArtifactId", + "deref_field": "artifactId", + "npe_class": "JarArtifactStub", + "repo": "maven-war-plugin", + "bug_id": "JarArtifactStub_79" + } +} diff --git a/Java/maven-war-plugin-JarArtifactStub_79/npe.json b/Java/maven-war-plugin-JarArtifactStub_79/npe.json new file mode 100644 index 000000000..3506296b7 --- /dev/null +++ b/Java/maven-war-plugin-JarArtifactStub_79/npe.json @@ -0,0 +1,7 @@ +{ + "filepath": "src/test/java/org/apache/maven/plugins/war/stub/JarArtifactStub.java", + "line": 80, + "npe_method": "getArtifactId", + "deref_field": "artifactId", + "npe_class": "JarArtifactStub" +} \ No newline at end of file diff --git a/Java/maven-war-plugin-JarArtifactStub_91/Dockerfile b/Java/maven-war-plugin-JarArtifactStub_91/Dockerfile new file mode 100644 index 000000000..34955205a --- /dev/null +++ b/Java/maven-war-plugin-JarArtifactStub_91/Dockerfile @@ -0,0 +1,18 @@ +FROM ghcr.io/kupl/starlab-benchmarks/java-base:maven-war-plugin + +ENV TZ=Asia/Seoul + +COPY ./metadata.json . +COPY ./npe.json . +COPY ./buggy.java /tmp/buggy.java +RUN export BUGGY_PATH=$(cat metadata.json | jq -r ".npe.filepath") \ + && export BUGGY_LINE=$(cat metadata.json | jq -r ".npe.line") \ + && export BUGGY_MTHD=$(cat metadata.json | jq -r ".npe.npe_method") \ + && mv /tmp/buggy.java $BUGGY_PATH \ + && echo "[{\"filepath\": \"$BUGGY_PATH\", \"line\": $BUGGY_LINE, \"method_name\": \"$BUGGY_MTHD\"}]" | jq . > traces.json + +RUN git init . && git add -A + +RUN $(cat metadata.json | jq -r ".buildCommand") + +RUN $(cat metadata.json | jq -r ".testCommand"); if [ $? -eq 0 ]; then exit 1; fi diff --git a/Java/maven-war-plugin-JarArtifactStub_91/buggy.java b/Java/maven-war-plugin-JarArtifactStub_91/buggy.java new file mode 100644 index 000000000..31d296673 --- /dev/null +++ b/Java/maven-war-plugin-JarArtifactStub_91/buggy.java @@ -0,0 +1,146 @@ +package org.apache.maven.plugins.war.stub; + +/* + * 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. + */ + +import org.apache.maven.artifact.handler.ArtifactHandler; + +import java.io.File; + +public class JarArtifactStub + extends AbstractArtifactStub +{ + + protected String groupId; + + protected String artifactId; + + protected String version; + + protected boolean optional = false; + + protected String scope; + + private File file; + + private ArtifactHandler artifactHandler; + + public JarArtifactStub( String basedir, ArtifactHandler artifactHandler ) + { + super( basedir ); + this.artifactHandler = artifactHandler; + } + + public void setGroupId( String id ) + { + groupId = id; + } + + public String getGroupId() + { + if ( groupId != null ) + { + return groupId; + } + else + { + return "org.sample.jar"; + } + } + + public String getType() + { + return "jar"; + } + + public void setArtifactId( String artifactId ) + { + this.artifactId = artifactId; + } + + public String getArtifactId() + { + if ( artifactId != null ) + { + return artifactId; + } + else + { + return "jarartifact"; + } + } + +public java.lang.String getVersion() { + { + return /* NPEX_NULL_EXP */ + version; + } +} + + public void setVersion( String version ) + { + this.version = version; + } + + public boolean isOptional() + { + return optional; + } + + public void setOptional( boolean optional ) + { + this.optional = optional; + } + + public String getScope() + { + if ( scope != null ) + { + return scope; + } + else + { + return super.getScope(); + } + } + + public void setScope( String scope ) + { + this.scope = scope; + } + + public File getFile() + { + if ( file == null ) + { + return new File( basedir, "/target/test-classes/unit/sample_wars/simple.jar" ); + } + return file; + } + + public void setFile( File file ) + { + this.file = file; + } + + public ArtifactHandler getArtifactHandler() + { + return artifactHandler; + } +} diff --git a/Java/maven-war-plugin-JarArtifactStub_91/metadata.json b/Java/maven-war-plugin-JarArtifactStub_91/metadata.json new file mode 100644 index 000000000..6ad7f1048 --- /dev/null +++ b/Java/maven-war-plugin-JarArtifactStub_91/metadata.json @@ -0,0 +1,21 @@ +{ + "language": "java", + "id": "maven-war-plugin-JarArtifactStub_91", + "buggyPath": ".", + "referencePath": null, + "buildCommand": "mvn package -V -B -Denforcer.skip=true -Dcheckstyle.skip=true -Dcobertura.skip=true -Drat.skip=true -Dlicense.skip=true -Dfindbugs.skip=true -Dgpg.skip=true -Dskip.npm=true -Dskip.gulp=true -Dskip.bower=true -Drat.numUnapprovedLicenses=100 -DskipTests=true -DskipITs=true -Dtest=None -DfailIfNoTests=false", + "testCommand": "mvn test -V -B -Denforcer.skip=true -Dcheckstyle.skip=true -Dcobertura.skip=true -Drat.skip=true -Dlicense.skip=true -Dfindbugs.skip=true -Dgpg.skip=true -Dskip.npm=true -Dskip.gulp=true -Dskip.bower=true -Drat.numUnapprovedLicenses=100", + "categories": [ + "safety", + "npe" + ], + "npe": { + "filepath": "src/test/java/org/apache/maven/plugins/war/stub/JarArtifactStub.java", + "line": 92, + "npe_method": "getVersion", + "deref_field": "version", + "npe_class": "JarArtifactStub", + "repo": "maven-war-plugin", + "bug_id": "JarArtifactStub_91" + } +} diff --git a/Java/maven-war-plugin-JarArtifactStub_91/npe.json b/Java/maven-war-plugin-JarArtifactStub_91/npe.json new file mode 100644 index 000000000..858b5dc7c --- /dev/null +++ b/Java/maven-war-plugin-JarArtifactStub_91/npe.json @@ -0,0 +1,7 @@ +{ + "filepath": "src/test/java/org/apache/maven/plugins/war/stub/JarArtifactStub.java", + "line": 92, + "npe_method": "getVersion", + "deref_field": "version", + "npe_class": "JarArtifactStub" +} \ No newline at end of file diff --git a/Java/maven-war-plugin-OverlayManager_200/Dockerfile b/Java/maven-war-plugin-OverlayManager_200/Dockerfile new file mode 100644 index 000000000..34955205a --- /dev/null +++ b/Java/maven-war-plugin-OverlayManager_200/Dockerfile @@ -0,0 +1,18 @@ +FROM ghcr.io/kupl/starlab-benchmarks/java-base:maven-war-plugin + +ENV TZ=Asia/Seoul + +COPY ./metadata.json . +COPY ./npe.json . +COPY ./buggy.java /tmp/buggy.java +RUN export BUGGY_PATH=$(cat metadata.json | jq -r ".npe.filepath") \ + && export BUGGY_LINE=$(cat metadata.json | jq -r ".npe.line") \ + && export BUGGY_MTHD=$(cat metadata.json | jq -r ".npe.npe_method") \ + && mv /tmp/buggy.java $BUGGY_PATH \ + && echo "[{\"filepath\": \"$BUGGY_PATH\", \"line\": $BUGGY_LINE, \"method_name\": \"$BUGGY_MTHD\"}]" | jq . > traces.json + +RUN git init . && git add -A + +RUN $(cat metadata.json | jq -r ".buildCommand") + +RUN $(cat metadata.json | jq -r ".testCommand"); if [ $? -eq 0 ]; then exit 1; fi diff --git a/Java/maven-war-plugin-OverlayManager_200/buggy.java b/Java/maven-war-plugin-OverlayManager_200/buggy.java new file mode 100644 index 000000000..238828566 --- /dev/null +++ b/Java/maven-war-plugin-OverlayManager_200/buggy.java @@ -0,0 +1,256 @@ +package org.apache.maven.plugins.war.overlay; + +/* + * 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. + */ + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.ListIterator; +import java.util.Objects; +import java.util.Set; + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter; +import org.apache.maven.plugins.war.Overlay; +import org.apache.maven.project.MavenProject; + +/** + * Manages the overlays. + * + * @author Stephane Nicoll + */ +public class OverlayManager +{ + private final List overlays; + + private final MavenProject project; + + private final List artifactsOverlays; + + /** + * Creates a manager with the specified overlays. + * + * Note that the list is potentially updated by the manager so a new list is created based on the overlays. + * + * @param overlays the overlays + * @param project the maven project + * @param defaultIncludes the default includes to use + * @param defaultExcludes the default excludes to use + * @param currentProjectOverlay the overlay for the current project + * @throws InvalidOverlayConfigurationException if the config is invalid + */ + public OverlayManager( List overlays, MavenProject project, String[] defaultIncludes, + String[] defaultExcludes, Overlay currentProjectOverlay ) + throws InvalidOverlayConfigurationException + { + this.overlays = new ArrayList<>(); + if ( overlays != null ) + { + this.overlays.addAll( overlays ); + } + this.project = project; + + this.artifactsOverlays = getOverlaysAsArtifacts(); + + // Initialize + initialize( defaultIncludes, defaultExcludes, currentProjectOverlay ); + + } + + /** + * Returns the resolved overlays. + * + * @return the overlays + */ + public List getOverlays() + { + return overlays; + } + + /** + * Returns the id of the resolved overlays. + * + * @return the overlay ids + */ + public List getOverlayIds() + { + final List result = new ArrayList<>(); + for ( Overlay overlay : overlays ) + { + result.add( overlay.getId() ); + } + return result; + + } + + /** + * Initializes the manager and validates the overlays configuration. + * + * @param defaultIncludes the default includes to use + * @param defaultExcludes the default excludes to use + * @param currentProjectOverlay the overlay for the current project + * @throws InvalidOverlayConfigurationException if the configuration is invalid + */ + void initialize( String[] defaultIncludes, String[] defaultExcludes, Overlay currentProjectOverlay ) + throws InvalidOverlayConfigurationException + { + + // Build the list of configured artifacts and makes sure that each overlay + // refer to a valid artifact + final List configuredWarArtifacts = new ArrayList<>(); + final ListIterator it = overlays.listIterator(); + while ( it.hasNext() ) + { + Overlay overlay = it.next(); + if ( overlay == null ) + { + throw new InvalidOverlayConfigurationException( "overlay could not be null." ); + } + // If it's the current project, return the project instance + if ( overlay.isCurrentProject() ) + { + overlay = currentProjectOverlay; + it.set( overlay ); + } + // default includes/excludes - only if the overlay uses the default settings + if ( Arrays.equals( Overlay.DEFAULT_INCLUDES, overlay.getIncludes() ) + && Arrays.equals( Overlay.DEFAULT_EXCLUDES, overlay.getExcludes() ) ) + { + overlay.setIncludes( defaultIncludes ); + overlay.setExcludes( defaultExcludes ); + } + + final Artifact artifact = getAssociatedArtifact( overlay ); + if ( artifact != null ) + { + configuredWarArtifacts.add( artifact ); + overlay.setArtifact( artifact ); + } + } + + // Build the list of missing overlays + for ( Artifact artifact : artifactsOverlays ) + { + if ( !configuredWarArtifacts.contains( artifact ) ) + { + // Add a default overlay for the given artifact which will be applied after + // the ones that have been configured + overlays.add( new DefaultOverlay( artifact, defaultIncludes, defaultExcludes ) ); + } + } + + // Final validation, make sure that the current project is in there. Otherwise add it first + for ( Overlay overlay : overlays ) + { + if ( overlay.equals( currentProjectOverlay ) ) + { + return; + } + } + overlays.add( 0, currentProjectOverlay ); + } + + /** + * Returns the Artifact associated to the specified overlay. + * + * If the overlay defines the current project, null is returned. If no artifact could not be found for the + * overlay a InvalidOverlayConfigurationException is thrown. + * + * @param overlay an overlay + * @return the artifact associated to the overlay + * @throws org.apache.maven.plugins.war.overlay.InvalidOverlayConfigurationException if the overlay does not have an + * associated artifact + */ +/** + * Returns the Artifact associated to the specified overlay. + * + * If the overlay defines the current project, null is returned. If no artifact could not be found for the + * overlay a InvalidOverlayConfigurationException is thrown. + * + * @param overlay + * an overlay + * @return the artifact associated to the overlay + * @throws org.apache.maven.plugins.war.overlay.InvalidOverlayConfigurationException + * if the overlay does not have an + * associated artifact + */ +org.apache.maven.artifact.Artifact getAssociatedArtifact(final org.apache.maven.plugins.war.Overlay overlay) throws org.apache.maven.plugins.war.overlay.InvalidOverlayConfigurationException { + if (overlay.isCurrentProject()) { + return null; + } + for (org.apache.maven.artifact.Artifact artifact : artifactsOverlays) { + // Handle classifier dependencies properly (clash management) + if (compareOverlayWithArtifact(overlay, artifact)) { + return artifact; + } + } + // maybe its a project dependencies zip or an other type + java.util.Set projectArtifacts = this.project.getDependencyArtifacts(); + { + for (org.apache.maven.artifact.Artifact artifact : /* NPEX_NULL_EXP */ + projectArtifacts) { + if (compareOverlayWithArtifact(overlay, artifact)) { + return artifact; + } + } + } + // CHECKSTYLE_OFF: LineLength + throw new org.apache.maven.plugins.war.overlay.InvalidOverlayConfigurationException(("overlay [" + overlay) + "] is not a dependency of the project."); + // CHECKSTYLE_ON: LineLength +} + + /** + * Compare groupId && artifactId && type && classifier. + * + * @param overlay the overlay + * @param artifact the artifact + * @return boolean true if equals + */ + private boolean compareOverlayWithArtifact( Overlay overlay, Artifact artifact ) + { + return ( Objects.equals( overlay.getGroupId(), artifact.getGroupId() ) + && Objects.equals( overlay.getArtifactId(), artifact.getArtifactId() ) + && Objects.equals( overlay.getType(), artifact.getType() ) + // MWAR-241 Make sure to treat null and "" as equal when comparing the classifier + && Objects.equals( Objects.toString( overlay.getClassifier() ), + Objects.toString( artifact.getClassifier() ) ) ); + } + + /** + * Returns a list of WAR {@link org.apache.maven.artifact.Artifact} describing the overlays of the current project. + * + * @return the overlays as artifacts objects + */ + private List getOverlaysAsArtifacts() + { + ScopeArtifactFilter filter = new ScopeArtifactFilter( Artifact.SCOPE_RUNTIME ); + final Set artifacts = project.getArtifacts(); + + final List result = new ArrayList<>(); + for ( Artifact artifact : artifacts ) + { + if ( !artifact.isOptional() && filter.include( artifact ) && ( "war".equals( artifact.getType() ) ) ) + { + result.add( artifact ); + } + } + return result; + } +} diff --git a/Java/maven-war-plugin-OverlayManager_200/metadata.json b/Java/maven-war-plugin-OverlayManager_200/metadata.json new file mode 100644 index 000000000..119289202 --- /dev/null +++ b/Java/maven-war-plugin-OverlayManager_200/metadata.json @@ -0,0 +1,21 @@ +{ + "language": "java", + "id": "maven-war-plugin-OverlayManager_200", + "buggyPath": ".", + "referencePath": null, + "buildCommand": "mvn package -V -B -Denforcer.skip=true -Dcheckstyle.skip=true -Dcobertura.skip=true -Drat.skip=true -Dlicense.skip=true -Dfindbugs.skip=true -Dgpg.skip=true -Dskip.npm=true -Dskip.gulp=true -Dskip.bower=true -Drat.numUnapprovedLicenses=100 -DskipTests=true -DskipITs=true -Dtest=None -DfailIfNoTests=false", + "testCommand": "mvn test -V -B -Denforcer.skip=true -Dcheckstyle.skip=true -Dcobertura.skip=true -Drat.skip=true -Dlicense.skip=true -Dfindbugs.skip=true -Dgpg.skip=true -Dskip.npm=true -Dskip.gulp=true -Dskip.bower=true -Drat.numUnapprovedLicenses=100", + "categories": [ + "safety", + "npe" + ], + "npe": { + "filepath": "src/main/java/org/apache/maven/plugins/war/overlay/OverlayManager.java", + "line": 208, + "npe_method": "getAssociatedArtifact", + "deref_field": "projectArtifacts", + "npe_class": "OverlayManager", + "repo": "maven-war-plugin", + "bug_id": "OverlayManager_200" + } +} diff --git a/Java/maven-war-plugin-OverlayManager_200/npe.json b/Java/maven-war-plugin-OverlayManager_200/npe.json new file mode 100644 index 000000000..28847e1d7 --- /dev/null +++ b/Java/maven-war-plugin-OverlayManager_200/npe.json @@ -0,0 +1,7 @@ +{ + "filepath": "src/main/java/org/apache/maven/plugins/war/overlay/OverlayManager.java", + "line": 208, + "npe_method": "getAssociatedArtifact", + "deref_field": "projectArtifacts", + "npe_class": "OverlayManager" +} \ No newline at end of file diff --git a/Java/maven-war-plugin-OverlayPackagingTask_80/Dockerfile b/Java/maven-war-plugin-OverlayPackagingTask_80/Dockerfile new file mode 100644 index 000000000..34955205a --- /dev/null +++ b/Java/maven-war-plugin-OverlayPackagingTask_80/Dockerfile @@ -0,0 +1,18 @@ +FROM ghcr.io/kupl/starlab-benchmarks/java-base:maven-war-plugin + +ENV TZ=Asia/Seoul + +COPY ./metadata.json . +COPY ./npe.json . +COPY ./buggy.java /tmp/buggy.java +RUN export BUGGY_PATH=$(cat metadata.json | jq -r ".npe.filepath") \ + && export BUGGY_LINE=$(cat metadata.json | jq -r ".npe.line") \ + && export BUGGY_MTHD=$(cat metadata.json | jq -r ".npe.npe_method") \ + && mv /tmp/buggy.java $BUGGY_PATH \ + && echo "[{\"filepath\": \"$BUGGY_PATH\", \"line\": $BUGGY_LINE, \"method_name\": \"$BUGGY_MTHD\"}]" | jq . > traces.json + +RUN git init . && git add -A + +RUN $(cat metadata.json | jq -r ".buildCommand") + +RUN $(cat metadata.json | jq -r ".testCommand"); if [ $? -eq 0 ]; then exit 1; fi diff --git a/Java/maven-war-plugin-OverlayPackagingTask_80/buggy.java b/Java/maven-war-plugin-OverlayPackagingTask_80/buggy.java new file mode 100644 index 000000000..1c25b794b --- /dev/null +++ b/Java/maven-war-plugin-OverlayPackagingTask_80/buggy.java @@ -0,0 +1,139 @@ +package org.apache.maven.plugins.war.packaging; + +/* + * 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. + */ + +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugins.war.Overlay; +import org.apache.maven.plugins.war.util.PathSet; +import org.codehaus.plexus.util.FileUtils; + +import java.io.File; +import java.io.IOException; + +/** + * Handles an overlay. + * + * @author Stephane Nicoll + */ +public class OverlayPackagingTask + extends AbstractWarPackagingTask +{ + private final Overlay overlay; + + /** + * @param overlay {@link #overlay} + * @param currentProjectOverlay current overlay. + */ + public OverlayPackagingTask( Overlay overlay, Overlay currentProjectOverlay ) + { + if ( overlay == null ) + { + throw new NullPointerException( "overlay could not be null." ); + } + if ( overlay.equals( currentProjectOverlay ) ) + { + throw new IllegalStateException( "Could not handle the current project with this task." ); + } + this.overlay = overlay; + } + + @Override +public void performPackaging(org.apache.maven.plugins.war.packaging.WarPackagingContext context) throws org.apache.maven.plugin.MojoExecutionException { + context.getLog().debug("OverlayPackagingTask performPackaging overlay.getTargetPath() " + overlay.getTargetPath()); + if (overlay.shouldSkip()) { + context.getLog().info(("Skipping overlay [" + overlay) + "]"); + } else { + try { + context.getLog().info(("Processing overlay [" + overlay) + "]"); + // Step1: Extract if necessary + final java.io.File tmpDir = unpackOverlay(context, overlay); + // Step2: setup + final org.apache.maven.plugins.war.util.PathSet includes = getFilesToIncludes(tmpDir, overlay.getIncludes(), overlay.getExcludes()); + { + // overlay.getTargetPath() must ended with / + // if not we add it + java.lang.String targetPath = /* NPEX_NULL_EXP */ + overlay.getTargetPath(); + if (!targetPath.endsWith("/")) { + targetPath = targetPath + "/"; + } + copyFiles(overlay.getId(), context, tmpDir, includes, targetPath, overlay.isFiltered()); + } + } catch (java.io.IOException e) { + throw new org.apache.maven.plugin.MojoExecutionException(("Failed to copy file for overlay [" + overlay) + "]", e); + } + } +} + + /** + * Unpacks the specified overlay. + * + * Makes sure to skip the unpack process if the overlay has already been unpacked. + * + * @param context the packaging context + * @param overlay the overlay + * @return the directory containing the unpacked overlay + * @throws MojoExecutionException if an error occurred while unpacking the overlay + */ + protected File unpackOverlay( WarPackagingContext context, Overlay overlay ) + throws MojoExecutionException + { + final File tmpDir = getOverlayTempDirectory( context, overlay ); + + // TODO: not sure it's good, we should reuse the markers of the dependency plugin + if ( FileUtils.sizeOfDirectory( tmpDir ) == 0 + || overlay.getArtifact().getFile().lastModified() > tmpDir.lastModified() ) + { + doUnpack( context, overlay.getArtifact().getFile(), tmpDir ); + } + else + { + context.getLog().debug( "Overlay [" + overlay + "] was already unpacked" ); + } + return tmpDir; + } + + /** + * Returns the directory to use to unpack the specified overlay. + * + * @param context the packaging context + * @param overlay the overlay + * @return the temp directory for the overlay + */ + protected File getOverlayTempDirectory( WarPackagingContext context, Overlay overlay ) + { + final File groupIdDir = new File( context.getOverlaysWorkDirectory(), overlay.getGroupId() ); + if ( !groupIdDir.exists() ) + { + groupIdDir.mkdir(); + } + String directoryName = overlay.getArtifactId(); + if ( overlay.getClassifier() != null ) + { + directoryName = directoryName + "-" + overlay.getClassifier(); + } + final File result = new File( groupIdDir, directoryName ); + if ( !result.exists() ) + { + result.mkdirs(); + } + return result; + } +} diff --git a/Java/maven-war-plugin-OverlayPackagingTask_80/metadata.json b/Java/maven-war-plugin-OverlayPackagingTask_80/metadata.json new file mode 100644 index 000000000..4022306d1 --- /dev/null +++ b/Java/maven-war-plugin-OverlayPackagingTask_80/metadata.json @@ -0,0 +1,21 @@ +{ + "language": "java", + "id": "maven-war-plugin-OverlayPackagingTask_80", + "buggyPath": ".", + "referencePath": null, + "buildCommand": "mvn package -V -B -Denforcer.skip=true -Dcheckstyle.skip=true -Dcobertura.skip=true -Drat.skip=true -Dlicense.skip=true -Dfindbugs.skip=true -Dgpg.skip=true -Dskip.npm=true -Dskip.gulp=true -Dskip.bower=true -Drat.numUnapprovedLicenses=100 -DskipTests=true -DskipITs=true -Dtest=None -DfailIfNoTests=false", + "testCommand": "mvn test -V -B -Denforcer.skip=true -Dcheckstyle.skip=true -Dcobertura.skip=true -Drat.skip=true -Dlicense.skip=true -Dfindbugs.skip=true -Dgpg.skip=true -Dskip.npm=true -Dskip.gulp=true -Dskip.bower=true -Drat.numUnapprovedLicenses=100", + "categories": [ + "safety", + "npe" + ], + "npe": { + "filepath": "src/main/java/org/apache/maven/plugins/war/packaging/OverlayPackagingTask.java", + "line": 73, + "npe_method": "performPackaging", + "deref_field": "getTargetPath", + "npe_class": "OverlayPackagingTask", + "repo": "maven-war-plugin", + "bug_id": "OverlayPackagingTask_80" + } +} diff --git a/Java/maven-war-plugin-OverlayPackagingTask_80/npe.json b/Java/maven-war-plugin-OverlayPackagingTask_80/npe.json new file mode 100644 index 000000000..8a13aedbc --- /dev/null +++ b/Java/maven-war-plugin-OverlayPackagingTask_80/npe.json @@ -0,0 +1,7 @@ +{ + "filepath": "src/main/java/org/apache/maven/plugins/war/packaging/OverlayPackagingTask.java", + "line": 73, + "npe_method": "performPackaging", + "deref_field": "getTargetPath", + "npe_class": "OverlayPackagingTask" +} \ No newline at end of file diff --git a/Java/maven-war-plugin-WarArtifactStub_51/Dockerfile b/Java/maven-war-plugin-WarArtifactStub_51/Dockerfile new file mode 100644 index 000000000..34955205a --- /dev/null +++ b/Java/maven-war-plugin-WarArtifactStub_51/Dockerfile @@ -0,0 +1,18 @@ +FROM ghcr.io/kupl/starlab-benchmarks/java-base:maven-war-plugin + +ENV TZ=Asia/Seoul + +COPY ./metadata.json . +COPY ./npe.json . +COPY ./buggy.java /tmp/buggy.java +RUN export BUGGY_PATH=$(cat metadata.json | jq -r ".npe.filepath") \ + && export BUGGY_LINE=$(cat metadata.json | jq -r ".npe.line") \ + && export BUGGY_MTHD=$(cat metadata.json | jq -r ".npe.npe_method") \ + && mv /tmp/buggy.java $BUGGY_PATH \ + && echo "[{\"filepath\": \"$BUGGY_PATH\", \"line\": $BUGGY_LINE, \"method_name\": \"$BUGGY_MTHD\"}]" | jq . > traces.json + +RUN git init . && git add -A + +RUN $(cat metadata.json | jq -r ".buildCommand") + +RUN $(cat metadata.json | jq -r ".testCommand"); if [ $? -eq 0 ]; then exit 1; fi diff --git a/Java/maven-war-plugin-WarArtifactStub_51/buggy.java b/Java/maven-war-plugin-WarArtifactStub_51/buggy.java new file mode 100644 index 000000000..3da998746 --- /dev/null +++ b/Java/maven-war-plugin-WarArtifactStub_51/buggy.java @@ -0,0 +1,110 @@ +package org.apache.maven.plugins.war.stub; + +/* + * 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. + */ + +import java.io.File; + +/** + * Stub + */ +public class WarArtifactStub + extends AbstractArtifactStub +{ + + private String groupId; + + private String artifactId; + + private String classifier; + + private File file; + + public WarArtifactStub( String _basedir ) + { + super( _basedir ); + } + + public String getType() + { + return "war"; + } + +public java.lang.String getArtifactId() { + { + return /* NPEX_NULL_EXP */ + artifactId; + } +} + + public void setArtifactId( String _artifactId ) + { + artifactId = _artifactId; + } + + + public String getGroupId() + { + if ( groupId == null ) + { + return "wartests"; + } + else + { + return groupId; + } + } + + public void setGroupId( String groupId ) + { + this.groupId = groupId; + } + + public File getFile() + { + if ( file == null ) + { + return new File( basedir, "/target/test-classes/unit/sample_wars/simple.war" ); + } + else + { + return file; + } + } + + public void setFile( File _file ) + { + file = _file; + } + + public String getClassifier() + { + return classifier; + } + + public void setClassifier( String classifier ) + { + this.classifier = classifier; + } + + public boolean hasClassifier() + { + return classifier != null; + } +} diff --git a/Java/maven-war-plugin-WarArtifactStub_51/metadata.json b/Java/maven-war-plugin-WarArtifactStub_51/metadata.json new file mode 100644 index 000000000..0ccf7a784 --- /dev/null +++ b/Java/maven-war-plugin-WarArtifactStub_51/metadata.json @@ -0,0 +1,21 @@ +{ + "language": "java", + "id": "maven-war-plugin-WarArtifactStub_51", + "buggyPath": ".", + "referencePath": null, + "buildCommand": "mvn package -V -B -Denforcer.skip=true -Dcheckstyle.skip=true -Dcobertura.skip=true -Drat.skip=true -Dlicense.skip=true -Dfindbugs.skip=true -Dgpg.skip=true -Dskip.npm=true -Dskip.gulp=true -Dskip.bower=true -Drat.numUnapprovedLicenses=100 -DskipTests=true -DskipITs=true -Dtest=None -DfailIfNoTests=false", + "testCommand": "mvn test -V -B -Denforcer.skip=true -Dcheckstyle.skip=true -Dcobertura.skip=true -Drat.skip=true -Dlicense.skip=true -Dfindbugs.skip=true -Dgpg.skip=true -Dskip.npm=true -Dskip.gulp=true -Dskip.bower=true -Drat.numUnapprovedLicenses=100", + "categories": [ + "safety", + "npe" + ], + "npe": { + "filepath": "src/test/java/org/apache/maven/plugins/war/stub/WarArtifactStub.java", + "line": 52, + "npe_method": "getArtifactId", + "deref_field": "artifactId", + "npe_class": "WarArtifactStub", + "repo": "maven-war-plugin", + "bug_id": "WarArtifactStub_51" + } +} diff --git a/Java/maven-war-plugin-WarArtifactStub_51/npe.json b/Java/maven-war-plugin-WarArtifactStub_51/npe.json new file mode 100644 index 000000000..25554f83c --- /dev/null +++ b/Java/maven-war-plugin-WarArtifactStub_51/npe.json @@ -0,0 +1,7 @@ +{ + "filepath": "src/test/java/org/apache/maven/plugins/war/stub/WarArtifactStub.java", + "line": 52, + "npe_method": "getArtifactId", + "deref_field": "artifactId", + "npe_class": "WarArtifactStub" +} \ No newline at end of file diff --git a/Java/maven-war-plugin-WarArtifactStub_69/Dockerfile b/Java/maven-war-plugin-WarArtifactStub_69/Dockerfile new file mode 100644 index 000000000..34955205a --- /dev/null +++ b/Java/maven-war-plugin-WarArtifactStub_69/Dockerfile @@ -0,0 +1,18 @@ +FROM ghcr.io/kupl/starlab-benchmarks/java-base:maven-war-plugin + +ENV TZ=Asia/Seoul + +COPY ./metadata.json . +COPY ./npe.json . +COPY ./buggy.java /tmp/buggy.java +RUN export BUGGY_PATH=$(cat metadata.json | jq -r ".npe.filepath") \ + && export BUGGY_LINE=$(cat metadata.json | jq -r ".npe.line") \ + && export BUGGY_MTHD=$(cat metadata.json | jq -r ".npe.npe_method") \ + && mv /tmp/buggy.java $BUGGY_PATH \ + && echo "[{\"filepath\": \"$BUGGY_PATH\", \"line\": $BUGGY_LINE, \"method_name\": \"$BUGGY_MTHD\"}]" | jq . > traces.json + +RUN git init . && git add -A + +RUN $(cat metadata.json | jq -r ".buildCommand") + +RUN $(cat metadata.json | jq -r ".testCommand"); if [ $? -eq 0 ]; then exit 1; fi diff --git a/Java/maven-war-plugin-WarArtifactStub_69/buggy.java b/Java/maven-war-plugin-WarArtifactStub_69/buggy.java new file mode 100644 index 000000000..b1e2c571b --- /dev/null +++ b/Java/maven-war-plugin-WarArtifactStub_69/buggy.java @@ -0,0 +1,110 @@ +package org.apache.maven.plugins.war.stub; + +/* + * 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. + */ + +import java.io.File; + +/** + * Stub + */ +public class WarArtifactStub + extends AbstractArtifactStub +{ + + private String groupId; + + private String artifactId; + + private String classifier; + + private File file; + + public WarArtifactStub( String _basedir ) + { + super( _basedir ); + } + + public String getType() + { + return "war"; + } + + public String getArtifactId() + { + if ( artifactId == null ) + { + return "simple"; + } + else + { + return artifactId; + } + } + + public void setArtifactId( String _artifactId ) + { + artifactId = _artifactId; + } + + +public java.lang.String getGroupId() { + { + return /* NPEX_NULL_EXP */ + groupId; + } +} + + public void setGroupId( String groupId ) + { + this.groupId = groupId; + } + + public File getFile() + { + if ( file == null ) + { + return new File( basedir, "/target/test-classes/unit/sample_wars/simple.war" ); + } + else + { + return file; + } + } + + public void setFile( File _file ) + { + file = _file; + } + + public String getClassifier() + { + return classifier; + } + + public void setClassifier( String classifier ) + { + this.classifier = classifier; + } + + public boolean hasClassifier() + { + return classifier != null; + } +} diff --git a/Java/maven-war-plugin-WarArtifactStub_69/metadata.json b/Java/maven-war-plugin-WarArtifactStub_69/metadata.json new file mode 100644 index 000000000..b42544325 --- /dev/null +++ b/Java/maven-war-plugin-WarArtifactStub_69/metadata.json @@ -0,0 +1,21 @@ +{ + "language": "java", + "id": "maven-war-plugin-WarArtifactStub_69", + "buggyPath": ".", + "referencePath": null, + "buildCommand": "mvn package -V -B -Denforcer.skip=true -Dcheckstyle.skip=true -Dcobertura.skip=true -Drat.skip=true -Dlicense.skip=true -Dfindbugs.skip=true -Dgpg.skip=true -Dskip.npm=true -Dskip.gulp=true -Dskip.bower=true -Drat.numUnapprovedLicenses=100 -DskipTests=true -DskipITs=true -Dtest=None -DfailIfNoTests=false", + "testCommand": "mvn test -V -B -Denforcer.skip=true -Dcheckstyle.skip=true -Dcobertura.skip=true -Drat.skip=true -Dlicense.skip=true -Dfindbugs.skip=true -Dgpg.skip=true -Dskip.npm=true -Dskip.gulp=true -Dskip.bower=true -Drat.numUnapprovedLicenses=100", + "categories": [ + "safety", + "npe" + ], + "npe": { + "filepath": "src/test/java/org/apache/maven/plugins/war/stub/WarArtifactStub.java", + "line": 70, + "npe_method": "getGroupId", + "deref_field": "groupId", + "npe_class": "WarArtifactStub", + "repo": "maven-war-plugin", + "bug_id": "WarArtifactStub_69" + } +} diff --git a/Java/maven-war-plugin-WarArtifactStub_69/npe.json b/Java/maven-war-plugin-WarArtifactStub_69/npe.json new file mode 100644 index 000000000..a4fdcaaf8 --- /dev/null +++ b/Java/maven-war-plugin-WarArtifactStub_69/npe.json @@ -0,0 +1,7 @@ +{ + "filepath": "src/test/java/org/apache/maven/plugins/war/stub/WarArtifactStub.java", + "line": 70, + "npe_method": "getGroupId", + "deref_field": "groupId", + "npe_class": "WarArtifactStub" +} \ No newline at end of file diff --git a/Java/maven-war-plugin-WarArtifactStub_86/Dockerfile b/Java/maven-war-plugin-WarArtifactStub_86/Dockerfile new file mode 100644 index 000000000..34955205a --- /dev/null +++ b/Java/maven-war-plugin-WarArtifactStub_86/Dockerfile @@ -0,0 +1,18 @@ +FROM ghcr.io/kupl/starlab-benchmarks/java-base:maven-war-plugin + +ENV TZ=Asia/Seoul + +COPY ./metadata.json . +COPY ./npe.json . +COPY ./buggy.java /tmp/buggy.java +RUN export BUGGY_PATH=$(cat metadata.json | jq -r ".npe.filepath") \ + && export BUGGY_LINE=$(cat metadata.json | jq -r ".npe.line") \ + && export BUGGY_MTHD=$(cat metadata.json | jq -r ".npe.npe_method") \ + && mv /tmp/buggy.java $BUGGY_PATH \ + && echo "[{\"filepath\": \"$BUGGY_PATH\", \"line\": $BUGGY_LINE, \"method_name\": \"$BUGGY_MTHD\"}]" | jq . > traces.json + +RUN git init . && git add -A + +RUN $(cat metadata.json | jq -r ".buildCommand") + +RUN $(cat metadata.json | jq -r ".testCommand"); if [ $? -eq 0 ]; then exit 1; fi diff --git a/Java/maven-war-plugin-WarArtifactStub_86/buggy.java b/Java/maven-war-plugin-WarArtifactStub_86/buggy.java new file mode 100644 index 000000000..d321ef40e --- /dev/null +++ b/Java/maven-war-plugin-WarArtifactStub_86/buggy.java @@ -0,0 +1,110 @@ +package org.apache.maven.plugins.war.stub; + +/* + * 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. + */ + +import java.io.File; + +/** + * Stub + */ +public class WarArtifactStub + extends AbstractArtifactStub +{ + + private String groupId; + + private String artifactId; + + private String classifier; + + private File file; + + public WarArtifactStub( String _basedir ) + { + super( _basedir ); + } + + public String getType() + { + return "war"; + } + + public String getArtifactId() + { + if ( artifactId == null ) + { + return "simple"; + } + else + { + return artifactId; + } + } + + public void setArtifactId( String _artifactId ) + { + artifactId = _artifactId; + } + + + public String getGroupId() + { + if ( groupId == null ) + { + return "wartests"; + } + else + { + return groupId; + } + } + + public void setGroupId( String groupId ) + { + this.groupId = groupId; + } + +public java.io.File getFile() { + { + return /* NPEX_NULL_EXP */ + file; + } +} + + public void setFile( File _file ) + { + file = _file; + } + + public String getClassifier() + { + return classifier; + } + + public void setClassifier( String classifier ) + { + this.classifier = classifier; + } + + public boolean hasClassifier() + { + return classifier != null; + } +} diff --git a/Java/maven-war-plugin-WarArtifactStub_86/metadata.json b/Java/maven-war-plugin-WarArtifactStub_86/metadata.json new file mode 100644 index 000000000..e2d5de83a --- /dev/null +++ b/Java/maven-war-plugin-WarArtifactStub_86/metadata.json @@ -0,0 +1,21 @@ +{ + "language": "java", + "id": "maven-war-plugin-WarArtifactStub_86", + "buggyPath": ".", + "referencePath": null, + "buildCommand": "mvn package -V -B -Denforcer.skip=true -Dcheckstyle.skip=true -Dcobertura.skip=true -Drat.skip=true -Dlicense.skip=true -Dfindbugs.skip=true -Dgpg.skip=true -Dskip.npm=true -Dskip.gulp=true -Dskip.bower=true -Drat.numUnapprovedLicenses=100 -DskipTests=true -DskipITs=true -Dtest=None -DfailIfNoTests=false", + "testCommand": "mvn test -V -B -Denforcer.skip=true -Dcheckstyle.skip=true -Dcobertura.skip=true -Drat.skip=true -Dlicense.skip=true -Dfindbugs.skip=true -Dgpg.skip=true -Dskip.npm=true -Dskip.gulp=true -Dskip.bower=true -Drat.numUnapprovedLicenses=100", + "categories": [ + "safety", + "npe" + ], + "npe": { + "filepath": "src/test/java/org/apache/maven/plugins/war/stub/WarArtifactStub.java", + "line": 87, + "npe_method": "getFile", + "deref_field": "file", + "npe_class": "WarArtifactStub", + "repo": "maven-war-plugin", + "bug_id": "WarArtifactStub_86" + } +} diff --git a/Java/maven-war-plugin-WarArtifactStub_86/npe.json b/Java/maven-war-plugin-WarArtifactStub_86/npe.json new file mode 100644 index 000000000..f20ce5359 --- /dev/null +++ b/Java/maven-war-plugin-WarArtifactStub_86/npe.json @@ -0,0 +1,7 @@ +{ + "filepath": "src/test/java/org/apache/maven/plugins/war/stub/WarArtifactStub.java", + "line": 87, + "npe_method": "getFile", + "deref_field": "file", + "npe_class": "WarArtifactStub" +} \ No newline at end of file diff --git a/Java/maven-war-plugin-WarMojo_349/Dockerfile b/Java/maven-war-plugin-WarMojo_349/Dockerfile new file mode 100644 index 000000000..34955205a --- /dev/null +++ b/Java/maven-war-plugin-WarMojo_349/Dockerfile @@ -0,0 +1,18 @@ +FROM ghcr.io/kupl/starlab-benchmarks/java-base:maven-war-plugin + +ENV TZ=Asia/Seoul + +COPY ./metadata.json . +COPY ./npe.json . +COPY ./buggy.java /tmp/buggy.java +RUN export BUGGY_PATH=$(cat metadata.json | jq -r ".npe.filepath") \ + && export BUGGY_LINE=$(cat metadata.json | jq -r ".npe.line") \ + && export BUGGY_MTHD=$(cat metadata.json | jq -r ".npe.npe_method") \ + && mv /tmp/buggy.java $BUGGY_PATH \ + && echo "[{\"filepath\": \"$BUGGY_PATH\", \"line\": $BUGGY_LINE, \"method_name\": \"$BUGGY_MTHD\"}]" | jq . > traces.json + +RUN git init . && git add -A + +RUN $(cat metadata.json | jq -r ".buildCommand") + +RUN $(cat metadata.json | jq -r ".testCommand"); if [ $? -eq 0 ]; then exit 1; fi diff --git a/Java/maven-war-plugin-WarMojo_349/buggy.java b/Java/maven-war-plugin-WarMojo_349/buggy.java new file mode 100644 index 000000000..7b67e1b04 --- /dev/null +++ b/Java/maven-war-plugin-WarMojo_349/buggy.java @@ -0,0 +1,583 @@ +package org.apache.maven.plugins.war; + +/* + * 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. + */ + +import java.io.File; +import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLClassLoader; +import java.util.Arrays; +import java.util.List; + +import org.apache.maven.archiver.MavenArchiver; +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.DependencyResolutionRequiredException; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.MojoFailureException; +import org.apache.maven.plugins.annotations.Component; +import org.apache.maven.plugins.annotations.LifecyclePhase; +import org.apache.maven.plugins.annotations.Mojo; +import org.apache.maven.plugins.annotations.Parameter; +import org.apache.maven.plugins.annotations.ResolutionScope; +import org.apache.maven.plugins.war.util.ClassesPackager; +import org.apache.maven.project.MavenProjectHelper; +import org.codehaus.plexus.archiver.Archiver; +import org.codehaus.plexus.archiver.ArchiverException; +import org.codehaus.plexus.archiver.jar.ManifestException; +import org.codehaus.plexus.archiver.war.WarArchiver; +import org.codehaus.plexus.util.FileUtils; +import org.codehaus.plexus.util.StringUtils; + +/** + * Build a WAR file. + * + * @author Emmanuel Venisse + */ +@Mojo( name = "war", defaultPhase = LifecyclePhase.PACKAGE, threadSafe = true, + requiresDependencyResolution = ResolutionScope.COMPILE_PLUS_RUNTIME ) +public class WarMojo + extends AbstractWarMojo +{ + /** + * The directory for the generated WAR. + */ + @Parameter( defaultValue = "${project.build.directory}", required = true ) + private String outputDirectory; + + /** + * The name of the generated WAR. + */ + @Parameter( defaultValue = "${project.build.finalName}", required = true, readonly = true ) + private String warName; + + /** + * Classifier to add to the generated WAR. If given, the artifact will be an attachment instead. The classifier will + * not be applied to the JAR file of the project - only to the WAR file. + */ + @Parameter + private String classifier; + + /** + * The comma separated list of tokens to exclude from the WAR before packaging. This option may be used to implement + * the skinny WAR use case. Note that you can use the Java Regular Expressions engine to include and exclude + * specific pattern using the expression %regex[]. Hint: read the about (?!Pattern). + * + * @since 2.1-alpha-2 + */ + @Parameter + private String packagingExcludes; + + /** + * The comma separated list of tokens to include in the WAR before packaging. By default everything is included. + * This option may be used to implement the skinny WAR use case. Note that you can use the Java Regular Expressions + * engine to include and exclude specific pattern using the expression %regex[]. + * + * @since 2.1-beta-1 + */ + @Parameter + private String packagingIncludes; + + /** + * The WAR archiver. + */ + @Component( role = Archiver.class, hint = "war" ) + private WarArchiver warArchiver; + + /** + */ + @Component + private MavenProjectHelper projectHelper; + + /** + * Whether this is the main artifact being built. Set to false if you don't want to install or deploy + * it to the local repository instead of the default one in an execution. + */ + @Parameter( defaultValue = "true" ) + private boolean primaryArtifact; + + /** + * Whether classes (that is the content of the WEB-INF/classes directory) should be attached to the project as an + * additional artifact. + *

+ * By default the classifier for the additional artifact is 'classes'. You can change it with the + * someclassifier]]> parameter. + *

+ *

+ * If this parameter true, another project can depend on the classes by writing something like: + * + *

+     * 
+     *   myGroup
+     *   myArtifact
+     *   myVersion
+     *   classes
+     * ]]>
+     * 
+ *

+ * + * @since 2.1-alpha-2 + */ + @Parameter( defaultValue = "false" ) + private boolean attachClasses; + + /** + * The classifier to use for the attached classes artifact. + * + * @since 2.1-alpha-2 + */ + @Parameter( defaultValue = "classes" ) + private String classesClassifier; + + /** + * You can skip the execution of the plugin if you need to. Its use is NOT RECOMMENDED, but quite convenient on + * occasion. + * + * @since 3.0.0 + */ + @Parameter( property = "maven.war.skip", defaultValue = "false" ) + private boolean skip; + + // ---------------------------------------------------------------------- + // Implementation + // ---------------------------------------------------------------------- + + /** + * Executes the WarMojo on the current project. + * + * @throws MojoExecutionException if an error occurred while building the webapp + * @throws MojoFailureException if an error. + */ + @Override + public void execute() + throws MojoExecutionException, MojoFailureException + { + + if ( isSkip() ) + { + getLog().info( "Skipping the execution." ); + return; + } + + File warFile = getTargetWarFile(); + + try + { + performPackaging( warFile ); + } + catch ( DependencyResolutionRequiredException | ArchiverException e ) + { + throw new MojoExecutionException( "Error assembling WAR: " + e.getMessage(), e ); + } + catch ( ManifestException | IOException e ) + { + throw new MojoExecutionException( "Error assembling WAR", e ); + } + } + + /** + * Generates the webapp according to the mode attribute. + * + * @param warFile the target WAR file + * @throws IOException if an error occurred while copying files + * @throws ArchiverException if the archive could not be created + * @throws ManifestException if the manifest could not be created + * @throws DependencyResolutionRequiredException if an error occurred while resolving the dependencies + * @throws MojoExecutionException if the execution failed + * @throws MojoFailureException if a fatal exception occurred + */ + private void performPackaging( File warFile ) + throws IOException, ManifestException, DependencyResolutionRequiredException, MojoExecutionException, + MojoFailureException + { + getLog().info( "Packaging webapp" ); + + buildExplodedWebapp( getWebappDirectory() ); + + MavenArchiver archiver = new MavenArchiver(); + + archiver.setArchiver( warArchiver ); + + archiver.setCreatedBy( "Maven WAR Plugin", "org.apache.maven.plugins", "maven-war-plugin" ); + + archiver.setOutputFile( warFile ); + + // configure for Reproducible Builds based on outputTimestamp value + archiver.configureReproducible( outputTimestamp ); + + getLog().debug( "Excluding " + Arrays.asList( getPackagingExcludes() ) + + " from the generated webapp archive." ); + getLog().debug( "Including " + Arrays.asList( getPackagingIncludes() ) + " in the generated webapp archive." ); + + warArchiver.addDirectory( getWebappDirectory(), getPackagingIncludes(), getPackagingExcludes() ); + + final File webXmlFile = new File( getWebappDirectory(), "WEB-INF/web.xml" ); + if ( webXmlFile.exists() ) + { + warArchiver.setWebxml( webXmlFile ); + } + + warArchiver.setRecompressAddedZips( isRecompressZippedFiles() ); + + warArchiver.setIncludeEmptyDirs( isIncludeEmptyDirectories() ); + + if ( Boolean.FALSE.equals( failOnMissingWebXml ) + || ( failOnMissingWebXml == null && isProjectUsingAtLeastServlet30() ) ) + { + getLog().debug( "Build won't fail if web.xml file is missing." ); + warArchiver.setExpectWebXml( false ); + } + + // create archive + archiver.createArchive( getSession(), getProject(), getArchive() ); + + // create the classes to be attached if necessary + if ( isAttachClasses() ) + { + if ( isArchiveClasses() && getJarArchiver().getDestFile() != null ) + { + // special handling in case of archived classes: MWAR-240 + File targetClassesFile = getTargetClassesFile(); + FileUtils.copyFile( getJarArchiver().getDestFile(), targetClassesFile ); + projectHelper.attachArtifact( getProject(), "jar", getClassesClassifier(), targetClassesFile ); + } + else + { + ClassesPackager packager = new ClassesPackager(); + final File classesDirectory = packager.getClassesDirectory( getWebappDirectory() ); + if ( classesDirectory.exists() ) + { + getLog().info( "Packaging classes" ); + packager.packageClasses( classesDirectory, getTargetClassesFile(), getJarArchiver(), getSession(), + getProject(), getArchive(), outputTimestamp ); + projectHelper.attachArtifact( getProject(), "jar", getClassesClassifier(), getTargetClassesFile() ); + } + } + } + + if ( this.classifier != null ) + { + projectHelper.attachArtifact( getProject(), "war", this.classifier, warFile ); + } + else + { + Artifact artifact = getProject().getArtifact(); + if ( primaryArtifact ) + { + artifact.setFile( warFile ); + } + else if ( artifact.getFile() == null || artifact.getFile().isDirectory() ) + { + artifact.setFile( warFile ); + } + } + } + + /** + * Determines if the current Maven project being built uses the Servlet 3.0 API (JSR 315) + * or Jakarta Servlet API. + * If it does then the web.xml file can be omitted. + *

+ * This is done by checking if the interface javax.servlet.annotation.WebServlet + * or jakarta.servlet.annotation.WebServlet is in the compile-time + * dependencies (which includes provided dependencies) of the Maven project. + * + * @return true if the project being built depends on Servlet 3.0 API or Jakarta Servlet API, + * false otherwise. + * @throws DependencyResolutionRequiredException if the compile elements can't be resolved. + * @throws MalformedURLException if the path to a dependency file can't be transformed to a URL. + */ + private boolean isProjectUsingAtLeastServlet30() + throws DependencyResolutionRequiredException, MalformedURLException + { + List classpathElements = getProject().getCompileClasspathElements(); + URL[] urls = new URL[classpathElements.size()]; + for ( int i = 0; i < urls.length; i++ ) + { + urls[i] = new File( classpathElements.get( i ) ).toURI().toURL(); + } + ClassLoader loader = new URLClassLoader( urls, Thread.currentThread().getContextClassLoader() ); + + return hasWebServletAnnotationClassInClasspath( loader ); + } + + private static boolean hasWebServletAnnotationClassInClasspath( ClassLoader loader ) + { + return hasClassInClasspath( loader, "javax.servlet.annotation.WebServlet" ) + || hasClassInClasspath( loader, "jakarta.servlet.annotation.WebServlet" ); + } + + private static boolean hasClassInClasspath( ClassLoader loader, String clazz ) + { + try + { + Class.forName( clazz, false, loader ); + return true; + } + catch ( ClassNotFoundException e ) + { + return false; + } + } + + /** + * @param basedir The basedir + * @param finalName The finalName + * @param classifier The classifier. + * @param type The type. + * @return {@link File} + */ +/** + * + * + * @param basedir + * The basedir + * @param finalName + * The finalName + * @param classifier + * The classifier. + * @param type + * The type. + * @return {@link File} + */ +protected static java.io.File getTargetFile(java.io.File basedir, java.lang.String finalName, java.lang.String classifier, java.lang.String type) { + { + if ((/* NPEX_NULL_EXP */ + classifier.trim().length() > 0) && (!classifier.startsWith("-"))) { + classifier = "-" + classifier; + } + } + return new java.io.File(basedir, ((finalName + classifier) + ".") + type); +} + + /** + * @return The war {@link File} + */ + protected File getTargetWarFile() + { + return getTargetFile( new File( getOutputDirectory() ), getWarName(), getClassifier(), "war" ); + + } + + /** + * @return The target class {@link File} + */ + protected File getTargetClassesFile() + { + return getTargetFile( new File( getOutputDirectory() ), getWarName(), getClassesClassifier(), "jar" ); + } + + // Getters and Setters + + /** + * @return {@link #classifier} + */ + public String getClassifier() + { + return classifier; + } + + /** + * @param classifier {@link #classifier} + */ + public void setClassifier( String classifier ) + { + this.classifier = classifier; + } + + /** + * @return The package excludes. + */ + public String[] getPackagingExcludes() + { + if ( StringUtils.isEmpty( packagingExcludes ) ) + { + return new String[0]; + } + else + { + return StringUtils.split( packagingExcludes, "," ); + } + } + + /** + * @param packagingExcludes {@link #packagingExcludes} + */ + public void setPackagingExcludes( String packagingExcludes ) + { + this.packagingExcludes = packagingExcludes; + } + + /** + * @return The packaging includes. + */ + public String[] getPackagingIncludes() + { + if ( StringUtils.isEmpty( packagingIncludes ) ) + { + return new String[] { "**" }; + } + else + { + return StringUtils.split( packagingIncludes, "," ); + } + } + + /** + * @param packagingIncludes {@link #packagingIncludes} + */ + public void setPackagingIncludes( String packagingIncludes ) + { + this.packagingIncludes = packagingIncludes; + } + + /** + * @return {@link #outputDirectory} + */ + public String getOutputDirectory() + { + return outputDirectory; + } + + /** + * @param outputDirectory {@link #outputDirectory} + */ + public void setOutputDirectory( String outputDirectory ) + { + this.outputDirectory = outputDirectory; + } + + /** + * @return {@link #warName} + */ + public String getWarName() + { + return warName; + } + + /** + * @param warName {@link #warName} + */ + public void setWarName( String warName ) + { + this.warName = warName; + } + + /** + * @return {@link #warArchiver} + */ + public WarArchiver getWarArchiver() + { + return warArchiver; + } + + /** + * @param warArchiver {@link #warArchiver} + */ + public void setWarArchiver( WarArchiver warArchiver ) + { + this.warArchiver = warArchiver; + } + + /** + * @return {@link #projectHelper} + */ + public MavenProjectHelper getProjectHelper() + { + return projectHelper; + } + + /** + * @param projectHelper {@link #projectHelper} + */ + public void setProjectHelper( MavenProjectHelper projectHelper ) + { + this.projectHelper = projectHelper; + } + + /** + * @return {@link #primaryArtifact} + */ + public boolean isPrimaryArtifact() + { + return primaryArtifact; + } + + /** + * @param primaryArtifact {@link #primaryArtifact} + */ + public void setPrimaryArtifact( boolean primaryArtifact ) + { + this.primaryArtifact = primaryArtifact; + } + + /** + * @return {@link #attachClasses} + */ + public boolean isAttachClasses() + { + return attachClasses; + } + + /** + * @param attachClasses {@link #attachClasses} + */ + public void setAttachClasses( boolean attachClasses ) + { + this.attachClasses = attachClasses; + } + + /** + * @return {@link #classesClassifier} + */ + public String getClassesClassifier() + { + return classesClassifier; + } + + /** + * @param classesClassifier {@link #classesClassifier} + */ + public void setClassesClassifier( String classesClassifier ) + { + this.classesClassifier = classesClassifier; + } + + /** + * @return {@link #failOnMissingWebXml} + */ + public boolean isFailOnMissingWebXml() + { + return failOnMissingWebXml; + } + + /** + * @param failOnMissingWebXml {@link #failOnMissingWebXml} + */ + public void setFailOnMissingWebXml( boolean failOnMissingWebXml ) + { + this.failOnMissingWebXml = failOnMissingWebXml; + } + + public boolean isSkip() + { + return skip; + } +} diff --git a/Java/maven-war-plugin-WarMojo_349/metadata.json b/Java/maven-war-plugin-WarMojo_349/metadata.json new file mode 100644 index 000000000..1f0939743 --- /dev/null +++ b/Java/maven-war-plugin-WarMojo_349/metadata.json @@ -0,0 +1,21 @@ +{ + "language": "java", + "id": "maven-war-plugin-WarMojo_349", + "buggyPath": ".", + "referencePath": null, + "buildCommand": "mvn package -V -B -Denforcer.skip=true -Dcheckstyle.skip=true -Dcobertura.skip=true -Drat.skip=true -Dlicense.skip=true -Dfindbugs.skip=true -Dgpg.skip=true -Dskip.npm=true -Dskip.gulp=true -Dskip.bower=true -Drat.numUnapprovedLicenses=100 -DskipTests=true -DskipITs=true -Dtest=None -DfailIfNoTests=false", + "testCommand": "mvn test -V -B -Denforcer.skip=true -Dcheckstyle.skip=true -Dcobertura.skip=true -Drat.skip=true -Dlicense.skip=true -Dfindbugs.skip=true -Dgpg.skip=true -Dskip.npm=true -Dskip.gulp=true -Dskip.bower=true -Drat.numUnapprovedLicenses=100", + "categories": [ + "safety", + "npe" + ], + "npe": { + "filepath": "src/main/java/org/apache/maven/plugins/war/WarMojo.java", + "line": 363, + "npe_method": "getTargetFile", + "deref_field": "classifier", + "npe_class": "WarMojo", + "repo": "maven-war-plugin", + "bug_id": "WarMojo_349" + } +} diff --git a/Java/maven-war-plugin-WarMojo_349/npe.json b/Java/maven-war-plugin-WarMojo_349/npe.json new file mode 100644 index 000000000..4073aec0b --- /dev/null +++ b/Java/maven-war-plugin-WarMojo_349/npe.json @@ -0,0 +1,7 @@ +{ + "filepath": "src/main/java/org/apache/maven/plugins/war/WarMojo.java", + "line": 363, + "npe_method": "getTargetFile", + "deref_field": "classifier", + "npe_class": "WarMojo" +} \ No newline at end of file diff --git a/Java/maven-war-plugin-WarProjectPackagingTask_327/Dockerfile b/Java/maven-war-plugin-WarProjectPackagingTask_327/Dockerfile new file mode 100644 index 000000000..34955205a --- /dev/null +++ b/Java/maven-war-plugin-WarProjectPackagingTask_327/Dockerfile @@ -0,0 +1,18 @@ +FROM ghcr.io/kupl/starlab-benchmarks/java-base:maven-war-plugin + +ENV TZ=Asia/Seoul + +COPY ./metadata.json . +COPY ./npe.json . +COPY ./buggy.java /tmp/buggy.java +RUN export BUGGY_PATH=$(cat metadata.json | jq -r ".npe.filepath") \ + && export BUGGY_LINE=$(cat metadata.json | jq -r ".npe.line") \ + && export BUGGY_MTHD=$(cat metadata.json | jq -r ".npe.npe_method") \ + && mv /tmp/buggy.java $BUGGY_PATH \ + && echo "[{\"filepath\": \"$BUGGY_PATH\", \"line\": $BUGGY_LINE, \"method_name\": \"$BUGGY_MTHD\"}]" | jq . > traces.json + +RUN git init . && git add -A + +RUN $(cat metadata.json | jq -r ".buildCommand") + +RUN $(cat metadata.json | jq -r ".testCommand"); if [ $? -eq 0 ]; then exit 1; fi diff --git a/Java/maven-war-plugin-WarProjectPackagingTask_327/buggy.java b/Java/maven-war-plugin-WarProjectPackagingTask_327/buggy.java new file mode 100644 index 000000000..9edee00b6 --- /dev/null +++ b/Java/maven-war-plugin-WarProjectPackagingTask_327/buggy.java @@ -0,0 +1,380 @@ +package org.apache.maven.plugins.war.packaging; + +/* + * 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. + */ + +import java.io.File; +import java.io.IOException; +import java.util.Objects; + +import org.apache.maven.model.Resource; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.MojoFailureException; +import org.apache.maven.plugins.war.Overlay; +import org.apache.maven.plugins.war.util.PathSet; +import org.apache.maven.shared.filtering.MavenFilteringException; +import org.codehaus.plexus.util.DirectoryScanner; +import org.codehaus.plexus.util.StringUtils; + +/** + * Handles the project own resources, that is: + *

    + *
  • The list of web resources, if any
  • + *
  • The content of the webapp directory if it exists
  • + *
  • The custom deployment descriptor(s), if any
  • + *
  • The content of the classes directory if it exists
  • + *
  • The dependencies of the project
  • + *
+ * + * @author Stephane Nicoll + */ +public class WarProjectPackagingTask + extends AbstractWarPackagingTask +{ + private final Resource[] webResources; + + private final File webXml; + + private final File containerConfigXML; + + private final String id; + + private Overlay currentProjectOverlay; + + /** + * @param webResources {@link #webResources} + * @param webXml {@link #webXml} + * @param containerConfigXml {@link #containerConfigXML} + * @param currentProjectOverlay {@link #currentProjectOverlay} + */ + public WarProjectPackagingTask( Resource[] webResources, File webXml, File containerConfigXml, + Overlay currentProjectOverlay ) + { + if ( webResources != null ) + { + this.webResources = webResources; + } + else + { + this.webResources = new Resource[0]; + } + this.webXml = webXml; + this.containerConfigXML = containerConfigXml; + this.currentProjectOverlay = currentProjectOverlay; + this.id = currentProjectOverlay.getId(); + } + + @Override + public void performPackaging( WarPackagingContext context ) + throws MojoExecutionException, MojoFailureException + { + context.getLog().info( "Processing war project" ); + + // Prepare the INF directories + File webinfDir = new File( context.getWebappDirectory(), WEB_INF_PATH ); + webinfDir.mkdirs(); + File metainfDir = new File( context.getWebappDirectory(), META_INF_PATH ); + metainfDir.mkdirs(); + + handleWebResources( context ); + + handleWebAppSourceDirectory( context ); + + // Debug mode: dump the path set for the current build + PathSet pathSet = context.getWebappStructure().getStructure( "currentBuild" ); + context.getLog().debug( "Dump of the current build pathSet content -->" ); + for ( String path : pathSet ) + { + context.getLog().debug( path ); + } + context.getLog().debug( "-- end of dump --" ); + + handleDeploymentDescriptors( context, webinfDir, metainfDir, context.isFailOnMissingWebXml() ); + + handleClassesDirectory( context ); + + handleArtifacts( context ); + + if ( !context.getWebappDirectory().mkdirs() ) + { + context.deleteOutdatedResources(); + } + } + + /** + * Handles the web resources. + * + * @param context the packaging context + * @throws MojoExecutionException if a resource could not be copied + */ + protected void handleWebResources( WarPackagingContext context ) + throws MojoExecutionException + { + for ( Resource resource : webResources ) + { + + // MWAR-246 + if ( resource.getDirectory() == null ) + { + throw new MojoExecutionException( "The tag is missing from the tag." ); + } + + if ( !( new File( resource.getDirectory() ) ).isAbsolute() ) + { + resource.setDirectory( context.getProject().getBasedir() + File.separator + resource.getDirectory() ); + } + + // Make sure that the resource directory is not the same as the webappDirectory + if ( !resource.getDirectory().equals( context.getWebappDirectory().getPath() ) ) + { + + try + { + copyResources( context, resource ); + } + catch ( IOException e ) + { + throw new MojoExecutionException( "Could not copy resource [" + resource.getDirectory() + "]", e ); + } + } + } + } + + /** + * Handles the webapp sources. + * + * @param context the packaging context + * @throws MojoExecutionException if the sources could not be copied + */ + protected void handleWebAppSourceDirectory( WarPackagingContext context ) + throws MojoExecutionException + { + // CHECKSTYLE_OFF: LineLength + if ( !context.getWebappSourceDirectory().exists() ) + { + context.getLog().debug( "webapp sources directory does not exist - skipping." ); + } + else if ( !context.getWebappSourceDirectory().getAbsolutePath().equals( context.getWebappDirectory().getPath() ) ) + { + context.getLog().info( "Copying webapp resources [" + context.getWebappSourceDirectory() + "]" ); + final PathSet sources = + getFilesToIncludes( context.getWebappSourceDirectory(), context.getWebappSourceIncludes(), + context.getWebappSourceExcludes(), context.isWebappSourceIncludeEmptyDirectories() ); + + try + { + copyFiles( id, context, context.getWebappSourceDirectory(), sources, false ); + } + catch ( IOException e ) + { + throw new MojoExecutionException( "Could not copy webapp sources [" + + context.getWebappDirectory().getAbsolutePath() + "]", e ); + } + } + // CHECKSTYLE_ON: LineLength + } + + /** + * Handles the webapp artifacts. + * + * @param context the packaging context + * @throws MojoExecutionException if the artifacts could not be packaged + */ + protected void handleArtifacts( WarPackagingContext context ) + throws MojoExecutionException + { + ArtifactsPackagingTask task = + new ArtifactsPackagingTask( context.getProject().getArtifacts(), currentProjectOverlay ); + task.performPackaging( context ); + } + + /** + * Handles the webapp classes. + * + * @param context the packaging context + * @throws MojoExecutionException if the classes could not be packaged + */ + protected void handleClassesDirectory( WarPackagingContext context ) + throws MojoExecutionException + { + ClassesPackagingTask task = new ClassesPackagingTask( currentProjectOverlay ); + task.performPackaging( context ); + } + + /** + * Handles the deployment descriptors, if specified. Note that the behavior here is slightly different since the + * customized entry always win, even if an overlay has already packaged a web.xml previously. + * + * @param context the packaging context + * @param webinfDir the web-inf directory + * @param metainfDir the meta-inf directory + * @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, + Boolean failOnMissingWebXml ) + throws MojoFailureException, MojoExecutionException + { + try + { + if ( webXml != null && StringUtils.isNotEmpty( webXml.getName() ) ) + { + if ( !webXml.exists() + && ( failOnMissingWebXml == null || Boolean.TRUE.equals( failOnMissingWebXml ) ) ) + { + throw new MojoFailureException( "The specified web.xml file '" + webXml + "' does not exist" ); + } + + // Making sure that it won't get overlayed + context.getWebappStructure().registerFileForced( id, WEB_INF_PATH + "/web.xml" ); + + if ( context.isFilteringDeploymentDescriptors() ) + { + context.getMavenFileFilter().copyFile( webXml, new File( webinfDir, "web.xml" ), true, + context.getFilterWrappers(), getEncoding( webXml ) ); + } + else + { + copyFile( context, webXml, new File( webinfDir, "web.xml" ), "WEB-INF/web.xml", true ); + } + } + else + { + // the webXml can be the default one + File defaultWebXml = new File( context.getWebappSourceDirectory(), WEB_INF_PATH + "/web.xml" ); + // if exists we can filter it + if ( defaultWebXml.exists() && context.isFilteringDeploymentDescriptors() ) + { + context.getWebappStructure().registerFile( id, WEB_INF_PATH + "/web.xml" ); + context.getMavenFileFilter().copyFile( defaultWebXml, new File( webinfDir, "web.xml" ), true, + context.getFilterWrappers(), getEncoding( defaultWebXml ) ); + } + } + + if ( containerConfigXML != null && StringUtils.isNotEmpty( containerConfigXML.getName() ) ) + { + String xmlFileName = containerConfigXML.getName(); + + context.getWebappStructure().registerFileForced( id, META_INF_PATH + "/" + xmlFileName ); + + if ( context.isFilteringDeploymentDescriptors() ) + { + context.getMavenFileFilter().copyFile( containerConfigXML, new File( metainfDir, xmlFileName ), + true, context.getFilterWrappers(), + getEncoding( containerConfigXML ) ); + } + else + { + copyFile( context, containerConfigXML, new File( metainfDir, xmlFileName ), "META-INF/" + + xmlFileName, true ); + } + } + } + catch ( IOException e ) + { + if ( failOnMissingWebXml == null || Boolean.TRUE.equals( failOnMissingWebXml ) ) + { + throw new MojoExecutionException( "Failed to copy deployment descriptor", e ); + } + } + catch ( MavenFilteringException e ) + { + throw new MojoExecutionException( "Failed to copy deployment descriptor", e ); + } + } + + /** + * Copies webapp webResources from the specified directory. + * + * @param context the WAR packaging context to use + * @param resource the resource to copy + * @throws IOException if an error occurred while copying the resources + * @throws MojoExecutionException if an error occurred while retrieving the filter properties + */ +/** + * Copies webapp webResources from the specified directory. + * + * @param context + * the WAR packaging context to use + * @param resource + * the resource to copy + * @throws IOException + * if an error occurred while copying the resources + * @throws MojoExecutionException + * if an error occurred while retrieving the filter properties + */ +public void copyResources(org.apache.maven.plugins.war.packaging.WarPackagingContext context, org.apache.maven.model.Resource resource) throws java.io.IOException, org.apache.maven.plugin.MojoExecutionException { + if (!context.getWebappDirectory().exists()) { + context.getLog().warn(((("Not copying webapp webResources [" + resource.getDirectory()) + "]: webapp directory [") + context.getWebappDirectory().getAbsolutePath()) + "] does not exist!"); + } + context.getLog().info(((("Copying webapp webResources [" + resource.getDirectory()) + "] to [") + context.getWebappDirectory().getAbsolutePath()) + "]"); + java.lang.String[] fileNames = getFilesToCopy(resource); + for (java.lang.String fileName : fileNames) { + java.lang.String targetFileName = fileName; + { + // TODO make sure this thing is 100% safe + // MWAR-129 if targetPath is only a dot . or ./ + // and the Resource is in a part of the warSourceDirectory the file from sources will override this + // that's we don't have to add the targetPath yep not nice but works + if ((!java.util.Objects.equals(".", /* NPEX_NULL_EXP */ + resource.getTargetPath())) && (!java.util.Objects.equals("./", resource.getTargetPath()))) { + targetFileName = (resource.getTargetPath() + java.io.File.separator) + targetFileName; + } + } + if (resource.isFiltering() && (!context.isNonFilteredExtension(fileName))) { + copyFilteredFile(id, context, new java.io.File(resource.getDirectory(), fileName), targetFileName); + } else { + copyFile(id, context, new java.io.File(resource.getDirectory(), fileName), targetFileName); + } + } +} + + /** + * Returns a list of filenames that should be copied over to the destination directory. + * + * @param resource the resource to be scanned + * @return the array of filenames, relative to the sourceDir + */ + private String[] getFilesToCopy( Resource resource ) + { + // CHECKSTYLE_OFF: LineLength + DirectoryScanner scanner = new DirectoryScanner(); + scanner.setBasedir( resource.getDirectory() ); + if ( resource.getIncludes() != null && !resource.getIncludes().isEmpty() ) + { + scanner.setIncludes( resource.getIncludes().toArray( new String[resource.getIncludes().size()] ) ); + } + else + { + scanner.setIncludes( DEFAULT_INCLUDES ); + } + if ( resource.getExcludes() != null && !resource.getExcludes().isEmpty() ) + { + scanner.setExcludes( resource.getExcludes().toArray( new String[resource.getExcludes().size()] ) ); + } + + scanner.addDefaultExcludes(); + + scanner.scan(); + + return scanner.getIncludedFiles(); + // CHECKSTYLE_ON: LineLength + } +} diff --git a/Java/maven-war-plugin-WarProjectPackagingTask_327/metadata.json b/Java/maven-war-plugin-WarProjectPackagingTask_327/metadata.json new file mode 100644 index 000000000..075a965fe --- /dev/null +++ b/Java/maven-war-plugin-WarProjectPackagingTask_327/metadata.json @@ -0,0 +1,21 @@ +{ + "language": "java", + "id": "maven-war-plugin-WarProjectPackagingTask_327", + "buggyPath": ".", + "referencePath": null, + "buildCommand": "mvn package -V -B -Denforcer.skip=true -Dcheckstyle.skip=true -Dcobertura.skip=true -Drat.skip=true -Dlicense.skip=true -Dfindbugs.skip=true -Dgpg.skip=true -Dskip.npm=true -Dskip.gulp=true -Dskip.bower=true -Drat.numUnapprovedLicenses=100 -DskipTests=true -DskipITs=true -Dtest=None -DfailIfNoTests=false", + "testCommand": "mvn test -V -B -Denforcer.skip=true -Dcheckstyle.skip=true -Dcobertura.skip=true -Drat.skip=true -Dlicense.skip=true -Dfindbugs.skip=true -Dgpg.skip=true -Dskip.npm=true -Dskip.gulp=true -Dskip.bower=true -Drat.numUnapprovedLicenses=100", + "categories": [ + "safety", + "npe" + ], + "npe": { + "filepath": "src/main/java/org/apache/maven/plugins/war/packaging/WarProjectPackagingTask.java", + "line": 337, + "npe_method": "copyResources", + "deref_field": "getTargetPath", + "npe_class": "WarProjectPackagingTask", + "repo": "maven-war-plugin", + "bug_id": "WarProjectPackagingTask_327" + } +} diff --git a/Java/maven-war-plugin-WarProjectPackagingTask_327/npe.json b/Java/maven-war-plugin-WarProjectPackagingTask_327/npe.json new file mode 100644 index 000000000..031939565 --- /dev/null +++ b/Java/maven-war-plugin-WarProjectPackagingTask_327/npe.json @@ -0,0 +1,7 @@ +{ + "filepath": "src/main/java/org/apache/maven/plugins/war/packaging/WarProjectPackagingTask.java", + "line": 337, + "npe_method": "copyResources", + "deref_field": "getTargetPath", + "npe_class": "WarProjectPackagingTask" +} \ No newline at end of file