Skip to content

Commit

Permalink
Fix default repository for verify command
Browse files Browse the repository at this point in the history
  • Loading branch information
dwalluck committed Feb 12, 2024
1 parent 2ad7962 commit 70a0a60
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@

@Command(name = "verify-built-artifacts")
public class VerifyBuiltArtifactsCommand implements Callable<Integer> {
static final String REPOSITORY_ID = "internal";

static class LocalOptions {
@Option(required = true, names = { "-of", "--original-file" })
Expand Down Expand Up @@ -233,8 +234,7 @@ private List<String> getExcludes() throws IOException {
return newExcludes;
}

private void initMaven(Path globalSettingsFile, Path settingsFile)
throws IOException, BootstrapMavenException {
private void initMaven(Path globalSettingsFile, Path settingsFile) throws IOException, BootstrapMavenException {
session = newSession();
var settings = newSettings(globalSettingsFile, settingsFile);
var mirrorSelector = newMirrorSelector(settings);
Expand All @@ -247,15 +247,7 @@ private void initMaven(Path globalSettingsFile, Path settingsFile)
var manager = system.newLocalRepositoryManager(session, localRepository);
session.setLocalRepositoryManager(manager);
var centralRepository = new Builder(DEFAULT_REMOTE_REPO_ID, "default", DEFAULT_REMOTE_REPO_URL).build();
var mirror = mirrorSelector.getMirror(centralRepository);

if (mirror != null) {
Log.debugf("Mirror for %s: %s", centralRepository.getId(), mirror);
remoteRepositories = List.of(mirror);
} else {
Log.debugf("Using repository URL %s", options.mavenOptions.repositoryUrl);
remoteRepositories = List.of(new Builder("internal", "default", options.mavenOptions.repositoryUrl).build());
}
remoteRepositories = List.of(centralRepository);
}

private List<String> handleJar(Path remoteFile, Path file, List<String> excludes) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import picocli.CommandLine;

public class VerifyBuiltArtifactsCommandTest {
private static final String REPOSITORY_URL = "https://repo1.maven.org/maven2";

private Properties properties;

@BeforeEach
Expand Down Expand Up @@ -57,7 +59,7 @@ void testCommand() throws Exception {
var uri = url.toURI();
var file = Path.of(uri);
System.setProperty(ALT_USER_SETTINGS_XML_LOCATION, file.toAbsolutePath().toString());
var args = new String[] { "-r", "https://repo1.maven.org/maven2", "--deploy-path", tempMavenRepo.toString() };
var args = new String[] { "-r", REPOSITORY_URL, "--deploy-path", tempMavenRepo.toString() };
VerifyBuiltArtifactsCommand verifyBuiltArtifactsCommand = new VerifyBuiltArtifactsCommand();
verifyBuiltArtifactsCommand.mvnCtx = new BootstrapMavenContext();
var exitCode = new CommandLine(verifyBuiltArtifactsCommand).execute(args);
Expand All @@ -73,22 +75,25 @@ void testCommand() throws Exception {
out.write(in.readAllBytes());
}
//now add this class as an extra class
var thisClassData = VerifyBuiltArtifactsCommandTest.class
.getResourceAsStream(VerifyBuiltArtifactsCommandTest.class.getSimpleName() + ".class").readAllBytes();
entry = new ZipEntry(VerifyBuiltArtifactsCommandTest.class.getName().replace(".", "/") + ".class");
entry.setSize(thisClassData.length);
out.putNextEntry(entry);
out.write(thisClassData);
try (var is = VerifyBuiltArtifactsCommandTest.class
.getResourceAsStream(VerifyBuiltArtifactsCommandTest.class.getSimpleName() + ".class")) {
assertThat(is).isNotNull();
var thisClassData = is.readAllBytes();
entry = new ZipEntry(VerifyBuiltArtifactsCommandTest.class.getName().replace(".", "/") + ".class");
entry.setSize(thisClassData.length);
out.putNextEntry(entry);
out.write(thisClassData);
}
}
}

args = new String[] { "-r", "https://repo1.maven.org/maven2", "--deploy-path", tempMavenRepo.toString() };
args = new String[] { "-r", REPOSITORY_URL, "--deploy-path", tempMavenRepo.toString() };
exitCode = new CommandLine(verifyBuiltArtifactsCommand).execute(args);
assertThat(exitCode).isNotZero();

//now try with excludes

args = new String[] { "-r", "https://repo1.maven.org/maven2", "--deploy-path", tempMavenRepo.toString(), "--excludes",
args = new String[] { "-r", REPOSITORY_URL, "--deploy-path", tempMavenRepo.toString(), "--excludes",
"+:.*[^:]:class:" + VerifyBuiltArtifactsCommandTest.class.getName().replace(".", "/") };
exitCode = new CommandLine(verifyBuiltArtifactsCommand).execute(args);
assertThat(exitCode).isZero();
Expand All @@ -98,6 +103,7 @@ void testCommand() throws Exception {
static Path junitJar() {
var path = Thread.currentThread().getContextClassLoader()
.getResource(Test.class.getName().replace(".", "/") + ".class");
assertThat(path).isNotNull();
String file = path.getFile();
return Path.of(file.substring("file:".length(), file.indexOf("!")));
}
Expand Down

0 comments on commit 70a0a60

Please sign in to comment.