Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Move Java class path checking into a separate function for reusability

- Check explicitly for loci_tools.jar in the java class path and return a boolean
- Use javaaddpath only if no loci_tools is found in the path
  • Loading branch information...
commit 5d6406289b9ce6f12601e547a672076287406eac 1 parent 1ff9f6b
@sbesson authored
View
40 components/bio-formats/utils/bfCheckJavaPath.m
@@ -0,0 +1,40 @@
+function status = bfCheckJavaPath(varargin)
+% bfCheckJavaPath check Bio-Formats is included in the Java class path
+%
+% SYNOPSIS bfCheckJavaPath
+% status = bfCheckJavaPath(autoloadBioFormats)
+%
+% Input
+%
+% autoloadBioFormats - Optional. A boolean specifying the action to take
+% if loci_tools is not in the java path. If true, add loci_tools to the
+% dynamic java path. Default - true
+%
+% Output
+%
+% status - Boolean. True if loci_tools is part of the Java library.
+
+% Input check
+ip=inputParser;
+ip.addOptional('autoloadBioFormats',true,@isscalar);
+ip.parse(varargin{:});
+
+% Check if loci_tools is in the Java class path (static or dynamic)
+jPath = javaclasspath('-all');
+isLociTools = cellfun(@(x) ~isempty(regexp(x,'.*loci_tools.jar$','once')),...
+ jPath);
+status = any(isLociTools);
+
+% Return if loci_tools is in the java path or autoloadBioFormats is off
+if status || ~ip.Results.autoloadBioFormats, return; end
+
+% Assume the jar is in Matlab path or under the same folder as this file
+path =which('loci_tools.jar');
+if isempty(path)
+ path = fullfile(fileparts(mfilename('fullpath')), 'loci_tools.jar');
+end
+assert(~isempty(path),'Cannot automatically locate loci_tools.jar');
+
+% Add loci_tools to dynamic Java class path
+javaaddpath(path);
+status = true;
View
11 components/bio-formats/utils/bfGetReader.m
@@ -1,11 +1,11 @@
function r = bfGetReader(id,varargin)
-% Get the reader associated with a given dataset using Bio-Formats
+% bfGetReader get a reader for a microscopy image using Bio-Formats
%
% SYNOPSIS r=bfGetReader(path)
%
% Input
%
-% id - the path of a proprietary file
+% id - the path to the microscopy image
%
% stichFiles - Optional. Toggle the grouping of similarly
% named files into a single dataset based on file numbering.
@@ -13,7 +13,7 @@
%
% Output
%
-% r - object of class loci.formats.ChannelSeparator
+% r - a reader object of class extending loci.formats.ReaderWrapper
%
% Adapted from bfopen.m
@@ -30,6 +30,11 @@
java.lang.System.setProperty('lurawave.license', lurawaveLicense);
end
+% Check Bio-Formats is in the Java path
+status = bfCheckJavaPath();
+assert(status,['Missing Bio-Formats library. Either add loci_tools.jar '...
+ 'to the static Java path or add it to the Matlab path.']);
+
r = loci.formats.ChannelFiller();
r = loci.formats.ChannelSeparator(r);
if ip.Results.stitchFiles
View
10 components/bio-formats/utils/bfopen.m
@@ -98,13 +98,9 @@
% -- Main function - no need to edit anything past this point --
% load the Bio-Formats library into the MATLAB environment
-if autoloadBioFormats
- path =which('loci_tools.jar');
- if isempty(path)
- path = fullfile(fileparts(mfilename('fullpath')), 'loci_tools.jar');
- end
- javaaddpath(path);
-end
+status = bfCheckJavaPath(autoloadBioFormats);
+assert(status,['Missing Bio-Formats library. Either add loci_tools.jar '...
+ 'to the static Java path or add it to the Matlab path.']);
% Prompt for a file if not input
if exist('id','file') == 0
Please sign in to comment.
Something went wrong with that request. Please try again.