From 126273babd8cb5b23d5018670649e7dffb703093 Mon Sep 17 00:00:00 2001 From: Jean-Marie Burel Date: Sat, 16 Dec 2023 22:57:00 +0000 Subject: [PATCH 1/6] fix test failures on windows --- .../shoola/util/file/TestIOUtil.java | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/test/java/org/openmicroscopy/shoola/util/file/TestIOUtil.java b/src/test/java/org/openmicroscopy/shoola/util/file/TestIOUtil.java index 2c0584fd7..69dc37421 100644 --- a/src/test/java/org/openmicroscopy/shoola/util/file/TestIOUtil.java +++ b/src/test/java/org/openmicroscopy/shoola/util/file/TestIOUtil.java @@ -26,6 +26,7 @@ import java.io.FileOutputStream; import java.io.IOException; +import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.util.zip.ZipEntry; @@ -34,8 +35,6 @@ import org.apache.commons.io.FileUtils; import org.apache.commons.io.FilenameUtils; -import com.google.common.io.Files; - import junit.framework.TestCase; @@ -136,11 +135,12 @@ private void clean(File f) public void testZipDirectory() { try { - File dir = Files.createTempDir(); + final String prefix = "test_ome"; + File dir = Files.createTempDirectory(prefix).toFile(); File f = File.createTempFile("testZipDirectory", ".tmp", dir); File zip = IOUtil.zipDirectory(dir); assertEquals(FilenameUtils.getExtension(zip.getName()), "zip"); - File destDir = Files.createTempDir(); + File destDir = Files.createTempDirectory(prefix).toFile(); boolean b = unzip(zip, destDir); assertEquals(true, b); File[] files = destDir.listFiles(); @@ -159,15 +159,16 @@ public void testZipDirectory() public void testZipDirectoryWithSubfolder() { try { - File dir = Files.createTempDir(); + final String prefix = "test_ome"; + File dir = Files.createTempDirectory(prefix).toFile(); File f = File.createTempFile("testZipDirectoryWithSubfolder", ".tmp", dir); - File subfolder = Files.createTempDir(); + File subfolder = Files.createTempDirectory(prefix).toFile(); File f1 = File.createTempFile("sub_testZipDirectoryWithSubfolder", ".tmp", subfolder); FileUtils.moveDirectoryToDirectory(subfolder, dir, false); File zip = IOUtil.zipDirectory(dir); - File destDir = Files.createTempDir(); + File destDir = Files.createTempDirectory(prefix).toFile(); boolean b = unzip(zip, destDir); assertEquals(true, b); File[] files = destDir.listFiles(); From 642fafb07a64d6d79313b966172d98a55c69cb6f Mon Sep 17 00:00:00 2001 From: Jean-Marie Burel Date: Sat, 16 Dec 2023 23:06:48 +0000 Subject: [PATCH 2/6] use java.nio.file.Files instead of com.google.common.io.Files --- .../shoola/agents/fsimporter/view/ImporterModel.java | 6 +++--- .../shoola/env/data/views/calls/ArchivedImageLoader.java | 7 ++++--- .../shoola/env/data/views/calls/FileUploader.java | 4 ++-- .../shoola/env/data/views/calls/ResultsSaver.java | 5 +++-- 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/main/java/org/openmicroscopy/shoola/agents/fsimporter/view/ImporterModel.java b/src/main/java/org/openmicroscopy/shoola/agents/fsimporter/view/ImporterModel.java index 0f1f4435c..668d59087 100644 --- a/src/main/java/org/openmicroscopy/shoola/agents/fsimporter/view/ImporterModel.java +++ b/src/main/java/org/openmicroscopy/shoola/agents/fsimporter/view/ImporterModel.java @@ -24,6 +24,7 @@ import java.io.File; import java.text.SimpleDateFormat; +import java.nio.file.Files; import java.util.Collection; import java.util.Date; import java.util.HashMap; @@ -62,8 +63,6 @@ import org.openmicroscopy.shoola.util.CommonsLangUtils; import org.openmicroscopy.shoola.util.roi.io.ROIReader; -import com.google.common.io.Files; - import omero.gateway.model.DataObject; import omero.gateway.model.ExperimenterData; import omero.gateway.model.FileAnnotationData; @@ -731,7 +730,8 @@ component, ctx, new FileAnnotationData(f), */ private File createFile(String imageName) { - File dir = Files.createTempDir(); + final String prefix = "ome_"; + File dir = Files.createTempDirectory(prefix).toFile(); String name; String fileName = null; if (object != null) { diff --git a/src/main/java/org/openmicroscopy/shoola/env/data/views/calls/ArchivedImageLoader.java b/src/main/java/org/openmicroscopy/shoola/env/data/views/calls/ArchivedImageLoader.java index 7debb655d..873e59ec5 100644 --- a/src/main/java/org/openmicroscopy/shoola/env/data/views/calls/ArchivedImageLoader.java +++ b/src/main/java/org/openmicroscopy/shoola/env/data/views/calls/ArchivedImageLoader.java @@ -30,7 +30,8 @@ import java.util.List; import java.util.Map; -import com.google.common.io.Files; +import java.nio.file.Files; + import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.io.FileUtils; import org.apache.commons.io.FilenameUtils; @@ -158,8 +159,8 @@ public void doCall() throws Exception File tmpFolder = null; try { - if(zip) - tmpFolder = Files.createTempDir(); + if (zip) + tmpFolder = Files.createTempDirectory("ome_").toFile(); else tmpFolder = folder; diff --git a/src/main/java/org/openmicroscopy/shoola/env/data/views/calls/FileUploader.java b/src/main/java/org/openmicroscopy/shoola/env/data/views/calls/FileUploader.java index 984ae0ee3..12c5cec0c 100644 --- a/src/main/java/org/openmicroscopy/shoola/env/data/views/calls/FileUploader.java +++ b/src/main/java/org/openmicroscopy/shoola/env/data/views/calls/FileUploader.java @@ -30,7 +30,7 @@ import org.apache.commons.io.FileUtils; import org.apache.commons.io.FilenameUtils; -import com.google.common.io.Files; +import java.nio.file.Files; import org.openmicroscopy.shoola.env.LookupNames; import org.openmicroscopy.shoola.env.data.OmeroMetadataService; @@ -126,7 +126,7 @@ private void uploadFile(ImportErrorObject object) } } if (b || id > 0) { - directory = Files.createTempDir(); + directory = Files.createTempDirectory("ome_").toFile(); //Add the file to the directory. if (f != null) { directory = new File(directory.getParentFile(), diff --git a/src/main/java/org/openmicroscopy/shoola/env/data/views/calls/ResultsSaver.java b/src/main/java/org/openmicroscopy/shoola/env/data/views/calls/ResultsSaver.java index 4284f165d..fc5d42124 100644 --- a/src/main/java/org/openmicroscopy/shoola/env/data/views/calls/ResultsSaver.java +++ b/src/main/java/org/openmicroscopy/shoola/env/data/views/calls/ResultsSaver.java @@ -24,6 +24,7 @@ import ij.ImagePlus; import java.io.File; +import java.nio.file.Files; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Iterator; @@ -41,7 +42,7 @@ import org.openmicroscopy.shoola.util.CommonsLangUtils; import org.openmicroscopy.shoola.util.roi.io.ROIReader; -import com.google.common.io.Files; + import omero.gateway.model.ExperimenterData; import omero.gateway.model.FileAnnotationData; @@ -83,7 +84,7 @@ public class ResultsSaver */ private File createFile(ImagePlus img, String fileName) { - File dir = Files.createTempDir(); + File dir = Files.createTempDirectory("ome_").toFile(); String name; if (CommonsLangUtils.isBlank(fileName)) { name = "ImageJ-"+FilenameUtils.getBaseName( From af270911e77248b31f3630d7bcd28e91ecacc41e Mon Sep 17 00:00:00 2001 From: Jean-Marie Burel Date: Sun, 17 Dec 2023 09:23:30 +0000 Subject: [PATCH 3/6] catch exception --- .../agents/fsimporter/view/ImporterModel.java | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/main/java/org/openmicroscopy/shoola/agents/fsimporter/view/ImporterModel.java b/src/main/java/org/openmicroscopy/shoola/agents/fsimporter/view/ImporterModel.java index 668d59087..ec6152af2 100644 --- a/src/main/java/org/openmicroscopy/shoola/agents/fsimporter/view/ImporterModel.java +++ b/src/main/java/org/openmicroscopy/shoola/agents/fsimporter/view/ImporterModel.java @@ -730,23 +730,23 @@ component, ctx, new FileAnnotationData(f), */ private File createFile(String imageName) { - final String prefix = "ome_"; - File dir = Files.createTempDirectory(prefix).toFile(); - String name; - String fileName = null; - if (object != null) { - fileName = object.getTableName(); - } - if (CommonsLangUtils.isBlank(fileName)) { - name = "ImageJ-"+FilenameUtils.getBaseName( + try { + final String prefix = "ome_"; + File dir = Files.createTempDirectory(prefix).toFile(); + String name; + String fileName = null; + if (object != null) { + fileName = object.getTableName(); + } + if (CommonsLangUtils.isBlank(fileName)) { + name = "ImageJ-"+FilenameUtils.getBaseName( FilenameUtils.removeExtension(imageName))+"-Results-"; - name += new SimpleDateFormat("yyyy-MM-dd").format(new Date()); - } else { - name = FilenameUtils.removeExtension(fileName); - } + name += new SimpleDateFormat("yyyy-MM-dd").format(new Date()); + } else { + name = FilenameUtils.removeExtension(fileName); + } - name += ".csv"; - try { + name += ".csv"; File f = new File(dir, name); //read data ROIReader reader = new ROIReader(); From 331e261e37ed9458579ca8051934b4ba4abb9f8d Mon Sep 17 00:00:00 2001 From: Jean-Marie Burel Date: Sun, 17 Dec 2023 09:23:38 +0000 Subject: [PATCH 4/6] add option --- .../shoola/env/data/views/calls/ArchivedImageLoader.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/openmicroscopy/shoola/env/data/views/calls/ArchivedImageLoader.java b/src/main/java/org/openmicroscopy/shoola/env/data/views/calls/ArchivedImageLoader.java index 873e59ec5..c2ad605b2 100644 --- a/src/main/java/org/openmicroscopy/shoola/env/data/views/calls/ArchivedImageLoader.java +++ b/src/main/java/org/openmicroscopy/shoola/env/data/views/calls/ArchivedImageLoader.java @@ -31,6 +31,7 @@ import java.util.Map; import java.nio.file.Files; +import static java.nio.file.StandardCopyOption.REPLACE_EXISTING; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.io.FileUtils; @@ -174,7 +175,7 @@ public void doCall() throws Exception result = new HashMap>(); - if(CollectionUtils.isEmpty(files)) + if (CollectionUtils.isEmpty(files)) return; if (zip) { @@ -186,7 +187,7 @@ public void doCall() throws Exception File to = new File(f.getParentFile(), baseName + "." + FilenameUtils.getExtension(f.getName())); - Files.move(f, to); + Files.move(f, to, REPLACE_EXISTING); f = copyFile(to, folder.getParentFile()); ((Map>)result).put(Boolean.TRUE, Arrays.asList(f)); } From 92d9d8c52fe46374157c2aef52fe1693805e8699 Mon Sep 17 00:00:00 2001 From: Jean-Marie Burel Date: Sun, 17 Dec 2023 09:30:50 +0000 Subject: [PATCH 5/6] convert to Path --- .../shoola/env/data/views/calls/ArchivedImageLoader.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/openmicroscopy/shoola/env/data/views/calls/ArchivedImageLoader.java b/src/main/java/org/openmicroscopy/shoola/env/data/views/calls/ArchivedImageLoader.java index c2ad605b2..7c659ee40 100644 --- a/src/main/java/org/openmicroscopy/shoola/env/data/views/calls/ArchivedImageLoader.java +++ b/src/main/java/org/openmicroscopy/shoola/env/data/views/calls/ArchivedImageLoader.java @@ -187,7 +187,7 @@ public void doCall() throws Exception File to = new File(f.getParentFile(), baseName + "." + FilenameUtils.getExtension(f.getName())); - Files.move(f, to, REPLACE_EXISTING); + Files.move(f.toPath(), to.toPath(), REPLACE_EXISTING); f = copyFile(to, folder.getParentFile()); ((Map>)result).put(Boolean.TRUE, Arrays.asList(f)); } From c5ec3717abad53acfbd40ffb81f19c88d9267ce7 Mon Sep 17 00:00:00 2001 From: Jean-Marie Burel Date: Sun, 17 Dec 2023 18:23:06 +0000 Subject: [PATCH 6/6] handle exception --- .../env/data/views/calls/ResultsSaver.java | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/main/java/org/openmicroscopy/shoola/env/data/views/calls/ResultsSaver.java b/src/main/java/org/openmicroscopy/shoola/env/data/views/calls/ResultsSaver.java index fc5d42124..962478740 100644 --- a/src/main/java/org/openmicroscopy/shoola/env/data/views/calls/ResultsSaver.java +++ b/src/main/java/org/openmicroscopy/shoola/env/data/views/calls/ResultsSaver.java @@ -84,17 +84,17 @@ public class ResultsSaver */ private File createFile(ImagePlus img, String fileName) { - File dir = Files.createTempDirectory("ome_").toFile(); - String name; - if (CommonsLangUtils.isBlank(fileName)) { - name = "ImageJ-"+FilenameUtils.getBaseName( - FilenameUtils.removeExtension(img.getTitle()))+"-Results-"; - name += new SimpleDateFormat("yyyy-MM-dd").format(new Date()); - } else { - name = FilenameUtils.removeExtension(fileName); - } - name += ".csv"; try { + File dir = Files.createTempDirectory("ome_").toFile(); + String name; + if (CommonsLangUtils.isBlank(fileName)) { + name = "ImageJ-"+FilenameUtils.getBaseName( + FilenameUtils.removeExtension(img.getTitle()))+"-Results-"; + name += new SimpleDateFormat("yyyy-MM-dd").format(new Date()); + } else { + name = FilenameUtils.removeExtension(fileName); + } + name += ".csv"; File f = new File(dir, name); //read data ROIReader reader = new ROIReader();