-
Notifications
You must be signed in to change notification settings - Fork 9
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
feat: add autodocBom task to generate Autodoc manifests for BOMs #282
Merged
paullatzelsperger
merged 1 commit into
eclipse-edc:main
from
paullatzelsperger:feat/add_autodocBom_task
Oct 17, 2024
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe this functionality shouldn't be limited to bom modules, e.g. an EDC distribution (like Tractus-X) could be interested in generating a comprehensive autodoc out of a set of dependencies.
the warning wouldn't be needed then
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this would require a bit of refactoring, because then, the
autodocBom
task would not depend on theresolveManifest
task anymore, but on eitherresolveManifest
ordownloadManifests
.alternatively,
resolveManifest
anddownloadManifest
could be merged into one, and artifact resolution (of the manifest file) happens dynamically based on its URI.Definitely worth exploring, though in a different PR, IMO.