Search in sources :

Example 1 with ComponentSelectionRulesWithCurrent

use of com.github.benmanes.gradle.versions.updates.resolutionstrategy.ComponentSelectionRulesWithCurrent in project spring-security by spring-projects.

the class UpdateDependenciesPlugin method apply.

@Override
public void apply(Project project) {
    UpdateDependenciesExtension updateDependenciesSettings = project.getExtensions().create("updateDependenciesSettings", UpdateDependenciesExtension.class, defaultFiles(project));
    if (project.hasProperty("updateMode")) {
        String updateMode = String.valueOf(project.findProperty("updateMode"));
        updateDependenciesSettings.setUpdateMode(UpdateDependenciesExtension.UpdateMode.valueOf(updateMode));
    }
    if (project.hasProperty("nextVersion")) {
        String nextVersion = String.valueOf(project.findProperty("nextVersion"));
        updateDependenciesSettings.getGitHub().setMilestone(nextVersion);
    }
    if (project.hasProperty("gitHubAccessToken")) {
        String gitHubAccessToken = String.valueOf(project.findProperty("gitHubAccessToken"));
        updateDependenciesSettings.getGitHub().setAccessToken(gitHubAccessToken);
    }
    project.getTasks().register("updateDependencies", DependencyUpdatesTask.class, new Action<DependencyUpdatesTask>() {

        @Override
        public void execute(DependencyUpdatesTask updateDependencies) {
            updateDependencies.setDescription("Update the dependencies");
            updateDependencies.setCheckConstraints(true);
            updateDependencies.setOutputFormatter(new Closure<Void>(null) {

                @Override
                public Void call(Object argument) {
                    Result result = (Result) argument;
                    if (gitHubApi == null && updateDependenciesSettings.getUpdateMode() != UpdateDependenciesExtension.UpdateMode.COMMIT) {
                        gitHubApi = new GitHubApi(updateDependenciesSettings.getGitHub().getAccessToken());
                    }
                    updateDependencies(result, project, updateDependenciesSettings);
                    updateGradleVersion(result, project, updateDependenciesSettings);
                    return null;
                }
            });
            updateDependencies.resolutionStrategy(new Action<ResolutionStrategyWithCurrent>() {

                @Override
                public void execute(ResolutionStrategyWithCurrent resolution) {
                    resolution.componentSelection(new Action<ComponentSelectionRulesWithCurrent>() {

                        @Override
                        public void execute(ComponentSelectionRulesWithCurrent components) {
                            updateDependenciesSettings.getExcludes().getActions().forEach((action) -> {
                                components.all(action);
                            });
                            updateDependenciesSettings.getExcludes().getComponents().forEach((action) -> {
                                action.execute(components);
                            });
                            components.all((selection) -> {
                                ModuleComponentIdentifier candidate = selection.getCandidate();
                                if (candidate.getGroup().startsWith("org.apache.directory.") && !candidate.getVersion().equals(selection.getCurrentVersion())) {
                                    selection.reject("org.apache.directory.* has breaking changes in newer versions");
                                }
                            });
                            String jaxbBetaRegex = ".*?b\\d+.*";
                            components.withModule("javax.xml.bind:jaxb-api", excludeWithRegex(jaxbBetaRegex, "Reject jaxb-api beta versions"));
                            components.withModule("com.sun.xml.bind:jaxb-impl", excludeWithRegex(jaxbBetaRegex, "Reject jaxb-api beta versions"));
                            components.withModule("commons-collections:commons-collections", excludeWithRegex("^\\d{3,}.*", "Reject commons-collections date based releases"));
                        }
                    });
                }
            });
        }
    });
}
Also used : java.util(java.util) ComponentSelectionRulesWithCurrent(com.github.benmanes.gradle.versions.updates.resolutionstrategy.ComponentSelectionRulesWithCurrent) GradleUpdateResult(com.github.benmanes.gradle.versions.updates.gradle.GradleUpdateResult) Closure(groovy.lang.Closure) VersionAvailable(com.github.benmanes.gradle.versions.reporter.result.VersionAvailable) Function(java.util.function.Function) Supplier(java.util.function.Supplier) Result(com.github.benmanes.gradle.versions.reporter.result.Result) Matcher(java.util.regex.Matcher) ComponentSelectionWithCurrent(com.github.benmanes.gradle.versions.updates.resolutionstrategy.ComponentSelectionWithCurrent) Duration(java.time.Duration) Dependency(com.github.benmanes.gradle.versions.reporter.result.Dependency) OIDC_SDK_NAME(org.springframework.security.convention.versions.TransitiveDependencyLookupUtils.OIDC_SDK_NAME) PrintStream(java.io.PrintStream) Action(org.gradle.api.Action) Project(org.gradle.api.Project) Files(java.nio.file.Files) DependencyOutdated(com.github.benmanes.gradle.versions.reporter.result.DependencyOutdated) NIMBUS_JOSE_JWT_NAME(org.springframework.security.convention.versions.TransitiveDependencyLookupUtils.NIMBUS_JOSE_JWT_NAME) Mono(reactor.core.publisher.Mono) IOException(java.io.IOException) File(java.io.File) ModuleComponentIdentifier(org.gradle.api.artifacts.component.ModuleComponentIdentifier) ResolutionStrategyWithCurrent(com.github.benmanes.gradle.versions.updates.resolutionstrategy.ResolutionStrategyWithCurrent) DependencyUpdatesTask(com.github.benmanes.gradle.versions.updates.DependencyUpdatesTask) Pattern(java.util.regex.Pattern) Plugin(org.gradle.api.Plugin) InputStream(java.io.InputStream) Action(org.gradle.api.Action) Closure(groovy.lang.Closure) ResolutionStrategyWithCurrent(com.github.benmanes.gradle.versions.updates.resolutionstrategy.ResolutionStrategyWithCurrent) GradleUpdateResult(com.github.benmanes.gradle.versions.updates.gradle.GradleUpdateResult) Result(com.github.benmanes.gradle.versions.reporter.result.Result) DependencyUpdatesTask(com.github.benmanes.gradle.versions.updates.DependencyUpdatesTask) ModuleComponentIdentifier(org.gradle.api.artifacts.component.ModuleComponentIdentifier) ComponentSelectionRulesWithCurrent(com.github.benmanes.gradle.versions.updates.resolutionstrategy.ComponentSelectionRulesWithCurrent)

Aggregations

Dependency (com.github.benmanes.gradle.versions.reporter.result.Dependency)1 DependencyOutdated (com.github.benmanes.gradle.versions.reporter.result.DependencyOutdated)1 Result (com.github.benmanes.gradle.versions.reporter.result.Result)1 VersionAvailable (com.github.benmanes.gradle.versions.reporter.result.VersionAvailable)1 DependencyUpdatesTask (com.github.benmanes.gradle.versions.updates.DependencyUpdatesTask)1 GradleUpdateResult (com.github.benmanes.gradle.versions.updates.gradle.GradleUpdateResult)1 ComponentSelectionRulesWithCurrent (com.github.benmanes.gradle.versions.updates.resolutionstrategy.ComponentSelectionRulesWithCurrent)1 ComponentSelectionWithCurrent (com.github.benmanes.gradle.versions.updates.resolutionstrategy.ComponentSelectionWithCurrent)1 ResolutionStrategyWithCurrent (com.github.benmanes.gradle.versions.updates.resolutionstrategy.ResolutionStrategyWithCurrent)1 Closure (groovy.lang.Closure)1 File (java.io.File)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 PrintStream (java.io.PrintStream)1 Files (java.nio.file.Files)1 Duration (java.time.Duration)1 java.util (java.util)1 Function (java.util.function.Function)1 Supplier (java.util.function.Supplier)1 Matcher (java.util.regex.Matcher)1