You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by ve...@apache.org on 2009/05/23 02:23:09 UTC

svn commit: r777751 - in /webservices/axis2/trunk/java/modules: kernel/src/org/apache/axis2/deployment/ kernel/src/org/apache/axis2/deployment/repository/util/ kernel/src/org/apache/axis2/description/ kernel/src/org/apache/axis2/engine/ kernel/src/org/...

Author: veithen
Date: Sat May 23 00:23:08 2009
New Revision: 777751

URL: http://svn.apache.org/viewvc?rev=777751&view=rev
Log:
* Fixed the kernel to support module version numbers in the x.y.z-qualifier format (and not just SNAPSHOT and floats). This should avoid issues like AXIS2-4034 (caused by the fact that we had to use 1.41 as version numbers for the modules released with Axis2 1.4.1) and should also allow us to get rid of the xxx.mar.version properties introduced in r553898.
* Some general cleanup of the code related to module versions.

Note that the patch changes the type of the version property in AxisModule and therefore breaks compatibility with previous versions. This is acceptable because code that uses this part of the API should be revised anyway to make sure that it uses module version numbers in the correct way.

Added:
    webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/Version.java   (with props)
    webservices/axis2/trunk/java/modules/kernel/test/org/apache/axis2/description/VersionTest.java   (with props)
Modified:
    webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/DeploymentEngine.java
    webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/ModuleDeployer.java
    webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/repository/util/ArchiveReader.java
    webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/AxisDescription.java
    webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/AxisModule.java
    webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/engine/AxisConfiguration.java
    webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/util/Utils.java
    webservices/axis2/trunk/java/modules/kernel/test/org/apache/axis2/deployment/ModuleversionTest.java
    webservices/axis2/trunk/java/modules/osgi/src/org/apache/axis2/osgi/deployment/ModuleRegistry.java

Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/DeploymentEngine.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/DeploymentEngine.java?rev=777751&r1=777750&r2=777751&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/DeploymentEngine.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/DeploymentEngine.java Sat May 23 00:23:08 2009
@@ -273,8 +273,7 @@
                                             fileUrl.substring(0, fileUrl.indexOf(".aar")));
                     addServiceGroup(serviceGroup, servicelist, servicesURL, null, axisConfig);
                     log.info(Messages.getMessage(DeploymentErrorMsgs.DEPLOYING_WS,
-                                                 org.apache.axis2.util.Utils.getModuleName(
-                                                         serviceGroup.getServiceGroupName()),
+                                                 serviceGroup.getServiceGroupName(),
                                                  servicesURL.toString()));
                 }
             }
@@ -317,16 +316,12 @@
                     module.setModuleClassLoader(deploymentClassLoader);
                     module.setParent(axisConfig);
                     String moduleFile = fileUrl.substring(0, fileUrl.indexOf(".mar"));
-                    if (module.getName() == null) {
-                        module.setName(org.apache.axis2.util.Utils.getModuleName(moduleFile));
-                        module.setVersion(org.apache.axis2.util.Utils.getModuleVersion(moduleFile));
-                    }
+                    module.setArchiveName(moduleFile);
                     populateModule(module, moduleurl);
                     module.setFileName(moduleurl);
                     addNewModule(module, axisConfig);
                     log.info(Messages.getMessage(DeploymentErrorMsgs.DEPLOYING_MODULE,
-                                                 org.apache.axis2.util.Utils.getModuleName(module.getName(),
-                                                                                           module.getVersion()),
+                                                 module.getArchiveName(),
                                                  moduleurl.toString()));
                 }
             }

Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/ModuleDeployer.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/ModuleDeployer.java?rev=777751&r1=777750&r2=777751&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/ModuleDeployer.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/ModuleDeployer.java Sat May 23 00:23:08 2009
@@ -77,8 +77,7 @@
             metaData.setFileName(url);
             DeploymentEngine.addNewModule(metaData, axisConfig);
             log.info(Messages.getMessage(DeploymentErrorMsgs.DEPLOYING_MODULE,
-                                         Utils.getModuleName(metaData.getName(),
-                                                             metaData.getVersion()),
+                                         metaData.getArchiveName(),
                                          url.toString()));
         } catch (DeploymentException e) {
             log.error(Messages.getMessage(DeploymentErrorMsgs.INVALID_MODULE,

Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/repository/util/ArchiveReader.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/repository/util/ArchiveReader.java?rev=777751&r1=777750&r2=777751&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/repository/util/ArchiveReader.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/repository/util/ArchiveReader.java Sat May 23 00:23:08 2009
@@ -46,7 +46,6 @@
 import org.apache.axis2.engine.AxisConfiguration;
 import org.apache.axis2.i18n.Messages;
 import org.apache.axis2.namespace.Constants;
-import org.apache.axis2.util.Utils;
 import org.apache.axis2.util.XMLUtils;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -512,9 +511,8 @@
                     if (entry.getName().equalsIgnoreCase(MODULE_XML)) {
                         moduleXMLFound = true;
                         ModuleBuilder builder = new ModuleBuilder(zin, module, axisConfig);
-                        // setting module name
-                        module.setName(Utils.getModuleName(shortFileName));
-                        module.setVersion(Utils.getModuleVersion(shortFileName));
+                        // setting module name and version
+                        module.setArchiveName(shortFileName);
                         builder.populateModule();
                         break;
                     }
@@ -540,9 +538,8 @@
                 try {
                     in = new FileInputStream(file);
                     ModuleBuilder builder = new ModuleBuilder(in, module, axisConfig);
-                    // setting module name
-                    module.setName(Utils.getModuleName(shortFileName));
-                    module.setVersion(Utils.getModuleVersion(shortFileName));
+                    // setting module name and version
+                    module.setArchiveName(shortFileName);
                     builder.populateModule();
                 } catch (FileNotFoundException e) {
                     throw new DeploymentException(

Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/AxisDescription.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/AxisDescription.java?rev=777751&r1=777750&r2=777751&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/AxisDescription.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/AxisDescription.java Sat May 23 00:23:08 2009
@@ -59,6 +59,10 @@
 
     private Map<Object, AxisDescription> children;
 
+    /**
+     * Map of modules engaged on this object. The key is the archive name as defined by
+     * {@link AxisModule#getArchiveName()}.
+     */
     protected Map<String, AxisModule> engagedModules;
 
     /** List of ParameterObservers who want to be notified of changes */
@@ -450,12 +454,12 @@
             String tempModuleName = tempAxisModule.getName();
 
             if (moduleName.equals(tempModuleName)) {
-                String existing = tempAxisModule.getVersion();
+                Version existing = tempAxisModule.getVersion();
                 if (!Utils.checkVersion(axisModule.getVersion(), existing)) {
                     throw new AxisFault(Messages.getMessage("mismatchedModuleVersions",
                                                             getClass().getName(),
                                                             moduleName,
-                                                            existing));
+                                                            String.valueOf(existing)));
                 }
             }
 
@@ -470,8 +474,7 @@
         // If we have anything specific to do, let that happen
         onEngage(axisModule, source);
 
-        engagedModules.put(Utils.getModuleName(axisModule.getName(), axisModule.getVersion()),
-                           axisModule);
+        engagedModules.put(axisModule.getArchiveName(), axisModule);
     }
 
     protected void onEngage(AxisModule module, AxisDescription engager)
@@ -498,8 +501,7 @@
     }
 
     public boolean isEngaged(AxisModule axisModule) {
-        String id = Utils.getModuleName(axisModule.getName(), axisModule
-                .getVersion());
+        String id = axisModule.getArchiveName();
         return engagedModules != null && engagedModules.keySet().contains(id);
     }
 
@@ -510,8 +512,7 @@
         // module.getVersion());
         if (isEngaged(module)) {
             onDisengage(module);
-            engagedModules.remove(Utils.getModuleName(module.getName(), module
-                    .getVersion()));
+            engagedModules.remove(module.getArchiveName());
         }
     }
 

Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/AxisModule.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/AxisModule.java?rev=777751&r1=777750&r2=777751&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/AxisModule.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/AxisModule.java Sat May 23 00:23:08 2009
@@ -25,9 +25,11 @@
 import org.apache.axis2.engine.AxisConfiguration;
 import org.apache.axis2.i18n.Messages;
 import org.apache.axis2.modules.Module;
+import org.apache.axis2.util.Utils;
 
 import javax.xml.namespace.QName;
 import java.net.URL;
+import java.text.ParseException;
 import java.util.ArrayList;
 import java.util.HashMap;
 
@@ -63,7 +65,7 @@
 
     //This is to keep the version number of the module, if the module name is a-b-c-1.3.mar ,
     // then the module version would be 1.3
-    private String version;
+    private Version version;
 
     // to store module operations , which are suppose to be added to a service if it is engaged to a service
     private HashMap<QName, AxisOperation> operations = new HashMap<QName, AxisOperation>();
@@ -100,6 +102,94 @@
         this.name = name;
     }
 
+    /**
+     * Get the name of this module.
+     * Note that it is possible to deploy several versions of the same module. Therefore,
+     * the name of a module is not unique in the scope of a given {@link AxisConfiguration}.
+     * 
+     * @return the name of the module
+     */
+    public String getName() {
+        return name;
+    }
+
+    /**
+     * Set the name of this module.
+     * 
+     * @param name the name of the module
+     */
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    /**
+     * Get the archive name of this module. The archive name is the combination
+     * of the module name and version (if available). In general it is equal to the
+     * name of the module archive file without the suffix.
+     * 
+     * @return the archive name of the module
+     */
+    public String getArchiveName() {
+        return version == null ? name : (name + "-" + version);
+    }
+
+    /**
+     * Set the archive name of this module. This method will split the archive name
+     * to extract the module name and version (which can be retrieved using
+     * {@link #getName()} and {@link #getVersion()}).
+     * 
+     * @param archiveName the archive name of the module
+     */
+    public void setArchiveName(String archiveName) {
+        int index = 0;
+        // First look for a part that starts with a digit
+        while ((index = archiveName.indexOf('-', index)) != -1) {
+            char c = archiveName.charAt(++index);
+            if ('0' <= c && c <= '9') {
+                break;
+            }
+        }
+        // Also support SNAPSHOT
+        if (index == -1 && archiveName.endsWith("-SNAPSHOT")) {
+            index = archiveName.length()-8;
+        }
+        
+        if (index == -1) {
+            name = archiveName;
+            version = null;
+        } else {
+            try {
+                version = new Version(archiveName.substring(index));
+            } catch (ParseException ex) {
+                version = null;
+            }
+            if (version == null) {
+                name = archiveName;
+            } else {
+                name = archiveName.substring(0, index-1);
+            }
+        }
+    }
+
+    /**
+     * Get the version of this module.
+     * 
+     * @return the version of the module, or <code>null</code> if the module doesn't have a
+     *         version number
+     */
+    public Version getVersion() {
+        return version;
+    }
+
+    /**
+     * Set the version of this module.
+     * 
+     * @param version the version of the module
+     */
+    public void setVersion(Version version) {
+        this.version = version;
+    }
+
     public void addOperation(AxisOperation axisOperation) {
         operations.put(axisOperation.getName(), axisOperation);
     }
@@ -156,14 +246,6 @@
         return moduleClassLoader;
     }
 
-    /**
-     * Get the name of this Module
-     * @return a String name.
-     */
-    public String getName() {
-        return name;
-    }
-
     public HashMap<QName, AxisOperation> getOperations() {
         return operations;
     }
@@ -238,13 +320,6 @@
         this.moduleClassLoader = moduleClassLoader;
     }
 
-    /**
-     * @param name  : Setting name of the module
-     */
-    public void setName(String name) {
-        this.name = name;
-    }
-
     public void setOutFlow(Flow outFlow) {
         flowInclude.setOutFlow(outFlow);
     }
@@ -299,13 +374,4 @@
     public void setFileName(URL fileName) {
         this.fileName = fileName;
     }
-
-
-    public String getVersion() {
-        return version;
-    }
-
-    public void setVersion(String version) {
-        this.version = version;
-    }
 }

Added: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/Version.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/Version.java?rev=777751&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/Version.java (added)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/Version.java Sat May 23 00:23:08 2009
@@ -0,0 +1,164 @@
+/*
+ * 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 org.apache.axis2.description;
+
+import java.io.Serializable;
+import java.text.ParseException;
+import java.util.Arrays;
+
+/**
+ * Class representing a version number and implementing a comparison algorithm compatible
+ * with Maven. This class is primarily used for module versions.
+ */
+public class Version implements Serializable, Comparable<Version> {
+    private static final String S_SNAPSHOT = "SNAPSHOT";
+    
+    public static final Version SNAPSHOT = new Version(null, S_SNAPSHOT);
+    
+    private final int[] components;
+    private final String qualifier;
+    
+    /**
+     * Constructor.
+     * 
+     * @param components the numeric components of the version; may be null for SNAPSHOT version
+     * @param qualifier the qualifier
+     */
+    public Version(int[] components, String qualifier) {
+        this.components = components == null ? null : components.clone();
+        this.qualifier = qualifier;
+    }
+    
+    /**
+     * Constructor that parses the version from a string. The version must have the
+     * following format:
+     * <pre>
+     * integer ( "." integer )* ( "-" qualifier )?
+     * </pre>
+     * 
+     * @param versionString the string representation of the version
+     * @throws ParseException if the version is not in the correct format
+     */
+    public Version(String versionString) throws ParseException {
+        if (versionString.equals(S_SNAPSHOT)) {
+            components = null;
+            qualifier = S_SNAPSHOT;
+        } else {
+            int dashIndex = versionString.indexOf('-');
+            if (dashIndex != -1) {
+                qualifier = versionString.substring(dashIndex + 1);
+                versionString = versionString.substring(0, dashIndex);
+            } else {
+                qualifier = null;
+            }
+            String[] componentStrings = versionString.split("\\.");
+            int l = componentStrings.length;
+            components = new int[l];
+            for (int i=0; i<l; i++) {
+                components[i] = Integer.parseInt(componentStrings[i]);
+            }
+        }
+    }
+    
+    @Override
+    public int hashCode() {
+        return 31*Arrays.hashCode(components) + ((qualifier == null) ? 0 : qualifier.hashCode());
+    }
+    
+    @Override
+    public boolean equals(Object obj) {
+        if (this == obj) {
+            return true;
+        }
+        if (obj instanceof Version) {
+            Version other = (Version)obj;
+            return Arrays.equals(components, other.components)
+                && (qualifier == other.qualifier ||
+                        qualifier != null && qualifier.equals(other.qualifier));
+        } else {
+            return false;
+        }
+    }
+
+    @Override
+    public String toString() {
+        StringBuilder buffer = new StringBuilder();
+        if (components != null) {
+            for (int i=0; i<components.length; i++) {
+                if (i>0) {
+                    buffer.append('.');
+                }
+                buffer.append(components[i]);
+            }
+        }
+        if (qualifier != null) {
+            if (components != null) {
+                buffer.append('-');
+            }
+            buffer.append(qualifier);
+        }
+        return buffer.toString();
+    }
+
+    public int compareTo(Version o) {
+        // components == null means SNAPSHOT and SNAPSHOT is always
+        // assumed to be the most recent version
+        if (components == null && o.components != null) {
+            return 1;
+        } else if (components != null && o.components == null) {
+            return -1;
+        } else if (components == null && o.components == null) {
+            return 0;
+        }
+        // Now compare version components
+        int l = Math.min(components.length, o.components.length);
+        for (int i=0; i<l; i++) {
+            int c = components[i] - o.components[i];
+            if (c != 0) {
+                return c;
+            }
+        }
+        // x.y always comes before x.y.z
+        int c = components.length - o.components.length;
+        if (c != 0) {
+            return c;
+        }
+        // x.y always comes after x.y-qqqqqq
+        if (qualifier == null && o.qualifier != null) {
+            return 1;
+        } else if (qualifier != null && o.qualifier == null) {
+            return -1;
+        } else if (qualifier == null && o.qualifier == null) {
+            return 0;
+        }
+        // x.y-SNAPSHOT comes after any x.y-qqqqqq
+        boolean thisIsSnapshot = qualifier.equals(S_SNAPSHOT);
+        boolean otherIsSnapshot = o.qualifier.equals(S_SNAPSHOT);
+        if (thisIsSnapshot && !otherIsSnapshot) {
+            return 1;
+        } else if (!thisIsSnapshot && thisIsSnapshot) {
+            return -1;
+        } else if (thisIsSnapshot && otherIsSnapshot) {
+            return 0;
+        }
+        // Finally compare the qualifiers using case-insensitive string comparison.
+        return qualifier.compareToIgnoreCase(o.qualifier);
+    }
+}

Propchange: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/Version.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/engine/AxisConfiguration.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/engine/AxisConfiguration.java?rev=777751&r1=777750&r2=777751&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/engine/AxisConfiguration.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/engine/AxisConfiguration.java Sat May 23 00:23:08 2009
@@ -22,6 +22,7 @@
 import java.io.File;
 import java.net.URL;
 import java.security.PrivilegedAction;
+import java.text.ParseException;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.Hashtable;
@@ -55,6 +56,7 @@
 import org.apache.axis2.description.Parameter;
 import org.apache.axis2.description.TransportInDescription;
 import org.apache.axis2.description.TransportOutDescription;
+import org.apache.axis2.description.Version;
 import org.apache.axis2.description.java2wsdl.Java2WSDLConstants;
 import org.apache.axis2.i18n.Messages;
 import org.apache.axis2.phaseresolver.PhaseMetadata;
@@ -80,7 +82,8 @@
     private HashMap<String, String> dataLocatorClassNames = new HashMap<String, String>();
 
     /**
-     * This is a Map of String name -> AxisModule for all available Modules.
+     * Map of all available modules. The key is the archive name as defined by
+     * {@link AxisModule#getArchiveName()}.
      */
     private final HashMap<String, AxisModule> allModules = new HashMap<String, AxisModule>();
 
@@ -232,27 +235,18 @@
         module.setParent(this);
 
         // check whether the module version paramter is there , if so set the module version as that
-        Parameter verisonParamter = module.getParameter(org.apache.axis2.Constants.MODULE_VERSION);
-        if (verisonParamter !=null ) {
-            String version = (String) verisonParamter.getValue();
-            module.setVersion(version);
-        }
-
-        if (module.getVersion() == null) {
-            if (module.getName().endsWith(AxisModule.VERSION_SNAPSHOT)) {
-                allModules.put(module.getName(), module);
-                String moduleName =
-                        module.getName().substring(0,
-                                                   module.getName().indexOf(AxisModule.VERSION_SNAPSHOT) - 1);
-                module.setName(moduleName);
-                module.setVersion(AxisModule.VERSION_SNAPSHOT);
-            } else {
-                allModules.put(module.getName(), module);
+        Parameter versionParameter = module.getParameter(org.apache.axis2.Constants.MODULE_VERSION);
+        if (versionParameter !=null ) {
+            String version = (String) versionParameter.getValue();
+            try {
+                module.setVersion(new Version(version));
+            } catch (ParseException ex) {
+                throw new AxisFault("The version number '" + version + "' specified by the "
+                        + org.apache.axis2.Constants.MODULE_VERSION + " parameter is invalid");
             }
-
-        } else { // Calculate the module version from the name
-            allModules.put(Utils.getModuleName(module.getName(), module.getVersion()), module);
         }
+
+        allModules.put(module.getArchiveName(), module);
         notifyObservers(AxisEvent.MODULE_DEPLOY, module);
 
         // Registering the policy namespaces that the module understand
@@ -294,6 +288,16 @@
     }
 
     /**
+     * Remove a module with moduleName & moduleVersion
+     *
+     * @param moduleName the name of the module to remove
+     * @param moduleVersion the version of the module to remove
+     */
+    public void removeModule(String moduleName, Version moduleVersion) {
+        removeModule(moduleName, moduleVersion.toString());
+    }
+
+    /**
      * Adds module configuration, if there is a moduleConfig tag in service.
      *
      * @param moduleConfiguration a ModuleConfiguration to remember

Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/util/Utils.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/util/Utils.java?rev=777751&r1=777750&r2=777751&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/util/Utils.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/util/Utils.java Sat May 23 00:23:08 2009
@@ -42,6 +42,7 @@
 import org.apache.axis2.description.OutInAxisOperation;
 import org.apache.axis2.description.Parameter;
 import org.apache.axis2.description.PhaseRule;
+import org.apache.axis2.description.Version;
 import org.apache.axis2.description.WSDL2Constants;
 import org.apache.axis2.engine.AxisConfiguration;
 import org.apache.axis2.engine.AxisError;
@@ -57,9 +58,11 @@
 import java.io.File;
 import java.security.AccessController;
 import java.security.PrivilegedAction;
+import java.text.ParseException;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.Enumeration;
+import java.util.Map;
 import java.net.SocketException;
 import java.net.NetworkInterface;
 import java.net.InetAddress;
@@ -286,52 +289,6 @@
         }
     }
 
-    /**
-     * Get the name of the module , where archive name is combination of module name + its version
-     * The format of the name is as follows:
-     * moduleName-00.0000
-     * Example: "addressing-01.0001.mar" would return "addressing"
-     *
-     * @param moduleName the name of the module archive
-     * @return the module name parsed out of the file name
-     */
-    public static String getModuleName(String moduleName) {
-        if (moduleName.endsWith("-SNAPSHOT")) {
-            return moduleName.substring(0, moduleName.indexOf("-SNAPSHOT"));
-        }
-        char delimiter = '-';
-        int version_index = moduleName.lastIndexOf(delimiter);
-        if (version_index > 0) {
-            String versionString = getModuleVersion(moduleName);
-            if (versionString == null) {
-                return moduleName;
-            } else {
-                return moduleName.substring(0, version_index);
-            }
-        } else {
-            return moduleName;
-        }
-    }
-
-    public static String getModuleVersion(String moduleName) {
-        if (moduleName.endsWith("-SNAPSHOT")) {
-            return "SNAPSHOT";
-        }
-        char version_seperator = '-';
-        int version_index = moduleName.lastIndexOf(version_seperator);
-        if (version_index > 0) {
-            String versionString = moduleName.substring(version_index + 1, moduleName.length());
-            try {
-                Float.parseFloat(versionString);
-                return versionString;
-            } catch (NumberFormatException e) {
-                return null;
-            }
-        } else {
-            return null;
-        }
-    }
-
     public static String getModuleName(String moduleName, String moduleVersion) {
         if (moduleVersion != null && moduleVersion.length() != 0) {
             moduleName = moduleName + "-" + moduleVersion;
@@ -344,8 +301,8 @@
      * - else it will return true
      *
      */
-    public static boolean checkVersion(String module1version,
-                                       String module2version) throws AxisFault {
+    public static boolean checkVersion(Version module1version,
+                                       Version module2version) throws AxisFault {
         if ((module1version !=null && !module1version.equals(module2version)) ||
                 module2version !=null && !module2version.equals(module1version)) {
             throw new AxisFault("trying to engage two different module versions " +
@@ -357,61 +314,22 @@
     public static void calculateDefaultModuleVersion(HashMap modules,
                                                      AxisConfiguration axisConfig) {
         Iterator allModules = modules.values().iterator();
-        HashMap defaultModules = new HashMap();
+        Map<String,Version> defaultModules = new HashMap<String,Version>();
         while (allModules.hasNext()) {
             AxisModule axisModule = (AxisModule) allModules.next();
-            String moduleName = axisModule.getName();
-            String moduleNameString;
-            String moduleVersionString;
-            if (AxisModule.VERSION_SNAPSHOT.equals(axisModule.getVersion())) {
-                moduleNameString = axisModule.getName();
-                moduleVersionString = axisModule.getVersion();
-            } else {
-                if (axisModule.getVersion() == null) {
-                    moduleNameString = getModuleName(moduleName);
-                    moduleVersionString = getModuleVersion(moduleName);
-                    if (moduleVersionString != null) {
-                        try {
-                            Float.valueOf(moduleVersionString);
-                            axisModule.setVersion(moduleVersionString);
-                            axisModule.setName(moduleName);
-                        } catch (NumberFormatException e) {
-                            moduleVersionString = null;
-                        }
-                    }
-                } else {
-                    moduleNameString = axisModule.getName();
-                    moduleVersionString = axisModule.getVersion();
-                }
-            }
-            String currentDefaultVerison = (String) defaultModules.get(moduleNameString);
-            if (currentDefaultVerison != null) {
-                // if the module version is null then , that will be ignore in this case
-                if (!AxisModule.VERSION_SNAPSHOT.equals(currentDefaultVerison)) {
-                    if (moduleVersionString != null &&
-                        isLatest(moduleVersionString, currentDefaultVerison)) {
-                        defaultModules.put(moduleNameString, moduleVersionString);
-                    }
-                }
-            } else {
-                defaultModules.put(moduleNameString, moduleVersionString);
+            String name = axisModule.getName();
+            Version currentDefaultVersion = defaultModules.get(name);
+            Version version = axisModule.getVersion();
+            if (currentDefaultVersion == null ||
+                    (version != null && version.compareTo(currentDefaultVersion) > 0)) {
+                defaultModules.put(name, version);
             }
-
         }
         Iterator def_mod_itr = defaultModules.keySet().iterator();
         while (def_mod_itr.hasNext()) {
             String moduleName = (String) def_mod_itr.next();
-            axisConfig.addDefaultModuleVersion(moduleName, (String) defaultModules.get(moduleName));
-        }
-    }
-
-    public static boolean isLatest(String moduleVersion, String currentDefaultVersion) {
-        if (AxisModule.VERSION_SNAPSHOT.equals(moduleVersion)) {
-            return true;
-        } else {
-            float m_version = Float.parseFloat(moduleVersion);
-            float m_c_vresion = Float.parseFloat(currentDefaultVersion);
-            return m_version > m_c_vresion;
+            Version version = defaultModules.get(moduleName);
+            axisConfig.addDefaultModuleVersion(moduleName, version == null ? null : version.toString());
         }
     }
 

Modified: webservices/axis2/trunk/java/modules/kernel/test/org/apache/axis2/deployment/ModuleversionTest.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/test/org/apache/axis2/deployment/ModuleversionTest.java?rev=777751&r1=777750&r2=777751&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/test/org/apache/axis2/deployment/ModuleversionTest.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/test/org/apache/axis2/deployment/ModuleversionTest.java Sat May 23 00:23:08 2009
@@ -45,23 +45,23 @@
     public void testCalculateDefaultModuleVersions() throws AxisFault {
         AxisConfiguration axisConfiguration = new AxisConfiguration();
         AxisModule module1 = new AxisModule();
-        module1.setName("Module1");
+        module1.setArchiveName("Module1");
         axisConfiguration.addModule(module1);
 
         AxisModule module2 = new AxisModule();
-        module2.setName("Module2-0.94");
+        module2.setArchiveName("Module2-0.94");
         axisConfiguration.addModule(module2);
 
         AxisModule module3 = new AxisModule();
-        module3.setName("Module2-0.95");
+        module3.setArchiveName("Module2-0.95");
         axisConfiguration.addModule(module3);
 
         AxisModule module4 = new AxisModule();
-        module4.setName("Module2-0.93");
+        module4.setArchiveName("Module2-0.93");
         axisConfiguration.addModule(module4);
 
         AxisModule module5 = new AxisModule();
-        module5.setName("testModule-1.93");
+        module5.setArchiveName("testModule-1.93");
         axisConfiguration.addModule(module5);
 
         Utils.calculateDefaultModuleVersion(axisConfiguration.getModules(), axisConfiguration);
@@ -77,7 +77,7 @@
         boolean found2 = false;
         boolean found3 = false;
         while (engageModules.hasNext()) {
-            String name = ((AxisModule)engageModules.next()).getName();
+            String name = ((AxisModule)engageModules.next()).getArchiveName();
             if (name.equals("Module2-0.95")) {
                 found1 = true;
             }
@@ -103,15 +103,15 @@
      public void testModuleWithSNAPSHOT() throws AxisFault {
         AxisConfiguration axisConfiguration = new AxisConfiguration();
         AxisModule module1 = new AxisModule();
-        module1.setName("Module1");
+        module1.setArchiveName("Module1");
         axisConfiguration.addModule(module1);
 
         AxisModule module2 = new AxisModule();
-        module2.setName("Module1-SNAPSHOT");
+        module2.setArchiveName("Module1-SNAPSHOT");
         axisConfiguration.addModule(module2);
 
         AxisModule module3 = new AxisModule();
-        module3.setName("Module1-0.95");
+        module3.setArchiveName("Module1-0.95");
         axisConfiguration.addModule(module3);
         Utils.calculateDefaultModuleVersion(axisConfiguration.getModules(), axisConfiguration);
         assertEquals(module2, axisConfiguration.getDefaultModule("Module1"));
@@ -121,15 +121,15 @@
      public void testModuleWithSNAPSHOT2() throws AxisFault {
         AxisConfiguration axisConfiguration = new AxisConfiguration();
         AxisModule module1 = new AxisModule();
-        module1.setName("Module1-a");
+        module1.setArchiveName("Module1-a");
         axisConfiguration.addModule(module1);
 
         AxisModule module2 = new AxisModule();
-        module2.setName("Module1-a-SNAPSHOT");
+        module2.setArchiveName("Module1-a-SNAPSHOT");
         axisConfiguration.addModule(module2);
 
         AxisModule module3 = new AxisModule();
-        module3.setName("Module1-a-0.95");
+        module3.setArchiveName("Module1-a-0.95");
         axisConfiguration.addModule(module3);
         Utils.calculateDefaultModuleVersion(axisConfiguration.getModules(), axisConfiguration);
         Utils.calculateDefaultModuleVersion(axisConfiguration.getModules(), axisConfiguration);

Added: webservices/axis2/trunk/java/modules/kernel/test/org/apache/axis2/description/VersionTest.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/test/org/apache/axis2/description/VersionTest.java?rev=777751&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/test/org/apache/axis2/description/VersionTest.java (added)
+++ webservices/axis2/trunk/java/modules/kernel/test/org/apache/axis2/description/VersionTest.java Sat May 23 00:23:08 2009
@@ -0,0 +1,88 @@
+/*
+ * 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 org.apache.axis2.description;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import junit.framework.TestCase;
+
+public class VersionTest extends TestCase {
+    private static final String[] testVersionSequence = {
+        "0.1",
+        "0.2",
+        "1.0",
+        "1.1-beta1",
+        "1.1-beta2",
+        "1.1-RC1",
+        "1.1-RC2",
+        "1.1-SNAPSHOT",
+        "1.1",
+        "1.1.1",
+        "1.1.2",
+        "1.2",
+        "SNAPSHOT"
+    };
+    
+    private static int sign(int v) {
+        if (v < 0) {
+            return -1;
+        } else if (v > 0) {
+            return 1;
+        } else {
+            return 0;
+        }
+    }
+    
+    public void testCompareTo() throws Exception {
+        for (int i1=0; i1<testVersionSequence.length; i1++) {
+            for (int i2=0; i2<testVersionSequence.length; i2++) {
+                Version v1 = new Version(testVersionSequence[i1]);
+                Version v2 = new Version(testVersionSequence[i2]);
+                assertEquals(v1 + " vs. " + v2, sign(i1-i2), sign(v1.compareTo(v2)));
+            }
+        }
+    }
+    
+    public void testToString() throws Exception {
+        for (int i=0; i<testVersionSequence.length; i++) {
+            assertEquals(testVersionSequence[i], new Version(testVersionSequence[i]).toString());
+        }
+    }
+    
+    public void testEquals() throws Exception {
+        for (int i1=0; i1<testVersionSequence.length; i1++) {
+            for (int i2=0; i2<testVersionSequence.length; i2++) {
+                Version v1 = new Version(testVersionSequence[i1]);
+                Version v2 = new Version(testVersionSequence[i2]);
+                assertEquals(v1 + " vs. " + v2, i1 == i2, v1.equals(v2));
+            }
+        }
+    }
+    
+    public void testHashCode() throws Exception {
+        Set<Integer> values = new HashSet<Integer>();
+        for (int i=0; i<testVersionSequence.length; i++) {
+            values.add(new Version(testVersionSequence[i]).hashCode());
+        }
+        // Check that the collision frequency is less than 10%
+        assertTrue(values.size() > testVersionSequence.length*9/10);
+    }
+}

Propchange: webservices/axis2/trunk/java/modules/kernel/test/org/apache/axis2/description/VersionTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: webservices/axis2/trunk/java/modules/osgi/src/org/apache/axis2/osgi/deployment/ModuleRegistry.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/osgi/src/org/apache/axis2/osgi/deployment/ModuleRegistry.java?rev=777751&r1=777750&r2=777751&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/osgi/src/org/apache/axis2/osgi/deployment/ModuleRegistry.java (original)
+++ webservices/axis2/trunk/java/modules/osgi/src/org/apache/axis2/osgi/deployment/ModuleRegistry.java Sat May 23 00:23:08 2009
@@ -24,6 +24,7 @@
 import org.apache.axis2.description.AxisOperation;
 import org.apache.axis2.description.AxisService;
 import org.apache.axis2.description.AxisServiceGroup;
+import org.apache.axis2.description.Version;
 import org.apache.axis2.engine.AxisConfiguration;
 import org.apache.axis2.modules.Module;
 import static org.apache.axis2.osgi.deployment.OSGiAxis2Constants.OSGi_BUNDLE_ID;
@@ -169,7 +170,6 @@
                     }
                     String bundleVersion = (String) headers.get("Bundle-Version");
                     if (bundleVersion != null && bundleVersion.length() != 0) {
-                        String moduleVersion = "SNAPSHOT";
                         /*
                             Bundle version is defined as
                             version ::=
@@ -178,21 +178,14 @@
                                 minor ::= number
                                 micro ::= number
                                 qualifier ::= ( alphanum | ’_’ | '-' )+
-
-                            Hence, in order to sync up with Axis2 module versioning, which is a floating
-                            point number, following logic is used to create the version
-                            version := major(.minormircor)
                          */
                         String[] versionSplit = bundleVersion.split("\\.");
-                        if (versionSplit.length == 3) {
-                            moduleVersion =
-                                    versionSplit[0] + "." + versionSplit[1] + versionSplit[2];
-                        } else if (versionSplit.length == 2) {
-                            moduleVersion = versionSplit[0] + "." + versionSplit[1];
-                        } else if (versionSplit.length == 1) {
-                            moduleVersion = versionSplit[0];
+                        int[] components = new int[Math.min(versionSplit.length, 3)];
+                        for (int i=0; i<components.length; i++) {
+                            components[i] = Integer.parseInt(versionSplit[i]);
                         }
-                        axismodule.setVersion(moduleVersion);
+                        axismodule.setVersion(new Version(components, versionSplit.length > 3 ?
+                                versionSplit[3] : null));
                     }
                     builder.populateModule();
                     axismodule.setParent(axisConfig);