Skip to content

Commit

Permalink
Catalog json keys should be sorted #576
Browse files Browse the repository at this point in the history
  • Loading branch information
lburgazzoli committed Jan 11, 2021
1 parent aa70150 commit 94b4c63
Show file tree
Hide file tree
Showing 12 changed files with 131 additions and 119 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,42 @@
*/
package org.apache.camel.k.catalog.model;

import java.util.Comparator;
import java.util.Optional;

public interface Artifact {
import com.fasterxml.jackson.annotation.JsonPropertyOrder;

@JsonPropertyOrder({"groupId", "artifactId", "version"})
public interface Artifact extends Comparable<Artifact> {
String getGroupId();;
String getArtifactId();
Optional<String> getVersion();

@Override
default int compareTo(Artifact o) {
return Comparator
.comparing(Artifact::getGroupId)
.thenComparing(Artifact::getArtifactId)
.thenComparing(Artifact::getVersion, Comparator.comparing(c -> c.orElse("")))
.compare(this, o);
}

static Artifact from(String groupId, String artifactId) {
return new Artifact() {
@Override
public String getGroupId() {
return groupId;
}

@Override
public String getArtifactId() {
return artifactId;
}

@Override
public Optional<String> getVersion() {
return Optional.empty();
}
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package org.apache.camel.k.catalog.model;

import java.util.Collections;
import java.util.Set;
import java.util.SortedSet;

import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
Expand All @@ -30,38 +30,44 @@
public interface CamelArtifact extends Artifact {
@Value.Auxiliary
@Value.Default
default Set<CamelScheme> getSchemes() {
return Collections.emptySet();
@Value.NaturalOrder
default SortedSet<CamelScheme> getSchemes() {
return Collections.emptySortedSet();
}

@Value.Auxiliary
@Value.Default
default Set<String> getLanguages() {
return Collections.emptySet();
@Value.NaturalOrder
default SortedSet<String> getLanguages() {
return Collections.emptySortedSet();
}

@Value.Auxiliary
@Value.Default
default Set<String> getDataformats() {
return Collections.emptySet();
@Value.NaturalOrder
default SortedSet<String> getDataformats() {
return Collections.emptySortedSet();
}

@Value.Auxiliary
@Value.Default
default Set<Artifact> getDependencies() {
return Collections.emptySet();
@Value.NaturalOrder
default SortedSet<Artifact> getDependencies() {
return Collections.emptySortedSet();
}

@Value.Auxiliary
@Value.Default
default Set<Artifact> getExclusions() {
return Collections.emptySet();
@Value.NaturalOrder
default SortedSet<Artifact> getExclusions() {
return Collections.emptySortedSet();
}

@Value.Auxiliary
@Value.Default
default Set<String> getJavaTypes() {
return Collections.emptySet();
@Value.NaturalOrder
default SortedSet<String> getJavaTypes() {
return Collections.emptySortedSet();
}

static Builder from(String groupId, String artifactId) {
Expand All @@ -70,7 +76,7 @@ static Builder from(String groupId, String artifactId) {

class Builder extends ImmutableCamelArtifact.Builder {
public Builder addDependency(String groupId, String artifactId) {
return super.addDependencies(MavenArtifact.from(groupId, artifactId));
return super.addDependencies(Artifact.from(groupId, artifactId));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package org.apache.camel.k.catalog.model;

import java.util.Collections;
import java.util.Set;
import java.util.SortedSet;

import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
Expand All @@ -30,8 +30,9 @@
public interface CamelCapability {
@Value.Auxiliary
@Value.Default
default Set<Artifact> getDependencies() {
return Collections.emptySet();
@Value.NaturalOrder
default SortedSet<Artifact> getDependencies() {
return Collections.emptySortedSet();
}

static CamelCapability forArtifact(String groupId, String artifactId) {
Expand All @@ -40,8 +41,7 @@ static CamelCapability forArtifact(String groupId, String artifactId) {

class Builder extends ImmutableCamelCapability.Builder {
public Builder addDependency(String groupId, String artifactId) {
addDependencies(MavenArtifact.from(groupId, artifactId));
return this;
return super.addDependencies(Artifact.from(groupId, artifactId));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
package org.apache.camel.k.catalog.model;

import java.util.Collections;
import java.util.Map;
import java.util.Set;
import java.util.SortedMap;
import java.util.SortedSet;

import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
Expand All @@ -31,20 +31,23 @@
public interface CamelLoader extends Artifact {
@Value.Auxiliary
@Value.Default
default Set<String> getLanguages() {
return Collections.emptySet();
@Value.NaturalOrder
default SortedSet<String> getLanguages() {
return Collections.emptySortedSet();
}

@Value.Auxiliary
@Value.Default
default Set<Artifact> getDependencies() {
return Collections.emptySet();
@Value.NaturalOrder
default SortedSet<Artifact> getDependencies() {
return Collections.emptySortedSet();
}

@Value.Auxiliary
@Value.Default
default Map<String, String> getMetadata() {
return Collections.emptyMap();
@Value.NaturalOrder
default SortedMap<String, String> getMetadata() {
return Collections.emptySortedMap();
}

static Builder fromArtifact(String groupId, String artifactId) {
Expand All @@ -53,8 +56,7 @@ static Builder fromArtifact(String groupId, String artifactId) {

class Builder extends ImmutableCamelLoader.Builder {
public Builder addDependency(String groupId, String artifactId) {
addDependencies(MavenArtifact.from(groupId, artifactId));
return this;
return super.addDependencies(Artifact.from(groupId, artifactId));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,16 @@
package org.apache.camel.k.catalog.model;

import java.util.Collections;
import java.util.Comparator;
import java.util.Optional;
import java.util.Set;
import java.util.SortedSet;

import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import org.immutables.value.Value;

@Value.Immutable
@JsonDeserialize(builder = CamelScheme.Builder.class)
public interface CamelScheme {
public interface CamelScheme extends Comparable<CamelScheme> {
String getId();

@Value.Auxiliary
Expand All @@ -42,8 +43,9 @@ default boolean passive() {

@Value.Auxiliary
@Value.Default
default Set<String> getRequiredCapabilities() {
return Collections.emptySet();
@Value.NaturalOrder
default SortedSet<String> getRequiredCapabilities() {
return Collections.emptySortedSet();
}

@Value.Auxiliary
Expand All @@ -52,6 +54,13 @@ default Set<String> getRequiredCapabilities() {
@Value.Auxiliary
Optional<CamelScopedArtifact> getConsumer();

@Override
default int compareTo(CamelScheme o) {
return Comparator
.comparing(CamelScheme::getId)
.compare(this, o);
}

class Builder extends ImmutableCamelScheme.Builder {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package org.apache.camel.k.catalog.model;

import java.util.Collections;
import java.util.Set;
import java.util.SortedSet;

import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
Expand All @@ -30,19 +30,21 @@
public interface CamelScopedArtifact {
@Value.Auxiliary
@Value.Default
default Set<Artifact> getDependencies() {
return Collections.emptySet();
@Value.NaturalOrder
default SortedSet<Artifact> getDependencies() {
return Collections.emptySortedSet();
}

@Value.Auxiliary
@Value.Default
default Set<String> getRequiredCapabilities() {
return Collections.emptySet();
@Value.NaturalOrder
default SortedSet<String> getRequiredCapabilities() {
return Collections.emptySortedSet();
}

class Builder extends ImmutableCamelScopedArtifact.Builder {
public Builder addDependency(String groupId, String artifactId) {
return super.addDependencies(MavenArtifact.from(groupId, artifactId));
return super.addDependencies(Artifact.from(groupId, artifactId));
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package org.apache.camel.k.catalog.model.k8s;

import java.util.Collections;
import java.util.Map;
import java.util.SortedMap;

import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import org.immutables.value.Value;
Expand All @@ -28,8 +28,9 @@ public interface ObjectMeta {
String getName();

@Value.Default
default Map<String, String> getLabels() {
return Collections.emptyMap();
@Value.NaturalOrder
default SortedMap<String, String> getLabels() {
return Collections.emptySortedMap();
}

class Builder extends ImmutableObjectMeta.Builder {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package org.apache.camel.k.catalog.model.k8s.crd;

import java.util.Collections;
import java.util.Map;
import java.util.SortedMap;

import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
Expand All @@ -33,23 +33,24 @@ public interface CamelCatalogSpec {
RuntimeSpec getRuntime();

@Value.Default
default Map<String, CamelArtifact> getArtifacts() {
return Collections.emptyMap();
@Value.NaturalOrder
default SortedMap<String, CamelArtifact> getArtifacts() {
return Collections.emptySortedMap();
}

@Value.Default
default Map<String, CamelLoader> getLoaders() {
return Collections.emptyMap();
@Value.NaturalOrder
default SortedMap<String, CamelLoader> getLoaders() {
return Collections.emptySortedMap();
}

class Builder extends ImmutableCamelCatalogSpec.Builder {
public Builder putArtifact(CamelArtifact artifact) {
putArtifact(artifact.getArtifactId(), artifact);
return this;
return putArtifact(artifact.getArtifactId(), artifact);
}

public Builder putArtifact(String groupId, String artifactId) {
putArtifact(new CamelArtifact.Builder().groupId(groupId).artifactId(artifactId).build());
return this;
return putArtifact(new CamelArtifact.Builder().groupId(groupId).artifactId(artifactId).build());
}
}
}
Loading

0 comments on commit 94b4c63

Please sign in to comment.