aboutsummaryrefslogtreecommitdiffstats
path: root/tests/server-side
diff options
context:
space:
mode:
authorArtur Signell <artur@vaadin.com>2012-01-31 15:33:01 +0200
committerArtur Signell <artur@vaadin.com>2012-01-31 15:33:01 +0200
commitc1f26940cd893dc5e89d2c6eb39d83ce668557fe (patch)
treecbe03a6cba732d0bcb1ddce2ece938dd07165489 /tests/server-side
parent1d01f9204bd760789592238be039acef57616109 (diff)
parentb1ae3cd70e2ca4656bb28f77ca79fe0efd29dd67 (diff)
downloadvaadin-framework-c1f26940cd893dc5e89d2c6eb39d83ce668557fe.tar.gz
vaadin-framework-c1f26940cd893dc5e89d2c6eb39d83ce668557fe.zip
Merged 'b1ae3cd70e2ca4656bb28f77ca79fe0efd29dd67' (origin/6.8)
Conflicts: WebContent/release-notes.html tests/server-side/com/vaadin/tests/server/LicenseInJavaFiles.java
Diffstat (limited to 'tests/server-side')
-rw-r--r--tests/server-side/com/vaadin/tests/server/SourceFileChecker.java114
1 files changed, 114 insertions, 0 deletions
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();
+ }
+ }
+ }
+}