-
Notifications
You must be signed in to change notification settings - Fork 223
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Simplify Maven Eclipse configuration
A new `walaEclipseMavenCentral` Kotlin DSL extension allows configuring the diffplug MavenCentral plugin more easily by internalizing certain WALA-specific behaviors and adding a few convenience features. See KDoc comments in `build-logic/src/main/kotlin/com/ibm/wala/gradle/eclipse-maven-central.gradle.kts` for more details about what this new extension can do. Resolves #1280.
- Loading branch information
Showing
11 changed files
with
187 additions
and
108 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
115 changes: 115 additions & 0 deletions
115
build-logic/src/main/kotlin/com/ibm/wala/gradle/eclipse-maven-central.gradle.kts
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,115 @@ | ||
package com.ibm.wala.gradle | ||
|
||
import com.diffplug.gradle.eclipse.MavenCentralExtension | ||
import com.diffplug.gradle.eclipse.MavenCentralExtension.ReleaseConfigurer | ||
import com.diffplug.gradle.eclipse.MavenCentralPlugin | ||
import com.diffplug.gradle.pde.EclipseRelease | ||
|
||
/** | ||
* WALA-specialized adaptation of | ||
* [ReleaseConfigurer](https://javadoc.io/doc/com.diffplug.gradle/goomph/latest/com/diffplug/gradle/eclipse/MavenCentralExtension.ReleaseConfigurer.html). | ||
* | ||
* ## WALA-Specific Specializations | ||
* | ||
* ### Release Selection | ||
* | ||
* The standard | ||
* [MavenCentralExtension](https://javadoc.io/doc/com.diffplug.gradle/goomph/latest/com/diffplug/gradle/eclipse/MavenCentralExtension.html) | ||
* offers a few overloaded `release` methods to allow selecting the Eclipse release to configure. | ||
* However, WALA does not need that flexibility. Instead, this extension always configures the | ||
* Eclipse release identified by the `eclipseVersion` extra property on the root project. | ||
* | ||
* ### Default Configuration | ||
* | ||
* This extension always applies [ReleaseConfigurer.constrainTransitivesToThisRelease] and | ||
* [ReleaseConfigurer.useNativesForRunningPlatform] to the selected release. | ||
* | ||
* ## Generally Useful Additions | ||
* | ||
* ### Variadic Configuration Methods | ||
* | ||
* This extension offers variadic analogs of standard unary [ReleaseConfigurer] dependency-declaring | ||
* methods. For example, [implementation] accepts any number of `bundleId` arguments rather than | ||
* just one as expected by [ReleaseConfigurer.implementation] | ||
* | ||
* ### Test Fixtures Configuration Methods | ||
* | ||
* This extension offers variadic methods for configuring dependencies for test fixtures: | ||
* [testFixturesApi] and [testFixturesImplementation]. | ||
*/ | ||
open class WalaMavenCentralReleaseConfigurerExtension @Inject constructor(project: Project) { | ||
|
||
/** | ||
* Internal [ReleaseConfigurer] instance to which all dependency-declaring methods apply. | ||
* | ||
* This instance always operates on the Eclipse release identified by the `eclipseVersion` extra | ||
* property on the root project. The instance is created lazily in case the root project itself | ||
* loads this extension before setting that property. | ||
*/ | ||
private val configurer by lazy { | ||
project.run { | ||
the<MavenCentralExtension>() | ||
.ReleaseConfigurer(rootProject.extra["eclipseVersion"] as EclipseRelease) | ||
} | ||
} | ||
|
||
/** | ||
* Delegates to [configurer] to apply default WALA configuration. | ||
* | ||
* @see ReleaseConfigurer.constrainTransitivesToThisRelease | ||
* @see ReleaseConfigurer.useNativesForRunningPlatform | ||
*/ | ||
internal fun defaults() = | ||
configurer.run { | ||
constrainTransitivesToThisRelease() | ||
useNativesForRunningPlatform() | ||
} | ||
|
||
/** | ||
* Delegates to [configurer] to configure each argument as an `api` dependency. | ||
* | ||
* @see ReleaseConfigurer.api | ||
*/ | ||
fun api(vararg bundleIds: String) = bundleIds.forEach(configurer::api) | ||
|
||
/** | ||
* Delegates to [configurer] to configure each argument as an `implementation` dependency. | ||
* | ||
* @see ReleaseConfigurer.implementation | ||
*/ | ||
@Suppress("MemberVisibilityCanBePrivate") | ||
fun implementation(vararg bundleIds: String) = bundleIds.forEach(configurer::implementation) | ||
|
||
/** | ||
* Delegates to [configurer] to configure each argument as a `testFixturesApi` dependency. | ||
* | ||
* @see ReleaseConfigurer.dep | ||
*/ | ||
@Suppress("MemberVisibilityCanBePrivate") | ||
fun testFixturesApi(vararg bundleIds: String) = | ||
bundleIds.forEach { configurer.dep("testFixturesApi", it) } | ||
|
||
/** | ||
* Delegates to [configurer] to configure each argument as a `testFixturesImplementation` | ||
* dependency. | ||
* | ||
* @see ReleaseConfigurer.dep | ||
*/ | ||
@Suppress("MemberVisibilityCanBePrivate") | ||
fun testFixturesImplementation(vararg bundleIds: String) = | ||
bundleIds.forEach { configurer.dep("testFixturesImplementation", it) } | ||
|
||
/** | ||
* Delegates to [configurer] to configure each argument as a `testImplementation` dependency. | ||
* | ||
* @see ReleaseConfigurer.testImplementation | ||
*/ | ||
fun testImplementation(vararg bundleIds: String) = | ||
bundleIds.forEach(configurer::testImplementation) | ||
} | ||
|
||
apply<MavenCentralPlugin>() | ||
|
||
extensions.create<WalaMavenCentralReleaseConfigurerExtension>("walaEclipseMavenCentral") | ||
|
||
afterEvaluate { configure(WalaMavenCentralReleaseConfigurerExtension::defaults) } |
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
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.