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

initial config for subproject pkg customization #15

Merged
merged 1 commit into from
Sep 25, 2023
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
7 changes: 7 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@ gradlePlugin {
description = "This plugin generates json formatted spdx sboms for gradle projects"
tags.set(listOf("spdx", "sbom"))
}
create("spdxPackage") {
id = "org.spdx.sbom-package"
implementationClass = "org.spdx.sbom.gradle.SpdxPackagePlugin"
displayName = "Companion plugin to org.spdx.sbom"
description = "This plugin enables customization of spdx package properties on subprojects"
tags.set(listOf("spdx", "sbom"))
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,15 @@ void canRunTask() throws IOException, SpdxVerificationException {

Path sub = projectDir.toPath().resolve("sub-project");
Files.createDirectories(sub);
writeString(sub.resolve("build.gradle").toFile(), "plugins {\n" + " id('java')\n" + "}\n");
writeString(
sub.resolve("build.gradle").toFile(),
"plugins {\n"
+ " id('org.spdx.sbom-package')\n"
+ " id('java')\n"
+ "}\n"
+ "spdxPackage {\n"
+ " supplier.set(\"someone\")\n"
+ "}\n");

Path lib = sub.resolve(Paths.get("src/main/java/lib/Lib.java"));
Files.createDirectories(lib.getParent());
Expand Down
45 changes: 45 additions & 0 deletions src/main/java/org/spdx/sbom/gradle/SpdxPackageExtension.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright 2023 The Project Authors.
*
* 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
*
* 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.spdx.sbom.gradle;

import org.gradle.api.Action;
import org.gradle.api.provider.Property;
import org.gradle.api.tasks.Nested;

public abstract class SpdxPackageExtension {
public abstract Property<String> getName();

public abstract Property<String> getVersion();

public abstract Property<String> getSupplier();

public abstract Property<Boolean> getCreatePackage();

@Nested
public abstract SpdxSbomExtension.Scm getScm();

public void scm(Action<? super SpdxSbomExtension.Scm> configure) {
configure.execute(getScm());
}

abstract class Scm {
public abstract Property<String> getTool();

public abstract Property<String> getUri();

public abstract Property<String> getRevision();
}
}
31 changes: 31 additions & 0 deletions src/main/java/org/spdx/sbom/gradle/SpdxPackagePlugin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright 2023 The Project Authors.
*
* 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
*
* 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.spdx.sbom.gradle;

import org.gradle.api.Plugin;
import org.gradle.api.Project;
import org.jetbrains.annotations.NotNull;

public class SpdxPackagePlugin implements Plugin<Project> {

@Override
public void apply(@NotNull Project project) {
var extension = project.getExtensions().create("spdxPackage", SpdxPackageExtension.class);
extension.getName().convention(project.getName());
extension.getVersion().convention(project.getVersion().toString());
extension.getCreatePackage().convention(true);
}
}
Loading