more on remove installed packages
authorEugene Petrenko <eugene.petrenko@gmail.com>
Mon, 15 Aug 2011 21:12:02 +0000 (01:12 +0400)
committerEugene Petrenko <eugene.petrenko@gmail.com>
Mon, 15 Aug 2011 21:12:02 +0000 (01:12 +0400)
nuget-server/src/META-INF/build-server-plugin-nuget-tools.xml
nuget-server/src/jetbrains/buildServer/nuget/server/toolRegistry/impl/NuGetToolsInstaller.java
nuget-server/src/jetbrains/buildServer/nuget/server/toolRegistry/impl/PluginNaming.java [new file with mode: 0644]
nuget-server/src/jetbrains/buildServer/nuget/server/toolRegistry/impl/ToolPacker.java
nuget-server/src/jetbrains/buildServer/nuget/server/toolRegistry/impl/ToolsRegistry.java

index bc4c44af94cf01b149db03ac648ea1f44ee87d51..cb6746aa94de500a3b98eae8d3f9a482d95da27c 100644 (file)
@@ -14,4 +14,5 @@
   <bean class="jetbrains.buildServer.nuget.server.toolRegistry.impl.ToolsRegistry"/>\r
   <bean class="jetbrains.buildServer.nuget.server.toolRegistry.impl.ToolPacker"/>\r
   <bean class="jetbrains.buildServer.nuget.server.toolRegistry.impl.ToolPaths"/>\r
+  <bean class="jetbrains.buildServer.nuget.server.toolRegistry.impl.PluginNaming"/>\r
 </beans>
\ No newline at end of file
index af6f5787720da1d9311c4d33f1fc9cbf66410571..82172d33b83cdbc20b962446202c795b46e5d32d 100644 (file)
@@ -37,15 +37,18 @@ public class NuGetToolsInstaller {
   private final NuGetFeedReader myClient;\r
   private final AvailableToolsState myState;\r
   private final ToolPacker myPacker;\r
+  private final PluginNaming myNaming;\r
 \r
   public NuGetToolsInstaller(@NotNull final ToolPaths toolPaths,\r
                              @NotNull final NuGetFeedReader client,\r
                              @NotNull final AvailableToolsState state,\r
-                             @NotNull final ToolPacker packer) {\r
+                             @NotNull final ToolPacker packer,\r
+                             @NotNull final PluginNaming naming) {\r
     myToolPaths = toolPaths;\r
     myClient = client;\r
     myState = state;\r
     myPacker = packer;\r
+    myNaming = naming;\r
   }\r
 \r
   public InstallResult installNuGet(@NotNull final String packageId, @NotNull final InstallLogger logger) {\r
@@ -80,7 +83,7 @@ public class NuGetToolsInstaller {
     logger.agentToolPubslishStarted(tool, agentTool);\r
 \r
     try {\r
-      final File dest = new File(myToolPaths.getAgentPluginsPath(), agentTool.getName());\r
+      final File dest = myNaming.getAgetToolFilePath(tool);\r
       if (!agentTool.renameTo(dest)) {\r
         FileUtil.copy(agentTool, dest);\r
         FileUtil.delete(agentTool);\r
@@ -94,12 +97,16 @@ public class NuGetToolsInstaller {
     }\r
   }\r
 \r
+  private String getAgentToolFileName(@NotNull String version) {\r
+    return "nuget-commnadline-" + version;\r
+  }\r
+\r
   private File packAgentPlugin(@NotNull final InstallLogger logger,\r
                                @NotNull final FeedPackage tool,\r
                                @NotNull final File dest) {\r
     logger.agentToolPackStarted(tool, dest);\r
     try {\r
-      return myPacker.packTool("nuget-commandline-" + tool.getInfo().getVersion(), dest);\r
+      return myPacker.packTool(getAgentToolFileName(tool.getInfo().getVersion()), dest);\r
     } catch (Exception e) {\r
       logger.agentToolPackFailed(tool, dest, e);\r
       LOG.warn("Failed to pack agent tool " + tool);\r
diff --git a/nuget-server/src/jetbrains/buildServer/nuget/server/toolRegistry/impl/PluginNaming.java b/nuget-server/src/jetbrains/buildServer/nuget/server/toolRegistry/impl/PluginNaming.java
new file mode 100644 (file)
index 0000000..206b161
--- /dev/null
@@ -0,0 +1,49 @@
+/*\r
+ * Copyright 2000-2011 JetBrains s.r.o.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+\r
+package jetbrains.buildServer.nuget.server.toolRegistry.impl;\r
+\r
+import jetbrains.buildServer.nuget.server.feed.reader.FeedPackage;\r
+import jetbrains.buildServer.nuget.server.toolRegistry.NuGetTool;\r
+import org.jetbrains.annotations.NotNull;\r
+\r
+import java.io.File;\r
+\r
+/**\r
+ * Created by Eugene Petrenko (eugene.petrenko@gmail.com)\r
+ * Date: 16.08.11 1:00\r
+ */\r
+public class PluginNaming {\r
+  private final ToolPaths myPaths;\r
+\r
+  public PluginNaming(@NotNull final ToolPaths paths) {\r
+    myPaths = paths;\r
+  }\r
+\r
+  @NotNull\r
+  public String getAgentToolFileName(@NotNull String version) {\r
+    return "nuget-commnadline-" + version + ".zip";\r
+  }\r
+\r
+  public File getAgetToolFilePath(@NotNull NuGetTool tool) {\r
+    return new File(myPaths.getAgentPluginsPath(), getAgentToolFileName(tool.getVersion()));\r
+  }\r
+\r
+  public File getAgetToolFilePath(@NotNull FeedPackage tool) {\r
+    return new File(myPaths.getAgentPluginsPath(), getAgentToolFileName(tool.getInfo().getVersion()));\r
+  }\r
+\r
+}\r
index 0d26570d8354c61a987a359bcfda7e6f8c10acef..661a1af1dba817264a7659d16dd78352bd915761 100644 (file)
@@ -24,7 +24,6 @@ import java.io.BufferedOutputStream;
 import java.io.File;\r
 import java.io.FileOutputStream;\r
 import java.io.IOException;\r
-import java.util.Collection;\r
 import java.util.zip.ZipEntry;\r
 import java.util.zip.ZipOutputStream;\r
 \r
index a72f2aaa9abb91c77ed6aa47432a41591b8a0ba7..1859bbf6f3f56687074ba131ca7d3bf84057cff3 100644 (file)
@@ -16,6 +16,7 @@
 \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
@@ -30,10 +31,14 @@ import java.util.Collections;
  * 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
@@ -54,7 +59,15 @@ public class ToolsRegistry {
   public void removeTool(@NotNull final String toolId) {\r
     for (InstalledTool tool : getToolsInternal()) {\r
       if (tool.getId().equals(toolId)) {\r
-        tool.delete();\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
@@ -67,10 +80,9 @@ public class ToolsRegistry {
       myPath = path;\r
     }\r
 \r
-    public void delete() {\r
-      while(myPath.exists()) {\r
-        FileUtil.delete(myPath);\r
-      }\r
+    @NotNull\r
+    public File getRootPath() {\r
+      return myPath;\r
     }\r
 \r
     @NotNull\r
@@ -78,6 +90,11 @@ public class ToolsRegistry {
       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