Search in sources :

Example 61 with Project

use of org.gradle.api.Project in project spring-security by spring-projects.

the class UpdateDependenciesPlugin method updateDependencies.

private void updateDependencies(Result result, Project project, UpdateDependenciesExtension updateDependenciesSettings) {
    SortedSet<DependencyOutdated> dependencies = result.getOutdated().getDependencies();
    if (dependencies.isEmpty()) {
        return;
    }
    Map<String, List<DependencyOutdated>> groups = new LinkedHashMap<>();
    dependencies.forEach(outdated -> {
        groups.computeIfAbsent(outdated.getGroup(), (key) -> new ArrayList<>()).add(outdated);
    });
    List<DependencyOutdated> nimbusds = groups.getOrDefault("com.nimbusds", new ArrayList<>());
    DependencyOutdated oidcSdc = nimbusds.stream().filter(d -> d.getName().equals(OIDC_SDK_NAME)).findFirst().orElseGet(() -> null);
    if (oidcSdc != null) {
        String oidcVersion = updatedVersion(oidcSdc);
        String jwtVersion = TransitiveDependencyLookupUtils.lookupJwtVersion(oidcVersion);
        Dependency nimbusJoseJwtDependency = result.getCurrent().getDependencies().stream().filter(d -> d.getName().equals(NIMBUS_JOSE_JWT_NAME)).findFirst().get();
        DependencyOutdated outdatedJwt = new DependencyOutdated();
        outdatedJwt.setVersion(nimbusJoseJwtDependency.getVersion());
        outdatedJwt.setGroup(oidcSdc.getGroup());
        outdatedJwt.setName(NIMBUS_JOSE_JWT_NAME);
        VersionAvailable available = new VersionAvailable();
        available.setRelease(jwtVersion);
        outdatedJwt.setAvailable(available);
        nimbusds.add(outdatedJwt);
    }
    File gradlePropertiesFile = project.getRootProject().file(Project.GRADLE_PROPERTIES);
    Mono<GitHubApi.FindCreateIssueResult> createIssueResult = createIssueResultMono(updateDependenciesSettings);
    List<File> filesWithDependencies = updateDependenciesSettings.getFiles().get();
    groups.forEach((group, outdated) -> {
        outdated.forEach((dependency) -> {
            String ga = dependency.getGroup() + ":" + dependency.getName() + ":";
            String originalDependency = ga + dependency.getVersion();
            String replacementDependency = ga + updatedVersion(dependency);
            System.out.println("Update " + originalDependency + " to " + replacementDependency);
            filesWithDependencies.forEach((fileWithDependency) -> {
                updateDependencyInlineVersion(fileWithDependency, dependency);
                updateDependencyWithVersionVariable(fileWithDependency, gradlePropertiesFile, dependency);
            });
        });
        // commit
        DependencyOutdated firstDependency = outdated.get(0);
        String updatedVersion = updatedVersion(firstDependency);
        String title = outdated.size() == 1 ? "Update " + firstDependency.getName() + " to " + updatedVersion : "Update " + firstDependency.getGroup() + " to " + updatedVersion;
        afterGroup(updateDependenciesSettings, project.getRootDir(), title, createIssueResult);
    });
}
Also used : DependencyOutdated(com.github.benmanes.gradle.versions.reporter.result.DependencyOutdated) 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) VersionAvailable(com.github.benmanes.gradle.versions.reporter.result.VersionAvailable) Dependency(com.github.benmanes.gradle.versions.reporter.result.Dependency) File(java.io.File)

Example 62 with Project

use of org.gradle.api.Project in project spring-security by spring-projects.

the class CheckAntoraVersionPluginTests method defaultsPropertiesWhenSnapshot.

@Test
void defaultsPropertiesWhenSnapshot() {
    String expectedVersion = "1.0.0-SNAPSHOT";
    Project project = ProjectBuilder.builder().build();
    project.setVersion(expectedVersion);
    project.getPluginManager().apply(CheckAntoraVersionPlugin.class);
    Task task = project.getTasks().findByName(CheckAntoraVersionPlugin.ANTORA_CHECK_VERSION_TASK_NAME);
    assertThat(task).isInstanceOf(CheckAntoraVersionTask.class);
    CheckAntoraVersionTask checkAntoraVersionTask = (CheckAntoraVersionTask) task;
    assertThat(checkAntoraVersionTask.getAntoraVersion().get()).isEqualTo("1.0.0");
    assertThat(checkAntoraVersionTask.getAntoraPrerelease().get()).isEqualTo("-SNAPSHOT");
    assertThat(checkAntoraVersionTask.getAntoraDisplayVersion().isPresent()).isFalse();
    assertThat(checkAntoraVersionTask.getAntoraYmlFile().getAsFile().get()).isEqualTo(project.file("antora.yml"));
}
Also used : Project(org.gradle.api.Project) Task(org.gradle.api.Task) Test(org.junit.jupiter.api.Test)

Example 63 with Project

use of org.gradle.api.Project in project spring-security by spring-projects.

the class CheckAntoraVersionPluginTests method actualAntoraPrereleaseNull.

@Test
void actualAntoraPrereleaseNull() throws Exception {
    String expectedVersion = "1.0.0-SNAPSHOT";
    Project project = ProjectBuilder.builder().build();
    File rootDir = project.getRootDir();
    IOUtils.write("version: '1.0.0'", new FileOutputStream(new File(rootDir, "antora.yml")), StandardCharsets.UTF_8);
    project.setVersion(expectedVersion);
    project.getPluginManager().apply(CheckAntoraVersionPlugin.class);
    Task task = project.getTasks().findByName(CheckAntoraVersionPlugin.ANTORA_CHECK_VERSION_TASK_NAME);
    assertThat(task).isInstanceOf(CheckAntoraVersionTask.class);
    CheckAntoraVersionTask checkAntoraVersionTask = (CheckAntoraVersionTask) task;
    assertThatExceptionOfType(GradleException.class).isThrownBy(() -> checkAntoraVersionTask.check());
}
Also used : Project(org.gradle.api.Project) Task(org.gradle.api.Task) FileOutputStream(java.io.FileOutputStream) GradleException(org.gradle.api.GradleException) File(java.io.File) Test(org.junit.jupiter.api.Test)

Example 64 with Project

use of org.gradle.api.Project in project spring-security by spring-projects.

the class CheckAntoraVersionPluginTests method defaultsPropertiesWhenMilestone.

@Test
void defaultsPropertiesWhenMilestone() {
    String expectedVersion = "1.0.0-M1";
    Project project = ProjectBuilder.builder().build();
    project.setVersion(expectedVersion);
    project.getPluginManager().apply(CheckAntoraVersionPlugin.class);
    Task task = project.getTasks().findByName(CheckAntoraVersionPlugin.ANTORA_CHECK_VERSION_TASK_NAME);
    assertThat(task).isInstanceOf(CheckAntoraVersionTask.class);
    CheckAntoraVersionTask checkAntoraVersionTask = (CheckAntoraVersionTask) task;
    assertThat(checkAntoraVersionTask.getAntoraVersion().get()).isEqualTo("1.0.0-M1");
    assertThat(checkAntoraVersionTask.getAntoraPrerelease().get()).isEqualTo("true");
    assertThat(checkAntoraVersionTask.getAntoraDisplayVersion().get()).isEqualTo(checkAntoraVersionTask.getAntoraVersion().get());
    assertThat(checkAntoraVersionTask.getAntoraYmlFile().getAsFile().get()).isEqualTo(project.file("antora.yml"));
}
Also used : Project(org.gradle.api.Project) Task(org.gradle.api.Task) Test(org.junit.jupiter.api.Test)

Example 65 with Project

use of org.gradle.api.Project in project spring-security by spring-projects.

the class CheckAntoraVersionPluginTests method matchesWhenReleaseAndPrereleaseUndefined.

@Test
void matchesWhenReleaseAndPrereleaseUndefined() throws Exception {
    String expectedVersion = "1.0.0";
    Project project = ProjectBuilder.builder().build();
    File rootDir = project.getRootDir();
    IOUtils.write("version: '1.0.0'", new FileOutputStream(new File(rootDir, "antora.yml")), StandardCharsets.UTF_8);
    project.setVersion(expectedVersion);
    project.getPluginManager().apply(CheckAntoraVersionPlugin.class);
    Task task = project.getTasks().findByName(CheckAntoraVersionPlugin.ANTORA_CHECK_VERSION_TASK_NAME);
    assertThat(task).isInstanceOf(CheckAntoraVersionTask.class);
    CheckAntoraVersionTask checkAntoraVersionTask = (CheckAntoraVersionTask) task;
    checkAntoraVersionTask.check();
}
Also used : Project(org.gradle.api.Project) Task(org.gradle.api.Task) FileOutputStream(java.io.FileOutputStream) File(java.io.File) Test(org.junit.jupiter.api.Test)

Aggregations

Project (org.gradle.api.Project)269 File (java.io.File)98 Task (org.gradle.api.Task)71 Plugin (org.gradle.api.Plugin)69 Configuration (org.gradle.api.artifacts.Configuration)53 List (java.util.List)40 ArrayList (java.util.ArrayList)39 SourceSet (org.gradle.api.tasks.SourceSet)38 TaskProvider (org.gradle.api.tasks.TaskProvider)38 IOException (java.io.IOException)35 Map (java.util.Map)35 Action (org.gradle.api.Action)34 Set (java.util.Set)32 JavaPlugin (org.gradle.api.plugins.JavaPlugin)31 FileCollection (org.gradle.api.file.FileCollection)30 Provider (org.gradle.api.provider.Provider)27 HashMap (java.util.HashMap)26 Collectors (java.util.stream.Collectors)26 ObjectFactory (org.gradle.api.model.ObjectFactory)25 Collections (java.util.Collections)24