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 2017/01/09 15:47:40 UTC
karaf git commit: [KARAF-4933][KARAF-4934] Resolve maven versions,
allow blacklisting repositories
Repository: karaf
Updated Branches:
refs/heads/master 48f0a1603 -> 69f54ee11
[KARAF-4933][KARAF-4934] Resolve maven versions, allow blacklisting repositories
Project: http://git-wip-us.apache.org/repos/asf/karaf/repo
Commit: http://git-wip-us.apache.org/repos/asf/karaf/commit/69f54ee1
Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/69f54ee1
Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/69f54ee1
Branch: refs/heads/master
Commit: 69f54ee11c6ee920dce4f8d803ae7ec99c471097
Parents: 48f0a16
Author: Guillaume Nodet <gn...@apache.org>
Authored: Mon Jan 9 16:11:29 2017 +0100
Committer: Guillaume Nodet <gn...@apache.org>
Committed: Mon Jan 9 16:47:24 2017 +0100
----------------------------------------------------------------------
features/core/pom.xml | 1 +
.../download/impl/MavenDownloadTask.java | 11 ++++++++
.../features/internal/service/Blacklist.java | 27 ++++++++++++--------
.../apache/karaf/profile/assembly/Builder.java | 22 ++++++++++++++--
.../org/apache/karaf/tooling/AssemblyMojo.java | 5 ++++
.../org/apache/karaf/util/maven/Parser.java | 20 ++++++++++++++-
6 files changed, 72 insertions(+), 14 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/karaf/blob/69f54ee1/features/core/pom.xml
----------------------------------------------------------------------
diff --git a/features/core/pom.xml b/features/core/pom.xml
index de354c9..f8a866f 100644
--- a/features/core/pom.xml
+++ b/features/core/pom.xml
@@ -147,6 +147,7 @@
org.apache.karaf.util,
org.apache.karaf.util.bundles,
org.apache.karaf.util.collections,
+ org.apache.karaf.util.maven,
org.eclipse.equinox.internal.region.*;-split-package:=merge-first,
org.apache.felix.resolver.*,
</Private-Package>
http://git-wip-us.apache.org/repos/asf/karaf/blob/69f54ee1/features/core/src/main/java/org/apache/karaf/features/internal/download/impl/MavenDownloadTask.java
----------------------------------------------------------------------
diff --git a/features/core/src/main/java/org/apache/karaf/features/internal/download/impl/MavenDownloadTask.java b/features/core/src/main/java/org/apache/karaf/features/internal/download/impl/MavenDownloadTask.java
index 70a4594..7e878df 100644
--- a/features/core/src/main/java/org/apache/karaf/features/internal/download/impl/MavenDownloadTask.java
+++ b/features/core/src/main/java/org/apache/karaf/features/internal/download/impl/MavenDownloadTask.java
@@ -20,6 +20,7 @@ import java.io.File;
import java.io.IOException;
import java.util.concurrent.ScheduledExecutorService;
+import org.apache.karaf.util.maven.Parser;
import org.ops4j.pax.url.mvn.MavenResolver;
public class MavenDownloadTask extends AbstractRetryableDownloadTask {
@@ -32,6 +33,16 @@ public class MavenDownloadTask extends AbstractRetryableDownloadTask {
}
@Override
+ public String getUrl() {
+ try {
+ // This ensures the version of the artifact is resolved in the returned url
+ return Parser.pathToMaven(Parser.pathFromMaven(url, getFile().toString()));
+ } catch (IOException e) {
+ return super.getUrl();
+ }
+ }
+
+ @Override
protected File download(Exception previousException) throws Exception {
return resolver.resolve(url, previousException);
}
http://git-wip-us.apache.org/repos/asf/karaf/blob/69f54ee1/features/core/src/main/java/org/apache/karaf/features/internal/service/Blacklist.java
----------------------------------------------------------------------
diff --git a/features/core/src/main/java/org/apache/karaf/features/internal/service/Blacklist.java b/features/core/src/main/java/org/apache/karaf/features/internal/service/Blacklist.java
index 294eac3..ba8c8a6 100644
--- a/features/core/src/main/java/org/apache/karaf/features/internal/service/Blacklist.java
+++ b/features/core/src/main/java/org/apache/karaf/features/internal/service/Blacklist.java
@@ -21,11 +21,7 @@ import java.io.FileNotFoundException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Set;
+import java.util.*;
import org.apache.felix.utils.manifest.Clause;
import org.apache.felix.utils.manifest.Parser;
@@ -43,11 +39,12 @@ import org.slf4j.LoggerFactory;
*/
public class Blacklist {
- protected static final String BLACKLIST_URL = "url";
- protected static final String BLACKLIST_RANGE = "range";
- protected static final String BLACKLIST_TYPE = "type";
- protected static final String TYPE_FEATURE = "feature";
- protected static final String TYPE_BUNDLE = "bundle";
+ public static final String BLACKLIST_URL = "url";
+ public static final String BLACKLIST_RANGE = "range";
+ public static final String BLACKLIST_TYPE = "type";
+ public static final String TYPE_FEATURE = "feature";
+ public static final String TYPE_BUNDLE = "bundle";
+ public static final String TYPE_REPOSITORY = "repository";
private static final Logger LOGGER = LoggerFactory.getLogger(Blacklist.class);
@@ -168,7 +165,15 @@ public class Blacklist {
}
public static boolean isBundleBlacklisted(List<String> blacklist, String uri) {
+ return isBlacklisted(blacklist, uri, TYPE_BUNDLE);
+ }
+
+ public static boolean isBlacklisted(List<String> blacklist, String uri, String btype) {
Clause[] clauses = Parser.parseClauses(blacklist.toArray(new String[blacklist.size()]));
+ return isBlacklisted(clauses, uri, btype);
+ }
+
+ public static boolean isBlacklisted(Clause[] clauses, String uri, String btype) {
for (Clause clause : clauses) {
String url = clause.getName();
if (clause.getAttribute(BLACKLIST_URL) != null) {
@@ -176,7 +181,7 @@ public class Blacklist {
}
if (uri.equals(url)) {
String type = clause.getAttribute(BLACKLIST_TYPE);
- if (type == null || TYPE_BUNDLE.equals(type)) {
+ if (type == null || btype.equals(type)) {
return true;
}
}
http://git-wip-us.apache.org/repos/asf/karaf/blob/69f54ee1/profile/src/main/java/org/apache/karaf/profile/assembly/Builder.java
----------------------------------------------------------------------
diff --git a/profile/src/main/java/org/apache/karaf/profile/assembly/Builder.java b/profile/src/main/java/org/apache/karaf/profile/assembly/Builder.java
index 0227c21..ba15bfe 100644
--- a/profile/src/main/java/org/apache/karaf/profile/assembly/Builder.java
+++ b/profile/src/main/java/org/apache/karaf/profile/assembly/Builder.java
@@ -96,6 +96,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import static java.util.jar.JarFile.MANIFEST_NAME;
+import static org.apache.karaf.features.internal.service.Blacklist.TYPE_REPOSITORY;
import static org.apache.karaf.profile.assembly.Builder.Stage.Startup;
public class Builder {
@@ -146,6 +147,7 @@ public class Builder {
List<String> blacklistedProfiles = new ArrayList<>();
List<String> blacklistedFeatures = new ArrayList<>();
List<String> blacklistedBundles = new ArrayList<>();
+ List<String> blacklistedRepositories = new ArrayList<>();
BlacklistPolicy blacklistPolicy = BlacklistPolicy.Discard;
List<String> libraries = new ArrayList<>();
String javase = "1.7";
@@ -357,6 +359,11 @@ public class Builder {
return this;
}
+ public Builder blacklistRepositories(Collection<String> repositories) {
+ this.blacklistedRepositories.addAll(repositories);
+ return this;
+ }
+
public Builder blacklistPolicy(BlacklistPolicy policy) {
this.blacklistPolicy = policy;
return this;
@@ -410,6 +417,10 @@ public class Builder {
return blacklistedBundles;
}
+ public List<String> getBlacklistedRepositories() {
+ return blacklistedRepositories;
+ }
+
public BlacklistPolicy getBlacklistPolicy() {
return blacklistPolicy;
}
@@ -1279,20 +1290,27 @@ public class Builder {
final List<String> blacklist = new ArrayList<>();
blacklist.addAll(blacklistedBundles);
blacklist.addAll(blacklistedFeatures);
+ final List<String> blacklistRepos = new ArrayList<>();
+ blacklistRepos.addAll(blacklistedRepositories);
final Clause[] clauses = org.apache.felix.utils.manifest.Parser.parseClauses(blacklist.toArray(new String[blacklist.size()]));
+ final Clause[] clausesRepos = org.apache.felix.utils.manifest.Parser.parseClauses(blacklistRepos.toArray(new String[blacklistRepos.size()]));
for (String repository : repositories) {
downloader.download(repository, new DownloadCallback() {
@Override
public void downloaded(final StreamProvider provider) throws Exception {
+ String url = provider.getUrl();
+ if (Blacklist.isBlacklisted(clausesRepos, url, TYPE_REPOSITORY)) {
+ return;
+ }
if (install) {
synchronized (provider) {
- Path path = systemDirectory.resolve(pathFromProviderUrl(provider.getUrl()));
+ Path path = systemDirectory.resolve(pathFromProviderUrl(url));
Files.createDirectories(path.getParent());
Files.copy(provider.getFile().toPath(), path, StandardCopyOption.REPLACE_EXISTING);
}
}
try (InputStream is = provider.open()) {
- Features featuresModel = JaxbUtil.unmarshal(provider.getUrl(), is, false);
+ Features featuresModel = JaxbUtil.unmarshal(url, is, false);
if (blacklistPolicy == BlacklistPolicy.Discard) {
Blacklist.blacklist(featuresModel, clauses);
}
http://git-wip-us.apache.org/repos/asf/karaf/blob/69f54ee1/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/AssemblyMojo.java
----------------------------------------------------------------------
diff --git a/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/AssemblyMojo.java b/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/AssemblyMojo.java
index 0bb61c8..2450411 100644
--- a/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/AssemblyMojo.java
+++ b/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/AssemblyMojo.java
@@ -100,6 +100,9 @@ public class AssemblyMojo extends MojoSupport {
@Parameter
private List<String> installedRepositories;
+ @Parameter
+ private List<String> blacklistedRepositories;
+
/**
* List of features from runtime-scope features xml and kars to be installed into system and listed in startup.properties.
*/
@@ -282,6 +285,7 @@ public class AssemblyMojo extends MojoSupport {
bootProfiles = nonNullList(bootProfiles);
installedProfiles = nonNullList(installedProfiles);
blacklistedProfiles = nonNullList(blacklistedProfiles);
+ blacklistedRepositories = nonNullList(blacklistedRepositories);
if (!startupProfiles.isEmpty() || !bootProfiles.isEmpty() || !installedProfiles.isEmpty()) {
if (profilesUri == null) {
@@ -330,6 +334,7 @@ public class AssemblyMojo extends MojoSupport {
builder.blacklistBundles(blacklistedBundles);
builder.blacklistFeatures(blacklistedFeatures);
builder.blacklistProfiles(blacklistedProfiles);
+ builder.blacklistRepositories(blacklistedRepositories);
builder.blacklistPolicy(blacklistPolicy);
if (propertyFileEdits != null) {
http://git-wip-us.apache.org/repos/asf/karaf/blob/69f54ee1/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
index 289c238..96b9f88 100644
--- a/util/src/main/java/org/apache/karaf/util/maven/Parser.java
+++ b/util/src/main/java/org/apache/karaf/util/maven/Parser.java
@@ -156,10 +156,28 @@ public class Parser
* @throws MalformedURLException in case of "bad" provided URL/URI.
*/
public static String pathFromMaven(String uri) throws MalformedURLException {
+ return pathFromMaven(uri, null);
+ }
+
+ public static String pathFromMaven(String uri, String resolved) throws MalformedURLException {
if (!uri.startsWith("mvn:")) {
return uri;
}
- return new Parser(uri.substring("mvn:".length())).getArtifactPath();
+ Parser parser = new Parser(uri.substring("mvn:".length()));
+ if (resolved != null) {
+ String grp = FILE_SEPARATOR
+ + parser.getGroup().replaceAll(GROUP_SEPARATOR, FILE_SEPARATOR)
+ + FILE_SEPARATOR
+ + parser.getArtifact()
+ + FILE_SEPARATOR;
+ int idx = resolved.indexOf(grp);
+ if (idx >= 0) {
+ String version = resolved.substring(idx + grp.length(), resolved.indexOf('/', idx + grp.length()));
+ return parser.getArtifactPath(version);
+ }
+
+ }
+ return parser.getArtifactPath();
}
public static String pathToMaven(String location, Map parts) {