You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2023/03/15 09:29:12 UTC

[camel] branch camel-3.x updated: CAMEL-19145: maven downloaded - Add known maven repos to use ids instead of urls.

This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch camel-3.x
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/camel-3.x by this push:
     new 72d5cf69b7c CAMEL-19145: maven downloaded - Add known maven repos to use ids instead of urls.
72d5cf69b7c is described below

commit 72d5cf69b7ca6cbb7fb2f562a698b367e16505ba
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Wed Mar 15 10:28:24 2023 +0100

    CAMEL-19145: maven downloaded - Add known maven repos to use ids instead of urls.
---
 .../tooling/maven/DefaultRepositoryResolver.java   | 47 ++++++++++++++++++++++
 .../camel/tooling/maven/MavenDownloaderImpl.java   |  6 +++
 .../camel/tooling/maven/RepositoryResolver.java    | 31 ++++++++++++++
 .../main/resources/known-maven-repos.properties    | 22 ++++++++++
 4 files changed, 106 insertions(+)

diff --git a/tooling/camel-tooling-maven/src/main/java/org/apache/camel/tooling/maven/DefaultRepositoryResolver.java b/tooling/camel-tooling-maven/src/main/java/org/apache/camel/tooling/maven/DefaultRepositoryResolver.java
new file mode 100644
index 00000000000..7661f6d3958
--- /dev/null
+++ b/tooling/camel-tooling-maven/src/main/java/org/apache/camel/tooling/maven/DefaultRepositoryResolver.java
@@ -0,0 +1,47 @@
+/*
+ * 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.camel.tooling.maven;
+
+import java.io.InputStream;
+import java.util.Properties;
+
+import org.apache.camel.support.service.ServiceSupport;
+import org.apache.camel.util.IOHelper;
+
+public class DefaultRepositoryResolver extends ServiceSupport implements RepositoryResolver {
+
+    private Properties repos;
+
+    @Override
+    public String resolveRepository(String idOrUrl) {
+        String answer = idOrUrl;
+        if (repos != null) {
+            answer = repos.getProperty(idOrUrl, idOrUrl);
+        }
+        return answer;
+    }
+
+    @Override
+    protected void doBuild() throws Exception {
+        InputStream is = RepositoryResolver.class.getClassLoader().getResourceAsStream("known-maven-repos.properties");
+        if (is != null) {
+            repos = new Properties();
+            repos.load(is);
+        }
+        IOHelper.close(is);
+    }
+}
diff --git a/tooling/camel-tooling-maven/src/main/java/org/apache/camel/tooling/maven/MavenDownloaderImpl.java b/tooling/camel-tooling-maven/src/main/java/org/apache/camel/tooling/maven/MavenDownloaderImpl.java
index 4d2682dc829..fbdb342c00a 100644
--- a/tooling/camel-tooling-maven/src/main/java/org/apache/camel/tooling/maven/MavenDownloaderImpl.java
+++ b/tooling/camel-tooling-maven/src/main/java/org/apache/camel/tooling/maven/MavenDownloaderImpl.java
@@ -225,6 +225,8 @@ public class MavenDownloaderImpl extends ServiceSupport implements MavenDownload
     private static final RepositoryPolicy POLICY_DISABLED = new RepositoryPolicy(
             false, RepositoryPolicy.UPDATE_POLICY_NEVER, RepositoryPolicy.CHECKSUM_POLICY_IGNORE);
 
+    private RepositoryResolver repositoryResolver;
+
     private RepositorySystem repositorySystem;
     private RepositorySystemSession repositorySystemSession;
 
@@ -259,6 +261,9 @@ public class MavenDownloaderImpl extends ServiceSupport implements MavenDownload
     protected void doBuild() {
         // prepare all services that don't change when resolving Maven artifacts
 
+        repositoryResolver = new DefaultRepositoryResolver();
+        repositoryResolver.build();
+
         // Aether/maven-resolver configuration used without Shrinkwrap
         // and without deprecated:
         //  - org.eclipse.aether.impl.DefaultServiceLocator
@@ -1162,6 +1167,7 @@ public class MavenDownloaderImpl extends ServiceSupport implements MavenDownload
     private void configureRepositories(List<RemoteRepository> repositories, Set<String> urls) {
         urls.forEach(repo -> {
             try {
+                repo = repositoryResolver.resolveRepository(repo);
                 URL url = new URL(repo);
                 if (url.getHost().equals("repo1.maven.org")) {
                     // Maven Central is always used, so skip it
diff --git a/tooling/camel-tooling-maven/src/main/java/org/apache/camel/tooling/maven/RepositoryResolver.java b/tooling/camel-tooling-maven/src/main/java/org/apache/camel/tooling/maven/RepositoryResolver.java
new file mode 100644
index 00000000000..a6305fbc9bf
--- /dev/null
+++ b/tooling/camel-tooling-maven/src/main/java/org/apache/camel/tooling/maven/RepositoryResolver.java
@@ -0,0 +1,31 @@
+/*
+ * 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.camel.tooling.maven;
+
+import org.apache.camel.StaticService;
+
+public interface RepositoryResolver extends StaticService {
+
+    /**
+     * Resolves the maven repository.
+     *
+     * @param  idOrUrl id or url
+     * @return         url of the maven repository
+     */
+    String resolveRepository(String idOrUrl);
+
+}
diff --git a/tooling/camel-tooling-maven/src/main/resources/known-maven-repos.properties b/tooling/camel-tooling-maven/src/main/resources/known-maven-repos.properties
new file mode 100644
index 00000000000..a7713de3ea1
--- /dev/null
+++ b/tooling/camel-tooling-maven/src/main/resources/known-maven-repos.properties
@@ -0,0 +1,22 @@
+## ---------------------------------------------------------------------------
+## 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.
+## ---------------------------------------------------------------------------
+
+central = https://repo1.maven.org/maven2
+apache-snapshot = https://repository.apache.org/snapshots
+atlassian = https://packages.atlassian.com/maven-external
+jboss = https://repository.jboss.org/nexus/service/local/repositories/thirdparty-releases/content
+redhat = https://maven.repository.redhat.com/ga
\ No newline at end of file