From 9259f65315249293a97a8bfea8e50fd6e3531b1a Mon Sep 17 00:00:00 2001 From: Eugene Petrenko Date: Tue, 16 Aug 2011 01:12:02 +0400 Subject: [PATCH 1/1] more on remove installed packages --- .../build-server-plugin-nuget-tools.xml | 1 + .../impl/NuGetToolsInstaller.java | 13 +++-- .../toolRegistry/impl/PluginNaming.java | 49 +++++++++++++++++++ .../server/toolRegistry/impl/ToolPacker.java | 1 - .../toolRegistry/impl/ToolsRegistry.java | 29 ++++++++--- 5 files changed, 83 insertions(+), 10 deletions(-) create mode 100644 nuget-server/src/jetbrains/buildServer/nuget/server/toolRegistry/impl/PluginNaming.java diff --git a/nuget-server/src/META-INF/build-server-plugin-nuget-tools.xml b/nuget-server/src/META-INF/build-server-plugin-nuget-tools.xml index bc4c44a..cb6746a 100644 --- a/nuget-server/src/META-INF/build-server-plugin-nuget-tools.xml +++ b/nuget-server/src/META-INF/build-server-plugin-nuget-tools.xml @@ -14,4 +14,5 @@ + \ No newline at end of file diff --git a/nuget-server/src/jetbrains/buildServer/nuget/server/toolRegistry/impl/NuGetToolsInstaller.java b/nuget-server/src/jetbrains/buildServer/nuget/server/toolRegistry/impl/NuGetToolsInstaller.java index af6f578..82172d3 100644 --- a/nuget-server/src/jetbrains/buildServer/nuget/server/toolRegistry/impl/NuGetToolsInstaller.java +++ b/nuget-server/src/jetbrains/buildServer/nuget/server/toolRegistry/impl/NuGetToolsInstaller.java @@ -37,15 +37,18 @@ public class NuGetToolsInstaller { private final NuGetFeedReader myClient; private final AvailableToolsState myState; private final ToolPacker myPacker; + private final PluginNaming myNaming; public NuGetToolsInstaller(@NotNull final ToolPaths toolPaths, @NotNull final NuGetFeedReader client, @NotNull final AvailableToolsState state, - @NotNull final ToolPacker packer) { + @NotNull final ToolPacker packer, + @NotNull final PluginNaming naming) { myToolPaths = toolPaths; myClient = client; myState = state; myPacker = packer; + myNaming = naming; } public InstallResult installNuGet(@NotNull final String packageId, @NotNull final InstallLogger logger) { @@ -80,7 +83,7 @@ public class NuGetToolsInstaller { logger.agentToolPubslishStarted(tool, agentTool); try { - final File dest = new File(myToolPaths.getAgentPluginsPath(), agentTool.getName()); + final File dest = myNaming.getAgetToolFilePath(tool); if (!agentTool.renameTo(dest)) { FileUtil.copy(agentTool, dest); FileUtil.delete(agentTool); @@ -94,12 +97,16 @@ public class NuGetToolsInstaller { } } + private String getAgentToolFileName(@NotNull String version) { + return "nuget-commnadline-" + version; + } + private File packAgentPlugin(@NotNull final InstallLogger logger, @NotNull final FeedPackage tool, @NotNull final File dest) { logger.agentToolPackStarted(tool, dest); try { - return myPacker.packTool("nuget-commandline-" + tool.getInfo().getVersion(), dest); + return myPacker.packTool(getAgentToolFileName(tool.getInfo().getVersion()), dest); } catch (Exception e) { logger.agentToolPackFailed(tool, dest, e); LOG.warn("Failed to pack agent tool " + tool); 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 index 0000000..206b161 --- /dev/null +++ b/nuget-server/src/jetbrains/buildServer/nuget/server/toolRegistry/impl/PluginNaming.java @@ -0,0 +1,49 @@ +/* + * Copyright 2000-2011 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package jetbrains.buildServer.nuget.server.toolRegistry.impl; + +import jetbrains.buildServer.nuget.server.feed.reader.FeedPackage; +import jetbrains.buildServer.nuget.server.toolRegistry.NuGetTool; +import org.jetbrains.annotations.NotNull; + +import java.io.File; + +/** + * Created by Eugene Petrenko (eugene.petrenko@gmail.com) + * Date: 16.08.11 1:00 + */ +public class PluginNaming { + private final ToolPaths myPaths; + + public PluginNaming(@NotNull final ToolPaths paths) { + myPaths = paths; + } + + @NotNull + public String getAgentToolFileName(@NotNull String version) { + return "nuget-commnadline-" + version + ".zip"; + } + + public File getAgetToolFilePath(@NotNull NuGetTool tool) { + return new File(myPaths.getAgentPluginsPath(), getAgentToolFileName(tool.getVersion())); + } + + public File getAgetToolFilePath(@NotNull FeedPackage tool) { + return new File(myPaths.getAgentPluginsPath(), getAgentToolFileName(tool.getInfo().getVersion())); + } + +} diff --git a/nuget-server/src/jetbrains/buildServer/nuget/server/toolRegistry/impl/ToolPacker.java b/nuget-server/src/jetbrains/buildServer/nuget/server/toolRegistry/impl/ToolPacker.java index 0d26570..661a1af 100644 --- a/nuget-server/src/jetbrains/buildServer/nuget/server/toolRegistry/impl/ToolPacker.java +++ b/nuget-server/src/jetbrains/buildServer/nuget/server/toolRegistry/impl/ToolPacker.java @@ -24,7 +24,6 @@ import java.io.BufferedOutputStream; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; -import java.util.Collection; import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; 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 a72f2aa..1859bbf 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 @@ -16,6 +16,7 @@ package jetbrains.buildServer.nuget.server.toolRegistry.impl; +import com.intellij.openapi.diagnostic.Logger; import jetbrains.buildServer.nuget.server.toolRegistry.NuGetInstalledTool; import jetbrains.buildServer.util.FileUtil; import org.jetbrains.annotations.NotNull; @@ -30,10 +31,14 @@ import java.util.Collections; * Date: 16.08.11 0:25 */ public class ToolsRegistry { + private static final Logger LOG = Logger.getInstance(ToolsRegistry.class.getName()); private final ToolPaths myPaths; + private final PluginNaming myNaming; - public ToolsRegistry(@NotNull final ToolPaths paths) { + public ToolsRegistry(@NotNull final ToolPaths paths, + @NotNull final PluginNaming naming) { myPaths = paths; + myNaming = naming; } @NotNull @@ -54,7 +59,15 @@ public class ToolsRegistry { public void removeTool(@NotNull final String toolId) { for (InstalledTool tool : getToolsInternal()) { if (tool.getId().equals(toolId)) { - tool.delete(); + LOG.info("Removing NuGet plugin: " + tool); + + final File agentPlugin = myNaming.getAgetToolFilePath(tool); + LOG.info("Removing NuGet plugin agent tool : " + agentPlugin); + FileUtil.delete(agentPlugin); + + final File toolHome = tool.getRootPath(); + LOG.info("Removing NuGet files from: " + toolHome); + FileUtil.delete(toolHome); return; } } @@ -67,10 +80,9 @@ public class ToolsRegistry { myPath = path; } - public void delete() { - while(myPath.exists()) { - FileUtil.delete(myPath); - } + @NotNull + public File getRootPath() { + return myPath; } @NotNull @@ -78,6 +90,11 @@ public class ToolsRegistry { return new File(myPath, "tools/NuGet.exe"); } + @NotNull + public String getAgentToolName() { + return "nuget-commandline-" + getVersion() + ".zip"; + } + @NotNull public String getId() { return myPath.getName(); -- 2.32.0