/*
 * Copyright 2016 ZJNU ACM.
 *
 * 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 a;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 *
 * @author zhanhb
 */
public class ExtensionsViewer {

    /**
     * @param args the command line arguments
     * @throws java.io.IOException
     */
    @SuppressWarnings("UseOfSystemOutOrSystemErr")
    public static void main(String[] args) throws IOException {
        Path path = Paths.get(".");
        Map<String, List<Path>> map = Files.walk(path).filter(p -> p.getNameCount() == 1 || !p.getName(1).toString()
                .matches("target|\\.(?:git|idea|svn|settings)"))
                .filter(Files::isRegularFile)
                .filter(pp -> !getExtension(pp).isEmpty())
                .collect(Collectors.groupingBy(ExtensionsViewer::getExtension));
        map.keySet().removeIf(Files.lines(path.resolve(".gitattributes"))
                .map(String::trim)
                .filter(str -> str.startsWith("*."))
                .map(str -> str.replaceAll("\\*\\.|\\s.+", ""))
                .collect(Collectors.toSet())::contains);
        System.out.println(map);
    }

    private static String getExtension(Path path) {
        String name = path.getFileName().toString();
        return name.lastIndexOf('.') > 0 ? name.substring(name.lastIndexOf('.') + 1) : "";
    }

}

@@ -606,35 +606,249 @@
 %0Aimport 
-java.io.IOException
+com.google.common.collect.Lists;%0Aimport com.google.common.collect.Maps;%0Aimport java.io.BufferedReader;%0Aimport java.io.IOException;%0Aimport java.io.InputStream;%0Aimport java.io.InputStreamReader;%0Aimport java.nio.charset.StandardCharsets
 ;%0Aimport
@@ -1293,310 +1293,893 @@
    P
-ath path = Paths.get(%22.%22);%0A        Map%3CString, List%3CPath%3E%3E map = Files.walk(path).filter(p -%3E p.getNameCount() == 1 %7C%7C !p.getName(1).toString()%0A                .matches(%22target%7C%5C%5C.(?:git%7Cidea%7Csvn%7Csettings)%22))%0A                .filter(Files::isRegularFile)%0A                .filter(pp -%3E !getExtension(pp)
+rocess process = new ProcessBuilder()%0A                .command(%22git%22, %22ls-files%22, %22-z%22, %22--%22, %22:(glob,top,exclude).gitattributes%22)%0A                .redirectErrorStream(true).start();%0A        Map%3CString, List%3CPath%3E%3E map = Maps.newLinkedHashMap();%0A        try (InputStream is = process.getInputStream();%0A                InputStreamReader ir = new InputStreamReader(is, StandardCharsets.UTF_8);%0A                BufferedReader br = new BufferedReader(ir)) %7B%0A            for (StringBuilder sb = new StringBuilder(20);;) %7B%0A                int x = br.read();%0A                if (x == -1) %7B%0A                    break;%0A                %7D%0A                if (x != 0) %7B%0A                    sb.append((char) x);%0A                    continue;%0A                %7D%0A                Path path = Paths.get(sb.toString());%0A                String extension = getExtension(path);%0A                if (extension
 .isE
@@ -2185,17 +2185,22 @@
 Empty())
-%0A
+ %7B%0A   
         
@@ -2211,72 +2211,179 @@
     
-.collect(Collectors.groupingBy(ExtensionsViewer::getExtension));
+ continue;%0A                %7D%0A                map.computeIfAbsent(extension, __ -%3E Lists.newArrayList()).add(path);%0A                sb.setLength(0);%0A            %7D%0A        %7D
 %0A   
@@ -2425,20 +2425,17 @@
 nes(
-path.resolve
+Paths.get
 (%22.g
@@ -2816,14 +2816,25 @@
     
-return
+int lastIndexOf =
  nam
@@ -2851,16 +2851,44 @@
 xOf('.')
+;%0A        return lastIndexOf
  %3E 0 ? n
@@ -2901,21 +2901,16 @@
 bstring(
-name.
 lastInde
@@ -2912,21 +2912,16 @@
 tIndexOf
-('.')
  + 1) : 

Resolve gitignore