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 2020/09/19 20:07:01 UTC
[camel] 01/02: CAMEL-15478: Generate api json sorted A..Z so its
the same always
This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git
commit a3444e0f18a135220690c58d99f0888da119c231
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Sat Sep 19 17:22:02 2020 +0200
CAMEL-15478: Generate api json sorted A..Z so its the same always
---
.../org/apache/camel/tooling/model/ApiModel.java | 7 +++--
.../apache/camel/tooling/model/Comparators.java | 33 ++++++++++++++++++++++
.../apache/camel/tooling/model/ComponentModel.java | 7 +++--
.../org/apache/camel/tooling/model/JsonMapper.java | 4 +--
.../packaging/EndpointSchemaGeneratorMojo.java | 2 +-
.../camel/maven/packaging/UpdateReadmeMojo.java | 10 -------
6 files changed, 46 insertions(+), 17 deletions(-)
diff --git a/tooling/camel-tooling-model/src/main/java/org/apache/camel/tooling/model/ApiModel.java b/tooling/camel-tooling-model/src/main/java/org/apache/camel/tooling/model/ApiModel.java
index fdc5bc8..cf76a6a 100644
--- a/tooling/camel-tooling-model/src/main/java/org/apache/camel/tooling/model/ApiModel.java
+++ b/tooling/camel-tooling-model/src/main/java/org/apache/camel/tooling/model/ApiModel.java
@@ -17,14 +17,17 @@
package org.apache.camel.tooling.model;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.List;
+import java.util.TreeSet;
public final class ApiModel {
private String name;
private String description;
private final List<String> aliases = new ArrayList<>();
- private final List<ApiMethodModel> methods = new ArrayList<>();
+ // lets sort api methods A..Z so they are always in the same order
+ private final Collection<ApiMethodModel> methods = new TreeSet<>(Comparators.apiMethodModelModelComparator());
public String getName() {
return name;
@@ -50,7 +53,7 @@ public final class ApiModel {
this.aliases.add(alias);
}
- public List<ApiMethodModel> getMethods() {
+ public Collection<ApiMethodModel> getMethods() {
return methods;
}
diff --git a/tooling/camel-tooling-model/src/main/java/org/apache/camel/tooling/model/Comparators.java b/tooling/camel-tooling-model/src/main/java/org/apache/camel/tooling/model/Comparators.java
new file mode 100644
index 0000000..8879c4c
--- /dev/null
+++ b/tooling/camel-tooling-model/src/main/java/org/apache/camel/tooling/model/Comparators.java
@@ -0,0 +1,33 @@
+/*
+ * 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.model;
+
+import java.util.Comparator;
+
+public final class Comparators {
+
+ private Comparators() {
+ }
+
+ public static Comparator<ApiModel> apiModelComparator() {
+ return (o1, o2) -> o1.getName().compareToIgnoreCase(o2.getName());
+ }
+
+ public static Comparator<ApiMethodModel> apiMethodModelModelComparator() {
+ return (o1, o2) -> o1.getName().compareToIgnoreCase(o2.getName());
+ }
+}
diff --git a/tooling/camel-tooling-model/src/main/java/org/apache/camel/tooling/model/ComponentModel.java b/tooling/camel-tooling-model/src/main/java/org/apache/camel/tooling/model/ComponentModel.java
index 23f8687..727bf1b 100644
--- a/tooling/camel-tooling-model/src/main/java/org/apache/camel/tooling/model/ComponentModel.java
+++ b/tooling/camel-tooling-model/src/main/java/org/apache/camel/tooling/model/ComponentModel.java
@@ -17,7 +17,9 @@
package org.apache.camel.tooling.model;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.List;
+import java.util.TreeSet;
import java.util.stream.Collectors;
public class ComponentModel extends ArtifactModel<ComponentModel.ComponentOptionModel> {
@@ -35,7 +37,8 @@ public class ComponentModel extends ArtifactModel<ComponentModel.ComponentOption
protected boolean lenientProperties;
protected String verifiers;
protected final List<EndpointOptionModel> endpointOptions = new ArrayList<>();
- protected final List<ApiModel> apiOptions = new ArrayList<>();
+ // lets sort apis A..Z so they are always in the same order
+ protected final Collection<ApiModel> apiOptions = new TreeSet<>(Comparators.apiModelComparator());
public ComponentModel() {
}
@@ -169,7 +172,7 @@ public class ComponentModel extends ArtifactModel<ComponentModel.ComponentOption
.collect(Collectors.toList());
}
- public List<ApiModel> getApiOptions() {
+ public Collection<ApiModel> getApiOptions() {
return apiOptions;
}
diff --git a/tooling/camel-tooling-model/src/main/java/org/apache/camel/tooling/model/JsonMapper.java b/tooling/camel-tooling-model/src/main/java/org/apache/camel/tooling/model/JsonMapper.java
index 2615d95..f207c7e 100644
--- a/tooling/camel-tooling-model/src/main/java/org/apache/camel/tooling/model/JsonMapper.java
+++ b/tooling/camel-tooling-model/src/main/java/org/apache/camel/tooling/model/JsonMapper.java
@@ -105,9 +105,9 @@ public final class JsonMapper {
String name = entry.getKey();
JsonObject mp = (JsonObject) entry.getValue();
ApiModel am = new ApiModel();
- model.getApiOptions().add(am);
am.setName(name);
am.setDescription(mp.getStringOrDefault("description", ""));
+ model.getApiOptions().add(am);
Collection<String> aliases = mp.getCollection("aliases");
if (aliases != null && !aliases.isEmpty()) {
aliases.forEach(am::addAlias);
@@ -441,7 +441,7 @@ public final class JsonMapper {
return json;
}
- public static JsonObject apiModelAsJsonObject(List<ApiModel> model, boolean options) {
+ public static JsonObject apiModelAsJsonObject(Collection<ApiModel> model, boolean options) {
JsonObject root = new JsonObject();
model.forEach(a -> {
JsonObject json = new JsonObject();
diff --git a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/EndpointSchemaGeneratorMojo.java b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/EndpointSchemaGeneratorMojo.java
index 2d301d3..cef2eed 100644
--- a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/EndpointSchemaGeneratorMojo.java
+++ b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/EndpointSchemaGeneratorMojo.java
@@ -1107,6 +1107,7 @@ public class EndpointSchemaGeneratorMojo extends AbstractGeneratorMojo {
.findFirst();
if (!op.isPresent()) {
api = new ApiModel();
+ api.setName(apiName);
componentModel.getApiOptions().add(api);
if (apiParams != null) {
for (String alias : apiParams.aliases()) {
@@ -1119,7 +1120,6 @@ public class EndpointSchemaGeneratorMojo extends AbstractGeneratorMojo {
} else {
api = op.get();
}
- api.setName(apiName);
for (ApiMethod method : apiParam.apiMethods()) {
ApiMethodModel apiMethod = null;
for (ApiMethodModel m : api.getMethods()) {
diff --git a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/UpdateReadmeMojo.java b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/UpdateReadmeMojo.java
index e228666..0067ff2 100644
--- a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/UpdateReadmeMojo.java
+++ b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/UpdateReadmeMojo.java
@@ -34,7 +34,6 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Stream;
-import org.apache.camel.tooling.model.ApiModel;
import org.apache.camel.tooling.model.ArtifactModel;
import org.apache.camel.tooling.model.BaseModel;
import org.apache.camel.tooling.model.BaseOptionModel;
@@ -185,15 +184,6 @@ public class UpdateReadmeMojo extends AbstractGeneratorMojo {
option.setDescription(desc);
});
- // sort API groups
- if (model.isApi()) {
- List<ApiModel> sorted = new ArrayList<>();
- sorted.addAll(model.getApiOptions());
- Collections.sort(sorted, (o1, o2) -> o1.getName().compareToIgnoreCase(o2.getName()));
- model.getApiOptions().clear();
- model.getApiOptions().addAll(sorted);
- }
-
String options = evaluateTemplate("component-options.mvel", model);
updated |= updateOptionsIn(file, "component", options);