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.agent.runner.publish;
\r
19 import com.intellij.openapi.diagnostic.Logger;
\r
20 import com.intellij.openapi.util.SystemInfo;
\r
21 import jetbrains.buildServer.RunBuildException;
\r
22 import jetbrains.buildServer.agent.BuildFinishedStatus;
\r
23 import jetbrains.buildServer.agent.BuildRunnerContext;
\r
24 import jetbrains.buildServer.agent.util.AntPatternFileFinder;
\r
25 import jetbrains.buildServer.nuget.agent.parameters.NuGetPublishParameters;
\r
26 import jetbrains.buildServer.nuget.agent.util.BuildProcessBase;
\r
27 import jetbrains.buildServer.util.StringUtil;
\r
28 import org.jetbrains.annotations.NotNull;
\r
30 import java.io.File;
\r
31 import java.io.IOException;
\r
32 import java.util.ArrayList;
\r
33 import java.util.List;
\r
36 * Created by Eugene Petrenko (eugene.petrenko@gmail.com)
\r
37 * Date: 21.07.11 20:02
\r
39 public class MatchFilesBuildProcess extends BuildProcessBase {
\r
40 private static final Logger LOG = Logger.getInstance(MatchFilesBuildProcess.class.getName());
\r
42 private final BuildRunnerContext myContext;
\r
43 private final NuGetPublishParameters myParameters;
\r
44 private final Callback myCallback;
\r
46 public MatchFilesBuildProcess(@NotNull final BuildRunnerContext context,
\r
47 @NotNull final NuGetPublishParameters parameters,
\r
48 @NotNull final Callback callback) {
\r
49 myContext = context;
\r
50 myParameters = parameters;
\r
51 myCallback = callback;
\r
56 protected BuildFinishedStatus waitForImpl() throws RunBuildException {
\r
58 boolean found = false;
\r
60 final List<String> patterns = new ArrayList<String>();
\r
61 for (String _pattern : myParameters.getFiles()) {
\r
62 String pattern = _pattern.trim();
\r
63 if (StringUtil.isEmptyOrSpaces(pattern)) {
\r
67 if (SystemInfo.isWindows
\r
68 && (pattern.startsWith("/") || pattern.startsWith("\\"))
\r
69 && !(pattern.startsWith("//") || pattern.startsWith("\\\\"))) {
\r
70 pattern = pattern.substring(1);
\r
73 if (!pattern.contains("*") && !pattern.contains("?")) {
\r
74 final File file = new File(pattern);
\r
75 if (file.isAbsolute()) {
\r
77 LOG.debug("Found .nugkg to push: " + file);
\r
78 myCallback.fileFound(file);
\r
83 patterns.add(pattern.replace('\\', '/'));
\r
86 final String[] includes = patterns.toArray(new String[patterns.size()]);
\r
87 AntPatternFileFinder finder = new AntPatternFileFinder(
\r
90 SystemInfo.isFileSystemCaseSensitive
\r
93 final File root = myContext.getBuild().getCheckoutDirectory();
\r
95 final File[] result = finder.findFiles(root);
\r
97 for (File file : result) {
\r
98 LOG.debug("Found nugkg to push: " + file);
\r
100 myCallback.fileFound(file);
\r
102 } catch (IOException e) {
\r
103 throw new RunBuildException("Failed to find packages to publish. " + e.getMessage(), e);
\r
107 throw new RunBuildException("Failed to find files to publish matching: " + new ArrayList<String>(myParameters.getFiles()) + " under " + root + ". No packages to publish. ");
\r
110 return BuildFinishedStatus.FINISHED_SUCCESS;
\r
113 public static interface Callback {
\r
114 void fileFound(@NotNull final File file) throws RunBuildException;
\r