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.server.toolRegistry.*;
\r
21 import org.jetbrains.annotations.NotNull;
\r
23 import java.lang.reflect.InvocationHandler;
\r
24 import java.lang.reflect.Method;
\r
25 import java.lang.reflect.Proxy;
\r
26 import java.util.Arrays;
\r
27 import java.util.Collection;
\r
28 import java.util.Collections;
\r
29 import java.util.List;
\r
32 * Created by Eugene Petrenko (eugene.petrenko@gmail.com)
\r
33 * Date: 11.08.11 1:07
\r
35 public class NuGetToolManagerImpl implements NuGetToolManager {
\r
36 private static final Logger LOG = Logger.getInstance(NuGetToolManagerImpl.class.getName());
\r
38 private final AvailableToolsState myAvailables;
\r
39 private final NuGetToolsInstaller myInstaller;
\r
40 private final ToolsRegistry myInstalled;
\r
42 public NuGetToolManagerImpl(@NotNull final AvailableToolsState availables,
\r
43 @NotNull final NuGetToolsInstaller installer,
\r
44 @NotNull final ToolsRegistry installed) {
\r
45 myAvailables = availables;
\r
46 myInstaller = installer;
\r
47 myInstalled = installed;
\r
51 public Collection<? extends NuGetInstalledTool> getInstalledTools() {
\r
52 return myInstalled.getTools();
\r
56 public Collection<NuGetInstallingTool> getInstallingTool() {
\r
57 return Collections.emptyList();
\r
61 public Collection<? extends NuGetTool> getAvailableTools(@NotNull ToolsPolicy policy) throws FetchException {
\r
62 //This must be cached to make if work faster!
\r
63 return myAvailables.getAvailable(policy);
\r
66 public void installTool(@NotNull String toolId) {
\r
67 myInstaller.installNuGet(
\r
69 (InstallLogger) Proxy.newProxyInstance(getClass().getClassLoader(),
\r
70 new Class<?>[]{InstallLogger.class},
\r
71 new InvocationHandler() {
\r
72 public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
\r
73 StringBuilder sb = new StringBuilder();
\r
74 sb.append(method.getName());
\r
75 for (Object arg : args) {
\r
76 sb.append(" ").append(arg);
\r
78 LOG.debug(sb.toString());
\r
84 public void removeTool(@NotNull String toolId) {
\r
85 myInstalled.removeTool(toolId);
\r