From 2c10b594e2fdc2a834fbb61b3bbe2af5cc5eac1e Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Thu, 15 Jun 2023 01:19:58 +0200 Subject: [PATCH] spotless is clueless Promulgates inconsistent coding style and breaks "logical" markup of messages defined on multiple lines (like "item " + javavar) which it fails to keep together, etc. Unavoidable evil I guess, but hopefully someone can configure it. --- .../plugins/gitclient/CliGitAPIImpl.java | 6 +- .../plugins/gitclient/JGitAPIImpl.java | 3 +- .../gitclient/LegacyCompatibleGitAPIImpl.java | 126 ++++++------------ .../plugins/gitclient/GitClientCloneTest.java | 22 ++- 4 files changed, 53 insertions(+), 104 deletions(-) diff --git a/src/main/java/org/jenkinsci/plugins/gitclient/CliGitAPIImpl.java b/src/main/java/org/jenkinsci/plugins/gitclient/CliGitAPIImpl.java index a65efcffc0..298ea0aeed 100644 --- a/src/main/java/org/jenkinsci/plugins/gitclient/CliGitAPIImpl.java +++ b/src/main/java/org/jenkinsci/plugins/gitclient/CliGitAPIImpl.java @@ -1597,11 +1597,9 @@ public void execute() throws GitException, InterruptedException { expRef += " (expanded from " + ref + ")"; } if (!referencePath.exists()) { - listener.getLogger() - .println("[WARNING] Reference path does not exist: " + expRef); + listener.getLogger().println("[WARNING] Reference path does not exist: " + expRef); } else if (!referencePath.isDirectory()) { - listener.getLogger() - .println("[WARNING] Reference path is not a directory: " + expRef); + listener.getLogger().println("[WARNING] Reference path is not a directory: " + expRef); } else { args.add("--reference", referencePath.getPath()); } diff --git a/src/main/java/org/jenkinsci/plugins/gitclient/JGitAPIImpl.java b/src/main/java/org/jenkinsci/plugins/gitclient/JGitAPIImpl.java index 885d8a693c..17fa0c9c7e 100644 --- a/src/main/java/org/jenkinsci/plugins/gitclient/JGitAPIImpl.java +++ b/src/main/java/org/jenkinsci/plugins/gitclient/JGitAPIImpl.java @@ -1583,8 +1583,7 @@ public void execute() throws GitException { } if (!referencePath.exists()) { - listener.getLogger() - .println("[WARNING] Reference path does not exist: " + reference); + listener.getLogger().println("[WARNING] Reference path does not exist: " + reference); } else if (!referencePath.isDirectory()) { listener.getLogger() .println("[WARNING] Reference path is not a directory: " + reference); diff --git a/src/main/java/org/jenkinsci/plugins/gitclient/LegacyCompatibleGitAPIImpl.java b/src/main/java/org/jenkinsci/plugins/gitclient/LegacyCompatibleGitAPIImpl.java index 55ff32c1b9..f85a8cc1f3 100644 --- a/src/main/java/org/jenkinsci/plugins/gitclient/LegacyCompatibleGitAPIImpl.java +++ b/src/main/java/org/jenkinsci/plugins/gitclient/LegacyCompatibleGitAPIImpl.java @@ -468,8 +468,7 @@ public static String normalizeGitUrl(String url, Boolean checkLocalPaths) { } LOGGER.log( - Level.FINEST, - "normalizeGitUrl('" + url + "', " + checkLocalPaths.toString() + ") => " + urlNormalized); + Level.FINEST, "normalizeGitUrl('" + url + "', " + checkLocalPaths.toString() + ") => " + urlNormalized); return urlNormalized; } @@ -636,8 +635,8 @@ public SimpleEntry> getSubmodulesUrls( LOGGER.log( Level.FINE, - "getSubmodulesUrls(): looking at basename-like subdirs under base refrepo '" - + referenceBaseDirAbs + "', per arrDirnames: " + arrDirnames.toString()); + "getSubmodulesUrls(): looking at basename-like subdirs under base refrepo '" + referenceBaseDirAbs + + "', per arrDirnames: " + arrDirnames.toString()); for (String dirname : arrDirnames) { f = new File(dirname); @@ -666,8 +665,8 @@ public SimpleEntry> getSubmodulesUrls( String uriNorm = normalizeGitUrl(uri, true); LOGGER.log( Level.FINE, - "getSubmodulesUrls(): checking uri='" + uri - + "' (uriNorm='" + uriNorm + "') vs needle"); + "getSubmodulesUrls(): checking uri='" + uri + "' (uriNorm='" + uriNorm + + "') vs needle"); if (needleNorm.equals(uriNorm) || needle.equals(uri)) { result = new LinkedHashSet<>(); result.add(new String[] {dirname, uri, uriNorm, remoteName}); @@ -815,9 +814,7 @@ public SimpleEntry> getSubmodulesUrls( for (String dirname : arrDirnames) { // Note that here dirnames deal in absolutes f = new File(dirname); - LOGGER.log( - Level.FINEST, - "getSubmodulesUrls(): probing dir '" + dirname + "' if it exists"); + LOGGER.log(Level.FINEST, "getSubmodulesUrls(): probing dir '" + dirname + "' if it exists"); if (f.exists() && f.isDirectory()) { // No checks for ".git" or "objects" this time, already checked above // by getObjectsFile(). Probably should not check exists/dir either, @@ -845,12 +842,11 @@ public SimpleEntry> getSubmodulesUrls( String uriNorm = normalizeGitUrl(uri, true); LOGGER.log( Level.FINE, - "getSubmodulesUrls(): checking uri='" + uri - + "' (uriNorm='" + uriNorm + "') vs needle"); + "getSubmodulesUrls(): checking uri='" + uri + "' (uriNorm='" + uriNorm + + "') vs needle"); if (needle != null && needleNorm != null - && (needleNorm.equals(uriNorm) || needle.equals(uri)) - ) { + && (needleNorm.equals(uriNorm) || needle.equals(uri))) { result = new LinkedHashSet<>(); result.add(new String[] {dirname, uri, uriNorm, remoteName}); return new SimpleEntry<>(true, result); @@ -875,24 +871,21 @@ public SimpleEntry> getSubmodulesUrls( // Here is a good spot to recurse this routine into a // subdir that is already a known git workspace, to // add its data to list and/or return a found needle. - LOGGER.log( - Level.FINE, - "getSubmodulesUrls(): recursing into dir '" + dirname + "'..."); - SimpleEntry> subEntriesRet = - getSubmodulesUrls(dirname, needle, false); + LOGGER.log(Level.FINE, "getSubmodulesUrls(): recursing into dir '" + dirname + "'..."); + SimpleEntry> subEntriesRet = getSubmodulesUrls(dirname, needle, false); Boolean subEntriesExactMatched = subEntriesRet.getKey(); LinkedHashSet subEntries = subEntriesRet.getValue(); LOGGER.log( Level.FINE, - "getSubmodulesUrls(): returned from recursing into dir '" + dirname - + "' with " + subEntries.size() + " found mappings"); + "getSubmodulesUrls(): returned from recursing into dir '" + dirname + "' with " + + subEntries.size() + " found mappings"); if (!subEntries.isEmpty()) { if (needle != null && subEntriesExactMatched) { // We found nothing... until now! Bubble it up! LOGGER.log( Level.FINE, - "getSubmodulesUrls(): got an exact needle match from recursing into dir '" - + dirname + "': " + subEntries.iterator().next()[0]); + "getSubmodulesUrls(): got an exact needle match from recursing into dir '" + dirname + + "': " + subEntries.iterator().next()[0]); return subEntriesRet; } // ...else collect results to inspect and/or propagate later @@ -1061,25 +1054,17 @@ public File findParameterizedReferenceRepository(String reference, String url) { // Note: Initially we expect the reference to be a realistic dirname // with a special suffix to substitute after the logic below, so the // referencePath for that verbatim funny string should not exist now: - if (!referencePath.exists() - && isParameterizedReferenceRepository(reference) - && url != null - && !url.isEmpty() - ) { + if (!referencePath.exists() && isParameterizedReferenceRepository(reference) && url != null && !url.isEmpty()) { // Drop the trailing keyword to know the root refrepo dirname String referenceBaseDir = reference.replaceAll("/\\$\\{GIT_[^\\}]*\\}$", ""); File referenceBaseDirFile = new File(referenceBaseDir); if (!referenceBaseDirFile.exists()) { - LOGGER.log( - Level.WARNING, - "Base Git reference directory " + referenceBaseDir + " does not exist"); + LOGGER.log(Level.WARNING, "Base Git reference directory " + referenceBaseDir + " does not exist"); return null; } if (!referenceBaseDirFile.isDirectory()) { - LOGGER.log( - Level.WARNING, - "Base Git reference directory " + referenceBaseDir + " is not a directory"); + LOGGER.log(Level.WARNING, "Base Git reference directory " + referenceBaseDir + " is not a directory"); return null; } @@ -1107,26 +1092,21 @@ && isParameterizedReferenceRepository(reference) String referenceExpanded = null; if (reference.endsWith("/${GIT_URL_SHA256}")) { // This may be the more portable solution with regard to filesystems - referenceExpanded = reference.replaceAll( - "\\$\\{GIT_URL_SHA256\\}$", - DigestUtils.sha256Hex(urlNormalized)); + referenceExpanded = + reference.replaceAll("\\$\\{GIT_URL_SHA256\\}$", DigestUtils.sha256Hex(urlNormalized)); } else if (reference.endsWith("/${GIT_URL_SHA256_FALLBACK}")) { // The safest option - fall back to parent directory if // the expanded one does not have git repo data right now: // it allows to gradually convert a big combined reference // repository into smaller chunks without breaking builds. - referenceExpanded = reference.replaceAll( - "\\$\\{GIT_URL_SHA256_FALLBACK\\}$", - DigestUtils.sha256Hex(urlNormalized)); - if (getObjectsFile(referenceExpanded) == null - && getObjectsFile(referenceExpanded + ".git") == null - ) { + referenceExpanded = + reference.replaceAll("\\$\\{GIT_URL_SHA256_FALLBACK\\}$", DigestUtils.sha256Hex(urlNormalized)); + if (getObjectsFile(referenceExpanded) == null && getObjectsFile(referenceExpanded + ".git") == null) { // chop it off, use main directory referenceExpanded = referenceBaseDir; } } else if (reference.endsWith("/${GIT_URL_BASENAME}") - || reference.endsWith("/${GIT_URL_BASENAME_FALLBACK}") - ) { + || reference.endsWith("/${GIT_URL_BASENAME_FALLBACK}")) { // This may be the more portable solution with regard to filesystems // First try with original user-provided casing of the URL (if local // dirs were cloned manually) @@ -1140,17 +1120,12 @@ && getObjectsFile(referenceExpanded + ".git") == null needleBasename = needleBasename.replaceAll(".git$", ""); if (reference.endsWith("/${GIT_URL_BASENAME}")) { - referenceExpanded = reference.replaceAll( - "\\$\\{GIT_URL_BASENAME\\}$", - needleBasename); + referenceExpanded = reference.replaceAll("\\$\\{GIT_URL_BASENAME\\}$", needleBasename); } else { // if (reference.endsWith("/${GIT_URL_BASENAME_FALLBACK}")) { - referenceExpanded = reference.replaceAll( - "\\$\\{GIT_URL_BASENAME_FALLBACK\\}$", - needleBasename); + referenceExpanded = reference.replaceAll("\\$\\{GIT_URL_BASENAME_FALLBACK\\}$", needleBasename); if (url.equals(urlNormalized) && getObjectsFile(referenceExpanded) == null - && getObjectsFile(referenceExpanded + ".git") == null - ) { + && getObjectsFile(referenceExpanded + ".git") == null) { // chop it off, use main directory (only if we do not check urlNormalized separately below) referenceExpanded = referenceBaseDir; } @@ -1158,8 +1133,7 @@ && getObjectsFile(referenceExpanded + ".git") == null if (!url.equals(urlNormalized) && getObjectsFile(referenceExpanded) == null - && getObjectsFile(referenceExpanded + ".git") == null - ) { + && getObjectsFile(referenceExpanded + ".git") == null) { // Retry with automation-ready normalized URL sep = urlNormalized.lastIndexOf("/"); if (sep < 0) { @@ -1170,24 +1144,17 @@ && getObjectsFile(referenceExpanded + ".git") == null needleBasename = needleBasename.replaceAll(".git$", ""); if (reference.endsWith("/${GIT_URL_BASENAME}")) { - referenceExpanded = reference.replaceAll( - "\\$\\{GIT_URL_BASENAME\\}$", - needleBasename); + referenceExpanded = reference.replaceAll("\\$\\{GIT_URL_BASENAME\\}$", needleBasename); } else { // if (reference.endsWith("/${GIT_URL_BASENAME_FALLBACK}")) { - referenceExpanded = reference.replaceAll( - "\\$\\{GIT_URL_BASENAME_FALLBACK\\}$", - needleBasename); + referenceExpanded = reference.replaceAll("\\$\\{GIT_URL_BASENAME_FALLBACK\\}$", needleBasename); if (getObjectsFile(referenceExpanded) == null - && getObjectsFile(referenceExpanded + ".git") == null - ) { + && getObjectsFile(referenceExpanded + ".git") == null) { // chop it off, use main directory referenceExpanded = referenceBaseDir; } } } - } else if (reference.endsWith("/${GIT_SUBMODULES}") - || reference.endsWith("/${GIT_SUBMODULES_FALLBACK}") - ) { + } else if (reference.endsWith("/${GIT_SUBMODULES}") || reference.endsWith("/${GIT_SUBMODULES_FALLBACK}")) { // Here we employ git submodules - so we can reliably match // remote URLs (easily multiple) to particular modules, and // yet keep separate git index directories per module with @@ -1231,19 +1198,16 @@ && getObjectsFile(referenceExpanded + ".git") == null } LOGGER.log( Level.FINE, - "findParameterizedReferenceRepository(): got referenceExpanded='" - + referenceExpanded + "' from subEntries"); + "findParameterizedReferenceRepository(): got referenceExpanded='" + referenceExpanded + + "' from subEntries"); if (reference.endsWith("/${GIT_SUBMODULES_FALLBACK}") && getObjectsFile(referenceExpanded) == null - && getObjectsFile(referenceExpanded + ".git") == null - ) { + && getObjectsFile(referenceExpanded + ".git") == null) { // chop it off, use main directory referenceExpanded = referenceBaseDir; } } else { - LOGGER.log( - Level.FINE, - "findParameterizedReferenceRepository(): got no subEntries"); + LOGGER.log(Level.FINE, "findParameterizedReferenceRepository(): got no subEntries"); // If there is no hit, the non-fallback mode suggests a new // directory name to host the submodule (same rules as for // the refrepo forks' co-hosting friendly basename search), @@ -1258,18 +1222,12 @@ && getObjectsFile(referenceExpanded + ".git") == null needleBasename = needleBasename.replaceAll(".git$", ""); if (reference.endsWith("/${GIT_SUBMODULES}")) { - referenceExpanded = reference.replaceAll( - "\\$\\{GIT_SUBMODULES\\}$", - needleBasename); - } - else { // if (reference.endsWith("/${GIT_SUBMODULES_FALLBACK}")) { - referenceExpanded = reference.replaceAll( - "\\$\\{GIT_SUBMODULES\\}$", - needleBasename); + referenceExpanded = reference.replaceAll("\\$\\{GIT_SUBMODULES\\}$", needleBasename); + } else { // if (reference.endsWith("/${GIT_SUBMODULES_FALLBACK}")) { + referenceExpanded = reference.replaceAll("\\$\\{GIT_SUBMODULES\\}$", needleBasename); if (reference.endsWith("/${GIT_SUBMODULES_FALLBACK}") && getObjectsFile(referenceExpanded) == null - && getObjectsFile(referenceExpanded + ".git") == null - ) { + && getObjectsFile(referenceExpanded + ".git") == null) { // chop it off, use main directory referenceExpanded = referenceBaseDir; } @@ -1288,8 +1246,8 @@ && getObjectsFile(referenceExpanded + ".git") == null LOGGER.log( Level.INFO, - "After resolving the parameterized Git reference repository, " - + "decided to use '" + reference + "' directory for URL '" + url + "'"); + "After resolving the parameterized Git reference repository, " + "decided to use '" + reference + + "' directory for URL '" + url + "'"); } // if referencePath is the replaceable token and not existing directory if (!referencePath.exists() && !reference.endsWith(".git")) { diff --git a/src/test/java/org/jenkinsci/plugins/gitclient/GitClientCloneTest.java b/src/test/java/org/jenkinsci/plugins/gitclient/GitClientCloneTest.java index 61deef1667..b33c475369 100644 --- a/src/test/java/org/jenkinsci/plugins/gitclient/GitClientCloneTest.java +++ b/src/test/java/org/jenkinsci/plugins/gitclient/GitClientCloneTest.java @@ -363,8 +363,7 @@ public void test_clone_reference_parameterized_sha256() throws Exception, IOExce // the provided string, as we check in log below } - System.err.println("wsRefrepoBase='" + wsRefrepoBase + "'\n" - + "wsRefrepo='" + wsRefrepo); + System.err.println("wsRefrepoBase='" + wsRefrepoBase + "'\n" + "wsRefrepo='" + wsRefrepo); testGitClient .clone_() @@ -398,7 +397,7 @@ public void test_clone_reference_parameterized_sha256() throws Exception, IOExce assertBranchesExist(testGitClient.getBranches(), "master"); assertNoObjectsInRepository(); } // else Skip: Missing if clone failed - currently would, - // with bogus path above and not pre-created path structure + // with bogus path above and not pre-created path structure } @Test @@ -433,8 +432,7 @@ public void test_clone_reference_parameterized_sha256_fallback() // the provided string, as we check in log below } - System.err.println("wsRefrepoBase='" + wsRefrepoBase + "'\n" - + "wsRefrepo='" + wsRefrepo); + System.err.println("wsRefrepoBase='" + wsRefrepoBase + "'\n" + "wsRefrepo='" + wsRefrepo); testGitClient .clone_() @@ -470,7 +468,7 @@ public void test_clone_reference_parameterized_sha256_fallback() assertBranchesExist(testGitClient.getBranches(), "master"); assertNoObjectsInRepository(); } // else Skip: Missing if clone failed - currently would, - // with bogus path above and not pre-created path structure + // with bogus path above and not pre-created path structure } private static final String SRC_DIR = (new File(".")).getAbsolutePath(); @@ -658,13 +656,11 @@ private void assertNoObjectsInRepository() { } // Most tests use this method, expecting a non-bare repo - private void assertAlternateFilePointsToLocalMirror() - throws IOException, InterruptedException { + private void assertAlternateFilePointsToLocalMirror() throws IOException, InterruptedException { assertAlternateFilePointsToLocalWorkspaceMirror(testGitDir); } - private void assertAlternateFilePointsToLocalWorkspaceMirror() - throws IOException, InterruptedException { + private void assertAlternateFilePointsToLocalWorkspaceMirror() throws IOException, InterruptedException { assertAlternateFilePointsToLocalWorkspaceMirror(testGitDir); } @@ -686,13 +682,11 @@ private void assertAlternateFilePointsToLocalWorkspaceMirror(String _testGitDir, } // Similar for bare repos, without ".git/" dir - private void assertAlternateFilePointsToLocalBareMirror() - throws IOException, InterruptedException { + private void assertAlternateFilePointsToLocalBareMirror() throws IOException, InterruptedException { assertAlternateFilePointsToLocalBareMirror(testGitDir); } - private void assertAlternateFilePointsToLocalBareMirror(File _testGitDir) - throws IOException, InterruptedException { + private void assertAlternateFilePointsToLocalBareMirror(File _testGitDir) throws IOException, InterruptedException { assertAlternateFilePointsToLocalBareMirror(_testGitDir.getPath()); }