Skip to content

Commit

Permalink
SHRINKRES-196 Added list return type to better support JDK8 streams.
Browse files Browse the repository at this point in the history
  • Loading branch information
John D. Ament authored and kpiwko committed Sep 1, 2014
1 parent 51c6429 commit fb9d644
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 4 deletions.
Expand Up @@ -18,6 +18,7 @@

import java.io.File;
import java.io.InputStream;
import java.util.List;

/**
* Represents the formatting stage of resolution in which the {@code RESOLVEDTYPE} is returned in the desired format.
Expand Down Expand Up @@ -87,6 +88,18 @@ public interface FormatStage<RESOLVEDTYPE extends ResolvedArtifact<RESOLVEDTYPE>
<RETURNTYPE> RETURNTYPE[] as(Class<RETURNTYPE> returnTypeClass) throws IllegalArgumentException,
UnsupportedOperationException;

/**
* Formats the resultant artifacts as a list of {@code type}s. If nothing matches resolution, an empty list will
* be returned. Supports extensible formats by registering a {@link FormatProcessor} for given {@code returnTypeClass}.
*
* @param returnTypeClass
* @return
* @throws {@link IllegalArgumentException} If the type is not specified
* @throws {@link UnsupportedOperationException} If the type is not supported *
*/
<RETURNTYPE> List<RETURNTYPE> asList(Class<RETURNTYPE> returnTypeClass) throws IllegalArgumentException,
UnsupportedOperationException;

/**
* Formats the resultant artifact as a {@code type}; assumes a single artifact is returned from resolution.
* Supports extensible formats by registering a {@link FormatProcessor} for given {@code returnTypeClass}.
Expand Down
Expand Up @@ -20,7 +20,9 @@
import java.io.InputStream;
import java.lang.reflect.Array;
import java.text.MessageFormat;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;

import org.jboss.shrinkwrap.resolver.api.NoResolvedResultException;
import org.jboss.shrinkwrap.resolver.api.NonUniqueResultException;
Expand Down Expand Up @@ -92,6 +94,11 @@ public <RETURNTYPE> RETURNTYPE[] as(Class<RETURNTYPE> returnTypeClass) throws Il
return array;
}

@Override
public <RETURNTYPE> List<RETURNTYPE> asList(Class<RETURNTYPE> returnTypeClass) throws IllegalArgumentException, UnsupportedOperationException {
return Arrays.asList(as(returnTypeClass));
}

@Override
public <RETURNTYPE> RETURNTYPE asSingle(Class<RETURNTYPE> type) throws IllegalArgumentException,
UnsupportedOperationException, NonUniqueResultException,
Expand Down
Expand Up @@ -17,6 +17,7 @@
package org.jboss.shrinkwrap.resolver.impl.maven.integration;

import java.io.File;
import java.util.List;

import org.jboss.shrinkwrap.resolver.api.maven.Maven;
import org.jboss.shrinkwrap.resolver.api.maven.ScopeType;
Expand Down Expand Up @@ -159,4 +160,19 @@ public void pomBasedDependenciesWithScope() {
ScopeType.TEST).validate(files);
}

/**
* Tests resolution of dependencies for a POM file with parent on local file system
*
*
*/
@Test
public void pomBasedDependenciesWithScopeAsList() {

final List<File> files = Maven.resolver().loadPomFromFile("target/poms/test-child.xml")
.importTestDependencies().resolve().withTransitivity().asList(File.class);

ValidationUtil.fromDependencyTree(new File("src/test/resources/dependency-trees/test-child.tree"), false,
ScopeType.TEST).validate(files);
}

}
Expand Up @@ -22,6 +22,7 @@
import java.io.IOException;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
Expand Down Expand Up @@ -157,13 +158,17 @@ else if (realAllowedScopes.contains(artifact.scope)) {
}

public void validate(final File single) throws AssertionError {
validate(new File[] { single });
validate(Collections.singletonList(single));
}

public void validate(final File... resolvedFiles) throws AssertionError {
public void validate(final File... files) {
validate(Arrays.asList(files));
}

public void validate(final List<File> resolvedFiles) throws AssertionError {
Assert.assertNotNull("There must be some files passed for validation, but the array was null", resolvedFiles);

final Collection<String> resolvedFileNames = new ArrayList<String>(resolvedFiles.length);
final Collection<String> resolvedFileNames = new ArrayList<String>(resolvedFiles.size());
for (final File resolvedFile : resolvedFiles) {
resolvedFileNames.add(resolvedFile.getName());
}
Expand Down Expand Up @@ -204,7 +209,7 @@ public void validate(final File... resolvedFiles) throws AssertionError {

// Problems; report 'em
final StringBuilder errorMessage = new StringBuilder().append(requiredFileNamePrefixes.size())
.append(" files required to be resolved, however ").append(resolvedFiles.length)
.append(" files required to be resolved, however ").append(resolvedFiles.size())
.append(" files were resolved. ").append("Resolution contains: \n");
if (foundNotAllowed.size() > 0) {
errorMessage.append("\tFound but not allowed:\n\t\t");
Expand Down

0 comments on commit fb9d644

Please sign in to comment.