2 * Copyright 2000-2011 JetBrains s.r.o.
\r
4 * Licensed under the Apache License, Version 2.0 (the "License");
\r
5 * you may not use this file except in compliance with the License.
\r
6 * You may obtain a copy of the License at
\r
8 * http://www.apache.org/licenses/LICENSE-2.0
\r
10 * Unless required by applicable law or agreed to in writing, software
\r
11 * distributed under the License is distributed on an "AS IS" BASIS,
\r
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
13 * See the License for the specific language governing permissions and
\r
14 * limitations under the License.
\r
17 package jetbrains.buildServer.nuget.server.toolRegistry.impl;
\r
19 import com.intellij.openapi.diagnostic.Logger;
\r
20 import jetbrains.buildServer.nuget.common.PackagesConstants;
\r
21 import jetbrains.buildServer.nuget.server.toolRegistry.NuGetInstalledTool;
\r
22 import jetbrains.buildServer.util.FileUtil;
\r
23 import org.jetbrains.annotations.NotNull;
\r
25 import java.io.File;
\r
26 import java.io.FileFilter;
\r
27 import java.util.ArrayList;
\r
28 import java.util.Collection;
\r
29 import java.util.Collections;
\r
32 * Created by Eugene Petrenko (eugene.petrenko@gmail.com)
\r
33 * Date: 16.08.11 0:25
\r
35 public class ToolsRegistry {
\r
36 private static final Logger LOG = Logger.getInstance(ToolsRegistry.class.getName());
\r
38 private final ToolPaths myPaths;
\r
39 private final PluginNaming myNaming;
\r
40 private final ToolsWatcher myWatcher;
\r
42 public ToolsRegistry(@NotNull final ToolPaths paths,
\r
43 @NotNull final PluginNaming naming,
\r
44 @NotNull final ToolsWatcher watcher) {
\r
47 myWatcher = watcher;
\r
51 public Collection<? extends NuGetInstalledTool> getTools() {
\r
52 return getToolsInternal();
\r
55 private Collection<InstalledTool> getToolsInternal() {
\r
56 final File[] tools = myPaths.getPackages().listFiles(IS_PACKAGE);
\r
57 if (tools == null) return Collections.emptyList();
\r
59 final Collection<InstalledTool> result = new ArrayList<InstalledTool>();
\r
60 for (final File path : tools) {
\r
61 final InstalledTool e = new InstalledTool(myNaming, path);
\r
62 if (!e.getPath().isFile()) {
\r
63 LOG.warn("NuGet.exe is not found at " + e);
\r
67 if (!e.getAgentPluginFile().isFile()) {
\r
68 LOG.warn("NuGet tool is not packed for agent. " + e);
\r
76 public void removeTool(@NotNull final String toolId) {
\r
77 for (InstalledTool tool : getToolsInternal()) {
\r
78 if (tool.getId().equals(toolId)) {
\r
79 LOG.info("Removing NuGet plugin: " + tool);
\r
83 myWatcher.checkNow();
\r
86 private static class InstalledTool implements NuGetInstalledTool {
\r
87 private final PluginNaming myNaming;
\r
88 private final File myPath;
\r
90 public InstalledTool(PluginNaming naming, @NotNull final File path) {
\r
96 public File getPath() {
\r
97 return FileUtil.getCanonicalFile(new File(myNaming.getUnpackedFolder(myPath), PackagesConstants.NUGET_TOOL_REL_PATH));
\r
101 public File getAgentPluginFile() {
\r
102 return FileUtil.getCanonicalFile(myNaming.getAgentFile(myPath));
\r
105 public void delete() {
\r
106 FileUtil.delete(myPath);
\r
110 public String getId() {
\r
111 return getVersion();
\r
115 public String getVersion() {
\r
116 return myNaming.getVersion(myPath);
\r
120 public String toString() {
\r
121 return "InstalledTool{version=" + getVersion() +
\r
122 ", myPath=" + myPath +
\r
127 private final FileFilter IS_PACKAGE = new FileFilter() {
\r
128 public boolean accept(File pathname) {
\r
129 return pathname.isFile() && pathname.getName().endsWith(".nupkg");
\r