Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright 1&1 Internet AG, https://github.com/1and1/ 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 net.oneandone.jasmin.main;
 
 
 import java.io.Writer;
 import java.util.List;
 import java.util.Map;
 
 public class FileCheck {
     private static final Logger LOG = Logger.getLogger(FileCheck.class);
 
     public static void main(String[] argsthrows IOException {
         World world;
         FileCheck check;
 
         // usually called via wsd-app parent pom - without log4j config in place ...
         ConsoleAppender ca = new ConsoleAppender();
         ca.setWriter(new OutputStreamWriter(.));
         ca.setLayout(new PatternLayout("%-5p [%t]: %m%n"));
         Logger.getRootLogger().setLevel(.);
         Logger.getRootLogger().addAppender(ca);
 
         world = new World();
         if (args.length > 0) {
             world.setWorking(world.file(args[0]));
         }
         check = new FileCheck();
         check.minimizeApplication(getWepappDir((FileNodeworld.getWorking().join("target")));
         ..println("file-check: " + check.size() + " files ...");
         check = check.exceptions();
         if (check.size() > 0) {
             ..println("failed with "  + check.size() + " errors:");
             ..println(check.toString());
             System.exit(1);
         } else {
             ..println("ok");
         }
     }
 
     private static FileNode getWepappDir(FileNode basethrows IOException {
         for (FileNode dir : base.list()) {
             if (dir.join("WEB-INF").isDirectory()) {
                 return dir;
             }
         }
         throw new IOException("no webapp dir in " + base);
     }
 
     private final Map<NodeList<Exception>> map;
 
     public FileCheck() {
         this(new HashMap<NodeList<Exception>>());
     }
 
     public FileCheck(Map<NodeList<Exception>> map) {
         this. = map;
     }
 
     public FileCheck exceptions() {
         Map<NodeList<Exception>> result;
 
         result = new HashMap<NodeList<Exception>>();
         for (Map.Entry<NodeList<Exception>> entry : .entrySet()) {
             if (entry.getValue().size() > 0) {
                 result.put(entry.getKey(), entry.getValue());
             }
         }
         return new FileCheck(result);
    }
    @Override
    public String toString() {
        StringBuilder result;
        result = new StringBuilder();
        for (Map.Entry<NodeList<Exception>> entry : .entrySet()) {
            result.append(entry.getKey().getURI()).append('\n');
            for (Exception e : entry.getValue()) {
                result.append("  ").append(e.getMessage()).append('\n');
            }
        }
        return result.toString();
    }
    public void add(Node node) {
        if (!.containsKey(node)) {
            .put(nodenew ArrayList<Exception>());
        }
    }
    public void add(Node nodeException e) {
        .get(node).add(e);
    }
    //--
    public void minimizeClasspath() throws IOException {
        World world;
        Resolver resolver;
        world = new World();
        resolver = new Resolver(world);
        minimize(false, Repository.load(resolver), world);
    }
    public void minimizeApplication(FileNode applicationthrows IOException {
        World world;
        Repository repository;
        Node descriptor;
        Resolver resolver;
        world = new World();
        resolver = new Resolver(world);
        resolver.add(.application);
        resolver.add(.world.validNode("http://nosuchhost"));
        repository = new Repository();
        repository.loadClasspath(resolver);
        descriptor = application.join("conf/jasmin.xml");
        if (!descriptor.exists()) {
            descriptor = application.join("WEB-INF/jasmin.xml");
            if (!descriptor.exists()) {
                descriptor = null;
            }
        }
        if (descriptor != null) {
            repository.loadApplication(resolverapplicationdescriptor);
        }
        repository.link();
        minimize(falserepositoryapplication.getWorld());
    }
    public void minimize(boolean httpRepository repositoryWorld worldthrows IOException {
        Node src;
        Node dest;
        long started;
        for (Module module : repository.modules()) {
            for (File file : module.files()) {
                src = file.getNormal();
                if (http || !"http".equals(src.getRoot().getFilesystem().getScheme())) {
                    add(src);
                    try {
                        dest = world.getTemp().createTempFile();
                        .info("fileCheck module=" + module.getName() + ", file=" + src);
                        started = System.currentTimeMillis();
                        try (Writer writer = dest.createWriter()) {
                            References.create(file.getType(), truesrc).writeTo(writer);
                        }
                        .info("done, " + (System.currentTimeMillis() - started) + " ms");
                        dest.deleteFile();
                    } catch (Exception e) {
                        add(srce);
                    }
                }
            }
        }
    }
    public int size() {
        return .size();
    }
New to GrepCode? Check out our FAQ X