You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by GitBox <gi...@apache.org> on 2021/07/06 07:44:28 UTC

[GitHub] [camel-quarkus] jamesnetherton opened a new pull request #2881: Leverage catalog metadata to discover unremovable types

jamesnetherton opened a new pull request #2881:
URL: https://github.com/apache/camel-quarkus/pull/2881


   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel-quarkus] ppalaga commented on pull request #2881: Leverage catalog metadata to discover unremovable types

Posted by GitBox <gi...@apache.org>.
ppalaga commented on pull request #2881:
URL: https://github.com/apache/camel-quarkus/pull/2881#issuecomment-877120444


   Nice work, thanks @jamesnetherton !


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel-quarkus] aldettinger commented on a change in pull request #2881: Leverage catalog metadata to discover unremovable types

Posted by GitBox <gi...@apache.org>.
aldettinger commented on a change in pull request #2881:
URL: https://github.com/apache/camel-quarkus/pull/2881#discussion_r665147696



##########
File path: extensions-core/core/deployment/src/main/java/org/apache/camel/quarkus/core/deployment/catalog/BuildTimeCamelCatalog.java
##########
@@ -0,0 +1,86 @@
+/*
+ * 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.quarkus.core.deployment.catalog;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Objects;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+import org.apache.camel.catalog.impl.AbstractCamelCatalog;
+import org.apache.camel.tooling.model.BaseOptionModel;
+import org.apache.camel.tooling.model.ComponentModel;
+
+public class BuildTimeCamelCatalog extends AbstractCamelCatalog {
+
+    public BuildTimeCamelCatalog(BuildTimeJsonSchemaResolver resolver) {
+        setJSonSchemaResolver(resolver);
+    }
+
+    public BuildTimeJsonSchemaResolver getJSonSchemaResolver() {
+        return (BuildTimeJsonSchemaResolver) super.getJSonSchemaResolver();
+    }
+
+    /**
+     * Gets a list of all component, endpoint, dataformat & language options for the components that are on the classpath
+     * 
+     * @return List of {@link BaseOptionModel} instances
+     */
+    public List<BaseOptionModel> getAllOptions() {
+        List<BaseOptionModel> options = new ArrayList<>();
+        BuildTimeJsonSchemaResolver resolver = getJSonSchemaResolver();
+        Set<SchemaResource> schemaResources = resolver.getSchemaResources();
+
+        // Component options
+        List<ComponentModel> componentModels = schemaResources
+                .stream()
+                .map(SchemaResource::getName)
+                .map(this::componentModel)
+                .filter(Objects::nonNull)
+                .collect(Collectors.toList());
+
+        // For components we need to combine the component options with the endpoint options
+        componentModels.stream()
+                .flatMap(componentModel -> componentModel.getComponentOptions().stream())
+                .forEach(options::add);
+
+        componentModels.stream()

Review comment:
       this statement may be a duplicate ?




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel-quarkus] jamesnetherton commented on a change in pull request #2881: Leverage catalog metadata to discover unremovable types

Posted by GitBox <gi...@apache.org>.
jamesnetherton commented on a change in pull request #2881:
URL: https://github.com/apache/camel-quarkus/pull/2881#discussion_r665157707



##########
File path: extensions-core/core/deployment/src/main/java/org/apache/camel/quarkus/core/deployment/catalog/SchemaResource.java
##########
@@ -0,0 +1,109 @@
+/*
+ * 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.quarkus.core.deployment.catalog;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Objects;
+
+import org.apache.camel.util.IOHelper;
+import org.jboss.jandex.DotName;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class SchemaResource {
+    private static final Logger LOGGER = LoggerFactory.getLogger(SchemaResource.class);
+
+    private String type;
+    private String name;
+    private DotName className;
+
+    public String getType() {
+        return type;
+    }
+
+    public void setType(String type) {
+        this.type = type;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public DotName getClassName() {
+        return className;
+    }
+
+    public void setClassName(DotName className) {
+        this.className = className;
+    }
+
+    public String getLocation() {
+        String packageName = className.prefix().toString();
+        return packageName.replace('.', '/') + "/" + name + ".json";
+    }
+
+    public String load() {
+        InputStream resource = Thread.currentThread().getContextClassLoader().getResourceAsStream(getLocation());
+        if (resource != null) {
+            try {
+                if (LOGGER.isDebugEnabled()) {
+                    LOGGER.debug("Resolved JSON schema resource: {}", getLocation());
+                }
+
+                return IOHelper.loadText(resource);
+            } catch (IOException e) {
+                if (LOGGER.isErrorEnabled()) {
+                    LOGGER.error("Unable to load JSON schema resource: {}", getLocation(), e);
+                }
+            } finally {
+                IOHelper.close(resource);
+            }
+        }
+        return null;
+    }
+
+    @Override
+    public boolean equals(Object o) {
+        if (this == o) {
+            return true;
+        }
+
+        if (o == null || getClass() != o.getClass()) {
+            return false;
+        }
+
+        SchemaResource that = (SchemaResource) o;
+        return Objects.equals(type, that.type)
+                && Objects.equals(name, that.name)
+                && Objects.equals(className, that.className);
+    }
+
+    @Override
+    public int hashCode() {
+        return Objects.hash(type, name, className);
+    }
+
+    @Override
+    public String toString() {
+        return "SchemaInfo{" + "type='" + type + '\'' + ", name='" + name + '\'' + ", packageName='" + className + '\'' + '}';

Review comment:
       > neat pick :) But maybe we could say "SchemaResource" instead of "SchemaInfo" ?
   
   Yeah, I renamed that class quite a few times :grinning:. I'll fix...




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel-quarkus] jamesnetherton merged pull request #2881: Leverage catalog metadata to discover unremovable types

Posted by GitBox <gi...@apache.org>.
jamesnetherton merged pull request #2881:
URL: https://github.com/apache/camel-quarkus/pull/2881


   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel-quarkus] aldettinger commented on a change in pull request #2881: Leverage catalog metadata to discover unremovable types

Posted by GitBox <gi...@apache.org>.
aldettinger commented on a change in pull request #2881:
URL: https://github.com/apache/camel-quarkus/pull/2881#discussion_r665155219



##########
File path: extensions-core/core/deployment/src/main/java/org/apache/camel/quarkus/core/deployment/catalog/SchemaResource.java
##########
@@ -0,0 +1,109 @@
+/*
+ * 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.quarkus.core.deployment.catalog;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Objects;
+
+import org.apache.camel.util.IOHelper;
+import org.jboss.jandex.DotName;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class SchemaResource {
+    private static final Logger LOGGER = LoggerFactory.getLogger(SchemaResource.class);
+
+    private String type;
+    private String name;
+    private DotName className;
+
+    public String getType() {
+        return type;
+    }
+
+    public void setType(String type) {
+        this.type = type;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public DotName getClassName() {
+        return className;
+    }
+
+    public void setClassName(DotName className) {
+        this.className = className;
+    }
+
+    public String getLocation() {
+        String packageName = className.prefix().toString();
+        return packageName.replace('.', '/') + "/" + name + ".json";
+    }
+
+    public String load() {
+        InputStream resource = Thread.currentThread().getContextClassLoader().getResourceAsStream(getLocation());
+        if (resource != null) {
+            try {
+                if (LOGGER.isDebugEnabled()) {
+                    LOGGER.debug("Resolved JSON schema resource: {}", getLocation());
+                }
+
+                return IOHelper.loadText(resource);
+            } catch (IOException e) {
+                if (LOGGER.isErrorEnabled()) {
+                    LOGGER.error("Unable to load JSON schema resource: {}", getLocation(), e);
+                }
+            } finally {
+                IOHelper.close(resource);
+            }
+        }
+        return null;
+    }
+
+    @Override
+    public boolean equals(Object o) {
+        if (this == o) {
+            return true;
+        }
+
+        if (o == null || getClass() != o.getClass()) {
+            return false;
+        }
+
+        SchemaResource that = (SchemaResource) o;
+        return Objects.equals(type, that.type)
+                && Objects.equals(name, that.name)
+                && Objects.equals(className, that.className);
+    }
+
+    @Override
+    public int hashCode() {
+        return Objects.hash(type, name, className);
+    }
+
+    @Override
+    public String toString() {
+        return "SchemaInfo{" + "type='" + type + '\'' + ", name='" + name + '\'' + ", packageName='" + className + '\'' + '}';

Review comment:
       neat pick :) But maybe we could say "SchemaResource" instead of "SchemaInfo"

##########
File path: extensions-core/core/deployment/src/main/java/org/apache/camel/quarkus/core/deployment/catalog/SchemaResource.java
##########
@@ -0,0 +1,109 @@
+/*
+ * 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.quarkus.core.deployment.catalog;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Objects;
+
+import org.apache.camel.util.IOHelper;
+import org.jboss.jandex.DotName;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class SchemaResource {
+    private static final Logger LOGGER = LoggerFactory.getLogger(SchemaResource.class);
+
+    private String type;
+    private String name;
+    private DotName className;
+
+    public String getType() {
+        return type;
+    }
+
+    public void setType(String type) {
+        this.type = type;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public DotName getClassName() {
+        return className;
+    }
+
+    public void setClassName(DotName className) {
+        this.className = className;
+    }
+
+    public String getLocation() {
+        String packageName = className.prefix().toString();
+        return packageName.replace('.', '/') + "/" + name + ".json";
+    }
+
+    public String load() {
+        InputStream resource = Thread.currentThread().getContextClassLoader().getResourceAsStream(getLocation());
+        if (resource != null) {
+            try {
+                if (LOGGER.isDebugEnabled()) {
+                    LOGGER.debug("Resolved JSON schema resource: {}", getLocation());
+                }
+
+                return IOHelper.loadText(resource);
+            } catch (IOException e) {
+                if (LOGGER.isErrorEnabled()) {
+                    LOGGER.error("Unable to load JSON schema resource: {}", getLocation(), e);
+                }
+            } finally {
+                IOHelper.close(resource);
+            }
+        }
+        return null;
+    }
+
+    @Override
+    public boolean equals(Object o) {
+        if (this == o) {
+            return true;
+        }
+
+        if (o == null || getClass() != o.getClass()) {
+            return false;
+        }
+
+        SchemaResource that = (SchemaResource) o;
+        return Objects.equals(type, that.type)
+                && Objects.equals(name, that.name)
+                && Objects.equals(className, that.className);
+    }
+
+    @Override
+    public int hashCode() {
+        return Objects.hash(type, name, className);
+    }
+
+    @Override
+    public String toString() {
+        return "SchemaInfo{" + "type='" + type + '\'' + ", name='" + name + '\'' + ", packageName='" + className + '\'' + '}';

Review comment:
       neat pick :) But maybe we could say "SchemaResource" instead of "SchemaInfo" ?




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org