Commit 5d143974 authored by Matyáš Latner's avatar Matyáš Latner

Copyright test moved to separated project

parent f42cd3ad
[submodule "core/external"]
path = core/external/tablexia-shared
url = git@gitlab.labs.nic.cz:labs/tablexia-model.git
[submodule "core/external/copyright-test"]
path = core/external/copyright-test
url = git@gitlab.labs.nic.cz:util/copyright-test.git
......@@ -9,6 +9,7 @@ sourceCompatibility = 1.7
[compileJava, compileTestJava]*.options*.encoding = 'UTF-8'
sourceSets.main.java.srcDirs = ["src/", "gen/", "external/tablexia-shared"]
sourceSets.test.java.srcDirs = ["test/", "external/copyright-test"]
eclipse.project {
......
Subproject commit cd7d18110b942eacface09c6fd90694c5835f872
/*
* Copyright (C) 2016 CZ.NIC, z.s.p.o. <info@tablexia.cz>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package cz.nic.tablexia.test.games;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Pattern;
public class CopyrightTest {
private static final String EMAIL_PATTERN = "(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|\"(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21\\x23-\\x5b\\x5d-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])*\")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21-\\x5a\\x53-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])+)\\])";
private static final String COPYRIGHT_PATTERN = ".*Copyright \\(C\\) \\d{4} CZ\\.NIC, z\\.s\\.p\\.o\\. <" + EMAIL_PATTERN + ">.*" +
"This program is free software: you can redistribute it and/or modify.*" +
"it under the terms of the GNU General Public License as published by.*" +
"the Free Software Foundation, either version 3 of the License, or.*" +
"\\(at your option\\) any later version\\..*" +
"This program is distributed in the hope that it will be useful,.*" +
"but WITHOUT ANY WARRANTY; without even the implied warranty of.*" +
"MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE\\. See the.*" +
"GNU General Public License for more details\\..*" +
"You should have received a copy of the GNU General Public License.*" +
"along with this program\\. If not, see <http://www\\.gnu\\.org/licenses/>\\..*";
private static final Pattern PATTERN = Pattern.compile(COPYRIGHT_PATTERN, Pattern.DOTALL);
private static final List<String> EXCLUDED_FILES = new ArrayList<String>() {{
add("R.java");
add("BuildConfig.java");
add("TablexiaBuildConfig.java");
add("cache.properties");
add("robovm.properties");
add("gradle-wrapper.properties");
add("project.properties");
add("gradle.properties");
add("local.properties");
}};
private static final String TABLEXIA_PATH = "../";
private static final String TEXTS_PATH = "../android/assets/text/";
private static final String JAVA_EXTENSION = ".java";
private static final String PROPERTIES_EXTENSION = ".properties";
private List<Path> filesToControl = new ArrayList<>();
@Before
public void tearUp() {
loadFiles(new File(TABLEXIA_PATH).listFiles(), JAVA_EXTENSION);
loadFiles(new File(TEXTS_PATH).listFiles(), PROPERTIES_EXTENSION);
}
@Test
public void copyrightTest() {
int filesContainsCopyright = 0;
for(Path filePath : filesToControl) {
try {
if (PATTERN.matcher(new String(Files.readAllBytes(filePath))).matches()) {
filesContainsCopyright++;
} else {
System.out.println(filePath + " - Missing or corrupted copyright!");
}
} catch (IOException e) {
e.printStackTrace();
}
}
Assert.assertEquals("Files with copyright: " + filesContainsCopyright + ", Files expected to have copyright: " + filesToControl.size(), filesContainsCopyright, filesToControl.size());
}
private void loadFiles(File[] files, String extension) {
for (File file : files) {
if (file.isDirectory()) loadFiles(file.listFiles(), extension);
if (!file.isDirectory() && file.getName().endsWith(extension) && !EXCLUDED_FILES.contains(file.getName())) filesToControl.add(file.toPath());
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment