Skip to content

Commit

Permalink
chore: add platform-test workflow (#74)
Browse files Browse the repository at this point in the history
* chore: add n5-aws-s3, n5-blosc dependencies
* test: fix macro test for windows
* pref: add uri validation
* pref: rm file:// prefix from uri
* test: uri validation
  • Loading branch information
bogovicj authored Apr 29, 2024
1 parent ec9dc25 commit 8533bf8
Show file tree
Hide file tree
Showing 9 changed files with 626 additions and 87 deletions.
44 changes: 44 additions & 0 deletions .github/workflows/platform-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: test

on:
push:
branches:
- master
tags:
- "*-[0-9]+.*"
pull_request:
branches:
- master
workflow_dispatch:

jobs:
build:
strategy:
matrix:
os: [ubuntu-latest, windows-latest]
runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v2
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: '3.10'
- name: Install blosc (Windows)
if: matrix.os == 'windows-latest'
run: |
pip install blosc --no-input --target src/test/resources
mv src/test/resources/bin/* src/test/resources
- name: Install blosc (Ubuntu)
if: matrix.os == 'ubuntu-latest'
run: |
pip install blosc --no-input --target src/test/resources
mv src/test/resources/lib64/* src/test/resources
- name: Set up Java
uses: actions/setup-java@v2
with:
java-version: '8'
distribution: 'zulu'
cache: 'maven'
- name: Maven Test
run: mvn -B clean test --file pom.xml
8 changes: 5 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

<groupId>org.janelia.saalfeldlab</groupId>
<artifactId>n5-ij</artifactId>
<version>4.1.3-SNAPSHOT</version>
<version>4.1.2-SNAPSHOT</version>

<name>N5 ImageJ Bindings</name>
<description>ImageJ convenience layer for N5</description>
Expand Down Expand Up @@ -86,10 +86,12 @@
<releaseProfiles>sign,deploy-to-scijava</releaseProfiles>

<n5.version>3.2.0</n5.version>
<n5-aws-s3.version>4.1.2</n5-aws-s3.version>
<n5-blosc.version>1.1.1</n5-blosc.version>
<n5-google-cloud.version>4.1.0</n5-google-cloud.version>
<n5-hdf5.version>2.2.0</n5-hdf5.version>
<n5-imglib2.version>7.0.0</n5-imglib2.version>
<n5-google-cloud.version>4.1.0</n5-google-cloud.version>
<n5-universe.version>1.4.2</n5-universe.version>
<n5-universe.version>1.4.3-SNAPSHOT</n5-universe.version>
<n5-zarr.version>1.3.1</n5-zarr.version>
<n5-zstandard.version>1.0.2</n5-zstandard.version>
</properties>
Expand Down
52 changes: 49 additions & 3 deletions src/main/java/org/janelia/saalfeldlab/n5/ij/N5Importer.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@

import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
Expand Down Expand Up @@ -62,6 +64,7 @@
import org.janelia.saalfeldlab.n5.universe.N5DatasetDiscoverer;
import org.janelia.saalfeldlab.n5.universe.N5Factory;
import org.janelia.saalfeldlab.n5.universe.N5TreeNode;
import org.janelia.saalfeldlab.n5.universe.N5Factory.StorageFormat;
import org.janelia.saalfeldlab.n5.universe.metadata.N5CosemMetadata;
import org.janelia.saalfeldlab.n5.universe.metadata.N5CosemMetadataParser;
import org.janelia.saalfeldlab.n5.universe.metadata.N5CosemMultiScaleMetadata;
Expand Down Expand Up @@ -108,6 +111,7 @@
import net.imglib2.type.numeric.integer.UnsignedShortType;
import net.imglib2.type.numeric.real.DoubleType;
import net.imglib2.type.numeric.real.FloatType;
import net.imglib2.util.Pair;
import net.imglib2.util.Util;
import net.imglib2.view.Views;

Expand Down Expand Up @@ -855,11 +859,17 @@ public N5Reader apply(final String n5UriOrPath) {
if (n5UriOrPath == null || n5UriOrPath.isEmpty())
return null;


String rootPath = null ;
String rootPath = null;
if (n5UriOrPath.contains("?")) {

try {
rootPath = new N5URI(n5UriOrPath).getContainerPath();
// need to strip off storage format for n5uri to correctly remove query;
final Pair<StorageFormat, URI> fmtUri = N5Factory.StorageFormat.parseUri(n5UriOrPath);
final StorageFormat format = fmtUri.getA();

final N5URI n5uri = from(fmtUri.getB().toString());
// add the format prefix back if it was present
rootPath = format == null ? n5uri.getContainerPath() : format.toString().toLowerCase() + ":" + n5uri.getContainerPath();
} catch (URISyntaxException e) {}
}

Expand All @@ -877,6 +887,42 @@ public N5Reader apply(final String n5UriOrPath) {
}
}

/**
* Generate an {@link N5URI} from a String.
*
* @param uriOrPath
* a string representation of a uri or a path string.
* @return the {@link N5URI}
*/
private static N5URI from(final String uriOrPath) {

try {
return new N5URI(new URI(uriOrPath));
} catch (Throwable ignore) {}

try {
final String[] split = uriOrPath.split("\\?");
final URI tmp = Paths.get(split[0]).toUri();
if (split.length == 1)
return new N5URI(tmp);
else {
StringBuffer buildUri = new StringBuffer();
buildUri.append(tmp.toString());
buildUri.append("?");
for (int i = 1; i < split.length; i++)
buildUri.append(split[i]);

return new N5URI(new URI(buildUri.toString()));
}
} catch (Throwable ignore) {}

try {
return new N5URI(N5URI.encodeAsUri(uriOrPath));
} catch (URISyntaxException e) {
throw new N5Exception(e);
}
}

private static String upToLastExtension(final String path) {

final int i = path.lastIndexOf('.');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1514,9 +1514,6 @@ private static class DetailedOverwriteWarningDialog extends JDialog {
public DetailedOverwriteWarningDialog(final Frame parent, final String root, final String dataset) {
super(parent,"WARNING", true);
initComponents(root, dataset);
final Dimension dims = new Dimension(600, 250);
setSize(dims);
setPreferredSize(dims);
setResizable(false);
setLocationRelativeTo(null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFileChooser;
import javax.swing.JFormattedTextField.AbstractFormatter;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTabbedPane;
import javax.swing.JTextField;
import javax.swing.JTree;
import javax.swing.ScrollPaneConstants;
import javax.swing.SwingUtilities;
Expand All @@ -72,7 +72,11 @@
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.io.File;
import java.net.URI;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.text.Collator;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
Expand Down Expand Up @@ -105,7 +109,7 @@ public class DatasetSelectorDialog {

private JFrame dialog;

private JTextField containerPathText;
private ImprovedFormattedTextField containerPathText;

private JCheckBox virtualBox;

Expand Down Expand Up @@ -366,8 +370,7 @@ private JFrame buildDialog() {
tabs.addTab("Metadata Translation", translationPanel.buildPanel());
tabs.addTab("Translation Result", translationResultPanel.buildPanel());

containerPathText = new JTextField();
containerPathText.setText(initialContainerPath);
containerPathText = new ImprovedFormattedTextField(new UriValidator(), initialContainerPath);
containerPathText.setPreferredSize(new Dimension(frameSizeX / 3, containerPathText.getPreferredSize().height));
containerPathText.addActionListener(e -> openContainer(n5Fun, () -> getN5RootPath(), pathFun));

Expand Down Expand Up @@ -934,4 +937,38 @@ private static boolean pathsEqual(final String a, final String b) {
return normalDatasetName(a, "/").equals(normalDatasetName(b, "/"));
}

protected static class UriValidator extends AbstractFormatter {

private static final long serialVersionUID = 6765664180035018335L;

@Override
public Object stringToValue(String input) throws ParseException {

if (input == null || input.isEmpty())
return null;

try {
final URI uri = new URI(input);
if (uri.isAbsolute())
return uri;
} catch (Throwable ignore) {}

try {
return Paths.get(input).toUri();
} catch (Throwable ignore) {}

throw new ParseException("input " + input + " not a valid URI", 0);
}

@Override
public String valueToString(Object arg) throws ParseException {

if( arg instanceof URI )
return ((URI)arg).toString().replaceFirst("^file://", "");
else
throw new ParseException("input " + arg + " not a valid URI", 0);
}

}

}
Loading

0 comments on commit 8533bf8

Please sign in to comment.