sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1747279 - in /sis/branches/JDK8: ./ application/sis-openoffice/ application/sis-openoffice/src/main/java/org/apache/sis/openoffice/ application/sis-openoffice/src/main/unopkg/
Date Tue, 07 Jun 2016 17:32:37 GMT
Author: desruisseaux
Date: Tue Jun  7 17:32:36 2016
New Revision: 1747279

URL: http://svn.apache.org/viewvc?rev=1747279&view=rev
Log:
Resolve a classpath issue when installing openoffice addins.
The Apache SIS classes were not found. The issue is caused by
https://issues.apache.org/jira/browse/MJAR-223

Modified:
    sis/branches/JDK8/application/sis-openoffice/pom.xml
    sis/branches/JDK8/application/sis-openoffice/src/main/java/org/apache/sis/openoffice/CalcAddins.java
    sis/branches/JDK8/application/sis-openoffice/src/main/java/org/apache/sis/openoffice/Referencing.java
    sis/branches/JDK8/application/sis-openoffice/src/main/java/org/apache/sis/openoffice/Registration.java
    sis/branches/JDK8/application/sis-openoffice/src/main/unopkg/build-instruction.html
    sis/branches/JDK8/pom.xml

Modified: sis/branches/JDK8/application/sis-openoffice/pom.xml
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/application/sis-openoffice/pom.xml?rev=1747279&r1=1747278&r2=1747279&view=diff
==============================================================================
--- sis/branches/JDK8/application/sis-openoffice/pom.xml (original)
+++ sis/branches/JDK8/application/sis-openoffice/pom.xml Tue Jun  7 17:32:36 2016
@@ -146,7 +146,6 @@
 
       <!-- Add a manifest entry for add-ins registration in OpenOffice -->
       <plugin>
-        <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-jar-plugin</artifactId>
         <configuration>
           <archive>
@@ -165,7 +164,7 @@
         <artifactId>sis-build-helper</artifactId>
         <version>${project.version}</version>
         <configuration>
-          <oxtName>sis-${project.version}</oxtName>
+          <oxtName>apache-sis-${project.version}</oxtName>
           <pack200>true</pack200>
         </configuration>
         <executions>

Modified: sis/branches/JDK8/application/sis-openoffice/src/main/java/org/apache/sis/openoffice/CalcAddins.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/application/sis-openoffice/src/main/java/org/apache/sis/openoffice/CalcAddins.java?rev=1747279&r1=1747278&r2=1747279&view=diff
==============================================================================
--- sis/branches/JDK8/application/sis-openoffice/src/main/java/org/apache/sis/openoffice/CalcAddins.java
[UTF-8] (original)
+++ sis/branches/JDK8/application/sis-openoffice/src/main/java/org/apache/sis/openoffice/CalcAddins.java
[UTF-8] Tue Jun  7 17:32:36 2016
@@ -49,7 +49,7 @@ import org.apache.sis.util.collection.Ba
  * @version 0.8
  * @module
  */
-abstract class CalcAddins extends WeakBase implements XAddIn, XServiceName, XServiceInfo
{
+public abstract class CalcAddins extends WeakBase implements XAddIn, XServiceName, XServiceInfo
{
     /**
      * {@code true} for throwing an exception in case of failure, or {@code false} for returning
{@code NaN} instead.
      * This apply only to numerical computations; formulas returning a text value will returns
the exception message

Modified: sis/branches/JDK8/application/sis-openoffice/src/main/java/org/apache/sis/openoffice/Referencing.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/application/sis-openoffice/src/main/java/org/apache/sis/openoffice/Referencing.java?rev=1747279&r1=1747278&r2=1747279&view=diff
==============================================================================
--- sis/branches/JDK8/application/sis-openoffice/src/main/java/org/apache/sis/openoffice/Referencing.java
[UTF-8] (original)
+++ sis/branches/JDK8/application/sis-openoffice/src/main/java/org/apache/sis/openoffice/Referencing.java
[UTF-8] Tue Jun  7 17:32:36 2016
@@ -49,12 +49,12 @@ import org.apache.sis.internal.util.Patc
  * @version 0.8
  * @module
  */
-final class Referencing extends CalcAddins implements XReferencing {
+public class Referencing extends CalcAddins implements XReferencing {
     /**
      * The name for the registration of this component.
      * <strong>NOTE:</strong> OpenOffice expects a field with exactly that name;
do not rename!
      */
-    static final String __serviceName = "org.apache.sis.openoffice.Referencing";
+    public static final String __serviceName = "org.apache.sis.openoffice.Referencing";
 
     /**
      * Constructs a default implementation of {@code XReferencing} interface.
@@ -77,7 +77,7 @@ final class Referencing extends CalcAddi
             new String[] {
                 "xOptions",   "Provided by OpenOffice.",
                 "code",       "The code allocated by authority.",
-                "dimension",  "The dimension (1, 2, ...)."
+                "dimension",  "The dimension (1, 2, …)."
         }));
         methods.put("getAccuracy", new MethodInfo("Referencing", "TRANSFORM.ACCURACY",
             "Returns the accuracy of a transformation between two coordinate reference systems.",
@@ -113,6 +113,8 @@ final class Referencing extends CalcAddi
 
     /**
      * The service name that can be used to create such an object by a factory.
+     *
+     * @return value of {@code __serviceName}.
      */
     @Override
     public String getServiceName() {

Modified: sis/branches/JDK8/application/sis-openoffice/src/main/java/org/apache/sis/openoffice/Registration.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/application/sis-openoffice/src/main/java/org/apache/sis/openoffice/Registration.java?rev=1747279&r1=1747278&r2=1747279&view=diff
==============================================================================
--- sis/branches/JDK8/application/sis-openoffice/src/main/java/org/apache/sis/openoffice/Registration.java
[UTF-8] (original)
+++ sis/branches/JDK8/application/sis-openoffice/src/main/java/org/apache/sis/openoffice/Registration.java
[UTF-8] Tue Jun  7 17:32:36 2016
@@ -21,18 +21,20 @@ import java.io.IOException;
 import java.io.FilenameFilter;
 import java.io.FileOutputStream;
 import java.net.URI;
+import java.net.URL;
+import java.net.URLClassLoader;
 import java.net.URISyntaxException;
 import java.util.jar.Pack200;
 import java.util.jar.JarOutputStream;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 import java.util.logging.LogRecord;
+import java.lang.reflect.InvocationTargetException;
 
 import com.sun.star.lang.XSingleServiceFactory;
 import com.sun.star.lang.XMultiServiceFactory;
 import com.sun.star.comp.loader.FactoryHelper;
 import com.sun.star.registry.XRegistryKey;
-import org.apache.sis.referencing.CRS;
 
 
 /**
@@ -89,21 +91,32 @@ public final class Registration implemen
     /**
      * Ensures that the {@code sis.pack} files have been uncompressed.
      *
-     * @throws URISyntaxException if the path to the add-in JAR file does not have the expected
syntax.
-     * @throws IOException if an error occurred while uncompressing the PACK200 file.
+     * @param  caller the public caller method, for logging purpose only.
+     * @return {@code true} on success.
      */
-    private static void ensureInstalled() throws URISyntaxException, IOException {
-        final File directory = getInstallDirectory();
+    private static boolean ensureInstalled(final String caller) {
+        final File directory;
+        try {
+            directory = getInstallDirectory();
+        } catch (URISyntaxException e) {
+            fatalException(caller, "Can not locate the installation directory.", e);
+            return false;
+        }
         final String[] content = directory.list(new Registration());
         if (content != null && content.length != 0) {
-            final Pack200.Unpacker unpacker = Pack200.newUnpacker();
-            for (final String filename : content) {
-                final File packFile = new File(directory, filename);
-                final File jarFile  = new File(directory, filename.substring(0, filename.length()
- PACK.length()) + "jar");
-                try (JarOutputStream out = new JarOutputStream(new FileOutputStream(jarFile)))
{
-                    unpacker.unpack(packFile, out);
+            try {
+                final Pack200.Unpacker unpacker = Pack200.newUnpacker();
+                for (final String filename : content) {
+                    final File packFile = new File(directory, filename);
+                    final File jarFile  = new File(directory, filename.substring(0, filename.length()
- PACK.length()) + "jar");
+                    try (JarOutputStream out = new JarOutputStream(new FileOutputStream(jarFile)))
{
+                        unpacker.unpack(packFile, out);
+                    }
+                    packFile.delete();
                 }
-                packFile.delete();
+            } catch (IOException e) {
+                fatalException(caller, "Can not uncompress the JAR files.", e);
+                return false;
             }
             /*
              * Ensures that the EPSG database is installed. We force the EPSG installation
at add-in
@@ -116,29 +129,50 @@ public final class Registration implemen
              * Remainder: no GeoAPI or Apache SIS classes in any method signature of this
class!
              */
             try {
-                CRS.forCode("EPSG:4326");
-            } catch (Throwable e) {
-                unexpectedException(CRS.class, "forCode", e);
-                // Ignore. A new attempt to create the EPSG database will be performed
-                // when first needed, and the user may see the error at that time.
+                Class.forName("org.apache.sis.referencing.CRS")
+                     .getMethod("forCode", String.class)
+                     .invoke(null, "EPSG:4326");
+                return true;
+            } catch (InvocationTargetException e) {
+                fatalException(caller, "Failed to install EPSG geodetic dataset.", e.getTargetException());
+            } catch (ReflectiveOperationException | LinkageError e) {
+                classpathException(caller, e);
             }
         }
+        return false;
     }
 
     /**
-     * Logs the given exception.
+     * Logs the given exception before to abort installation. We use logging service instead
than
+     * propagating the exception because OpenOffice does not report the exception message.
      */
-    private static void unexpectedException(final Class<?> classe, final String method,
final Throwable exception) {
+    private static void fatalException(final String method, final String message, final Throwable
exception) {
         final Logger logger = Logger.getLogger(LOGGER);
-        final LogRecord record = new LogRecord(Level.WARNING, exception.getLocalizedMessage());
-        record.setLoggerName(logger.getName());
-        record.setSourceClassName(classe.getName());
+        final LogRecord record = new LogRecord(Level.SEVERE, message);
+        record.setSourceClassName(Registration.class.getName());
         record.setSourceMethodName(method);
+        record.setLoggerName(LOGGER);
         record.setThrown(exception);
         logger.log(record);
     }
 
     /**
+     * Logs the given exception for a classpath problem.
+     */
+    private static void classpathException(final String method, final Throwable exception)
{
+        final String lineSeparator = System.lineSeparator();
+        final StringBuilder message = new StringBuilder("Can not find Apache SIS classes.").append(lineSeparator)
+                .append("Classpath = ").append(System.getProperty("java.class.path"));
+        final ClassLoader loader = Referencing.class.getClassLoader();
+        if (loader instanceof URLClassLoader) {
+            for (final URL url : ((URLClassLoader) loader).getURLs()) {
+                message.append(lineSeparator).append("  + ").append(url);
+            }
+        }
+        fatalException(method, message.toString(), exception);
+    }
+
+    /**
      * Filters a directory content in order to retain only the {@code "*.pack"} files.
      *
      * @param directory the add-in installation directory.
@@ -157,17 +191,19 @@ public final class Registration implemen
      * @param   factories the service manager to be used if needed.
      * @param   registry the registry key
      * @return  A factory for creating the component.
-     * @throws  URISyntaxException if the path to the add-in JAR file does not have the expected
syntax.
-     * @throws  IOException if an error occurred while uncompressing the PACK200 file.
      */
     public static XSingleServiceFactory __getServiceFactory(
             final String               implementation,
             final XMultiServiceFactory factories,
-            final XRegistryKey         registry) throws URISyntaxException, IOException
+            final XRegistryKey         registry)
     {
-        ensureInstalled();
-        if (implementation.equals(Referencing.class.getName())) {
-            return FactoryHelper.getServiceFactory(Referencing.class, Referencing.__serviceName,
factories, registry);
+        if (ensureInstalled("__getServiceFactory")) {
+            if (implementation.equals(Referencing.class.getName())) try {
+                return FactoryHelper.getServiceFactory(Referencing.class, Referencing.__serviceName,
factories, registry);
+            } catch (LinkageError e) {
+                classpathException("__getServiceFactory", e);
+                throw e;
+            }
         }
         return null;
     }
@@ -178,14 +214,14 @@ public final class Registration implemen
      *
      * @param  registry the registry key.
      * @return {@code true} if the operation succeeded.
-     * @throws URISyntaxException if the path to the add-in JAR file does not have the expected
syntax.
-     * @throws IOException if an error occurred while uncompressing the PACK200 file.
      */
-    public static boolean __writeRegistryServiceInfo(final XRegistryKey registry)
-            throws URISyntaxException, IOException
-    {
-        ensureInstalled();
-        return register(Referencing.class, Referencing.__serviceName, registry);
+    public static boolean __writeRegistryServiceInfo(final XRegistryKey registry) {
+        if (ensureInstalled("__writeRegistryServiceInfo")) try {
+            return register(Referencing.class, Referencing.__serviceName, registry);
+        } catch (LinkageError e) {
+            classpathException("__writeRegistryServiceInfo", e);
+        }
+        return false;
     }
 
     /**

Modified: sis/branches/JDK8/application/sis-openoffice/src/main/unopkg/build-instruction.html
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/application/sis-openoffice/src/main/unopkg/build-instruction.html?rev=1747279&r1=1747278&r2=1747279&view=diff
==============================================================================
--- sis/branches/JDK8/application/sis-openoffice/src/main/unopkg/build-instruction.html (original)
+++ sis/branches/JDK8/application/sis-openoffice/src/main/unopkg/build-instruction.html Tue
Jun  7 17:32:36 2016
@@ -88,7 +88,7 @@ mvn install</pre></blockquote>
 
 <h2>Test in Apache OpenOffice:</h2>
 <blockquote><pre>cd target
-unopkg add sis-0.8-SNAPSHOT.oxt --log-file log.txt</pre></blockquote>
+unopkg add apache-sis-0.8-SNAPSHOT.oxt --log-file log.txt</pre></blockquote>
 
   </body>
 </html>

Modified: sis/branches/JDK8/pom.xml
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/pom.xml?rev=1747279&r1=1747278&r2=1747279&view=diff
==============================================================================
--- sis/branches/JDK8/pom.xml (original)
+++ sis/branches/JDK8/pom.xml Tue Jun  7 17:32:36 2016
@@ -513,17 +513,22 @@ Apache SIS is a free software, Java lang
            INDEX.LIST file is incomplete (which seem to happen in practice). -->
       <plugin>
         <artifactId>maven-jar-plugin</artifactId>
+        <version>2.6</version>
+        <!-- Regression in maven-jar-plugin version 3.0: the class-path entry in MANIFEST.MF
+             has the "repository" layout in sis-openoffice artifact even if we explicitely
+             ask for the "simple" layout. https://issues.apache.org/jira/browse/MJAR-223
-->
+
         <configuration>
           <archive>
             <addMavenDescriptor>false</addMavenDescriptor>
             <index>false</index>
             <manifest>
               <addClasspath>true</addClasspath>
+              <classpathLayoutType>simple</classpathLayoutType>
               <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
             </manifest>
             <manifestEntries>
               <Built-On>${maven.build.timestamp}</Built-On>
-              <Implementation-URL>${project.url}</Implementation-URL>
               <Specification-Title>GeoAPI</Specification-Title>
               <Specification-Version>${geoapi.version}</Specification-Version>
               <Specification-Vendor>Open Geospatial Consortium</Specification-Vendor>



Mime
View raw message