You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicemix.apache.org by jb...@apache.org on 2010/03/26 12:41:25 UTC

svn commit: r927781 - in /servicemix/smx4/bundles/trunk/rome-1.0: ./ src/ src/main/ src/main/java/ src/main/java/com/ src/main/java/com/sun/ src/main/java/com/sun/syndication/ src/main/java/com/sun/syndication/io/ src/main/java/com/sun/syndication/io/i...

Author: jbonofre
Date: Fri Mar 26 11:41:24 2010
New Revision: 927781

URL: http://svn.apache.org/viewvc?rev=927781&view=rev
Log:
[SMX4-510] Build ServiceMix bundle for Rome.

Added:
    servicemix/smx4/bundles/trunk/rome-1.0/
    servicemix/smx4/bundles/trunk/rome-1.0/pom.xml   (with props)
    servicemix/smx4/bundles/trunk/rome-1.0/src/
    servicemix/smx4/bundles/trunk/rome-1.0/src/main/
    servicemix/smx4/bundles/trunk/rome-1.0/src/main/java/
    servicemix/smx4/bundles/trunk/rome-1.0/src/main/java/com/
    servicemix/smx4/bundles/trunk/rome-1.0/src/main/java/com/sun/
    servicemix/smx4/bundles/trunk/rome-1.0/src/main/java/com/sun/syndication/
    servicemix/smx4/bundles/trunk/rome-1.0/src/main/java/com/sun/syndication/io/
    servicemix/smx4/bundles/trunk/rome-1.0/src/main/java/com/sun/syndication/io/impl/
    servicemix/smx4/bundles/trunk/rome-1.0/src/main/java/com/sun/syndication/io/impl/PluginManager.java   (with props)

Added: servicemix/smx4/bundles/trunk/rome-1.0/pom.xml
URL: http://svn.apache.org/viewvc/servicemix/smx4/bundles/trunk/rome-1.0/pom.xml?rev=927781&view=auto
==============================================================================
--- servicemix/smx4/bundles/trunk/rome-1.0/pom.xml (added)
+++ servicemix/smx4/bundles/trunk/rome-1.0/pom.xml Fri Mar 26 11:41:24 2010
@@ -0,0 +1,104 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+    <!--
+
+        Licensed to the Apache Software Foundation (ASF) under one or more
+        contributor license agreements.  See the NOTICE file distributed with
+        this work for additional information regarding copyright ownership.
+        The ASF licenses this file to You under the Apache License, Version 2.0
+        (the "License"); you may not use this file except in compliance with
+        the License.  You may obtain a copy of the License at
+
+           http://www.apache.org/licenses/LICENSE-2.0
+
+        Unless required by applicable law or agreed to in writing, software
+        distributed under the License is distributed on an "AS IS" BASIS,
+        WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+        See the License for the specific language governing permissions and
+        limitations under the License.
+    -->
+    
+    <modelVersion>4.0.0</modelVersion>
+    
+    <parent>
+        <groupId>org.apache.servicemix.bundles</groupId>
+        <artifactId>bundles-pom</artifactId>
+        <version>4</version>
+    </parent>
+    
+    <groupId>org.apache.servicemix.bundles</groupId>
+    <artifactId>org.apache.servicemix.bundles.rome</artifactId>
+    <version>1.0_1-SNAPSHOT</version>
+    <packaging>bundle</packaging>
+    <name>Apache ServiceMix Bundles: ${pkgArtifactId}-${pkgVersion}</name>
+    <description>
+        This bundle simply wraps ${pkgArtifactId}-${pkgVersion}.jar.
+    </description>
+    
+    <properties>
+        <pkgGroupId>rome</pkgGroupId>
+        <pkgArtifactId>rome</pkgArtifactId>
+        <pkgVersion>1.0</pkgVersion>
+        <servicemix.osgi.export>
+            com.sun.syndication*;version=${pkgVersion};-split-package:=merge-first
+        </servicemix.osgi.export>
+        <servicemix.osgi.import.pkg>
+            !com.sun.syndication*,
+            org.jdom;resolution:=optional,
+            org.jdom.input;resolution:=optional,
+            org.jdom.output;resolution:=optional,
+            *
+        </servicemix.osgi.import.pkg>
+    </properties>
+    
+    <repositories>
+        <repository>
+            <id>java.net</id>
+            <name>Java.net Maven Repository</name>
+            <url>http://download.java.net/maven/2</url>
+        </repository>
+    </repositories>
+    
+    <dependencies>
+        <dependency>
+            <groupId>${pkgGroupId}</groupId>
+            <artifactId>${pkgArtifactId}</artifactId>
+            <version>${pkgVersion}</version>
+            <optional>true</optional>
+        </dependency>
+    </dependencies>
+    
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-shade-plugin</artifactId>
+                <executions>
+                    <execution>
+                        <phase>package</phase>
+                        <goals>
+                            <goal>shade</goal>
+                        </goals>
+                        <configuration>
+                            <artifactSet>
+                                <includes>
+                                    <include>${pkgGroupId}:${pkgArtifactId}</include>
+                                </includes>
+                            </artifactSet>
+                            <filters>
+                                <filter>
+                                    <artifact>${pkgGroupId}:${pkgArtifactId}</artifact>
+                                    <excludes>
+                                        <exclude>**</exclude>
+                                    </excludes>
+                                </filter>
+                            </filters>
+                        </configuration>
+                    </execution>
+                </executions>
+            </plugin>
+        </plugins>
+    </build>
+
+</project>
\ No newline at end of file

Propchange: servicemix/smx4/bundles/trunk/rome-1.0/pom.xml
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: servicemix/smx4/bundles/trunk/rome-1.0/src/main/java/com/sun/syndication/io/impl/PluginManager.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/bundles/trunk/rome-1.0/src/main/java/com/sun/syndication/io/impl/PluginManager.java?rev=927781&view=auto
==============================================================================
--- servicemix/smx4/bundles/trunk/rome-1.0/src/main/java/com/sun/syndication/io/impl/PluginManager.java (added)
+++ servicemix/smx4/bundles/trunk/rome-1.0/src/main/java/com/sun/syndication/io/impl/PluginManager.java Fri Mar 26 11:41:24 2010
@@ -0,0 +1,162 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.sun.syndication.io.impl;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import com.sun.syndication.io.DelegatingModuleGenerator;
+import com.sun.syndication.io.DelegatingModuleParser;
+import com.sun.syndication.io.WireFeedGenerator;
+import com.sun.syndication.io.WireFeedParser;
+
+/**
+ * <p>
+ * Override the default Rome plugin manager to be OSGi compliant around classloader.
+ * </p>
+ * 
+ * @author Alejandro Abdelnur
+ * @author Jean-Baptiste Onofré
+ * @author Lukasz Dywicki
+ */
+public abstract class PluginManager {
+    
+    private String[] _propertyValues;
+    private Map _pluginsMap;
+    private List _pluginsList;
+    private List _keys;
+    private WireFeedParser _parentParser;
+    private WireFeedGenerator _parentGenerator;
+    
+    /**
+     * <p>
+     * Creates a PluginManager.
+     * <p>
+     * 
+     * @param propertyKey property key defining the plugins classes. 
+     */
+    protected PluginManager(String propertyKey) {
+        this(propertyKey, null, null);
+    }
+    
+    protected PluginManager(String propertyKey, WireFeedParser parentParser, WireFeedGenerator parentGenerator) {
+        _parentParser = parentParser;
+        _parentGenerator = parentGenerator;
+        _propertyValues = PropertiesLoader.getPropertiesLoader().getTokenizedProperty(propertyKey, ", ");
+        loadPlugins();
+        _pluginsMap = Collections.unmodifiableMap(_pluginsMap);
+        _pluginsList = Collections.unmodifiableList(_pluginsList);
+        _keys = Collections.unmodifiableList(new ArrayList(_pluginsMap.keySet()));
+    }
+    
+    protected abstract String getKey(Object obj);
+    
+    protected List getKeys() {
+        return _keys;
+    }
+    
+    protected List getPlugins() {
+        return _pluginsList;
+    }
+    
+    protected Map getPluginMap() {
+        return _pluginsMap;
+    }
+    
+    protected Object getPlugin(String key) {
+        return _pluginsMap.get(key);
+    }
+    
+    // PRIVATE - LOADER PART
+    
+    private void loadPlugins() {
+        List finalPluginsList = new ArrayList();
+        _pluginsList = new ArrayList();
+        _pluginsMap = new HashMap();
+        String className = null;
+        try {
+            Class[] classes = getClasses();
+            for (int i = 0; i < classes.length; i++) {
+                className = classes[i].getName();
+                Object plugin = classes[i].newInstance();
+                if (plugin instanceof DelegatingModuleParser) {
+                    ((DelegatingModuleParser) plugin).setFeedParser(_parentParser);
+                }
+                if (plugin instanceof DelegatingModuleGenerator) {
+                    ((DelegatingModuleGenerator) plugin).setFeedGenerator(_parentGenerator);
+                }
+                
+                _pluginsMap.put(getKey(plugin), plugin);
+                _pluginsList.add(plugin); // to preserve the order of definition in the rome.properties files
+            }
+            Iterator i = _pluginsMap.values().iterator();
+            while (i.hasNext()) {
+                finalPluginsList.add(i.next()); // to remove overridden plugin impls
+            }
+            
+            i = _pluginsList.iterator();
+            while (i.hasNext()) {
+                Object plugin = i.next();
+                if (!finalPluginsList.contains(plugin)) {
+                    i.remove();
+                }
+            }
+        } catch (Exception ex) {
+            throw new RuntimeException("could not instantiate plugin " + className, ex);
+        } catch (ExceptionInInitializerError er) {
+            throw new RuntimeException("could not instantiate plugin " + className, er);
+        }
+    }
+    
+    /**
+     * <p>
+     * Loads and returns the classes defined in the properties files. If the system property "rome.pluginmanager.useloadclass" is
+     * set to true then classLoader.loadClass will be used to load classes (instead of Class.forName). This is designed to improve
+     * OSGi compatibility. Further information can be found in https://rome.dev.java.net/issues/show_bug.cgi?id=118
+     * </p>
+     * 
+     * @return array containing the classes defined in the properties files.
+     * @throws ClassNotFoundException thrown if one of the classes defined in the properties file cannot be loaded and hard failure is ON.
+     */
+    private Class[] getClasses() throws ClassNotFoundException {
+        ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
+        List classes = new ArrayList();
+        boolean useLoadClass = Boolean.valueOf(System.getProperty("rome.pluginmanager.useloadclass", "false")).booleanValue();
+        for (int i = 0; i < _propertyValues.length; i++) {
+            Class mClass = null;
+            try {
+                if (useLoadClass) {
+                    mClass = classLoader.loadClass(_propertyValues[i]);
+                } else {
+                    mClass = Class.forName(_propertyValues[i], true, classLoader);
+                }
+            } catch (ClassNotFoundException e) {
+                // if external class loader fail use local class loader
+                mClass = getClass().getClassLoader().loadClass(_propertyValues[i]);
+            }
+            classes.add(mClass);
+        }
+        Class[] array = new Class[classes.size()];
+        classes.toArray(array);
+        return array;
+    }
+
+}

Propchange: servicemix/smx4/bundles/trunk/rome-1.0/src/main/java/com/sun/syndication/io/impl/PluginManager.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain