r1716 - in trunk/src/main: java/org/nuiton/license/plugin java/org/nuiton/license/plugin/model mdo
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>
participants (1)
-
tchemit@users.nuiton.org