Skip to content

Commit

Permalink
Merge pull request #226 from mathieucarbou/enhancements/156
Browse files Browse the repository at this point in the history
Fix #156
  • Loading branch information
mathieucarbou authored Sep 12, 2021
2 parents e5ed3e9 + e6601e8 commit 4c7da27
Show file tree
Hide file tree
Showing 10 changed files with 253 additions and 0 deletions.
20 changes: 20 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,26 @@ The plugin has been designed so that it is very easy to add new supports for new
//
```

- `MVEL_STYLE`

```mvel
@comment{
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.
}
```

- `ASCIIDOC_STYLE`

```asciidoc
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ public enum DocumentType {
LISP("el", HeaderType.EXCLAMATION3_STYLE),
LUA("lua", HeaderType.LUA),
MUSTACHE("mustache", HeaderType.MUSTACHE_STYLE),
MVEL("mv", HeaderType.MVEL_STYLE),
MXML("mxml", HeaderType.XML_STYLE),
PERL("pl", HeaderType.SCRIPT_STYLE),
PERL_MODULE("pm", HeaderType.SCRIPT_STYLE),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public enum HeaderType {
// firstLine beforeEachLine endLine afterEachLine skipLinePattern firstLineDetectionPattern lastLineDetectionPattern allowBlankLines isMultiline padLines
//generic
ASCIIDOC_STYLE("////", " // ", "////", "", null, "^////$", "^////$", false, true, false),
MVEL_STYLE("@comment{", " ", "}", "", null, "@comment\\{$", "\\}$", true, true, false),
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),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
/**
* Copyright (C) 2008 Mycila (mathieu.carbou@gmail.com)
* <p>
* 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
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* 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.
*/
package com.mycila.maven.plugin.license;

import com.mycila.maven.plugin.license.util.FileUtils;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.testing.stubs.MavenProjectStub;
import org.junit.Test;

import java.io.File;

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.fail;

/**
* @author Mathieu Carbou (mathieu.carbou@gmail.com)
*/
public final class MvelTest {

@Test
public void test_add() throws Exception {
File tmp = new File("target/test/issues/issue-156/test_add");
FileUtils.copyFilesToFolder(new File("src/test/resources/issues/issue-156"), tmp);

AbstractLicenseMojo plugin = new LicenseFormatMojo();
plugin.project = new MavenProjectStub();
plugin.defaultBasedir = tmp;
plugin.legacyConfigHeader = "src/test/resources/issues/issue-156/header1.txt";
plugin.legacyConfigIncludes = new String[]{"file.mv"};

plugin.execute();

String processed = FileUtils.read(new File(tmp, "file.mv"), System.getProperty("file.encoding"));
String expected = FileUtils.read(new File("src/test/resources/issues/issue-156/expected1.mv"), System.getProperty("file.encoding"));
assertThat(processed, is(equalTo(expected)));
}

@Test
public void test_update() throws Exception {
File tmp = new File("target/test/issues/issue-156/test_update");
FileUtils.copyFilesToFolder(new File("src/test/resources/issues/issue-156"), tmp);

AbstractLicenseMojo plugin = new LicenseFormatMojo();
plugin.project = new MavenProjectStub();
plugin.defaultBasedir = tmp;
plugin.legacyConfigHeader = "src/test/resources/issues/issue-156/header1.txt";
plugin.legacyConfigIncludes = new String[]{"file.mv"};

plugin.execute();

plugin = new LicenseFormatMojo();
plugin.project = new MavenProjectStub();
plugin.defaultBasedir = tmp;
plugin.legacyConfigHeader = "src/test/resources/issues/issue-156/header2.txt";
plugin.legacyConfigIncludes = new String[]{"file.mv"};

plugin.execute();

String processed = FileUtils.read(new File(tmp, "file.mv"), System.getProperty("file.encoding"));
String expected = FileUtils.read(new File("src/test/resources/issues/issue-156/expected2.mv"), System.getProperty("file.encoding"));
assertThat(processed, is(equalTo(expected)));
}

@Test
public void test_remove() throws Exception {
File tmp = new File("target/test/issues/issue-156/test_remove");
FileUtils.copyFilesToFolder(new File("src/test/resources/issues/issue-156"), tmp);

AbstractLicenseMojo plugin = new LicenseFormatMojo();
plugin.project = new MavenProjectStub();
plugin.defaultBasedir = tmp;
plugin.legacyConfigHeader = "src/test/resources/issues/issue-156/header1.txt";
plugin.legacyConfigIncludes = new String[]{"file.mv"};

plugin.execute();

plugin = new LicenseRemoveMojo();
plugin.project = new MavenProjectStub();
plugin.defaultBasedir = tmp;
plugin.legacyConfigHeader = "src/test/resources/issues/issue-156/header1.txt";
plugin.legacyConfigIncludes = new String[]{"file.mv"};

plugin.execute();

String processed = FileUtils.read(new File(tmp, "file.mv"), System.getProperty("file.encoding"));
String expected = FileUtils.read(new File("src/test/resources/issues/issue-156/file.mv"), System.getProperty("file.encoding"));
assertThat(processed, is(equalTo(expected)));
}

@Test
public void test_check_failed() throws Exception {
File tmp = new File("target/test/issues/issue-156/test_check_failed");
FileUtils.copyFilesToFolder(new File("src/test/resources/issues/issue-156"), tmp);

AbstractLicenseMojo plugin = new LicenseCheckMojo();
plugin.project = new MavenProjectStub();
plugin.defaultBasedir = tmp;
plugin.legacyConfigHeader = "src/test/resources/issues/issue-156/header1.txt";
plugin.legacyConfigIncludes = new String[]{"file.mv"};


try {
plugin.execute();
fail();
} catch (MojoExecutionException e) {
assertEquals("Some files do not have the expected license header", e.getMessage());
}
}

@Test
public void test_check_success() throws Exception {
File tmp = new File("target/test/issues/issue-156/test_check_success");
FileUtils.copyFilesToFolder(new File("src/test/resources/issues/issue-156"), tmp);

AbstractLicenseMojo plugin = new LicenseFormatMojo();
plugin.project = new MavenProjectStub();
plugin.defaultBasedir = tmp;
plugin.legacyConfigHeader = "src/test/resources/issues/issue-156/header1.txt";
plugin.legacyConfigIncludes = new String[]{"file.mv"};

plugin.execute();

plugin = new LicenseCheckMojo();
plugin.project = new MavenProjectStub();
plugin.defaultBasedir = tmp;
plugin.legacyConfigHeader = "src/test/resources/issues/issue-156/header1.txt";
plugin.legacyConfigIncludes = new String[]{"file.mv"};

plugin.execute();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
@comment{
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.
}
### Hello world!

I am a Markdown doc
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
@comment{
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.
}
### Hello world!

I am a Markdown doc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
### Hello world!

I am a Markdown doc
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.
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
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.
15 changes: 15 additions & 0 deletions license-maven-plugin/src/test/resources/styles/mvel_style.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
@comment{
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.
}

0 comments on commit 4c7da27

Please sign in to comment.