Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove apache commons io #437

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ repositories {
mavenCentral()
}

configurations.all {
exclude group: 'commons-io'
}

java {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
//Java imports
import java.awt.Color;
import java.awt.Component;
import java.nio.file.Paths;
import javax.swing.Icon;
import javax.swing.JTable;
import javax.swing.SwingConstants;
Expand All @@ -35,7 +36,6 @@
//Third-party libraries

//Application-internal dependencies
import org.apache.commons.io.FilenameUtils;
import org.openmicroscopy.shoola.util.ui.UIUtilities;

/**
Expand Down Expand Up @@ -107,7 +107,7 @@ public Component getTableCellRendererComponent(JTable table, Object value,
setText(v.substring(0, MAX_CHARACTERS));
else setText(v);
} else {
setText(FilenameUtils.getName(v));
setText(Paths.get(v).getFileName().toString());
}
}
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@
import omero.cmd.CmdCallbackI;

import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.io.FileUtils;
import org.jdesktop.swingx.JXBusyLabel;
import org.jdesktop.swingx.JXTaskPane;
import org.openmicroscopy.shoola.agents.events.importer.BrowseContainer;
Expand All @@ -80,6 +79,7 @@
import org.openmicroscopy.shoola.env.data.util.Status;
import org.openmicroscopy.shoola.env.data.util.StatusLabel;
import org.openmicroscopy.shoola.env.event.EventBus;
import org.openmicroscopy.shoola.util.file.IOUtil;
import org.openmicroscopy.shoola.util.file.ImportErrorObject;
import org.openmicroscopy.shoola.util.ui.UIUtilities;

Expand Down Expand Up @@ -363,7 +363,7 @@ private void formatResultTooltip()
}
}
buf.append("<b>Size: </b>");
buf.append(FileUtils.byteCountToDisplaySize(status.getSizeUpload()));
buf.append(IOUtil.byteCountToDisplaySize(status.getSizeUpload()));
buf.append("<br>");
buf.append("<b>Group: </b>");
buf.append(importable.getGroup().getName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,12 @@
*/
package org.openmicroscopy.shoola.agents.fsimporter.view;

import com.google.common.io.MoreFiles;
import ij.ImagePlus;

import java.io.File;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.text.SimpleDateFormat;
import java.nio.file.Files;
import java.util.Collection;
Expand All @@ -39,7 +42,6 @@
import omero.model.ImageI;

import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.io.FilenameUtils;
import org.openmicroscopy.shoola.agents.fsimporter.AnnotationDataLoader;
import org.openmicroscopy.shoola.agents.fsimporter.DataLoader;
import org.openmicroscopy.shoola.agents.fsimporter.DataObjectCreator;
Expand Down Expand Up @@ -203,7 +205,7 @@ private GroupData getGroup(long groupId)
/**
* Creates a new instance.
*
* @param groupID The id to the group selected for the current user.
* @param groupId The id to the group selected for the current user.
* @param displayMode Group/Experimenter view.
*/
ImporterModel(long groupId, int displayMode)
Expand All @@ -214,7 +216,7 @@ private GroupData getGroup(long groupId)
/**
* Creates a new instance.
*
* @param groupID The id to the group selected for the current user.
* @param groupId The id to the group selected for the current user.
* @param master Pass <code>true</code> if the importer is used a stand-alone
* application, <code>false</code> otherwise.
* @param displayMode Group/Experimenter view.
Expand Down Expand Up @@ -381,7 +383,7 @@ void importCompleted(int loaderID)
/**
* Sets the collection of the existing tags.
*
* @param The value to set.
* @param tags The value to set.
*/
void setTags(Collection tags)
{
Expand Down Expand Up @@ -739,11 +741,11 @@ private File createFile(String imageName)
fileName = object.getTableName();
}
if (CommonsLangUtils.isBlank(fileName)) {
name = "ImageJ-"+FilenameUtils.getBaseName(
FilenameUtils.removeExtension(imageName))+"-Results-";
Path baseName = Paths.get(imageName).getFileName();
name = "ImageJ-"+MoreFiles.getNameWithoutExtension(baseName)+"-Results-";
name += new SimpleDateFormat("yyyy-MM-dd").format(new Date());
} else {
name = FilenameUtils.removeExtension(fileName);
name = MoreFiles.getNameWithoutExtension(Paths.get(fileName));
}

name += ".csv";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@
import omero.gateway.model.TagAnnotationData;

import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.io.FileUtils;
import org.jdesktop.swingx.JXBusyLabel;
import org.openmicroscopy.shoola.agents.fsimporter.IconManager;
import org.openmicroscopy.shoola.agents.fsimporter.ImporterAgent;
Expand All @@ -75,6 +74,7 @@
import org.openmicroscopy.shoola.env.data.model.ImportableObject;
import org.openmicroscopy.shoola.env.ui.UserNotifier;
import org.openmicroscopy.shoola.util.CommonsLangUtils;
import org.openmicroscopy.shoola.util.file.IOUtil;
import org.openmicroscopy.shoola.util.file.ImportErrorObject;
import org.openmicroscopy.shoola.util.ui.ClosableTabbedPaneComponent;
import org.openmicroscopy.shoola.util.ui.RotationIcon;
Expand Down Expand Up @@ -517,7 +517,7 @@ void setNumberOfImport()
JPanel buildHeader()
{
sizeLabel = UIUtilities.createComponent(null);
sizeLabel.setText(FileUtils.byteCountToDisplaySize(sizeImport));
sizeLabel.setText(IOUtil.byteCountToDisplaySize(sizeImport));
reportLabel = UIUtilities.setTextFont("Report:", Font.BOLD);
importSizeLabel = UIUtilities.setTextFont("Import Size:", Font.BOLD);

Expand Down Expand Up @@ -638,7 +638,7 @@ Object uploadComplete(FileImportComponentI c, Object result) {
if (file.isFile()) {
countUploaded++;
sizeImport += c.getImportSize();
sizeLabel.setText(FileUtils.byteCountToDisplaySize(sizeImport));
sizeLabel.setText(IOUtil.byteCountToDisplaySize(sizeImport));
// handle error that occurred during the scanning or upload.
// Check that the result has not been set.
// if (!c.hasResult()) {
Expand Down Expand Up @@ -718,7 +718,7 @@ void setImportResult(FileImportComponentI fc, Object result) {
if (fc.hasUploadFailed()) {
countUploadFailure++;
sizeImport -= fc.getImportSize();
sizeLabel.setText(FileUtils.byteCountToDisplaySize(sizeImport));
sizeLabel.setText(IOUtil.byteCountToDisplaySize(sizeImport));
}
if (fc.hasImportFailed())
countFailure++;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,14 @@
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Iterator;
import java.util.List;
import java.util.regex.Pattern;
import javax.swing.JDialog;
import javax.swing.JFrame;

import org.apache.commons.io.FileUtils;
import org.openmicroscopy.shoola.agents.imviewer.ImViewerAgent;
import org.openmicroscopy.shoola.agents.imviewer.util.ImagePaintingFactory;
import org.openmicroscopy.shoola.agents.imviewer.view.ImViewer;
Expand Down Expand Up @@ -486,7 +487,7 @@ void saveImage(boolean init)
String name = uiDelegate.getSelectedFilePath();

// make sure the parent directory paths all exist
FileUtils.forceMkdir(new File(name).getParentFile());
Files.createDirectories(Paths.get(new File(name).getParentFile().toURI()));

if (imageComponents == null) {
if (mainImage == null) return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import java.awt.Rectangle;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
Expand All @@ -38,13 +39,13 @@
import java.util.List;
import java.util.Map;

import com.google.common.io.MoreFiles;
import omero.model.Length;
import omero.model.LengthI;
import omero.model.PlaneInfo;
import omero.model.enums.UnitsLength;
import omero.romio.PlaneDef;

import org.apache.commons.io.FilenameUtils;
import org.openmicroscopy.shoola.agents.events.iviewer.CopyRndSettings;
import org.openmicroscopy.shoola.agents.imviewer.AcquisitionDataLoader;
import org.openmicroscopy.shoola.agents.imviewer.BirdEyeLoader;
Expand Down Expand Up @@ -2199,7 +2200,7 @@ void fireImageProjection(int startZ, int endZ, int stepping, int type,
* @return See above.
*/
private String combineFilenameWith(String projectName, String imageName) {
String extension = FilenameUtils.getExtension(imageName);
String extension = MoreFiles.getFileExtension(Paths.get(imageName));

StringBuilder nameBuilder = new StringBuilder();
nameBuilder.append(projectName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedHashMap;
Expand All @@ -49,8 +50,8 @@
import javax.swing.JToolBar;
import javax.swing.table.DefaultTableModel;

import com.google.common.io.MoreFiles;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.io.FilenameUtils;
import org.openmicroscopy.shoola.util.CommonsLangUtils;
import org.jdesktop.swingx.JXBusyLabel;
import org.jdesktop.swingx.JXTable;
Expand Down Expand Up @@ -121,7 +122,7 @@ private void download()
if (data != null) name = data.getFileName();
else {
ImageData img = model.getImage();
name = FilenameUtils.removeExtension(img.getName());
name = MoreFiles.getNameWithoutExtension(Paths.get(img.getName()));
}
chooser.setSelectedFileFull(name);
chooser.setApproveButtonText("Download");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeListenerProxy;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
Expand Down Expand Up @@ -69,7 +70,6 @@
import javax.swing.border.BevelBorder;

import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.io.FilenameUtils;
import org.jdesktop.swingx.JXBusyLabel;
import org.openmicroscopy.shoola.agents.treeviewer.IconManager;
import org.openmicroscopy.shoola.agents.treeviewer.TreeViewerAgent;
Expand Down Expand Up @@ -1015,7 +1015,7 @@ public void actionPerformed(ActionEvent e) {
value = "";
path = so.getPath();
if (path != null && path.length() > 1) {
sep = FilenameUtils.getPrefix(path);
sep = Paths.get(path).getRoot().toString();
if (path.startsWith(sep))
path = path.substring(1, path.length());
values = UIUtilities.splitString(path);
Expand All @@ -1036,7 +1036,7 @@ public void actionPerformed(ActionEvent e) {
so = i.next();
path = so.getPath();
if (path != null) {
sep = FilenameUtils.getPrefix(path);
sep = Paths.get(path).getRoot().toString();
if (path.startsWith(sep))
path = path.substring(1, path.length());
values = UIUtilities.splitString(path);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
Expand All @@ -42,7 +43,6 @@
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

import org.apache.commons.io.FilenameUtils;
import org.openmicroscopy.shoola.agents.events.SaveData;
import org.openmicroscopy.shoola.agents.treeviewer.TreeViewerAgent;
import org.openmicroscopy.shoola.env.Agent;
Expand Down Expand Up @@ -442,7 +442,7 @@ private void readExternalApplications()

Environment env = (Environment)
TreeViewerAgent.getRegistry().lookup(LookupNames.ENV);
String name = FilenameUtils.concat(env.getOmeroHome(),FILE_NAME);
String name = Paths.get(env.getOmeroHome(), FILE_NAME).toString();

File f = new File(name);
if (!f.exists()) return;
Expand Down
20 changes: 11 additions & 9 deletions src/main/java/org/openmicroscopy/shoola/env/Container.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@
package org.openmicroscopy.shoola.env;

import java.io.File;
import java.nio.file.Paths;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;

import org.apache.commons.io.FilenameUtils;
import com.google.common.io.MoreFiles;
import org.openmicroscopy.shoola.util.CommonsLangUtils;
import org.openmicroscopy.shoola.env.config.AgentInfo;
import org.openmicroscopy.shoola.env.config.Registry;
Expand Down Expand Up @@ -247,12 +248,13 @@ private Container(String home, String configFile, String pluginDir)
private Container(String home, String configFile, String pluginDir, List<String> cmdLineArgs)
throws StartupException
{
if (CommonsLangUtils.isBlank(configFile) || !FilenameUtils.isExtension(configFile, "xml")) {
if (CommonsLangUtils.isBlank(configFile) ||
!MoreFiles.getFileExtension(Paths.get(configFile)).toLowerCase().equals("xml")) {
configFile = CONFIG_FILE;
}
this.configFile = configFile;

if (CommonsLangUtils.isBlank(FilenameUtils.getPath(home))) {
if (CommonsLangUtils.isBlank(home)) {
home = System.getProperty("user.dir");
}
File f = new File(home);
Expand Down Expand Up @@ -465,7 +467,7 @@ public void exit()
* plug-in. Those plug-in will have an UI entry.
* @param pluginDir Path to the plugin directory. Used in plugin mode only.
* @return A reference to the newly created singleton Container.
* @throws Throws a startup exception if the application cannot be used as
* @throws StartupException Throws a startup exception if the application cannot be used as
* a plugin due to missing dependencies.
*/
public static Container startupInPluginMode(String home, String configFile,
Expand Down Expand Up @@ -493,7 +495,7 @@ public static Container startupInPluginMode(String home, String configFile,
* @param plugin Pass positive value. See {@link LookupNames} for supported
* plug-in. Those plug-in will have an UI entry.
* @return A reference to the newly created singleton Container.
* @throws Throws a startup exception if the application cannot be used as
* @throws StartupException Throws a startup exception if the application cannot be used as
* a plugin due to missing dependencies.
*/
public static Container startupInPluginMode(String home, String configFile,
Expand Down Expand Up @@ -522,7 +524,7 @@ public static Container startupInPluginMode(String home, String configFile,
* plug-in. Those plug-in will have an UI entry.
* @param listener Listens to <code>ConnectedEvent</code>.
* @return A reference to the newly created singleton Container.
* @throws Throws a startup exception if the application cannot be used as
* @throws StartupException Throws a startup exception if the application cannot be used as
* a plugin due to missing dependencies.
*/
public static Container startupInPluginMode(String home, String configFile,
Expand Down Expand Up @@ -552,7 +554,7 @@ public static Container startupInPluginMode(String home, String configFile,
* plug-in. Those plug-in will have an UI entry.
* @param listener Listens to <code>ConnectedEvent</code>.
* @return A reference to the newly created singleton Container.
* @throws Throws a startup exception if the application cannot be used as
* @throws StartupException Throws a startup exception if the application cannot be used as
* a plugin due to missing dependencies.
*/
public static Container startupInPluginMode(String home, String configFile,
Expand Down Expand Up @@ -637,7 +639,7 @@ public static Container startupInPluginMode(String home, String configFile,
* @param plugin Pass positive value. See {@link LookupNames} for supported
* plug-in. Those plug-in will have an UI entry.
* @return A reference to the newly created singleton Container.
* @throws Throws a startup exception if the application cannot be used as
* @throws StartupException Throws a startup exception if the application cannot be used as
* a plugin due to missing dependencies.
*/
public static Container startupInHeadlessMode(String home,
Expand Down Expand Up @@ -695,7 +697,7 @@ public void eventFired(AgentEvent e) {
* empty, then the user directory is assumed.
* @param configFile The configuration file.
* @return A reference to the newly created singleton Container.
* @throws Throws a startup exception if the application cannot be used as
* @throws StartupException Throws a startup exception if the application cannot be used as
* a plugin due to missing dependencies.
*/
public static Container startupInHeadlessMode(String home, String configFile
Expand Down
Loading
Loading