protected SnapshotComparisonPageResponse compareSnapshots(SnapshotComparisonPageRequest request) { SnapshotComparisonPageResponse response = new SnapshotComparisonPageResponse(); // Do query (bit of a cheat really!) long start = System.currentTimeMillis(); SnapshotDiffs diffs = compareSnapshots( request.getPackageName(), request.getFirstSnapshotName(), request.getSecondSnapshotName()); log.debug("Search time: " + (System.currentTimeMillis() - start)); // Populate response response.setLeftSnapshotName(diffs.leftName); response.setRightSnapshotName(diffs.rightName); List<SnapshotComparisonPageRow> rowList = new SnapshotComparisonPageRowBuilder() .withPageRequest(request) .withIdentity(identity) .withContent(diffs) .build(); response.setPageRowList(rowList); response.setStartRowIndex(request.getStartRowIndex()); response.setTotalRowSize(diffs.diffs.length); response.setTotalRowSizeExact(true); response.setLastPage((request.getStartRowIndex() + rowList.size() == diffs.diffs.length)); long methodDuration = System.currentTimeMillis() - start; log.debug( "Compared Snapshots ('" + request.getFirstSnapshotName() + "') and ('" + request.getSecondSnapshotName() + "') in package ('" + request.getPackageName() + "') in " + methodDuration + " ms."); return response; }
/** * Add the directories matched by the nested dirsets to the resulting packages list and the base * directories of the dirsets to the Path. It also handles the packages and excludepackages * attributes and elements. * * @param resultantPackages a list to which we add the packages found * @param sourcePath a path to which we add each basedir found * @since 1.5 */ private void parsePackages(List<String> resultantPackages, Path sourcePath) { List<String> addedPackages = new ArrayList<String>(); List<DirSet> dirSets = new ArrayList<DirSet>(packageSets); // for each sourcePath entry, add a directoryset with includes // taken from packagenames attribute and nested package // elements and excludes taken from excludepackages attribute // and nested excludepackage elements if (this.sourcePath != null) { PatternSet ps = new PatternSet(); if (packageNames.size() > 0) { for (String pn : packageNames) { String pkg = pn.replace('.', '/'); if (pkg.endsWith("*")) { pkg += "*"; } ps.createInclude().setName(pkg); } } else { ps.createInclude().setName("**"); } for (String epn : excludePackageNames) { String pkg = epn.replace('.', '/'); if (pkg.endsWith("*")) { pkg += "*"; } ps.createExclude().setName(pkg); } String[] pathElements = this.sourcePath.list(); for (String pathElement : pathElements) { File dir = new File(pathElement); if (dir.isDirectory()) { DirSet ds = new DirSet(); ds.setDefaultexcludes(useDefaultExcludes); ds.setDir(dir); ds.createPatternSet().addConfiguredPatternset(ps); dirSets.add(ds); } else { log.warn("Skipping " + pathElement + " since it is no directory."); } } } for (DirSet ds : dirSets) { File baseDir = ds.getDir(getProject()); log.debug("scanning " + baseDir + " for packages."); DirectoryScanner dsc = ds.getDirectoryScanner(getProject()); String[] dirs = dsc.getIncludedDirectories(); boolean containsPackages = false; for (String dir : dirs) { // are there any groovy or java files in this directory? File pd = new File(baseDir, dir); String[] files = pd.list( new FilenameFilter() { public boolean accept(File dir1, String name) { if (!includeNoSourcePackages && name.equals("package.html")) return true; final StringTokenizer tokenizer = new StringTokenizer(extensions, ":"); while (tokenizer.hasMoreTokens()) { String ext = tokenizer.nextToken(); if (name.endsWith(ext)) return true; } return false; } }); for (String filename : Arrays.asList(files)) { sourceFilesToDoc.add(dir + File.separator + filename); } if (files.length > 0) { if ("".equals(dir)) { log.warn( baseDir + " contains source files in the default package," + " you must specify them as source files not packages."); } else { containsPackages = true; String pn = dir.replace(File.separatorChar, '.'); if (!addedPackages.contains(pn)) { addedPackages.add(pn); resultantPackages.add(pn); } } } } if (containsPackages) { // We don't need to care for duplicates here, // Path.list does it for us. sourcePath.createPathElement().setLocation(baseDir); } else { log.verbose(baseDir + " doesn't contain any packages, dropping it."); } } }