Skip to content

Commit 3f3c7f8

Browse files
authored
Merge pull request #2 from scijava/add-location-resolver
Implement LocationResolver
2 parents 11fdc96 + abe3018 commit 3f3c7f8

File tree

4 files changed

+71
-2
lines changed

4 files changed

+71
-2
lines changed

pom.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<groupId>org.scijava</groupId>
77
<artifactId>pom-scijava</artifactId>
8-
<version>17.1.1</version>
8+
<version>23.0.0</version>
99
<relativePath />
1010
</parent>
1111

@@ -98,7 +98,6 @@
9898
<license.copyrightOwners>KNIME GmbH and Board of Regents of the University
9999
of Wisconsin-Madison.</license.copyrightOwners>
100100

101-
<scijava-common.version>2.65.0</scijava-common.version>
102101
<okhttp.version>3.6.0</okhttp.version>
103102

104103
<!-- NB: Deploy releases to the ImageJ Maven repository. -->

src/main/java/org/scijava/io/http/HTTPLocation.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import java.net.URI;
3535
import java.net.URISyntaxException;
3636
import java.net.URL;
37+
import java.util.List;
3738
import java.util.Objects;
3839

3940
import org.scijava.io.location.AbstractRemoteLocation;
@@ -136,4 +137,13 @@ public HttpUrl getHttpUrl() {
136137
public URI getURI() {
137138
return url.uri();
138139
}
140+
141+
/**
142+
* @return the last path element
143+
*/
144+
@Override
145+
public String getName() {
146+
final List<String> segs = url.pathSegments();
147+
return segs.get(segs.size() - 1);
148+
}
139149
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
2+
package org.scijava.io.http;
3+
4+
import java.net.URI;
5+
import java.net.URISyntaxException;
6+
7+
import org.scijava.io.location.AbstractLocationResolver;
8+
import org.scijava.io.location.Location;
9+
import org.scijava.io.location.LocationResolver;
10+
import org.scijava.plugin.Plugin;
11+
12+
@Plugin(type = LocationResolver.class)
13+
public class HTTPLocationResolver extends AbstractLocationResolver {
14+
15+
public HTTPLocationResolver() {
16+
super("http", "https");
17+
}
18+
19+
@Override
20+
public Location resolve(URI uri) throws URISyntaxException {
21+
return new HTTPLocation(uri);
22+
}
23+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
2+
package org.scijava.io.http;
3+
4+
import static org.junit.Assert.assertEquals;
5+
6+
import java.io.IOException;
7+
import java.net.URISyntaxException;
8+
9+
import org.junit.Test;
10+
import org.scijava.Context;
11+
import org.scijava.io.handle.DataHandleService;
12+
import org.scijava.io.location.Location;
13+
import org.scijava.io.location.LocationService;
14+
15+
public class HTTPLocationResolverTest {
16+
17+
final Context context = new Context();
18+
final DataHandleService dataHandleService = context.service(
19+
DataHandleService.class);
20+
final LocationService resolver = context.service(LocationService.class);
21+
22+
/**
23+
* Tests the location creation with a file located on Github
24+
*
25+
* @throws URISyntaxException
26+
*/
27+
@Test
28+
public void testDataHandleRemote() throws IOException, URISyntaxException {
29+
30+
String url =
31+
"https://github.com/scijava/scijava-io-http/blob/master/src/test/resources/testfile?raw=true";
32+
final Location loc = new HTTPLocation(url);
33+
final Location locResolved = resolver.resolve(url);
34+
35+
assertEquals(loc, locResolved);
36+
}
37+
}

0 commit comments

Comments
 (0)