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.exec;
\r
19 import com.intellij.openapi.diagnostic.Logger;
\r
20 import jetbrains.buildServer.messages.serviceMessages.ServiceMessage;
\r
21 import jetbrains.buildServer.messages.serviceMessages.ServiceMessageParserCallback;
\r
22 import jetbrains.buildServer.util.StringUtil;
\r
23 import org.jetbrains.annotations.NotNull;
\r
25 import java.text.ParseException;
\r
26 import java.util.ArrayList;
\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: 14.07.11 13:23
\r
35 public class ListPackagesCommandProcessor implements NuGetOutputProcessor<Collection<PackageInfo>> {
\r
36 private static final Logger LOG = Logger.getInstance(ListPackagesCommandProcessor.class.getName());
\r
37 private final String mySource;
\r
38 private final List<PackageInfo> myPackages = new ArrayList<PackageInfo>();
\r
40 public ListPackagesCommandProcessor(@NotNull final String source) {
\r
44 public void onStdOutput(String text) {
\r
45 if (LOG.isDebugEnabled()) {
\r
49 ServiceMessage.parse(text, new ServiceMessageParserCallback() {
\r
50 public void regularText(@NotNull String s) {
\r
53 public void serviceMessage(@NotNull ServiceMessage serviceMessage) {
\r
54 if (!"nuget-package".equals(serviceMessage.getMessageName())) return;
\r
55 final String id = serviceMessage.getAttributes().get("Id");
\r
56 final String version = serviceMessage.getAttributes().get("Version");
\r
58 if (StringUtil.isEmptyOrSpaces(id)) return;
\r
59 if (StringUtil.isEmptyOrSpaces(version)) return;
\r
61 myPackages.add(new PackageInfo(mySource, id, version));
\r
65 public void parseException(@NotNull ParseException e, @NotNull String s) {
\r
70 public void onStdError(String text) {
\r
74 public void onFinished(int exitCode) {
\r
75 if (LOG.isDebugEnabled()) {
\r
76 LOG.debug("NuGet TeamCity.List command exited with " + exitCode);
\r
78 if (exitCode != 0) {
\r
79 throw new RuntimeException("Failed to execute TeamCity.List command. Exit code was " + exitCode);
\r
84 public Collection<PackageInfo> getResult() {
\r
85 return Collections.unmodifiableList(myPackages);
\r