Skip to content

Commit 6d4bd49

Browse files
committed
Switching some clone-mode messages to fine logger #55 (comment)
1 parent 7f1251d commit 6d4bd49

File tree

2 files changed

+15
-13
lines changed

2 files changed

+15
-13
lines changed

src/main/java/org/jenkinsci/plugins/workflow/libs/SCMBasedRetriever.java

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,10 @@
5050
import java.util.HashMap;
5151
import java.util.List;
5252
import java.util.Map;
53-
import java.util.Set;
54-
import java.util.TreeSet;
5553
import java.util.concurrent.Callable;
5654
import java.util.logging.Level;
5755
import java.util.logging.Logger;
5856
import java.util.regex.Pattern;
59-
import java.util.stream.Collectors;
6057
import jenkins.model.Jenkins;
6158
import org.jenkinsci.plugins.workflow.steps.scm.GenericSCMStep;
6259
import org.jenkinsci.plugins.workflow.steps.scm.SCMStep;
@@ -149,20 +146,18 @@ protected final void doRetrieve(String name, boolean changelog, @NonNull SCM scm
149146
for (String content : List.of("src", "vars", "resources")) {
150147
FilePath contentDir = subdir.child(content);
151148
if (contentDir.isDirectory()) {
152-
listener.getLogger().println("Moving " + content + " to top level");
149+
LOGGER.fine(() -> "Moving " + content + " to top level in " + target);
153150
contentDir.renameTo(target.child(content));
154151
}
155152
}
156153
// root itself will be deleted below
157154
}
158-
Set<String> deleted = new TreeSet<>();
159155
if (!INCLUDE_SRC_TEST_IN_LIBRARIES) {
160156
FilePath srcTest = target.child("src/test");
161157
if (srcTest.isDirectory()) {
162158
listener.getLogger().println("Excluding src/test/ from checkout of " + scm.getKey() + " so that library test code cannot be accessed by Pipelines.");
163159
listener.getLogger().println("To remove this log message, move the test code outside of src/. To restore the previous behavior that allowed access to files in src/test/, pass -D" + SCMSourceRetriever.class.getName() + ".INCLUDE_SRC_TEST_IN_LIBRARIES=true to the java command used to start Jenkins.");
164160
srcTest.deleteRecursive();
165-
deleted.add("src/test");
166161
}
167162
}
168163
for (FilePath child : target.list()) {
@@ -178,13 +173,10 @@ protected final void doRetrieve(String name, boolean changelog, @NonNull SCM scm
178173
// OK, leave it all
179174
break;
180175
default:
181-
deleted.add(subdir);
182176
child.deleteRecursive();
177+
LOGGER.fine(() -> "Deleted " + child);
183178
}
184179
}
185-
if (!deleted.isEmpty()) {
186-
listener.getLogger().println("Deleted " + deleted.stream().collect(Collectors.joining(", ")));
187-
}
188180
} else { // !clone
189181
FilePath dir;
190182
if (run.getParent() instanceof TopLevelItem) {

src/test/java/org/jenkinsci/plugins/workflow/libs/SCMSourceRetrieverTest.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import java.util.Collections;
4444
import java.util.Iterator;
4545
import java.util.List;
46+
import java.util.logging.Level;
4647
import jenkins.plugins.git.GitSCMSource;
4748
import jenkins.plugins.git.GitSampleRepoRule;
4849
import jenkins.scm.api.SCMHead;
@@ -80,12 +81,15 @@
8081
import org.jvnet.hudson.test.WithoutJenkins;
8182

8283
import static org.hamcrest.MatcherAssert.assertThat;
84+
import static org.hamcrest.Matchers.arrayContainingInAnyOrder;
85+
import static org.hamcrest.Matchers.arrayWithSize;
8386
import static org.hamcrest.Matchers.equalTo;
8487
import static org.hamcrest.Matchers.matchesPattern;
8588
import static org.hamcrest.Matchers.nullValue;
8689
import static org.jenkinsci.plugins.workflow.libs.SCMBasedRetriever.PROHIBITED_DOUBLE_DOT;
8790
import static org.junit.Assume.assumeFalse;
8891
import org.jvnet.hudson.test.FlagRule;
92+
import org.jvnet.hudson.test.LoggerRule;
8993

9094
public class SCMSourceRetrieverTest {
9195

@@ -94,6 +98,7 @@ public class SCMSourceRetrieverTest {
9498
@Rule public GitSampleRepoRule sampleRepo = new GitSampleRepoRule();
9599
@Rule public SubversionSampleRepoRule sampleRepoSvn = new SubversionSampleRepoRule();
96100
@Rule public FlagRule<Boolean> includeSrcTest = new FlagRule<>(() -> SCMBasedRetriever.INCLUDE_SRC_TEST_IN_LIBRARIES, v -> SCMBasedRetriever.INCLUDE_SRC_TEST_IN_LIBRARIES = v);
101+
@Rule public LoggerRule logging = new LoggerRule().record(SCMBasedRetriever.class, Level.FINE);
97102

98103
@Issue("JENKINS-40408")
99104
@Test public void lease() throws Exception {
@@ -393,10 +398,13 @@ public static class BasicSCMSource extends SCMSource {
393398
WorkflowRun b = r.buildAndAssertSuccess(p);
394399
assertFalse(r.jenkins.getWorkspaceFor(p).withSuffix("@libs").isDirectory());
395400
r.assertLogContains("something special", b);
396-
r.assertLogContains("Deleted .git, README.md", b);
397401
r.assertLogContains("Using shallow clone with depth 1", b);
398402
r.assertLogContains("Avoid fetching tags", b);
399403
r.assertLogNotContains("+refs/heads/*:refs/remotes/origin/*", b);
404+
File[] libDirs = new File(b.getRootDir(), "libs").listFiles(File::isDirectory);
405+
assertThat(libDirs, arrayWithSize(1));
406+
String[] entries = libDirs[0].list();
407+
assertThat(entries, arrayContainingInAnyOrder("vars"));
400408
}
401409

402410
@Test public void cloneModeLibraryPath() throws Exception {
@@ -414,8 +422,10 @@ public static class BasicSCMSource extends SCMSource {
414422
p.setDefinition(new CpsFlowDefinition("@Library('root_sub_path@master') import myecho; myecho()", true));
415423
WorkflowRun b = r.buildAndAssertSuccess(p);
416424
r.assertLogContains("something special", b);
417-
r.assertLogContains("Moving vars to top level", b);
418-
r.assertLogContains("Deleted root", b);
425+
File[] libDirs = new File(b.getRootDir(), "libs").listFiles(File::isDirectory);
426+
assertThat(libDirs, arrayWithSize(1));
427+
String[] entries = libDirs[0].list();
428+
assertThat(entries, arrayContainingInAnyOrder("vars"));
419429
}
420430

421431
@Test public void cloneModeLibraryPathSecurity() throws Exception {

0 commit comments

Comments
 (0)