Skip to content

Commit

Permalink
FORGE-1883: Created Resource.resolveChildren
Browse files Browse the repository at this point in the history
  • Loading branch information
gastaldi committed Jun 16, 2014
1 parent 9be185c commit e45d9b4
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import java.util.List;

import org.jboss.forge.addon.facets.AbstractFaceted;
import org.jboss.forge.addon.resource.util.ResourcePathResolver;
import org.jboss.forge.furnace.util.Streams;

/**
Expand Down Expand Up @@ -170,4 +171,12 @@ public <F extends ResourceFacet> boolean supports(F facet)
{
return facet != null;
}

@Override
public List<Resource<?>> resolveChildren(String path)
{
ResourcePathResolver resolver = new ResourcePathResolver(getResourceFactory(), this, path);
return resolver.resolve();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import java.util.List;

import org.jboss.forge.addon.facets.Faceted;
import org.jboss.forge.addon.resource.util.ResourcePathResolver;
import org.jboss.forge.furnace.addons.Addon;

/**
Expand Down Expand Up @@ -131,4 +132,12 @@ public interface Resource<T> extends Faceted<ResourceFacet>
* <code>null</code>.
*/
ResourceFactory getResourceFactory();

/**
* Resolve children resources from this {@link Resource} given a specific path.
*
* @see ResourcePathResolver
* @see ResourcePathResolver#resolve()
*/
List<Resource<?>> resolveChildren(String path);
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import java.io.IOException;
import java.io.OutputStream;
import java.nio.charset.Charset;
import java.util.List;

import javax.inject.Inject;

Expand Down Expand Up @@ -79,4 +80,19 @@ public void testResourceOutputStream() throws IOException
Assert.assertEquals("CONTENT", fileContent);
}

@Test
@SuppressWarnings("unchecked")
public void testDirectoryResourceResolveShouldBeTheSameForChild() throws IOException
{
File file = File.createTempFile("fileresourcetest", ".tmp");
file.deleteOnExit();
FileResource<?> fileResource = resourceFactory.create(FileResource.class, file);
FileResource<?> parentResource = resourceFactory.create(FileResource.class, file.getParentFile());
Assert.assertNotNull(fileResource);
Assert.assertNotNull(parentResource);
List<Resource<?>> children = parentResource.resolveChildren(file.getName());
Assert.assertEquals(1, children.size());
Assert.assertEquals(fileResource, children.get(0));
}

}

0 comments on commit e45d9b4

Please sign in to comment.