[jboss-cvs] JBossAS SVN: r76487 - in projects/jboss-cl/trunk/classloading-vfs/src: main/org/jboss/classloading/spi/vfs/dependency and 2 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Jul 30 13:29:48 EDT 2008
Author: adrian at jboss.org
Date: 2008-07-30 13:29:48 -0400 (Wed, 30 Jul 2008)
New Revision: 76487
Modified:
projects/jboss-cl/trunk/classloading-vfs/src/main/org/jboss/classloading/plugins/vfs/PackageVisitor.java
projects/jboss-cl/trunk/classloading-vfs/src/main/org/jboss/classloading/plugins/vfs/VFSResourceVisitor.java
projects/jboss-cl/trunk/classloading-vfs/src/main/org/jboss/classloading/spi/vfs/dependency/VFSClassLoaderPolicyModule.java
projects/jboss-cl/trunk/classloading-vfs/src/main/org/jboss/classloading/spi/vfs/policy/VFSClassLoaderPolicy.java
projects/jboss-cl/trunk/classloading-vfs/src/tests/org/jboss/test/classloading/vfs/policy/test/ExportAllUnitTestCase.java
Log:
[JBCL-27] - Add support for excluded roots
Modified: projects/jboss-cl/trunk/classloading-vfs/src/main/org/jboss/classloading/plugins/vfs/PackageVisitor.java
===================================================================
--- projects/jboss-cl/trunk/classloading-vfs/src/main/org/jboss/classloading/plugins/vfs/PackageVisitor.java 2008-07-30 16:56:21 UTC (rev 76486)
+++ projects/jboss-cl/trunk/classloading-vfs/src/main/org/jboss/classloading/plugins/vfs/PackageVisitor.java 2008-07-30 17:29:48 UTC (rev 76487)
@@ -47,6 +47,9 @@
/** The roots */
private VirtualFile[] roots;
+
+ /** The excluded roots */
+ private VirtualFile[] excludedRoots;
/** The current root */
private VirtualFile root;
@@ -73,15 +76,16 @@
* Determine the packages
*
* @param roots the roots
+ * @param excludedRoots the excluded roots
* @param exportAll the exportAll
* @param included the included packages
* @param excluded the excluded packages
* @param excludedExport the excluded export packages
* @return the packages
*/
- public static Set<String> determineAllPackages(VirtualFile[] roots, ExportAll exportAll, ClassFilter included, ClassFilter excluded, ClassFilter excludedExport)
+ public static Set<String> determineAllPackages(VirtualFile[] roots, VirtualFile[] excludedRoots, ExportAll exportAll, ClassFilter included, ClassFilter excluded, ClassFilter excludedExport)
{
- PackageVisitor visitor = new PackageVisitor(roots, exportAll, included, excluded, excludedExport);
+ PackageVisitor visitor = new PackageVisitor(roots, excludedRoots, exportAll, included, excluded, excludedExport);
for (VirtualFile root : roots)
{
try
@@ -101,17 +105,19 @@
* Create a new PackageVisitor.
*
* @param roots the vfs roots
+ * @param excludedRoots the excluded roots
* @param exportAll the export all policy
* @param included the included packages
* @param excluded the excluded packages
* @param excludedExport the excluded export packages
* @throws IllegalArgumentException for a null exportAll policy
*/
- PackageVisitor(VirtualFile[] roots, ExportAll exportAll, ClassFilter included, ClassFilter excluded, ClassFilter excludedExport)
+ PackageVisitor(VirtualFile[] roots, VirtualFile[] excludedRoots, ExportAll exportAll, ClassFilter included, ClassFilter excluded, ClassFilter excludedExport)
{
if (exportAll == null)
throw new IllegalArgumentException("Null export policy");
this.roots = roots;
+ this.excludedRoots = excludedRoots;
this.exportAll = exportAll;
this.included = included;
this.excluded = excluded;
@@ -163,6 +169,15 @@
if (file.equals(other))
return false;
}
+ // Is this an excluded roots?
+ if (excludedRoots != null)
+ {
+ for (VirtualFile other : excludedRoots)
+ {
+ if (file.equals(other))
+ return false;
+ }
+ }
// Ok
return true;
Modified: projects/jboss-cl/trunk/classloading-vfs/src/main/org/jboss/classloading/plugins/vfs/VFSResourceVisitor.java
===================================================================
--- projects/jboss-cl/trunk/classloading-vfs/src/main/org/jboss/classloading/plugins/vfs/VFSResourceVisitor.java 2008-07-30 16:56:21 UTC (rev 76486)
+++ projects/jboss-cl/trunk/classloading-vfs/src/main/org/jboss/classloading/plugins/vfs/VFSResourceVisitor.java 2008-07-30 17:29:48 UTC (rev 76487)
@@ -42,6 +42,9 @@
/** The roots */
private VirtualFile[] roots;
+ /** The excluded roots */
+ private VirtualFile[] excludedRoots;
+
/** The current root */
private VirtualFile root;
@@ -73,6 +76,7 @@
* Visit the resources
*
* @param roots the roots
+ * @param excludedRoots the excluded roots
* @param included the included packages
* @param excluded the excluded packages
* @param classLoader the classLoader
@@ -80,9 +84,9 @@
* @param filter the filter
* @param recurseFilter the recurse filter
*/
- public static void visit(VirtualFile[] roots, ClassFilter included, ClassFilter excluded, ClassLoader classLoader, ResourceVisitor visitor, ResourceFilter filter, ResourceFilter recurseFilter)
+ public static void visit(VirtualFile[] roots, VirtualFile[] excludedRoots, ClassFilter included, ClassFilter excluded, ClassLoader classLoader, ResourceVisitor visitor, ResourceFilter filter, ResourceFilter recurseFilter)
{
- VFSResourceVisitor vfsVisitor = new VFSResourceVisitor(roots, included, excluded, classLoader, visitor, filter, recurseFilter);
+ VFSResourceVisitor vfsVisitor = new VFSResourceVisitor(roots, excludedRoots, included, excluded, classLoader, visitor, filter, recurseFilter);
for (VirtualFile root : roots)
{
try
@@ -108,7 +112,7 @@
* @param filter the filter
* @param recurseFilter the recurse filter
*/
- VFSResourceVisitor(VirtualFile[] roots, ClassFilter included, ClassFilter excluded, ClassLoader classLoader, ResourceVisitor visitor, ResourceFilter filter, ResourceFilter recurseFilter)
+ VFSResourceVisitor(VirtualFile[] roots, VirtualFile[] excludedRoots, ClassFilter included, ClassFilter excluded, ClassLoader classLoader, ResourceVisitor visitor, ResourceFilter filter, ResourceFilter recurseFilter)
{
if (roots == null)
throw new IllegalArgumentException("Null roots");
@@ -118,6 +122,7 @@
throw new IllegalArgumentException("Null visitor");
this.roots = roots;
+ this.excludedRoots = excludedRoots;
this.included = included;
this.excluded = excluded;
this.classLoader = classLoader;
@@ -192,6 +197,15 @@
if (file.equals(other))
return false;
}
+ // Is it an excluded root?
+ if (excludedRoots != null)
+ {
+ for (VirtualFile other : excludedRoots)
+ {
+ if (file.equals(other))
+ return false;
+ }
+ }
// Ok
return true;
Modified: projects/jboss-cl/trunk/classloading-vfs/src/main/org/jboss/classloading/spi/vfs/dependency/VFSClassLoaderPolicyModule.java
===================================================================
--- projects/jboss-cl/trunk/classloading-vfs/src/main/org/jboss/classloading/spi/vfs/dependency/VFSClassLoaderPolicyModule.java 2008-07-30 16:56:21 UTC (rev 76486)
+++ projects/jboss-cl/trunk/classloading-vfs/src/main/org/jboss/classloading/spi/vfs/dependency/VFSClassLoaderPolicyModule.java 2008-07-30 17:29:48 UTC (rev 76487)
@@ -116,7 +116,7 @@
ExportAll exportAll = getExportAll();
if (exportAll != null)
{
- Set<String> exportedPackages = PackageVisitor.determineAllPackages(roots, exportAll, included, excluded, excludedExport);
+ Set<String> exportedPackages = PackageVisitor.determineAllPackages(roots, null, exportAll, included, excluded, excludedExport);
for (String packageName : exportedPackages)
{
capability = factory.createPackage(packageName, version);
@@ -225,7 +225,7 @@
{
ClassFilter included = getIncluded();
ClassFilter excluded = getExcluded();
- VFSResourceVisitor.visit(roots, included, excluded, classLoader, visitor, filter, recurseFilter);
+ VFSResourceVisitor.visit(roots, null, included, excluded, classLoader, visitor, filter, recurseFilter);
}
}
}
Modified: projects/jboss-cl/trunk/classloading-vfs/src/main/org/jboss/classloading/spi/vfs/policy/VFSClassLoaderPolicy.java
===================================================================
--- projects/jboss-cl/trunk/classloading-vfs/src/main/org/jboss/classloading/spi/vfs/policy/VFSClassLoaderPolicy.java 2008-07-30 16:56:21 UTC (rev 76486)
+++ projects/jboss-cl/trunk/classloading-vfs/src/main/org/jboss/classloading/spi/vfs/policy/VFSClassLoaderPolicy.java 2008-07-30 17:29:48 UTC (rev 76487)
@@ -71,6 +71,9 @@
/** The roots */
private VirtualFile[] roots;
+
+ /** The excluded roots */
+ private VirtualFile[] excludedRoots;
/** Whether to export all */
private ExportAll exportAll;
@@ -149,6 +152,33 @@
{
return new VFSClassLoaderPolicy(name, roots);
}
+
+ /**
+ * Create a new VFSClassLoaderPolicy.
+ *
+ * @param roots the roots
+ * @param excludedRoots the excluded roots
+ * @return the classloader policy
+ * @throws IllegalArgumentException for null roots
+ */
+ public static VFSClassLoaderPolicy createVFSClassLoaderPolicy(VirtualFile[] roots, VirtualFile[] excludedRoots)
+ {
+ return new VFSClassLoaderPolicy(roots, excludedRoots);
+ }
+
+ /**
+ * Create a new VFSClassLoaderPolicy.
+ *
+ * @param name a name of the policy
+ * @param roots the roots
+ * @param excludedRoots the excluded roots
+ * @return the classloader policy
+ * @throws IllegalArgumentException for null roots
+ */
+ public static VFSClassLoaderPolicy createVFSClassLoaderPolicy(String name, VirtualFile[] roots, VirtualFile[] excludedRoots)
+ {
+ return new VFSClassLoaderPolicy(name, roots, excludedRoots);
+ }
/**
* Create a new VFSClassLoaderPolicy.
@@ -164,12 +194,37 @@
/**
* Create a new VFSClassLoaderPolicy.
*
+ * @param roots the roots
+ * @param excludedRoots the excluded roots
+ * @throws IllegalArgumentException for null roots
+ */
+ public VFSClassLoaderPolicy(VirtualFile[] roots, VirtualFile[] excludedRoots)
+ {
+ this(determineName(roots), roots, excludedRoots);
+ }
+
+ /**
+ * Create a new VFSClassLoaderPolicy.
+ *
* @param name the name
* @param roots the roots
* @throws IllegalArgumentException for null roots
*/
public VFSClassLoaderPolicy(String name, VirtualFile[] roots)
{
+ this(name, roots, null);
+ }
+
+ /**
+ * Create a new VFSClassLoaderPolicy.
+ *
+ * @param name the name
+ * @param roots the roots
+ * @param excludedRoots the excluded roots
+ * @throws IllegalArgumentException for null roots
+ */
+ public VFSClassLoaderPolicy(String name, VirtualFile[] roots, VirtualFile[] excludedRoots)
+ {
if (name == null)
throw new IllegalArgumentException("Null name");
if (roots == null)
@@ -179,9 +234,18 @@
if (root == null)
throw new IllegalArgumentException("Null root in " + Arrays.asList(roots));
}
+ if (excludedRoots != null)
+ {
+ for (VirtualFile excludedRoot : excludedRoots)
+ {
+ if (excludedRoot == null)
+ throw new IllegalArgumentException("Null excluded root in " + Arrays.asList(excludedRoots));
+ }
+ }
this.name = name;
this.roots = roots;
+ this.excludedRoots = excludedRoots;
}
@Override
@@ -288,7 +352,7 @@
{
if (exportedPackages == null)
{
- Set<String> exported = PackageVisitor.determineAllPackages(roots, exportAll, included, excluded, excludedExport);
+ Set<String> exported = PackageVisitor.determineAllPackages(roots, excludedRoots, exportAll, included, excluded, excludedExport);
exportedPackages = exported.toArray(new String[exported.size()]);
}
}
Modified: projects/jboss-cl/trunk/classloading-vfs/src/tests/org/jboss/test/classloading/vfs/policy/test/ExportAllUnitTestCase.java
===================================================================
--- projects/jboss-cl/trunk/classloading-vfs/src/tests/org/jboss/test/classloading/vfs/policy/test/ExportAllUnitTestCase.java 2008-07-30 16:56:21 UTC (rev 76486)
+++ projects/jboss-cl/trunk/classloading-vfs/src/tests/org/jboss/test/classloading/vfs/policy/test/ExportAllUnitTestCase.java 2008-07-30 17:29:48 UTC (rev 76487)
@@ -52,19 +52,28 @@
{
protected void testExportAll(ExportAll exportAll, Map<String, String> expected, String... urls) throws Exception
{
- Set<String> empty = Collections.emptySet();
- testExportAll(exportAll, expected, empty, urls);
+ testExportAll(exportAll, expected, urls, null);
}
protected void testExportAll(ExportAll exportAll, Map<String, String> expected, Set<String> empty, String... urls) throws Exception
{
- testExportAllAbsolute(exportAll, expected, empty, urls);
- testExportAllFromBase(exportAll, expected, empty, urls);
+ testExportAll(exportAll, expected, empty, urls, null);
}
+ protected void testExportAll(ExportAll exportAll, Map<String, String> expected, String[] urls, String[] excluded) throws Exception
+ {
+ Set<String> empty = Collections.emptySet();
+ testExportAll(exportAll, expected, empty, urls, excluded);
+ }
- protected void testExportAllCommon(ExportAll exportAll, Map<String, String> expected, Set<String> empty, VirtualFile[] files) throws Exception
+ protected void testExportAll(ExportAll exportAll, Map<String, String> expected, Set<String> empty, String[] urls, String[] excluded) throws Exception
{
- VFSClassLoaderPolicy policy = VFSClassLoaderPolicy.createVFSClassLoaderPolicy(files);
+ testExportAllAbsolute(exportAll, expected, empty, urls, excluded);
+ testExportAllFromBase(exportAll, expected, empty, urls, excluded);
+ }
+
+ protected void testExportAllCommon(ExportAll exportAll, Map<String, String> expected, Set<String> empty, VirtualFile[] files, VirtualFile[] excluded) throws Exception
+ {
+ VFSClassLoaderPolicy policy = VFSClassLoaderPolicy.createVFSClassLoaderPolicy(files, excluded);
policy.setExportAll(exportAll);
String[] packageNames = policy.getPackageNames();
@@ -90,7 +99,7 @@
}
}
- protected void testExportAllFromBase(ExportAll exportAll, Map<String, String> expected, Set<String> empty, String... urls) throws Exception
+ protected void testExportAllFromBase(ExportAll exportAll, Map<String, String> expected, Set<String> empty, String[] urls, String[] excluded) throws Exception
{
URL baseURL = getResource("/classloader");
assertNotNull(baseURL);
@@ -119,10 +128,38 @@
fail("Can't find " + urls[i]);
}
- testExportAllCommon(exportAll, expected, empty, files);
+ VirtualFile[] excludedFiles = null;
+ if (excluded != null)
+ {
+ excludedFiles = new VirtualFile[excluded.length];
+ for (int i = 0; i < excluded.length; ++i)
+ {
+ try
+ {
+ excludedFiles[i] = base.getChild(excluded[i]);
+ }
+ catch (IOException ignored)
+ {
+ }
+ if (excludedFiles[i] == null)
+ {
+ try
+ {
+ excludedFiles[i] = files[0].getChild(excluded[i]);
+ }
+ catch (IOException ignored)
+ {
+ }
+ }
+ if (excludedFiles[i] == null)
+ fail("Can't find " + excluded[i]);
+ }
+ }
+
+ testExportAllCommon(exportAll, expected, empty, files, excludedFiles);
}
- protected void testExportAllAbsolute(ExportAll exportAll, Map<String, String> expected, Set<String> empty, String... urls) throws Exception
+ protected void testExportAllAbsolute(ExportAll exportAll, Map<String, String> expected, Set<String> empty, String[] urls, String[] excluded) throws Exception
{
VirtualFile[] files = new VirtualFile[urls.length];
for (int i = 0; i < urls.length; ++i)
@@ -142,7 +179,28 @@
}
}
- testExportAllCommon(exportAll, expected, empty, files);
+ VirtualFile[] excludedFiles = null;
+ if (excluded != null)
+ {
+ excludedFiles = new VirtualFile[excluded.length];
+ for (int i = 0; i < excluded.length; ++i)
+ {
+ String urlString = "/classloader/" + excluded[i];
+ URL url = getResource(urlString);
+ if (url != null)
+ {
+ excludedFiles[i]= VFS.getRoot(url);
+ }
+ else
+ {
+ excludedFiles[i] = files[0].getChild(excluded[i]);
+ if (excludedFiles[i] == null)
+ fail("Expected to find resource: " + files[0].getName() + "/" + excluded[i]);
+ }
+ }
+ }
+
+ testExportAllCommon(exportAll, expected, empty, files, excludedFiles);
}
public void testExportAllJar1() throws Exception
@@ -289,6 +347,36 @@
testExportAll(ExportAll.ALL, expected, "testjar3", "subjar1.jar");
}
+
+ public void testExportAllSimpleExcluded() throws Exception
+ {
+ Map<String,String> expected = makeSimpleMap("testjar1",
+ "",
+ "package1"
+ );
+
+ testExportAll(ExportAll.ALL, expected, new String[] { "testjar1" } , new String[] { "package2" });
+ }
+
+ public void testExportAllMultipleRootsExcluded() throws Exception
+ {
+ Map<String,String> expected = makeSimpleMap("testjar1",
+ "",
+ "package1"
+ );
+
+ testExportAll(ExportAll.ALL, expected, new String[] { "testjar1", "testjar2" } , new String[] { "package2" });
+ }
+
+ public void testExportAllMultipleExcluded() throws Exception
+ {
+ Map<String,String> expected = makeSimpleMap("testjar1",
+ ""
+ );
+
+ testExportAll(ExportAll.ALL, expected, new String[] { "testjar1" } , new String[] { "package1", "package2" });
+ }
+
public void testJar3Resources()
throws Exception
{
More information about the jboss-cvs-commits
mailing list