You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@karaf.apache.org by gn...@apache.org on 2014/02/25 23:19:36 UTC
[1/2] git commit: [KARAF-2793] Remove tight coupling from bundle/core
and kar/core to pax-url-aether
Repository: karaf
Updated Branches:
refs/heads/master 35564b9ce -> 86c5e3c4b
[KARAF-2793] Remove tight coupling from bundle/core and kar/core to pax-url-aether
Project: http://git-wip-us.apache.org/repos/asf/karaf/repo
Commit: http://git-wip-us.apache.org/repos/asf/karaf/commit/86c5e3c4
Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/86c5e3c4
Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/86c5e3c4
Branch: refs/heads/master
Commit: 86c5e3c4b28c2668dc227b7a7e13b2ea9dcff19c
Parents: 3987408
Author: Guillaume Nodet <gn...@gmail.com>
Authored: Tue Feb 25 22:45:39 2014 +0100
Committer: Guillaume Nodet <gn...@gmail.com>
Committed: Tue Feb 25 23:01:41 2014 +0100
----------------------------------------------------------------------
bundle/core/pom.xml | 9 +-
.../bundle/core/internal/BundleWatcherImpl.java | 3 +-
.../core/internal/MavenConfigService.java | 80 ++--
.../core/internal/MavenConfigServiceTest.java | 56 +++
bundle/core/src/test/resources/settings.xml | 64 +++
bundle/core/src/test/resources/settings2.xml | 67 +++
kar/core/pom.xml | 11 +-
.../karaf/kar/internal/KarServiceImpl.java | 2 +-
.../org/apache/karaf/util/maven/Parser.java | 408 +++++++++++++++++++
9 files changed, 663 insertions(+), 37 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/karaf/blob/86c5e3c4/bundle/core/pom.xml
----------------------------------------------------------------------
diff --git a/bundle/core/pom.xml b/bundle/core/pom.xml
index f224c6c..e1ba3fa 100644
--- a/bundle/core/pom.xml
+++ b/bundle/core/pom.xml
@@ -67,11 +67,17 @@
</dependency>
<dependency>
+ <groupId>org.apache.karaf</groupId>
+ <artifactId>org.apache.karaf.util</artifactId>
+ <scope>provided</scope>
+ </dependency>
+
+ <dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.utils</artifactId>
<scope>provided</scope>
</dependency>
-
+
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-jdk14</artifactId>
@@ -108,6 +114,7 @@
</Import-Package>
<Private-Package>
org.apache.karaf.bundle.core.internal,
+ org.apache.karaf.util.maven,
org.apache.felix.utils.version,
org.apache.felix.utils.manifest
</Private-Package>
http://git-wip-us.apache.org/repos/asf/karaf/blob/86c5e3c4/bundle/core/src/main/java/org/apache/karaf/bundle/core/internal/BundleWatcherImpl.java
----------------------------------------------------------------------
diff --git a/bundle/core/src/main/java/org/apache/karaf/bundle/core/internal/BundleWatcherImpl.java b/bundle/core/src/main/java/org/apache/karaf/bundle/core/internal/BundleWatcherImpl.java
index 925e3ba..1a9b076 100644
--- a/bundle/core/src/main/java/org/apache/karaf/bundle/core/internal/BundleWatcherImpl.java
+++ b/bundle/core/src/main/java/org/apache/karaf/bundle/core/internal/BundleWatcherImpl.java
@@ -33,7 +33,7 @@ import java.util.concurrent.atomic.AtomicInteger;
import org.apache.karaf.bundle.core.BundleService;
import org.apache.karaf.bundle.core.BundleWatcher;
-import org.ops4j.pax.url.mvn.Parser;
+import org.apache.karaf.util.maven.Parser;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleEvent;
@@ -42,7 +42,6 @@ import org.osgi.framework.BundleListener;
import org.osgi.framework.FrameworkEvent;
import org.osgi.framework.FrameworkListener;
import org.osgi.framework.wiring.FrameworkWiring;
-import org.osgi.service.packageadmin.PackageAdmin;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
http://git-wip-us.apache.org/repos/asf/karaf/blob/86c5e3c4/bundle/core/src/main/java/org/apache/karaf/bundle/core/internal/MavenConfigService.java
----------------------------------------------------------------------
diff --git a/bundle/core/src/main/java/org/apache/karaf/bundle/core/internal/MavenConfigService.java b/bundle/core/src/main/java/org/apache/karaf/bundle/core/internal/MavenConfigService.java
index 7149ab0..ba0049a 100644
--- a/bundle/core/src/main/java/org/apache/karaf/bundle/core/internal/MavenConfigService.java
+++ b/bundle/core/src/main/java/org/apache/karaf/bundle/core/internal/MavenConfigService.java
@@ -17,14 +17,15 @@
package org.apache.karaf.bundle.core.internal;
import java.io.File;
-import java.io.IOException;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
import java.util.Dictionary;
-import org.ops4j.pax.url.maven.commons.MavenConfiguration;
-import org.ops4j.pax.url.maven.commons.MavenConfigurationImpl;
-import org.ops4j.pax.url.maven.commons.MavenRepositoryURL;
-import org.ops4j.pax.url.mvn.ServiceConstants;
-import org.ops4j.util.property.DictionaryPropertyResolver;
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamConstants;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
import org.osgi.service.cm.Configuration;
import org.osgi.service.cm.ConfigurationAdmin;
import org.slf4j.Logger;
@@ -32,7 +33,7 @@ import org.slf4j.LoggerFactory;
public class MavenConfigService {
- private final Logger logger = LoggerFactory.getLogger(BundleWatcherImpl.class);
+ private final Logger logger = LoggerFactory.getLogger(MavenConfigService.class);
private final ConfigurationAdmin configurationAdmin;
public MavenConfigService(ConfigurationAdmin configurationAdmin) {
@@ -40,35 +41,56 @@ public class MavenConfigService {
}
public File getLocalRepository() {
- // Attempt to retrieve local repository location from MavenConfiguration
- MavenConfiguration configuration = retrieveMavenConfiguration();
- if (configuration != null) {
- MavenRepositoryURL localRepositoryURL = configuration.getLocalRepository();
- if (localRepositoryURL != null) {
- return localRepositoryURL.getFile().getAbsoluteFile();
+ String path = null;
+ try {
+ Configuration configuration = configurationAdmin.getConfiguration("org.ops4j.pax.url.mvn");
+ if (configuration != null) {
+ Dictionary<String, Object> dict = configuration.getProperties();
+ path = getLocalRepoFromConfig(dict);
+
}
+ } catch (Exception e) {
+ logger.error("Error retrieving maven configuration", e);
+ }
+ if (path == null) {
+ path = System.getProperty("user.home") + File.separator + ".m2" + File.separator + "repository";
+ }
+ int index = path.indexOf('@');
+ if (index > 0) {
+ return new File(path.substring(index)).getAbsoluteFile();
+ } else {
+ return new File(path).getAbsoluteFile();
}
- // If local repository not found assume default.
- String localRepo = System.getProperty("user.home") + File.separator + ".m2" + File.separator + "repository";
- return new File(localRepo).getAbsoluteFile();
}
- private MavenConfiguration retrieveMavenConfiguration() {
- MavenConfiguration mavenConfiguration = null;
- try {
- Configuration configuration = configurationAdmin.getConfiguration(ServiceConstants.PID);
- if (configuration != null) {
- @SuppressWarnings("rawtypes")
- Dictionary dictonary = configuration.getProperties();
- if (dictonary != null) {
- DictionaryPropertyResolver resolver = new DictionaryPropertyResolver(dictonary);
- mavenConfiguration = new MavenConfigurationImpl(resolver, ServiceConstants.PID);
+ static String getLocalRepoFromConfig(Dictionary<String, Object> dict) throws XMLStreamException, FileNotFoundException {
+ String path = null;
+ if (dict != null) {
+ path = (String) dict.get("org.ops4j.pax.url.mvn.localRepository");
+ if (path == null) {
+ String settings = (String) dict.get("org.ops4j.pax.url.mvn.settings");
+ if (settings != null) {
+ File file = new File(settings);
+ XMLStreamReader reader = XMLInputFactory.newFactory().createXMLStreamReader(new FileInputStream(file));
+ try {
+ int event;
+ String elementName = null;
+ while ((event = reader.next()) != XMLStreamConstants.END_DOCUMENT) {
+ if (event == XMLStreamConstants.START_ELEMENT) {
+ elementName = reader.getLocalName();
+ } else if (event == XMLStreamConstants.END_ELEMENT) {
+ elementName = null;
+ } else if (event == XMLStreamConstants.CHARACTERS && "localRepository".equals(elementName)) {
+ path = reader.getText().trim();
+ }
+ }
+ } finally {
+ reader.close();
+ }
}
}
- } catch (IOException e) {
- logger.error("Error retrieving maven configuration", e);
}
- return mavenConfiguration;
+ return path;
}
}
http://git-wip-us.apache.org/repos/asf/karaf/blob/86c5e3c4/bundle/core/src/test/java/org/apache/karaf/bundle/core/internal/MavenConfigServiceTest.java
----------------------------------------------------------------------
diff --git a/bundle/core/src/test/java/org/apache/karaf/bundle/core/internal/MavenConfigServiceTest.java b/bundle/core/src/test/java/org/apache/karaf/bundle/core/internal/MavenConfigServiceTest.java
new file mode 100644
index 0000000..55af586
--- /dev/null
+++ b/bundle/core/src/test/java/org/apache/karaf/bundle/core/internal/MavenConfigServiceTest.java
@@ -0,0 +1,56 @@
+/*
+ * 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.karaf.bundle.core.internal;
+
+import java.io.File;
+import java.util.HashMap;
+import java.util.Hashtable;
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+public class MavenConfigServiceTest {
+
+ @Test
+ public void testLocalRepoEmpty() throws Exception {
+ Hashtable<String, Object> config = new Hashtable<String, Object>();
+ assertEquals(null, MavenConfigService.getLocalRepoFromConfig(config));
+ }
+
+ @Test
+ public void testLocalRepoExplicit() throws Exception {
+ Hashtable<String, Object> config = new Hashtable<String, Object>();
+ config.put("org.ops4j.pax.url.mvn.localRepository", "foo/bar");
+ assertEquals("foo/bar", MavenConfigService.getLocalRepoFromConfig(config));
+ }
+
+ @Test
+ public void testLocalRepoFromSettings() throws Exception {
+ Hashtable<String, Object> config = new Hashtable<String, Object>();
+ config.put("org.ops4j.pax.url.mvn.settings", getClass().getResource("/settings.xml").getPath());
+ assertEquals("foo/bar", MavenConfigService.getLocalRepoFromConfig(config));
+ }
+
+ @Test
+ public void testLocalRepoFromSettingsNs() throws Exception {
+ Hashtable<String, Object> config = new Hashtable<String, Object>();
+ config.put("org.ops4j.pax.url.mvn.settings", getClass().getResource("/settings2.xml").getPath());
+ assertEquals("foo/bar", MavenConfigService.getLocalRepoFromConfig(config));
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/karaf/blob/86c5e3c4/bundle/core/src/test/resources/settings.xml
----------------------------------------------------------------------
diff --git a/bundle/core/src/test/resources/settings.xml b/bundle/core/src/test/resources/settings.xml
new file mode 100644
index 0000000..ea73c3e
--- /dev/null
+++ b/bundle/core/src/test/resources/settings.xml
@@ -0,0 +1,64 @@
+<settings>
+ <!--
+ <mirrors>
+ <mirror>
+ <id>nexus</id>
+ <mirrorOf>*</mirrorOf>
+ <url>http://192.168.0.128:8081/nexus/content/groups/public</url>
+ </mirror>
+ </mirrors>
+ -->
+ <servers>
+ </servers>
+ <localRepository>foo/bar</localRepository>
+ <profiles>
+ <profile>
+ <id>signing-key</id>
+ <properties>
+ <gpg.passphrase>paulaudesixtinemarieamelie</gpg.passphrase>
+ <gpg.keyname>B4493B94</gpg.keyname>
+ <!--
+ <release-paxurl-altGitURL>scm:git:file:///Users/gnodet/work/git/org.ops4j.pax.url</release-paxurl-altGitURL>
+ <release-altGitURL>scm:git:file:///Users/gnodet/work/git/org.ops4j.pax.web</release-altGitURL>
+ <altDeploymentRepository>apache.releases.https::default::https://repository.apache.org/service/local/staging/deploy/maven2/</altDeploymentRepository>
+ -->
+ </properties>
+ </profile>
+ <profile>
+ <id>nexus</id>
+ <!--Enable snapshots for the built in central repo to direct -->
+ <!--all requests to nexus via the mirror -->
+ <repositories>
+ <repository>
+ <id>central</id>
+ <url>http://central</url>
+ <releases><enabled>true</enabled></releases>
+ <snapshots><enabled>true</enabled></snapshots>
+ </repository>
+ </repositories>
+ <pluginRepositories>
+ <pluginRepository>
+ <id>central</id>
+ <url>http://central</url>
+ <releases><enabled>true</enabled></releases>
+ <snapshots><enabled>true</enabled></snapshots>
+ </pluginRepository>
+ </pluginRepositories>
+ </profile>
+ <profile>
+ <id>downloadSources</id>
+ <properties>
+ <downloadSources>true</downloadSources>
+ </properties>
+ </profile>
+ </profiles>
+ <activeProfiles>
+ <!--make the profile active all the time -->
+ <!--
+ <activeProfile>nexus</activeProfile>
+ <activeProfile>fuse-repo</activeProfile>
+ -->
+ <activeProfile>signing-key</activeProfile>
+ <activeProfile>downloadSources</activeProfile>
+ </activeProfiles>
+</settings>
http://git-wip-us.apache.org/repos/asf/karaf/blob/86c5e3c4/bundle/core/src/test/resources/settings2.xml
----------------------------------------------------------------------
diff --git a/bundle/core/src/test/resources/settings2.xml b/bundle/core/src/test/resources/settings2.xml
new file mode 100644
index 0000000..82bc7cb
--- /dev/null
+++ b/bundle/core/src/test/resources/settings2.xml
@@ -0,0 +1,67 @@
+<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
+ http://maven.apache.org/xsd/settings-1.0.0.xsd">
+ <!--
+ <mirrors>
+ <mirror>
+ <id>nexus</id>
+ <mirrorOf>*</mirrorOf>
+ <url>http://192.168.0.128:8081/nexus/content/groups/public</url>
+ </mirror>
+ </mirrors>
+ -->
+ <servers>
+ </servers>
+ <localRepository>foo/bar</localRepository>
+ <profiles>
+ <profile>
+ <id>signing-key</id>
+ <properties>
+ <gpg.passphrase>paulaudesixtinemarieamelie</gpg.passphrase>
+ <gpg.keyname>B4493B94</gpg.keyname>
+ <!--
+ <release-paxurl-altGitURL>scm:git:file:///Users/gnodet/work/git/org.ops4j.pax.url</release-paxurl-altGitURL>
+ <release-altGitURL>scm:git:file:///Users/gnodet/work/git/org.ops4j.pax.web</release-altGitURL>
+ <altDeploymentRepository>apache.releases.https::default::https://repository.apache.org/service/local/staging/deploy/maven2/</altDeploymentRepository>
+ -->
+ </properties>
+ </profile>
+ <profile>
+ <id>nexus</id>
+ <!--Enable snapshots for the built in central repo to direct -->
+ <!--all requests to nexus via the mirror -->
+ <repositories>
+ <repository>
+ <id>central</id>
+ <url>http://central</url>
+ <releases><enabled>true</enabled></releases>
+ <snapshots><enabled>true</enabled></snapshots>
+ </repository>
+ </repositories>
+ <pluginRepositories>
+ <pluginRepository>
+ <id>central</id>
+ <url>http://central</url>
+ <releases><enabled>true</enabled></releases>
+ <snapshots><enabled>true</enabled></snapshots>
+ </pluginRepository>
+ </pluginRepositories>
+ </profile>
+ <profile>
+ <id>downloadSources</id>
+ <properties>
+ <downloadSources>true</downloadSources>
+ </properties>
+ </profile>
+ </profiles>
+ <activeProfiles>
+ <!--make the profile active all the time -->
+ <!--
+ <activeProfile>nexus</activeProfile>
+ <activeProfile>fuse-repo</activeProfile>
+ -->
+ <activeProfile>signing-key</activeProfile>
+ <activeProfile>downloadSources</activeProfile>
+ </activeProfiles>
+</settings>
http://git-wip-us.apache.org/repos/asf/karaf/blob/86c5e3c4/kar/core/pom.xml
----------------------------------------------------------------------
diff --git a/kar/core/pom.xml b/kar/core/pom.xml
index 9d9a51f..2c43d38 100644
--- a/kar/core/pom.xml
+++ b/kar/core/pom.xml
@@ -41,6 +41,12 @@
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.utils</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.karaf</groupId>
+ <artifactId>org.apache.karaf.util</artifactId>
+ <scope>provided</scope>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
@@ -53,10 +59,6 @@
<scope>provided</scope>
</dependency>
<dependency>
- <groupId>org.ops4j.pax.url</groupId>
- <artifactId>pax-url-aether</artifactId>
- </dependency>
- <dependency>
<groupId>org.ops4j.pax.swissbox</groupId>
<artifactId>pax-swissbox-property</artifactId>
</dependency>
@@ -99,6 +101,7 @@
</Export-Package>
<Private-Package>
org.apache.karaf.kar.internal,
+ org.apache.karaf.util.maven,
org.apache.felix.utils.properties
</Private-Package>
</instructions>
http://git-wip-us.apache.org/repos/asf/karaf/blob/86c5e3c4/kar/core/src/main/java/org/apache/karaf/kar/internal/KarServiceImpl.java
----------------------------------------------------------------------
diff --git a/kar/core/src/main/java/org/apache/karaf/kar/internal/KarServiceImpl.java b/kar/core/src/main/java/org/apache/karaf/kar/internal/KarServiceImpl.java
index 47c09f0..74db7b7 100644
--- a/kar/core/src/main/java/org/apache/karaf/kar/internal/KarServiceImpl.java
+++ b/kar/core/src/main/java/org/apache/karaf/kar/internal/KarServiceImpl.java
@@ -49,7 +49,7 @@ import org.apache.karaf.features.Feature;
import org.apache.karaf.features.FeaturesService;
import org.apache.karaf.features.Repository;
import org.apache.karaf.kar.KarService;
-import org.ops4j.pax.url.mvn.Parser;
+import org.apache.karaf.util.maven.Parser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
http://git-wip-us.apache.org/repos/asf/karaf/blob/86c5e3c4/util/src/main/java/org/apache/karaf/util/maven/Parser.java
----------------------------------------------------------------------
diff --git a/util/src/main/java/org/apache/karaf/util/maven/Parser.java b/util/src/main/java/org/apache/karaf/util/maven/Parser.java
new file mode 100644
index 0000000..94f0478
--- /dev/null
+++ b/util/src/main/java/org/apache/karaf/util/maven/Parser.java
@@ -0,0 +1,408 @@
+/*
+ * Copyright 2007 Alin Dreghiciu.
+ * Copyright 2010,2011 Toni Menzel.
+ *
+ * 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.karaf.util.maven;
+
+import java.net.MalformedURLException;
+
+/**
+ * Parser for mvn: protocol.<br/>
+ *
+ * @author Alin Dreghiciu
+ * @author Toni Menzel
+ *
+ * @since August 10, 2007
+ */
+public class Parser
+{
+
+ /**
+ * Default version if none present in the url.
+ */
+ public static final String VERSION_LATEST = "LATEST";
+
+ /**
+ * Syntax for the url; to be shown on exception messages.
+ */
+ private static final String SYNTAX = "mvn:[repository_url!]groupId/artifactId[/[version]/[type]]";
+
+ /**
+ * Separator between repository and artifact definition.
+ */
+ private static final String REPOSITORY_SEPARATOR = "!";
+ /**
+ * Artifact definition segments separator.
+ */
+ private static final String ARTIFACT_SEPARATOR = "/";
+
+ /**
+ * Snapshot version
+ */
+ private static final String VERSION_SNAPSHOT = "SNAPSHOT";
+ /**
+ * Default type if not present in the url.
+ */
+ private static final String TYPE_JAR = "jar";
+
+ /**
+ * Final artifact path separator.
+ */
+ public static final String FILE_SEPARATOR = "/";
+ /**
+ * Group id path separator.
+ */
+ private static final String GROUP_SEPARATOR = "\\.";
+ /**
+ * Separator used to constructs the artifact file name.
+ */
+ private static final String VERSION_SEPARATOR = "-";
+ /**
+ * Artifact extension(type) separator.
+ */
+ private static final String TYPE_SEPARATOR = ".";
+ /**
+ * Separator used to separate classifier in artifact name.
+ */
+ private static final String CLASSIFIER_SEPARATOR = "-";
+ /**
+ * Maven metadata file.
+ */
+ private static final String METADATA_FILE = "maven-metadata.xml";
+ /**
+ * Maven local metadata file.
+ */
+ private static final String METADATA_FILE_LOCAL = "maven-metadata-local.xml";
+
+ /**
+ * Repository URL. Null if not present.
+ */
+ private String m_repositoryURL;
+ /**
+ * Artifact group id.
+ */
+ private String m_group;
+ /**
+ * Artifact id.
+ */
+ private String m_artifact;
+ /**
+ * Artifact version.
+ */
+ private String m_version;
+ /**
+ * Artifact type.
+ */
+ private String m_type;
+ /**
+ * Artifact classifier.
+ */
+ private String m_classifier;
+ /**
+ * Artifact classifier to use to build artifact name.
+ */
+ private String m_fullClassifier;
+
+ /**
+ * Creates a new protocol parser.
+ *
+ * @param path the path part of the url (without starting mvn:)
+ *
+ * @throws MalformedURLException if provided path does not comply to expected syntax or an malformed repository URL
+ */
+ public Parser( final String path )
+ throws MalformedURLException
+ {
+ if( path == null )
+ {
+ throw new MalformedURLException( "Path cannot be null. Syntax " + SYNTAX );
+ }
+ if( path.startsWith( REPOSITORY_SEPARATOR ) || path.endsWith( REPOSITORY_SEPARATOR ) )
+ {
+ throw new MalformedURLException(
+ "Path cannot start or end with " + REPOSITORY_SEPARATOR + ". Syntax " + SYNTAX
+ );
+ }
+ if( path.contains( REPOSITORY_SEPARATOR ) )
+ {
+ int pos = path.lastIndexOf( REPOSITORY_SEPARATOR );
+ parseArtifactPart( path.substring( pos + 1 ) );
+ m_repositoryURL = path.substring( 0, pos ) + "@snapshots";
+ }
+ else
+ {
+ parseArtifactPart( path );
+ }
+ }
+
+ /**
+ * Parses the artifact part of the url ( without the repository).
+ *
+ * @param part url part without protocol and repository.
+ *
+ * @throws MalformedURLException if provided path does not comply to syntax.
+ */
+ private void parseArtifactPart( final String part )
+ throws MalformedURLException
+ {
+ String[] segments = part.split( ARTIFACT_SEPARATOR );
+ if( segments.length < 2 )
+ {
+ throw new MalformedURLException( "Invalid path. Syntax " + SYNTAX );
+ }
+ // we must have a valid group
+ m_group = segments[ 0 ];
+ if( m_group.trim().length() == 0 )
+ {
+ throw new MalformedURLException( "Invalid groupId. Syntax " + SYNTAX );
+ }
+ // valid artifact
+ m_artifact = segments[ 1 ];
+ if( m_artifact.trim().length() == 0 )
+ {
+ throw new MalformedURLException( "Invalid artifactId. Syntax " + SYNTAX );
+ }
+ // version is optional but we have a default value
+ m_version = VERSION_LATEST;
+ if( segments.length >= 3 && segments[ 2 ].trim().length() > 0 )
+ {
+ m_version = segments[ 2 ];
+ }
+ // type is optional but we have a default value
+ m_type = TYPE_JAR;
+ if( segments.length >= 4 && segments[ 3 ].trim().length() > 0 )
+ {
+ m_type = segments[ 3 ];
+ }
+ // classifier is optional (if not pressent or empty we will have a null classsifier
+ m_fullClassifier = "";
+ if( segments.length >= 5 && segments[ 4 ].trim().length() > 0 )
+ {
+ m_classifier = segments[ 4 ];
+ m_fullClassifier = CLASSIFIER_SEPARATOR + m_classifier;
+ }
+ }
+
+ /**
+ * Returns the repository URL if present, null otherwise
+ *
+ * @return repository URL
+ */
+ public String getRepositoryURL()
+ {
+ return m_repositoryURL;
+ }
+
+ /**
+ * Returns the group id of the artifact.
+ *
+ * @return group Id
+ */
+ public String getGroup()
+ {
+ return m_group;
+ }
+
+ /**
+ * Returns the artifact id.
+ *
+ * @return artifact id
+ */
+ public String getArtifact()
+ {
+ return m_artifact;
+ }
+
+ /**
+ * Returns the artifact version.
+ *
+ * @return version
+ */
+ public String getVersion()
+ {
+ return m_version;
+ }
+
+ /**
+ * Returns the artifact type.
+ *
+ * @return type
+ */
+ public String getType()
+ {
+ return m_type;
+ }
+
+ /**
+ * Returns the artifact classifier.
+ *
+ * @return classifier
+ */
+ public String getClassifier()
+ {
+ return m_classifier;
+ }
+
+ /**
+ * Returns the complete path to artifact as stated by Maven 2 repository layout.
+ *
+ * @return artifact path
+ */
+ public String getArtifactPath()
+ {
+ return getArtifactPath( m_version );
+ }
+
+ /**
+ * Returns the complete path to artifact as stated by Maven 2 repository layout.
+ *
+ * @param version The version of the artifact.
+ *
+ * @return artifact path
+ */
+ public String getArtifactPath( final String version )
+ {
+ return new StringBuilder()
+ .append( m_group.replaceAll( GROUP_SEPARATOR, FILE_SEPARATOR ) )
+ .append( FILE_SEPARATOR )
+ .append( m_artifact )
+ .append( FILE_SEPARATOR )
+ .append( version )
+ .append( FILE_SEPARATOR )
+ .append( m_artifact )
+ .append( VERSION_SEPARATOR )
+ .append( version )
+ .append( m_fullClassifier )
+ .append( TYPE_SEPARATOR )
+ .append( m_type )
+ .toString();
+ }
+
+ /**
+ * Returns the version for an artifact for a snapshot version.
+ *
+ * @param version The version of the snapshot.
+ * @param timestamp The timestamp of the snapshot.
+ * @param buildnumber The buildnumber of the snapshot.
+ *
+ * @return artifact path
+ */
+ public String getSnapshotVersion( final String version, final String timestamp, final String buildnumber )
+ {
+ return version.replace( VERSION_SNAPSHOT, timestamp ) + VERSION_SEPARATOR + buildnumber;
+ }
+
+ /**
+ * Returns the complete path to artifact for a snapshot file.
+ *
+ * @param version The version of the snapshot.
+ * @param timestamp The timestamp of the snapshot.
+ * @param buildnumber The buildnumber of the snapshot.
+ *
+ * @return artifact path
+ */
+ public String getSnapshotPath( final String version, final String timestamp, final String buildnumber )
+ {
+ return new StringBuilder()
+ .append( m_group.replaceAll( GROUP_SEPARATOR, FILE_SEPARATOR ) )
+ .append( FILE_SEPARATOR )
+ .append( m_artifact )
+ .append( FILE_SEPARATOR )
+ .append( version )
+ .append( FILE_SEPARATOR )
+ .append( m_artifact )
+ .append( VERSION_SEPARATOR )
+ .append( getSnapshotVersion( version, timestamp, buildnumber ) )
+ .append( m_fullClassifier )
+ .append( TYPE_SEPARATOR )
+ .append( m_type )
+ .toString();
+ }
+
+ /**
+ * Returns the path to metdata file corresponding to this artifact version.
+ *
+ * @param version The version of the the metadata.
+ *
+ * @return metadata file path
+ */
+ public String getVersionMetadataPath( final String version )
+ {
+ return new StringBuilder()
+ .append( m_group.replaceAll( GROUP_SEPARATOR, FILE_SEPARATOR ) )
+ .append( FILE_SEPARATOR )
+ .append( m_artifact )
+ .append( FILE_SEPARATOR )
+ .append( version )
+ .append( FILE_SEPARATOR )
+ .append( METADATA_FILE )
+ .toString();
+ }
+
+ /**
+ * Returns the path to local metdata file corresponding to this artifact version.
+ *
+ * @param version The version of the the metadata.
+ *
+ * @return metadata file path
+ */
+ public String getVersionLocalMetadataPath( final String version )
+ {
+ return new StringBuilder()
+ .append( m_group.replaceAll( GROUP_SEPARATOR, FILE_SEPARATOR ) )
+ .append( FILE_SEPARATOR )
+ .append( m_artifact )
+ .append( FILE_SEPARATOR )
+ .append( version )
+ .append( FILE_SEPARATOR )
+ .append( METADATA_FILE_LOCAL )
+ .toString();
+ }
+
+ /**
+ * Returns the complete path to artifact local metadata file.
+ *
+ * @return artifact path
+ */
+ public String getArtifactLocalMetdataPath()
+ {
+ return new StringBuilder()
+ .append( m_group.replaceAll( GROUP_SEPARATOR, FILE_SEPARATOR ) )
+ .append( FILE_SEPARATOR )
+ .append( m_artifact )
+ .append( FILE_SEPARATOR )
+ .append( METADATA_FILE_LOCAL )
+ .toString();
+ }
+
+ /**
+ * Returns the complete path to artifact metadata file.
+ *
+ * @return artifact path
+ */
+ public String getArtifactMetdataPath()
+ {
+ return new StringBuilder()
+ .append( m_group.replaceAll( GROUP_SEPARATOR, FILE_SEPARATOR ) )
+ .append( FILE_SEPARATOR )
+ .append( m_artifact )
+ .append( FILE_SEPARATOR )
+ .append( METADATA_FILE )
+ .toString();
+ }
+
+}
[2/2] git commit: [KARAF-2790] Bundle commands wrongly default to
select all bundles
Posted by gn...@apache.org.
[KARAF-2790] Bundle commands wrongly default to select all bundles
Project: http://git-wip-us.apache.org/repos/asf/karaf/repo
Commit: http://git-wip-us.apache.org/repos/asf/karaf/commit/3987408e
Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/3987408e
Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/3987408e
Branch: refs/heads/master
Commit: 3987408e032c19611338b32bbfce3c16140106c1
Parents: 35564b9
Author: Guillaume Nodet <gn...@gmail.com>
Authored: Mon Feb 24 21:57:34 2014 +0100
Committer: Guillaume Nodet <gn...@gmail.com>
Committed: Tue Feb 25 23:01:41 2014 +0100
----------------------------------------------------------------------
.../org/apache/karaf/bundle/core/internal/BundleSelectorImpl.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/karaf/blob/3987408e/bundle/core/src/main/java/org/apache/karaf/bundle/core/internal/BundleSelectorImpl.java
----------------------------------------------------------------------
diff --git a/bundle/core/src/main/java/org/apache/karaf/bundle/core/internal/BundleSelectorImpl.java b/bundle/core/src/main/java/org/apache/karaf/bundle/core/internal/BundleSelectorImpl.java
index 406a897..5806f39 100644
--- a/bundle/core/src/main/java/org/apache/karaf/bundle/core/internal/BundleSelectorImpl.java
+++ b/bundle/core/src/main/java/org/apache/karaf/bundle/core/internal/BundleSelectorImpl.java
@@ -43,7 +43,7 @@ public class BundleSelectorImpl {
}
addMatchingBundles(id, bundles);
}
- } else {
+ } else if (defaultAllBundles) {
Collections.addAll(bundles, bundleContext.getBundles());
}
return bundles;