diff --git a/enterprise-update-test/src/main/java/org/alfresco/update/tool/dircomp/FileTreeCompareImpl.java b/enterprise-update-test/src/main/java/org/alfresco/update/tool/dircomp/FileTreeCompareImpl.java index d82a7b0a24..df0f1ba45b 100644 --- a/enterprise-update-test/src/main/java/org/alfresco/update/tool/dircomp/FileTreeCompareImpl.java +++ b/enterprise-update-test/src/main/java/org/alfresco/update/tool/dircomp/FileTreeCompareImpl.java @@ -41,16 +41,44 @@ public class FileTreeCompareImpl implements FileTreeCompare public FileTreeCompareImpl() { - this(new HashSet(), new HashSet()); + this(null, null); } - public FileTreeCompareImpl(Set ignorePaths, Set allowedDiffsPath) + public FileTreeCompareImpl(Set ignorePaths, Set allowedDiffsPaths) { // This config MUST be present before any TFile objects etc. are created. TConfig config = TConfig.get(); config.setArchiveDetector(new TArchiveDetector("war|jar|amp", new ZipDriver(IOPoolLocator.SINGLETON))); + if (ignorePaths == null) + { + // Add default ignores + ignorePaths = new HashSet<>(); + ignorePaths.add("alf_data/postgresql/**"); + ignorePaths.add("META-INF/MANIFEST.MF"); + ignorePaths.add("META-INF/maven/**"); + ignorePaths.add("README.txt"); + ignorePaths.add("uninstall.app/**"); + } + if (allowedDiffsPaths == null) + { + // Add default paths where certain differences are allowed, e.g. absolute path references. + allowedDiffsPaths = new HashSet<>(); + allowedDiffsPaths.add("common/bin/**"); + allowedDiffsPaths.add("common/include/**/*.h"); + allowedDiffsPaths.add("common/lib/**/*.pc"); + allowedDiffsPaths.add("common/lib/**/*.la"); + allowedDiffsPaths.add("libreoffice.app/Contents/Resources/bootstraprc"); + allowedDiffsPaths.add("postgresql/bin/**"); + allowedDiffsPaths.add("**/*.sh"); + allowedDiffsPaths.add("**/*.bat"); + allowedDiffsPaths.add("**/*.ini"); + allowedDiffsPaths.add("**/*.properties"); + allowedDiffsPaths.add("**/*.xml"); + allowedDiffsPaths.add("**/*.sample"); + allowedDiffsPaths.add("**/*.txt"); + } this.ignorePaths.addAll(ignorePaths); - this.allowedDiffsPaths.addAll(allowedDiffsPath); + this.allowedDiffsPaths.addAll(allowedDiffsPaths); } @Override diff --git a/enterprise-update-test/src/test/java/EndToEndIntegrationTest.java b/enterprise-update-test/src/test/java/EndToEndIntegrationTest.java index 9694d09c10..e19bcb75a6 100644 --- a/enterprise-update-test/src/test/java/EndToEndIntegrationTest.java +++ b/enterprise-update-test/src/test/java/EndToEndIntegrationTest.java @@ -6,20 +6,24 @@ * agreement is prohibited. */ -import static org.junit.Assert.*; - -import java.io.BufferedReader; -import java.io.BufferedWriter; -import java.io.File; -import java.io.IOException; -import java.io.InputStreamReader; -import java.io.OutputStream; -import java.io.OutputStreamWriter; -import java.util.ArrayList; - +import org.alfresco.update.tool.dircomp.FileTreeCompare; +import org.alfresco.update.tool.dircomp.FileTreeCompareImpl; +import org.alfresco.update.tool.dircomp.HtmlResultFormatter; +import org.alfresco.update.tool.dircomp.ResultSet; import org.junit.Before; +import org.junit.Ignore; import org.junit.Test; +import java.io.*; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.Set; + +import static org.junit.Assert.assertTrue; + public class EndToEndIntegrationTest { private final static String JAR_FILE_NAME = "alfresco-update-tool.jar"; @@ -132,14 +136,47 @@ public class EndToEndIntegrationTest /** * Run the diff tool * - * @param src - * @param dest + * @param path1 + * @param path2 */ - public void compare(File src, File dest) + public void compare(File path1, File path2) throws IOException { - //assertTrue("test not implemented", false); + FileTreeCompare comparator = new FileTreeCompareImpl(); + ResultSet resultSet = comparator.compare(path1.toPath(), path2.toPath()); + + File dircompDir = new File(targetDir, "installation-diff"); + dircompDir.mkdirs(); + + // Format the results as an HTML report. + File file = new File(dircompDir, "installation-diff-report.html"); + file.createNewFile(); + + HtmlResultFormatter formatter = new HtmlResultFormatter(); + formatter.setDifferencesOnly(true); + try(FileOutputStream fos = new FileOutputStream(file); + BufferedOutputStream bos = new BufferedOutputStream(fos)) + { + formatter.format(resultSet, bos); + } } - + + /** + * Utility/harness to allow easy testing of {@link #compare(File, File)}. + *

+ * Uncomment @Ignore, but do not check in. + * + * @throws IOException + */ + @Ignore + @Test + public void bigDiff() throws IOException + { + Path path1 = Paths.get("/Users/MWard/dev2/alf-installs/alf-5.1-b667"); + Path path2 = Paths.get("/Users/MWard/dev2/alf-installs/alf-5.1-b669"); + + compare(path1.toFile(), path2.toFile()); + } + /* * Method to execute a command * diff --git a/enterprise-update-test/src/test/java/org/alfresco/update/tool/dircomp/HtmlResultFormatterTest.java b/enterprise-update-test/src/test/java/org/alfresco/update/tool/dircomp/HtmlResultFormatterTest.java index 85d1f3ddf9..6ba39f8c6b 100644 --- a/enterprise-update-test/src/test/java/org/alfresco/update/tool/dircomp/HtmlResultFormatterTest.java +++ b/enterprise-update-test/src/test/java/org/alfresco/update/tool/dircomp/HtmlResultFormatterTest.java @@ -68,51 +68,6 @@ public class HtmlResultFormatterTest // System.out.println("File: "+file); } } - - @Ignore - @Test - public void bigDiff() throws IOException - { - Path path1 = Paths.get("/Users/MWard/dev2/alf-installs/alf-5.1-b667"); - Path path2 = Paths.get("/Users/MWard/dev2/alf-installs/alf-5.1-b669"); - - Set ignores = new HashSet<>(); - ignores.add("alf_data/postgresql/**"); - ignores.add("META-INF/MANIFEST.MF"); - ignores.add("META-INF/maven/**"); - ignores.add("README.txt"); - ignores.add("uninstall.app/**"); - - // All the patterns will be applied to these files, e.g. they will all have differences - // in absolute path references ignored. - Set ignoreSpecialDifferences = new HashSet<>(); - ignoreSpecialDifferences.add("common/bin/**"); - ignoreSpecialDifferences.add("common/include/**/*.h"); - ignoreSpecialDifferences.add("common/lib/**/*.pc"); - ignoreSpecialDifferences.add("common/lib/**/*.la"); - ignoreSpecialDifferences.add("libreoffice.app/Contents/Resources/bootstraprc"); - ignoreSpecialDifferences.add("postgresql/bin/**"); - ignoreSpecialDifferences.add("**/*.sh"); - ignoreSpecialDifferences.add("**/*.bat"); - ignoreSpecialDifferences.add("**/*.ini"); - ignoreSpecialDifferences.add("**/*.properties"); - ignoreSpecialDifferences.add("**/*.xml"); - ignoreSpecialDifferences.add("**/*.sample"); - ignoreSpecialDifferences.add("**/*.txt"); - - FileTreeCompare comparator = new FileTreeCompareImpl(ignores, ignoreSpecialDifferences); - ResultSet resultSet = comparator.compare(path1, path2); - - Path file = Files.createTempFile(getClass().getSimpleName(), ".html"); - HtmlResultFormatter formatter = new HtmlResultFormatter(); - formatter.setDifferencesOnly(true); - try(FileOutputStream fos = new FileOutputStream(file.toFile()); - BufferedOutputStream bos = new BufferedOutputStream(fos)) - { - formatter.format(resultSet, bos); - } - System.out.println("File: "+file); - } private void addResult(List results, String p1, String p2, boolean contentMatch) {