Skip to content

Commit

Permalink
make sure we contruct the path correctly when testing on isDirectory
Browse files Browse the repository at this point in the history
this is only an issue with uri:classloader:/ and a classloader setup
where the .jrubydir needs to be loaded to treat the path as directory

fixes #3342

Sponsored by Lookout Inc.
mkristian committed Sep 22, 2015
1 parent df07868 commit 5302de7
Showing 4 changed files with 55 additions and 4 deletions.
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/util/URLResource.java
Original file line number Diff line number Diff line change
@@ -265,7 +265,7 @@ private static String[] listClassLoaderFiles(ClassLoader classloader, String pat
}
try
{
pathname = pathname + (pathname.equals("") ? ".jrubydir" : "/.jrubydir");
pathname = pathname + (pathname.equals("") || pathname.endsWith("/") ? ".jrubydir" : "/.jrubydir");
Enumeration<URL> urls = classloader.getResources(pathname);
if (!urls.hasMoreElements()) {
return null;
32 changes: 29 additions & 3 deletions core/src/test/java/org/jruby/util/URLResourceTest.java
Original file line number Diff line number Diff line change
@@ -20,6 +20,18 @@ public void testDirectory(){
Arrays.asList(new String[] {".", "dir_without_listing", "dir_with_listing"}));
}

public void testDirectoryWithTrailingSlash(){
String uri = Thread.currentThread().getContextClassLoader().getResource( "somedir" ).toExternalForm();
FileResource resource = URLResource.create((Ruby) null, "uri:" + uri + "/");

assertNotNull(resource );
assertFalse(resource.isFile());
assertTrue(resource.isDirectory());
assertTrue(resource.exists());
assertEquals(Arrays.asList(resource.list()),
Arrays.asList(new String[] {".", "dir_without_listing", "dir_with_listing"}));
}

public void testNoneDirectory(){
String uri = Thread.currentThread().getContextClassLoader().getResource( "somedir/dir_without_listing" ).toExternalForm();
FileResource resource = URLResource.create((Ruby) null, "uri:" + uri);
@@ -59,13 +71,27 @@ public void testDirectoryClassloader()
{
FileResource resource = URLResource.create((Ruby) null, "uri:classloader:/somedir");

assertNotNull(resource);
assertFalse(resource.isFile());
assertTrue(resource.isDirectory());
assertTrue(resource.exists());
assertEquals(Arrays.asList(resource.list()),
Arrays.asList(new String[]{".", "dir_without_listing",
"dir_with_listing"}));
}

public void testDirectoryWithTrailingClassloader()
{
FileResource resource = URLResource.create((Ruby) null,
"uri:classloader:/somedir/");

assertNotNull( resource );
assertFalse( resource.isFile() );
assertTrue( resource.isDirectory() );
assertTrue( resource.exists() );
assertEquals( Arrays.asList( resource.list() ),
Arrays.asList( new String[] { ".", "dir_without_listing",
"dir_with_listing" } ) );
Arrays.asList( new String[] { ".", "dir_without_listing",
"dir_with_listing" } ) );
}

public void testNoneDirectoryClassloader()
@@ -102,4 +128,4 @@ public void testNonExistingFileClassloader()
assertFalse( resource.isDirectory() );
assertNull( resource.list() );
}
}
}
22 changes: 22 additions & 0 deletions maven/jruby-complete/src/it/integrity/pom.xml
Original file line number Diff line number Diff line change
@@ -198,6 +198,28 @@
</arguments>
</configuration>
</execution>
<execution>
<id>META-INF/jruby.home is not a file - GH-3342</id>
<phase>test</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<workingDirectory>${basedir}</workingDirectory>
<executable>java</executable>
<arguments>
<argument>-classpath</argument>
<classpath/>
<argument>org.jruby.Main</argument>
<argument>-e</argument>
<argument>
puts "jruby home is a file: " +
File.file?("uri:classloader:/META-INF/jruby.home").to_s +
File.file?("uri:classloader:/META-INF/jruby.home/").to_s
</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
3 changes: 3 additions & 0 deletions maven/jruby-complete/src/it/integrity/verify.bsh
Original file line number Diff line number Diff line change
@@ -53,3 +53,6 @@ if ( !log.contains( expected ) )
{
throw new RuntimeException( "log file does not contain '" + expected + "'" );
}

expected = "jruby home is a file: falsefalse";
if ( !log.contains( expected ) ) throw new RuntimeException( "log file does not contain '" + expected + "'" );

0 comments on commit 5302de7

Please sign in to comment.