-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Markers shown on Spring application.yml (#52)
* Markers shown on Spring application.yml * Introduce Traits to match KubernetesResources * Push kind check down into matcher * Add missing license header Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * Rename variable to prevent confusion * Filter before map * Null safe equals * Use AtomicBoolean for search logic * Inline return * Use JsonPathMatcher directly & short circuit after found * Only create KubernetesModel conditionally --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
- Loading branch information
1 parent
8e3d376
commit b711be6
Showing
8 changed files
with
225 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
src/main/java/org/openrewrite/kubernetes/trait/KubernetesResource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* Copyright 2024 the original author or authors. | ||
* <p> | ||
* Licensed 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 | ||
* <p> | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* <p> | ||
* 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.openrewrite.kubernetes.trait; | ||
|
||
import lombok.EqualsAndHashCode; | ||
import lombok.Value; | ||
import org.openrewrite.Cursor; | ||
import org.openrewrite.ExecutionContext; | ||
import org.openrewrite.InMemoryExecutionContext; | ||
import org.openrewrite.internal.lang.Nullable; | ||
import org.openrewrite.kubernetes.UpdateKubernetesModel; | ||
import org.openrewrite.kubernetes.tree.KubernetesModel; | ||
import org.openrewrite.trait.SimpleTraitMatcher; | ||
import org.openrewrite.trait.Trait; | ||
import org.openrewrite.yaml.tree.Yaml; | ||
|
||
@Value | ||
public class KubernetesResource implements Trait<Yaml.Document> { | ||
|
||
Cursor cursor; | ||
KubernetesModel model; | ||
|
||
@Value | ||
@EqualsAndHashCode(callSuper = false) | ||
public static class Matcher extends SimpleTraitMatcher<KubernetesResource> { | ||
|
||
@Nullable | ||
String kind; | ||
|
||
@Override | ||
protected @Nullable KubernetesResource test(Cursor cursor) { | ||
Object value = cursor.getValue(); | ||
if (value instanceof Yaml.Document) { | ||
return new UpdateKubernetesModel<ExecutionContext>() | ||
.visitNonNull((Yaml.Document) value, new InMemoryExecutionContext(), cursor.getParent()) | ||
.getMarkers() | ||
.findFirst(KubernetesModel.class) | ||
.filter(model -> kind == null || kind.equals(model.getKind())) | ||
.map(kubernetesModel -> new KubernetesResource(cursor, kubernetesModel)) | ||
.orElse(null); | ||
} | ||
return null; | ||
} | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
src/main/java/org/openrewrite/kubernetes/trait/Traits.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* Copyright 2024 the original author or authors. | ||
* <p> | ||
* Licensed 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 | ||
* <p> | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* <p> | ||
* 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.openrewrite.kubernetes.trait; | ||
|
||
import org.openrewrite.internal.lang.Nullable; | ||
|
||
public class Traits { | ||
|
||
private Traits() { | ||
} | ||
|
||
public static KubernetesResource.Matcher kubernetesResource(@Nullable String kind) { | ||
return new KubernetesResource.Matcher(kind); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.