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.List;
\r
31 * Created by Eugene Petrenko (eugene.petrenko@gmail.com)
\r
32 * Date: 11.08.11 1:07
\r
34 public class NuGetToolManagerImpl implements NuGetToolManager {
\r
35 private static final Logger LOG = Logger.getInstance(NuGetToolManagerImpl.class.getName());
\r
37 private final AvailableToolsState myAvailables;
\r
38 private final NuGetToolsInstaller myInstaller;
\r
39 private final ToolsRegistry myInstalled;
\r
41 public NuGetToolManagerImpl(@NotNull final AvailableToolsState availables,
\r
42 @NotNull final NuGetToolsInstaller installer,
\r
43 @NotNull final ToolsRegistry installed) {
\r
44 myAvailables = availables;
\r
45 myInstaller = installer;
\r
46 myInstalled = installed;
\r
50 public Collection<? extends NuGetInstalledTool> getInstalledTools() {
\r
51 return myInstalled.getTools();
\r
55 public Collection<NuGetInstallingTool> getInstallingTool() {
\r
56 return mockInstallingTools();
\r
60 public Collection<? extends NuGetTool> getAvailableTools(@NotNull ToolsPolicy policy) throws FetchException {
\r
61 //This must be cached to make if work faster!
\r
62 return myAvailables.getAvailable(policy);
\r
65 public void installTool(@NotNull String toolId) {
\r
66 myInstaller.installNuGet(
\r
68 (InstallLogger) Proxy.newProxyInstance(getClass().getClassLoader(),
\r
69 new Class<?>[]{InstallLogger.class},
\r
70 new InvocationHandler() {
\r
71 public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
\r
72 StringBuilder sb = new StringBuilder();
\r
73 sb.append(method.getName());
\r
74 for (Object arg : args) {
\r
75 sb.append(" ").append(arg);
\r
77 LOG.debug(sb.toString());
\r
83 public void removeTool(@NotNull String toolId) {
\r
84 myInstalled.removeTool(toolId);
\r
87 private List<NuGetInstallingTool> mockInstallingTools() {
\r
88 return Arrays.<NuGetInstallingTool>asList(
\r
89 new NuGetInstallingTool() {
\r
91 public Collection<String> getInstallMessages() {
\r
92 return Arrays.asList("mgs1", "msg2", "msg3");
\r
96 public String getId() {
\r
101 public String getVersion() {
\r
102 return "ii.1.2.43";
\r