Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include camel-k-runtime version in camel-catalog #142

Merged
merged 2 commits into from
Sep 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@
</sourceDirectories>
<headerLocation>header-java.txt</headerLocation>
<includes>**/*.java,**/*.groovy,**/*.scala,**/*.properties,**/*.xml,**/*.xsd</includes>
<excludes>**/MyRoutes*.java,**/routes*.java</excludes>
<excludes>**/MyRoutes*.java,**/routes*.java,**/verify.groovy</excludes>
</configuration>
<goals>
<goal>checkstyle</goal>
Expand Down
43 changes: 43 additions & 0 deletions tooling/camel-k-maven-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,18 @@

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
<addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-plugin-plugin</artifactId>
Expand All @@ -187,6 +199,37 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-invoker-plugin</artifactId>
<configuration>
<cloneProjectsTo>${project.build.directory}/it</cloneProjectsTo>
<cloneClean>true</cloneClean>
<postBuildHookScript>verify</postBuildHookScript>
<addTestClassPath>true</addTestClassPath>
<streamLogs>true</streamLogs>
<goals>
<goal>generate-resources</goal>
</goals>
</configuration>
<executions>
<execution>
<id>integration-tests</id>
<goals>
<goal>install</goal>
<goal>run</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.yaml</groupId>
<artifactId>snakeyaml</artifactId>
<version>1.25</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</project>
109 changes: 109 additions & 0 deletions tooling/camel-k-maven-plugin/src/it/generate-catalog/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--

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.

-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">


<modelVersion>4.0.0</modelVersion>
<groupId>org.apache.camel.k</groupId>
<artifactId>camel-k-catalog-generator</artifactId>
<version>1.0.0</version>

<properties>
<catalog.path>${project.basedir}</catalog.path>
<camel.version>3.0.0-RC1</camel.version>
<runtime.version>1.0.2-SNAPSHOT</runtime.version>
</properties>

<build>
<plugins>
<plugin>
<groupId>org.apache.camel.k</groupId>
<artifactId>camel-k-maven-plugin</artifactId>
<version>${runtime.version}</version>
<executions>
<execution>
<id>generate-catalog</id>
<goals>
<goal>generate-catalog</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-catalog</artifactId>
<version>${camel.version}</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>

<repositories>
<repository>
<id>apache.snapshots</id>
<name>Apache Development Snapshot Repository</name>
<url>https://repository.apache.org/content/repositories/snapshots/</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
<repository>
<id>oss.snapshots</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>

<pluginRepositories>
<pluginRepository>
<id>apache.snapshots</id>
<name>Apache Development Snapshot Repository</name>
<url>https://repository.apache.org/content/repositories/snapshots/</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
<pluginRepository>
<id>oss.snapshots</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>

</project>
26 changes: 26 additions & 0 deletions tooling/camel-k-maven-plugin/src/it/generate-catalog/verify.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* 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.
*/
def catalogVersion = '3.0.0-RC1'
def runtimeVersion = '1.0.2-SNAPSHOT'

def source = new File(basedir, "camel-catalog-${catalogVersion}-${runtimeVersion}.yaml")
def catalog = new org.yaml.snakeyaml.Yaml().load(new FileInputStream(source))

assert catalog.spec.version == catalogVersion
assert catalog.spec.runtimeVersion == runtimeVersion
assert catalog.metadata.labels['camel.apache.org/catalog.version'] == catalogVersion
assert catalog.metadata.labels['camel.apache.org/runtime.version'] == runtimeVersion
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package org.apache.camel.k.tooling.maven;

import java.io.IOException;
import java.io.InputStream;
import java.io.Writer;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
Expand All @@ -25,6 +26,7 @@
import java.util.Comparator;
import java.util.Map;
import java.util.Objects;
import java.util.Properties;
import java.util.ServiceLoader;
import java.util.SortedMap;
import java.util.TreeMap;
Expand Down Expand Up @@ -69,7 +71,7 @@ public class GenerateCatalogMojo extends AbstractMojo {
@Parameter(property = "catalog.path", defaultValue = "${project.build.directory}")
private String outputPath;

@Parameter(property = "catalog.file", defaultValue = "camel-catalog-${catalog.version}.yaml")
@Parameter(property = "catalog.file", defaultValue = "camel-catalog-${camel.version}-${runtime.version}.yaml")
private String outputFile;

// ********************
Expand Down Expand Up @@ -116,26 +118,35 @@ public void execute() throws MojoExecutionException, MojoFailureException {
// apiVersion: camel.apache.org/v1alpha1
// kind: CamelCatalog
// metadata:
// name: catalog-x.y.z
// name: catalog-x.y.z-a.b.c
// labels:
// app: "camel-k"
// camel.apache.org/catalog.version: x.y.x
// camel.apache.org/catalog.loader.version: x.y.z
// camel.apache.org/runtime.version: x.y.x
// spec:
// version:
// runtimeVersion:
// status:
// artifacts:
//
try (Writer writer = Files.newBufferedWriter(output, StandardCharsets.UTF_8)) {
String catalogName = String.format("camel-catalog-%s-%s",
catalog.getCatalogVersion().toLowerCase(),
getRuntimeVersion().toLowerCase()
);

CamelCatalog cr = new CamelCatalog.Builder()
.metadata(new ObjectMeta.Builder()
.name("camel-catalog-" + catalog.getCatalogVersion().toLowerCase())
.name(catalogName)
.putLabels("app", "camel-k")
.putLabels("camel.apache.org/catalog.version", catalog.getCatalogVersion())
.putLabels("camel.apache.org/catalog.loader.version", catalog.getLoadedVersion())
.putLabels("camel.apache.org/runtime.version", getRuntimeVersion())
.build())
.spec(new CamelCatalogSpec.Builder()
.version(catalog.getCatalogVersion())
.runtimeVersion(getRuntimeVersion())
.artifacts(artifacts)
.build())
.build();
Expand All @@ -152,6 +163,8 @@ public void execute() throws MojoExecutionException, MojoFailureException {
GenerateSupport.getResourceAsString("/catalog-license.txt")
);

getLog().info("Writing catalog file to: " + output);

// write catalog data
ObjectMapper mapper = new ObjectMapper(factory);
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
Expand Down Expand Up @@ -237,4 +250,42 @@ private void processDataFormats(org.apache.camel.catalog.CamelCatalog catalog, M
});
}
}

public synchronized String getRuntimeVersion() {
String version = null;

// try to load from maven properties first
try {

InputStream is = getClass().getResourceAsStream(
"/META-INF/maven/org.apache.camel.k/camel-k-maven-plugin/pom.properties"
);

if (is != null) {
Properties p = new Properties();
p.load(is);
version = p.getProperty("version", "");
}
} catch (Exception e) {
// ignore
}

// fallback to using Java API
if (version == null) {
Package aPackage = getClass().getPackage();
if (aPackage != null) {
version = aPackage.getImplementationVersion();
if (version == null) {
version = aPackage.getSpecificationVersion();
}
}
}

if (version == null) {
// we could not compute the version so use a blank
throw new IllegalStateException("Unable to determine runtime version");
}

return version;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@

@Value.Immutable
@JsonDeserialize(builder = CamelCatalogSpec.Builder.class)
@JsonPropertyOrder({ "version", "artifacts" })
@JsonPropertyOrder({ "version", "runtimeVersion", "artifacts" })
public interface CamelCatalogSpec {
String getVersion();
String getRuntimeVersion();

@Value.Default
default SortedMap<String, CamelArtifact> getArtifacts() {
Expand Down