Update examples to use Path instead of File Change-Id: Ie9e1dc99b60d9f9bdb5d02b8a4e09ff43aa7ac56
diff --git a/src/main/java/com/googlesource/gerrit/plugins/cookbook/pluginprovider/HelloSshCommand.java b/src/main/java/com/googlesource/gerrit/plugins/cookbook/pluginprovider/HelloSshCommand.java index b1da6de..a2b678e 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/cookbook/pluginprovider/HelloSshCommand.java +++ b/src/main/java/com/googlesource/gerrit/plugins/cookbook/pluginprovider/HelloSshCommand.java
@@ -20,9 +20,9 @@ import com.google.gerrit.sshd.SshCommand; import com.google.inject.Inject; -import java.io.File; import java.io.IOException; import java.nio.file.Files; +import java.nio.file.Path; /** * SSH command defined by dynamically registered plugins. @@ -31,7 +31,7 @@ @CommandMetaData(name = "print", description = "Print content of the plugin file") public final class HelloSshCommand extends SshCommand { private final String pluginName; - private final File pluginDir; + private final Path pluginDir; @Inject public HelloSshCommand(@PluginName String pluginName, SitePaths sitePaths) { @@ -41,11 +41,11 @@ @Override public void run() { - File pluginFile = new File(pluginDir, pluginName + ".ssh"); + Path pluginPath = pluginDir.resolve(pluginName + ".ssh"); try { - Files.copy(pluginFile.toPath(), out); + Files.copy(pluginPath, out); } catch (IOException e) { - throw new RuntimeException("Cannot read plugin content of " + pluginFile, + throw new RuntimeException("Cannot read plugin content of " + pluginPath, e); } }
diff --git a/src/main/java/com/googlesource/gerrit/plugins/cookbook/pluginprovider/HelloSshPluginProvider.java b/src/main/java/com/googlesource/gerrit/plugins/cookbook/pluginprovider/HelloSshPluginProvider.java index a7d7268..de213e7 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/cookbook/pluginprovider/HelloSshPluginProvider.java +++ b/src/main/java/com/googlesource/gerrit/plugins/cookbook/pluginprovider/HelloSshPluginProvider.java
@@ -22,7 +22,7 @@ import org.eclipse.jgit.internal.storage.file.FileSnapshot; -import java.io.File; +import java.nio.file.Path; /** * Dynamic provider of Gerrit plugins derived by *.ssh files under $GERRIT_SITE/plugins. @@ -46,22 +46,22 @@ } @Override - public boolean handles(File srcFile) { - return srcFile.getName().endsWith(SSH_EXT); + public boolean handles(Path srcPath) { + return srcPath.getFileName().toString().endsWith(SSH_EXT); } @Override - public String getPluginName(File srcFile) { - String srcFileName = srcFile.getName(); - return srcFileName.substring(0, srcFileName.length() - SSH_EXT.length()); + public String getPluginName(Path srcPath) { + String name = srcPath.getFileName().toString(); + return name.substring(0, name.length() - SSH_EXT.length()); } @Override - public ServerPlugin get(File srcFile, FileSnapshot snapshot, + public ServerPlugin get(Path srcPath, FileSnapshot snapshot, PluginDescription pluginDescriptor) throws InvalidPluginException { - String name = getPluginName(srcFile); + String name = getPluginName(srcPath); return new ServerPlugin(name, pluginDescriptor.canonicalUrl, - pluginDescriptor.user, srcFile, snapshot, + pluginDescriptor.user, srcPath, snapshot, new HelloSshPluginContentScanner(name), pluginDescriptor.dataDir, getClass().getClassLoader()); }