\r
package jetbrains.buildServer.nuget.server.toolRegistry.impl;\r
\r
+import com.intellij.openapi.diagnostic.Logger;\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
* Date: 16.08.11 0:25\r
*/\r
public class ToolsRegistry {\r
+ private static final Logger LOG = Logger.getInstance(ToolsRegistry.class.getName());\r
private final ToolPaths myPaths;\r
+ private final PluginNaming myNaming;\r
\r
- public ToolsRegistry(@NotNull final ToolPaths paths) {\r
+ public ToolsRegistry(@NotNull final ToolPaths paths,\r
+ @NotNull final PluginNaming naming) {\r
myPaths = paths;\r
+ myNaming = naming;\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
+ LOG.info("Removing NuGet plugin: " + tool);\r
+\r
+ final File agentPlugin = myNaming.getAgetToolFilePath(tool);\r
+ LOG.info("Removing NuGet plugin agent tool : " + agentPlugin);\r
+ FileUtil.delete(agentPlugin);\r
+\r
+ final File toolHome = tool.getRootPath();\r
+ LOG.info("Removing NuGet files from: " + toolHome);\r
+ FileUtil.delete(toolHome);\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
+ @NotNull\r
+ public File getRootPath() {\r
+ return myPath;\r
+ }\r
+\r
+ @NotNull\r
+ public File getPath() {\r
+ return new File(myPath, "tools/NuGet.exe");\r
+ }\r
+\r
+ @NotNull\r
+ public String getAgentToolName() {\r
+ return "nuget-commandline-" + getVersion() + ".zip";\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