This repository has been archived by the owner on Jan 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Perform version checking and version mapping against separate configs
Previously the springioTestRuntime configuration was used both when checking that all of a project's dependencies were part of the platform and when modifying those dependencies to use the platform's versions. This meant that test-only dependencies had to be included in the Platform. This commit updates the plugin to use separate configuration for checking that a dependency is in the platform. By default the checking will be performed against the runtime configuration that's provided by the Java plugin. The task can be configured to use a different configuration: springioDependencyVersionMappingCheck { configuration = configurations.configurationToCheck } The configuration options for controlling whether or not unmapped direct dependencies and unmapped transitive dependencies should cause a failure have been moved from the Spring IO platform extension onto this task. These options can be configured as follows: springioDependencyVersionMappingCheck { failOnUnmappedDirectDependency = true failOnUnmappedTransitiveDependency = true } The Spring IO platform extension has been removed.
- Loading branch information
1 parent
aeefc3d
commit 5523434
Showing
14 changed files
with
447 additions
and
423 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
37 changes: 37 additions & 0 deletions
37
...ingframework/build/gradle/springio/platform/AbstractDependencyResolveDetailsAction.groovy
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,37 @@ | ||
import java.util.Map; | ||
import java.util.Set; | ||
|
||
import org.gradle.api.Action; | ||
import org.gradle.api.artifacts.DependencyResolveDetails; | ||
import org.gradle.api.artifacts.ModuleVersionSelector; | ||
|
||
abstract class AbstractDependencyResolveDetailsAction implements Action<DependencyResolveDetails> { | ||
|
||
Map<String,ModuleVersionSelector> dependencyToSelector = [:] | ||
|
||
/** | ||
* In the form {@code group:name} | ||
*/ | ||
Set<String> ignoredDependencies = [] | ||
|
||
void execute(DependencyResolveDetails details) { | ||
if (!isIgnoredDependency(details)) { | ||
ModuleVersionSelector selector = getSelector(details) | ||
execute(details, selector) | ||
} | ||
} | ||
|
||
protected abstract void execute(DependencyResolveDetails details, ModuleVersionSelector springIoMapping) | ||
|
||
private boolean isIgnoredDependency(DependencyResolveDetails details) { | ||
ignoredDependencies.contains(getId(details)) | ||
} | ||
|
||
protected ModuleVersionSelector getSelector(DependencyResolveDetails details) { | ||
dependencyToSelector[getId(details)] | ||
} | ||
|
||
private String getId(DependencyResolveDetails details) { | ||
"$details.requested.group:$details.requested.name" | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
...ork/build/gradle/springio/platform/AbstractPlatformDependenciesBeforeResolveAction.groovy
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,57 @@ | ||
package org.springframework.build.gradle.springio.platform; | ||
|
||
import org.gradle.api.Action | ||
import org.gradle.api.InvalidUserDataException | ||
import org.gradle.api.Project | ||
import org.gradle.api.artifacts.Configuration | ||
import org.gradle.api.artifacts.Dependency; | ||
import org.gradle.api.artifacts.DependencyResolveDetails | ||
import org.gradle.api.artifacts.ModuleVersionSelector | ||
import org.gradle.api.artifacts.ResolvableDependencies | ||
import org.gradle.api.internal.artifacts.DefaultModuleVersionSelector | ||
|
||
/** | ||
* @author Rob Winch | ||
* @author Andy Wilkinson | ||
*/ | ||
abstract class AbstractPlatformDependenciesBeforeResolveAction implements Action<ResolvableDependencies> { | ||
|
||
Project project | ||
|
||
Configuration configuration | ||
|
||
String resource = 'springio-dependencies' | ||
|
||
@Override | ||
public void execute(ResolvableDependencies resolvableDependencies) { | ||
Map<String, ModuleVersionSelector> selectors = createSelectorsFromStream(getClass().getResourceAsStream(resource)) | ||
doExecute(resolvableDependencies, selectors) | ||
} | ||
|
||
abstract void doExecute(ResolvableDependencies resolvableDependencies, Map<String, ModuleVersionSelector> selectors) | ||
|
||
/** | ||
* Reads the given stream, each line of which is expected to be in the format {@code group:artifact:version}, and | ||
* returns a {@code Map<String, ModuleVersionSelector>} where the keys are of the form {@code group:version} and | ||
* the values are ModuleVersion selectors created with {@code group}, {@code name}, and {@code version}. | ||
* | ||
* @param stream The stream to read the dependency information from | ||
* | ||
* @return The map of selectors | ||
*/ | ||
private Map<String, ModuleVersionSelector> createSelectorsFromStream(InputStream stream) { | ||
Map<String,ModuleVersionSelector> depToSelector = [:] | ||
stream.eachLine { line -> | ||
if(line && !line.startsWith('#')) { | ||
def (group, name, version) = line.split(':') | ||
depToSelector.put("$group:$name" as String, new DefaultModuleVersionSelector(group, name, version)) | ||
} | ||
} | ||
depToSelector | ||
} | ||
|
||
protected Set<String> getIgnoredDependencies() { | ||
project.rootProject.allprojects.collect { "$it.group:$it.name" as String } | ||
} | ||
|
||
} |
70 changes: 70 additions & 0 deletions
70
...mework/build/gradle/springio/platform/CheckPlatformDependenciesBeforeResolveAction.groovy
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,70 @@ | ||
package org.springframework.build.gradle.springio.platform | ||
|
||
import org.gradle.api.InvalidUserDataException | ||
import org.gradle.api.artifacts.Configuration | ||
import org.gradle.api.artifacts.Dependency | ||
import org.gradle.api.artifacts.DependencyResolveDetails | ||
import org.gradle.api.artifacts.ModuleVersionSelector | ||
import org.gradle.api.artifacts.ResolvableDependencies | ||
|
||
class CheckPlatformDependenciesBeforeResolveAction extends AbstractPlatformDependenciesBeforeResolveAction { | ||
|
||
boolean failOnUnmappedDirectDependency = true | ||
|
||
boolean failOnUnmappedTransitiveDependency = false | ||
|
||
@Override | ||
public void doExecute(ResolvableDependencies resolvableDependencies, Map<String, ModuleVersionSelector> selectors) { | ||
CheckingDependencyResolveDetailsAction checkingAction = new CheckingDependencyResolveDetailsAction( | ||
dependencyToSelector: selectors, configuration: configuration, ignoredDependencies: ignoredDependencies) | ||
|
||
configuration.resolutionStrategy.eachDependency checkingAction | ||
configuration.incoming.afterResolve { | ||
String message | ||
if (failOnUnmappedDirectDependency && checkingAction.unmappedDirectDependencies) { | ||
message = "The following direct dependencies do not have Spring IO versions: " + checkingAction.unmappedDirectDependencies.collect { "$it.group:$it.name" }.join(", ") | ||
} | ||
|
||
if (failOnUnmappedTransitiveDependency && checkingAction.unmappedTransitiveDependencies) { | ||
message = message ? message + ". " : "" | ||
message += "The following transitive dependencies do not have Spring IO versions: " + checkingAction.unmappedTransitiveDependencies.collect { "$it.group:$it.name" }.join(", ") | ||
} | ||
|
||
if (message) { | ||
throw new InvalidUserDataException(message) | ||
} | ||
} | ||
} | ||
|
||
private static class CheckingDependencyResolveDetailsAction extends AbstractDependencyResolveDetailsAction { | ||
|
||
Configuration configuration | ||
|
||
List<ModuleVersionSelector> unmappedDirectDependencies = [] | ||
|
||
List<ModuleVersionSelector> unmappedTransitiveDependencies = [] | ||
|
||
void execute(DependencyResolveDetails details, ModuleVersionSelector springIoMapping) { | ||
ModuleVersionSelector requested = details.requested | ||
if(!springIoMapping) { | ||
if (isDirectDependency(requested)) { | ||
unmappedDirectDependencies << requested | ||
} else { | ||
unmappedTransitiveDependencies << requested | ||
} | ||
} else { | ||
details.useTarget springIoMapping | ||
} | ||
} | ||
|
||
private boolean isDirectDependency(ModuleVersionSelector selector) { | ||
for (Dependency dependency: configuration.allDependencies) { | ||
if (dependency.group == selector.group && dependency.name == selector.name) { | ||
return true | ||
} | ||
} | ||
return false | ||
} | ||
} | ||
|
||
} |
41 changes: 41 additions & 0 deletions
41
...g/springframework/build/gradle/springio/platform/DependencyVersionMappingCheckTask.groovy
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 @@ | ||
package org.springframework.build.gradle.springio.platform | ||
|
||
import org.gradle.api.DefaultTask | ||
import org.gradle.api.artifacts.Configuration | ||
import org.gradle.api.plugins.JavaPlugin | ||
import org.gradle.api.tasks.Input | ||
import org.gradle.api.tasks.Optional | ||
import org.gradle.api.tasks.TaskAction | ||
|
||
class DependencyVersionMappingCheckTask extends DefaultTask { | ||
|
||
@Input | ||
@Optional | ||
Configuration configuration | ||
|
||
@Input | ||
@Optional | ||
boolean failOnUnmappedDirectDependency = true | ||
|
||
@Input | ||
@Optional | ||
boolean failOnUnmappedTransitiveDependency = false | ||
|
||
@TaskAction | ||
void checkVersionMapping() { | ||
if (!configuration) { | ||
configuration = project.configurations.getByName(JavaPlugin.RUNTIME_CONFIGURATION_NAME) | ||
} | ||
|
||
configuration.incoming.beforeResolve( | ||
new CheckPlatformDependenciesBeforeResolveAction(project: project, configuration: configuration, | ||
failOnUnmappedDirectDependency: failOnUnmappedDirectDependency, | ||
failOnUnmappedTransitiveDependency: failOnUnmappedTransitiveDependency)) | ||
|
||
configuration.resolvedConfiguration | ||
} | ||
|
||
void setConfiguration(Configuration configuration) { | ||
this.configuration = configuration; | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
...ramework/build/gradle/springio/platform/MapPlatformDependenciesBeforeResolveAction.groovy
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,23 @@ | ||
package org.springframework.build.gradle.springio.platform | ||
|
||
import org.gradle.api.artifacts.DependencyResolveDetails; | ||
import org.gradle.api.artifacts.ModuleVersionSelector; | ||
import org.gradle.api.artifacts.ResolvableDependencies; | ||
|
||
class MapPlatformDependenciesBeforeResolveAction extends AbstractPlatformDependenciesBeforeResolveAction { | ||
|
||
@Override | ||
public void doExecute(ResolvableDependencies resolvableDependencies, Map<String, ModuleVersionSelector> selectors) { | ||
MappingDependencyResolveDetailsAction action = new MappingDependencyResolveDetailsAction( | ||
dependencyToSelector: selectors, ignoredDependencies: ignoredDependencies) | ||
configuration.resolutionStrategy.eachDependency action | ||
} | ||
|
||
private static class MappingDependencyResolveDetailsAction extends AbstractDependencyResolveDetailsAction { | ||
void execute(DependencyResolveDetails details, ModuleVersionSelector springIoMapping) { | ||
if(springIoMapping) { | ||
details.useTarget springIoMapping | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.