/**
 * Copyright (C) 2016 WhiteSource Ltd.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.whitesource.docker;


import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * This class contains all supported file extensions and creates regex and GLOB patterns for the directory scanner.
 *
 * @author tom.shapira
 */
public class ExtensionUtils {

    /* --- Static members --- */

    public static final String REGEX_PATTERN_PREFIX = ".*\\.";
    public static final String REGEX_OR = "|";
    public static final String GLOB_PATTERN_PREFIX = "**/*.";

    public static final List<String> SOURCE_EXTENSIONS = Arrays.asList("js", "php");
    public static final List<String> BINARY_EXTENSIONS = Arrays.asList("jar", "egg", "tar.gz", "tgz", "zip", "whl", "gem",
            "apk", "air", "dmg", "exe", "gem", "gzip", "msi", "nupkg", "swc", "swf", "tar.bz2", "pkg.tar.xz", "(u)?deb", "(a)?rpm");
    public static final List<String> ARCHIVE_EXTENSIONS = Arrays.asList("war", "ear", "zip", "whl", "tar.gz", "tgz", "tar");

    public static final String SOURCE_FILE_PATTERN;
    public static final String BINARY_FILE_PATTERN;
    public static final String ARCHIVE_FILE_PATTERN;
    public static final String[] INCLUDES;
    public static final String[] EXCLUDES = new String[] { "**/*sources.jar", "**/*javadoc.jar", "**/tests/**" };
    public static final String[] ARCHIVE_INCLUDES;
    public static final String[] ARCHIVE_EXCLUDES = new String[] { "**/*sources.jar", "**/*javadoc.jar", "**/tests/**" };

    static {
        SOURCE_FILE_PATTERN = initializeRegexPattern(SOURCE_EXTENSIONS);
        BINARY_FILE_PATTERN = initializeRegexPattern(BINARY_EXTENSIONS);
        ARCHIVE_FILE_PATTERN = initializeRegexPattern(ARCHIVE_EXTENSIONS);

        List<String> allExtensions = new ArrayList<>();
        allExtensions.addAll(SOURCE_EXTENSIONS);
        allExtensions.addAll(BINARY_EXTENSIONS);
        INCLUDES = initializeGlobPattern(allExtensions);
        ARCHIVE_INCLUDES = initializeGlobPattern(ARCHIVE_EXTENSIONS);
    }

    private static String initializeRegexPattern(List<String> extensions) {
        StringBuilder sb = new StringBuilder();
        for (String extension : extensions) {
            sb.append(REGEX_PATTERN_PREFIX);
            sb.append(extension);
            sb.append(REGEX_OR);
        }

        return sb.toString().substring(0, sb.toString().lastIndexOf(REGEX_OR));
    }

    private static String[] initializeGlobPattern(List<String> extensions) {
        String[] globPatterns = new String[extensions.size()];
        for (int i = 0; i < extensions.size(); i++) {
            globPatterns[i] = GLOB_PATTERN_PREFIX + extensions.get(i);
        }
        return globPatterns;
    }
}

@@ -1168,21 +1168,598 @@
 ist(
-%22js%22, %22php%22);
+%0A            %22c%22, %22cc%22, %22cp%22, %22cpp%22, %22cxx%22, %22c%5C%5C+%5C%5C+%22, %22h%22, %22hh%22, %22hpp%22, %22hxx%22, %22h%5C%5C+%5C%5C+%22, %22m%22, %22mm%22,  %22pch%22, // C and C++%0A            %22c#%22, %22cs%22, %22csharp%22,  // C#%0A            %22go%22, %22goc%22,  // GO%0A            %22js%22, // JavaScript%0A            %22pl%22, %22plx%22, %22pm%22, %22ph%22, %22cgi%22, %22fcgi%22, %22pod%22, %22psgi%22, %22al%22, %22perl%22, %22t%22, // PERL%0A            %22pl6%22, %22p6m%22, %22p6l%22, %22pm6%22, %22nqp%22, %226pl%22, %226pm%22, %22p6%22, // PERL6%0A            %22php%22, // PHP%0A            %22py%22, // Python%0A            %22rb%22, // Ruby%0A            %22swift%22, // Swift%0A            %22java%22, // Java%0A            %22clj%22, %22cljx%22, %22cljs%22, %22cljc%22); // Clojure
 %0A   

Add source file extensions to docker agent (in addition to php and js) WSA-477