X-Git-Url: https://git.jetbrains.org/?p=teamcity%2FdotNetPackagesSupport.git;a=blobdiff_plain;f=nuget-server%2Fsrc%2Fjetbrains%2FbuildServer%2Fnuget%2Fserver%2FtoolRegistry%2Fimpl%2FToolsRegistry.java;h=a72f2aaa9abb91c77ed6aa47432a41591b8a0ba7;hp=1ca113ed8dc56c654bc3d0b0679734cb05381079;hb=46d6ef65c5eaa65d1ef6946fc18a16a7b66dac55;hpb=8fe6a85d16ad8c093662d7103848efa76d555b2c diff --git a/nuget-server/src/jetbrains/buildServer/nuget/server/toolRegistry/impl/ToolsRegistry.java b/nuget-server/src/jetbrains/buildServer/nuget/server/toolRegistry/impl/ToolsRegistry.java index 1ca113e..a72f2aa 100644 --- a/nuget-server/src/jetbrains/buildServer/nuget/server/toolRegistry/impl/ToolsRegistry.java +++ b/nuget-server/src/jetbrains/buildServer/nuget/server/toolRegistry/impl/ToolsRegistry.java @@ -17,6 +17,7 @@ package jetbrains.buildServer.nuget.server.toolRegistry.impl; import jetbrains.buildServer.nuget.server.toolRegistry.NuGetInstalledTool; +import jetbrains.buildServer.util.FileUtil; import org.jetbrains.annotations.NotNull; import java.io.File; @@ -36,28 +37,55 @@ public class ToolsRegistry { } @NotNull - public Collection getTools() { + public Collection getTools() { + return getToolsInternal(); + } + + private Collection getToolsInternal() { final File[] tools = myPaths.getTools().listFiles(); if (tools == null) return Collections.emptyList(); - final Collection result = new ArrayList(); + final Collection result = new ArrayList(); for (final File path : tools) { - result.add(new NuGetInstalledTool() { - @NotNull - public File getPath() { - return new File(path, "tools/NuGet.exe"); - } - - @NotNull - public String getId() { - return path.getName(); - } - - @NotNull - public String getVersion() { - return path.getName(); - } - }); + result.add(new InstalledTool(path)); } return result; } + + public void removeTool(@NotNull final String toolId) { + for (InstalledTool tool : getToolsInternal()) { + if (tool.getId().equals(toolId)) { + tool.delete(); + return; + } + } + } + + private static class InstalledTool implements NuGetInstalledTool { + private final File myPath; + + public InstalledTool(@NotNull final File path) { + myPath = path; + } + + public void delete() { + while(myPath.exists()) { + FileUtil.delete(myPath); + } + } + + @NotNull + public File getPath() { + return new File(myPath, "tools/NuGet.exe"); + } + + @NotNull + public String getId() { + return myPath.getName(); + } + + @NotNull + public String getVersion() { + return myPath.getName(); + } + } }