Skip to content

Commit

Permalink
PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
cstamas committed Apr 30, 2024
1 parent 24abd59 commit 9c5b114
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ protected void initialize(Model model, Properties parameters) throws ModelloExce

generatedVersion = new Version(version);

packageWithVersion = Boolean.valueOf(getParameter(parameters, ModelloParameterConstants.PACKAGE_WITH_VERSION));
packageWithVersion =
Boolean.parseBoolean(getParameter(parameters, ModelloParameterConstants.PACKAGE_WITH_VERSION));

encoding = parameters.getProperty(ModelloParameterConstants.ENCODING);

Expand Down Expand Up @@ -116,16 +117,16 @@ protected String getHeader() {
if (header == null) {
return getGeneratedHeader();
}
header += "\n";
header += System.lineSeparator();
header += getGeneratedHeader();
return header;
}

protected String getGeneratedHeader() {
String version = getClass().getPackage().getImplementationVersion();
return "=================== DO NOT EDIT THIS FILE ====================\n"
+ "Generated by Modello" + ((version == null) ? "" : (' ' + version)) + ",\n"
+ "any modifications will be overwritten.\n"
return "=================== DO NOT EDIT THIS FILE ====================" + System.lineSeparator()
+ "Generated by Modello" + ((version == null) ? "" : (' ' + version)) + "," + System.lineSeparator()
+ "any modifications will be overwritten." + System.lineSeparator()
+ "==============================================================";
}

Expand Down
2 changes: 2 additions & 0 deletions modello-maven-plugin/src/it/maven-model/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,14 @@
<models>
<model>src/main/mdo/maven.mdo</model>
</models>
<licenseText>The license of this file</licenseText>
</configuration>
<executions>
<execution>
<goals>
<goal>java</goal>
<goal>xpp3-reader</goal>
<goal>xsd</goal>
</goals>
</execution>
</executions>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@
| definition of these types
|
-->
<model>
<model xmlns="http://codehaus-plexus.github.io/MODELLO/2.3.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://codehaus-plexus.github.io/MODELLO/2.3.0 https://codehaus-plexus.github.io/modello/xsd/modello-2.3.0.xsd"
xml.namespace="http://maven.apache.org/POM/${version}"
xml.schemaLocation="https://maven.apache.org/xsd/maven-${version}.xsd">
<id>maven</id>
<name>Maven</name>
<description><![CDATA[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@
import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.InvalidPathException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
Expand Down Expand Up @@ -100,14 +97,21 @@ public abstract class AbstractModelloGeneratorMojo extends AbstractMojo {
private List<String> packagedVersions = new ArrayList<String>();

/**
* The contents of license header, verbatim. It may be file path and if file exists, will be loaded up. Otherwise,
* the contents of this parameter is reused as-is.
* The contents of license header text, verbatim.
*
* @since 2.3.1
*/
@Parameter
private String licenseText;

/**
* The file that contains license header text. If both configured, the {@link #licenseText} prevails.
*
* @since 2.3.1
*/
@Parameter
private File licenseFile;

/**
* @since 1.0.1
*/
Expand Down Expand Up @@ -178,20 +182,18 @@ public void execute() throws MojoExecutionException {
ModelloParameterConstants.ALL_VERSIONS, StringUtils.join(packagedVersions.iterator(), ","));
}

if (licenseText != null && !licenseText.trim().isEmpty()) {
if (licenseText != null || licenseFile != null) {
String license = "";
try {
Path licenseFile = Paths.get(licenseText);
if (Files.isRegularFile(licenseFile)) {
license = String.join("\n", Files.readAllLines(licenseFile));
}
} catch (IOException e) {
throw new MojoExecutionException("Could not load up license text from " + licenseText, e);
} catch (InvalidPathException e) {
// ignore, is verbatim text probably
}
if (license.isEmpty()) {
if (licenseText != null) {
// licenseText prevails
license = licenseText;
} else {
try {
// load it up and hard fail if cannot, as it is user misconfiguration
license = String.join(System.lineSeparator(), Files.readAllLines(licenseFile.toPath()));
} catch (IOException e) {
throw new MojoExecutionException("Could not load up license text from " + licenseFile, e);
}
}
parameters.setProperty(ModelloParameterConstants.LICENSE_TEXT, license);
}
Expand Down

0 comments on commit 9c5b114

Please sign in to comment.