generated from oracle/template-repo
-
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.
- Loading branch information
1 parent
832f7dd
commit 4fc6a54
Showing
23 changed files
with
241 additions
and
95 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
70 changes: 70 additions & 0 deletions
70
gdk-core/src/main/java/cloud/graal/gdk/feature/misc/CycloneDXPlugin.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,70 @@ | ||
/* | ||
* Copyright 2025 Oracle and/or its affiliates | ||
* | ||
* 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 | ||
* | ||
* https://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 cloud.graal.gdk.feature.misc; | ||
|
||
import cloud.graal.gdk.GdkGeneratorContext; | ||
import io.micronaut.core.annotation.NonNull; | ||
import io.micronaut.starter.application.ApplicationType; | ||
import io.micronaut.starter.application.generator.GeneratorContext; | ||
import io.micronaut.starter.feature.Feature; | ||
import io.micronaut.starter.feature.graalvm.GraalVM; | ||
import io.micronaut.starter.options.BuildTool; | ||
import jakarta.inject.Singleton; | ||
|
||
@Singleton | ||
public class CycloneDXPlugin implements Feature { | ||
|
||
/** | ||
* The feature name. | ||
*/ | ||
public static final String NAME = "cyclone-dx-plugin"; | ||
|
||
private static final CycloneDXPluginPostProcessor CYCLONE_DX_POST_PROCESSOR = new CycloneDXPluginPostProcessor(BuildTool.GRADLE); | ||
|
||
private final GraalVM graalvm; | ||
|
||
public CycloneDXPlugin(GraalVM graalvm) { | ||
this.graalvm = graalvm; | ||
} | ||
|
||
@Override | ||
public void apply(GeneratorContext ctx) { | ||
if (ctx.getBuildTool().isGradle()) { | ||
String template = "build"; | ||
if (!((GdkGeneratorContext) ctx).getCloud().getModuleName().isBlank()) { | ||
template = template + "-" + ((GdkGeneratorContext) ctx).getCloud().getModuleName(); | ||
} | ||
((GdkGeneratorContext) ctx).addPostProcessor(template, CYCLONE_DX_POST_PROCESSOR); | ||
} | ||
} | ||
|
||
@NonNull | ||
@Override | ||
public String getName() { | ||
return NAME; | ||
} | ||
|
||
@Override | ||
public boolean supports(ApplicationType applicationType) { | ||
return true; | ||
} | ||
|
||
@Override | ||
public boolean isVisible() { | ||
return false; | ||
} | ||
|
||
} |
55 changes: 55 additions & 0 deletions
55
gdk-core/src/main/java/cloud/graal/gdk/feature/misc/CycloneDXPluginPostProcessor.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,55 @@ | ||
/* | ||
* Copyright 2025 Oracle and/or its affiliates | ||
* | ||
* 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 | ||
* | ||
* https://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 cloud.graal.gdk.feature.misc; | ||
|
||
import cloud.graal.gdk.template.TemplatePostProcessor; | ||
import io.micronaut.core.annotation.NonNull; | ||
import io.micronaut.starter.options.BuildTool; | ||
|
||
public class CycloneDXPluginPostProcessor implements TemplatePostProcessor { | ||
|
||
private static final String PLUGIN_START = "plugins {"; | ||
private static final String CYCLONE_DX_PLUGIN = "\n\tid 'org.cyclonedx.bom' version '2.1.0'"; | ||
|
||
private static final String CYCLONE_DX_CONFIG = """ | ||
cyclonedxBom { | ||
includeConfigs = ["compileClasspath", "runtimeClasspath"] | ||
} | ||
"""; | ||
|
||
private final BuildTool buildTool; | ||
|
||
public CycloneDXPluginPostProcessor(BuildTool buildTool) { | ||
this.buildTool = buildTool; | ||
} | ||
|
||
@NonNull | ||
@Override | ||
public String process(@NonNull String input) { | ||
String result = input; | ||
if (buildTool.isGradle()) { | ||
int start = input.indexOf(PLUGIN_START); | ||
if (start >= 0) { | ||
start += PLUGIN_START.length(); | ||
String top = input.substring(0, start); | ||
String bottom = input.substring(start); | ||
result = top + CYCLONE_DX_PLUGIN + bottom + CYCLONE_DX_CONFIG; | ||
} | ||
} | ||
return result; | ||
} | ||
|
||
} |
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
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
Oops, something went wrong.