This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push:
new 47e446b3f69 CAMEL-18206: camel-catalog - Add API to check if an
artifact exists with a given GAV
47e446b3f69 is described below
commit 47e446b3f69c18bd600b93700507610acf793838
Author: Claus Ibsen <[email protected]>
AuthorDate: Sat Jun 18 09:42:39 2022 +0200
CAMEL-18206: camel-catalog - Add API to check if an artifact exists with a
given GAV
---
.../org/apache/camel/catalog/CamelCatalog.java | 13 ++++++++
.../apache/camel/catalog/DefaultCamelCatalog.java | 35 ++++++++++++++++++++++
.../org/apache/camel/catalog/CamelCatalogTest.java | 33 ++++++++++++++++++++
3 files changed, 81 insertions(+)
diff --git
a/catalog/camel-catalog/src/main/java/org/apache/camel/catalog/CamelCatalog.java
b/catalog/camel-catalog/src/main/java/org/apache/camel/catalog/CamelCatalog.java
index 007cd388e23..ff9bcf1d13c 100644
---
a/catalog/camel-catalog/src/main/java/org/apache/camel/catalog/CamelCatalog.java
+++
b/catalog/camel-catalog/src/main/java/org/apache/camel/catalog/CamelCatalog.java
@@ -21,6 +21,7 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
+import org.apache.camel.tooling.model.ArtifactModel;
import org.apache.camel.tooling.model.BaseModel;
import org.apache.camel.tooling.model.ComponentModel;
import org.apache.camel.tooling.model.DataFormatModel;
@@ -536,6 +537,8 @@ public interface CamelCatalog {
MainModel mainModel();
/**
+ * Lookup the model for the given kind and name
+ *
* @param kind the requested kind
* @param name the name to look up
* @return the requested model or {@code null} in case it is not
available in this {@link CamelCatalog}
@@ -557,4 +560,14 @@ public interface CamelCatalog {
}
}
+ /**
+ * Lookup the model for the given Maven GAV
+ *
+ * @param groupId maven group id
+ * @param artifactId maven artifact id
+ * @param version maven version (optional)
+ * @return the requested model or {@code null} in case it is
not available in this {@link CamelCatalog}
+ */
+ ArtifactModel<?> modelFromMavenGAV(String groupId, String artifactId,
String version);
+
}
diff --git
a/catalog/camel-catalog/src/main/java/org/apache/camel/catalog/DefaultCamelCatalog.java
b/catalog/camel-catalog/src/main/java/org/apache/camel/catalog/DefaultCamelCatalog.java
index bfe16c9450b..8791b097985 100644
---
a/catalog/camel-catalog/src/main/java/org/apache/camel/catalog/DefaultCamelCatalog.java
+++
b/catalog/camel-catalog/src/main/java/org/apache/camel/catalog/DefaultCamelCatalog.java
@@ -43,6 +43,7 @@ import org.w3c.dom.Document;
import org.apache.camel.catalog.impl.AbstractCamelCatalog;
import org.apache.camel.catalog.impl.CatalogHelper;
+import org.apache.camel.tooling.model.ArtifactModel;
import org.apache.camel.tooling.model.BaseModel;
import org.apache.camel.tooling.model.ComponentModel;
import org.apache.camel.tooling.model.DataFormatModel;
@@ -465,6 +466,40 @@ public class DefaultCamelCatalog extends
AbstractCamelCatalog implements CamelCa
});
}
+ @Override
+ public ArtifactModel<?> modelFromMavenGAV(String groupId, String
artifactId, String version) {
+ for (String name : findComponentNames()) {
+ ArtifactModel<?> am = componentModel(name);
+ if (matchArtifact(am, groupId, artifactId, version)) {
+ return am;
+ }
+ }
+ for (String name : findDataFormatNames()) {
+ ArtifactModel<?> am = dataFormatModel(name);
+ if (matchArtifact(am, groupId, artifactId, version)) {
+ return am;
+ }
+ }
+ for (String name : findLanguageNames()) {
+ ArtifactModel<?> am = languageModel(name);
+ if (matchArtifact(am, groupId, artifactId, version)) {
+ return am;
+ }
+ }
+ for (String name : findOtherNames()) {
+ ArtifactModel<?> am = otherModel(name);
+ if (matchArtifact(am, groupId, artifactId, version)) {
+ return am;
+ }
+ }
+ return null;
+ }
+
+ private static boolean matchArtifact(ArtifactModel<?> am, String groupId,
String artifactId, String version) {
+ return groupId.equals(am.getGroupId()) &&
artifactId.equals(am.getArtifactId())
+ && (version == null || version.isBlank() ||
version.equals(am.getVersion()));
+ }
+
private int getArchetypesCount() {
int archetypes = 0;
try {
diff --git
a/catalog/camel-catalog/src/test/java/org/apache/camel/catalog/CamelCatalogTest.java
b/catalog/camel-catalog/src/test/java/org/apache/camel/catalog/CamelCatalogTest.java
index 4c6ae210985..407ec076ce2 100644
---
a/catalog/camel-catalog/src/test/java/org/apache/camel/catalog/CamelCatalogTest.java
+++
b/catalog/camel-catalog/src/test/java/org/apache/camel/catalog/CamelCatalogTest.java
@@ -24,6 +24,12 @@ import java.util.Map;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
+import org.apache.camel.tooling.model.ArtifactModel;
+import org.apache.camel.tooling.model.ComponentModel;
+import org.apache.camel.tooling.model.DataFormatModel;
+import org.apache.camel.tooling.model.LanguageModel;
+import org.apache.camel.tooling.model.OtherModel;
+import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
@@ -1544,4 +1550,31 @@ public class CamelCatalogTest {
assertTrue(result.isSuccess());
}
+ @Test
+ public void modelFromMavenGAV() {
+ ArtifactModel<?> am = catalog.modelFromMavenGAV("org.apache.camel",
"camel-ftp", catalog.getCatalogVersion());
+ Assertions.assertInstanceOf(ComponentModel.class, am);
+ Assertions.assertEquals("Upload and download files to/from FTP
servers.", am.getDescription());
+
+ am = catalog.modelFromMavenGAV("org.apache.camel", "camel-ognl",
catalog.getCatalogVersion());
+ Assertions.assertInstanceOf(LanguageModel.class, am);
+ Assertions.assertEquals("Evaluates an OGNL expression (Apache Commons
OGNL).", am.getDescription());
+
+ am = catalog.modelFromMavenGAV("org.apache.camel", "camel-bindy",
catalog.getCatalogVersion());
+ Assertions.assertInstanceOf(DataFormatModel.class, am);
+ Assertions.assertEquals("Marshal and unmarshal between POJOs and Comma
separated values (CSV) format using Camel Bindy",
+ am.getDescription());
+
+ am = catalog.modelFromMavenGAV("org.apache.camel", "camel-zipkin",
catalog.getCatalogVersion());
+ Assertions.assertInstanceOf(OtherModel.class, am);
+ Assertions.assertEquals("Distributed message tracing using Zipkin",
am.getDescription());
+
+ am = catalog.modelFromMavenGAV("org.apache.camel", "camel-unknown",
catalog.getCatalogVersion());
+ Assertions.assertNull(am);
+
+ am = catalog.modelFromMavenGAV("org.apache.camel", "camel-jms", null);
+ Assertions.assertInstanceOf(ComponentModel.class, am);
+ Assertions.assertEquals("Sent and receive messages to/from a JMS Queue
or Topic.", am.getDescription());
+ }
+
}