-
-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Default values for configuration, especially VersionInfo (#205)
* Fix: Escape angle brackets in Markdown documentation to be printed out. GitHub uses one of many kinds of Markdown syntaxes. In this one it does not display plain text inside angle brackets (like <any text>) in the headers, so we need to escape them. For details, please see the issue: microsoft/vscode#12491 * `disableVersionInfoDefaults` docs note added * Snapshot version bump according to default parameters changes * New parameter for disabling VersionInfo defaults * Filling out VersionInfo defaults * Filling out VersionInfo defaults * Unit tests for Copyright generator * Copyright generator description * JUnitParams lib added to POM.xml * Unit tests for Launch4j fileVersion generator * Additional Unit tests for Launch4j fileVersion generator * Refactoring of Launch4j fileVersion generator * "errTitle" default value provided * "errTitle" default value in docs * "versionInfo -> originalFilename" default value added * release version notes Resolves #98 * Line added to MOJO doc * trademarks & companyName also filled by defaults * Mockito Core library added * VersionInfo refactoring * VersionInfo unit tests * Adds missing VersionInfo unit tests * Adds missing Mojo param to MojoTest * Refactoring MojoTest * Missing dependency added to POM * Possibility of not filling out VersionInfo in XML at all * Documentation for VersionInfo defaults added * Throwing exception datailed descriptions * Release version without snapshot * Revert "Release version without snapshot" This reverts commit d019663. * default scope for filling out defaults inside VersionInfo * Newline's at the end of the files * Private constructors for utility classes added
- Loading branch information
Showing
13 changed files
with
986 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
src/main/java/com/akathist/maven/plugins/launch4j/generators/CopyrightGenerator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package com.akathist.maven.plugins.launch4j.generators; | ||
|
||
import org.apache.commons.lang3.StringUtils; | ||
import org.apache.maven.model.Organization; | ||
|
||
import java.time.LocalDate; | ||
|
||
public class CopyrightGenerator { | ||
private CopyrightGenerator() { | ||
} | ||
|
||
/** | ||
* Parameters should be taken from MavenProject properties: | ||
* @param projectInceptionYear as ${project.inceptionYear} | ||
* @param projectOrganization as ${project.organization} | ||
*/ | ||
public static String generate(String projectInceptionYear, Organization projectOrganization) { | ||
String inceptionYear = generateInceptionYear(projectInceptionYear); | ||
int buildYear = LocalDate.now().getYear(); | ||
String organizationName = generateOrganizationName(projectOrganization); | ||
|
||
return String.format("Copyright © %s%d%s. All rights reserved.", inceptionYear, buildYear, organizationName); | ||
} | ||
|
||
private static String generateInceptionYear(String projectInceptionYear) { | ||
if(StringUtils.isNotBlank(projectInceptionYear)) { | ||
return projectInceptionYear + "-"; | ||
} | ||
|
||
return ""; | ||
} | ||
|
||
private static String generateOrganizationName(Organization projectOrganization) { | ||
if(projectOrganization != null && StringUtils.isNotBlank(projectOrganization.getName())) { | ||
return " " + projectOrganization.getName(); | ||
} | ||
|
||
return ""; | ||
} | ||
} |
72 changes: 72 additions & 0 deletions
72
...ain/java/com/akathist/maven/plugins/launch4j/generators/Launch4jFileVersionGenerator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package com.akathist.maven.plugins.launch4j.generators; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.regex.Pattern; | ||
|
||
public class Launch4jFileVersionGenerator { | ||
private static final int REQUIRED_NESTED_VERSION_LEVELS = 4; | ||
private static final String SIMPLE_PROJECT_VERSION_REGEX = "^((\\d(\\.)?)*\\d+)(-\\w+)?$"; | ||
private static final Pattern simpleProjectVersionPattern = Pattern.compile( | ||
SIMPLE_PROJECT_VERSION_REGEX, Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE | ||
); | ||
|
||
private Launch4jFileVersionGenerator() { | ||
} | ||
|
||
/** | ||
* Converts projectVersion into a format "x.x.x.x" ('x' as a number), which is required by Launch4j. | ||
* | ||
* For shorter versions like "x.x.x" it will append zeros (to the 4th level) at the end like "x.x.x.0". | ||
* Every text flag like "-SNAPSHOT" or "-alpha" will be cut off. | ||
* Too many nested numbers (more than 4 levels) will be cut off as well: "1.2.3.4.5.6" -> "1.2.3.4". | ||
* | ||
* Param should be taken from MavenProject property: | ||
* @param projectVersion as ${project.version} | ||
*/ | ||
public static String generate(String projectVersion) { | ||
if(projectVersion == null) { | ||
return null; | ||
} | ||
if(!simpleProjectVersionPattern.matcher(projectVersion).matches()) { | ||
throw new IllegalArgumentException("'project.version' is in invalid format. Regex pattern: " + SIMPLE_PROJECT_VERSION_REGEX); | ||
} | ||
|
||
String versionLevels = removeTextFlags(projectVersion); | ||
String limitedVersionLevels = cutOffTooManyNestedLevels(versionLevels); | ||
|
||
return appendMissingNestedLevelsByZeros(limitedVersionLevels); | ||
} | ||
|
||
private static String removeTextFlags(String version) { | ||
if(version.contains("-")) { | ||
String[] parts = version.split("-"); | ||
return parts[0]; | ||
} | ||
|
||
return version; | ||
} | ||
|
||
private static String cutOffTooManyNestedLevels(String versionLevels) { | ||
String[] levels = versionLevels.split("\\."); | ||
|
||
if(levels.length > REQUIRED_NESTED_VERSION_LEVELS) { | ||
List<String> limitedLevels = Arrays.asList(levels) | ||
.subList(0, REQUIRED_NESTED_VERSION_LEVELS); | ||
return String.join(".", limitedLevels); | ||
} | ||
|
||
return versionLevels; | ||
} | ||
|
||
private static String appendMissingNestedLevelsByZeros(String versionLevels) { | ||
String[] levels = versionLevels.split("\\."); | ||
|
||
StringBuilder filledLevels = new StringBuilder(versionLevels); | ||
for (int i = levels.length; i < REQUIRED_NESTED_VERSION_LEVELS; i++) { | ||
filledLevels.append(".0"); | ||
} | ||
|
||
return filledLevels.toString(); | ||
} | ||
} |
Oops, something went wrong.