Skip to content

Commit

Permalink
fix: add default licenses property to pom.xml and remove support for …
Browse files Browse the repository at this point in the history
…licenseOptions in Java (#733)
  • Loading branch information
agdimech authored Mar 24, 2024
1 parent 1f530c1 commit 09420b6
Show file tree
Hide file tree
Showing 5 changed files with 355 additions and 13 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 21 additions & 4 deletions packages/monorepo/src/components/nx-configurator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -500,22 +500,39 @@ export class NxConfigurator extends Component implements INxProjectCore {
* Add licenses to any subprojects which don't already have a license.
*/
private _addLicenses() {
this.project.subprojects
[this.project, ...this.project.subprojects]
.filter(
(p) => p.components.find((c) => c instanceof License) === undefined
)
.forEach((p) => {
if (!this.licenseOptions || this.licenseOptions.spdx) {
if (!this.licenseOptions) {
new License(p, {
spdx: this.licenseOptions?.spdx ?? DEFAULT_LICENSE,
copyrightOwner: this.licenseOptions?.copyrightOwner,
spdx: DEFAULT_LICENSE,
});
if (ProjectUtils.isNamedInstanceOf(p, JavaProject)) {
// Force all Java projects to use Apache 2.0
p.tryFindObjectFile("pom.xml")?.addOverride("project.licenses", [
{
license: {
name: "Apache License 2.0",
url: "https://www.apache.org/licenses/LICENSE-2.0",
distribution: "repo",
comments: "An OSI-approved license",
},
},
]);
}
} else if (!!this.licenseOptions?.licenseText) {
new TextFile(p, "LICENSE", {
marker: false,
committed: true,
lines: this.licenseOptions.licenseText.split("\n"),
});
} else if (this.licenseOptions.spdx) {
new License(p, {
spdx: this.licenseOptions.spdx,
copyrightOwner: this.licenseOptions?.copyrightOwner,
});
} else {
throw new Error("Either spdx or licenseText must be specified.");
}
Expand Down
9 changes: 0 additions & 9 deletions packages/monorepo/src/projects/java/monorepo-java.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { JavaProjectOptions } from "./java-project-options";
import {
NxConfigurator,
INxProjectCore,
LicenseOptions,
} from "../../components/nx-configurator";
import { NxWorkspace } from "../../components/nx-workspace";
import {
Expand All @@ -26,13 +25,6 @@ const MVN_PLUGIN_PATH = "./.nx/plugins/nx_plugin.js";
*/
export interface MonorepoJavaOptions extends JavaProjectOptions {
readonly defaultReleaseBranch?: string;

/**
* Default license to apply to all PDK managed packages.
*
* @default Apache-2.0
*/
readonly licenseOptions?: LicenseOptions;
}

/**
Expand Down Expand Up @@ -80,7 +72,6 @@ export class MonorepoJavaProject extends JavaProject implements INxProjectCore {

this.nxConfigurator = new NxConfigurator(this, {
defaultReleaseBranch: options.defaultReleaseBranch ?? "main",
licenseOptions: options.licenseOptions,
});

// Setup maven nx plugin
Expand Down
Loading

0 comments on commit 09420b6

Please sign in to comment.