package hudson.plugins.octopusdeploy.services.impl;


import hudson.FilePath;
import hudson.model.Computer;
import hudson.plugins.octopusdeploy.exception.ResourceException;
import hudson.plugins.octopusdeploy.services.FileService;
import hudson.slaves.WorkspaceList;
import org.apache.commons.lang.StringUtils;
import org.jetbrains.annotations.NotNull;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.core.io.support.ResourcePatternResolver;
import org.springframework.stereotype.Component;

import java.io.File;
import java.io.FileFilter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;

/**
 * An implementation of the file service using Spring utils
 */
@Component
public class FileServiceImpl implements FileService {
    @NotNull
    @Override
    public List<FilePath> getMatchingFile(@NotNull final FilePath workingDir, @NotNull final String pattern) {
        checkNotNull(workingDir);
        checkArgument(StringUtils.isNotBlank(pattern));
        String p = pattern;
        if (pattern.startsWith("/") || (pattern.startsWith("/") && !pattern.startsWith("//"))) {
            // leading slashes are not valid glob patterns, remove them
            p = pattern.replaceAll("^/+", "").replaceAll("^\\+", "");
        }

        List<FilePath> list;
        try {
            list = Arrays.asList(workingDir.list(p));
        } catch (final Exception ex) {
            throw new ResourceException(ex);
        }

        return list;
    }
}

@@ -661,24 +661,52 @@
 OException;%0A
+import java.nio.file.Paths;%0A
 import java.
@@ -1533,32 +1533,246 @@
 %22%22);%0A        %7D%0A%0A
+        final File absoluteFile = new File(pattern);%0A        if (absoluteFile.exists()) %7B%0A            return new ArrayList%3CFilePath%3E() %7B%7B%0A                add(new FilePath(absoluteFile));%0A            %7D%7D;%0A        %7D%0A%0A
         List%3CFil

Check if pattern is a file that exists before trying to use it on working directory