From 1ce344c9b0fbd89313da8be1021a3fd82daccc87 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Euzenat?= <Jerome.Euzenat@inria.fr>
Date: Wed, 12 Jul 2017 19:51:43 +0000
Subject: [PATCH] Added guards to better catch the problem of OWL API not
 having guava available

---
 html/relnotes.html                            |  1 +
 lib/owlapi30/README.TXT                       | 27 +++++++++++++++++++
 lib/owlapi30/owlapi-bin.pom                   | 10 -------
 .../exmo/ontowrap/OntologyFactory.java        |  4 +--
 .../owlapi30/OWLAPI3OntologyFactory.java      |  6 ++++-
 5 files changed, 35 insertions(+), 13 deletions(-)
 create mode 100644 lib/owlapi30/README.TXT

diff --git a/html/relnotes.html b/html/relnotes.html
index 4173dbe5..f8f4472b 100644
--- a/html/relnotes.html
+++ b/html/relnotes.html
@@ -76,6 +76,7 @@ with a warning:
 <li>Added language support in EDOAL (edoal)</li>
 <li>Added <tt>sameAs</tt> triples in SPARQL link generation (edoal)</li>
 <li>Added <tt>nbCells()</tt> to <tt>BasiicOntologyNetwork</tt> (impl)</li>
+<li>Added guards to better catch the problem of OWL API not having guava available (onto)</li>
 <li>Moved all shell examples from csh to bash (html)</li>
 <li>Clarified EDOAL documentation (html)</li>
 <li>Several documentation fixes --alignwn, rest-- (html)</li>
diff --git a/lib/owlapi30/README.TXT b/lib/owlapi30/README.TXT
new file mode 100644
index 00000000..8c2624b3
--- /dev/null
+++ b/lib/owlapi30/README.TXT
@@ -0,0 +1,27 @@
+2017-07-07
+
+* Why do we stick to OWL API 3.5.0?
+
+Version 3.5.1 and above (up to 3.5.4) do not work, they have the issue:
+ClassNotFoundException: com.google.common.cache.CacheLoader
+when running: OWLManager.createOWLOntologyManager()
+This then causes NoClassDefFoundError Could not initialize class uk.ac.manchester.cs.owl.owlapi.OWLDataFactoryImpl
+
+This is due to relying on guava without providing it.
+
+If you really need it, you may add a guava library in the build.xml wherever the owlapi-bin.jar is, replace the owlapi-bin.jar by a newer 3.x and it should work (not tested).
+
+* What about 4.x?
+
+Version 4.x has a drastically modified API
+see: https://github.com/owlcs/owlapi/wiki/Migrate-from-version-3.4-and-3.5-to-4.0
+and so far not supported by HermiT
+
+Integrating it would require a new OWLAPI40 implementation in ontosim, like that was done for 3.x
+Like that was done for 2.x, the OWL API developer did not change the package names with the new API.
+But it seems possible to have 3.x and 4.x to cohabits, contrary to 2.x and 3.x.
+It is sufficient to change the order of the jars in the build.xml (tested with 3.5.0 and 4.1.4)
+
+We however decided to wait for wider adoption of 4.x
+
+If you have implemented ontosim for OWL API 4.x or if you need it, please do not hesitate to let us know.
diff --git a/lib/owlapi30/owlapi-bin.pom b/lib/owlapi30/owlapi-bin.pom
index c0671003..071d21bb 100644
--- a/lib/owlapi30/owlapi-bin.pom
+++ b/lib/owlapi30/owlapi-bin.pom
@@ -4,16 +4,6 @@
   <groupId>org.semanticweb</groupId>
   <artifactId>owlapi</artifactId>
   <version>3.5.0</version>
-  <!-- version 3.5.1 does not work, strangely -->
-  <!-- versions 3.5.3 has the issue:
-       ClassNotFoundException: com.google.common.cache.CacheLoader
-       when running: OWLManager.createOWLOntologyManager()
-       [that's relying on guava without providing it]
-    or Could not initialize class uk.ac.manchester.cs.owl.owlapi.OWLDataFactoryImpl
-    -->
-  <!-- version 4.0.2 has a drastically modified API
-       and the path to this API is poorly documented
-       (it has to be done...) -->
   <name>OWL API</name>
   <description>API and implementation for OWL</description>
   <licenses>
diff --git a/src/fr/inrialpes/exmo/ontowrap/OntologyFactory.java b/src/fr/inrialpes/exmo/ontowrap/OntologyFactory.java
index 6369c296..dea42ea4 100644
--- a/src/fr/inrialpes/exmo/ontowrap/OntologyFactory.java
+++ b/src/fr/inrialpes/exmo/ontowrap/OntologyFactory.java
@@ -1,7 +1,7 @@
 /*
  * $Id$
  *
- * Copyright (C) INRIA, 2008, 2010-2015
+ * Copyright (C) INRIA, 2008, 2010-2015, 2017
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU Lesser General Public License as published by
@@ -126,7 +126,7 @@ public abstract class OntologyFactory {
 	} catch ( InvocationTargetException itex ) {
 	    logger.debug( "IGNORED Exception", itex );
 	}
-	instances.put( apiName, of );
+	if ( of != null ) instances.put( apiName, of );
 	return of;
     }
 
diff --git a/src/fr/inrialpes/exmo/ontowrap/owlapi30/OWLAPI3OntologyFactory.java b/src/fr/inrialpes/exmo/ontowrap/owlapi30/OWLAPI3OntologyFactory.java
index 9dcdbcdc..c476f3d7 100644
--- a/src/fr/inrialpes/exmo/ontowrap/owlapi30/OWLAPI3OntologyFactory.java
+++ b/src/fr/inrialpes/exmo/ontowrap/owlapi30/OWLAPI3OntologyFactory.java
@@ -1,7 +1,7 @@
 /*
  * $Id$
  *
- * Copyright (C) INRIA, 2008-2011, 2013-2014
+ * Copyright (C) INRIA, 2008-2011, 2013-2014, 2017
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU Lesser General Public License as published by
@@ -58,6 +58,10 @@ public class OWLAPI3OntologyFactory extends OntologyFactory {
 	    manager = OWLManager.createOWLOntologyManager();
 	} catch (URISyntaxException ex) {
 	    logger.debug( "IGNORED should never happen", ex );
+	} catch (Throwable t) {
+	    logger.error("Failure during static initialization", t);
+	    //t.printStackTrace();
+	    throw t;
 	}
     }
 
-- 
GitLab