Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

POM Project Organization properties #200

Merged
merged 2 commits into from
Apr 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 `<properties>` tag)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
invoker.goals = license:format
11 changes: 11 additions & 0 deletions license-maven-plugin/src/it/pom-properties/mock-license.txt
Original file line number Diff line number Diff line change
@@ -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
39 changes: 39 additions & 0 deletions license-maven-plugin/src/it/pom-properties/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.mycila.license-maven-plugin.it</groupId>
<artifactId>pom-properties</artifactId>
<version>1.0.0</version>

<name>Format using pom properties</name>
<description>Integration Test for checking pom property replacement</description>
<url>https://it.example.org</url>
<inceptionYear>2008</inceptionYear>
<organization>
<name>Example, Inc.</name>
<url>https://example.com</url>
</organization>

<build>
<plugins>
<plugin>
<groupId>com.mycila</groupId>
<artifactId>license-maven-plugin</artifactId>
<version>@project.version@</version>
<configuration>
<header>mock-license.txt</header>
<excludes>
<exclude>invoker.properties</exclude>
<exclude>pom.xml</exclude>
<exclude>*.groovy</exclude>
<exclude>**/*.expected</exclude>
<exclude>*.log</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>

</project>
23 changes: 23 additions & 0 deletions license-maven-plugin/src/it/pom-properties/setup.groovy
Original file line number Diff line number Diff line change
@@ -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;
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.mycila.it;

public class Unformatted1 {
}
Original file line number Diff line number Diff line change
@@ -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 {
}
36 changes: 36 additions & 0 deletions license-maven-plugin/src/it/pom-properties/verify.groovy
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -596,6 +597,11 @@ private Map<String, String> 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());

Expand Down