Skip to content

Commit 22b13f6

Browse files
authored
Added checks for non-exisiting files in classpath converters. (#21)
2 parents 1695f11 + 2f63fcb commit 22b13f6

4 files changed

Lines changed: 32 additions & 11 deletions

File tree

.gitattributes

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
* text eol=lf
2+
*.png binary
3+
*.jar binary

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
language: java
22
jdk:
3-
- oraclejdk8
3+
- openjdk8
44
script: "./.ci/ci.sh"
55
before_cache:
66
- rm -f $HOME/.gradle/caches/modules-2/modules-2.lock

CHANGES.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
### Version 4.6.0-SNAPSHOT - TBD ([javadoc](http://diffplug.github.io/matconsolectl/javadoc/snapshot/), [jcenter](https://oss.sonatype.org/content/repositories/snapshots/com/diffplug/matsim/matconsolectl/))
44

5+
- Added checks for directories and non-exisiting files in classpath converters: In Configuration.getClassPathAsRMICodebase() and Configuration.getClassPathAsCanonicalPaths(). This prevents unnecessary IOExceptions for invalid classpaths.
6+
- https://github.com/diffplug/matconsolectl/pull/21
7+
58
### Version 4.5.0 - July 18th 2017 ([javadoc](http://diffplug.github.io/matconsolectl/javadoc/4.5.0/), [jcenter](https://bintray.com/diffplug/opensource/matconsolectl/4.5.0/view))
69

710
- Added `Builder.setOutputWriter` and `Builder.setErrorWriter` for capturing `stdout` and `stderr` from MATLAB. ([#20](https://github.com/diffplug/matconsolectl/pull/20))

src/matlabcontrol/Configuration.java

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import java.net.URL;
1313
import java.security.CodeSource;
1414
import java.security.ProtectionDomain;
15+
import java.util.logging.Logger;
1516

1617
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
1718

@@ -23,12 +24,15 @@
2324
* @author <a href="mailto:nonother@gmail.com">Joshua Kaplan</a>
2425
*/
2526
class Configuration {
27+
28+
private static Logger sLog = Logger.getLogger(Configuration.class.getName());
29+
2630
private Configuration() {}
2731

2832
/**
2933
* If running on OS X.
3034
*
31-
* @return
35+
* @return
3236
*/
3337
static boolean isOSX() {
3438
return getOperatingSystem().startsWith("Mac OS X");
@@ -37,7 +41,7 @@ static boolean isOSX() {
3741
/**
3842
* If running on Windows.
3943
*
40-
* @return
44+
* @return
4145
*/
4246
static boolean isWindows() {
4347
return getOperatingSystem().startsWith("Windows");
@@ -55,7 +59,7 @@ static boolean isLinux() {
5559
/**
5660
* Gets a string naming the operating system.
5761
*
58-
* @return
62+
* @return
5963
*/
6064
static String getOperatingSystem() {
6165
return System.getProperty("os.name");
@@ -64,7 +68,7 @@ static String getOperatingSystem() {
6468
/**
6569
* Returns the location or alias of MATLAB on an operating system specific basis.
6670
* <br><br>
67-
* For OS X this will be the location, for Windows or Linux this will be an alias. For any other operating system an
71+
* For OS X this will be the location, for Windows or Linux this will be an alias. For any other operating system an
6872
* exception will be thrown.
6973
*
7074
* @return
@@ -139,21 +143,26 @@ private static String getOSXMatlabLocation() throws MatlabConnectionException {
139143
* @throws MatlabConnectionException
140144
*/
141145
static String getClassPathAsRMICodebase() throws MatlabConnectionException {
146+
String entry = "";
142147
try {
143148
StringBuilder codebaseBuilder = new StringBuilder();
144149
String[] paths = System.getProperty("java.class.path", "").split(File.pathSeparator);
145150

146151
for (int i = 0; i < paths.length; i++) {
147-
codebaseBuilder.append("file://");
148-
codebaseBuilder.append(new File(paths[i]).getCanonicalFile().toURI().toURL().getPath());
149-
152+
File f = new File(paths[i]);
153+
if (f.exists() && !f.isDirectory()) {
154+
entry = new File(paths[i]).getCanonicalFile().toURI().toURL().getPath();
155+
codebaseBuilder.append("file://");
156+
codebaseBuilder.append(entry);
157+
}
150158
if (i != paths.length - 1) {
151159
codebaseBuilder.append(" ");
152160
}
153161
}
154162

155163
return codebaseBuilder.toString();
156164
} catch (IOException e) {
165+
sLog.severe("Unable to resolve classpath entry: " + entry);
157166
throw new MatlabConnectionException("Unable to resolve classpath entry", e);
158167
}
159168
}
@@ -162,14 +171,20 @@ static String getClassPathAsRMICodebase() throws MatlabConnectionException {
162171
* Converts the classpath into individual canonical entries.
163172
*
164173
* @return
165-
* @throws MatlabConnectionException
174+
* @throws MatlabConnectionException
166175
*/
167176
static String[] getClassPathAsCanonicalPaths() throws MatlabConnectionException {
168177
try {
169178
String[] paths = System.getProperty("java.class.path", "").split(File.pathSeparator);
170179

171180
for (int i = 0; i < paths.length; i++) {
172-
paths[i] = new File(paths[i]).getCanonicalPath();
181+
File f = new File(paths[i]);
182+
if (f.exists()) {
183+
paths[i] = f.getCanonicalPath();
184+
} else {
185+
sLog.severe("Classpath entry " + paths[i] + " not found. Adding absolute path instead.");
186+
paths[i] = new File(paths[i]).getAbsolutePath();
187+
}
173188
}
174189

175190
return paths;
@@ -272,7 +287,7 @@ static String getSupportCodeLocation() throws MatlabConnectionException {
272287
/**
273288
* Whether this code is running inside of MATLAB.
274289
*
275-
* @return
290+
* @return
276291
*/
277292
static boolean isRunningInsideMatlab() {
278293
boolean available;

0 commit comments

Comments
 (0)