ctakes-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From seanfi...@apache.org
Subject svn commit: r1653369 - /ctakes/trunk/ctakes-dictionary-lookup-fast/src/main/java/org/apache/ctakes/dictionary/lookup2/util/JdbcConnectionFactory.java
Date Tue, 20 Jan 2015 21:00:44 GMT
Author: seanfinan
Date: Tue Jan 20 21:00:44 2015
New Revision: 1653369

URL: http://svn.apache.org/r1653369
Log:
CTAKES-345 enhancement to use $CTAKES_HOME in finding dictionary database when cwd is not
associated with the ctakes installation

Modified:
    ctakes/trunk/ctakes-dictionary-lookup-fast/src/main/java/org/apache/ctakes/dictionary/lookup2/util/JdbcConnectionFactory.java

Modified: ctakes/trunk/ctakes-dictionary-lookup-fast/src/main/java/org/apache/ctakes/dictionary/lookup2/util/JdbcConnectionFactory.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-dictionary-lookup-fast/src/main/java/org/apache/ctakes/dictionary/lookup2/util/JdbcConnectionFactory.java?rev=1653369&r1=1653368&r2=1653369&view=diff
==============================================================================
--- ctakes/trunk/ctakes-dictionary-lookup-fast/src/main/java/org/apache/ctakes/dictionary/lookup2/util/JdbcConnectionFactory.java
(original)
+++ ctakes/trunk/ctakes-dictionary-lookup-fast/src/main/java/org/apache/ctakes/dictionary/lookup2/util/JdbcConnectionFactory.java
Tue Jan 20 21:00:44 2015
@@ -57,9 +57,6 @@ public enum JdbcConnectionFactory {
       if ( jdbcUrl.startsWith( HSQL_FILE_PREFIX ) ) {
          // Hack for hsqldb file needing to be absolute or relative to current working directory
          trueJdbcUrl = getConnectionUrl( jdbcUrl );
-         if ( trueJdbcUrl.endsWith( HSQL_DB_EXT ) ) {
-            trueJdbcUrl = trueJdbcUrl.substring( 0, trueJdbcUrl.length() - HSQL_DB_EXT.length()
);
-         }
       }
       try {
          // DO NOT use try with resources here.
@@ -99,29 +96,34 @@ public enum JdbcConnectionFactory {
       final String urlFilePath = urlDbPath + HSQL_DB_EXT;
       File file = new File( urlFilePath );
       if ( file.exists() ) {
-         return file.getPath();
+         return urlDbPath;
       }
       // file url is not absolute, check for relative directly under current working directory
       final String cwd = System.getProperty( "user.dir" );
       file = new File( cwd, urlFilePath );
       if ( file.exists() ) {
-         return file.getPath();
+         return urlDbPath;
       }
       // Users running projects out of an ide may have the module directory as cwd
-      final String cwdParent = new File( cwd ).getParent();
-      file = new File( cwdParent, urlFilePath );
-      if ( file.exists() ) {
-         return file.getPath();
+      String upOne = "../";
+      File cwdDerived = new File( cwd );
+      while ( cwdDerived.getParentFile() != null ) {
+         cwdDerived = cwdDerived.getParentFile();
+         file = new File( cwdDerived, urlFilePath );
+         if ( file.exists() ) {
+            return upOne+urlDbPath;
+         }
+         upOne += "../";
       }
       final String cTakesHome = System.getenv( CTAKES_HOME );
       if ( cTakesHome != null && !cTakesHome.isEmpty() ) {
          file = new File( cTakesHome, urlFilePath );
          if ( file.exists() ) {
-            return file.getPath();
+            return cTakesHome + "/" + urlDbPath;
          }
       }
-      LOGGER.error( "Could not find " + urlFilePath + " as absolute or in \n" + cwd + " or
in \n"
-              + cwdParent + " or in \n" + cTakesHome );
+      LOGGER.error( "Could not find " + urlFilePath + " as absolute or in \n" + cwd
+              + " or in any parent thereof or in $CTAKES_HOME \n" + cTakesHome );
       throw new SQLException( "No HsqlDB script file exists at Url" );
    }
 



Mime
View raw message