You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by jl...@apache.org on 2022/05/24 09:33:19 UTC

svn commit: r1901206 - in /geronimo/specs/trunk/geronimo-activation_2.0_spec: ./ src/main/java/jakarta/activation/

Author: jlmonteiro
Date: Tue May 24 09:33:18 2022
New Revision: 1901206

URL: http://svn.apache.org/viewvc?rev=1901206&view=rev
Log:
GERONIMO-6832 Fix TCK and Signature Tests. Patch from Richard Zowalla. Thanks.

Modified:
    geronimo/specs/trunk/geronimo-activation_2.0_spec/pom.xml
    geronimo/specs/trunk/geronimo-activation_2.0_spec/src/main/java/jakarta/activation/ActivationDataFlavor.java
    geronimo/specs/trunk/geronimo-activation_2.0_spec/src/main/java/jakarta/activation/CommandInfo.java
    geronimo/specs/trunk/geronimo-activation_2.0_spec/src/main/java/jakarta/activation/MailcapCommandMap.java
    geronimo/specs/trunk/geronimo-activation_2.0_spec/src/main/java/jakarta/activation/MimetypesFileTypeMap.java

Modified: geronimo/specs/trunk/geronimo-activation_2.0_spec/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/specs/trunk/geronimo-activation_2.0_spec/pom.xml?rev=1901206&r1=1901205&r2=1901206&view=diff
==============================================================================
--- geronimo/specs/trunk/geronimo-activation_2.0_spec/pom.xml (original)
+++ geronimo/specs/trunk/geronimo-activation_2.0_spec/pom.xml Tue May 24 09:33:18 2022
@@ -113,6 +113,19 @@
             </plugin>
             <plugin>
                 <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-source-plugin</artifactId>
+                <version>3.2.0</version>
+                <executions>
+                    <execution>
+                        <id>attach-sources</id>
+                        <goals>
+                            <goal>jar</goal>
+                        </goals>
+                    </execution>
+                </executions>
+            </plugin>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
                 <artifactId>maven-surefire-plugin</artifactId>
                 <configuration>
                     <redirectTestOutputToFile>true</redirectTestOutputToFile>

Modified: geronimo/specs/trunk/geronimo-activation_2.0_spec/src/main/java/jakarta/activation/ActivationDataFlavor.java
URL: http://svn.apache.org/viewvc/geronimo/specs/trunk/geronimo-activation_2.0_spec/src/main/java/jakarta/activation/ActivationDataFlavor.java?rev=1901206&r1=1901205&r2=1901206&view=diff
==============================================================================
--- geronimo/specs/trunk/geronimo-activation_2.0_spec/src/main/java/jakarta/activation/ActivationDataFlavor.java (original)
+++ geronimo/specs/trunk/geronimo-activation_2.0_spec/src/main/java/jakarta/activation/ActivationDataFlavor.java Tue May 24 09:33:18 2022
@@ -19,13 +19,12 @@
 
 package jakarta.activation;
 
-import java.awt.datatransfer.DataFlavor;
 import java.io.InputStream;
 
 /**
  * @version $Rev$ $Date$
  */
-public class ActivationDataFlavor extends DataFlavor {
+public class ActivationDataFlavor {
     private final Class representationClass;
     private final String mimeType;
     private String humanPresentableName;
@@ -68,6 +67,13 @@ public class ActivationDataFlavor extend
         return this.isMimeTypeEqual(dataFlavor.getMimeType()) && representationClass == dataFlavor.getRepresentationClass();
     }
 
+    @Deprecated
+    public boolean equals(String s) {
+        if (s == null || mimeType == null)
+            return false;
+        return isMimeTypeEqual(s);
+    }
+
     public boolean isMimeTypeEqual(String mimeType) {
         try {
             MimeType thisType = new MimeType(this.mimeType);
@@ -78,11 +84,15 @@ public class ActivationDataFlavor extend
         }
     }
 
+    @Deprecated
     protected String normalizeMimeTypeParameter(String parameterName, String parameterValue) {
-        return parameterName + "=" + parameterValue;
+        return parameterValue;
     }
 
+    @Deprecated
     protected String normalizeMimeType(String mimeType) {
         return mimeType;
     }
+
+
 }
\ No newline at end of file

Modified: geronimo/specs/trunk/geronimo-activation_2.0_spec/src/main/java/jakarta/activation/CommandInfo.java
URL: http://svn.apache.org/viewvc/geronimo/specs/trunk/geronimo-activation_2.0_spec/src/main/java/jakarta/activation/CommandInfo.java?rev=1901206&r1=1901205&r2=1901206&view=diff
==============================================================================
--- geronimo/specs/trunk/geronimo-activation_2.0_spec/src/main/java/jakarta/activation/CommandInfo.java (original)
+++ geronimo/specs/trunk/geronimo-activation_2.0_spec/src/main/java/jakarta/activation/CommandInfo.java Tue May 24 09:33:18 2022
@@ -19,10 +19,13 @@
 
 package jakarta.activation;
 
-import java.beans.Beans;
 import java.io.Externalizable;
 import java.io.IOException;
 import java.io.ObjectInputStream;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
 
 /**
  * @version $Rev$ $Date$
@@ -62,7 +65,12 @@ public class CommandInfo {
 
     /**
      * Instantiate and return a command JavaBean.
-     * The bean is created using Beans.instantiate(loader, commandClass).
+     *
+     * If the current runtime environment supports {@code Beans.instantiate},
+     * the bean is created using Beans.instantiate(loader, commandClass).
+     *
+     * Otherwise, use {@link java.lang.Class#forName Class.forName}.
+     *
      * If the new bean implements CommandObject then its setCommandContext(String, DataHandler)
      * method is called.
      * Otherwise if it implements Externalizable and the supplied DataHandler is not null
@@ -84,4 +92,83 @@ public class CommandInfo {
         }
         return bean;
     }
+
+    /**
+     * Helper class to invoke Beans.instantiate if java.desktop is not available.
+     */
+    private static final class Beans {
+        private static final Method instantiateMethod;
+
+        static {
+            Method m;
+            try {
+                Class<?> c = Class.forName("java.beans.Beans");
+                m = c.getDeclaredMethod("instantiate", ClassLoader.class, String.class);
+            } catch (ClassNotFoundException | NoSuchMethodException e) {
+                m = null;
+            }
+            instantiateMethod = m;
+
+        }
+
+        /**
+         * Equivalent to invoking java.beans.Beans.instantiate(loader, cn)
+         */
+        static Object instantiate(ClassLoader loader, String cn)
+                throws IOException, ClassNotFoundException {
+
+            if (instantiateMethod != null) {
+
+                // invoke Beans.instantiate
+                try {
+                    return instantiateMethod.invoke(null, loader, cn);
+                } catch (InvocationTargetException e) {
+                    if (e.getCause() instanceof ClassNotFoundException) {
+                        throw (ClassNotFoundException) e.getCause();
+                    }
+                } catch (IllegalAccessException e) {
+                    //ignored
+                }
+
+            } else {
+
+                SecurityManager security = System.getSecurityManager();
+                if (security != null) {
+                    // if it's ok with the SecurityManager, it's ok with me.
+                    String cname = cn.replace('/', '.');
+                    if (cname.startsWith("[")) {
+                        int b = cname.lastIndexOf('[') + 2;
+                        if (b > 1 && b < cname.length()) {
+                            cname = cname.substring(b);
+                        }
+                    }
+                    int i = cname.lastIndexOf('.');
+                    if (i != -1) {
+                        security.checkPackageAccess(cname.substring(0, i));
+                    }
+                }
+
+                // Beans.instantiate specified to use SCL when loader is null
+                if (loader == null) {
+                    loader = (ClassLoader)
+                            AccessController.doPrivileged((PrivilegedAction) () -> {
+                                ClassLoader cl = null;
+                                try {
+                                    cl = ClassLoader.getSystemClassLoader();
+                                } catch (SecurityException ex) {
+                                }
+                                return cl;
+                            });
+                }
+                final Class<?> beanClass = Class.forName(cn, true, loader);
+                try {
+                    return beanClass.getDeclaredConstructor().newInstance();
+                } catch (Exception ex) {
+                    throw new ClassNotFoundException(beanClass + ": " + ex, ex);
+                }
+
+            }
+            return null;
+        }
+    }
 }
\ No newline at end of file

Modified: geronimo/specs/trunk/geronimo-activation_2.0_spec/src/main/java/jakarta/activation/MailcapCommandMap.java
URL: http://svn.apache.org/viewvc/geronimo/specs/trunk/geronimo-activation_2.0_spec/src/main/java/jakarta/activation/MailcapCommandMap.java?rev=1901206&r1=1901205&r2=1901206&view=diff
==============================================================================
--- geronimo/specs/trunk/geronimo-activation_2.0_spec/src/main/java/jakarta/activation/MailcapCommandMap.java (original)
+++ geronimo/specs/trunk/geronimo-activation_2.0_spec/src/main/java/jakarta/activation/MailcapCommandMap.java Tue May 24 09:33:18 2022
@@ -90,22 +90,41 @@ public class MailcapCommandMap extends C
             // ignore
         }
 
-        // process ${java.home}/lib/mailcap
-        try {
-            File file = new File(System.getProperty("java.home"), "lib/mailcap");
-            InputStream is = new FileInputStream(file);
+
+        // process ${java.home}/conf/mailcap if it exists otherwise process ${java.home}/lib/mailcap
+        final File confDir = new File(System.getProperty("java.home"), "conf/mailcap");
+
+        if(confDir.exists()) {
             try {
-                parseMailcap(is);
-            } finally {
-                is.close();
+                InputStream is = new FileInputStream(confDir);
+                try {
+                    parseMailcap(is);
+                } finally {
+                    is.close();
+                }
+            } catch (SecurityException e) {
+                // ignore
+            } catch (IOException e) {
+                // ignore
+            }
+        } else {
+            // process ${java.home}/lib/mailcap
+            try {
+                File file = new File(System.getProperty("java.home"), "lib/mailcap");
+                InputStream is = new FileInputStream(file);
+                try {
+                    parseMailcap(is);
+                } finally {
+                    is.close();
+                }
+            } catch (SecurityException e) {
+                // ignore
+            } catch (IOException e) {
+                // ignore
             }
-        } catch (SecurityException e) {
-            // ignore
-        } catch (IOException e) {
-            // ignore
         }
 
-        // process ${user.home}/lib/mailcap
+        // process ${user.home}/.mailcap
         try {
             File file = new File(System.getProperty("user.home"), ".mailcap");
             InputStream is = new FileInputStream(file);

Modified: geronimo/specs/trunk/geronimo-activation_2.0_spec/src/main/java/jakarta/activation/MimetypesFileTypeMap.java
URL: http://svn.apache.org/viewvc/geronimo/specs/trunk/geronimo-activation_2.0_spec/src/main/java/jakarta/activation/MimetypesFileTypeMap.java?rev=1901206&r1=1901205&r2=1901206&view=diff
==============================================================================
--- geronimo/specs/trunk/geronimo-activation_2.0_spec/src/main/java/jakarta/activation/MimetypesFileTypeMap.java (original)
+++ geronimo/specs/trunk/geronimo-activation_2.0_spec/src/main/java/jakarta/activation/MimetypesFileTypeMap.java Tue May 24 09:33:18 2022
@@ -82,21 +82,39 @@ public class MimetypesFileTypeMap extend
             // ignore
         }
 
-        // defaults from ${java.home}/lib/mime.types
-        try {
-            File file = new File(System.getProperty("java.home"), "lib/mime.types");
-            InputStream is = new FileInputStream(file);
+        // process ${java.home}/conf/mime.types if it exists otherwise process ${java.home}/lib/mime.types
+        final File confDir = new File(System.getProperty("java.home"), "conf/mime.types");
+
+        if(confDir.exists()) {
             try {
-                loadStream(is);
-            } finally {
-                is.close();
+                InputStream is = new FileInputStream(confDir);
+                try {
+                    loadStream(is);
+                } finally {
+                    is.close();
+                }
+            } catch (SecurityException e) {
+                // ignore
+            } catch (IOException e) {
+                // ignore
+            }
+        } else {
+            // defaults from ${java.home}/lib/mime.types
+            try {
+                File file = new File(System.getProperty("java.home"), "lib/mime.types");
+                InputStream is = new FileInputStream(file);
+                try {
+                    loadStream(is);
+                } finally {
+                    is.close();
+                }
+            } catch (SecurityException e) {
+                // ignore
+            } catch (FileNotFoundException e) {
+                // ignore
+            } catch (IOException e) {
+                // ignore
             }
-        } catch (SecurityException e) {
-            // ignore
-        } catch (FileNotFoundException e) {
-            // ignore
-        } catch (IOException e) {
-            // ignore
         }
 
         // defaults from ${user.home}/.mime.types