Skip to content

Commit

Permalink
apacheGH-2232: Handle drive letter in base
Browse files Browse the repository at this point in the history
  • Loading branch information
afs committed Feb 3, 2024
1 parent 2e2cec8 commit 23c4910
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@

public abstract class DatasetAssembler extends AssemblerBase implements Assembler {

/** @deprecated To be removed - use {@link #getGeneralType()} */
@Deprecated
public static Resource getType() { return getGeneralType(); }

/** This is the superclass of all datasets assemblers */
public static Resource getGeneralType() {
return DatasetAssemblerVocab.tDataset ;
Expand Down
18 changes: 11 additions & 7 deletions jena-arq/src/test/java/org/apache/jena/riot/TestSysRIOT.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@

import static org.apache.jena.atlas.lib.Lib.lowercase;

import java.util.function.Predicate;

import org.apache.jena.atlas.io.IO;
import org.apache.jena.base.Sys;
import org.junit.Assert;
Expand All @@ -43,7 +41,7 @@ public void chooseBaseIRI_2() {
public void chooseBaseIRI_3() {
if ( Sys.isWindows ) {
if ( IO.exists("c:/") )
testChooseBaseIRI("c:", s->lowercase(s).startsWith("file:///c:/"));
testChooseBaseIRI_windows("c:/", "file:///c:/");
} else
testChooseBaseIRI("x:", "x:");
}
Expand All @@ -52,23 +50,29 @@ public void chooseBaseIRI_3() {
public void chooseBaseIRI_4() {
if ( Sys.isWindows ) {
if ( IO.exists("c:/") )
testChooseBaseIRI("c:", s->lowercase(s).startsWith("file:///c:/"));
testChooseBaseIRI_windows("c:", "file:///c:");
} else
testChooseBaseIRI("x:/", "x:/");
}

@Test
public void chooseBaseIRI_10() {
testChooseBaseIRI("foo", s->s.startsWith("file:///"));
String x = SysRIOT.chooseBaseIRI(null, "foo");
Assert.assertTrue(x.startsWith("file:///"));
}

private void testChooseBaseIRI(String input, String expected) {
String x = SysRIOT.chooseBaseIRI(null, input);
Assert.assertEquals(expected, x);
}

private void testChooseBaseIRI(String input, Predicate<String> test) {
private void testChooseBaseIRI_windows(String input, String prefix) {
String x = SysRIOT.chooseBaseIRI(null, input);
Assert.assertTrue(test.test(x));
String x1 = lowercase(x);
boolean b = x1.startsWith(prefix);
if ( ! b )
System.out.printf("Input: %s => (prefix(%s) A:%s)=\n", input, prefix, x1);
// drive letters can be uppercase.
Assert.assertTrue(x1.startsWith(prefix));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.io.File ;
import java.nio.file.Path;

import org.apache.jena.base.Sys;
import org.junit.Test ;

public class TestFilenameProcessing
Expand All @@ -37,7 +38,7 @@ public class TestFilenameProcessing
// ---- Main tests.
// Portablility

static boolean isWindows = File.separatorChar != '/' ;
static boolean isWindows = Sys.isWindows;

private static String cwd = Path.of(".").toAbsolutePath().normalize().toString() ;
// Sort out cwd, not using the IRILib code.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@

import org.junit.Test;

/*
* @see TestFilenameProcessing
*/
public class TestIRILib {

@Test public void encodeDecode01() { encodeDecode("", ""); }
Expand Down
4 changes: 3 additions & 1 deletion jena-core/src/main/java/org/apache/jena/irix/IRIs.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,10 @@ public static String toBase(String uriForBase) {
String scheme = scheme(uriForBase);
if ( Sys.isWindows ) {
// Assume a scheme of one letter is a Windows drive letter.
if ( scheme != null && scheme.length() == 1 )
if ( scheme != null && scheme.length() == 1 ) {
scheme = "file";
uriForBase = "file:/"+uriForBase;
}
}
if ( scheme == null ) {
// Relative name: it the base is a file: URI, encode the relative
Expand Down

0 comments on commit 23c4910

Please sign in to comment.