package jetbrains.buildServer.nuget.server.toolRegistry.impl;\r
\r
import jetbrains.buildServer.nuget.server.toolRegistry.NuGetInstalledTool;\r
+import jetbrains.buildServer.util.FileUtil;\r
import org.jetbrains.annotations.NotNull;\r
\r
import java.io.File;\r
}\r
\r
@NotNull\r
- public Collection<NuGetInstalledTool> getTools() {\r
+ public Collection<? extends NuGetInstalledTool> getTools() {\r
+ return getToolsInternal();\r
+ }\r
+\r
+ private Collection<InstalledTool> getToolsInternal() {\r
final File[] tools = myPaths.getTools().listFiles();\r
if (tools == null) return Collections.emptyList();\r
- final Collection<NuGetInstalledTool> result = new ArrayList<NuGetInstalledTool>();\r
+ final Collection<InstalledTool> result = new ArrayList<InstalledTool>();\r
for (final File path : tools) {\r
- result.add(new NuGetInstalledTool() {\r
- @NotNull\r
- public File getPath() {\r
- return new File(path, "tools/NuGet.exe");\r
- }\r
-\r
- @NotNull\r
- public String getId() {\r
- return path.getName();\r
- }\r
-\r
- @NotNull\r
- public String getVersion() {\r
- return path.getName();\r
- }\r
- });\r
+ result.add(new InstalledTool(path));\r
}\r
return result;\r
}\r
+\r
+ public void removeTool(@NotNull final String toolId) {\r
+ for (InstalledTool tool : getToolsInternal()) {\r
+ if (tool.getId().equals(toolId)) {\r
+ tool.delete();\r
+ return;\r
+ }\r
+ }\r
+ }\r
+\r
+ private static class InstalledTool implements NuGetInstalledTool {\r
+ private final File myPath;\r
+\r
+ public InstalledTool(@NotNull final File path) {\r
+ myPath = path;\r
+ }\r
+\r
+ public void delete() {\r
+ while(myPath.exists()) {\r
+ FileUtil.delete(myPath);\r
+ }\r
+ }\r
+\r
+ @NotNull\r
+ public File getPath() {\r
+ return new File(myPath, "tools/NuGet.exe");\r
+ }\r
+\r
+ @NotNull\r
+ public String getId() {\r
+ return myPath.getName();\r
+ }\r
+\r
+ @NotNull\r
+ public String getVersion() {\r
+ return myPath.getName();\r
+ }\r
+ }\r
}\r