Skip to content

Commit

Permalink
Merge pull request #302 from bitwiseman/issue/JENKINS-65068
Browse files Browse the repository at this point in the history
[JENKINS-65068] `RestartableJenkinsRule`: Handle `NoSuchFileException` thrown from `FileTreeWalker`
  • Loading branch information
jglick committed Apr 27, 2021
2 parents 7adf295 + 5c4a1cc commit e14c168
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,10 @@ public FileVisitResult visitFile(final Path file,
@Override
public FileVisitResult visitFileFailed(Path file, IOException exc) {
if (exc instanceof FileNotFoundException) {
LOGGER.log(Level.FINE, "File not found while trying to copy to new home, continuing anyway: "+file.toString());
LOGGER.log(Level.FINE, "File not found while trying to copy to new home, continuing anyway: " + file.toString());
return FileVisitResult.CONTINUE;
} else if (exc instanceof NoSuchFileException) {
LOGGER.log(Level.FINE, "File disappeared while trying to copy to new home, continuing anyway: " + file.toString());
return FileVisitResult.CONTINUE;
} else {
LOGGER.log(Level.WARNING, "Error copying file", exc);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@
import static org.junit.Assume.assumeThat;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.file.FileVisitResult;
import java.nio.file.Files;
import java.nio.file.NoSuchFileException;
import java.nio.file.Path;
import java.util.concurrent.atomic.AtomicInteger;

Expand All @@ -23,7 +27,8 @@

public class RestartableJenkinsRuleTest {

@Rule public RestartableJenkinsRule noPortReuse = new RestartableJenkinsRule();
@Rule
public RestartableJenkinsRule noPortReuse = new RestartableJenkinsRule();

@Rule
public RestartableJenkinsRule portReuse =
Expand Down Expand Up @@ -63,14 +68,14 @@ public void pluginsCanBeDisabled() {
final String pluginId = "display-url-api";
noPortReuse.then(jr -> {
System.out.println(WarExploder.getExplodedDir());
Path srcLdap = new File(WarExploder.getExplodedDir(), "WEB-INF/detached-plugins/"+pluginId+".hpi").toPath();
Path dstLdap = new File(jr.jenkins.pluginManager.rootDir, pluginId+".jpi").toPath();
Path srcLdap = new File(WarExploder.getExplodedDir(), "WEB-INF/detached-plugins/" + pluginId + ".hpi").toPath();
Path dstLdap = new File(jr.jenkins.pluginManager.rootDir, pluginId + ".jpi").toPath();
Files.createDirectories(dstLdap.getParent());
Files.copy(srcLdap, dstLdap);
//jr.getPluginManager().doCheckUpdatesServer();
//jr.getPluginManager().install(Collections.singletonList("cvs"),true);
});

noPortReuse.then(jr -> {
Jenkins j = jr.jenkins;
PluginManager pm = j.getPluginManager();
Expand All @@ -81,9 +86,20 @@ public void pluginsCanBeDisabled() {

noPortReuse.then(jr -> {
assertFalse(pluginId + " is not enabled",
jr.jenkins.getPluginManager().getPlugin(pluginId).isEnabled());
jr.jenkins.getPluginManager().getPlugin(pluginId).isEnabled());
assertFalse(pluginId + " should not be active",
jr.jenkins.getPluginManager().getPlugin(pluginId).isActive());
jr.jenkins.getPluginManager().getPlugin(pluginId).isActive());
});
}

@Test
public void verify_CopyFileVisitor_visitFileFailed_NoSuchFileException() {
Path testPath = new File("./").toPath();
RestartableJenkinsRule.CopyFileVisitor visitor = new RestartableJenkinsRule.CopyFileVisitor(testPath);

assertEquals(FileVisitResult.CONTINUE, visitor.visitFileFailed(testPath, new FileNotFoundException()));
assertEquals(FileVisitResult.CONTINUE, visitor.visitFileFailed(testPath, new NoSuchFileException("./")));
assertEquals(FileVisitResult.TERMINATE, visitor.visitFileFailed(testPath, new IOException()));
}
}

0 comments on commit e14c168

Please sign in to comment.