Skip to content

Commit

Permalink
Merge pull request #23 from saalfeldlab/feat/refactorTests
Browse files Browse the repository at this point in the history
Feat/refactor tests
  • Loading branch information
bogovicj authored Mar 5, 2024
2 parents bc13c09 + 66ce01b commit 4fcb020
Show file tree
Hide file tree
Showing 18 changed files with 561 additions and 764 deletions.
49 changes: 33 additions & 16 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
<parent>
<groupId>org.scijava</groupId>
<artifactId>pom-scijava</artifactId>
<version>36.0.0</version>
<version>37.0.0</version>
<relativePath />
</parent>

<groupId>org.janelia.saalfeldlab</groupId>
<artifactId>n5-google-cloud</artifactId>
<version>4.0.1-SNAPSHOT</version>
<version>4.1.0-SNAPSHOT</version>

<name>N5 Google Cloud</name>
<description>N5 library implementation using Google Cloud Storage backend.</description>
Expand Down Expand Up @@ -123,7 +123,7 @@
<!-- NB: Deploy releases to the SciJava Maven repository. -->
<releaseProfiles>sign,deploy-to-scijava</releaseProfiles>

<n5.version>3.0.2</n5.version>
<n5.version>3.2.0</n5.version>
</properties>

<dependencies>
Expand Down Expand Up @@ -168,18 +168,35 @@
</repositories>

<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<excludes>
<exclude>org.janelia.saalfeldlab.n5.googlecloud.backend.**</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<excludes>
<exclude>org.janelia.saalfeldlab.n5.googlecloud.backend.**</exclude>
<exclude>org.janelia.saalfeldlab.n5.googlecloud.N5GoogleCloudStorageTests.java</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>

<profiles>
<profile>
<id>run-backend-tests</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<excludes combine.self="override"/>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public class GoogleCloudStorageURI
private static final String storagePathPrefix = "/storage/v1/b/";
private static final String projectKey = "project";

private final URI uri;
private final String bucketName;
private final String objectKey;
private final String query;
Expand All @@ -54,8 +55,9 @@ public GoogleCloudStorageURI( final String str )

public GoogleCloudStorageURI( final URI uri )
{
this.uri = uri;
final String path;
if ( uri.getScheme().equalsIgnoreCase( "gs" ) )
if ( uri.getScheme() != null && uri.getScheme().equalsIgnoreCase( "gs" ) )
{
bucketName = uri.getAuthority();
objectKey = uri.getPath();
Expand Down Expand Up @@ -103,6 +105,10 @@ public String getBucket()
return bucketName;
}

public URI asURI() {
return this.uri;
}

public String getKey()
{
return objectKey;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package org.janelia.saalfeldlab.googlecloud;

import com.google.cloud.storage.Storage;
import com.google.cloud.storage.StorageOptions;

import javax.annotation.Nullable;
import java.net.URI;
import java.util.regex.Pattern;

public class GoogleCloudUtils {

public final static Pattern GS_SCHEME = Pattern.compile("gs", Pattern.CASE_INSENSITIVE);
public final static Pattern GS_HOST = Pattern.compile("(cloud\\.google|storage\\.googleapis)\\.com", Pattern.CASE_INSENSITIVE);

private GoogleCloudUtils() {

}

public static String getGoogleCloudStorageKey(String uri) {

return getGoogleCloudStorageKey(URI.create(uri));
}

public static String getGoogleCloudStorageKey(URI uri) {

try {
// if key is null, return the empty string
final String key = new GoogleCloudStorageURI(uri).getKey();
return key == null ? "" : key;
} catch (final Exception e) {
}
// parse key manually when GoogleCLoudStorageURI can't
final String path = uri.getPath().replaceFirst("^/", "");
return path.substring(path.indexOf('/') + 1);
}

public static Storage createGoogleCloudStorage(@Nullable final String googleCloudProjectId) {

final GoogleCloudStorageClient storageClient = getGoogleCloudStorageClient(googleCloudProjectId);
if (storageClient == null)
return null;

return storageClient.create();
}

public static GoogleCloudStorageClient getGoogleCloudStorageClient(@Nullable final String googleCloudProjectId) {

return new GoogleCloudStorageClient(googleCloudProjectId != null ? googleCloudProjectId :
StorageOptions.getDefaultProjectId());

}
}
Loading

0 comments on commit 4fcb020

Please sign in to comment.