Skip to content

Commit

Permalink
SHRINKRES-141 Fixed behavior when missing resources directory
Browse files Browse the repository at this point in the history
  • Loading branch information
kpiwko committed Jun 11, 2013
1 parent 89f2ca6 commit 20a6637
Show file tree
Hide file tree
Showing 7 changed files with 143 additions and 2 deletions.
56 changes: 56 additions & 0 deletions impl-maven-archive/src/it/jar-without-resources/pom.xml
@@ -0,0 +1,56 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

<!-- Model Version -->
<modelVersion>4.0.0</modelVersion>

<!-- Artifact Configuration -->
<groupId>org.jboss.shrinkwrap.resolver.test</groupId>
<artifactId>shrinkwrap-resolver-impl-maven-test-jar-without-resources-sample</artifactId>
<version>1.0.0</version>
<packaging>jar</packaging>
<name>ShrinkWrap Resolver Maven Importer Implementation Tests: Jar Without Resources</name>

<dependencies>
<!-- External Projects -->
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.7</version>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
<version>4.10</version>
</dependency>

<dependency>
<groupId>org.jboss.spec</groupId>
<artifactId>jboss-javaee-web-6.0</artifactId>
<version>3.0.2.Final</version>
<scope>provided</scope>
<type>pom</type>
<exclusions>
<!-- xalan is not in Maven Central -->
<exclusion>
<groupId>xalan</groupId>
<artifactId>xalan</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.3.2</version>
</plugin>
</plugins>
</build>

</project>
@@ -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;
}
}
@@ -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()));
}

}
@@ -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 <a href="kpiwko@redhat.com>Karel Piwko</a>
*
*/
public class JarTestCase {

@Test
public void testJar() {
Assert.assertTrue(true);
}

}
@@ -0,0 +1 @@
test.property=value
Expand Up @@ -43,6 +43,7 @@ public class JarMavenImporterTestCase {
@Before
public void cleanTarget() throws IOException {
TestFileUtil.removeDirectory(new File("src/it/jar-sample/target"));
TestFileUtil.removeDirectory(new File("src/it/jar-without-resources/target"));
}

@Test
Expand All @@ -67,6 +68,15 @@ public void importJarWithIncludes() {
assertThat(archive.getContent(), size(4));
}

//SHRINKRES-141
@Test
public void importJarWithoutResources() {
// When
final Archive<?> 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()
Expand Down
Expand Up @@ -128,7 +128,12 @@ public List<File> getProjectResources() {
List<Resource> 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);
}
Expand Down Expand Up @@ -174,6 +179,9 @@ public Map<String, Object> getPluginConfiguration(String pluginKey) {

// get raw configuration
Xpp3Dom rawConfiguration = (Xpp3Dom) plugin.getConfiguration();
if (rawConfiguration == null) {
return Collections.emptyMap();
}
return toMappedConfiguration(rawConfiguration);
}

Expand Down Expand Up @@ -215,7 +223,6 @@ private Map<String, Object> toMappedConfiguration(Xpp3Dom node) {
*/
private static final class FileUtils {
public static Collection<File> listFiles(File root) {

List<File> allFiles = new ArrayList<File>();
Queue<File> dirs = new LinkedList<File>();
dirs.add(root);
Expand Down

0 comments on commit 20a6637

Please sign in to comment.