-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add autodocBom task to generate Autodoc manifests for BOMs (#282)
- Loading branch information
1 parent
9d042ea
commit c81de48
Showing
7 changed files
with
115 additions
and
13 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
71 changes: 71 additions & 0 deletions
71
...oc/autodoc-plugin/src/main/java/org/eclipse/edc/plugins/autodoc/tasks/AutodocBomTask.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,71 @@ | ||
/* | ||
* Copyright (c) 2024 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Apache License, Version 2.0 which is available at | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* Contributors: | ||
* Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - initial API and implementation | ||
* | ||
*/ | ||
|
||
package org.eclipse.edc.plugins.autodoc.tasks; | ||
|
||
import org.gradle.api.DefaultTask; | ||
import org.gradle.api.tasks.OutputFile; | ||
import org.gradle.api.tasks.TaskAction; | ||
import org.gradle.util.internal.GFileUtils; | ||
|
||
import java.io.File; | ||
|
||
public class AutodocBomTask extends DefaultTask { | ||
|
||
public static final String NAME = "autodocBom"; | ||
public static final String DESCRIPTION = """ | ||
This task is intended for BOM modules. It resolves all autodoc manifests of modules that the BOM depends on | ||
and generates a merged manifest file. By default, this merged file is stored at {project}/build/edc.json. | ||
"""; | ||
private final JsonFileAppender appender; | ||
private File outputFile; | ||
|
||
public AutodocBomTask() { | ||
appender = new JsonFileAppender(getLogger()); | ||
outputFile = getProject().getLayout().getBuildDirectory().file(outputFileName()).get().getAsFile(); | ||
} | ||
|
||
@TaskAction | ||
public void mergeManifests() { | ||
if (!getProject().getName().endsWith("-bom")) { | ||
getLogger().warn("Project name does not end with '-bom'. Is this really a BOM module?"); | ||
} | ||
|
||
var inputDirectory = getProject().getLayout().getBuildDirectory().dir(Constants.DEFAULT_AUTODOC_FOLDER).get(); | ||
if (!inputDirectory.getAsFile().exists()) { | ||
getLogger().info("Input directory does not exist: {}, Skipping", inputDirectory); | ||
return; | ||
} | ||
|
||
var destinationFile = outputFile; | ||
|
||
var files = GFileUtils.listFiles(inputDirectory.getAsFile(), new String[]{ "json" }, false); | ||
getLogger().debug("Appending [{}] additional JSON files to the merged manifest", files.size()); | ||
files.forEach(f -> appender.append(destinationFile, f)); | ||
|
||
} | ||
|
||
@OutputFile | ||
public File getOutputFile() { | ||
return outputFile; | ||
} | ||
|
||
public void setOutputFile(File outputFile) { | ||
this.outputFile = outputFile; | ||
} | ||
|
||
private String outputFileName() { | ||
return "edc.json"; | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
...autodoc/autodoc-plugin/src/main/java/org/eclipse/edc/plugins/autodoc/tasks/Constants.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,19 @@ | ||
/* | ||
* Copyright (c) 2024 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Apache License, Version 2.0 which is available at | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* Contributors: | ||
* Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - initial API and implementation | ||
* | ||
*/ | ||
|
||
package org.eclipse.edc.plugins.autodoc.tasks; | ||
|
||
public interface Constants { | ||
String DEFAULT_AUTODOC_FOLDER = "autodoc"; | ||
} |
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