From 3f2f80110edf44e8e510013ff5fd8d3c0a6896af Mon Sep 17 00:00:00 2001 From: Peter Palaga Date: Mon, 15 Aug 2016 21:59:18 +0200 Subject: [PATCH 1/2] Issue #104 inlineHeader not working --- .../plugin/license/AbstractLicenseMojo.java | 16 +- .../plugin/license/document/Document.java | 2 +- .../maven/plugin/license/header/Header.java | 29 ++-- .../plugin/license/header/HeaderSource.java | 143 ++++++++++++++++++ .../plugin/license/document/DocumentTest.java | 6 +- .../AdditionalHeaderDefinitionTest.java | 7 +- .../header/DefaultHeaderDefinitionTest.java | 3 +- .../license/header/HeaderSourceTest.java | 49 ++++++ .../plugin/license/header/HeaderTest.java | 24 +-- 9 files changed, 235 insertions(+), 44 deletions(-) create mode 100644 license-maven-plugin/src/main/java/com/mycila/maven/plugin/license/header/HeaderSource.java create mode 100644 license-maven-plugin/src/test/java/com/mycila/maven/plugin/license/header/HeaderSourceTest.java 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 1c02a94b6..780fbf0f1 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 @@ -22,6 +22,7 @@ import com.mycila.maven.plugin.license.header.AdditionalHeaderDefinition; import com.mycila.maven.plugin.license.header.Header; import com.mycila.maven.plugin.license.header.HeaderDefinition; +import com.mycila.maven.plugin.license.header.HeaderSource; import com.mycila.maven.plugin.license.header.HeaderType; import com.mycila.maven.plugin.license.util.Selection; import com.mycila.maven.plugin.license.util.resource.ResourceFinder; @@ -43,6 +44,7 @@ import java.io.File; import java.io.IOException; +import java.net.URL; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; @@ -307,7 +309,7 @@ public void checkUnknown() throws MojoExecutionException { @SuppressWarnings({"unchecked"}) public final void execute(final Callback callback) throws MojoExecutionException, MojoFailureException { if (!skip) { - if (header == null) { + if (header == null && (this.inlineHeader == null || this.inlineHeader.isEmpty())) { warn("No header file specified to check for license"); return; } @@ -323,16 +325,18 @@ public final void execute(final Callback callback) throws MojoExecutionException throw new MojoExecutionException(e.getMessage(), e); } finder.setPluginClassPath(getClass().getClassLoader()); - - final Header h = new Header(finder.findResource(this.header), encoding, headerSections, inlineHeader); - debug("Header %s:\n%s", h.isInline() ? "inline" : h.getLocation(), h); - + + final HeaderSource headerSource = HeaderSource.of(this.inlineHeader, this.header, this.encoding, this.finder); + final Header h = new Header(headerSource, headerSections); + debug("Header: %s", h.getLocation()); + if (this.validHeaders == null) { this.validHeaders = new String[0]; } final List
validHeaders = new ArrayList
(this.validHeaders.length); for (String validHeader : this.validHeaders) { - validHeaders.add(new Header(finder.findResource(validHeader), encoding, headerSections, inlineHeader)); + final HeaderSource validHeaderSource = HeaderSource.of(null, validHeader, this.encoding, this.finder); + validHeaders.add(new Header(validHeaderSource, headerSections)); } final List propertiesProviders = new LinkedList(); diff --git a/license-maven-plugin/src/main/java/com/mycila/maven/plugin/license/document/Document.java b/license-maven-plugin/src/main/java/com/mycila/maven/plugin/license/document/Document.java index 9da0340e5..413b07b8d 100755 --- a/license-maven-plugin/src/main/java/com/mycila/maven/plugin/license/document/Document.java +++ b/license-maven-plugin/src/main/java/com/mycila/maven/plugin/license/document/Document.java @@ -123,7 +123,7 @@ public void removeHeader() { public boolean is(Header header) { try { - return !header.isInline() && header.getLocation().sameFile(this.file.toURI().toURL()); + return header.getLocation().isFromUrl(this.file.toURI().toURL()); } catch (Exception e) { throw new IllegalStateException("Error comparing document " + this.file + " with file " + file + ". Cause: " + e.getMessage(), e); } diff --git a/license-maven-plugin/src/main/java/com/mycila/maven/plugin/license/header/Header.java b/license-maven-plugin/src/main/java/com/mycila/maven/plugin/license/header/Header.java index d6356ae4c..aea968acc 100755 --- a/license-maven-plugin/src/main/java/com/mycila/maven/plugin/license/header/Header.java +++ b/license-maven-plugin/src/main/java/com/mycila/maven/plugin/license/header/Header.java @@ -15,19 +15,17 @@ */ package com.mycila.maven.plugin.license.header; -import com.mycila.maven.plugin.license.HeaderSection; -import com.mycila.maven.plugin.license.document.Document; -import com.mycila.maven.plugin.license.util.StringUtils; - import java.io.IOException; -import java.net.URL; import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.SortedMap; import java.util.TreeMap; -import static com.mycila.maven.plugin.license.util.FileUtils.read; +import com.mycila.maven.plugin.license.HeaderSection; +import com.mycila.maven.plugin.license.document.Document; +import com.mycila.maven.plugin.license.util.StringUtils; + import static com.mycila.maven.plugin.license.util.FileUtils.readFirstLines; import static com.mycila.maven.plugin.license.util.FileUtils.remove; @@ -38,13 +36,12 @@ * @author Mathieu Carbou (mathieu.carbou@gmail.com) */ public final class Header { - private final URL location; + private final HeaderSource location; private final String headerContent; private final String headerContentOneLine; private String[] lines; private final HeaderSection[] sections; private final int maxLength; - private final boolean inline; /** * Constructs a Header object pointing to a license template file. In case of the template contains @@ -55,15 +52,11 @@ public final class Header { * @throws IllegalArgumentException If the header file location is null or if an error occurred while reading the * file content. */ - public Header(URL location, String encoding, HeaderSection[] sections, String headerText) { - if (location == null && headerText == null) { - throw new IllegalArgumentException("Cannot read license template header file with a null location"); - } + public Header(HeaderSource location, HeaderSection[] sections) { this.location = location; - this.inline = location == null; this.sections = sections; try { - this.headerContent = location == null ? headerText : read(location, encoding); + this.headerContent = location.getContent(); lines = headerContent.replace("\r", "").split("\n"); headerContentOneLine = remove(headerContent, " ", "\t", "\r", "\n"); } catch (Exception e) { @@ -101,15 +94,11 @@ public int getMaxLineLength() { * * @return The URL location. */ - public URL getLocation() { + public HeaderSource getLocation() { return location; } - public boolean isInline() { - return inline; - } - - public String eol(boolean unix) { + public String eol(boolean unix) { return unix ? "\n" : "\r\n"; } diff --git a/license-maven-plugin/src/main/java/com/mycila/maven/plugin/license/header/HeaderSource.java b/license-maven-plugin/src/main/java/com/mycila/maven/plugin/license/header/HeaderSource.java new file mode 100644 index 000000000..9a37dd8e2 --- /dev/null +++ b/license-maven-plugin/src/main/java/com/mycila/maven/plugin/license/header/HeaderSource.java @@ -0,0 +1,143 @@ +/** + * Copyright (C) 2008 Mycila (mathieu.carbou@gmail.com) + * + * 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. + */ +package com.mycila.maven.plugin.license.header; + +import java.io.IOException; +import java.net.URL; + +import com.mycila.maven.plugin.license.util.FileUtils; +import com.mycila.maven.plugin.license.util.resource.ResourceFinder; + +/** + * Provides an access to the license template text. + * + * @author Peter Palaga + */ +public abstract class HeaderSource { + + /** + * A {@link HeaderSource} built from a lincense header template literal. + */ + public static class LiteralHeaderSource extends HeaderSource { + public LiteralHeaderSource(String content) { + super(content, true); + } + + /** + * @return always {@code false} because this {@link LiteralHeaderSource} was not loaded from any {@link URL} + */ + @Override + public boolean isFromUrl(URL location) { + return false; + } + + @Override + public String toString() { + return "inline: " + content; + } + + } + + /** + * A {@link HeaderSource} loaded from a {@link URL}. + */ + public static class UrlHeaderSource extends HeaderSource { + private final URL url; + + public UrlHeaderSource(URL url, String encoding) throws IOException { + super(FileUtils.read(url, encoding), false); + this.url = url; + } + + @Override + public boolean isFromUrl(URL location) { + return this.url.equals(location); + } + + @Override + public String toString() { + return url + ": " + content; + } + + } + + public static HeaderSource of(String headerPath, String encoding, ResourceFinder finder) { + return of(null, encoding, finder); + } + + /** + * Checking the params left to right, returns the first available {@link HeaderSource} that can be created. If + * {@code inlineHeader} is not {@code null} returns a new {@link LiteralHeaderSource}. Otherwise attempts to create a + * new {@link UrlHeaderSource} out of {@code headerPath} and {@code encoding}. + * + * @param inlineHeader the text of a lincense header template + * @param headerPath a path resolvable by the {@code finder} + * @param encoding the encoding to use when readinf {@code headerPath} + * @param finder the {@link ResourceFinder} to use to resolve {@code headerPath} + * @return a new {@link HeaderSource} + */ + public static HeaderSource of(String inlineHeader, String headerPath, String encoding, ResourceFinder finder) { + if (inlineHeader != null && !inlineHeader.isEmpty()) { + return new LiteralHeaderSource(inlineHeader); + } else if (headerPath == null) { + throw new IllegalArgumentException("Either inlineHeader or header path need to be specified"); + } else { + try { + final URL headerUrl = finder.findResource(headerPath); + return new UrlHeaderSource(headerUrl, encoding); + } catch (Exception e) { + throw new IllegalArgumentException( + "Cannot read header document " + headerPath + ". Cause: " + e.getMessage(), e); + } + } + } + + protected final String content; + private final boolean inline; + + public HeaderSource(String content, boolean inline) { + super(); + this.content = content; + this.inline = inline; + } + + /** + * @return the text of the license template + */ + public String getContent() { + return content; + } + + /** + * @return {@code true} if this {@link HeaderSource} was created from a string rather by loading the bits from an + * URL; {@code false} otherwise + */ + public boolean isInline() { + return inline; + } + + /** + * Retuns {@code true} if this {@link HeaderSource} was loaded from the URL given in the {@code location} parameter + * or {@code false} otherwise. + * + * @param location + * the URL to tell if this {@link HeaderSource} was loaded from it + * @return {@code true} if this {@link HeaderSource} was loaded from the URL given in the {@code location} parameter + * or {@code false} otherwise + */ + public abstract boolean isFromUrl(URL location); + +} diff --git a/license-maven-plugin/src/test/java/com/mycila/maven/plugin/license/document/DocumentTest.java b/license-maven-plugin/src/test/java/com/mycila/maven/plugin/license/document/DocumentTest.java index 9796e187b..505b24172 100755 --- a/license-maven-plugin/src/test/java/com/mycila/maven/plugin/license/document/DocumentTest.java +++ b/license-maven-plugin/src/test/java/com/mycila/maven/plugin/license/document/DocumentTest.java @@ -16,11 +16,13 @@ package com.mycila.maven.plugin.license.document; import com.mycila.maven.plugin.license.header.Header; +import com.mycila.maven.plugin.license.header.HeaderSource.UrlHeaderSource; import com.mycila.maven.plugin.license.util.FileUtils; import org.junit.BeforeClass; import org.junit.Test; import java.io.File; +import java.io.IOException; import java.net.MalformedURLException; import java.util.Properties; @@ -42,9 +44,9 @@ public Properties load(Document d) { }; @BeforeClass - public static void setup() throws MalformedURLException { + public static void setup() throws IOException { - header = new Header(new File("src/test/resources/test-header1.txt").toURI().toURL(), "UTF-8", null, null); + header = new Header(new UrlHeaderSource(new File("src/test/resources/test-header1.txt").toURI().toURL(), "UTF-8"), null); } @Test diff --git a/license-maven-plugin/src/test/java/com/mycila/maven/plugin/license/header/AdditionalHeaderDefinitionTest.java b/license-maven-plugin/src/test/java/com/mycila/maven/plugin/license/header/AdditionalHeaderDefinitionTest.java index 0cc57e80b..badf739c8 100755 --- a/license-maven-plugin/src/test/java/com/mycila/maven/plugin/license/header/AdditionalHeaderDefinitionTest.java +++ b/license-maven-plugin/src/test/java/com/mycila/maven/plugin/license/header/AdditionalHeaderDefinitionTest.java @@ -15,6 +15,7 @@ */ package com.mycila.maven.plugin.license.header; +import com.mycila.maven.plugin.license.header.HeaderSource.UrlHeaderSource; import com.mycila.maven.plugin.license.util.FileUtils; import com.mycila.xmltool.XMLDoc; import com.mycila.xmltool.XMLTag; @@ -49,7 +50,7 @@ public void test_load_definitions() throws Exception { assertEquals(loader.getDefinitions().get("xquery").getType(), "xquery"); assertNull(loader.getDefinitions().get("xquery").getSkipLinePattern()); - Header header = new Header(getClass().getResource("/test-header1.txt"), "UTF-8", null, null); + Header header = new Header(new UrlHeaderSource(getClass().getResource("/test-header1.txt"), "UTF-8"), null); //FileUtils.write(new File("src/test/resources/test-header3.txt"), header.buildForDefinition(loader.getDefinitions().get("xquery"))); @@ -74,7 +75,7 @@ public void test_load_definitions2() throws Exception { AdditionalHeaderDefinition loader = new AdditionalHeaderDefinition(def); - Header header = new Header(getClass().getResource("/check/header.txt"), "UTF-8", null, null); + Header header = new Header(new UrlHeaderSource(getClass().getResource("/check/header.txt"), "UTF-8"), null); System.out.println(header.buildForDefinition(loader.getDefinitions().get("text"), false)); } @@ -93,7 +94,7 @@ public void test_advanced_definitions() throws Exception { AdditionalHeaderDefinition loader = new AdditionalHeaderDefinition(def); - Header header = new Header(getClass().getResource("/test-header1.txt"), "UTF-8", null, null); + Header header = new Header(new UrlHeaderSource(getClass().getResource("/test-header1.txt"), "UTF-8"), null); //FileUtils.write(new File("src/test/resources/test-header4.txt"), header.buildForDefinition(loader.getDefinitions().get("csregion"), false), System.getProperty("file.encoding")); diff --git a/license-maven-plugin/src/test/java/com/mycila/maven/plugin/license/header/DefaultHeaderDefinitionTest.java b/license-maven-plugin/src/test/java/com/mycila/maven/plugin/license/header/DefaultHeaderDefinitionTest.java index 24e3252c2..4074034b2 100755 --- a/license-maven-plugin/src/test/java/com/mycila/maven/plugin/license/header/DefaultHeaderDefinitionTest.java +++ b/license-maven-plugin/src/test/java/com/mycila/maven/plugin/license/header/DefaultHeaderDefinitionTest.java @@ -15,6 +15,7 @@ */ package com.mycila.maven.plugin.license.header; +import com.mycila.maven.plugin.license.header.HeaderSource.UrlHeaderSource; import com.mycila.maven.plugin.license.util.FileUtils; import org.junit.Test; @@ -29,7 +30,7 @@ public final class DefaultHeaderDefinitionTest { @Test public void test_styles() throws Exception { - Header header = new Header(getClass().getResource("/test-header1.txt"), "UTF-8", null, null); + Header header = new Header(new UrlHeaderSource(getClass().getResource("/test-header1.txt"), "UTF-8"), null); for (HeaderDefinition definition : HeaderType.defaultDefinitions().values()) { final String content = FileUtils.read(new File(format("src/test/resources/styles/%s.txt", definition.getType())), System.getProperty("file.encoding")); assertEquals("Bad header for type: " + definition.getType(), content, header.buildForDefinition(definition, !containsWindowsLineEnding(content))); diff --git a/license-maven-plugin/src/test/java/com/mycila/maven/plugin/license/header/HeaderSourceTest.java b/license-maven-plugin/src/test/java/com/mycila/maven/plugin/license/header/HeaderSourceTest.java new file mode 100644 index 000000000..ccd29da86 --- /dev/null +++ b/license-maven-plugin/src/test/java/com/mycila/maven/plugin/license/header/HeaderSourceTest.java @@ -0,0 +1,49 @@ +package com.mycila.maven.plugin.license.header; + +import java.io.File; + +import org.junit.Assert; +import org.junit.Test; + +import com.mycila.maven.plugin.license.util.resource.ResourceFinder; + +public class HeaderSourceTest { + + private ResourceFinder finder = new ResourceFinder(new File("src/test/resources")); + + @Test + public void testOfInline() { + HeaderSource actual = HeaderSource.of("inline header", "single-line-header.txt", "utf-8", finder); + Assert.assertEquals("inline header", actual.getContent()); + Assert.assertEquals(true, actual.isInline()); + } + + @Test + public void testOfInlineOnly() { + HeaderSource actual = HeaderSource.of("inline header", null, null, null); + Assert.assertEquals("inline header", actual.getContent()); + Assert.assertEquals(true, actual.isInline()); + } + + @Test + public void testOfUrl() { + HeaderSource actual = HeaderSource.of(null, "single-line-header.txt", "utf-8", finder); + Assert.assertEquals("just a one line header file for copyright", actual.getContent()); + Assert.assertEquals(false, actual.isInline()); + + actual = HeaderSource.of("", "single-line-header.txt", "utf-8", finder); + Assert.assertEquals("just a one line header file for copyright", actual.getContent()); + Assert.assertEquals(false, actual.isInline()); + } + + @Test(expected=IllegalArgumentException.class) + public void testOfNulls() { + HeaderSource.of(null, null, "utf-8", finder); + } + + @Test(expected=IllegalArgumentException.class) + public void testOfEmptyAndNull() { + HeaderSource.of("", null, "utf-8", finder); + } + +} diff --git a/license-maven-plugin/src/test/java/com/mycila/maven/plugin/license/header/HeaderTest.java b/license-maven-plugin/src/test/java/com/mycila/maven/plugin/license/header/HeaderTest.java index d2a80d151..09fd5b815 100755 --- a/license-maven-plugin/src/test/java/com/mycila/maven/plugin/license/header/HeaderTest.java +++ b/license-maven-plugin/src/test/java/com/mycila/maven/plugin/license/header/HeaderTest.java @@ -16,10 +16,12 @@ package com.mycila.maven.plugin.license.header; import com.mycila.maven.plugin.license.HeaderSection; +import com.mycila.maven.plugin.license.header.HeaderSource.UrlHeaderSource; import com.mycila.maven.plugin.license.util.FileUtils; import org.junit.Test; import java.io.File; +import java.io.IOException; import static org.junit.Assert.*; @@ -29,10 +31,10 @@ public final class HeaderTest { @Test public void test() throws Exception { - Header header = new Header(getClass().getResource("/test-header1.txt"), "UTF-8", null, null); + Header header = new Header(new UrlHeaderSource(getClass().getResource("/test-header1.txt"), "UTF-8"), null); assertEquals(header.getLineCount(), 13); assertTrue(header.asOneLineString().contains("${year}")); - assertEquals(header.getLocation(), getClass().getResource("/test-header1.txt")); + assertTrue(header.getLocation().isFromUrl(getClass().getResource("/test-header1.txt"))); //FileUtils.write(new File("src/test/resources/test-header2.txt"), header.buildForDefinition(HeaderType.ASP.getDefinition(), false)); @@ -42,7 +44,7 @@ public void test() throws Exception { } @Test - public void testHeaderSections() { + public void testHeaderSections() throws IOException { HeaderSection section = new HeaderSection(); section.setKey("COPYRIGHT_SECTION"); @@ -51,8 +53,8 @@ public void testHeaderSections() { HeaderSection[] sections = { section }; - Header header = new Header(getClass().getResource("/test-header5.txt"), "UTF-8", sections, null); - + Header header = new Header(new UrlHeaderSource(getClass().getResource("/test-header5.txt"), "UTF-8"), sections); + HeaderDefinition headerDefinition = HeaderType.JAVADOC_STYLE.getDefinition(); StringBuilder h1 = new StringBuilder(); @@ -100,7 +102,7 @@ public void testHeaderSections() { } @Test - public void testHeaderSectionsWithAmbiguousSeparation() { + public void testHeaderSectionsWithAmbiguousSeparation() throws IOException { HeaderSection sectionA = new HeaderSection(); sectionA.setKey("COPYRIGHT_SECTION"); @@ -113,8 +115,8 @@ public void testHeaderSectionsWithAmbiguousSeparation() { HeaderSection[] sections = { sectionA, sectionB }; - Header header = new Header(getClass().getResource("/test-header6.txt"), "UTF-8", sections, null); - + Header header = new Header(new UrlHeaderSource(getClass().getResource("/test-header6.txt"), "UTF-8"), sections); + HeaderDefinition headerDefinition = HeaderType.JAVADOC_STYLE.getDefinition(); /** @@ -158,7 +160,7 @@ public void testHeaderSectionsWithAmbiguousSeparation() { } @Test - public void testHeaderSectionsWithMultiLineMatch() { + public void testHeaderSectionsWithMultiLineMatch() throws IOException { HeaderSection section = new HeaderSection(); section.setKey("COPYRIGHT_SECTION"); @@ -168,8 +170,8 @@ public void testHeaderSectionsWithMultiLineMatch() { HeaderSection[] sections = { section }; - Header header = new Header(getClass().getResource("/test-header5.txt"), "UTF-8", sections, null); - + Header header = new Header(new UrlHeaderSource(getClass().getResource("/test-header5.txt"), "UTF-8"), sections); + HeaderDefinition headerDefinition = HeaderType.JAVADOC_STYLE.getDefinition(); StringBuilder h1 = new StringBuilder(); From fd347b48f17fa16e15b1fbc2e9a3b4b41917ad15 Mon Sep 17 00:00:00 2001 From: Peter Palaga Date: Thu, 18 Aug 2016 13:47:54 +0200 Subject: [PATCH 2/2] Add inlineHeader tests --- .../maven/plugin/license/HeaderMojoTest.java | 15 +++++++++++++++ .../maven/plugin/license/UpdateMojoTest.java | 18 ++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/license-maven-plugin/src/test/java/com/mycila/maven/plugin/license/HeaderMojoTest.java b/license-maven-plugin/src/test/java/com/mycila/maven/plugin/license/HeaderMojoTest.java index d8e39728c..6228c26a9 100755 --- a/license-maven-plugin/src/test/java/com/mycila/maven/plugin/license/HeaderMojoTest.java +++ b/license-maven-plugin/src/test/java/com/mycila/maven/plugin/license/HeaderMojoTest.java @@ -18,6 +18,8 @@ import org.apache.maven.plugin.testing.stubs.MavenProjectStub; import org.junit.Test; +import com.mycila.maven.plugin.license.util.FileUtils; + import java.io.File; /** @@ -84,4 +86,17 @@ public void test_load_header_from_plugin_classpath() throws Exception { check.execute(); } + @Test + public void test_inlineHeader() throws Exception { + MavenProjectStub project = new MavenProjectStub(); + LicenseCheckMojo check = new LicenseCheckMojo(); + check.basedir = new File("src/test/resources/check"); + check.inlineHeader = FileUtils.read(new File("src/test/resources/check/header.txt"), "utf-8"); + check.project = project; + check.failIfMissing = false; + check.strictCheck = true; + check.execute(); + } + + } 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 dccf5200b..0a3525c18 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 @@ -56,6 +56,24 @@ public void test_update() throws Exception { assertEquals(FileUtils.read(new File(tmp, "doc2.txt"), System.getProperty("file.encoding")), "====\r\n My @Copyright license 2 with my-custom-value and 2008 and doc2.txt\r\n====\r\n\r\nsome data\r\n"); } + @Test + public void test_update_inlineHeader() throws Exception { + File tmp = new File("target/test/update-inlineHeader"); + tmp.mkdirs(); + FileUtils.copyFileToFolder(new File("src/test/resources/update/doc1.txt"), tmp); + FileUtils.copyFileToFolder(new File("src/test/resources/update/doc2.txt"), tmp); + + LicenseFormatMojo updater = new LicenseFormatMojo(); + updater.basedir = tmp; + updater.inlineHeader = FileUtils.read(new File("src/test/resources/update/header.txt"), "utf-8"); + updater.project = new MavenProjectStub(); + updater.properties = ImmutableMap.of("year", "2008"); + updater.execute(); + + assertEquals(FileUtils.read(new File(tmp, "doc1.txt"), System.getProperty("file.encoding")), "====\r\n My @Copyright license 2 with my-custom-value and 2008 and doc1.txt\r\n====\r\n\r\nsome data\r\n"); + assertEquals(FileUtils.read(new File(tmp, "doc2.txt"), System.getProperty("file.encoding")), "====\r\n My @Copyright license 2 with my-custom-value and 2008 and doc2.txt\r\n====\r\n\r\nsome data\r\n"); + } + @Test public void test_skipExistingHeaders() throws Exception { File tmp = new File("target/test/test_skipExistingHeaders");