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

fix(java): Fix typos #596

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from
Draft
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 @@ -93,11 +93,11 @@ public void validate() {
}
if (getGithubOwner() == null) {
throw new ModernizerException(
"GitHub owner (username/organization) is not set. Please set GH_OWNER or GITHUB_OWNER environment variable. Or use --github-owner if running from CLI");
"GitHub owner (username/organization) is not set. Please set GH_OWNER or GITHUB_OWNER environment variable. Or use --github-owner if running from CLI.");
}
if (config.getGithubAppId() != null && config.getGithubAppSourceInstallationId() != null) {
if (Settings.GITHUB_APP_PRIVATE_KEY_FILE == null) {
throw new ModernizerException("GitHub App not configured. Please set GH_APP_PRIVATE_KEY_FILE");
throw new ModernizerException("GitHub App is not configured. Please set GH_APP_PRIVATE_KEY_FILE.");
}
}
}
Expand Down Expand Up @@ -125,7 +125,7 @@ public void connect() {
if (config.getGithubAppId() != null
&& config.getGithubAppSourceInstallationId() != null
&& config.getGithubAppTargetInstallationId() != null) {
LOG.debug("Connecting to GitHub using GitHub App...");
LOG.debug("Connecting to GitHub using GitHub App");
LOG.debug("GitHub App ID: {}", config.getGithubAppId());
LOG.debug("GitHub App Source Installation ID: {}", config.getGithubAppSourceInstallationId());
LOG.debug("GitHub App Target Installation ID: {}", config.getGithubAppTargetInstallationId());
Expand All @@ -146,7 +146,7 @@ public void connect() {
}
// Connect with token
else {
LOG.debug("Connecting to GitHub using token...");
LOG.debug("Connecting to GitHub using token");
github = new GitHubBuilder()
.withEndpoint(config.getGithubApiUrl().toString())
.withOAuthToken(Settings.GITHUB_TOKEN)
Expand Down Expand Up @@ -287,7 +287,7 @@ public void fork(Plugin plugin) {
LOG.info("Plugin {} is archived. Not forking", plugin);
return;
}
LOG.info("Forking plugin {} locally from repo {}...", plugin, plugin.getRepositoryName());
LOG.info("Forking plugin {} locally from repo {}", plugin, plugin.getRepositoryName());
try {
GHRepository fork = forkPlugin(plugin);
LOG.debug("Forked repository: {}", fork.getHtmlUrl());
Expand Down Expand Up @@ -345,11 +345,11 @@ private GHRepository forkRepository(GHRepository originalRepo, GHOrganization or
throws IOException, InterruptedException {
if (organization == null) {
LOG.info(
"Forking the repository to personal account {}...",
"Forking the repository to personal account {}",
getCurrentUser().getLogin());
return originalRepo.fork();
} else {
LOG.info("Forking the repository to organisation {}...", organization.getLogin());
LOG.info("Forking the repository to organisation {}", organization.getLogin());
return originalRepo.forkTo(organization);
}
}
Expand Down Expand Up @@ -499,9 +499,9 @@ public void deleteFork(Plugin plugin) {
return;
}
if (config.isDebug()) {
LOG.debug("Deleting fork for plugin {} from repo {}...", plugin, repository.getHtmlUrl());
LOG.debug("Deleting fork for plugin {} from repo {}", plugin, repository.getHtmlUrl());
} else {
LOG.info("Deleting fork for plugin {}...", plugin);
LOG.info("Deleting fork for plugin {}", plugin);
}
try {
repository.delete();
Expand All @@ -528,12 +528,12 @@ public void fetch(Plugin plugin) {

if (config.isDebug()) {
LOG.debug(
"Fetch plugin code {} from {} into directory {}...",
"Fetch plugin code {} from {} into directory {}",
plugin,
repository.getHtmlUrl(),
plugin.getRepositoryName());
} else {
LOG.info("Fetching plugin code locally {}...", plugin);
LOG.info("Fetching plugin code locally {}", plugin);
}
try {
fetchRepository(plugin);
Expand Down Expand Up @@ -742,12 +742,12 @@ public GHUser getCurrentUser() {
try {
// Get myself
if (config.getGithubAppId() == null) {
LOG.debug("Getting current user using token...");
LOG.debug("Getting current user using token");
return github.getMyself();
}
// Get the bot user
else {
LOG.debug("Getting current user using GitHub App...");
LOG.debug("Getting current user using GitHub App");
LOG.debug("GitHub App name: {}", app.getName());
return github.getUser("%s[bot]".formatted(app.getName()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public class MavenInvoker {
}
return new ComparableVersion(versionValue);
} catch (MavenInvocationException e) {
LOG.error("Failed to check for maven version", e);
LOG.error("Failed to check for maven version.", e);
return null;
}
}
Expand All @@ -81,9 +81,9 @@ public class MavenInvoker {
* @param goals The goals to run. For example, "clean"
*/
public void invokeGoal(Plugin plugin, String... goals) {
LOG.debug("Running {} phase for plugin {}", goals, plugin.getName());
LOG.debug("Running {} phase for plugin {}.", goals, plugin.getName());
LOG.debug(
"Running maven on directory {}",
"Running maven on directory {}.",
plugin.getLocalRepository().toAbsolutePath().toFile());
invokeGoals(plugin, goals);
}
Expand All @@ -93,9 +93,9 @@ public void invokeGoal(Plugin plugin, String... goals) {
* @param plugin The plugin to run the rewrite on
*/
public void collectMetadata(Plugin plugin) {
LOG.info("Collecting metadata for plugin {}... Please be patient", plugin);
LOG.info("Collecting metadata for plugin {} Please be patient.", plugin);
invokeGoals(plugin, getSingleRecipeArgs(Settings.FETCH_METADATA_RECIPE));
LOG.info("Done");
LOG.info("Done.");
}

/**
Expand All @@ -105,7 +105,7 @@ public void collectMetadata(Plugin plugin) {
public void invokeRewrite(Plugin plugin) {
plugin.addTags(config.getRecipe().getTags());
LOG.info(
"Running recipes {} for plugin {}... Please be patient",
"Running recipes {} for plugin {} Please be patient.",
config.getRecipe().getName(),
plugin);
invokeGoals(plugin, getSingleRecipeArgs(config.getRecipe()));
Expand Down Expand Up @@ -144,23 +144,23 @@ private void invokeGoals(Plugin plugin, String... goals) {

// In order to rewrite on outdated plugins set add-opens
if (jdk.getMajor() >= 17) {
LOG.debug("Adding --add-opens for JDK 17+");
LOG.debug("Adding --add-opens for JDK 17+.");
request.setMavenOpts(
"--add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.io=ALL-UNNAMED --add-opens java.base/java.util=ALL-UNNAMED");
}
}
request.setBatchMode(true);
request.setNoTransferProgress(false);
request.setErrorHandler((message) -> {
LOG.error(plugin.getMarker(), String.format("Something went wrong when running maven: %s", message));
LOG.error(plugin.getMarker(), String.format("Something went wrong when running maven: %s.", message));
});
request.setOutputHandler((message) -> {
LOG.info(plugin.getMarker(), message);
});
InvocationResult result = invoker.execute(request);
handleInvocationResult(plugin, result);
} catch (MavenInvocationException | InterruptedException | IOException e) {
plugin.addError("Maven invocation failed", e);
plugin.addError("Maven invocation failed.", e);
}
}

Expand All @@ -169,10 +169,10 @@ private void invokeGoals(Plugin plugin, String... goals) {
* @param plugin The plugin to validate
*/
private void validatePom(Plugin plugin) {
LOG.debug("Validating POM for plugin: {}", plugin);
LOG.debug("Validating POM for plugin: {}.", plugin);
if (!plugin.getLocalRepository().resolve("pom.xml").toFile().isFile()) {
plugin.addError("POM file not found");
throw new PluginProcessingException("POM file not found", plugin);
plugin.addError("POM file not found.");
throw new PluginProcessingException("POM file not found.", plugin);
}
}

Expand All @@ -184,7 +184,7 @@ public void validateMaven() {
Path mavenHome = config.getMavenHome();
if (mavenHome == null) {
throw new ModernizerException(
"Neither MAVEN_HOME nor M2_HOME environment variables are set. Or use --maven-home if running from CLI");
"Neither MAVEN_HOME nor M2_HOME environment variables are set. Or use --maven-home if running from CLI.");
}

if (!Files.isDirectory(mavenHome) || !Files.isExecutable(mavenHome.resolve("bin/mvn"))) {
Expand All @@ -206,14 +206,14 @@ public void validateMaven() {
*/
public void validateMavenVersion() {
ComparableVersion mavenVersion = getMavenVersion();
LOG.debug("Maven version detected: {}", mavenVersion);
LOG.debug("Detected Maven version: {}.", mavenVersion);
if (mavenVersion == null) {
LOG.error("Failed to check Maven version. Aborting build.");
throw new ModernizerException("Failed to check Maven version.");
LOG.error("Failed to check the Maven version. Aborting build.");
throw new ModernizerException("Failed to check the Maven version.");
}
if (mavenVersion.compareTo(Settings.MAVEN_MINIMAL_VERSION) < 0) {
LOG.error(
"Maven version detected {}, is too old. Please use at least version {}",
"Detected Maven version ({}) is too old. Please use at least version {}.",
mavenVersion,
Settings.MAVEN_MINIMAL_VERSION);
throw new ModernizerException("Maven version is too old.");
Expand Down Expand Up @@ -244,15 +244,15 @@ private InvocationRequest createInvocationRequest(Plugin plugin, String... args)
*/
private void handleInvocationResult(Plugin plugin, InvocationResult result) {
if (result.getExitCode() != 0) {
LOG.error(plugin.getMarker(), "Build fail with code: {}", result.getExitCode());
LOG.error(plugin.getMarker(), "Build failed with code: {}.", result.getExitCode());
if (result.getExecutionException() != null) {
plugin.addError("Maven generic exception occurred", result.getExecutionException());
plugin.addError("Maven generic exception occurred.", result.getExecutionException());
} else {
String errorMessage;
if (config.isDebug()) {
errorMessage = "Build failed with code: " + result.getExitCode();
} else {
errorMessage = "Build failed";
errorMessage = "Build failed.";
}
plugin.addError(errorMessage);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ private void process(Plugin plugin) {

// Handle outdated plugin or unparsable Jenkinsfile
if (plugin.getMetadata().getJdks().stream().allMatch(jdk -> jdk.equals(JDK.getImplicit()))) {
LOG.info("Plugin look outdated or without Jenkinsfile.");
LOG.info("Plugin looks outdated, or without Jenkinsfile.");
StaticPomParser parser = new StaticPomParser(
plugin.getLocalRepository().resolve("pom.xml").toString());
String jenkinsVersion = parser.getJenkinsVersion();
Expand All @@ -281,7 +281,7 @@ private void process(Plugin plugin) {
}
LOG.debug("Found jenkins version from pom {}", jenkinsVersion);
JDK jdk = JDK.get(jenkinsVersion).stream().findFirst().orElse(JDK.min());
LOG.info("Plugin support Java {}. Need a first compile to generate classes", jdk.getMajor());
LOG.info("Plugin supports Java {}. Need a first compilation to generate classes", jdk.getMajor());
plugin.verifyQuickBuild(mavenInvoker, jdk);
if (plugin.hasErrors()) {
plugin.raiseLastError();
Expand Down Expand Up @@ -362,7 +362,7 @@ private void process(Plugin plugin) {
* @param plugin The plugin
*/
private void collectMetadata(Plugin plugin, boolean retryAfterFirstCompile) {
LOG.trace("Collecting metadata for plugin {}... Please be patient", plugin.getName());
LOG.trace("Collecting metadata for plugin {} Please be patient.", plugin.getName());
plugin.withJDK(JDK.JAVA_17);
try {
plugin.collectMetadata(mavenInvoker);
Expand All @@ -373,12 +373,12 @@ private void collectMetadata(Plugin plugin, boolean retryAfterFirstCompile) {
if (retryAfterFirstCompile) {
plugin.removeErrors();
LOG.warn(
"Failed to collect metadata for plugin {}. Will retry after a first compile using lowest JDK",
"Failed to collect metadata for plugin {}. Will retry after a first compile using the lowest JDK.",
plugin.getName());
plugin.verifyQuickBuild(mavenInvoker, JDK.JAVA_8);
if (plugin.hasErrors()) {
LOG.debug(
"Plugin {} failed to compile with JDK 8. Skipping metadata collection after retry",
"Plugin {} failed to compile with JDK 8. Skipping metadata collection after retry.",
plugin.getName());
plugin.raiseLastError();
}
Expand Down Expand Up @@ -420,11 +420,11 @@ private JDK verifyPlugin(Plugin plugin) {
if (metadata.getJdks() == null || metadata.getJdks().isEmpty()) {
jdk = JDK.JAVA_17;
LOG.info(
"No JDKs found in metadata for plugin {}. Using same JDK as rewrite for verification",
"No JDKs found in metadata for plugin {}. Using same JDK as rewrite for verification.",
plugin.getName());
} else {
jdk = JDK.min(metadata.getJdks(), metadata.getJenkinsVersion());
LOG.info("Using minimum JDK {} from metadata for plugin {}", jdk.getMajor(), plugin.getName());
LOG.info("Using minimum JDK {} from metadata for plugin {}.", jdk.getMajor(), plugin.getName());
}
// If the plugin was modernized we should find next JDK compatible
// For example a Java 8 plugin was modernized to Java 11
Expand All @@ -438,7 +438,7 @@ private JDK verifyPlugin(Plugin plugin) {
plugin.format(mavenInvoker);
plugin.verify(mavenInvoker);
if (plugin.hasErrors()) {
LOG.info("Plugin {} failed to verify with JDK {}", plugin.getName(), jdk.getMajor());
LOG.info("Plugin {} failed to verify with JDK {}.", plugin.getName(), jdk.getMajor());
plugin.withoutErrors();
}
plugin.withoutErrors();
Expand All @@ -458,7 +458,7 @@ private void printResults(List<Plugin> plugins) {
// Display error
if (plugin.hasErrors()) {
for (PluginProcessingException error : plugin.getErrors()) {
LOG.error("Error: {}", error.getMessage());
LOG.error("Error: {}.", error.getMessage());
if (config.isDebug()) {
LOG.error("Stacktrace: ", error);
}
Expand All @@ -469,20 +469,20 @@ private void printResults(List<Plugin> plugins) {
else {
if (config.isFetchMetadataOnly()) {
LOG.info(
"Metadata was fetched for plugin {} and is available at {}",
"Metadata was fetched for the {} plugin and is available at {}.",
plugin.getName(),
plugin.getMetadata().getLocation().toAbsolutePath());
} else if (config.isDryRun()) {
LOG.info("Dry run mode. Changes were commited on on " + plugin.getLocalRepository()
+ " but not pushed");
LOG.info("Dry run mode. Changes were commited on " + plugin.getLocalRepository()
+ ", but not pushed.");
} else {
// Change were made
LOG.info("Pull request was open on "
LOG.info("Pull request was opened on "
+ plugin.getRemoteRepository(this.ghService).getHtmlUrl());

// Display changes depending on the recipe
if (config.getRecipe().getName().equals("io.jenkins.tools.pluginmodernizer.UpgradeBomVersion")) {
LOG.info("New BOM version: {}", plugin.getMetadata().getBomVersion());
LOG.info("New BOM version: {}.", plugin.getMetadata().getBomVersion());
}
}
}
Expand Down
Loading
Loading