From c43abe8d99b4ea3143eb814e5559f55671c02c32 Mon Sep 17 00:00:00 2001 From: Shane Saunders Date: Mon, 8 Aug 2016 15:20:00 -0600 Subject: [PATCH 1/3] first version of testing ordering --- .../plugin/license/AbstractLicenseMojo.java | 4 +- .../maven/plugin/license/MappingMojoTest.java | 37 +++++++++++++++++++ .../src/test/resources/check/test.xml.tmpl | 24 ++++++++++++ 3 files changed, 63 insertions(+), 2 deletions(-) create mode 100644 license-maven-plugin/src/test/resources/check/test.xml.tmpl diff --git a/license-maven-plugin/src/main/java/com/mycila/maven/plugin/license/AbstractLicenseMojo.java b/license-maven-plugin/src/main/java/com/mycila/maven/plugin/license/AbstractLicenseMojo.java index b44d5b5e6..992baa088 100755 --- a/license-maven-plugin/src/main/java/com/mycila/maven/plugin/license/AbstractLicenseMojo.java +++ b/license-maven-plugin/src/main/java/com/mycila/maven/plugin/license/AbstractLicenseMojo.java @@ -113,7 +113,7 @@ public abstract class AbstractLicenseMojo extends AbstractMojo { /** * HeadSections define special regions of a header that allow for dynamic - * substitution and validation. + * substitution and validation */ @Parameter public HeaderSection[] headerSections = new HeaderSection[0]; @@ -176,7 +176,7 @@ public abstract class AbstractLicenseMojo extends AbstractMojo { * support, and the value is the name of the comment type to use. */ @Parameter - public Map mapping = new HashMap(); + public Map mapping = new LinkedHashMap(); /** * Whether to use the default mapping between file extensions and comment diff --git a/license-maven-plugin/src/test/java/com/mycila/maven/plugin/license/MappingMojoTest.java b/license-maven-plugin/src/test/java/com/mycila/maven/plugin/license/MappingMojoTest.java index 209e21b0f..7e7abb140 100755 --- a/license-maven-plugin/src/test/java/com/mycila/maven/plugin/license/MappingMojoTest.java +++ b/license-maven-plugin/src/test/java/com/mycila/maven/plugin/license/MappingMojoTest.java @@ -23,6 +23,8 @@ import java.io.File; import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.TreeMap; import static org.junit.Assert.*; @@ -98,6 +100,41 @@ public void test_mapping_composed_extension() throws Exception { check.execute(); } + @Test + public void test_mapping_composed_extension_ordered() throws Exception { + LicenseCheckMojo check = new LicenseCheckMojo(); + MockedLog logger = new MockedLog(); + check.setLog(new DefaultLog(logger)); + //check.setLog(new SystemStreamLog()); + check.basedir = new File("src/test/resources/check"); + check.header = "header.txt"; + check.project = new MavenProjectStub(); + check.includes = new String[]{"test.xml.tmpl"}; + check.properties = new HashMap() {{ + put("year", "2008"); + }}; + + check.mapping = new TreeMap() {{ + put("jmx", "XML_STYLE"); + put("feature", "SCRIPT_STYLE"); + put("properties.tmpl", "SCRIPT_STYLE"); + put("xml.tmpl", "XML_STYLE"); + put("tmpl", "SCRIPT_STYLE"); + }}; + + try { + check.execute(); + fail(); + } catch (MojoExecutionException e) { + e.printStackTrace(System.out); + assertTrue(logger.getContent().contains("test.xml.tmpl [header style: script_style]")); + assertEquals("Some files do not have the expected license header", e.getMessage()); + } + + check.setLog(new SystemStreamLog()); + + check.execute(); + } @Test public void test_mapping_extension_less_file() throws Exception { diff --git a/license-maven-plugin/src/test/resources/check/test.xml.tmpl b/license-maven-plugin/src/test/resources/check/test.xml.tmpl new file mode 100644 index 000000000..9fd89fb39 --- /dev/null +++ b/license-maven-plugin/src/test/resources/check/test.xml.tmpl @@ -0,0 +1,24 @@ + + + + + + + + From 69d131819c54d5bdc088d26e16cea17ac86ae780 Mon Sep 17 00:00:00 2001 From: Shane Saunders Date: Mon, 8 Aug 2016 16:39:47 -0600 Subject: [PATCH 2/3] fixed order of mappings --- .../plugin/license/AbstractLicenseMojo.java | 4 ++-- .../maven/plugin/license/MappingMojoTest.java | 22 +++++-------------- .../maven/plugin/license/QuietMojoTest.java | 1 + .../maven/plugin/license/UpdateMojoTest.java | 7 +++--- .../test/resources/check/issue107/header.txt | 13 +++++++++++ .../check/{ => issue107}/test.xml.tmpl | 3 ++- 6 files changed, 28 insertions(+), 22 deletions(-) create mode 100644 license-maven-plugin/src/test/resources/check/issue107/header.txt rename license-maven-plugin/src/test/resources/check/{ => issue107}/test.xml.tmpl (90%) diff --git a/license-maven-plugin/src/main/java/com/mycila/maven/plugin/license/AbstractLicenseMojo.java b/license-maven-plugin/src/main/java/com/mycila/maven/plugin/license/AbstractLicenseMojo.java index 992baa088..1c02a94b6 100755 --- a/license-maven-plugin/src/main/java/com/mycila/maven/plugin/license/AbstractLicenseMojo.java +++ b/license-maven-plugin/src/main/java/com/mycila/maven/plugin/license/AbstractLicenseMojo.java @@ -176,7 +176,7 @@ public abstract class AbstractLicenseMojo extends AbstractMojo { * support, and the value is the name of the comment type to use. */ @Parameter - public Map mapping = new LinkedHashMap(); + public LinkedHashMap mapping = new LinkedHashMap(); /** * Whether to use the default mapping between file extensions and comment @@ -373,7 +373,7 @@ public Properties load(Document document) { }; final DocumentFactory documentFactory = new DocumentFactory(basedir, buildMapping(), buildHeaderDefinitions(), encoding, keywords, propertiesLoader); - + int nThreads = (int) (Runtime.getRuntime().availableProcessors() * concurrencyFactor); ExecutorService executorService = Executors.newFixedThreadPool(nThreads); CompletionService completionService = new ExecutorCompletionService(executorService); diff --git a/license-maven-plugin/src/test/java/com/mycila/maven/plugin/license/MappingMojoTest.java b/license-maven-plugin/src/test/java/com/mycila/maven/plugin/license/MappingMojoTest.java index 7e7abb140..d575a102e 100755 --- a/license-maven-plugin/src/test/java/com/mycila/maven/plugin/license/MappingMojoTest.java +++ b/license-maven-plugin/src/test/java/com/mycila/maven/plugin/license/MappingMojoTest.java @@ -55,7 +55,7 @@ public void test_mapping() throws Exception { } logger.clear(); - check.mapping = new HashMap() {{ + check.mapping = new LinkedHashMap() {{ put("txt", "javadoc_style"); }}; @@ -93,7 +93,7 @@ public void test_mapping_composed_extension() throws Exception { } check.setLog(new SystemStreamLog()); - check.mapping = new HashMap() {{ + check.mapping = new LinkedHashMap() {{ put("apt.vm", "DOUBLETILDE_STYLE"); }}; @@ -106,7 +106,7 @@ public void test_mapping_composed_extension_ordered() throws Exception { MockedLog logger = new MockedLog(); check.setLog(new DefaultLog(logger)); //check.setLog(new SystemStreamLog()); - check.basedir = new File("src/test/resources/check"); + check.basedir = new File("src/test/resources/check/issue107"); check.header = "header.txt"; check.project = new MavenProjectStub(); check.includes = new String[]{"test.xml.tmpl"}; @@ -114,7 +114,8 @@ public void test_mapping_composed_extension_ordered() throws Exception { put("year", "2008"); }}; - check.mapping = new TreeMap() {{ + check.setLog(new SystemStreamLog()); + check.mapping = new LinkedHashMap() {{ put("jmx", "XML_STYLE"); put("feature", "SCRIPT_STYLE"); put("properties.tmpl", "SCRIPT_STYLE"); @@ -122,17 +123,6 @@ public void test_mapping_composed_extension_ordered() throws Exception { put("tmpl", "SCRIPT_STYLE"); }}; - try { - check.execute(); - fail(); - } catch (MojoExecutionException e) { - e.printStackTrace(System.out); - assertTrue(logger.getContent().contains("test.xml.tmpl [header style: script_style]")); - assertEquals("Some files do not have the expected license header", e.getMessage()); - } - - check.setLog(new SystemStreamLog()); - check.execute(); } @@ -157,7 +147,7 @@ public void test_mapping_extension_less_file() throws Exception { /* Add the mapping and expect the missing header */ MockedLog mappedLogger = new MockedLog(); check.setLog(new DefaultLog(mappedLogger)); - check.mapping = new HashMap() {{ + check.mapping = new LinkedHashMap() {{ put("extensionless-file", "SCRIPT_STYLE"); }}; diff --git a/license-maven-plugin/src/test/java/com/mycila/maven/plugin/license/QuietMojoTest.java b/license-maven-plugin/src/test/java/com/mycila/maven/plugin/license/QuietMojoTest.java index b2bfc638c..200f8425d 100755 --- a/license-maven-plugin/src/test/java/com/mycila/maven/plugin/license/QuietMojoTest.java +++ b/license-maven-plugin/src/test/java/com/mycila/maven/plugin/license/QuietMojoTest.java @@ -37,6 +37,7 @@ public void test_load_header_from_relative_file() throws Exception { check.project = new MavenProjectStub(); check.failIfMissing = false; check.strictCheck = true; + check.excludes = new String[]{"**/issue107/**"}; MockedLog logger = new MockedLog(); check.setLog(new DefaultLog(logger)); diff --git a/license-maven-plugin/src/test/java/com/mycila/maven/plugin/license/UpdateMojoTest.java b/license-maven-plugin/src/test/java/com/mycila/maven/plugin/license/UpdateMojoTest.java index d8505679a..dccf5200b 100755 --- a/license-maven-plugin/src/test/java/com/mycila/maven/plugin/license/UpdateMojoTest.java +++ b/license-maven-plugin/src/test/java/com/mycila/maven/plugin/license/UpdateMojoTest.java @@ -25,6 +25,7 @@ import java.io.File; import java.nio.charset.Charset; import java.util.HashMap; +import java.util.LinkedHashMap; import java.util.List; import static org.hamcrest.CoreMatchers.is; @@ -107,7 +108,7 @@ public void test_issue50() throws Exception { updater.basedir = tmp; updater.header = "src/test/resources/update/header.txt"; updater.properties = ImmutableMap.of("year", "2008"); - updater.mapping = new HashMap() {{ + updater.mapping = new LinkedHashMap() {{ put("properties", "SCRIPT_STYLE"); }}; updater.project = new MavenProjectStub(); @@ -132,7 +133,7 @@ public void test_issue48() throws Exception { updater.basedir = tmp; updater.header = "src/test/resources/update/header.txt"; updater.properties = ImmutableMap.of("year", "2008"); - updater.mapping = new HashMap() {{ + updater.mapping = new LinkedHashMap() {{ put("properties", "SCRIPT_STYLE"); }}; updater.project = new MavenProjectStub(); @@ -237,7 +238,7 @@ public void test_issue71_canSkipSeveralLines() throws Exception { updater.basedir = tmp; updater.header = "src/test/resources/issues/issue-71/issue-71-header.txt"; updater.project = new MavenProjectStub(); - updater.mapping = new HashMap() {{ + updater.mapping = new LinkedHashMap() {{ put("txt.extended", "EXTENDED_STYLE"); }}; updater.headerDefinitions = new String[]{"/issues/issue-71/issue-71-additionalHeaderDefinitions.xml"}; diff --git a/license-maven-plugin/src/test/resources/check/issue107/header.txt b/license-maven-plugin/src/test/resources/check/issue107/header.txt new file mode 100644 index 000000000..a4d2ac474 --- /dev/null +++ b/license-maven-plugin/src/test/resources/check/issue107/header.txt @@ -0,0 +1,13 @@ +Copyright (C) ${year} http://code.google.com/p/maven-license-plugin/ + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. \ No newline at end of file diff --git a/license-maven-plugin/src/test/resources/check/test.xml.tmpl b/license-maven-plugin/src/test/resources/check/issue107/test.xml.tmpl similarity index 90% rename from license-maven-plugin/src/test/resources/check/test.xml.tmpl rename to license-maven-plugin/src/test/resources/check/issue107/test.xml.tmpl index 9fd89fb39..4a4c5e907 100644 --- a/license-maven-plugin/src/test/resources/check/test.xml.tmpl +++ b/license-maven-plugin/src/test/resources/check/issue107/test.xml.tmpl @@ -1,7 +1,8 @@ +