summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorArtur Signell <artur.signell@itmill.com>2012-01-27 14:07:33 +0000
committerArtur Signell <artur.signell@itmill.com>2012-01-27 14:07:33 +0000
commitb1ae3cd70e2ca4656bb28f77ca79fe0efd29dd67 (patch)
treea4797af5a9437d8ee5d31718654eb9eb225476e1 /tests
parent15bceb7d5958326b2747ad191332af56bb1677ec (diff)
downloadvaadin-framework-b1ae3cd70e2ca4656bb28f77ca79fe0efd29dd67.tar.gz
vaadin-framework-b1ae3cd70e2ca4656bb28f77ca79fe0efd29dd67.zip
#8311 Verify that all source files use unix style line delimiters
svn changeset:22796/svn branch:6.7
Diffstat (limited to 'tests')
-rw-r--r--tests/server-side/com/vaadin/tests/server/LicenseInJavaFiles.java54
-rw-r--r--tests/server-side/com/vaadin/tests/server/SourceFileChecker.java114
2 files changed, 114 insertions, 54 deletions
diff --git a/tests/server-side/com/vaadin/tests/server/LicenseInJavaFiles.java b/tests/server-side/com/vaadin/tests/server/LicenseInJavaFiles.java
deleted file mode 100644
index 6f3a05562b..0000000000
--- a/tests/server-side/com/vaadin/tests/server/LicenseInJavaFiles.java
+++ /dev/null
@@ -1,54 +0,0 @@
-package com.vaadin.tests.server;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.util.HashSet;
-
-import junit.framework.Assert;
-import junit.framework.TestCase;
-
-import org.apache.commons.io.IOUtils;
-
-public class LicenseInJavaFiles extends TestCase {
-
- /**
- * The tests are run in the build directory.
- */
- public static String SRC_DIR = "../src";
-
- public void testJavaFilesContainsLicense() throws IOException {
- File srcDir = new File(SRC_DIR);
- System.out.println(new File(".").getAbsolutePath());
- HashSet<String> missing = new HashSet<String>();
- checkForLicense(srcDir, missing);
- if (!missing.isEmpty()) {
- throw new RuntimeException(
- "The following files are missing license information:\n"
- + missing.toString());
- }
- }
-
- private void checkForLicense(File srcDir, HashSet<String> missing)
- throws IOException {
- Assert.assertTrue("Source directory " + srcDir + " does not exist",
- srcDir.exists());
-
- for (File f : srcDir.listFiles()) {
- if (f.isDirectory()) {
- checkForLicense(f, missing);
- } else if (f.getName().endsWith(".java")) {
- checkForLicenseInFile(f, missing);
- }
- }
- }
-
- private void checkForLicenseInFile(File f, HashSet<String> missing)
- throws IOException {
- String contents = IOUtils.toString(new FileInputStream(f));
- if (!contents.contains("@" + "VaadinApache2LicenseForJavaFiles" + "@")) {
- missing.add(f.getPath());
- }
-
- }
-}
diff --git a/tests/server-side/com/vaadin/tests/server/SourceFileChecker.java b/tests/server-side/com/vaadin/tests/server/SourceFileChecker.java
new file mode 100644
index 0000000000..91aaf131f5
--- /dev/null
+++ b/tests/server-side/com/vaadin/tests/server/SourceFileChecker.java
@@ -0,0 +1,114 @@
+package com.vaadin.tests.server;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.util.HashSet;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+import org.apache.commons.io.IOUtils;
+
+public class SourceFileChecker extends TestCase {
+
+ /**
+ * The tests are run in the build directory.
+ */
+ public static String baseDirectory = null;
+ public static final String SRC_DIR = getBaseDir() + "src";
+ public static final String TESTBENCH_SRC_DIR = getBaseDir()
+ + "tests/testbench";
+ public static final String SERVERSIDE_SRC_DIR = getBaseDir()
+ + "tests/server-side";
+ public static final String CLIENTSIDE_SRC_DIR = getBaseDir()
+ + "tests/client-side";
+
+ public static String getBaseDir() {
+ if (baseDirectory != null) {
+ return baseDirectory;
+ }
+ // Run in the "build" directory by build, in the project root by Eclipse
+ for (File f : new File("..").listFiles()) {
+ if (f.getName().equals("buildhelpers")) {
+ // We are in "build"
+ baseDirectory = "../";
+ return baseDirectory;
+ }
+ }
+
+ baseDirectory = "";
+ return baseDirectory;
+ }
+
+ private static final String[] ALL_SRC_DIRS = new String[] { SRC_DIR,
+ 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}");
+ }
+
+ public void testJavaFilesUseUnixNewline() throws IOException {
+ for (String dir : ALL_SRC_DIRS) {
+ validateJavaFiles(dir, new DosNewlineDetector(),
+ "The following files contain CRLF instead of LF:\n{0}");
+ }
+ }
+
+ public interface FileValidator {
+ void validateFile(File f) throws Exception;
+ }
+
+ private void validateJavaFiles(String directory, FileValidator validator,
+ String errorMessage) {
+ File srcDir = new File(directory);
+ System.out.println(new File(".").getAbsolutePath());
+ HashSet<String> missing = new HashSet<String>();
+ validateFiles(srcDir, missing, validator, ".java");
+ if (!missing.isEmpty()) {
+ throw new RuntimeException(errorMessage.replace("{0}",
+ missing.toString()));
+ }
+
+ }
+
+ private void validateFiles(File srcDir, HashSet<String> missing,
+ FileValidator validator, String suffix) {
+ Assert.assertTrue("Directory " + srcDir + " does not exist",
+ srcDir.exists());
+
+ for (File f : srcDir.listFiles()) {
+ if (f.isDirectory()) {
+ validateFiles(f, missing, validator, suffix);
+ } else if (f.getName().endsWith(suffix)) {
+ try {
+ validator.validateFile(f);
+ } catch (Throwable t) {
+ missing.add(f.getPath());
+ }
+ }
+ }
+ }
+
+ class DosNewlineDetector implements FileValidator {
+
+ public void validateFile(File f) throws Exception {
+ String contents = IOUtils.toString(new FileInputStream(f));
+ if (contents.contains("\r\n")) {
+ throw new IllegalArgumentException();
+ }
+
+ }
+ }
+
+ class LicenseChecker implements FileValidator {
+ public void validateFile(File f) throws Exception {
+ String contents = IOUtils.toString(new FileInputStream(f));
+ if (!contents.contains("@" + "VaadinApache2LicenseForJavaFiles"
+ + "@")) {
+ throw new IllegalArgumentException();
+ }
+ }
+ }
+}