/** * Checks whether a given list of duplicates can be replaced by a single one. * @param filename the filename of the files * @param list the list of dup files * @throws DifferentLibException * @throws Sha1Exception */ private void checkEntities(String filename, List<JarEntity> list) throws DifferentLibException, Sha1Exception { if (list.size() == 1) { return; } JarEntity baseEntity = list.get(0); long baseLength = baseEntity.getLength(); String baseSha1 = baseEntity.getSha1(); final int count = list.size(); for (int i = 1; i < count ; i++) { JarEntity entity = list.get(i); if (entity.getLength() != baseLength || entity.getSha1().equals(baseSha1) == false) { throw new DifferentLibException("Jar mismatch! Fix your dependencies", getEntityDetails(filename, list)); } } }
Map<String, JarEntity> jarList = getCachedJarList(); checkEntities(entry.getKey(), list); checkSupportLibs(nameMap, results); } finally { if (updateJarList) { writeJarList(nameMap);
private String[] getEntityDetails(String filename, List<JarEntity> list) throws Sha1Exception { ArrayList<String> result = new ArrayList<String>(); result.add( String.format("Found %d versions of %s in the dependency list,", list.size(), filename)); result.add("but not all the versions are identical (check is based on SHA-1 only at this time)."); result.add("All versions of the libraries must be the same at this time."); result.add("Versions found are:"); for (JarEntity entity : list) { result.add("Path: " + entity.getFile().getAbsolutePath()); result.add("\tLength: " + entity.getLength()); result.add("\tSHA-1: " + entity.getSha1()); } return result.toArray(new String[result.size()]); }
return byteArray2Hex(md.digest());
entity.getLastModified(), entity.getLength(), entity.getSha1(), entity.getFile().getAbsolutePath()));