You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by do...@apache.org on 2007/08/15 21:04:16 UTC
svn commit: r566304 - in /felix/sandbox/donsez/urlhandler.maven: pom.xml
src/main/java/org/apache/felix/sandbox/urlhandler/maven/MavenURLStreamHandlerService.java
src/site/script.txt
Author: donsez
Date: Wed Aug 15 12:04:16 2007
New Revision: 566304
URL: http://svn.apache.org/viewvc?view=rev&rev=566304
Log:
add org.osgi.service.cm.ManagedService to configure the default maven repository
Modified:
felix/sandbox/donsez/urlhandler.maven/pom.xml
felix/sandbox/donsez/urlhandler.maven/src/main/java/org/apache/felix/sandbox/urlhandler/maven/MavenURLStreamHandlerService.java
felix/sandbox/donsez/urlhandler.maven/src/site/script.txt
Modified: felix/sandbox/donsez/urlhandler.maven/pom.xml
URL: http://svn.apache.org/viewvc/felix/sandbox/donsez/urlhandler.maven/pom.xml?view=diff&rev=566304&r1=566303&r2=566304
==============================================================================
--- felix/sandbox/donsez/urlhandler.maven/pom.xml (original)
+++ felix/sandbox/donsez/urlhandler.maven/pom.xml Wed Aug 15 12:04:16 2007
@@ -20,7 +20,7 @@
<properties>
<repositoryLocation>http://www.apache.org/~donsez/dev/felix/</repositoryLocation>
- <description>provides a URLHandler to located bundle jarfiles in the local Maven reposity</description>
+ <description>provides a URLHandler to located bundle jarfiles in a local (or remote) Maven repository</description>
</properties>
<parent>
@@ -69,7 +69,7 @@
<Import-Package>*</Import-Package>
<Private-Package>${pom.artifactId},org.apache.felix.sandbox.util</Private-Package>
- <Export-Service>org.osgi.service.url.URLStreamHandlerService</Export-Service>
+ <Export-Service>org.osgi.service.url.URLStreamHandlerService,org.osgi.service.cm.ManagedService</Export-Service>
<Bundle-Activator>${pom.artifactId}.MavenURLStreamHandlerService</Bundle-Activator>
@@ -79,7 +79,7 @@
<Bundle-Source>${repositoryLocation}${pom.artifactId}/${pom.artifactId}-${pom.version}-src.jar</Bundle-Source>
-->
- <!-- for experiment with OBR and Maven -->
+ <!-- Experimental: merge OBR repository and Maven repository -->
<Maven-URL>mvn:${pom.groupId}:${pom.artifactId}:${pom.version}</Maven-URL>
</instructions>
Modified: 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=diff&rev=566304&r1=566303&r2=566304
==============================================================================
--- felix/sandbox/donsez/urlhandler.maven/src/main/java/org/apache/felix/sandbox/urlhandler/maven/MavenURLStreamHandlerService.java (original)
+++ felix/sandbox/donsez/urlhandler.maven/src/main/java/org/apache/felix/sandbox/urlhandler/maven/MavenURLStreamHandlerService.java Wed Aug 15 12:04:16 2007
@@ -32,32 +32,55 @@
import org.apache.felix.sandbox.util.MavenCompliantVersion;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
import org.osgi.framework.ServiceRegistration;
+import org.osgi.service.cm.ConfigurationException;
+import org.osgi.service.cm.ManagedService;
import org.osgi.service.url.AbstractURLStreamHandlerService;
import org.osgi.service.url.URLConstants;
+import org.osgi.service.url.URLStreamHandlerService;
/**
- * this class provides a URLHandler to located bundle jarfiles in the local Maven reposity.
+ * this class provides a URLHandler to located bundle jarfiles in a local (or remote) Maven reposity.
* @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
*/
public class MavenURLStreamHandlerService extends AbstractURLStreamHandlerService
- implements BundleActivator
+ implements BundleActivator, ManagedService
{
- public String MAVEN_URL_HANDLER_PROTOCOL="mvn";
+ public static String MAVEN_URL_HANDLER_PROTOCOL="mvn";
+ public static String DEFAULT_MAVEN_REPOSITORY_ROOTDIR_CONFIG_PROP_NAME="defaultMavenRepositoryRootDir";
+
+ private String m_defaultMavenRepositoryRootDir;
- private BundleContext bundleContext;
- private ServiceRegistration serviceRegistration;
+ private BundleContext m_bundleContext;
+ private ServiceRegistration m_serviceRegistration;
+
+ /**
+ * initialize the default Maven repository root dir
+ */
+ public MavenURLStreamHandlerService(){
+ if(System.getProperty("os.name").toLowerCase().startsWith("win")){ // m_bundleContext.getProperty(Constants.FRAMEWORK_OS_NAME)
+ m_defaultMavenRepositoryRootDir="C:\\Docume~1\\"+System.getProperty("user.name")+"\\.m2\\repository\\";
+ } else {
+ m_defaultMavenRepositoryRootDir=System.getProperty("user.dir")+"/.m2/repository/";
+ }
+ }
+
/**
* @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
*/
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);
+ m_bundleContext=context;
+ Dictionary registrationProperties = new Hashtable();
+ registrationProperties.put(URLConstants.URL_HANDLER_PROTOCOL, new String[] { MAVEN_URL_HANDLER_PROTOCOL });
+ registrationProperties.put(Constants.SERVICE_PID, "org.apache.felix.sandbox.urlhandler.maven");
+ m_serviceRegistration=context.registerService(
+ new String[] {
+ URLStreamHandlerService.class.getName(),
+ ManagedService.class.getName()
+ }, this, registrationProperties);
}
/**
@@ -65,7 +88,7 @@
*/
public void stop(BundleContext context) throws Exception
{
- serviceRegistration.unregister();
+ m_serviceRegistration.unregister();
}
@@ -90,7 +113,18 @@
throw new MalformedURLException(urlstr+" syntax is incorrect");
}
alternativeRepositoryField=urlstr.substring(index+1);
+
+ try {
+ // check if the alternativeRepositoryField is valid
+ URL alternativeRepositoryURL=new URL(alternativeRepositoryField);
+ } catch (MalformedURLException e) {
+ throw new MalformedURLException("root dir "+alternativeRepositoryField+" syntax is incorrect");
+ }
+
urlstr=urlstr.substring(0,index);
+
+ // TODO transform file:~${user.name}/ in file:C:\Docume~1\${user.name}\ if windows
+
}
// translate the mvn url in file url
@@ -100,7 +134,7 @@
if(countTokens!=3 && countTokens!=4) {
throw new MalformedURLException(urlstr+" syntax is incorrect");
}
- st.nextToken(); // discard mvn
+ st.nextToken(); // skip protocol
String groupId=st.nextToken();
String artifactId=st.nextToken();
String versionStr=null;
@@ -135,12 +169,7 @@
}
} 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/";
- }
+ final String mavenRepositoryRootDir=m_defaultMavenRepositoryRootDir;
String artifactRootDirStr=mavenRepositoryRootDir
+groupId.replace('.', File.separatorChar)+File.separatorChar
+artifactId;
@@ -198,4 +227,12 @@
return translatedUrl.openConnection();
}
+
+ /**
+ * update the value of the default repository root dir
+ */
+ public void updated(Dictionary configurationProperties) throws ConfigurationException {
+ String s=(String) configurationProperties.get(DEFAULT_MAVEN_REPOSITORY_ROOTDIR_CONFIG_PROP_NAME);
+ if(s!=null) m_defaultMavenRepositoryRootDir=s;
+ }
}
Modified: 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=diff&rev=566304&r1=566303&r2=566304
==============================================================================
--- felix/sandbox/donsez/urlhandler.maven/src/site/script.txt (original)
+++ felix/sandbox/donsez/urlhandler.maven/src/site/script.txt Wed Aug 15 12:04:16 2007
@@ -1,11 +1,17 @@
start file:C:\Docume~1\Donsez\.m2\repository\org\apache\felix\org.apache.felix.sandbox.urlhandler.maven\0.9.0-incubator-SNAPSHOT\org.apache.felix.sandbox.urlhandler.maven-0.9.0-incubator-SNAPSHOT.jar
+services 4
+
start mvn:org.apache.felix:org.osgi.core:1.0.0@http://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
+update 5
+refresh
rem update <bid> mvn:org.apache.felix:org.apache.felix.<subproject>
+ps
+ps -l