-
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: create custom merger task (#45)
* feat: create custom merger task * pr remarks
- Loading branch information
1 parent
2da8545
commit 1fca9c5
Showing
12 changed files
with
212 additions
and
7 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
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
31 changes: 31 additions & 0 deletions
31
...ins/edc-build/src/main/java/org/eclipse/edc/plugins/edcbuild/tasks/PrintApiGroupTask.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,31 @@ | ||
/* | ||
* Copyright (c) 2022 Microsoft Corporation | ||
* | ||
* 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: | ||
* Microsoft Corporation - initial API and implementation | ||
* | ||
*/ | ||
|
||
package org.eclipse.edc.plugins.edcbuild.tasks; | ||
|
||
import org.eclipse.edc.plugins.edcbuild.extensions.BuildExtension; | ||
import org.gradle.api.DefaultTask; | ||
import org.gradle.api.tasks.TaskAction; | ||
|
||
import static org.eclipse.edc.plugins.edcbuild.conventions.ConventionFunctions.requireExtension; | ||
|
||
|
||
public class PrintApiGroupTask extends DefaultTask { | ||
|
||
@TaskAction | ||
public void printApiGroup() { | ||
var buildExt = requireExtension(getProject(), BuildExtension.class); | ||
getProject().getLogger().lifecycle("API Group: {}", buildExt.getSwagger().getApiGroup().getOrElse("")); | ||
} | ||
} |
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 @@ | ||
This module contains a gradle plugin that allows to merge partial OpenAPI spec files into one file. |
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,35 @@ | ||
plugins { | ||
`java-gradle-plugin` | ||
id("org.gradle.crypto.checksum") version "1.4.0" | ||
} | ||
|
||
val jupiterVersion: String by project | ||
val assertj: String by project | ||
val groupId: String by project | ||
|
||
dependencies { | ||
// contains the actual merger task | ||
implementation("com.rameshkp:openapi-merger-gradle-plugin:1.0.4") | ||
// needed for the OpenApiDataInvalidException: | ||
implementation("com.rameshkp:openapi-merger-app:1.0.4") | ||
} | ||
|
||
gradlePlugin { | ||
// Define the plugin | ||
plugins { | ||
create("openapi-merger") { | ||
displayName = "openapi-merger" | ||
description = | ||
"Plugin to several OpenAPI spec files into one" | ||
id = "${groupId}.openapi-merger" | ||
implementationClass = "org.eclipse.edc.plugins.openapimerger.OpenApiMergerPlugin" | ||
} | ||
} | ||
} | ||
|
||
pluginBundle { | ||
website = "https://projects.eclipse.org/proposals/eclipse-dataspace-connector" | ||
vcsUrl = "https://github.com/eclipse-dataspaceconnector/GradlePlugins.git" | ||
version = version | ||
tags = listOf("build", "openapi", "merge", "documentation") | ||
} |
40 changes: 40 additions & 0 deletions
40
...enapi-merger/src/main/java/org/eclipse/edc/plugins/openapimerger/OpenApiMergerPlugin.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,40 @@ | ||
/* | ||
* Copyright (c) 2022 Microsoft Corporation | ||
* | ||
* 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: | ||
* Microsoft Corporation - initial API and implementation | ||
* | ||
*/ | ||
|
||
package org.eclipse.edc.plugins.openapimerger; | ||
|
||
import com.rameshkp.openapi.merger.gradle.plugin.OpenApiMergerGradlePlugin; | ||
import org.eclipse.edc.plugins.openapimerger.tasks.MergeApiSpecByPathTask; | ||
import org.gradle.api.Plugin; | ||
import org.gradle.api.Project; | ||
|
||
/** | ||
* Custom grade plugin to avoid module name duplications. | ||
* Checks between modules with a gradle build file that their names are unique in the whole project. | ||
* `samples` and `system-tests` modules are excluded. | ||
* <p> | ||
* Ref: <a href="https://github.com/gradle/gradle/issues/847">Github Issue</a> | ||
*/ | ||
public class OpenApiMergerPlugin implements Plugin<Project> { | ||
|
||
@Override | ||
public void apply(Project project) { | ||
|
||
if (project == project.getRootProject()) { | ||
project.getPlugins().apply(OpenApiMergerGradlePlugin.class); | ||
project.getTasks().register(MergeApiSpecByPathTask.NAME, MergeApiSpecByPathTask.class); | ||
} | ||
} | ||
|
||
} |
41 changes: 41 additions & 0 deletions
41
...ger/src/main/java/org/eclipse/edc/plugins/openapimerger/tasks/MergeApiSpecByPathTask.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,41 @@ | ||
/* | ||
* Copyright (c) 2022 Microsoft Corporation | ||
* | ||
* 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: | ||
* Microsoft Corporation - initial API and implementation | ||
* | ||
*/ | ||
|
||
package org.eclipse.edc.plugins.openapimerger.tasks; | ||
|
||
import com.rameshkp.openapi.merger.gradle.task.OpenApiMergerTask; | ||
import org.gradle.api.tasks.options.Option; | ||
|
||
import java.io.File; | ||
|
||
/** | ||
* Customization of the {@link OpenApiMergerTask}, which allows to pass in the input and output directories via command line. | ||
*/ | ||
public class MergeApiSpecByPathTask extends OpenApiMergerTask { | ||
|
||
public static final String NAME = "mergeApiSpec"; | ||
|
||
@Option(option = "output", description = "Output directory where the merged spec file is stores. Optional.") | ||
public void setOutputDir(String outputDirectory) { | ||
// inject the command line arg into the merger task's config | ||
getOutputFileProperty().set(new File(outputDirectory)); | ||
} | ||
|
||
@Option(option = "input", description = "Input directory where to look for partial specs. Required") | ||
public void setInputDir(String inputDir) { | ||
// inject the command line arg into the merger task's config | ||
getInputDirectory().set(new File(inputDir)); | ||
} | ||
} | ||
|
51 changes: 51 additions & 0 deletions
51
...api-merger/src/test/java/org/eclipse/edc/plugins/modulenames/OpenApiMergerPluginTest.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,51 @@ | ||
/* | ||
* Copyright (c) 2022 Microsoft Corporation | ||
* | ||
* 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: | ||
* Microsoft Corporation - initial API and implementation | ||
* | ||
*/ | ||
|
||
package org.eclipse.edc.plugins.modulenames; | ||
|
||
import org.eclipse.edc.plugins.openapimerger.OpenApiMergerPlugin; | ||
import org.eclipse.edc.plugins.openapimerger.tasks.MergeApiSpecByPathTask; | ||
import org.gradle.api.Project; | ||
import org.gradle.testfixtures.ProjectBuilder; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
class OpenApiMergerPluginTest { | ||
|
||
private Project project; | ||
|
||
@BeforeEach | ||
void setUp() { | ||
project = ProjectBuilder.builder().build(); | ||
project.getPlugins().apply(OpenApiMergerPlugin.class); | ||
} | ||
|
||
@Test | ||
void verify_hasMergerTask() { | ||
assertThat(project.getTasks().findByName(MergeApiSpecByPathTask.NAME)).isNotNull(); | ||
} | ||
|
||
|
||
@Test | ||
void verify_pluginIsOnlyAppliedToRootProject() { | ||
var subproj = ProjectBuilder.builder().withParent(project).build(); | ||
|
||
subproj.getPlugins().apply(OpenApiMergerPlugin.class); | ||
|
||
assertThat(subproj.getTasks().findByName(MergeApiSpecByPathTask.NAME)).isNull(); | ||
} | ||
|
||
} |
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 |
---|---|---|
@@ -1,8 +1,9 @@ | ||
rootProject.name = "edcPlugins" | ||
include("plugins:module-names") | ||
include("plugins:test-summary") | ||
include("plugins:openapi-merger") | ||
include("plugins:edc-build") | ||
include("plugins:autodoc:autodoc-plugin") | ||
include("plugins:autodoc:autodoc-processor") | ||
include("runtime-metamodel") | ||
include("version-catalog") | ||
include("version-catalog") |