io.codemodder.MarkdownDependencyDescriptor Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of codemodder-base Show documentation
Show all versions of codemodder-base Show documentation
Base framework for writing codemods in Java
package io.codemodder;
import java.util.Optional;
/**
* A dependency descriptor that renders a dependency as a markdown table, with a links to more info.
*/
final class MarkdownDependencyDescriptor implements DependencyDescriptor {
@Override
public String create(final DependencyGAV dependency) {
StringBuilder sb = new StringBuilder();
Optional justification = dependency.justification();
if (justification.isPresent()) {
sb.append(justification.get());
} else {
sb.append("This dependency change is required to use the new code.");
}
sb.append("\n\n");
boolean hadPreviousFooterItem = false;
Optional license = dependency.license();
if (license.isPresent()) {
hadPreviousFooterItem = true;
sb.append("License: ");
sb.append(license.get());
if (DependencyLicenses.isOpenSource(license.get())) {
sb.append(" ✅");
} else {
// we don't know, so use a question mark
sb.append(" ❓");
}
}
if (hadPreviousFooterItem) {
sb.append(" | ");
}
Optional repositoryUrl = dependency.repositoryUrl();
if (repositoryUrl.isPresent()) {
hadPreviousFooterItem = true;
sb.append("[Open source](");
sb.append(repositoryUrl.get());
sb.append(") ✅");
}
Optional hasNoTransitiveDependencies = dependency.hasNoTransitiveDependencies();
if (hasNoTransitiveDependencies.isPresent()) {
if (hasNoTransitiveDependencies.get()) {
if (hadPreviousFooterItem) {
sb.append(" | ");
} else {
hadPreviousFooterItem = true;
}
sb.append("No transitive dependencies ");
sb.append("✅");
}
}
if (hadPreviousFooterItem) {
sb.append(" | ");
}
String moreFactsUrl =
String.format(
"https://mvnrepository.com/artifact/%s/%s/%s",
dependency.group(), dependency.artifact(), dependency.version());
sb.append("[More facts](");
sb.append(moreFactsUrl);
sb.append(")\n");
return sb.toString();
}
}