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
6 changes: 4 additions & 2 deletions private/outdated.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ set -e -o pipefail

outdated_jar_path=$1
artifacts_file_path=$2
repositories_file_path=$3
extra_option_flag=$4
boms_file_path=$3
repositories_file_path=$4
extra_option_flag=$5

java {proxy_opts} -jar "$outdated_jar_path" \
--artifacts-file "$artifacts_file_path" \
--boms-file "$boms_file_path" \
--repositories-file "$repositories_file_path" \
$extra_option_flag
14 changes: 11 additions & 3 deletions private/rules/coursier.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,13 @@ sh_binary(
data = [
"@rules_jvm_external//private/tools/prebuilt:outdated_deploy.jar",
"outdated.artifacts",
"outdated.boms",
"outdated.repositories",
],
args = [
"$(location @rules_jvm_external//private/tools/prebuilt:outdated_deploy.jar)",
"$(location outdated.artifacts)",
"$(location outdated.boms)",
"$(location outdated.repositories)",
],
visibility = ["//visibility:public"],
Expand Down Expand Up @@ -373,13 +375,19 @@ def get_home_netrc_contents(repository_ctx):

return repository_ctx.read(netrcfile)

def _add_outdated_files(repository_ctx, artifacts, repositories):
def _add_outdated_files(repository_ctx, artifacts, boms, repositories):
repository_ctx.file(
"outdated.artifacts",
"\n".join(["{}:{}:{}".format(artifact["group"], artifact["artifact"], artifact["version"]) for artifact in artifacts]) + "\n",
executable = False,
)

repository_ctx.file(
"outdated.boms",
"\n".join(["{}:{}:{}".format(bom["group"], bom["artifact"], bom["version"]) for bom in boms]) + "\n",
executable = False,
)

repository_ctx.file(
"outdated.repositories",
"\n".join([repo["repo_url"] for repo in repositories]) + "\n",
Expand Down Expand Up @@ -659,7 +667,7 @@ def _pinned_coursier_fetch_impl(repository_ctx):
executable = False,
)

_add_outdated_files(repository_ctx, artifacts, repositories)
_add_outdated_files(repository_ctx, artifacts, boms, repositories)

# Generate a compatibility layer of external repositories for all jar artifacts.
if repository_ctx.attr.generate_compat_repositories:
Expand Down Expand Up @@ -1307,7 +1315,7 @@ def _coursier_fetch_impl(repository_ctx):

# Add outdated artifact files if this is a pinned repo
outdated_build_file_content = _BUILD_OUTDATED
_add_outdated_files(repository_ctx, artifacts, repositories)
_add_outdated_files(repository_ctx, artifacts, boms, repositories)

repository_ctx.file(
"BUILD",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,65 +188,27 @@ public static Element getFirstChildElement(Element element, String tagName) {
return null;
}

public static void verboseLog(String logline) {
if (System.getenv("RJE_VERBOSE") != null) {
System.out.println(logline);
}
}

public static void main(String[] args) throws IOException {
verboseLog(String.format("Running outdated with args %s", Arrays.toString(args)));

Path artifactsFilePath = null;
Path repositoriesFilePath = null;
boolean useLegacyOutputFormat = false;

for (int i = 0; i < args.length; i++) {
switch (args[i]) {
case "--artifacts-file":
artifactsFilePath = Paths.get(args[++i]);
break;

case "--repositories-file":
repositoriesFilePath = Paths.get(args[++i]);
break;

case "--legacy-output":
useLegacyOutputFormat = true;
break;

default:
throw new IllegalArgumentException(
"Unable to parse command line: " + Arrays.toString(args));
}
}

Objects.requireNonNull(artifactsFilePath, "Artifacts file must be set.");
Objects.requireNonNull(repositoriesFilePath, "Repositories file must be set.");

List<String> artifacts = Files.readAllLines(artifactsFilePath, StandardCharsets.UTF_8);
List<String> repositories = Files.readAllLines(repositoriesFilePath, StandardCharsets.UTF_8);

System.out.println(
String.format(
"Checking for updates of %d artifacts against the following repositories:",
artifacts.size()));
for (String repository : repositories) {
System.out.println(String.format("\t%s", repository));
}
System.out.println();

public static void printUpdatesFor(
List<String> artifacts, List<String> repositories, boolean useLegacyOutputFormat) {
boolean foundUpdates = false;

// Note: This should be straightforward to run in a thread and do multiple
// update checks at once if we want to improve performance in the future.
for (String artifact : artifacts) {
verboseLog(String.format("Checking artifact [%s]", artifact));
if (artifact.isEmpty()) {
continue;
}
String[] artifactParts = artifact.split(":");
String groupId = artifactParts[0];
String artifactId = artifactParts[1];

// artifacts might have empty versions if they come from a BOM
// In this case, skip the artifact.
if (artifactParts.length < 3) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll close #1338 since this is the fix in there.

continue;
}

String version = artifactParts[2];

ArtifactReleaseInfo artifactReleaseInfo = null;
Expand Down Expand Up @@ -311,4 +273,82 @@ public static void main(String[] args) throws IOException {
System.out.println("No updates found");
}
}

public static void verboseLog(String logline) {
if (System.getenv("RJE_VERBOSE") != null) {
System.out.println(logline);
}
}

public static void main(String[] args) throws IOException {
verboseLog(String.format("Running outdated with args %s", Arrays.toString(args)));

Path artifactsFilePath = null;
Path bomsFilePath = null;
Path repositoriesFilePath = null;
boolean useLegacyOutputFormat = false;

for (int i = 0; i < args.length; i++) {
switch (args[i]) {
case "--artifacts-file":
artifactsFilePath = Paths.get(args[++i]);
break;

case "--boms-file":
bomsFilePath = Paths.get(args[++i]);
break;

case "--repositories-file":
repositoriesFilePath = Paths.get(args[++i]);
break;

case "--legacy-output":
useLegacyOutputFormat = true;
break;

default:
throw new IllegalArgumentException(
"Unable to parse command line: " + Arrays.toString(args));
}
}

Objects.requireNonNull(artifactsFilePath, "Artifacts file must be set.");
Objects.requireNonNull(repositoriesFilePath, "Repositories file must be set.");

List<String> artifacts = Files.readAllLines(artifactsFilePath, StandardCharsets.UTF_8);
List<String> boms = List.of();
if (bomsFilePath != null) {
boms = Files.readAllLines(bomsFilePath, StandardCharsets.UTF_8);
if (boms.size() == 1 && boms.get(0).isBlank()) {
boms = List.of();
}
}
List<String> repositories = Files.readAllLines(repositoriesFilePath, StandardCharsets.UTF_8);

if (boms.size() > 0) {
System.out.println(
String.format(
"Checking for updates of %d boms and %d artifacts against the following"
+ " repositories:",
boms.size(), artifacts.size()));
} else {
System.out.println(
String.format(
"Checking for updates of %d artifacts against the following repositories:",
artifacts.size()));
}
for (String repository : repositories) {
System.out.println(String.format("\t%s", repository));
}
System.out.println();

if (boms.size() > 0) {
System.out.println("BOMs");
printUpdatesFor(boms, repositories, useLegacyOutputFormat);
System.out.println();
System.out.println("Artifacts");
}

printUpdatesFor(artifacts, repositories, useLegacyOutputFormat);
}
}
Binary file modified private/tools/prebuilt/outdated_deploy.jar
Binary file not shown.
7 changes: 7 additions & 0 deletions tests/bazel_run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,13 @@ function test_outdated_no_external_runfiles() {
expect_log "junit:junit \[4.12"
}

function test_outdated_with_boms() {
bazel run @regression_testing_maven//:outdated >> "$TEST_LOG" 2>&1

expect_log "Checking for updates of .* boms and .* artifacts against the following repositories"
expect_log "org.seleniumhq.selenium:selenium-bom \[4.14.1"
}

function test_v1_lock_file_format() {
# Because we run with `-e` this command succeeding is enough to
# know that the v1 lock file format was parsed successfully
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public void shouldFindUpdatedVersionForGuava() throws IOException {
assertThat(outdatedOutput.toString(), containsString("https://repo1.maven.org/maven2"));
assertThat(outdatedOutput.toString(), containsString("com.google.guava:guava [27.0-jre -> "));
assertThat(outdatedOutput.toString(), not(containsString("No updates found")));
assertThat(outdatedOutput.toString(), not(containsString("BOMs")));
}

@Test
Expand Down Expand Up @@ -438,4 +439,78 @@ public void worksWithCommonsVersions() throws IOException {
assertThat(releaseInfo.releaseVersion, equalTo("20040616"));
assertThat(releaseInfo.preReleaseVersion, is(nullValue()));
}

@Test
public void shouldFindUpdatedVersionForBOMs() throws IOException {
Path artifactsFile = temp.newFile("outdated.artifacts").toPath();
Files.write(
artifactsFile, Arrays.asList("com.google.guava:guava:27.0-jre"), StandardCharsets.UTF_8);

Path bomsFile = temp.newFile("outdated.boms").toPath();
Files.write(
bomsFile, Arrays.asList("com.google.cloud:libraries-bom:26.0.0"), StandardCharsets.UTF_8);

Path repositoriesFile = temp.newFile("outdated.repositories").toPath();
Files.write(
repositoriesFile, Arrays.asList("https://repo1.maven.org/maven2"), StandardCharsets.UTF_8);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-actionable comment: at some point, we should stop relying on Maven Central in our own tests since it breaks the hermeticity of the build.


ByteArrayOutputStream outdatedOutput = new ByteArrayOutputStream();
try {
System.setOut(new PrintStream(outdatedOutput));
Outdated.main(
new String[] {
"--artifacts-file", artifactsFile.toAbsolutePath().toString(),
"--boms-file", bomsFile.toAbsolutePath().toString(),
"--repositories-file", repositoriesFile.toAbsolutePath().toString()
});
} finally {
System.setOut(originalOut);
}

assertThat(
outdatedOutput.toString(),
containsString(
"Checking for updates of 1 boms and 1 artifacts against the following repositories"));
assertThat(outdatedOutput.toString(), containsString("https://repo1.maven.org/maven2"));
assertThat(outdatedOutput.toString(), containsString("BOMs"));
assertThat(
outdatedOutput.toString(), containsString("com.google.cloud:libraries-bom [26.0.0 -> "));
assertThat(outdatedOutput.toString(), containsString("com.google.guava:guava [27.0-jre -> "));
assertThat(outdatedOutput.toString(), not(containsString("No updates found")));
}

@Test
public void shouldPrintNoUpdatesIfBOMInputFileIsEmpty() throws IOException {
Path artifactsFile = temp.newFile("outdated.artifacts").toPath();
Files.write(
artifactsFile, Arrays.asList("com.google.guava:guava:27.0-jre"), StandardCharsets.UTF_8);

Path bomsFile = temp.newFile("outdated.boms").toPath();
Files.write(bomsFile, Arrays.asList(""), StandardCharsets.UTF_8);

Path repositoriesFile = temp.newFile("outdated.repositories").toPath();
Files.write(
repositoriesFile, Arrays.asList("https://repo1.maven.org/maven2"), StandardCharsets.UTF_8);

ByteArrayOutputStream outdatedOutput = new ByteArrayOutputStream();
try {
System.setOut(new PrintStream(outdatedOutput));
Outdated.main(
new String[] {
"--artifacts-file", artifactsFile.toAbsolutePath().toString(),
"--boms-file", bomsFile.toAbsolutePath().toString(),
"--repositories-file", repositoriesFile.toAbsolutePath().toString()
});
} finally {
System.setOut(originalOut);
}

assertThat(
outdatedOutput.toString(),
containsString("Checking for updates of 1 artifacts against the following repositories"));
assertThat(outdatedOutput.toString(), containsString("https://repo1.maven.org/maven2"));
assertThat(outdatedOutput.toString(), not(containsString("BOMs")));
assertThat(outdatedOutput.toString(), containsString("com.google.guava:guava [27.0-jre -> "));
assertThat(outdatedOutput.toString(), not(containsString("No updates found")));
}
}