From 20a66376d649ef1bae22977bfc2c6aeb4445ce8f Mon Sep 17 00:00:00 2001 From: Karel Piwko Date: Tue, 11 Jun 2013 15:23:17 +0200 Subject: [PATCH] SHRINKRES-141 Fixed behavior when missing resources directory --- .../src/it/jar-without-resources/pom.xml | 56 +++++++++++++++++++ .../src/main/java/test/JarClass.java | 13 +++++ .../main/java/test/nested/NestedJarClass.java | 19 +++++++ .../src/test/java/test/JarTestCase.java | 35 ++++++++++++ .../src/test/resources/test.properties | 1 + .../importer/JarMavenImporterTestCase.java | 10 ++++ .../impl/maven/pom/ParsedPomFileImpl.java | 11 +++- 7 files changed, 143 insertions(+), 2 deletions(-) create mode 100644 impl-maven-archive/src/it/jar-without-resources/pom.xml create mode 100644 impl-maven-archive/src/it/jar-without-resources/src/main/java/test/JarClass.java create mode 100644 impl-maven-archive/src/it/jar-without-resources/src/main/java/test/nested/NestedJarClass.java create mode 100644 impl-maven-archive/src/it/jar-without-resources/src/test/java/test/JarTestCase.java create mode 100644 impl-maven-archive/src/it/jar-without-resources/src/test/resources/test.properties diff --git a/impl-maven-archive/src/it/jar-without-resources/pom.xml b/impl-maven-archive/src/it/jar-without-resources/pom.xml new file mode 100644 index 00000000..86784f74 --- /dev/null +++ b/impl-maven-archive/src/it/jar-without-resources/pom.xml @@ -0,0 +1,56 @@ + + + + + 4.0.0 + + + org.jboss.shrinkwrap.resolver.test + shrinkwrap-resolver-impl-maven-test-jar-without-resources-sample + 1.0.0 + jar + ShrinkWrap Resolver Maven Importer Implementation Tests: Jar Without Resources + + + + + commons-codec + commons-codec + 1.7 + + + + junit + junit + test + 4.10 + + + + org.jboss.spec + jboss-javaee-web-6.0 + 3.0.2.Final + provided + pom + + + + xalan + xalan + + + + + + + + + org.apache.maven.plugins + maven-jar-plugin + 2.3.2 + + + + + diff --git a/impl-maven-archive/src/it/jar-without-resources/src/main/java/test/JarClass.java b/impl-maven-archive/src/it/jar-without-resources/src/main/java/test/JarClass.java new file mode 100644 index 00000000..af0907d1 --- /dev/null +++ b/impl-maven-archive/src/it/jar-without-resources/src/main/java/test/JarClass.java @@ -0,0 +1,13 @@ +package test; + +import javax.ejb.Stateless; + +@Stateless +public class JarClass { + + public static final String GREETINGS = "Hello from MavenImporter imported class"; + + public String greet() { + return GREETINGS; + } +} diff --git a/impl-maven-archive/src/it/jar-without-resources/src/main/java/test/nested/NestedJarClass.java b/impl-maven-archive/src/it/jar-without-resources/src/main/java/test/nested/NestedJarClass.java new file mode 100644 index 00000000..c3bf28cf --- /dev/null +++ b/impl-maven-archive/src/it/jar-without-resources/src/main/java/test/nested/NestedJarClass.java @@ -0,0 +1,19 @@ +package test.nested; + +import java.nio.charset.Charset; + +import org.apache.commons.codec.binary.Base64; + +import test.JarClass; + +// this file greets in Base64 +public class NestedJarClass extends JarClass { + + public static final String GREETINGS = "Hello from MavenImporter imported nested class"; + + @Override + public String greet() { + return Base64.encodeBase64String(GREETINGS.getBytes(Charset.defaultCharset())); + } + +} diff --git a/impl-maven-archive/src/it/jar-without-resources/src/test/java/test/JarTestCase.java b/impl-maven-archive/src/it/jar-without-resources/src/test/java/test/JarTestCase.java new file mode 100644 index 00000000..5478aeee --- /dev/null +++ b/impl-maven-archive/src/it/jar-without-resources/src/test/java/test/JarTestCase.java @@ -0,0 +1,35 @@ +/* + * JBoss, Home of Professional Open Source + * Copyright 2010, Red Hat Middleware LLC, and individual contributors + * by the @authors tag. See the copyright.txt in the distribution for a + * full listing of individual contributors. + * + * Licensed 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 test; + +import org.junit.Assert; +import org.junit.Test; + +/** + * Test cases for MavenImporter with Jar + * + * @author archive = doImport("src/it/jar-without-resources/pom.xml"); + + assertThat(archive.getContent(), size(3)); + } + private Archive doImport(String pomFile) { // When WebArchive archive = ShrinkWrap.create(MavenImporter.class).loadPomFromFile(pomFile).importBuildOutput() diff --git a/impl-maven/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/pom/ParsedPomFileImpl.java b/impl-maven/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/pom/ParsedPomFileImpl.java index cbd549e0..17f8a32d 100644 --- a/impl-maven/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/pom/ParsedPomFileImpl.java +++ b/impl-maven/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/pom/ParsedPomFileImpl.java @@ -128,7 +128,12 @@ public List getProjectResources() { List resources = model.getBuild().getResources(); // FIXME filtering is not set here for (Resource res : resources) { - for (File candidate : FileUtils.listFiles(new File(res.getDirectory()))) { + // we add resources only if they can be read + File resourceDir = new File(res.getDirectory()); + if (!Validate.isReadable(resourceDir)) { + continue; + } + for (File candidate : FileUtils.listFiles(resourceDir)) { // FIXME handle exclusions and inclusions here files.add(candidate); } @@ -174,6 +179,9 @@ public Map getPluginConfiguration(String pluginKey) { // get raw configuration Xpp3Dom rawConfiguration = (Xpp3Dom) plugin.getConfiguration(); + if (rawConfiguration == null) { + return Collections.emptyMap(); + } return toMappedConfiguration(rawConfiguration); } @@ -215,7 +223,6 @@ private Map toMappedConfiguration(Xpp3Dom node) { */ private static final class FileUtils { public static Collection listFiles(File root) { - List allFiles = new ArrayList(); Queue dirs = new LinkedList(); dirs.add(root);