Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Investigate mapping ordering #108

Merged
merged 3 commits into from
Aug 12, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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<String, String> mapping = new HashMap<String, String>();
public LinkedHashMap<String, String> mapping = new LinkedHashMap<String, String>();

/**
* Whether to use the default mapping between file extensions and comment
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

import java.io.File;
import java.util.HashMap;
import java.util.LinkedHashMap;

import static org.junit.Assert.*;

Expand Down Expand Up @@ -53,7 +54,7 @@ public void test_mapping() throws Exception {
}

logger.clear();
check.mapping = new HashMap<String, String>() {{
check.mapping = new LinkedHashMap<String, String>() {{
put("txt", "javadoc_style");
}};

Expand Down Expand Up @@ -91,13 +92,38 @@ public void test_mapping_composed_extension() throws Exception {
}

check.setLog(new SystemStreamLog());
check.mapping = new HashMap<String, String>() {{
check.mapping = new LinkedHashMap<String, String>() {{
put("apt.vm", "DOUBLETILDE_STYLE");
}};

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/issue107");
check.header = "header.txt";
check.project = new MavenProjectStub();
check.includes = new String[]{"test.xml.tmpl"};
check.properties = new HashMap<String, String>() {{
put("year", "2008");
}};

check.setLog(new SystemStreamLog());
check.mapping = new LinkedHashMap<String, String>() {{
put("jmx", "XML_STYLE");
put("feature", "SCRIPT_STYLE");
put("properties.tmpl", "SCRIPT_STYLE");
put("xml.tmpl", "XML_STYLE");
put("tmpl", "SCRIPT_STYLE");
}};

check.execute();
}

@Test
public void test_mapping_extension_less_file() throws Exception {
Expand All @@ -120,7 +146,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<String, String>() {{
check.mapping = new LinkedHashMap<String, String>() {{
put("extensionless-file", "SCRIPT_STYLE");
}};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<String, String>() {{
updater.mapping = new LinkedHashMap<String, String>() {{
put("properties", "SCRIPT_STYLE");
}};
updater.project = new MavenProjectStub();
Expand All @@ -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<String, String>() {{
updater.mapping = new LinkedHashMap<String, String>() {{
put("properties", "SCRIPT_STYLE");
}};
updater.project = new MavenProjectStub();
Expand Down Expand Up @@ -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<String, String>() {{
updater.mapping = new LinkedHashMap<String, String>() {{
put("txt.extended", "EXTENDED_STYLE");
}};
updater.headerDefinitions = new String[]{"/issues/issue-71/issue-71-additionalHeaderDefinitions.xml"};
Expand Down
13 changes: 13 additions & 0 deletions license-maven-plugin/src/test/resources/check/issue107/header.txt
Original file line number Diff line number Diff line change
@@ -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.
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>

<!--

Copyright (C) 2008 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.

-->

<configuration>
<system />
</configuration>