Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
package org.openrewrite.java.dependencies;

import org.junit.jupiter.api.Test;
import org.openrewrite.InMemoryExecutionContext;
import org.openrewrite.java.dependencies.table.DependencyListReport;
import org.openrewrite.maven.MavenExecutionContextView;
import org.openrewrite.maven.tree.*;
import org.openrewrite.test.RecipeSpec;
import org.openrewrite.test.RewriteTest;
Expand Down Expand Up @@ -138,6 +140,11 @@ void directOnly() {
void validateResolvable() {
rewriteRun(
spec -> spec.recipe(new DependencyList(DependencyList.Scope.Compile, false, true))
// Only the pretend repository below, which can't be reached, is asked: Maven Central and the local
// repository, which the recipe would ask too, are left out
.executionContext(MavenExecutionContextView.view(new InMemoryExecutionContext())
.setAddCentralRepository(false)
.setAddLocalRepository(false))
.dataTable(DependencyListReport.Row.class, rows -> assertThat(rows)
.singleElement()
.extracting(DependencyListReport.Row::getResolutionFailure)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

import org.junit.jupiter.api.Test;
import org.openrewrite.DocumentExample;
import org.openrewrite.ExecutionContext;
import org.openrewrite.InMemoryExecutionContext;
import org.openrewrite.Parser;
import org.openrewrite.java.dependencies.table.RepositoryAccessibilityReport;
Expand All @@ -33,6 +32,7 @@
import static org.assertj.core.api.Assertions.assertThat;
import static org.openrewrite.gradle.Assertions.buildGradle;
import static org.openrewrite.gradle.toolingapi.Assertions.withToolingApi;
import static org.openrewrite.java.dependencies.MavenCentralMirror.settingsMirroringOnlyCentral;
import static org.openrewrite.maven.Assertions.pomXml;

/**
Expand Down Expand Up @@ -262,34 +262,4 @@ private static void reachable(RepositoryAccessibilityReport.Row row) {
assertThat(row.getPingHttpCode()).as("what %s answered", row.getUri()).isEqualTo(200);
assertThat(row.getPingExceptionType()).as("what reaching %s threw", row.getUri()).isEmpty();
}

/**
* Settings with no mirror but one of Maven Central, the mirror CI names in MAVEN_CENTRAL_MIRROR_URL, _USERNAME and
* _PASSWORD, so that Central is reached as the rest of the build reaches it. With no mirror named, none at all.
*/
private static MavenSettings settingsMirroringOnlyCentral(ExecutionContext ctx) {
if (System.getenv("MAVEN_CENTRAL_MIRROR_URL") == null) {
return new MavenSettings(null, null, null, null, null, null);
}
return MavenSettings.parse(new Parser.Input(Path.of("settings.xml"), () -> new ByteArrayInputStream(
//language=xml
"""
<settings>
<servers>
<server>
<id>central-mirror</id>
<username>${env.MAVEN_CENTRAL_MIRROR_USERNAME}</username>
<password>${env.MAVEN_CENTRAL_MIRROR_PASSWORD}</password>
</server>
</servers>
<mirrors>
<mirror>
<id>central-mirror</id>
<mirrorOf>central</mirrorOf>
<url>${env.MAVEN_CENTRAL_MIRROR_URL}</url>
</mirror>
</mirrors>
</settings>
""".getBytes())), ctx);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* Copyright 2026 the original author or authors.
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* https://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.openrewrite.java.dependencies;

import org.openrewrite.ExecutionContext;
import org.openrewrite.Parser;
import org.openrewrite.maven.MavenSettings;

import java.io.ByteArrayInputStream;
import java.nio.file.Path;

public final class MavenCentralMirror {

private MavenCentralMirror() {
}

/**
* Settings with no mirror but one of Maven Central, the mirror CI names in MAVEN_CENTRAL_MIRROR_URL, _USERNAME and
* _PASSWORD, so that Central is reached as the rest of the build reaches it. With no mirror named, none at all.
*/
public static MavenSettings settingsMirroringOnlyCentral(ExecutionContext ctx) {
if (System.getenv("MAVEN_CENTRAL_MIRROR_URL") == null) {
return new MavenSettings(null, null, null, null, null, null);
}
return MavenSettings.parse(new Parser.Input(Path.of("settings.xml"), () -> new ByteArrayInputStream(
//language=xml
"""
<settings>
<servers>
<server>
<id>central-mirror</id>
<username>${env.MAVEN_CENTRAL_MIRROR_USERNAME}</username>
<password>${env.MAVEN_CENTRAL_MIRROR_PASSWORD}</password>
</server>
</servers>
<mirrors>
<mirror>
<id>central-mirror</id>
<mirrorOf>central</mirrorOf>
<url>${env.MAVEN_CENTRAL_MIRROR_URL}</url>
</mirror>
</mirrors>
</settings>
""".getBytes())), ctx);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,16 @@
import org.junit.jupiter.params.provider.NullSource;
import org.junit.jupiter.params.provider.ValueSource;
import org.openrewrite.InMemoryExecutionContext;
import org.openrewrite.Parser;
import org.openrewrite.maven.MavenExecutionContextView;
import org.openrewrite.maven.MavenSettings;
import org.openrewrite.test.RecipeSpec;
import org.openrewrite.test.RewriteTest;

import java.io.ByteArrayInputStream;
import java.nio.file.Path;

import static org.assertj.core.api.Assertions.assertThat;
import static org.openrewrite.gradle.Assertions.buildGradle;
import static org.openrewrite.gradle.toolingapi.Assertions.withToolingApi;
import static org.openrewrite.java.Assertions.java;
import static org.openrewrite.java.Assertions.mavenProject;
import static org.openrewrite.java.dependencies.MavenCentralMirror.settingsMirroringOnlyCentral;
import static org.openrewrite.maven.Assertions.pomXml;

class ModuleHasDependencyTest implements RewriteTest {
Expand Down Expand Up @@ -412,14 +408,7 @@ void mavenMatchesOnRequested() {
rewriteRun(
spec -> {
MavenExecutionContextView ctx = MavenExecutionContextView.view(new InMemoryExecutionContext());
MavenSettings emptySettings = MavenSettings.parse(new Parser.Input(Path.of("settings.xml"), () -> new ByteArrayInputStream(
//language=xml
"""
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd"/>
""".getBytes())), ctx);
ctx.setMavenSettings(emptySettings);
ctx.setMavenSettings(settingsMirroringOnlyCentral(ctx));
spec.recipe(new ModuleHasDependency(GroupId, ArtifactId, null, null, null, null))
.executionContext(ctx);
},
Expand Down
Loading