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

Fix #187 #221

Merged
merged 1 commit into from
Sep 11, 2021
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 @@ -33,7 +33,7 @@ public enum HeaderType {
//generic
JAVADOC_STYLE("/**", " * ", " */", "", null, "(\\s|\\t)*/\\*.*$", ".*\\*/(\\s|\\t)*$", false, true, false),
SCALA_STYLE("/**", " * ", " */", "", null, "(\\s|\\t)*/\\*.*$", ".*\\*/(\\s|\\t)*$", false, true, false),
JAVAPKG_STYLE("EOL/*-", " * ", " */", "", "^package [a-z]+(\\.[a-z][a-z0-9]*)*;$", "(EOL)*(\\s|\\t)*/\\*.*$", ".*\\*/(\\s|\\t)*$", false, true, false),
JAVAPKG_STYLE("EOL/*-", " * ", " */", "", "^package [a-z_]+(\\.[a-z_][a-z0-9_]*)*;$", "(EOL)*(\\s|\\t)*/\\*.*$", ".*\\*/(\\s|\\t)*$", false, true, false),
SCRIPT_STYLE("#", "# ", "#EOL", "", "^#!.*$", "#.*$", "#.*$", false, false, false),
HAML_STYLE("-#", "-# ", "-#EOL", "", "^-#!.*$", "-#.*$", "-#.*$", false, false, false),
XML_STYLE("<!--EOL", " ", "EOL-->", "", "^<\\?xml.*>$", "(\\s|\\t)*<!--.*$", ".*-->(\\s|\\t)*$", true, true, false),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,17 @@
import java.util.LinkedHashMap;
import java.util.List;

import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.fail;
/**
* @author Mathieu Carbou (mathieu.carbou@gmail.com)
*/
public final class UpdateMojoTest {
public static final String LS = "\n";

@Test
public void test_update() throws Exception {
File tmp = new File("target/test/update");
Expand Down Expand Up @@ -244,7 +245,7 @@ public void test_issue_14() throws Exception {

assertEquals(expectedString, readModifiedContent);
}

@Test
public void test_issue71_canSkipSeveralLines() throws Exception {
File tmp = new File("target/test/update/issue71");
Expand All @@ -267,29 +268,29 @@ public void test_issue71_canSkipSeveralLines() throws Exception {
assertThat(linesOfModifiedFile.get(0 /* line 1 */), is("|||"));
assertThat(linesOfModifiedFile.get(8) /* line 9 */, is("|||"));
}

@Test
public void test_issue37_RunningUpdaterTwiceMustNotChangeTheFile() throws Exception {
File tmp = new File("target/test/update/issue37");
tmp.mkdirs();
FileUtils.copyFileToFolder(new File("src/test/resources/update/issue37/xwiki.xml"), tmp);

LicenseFormatMojo execution1 = new LicenseFormatMojo();
execution1.defaultBasedir = tmp;
execution1.legacyConfigHeader = "src/test/resources/update/issue37/xwiki-license.txt";
execution1.project = new MavenProjectStub();
execution1.execute();

String execution1FileContent = FileUtils.read(new File(tmp, "xwiki.xml"), System.getProperty("file.encoding"));

LicenseFormatMojo execution2 = new LicenseFormatMojo();
execution2.defaultBasedir = tmp;
execution2.legacyConfigHeader = "src/test/resources/update/issue37/xwiki-license.txt";
execution2.project = new MavenProjectStub();
execution2.execute();

String execution2FileContent = FileUtils.read(new File(tmp, "xwiki.xml"), System.getProperty("file.encoding"));

assertThat(execution1FileContent, is(execution2FileContent));
}

Expand All @@ -298,16 +299,16 @@ public void test_UpdateWorksHasExpectedOnAOneLineCommentFile_relatesTo_issue30()
File tmp = new File("target/test/update/issue30");
tmp.mkdirs();
FileUtils.copyFileToFolder(new File("src/test/resources/update/issue30/one-line-comment.ftl"), tmp);

LicenseFormatMojo updater = new LicenseFormatMojo();
updater.defaultBasedir = tmp;
updater.legacyConfigHeader = "src/test/resources/single-line-header.txt";
updater.project = new MavenProjectStub();
updater.execute();

List<String> linesOfOriginFile = Files.readLines(new File("src/test/resources/update/issue30/one-line-comment.ftl"), Charset.defaultCharset());
List<String> linesOfUpdatedFile = Files.readLines(new File(tmp, "one-line-comment.ftl"), Charset.defaultCharset());

// check that the original line is kept as the latest one even when introducing a license header
assertThat(linesOfOriginFile.get(0), is(linesOfUpdatedFile.get(linesOfUpdatedFile.size() - 1)));
}
Expand Down Expand Up @@ -348,4 +349,26 @@ public void test_issue213() throws Exception {
FileUtils.read(new File(tmp, "test.xml"), System.getProperty("file.encoding"))
);
}

@Test
public void test_issue71_underscore_in_package_name() throws Exception {
File tmp = new File("target/test/update/issue-187");
tmp.mkdirs();
FileUtils.copyFileToFolder(new File("src/test/resources/update/issue-187/Main.java"), tmp);

LicenseFormatMojo updater = new LicenseFormatMojo();
updater.defaultBasedir = tmp;
updater.legacyConfigHeader = "src/test/resources/update/issue-187/header.txt";
updater.project = new MavenProjectStub();
updater.mapping = new LinkedHashMap<String, String>() {{
put("java", "JAVAPKG_STYLE");
}};

updater.execute();

String processed = FileUtils.read(new File(tmp, "Main.java"), System.getProperty("file.encoding"));
String expected = FileUtils.read(new File("src/test/resources/update/issue-187/expected.txt"), System.getProperty("file.encoding"));

assertThat(processed, is(equalTo(expected)));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package with_underscore;

public class Main {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package with_underscore;

/*-
* Copyright (c) 2006-2009
*
* All rights reserved.
*
* 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.
*/

public class Main {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Copyright (c) 2006-2009

All rights reserved.

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.