diff --git a/README.md b/README.md index c99e63154..386650799 100755 --- a/README.md +++ b/README.md @@ -221,6 +221,8 @@ Properties which can be used as placeholder comes from: - `project.description` - `project.inceptionYear` - `project.url` + - `project.organization.name` + - `project.organization.url` - Per-Document properties - `file.name` - Plugin configuration properties (from `` tag) diff --git a/license-maven-plugin/src/it/pom-properties/invoker.properties b/license-maven-plugin/src/it/pom-properties/invoker.properties new file mode 100644 index 000000000..f698fd62a --- /dev/null +++ b/license-maven-plugin/src/it/pom-properties/invoker.properties @@ -0,0 +1 @@ +invoker.goals = license:format \ No newline at end of file diff --git a/license-maven-plugin/src/it/pom-properties/mock-license.txt b/license-maven-plugin/src/it/pom-properties/mock-license.txt new file mode 100644 index 000000000..cf3af799d --- /dev/null +++ b/license-maven-plugin/src/it/pom-properties/mock-license.txt @@ -0,0 +1,11 @@ +Mock license +${project.groupId} +${project.artifactId} +${project.version} +${project.name} +${project.description} +${project.inceptionYear} +${project.url} +${project.organization.name} +${project.organization.url} +ends here diff --git a/license-maven-plugin/src/it/pom-properties/pom.xml b/license-maven-plugin/src/it/pom-properties/pom.xml new file mode 100644 index 000000000..da9a9b178 --- /dev/null +++ b/license-maven-plugin/src/it/pom-properties/pom.xml @@ -0,0 +1,39 @@ + + 4.0.0 + + com.mycila.license-maven-plugin.it + pom-properties + 1.0.0 + + Format using pom properties + Integration Test for checking pom property replacement + https://it.example.org + 2008 + + Example, Inc. + https://example.com + + + + + + com.mycila + license-maven-plugin + @project.version@ + +
mock-license.txt
+ + invoker.properties + pom.xml + *.groovy + **/*.expected + *.log + +
+
+
+
+ +
diff --git a/license-maven-plugin/src/it/pom-properties/setup.groovy b/license-maven-plugin/src/it/pom-properties/setup.groovy new file mode 100644 index 000000000..46c3734b0 --- /dev/null +++ b/license-maven-plugin/src/it/pom-properties/setup.groovy @@ -0,0 +1,23 @@ +import java.nio.file.Files +import java.nio.file.Path + +final Path base = basedir.toPath() + +if (!Files.exists(base) || !Files.isDirectory(base)) { + System.err.println("base directory is missing.") + return false +} + +final Path expectedJavaFile = base.resolve("src/main/java/com/mycilla/it/Unformatted1.java.expected") +if (!Files.exists(expectedJavaFile)) { + System.err.println("Unformatted1.java.expected file is missing.") + return false +} + +final Path unformattedJavaFile = base.resolve("src/main/java/com/mycilla/it/Unformatted1.java") +if (!Files.exists(unformattedJavaFile)) { + System.err.println("Unformatted1.java file is missing.") + return false +} + +return true; diff --git a/license-maven-plugin/src/it/pom-properties/src/main/java/com/mycilla/it/Unformatted1.java b/license-maven-plugin/src/it/pom-properties/src/main/java/com/mycilla/it/Unformatted1.java new file mode 100644 index 000000000..53c628eba --- /dev/null +++ b/license-maven-plugin/src/it/pom-properties/src/main/java/com/mycilla/it/Unformatted1.java @@ -0,0 +1,4 @@ +package com.mycila.it; + +public class Unformatted1 { +} diff --git a/license-maven-plugin/src/it/pom-properties/src/main/java/com/mycilla/it/Unformatted1.java.expected b/license-maven-plugin/src/it/pom-properties/src/main/java/com/mycilla/it/Unformatted1.java.expected new file mode 100644 index 000000000..f50f7028b --- /dev/null +++ b/license-maven-plugin/src/it/pom-properties/src/main/java/com/mycilla/it/Unformatted1.java.expected @@ -0,0 +1,17 @@ +/* + * Mock license + * com.mycila.license-maven-plugin.it + * pom-properties + * 1.0.0 + * Format using pom properties + * Integration Test for checking pom property replacement + * 2008 + * https://it.example.org + * Example, Inc. + * https://example.com + * ends here + */ +package com.mycila.it; + +public class Unformatted1 { +} diff --git a/license-maven-plugin/src/it/pom-properties/verify.groovy b/license-maven-plugin/src/it/pom-properties/verify.groovy new file mode 100644 index 000000000..088bc8e11 --- /dev/null +++ b/license-maven-plugin/src/it/pom-properties/verify.groovy @@ -0,0 +1,36 @@ +import java.nio.file.Files +import java.nio.file.Path + +import static org.junit.Assert.* + + +final Path base = basedir.toPath() + +if (!Files.exists(base) || !Files.isDirectory(base)) { + System.err.println("base directory is missing.") + return false +} + +final Path license = base.resolve("mock-license.txt") +if (!Files.exists(license)) { + System.err.println("license file is missing.") + return false +} + +final Path expectedJavaFile = base.resolve("src/main/java/com/mycilla/it/Unformatted1.java.expected") +if (!Files.exists(expectedJavaFile)) { + System.err.println(expectedJavaFile.getFileName() + " file is missing.") + return false +} + +final Path formattedJavaFile = base.resolve("src/main/java/com/mycilla/it/Unformatted1.java") +if (!Files.exists(formattedJavaFile)) { + System.err.println(formattedJavaFile.getFileName() + " file is missing.") + return false +} +final String expected = new String(Files.readAllBytes(expectedJavaFile)) +final String actual = new String(Files.readAllBytes(formattedJavaFile)) + +assertEquals(expected, actual) + +return true diff --git a/license-maven-plugin/src/main/java/com/mycila/maven/plugin/license/AbstractLicenseMojo.java b/license-maven-plugin/src/main/java/com/mycila/maven/plugin/license/AbstractLicenseMojo.java index 0f1db58c1..a056093a9 100755 --- a/license-maven-plugin/src/main/java/com/mycila/maven/plugin/license/AbstractLicenseMojo.java +++ b/license-maven-plugin/src/main/java/com/mycila/maven/plugin/license/AbstractLicenseMojo.java @@ -28,6 +28,7 @@ import com.mycila.maven.plugin.license.util.resource.ResourceFinder; import com.mycila.xmltool.XMLDoc; import org.apache.maven.artifact.DependencyResolutionRequiredException; +import org.apache.maven.model.Organization; import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; @@ -596,6 +597,11 @@ private Map mergeProperties(final LicenseSet licenseSet, final D props.put("project.description", project.getDescription()); props.put("project.inceptionYear", project.getInceptionYear()); props.put("project.url", project.getUrl()); + Organization org = project.getOrganization(); + if(org != null){ + props.put("project.organization.name", org.getName()); + props.put("project.organization.url", org.getUrl()); + } // then add per document properties props.put("file.name", document.getFile().getName());