Maven-license-plugin-commits
Threads by month
- ----- 2026 -----
- June
- May
- April
- March
- February
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- 268 discussions
r1721 - trunk/src/it/update-header-file/src/main/java/org/nuiton/license/plugin/test
by tchemit@users.nuiton.org 08 Apr '10
by tchemit@users.nuiton.org 08 Apr '10
08 Apr '10
Author: tchemit
Date: 2010-04-08 22:03:11 +0200 (Thu, 08 Apr 2010)
New Revision: 1721
Log:
add a test file with existing header
Added:
trunk/src/it/update-header-file/src/main/java/org/nuiton/license/plugin/test/MyBean2.java
Added: trunk/src/it/update-header-file/src/main/java/org/nuiton/license/plugin/test/MyBean2.java
===================================================================
--- trunk/src/it/update-header-file/src/main/java/org/nuiton/license/plugin/test/MyBean2.java (rev 0)
+++ trunk/src/it/update-header-file/src/main/java/org/nuiton/license/plugin/test/MyBean2.java 2010-04-08 20:03:11 UTC (rev 1721)
@@ -0,0 +1,20 @@
+/*
+ * #%L
+ * License Test :: do NOT update!
+ * --
+ * Copyright (C) 2010 Tony
+ * --
+ * Fake to be removed!
+ * #L%
+ */
+
+/**
+ * this class owns a header, only license will be updated.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 2.1
+ */
+package org.nuiton.license.plugin.test;
+
+public class MyBean2 {
+}
Property changes on: trunk/src/it/update-header-file/src/main/java/org/nuiton/license/plugin/test/MyBean2.java
___________________________________________________________________
Added: svn:keywords
+ "Author Date Id Revision HeadURL
1
0
r1720 - in trunk/src: it/update-header-file it/update-header-file/src/main/java/org/nuiton/license/plugin/test main/java/org/nuiton/license/plugin main/java/org/nuiton/license/plugin/header/transformer test/java/org/nuiton/license/plugin/header/transformer
by tchemit@users.nuiton.org 08 Apr '10
by tchemit@users.nuiton.org 08 Apr '10
08 Apr '10
Author: tchemit
Date: 2010-04-08 22:00:56 +0200 (Thu, 08 Apr 2010)
New Revision: 1720
Log:
fix license header content formating + implements update only license
Modified:
trunk/src/it/update-header-file/pom.xml
trunk/src/it/update-header-file/src/main/java/org/nuiton/license/plugin/test/MyBean.java
trunk/src/it/update-header-file/verify.groovy
trunk/src/main/java/org/nuiton/license/plugin/UpdateHeaderFileMojo.java
trunk/src/main/java/org/nuiton/license/plugin/header/transformer/AbstractFileHeaderTransformer.java
trunk/src/main/java/org/nuiton/license/plugin/header/transformer/FileHeaderTransformer.java
trunk/src/test/java/org/nuiton/license/plugin/header/transformer/AbstractFileHeaderTransformerTest.java
Modified: trunk/src/it/update-header-file/pom.xml
===================================================================
--- trunk/src/it/update-header-file/pom.xml 2010-04-08 17:55:28 UTC (rev 1719)
+++ trunk/src/it/update-header-file/pom.xml 2010-04-08 20:00:56 UTC (rev 1720)
@@ -25,8 +25,11 @@
<packaging>jar</packaging>
- <inceptionYear>2010</inceptionYear>
-
+ <inceptionYear>2012</inceptionYear>
+
+ <organization>
+ <name>License Test</name>
+ </organization>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
Modified: trunk/src/it/update-header-file/src/main/java/org/nuiton/license/plugin/test/MyBean.java
===================================================================
--- trunk/src/it/update-header-file/src/main/java/org/nuiton/license/plugin/test/MyBean.java 2010-04-08 17:55:28 UTC (rev 1719)
+++ trunk/src/it/update-header-file/src/main/java/org/nuiton/license/plugin/test/MyBean.java 2010-04-08 20:00:56 UTC (rev 1720)
@@ -1,4 +1,10 @@
package org.nuiton.license.plugin.test;
+/**
+ * this class has no license, a new default one will be added.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 2.1
+ */
public class MyBean {
}
Modified: trunk/src/it/update-header-file/verify.groovy
===================================================================
--- trunk/src/it/update-header-file/verify.groovy 2010-04-08 17:55:28 UTC (rev 1719)
+++ trunk/src/it/update-header-file/verify.groovy 2010-04-08 20:00:56 UTC (rev 1720)
@@ -3,6 +3,14 @@
assert file.exists();
content = file.text;
-//assert content.contains( 'Copyright' );
+assert content.contains( 'Copyright (C) 2012 License Test' );
+file = new File(basedir, 'src/main/java/org/nuiton/license/plugin/test/MyBean2.java');
+assert file.exists();
+
+content = file.text;
+assert content.contains( 'Copyright (C) 2010 Tony' );
+assert content.contains( 'do NOT update!' );
+assert !content.contains( 'Fake to be removed!' );
+
return true;
Modified: trunk/src/main/java/org/nuiton/license/plugin/UpdateHeaderFileMojo.java
===================================================================
--- trunk/src/main/java/org/nuiton/license/plugin/UpdateHeaderFileMojo.java 2010-04-08 17:55:28 UTC (rev 1719)
+++ trunk/src/main/java/org/nuiton/license/plugin/UpdateHeaderFileMojo.java 2010-04-08 20:00:56 UTC (rev 1720)
@@ -5,6 +5,7 @@
import org.nuiton.license.plugin.header.FileHeader;
import org.nuiton.license.plugin.header.FileHeaderFilter;
import org.nuiton.license.plugin.header.FileHeaderProcessor;
+import org.nuiton.license.plugin.header.transformer.AbstractFileHeaderTransformer;
import org.nuiton.license.plugin.header.transformer.FileHeaderTransformer;
import org.nuiton.license.plugin.model.License;
import org.nuiton.license.plugin.model.LicenseStore;
@@ -133,7 +134,12 @@
@Override
protected void init() throws Exception {
+ if (getLog().isDebugEnabled()) {
+ // always be verbose in debug mode
+ setVerbose(true);
+ }
+
if (skipUpdateHeader) {
return;
}
@@ -153,54 +159,20 @@
// check that license project is sane (known licenses + header types)
// + populate default license name in LicenseSet (with main License)
validateProjectfile(licenseProject, licenseStore, transformers);
-
-
}
@Override
protected void doAction() throws Exception {
// create a file header processor which updates license content only
- FileHeaderProcessor processor = new FileHeaderProcessor() {
+ FileHeaderProcessor processor = new UpdateHeaderLicenseProcessor();
- @Override
- public FileHeaderFilter newFilter(FileHeader header, FileHeaderTransformer transformer) {
- return new FileHeaderFilter(header, transformer) {
- @Override
- protected String treateHeader(String ch) {
-
- // unbox comment
- String unbox = transformer.unboxComent(ch);
-
- // obtain current license of file
-
- FileHeader fileHeader = transformer.toFileHeader(unbox);
-
- // updates license
- fileHeader.setLicense(header.getLicense());
-
- // build new brut header (with no boxing)
-
- String newHeader = transformer.toString(fileHeader);
-
- //TODO-TC-20100408 must box header with comment prefix
-
- // box with process tag
- newHeader = transformer.boxProcessTag(newHeader);
-
- if (getLog().isDebugEnabled()) {
- getLog().debug("new Header =\n" + newHeader);
- }
- return newHeader;
- }
- };
- }
- };
-
for (LicenseSet licenseSet : licenseProject.getLicenseSets()) {
String licenseName = licenseSet.getLicenseName();
License license = licenseStore.getLicense(licenseName);
+ getLog().info("process license \n" + license.getDescription());
+
// file header to use if no header is found on a file
FileHeader defaultFileHeader = buildDefaultFileHeader(
license,
@@ -235,13 +207,13 @@
transformers.get(fileSet.getHeaderType());
processor.setTransformer(transformer);
- updateHeader(processor, filestoTreate);
+ updateFiles(processor, filestoTreate);
}
}
}
- public void updateHeader(FileHeaderProcessor processor,
- Map<File, String[]> filestoTreate) throws IOException {
+ public void updateFiles(FileHeaderProcessor processor,
+ Map<File, String[]> filestoTreate) throws IOException {
FileHeaderTransformer transformer = processor.getTransformer();
FileHeader header = processor.getHeader();
@@ -252,7 +224,7 @@
String defaultFullHeaderContent = transformer.boxProcessTag(defaultHeaderContent);
getLog().info("default header (process tag boxed) :\n" + defaultFullHeaderContent);
- defaultFullHeaderContent = transformer.boxComment(defaultFullHeaderContent);
+ defaultFullHeaderContent = transformer.boxComment(defaultFullHeaderContent, true);
getLog().info("default header to use :\n" + defaultFullHeaderContent);
for (Map.Entry<File, String[]> entry : filestoTreate.entrySet()) {
@@ -270,21 +242,25 @@
public void updateFile(FileHeaderProcessor processor,
File file,
String defaultFullHeaderContent) throws IOException {
- getLog().info("scan file " + file);
+ getLog().debug("scan file " + file);
- if (isVerbose()) {
- getLog().info("process file " + file);
- }
// file where to writeFile result
File processFile = new File(file.getAbsolutePath() + "_" +
timestamp);
+ if (isVerbose()) {
+ getLog().info("process file " + file);
+ }
+
try {
processor.process(file, processFile);
- boolean foundLicenseHeader = processor.isTouched();
+ boolean touched = processor.isTouched();
- if (!foundLicenseHeader) {
+ if (touched) {
+
+ getLog().info("header was updated for " + file);
+ } else {
if (processor.isDetectHeader()) {
getLog().warn(
"skip file " + file +
@@ -442,11 +418,54 @@
Calendar cal = Calendar.getInstance();
cal.setTime(new Date());
Integer lastYear = cal.get(Calendar.YEAR);
- if (firstYear.equals(lastYear)) {
+ if (firstYear < lastYear) {
result.setCopyrightLastYear(lastYear);
}
result.setCopyrightHolder(copyrightHolder);
return result;
}
+ public class UpdateHeaderLicenseProcessor extends FileHeaderProcessor {
+
+ @Override
+ public FileHeaderFilter newFilter(FileHeader header, FileHeaderTransformer transformer) {
+ return new FileHeaderFilter(header, transformer) {
+ @Override
+ protected String treateHeader(String ch) {
+
+ // unbox comment
+ String unbox = transformer.unboxComent(ch);
+
+ // obtain current license of file
+
+ FileHeader fileHeader = transformer.toFileHeader(unbox);
+
+ // updates license
+ fileHeader.setLicense(header.getLicense());
+
+ // build new brut header (with no boxing)
+
+ String newHeader = transformer.toString(fileHeader);
+
+ // box with process tag
+ newHeader = transformer.boxProcessTag(newHeader);
+
+ // box header with comment prefix
+ newHeader = transformer.boxComment(newHeader, false);
+
+ int index = newHeader.indexOf(transformer.getProcessStartTag());
+
+ String result = newHeader.substring(index);
+ while (result.charAt(result.length() - 1) == AbstractFileHeaderTransformer.LINE_SEPARATOR) {
+ result = result.substring(0, result.length() - 1);
+ }
+ if (isVerbose()) {
+ getLog().debug("new Header =\n" + result);
+ }
+
+ return result;
+ }
+ };
+ }
+ }
}
Modified: trunk/src/main/java/org/nuiton/license/plugin/header/transformer/AbstractFileHeaderTransformer.java
===================================================================
--- trunk/src/main/java/org/nuiton/license/plugin/header/transformer/AbstractFileHeaderTransformer.java 2010-04-08 17:55:28 UTC (rev 1719)
+++ trunk/src/main/java/org/nuiton/license/plugin/header/transformer/AbstractFileHeaderTransformer.java 2010-04-08 20:00:56 UTC (rev 1720)
@@ -6,11 +6,9 @@
import java.util.regex.Pattern;
/**
- * Abstract implementation of {@link FileHeaderTransformer} which does NOT deal
- * with the boxing-unboxing part, but just with transformation methods, since
- * they are common to any transformer.
+ * Abstract implementation of {@link FileHeaderTransformer}.
* <p/>
- * Concrete implementation should just has to deal with to boxing stuff.
+ * Concrete implementation should only have to give comment configuration.
*
* @author tchemit <chemit(a)codelutin.com>
* @since 2.1
@@ -219,15 +217,19 @@
}
@Override
- public String boxComment(String header) {
+ public String boxComment(String header, boolean withTags) {
StringBuilder buffer = new StringBuilder();
- buffer.append(getCommentStartTag()).append(LINE_SEPARATOR);
+ if (withTags) {
+ buffer.append(getCommentStartTag()).append(LINE_SEPARATOR);
+ }
for (String line : header.split(LINE_SEPARATOR + "")) {
buffer.append(getCommentLinePrefix());
buffer.append(line);
buffer.append(LINE_SEPARATOR);
}
- buffer.append(getCommentEndTag()).append(LINE_SEPARATOR);
+ if (withTags) {
+ buffer.append(getCommentEndTag()).append(LINE_SEPARATOR);
+ }
return buffer.toString();
}
@@ -254,7 +256,6 @@
return buffer.toString();
}
-
@Override
public String boxProcessTag(String header) {
StringBuilder buffer = new StringBuilder();
Modified: trunk/src/main/java/org/nuiton/license/plugin/header/transformer/FileHeaderTransformer.java
===================================================================
--- trunk/src/main/java/org/nuiton/license/plugin/header/transformer/FileHeaderTransformer.java 2010-04-08 17:55:28 UTC (rev 1719)
+++ trunk/src/main/java/org/nuiton/license/plugin/header/transformer/FileHeaderTransformer.java 2010-04-08 20:00:56 UTC (rev 1720)
@@ -3,7 +3,7 @@
import org.nuiton.license.plugin.header.FileHeader;
/**
- * Contract to transform a file header to {@link org.nuiton.license.plugin.header.FileHeader} in both way :
+ * Contract to transform a file header to {@link FileHeader} in both way :
* <p/>
* <ul>
* <li>Obtain a object representation of a file header from a existing file
@@ -15,7 +15,7 @@
* Moreover the contract offers tow method to box and unbox a String
* representation of a header content :
* <ul>
- * <li>{@link #boxComment(String)}</li>
+ * <li>{@link #boxComment(String, boolean)}</li>
* <li>{@link #unboxComent(String)}</li>
* </ul>
*
@@ -28,7 +28,7 @@
String ROLE_NAME = FileHeaderTransformer.class.getName();
/** default section delimiter */
- String DEFAULT_SECTION_DELIMITER = "%--";
+ String DEFAULT_SECTION_DELIMITER = "--";
/** default process start tag */
String DEFAULT_PROCESS_START_TAG = "#%L";
@@ -118,9 +118,10 @@
* Box the given {@code header} in a comment.
*
* @param header the header content WITHOUT any comment boxing
+ * @param withTags flag to add start and end comment tags.
* @return the header content WITH comment boxing
*/
- String boxComment(String header);
+ String boxComment(String header, boolean withTags);
/**
* Unbox the given boxed {@code boxedHeader} to obtain the header content.
@@ -152,7 +153,7 @@
String unboxProcessTag(String boxedHeader);
/**
- * Build a {@link org.nuiton.license.plugin.header.FileHeader} from an UNBOXED header content.
+ * Build a {@link FileHeader} from an UNBOXED header content.
*
* @param header unboxed header content
* @return The model of the header content
Modified: trunk/src/test/java/org/nuiton/license/plugin/header/transformer/AbstractFileHeaderTransformerTest.java
===================================================================
--- trunk/src/test/java/org/nuiton/license/plugin/header/transformer/AbstractFileHeaderTransformerTest.java 2010-04-08 17:55:28 UTC (rev 1719)
+++ trunk/src/test/java/org/nuiton/license/plugin/header/transformer/AbstractFileHeaderTransformerTest.java 2010-04-08 20:00:56 UTC (rev 1720)
@@ -192,7 +192,7 @@
String boxedHeader;
header = transformer.toString(model1);
- boxedHeader = transformer.boxComment(header);
+ boxedHeader = transformer.boxComment(header, true);
Assert.assertEquals(
COMMENT_START_TAG + LINE_SEPARATOR +
@@ -205,8 +205,20 @@
boxedHeader
);
+ boxedHeader = transformer.boxComment(header, false);
+
+ Assert.assertEquals(
+ COMMENT_LINE_PREFIX + "Description" + LINE_SEPARATOR +
+ COMMENT_LINE_PREFIX + DEFAULT_SECTION_DELIMITER + LINE_SEPARATOR +
+ COMMENT_LINE_PREFIX + "Copyright (C) 2010 Tony" + LINE_SEPARATOR +
+ COMMENT_LINE_PREFIX + DEFAULT_SECTION_DELIMITER + LINE_SEPARATOR +
+ COMMENT_LINE_PREFIX + "License" + LINE_SEPARATOR,
+ boxedHeader
+ );
+
header = transformer.toString(model2);
- boxedHeader = transformer.boxComment(header);
+
+ boxedHeader = transformer.boxComment(header, true);
Assert.assertEquals(
COMMENT_START_TAG + LINE_SEPARATOR +
COMMENT_LINE_PREFIX + "Description2" + LINE_SEPARATOR +
@@ -217,6 +229,16 @@
COMMENT_END_TAG + LINE_SEPARATOR,
boxedHeader
);
+
+ boxedHeader = transformer.boxComment(header, false);
+ Assert.assertEquals(
+ COMMENT_LINE_PREFIX + "Description2" + LINE_SEPARATOR +
+ COMMENT_LINE_PREFIX + DEFAULT_SECTION_DELIMITER + LINE_SEPARATOR +
+ COMMENT_LINE_PREFIX + "Copyright (C) 2010 - 2012 Tony2" + LINE_SEPARATOR +
+ COMMENT_LINE_PREFIX + DEFAULT_SECTION_DELIMITER + LINE_SEPARATOR +
+ COMMENT_LINE_PREFIX + "License2" + LINE_SEPARATOR,
+ boxedHeader
+ );
}
@Test
@@ -226,13 +248,13 @@
String unboxedHeader;
header = transformer.toString(model1);
- boxedHeader = transformer.boxComment(header);
+ boxedHeader = transformer.boxComment(header, true);
unboxedHeader = transformer.unboxComent(boxedHeader);
Assert.assertEquals(header, unboxedHeader);
header = transformer.toString(model2);
- boxedHeader = transformer.boxComment(header);
+ boxedHeader = transformer.boxComment(header, true);
unboxedHeader = transformer.unboxComent(boxedHeader);
Assert.assertEquals(header, unboxedHeader);
1
0
08 Apr '10
Author: tchemit
Date: 2010-04-08 19:55:28 +0200 (Thu, 08 Apr 2010)
New Revision: 1719
Log:
continue update-file-header mojo (just need to rebox (comment) updated header)
Added:
trunk/src/main/java/org/nuiton/license/plugin/header/FileHeader.java
trunk/src/main/java/org/nuiton/license/plugin/header/FileHeaderFilter.java
trunk/src/main/java/org/nuiton/license/plugin/header/FileHeaderProcessor.java
trunk/src/main/java/org/nuiton/license/plugin/header/transformer/
trunk/src/main/java/org/nuiton/license/plugin/header/transformer/AbstractFileHeaderTransformer.java
trunk/src/main/java/org/nuiton/license/plugin/header/transformer/AptFileHeaderTransformer.java
trunk/src/main/java/org/nuiton/license/plugin/header/transformer/FileHeaderTransformer.java
trunk/src/main/java/org/nuiton/license/plugin/header/transformer/JavaFileHeaderTransformer.java
trunk/src/main/java/org/nuiton/license/plugin/header/transformer/PropertiesFileHeaderTransformer.java
trunk/src/main/java/org/nuiton/license/plugin/header/transformer/XmlFileHeaderTransformer.java
trunk/src/test/java/org/nuiton/license/plugin/header/
trunk/src/test/java/org/nuiton/license/plugin/header/transformer/
trunk/src/test/java/org/nuiton/license/plugin/header/transformer/AbstractFileHeaderTransformerTest.java
Modified:
trunk/src/it/update-header-file/pom.xml
trunk/src/it/update-header-file/src/license/project.xml
trunk/src/main/java/org/nuiton/license/plugin/AddLicenseFileMojo.java
trunk/src/main/java/org/nuiton/license/plugin/AddThirdPartyFileMojo.java
trunk/src/main/java/org/nuiton/license/plugin/UpdateHeaderFileMojo.java
trunk/src/main/java/org/nuiton/license/plugin/UpdateHeaderMojo.java
trunk/src/main/java/org/nuiton/license/plugin/model/LicenseRepository.java
trunk/src/main/mdo/descriptor.mdo
Modified: trunk/src/it/update-header-file/pom.xml
===================================================================
--- trunk/src/it/update-header-file/pom.xml 2010-04-07 10:21:25 UTC (rev 1718)
+++ trunk/src/it/update-header-file/pom.xml 2010-04-08 17:55:28 UTC (rev 1719)
@@ -3,59 +3,64 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
- <modelVersion>4.0.0</modelVersion>
+ <modelVersion>4.0.0</modelVersion>
- <!-- ************************************************************* -->
- <!-- *** POM Relationships *************************************** -->
- <!-- ************************************************************* -->
+ <!-- ************************************************************* -->
+ <!-- *** POM Relationships *************************************** -->
+ <!-- ************************************************************* -->
- <groupId>org.nuiton.license.test</groupId>
- <artifactId>test-update-header-file</artifactId>
- <version>@pom.version@</version>
+ <groupId>org.nuiton.license.test</groupId>
+ <artifactId>test-update-header-file</artifactId>
+ <version>@pom.version@</version>
- <!-- ************************************************************* -->
- <!-- *** Project Information ************************************* -->
- <!-- ************************************************************* -->
+ <!-- ************************************************************* -->
+ <!-- *** Project Information ************************************* -->
+ <!-- ************************************************************* -->
- <name>License Test :: update-header-file</name>
+ <name>License Test :: update-header-file</name>
- <!-- ************************************************************* -->
- <!-- *** Build Settings ****************************************** -->
- <!-- ************************************************************* -->
+ <!-- ************************************************************* -->
+ <!-- *** Build Settings ****************************************** -->
+ <!-- ************************************************************* -->
- <packaging>jar</packaging>
+ <packaging>jar</packaging>
- <build>
+ <inceptionYear>2010</inceptionYear>
+
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ </properties>
+ <build>
- <plugins>
+ <plugins>
- <plugin>
- <groupId>org.nuiton</groupId>
- <artifactId>maven-license-plugin</artifactId>
- <version>@pom.version@</version>
- <configuration>
- <verbose>true</verbose>
- </configuration>
- <executions>
- <execution>
- <id>first</id>
- <goals>
- <goal>update-header-file</goal>
- </goals>
- <phase>process-sources</phase>
- </execution>
- <execution>
- <!-- this execution is to test with no files -->
- <id>second</id>
- <goals>
- <goal>update-header-file</goal>
- </goals>
- <phase>compile</phase>
- </execution>
- </executions>
- </plugin>
- </plugins>
- </build>
+ <plugin>
+ <groupId>org.nuiton</groupId>
+ <artifactId>maven-license-plugin</artifactId>
+ <version>@pom.version@</version>
+ <configuration>
+ <verbose>true</verbose>
+ </configuration>
+ <executions>
+ <execution>
+ <id>first</id>
+ <goals>
+ <goal>update-header-file</goal>
+ </goals>
+ <phase>process-sources</phase>
+ </execution>
+ <execution>
+ <!-- this execution is to test with no files -->
+ <id>second</id>
+ <goals>
+ <goal>update-header-file</goal>
+ </goals>
+ <phase>compile</phase>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
</project>
Modified: trunk/src/it/update-header-file/src/license/project.xml
===================================================================
--- trunk/src/it/update-header-file/src/license/project.xml 2010-04-07 10:21:25 UTC (rev 1718)
+++ trunk/src/it/update-header-file/src/license/project.xml 2010-04-08 17:55:28 UTC (rev 1719)
@@ -8,7 +8,7 @@
<licenseName>gpl_v3</licenseName>
<fileSets>
<fileSet>
- <headerType>license-java</headerType>
+ <headerType>java</headerType>
<basedir>src/main/java</basedir>
<includes>
<include>**/*.java</include>
Modified: trunk/src/main/java/org/nuiton/license/plugin/AddLicenseFileMojo.java
===================================================================
--- trunk/src/main/java/org/nuiton/license/plugin/AddLicenseFileMojo.java 2010-04-07 10:21:25 UTC (rev 1718)
+++ trunk/src/main/java/org/nuiton/license/plugin/AddLicenseFileMojo.java 2010-04-08 17:55:28 UTC (rev 1719)
@@ -179,7 +179,7 @@
File destFile = PluginHelper.getFile(
outputDirectory,
"META-INF", getProject().getArtifactId() + "-" +
- licenseFile.getName()
+ licenseFile.getName()
);
copyFile(licenseFile, destFile);
}
Modified: trunk/src/main/java/org/nuiton/license/plugin/AddThirdPartyFileMojo.java
===================================================================
--- trunk/src/main/java/org/nuiton/license/plugin/AddThirdPartyFileMojo.java 2010-04-07 10:21:25 UTC (rev 1718)
+++ trunk/src/main/java/org/nuiton/license/plugin/AddThirdPartyFileMojo.java 2010-04-08 17:55:28 UTC (rev 1719)
@@ -229,7 +229,7 @@
copyFile(thirdPartyFile, new File(
outputDirectory,
"META-INF" + File.separator + getProject().getArtifactId() +
- "-" + thirdPartyFile.getName())
+ "-" + thirdPartyFile.getName())
);
}
addResourceDir(outputDirectory, "**/*.txt");
@@ -259,7 +259,7 @@
// this dependency is not included, so do not treate it
if (isVerbose()) {
getLog().info("do not include this dependency " +
- node.toNodeString());
+ node.toNodeString());
}
return;
}
@@ -285,7 +285,7 @@
for (Object o : licenses) {
if (o == null) {
getLog().warn("could not acquire the license for "
- + artifactName);
+ + artifactName);
continue;
}
License license = (License) o;
@@ -310,7 +310,7 @@
protected String buildGroupedLicenses(LicenseMap licenseMap) {
StringBuilder sb = new StringBuilder();
sb.append("List of third-party dependencies grouped by " +
- "their license type.");
+ "their license type.");
for (String licenseName : licenseMap.keySet()) {
sb.append("\n\n").append(licenseName).append(" : ");
Modified: trunk/src/main/java/org/nuiton/license/plugin/UpdateHeaderFileMojo.java
===================================================================
--- trunk/src/main/java/org/nuiton/license/plugin/UpdateHeaderFileMojo.java 2010-04-07 10:21:25 UTC (rev 1718)
+++ trunk/src/main/java/org/nuiton/license/plugin/UpdateHeaderFileMojo.java 2010-04-08 17:55:28 UTC (rev 1719)
@@ -1,19 +1,23 @@
package org.nuiton.license.plugin;
+import org.apache.commons.lang.StringUtils;
import org.apache.maven.plugin.MojoFailureException;
-import org.codehaus.plexus.velocity.VelocityComponent;
-import org.nuiton.license.plugin.header.generator.HeaderGenerator;
+import org.nuiton.license.plugin.header.FileHeader;
+import org.nuiton.license.plugin.header.FileHeaderFilter;
+import org.nuiton.license.plugin.header.FileHeaderProcessor;
+import org.nuiton.license.plugin.header.transformer.FileHeaderTransformer;
+import org.nuiton.license.plugin.model.License;
import org.nuiton.license.plugin.model.LicenseStore;
import org.nuiton.license.plugin.model.project.FileSet;
import org.nuiton.license.plugin.model.project.LicenseProject;
import org.nuiton.license.plugin.model.project.LicenseSet;
import org.nuiton.license.plugin.model.project.io.xpp3.LicenseProjectXpp3Reader;
+import org.nuiton.plugin.PluginHelper;
import java.io.File;
import java.io.FileReader;
-import java.util.Arrays;
-import java.util.List;
-import java.util.Map;
+import java.io.IOException;
+import java.util.*;
/**
* The goal to update (or add) the licence header on some files.
@@ -68,15 +72,6 @@
*/
protected String projectName;
-// /**
-// * Le type de license a appliquer.
-// *
-// * @parameter expression="${license.licenseName}"
-// * @required
-// * @since 2.1
-// */
-// protected String licenseName;
-
/**
* To specify an external licenses repository resolver (says the base url
* of the repository).
@@ -86,12 +81,11 @@
*/
protected String licenseResolver;
-
/**
* A flag to keep a backup of every modified file.
*
* @parameter expression="${license.keepBackup}" default-value="false"
- * @since 1.0.0
+ * @since 2.1
*/
protected boolean keepBackup;
@@ -99,7 +93,7 @@
* A flag to skip the goal.
*
* @parameter expression="${skipUpdateHeader}" default-value="false"
- * @since 1.0.3
+ * @since 2.1
*/
protected boolean skipUpdateHeader;
@@ -107,25 +101,18 @@
* A flag to test plugin but modify no file.
*
* @parameter expression="${dryRun}" default-value="false"
- * @since 1.0.3
+ * @since 2.1
*/
protected boolean dryRun;
/**
- * Velocity Component.
+ * All available header transformers.
*
- * @component roleHint="maven-license-plugin"
- * @since 2.0.0
+ * @component role="org.nuiton.license.plugin.header.transformer.FileHeaderTransformer"
+ * @since 2.1
*/
- protected VelocityComponent velocity;
+ protected Map<String, FileHeaderTransformer> transformers;
- /**
- * All available generators.
- *
- * @component role="org.nuiton.license.plugin.header.generator.HeaderGenerator"
- */
- protected Map<String, HeaderGenerator> _generators;
-
/** timestamp used for generation */
protected long timestamp;
@@ -136,8 +123,22 @@
protected LicenseProject licenseProject;
@Override
+ protected boolean checkSkip() {
+ if (skipUpdateHeader) {
+ getLog().info("skip flag is on, will skip goal.");
+ return false;
+ }
+ return super.checkSkip();
+ }
+
+ @Override
protected void init() throws Exception {
+ if (skipUpdateHeader) {
+ return;
+ }
+ timestamp = System.nanoTime();
+
// init licenses store
licenseStore = createLicenseStore(licenseResolver);
@@ -149,41 +150,185 @@
reader.close();
}
- List<String> licenseNames = Arrays.asList(licenseStore.getLicenseNames());
+ // check that license project is sane (known licenses + header types)
+ // + populate default license name in LicenseSet (with main License)
+ validateProjectfile(licenseProject, licenseStore, transformers);
- // check licenses is known
- String mainLicense = licenseProject.getMainLicense();
- if (licenseStore.getLicense(mainLicense) == null) {
- throw new MojoFailureException(
- "main license '" + mainLicense +
- "' is unknown, use one of " + licenseNames);
- }
- for (LicenseSet licenseSet : licenseProject.getLicenseSets()) {
- // check license name
- String licenseName = licenseSet.getLicenseName();
- if (licenseStore.getLicense(licenseName) == null) {
- throw new MojoFailureException(
- "license '" + licenseName +
- "' is unknown, use one of " + licenseNames);
+ }
+
+ @Override
+ protected void doAction() throws Exception {
+
+ // create a file header processor which updates license content only
+ FileHeaderProcessor processor = new FileHeaderProcessor() {
+
+ @Override
+ public FileHeaderFilter newFilter(FileHeader header, FileHeaderTransformer transformer) {
+ return new FileHeaderFilter(header, transformer) {
+ @Override
+ protected String treateHeader(String ch) {
+
+ // unbox comment
+ String unbox = transformer.unboxComent(ch);
+
+ // obtain current license of file
+
+ FileHeader fileHeader = transformer.toFileHeader(unbox);
+
+ // updates license
+ fileHeader.setLicense(header.getLicense());
+
+ // build new brut header (with no boxing)
+
+ String newHeader = transformer.toString(fileHeader);
+
+ //TODO-TC-20100408 must box header with comment prefix
+
+ // box with process tag
+ newHeader = transformer.boxProcessTag(newHeader);
+
+ if (getLog().isDebugEnabled()) {
+ getLog().debug("new Header =\n" + newHeader);
+ }
+ return newHeader;
+ }
+ };
}
+ };
- // check header types (for each file set)
+ for (LicenseSet licenseSet : licenseProject.getLicenseSets()) {
+ String licenseName = licenseSet.getLicenseName();
+ License license = licenseStore.getLicense(licenseName);
+
+ // file header to use if no header is found on a file
+ FileHeader defaultFileHeader = buildDefaultFileHeader(
+ license,
+ getProjectName(),
+ getInceptionYear(),
+ getOrganizationName(),
+ getEncoding()
+ );
+
+ processor.setHeader(defaultFileHeader);
+
for (FileSet fileSet : licenseSet.getFileSets()) {
- String headerType = fileSet.getHeaderType();
- if (!_generators.containsKey(headerType)) {
- throw new MojoFailureException(
- "headerType '" + headerType +
- "' is unknown, use one of " + _generators.keySet());
+ File basedir = new File(getProject().getBasedir(), fileSet.getBasedir());
+ List<String> includes = fileSet.getIncludes();
+ if (includes.isEmpty()) {
+
+ // it means include all
+ includes.add("**/*");
}
+ List<String> excludes = fileSet.getExcludes();
+
+ Map<File, String[]> filestoTreate = new TreeMap<File, String[]>();
+ getFilesToTreateForRoots(
+ includes.toArray(new String[includes.size()]),
+ excludes.isEmpty() ? null :
+ excludes.toArray(new String[excludes.size()]),
+ Arrays.asList(basedir.getAbsolutePath()),
+ filestoTreate,
+ null
+ );
+ FileHeaderTransformer transformer =
+ transformers.get(fileSet.getHeaderType());
+ processor.setTransformer(transformer);
+
+ updateHeader(processor, filestoTreate);
}
}
}
- @Override
- protected void doAction() throws Exception {
+ public void updateHeader(FileHeaderProcessor processor,
+ Map<File, String[]> filestoTreate) throws IOException {
+
+ FileHeaderTransformer transformer = processor.getTransformer();
+ FileHeader header = processor.getHeader();
+
+ String defaultHeaderContent = transformer.toString(header);
+ getLog().debug("default header :\n" + defaultHeaderContent);
+
+ String defaultFullHeaderContent = transformer.boxProcessTag(defaultHeaderContent);
+ getLog().info("default header (process tag boxed) :\n" + defaultFullHeaderContent);
+
+ defaultFullHeaderContent = transformer.boxComment(defaultFullHeaderContent);
+ getLog().info("default header to use :\n" + defaultFullHeaderContent);
+
+ for (Map.Entry<File, String[]> entry : filestoTreate.entrySet()) {
+ File basedir = entry.getKey();
+ getLog().info("start entry \n" + basedir);
+ String[] paths = entry.getValue();
+ getLog().info(paths.length + " file(s) to treate.");
+ for (String path : paths) {
+ File file = new File(basedir, path);
+ updateFile(processor, file, defaultFullHeaderContent);
+ }
+ }
}
+ public void updateFile(FileHeaderProcessor processor,
+ File file,
+ String defaultFullHeaderContent) throws IOException {
+ getLog().info("scan file " + file);
+
+ if (isVerbose()) {
+ getLog().info("process file " + file);
+ }
+
+ // file where to writeFile result
+ File processFile = new File(file.getAbsolutePath() + "_" +
+ timestamp);
+
+ try {
+ processor.process(file, processFile);
+ boolean foundLicenseHeader = processor.isTouched();
+
+ if (!foundLicenseHeader) {
+ if (processor.isDetectHeader()) {
+ getLog().warn(
+ "skip file " + file +
+ " (no license footer tag found : '##%*' !)");
+ } else {
+
+ // no license header found in file, add it
+ getLog().info("adding license header on file " + file);
+ String content = PluginHelper.readAsString(
+ file,
+ getEncoding()
+ );
+ content = defaultFullHeaderContent + content;
+ if (!dryRun) {
+ writeFile(processFile, content, getEncoding());
+ }
+ }
+ }
+
+ if (keepBackup && !dryRun) {
+ File backupFile = new File(file.getAbsolutePath() + "~");
+ if (isVerbose()) {
+ getLog().debug("backup original file " + file);
+ }
+ renameFile(file, backupFile);
+ }
+ if (dryRun) {
+ deleteFile(processFile);
+ } else {
+ renameFile(processFile, file);
+
+ }
+
+ } catch (Exception e) {
+ getLog().warn(
+ "skip file " + file + " (could not process " +
+ "for reason : " + e.getMessage() + ")");
+ deleteFile(processFile);
+ } finally {
+ // toujours cleaner les états du filtre du processeur
+ processor.reset();
+ }
+ }
+
public long getTimestamp() {
return timestamp;
}
@@ -192,10 +337,6 @@
return projectName;
}
-// public String getLicenseName() {
-// return licenseName;
-// }
-
public String getInceptionYear() {
return inceptionYear;
}
@@ -240,12 +381,72 @@
this.inceptionYear = inceptionYear;
}
-// public void setLicenseName(String licenseName) {
-// this.licenseName = licenseName;
-// }
-
public void setOrganizationName(String organizationName) {
this.organizationName = organizationName;
}
+ protected void validateProjectfile(
+ LicenseProject licenseProject,
+ LicenseStore licenseStore,
+ Map<String, FileHeaderTransformer> transformers)
+ throws MojoFailureException {
+
+ List<String> licenseNames = Arrays.asList(licenseStore.getLicenseNames());
+
+ // check licenses is known
+ String mainLicense = licenseProject.getMainLicense();
+ if (licenseStore.getLicense(mainLicense) == null) {
+ throw new MojoFailureException(
+ "main license '" + mainLicense +
+ "' is unknown, use one of " + licenseNames);
+ }
+ for (LicenseSet licenseSet : licenseProject.getLicenseSets()) {
+
+ String licenseName = licenseSet.getLicenseName();
+ if (StringUtils.isEmpty(licenseName)) {
+
+ // use the main license
+ licenseSet.setLicenseName(mainLicense);
+ } else {
+
+ // check license name
+ if (licenseStore.getLicense(licenseName) == null) {
+ throw new MojoFailureException(
+ "license '" + licenseName +
+ "' is unknown, use one of " + licenseNames);
+ }
+ }
+
+ // check header types (for each file set)
+ for (FileSet fileSet : licenseSet.getFileSets()) {
+ String headerType = fileSet.getHeaderType();
+ if (!transformers.containsKey(headerType)) {
+ throw new MojoFailureException(
+ "headerType '" + headerType +
+ "' is unknown, use one of " + transformers.keySet());
+ }
+ }
+ }
+ }
+
+ protected FileHeader buildDefaultFileHeader(License license,
+ String projectName,
+ String inceptionYear,
+ String copyrightHolder,
+ String encoding) throws IOException {
+ FileHeader result = new FileHeader();
+ result.setDescription(projectName);
+ result.setLicense(license.getHeaderContent(encoding));
+ Integer firstYear = Integer.valueOf(inceptionYear);
+ result.setCopyrightFirstYear(firstYear);
+ Calendar cal = Calendar.getInstance();
+ cal.setTime(new Date());
+ Integer lastYear = cal.get(Calendar.YEAR);
+ if (firstYear.equals(lastYear)) {
+ result.setCopyrightLastYear(lastYear);
+ }
+ result.setCopyrightHolder(copyrightHolder);
+ return result;
+ }
+
}
Modified: trunk/src/main/java/org/nuiton/license/plugin/UpdateHeaderMojo.java
===================================================================
--- trunk/src/main/java/org/nuiton/license/plugin/UpdateHeaderMojo.java 2010-04-07 10:21:25 UTC (rev 1718)
+++ trunk/src/main/java/org/nuiton/license/plugin/UpdateHeaderMojo.java 2010-04-08 17:55:28 UTC (rev 1719)
@@ -353,16 +353,8 @@
// recuperation de la license a utiliser
licenseStore = createLicenseStore(licenseResolver);
-
+
License license = licenseStore.getLicense(licenseName);
-//
-// LicenseRepository factory =
-// LicenseRepositoryFactory.newLicenseRepository(
-// true,
-// true,
-// licenseResolver
-// );
-// License license = factory.getLicense(licenseName);
if (isVerbose()) {
getLog().info("config - use license " + license.getName());
Added: trunk/src/main/java/org/nuiton/license/plugin/header/FileHeader.java
===================================================================
--- trunk/src/main/java/org/nuiton/license/plugin/header/FileHeader.java (rev 0)
+++ trunk/src/main/java/org/nuiton/license/plugin/header/FileHeader.java 2010-04-08 17:55:28 UTC (rev 1719)
@@ -0,0 +1,133 @@
+package org.nuiton.license.plugin.header;
+
+/**
+ * Contract of a file header.
+ * <p/>
+ * A header has thre sections like in this example :
+ * <p/>
+ * <pre>
+ * Description
+ * %--
+ * Copyright (C) firstYear[ - lastYear] holder
+ * %--
+ * License
+ * </pre>
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 2.1
+ */
+public class FileHeader {
+
+ /** Copyright to string format */
+ protected static final String COPYRIGHT_TO_STRING_FORMAT = "Copyright (C) %1$s %2$s";
+
+ /** Description of the project or module to add in header */
+ protected String description;
+
+ /** Copyright holder */
+ protected String copyrightHolder;
+
+ /** Copyright first year of application */
+ protected Integer copyrightFirstYear;
+
+ /**
+ * Copyright last year of application (can be nullif copyright is
+ * only on one year).
+ */
+ protected Integer copyrightLastYear;
+
+ /** License used in the header. */
+ protected String license;
+
+ /**
+ * @return the project name, or nay other common informations for all
+ * files of a project (or module)
+ */
+ public String getDescription() {
+ return description;
+ }
+
+ /** @return the copyright holder */
+ public String getCopyrightHolder() {
+ return copyrightHolder;
+ }
+
+ /** @return the first year of the copyright */
+ public Integer getCopyrightFirstYear() {
+ return copyrightFirstYear;
+ }
+
+ /**
+ * @return the last year of the copyright (if copyright affects only one
+ * year, can be equals to the {@link #getCopyrightFirstYear()}).
+ */
+ public Integer getCopyrightLastYear() {
+ return copyrightLastYear;
+ }
+
+ /**
+ * Produces a string representation of the copyright.
+ * <p/>
+ * If copyright acts on one year :
+ * <pre>
+ * Copyright (C) 2010 Holder
+ * </pre>
+ * <p/>
+ * If copyright acts on more than one year :
+ * <pre>
+ * Copyright (C) 2010 - 2012 Holder
+ * </pre>
+ *
+ * @return the String representation of the copyright
+ */
+ public String getCopyright() {
+ String copyright;
+ if (getCopyrightLastYear() == null) {
+
+ // copyright on one year
+ copyright = String.format(
+ COPYRIGHT_TO_STRING_FORMAT,
+ getCopyrightFirstYear(),
+ getCopyrightHolder()
+ );
+ } else {
+
+ // copyright on more than one year
+ copyright = String.format(
+ COPYRIGHT_TO_STRING_FORMAT,
+ getCopyrightFirstYear() + " - " +
+ getCopyrightLastYear(),
+ getCopyrightHolder()
+ );
+ }
+ return copyright;
+ }
+
+ /**
+ * @return the license content (this is not the fully license content,
+ * but just a per file license resume)
+ */
+ public String getLicense() {
+ return license;
+ }
+
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ public void setCopyrightHolder(String copyrightHolder) {
+ this.copyrightHolder = copyrightHolder;
+ }
+
+ public void setCopyrightFirstYear(Integer copyrightFirstYear) {
+ this.copyrightFirstYear = copyrightFirstYear;
+ }
+
+ public void setCopyrightLastYear(Integer copyrightLastYear) {
+ this.copyrightLastYear = copyrightLastYear;
+ }
+
+ public void setLicense(String license) {
+ this.license = license;
+ }
+}
Property changes on: trunk/src/main/java/org/nuiton/license/plugin/header/FileHeader.java
___________________________________________________________________
Added: svn:keywords
+ "Author Date Id Revision HeadURL
Added: trunk/src/main/java/org/nuiton/license/plugin/header/FileHeaderFilter.java
===================================================================
--- trunk/src/main/java/org/nuiton/license/plugin/header/FileHeaderFilter.java (rev 0)
+++ trunk/src/main/java/org/nuiton/license/plugin/header/FileHeaderFilter.java 2010-04-08 17:55:28 UTC (rev 1719)
@@ -0,0 +1,100 @@
+package org.nuiton.license.plugin.header;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.nuiton.license.plugin.header.transformer.FileHeaderTransformer;
+import org.nuiton.processor.filters.DefaultFilter;
+
+/**
+ * TODO
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 2.1
+ */
+public abstract class FileHeaderFilter extends DefaultFilter {
+
+ /** to use log facility, just put in your code: log.info(\"...\"); */
+ static private final Log log = LogFactory.getLog(FileHeaderFilter.class);
+
+ /** flag pour indiquer si la licence a ete trouvee entre le header et le footer */
+ protected boolean touched;
+
+ /** flag pour indiquer si on a rencontree le header du filtre */
+ protected boolean detectHeader;
+
+ protected FileHeader header;
+
+ protected FileHeaderTransformer transformer;
+
+ protected abstract String treateHeader(String ch);
+
+ public FileHeaderFilter(FileHeader header, FileHeaderTransformer transformer) {
+ this.header = header;
+ this.transformer = transformer;
+ }
+
+ @Override
+ protected String performInFilter(String ch) {
+ if (log.isDebugEnabled()) {
+ log.debug(ch);
+ }
+ if (touched) {
+ // on autorise pas deux process de la licence dans un fichier java
+ throw new IllegalStateException("Can only have one file header start tag : " + getHeader());
+ }
+ if (getMatchIndexFor(ch, getHeader()) == NOT_FOUND) {
+
+ // the header was detected, mark file to be touched
+ touched = true;
+
+ // update header
+ String newHeader = treateHeader(ch);
+ return newHeader;
+ }
+ // ce cas arrive lorsque l'on a parcouru tout le fichier avec detection
+ // de la balise header mais sans balise footer
+ // et on arrive dans cette methode dans le flush du filter
+ return ch;
+ }
+
+ @Override
+ protected String performOutFilter(String ch) {
+ if (log.isDebugEnabled()) {
+ log.debug(ch);
+ }
+ return ch;
+ }
+
+ @Override
+ protected String getHeader() {
+ return transformer.getProcessStartTag();
+ }
+
+ @Override
+ protected String getFooter() {
+ return transformer.getProcessEndTag();
+ }
+
+ @Override
+ protected void changeState(State newState) {
+ super.changeState(newState);
+ if (newState == State.SEARCH_FOOTER) {
+ // on a decouvert un header
+ detectHeader = true;
+ }
+ }
+
+ public boolean isTouched() {
+ return touched;
+ }
+
+ public boolean isDetectHeader() {
+ return detectHeader;
+ }
+
+ public void reset() {
+ touched = false;
+ detectHeader = false;
+ state = State.SEARCH_HEADER;
+ }
+}
\ No newline at end of file
Property changes on: trunk/src/main/java/org/nuiton/license/plugin/header/FileHeaderFilter.java
___________________________________________________________________
Added: svn:keywords
+ "Author Date Id Revision HeadURL
Added: trunk/src/main/java/org/nuiton/license/plugin/header/FileHeaderProcessor.java
===================================================================
--- trunk/src/main/java/org/nuiton/license/plugin/header/FileHeaderProcessor.java (rev 0)
+++ trunk/src/main/java/org/nuiton/license/plugin/header/FileHeaderProcessor.java 2010-04-08 17:55:28 UTC (rev 1719)
@@ -0,0 +1,105 @@
+package org.nuiton.license.plugin.header;
+
+import org.nuiton.license.plugin.header.transformer.FileHeaderTransformer;
+import org.nuiton.processor.Processor;
+
+import java.io.File;
+import java.io.FileReader;
+import java.io.FileWriter;
+import java.io.IOException;
+
+/**
+ * TODO
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 2.1
+ */
+public abstract class FileHeaderProcessor extends Processor {
+
+ /** file header */
+ protected FileHeader header;
+
+ protected FileHeaderTransformer transformer;
+
+ /** internal filter */
+ protected FileHeaderFilter filter;
+
+ public abstract FileHeaderFilter newFilter(FileHeader header, FileHeaderTransformer transformer);
+
+ public FileHeaderProcessor() {
+ }
+
+ /**
+ * @return {@code true} if processed file was modified (says the header was
+ * fully found and updating), {@code false} otherwise
+ * @see FileHeaderFilter#isTouched()
+ */
+ public boolean isTouched() {
+ return filter != null && filter.isTouched();
+ }
+
+ /**
+ * @return {@code true} if header of header was detected
+ * @see FileHeaderFilter#isDetectHeader()
+ */
+ public boolean isDetectHeader() {
+ return filter != null && filter.isDetectHeader();
+ }
+
+ public void process(File filein, File fileout) throws IOException {
+ if (header == null) {
+ throw new IllegalStateException("no file header sets.");
+ }
+ if (transformer == null) {
+ throw new IllegalStateException("no file header transformer sets.");
+ }
+ if (filter == null) {
+ setFilter(newFilter(header, transformer));
+ }
+ FileReader input = new FileReader(filein);
+ try {
+ FileWriter output = new FileWriter(fileout);
+ try {
+ process(input, output);
+ } finally {
+ output.close();
+ }
+ } finally {
+ input.close();
+ }
+ }
+
+ public FileHeader getHeader() {
+ return header;
+ }
+
+ public void setHeader(FileHeader header) {
+ this.header = header;
+ filter = null;
+ }
+
+ public FileHeaderTransformer getTransformer() {
+ return transformer;
+ }
+
+ public void setTransformer(FileHeaderTransformer transformer) {
+ this.transformer = transformer;
+ filter = null;
+ }
+//
+// protected FileHeaderFilter getFilter() {
+// return filter;
+// }
+
+ public void setFilter(FileHeaderFilter filter) {
+ this.filter = filter;
+ setInputFilter(filter);
+ }
+
+
+ public void reset() {
+ if (filter != null) {
+ filter.reset();
+ }
+ }
+}
Property changes on: trunk/src/main/java/org/nuiton/license/plugin/header/FileHeaderProcessor.java
___________________________________________________________________
Added: svn:keywords
+ "Author Date Id Revision HeadURL
Added: trunk/src/main/java/org/nuiton/license/plugin/header/transformer/AbstractFileHeaderTransformer.java
===================================================================
--- trunk/src/main/java/org/nuiton/license/plugin/header/transformer/AbstractFileHeaderTransformer.java (rev 0)
+++ trunk/src/main/java/org/nuiton/license/plugin/header/transformer/AbstractFileHeaderTransformer.java 2010-04-08 17:55:28 UTC (rev 1719)
@@ -0,0 +1,282 @@
+package org.nuiton.license.plugin.header.transformer;
+
+import org.nuiton.license.plugin.header.FileHeader;
+
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * Abstract implementation of {@link FileHeaderTransformer} which does NOT deal
+ * with the boxing-unboxing part, but just with transformation methods, since
+ * they are common to any transformer.
+ * <p/>
+ * Concrete implementation should just has to deal with to boxing stuff.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 2.1
+ */
+public abstract class AbstractFileHeaderTransformer implements FileHeaderTransformer {
+
+ /**
+ * pattern of the copyright string representation :
+ * <ul>
+ * <li>group(1) is Copyright prefix</li>
+ * <li>group(2) is Copyright first year</li>
+ * <li>group(3) is Copyright last year with prefix (can be null)</li>
+ * <li>group(4) is Copyright last year (can be null)</li>
+ * <li>group(5) is Copyright holder</li>
+ * </ul>
+ */
+ protected static final Pattern COPYRIGHT_PATTERN =
+ Pattern.compile(
+ "(.[^\\d]+)?\\s(\\d{4})?(\\s+-\\s+(\\d{4})?){0,1}\\s+(.+)?"
+ );
+
+ public static final char LINE_SEPARATOR = '\n';
+
+ /** name of transformer */
+ protected String name;
+
+ /** description of transfomer */
+ protected String description;
+
+ /** section delimiter */
+ protected String sectionDelimiter = DEFAULT_SECTION_DELIMITER;
+
+ /** start process tag */
+ protected String processStartTag = DEFAULT_PROCESS_START_TAG;
+
+ /** end process tag */
+ protected String processEndTag = DEFAULT_PROCESS_END_TAG;
+
+ /** comment start tag */
+ protected String commentStartTag;
+
+ /** comment end tag */
+ protected String commentEndTag;
+
+ /** comment line prefix (to add for header content) */
+ protected String commentLinePrefix;
+
+ protected AbstractFileHeaderTransformer() {
+
+ }
+
+ protected AbstractFileHeaderTransformer(String name,
+ String description,
+ String commentStartTag,
+ String commentEndTag,
+ String commentLinePrefix) {
+ this.name = name;
+ this.description = description;
+ this.commentStartTag = commentStartTag;
+ this.commentEndTag = commentEndTag;
+ this.commentLinePrefix = commentLinePrefix;
+ }
+
+ protected AbstractFileHeaderTransformer(String commentStartTag,
+ String commentEndTag,
+ String commentLinePrefix) {
+ this.commentStartTag = commentStartTag;
+ this.commentEndTag = commentEndTag;
+ this.commentLinePrefix = commentLinePrefix;
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ @Override
+ public String getDescription() {
+ return description;
+ }
+
+ @Override
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ @Override
+ public String getSectionDelimiter() {
+ return sectionDelimiter;
+ }
+
+ @Override
+ public void setSectionDelimiter(String sectionDelimiter) {
+ this.sectionDelimiter = sectionDelimiter;
+ }
+
+ @Override
+ public String getProcessStartTag() {
+ return processStartTag;
+ }
+
+ @Override
+ public void setProcessStartTag(String processStartTag) {
+ this.processStartTag = processStartTag;
+ }
+
+ @Override
+ public String getProcessEndTag() {
+ return processEndTag;
+ }
+
+ @Override
+ public void setProcessEndTag(String processEndTag) {
+ this.processEndTag = processEndTag;
+ }
+
+ @Override
+ public String getCommentStartTag() {
+ return commentStartTag;
+ }
+
+ @Override
+ public void setCommentStartTag(String commentStartTag) {
+ this.commentStartTag = commentStartTag;
+ }
+
+ @Override
+ public String getCommentEndTag() {
+ return commentEndTag;
+ }
+
+ @Override
+ public void setCommentEndTag(String commentEndTag) {
+ this.commentEndTag = commentEndTag;
+ }
+
+ @Override
+ public String getCommentLinePrefix() {
+ return commentLinePrefix;
+ }
+
+ @Override
+ public void setCommentLinePrefix(String commentLinePrefix) {
+ this.commentLinePrefix = commentLinePrefix;
+ }
+
+ @Override
+ public FileHeader toFileHeader(String header) {
+ FileHeader model = new FileHeader();
+
+ String[] sections = header.split(getSectionDelimiter());
+ if (sections.length != 3) {
+ throw new IllegalStateException(
+ "could not find 3 sections in\n" + header);
+ }
+
+ // first section is the description
+ String description = sections[0].trim();
+ model.setDescription(description);
+
+ // second section is the copyright
+ String copyright = sections[1].trim();
+ Matcher matcher = COPYRIGHT_PATTERN.matcher(copyright);
+ if (!matcher.matches()) {
+ throw new IllegalStateException(
+ "copyright [" + copyright + "] is not valid");
+ }
+ String firstYear = matcher.group(2);
+ String lastYear = matcher.group(4);
+ String holder = matcher.group(5);
+ model.setCopyrightFirstYear(Integer.valueOf(firstYear.trim()));
+ if (lastYear != null) {
+ model.setCopyrightLastYear(Integer.valueOf(lastYear.trim()));
+ }
+ model.setCopyrightHolder(holder.trim());
+
+ // third section is the license
+ String license = sections[2].trim();
+ model.setLicense(license);
+ return model;
+ }
+
+ @Override
+ public String toString(FileHeader model) {
+ StringBuilder buffer = new StringBuilder();
+
+ String sectionDelimiter = LINE_SEPARATOR + getSectionDelimiter() +
+ LINE_SEPARATOR;
+
+ // add description section
+ buffer.append(model.getDescription().trim());
+ buffer.append(sectionDelimiter);
+
+ // add copyright section
+ buffer.append(model.getCopyright().trim());
+ buffer.append(sectionDelimiter);
+
+ // add license section
+ buffer.append(model.getLicense().trim()).append(LINE_SEPARATOR);
+ return buffer.toString();
+ }
+
+ @Override
+ public String boxComment(String header) {
+ StringBuilder buffer = new StringBuilder();
+ buffer.append(getCommentStartTag()).append(LINE_SEPARATOR);
+ for (String line : header.split(LINE_SEPARATOR + "")) {
+ buffer.append(getCommentLinePrefix());
+ buffer.append(line);
+ buffer.append(LINE_SEPARATOR);
+ }
+ buffer.append(getCommentEndTag()).append(LINE_SEPARATOR);
+ return buffer.toString();
+ }
+
+ @Override
+ public String unboxComent(String header) {
+ StringBuilder buffer = new StringBuilder();
+ int prefixLength = getCommentLinePrefix().length();
+ for (String line : header.split(LINE_SEPARATOR + "")) {
+ if (line.isEmpty() ||
+ line.contains(getCommentStartTag()) ||
+ line.contains(getCommentEndTag())) {
+
+ // not be unboxed, but just skipped
+ continue;
+ }
+ int index = line.indexOf(getCommentLinePrefix());
+ if (index > -1) {
+
+ // remove comment prefix
+ line = line.substring(index + prefixLength);
+ }
+ buffer.append(line).append(LINE_SEPARATOR);
+ }
+ return buffer.toString();
+ }
+
+
+ @Override
+ public String boxProcessTag(String header) {
+ StringBuilder buffer = new StringBuilder();
+ buffer.append(getProcessStartTag()).append(LINE_SEPARATOR);
+ buffer.append(header.trim()).append(LINE_SEPARATOR);
+ buffer.append(getProcessEndTag()).append(LINE_SEPARATOR);
+ return buffer.toString();
+ }
+
+ @Override
+ public String unboxProcessTag(String boxedHeader) {
+ StringBuilder buffer = new StringBuilder();
+ for (String line : boxedHeader.split(LINE_SEPARATOR + "")) {
+ if (line.isEmpty() ||
+ line.contains(getProcessStartTag()) ||
+ line.contains(getProcessEndTag())) {
+
+ // not be unboxed, but just skipped
+ continue;
+ }
+ buffer.append(line).append(LINE_SEPARATOR);
+ }
+ return buffer.toString();
+ }
+}
Property changes on: trunk/src/main/java/org/nuiton/license/plugin/header/transformer/AbstractFileHeaderTransformer.java
___________________________________________________________________
Added: svn:keywords
+ "Author Date Id Revision HeadURL
Added: trunk/src/main/java/org/nuiton/license/plugin/header/transformer/AptFileHeaderTransformer.java
===================================================================
--- trunk/src/main/java/org/nuiton/license/plugin/header/transformer/AptFileHeaderTransformer.java (rev 0)
+++ trunk/src/main/java/org/nuiton/license/plugin/header/transformer/AptFileHeaderTransformer.java 2010-04-08 17:55:28 UTC (rev 1719)
@@ -0,0 +1,30 @@
+package org.nuiton.license.plugin.header.transformer;
+
+/**
+ * Implementation of {@link FileHeaderTransformer} for apt format.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @plexus.component role-hint="apt"
+ * @since 2.1
+ */
+public class AptFileHeaderTransformer extends AbstractFileHeaderTransformer {
+
+ public static final String NAME = "apt";
+
+ public static final String DESCRIPTION = "header transformer with apt comment style";
+
+ public static final String COMMENT_LINE_PREFIX = "~~~ ";
+
+ public static final String COMMENT_START_TAG = "\n";
+
+ public static final String COMMENT_END_TAG = "\n";
+
+ public AptFileHeaderTransformer() {
+ super(NAME,
+ DESCRIPTION,
+ COMMENT_START_TAG,
+ COMMENT_END_TAG,
+ COMMENT_LINE_PREFIX
+ );
+ }
+}
Property changes on: trunk/src/main/java/org/nuiton/license/plugin/header/transformer/AptFileHeaderTransformer.java
___________________________________________________________________
Added: svn:keywords
+ "Author Date Id Revision HeadURL
Added: trunk/src/main/java/org/nuiton/license/plugin/header/transformer/FileHeaderTransformer.java
===================================================================
--- trunk/src/main/java/org/nuiton/license/plugin/header/transformer/FileHeaderTransformer.java (rev 0)
+++ trunk/src/main/java/org/nuiton/license/plugin/header/transformer/FileHeaderTransformer.java 2010-04-08 17:55:28 UTC (rev 1719)
@@ -0,0 +1,169 @@
+package org.nuiton.license.plugin.header.transformer;
+
+import org.nuiton.license.plugin.header.FileHeader;
+
+/**
+ * Contract to transform a file header to {@link org.nuiton.license.plugin.header.FileHeader} in both way :
+ * <p/>
+ * <ul>
+ * <li>Obtain a object representation of a file header from a existing file
+ * (String to FileHeader).</li>
+ * <li>Obtain the file header to inject in a file from a FileHeader (to update
+ * or create a file header from the file header model).
+ * </ul>
+ * <p/>
+ * Moreover the contract offers tow method to box and unbox a String
+ * representation of a header content :
+ * <ul>
+ * <li>{@link #boxComment(String)}</li>
+ * <li>{@link #unboxComent(String)}</li>
+ * </ul>
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 2.1
+ */
+public interface FileHeaderTransformer {
+
+ /** Plexus component role */
+ String ROLE_NAME = FileHeaderTransformer.class.getName();
+
+ /** default section delimiter */
+ String DEFAULT_SECTION_DELIMITER = "%--";
+
+ /** default process start tag */
+ String DEFAULT_PROCESS_START_TAG = "#%L";
+
+ /** default process end tag */
+ String DEFAULT_PROCESS_END_TAG = "#L%";
+
+ /** @return the name of the transformer */
+ String getName();
+
+ /** @return the description of the transformer */
+ String getDescription();
+
+ /**
+ * Obtains the process tag which indicates the begin of the header content.
+ * <p/>
+ * By default, (says if you do not explicitly invoke the
+ * {@link #setProcessStartTag(String)} method), will use the
+ * {@link #DEFAULT_PROCESS_START_TAG}
+ *
+ * @return the starting header tag
+ */
+ String getProcessStartTag();
+
+ /**
+ * Obtain the process tag which indiciates the end of the header content.
+ * <p/>
+ * By default, (says if you do not explicitly invoke the
+ * {@link #setProcessEndTag(String)} method), will use the
+ * {@link #DEFAULT_PROCESS_END_TAG}.
+ *
+ * @return the ending header tag
+ */
+ String getProcessEndTag();
+
+ /**
+ * The pattern used to separate sections of the header.
+ * <p/>
+ * By default, (says if you do not explicitly invoke the
+ * {@link #setSectionDelimiter(String)} method), will use the
+ * {@link #DEFAULT_SECTION_DELIMITER}.
+ *
+ * @return the delimiter used to separate sections in the header.
+ */
+ String getSectionDelimiter();
+
+ String getCommentStartTag();
+
+ String getCommentEndTag();
+
+ String getCommentLinePrefix();
+
+ void setName(String name);
+
+ void setDescription(String description);
+
+ /**
+ * Sets the header section delimiter.
+ * <p/>
+ * By default, will use the {@link #DEFAULT_SECTION_DELIMITER}.
+ *
+ * @param headerSectionDelimiter the new delimiter
+ */
+ void setSectionDelimiter(String headerSectionDelimiter);
+
+ /**
+ * Changes the process start tag.
+ *
+ * @param tag the new start tag
+ */
+ void setProcessStartTag(String tag);
+
+ /**
+ * Changes the process end tag.
+ *
+ * @param tag the new endtag
+ */
+ void setProcessEndTag(String tag);
+
+ void setCommentStartTag(String commentStartTag);
+
+ void setCommentEndTag(String commentEndTag);
+
+ void setCommentLinePrefix(String commentLinePrefix);
+
+ /**
+ * Box the given {@code header} in a comment.
+ *
+ * @param header the header content WITHOUT any comment boxing
+ * @return the header content WITH comment boxing
+ */
+ String boxComment(String header);
+
+ /**
+ * Unbox the given boxed {@code boxedHeader} to obtain the header content.
+ *
+ * @param boxedHeader the boxed header
+ * @return the unboxed header.
+ */
+ String unboxComent(String boxedHeader);
+
+ /**
+ * Box the given {@code header} between process tags.
+ *
+ * @param header the header content WITHOUT any comment boxing
+ * @return the header content boxed between process tags
+ * @see #getProcessStartTag()
+ * @see #getProcessEndTag()
+ */
+ String boxProcessTag(String header);
+
+ /**
+ * Unbox the process tag on the given boxed {@code boxedHeader} to obtain
+ * the brute header content.
+ *
+ * @param boxedHeader the boxed header
+ * @return the brute header content.
+ * @see #getProcessStartTag()
+ * @see #getProcessEndTag()
+ */
+ String unboxProcessTag(String boxedHeader);
+
+ /**
+ * Build a {@link org.nuiton.license.plugin.header.FileHeader} from an UNBOXED header content.
+ *
+ * @param header unboxed header content
+ * @return The model of the header content
+ */
+ FileHeader toFileHeader(String header);
+
+ /**
+ * Build a UNBOXED header content from the given {@code model}.
+ *
+ * @param model the model of the file header
+ * @return the UNBOXED header content
+ */
+ String toString(FileHeader model);
+}
Property changes on: trunk/src/main/java/org/nuiton/license/plugin/header/transformer/FileHeaderTransformer.java
___________________________________________________________________
Added: svn:keywords
+ "Author Date Id Revision HeadURL
Added: trunk/src/main/java/org/nuiton/license/plugin/header/transformer/JavaFileHeaderTransformer.java
===================================================================
--- trunk/src/main/java/org/nuiton/license/plugin/header/transformer/JavaFileHeaderTransformer.java (rev 0)
+++ trunk/src/main/java/org/nuiton/license/plugin/header/transformer/JavaFileHeaderTransformer.java 2010-04-08 17:55:28 UTC (rev 1719)
@@ -0,0 +1,30 @@
+package org.nuiton.license.plugin.header.transformer;
+
+/**
+ * Implementation of {@link FileHeaderTransformer} for java format.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @plexus.component role-hint="java"
+ * @since 2.1
+ */
+public class JavaFileHeaderTransformer extends AbstractFileHeaderTransformer {
+
+ public static final String NAME = "java";
+
+ public static final String DESCRIPTION = "header transformer with java comment style";
+
+ public static final String COMMENT_LINE_PREFIX = " * ";
+
+ public static final String COMMENT_START_TAG = "/*";
+
+ public static final String COMMENT_END_TAG = " */";
+
+ public JavaFileHeaderTransformer() {
+ super(NAME,
+ DESCRIPTION,
+ COMMENT_START_TAG,
+ COMMENT_END_TAG,
+ COMMENT_LINE_PREFIX
+ );
+ }
+}
\ No newline at end of file
Property changes on: trunk/src/main/java/org/nuiton/license/plugin/header/transformer/JavaFileHeaderTransformer.java
___________________________________________________________________
Added: svn:keywords
+ "Author Date Id Revision HeadURL
Added: trunk/src/main/java/org/nuiton/license/plugin/header/transformer/PropertiesFileHeaderTransformer.java
===================================================================
--- trunk/src/main/java/org/nuiton/license/plugin/header/transformer/PropertiesFileHeaderTransformer.java (rev 0)
+++ trunk/src/main/java/org/nuiton/license/plugin/header/transformer/PropertiesFileHeaderTransformer.java 2010-04-08 17:55:28 UTC (rev 1719)
@@ -0,0 +1,30 @@
+package org.nuiton.license.plugin.header.transformer;
+
+/**
+ * Implementation of {@link FileHeaderTransformer} for properties format.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @plexus.component role-hint="properties"
+ * @since 2.1
+ */
+public class PropertiesFileHeaderTransformer extends AbstractFileHeaderTransformer {
+
+ public static final String NAME = "properties";
+
+ public static final String DESCRIPTION = "header transformer with properties file comment style";
+
+ public static final String COMMENT_LINE_PREFIX = "# ";
+
+ public static final String COMMENT_START_TAG = "###############################################################################";
+
+ public static final String COMMENT_END_TAG = "###############################################################################";
+
+ public PropertiesFileHeaderTransformer() {
+ super(NAME,
+ DESCRIPTION,
+ COMMENT_START_TAG,
+ COMMENT_END_TAG,
+ COMMENT_LINE_PREFIX
+ );
+ }
+}
\ No newline at end of file
Property changes on: trunk/src/main/java/org/nuiton/license/plugin/header/transformer/PropertiesFileHeaderTransformer.java
___________________________________________________________________
Added: svn:keywords
+ "Author Date Id Revision HeadURL
Added: trunk/src/main/java/org/nuiton/license/plugin/header/transformer/XmlFileHeaderTransformer.java
===================================================================
--- trunk/src/main/java/org/nuiton/license/plugin/header/transformer/XmlFileHeaderTransformer.java (rev 0)
+++ trunk/src/main/java/org/nuiton/license/plugin/header/transformer/XmlFileHeaderTransformer.java 2010-04-08 17:55:28 UTC (rev 1719)
@@ -0,0 +1,30 @@
+package org.nuiton.license.plugin.header.transformer;
+
+/**
+ * Implementation of {@link FileHeaderTransformer} for xml format.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @plexus.component role-hint="xml"
+ * @since 2.1
+ */
+public class XmlFileHeaderTransformer extends AbstractFileHeaderTransformer {
+
+ public static final String NAME = "xml";
+
+ public static final String DESCRIPTION = "header transformer with xml comment style";
+
+ public static final String COMMENT_LINE_PREFIX = " ";
+
+ public static final String COMMENT_START_TAG = "<!--";
+
+ public static final String COMMENT_END_TAG = "-->";
+
+ public XmlFileHeaderTransformer() {
+ super(NAME,
+ DESCRIPTION,
+ COMMENT_START_TAG,
+ COMMENT_END_TAG,
+ COMMENT_LINE_PREFIX
+ );
+ }
+}
\ No newline at end of file
Property changes on: trunk/src/main/java/org/nuiton/license/plugin/header/transformer/XmlFileHeaderTransformer.java
___________________________________________________________________
Added: svn:keywords
+ "Author Date Id Revision HeadURL
Modified: trunk/src/main/java/org/nuiton/license/plugin/model/LicenseRepository.java
===================================================================
--- trunk/src/main/java/org/nuiton/license/plugin/model/LicenseRepository.java 2010-04-07 10:21:25 UTC (rev 1718)
+++ trunk/src/main/java/org/nuiton/license/plugin/model/LicenseRepository.java 2010-04-08 17:55:28 UTC (rev 1719)
@@ -124,7 +124,7 @@
}
return result.toArray(new String[result.size()]);
}
-
+
public License[] getLicenses() {
checkInit("getLicenses");
return licenses.toArray(new License[licenses.size()]);
Modified: trunk/src/main/mdo/descriptor.mdo
===================================================================
--- trunk/src/main/mdo/descriptor.mdo 2010-04-07 10:21:25 UTC (rev 1718)
+++ trunk/src/main/mdo/descriptor.mdo 2010-04-08 17:55:28 UTC (rev 1719)
@@ -10,11 +10,11 @@
<p>
Maven License Plugin relies on the provided project descriptors to dictate
its execution. Although there are already prefabricated descriptors available
- for use, they can only suffice some of the common assembly requirements.
+ for use, they can only suffice some of the common license requirements.
</p>
<p>
- So in order for you to customize the way the License Plugin creates your
- assemblies, you need to know how to use the License project Descriptor.
+ So in order for you to customize the way the License Plugin updates your
+ licenses, you need to know how to use the License project Descriptor.
</p>
<p>
This descriptor specifies the type of licenses to apply for some defined
@@ -45,8 +45,10 @@
<required>true</required>
<type>String</type>
<description>
- The main license of the project (or module). The LICENSE.txt will
+ <![CDATA[
+ The main license of the project (or module). The LICENSE.txt will
contains the content of this license.
+ ]]>
</description>
</field>
<field>
@@ -66,7 +68,7 @@
</fields>
</class>
- <class>
+ <class>
<name>LicenseSet</name>
<description>
<![CDATA[
@@ -79,8 +81,13 @@
<name>licenseName</name>
<version>1.0.0+</version>
<type>String</type>
- <required>true</required>
- <description>The license to apply in this set.</description>
+ <!--<required>true</required>-->
+ <description>
+ <![CDATA[
+ The license to apply in this set. If not fill, will use
+ the main license.
+ ]]>
+ </description>
</field>
<field>
<name>fileSets</name>
@@ -91,8 +98,8 @@
</association>
<description>
<![CDATA[
- Specifies file sets to include in the license set. A fileSet is specified
- by providing one or more of <licenseSet> subelements.
+ Specifies file sets to include in the license set. A fileSet is
+ specified by providing one or more of <licenseSet> subelements.
]]>
</description>
</field>
@@ -103,10 +110,10 @@
<name>FileSet</name>
<version>1.0.0+</version>
<description>
- <![CDATA[
+ <![CDATA[
A fileSet allows the inclusion of groups of files into the license set
and defines also the type of header to generate.
- ]]>
+ ]]>
</description>
<fields>
<field>
@@ -114,7 +121,8 @@
<version>1.0.0+</version>
<type>String</type>
<required>true</required>
- <description>The type of header to generate (or updates).</description>
+ <description>The type of header to generate (or updates).
+ </description>
</field>
<field>
<name>useDefaultExcludes</name>
@@ -122,8 +130,10 @@
<type>boolean</type>
<defaultValue>true</defaultValue>
<description>
- Whether standard exclusion patterns, such as those matching CVS and Subversion
- metadata files, should be used when calculating the files affected by this set.
+ Whether standard exclusion patterns, such as those matching CVS and
+ Subversion
+ metadata files, should be used when calculating the files affected
+ by this set.
For backward compatibility, the default value is true. (Since 2.2)
</description>
</field>
Added: trunk/src/test/java/org/nuiton/license/plugin/header/transformer/AbstractFileHeaderTransformerTest.java
===================================================================
--- trunk/src/test/java/org/nuiton/license/plugin/header/transformer/AbstractFileHeaderTransformerTest.java (rev 0)
+++ trunk/src/test/java/org/nuiton/license/plugin/header/transformer/AbstractFileHeaderTransformerTest.java 2010-04-08 17:55:28 UTC (rev 1719)
@@ -0,0 +1,251 @@
+package org.nuiton.license.plugin.header.transformer;
+
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.nuiton.license.plugin.header.FileHeader;
+
+import java.util.regex.Matcher;
+
+import static org.nuiton.license.plugin.header.transformer.AbstractFileHeaderTransformer.COPYRIGHT_PATTERN;
+import static org.nuiton.license.plugin.header.transformer.AbstractFileHeaderTransformer.DEFAULT_PROCESS_END_TAG;
+import static org.nuiton.license.plugin.header.transformer.AbstractFileHeaderTransformer.DEFAULT_PROCESS_START_TAG;
+import static org.nuiton.license.plugin.header.transformer.AbstractFileHeaderTransformer.DEFAULT_SECTION_DELIMITER;
+import static org.nuiton.license.plugin.header.transformer.AbstractFileHeaderTransformer.LINE_SEPARATOR;
+import static org.nuiton.license.plugin.header.transformer.JavaFileHeaderTransformer.*;
+
+/**
+ * Tests the {@link AbstractFileHeaderTransformer}.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 2.1
+ */
+public class AbstractFileHeaderTransformerTest {
+
+ FileHeaderTransformer transformer;
+
+ FileHeader model1, model2;
+
+ @Before
+ public void setUp() throws Exception {
+ transformer = new JavaFileHeaderTransformer();
+
+ model1 = new FileHeader();
+ model1.setDescription("Description");
+ model1.setCopyrightFirstYear(2010);
+ model1.setCopyrightLastYear(null);
+ model1.setCopyrightHolder("Tony");
+ model1.setLicense("License");
+
+ model2 = new FileHeader();
+ model2.setDescription("Description2");
+ model2.setCopyrightFirstYear(2010);
+ model2.setCopyrightLastYear(2012);
+ model2.setCopyrightHolder("Tony2");
+ model2.setLicense("License2");
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ transformer = null;
+ model1 = null;
+ model2 = null;
+ }
+
+ @Test
+ public void testCopyrightPattern() throws Exception {
+ String actual;
+ Matcher matcher;
+ String prefix;
+ String firstYear;
+ String lastYear;
+ String holder;
+
+ actual = "Copyright (C) 2010 Tony";
+ matcher = COPYRIGHT_PATTERN.matcher(actual);
+ Assert.assertTrue(matcher.matches());
+ Assert.assertEquals(5, matcher.groupCount());
+ prefix = matcher.group(1);
+ Assert.assertEquals("Copyright (C)", prefix);
+ firstYear = matcher.group(2);
+ Assert.assertEquals("2010", firstYear);
+ lastYear = matcher.group(4);
+ Assert.assertEquals(null, lastYear);
+ holder = matcher.group(5);
+ Assert.assertEquals("Tony", holder);
+
+ actual = "Copyright (C) 2010 - 2012 Tony";
+ matcher = COPYRIGHT_PATTERN.matcher(actual);
+ Assert.assertTrue(matcher.matches());
+ Assert.assertEquals(5, matcher.groupCount());
+ prefix = matcher.group(1);
+ Assert.assertEquals("Copyright (C)", prefix);
+ firstYear = matcher.group(2);
+ Assert.assertEquals("2010", firstYear);
+ lastYear = matcher.group(4);
+ Assert.assertEquals("2012", lastYear);
+ holder = matcher.group(5);
+ Assert.assertEquals("Tony", holder);
+ }
+
+ @Test
+ public void testToFileHeader() throws Exception {
+ String header;
+ FileHeader model;
+
+ header = "Description" + LINE_SEPARATOR +
+ DEFAULT_SECTION_DELIMITER + LINE_SEPARATOR +
+ "Copyright (C) 2010 Tony" + LINE_SEPARATOR +
+ DEFAULT_SECTION_DELIMITER + LINE_SEPARATOR +
+ "License";
+ model = transformer.toFileHeader(header);
+ Assert.assertNotNull(model);
+ assertEquals(model1, model);
+
+ header = "Description2" + LINE_SEPARATOR +
+ DEFAULT_SECTION_DELIMITER + LINE_SEPARATOR +
+ "Copyright (C) 2010 - 2012 Tony2" + LINE_SEPARATOR +
+ DEFAULT_SECTION_DELIMITER + LINE_SEPARATOR +
+ "License2";
+ model = transformer.toFileHeader(header);
+ Assert.assertNotNull(model);
+ assertEquals(model2, model);
+ }
+
+ @Test
+ public void testToString() throws Exception {
+ String header;
+
+ header = transformer.toString(model1);
+ Assert.assertEquals("Description" + LINE_SEPARATOR +
+ DEFAULT_SECTION_DELIMITER + LINE_SEPARATOR +
+ "Copyright (C) 2010 Tony" + LINE_SEPARATOR +
+ DEFAULT_SECTION_DELIMITER + LINE_SEPARATOR +
+ "License" + LINE_SEPARATOR,
+ header
+ );
+
+ header = transformer.toString(model2);
+ Assert.assertEquals("Description2" + LINE_SEPARATOR +
+ DEFAULT_SECTION_DELIMITER + LINE_SEPARATOR +
+ "Copyright (C) 2010 - 2012 Tony2" + LINE_SEPARATOR +
+ DEFAULT_SECTION_DELIMITER + LINE_SEPARATOR +
+ "License2" + LINE_SEPARATOR,
+ header
+ );
+ }
+
+ @Test
+ public void testBoxProcessTag() throws Exception {
+ String header;
+ String boxedHeader;
+
+ header = transformer.toString(model1);
+ boxedHeader = transformer.boxProcessTag(header);
+ Assert.assertEquals(DEFAULT_PROCESS_START_TAG + LINE_SEPARATOR +
+ "Description" + LINE_SEPARATOR +
+ DEFAULT_SECTION_DELIMITER + LINE_SEPARATOR +
+ "Copyright (C) 2010 Tony" + LINE_SEPARATOR +
+ DEFAULT_SECTION_DELIMITER + LINE_SEPARATOR +
+ "License" + LINE_SEPARATOR +
+ DEFAULT_PROCESS_END_TAG + LINE_SEPARATOR,
+ boxedHeader
+ );
+
+ header = transformer.toString(model2);
+ boxedHeader = transformer.boxProcessTag(header);
+ Assert.assertEquals(DEFAULT_PROCESS_START_TAG + LINE_SEPARATOR +
+ "Description2" + LINE_SEPARATOR +
+ DEFAULT_SECTION_DELIMITER + LINE_SEPARATOR +
+ "Copyright (C) 2010 - 2012 Tony2" + LINE_SEPARATOR +
+ DEFAULT_SECTION_DELIMITER + LINE_SEPARATOR +
+ "License2" + LINE_SEPARATOR +
+ DEFAULT_PROCESS_END_TAG + LINE_SEPARATOR,
+ boxedHeader
+ );
+ }
+
+
+ @Test
+ public void testUnboxProcessTag() throws Exception {
+ String header;
+ String boxedHeader;
+ String unboxedHeader;
+
+ header = transformer.toString(model1);
+ boxedHeader = transformer.boxProcessTag(header);
+ unboxedHeader = transformer.unboxProcessTag(boxedHeader);
+
+ Assert.assertEquals(header, unboxedHeader);
+
+ header = transformer.toString(model2);
+ boxedHeader = transformer.boxProcessTag(header);
+ unboxedHeader = transformer.unboxProcessTag(boxedHeader);
+
+ Assert.assertEquals(header, unboxedHeader);
+ }
+
+ @Test
+ public void testBoxComment() throws Exception {
+ String header;
+ String boxedHeader;
+
+ header = transformer.toString(model1);
+ boxedHeader = transformer.boxComment(header);
+
+ Assert.assertEquals(
+ COMMENT_START_TAG + LINE_SEPARATOR +
+ COMMENT_LINE_PREFIX + "Description" + LINE_SEPARATOR +
+ COMMENT_LINE_PREFIX + DEFAULT_SECTION_DELIMITER + LINE_SEPARATOR +
+ COMMENT_LINE_PREFIX + "Copyright (C) 2010 Tony" + LINE_SEPARATOR +
+ COMMENT_LINE_PREFIX + DEFAULT_SECTION_DELIMITER + LINE_SEPARATOR +
+ COMMENT_LINE_PREFIX + "License" + LINE_SEPARATOR +
+ COMMENT_END_TAG + LINE_SEPARATOR,
+ boxedHeader
+ );
+
+ header = transformer.toString(model2);
+ boxedHeader = transformer.boxComment(header);
+ Assert.assertEquals(
+ COMMENT_START_TAG + LINE_SEPARATOR +
+ COMMENT_LINE_PREFIX + "Description2" + LINE_SEPARATOR +
+ COMMENT_LINE_PREFIX + DEFAULT_SECTION_DELIMITER + LINE_SEPARATOR +
+ COMMENT_LINE_PREFIX + "Copyright (C) 2010 - 2012 Tony2" + LINE_SEPARATOR +
+ COMMENT_LINE_PREFIX + DEFAULT_SECTION_DELIMITER + LINE_SEPARATOR +
+ COMMENT_LINE_PREFIX + "License2" + LINE_SEPARATOR +
+ COMMENT_END_TAG + LINE_SEPARATOR,
+ boxedHeader
+ );
+ }
+
+ @Test
+ public void testUnboxComment() throws Exception {
+ String header;
+ String boxedHeader;
+ String unboxedHeader;
+
+ header = transformer.toString(model1);
+ boxedHeader = transformer.boxComment(header);
+ unboxedHeader = transformer.unboxComent(boxedHeader);
+
+ Assert.assertEquals(header, unboxedHeader);
+
+ header = transformer.toString(model2);
+ boxedHeader = transformer.boxComment(header);
+ unboxedHeader = transformer.unboxComent(boxedHeader);
+
+ Assert.assertEquals(header, unboxedHeader);
+ }
+
+ public static void assertEquals(FileHeader model, FileHeader model2) {
+ Assert.assertEquals(model.getDescription(), model2.getDescription());
+ Assert.assertEquals(model.getCopyrightFirstYear(),
+ model2.getCopyrightFirstYear());
+ Assert.assertEquals(model.getCopyrightLastYear(),
+ model2.getCopyrightLastYear());
+ Assert.assertEquals(model.getCopyrightHolder(),
+ model2.getCopyrightHolder());
+ Assert.assertEquals(model.getLicense(), model2.getLicense());
+ }
+}
Property changes on: trunk/src/test/java/org/nuiton/license/plugin/header/transformer/AbstractFileHeaderTransformerTest.java
___________________________________________________________________
Added: svn:keywords
+ "Author Date Id Revision HeadURL
1
0
Author: tchemit
Date: 2010-04-07 12:21:25 +0200 (Wed, 07 Apr 2010)
New Revision: 1718
Log:
add skeleton integration test + improve test
Added:
trunk/src/it/settings.xml
trunk/src/it/update-header-file/LICENSE.txt
trunk/src/it/update-header-file/README.txt
trunk/src/it/update-header-file/changelog.txt
trunk/src/it/update-header-file/invoker.properties
trunk/src/it/update-header-file/pom.xml
trunk/src/it/update-header-file/src/
trunk/src/it/update-header-file/src/license/
trunk/src/it/update-header-file/src/license/project.xml
trunk/src/it/update-header-file/src/main/
trunk/src/it/update-header-file/src/main/java/
trunk/src/it/update-header-file/src/main/java/org/
trunk/src/it/update-header-file/src/main/java/org/nuiton/
trunk/src/it/update-header-file/src/main/java/org/nuiton/license/
trunk/src/it/update-header-file/src/main/java/org/nuiton/license/plugin/
trunk/src/it/update-header-file/src/main/java/org/nuiton/license/plugin/test/
trunk/src/it/update-header-file/src/main/java/org/nuiton/license/plugin/test/MyBean.java
trunk/src/it/update-header-file/verify.groovy
Modified:
trunk/pom.xml
trunk/src/main/java/org/nuiton/license/plugin/AbstractLicenseMojo.java
trunk/src/main/java/org/nuiton/license/plugin/UpdateHeaderFileMojo.java
trunk/src/main/java/org/nuiton/license/plugin/model/License.java
trunk/src/main/java/org/nuiton/license/plugin/model/LicenseRepository.java
trunk/src/main/java/org/nuiton/license/plugin/model/LicenseStore.java
trunk/src/test/java/org/nuiton/license/plugin/AddLicenseFileMojoTest.java
trunk/src/test/java/org/nuiton/license/plugin/model/LicenseRepositoryTest.java
trunk/src/test/java/org/nuiton/license/plugin/model/LicenseStoreTest.java
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2010-04-06 21:35:23 UTC (rev 1717)
+++ trunk/pom.xml 2010-04-07 10:21:25 UTC (rev 1718)
@@ -446,9 +446,10 @@
<profiles>
- <!--profile>
+ <profile>
<id>run-its</id>
<build>
+ <defaultGoal>integration-test</defaultGoal>
<plugins>
<plugin>
<artifactId>maven-invoker-plugin</artifactId>
@@ -460,6 +461,7 @@
<localRepositoryPath>${basedir}/target/local-repo</localRepositoryPath>
<settingsFile>src/it/settings.xml</settingsFile>
<cloneProjectsTo>${project.build.directory}/its</cloneProjectsTo>
+ <!--<debug>true</debug>-->
</configuration>
<executions>
<execution>
@@ -474,7 +476,7 @@
</plugin>
</plugins>
</build>
- </profile-->
+ </profile>
</profiles>
Added: trunk/src/it/settings.xml
===================================================================
--- trunk/src/it/settings.xml (rev 0)
+++ trunk/src/it/settings.xml 2010-04-07 10:21:25 UTC (rev 1718)
@@ -0,0 +1,56 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you 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.
+-->
+
+<settings>
+
+ <profiles>
+ <profile>
+ <id>it-repo</id>
+ <activation>
+ <activeByDefault>true</activeByDefault>
+ </activation>
+ <repositories>
+ <repository>
+ <id>local.central</id>
+ <url>file:///@localRepository@</url>
+ <releases>
+ <enabled>true</enabled>
+ </releases>
+ <snapshots>
+ <enabled>true</enabled>
+ </snapshots>
+ </repository>
+ </repositories>
+ <pluginRepositories>
+ <pluginRepository>
+ <id>local.central</id>
+ <url>file:///@localRepository@</url>
+ <releases>
+ <enabled>true</enabled>
+ </releases>
+ <snapshots>
+ <enabled>true</enabled>
+ </snapshots>
+ </pluginRepository>
+ </pluginRepositories>
+ </profile>
+ </profiles>
+</settings>
Added: trunk/src/it/update-header-file/LICENSE.txt
===================================================================
--- trunk/src/it/update-header-file/LICENSE.txt (rev 0)
+++ trunk/src/it/update-header-file/LICENSE.txt 2010-04-07 10:21:25 UTC (rev 1718)
@@ -0,0 +1,166 @@
+ GNU LESSER GENERAL PUBLIC LICENSE
+ Version 3, 29 June 2007
+
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+
+ This version of the GNU Lesser General Public License incorporates
+the terms and conditions of version 3 of the GNU General Public
+License, supplemented by the additional permissions listed below.
+
+ 0. Additional Definitions.
+
+ As used herein, "this License" refers to version 3 of the GNU Lesser
+General Public License, and the "GNU GPL" refers to version 3 of the GNU
+General Public License.
+
+ "The Library" refers to a covered work governed by this License,
+other than an Application or a Combined Work as defined below.
+
+ An "Application" is any work that makes use of an interface provided
+by the Library, but which is not otherwise based on the Library.
+Defining a subclass of a class defined by the Library is deemed a mode
+of using an interface provided by the Library.
+
+ A "Combined Work" is a work produced by combining or linking an
+Application with the Library. The particular version of the Library
+with which the Combined Work was made is also called the "Linked
+Version".
+
+ The "Minimal Corresponding Source" for a Combined Work means the
+Corresponding Source for the Combined Work, excluding any source code
+for portions of the Combined Work that, considered in isolation, are
+based on the Application, and not on the Linked Version.
+
+ The "Corresponding Application Code" for a Combined Work means the
+object code and/or source code for the Application, including any data
+and utility programs needed for reproducing the Combined Work from the
+Application, but excluding the System Libraries of the Combined Work.
+
+ 1. Exception to Section 3 of the GNU GPL.
+
+ You may convey a covered work under sections 3 and 4 of this License
+without being bound by section 3 of the GNU GPL.
+
+ 2. Conveying Modified Versions.
+
+ If you modify a copy of the Library, and, in your modifications, a
+facility refers to a function or data to be supplied by an Application
+that uses the facility (other than as an argument passed when the
+facility is invoked), then you may convey a copy of the modified
+version:
+
+ a) under this License, provided that you make a good faith effort to
+ ensure that, in the event an Application does not supply the
+ function or data, the facility still operates, and performs
+ whatever part of its purpose remains meaningful, or
+
+ b) under the GNU GPL, with none of the additional permissions of
+ this License applicable to that copy.
+
+ 3. Object Code Incorporating Material from Library Header Files.
+
+ The object code form of an Application may incorporate material from
+a header file that is part of the Library. You may convey such object
+code under terms of your choice, provided that, if the incorporated
+material is not limited to numerical parameters, data structure
+layouts and accessors, or small macros, inline functions and templates
+(ten or fewer lines in length), you do both of the following:
+
+ a) Give prominent notice with each copy of the object code that the
+ Library is used in it and that the Library and its use are
+ covered by this License.
+
+ b) Accompany the object code with a copy of the GNU GPL and this license
+ document.
+
+ 4. Combined Works.
+
+ You may convey a Combined Work under terms of your choice that,
+taken together, effectively do not restrict modification of the
+portions of the Library contained in the Combined Work and reverse
+engineering for debugging such modifications, if you also do each of
+the following:
+
+ a) Give prominent notice with each copy of the Combined Work that
+ the Library is used in it and that the Library and its use are
+ covered by this License.
+
+ b) Accompany the Combined Work with a copy of the GNU GPL and this license
+ document.
+
+ c) For a Combined Work that displays copyright notices during
+ execution, include the copyright notice for the Library among
+ these notices, as well as a reference directing the user to the
+ copies of the GNU GPL and this license document.
+
+ d) Do one of the following:
+
+ 0) Convey the Minimal Corresponding Source under the terms of this
+ License, and the Corresponding Application Code in a form
+ suitable for, and under terms that permit, the user to
+ recombine or relink the Application with a modified version of
+ the Linked Version to produce a modified Combined Work, in the
+ manner specified by section 6 of the GNU GPL for conveying
+ Corresponding Source.
+
+ 1) Use a suitable shared library mechanism for linking with the
+ Library. A suitable mechanism is one that (a) uses at run time
+ a copy of the Library already present on the user's computer
+ system, and (b) will operate properly with a modified version
+ of the Library that is interface-compatible with the Linked
+ Version.
+
+ e) Provide Installation Information, but only if you would otherwise
+ be required to provide such information under section 6 of the
+ GNU GPL, and only to the extent that such information is
+ necessary to install and execute a modified version of the
+ Combined Work produced by recombining or relinking the
+ Application with a modified version of the Linked Version. (If
+ you use option 4d0, the Installation Information must accompany
+ the Minimal Corresponding Source and Corresponding Application
+ Code. If you use option 4d1, you must provide the Installation
+ Information in the manner specified by section 6 of the GNU GPL
+ for conveying Corresponding Source.)
+
+ 5. Combined Libraries.
+
+ You may place library facilities that are a work based on the
+Library side by side in a single library together with other library
+facilities that are not Applications and are not covered by this
+License, and convey such a combined library under terms of your
+choice, if you do both of the following:
+
+ a) Accompany the combined library with a copy of the same work based
+ on the Library, uncombined with any other library facilities,
+ conveyed under the terms of this License.
+
+ b) Give prominent notice with the combined library that part of it
+ is a work based on the Library, and explaining where to find the
+ accompanying uncombined form of the same work.
+
+ 6. Revised Versions of the GNU Lesser General Public License.
+
+ The Free Software Foundation may publish revised and/or new versions
+of the GNU Lesser General Public License from time to time. Such new
+versions will be similar in spirit to the present version, but may
+differ in detail to address new problems or concerns.
+
+ Each version is given a distinguishing version number. If the
+Library as you received it specifies that a certain numbered version
+of the GNU Lesser General Public License "or any later version"
+applies to it, you have the option of following the terms and
+conditions either of that published version or of any later version
+published by the Free Software Foundation. If the Library as you
+received it does not specify a version number of the GNU Lesser
+General Public License, you may choose any version of the GNU Lesser
+General Public License ever published by the Free Software Foundation.
+
+ If the Library as you received it specifies that a proxy can decide
+whether future versions of the GNU Lesser General Public License shall
+apply, that proxy's public statement of acceptance of any version is
+permanent authorization for you to choose that version for the
+Library.
+
Added: trunk/src/it/update-header-file/README.txt
===================================================================
--- trunk/src/it/update-header-file/README.txt (rev 0)
+++ trunk/src/it/update-header-file/README.txt 2010-04-07 10:21:25 UTC (rev 1718)
@@ -0,0 +1,2 @@
+To test parserJava on a new project (says a project with no i18n translations)
+At the end we should have in target/generated-sources/i18n getters detected.
Added: trunk/src/it/update-header-file/changelog.txt
===================================================================
--- trunk/src/it/update-header-file/changelog.txt (rev 0)
+++ trunk/src/it/update-header-file/changelog.txt 2010-04-07 10:21:25 UTC (rev 1718)
@@ -0,0 +1 @@
+see the changelog of org.nuiton:i18n project.
\ No newline at end of file
Added: trunk/src/it/update-header-file/invoker.properties
===================================================================
--- trunk/src/it/update-header-file/invoker.properties (rev 0)
+++ trunk/src/it/update-header-file/invoker.properties 2010-04-07 10:21:25 UTC (rev 1718)
@@ -0,0 +1,21 @@
+# A comma or space separated list of goals/phases to execute, may
+# specify an empty list to execute the default goal of the IT project
+invoker.goals=clean compile
+
+# Optionally, a list of goals to run during further invocations of Maven
+#invoker.goals.2=${project.groupId}:${project.artifactId}:${project.version}:run
+
+# A comma or space separated list of profiles to activate
+#invoker.profiles=run-all run-once
+
+# The value for the environment variable MAVEN_OPTS
+#invoker.mavenOpts=-Dfile.encoding=UTF-16 -Xms32m -Xmx256m
+
+# Possible values are "fail-fast" (default), "fail-at-end" and "fail-never"
+invoker.failureBehavior=fail-at-end
+
+# The expected result of the build, possible values are "success" (default) and "failure"
+#invoker.buildResult=success
+
+# A boolean value controlling the -N flag, defaults to "false"
+#invoker.nonRecursive=false
Added: trunk/src/it/update-header-file/pom.xml
===================================================================
--- trunk/src/it/update-header-file/pom.xml (rev 0)
+++ trunk/src/it/update-header-file/pom.xml 2010-04-07 10:21:25 UTC (rev 1718)
@@ -0,0 +1,62 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <!-- ************************************************************* -->
+ <!-- *** POM Relationships *************************************** -->
+ <!-- ************************************************************* -->
+
+ <groupId>org.nuiton.license.test</groupId>
+ <artifactId>test-update-header-file</artifactId>
+ <version>@pom.version@</version>
+
+ <!-- ************************************************************* -->
+ <!-- *** Project Information ************************************* -->
+ <!-- ************************************************************* -->
+
+ <name>License Test :: update-header-file</name>
+
+ <!-- ************************************************************* -->
+ <!-- *** Build Settings ****************************************** -->
+ <!-- ************************************************************* -->
+
+ <packaging>jar</packaging>
+
+ <build>
+
+ <plugins>
+
+ <plugin>
+ <groupId>org.nuiton</groupId>
+ <artifactId>maven-license-plugin</artifactId>
+ <version>@pom.version@</version>
+ <configuration>
+ <verbose>true</verbose>
+ </configuration>
+ <executions>
+ <execution>
+ <id>first</id>
+ <goals>
+ <goal>update-header-file</goal>
+ </goals>
+ <phase>process-sources</phase>
+ </execution>
+ <execution>
+ <!-- this execution is to test with no files -->
+ <id>second</id>
+ <goals>
+ <goal>update-header-file</goal>
+ </goals>
+ <phase>compile</phase>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
+
+
Added: trunk/src/it/update-header-file/src/license/project.xml
===================================================================
--- trunk/src/it/update-header-file/src/license/project.xml (rev 0)
+++ trunk/src/it/update-header-file/src/license/project.xml 2010-04-07 10:21:25 UTC (rev 1718)
@@ -0,0 +1,20 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<project xmlns="http://maven-site.nuiton.org/maven-license-plugin/1.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven-site.nuiton.org/maven-license-plugin/1.0.0 http://maven-site.nuiton.org/maven-license-plugin/licenseProject-1.0.0.xsd">
+ <mainLicense>gpl_v3</mainLicense>
+ <licenseSets>
+ <licenseSet>
+ <licenseName>gpl_v3</licenseName>
+ <fileSets>
+ <fileSet>
+ <headerType>license-java</headerType>
+ <basedir>src/main/java</basedir>
+ <includes>
+ <include>**/*.java</include>
+ </includes>
+ </fileSet>
+ </fileSets>
+ </licenseSet>
+ </licenseSets>
+</project>
Added: trunk/src/it/update-header-file/src/main/java/org/nuiton/license/plugin/test/MyBean.java
===================================================================
--- trunk/src/it/update-header-file/src/main/java/org/nuiton/license/plugin/test/MyBean.java (rev 0)
+++ trunk/src/it/update-header-file/src/main/java/org/nuiton/license/plugin/test/MyBean.java 2010-04-07 10:21:25 UTC (rev 1718)
@@ -0,0 +1,4 @@
+package org.nuiton.license.plugin.test;
+
+public class MyBean {
+}
Property changes on: trunk/src/it/update-header-file/src/main/java/org/nuiton/license/plugin/test/MyBean.java
___________________________________________________________________
Added: svn:keywords
+ "Author Date Id Revision HeadURL
Added: trunk/src/it/update-header-file/verify.groovy
===================================================================
--- trunk/src/it/update-header-file/verify.groovy (rev 0)
+++ trunk/src/it/update-header-file/verify.groovy 2010-04-07 10:21:25 UTC (rev 1718)
@@ -0,0 +1,8 @@
+
+file = new File(basedir, 'src/main/java/org/nuiton/license/plugin/test/MyBean.java');
+assert file.exists();
+
+content = file.text;
+//assert content.contains( 'Copyright' );
+
+return true;
Modified: trunk/src/main/java/org/nuiton/license/plugin/AbstractLicenseMojo.java
===================================================================
--- trunk/src/main/java/org/nuiton/license/plugin/AbstractLicenseMojo.java 2010-04-06 21:35:23 UTC (rev 1717)
+++ trunk/src/main/java/org/nuiton/license/plugin/AbstractLicenseMojo.java 2010-04-07 10:21:25 UTC (rev 1718)
@@ -77,7 +77,10 @@
store.addJarRepository();
if (extraResolver != null) {
for (String s : extraResolver) {
- store.addRepository(s);
+ if (s != null && !s.trim().isEmpty()) {
+ getLog().info("adding extra resolver " + s);
+ store.addRepository(s);
+ }
}
}
store.init();
Modified: trunk/src/main/java/org/nuiton/license/plugin/UpdateHeaderFileMojo.java
===================================================================
--- trunk/src/main/java/org/nuiton/license/plugin/UpdateHeaderFileMojo.java 2010-04-06 21:35:23 UTC (rev 1717)
+++ trunk/src/main/java/org/nuiton/license/plugin/UpdateHeaderFileMojo.java 2010-04-07 10:21:25 UTC (rev 1718)
@@ -15,7 +15,6 @@
import java.util.List;
import java.util.Map;
-
/**
* The goal to update (or add) the licence header on some files.
* <p/>
@@ -69,14 +68,14 @@
*/
protected String projectName;
- /**
- * Le type de license a appliquer.
- *
- * @parameter expression="${license.licenseName}"
- * @required
- * @since 2.1
- */
- protected String licenseName;
+// /**
+// * Le type de license a appliquer.
+// *
+// * @parameter expression="${license.licenseName}"
+// * @required
+// * @since 2.1
+// */
+// protected String licenseName;
/**
* To specify an external licenses repository resolver (says the base url
@@ -193,9 +192,9 @@
return projectName;
}
- public String getLicenseName() {
- return licenseName;
- }
+// public String getLicenseName() {
+// return licenseName;
+// }
public String getInceptionYear() {
return inceptionYear;
@@ -241,9 +240,9 @@
this.inceptionYear = inceptionYear;
}
- public void setLicenseName(String licenseName) {
- this.licenseName = licenseName;
- }
+// public void setLicenseName(String licenseName) {
+// this.licenseName = licenseName;
+// }
public void setOrganizationName(String organizationName) {
this.organizationName = organizationName;
Modified: trunk/src/main/java/org/nuiton/license/plugin/model/License.java
===================================================================
--- trunk/src/main/java/org/nuiton/license/plugin/model/License.java 2010-04-06 21:35:23 UTC (rev 1717)
+++ trunk/src/main/java/org/nuiton/license/plugin/model/License.java 2010-04-07 10:21:25 UTC (rev 1718)
@@ -87,8 +87,10 @@
}
public String getLicenseContent(String encoding) throws IOException {
- if (licenseURL == null) {
- throw new IllegalStateException("no licenseURL defined, can not obtain license content in " + this);
+ if (baseURL == null) {
+ throw new IllegalStateException(
+ "no baseURL defined, can not obtain license content in " +
+ this);
}
Reader r = new BufferedReader(
@@ -102,7 +104,9 @@
public String getHeaderContent(String encoding) throws IOException {
if (baseURL == null) {
- throw new IllegalStateException("no baseURL defined, can not obtain header content in " + this);
+ throw new IllegalStateException(
+ "no baseURL defined, can not obtain header content in " +
+ this);
}
Reader r = new BufferedReader(
new InputStreamReader(getHeaderURL().openStream(), encoding));
Modified: trunk/src/main/java/org/nuiton/license/plugin/model/LicenseRepository.java
===================================================================
--- trunk/src/main/java/org/nuiton/license/plugin/model/LicenseRepository.java 2010-04-06 21:35:23 UTC (rev 1717)
+++ trunk/src/main/java/org/nuiton/license/plugin/model/LicenseRepository.java 2010-04-07 10:21:25 UTC (rev 1718)
@@ -85,7 +85,7 @@
if (!checkExists(definitionURL)) {
throw new IllegalArgumentException(
- "no licenses.properties found withurl [" +
+ "no licenses.properties found with url [" +
definitionURL + "] for resolver " + this);
}
Properties p = new Properties();
@@ -102,8 +102,11 @@
license.setDescription(licenseDescription);
license.setBaseURL(licenseURL);
if (log.isInfoEnabled()) {
- log.info("Adding license " + license);
+ log.info("register " + license.getDescription());
}
+ if (log.isDebugEnabled()) {
+ log.debug(license);
+ }
licenses.add(license);
}
licenses = Collections.unmodifiableList(licenses);
Modified: trunk/src/main/java/org/nuiton/license/plugin/model/LicenseStore.java
===================================================================
--- trunk/src/main/java/org/nuiton/license/plugin/model/LicenseStore.java 2010-04-06 21:35:23 UTC (rev 1717)
+++ trunk/src/main/java/org/nuiton/license/plugin/model/LicenseStore.java 2010-04-07 10:21:25 UTC (rev 1718)
@@ -128,7 +128,7 @@
}
if (log.isInfoEnabled()) {
- log.info("Adding a license repository " + repository);
+ log.info("Adding a license repository " + repository.getBaseURL());
}
repositories.add(repository);
}
Modified: trunk/src/test/java/org/nuiton/license/plugin/AddLicenseFileMojoTest.java
===================================================================
--- trunk/src/test/java/org/nuiton/license/plugin/AddLicenseFileMojoTest.java 2010-04-06 21:35:23 UTC (rev 1717)
+++ trunk/src/test/java/org/nuiton/license/plugin/AddLicenseFileMojoTest.java 2010-04-07 10:21:25 UTC (rev 1718)
@@ -65,7 +65,8 @@
AddLicenseFileMojo mojo = getMojo();
- long t0 = mojo.getLicenseFile().lastModified();
+ File licenseFile = mojo.getLicenseFile();
+ long t0 = licenseFile.lastModified();
// always assume pom is older than any file
// since we can not ensure order of copy test resources
@@ -74,7 +75,7 @@
// then executing the mojo, will do NOT change the licence file
mojo.execute();
- long t1 = mojo.getLicenseFile().lastModified();
+ long t1 = licenseFile.lastModified();
assertEquals(t0, t1);
@@ -82,7 +83,7 @@
mojo.setForce(true);
mojo.execute();
- t1 = mojo.getLicenseFile().lastModified();
+ t1 = licenseFile.lastModified();
assertTrue(t1 > t0);
}
@@ -92,7 +93,8 @@
AddLicenseFileMojo mojo = getMojo();
- long t0 = mojo.getLicenseFile().lastModified();
+ File licenseFile = mojo.getLicenseFile();
+ long t0 = licenseFile.lastModified();
// always assume pom is older than any file
// since we can not ensure order of copy test resources
@@ -101,7 +103,7 @@
// then executing the mojo, will do NOT change the licence file
mojo.execute();
- long t1 = mojo.getLicenseFile().lastModified();
+ long t1 = licenseFile.lastModified();
assertEquals(t0, t1);
@@ -109,7 +111,7 @@
mojo.setForce(true);
mojo.execute();
- t1 = mojo.getLicenseFile().lastModified();
+ t1 = licenseFile.lastModified();
assertTrue(t1 > t0);
}
Modified: trunk/src/test/java/org/nuiton/license/plugin/model/LicenseRepositoryTest.java
===================================================================
--- trunk/src/test/java/org/nuiton/license/plugin/model/LicenseRepositoryTest.java 2010-04-06 21:35:23 UTC (rev 1717)
+++ trunk/src/test/java/org/nuiton/license/plugin/model/LicenseRepositoryTest.java 2010-04-07 10:21:25 UTC (rev 1718)
@@ -41,5 +41,9 @@
License license = repository.getLicense(licenseName);
Assert.assertNotNull(license);
}
+
+ for (String licenseName : repository.getLicenseNames()) {
+ Assert.assertTrue(LicenseStoreTest.DEFAULT_LICENSES.contains(licenseName));
+ }
}
}
Modified: trunk/src/test/java/org/nuiton/license/plugin/model/LicenseStoreTest.java
===================================================================
--- trunk/src/test/java/org/nuiton/license/plugin/model/LicenseStoreTest.java 2010-04-06 21:35:23 UTC (rev 1717)
+++ trunk/src/test/java/org/nuiton/license/plugin/model/LicenseStoreTest.java 2010-04-07 10:21:25 UTC (rev 1718)
@@ -61,5 +61,10 @@
Assert.assertNotNull(license1);
Assert.assertEquals(license, license1);
}
+
+
+ for (String licenseName : store.getLicenseNames()) {
+ Assert.assertTrue(LicenseStoreTest.DEFAULT_LICENSES.contains(licenseName));
+ }
}
}
1
0
Author: tchemit
Date: 2010-04-06 23:35:23 +0200 (Tue, 06 Apr 2010)
New Revision: 1717
Log:
include xsd in site
Modified:
trunk/pom.xml
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2010-04-06 21:22:18 UTC (rev 1716)
+++ trunk/pom.xml 2010-04-06 21:35:23 UTC (rev 1717)
@@ -375,6 +375,31 @@
</executions>
</plugin>
+ <plugin>
+ <artifactId>maven-antrun-plugin</artifactId>
+ <!-- TC-20100117 : 1.3 does not works here -->
+ <version>1.2</version>
+ <executions>
+ <!-- copy generated xsd to site -->
+ <execution>
+ <id>copy licenProject.xsd</id>
+ <phase>pre-site</phase>
+ <configuration>
+ <tasks>
+ <copy verbose="${maven.verbose}"
+ failonerror="false"
+ overwrite="false"
+ file="target/generated-site/xsd/licenseProject-1.0.0.xsd"
+ tofile="target/site/licenseProject-1.0.0.xsd"/>
+ </tasks>
+ </configuration>
+ <goals>
+ <goal>run</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+
</plugins>
<pluginManagement>
1
0
r1716 - in trunk/src/main: java/org/nuiton/license/plugin java/org/nuiton/license/plugin/model mdo
by tchemit@users.nuiton.org 06 Apr '10
by tchemit@users.nuiton.org 06 Apr '10
06 Apr '10
Author: tchemit
Date: 2010-04-06 23:22:18 +0200 (Tue, 06 Apr 2010)
New Revision: 1716
Log:
- add headertype on each file set
- add getLicenNames on LicenRepository and LicenseStore
- check license anmes and header types before execution of mojo
Modified:
trunk/src/main/java/org/nuiton/license/plugin/UpdateHeaderFileMojo.java
trunk/src/main/java/org/nuiton/license/plugin/model/LicenseRepository.java
trunk/src/main/java/org/nuiton/license/plugin/model/LicenseStore.java
trunk/src/main/mdo/descriptor.mdo
Modified: trunk/src/main/java/org/nuiton/license/plugin/UpdateHeaderFileMojo.java
===================================================================
--- trunk/src/main/java/org/nuiton/license/plugin/UpdateHeaderFileMojo.java 2010-04-06 20:51:06 UTC (rev 1715)
+++ trunk/src/main/java/org/nuiton/license/plugin/UpdateHeaderFileMojo.java 2010-04-06 21:22:18 UTC (rev 1716)
@@ -4,12 +4,15 @@
import org.codehaus.plexus.velocity.VelocityComponent;
import org.nuiton.license.plugin.header.generator.HeaderGenerator;
import org.nuiton.license.plugin.model.LicenseStore;
+import org.nuiton.license.plugin.model.project.FileSet;
import org.nuiton.license.plugin.model.project.LicenseProject;
import org.nuiton.license.plugin.model.project.LicenseSet;
import org.nuiton.license.plugin.model.project.io.xpp3.LicenseProjectXpp3Reader;
import java.io.File;
import java.io.FileReader;
+import java.util.Arrays;
+import java.util.List;
import java.util.Map;
@@ -118,23 +121,24 @@
protected VelocityComponent velocity;
/**
- * All available generators
+ * All available generators.
*
* @component role="org.nuiton.license.plugin.header.generator.HeaderGenerator"
*/
protected Map<String, HeaderGenerator> _generators;
- /** le timestamp utilise pour la generation */
+ /** timestamp used for generation */
protected long timestamp;
/** store of licenses */
protected LicenseStore licenseStore;
- /** descriptor of project. */
+ /** descriptor of project */
protected LicenseProject licenseProject;
@Override
protected void init() throws Exception {
+
// init licenses store
licenseStore = createLicenseStore(licenseResolver);
@@ -145,15 +149,35 @@
} finally {
reader.close();
}
- // check main license is known
+
+ List<String> licenseNames = Arrays.asList(licenseStore.getLicenseNames());
+
+ // check licenses is known
String mainLicense = licenseProject.getMainLicense();
- if (!_generators.containsKey(mainLicense)) {
+ if (licenseStore.getLicense(mainLicense) == null) {
throw new MojoFailureException(
- "main license " + mainLicense +
- " is unknown, use one of " + _generators.keySet());
+ "main license '" + mainLicense +
+ "' is unknown, use one of " + licenseNames);
}
- for (LicenseSet set : licenseProject.getLicenseSets()) {
- set.getLicenseName();
+ for (LicenseSet licenseSet : licenseProject.getLicenseSets()) {
+
+ // check license name
+ String licenseName = licenseSet.getLicenseName();
+ if (licenseStore.getLicense(licenseName) == null) {
+ throw new MojoFailureException(
+ "license '" + licenseName +
+ "' is unknown, use one of " + licenseNames);
+ }
+
+ // check header types (for each file set)
+ for (FileSet fileSet : licenseSet.getFileSets()) {
+ String headerType = fileSet.getHeaderType();
+ if (!_generators.containsKey(headerType)) {
+ throw new MojoFailureException(
+ "headerType '" + headerType +
+ "' is unknown, use one of " + _generators.keySet());
+ }
+ }
}
}
Modified: trunk/src/main/java/org/nuiton/license/plugin/model/LicenseRepository.java
===================================================================
--- trunk/src/main/java/org/nuiton/license/plugin/model/LicenseRepository.java 2010-04-06 20:51:06 UTC (rev 1715)
+++ trunk/src/main/java/org/nuiton/license/plugin/model/LicenseRepository.java 2010-04-06 21:22:18 UTC (rev 1716)
@@ -113,6 +113,15 @@
}
}
+ public String[] getLicenseNames() {
+ checkInit("getLicenseNames");
+ List<String> result = new ArrayList<String>(licenses.size());
+ for (License license : this) {
+ result.add(license.getName());
+ }
+ return result.toArray(new String[result.size()]);
+ }
+
public License[] getLicenses() {
checkInit("getLicenses");
return licenses.toArray(new License[licenses.size()]);
Modified: trunk/src/main/java/org/nuiton/license/plugin/model/LicenseStore.java
===================================================================
--- trunk/src/main/java/org/nuiton/license/plugin/model/LicenseStore.java 2010-04-06 20:51:06 UTC (rev 1715)
+++ trunk/src/main/java/org/nuiton/license/plugin/model/LicenseStore.java 2010-04-06 21:22:18 UTC (rev 1716)
@@ -49,6 +49,17 @@
return repositories;
}
+ public String[] getLicenseNames() {
+ checkInit("getLicenseNames");
+ List<String> result = new ArrayList<String>();
+ for (LicenseRepository repository : this) {
+ for (License license : repository) {
+ result.add(license.getName());
+ }
+ }
+ return result.toArray(new String[result.size()]);
+ }
+
public License[] getLicenses() {
checkInit("getLicenses");
List<License> result = new ArrayList<License>();
Modified: trunk/src/main/mdo/descriptor.mdo
===================================================================
--- trunk/src/main/mdo/descriptor.mdo 2010-04-06 20:51:06 UTC (rev 1715)
+++ trunk/src/main/mdo/descriptor.mdo 2010-04-06 21:22:18 UTC (rev 1716)
@@ -70,7 +70,7 @@
<name>LicenseSet</name>
<description>
<![CDATA[
- A licenseSet represent one license to apply to one or more filesets.
+ A licenseSet represents one license to apply to one or more filesets.
]]>
</description>
<version>1.0.0+</version>
@@ -80,9 +80,7 @@
<version>1.0.0+</version>
<type>String</type>
<required>true</required>
- <description>
- The license to apply in this set.
- </description>
+ <description>The license to apply in this set.</description>
</field>
<field>
<name>fileSets</name>
@@ -105,10 +103,20 @@
<name>FileSet</name>
<version>1.0.0+</version>
<description>
- A fileSet allows the inclusion of groups of files into the license set.
+ <![CDATA[
+ A fileSet allows the inclusion of groups of files into the license set
+ and defines also the type of header to generate.
+ ]]>
</description>
<fields>
<field>
+ <name>headerType</name>
+ <version>1.0.0+</version>
+ <type>String</type>
+ <required>true</required>
+ <description>The type of header to generate (or updates).</description>
+ </field>
+ <field>
<name>useDefaultExcludes</name>
<version>1.0.0+</version>
<type>boolean</type>
1
0
r1715 - in trunk/src/main: java/org/nuiton/license/plugin mdo
by tchemit@users.nuiton.org 06 Apr '10
by tchemit@users.nuiton.org 06 Apr '10
06 Apr '10
Author: tchemit
Date: 2010-04-06 22:51:06 +0200 (Tue, 06 Apr 2010)
New Revision: 1715
Log:
clean pom + begin of use of Project descriptor
Modified:
trunk/src/main/java/org/nuiton/license/plugin/UpdateHeaderFileMojo.java
trunk/src/main/mdo/descriptor.mdo
Modified: trunk/src/main/java/org/nuiton/license/plugin/UpdateHeaderFileMojo.java
===================================================================
--- trunk/src/main/java/org/nuiton/license/plugin/UpdateHeaderFileMojo.java 2010-04-06 20:46:18 UTC (rev 1714)
+++ trunk/src/main/java/org/nuiton/license/plugin/UpdateHeaderFileMojo.java 2010-04-06 20:51:06 UTC (rev 1715)
@@ -1,9 +1,11 @@
package org.nuiton.license.plugin;
+import org.apache.maven.plugin.MojoFailureException;
import org.codehaus.plexus.velocity.VelocityComponent;
import org.nuiton.license.plugin.header.generator.HeaderGenerator;
import org.nuiton.license.plugin.model.LicenseStore;
import org.nuiton.license.plugin.model.project.LicenseProject;
+import org.nuiton.license.plugin.model.project.LicenseSet;
import org.nuiton.license.plugin.model.project.io.xpp3.LicenseProjectXpp3Reader;
import java.io.File;
@@ -143,6 +145,16 @@
} finally {
reader.close();
}
+ // check main license is known
+ String mainLicense = licenseProject.getMainLicense();
+ if (!_generators.containsKey(mainLicense)) {
+ throw new MojoFailureException(
+ "main license " + mainLicense +
+ " is unknown, use one of " + _generators.keySet());
+ }
+ for (LicenseSet set : licenseProject.getLicenseSets()) {
+ set.getLicenseName();
+ }
}
@Override
Modified: trunk/src/main/mdo/descriptor.mdo
===================================================================
--- trunk/src/main/mdo/descriptor.mdo 2010-04-06 20:46:18 UTC (rev 1714)
+++ trunk/src/main/mdo/descriptor.mdo 2010-04-06 20:51:06 UTC (rev 1715)
@@ -77,7 +77,7 @@
<fields>
<field>
<name>licenseName</name>
- <version>1.1.0+</version>
+ <version>1.0.0+</version>
<type>String</type>
<required>true</required>
<description>
@@ -110,7 +110,7 @@
<fields>
<field>
<name>useDefaultExcludes</name>
- <version>1.1.0+</version>
+ <version>1.0.0+</version>
<type>boolean</type>
<defaultValue>true</defaultValue>
<description>
1
0
06 Apr '10
Author: tchemit
Date: 2010-04-06 22:46:18 +0200 (Tue, 06 Apr 2010)
New Revision: 1714
Log:
clean pom + begin of use of Project descriptor
Modified:
trunk/pom.xml
trunk/src/main/java/org/nuiton/license/plugin/UpdateHeaderFileMojo.java
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2010-04-06 19:42:20 UTC (rev 1713)
+++ trunk/pom.xml 2010-04-06 20:46:18 UTC (rev 1714)
@@ -382,11 +382,6 @@
<plugin>
<artifactId>maven-site-plugin</artifactId>
- <!-- TODO Remove this when using mavenpom >=2.0.3 -->
- <!--<configuration>-->
- <!--<locales>${siteLocales}</locales>-->
- <!--<generateSitemap>true</generateSitemap>-->
- <!--</configuration>-->
<dependencies>
<dependency>
<groupId>org.nuiton.jrst</groupId>
Modified: trunk/src/main/java/org/nuiton/license/plugin/UpdateHeaderFileMojo.java
===================================================================
--- trunk/src/main/java/org/nuiton/license/plugin/UpdateHeaderFileMojo.java 2010-04-06 19:42:20 UTC (rev 1713)
+++ trunk/src/main/java/org/nuiton/license/plugin/UpdateHeaderFileMojo.java 2010-04-06 20:46:18 UTC (rev 1714)
@@ -3,7 +3,11 @@
import org.codehaus.plexus.velocity.VelocityComponent;
import org.nuiton.license.plugin.header.generator.HeaderGenerator;
import org.nuiton.license.plugin.model.LicenseStore;
+import org.nuiton.license.plugin.model.project.LicenseProject;
+import org.nuiton.license.plugin.model.project.io.xpp3.LicenseProjectXpp3Reader;
+import java.io.File;
+import java.io.FileReader;
import java.util.Map;
@@ -24,11 +28,20 @@
public class UpdateHeaderFileMojo extends AbstractLicenseMojo {
/**
+ * The project license descriptor file.
+ *
+ * @parameter expression="${license.descriptor}" default-value="src/license/project.xml"
+ * @required
+ * @since 2.1
+ */
+ protected File descriptor;
+
+ /**
* l'annee de creation du module (sera place dans le header)
*
* @parameter expression="${license.inceptionYear}" default-value="${project.inceptionYear}"
* @required
- * @since 1.0.0
+ * @since 2.1
*/
protected String inceptionYear;
@@ -38,7 +51,7 @@
* @parameter expression="${license.organizationName}"
* default-value="${project.organization.name}"
* @required
- * @since 1.0.0
+ * @since 2.1
*/
protected String organizationName;
@@ -47,7 +60,7 @@
*
* @parameter expression="${license.projectName}" default-value="${project.name}"
* @required
- * @since 1.0.0
+ * @since 2.1
*/
protected String projectName;
@@ -56,7 +69,7 @@
*
* @parameter expression="${license.licenseName}"
* @required
- * @since 1.0.0
+ * @since 2.1
*/
protected String licenseName;
@@ -69,6 +82,7 @@
*/
protected String licenseResolver;
+
/**
* A flag to keep a backup of every modified file.
*
@@ -114,10 +128,21 @@
/** store of licenses */
protected LicenseStore licenseStore;
+ /** descriptor of project. */
+ protected LicenseProject licenseProject;
+
@Override
protected void init() throws Exception {
// init licenses store
licenseStore = createLicenseStore(licenseResolver);
+
+ // load project descriptor
+ FileReader reader = new FileReader(descriptor);
+ try {
+ licenseProject = new LicenseProjectXpp3Reader().read(reader);
+ } finally {
+ reader.close();
+ }
}
@Override
1
0
06 Apr '10
Author: tchemit
Date: 2010-04-06 21:42:20 +0200 (Tue, 06 Apr 2010)
New Revision: 1713
Log:
remove onsolote package
Removed:
trunk/src/test/java/org/nuiton/license/plugin/repository/
1
0
r1712 - in trunk: . src/main src/main/mdo src/main/resources src/main/resources/license
by tchemit@users.nuiton.org 06 Apr '10
by tchemit@users.nuiton.org 06 Apr '10
06 Apr '10
Author: tchemit
Date: 2010-04-06 21:28:25 +0200 (Tue, 06 Apr 2010)
New Revision: 1712
Log:
use modello to generate project license descriptor file
Added:
trunk/src/main/mdo/
trunk/src/main/mdo/descriptor.mdo
trunk/src/main/resources/licenseProjects/
Modified:
trunk/pom.xml
trunk/src/main/resources/license/defaultHeader.vm
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2010-04-06 16:44:13 UTC (rev 1711)
+++ trunk/pom.xml 2010-04-06 19:28:25 UTC (rev 1712)
@@ -1,5 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
@@ -12,7 +14,7 @@
<artifactId>mavenpom4redmine</artifactId>
<version>2.0.7</version>
</parent>
-
+
<artifactId>maven-license-plugin</artifactId>
<version>2.1-SNAPSHOT</version>
@@ -248,7 +250,8 @@
<name>Maven License Plugin</name>
<description>
- Plugin pour mettre à jour l'en-tête des fichiers (avec la license choisie)
+ Plugin pour mettre à jour l'en-tête des fichiers (avec la license
+ choisie)
dans un module maven 2.
</description>
<inceptionYear>2008</inceptionYear>
@@ -274,9 +277,15 @@
<!-- Source control management. -->
<scm>
- <connection>scm:svn:http://svn.nuiton.org/svn/maven-license-plugin/trunk</connection>
- <developerConnection>scm:svn:http://svn.nuiton.org/svn/maven-license-plugin/trunk</developerConnection>
- <url>http://www.nuiton.org/repositories/browse/maven-license-plugin/trunk</url>
+ <connection>
+ scm:svn:http://svn.nuiton.org/svn/maven-license-plugin/trunk
+ </connection>
+ <developerConnection>
+ scm:svn:http://svn.nuiton.org/svn/maven-license-plugin/trunk
+ </developerConnection>
+ <url>
+ http://www.nuiton.org/repositories/browse/maven-license-plugin/trunk
+ </url>
</scm>
<!-- ************************************************************* -->
@@ -289,6 +298,7 @@
<processor.version>1.0.2</processor.version>
<helper.version>1.2.3-SNAPSHOT</helper.version>
+ <mdoVersion>1.0.0</mdoVersion>
<!-- documentation is in english -->
<siteLocales>en</siteLocales>
@@ -299,6 +309,48 @@
<plugins>
+ <!-- generate descriptor model + reader -->
+ <plugin>
+ <groupId>org.codehaus.modello</groupId>
+ <artifactId>modello-maven-plugin</artifactId>
+ <version>1.0</version>
+ <configuration>
+ <version>${mdoVersion}</version>
+ <lineLength>80</lineLength>
+ <useJava5>true</useJava5>
+ </configuration>
+ <executions>
+ <execution>
+ <id>mdo</id>
+ <phase>generate-sources</phase>
+ <goals>
+ <goal>xpp3-reader</goal>
+ <goal>xpp3-writer</goal>
+ <goal>java</goal>
+ <goal>xsd</goal>
+ </goals>
+ <configuration>
+ <models>
+ <model>src/main/mdo/descriptor.mdo</model>
+ </models>
+ </configuration>
+ </execution>
+ <execution>
+ <id>mdo-site</id>
+ <phase>pre-site</phase>
+ <goals>
+ <goal>xdoc</goal>
+ <goal>xsd</goal>
+ </goals>
+ <configuration>
+ <models>
+ <model>src/main/mdo/descriptor.mdo</model>
+ </models>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+
<!-- expose new plexus components -->
<plugin>
<groupId>org.codehaus.plexus</groupId>
@@ -331,10 +383,10 @@
<plugin>
<artifactId>maven-site-plugin</artifactId>
<!-- TODO Remove this when using mavenpom >=2.0.3 -->
- <configuration>
- <locales>${siteLocales}</locales>
- <generateSitemap>true</generateSitemap>
- </configuration>
+ <!--<configuration>-->
+ <!--<locales>${siteLocales}</locales>-->
+ <!--<generateSitemap>true</generateSitemap>-->
+ <!--</configuration>-->
<dependencies>
<dependency>
<groupId>org.nuiton.jrst</groupId>
@@ -362,7 +414,7 @@
<artifactId>maven-plugin-plugin</artifactId>
<version>2.5.1</version>
</plugin>
-
+
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
Added: trunk/src/main/mdo/descriptor.mdo
===================================================================
--- trunk/src/main/mdo/descriptor.mdo (rev 0)
+++ trunk/src/main/mdo/descriptor.mdo 2010-04-06 19:28:25 UTC (rev 1712)
@@ -0,0 +1,183 @@
+<?xml version="1.0"?>
+
+<model xsd.namespace="http://maven-site.nuiton.org/maven-license-plugin/1.0.0"
+ xsd.targetNamespace="http://maven-site.nuiton.org/maven-license-plugin/1.0.0">
+
+ <id>licenseProject</id>
+ <name>LicenseProject</name>
+ <description>
+ <![CDATA[
+ <p>
+ Maven License Plugin relies on the provided project descriptors to dictate
+ its execution. Although there are already prefabricated descriptors available
+ for use, they can only suffice some of the common assembly requirements.
+ </p>
+ <p>
+ So in order for you to customize the way the License Plugin creates your
+ assemblies, you need to know how to use the License project Descriptor.
+ </p>
+ <p>
+ This descriptor specifies the type of licenses to apply for some defined
+ filesets.
+ </p>
+ ]]>
+ </description>
+ <defaults>
+ <default>
+ <key>package</key>
+ <value>org.nuiton.license.plugin.model.project</value>
+ </default>
+ </defaults>
+ <classes>
+ <class rootElement="true" xml.tagName="project">
+ <name>LicenseProject</name>
+ <description>
+ <![CDATA[
+ An license project defines a collection of files to be reacted by the
+ plugin (says update header).
+ ]]>
+ </description>
+ <version>1.0.0+</version>
+ <fields>
+ <field>
+ <name>mainLicense</name>
+ <version>1.0.0+</version>
+ <required>true</required>
+ <type>String</type>
+ <description>
+ The main license of the project (or module). The LICENSE.txt will
+ contains the content of this license.
+ </description>
+ </field>
+ <field>
+ <name>licenseSets</name>
+ <version>1.0.0+</version>
+ <association>
+ <type>LicenseSet</type>
+ <multiplicity>*</multiplicity>
+ </association>
+ <description>
+ <![CDATA[
+ Specifies licenses to apply on a project. A licenseSet is specified
+ by providing one or more of <licenseSet> subelements.
+ ]]>
+ </description>
+ </field>
+ </fields>
+ </class>
+
+ <class>
+ <name>LicenseSet</name>
+ <description>
+ <![CDATA[
+ A licenseSet represent one license to apply to one or more filesets.
+ ]]>
+ </description>
+ <version>1.0.0+</version>
+ <fields>
+ <field>
+ <name>licenseName</name>
+ <version>1.1.0+</version>
+ <type>String</type>
+ <required>true</required>
+ <description>
+ The license to apply in this set.
+ </description>
+ </field>
+ <field>
+ <name>fileSets</name>
+ <version>1.0.0+</version>
+ <association>
+ <type>FileSet</type>
+ <multiplicity>*</multiplicity>
+ </association>
+ <description>
+ <![CDATA[
+ Specifies file sets to include in the license set. A fileSet is specified
+ by providing one or more of <licenseSet> subelements.
+ ]]>
+ </description>
+ </field>
+ </fields>
+ </class>
+
+ <class>
+ <name>FileSet</name>
+ <version>1.0.0+</version>
+ <description>
+ A fileSet allows the inclusion of groups of files into the license set.
+ </description>
+ <fields>
+ <field>
+ <name>useDefaultExcludes</name>
+ <version>1.1.0+</version>
+ <type>boolean</type>
+ <defaultValue>true</defaultValue>
+ <description>
+ Whether standard exclusion patterns, such as those matching CVS and Subversion
+ metadata files, should be used when calculating the files affected by this set.
+ For backward compatibility, the default value is true. (Since 2.2)
+ </description>
+ </field>
+ <field>
+ <name>basedir</name>
+ <version>1.0.0+</version>
+ <type>String</type>
+ <description>
+ Sets the basedir directory relative to the root
+ of the root directory of the assembly. For example,
+ "log" will put the specified files in the log directory.
+ </description>
+ </field>
+ <field>
+ <name>includes</name>
+ <version>1.0.0+</version>
+ <association>
+ <type>String</type>
+ <multiplicity>*</multiplicity>
+ </association>
+ <description>
+ <![CDATA[
+ When <include> subelements are present, they define a set of
+ files and directory to include. If none is present, then
+ <includes> represents all valid values.
+ ]]>
+ </description>
+ </field>
+ <field>
+ <name>excludes</name>
+ <version>1.0.0+</version>
+ <association>
+ <type>String</type>
+ <multiplicity>*</multiplicity>
+ </association>
+ <description>
+ <![CDATA[
+ When <exclude> subelements are present, they define a set of
+ files and directory to exclude. If none is present, then
+ <excludes> represents no exclusions.
+ ]]>
+ </description>
+ </field>
+ <field>
+ <name>lineEnding</name>
+ <version>1.0.0+</version>
+ <type>String</type>
+ <description>
+ <![CDATA[
+ Sets the line-endings of the files in this fileSet.
+ Valid values:
+ <ul>
+ <li><b>"keep"</b> - Preserve all line endings</li>
+ <li><b>"unix"</b> - Use Unix-style line endings</li>
+ <li><b>"lf"</b> - Use a single line-feed line endings</li>
+ <li><b>"dos"</b> - Use DOS-style line endings</li>
+ <li><b>"crlf"</b> - Use Carraige-return, line-feed line endings</li>
+ </ul>
+ ]]>
+ </description>
+ </field>
+ </fields>
+ </class>
+ </classes>
+</model>
Modified: trunk/src/main/resources/license/defaultHeader.vm
===================================================================
--- trunk/src/main/resources/license/defaultHeader.vm 2010-04-06 16:44:13 UTC (rev 1711)
+++ trunk/src/main/resources/license/defaultHeader.vm 2010-04-06 19:28:25 UTC (rev 1712)
@@ -1,4 +1,5 @@
$projectName
+--
Copyright (C) $inceptionYear $organizationName
-
+--
$licenseContent
1
0