diff options
author | Artur Signell <artur.signell@itmill.com> | 2012-02-02 15:23:26 +0000 |
---|---|---|
committer | Artur Signell <artur.signell@itmill.com> | 2012-02-02 15:23:26 +0000 |
commit | 2b7c87b8b3e681a7fd56b32c4884559afde158fa (patch) | |
tree | fb910b41638123dc0c8e63af9082016d6777c137 /tests | |
parent | 59e55e40b222cf06454f0bb936d26a9936a37913 (diff) | |
download | vaadin-framework-2b7c87b8b3e681a7fd56b32c4884559afde158fa.tar.gz vaadin-framework-2b7c87b8b3e681a7fd56b32c4884559afde158fa.zip |
#8311 Extended test to cover non-java files
svn changeset:22862/svn branch:6.7
Diffstat (limited to 'tests')
-rw-r--r-- | tests/server-side/com/vaadin/tests/server/SourceFileChecker.java | 71 |
1 files changed, 55 insertions, 16 deletions
diff --git a/tests/server-side/com/vaadin/tests/server/SourceFileChecker.java b/tests/server-side/com/vaadin/tests/server/SourceFileChecker.java index 5d39472712..51a2301be2 100644 --- a/tests/server-side/com/vaadin/tests/server/SourceFileChecker.java +++ b/tests/server-side/com/vaadin/tests/server/SourceFileChecker.java @@ -4,6 +4,7 @@ import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.util.HashSet; +import java.util.Set; import junit.framework.Assert; import junit.framework.TestCase; @@ -23,6 +24,13 @@ public class SourceFileChecker extends TestCase { + "tests/server-side"; public static final String CLIENTSIDE_SRC_DIR = getBaseDir() + "tests/client-side"; + private String externalJavaFiles = "com/vaadin/external"; + private String buildFiles = "build"; + private Set<String> alwaysIgnore = new HashSet<String>(); + { + alwaysIgnore.add(".settings"); + alwaysIgnore.add("eclipse"); + } public static String getBaseDir() { if (baseDirectory != null) { @@ -37,7 +45,7 @@ public class SourceFileChecker extends TestCase { } } - baseDirectory = ""; + baseDirectory = "./"; return baseDirectory; } @@ -45,14 +53,31 @@ public class SourceFileChecker extends TestCase { TESTBENCH_SRC_DIR, SERVERSIDE_SRC_DIR, CLIENTSIDE_SRC_DIR }; public void testJavaFilesContainsLicense() throws IOException { - validateJavaFiles(SRC_DIR, new LicenseChecker(), - "The following files are missing license information:\n{0}"); + Set<String> ignore = new HashSet<String>(alwaysIgnore); + ignore.add(externalJavaFiles); + validateFiles(SRC_DIR, new LicenseChecker(), ignore, + "The following files are missing license information:\n{0}", + ".java"); + } + + public void testNonJavaFilesUseUnixNewline() throws IOException { + Set<String> ignore = new HashSet<String>(alwaysIgnore); + ignore.add(buildFiles); + + for (String suffix : new String[] { ".html", ".css", ".xml" }) { + validateFiles(getBaseDir(), new DosNewlineDetector(), ignore, + "The following files contain CRLF instead of LF:\n{0}", + suffix); + } } public void testJavaFilesUseUnixNewline() throws IOException { + Set<String> ignore = new HashSet<String>(alwaysIgnore); + ignore.add(externalJavaFiles); for (String dir : ALL_SRC_DIRS) { - validateJavaFiles(dir, new DosNewlineDetector(), - "The following files contain CRLF instead of LF:\n{0}"); + validateFiles(dir, new DosNewlineDetector(), ignore, + "The following files contain CRLF instead of LF:\n{0}", + ".java"); } } @@ -60,27 +85,41 @@ public class SourceFileChecker extends TestCase { void validateFile(File f) throws Exception; } - private void validateJavaFiles(String directory, FileValidator validator, - String errorMessage) { + private void validateFiles(String directory, FileValidator validator, + Set<String> ignore, String errorMessage, String ending) { File srcDir = new File(directory); System.out.println(new File(".").getAbsolutePath()); HashSet<String> missing = new HashSet<String>(); - validateFiles(srcDir, missing, validator, ".java"); + validateFiles(directory, srcDir, missing, validator, ending, ignore); if (!missing.isEmpty()) { - throw new RuntimeException(errorMessage.replace("{0}", - missing.toString())); + throw new RuntimeException(errorMessage.replace("{0}", missing + .toString().replace(',', '\n'))); } } - private void validateFiles(File srcDir, HashSet<String> missing, - FileValidator validator, String suffix) { - Assert.assertTrue("Directory " + srcDir + " does not exist", - srcDir.exists()); + private void validateFiles(String baseDirectory, File directory, + HashSet<String> missing, FileValidator validator, String suffix, + Set<String> ignores) { + Assert.assertTrue("Directory " + directory + " does not exist", + directory.exists()); + + for (File f : directory.listFiles()) { + boolean ignoreThis = false; + for (String ignore : ignores) { + if (new File(baseDirectory, ignore).equals(f)) { + ignoreThis = true; + continue; + } + } + + if (ignoreThis) { + continue; + } - for (File f : srcDir.listFiles()) { if (f.isDirectory()) { - validateFiles(f, missing, validator, suffix); + validateFiles(baseDirectory, f, missing, validator, suffix, + ignores); } else if (f.getName().endsWith(suffix)) { try { validator.validateFile(f); |