Interesting...

-> richard

On Aug 14, 2007, at 7:13 PM, [EMAIL PROTECTED] wrote:

Author: donsez
Date: Tue Aug 14 16:13:17 2007
New Revision: 565965

URL: http://svn.apache.org/viewvc?view=rev&rev=565965
Log:
creation of the bundle urlhandler.maven

The Maven URLHandler looks for bundles jar files located in the local Maven repository. This URLHandler enables to write deployment scripts insensible to version change.

Added:
    felix/sandbox/donsez/urlhandler.maven/
    felix/sandbox/donsez/urlhandler.maven/README.txt   (with props)
    felix/sandbox/donsez/urlhandler.maven/pom.xml   (with props)
    felix/sandbox/donsez/urlhandler.maven/src/
    felix/sandbox/donsez/urlhandler.maven/src/main/
    felix/sandbox/donsez/urlhandler.maven/src/main/java/
    felix/sandbox/donsez/urlhandler.maven/src/main/java/org/
    felix/sandbox/donsez/urlhandler.maven/src/main/java/org/apache/
felix/sandbox/donsez/urlhandler.maven/src/main/java/org/apache/felix/ felix/sandbox/donsez/urlhandler.maven/src/main/java/org/apache/felix/ sandbox/ felix/sandbox/donsez/urlhandler.maven/src/main/java/org/apache/felix/ sandbox/urlhandler/ felix/sandbox/donsez/urlhandler.maven/src/main/java/org/apache/felix/ sandbox/urlhandler/maven/ felix/sandbox/donsez/urlhandler.maven/src/main/java/org/apache/felix/ sandbox/urlhandler/maven/MavenURLStreamHandlerService.java (with props) felix/sandbox/donsez/urlhandler.maven/src/main/java/org/apache/felix/ sandbox/util/ felix/sandbox/donsez/urlhandler.maven/src/main/java/org/apache/felix/ sandbox/util/MavenCompliantVersion.java (with props) felix/sandbox/donsez/urlhandler.maven/src/main/java/org/apache/felix/ sandbox/util/Version.java (with props)
    felix/sandbox/donsez/urlhandler.maven/src/site/
felix/sandbox/donsez/urlhandler.maven/src/site/script.txt (with props)
    felix/sandbox/donsez/urlhandler.maven/src/test/
    felix/sandbox/donsez/urlhandler.maven/src/test/java/
    felix/sandbox/donsez/urlhandler.maven/src/test/java/org/
    felix/sandbox/donsez/urlhandler.maven/src/test/java/org/apache/
felix/sandbox/donsez/urlhandler.maven/src/test/java/org/apache/felix/ felix/sandbox/donsez/urlhandler.maven/src/test/java/org/apache/felix/ sandbox/ felix/sandbox/donsez/urlhandler.maven/src/test/java/org/apache/felix/ sandbox/urlhandler/ felix/sandbox/donsez/urlhandler.maven/src/test/java/org/apache/felix/ sandbox/urlhandler/maven/ felix/sandbox/donsez/urlhandler.maven/src/test/java/org/apache/felix/ sandbox/urlhandler/maven/test/ felix/sandbox/donsez/urlhandler.maven/src/test/java/org/apache/felix/ sandbox/urlhandler/maven/test/MavenURLStreamHandlerServiceTest.java (with props) felix/sandbox/donsez/urlhandler.maven/src/test/java/org/apache/felix/ sandbox/util/ felix/sandbox/donsez/urlhandler.maven/src/test/java/org/apache/felix/ sandbox/util/test/ felix/sandbox/donsez/urlhandler.maven/src/test/java/org/apache/felix/ sandbox/util/test/MavenCompliantVersionTest.java (with props)

Added: felix/sandbox/donsez/urlhandler.maven/README.txt
URL: http://svn.apache.org/viewvc/felix/sandbox/donsez/urlhandler.maven/ README.txt?view=auto&rev=565965 ======================================================================= =======
--- felix/sandbox/donsez/urlhandler.maven/README.txt (added)
+++ felix/sandbox/donsez/urlhandler.maven/README.txt Tue Aug 14 16:13:17 2007
@@ -0,0 +1,29 @@
+Apache Felix Maven URLHandler
+Author: Didier Donsez
+
+
+The Maven URLHandler looks for (bundles) jar files located in the local Maven repository. +This URLHandler enables to write deployment scripts insensible to version change.
+
+
+URL schema samples:
+
+mvn:<groupId>:<artifactId>:<version>
+       the version of the artifact
+
+mvn:<groupId>:<artifactId>
+       the higher version of the artifact
+
+mvn:<groupId>:<artifactId>:(<regexpOnVersion>)
+ the higher version of the artifact that match the regular expression. Can be use to exclude snapshots, ...
+
+mvn:<groupId>:<artifactId>:<version>@<alternativeRepositoryRootURL>
+       the version of the artifact in a remote repository
+
+
+The default local repository is file:C:\Docume~1\${user.name}\.m2\repository\ (under Windows)
+
+TODOLIST
+--------
+* use Maven Archiva for updating the local cache ...
+

Propchange: felix/sandbox/donsez/urlhandler.maven/README.txt
----------------------------------------------------------------------- -------
    svn:eol-style = native

Added: felix/sandbox/donsez/urlhandler.maven/pom.xml
URL: http://svn.apache.org/viewvc/felix/sandbox/donsez/urlhandler.maven/ pom.xml?view=auto&rev=565965 ======================================================================= =======
--- felix/sandbox/donsez/urlhandler.maven/pom.xml (added)
+++ felix/sandbox/donsez/urlhandler.maven/pom.xml Tue Aug 14 16:13:17 2007
@@ -0,0 +1,126 @@
+<!--
+ 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.
+-->
+<project>
+
+       <properties>
+ <repositoryLocation>http://www.apache.org/~donsez/dev/felix/</ repositoryLocation> + <description>provides a URLHandler to located bundle jarfiles in the local Maven reposity</description>
+       </properties>
+
+  <parent>
+    <groupId>org.apache.felix</groupId>
+    <artifactId>felix</artifactId>
+    <version>0.9.0-incubator-SNAPSHOT</version>
+  </parent>
+  <modelVersion>4.0.0</modelVersion>
+  <packaging>bundle</packaging>
+  <name>Apache Felix Maven URLHandler</name>
+  <artifactId>org.apache.felix.sandbox.urlhandler.maven</artifactId>
+  <description>${description}</description>
+  <dependencies>
+
+    <dependency>
+      <groupId>${pom.groupId}</groupId>
+      <artifactId>org.osgi.core</artifactId>
+      <version>${pom.version}</version>
+    </dependency>
+    <dependency>
+      <groupId>${pom.groupId}</groupId>
+      <artifactId>org.osgi.compendium</artifactId>
+      <version>${pom.version}</version>
+    </dependency>
+
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <version>3.8.1</version>
+      <scope>test</scope>
+    </dependency>
+
+
+  </dependencies>
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.felix</groupId>
+        <artifactId>maven-bundle-plugin</artifactId>
+        <extensions>true</extensions>
+        <configuration>
+          <instructions>
+
+ <!-- docs in http://cwiki.apache.org/FELIX/bundle-plugin-for-maven-bnd.html and http://cwiki.apache.org/FELIX/osgi-plugin-for-maven-2.html -->
+               
+            <Import-Package>*</Import-Package>
+ <Private-Package>${pom.artifactId},org.apache.felix.sandbox.util</ Private-Package>
+
+ <Export-Service>org.osgi.service.url.URLStreamHandlerService</Export- Service>
+
+ <Bundle-Activator>${pom.artifactId}.MavenURLStreamHandlerService</ Bundle-Activator>
+
+            <!--
+ <Bundle-DocURL>${repositoryLocation}${pom.artifactId}/index.html</ Bundle-DocURL> + <Bundle-Url>${repositoryLocation}${pom.artifactId}/${pom.artifactId}- ${pom.version}.jar</Bundle-Url> + <Bundle-Source>${repositoryLocation}${pom.artifactId}/ ${pom.artifactId}-${pom.version}-src.jar</Bundle-Source>
+                       -->
+
+            <!-- for experiment with OBR and Maven -->
+ <Maven-URL>mvn:${pom.groupId}:${pom.artifactId}:${pom.version}</Maven- URL>
+
+          </instructions>
+        </configuration>
+      </plugin>
+
+    </plugins>
+  </build>
+
+  <reporting>
+       <plugins>
+      <plugin>
+        <groupId>org.codehaus.mojo</groupId>
+               <artifactId>taglist-maven-plugin</artifactId>
+               <configuration>
+                       <tags>
+                               <tag>TODO</tag>
+                               <tag>@todo</tag>
+                               <tag>FIXME</tag>
+                               <tag>XXX</tag>
+                               <tag>CHECKME</tag>
+                       </tags>
+               </configuration>                  
+         </plugin>
+    </plugins>
+  </reporting>
+
+  <!--
+  <repositories>
+    <repository>
+      <id>apache.m2.incubator</id>
+      <name>Apache M2 Incubator Repository</name>
+ <url>http://people.apache.org/repo/m2-incubating-repository/</url>
+    </repository>
+  </repositories>
+  <pluginRepositories>
+    <pluginRepository>
+      <id>apache.m2.incubator</id>
+      <name>Apache M2 Incubator Repository</name>
+ <url>http://people.apache.org/repo/m2-incubating-repository/</url>
+    </pluginRepository>
+  </pluginRepositories>
+  -->
+</project>

Propchange: felix/sandbox/donsez/urlhandler.maven/pom.xml
----------------------------------------------------------------------- -------
    svn:eol-style = native

Added: felix/sandbox/donsez/urlhandler.maven/src/main/java/org/apache/felix/ sandbox/urlhandler/maven/MavenURLStreamHandlerService.java URL: http://svn.apache.org/viewvc/felix/sandbox/donsez/urlhandler.maven/ src/main/java/org/apache/felix/sandbox/urlhandler/maven/ MavenURLStreamHandlerService.java?view=auto&rev=565965 ======================================================================= ======= --- felix/sandbox/donsez/urlhandler.maven/src/main/java/org/apache/felix/ sandbox/urlhandler/maven/MavenURLStreamHandlerService.java (added) +++ felix/sandbox/donsez/urlhandler.maven/src/main/java/org/apache/felix/ sandbox/urlhandler/maven/MavenURLStreamHandlerService.java Tue Aug 14 16:13:17 2007
@@ -0,0 +1,201 @@
+/*
+ * 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.felix.sandbox.urlhandler.maven;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.net.URLConnection;
+import java.util.Dictionary;
+import java.util.Hashtable;
+import java.util.StringTokenizer;
+import java.util.regex.Pattern;
+import java.util.regex.PatternSyntaxException;
+
+import org.apache.felix.sandbox.util.MavenCompliantVersion;
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceRegistration;
+import org.osgi.service.url.AbstractURLStreamHandlerService;
+import org.osgi.service.url.URLConstants;
+
+/**
+ * this class provides a URLHandler to located bundle jarfiles in the local Maven reposity. + * @author <a href="mailto:[email protected]";>Felix Project Team</a>
+ */
+
+public class MavenURLStreamHandlerService extends AbstractURLStreamHandlerService
+    implements BundleActivator
+{
+       public String MAVEN_URL_HANDLER_PROTOCOL="mvn";
+       
+    private BundleContext bundleContext;
+    private ServiceRegistration serviceRegistration;
+       /**
+ * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleConte xt)
+     */
+    public void start(BundleContext context) throws Exception
+    {
+       bundleContext=context;
+        Dictionary prop = new Hashtable();
+ prop.put(URLConstants.URL_HANDLER_PROTOCOL, new String[] { MAVEN_URL_HANDLER_PROTOCOL });
+        serviceRegistration=context.registerService(
+ org.osgi.service.url.URLStreamHandlerService.class.getName(), this, prop);
+    }
+
+    /**
+ * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContex t)
+     */
+    public void stop(BundleContext context) throws Exception
+    {
+       serviceRegistration.unregister();
+    }
+
+
+    /**
+ * @see org.osgi.service.url.AbstractURLStreamHandlerService#openConnection(jav a.net.URL)
+     */
+    public URLConnection openConnection(URL u) throws IOException
+    {
+        return openConnection(u.toString());
+    }
+
+    /**
+     * for unit testing purpose only
+ * since the url handler must be registered at runtime by the osgi framework
+     */
+ public URLConnection openConnection(String urlstr) throws IOException
+    {
+       String alternativeRepositoryField=null;
+       int index=urlstr.indexOf("@");
+       if(index>=0) {
+               if(index+1==urlstr.length()) {
+ throw new MalformedURLException(urlstr+" syntax is incorrect");
+               }       
+               alternativeRepositoryField=urlstr.substring(index+1);
+               urlstr=urlstr.substring(0,index);
+       }
+       
+       // translate the mvn url in file url
+       
+       StringTokenizer st=new StringTokenizer(urlstr,":");
+       int countTokens=st.countTokens();
+       if(countTokens!=3 && countTokens!=4) {
+               throw new MalformedURLException(urlstr+" syntax is incorrect"); 
      
+       }
+       st.nextToken(); // discard mvn
+       String groupId=st.nextToken();
+       String artifactId=st.nextToken();
+       String versionStr=null;
+       Pattern versionPattern = null;
+       
+       
+       if(countTokens==4) {
+               versionStr=st.nextToken();
+               if(versionStr.startsWith("(")){
+                       // the version string is a reg exp on artifact version
+                       try {
+                               versionPattern=Pattern.compile(versionStr);
+                       } catch (PatternSyntaxException e){
+ throw new MalformedURLException("version regexp in " + urlstr+" is incorrect");
+                       }
+               }
+       }
+       
+ // TODO check for a new version to the remote repository !! may be use the Maven Archiva
+
+       String artifactRootUrlStr=null;
+
+       if(alternativeRepositoryField!=null) {
+               artifactRootUrlStr=alternativeRepositoryField
+ +(alternativeRepositoryField.endsWith(""+File.separatorChar)?"":""+File .separatorChar)
+                       +groupId.replace('.', 
File.separatorChar)+File.separatorChar
+                       +artifactId;
+                       if(countTokens==3 || versionPattern!=null){
+                       // TODO may be use the Maven Archiva
+                       // TODO list files in the url started by file:
+ throw new IOException("Can not get the higher version in the repository "+alternativeRepositoryField);
+                       }
+               
+       } else {
+               String mavenRepositoryRootDir;
+ if(System.getProperty("os.name").toLowerCase().startsWith("win")){ // bundleContext.getProperty(Constants.FRAMEWORK_OS_NAME) + mavenRepositoryRootDir="C: \\Docume~1\\"+System.getProperty("user.name")+"\\.m2\\repository\\";
+               } else {
+ mavenRepositoryRootDir=System.getProperty("user.dir")+"/.m2/ repository/";
+               }
+               String artifactRootDirStr=mavenRepositoryRootDir
+                                                                               
+groupId.replace('.', File.separatorChar)+File.separatorChar
+                                                                               
+artifactId;
+                       if(countTokens==3 || versionPattern!=null){
+                               // find the higher version that matches with 
the regexp
+                               File artifactRootDir=new 
File(artifactRootDirStr);
+                               if(artifactRootDir.isDirectory()){
+                                       File 
files[]=artifactRootDir.listFiles();
+                                       
+                                       MavenCompliantVersion 
higherVersion=null;
+                                       for (int i = 0; i < files.length; i++) {
+                                               File file = files[i];
+                                               if(!file.isDirectory()) 
continue;
+                                               String filename=file.getName();
+ if(versionPattern!=null && !versionPattern.matcher(filename).matches()){
+                                                       continue;       
+                                               }
+                                               try {
+ // TODO OSGi version could not parser versions terminated by (.+(\\-incubator)?\\-SNAPSHOT$) + MavenCompliantVersion currentVersion=new MavenCompliantVersion(filename);
+                                                       if(higherVersion==null) 
{
+                                                               
higherVersion=currentVersion;                                                   
+                                                       } else {
+                                                               int 
res=currentVersion.compareTo(higherVersion);
+                                                               if(res>0) {
+                                                                       
higherVersion=currentVersion;
+                                                               }
+                                                       }               
+                                               } catch 
(java.lang.IllegalArgumentException  e) {
+                                                       continue;
+                                               }               
+                                       }
+                                       if(higherVersion!=null)
+                                               
versionStr=higherVersion.toString();
+                                       else
+ throw new IOException("No version matches the regexp "+versionPattern);
+                               } else {
+                                       throw new IOException(artifactRootDir+" is 
not a directory");
+                               }
+                       }
+                       artifactRootUrlStr="file:"+artifactRootDirStr;
+       }
+               
+               String translatedUrlStr=artifactRootUrlStr+File.separatorChar
+                                                               
+versionStr+File.separatorChar
+                                                               
+artifactId+'-'+versionStr+".jar";
+               
+               if(translatedUrlStr.startsWith("http:")) {
+                       
translatedUrlStr=translatedUrlStr.replace(File.separatorChar, '/');
+               }
+               
+               //System.err.println(translatedUrlStr);
+               
+       URL translatedUrl=new URL(translatedUrlStr);
+               return translatedUrl.openConnection();
+
+    }
+}
\ No newline at end of file

Propchange: felix/sandbox/donsez/urlhandler.maven/src/main/java/org/apache/felix/ sandbox/urlhandler/maven/MavenURLStreamHandlerService.java ----------------------------------------------------------------------- -------
    svn:eol-style = native

Added: felix/sandbox/donsez/urlhandler.maven/src/main/java/org/apache/felix/ sandbox/util/MavenCompliantVersion.java URL: http://svn.apache.org/viewvc/felix/sandbox/donsez/urlhandler.maven/ src/main/java/org/apache/felix/sandbox/util/ MavenCompliantVersion.java?view=auto&rev=565965 ======================================================================= ======= --- felix/sandbox/donsez/urlhandler.maven/src/main/java/org/apache/felix/ sandbox/util/MavenCompliantVersion.java (added) +++ felix/sandbox/donsez/urlhandler.maven/src/main/java/org/apache/felix/ sandbox/util/MavenCompliantVersion.java Tue Aug 14 16:13:17 2007
@@ -0,0 +1,196 @@
+/*
+ * 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.felix.sandbox.util;
+
+import org.osgi.framework.Version;
+
+/**
+ * Version identifier for Maven artifacts.
+ * This class reuses for the moment the comparison methods of the org.osgi.framework.Version
+ *
+ * <p>
+ * Version identifiers have four components.
+ * <ol>
+ * <li>Major version. A non-negative integer.</li>
+ * <li>Minor version. A non-negative integer.</li>
+ * <li>Micro version. A non-negative integer.</li>
+ * <li>Qualifier. A text string. See <code>MavenCompliantVersion(String)</code> for the
+ * format of the qualifier string.</li>
+ * </ol>
+ *
+ * <p>
+ * <code>MavenCompliantVersion</code> objects are immutable.
+ *
+ * @author <a href="mailto:[email protected]";>Felix Project Team</a>
+ * @version $Revision$
+ * $Id$
+ */
+
+public class MavenCompliantVersion implements Comparable {
+       private Version                 version;
+       private static final String     SEPARATOR               = ".";
+
+       /**
+        * Created a version identifier from the specified string.
+        *
+        * <p>
+        * Here is the grammar for version strings.
+        *
+        * <pre>
+        * version ::= major('.'minor('.'micro(qualifier)?)?)?
+        * major ::= digit+
+        * minor ::= digit+
+        * micro ::= digit+
+        * qualifier ::= (alpha|'_'|'-')(alpha|digit|'_'|'-')*
+        * digit ::= [0..9]
+        * alpha ::= [a..zA..Z]
+        * </pre>
+        *
+        * There must be no whitespace in version.
+        *
+        * @param versionStr String representation of the version identifier.
+ * @throws IllegalArgumentException If <code>version</code> is improperly
+        *         formatted.
+        */
+       public MavenCompliantVersion(String versionStr) {
+               int major = 0;
+               int minor = 0;
+               int micro = 0;
+               String qualifier = "";
+
+               try {
+                       int sep1=versionStr.indexOf(SEPARATOR);
+                       if(sep1<0) {
+                               major = Integer.parseInt(versionStr);
+                       } else if (sep1>0 ){
+                               major = 
Integer.parseInt(versionStr.substring(0, sep1));
+                               
+                               int sep2=versionStr.indexOf(SEPARATOR,sep1+1);
+                               if(sep2<0) {
+                                       minor = 
Integer.parseInt(versionStr.substring(sep1+1));
+                               } else if (sep2>0 ){
+                                       minor = 
Integer.parseInt(versionStr.substring(sep1+1, sep2));
+
+                                       int sep3=sep2+1;
+                                       for(;sep3<versionStr.length();sep3++){
+                                               
if(!Character.isDigit(versionStr.charAt(sep3))){
+                                                       break;
+                                               }
+                                       }
+                                       
+                                       if(sep3<versionStr.length()) {
+                                               micro = 
Integer.parseInt(versionStr.substring(sep2+1,sep3));
+                                               
qualifier=versionStr.substring(sep3);
+                                       } else {
+                                               micro = 
Integer.parseInt(versionStr.substring(sep2+1));                                 
        
+                                       }
+                               } else {
+                                       throw new IllegalArgumentException("invalid 
format");
+                               }
+                               
+                       } else {
+                               throw new IllegalArgumentException("invalid 
format");
+                       }
+               }
+               catch (NumberFormatException e) {
+                       throw new IllegalArgumentException("invalid format");
+               }
+               
+               version=new Version(major,minor,micro,qualifier);
+               return;
+
+       }
+
+       /**
+        * Returns the string representation of this version identifier.
+        *
+        * <p>
+ * The format of the version string will be <code>major.minor.micro</code>
+        * if qualifier is the empty string or
+        * <code>major.minor.microqualifier</code> otherwise.
+        *
+        * @return The string representation of this version identifier.
+        */
+       public String toString() {
+ String base = version.getMajor() + SEPARATOR + version.getMinor() + SEPARATOR + version.getMicro();
+               if (version.getQualifier().length() == 0) {
+                       return base;
+               }
+               else {
+                       return base + version.getQualifier();
+               }
+       }
+
+       /**
+        * Returns a hash code value for the object.
+        *
+        * @return An integer which is a hash code value for this object.
+        */
+       public int hashCode() {
+               return version.hashCode();
+       }
+
+       /**
+        * for equals and compareTo methods
+        * @return the version
+        */
+       private Version getVersion() {
+               return version;
+       }
+       
+       /**
+ * Compares this <code>MavenCompliantVersion</code> object to another object.
+        *       *
+ * @param object The <code>MavenCompliantVersion</code> object to be compared.
+        * @return <code>true</code> if <code>object</code> is a
+ * <code>MavenCompliantVersion</code> and is equal to this object;
+        *         <code>false</code> otherwise.
+        */
+       public boolean equals(Object object) {
+               if (object == this) { // quicktest
+                       return true;
+               }
+
+               if (!(object instanceof MavenCompliantVersion)) {
+                       return false;
+               }
+
+               MavenCompliantVersion other = (MavenCompliantVersion) object;
+               return version.equals(other.getVersion());
+       }
+
+       /**
+ * Compares this <code>MavenCompliantVersion</code> object to another object.
+        *
+ * @param object The <code>MavenCompliantVersion</code> object to be compared. + * @return A negative integer, zero, or a positive integer if this object is
+        *         less than, equal to, or greater than the specified
+        *         <code>MavenCompliantVersion</code> object.
+        * @throws ClassCastException If the specified object is not a
+        *         <code>MavenCompliantVersion</code>.
+        */
+       public int compareTo(Object object) {
+               if (object == this) { // quicktest
+                       return 0;
+               }
+               MavenCompliantVersion other = (MavenCompliantVersion) object;
+ return version.compareTo(other.getVersion()); // TODO do something special for comparison of 1.0.0 with 1.0.0-rc1, 1.0.0-rc2, 1.0.0-SNAPSHOT, ...
+       }
+}

Propchange: felix/sandbox/donsez/urlhandler.maven/src/main/java/org/apache/felix/ sandbox/util/MavenCompliantVersion.java ----------------------------------------------------------------------- -------
    svn:eol-style = native

Added: felix/sandbox/donsez/urlhandler.maven/src/main/java/org/apache/felix/ sandbox/util/Version.java URL: http://svn.apache.org/viewvc/felix/sandbox/donsez/urlhandler.maven/ src/main/java/org/apache/felix/sandbox/util/Version.java? view=auto&rev=565965 ======================================================================= ======= --- felix/sandbox/donsez/urlhandler.maven/src/main/java/org/apache/felix/ sandbox/util/Version.java (added) +++ felix/sandbox/donsez/urlhandler.maven/src/main/java/org/apache/felix/ sandbox/util/Version.java Tue Aug 14 16:13:17 2007
@@ -0,0 +1,366 @@
+/*
+ * $Header: /cvshome/build/org.osgi.framework/src/org/osgi/framework/ Version.java,v 1.16 2006/06/16 16:31:18 hargrave Exp $
+ *
+ * Copyright (c) OSGi Alliance (2004, 2006). All Rights Reserved.
+ *
+ * Licensed 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.felix.sandbox.util;
+
+import java.util.NoSuchElementException;
+import java.util.StringTokenizer;
+
+/**
+ * Version identifier for bundles and packages.
+ *
+ * <p>
+ * Version identifiers have four components.
+ * <ol>
+ * <li>Major version. A non-negative integer.</li>
+ * <li>Minor version. A non-negative integer.</li>
+ * <li>Micro version. A non-negative integer.</li>
+ * <li>Qualifier. A text string. See <code>Version(String)</code> for the
+ * format of the qualifier string.</li>
+ * </ol>
+ *
+ * <p>
+ * <code>Version</code> objects are immutable.
+ *
+ * @version $Revision: 1.16 $
+ * @since 1.3
+ */
+
+public class Version implements Comparable {
+       private final int                       major;
+       private final int                       minor;
+       private final int                       micro;
+       private final String            qualifier;
+       private static final String     SEPARATOR               = ".";          
                              //$NON-NLS-1$
+
+       /**
+        * The empty version "0.0.0". Equivalent to calling
+        * <code>new Version(0,0,0)</code>.
+        */
+       public static final Version     emptyVersion    = new Version(0, 0, 0);
+
+       /**
+ * Creates a version identifier from the specified numerical components.
+        *
+        * <p>
+        * The qualifier is set to the empty string.
+        *
+        * @param major Major component of the version identifier.
+        * @param minor Minor component of the version identifier.
+        * @param micro Micro component of the version identifier.
+        * @throws IllegalArgumentException If the numerical components are
+        *         negative.
+        */
+       public Version(int major, int minor, int micro) {
+               this(major, minor, micro, null);
+       }
+
+       /**
+        * Creates a version identifier from the specifed components.
+        *
+        * @param major Major component of the version identifier.
+        * @param minor Minor component of the version identifier.
+        * @param micro Micro component of the version identifier.
+        * @param qualifier Qualifier component of the version identifier. If
+ * <code>null</code> is specified, then the qualifier will be set
+        *        to the empty string.
+ * @throws IllegalArgumentException If the numerical components are negative
+        *         or the qualifier string is invalid.
+        */
+       public Version(int major, int minor, int micro, String qualifier) {
+               if (qualifier == null) {
+                       qualifier = ""; //$NON-NLS-1$
+               }
+
+               this.major = major;
+               this.minor = minor;
+               this.micro = micro;
+               this.qualifier = qualifier;
+               //validate();
+       }
+
+       /**
+        * Created a version identifier from the specified string.
+        *
+        * <p>
+        * Here is the grammar for version strings.
+        *
+        * <pre>
+        * version ::= major('.'minor('.'micro(qualifier)?)?)?
+        * major ::= digit+
+        * minor ::= digit+
+        * micro ::= digit+
+        * qualifier ::= (alpha|'_'|'-')(alpha|digit|'_'|'-')*
+        * digit ::= [0..9]
+        * alpha ::= [a..zA..Z]
+        * </pre>
+        *
+        * There must be no whitespace in version.
+        *
+        * @param version String representation of the version identifier.
+ * @throws IllegalArgumentException If <code>version</code> is improperly
+        *         formatted.
+        */
+       public Version(String version) {
+               int major = 0;
+               int minor = 0;
+               int micro = 0;
+               String qualifier = ""; //$NON-NLS-1$
+
+               try {
+                       int sep1=version.indexOf(SEPARATOR);
+                       if(sep1<0) {
+                               major = Integer.parseInt(version);
+                       } else if (sep1>0 ){
+                               major = Integer.parseInt(version.substring(0, 
sep1));
+                               
+                               int sep2=version.indexOf(SEPARATOR,sep1+1);
+                               if(sep2<0) {
+                                       minor = 
Integer.parseInt(version.substring(sep1+1));
+                               } else if (sep2>0 ){
+                                       minor = 
Integer.parseInt(version.substring(sep1+1, sep2));
+
+                                       int sep3=sep2+1;
+                                       for(;sep3<version.length();sep3++){
+                                               
if(!Character.isDigit(version.charAt(sep3))){
+                                                       break;
+                                               }
+                                       }
+                                       
+                                       if(sep3<version.length()) {
+                                               micro = 
Integer.parseInt(version.substring(sep2+1,sep3));
+                                               
qualifier=version.substring(sep3);
+                                       } else {
+                                               micro = 
Integer.parseInt(version.substring(sep2+1));                                    
        
+                                       }
+                               } else {
+                                       throw new IllegalArgumentException("invalid 
format");
+                               }
+                               
+                       } else {
+                               throw new IllegalArgumentException("invalid 
format");
+                       }
+               }
+               catch (NumberFormatException e) {
+                       throw new IllegalArgumentException("invalid format");
+               }
+               
+               this.major = major;
+               this.minor = minor;
+               this.micro = micro;
+               this.qualifier = qualifier;
+               validate();
+               return;
+
+       }
+
+       /**
+ * Called by the Version constructors to validate the version components.
+        *
+ * @throws IllegalArgumentException If the numerical components are negative
+        *         or the qualifier string is invalid.
+        */
+       private void validate() {
+               if (major < 0) {
+                       throw new IllegalArgumentException("negative major"); 
//$NON-NLS-1$
+               }
+               if (minor < 0) {
+                       throw new IllegalArgumentException("negative minor"); 
//$NON-NLS-1$
+               }
+               if (micro < 0) {
+                       throw new IllegalArgumentException("negative micro"); 
//$NON-NLS-1$
+               }
+               int length = qualifier.length();
+               for (int i = 0; i < length; i++) {
+ if ("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-".ind exOf(qualifier.charAt(i)) == -1) { //$NON-NLS-1$ + throw new IllegalArgumentException("invalid qualifier"); //$NON-NLS-1$
+                       }
+               }
+       }
+
+       /**
+        * Parses a version identifier from the specified string.
+        *
+        * <p>
+ * See <code>Version(String)</code> for the format of the version string.
+        *
+ * @param version String representation of the version identifier. Leading
+        *        and trailing whitespace will be ignored.
+        * @return A <code>Version</code> object representing the version
+ * identifier. If <code>version</code> is <code>null</code> or
+        *         the empty string then <code>emptyVersion</code> will be
+        *         returned.
+ * @throws IllegalArgumentException If <code>version</code> is improperly
+        *         formatted.
+        */
+       public static Version parseVersion(String version) {
+               if (version == null) {
+                       return emptyVersion;
+               }
+
+               version = version.trim();
+               if (version.length() == 0) {
+                       return emptyVersion;
+               }
+
+               return new Version(version);
+       }
+
+       /**
+        * Returns the major component of this version identifier.
+        *
+        * @return The major component.
+        */
+       public int getMajor() {
+               return major;
+       }
+
+       /**
+        * Returns the minor component of this version identifier.
+        *
+        * @return The minor component.
+        */
+       public int getMinor() {
+               return minor;
+       }
+
+       /**
+        * Returns the micro component of this version identifier.
+        *
+        * @return The micro component.
+        */
+       public int getMicro() {
+               return micro;
+       }
+
+       /**
+        * Returns the qualifier component of this version identifier.
+        *
+        * @return The qualifier component.
+        */
+       public String getQualifier() {
+               return qualifier;
+       }
+
+       /**
+        * Returns the string representation of this version identifier.
+        *
+        * <p>
+ * The format of the version string will be <code>major.minor.micro</code>
+        * if qualifier is the empty string or
+        * <code>major.minor.micro.qualifier</code> otherwise.
+        *
+        * @return The string representation of this version identifier.
+        */
+       public String toString() {
+               String base = major + SEPARATOR + minor + SEPARATOR + micro;
+               if (qualifier.length() == 0) { //$NON-NLS-1$
+                       return base;
+               }
+               else {
+                       return base + qualifier;
+               }
+       }
+
+       /**
+        * Returns a hash code value for the object.
+        *
+        * @return An integer which is a hash code value for this object.
+        */
+       public int hashCode() {
+               return (major << 24) + (minor << 16) + (micro << 8)
+                               + qualifier.hashCode();
+       }
+
+       /**
+        * Compares this <code>Version</code> object to another object.
+        *
+        * <p>
+ * A version is considered to be <b>equal to </b> another version if the + * major, minor and micro components are equal and the qualifier component
+        * is equal (using <code>String.equals</code>).
+        *
+        * @param object The <code>Version</code> object to be compared.
+        * @return <code>true</code> if <code>object</code> is a
+        *         <code>Version</code> and is equal to this object;
+        *         <code>false</code> otherwise.
+        */
+       public boolean equals(Object object) {
+               if (object == this) { // quicktest
+                       return true;
+               }
+
+               if (!(object instanceof Version)) {
+                       return false;
+               }
+
+               Version other = (Version) object;
+               return (major == other.major) && (minor == other.minor)
+                               && (micro == other.micro) && 
qualifier.equals(other.qualifier);
+       }
+
+       /**
+        * Compares this <code>Version</code> object to another object.
+        *
+        * <p>
+ * A version is considered to be <b>less than </b> another version if its + * major component is less than the other version's major component, or the + * major components are equal and its minor component is less than the other + * version's minor component, or the major and minor components are equal + * and its micro component is less than the other version's micro component, + * or the major, minor and micro components are equal and it's qualifier + * component is less than the other version's qualifier component (using
+        * <code>String.compareTo</code>).
+        *
+        * <p>
+ * A version is considered to be <b>equal to</b> another version if the + * major, minor and micro components are equal and the qualifier component
+        * is equal (using <code>String.compareTo</code>).
+        *
+        * @param object The <code>Version</code> object to be compared.
+ * @return A negative integer, zero, or a positive integer if this object is
+        *         less than, equal to, or greater than the specified
+        *         <code>Version</code> object.
+        * @throws ClassCastException If the specified object is not a
+        *         <code>Version</code>.
+        */
+       public int compareTo(Object object) {
+               if (object == this) { // quicktest
+                       return 0;
+               }
+
+               Version other = (Version) object;
+
+               int result = major - other.major;
+               if (result != 0) {
+                       return result;
+               }
+
+               result = minor - other.minor;
+               if (result != 0) {
+                       return result;
+               }
+
+               result = micro - other.micro;
+               if (result != 0) {
+                       return result;
+               }
+
+               return qualifier.compareTo(other.qualifier);
+       }
+}

Propchange: felix/sandbox/donsez/urlhandler.maven/src/main/java/org/apache/felix/ sandbox/util/Version.java ----------------------------------------------------------------------- -------
    svn:eol-style = native

Added: felix/sandbox/donsez/urlhandler.maven/src/site/script.txt
URL: http://svn.apache.org/viewvc/felix/sandbox/donsez/urlhandler.maven/ src/site/script.txt?view=auto&rev=565965 ======================================================================= =======
--- felix/sandbox/donsez/urlhandler.maven/src/site/script.txt (added)
+++ felix/sandbox/donsez/urlhandler.maven/src/site/script.txt Tue Aug 14 16:13:17 2007
@@ -0,0 +1,11 @@
+start file:C: \Docume~1\Donsez\.m2\repository\org\apache\felix\org.apache.felix.sandb ox.urlhandler.maven\0.9.0-incubator- SNAPSHOT\org.apache.felix.sandbox.urlhandler.maven-0.9.0-incubator- SNAPSHOT.jar
+
+start mvn:org.apache.felix:org.osgi.core:[EMAIL PROTECTED]://repo1.maven.org/maven2
+start mvn:org.apache.felix:javax.servlet
+start mvn:org.apache.felix:org.osgi.compendium:1.0.0
+start mvn:org.apache.felix:org.apache.felix.scr
+start mvn:org.apache.felix:org.apache.felix.eventadmin
+start mvn:org.apache.felix:org.apache.felix.wireadmin
+
+rem update <bid> mvn:org.apache.felix:org.apache.felix.<subproject>
+

Propchange: felix/sandbox/donsez/urlhandler.maven/src/site/script.txt
----------------------------------------------------------------------- -------
    svn:eol-style = native

Added: felix/sandbox/donsez/urlhandler.maven/src/test/java/org/apache/felix/ sandbox/urlhandler/maven/test/MavenURLStreamHandlerServiceTest.java URL: http://svn.apache.org/viewvc/felix/sandbox/donsez/urlhandler.maven/ src/test/java/org/apache/felix/sandbox/urlhandler/maven/test/ MavenURLStreamHandlerServiceTest.java?view=auto&rev=565965 ======================================================================= ======= --- felix/sandbox/donsez/urlhandler.maven/src/test/java/org/apache/felix/ sandbox/urlhandler/maven/test/MavenURLStreamHandlerServiceTest.java (added) +++ felix/sandbox/donsez/urlhandler.maven/src/test/java/org/apache/felix/ sandbox/urlhandler/maven/test/MavenURLStreamHandlerServiceTest.java Tue Aug 14 16:13:17 2007
@@ -0,0 +1,108 @@
+/*
+ * 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.felix.sandbox.urlhandler.maven.test;
+
+import java.io.IOException;
+import java.net.URL;
+
+import org.apache.felix.sandbox.urlhandler.maven.MavenURLStreamHandlerService;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+/**
+ * Unit test for MavenURLStreamHandlerService.
+ * @author <a href="mailto:[email protected]";>Felix Project Team</a>
+ * @version $Revision$
+ * $Id$
+ */
+public class MavenURLStreamHandlerServiceTest
+    extends TestCase
+{
+    /**
+     * Create the test case
+     *
+     * @param testName name of the test case
+     */
+    public MavenURLStreamHandlerServiceTest( String testName )
+    {
+        super( testName );
+    }
+
+    /**
+     * @return the suite of tests being tested
+     */
+    public static Test suite()
+    {
+ return new TestSuite( MavenURLStreamHandlerServiceTest.class );
+    }
+
+       private MavenURLStreamHandlerService mavenURLStreamHandlerService;
+
+    protected void setUp() throws Exception {
+       super.setUp();
+       mavenURLStreamHandlerService=new MavenURLStreamHandlerService();
+    }
+
+    /**
+     */
+ public void testURLWithGroupidArtifactidVersion() throws IOException
+    {
+               assertNotNull(mavenURLStreamHandlerService.openConnection(
+ "mvn:org.apache.felix:org.osgi.core:0.9.0-incubator-SNAPSHOT"
+            ) );       
+    }
+
+    /**
+     */
+    public void testURLWithGroupidArtifactid() throws IOException
+    {
+               assertNotNull(mavenURLStreamHandlerService.openConnection(
+                       "mvn:org.apache.felix:org.osgi.core"
+               ) );
+    }
+    /**
+     */
+ public void testURLWithGroupidArtifactidVersionregexp() throws IOException
+    {
+ // http://java.sun.com/j2se/1.4.2/docs/api/java/util/regex/Pattern.html
+               assertNotNull(mavenURLStreamHandlerService.openConnection(
+ "mvn:org.apache.felix:org.osgi.core:(0\\.9\\.0(.*SNAPSHOT$))"
+               ) );
+    }
+
+    /**
+     */
+// public void testURLWithFileAlternativeRepository() throws IOException
+//    {
+//             assertNull(mavenURLStreamHandlerService.openConnection(
+// "mvn:org.apache.felix:org.osgi.core:[EMAIL PROTECTED]:C: \\Docume~1\\foobar\\.m2\\repository"
+//             ) );
+//    }
+
+    /**
+     */
+ public void testURLWithHttpAlternativeRepository() throws IOException
+    {
+               assertNotNull(mavenURLStreamHandlerService.openConnection(
+ "mvn:org.apache.felix:org.osgi.core:[EMAIL PROTECTED]://repo1.maven.org/ maven2"
+               ) );
+    }
+}

Propchange: felix/sandbox/donsez/urlhandler.maven/src/test/java/org/apache/felix/ sandbox/urlhandler/maven/test/MavenURLStreamHandlerServiceTest.java ----------------------------------------------------------------------- -------
    svn:eol-style = native

Added: felix/sandbox/donsez/urlhandler.maven/src/test/java/org/apache/felix/ sandbox/util/test/MavenCompliantVersionTest.java URL: http://svn.apache.org/viewvc/felix/sandbox/donsez/urlhandler.maven/ src/test/java/org/apache/felix/sandbox/util/test/ MavenCompliantVersionTest.java?view=auto&rev=565965 ======================================================================= ======= --- felix/sandbox/donsez/urlhandler.maven/src/test/java/org/apache/felix/ sandbox/util/test/MavenCompliantVersionTest.java (added) +++ felix/sandbox/donsez/urlhandler.maven/src/test/java/org/apache/felix/ sandbox/util/test/MavenCompliantVersionTest.java Tue Aug 14 16:13:17 2007
@@ -0,0 +1,64 @@
+/*
+ * 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.felix.sandbox.util.test;
+
+import org.apache.felix.sandbox.util.MavenCompliantVersion;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+
+/**
+ * Unit test for MavenCompliantVersionTest.
+ * @author <a href="mailto:[email protected]";>Felix Project Team</a>
+ */
+public class MavenCompliantVersionTest
+    extends TestCase
+{
+    /**
+     * Create the test case
+     *
+     * @param testName name of the test case
+     */
+    public MavenCompliantVersionTest( String testName )
+    {
+        super( testName );
+    }
+
+    /**
+     * @return the suite of tests being tested
+     */
+    public static Test suite()
+    {
+        return new TestSuite( MavenCompliantVersionTest.class );
+    }
+
+    /**
+     */
+ public void testMavenCompliantMavenCompliantVersion() throws Exception
+    {
+ assertNotNull(new MavenCompliantVersion("0.9.0-incubator-SNAPSHOT")); +// assertEquals(new MavenCompliantVersion(0,9,0,"-incubator-SNAPSHOT"),new MavenCompliantVersion("0.9.0-incubator-SNAPSHOT")); +// assertNotNull(new MavenCompliantVersion(0,9,0,"-incubator-SNAPSHOT").getQualifier()); +// assertEquals((new MavenCompliantVersion(0,9,0,"-incubator-SNAPSHOT")).getMajor(),0); +// assertEquals((new MavenCompliantVersion(0,9,0,"-incubator-SNAPSHOT")).getMinor(),9); +// assertEquals((new MavenCompliantVersion(0,9,0,"-incubator-SNAPSHOT")).getMicro(),0);
+    }
+}

Propchange: felix/sandbox/donsez/urlhandler.maven/src/test/java/org/apache/felix/ sandbox/util/test/MavenCompliantVersionTest.java ----------------------------------------------------------------------- -------
    svn:eol-style = native



Reply via email to