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.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 org.jetbrains.annotations.NotNull;
\r
29 import java.io.File;
\r
30 import java.io.IOException;
\r
31 import java.util.Collection;
\r
34 * Created by Eugene Petrenko (eugene.petrenko@gmail.com)
\r
35 * Date: 21.07.11 20:02
\r
37 public class MatchFilesBuildProcess extends BuildProcessBase {
\r
38 private static final Logger LOG = Logger.getInstance(MatchFilesBuildProcess.class.getName());
\r
40 private final BuildRunnerContext myContext;
\r
41 private final NuGetPublishParameters myParameters;
\r
42 private final Callback myCallback;
\r
44 public MatchFilesBuildProcess(@NotNull final BuildRunnerContext context,
\r
45 @NotNull final NuGetPublishParameters parameters,
\r
46 @NotNull final Callback callback) {
\r
47 myContext = context;
\r
48 myParameters = parameters;
\r
49 myCallback = callback;
\r
54 protected BuildFinishedStatus waitForImpl() throws RunBuildException {
\r
55 final Collection<String> files = myParameters.getFiles();
\r
56 final String[] includes = files.toArray(new String[files.size()]);
\r
57 AntPatternFileFinder finder = new AntPatternFileFinder(
\r
60 SystemInfo.isFileSystemCaseSensitive
\r
64 final File root = myContext.getBuild().getCheckoutDirectory();
\r
65 final File[] result = finder.findFiles(root);
\r
66 if (result.length == 0) {
\r
67 throw new RunBuildException("Failed to find files to publish matching: " + files + " under " + root + ". No packages to publish. ");
\r
70 for (File file : result) {
\r
71 LOG.debug("Found nugkg to push: " + file);
\r
72 myCallback.fileFound(file);
\r
74 } catch (IOException e) {
\r
75 throw new RunBuildException("Failed to find packages to publish. " + e.getMessage(), e);
\r
78 return BuildFinishedStatus.FINISHED_SUCCESS;
\r
81 public static interface Callback {
\r
82 void fileFound(@NotNull final File file) throws RunBuildException;
\r