Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[tycho-4.0.x] Always write a version report #4622

Merged
merged 1 commit into from
Jan 21, 2025
Merged
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 @@ -139,6 +139,7 @@ public void execute() throws MojoExecutionException, MojoFailureException {
JrtClasses jrtClassResolver = getJRTClassResolver();
List<ClassUsage> usages = DependencyAnalyzer.analyzeUsage(file, jrtClassResolver);
if (usages.isEmpty()) {
writeReport("No usages detected");
return;
}
Collection<IInstallableUnit> units = artifacts.getInstallableUnits();
Expand Down Expand Up @@ -249,9 +250,8 @@ public void execute() throws MojoExecutionException, MojoFailureException {
packageName, packageVersion,
matchedPackageVersion.orElse(org.eclipse.equinox.p2.metadata.Version.emptyVersion)
.toString(),
unit.getId(), unit.getVersion(),
v.getVersion(), v.getProvider(), mthd.className(), getMethodRef(mthd)),
references.get(mthd), provided));
unit.getId(), unit.getVersion(), v.getVersion(), v.getProvider(), mthd.className(),
getMethodRef(mthd)), references.get(mthd), provided));
ok = false;
packageWithError.add(packageName);
}
Expand All @@ -271,6 +271,7 @@ public void execute() throws MojoExecutionException, MojoFailureException {
}
}
if (dependencyProblems.isEmpty()) {
writeReport("No Version Problems detected!");
return;
}
List<String> results = new ArrayList<>();
Expand All @@ -281,19 +282,20 @@ public void execute() throws MojoExecutionException, MojoFailureException {
message = problem.message();
} else {
if (verbose) {
String delimiter = System.lineSeparator() + "- ";
message = String.format("%s referenced by:%s%s ", problem.message(), delimiter,
problem.references().stream().collect(Collectors.joining(delimiter)));
} else {
int size = references.size();
if (size == 1) {
message = String.format("%s referenced by `%s`.", problem.message(), references.iterator().next());
String delimiter = System.lineSeparator() + "- ";
message = String.format("%s referenced by:%s%s ", problem.message(), delimiter,
problem.references().stream().collect(Collectors.joining(delimiter)));
} else {
message = String.format("%s referenced by `%s` and %d other.", problem.message(),
references.iterator().next(), size - 1);
int size = references.size();
if (size == 1) {
message = String.format("%s referenced by `%s`.", problem.message(),
references.iterator().next());
} else {
message = String.format("%s referenced by `%s` and %d other.", problem.message(),
references.iterator().next(), size - 1);
}
}
}
}
log.error(message);
results.add(message);
if (verbose) {
Expand Down Expand Up @@ -324,12 +326,15 @@ public void execute() throws MojoExecutionException, MojoFailureException {
if (results.isEmpty()) {
return;
}
writeReport(results.stream().collect(Collectors.joining(System.lineSeparator())));
if (applySuggestions) {
applyLowerBounds(packageWithError, lowestPackageVersion);
}
}

private void writeReport(String report) throws MojoFailureException {
try {
Files.writeString(reportFileName.toPath(),
results.stream().collect(Collectors.joining(System.lineSeparator())));
if (applySuggestions) {
applyLowerBounds(packageWithError, lowestPackageVersion);
}
Files.writeString(reportFileName.toPath(), report);
} catch (IOException e) {
throw new MojoFailureException(e);
}
Expand All @@ -343,23 +348,28 @@ private String getMethodRef(MethodSignature mthd) {
}

private void applyLowerBounds(Set<String> packageWithError, Map<String, Version> lowestPackageVersion)
throws IOException {
MutableBundleManifest manifest = MutableBundleManifest.read(manifestFile);
Map<String, String> exportedPackagesVersion = manifest.getExportedPackagesVersion();
Map<String, String> updates = new HashMap<>();
for (String packageName : packageWithError) {
Version lowestVersion = lowestPackageVersion.getOrDefault(packageName, Version.emptyVersion);
String current = exportedPackagesVersion.get(packageName);
if (current == null) {
updates.put(packageName, String.format("[%s,%d)", lowestVersion, (lowestVersion.getMajor() + 1)));
} else {
VersionRange range = VersionRange.valueOf(current);
Version right = range.getRight();
updates.put(packageName, String.format("[%s,%s%c", lowestVersion, right, range.getRightType()));
throws MojoFailureException {
try {
MutableBundleManifest manifest = MutableBundleManifest.read(manifestFile);
Map<String, String> exportedPackagesVersion = manifest.getExportedPackagesVersion();
Map<String, String> updates = new HashMap<>();
for (String packageName : packageWithError) {
Version lowestVersion = lowestPackageVersion.getOrDefault(packageName, Version.emptyVersion);
String current = exportedPackagesVersion.get(packageName);
if (current == null) {
updates.put(packageName, String.format("[%s,%d)", lowestVersion, (lowestVersion.getMajor() + 1)));
} else {
VersionRange range = VersionRange.valueOf(current);
Version right = range.getRight();
updates.put(packageName, String.format("[%s,%s%c", lowestVersion, right, range.getRightType()));
}
}
manifest.updateImportedPackageVersions(updates);

MutableBundleManifest.write(manifest, manifestFile);
} catch (IOException e) {
throw new MojoFailureException(e);
}
manifest.updateImportedPackageVersions(updates);
MutableBundleManifest.write(manifest, manifestFile);
}

private Map<String, String> getVersionInfo(GenericInfo genericInfo, String versionAttribute) {
Expand Down
Loading