From 45a820192170358c50882665b41e205f2b3855b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herv=C3=A9=20Boutemy?= Date: Sat, 13 Jun 2020 11:23:44 +0200 Subject: [PATCH] [MWAR-45] add an IT testing archiveClasses result --- src/it/archiveClasses/pom.xml | 69 +++++++++++++ .../java/org/apache/maven/it0016/Person.java | 35 +++++++ .../src/main/webapp/WEB-INF/web.xml | 23 +++++ .../archiveClasses/src/main/webapp/index.html | 23 +++++ src/it/archiveClasses/verify.bsh | 99 +++++++++++++++++++ 5 files changed, 249 insertions(+) create mode 100644 src/it/archiveClasses/pom.xml create mode 100644 src/it/archiveClasses/src/main/java/org/apache/maven/it0016/Person.java create mode 100644 src/it/archiveClasses/src/main/webapp/WEB-INF/web.xml create mode 100644 src/it/archiveClasses/src/main/webapp/index.html create mode 100644 src/it/archiveClasses/verify.bsh diff --git a/src/it/archiveClasses/pom.xml b/src/it/archiveClasses/pom.xml new file mode 100644 index 00000000..61a6fb3b --- /dev/null +++ b/src/it/archiveClasses/pom.xml @@ -0,0 +1,69 @@ + + + + + + 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 + + + + + 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/src/it/archiveClasses/src/main/java/org/apache/maven/it0016/Person.java b/src/it/archiveClasses/src/main/java/org/apache/maven/it0016/Person.java new file mode 100644 index 00000000..4a287e77 --- /dev/null +++ b/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/src/it/archiveClasses/src/main/webapp/WEB-INF/web.xml b/src/it/archiveClasses/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 00000000..c1af95de --- /dev/null +++ b/src/it/archiveClasses/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,23 @@ + + + + + + diff --git a/src/it/archiveClasses/src/main/webapp/index.html b/src/it/archiveClasses/src/main/webapp/index.html new file mode 100644 index 00000000..8e81e877 --- /dev/null +++ b/src/it/archiveClasses/src/main/webapp/index.html @@ -0,0 +1,23 @@ + + + + Hello World + + diff --git a/src/it/archiveClasses/verify.bsh b/src/it/archiveClasses/verify.bsh new file mode 100644 index 00000000..9b3da750 --- /dev/null +++ b/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;