From 1a18ba8534cd4b5f34cfc11c7cd422f6a2eeeffb Mon Sep 17 00:00:00 2001 From: Mateusz Palichleb <22062466+koksyn@users.noreply.github.com> Date: Tue, 6 Dec 2022 21:31:16 +0100 Subject: [PATCH 01/33] 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 ) in the headers, so we need to escape them. For details, please see the issue: https://github.com/Microsoft/vscode/issues/12491 --- src/main/resources/MOJO.md | 58 +++++++++++++++++++------------------- 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/src/main/resources/MOJO.md b/src/main/resources/MOJO.md index 89ff68e4..ad020462 100644 --- a/src/main/resources/MOJO.md +++ b/src/main/resources/MOJO.md @@ -13,7 +13,7 @@ Wraps a jar in a Windows executable. ### Parameter Details -#### **** +#### **\** Changes to the given directory, relative to the executable, before running your jar. If set to `.` the current directory will be where the executable is. If omitted, the directory will not be changed. @@ -22,7 +22,7 @@ Changes to the given directory, relative to the executable, before running your * * * -#### **** +#### **\** Details about the classpath your application should have. This is required if you are not wrapping a jar. @@ -31,7 +31,7 @@ Details about the classpath your application should have. This is required if yo * * * -#### **** +#### **\** Constant command line arguments to pass to your program's main method. Actual command line arguments entered by the user will appear after these. @@ -40,7 +40,7 @@ Constant command line arguments to pass to your program's main method. Actual co * * * -#### **** +#### **\** If `saveConfig` is set to true, config will be written to this file @@ -50,7 +50,7 @@ If `saveConfig` is set to true, config will be written to this file * * * -#### **** +#### **\** Whether the executable should wrap the jar or not. @@ -60,7 +60,7 @@ Whether the executable should wrap the jar or not. * * * -#### **** +#### **\** downloadUrl (?). @@ -69,7 +69,7 @@ downloadUrl (?). * * * -#### **** +#### **\** The title of the error popup if something goes wrong trying to run your program, like if java can't be found. If this is a console app and not a gui, then this value is used to prefix any error messages, as in ${errTitle}: ${errorMessage}. @@ -78,7 +78,7 @@ The title of the error popup if something goes wrong trying to run your program, * * * -#### **** +#### **\** Whether you want a gui or console app. Valid values are "gui" and "console." If you say gui, then launch4j will run your app from javaw instead of java in order to avoid opening a DOS window. Choosing gui also enables other options like taskbar icon and a splash screen. @@ -87,7 +87,7 @@ Whether you want a gui or console app. Valid values are "gui" and "console." If * * * -#### **** +#### **\** The icon to use in the taskbar. Must be in ico format. @@ -96,7 +96,7 @@ The icon to use in the taskbar. Must be in ico format. * * * -#### **** +#### **\** The name of the Launch4j native configuration file The path, if relative, is relative to the pom.xml. @@ -105,7 +105,7 @@ The name of the Launch4j native configuration file The path, if relative, is rel * * * -#### **** +#### **\** The jar to bundle inside the executable. The path, if relative, is relative to the pom.xml. If you don't want to wrap the jar, then this value should be the runtime path to the jar relative to the executable. You should also set dontWrapJar to true. You can only bundle a single jar. Therefore, you should either create a jar that contains your own code plus all your dependencies, or you should distribute your dependencies alongside the executable. @@ -115,7 +115,7 @@ The jar to bundle inside the executable. The path, if relative, is relative to t * * * -#### **** +#### **\** Details about the supported jres. @@ -124,7 +124,7 @@ Details about the supported jres. * * * -#### **** +#### **\** Win32 libraries to include. Used for custom headers only. @@ -133,7 +133,7 @@ Win32 libraries to include. Used for custom headers only. * * * -#### **** +#### **\** Windows manifest file (a XML file) with the same name as .exe file (myapp.exe.manifest) @@ -142,7 +142,7 @@ Windows manifest file (a XML file) with the same name as .exe file (myapp.exe.ma * * * -#### **** +#### **\** Various messages you can display. @@ -151,7 +151,7 @@ Various messages you can display. * * * -#### **** +#### **\** Object files to include. Used for custom headers only. @@ -160,7 +160,7 @@ Object files to include. Used for custom headers only. * * * -#### **** +#### **\** The name of the executable you want launch4j to produce. The path, if relative, is relative to the pom.xml. @@ -170,7 +170,7 @@ The name of the executable you want launch4j to produce. The path, if relative, * * * -#### **** +#### **\** If set to true, a synchronized block will be used to protect resources @@ -180,7 +180,7 @@ If set to true, a synchronized block will be used to protect resources * * * -#### **** +#### **\** The dependencies of this plugin. Used to get the Launch4j artifact version. @@ -190,7 +190,7 @@ The dependencies of this plugin. Used to get the Launch4j artifact version. * * * -#### **** +#### **\** Priority class of windows process. Valid values are "normal" (default), "idle" and "high". @@ -200,7 +200,7 @@ Priority class of windows process. Valid values are "normal" (default), "idle" a * * * -#### **** +#### **\** If true, when the application exits, any exit code other than 0 is considered a crash and the application will be started again. @@ -210,7 +210,7 @@ If true, when the application exits, any exit code other than 0 is considered a * * * -#### **** +#### **\** If set to true it will save final config into a XML file @@ -220,7 +220,7 @@ If set to true it will save final config into a XML file * * * -#### **** +#### **\** Details about whether to run as a single instance. @@ -229,7 +229,7 @@ Details about whether to run as a single instance. * * * -#### **** +#### **\** If set to true, execution of the plugin will be skipped @@ -239,7 +239,7 @@ If set to true, execution of the plugin will be skipped * * * -#### **** +#### **\** Details about the splash screen. @@ -248,7 +248,7 @@ Details about the splash screen. * * * -#### **** +#### **\** If true, the executable waits for the java application to finish before returning its exit code. Defaults to false for gui applications. Has no effect for console applications, which always wait. @@ -258,7 +258,7 @@ If true, the executable waits for the java application to finish before returnin * * * -#### **** +#### **\** supportUrl (?). @@ -267,7 +267,7 @@ supportUrl (?). * * * -#### **** +#### **\** Variables to set. @@ -276,7 +276,7 @@ Variables to set. * * * -#### **** +#### **\** Lots of information you can attach to the windows process. From 1db37ca213fcb6210cd2621b25fc189c55178d1c Mon Sep 17 00:00:00 2001 From: Mateusz Palichleb <22062466+koksyn@users.noreply.github.com> Date: Fri, 16 Dec 2022 17:05:37 +0100 Subject: [PATCH 02/33] `disableVersionInfoDefaults` docs note added --- src/main/resources/MOJO.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/main/resources/MOJO.md b/src/main/resources/MOJO.md index ad020462..558a091f 100644 --- a/src/main/resources/MOJO.md +++ b/src/main/resources/MOJO.md @@ -282,3 +282,13 @@ Lots of information you can attach to the windows process. * **Type**: `com.akathist.maven.plugins.launch4j.VersionInfo` * **Required**: `No` + +#### **\** + +If `disableVersionInfoDefaults` is set to true, it will prevent filling out the VersionInfo params with default values. + +* **Type**: `boolean` +* **Required**: `No` +* **Default**: `false` + +* * * \ No newline at end of file From ab175c33a6039346f43add33a437371ae3489450 Mon Sep 17 00:00:00 2001 From: Mateusz Palichleb <22062466+koksyn@users.noreply.github.com> Date: Fri, 16 Dec 2022 17:06:55 +0100 Subject: [PATCH 03/33] Snapshot version bump according to default parameters changes --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index dd302ffc..867da99c 100644 --- a/pom.xml +++ b/pom.xml @@ -22,7 +22,7 @@ com.akathist.maven.plugins.launch4j launch4j-maven-plugin maven-plugin - 2.2.1-SNAPSHOT + 2.3.0-SNAPSHOT Maven Launch4j Plugin This plugin creates Windows executables from Java jar files using the Launch4j utility. From 6ab798f9e04233d4a6862a30639eecd83588a243 Mon Sep 17 00:00:00 2001 From: Mateusz Palichleb <22062466+koksyn@users.noreply.github.com> Date: Tue, 20 Dec 2022 20:49:51 +0100 Subject: [PATCH 04/33] New parameter for disabling VersionInfo defaults --- .../akathist/maven/plugins/launch4j/Launch4jMojo.java | 9 ++++++++- .../launch4j-default/launch4j-default-plugin-config.xml | 3 +-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/akathist/maven/plugins/launch4j/Launch4jMojo.java b/src/main/java/com/akathist/maven/plugins/launch4j/Launch4jMojo.java index f84add38..52e6b285 100644 --- a/src/main/java/com/akathist/maven/plugins/launch4j/Launch4jMojo.java +++ b/src/main/java/com/akathist/maven/plugins/launch4j/Launch4jMojo.java @@ -262,7 +262,7 @@ public class Launch4jMojo extends AbstractMojo { * Details about the classpath your application should have. * This is required if you are not wrapping a jar. */ - @Parameter() + @Parameter private ClassPath classPath; /** @@ -283,6 +283,12 @@ public class Launch4jMojo extends AbstractMojo { @Parameter private VersionInfo versionInfo; + /** + * If set to true, it will prevent filling out the VersionInfo params with default values. + */ + @Parameter(defaultValue = "false") + private boolean disableVersionInfoDefaults; + /** * Various messages you can display. */ @@ -834,6 +840,7 @@ public String toString() { ", singleInstance=" + singleInstance + ", splash=" + splash + ", versionInfo=" + versionInfo + + ", disableVersionInfoDefaults=" + disableVersionInfoDefaults + ", messages=" + messages + ", manifest=" + manifest + ", saveConfig=" + saveConfig + diff --git a/src/test/resources/unit/launch4j-default/launch4j-default-plugin-config.xml b/src/test/resources/unit/launch4j-default/launch4j-default-plugin-config.xml index 7f38dba9..59b25602 100644 --- a/src/test/resources/unit/launch4j-default/launch4j-default-plugin-config.xml +++ b/src/test/resources/unit/launch4j-default/launch4j-default-plugin-config.xml @@ -54,7 +54,6 @@ - - + \ No newline at end of file From e7df172a84d4768ebf87c2f1d89c5dedee789091 Mon Sep 17 00:00:00 2001 From: Mateusz Palichleb <22062466+koksyn@users.noreply.github.com> Date: Tue, 20 Dec 2022 22:48:53 +0100 Subject: [PATCH 05/33] Filling out VersionInfo defaults --- .../maven/plugins/launch4j/Launch4jMojo.java | 8 +++ .../maven/plugins/launch4j/VersionInfo.java | 72 +++++++++++++++++++ 2 files changed, 80 insertions(+) diff --git a/src/main/java/com/akathist/maven/plugins/launch4j/Launch4jMojo.java b/src/main/java/com/akathist/maven/plugins/launch4j/Launch4jMojo.java index 52e6b285..3d0ae06b 100644 --- a/src/main/java/com/akathist/maven/plugins/launch4j/Launch4jMojo.java +++ b/src/main/java/com/akathist/maven/plugins/launch4j/Launch4jMojo.java @@ -346,6 +346,14 @@ private void doExecute() throws MojoExecutionException { return; } + if (!disableVersionInfoDefaults) { + try { + versionInfo.tryFillOutByDefaults(project); + } catch (RuntimeException exception) { + throw new MojoExecutionException("Cannot fill out VersionInfo by defaults", exception); + } + } + final File workDir = setupBuildEnvironment(); if (infile != null) { if (infile.exists()) { diff --git a/src/main/java/com/akathist/maven/plugins/launch4j/VersionInfo.java b/src/main/java/com/akathist/maven/plugins/launch4j/VersionInfo.java index 88e8116e..74aea94e 100644 --- a/src/main/java/com/akathist/maven/plugins/launch4j/VersionInfo.java +++ b/src/main/java/com/akathist/maven/plugins/launch4j/VersionInfo.java @@ -19,8 +19,12 @@ package com.akathist.maven.plugins.launch4j; import net.sf.launch4j.config.LanguageID; +import org.apache.commons.lang3.StringUtils; +import org.apache.maven.model.Organization; import org.apache.maven.plugins.annotations.Parameter; +import org.apache.maven.project.MavenProject; +import java.time.LocalDate; import java.util.HashMap; import java.util.Map; @@ -137,6 +141,74 @@ private void setLanguage(net.sf.launch4j.config.VersionInfo ret) { ret.setLanguage(languageID); } + // po zmianach zrobić git amend aby usunąć te komenty + public void tryFillOutByDefaults(MavenProject project) { + if(project == null) { + throw new IllegalArgumentException("'project' is required, but it is null."); + } + + final String defaultVersion = generateDefaultVersion(project.getVersion()); + + fileVersion = getDefaultWhenOriginalIsBlank(fileVersion, defaultVersion); + productVersion = getDefaultWhenOriginalIsBlank(productVersion, defaultVersion); + txtFileVersion = getDefaultWhenOriginalIsBlank(txtFileVersion, project.getVersion()); + fileDescription = getDefaultWhenOriginalIsBlank(fileDescription, project.getDescription()); + copyright = getDefaultWhenOriginalIsBlank(copyright, generateDefaultCopyright(project)); + productName = getDefaultWhenOriginalIsBlank(productName, project.getName()); + internalName = getDefaultWhenOriginalIsBlank(internalName, project.getArtifactId()); + txtProductVersion = getDefaultWhenOriginalIsBlank(txtProductVersion, project.getVersion()); + } + + private String generateDefaultVersion(String originalVersion) { + /** + * jeśli -SNAPSHOT jest to go wydzielić do innej zmiennej + * podzielić x.x.x.x.x string.split "." na array/liste + * brac tyle x-ów ile jest wypełnione (1, 1.1, 1.2.3, 1.2.3.4) ale max 4 liczby, dla wiekszych (1.2.3.4.5 olać resztę) + * jeśli x-ów jest mniej niż 4 to wypełnić pozostałem zerami np. dla 1.2 będzie to 1.2.0.0, + * jesli był wcześniej snapshot to dokleić go na koniec (sprawdzić czy się nie wysypie oryginalna wtyczka, być może nie można używać Snapshot?) + * + * errTitle + orginalFilename też zrobić + * opisać komentarze na temat jak dizalaja te defaulty do wersji itp. ma być full opisane + * + * podzielić ta klase na mniejsze klasy z samą tylko generacją defaultów + * napisać testy do tej klasy i do klas od defaultów + * + */ + return ".0"; + } + + private String getDefaultWhenOriginalIsBlank(final String originalValue, final String defaultValue) { + if(StringUtils.isBlank(originalValue) && StringUtils.isNotBlank(defaultValue)) { + return defaultValue; + } + + return originalValue; + } + + private String generateDefaultCopyright(MavenProject project) { + int buildYear = LocalDate.now().getYear(); + String inceptionYear = generateDefaultInceptionYear(project.getInceptionYear()); + String organizationName = generateDefaultOrganizationName(project.getOrganization()); + + return String.format("Copyright © %s%d%s. All rights reserved.", inceptionYear, buildYear, organizationName); + } + + private String generateDefaultInceptionYear(String inceptionYear) { + if(StringUtils.isNotBlank(inceptionYear)) { + return inceptionYear + "-"; + } + + return ""; + } + + private String generateDefaultOrganizationName(Organization organization) { + if(organization != null && organization.getName() != null) { + return " " + organization.getName(); + } + + return ""; + } + @Override public String toString() { return "VersionInfo{" + From d6165190b6a869abe54e5462dea9a94ef87241c6 Mon Sep 17 00:00:00 2001 From: Mateusz Palichleb <22062466+koksyn@users.noreply.github.com> Date: Thu, 29 Dec 2022 14:11:11 +0100 Subject: [PATCH 06/33] Filling out VersionInfo defaults --- .../maven/plugins/launch4j/VersionInfo.java | 62 ++++--------------- .../generators/CopyrightGenerator.java | 32 ++++++++++ .../Launch4jFileVersionGenerator.java | 58 +++++++++++++++++ 3 files changed, 101 insertions(+), 51 deletions(-) create mode 100644 src/main/java/com/akathist/maven/plugins/launch4j/generators/CopyrightGenerator.java create mode 100644 src/main/java/com/akathist/maven/plugins/launch4j/generators/Launch4jFileVersionGenerator.java diff --git a/src/main/java/com/akathist/maven/plugins/launch4j/VersionInfo.java b/src/main/java/com/akathist/maven/plugins/launch4j/VersionInfo.java index 74aea94e..f1c570f3 100644 --- a/src/main/java/com/akathist/maven/plugins/launch4j/VersionInfo.java +++ b/src/main/java/com/akathist/maven/plugins/launch4j/VersionInfo.java @@ -18,13 +18,13 @@ */ package com.akathist.maven.plugins.launch4j; +import com.akathist.maven.plugins.launch4j.generators.CopyrightGenerator; +import com.akathist.maven.plugins.launch4j.generators.Launch4jFileVersionGenerator; import net.sf.launch4j.config.LanguageID; import org.apache.commons.lang3.StringUtils; -import org.apache.maven.model.Organization; import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.project.MavenProject; -import java.time.LocalDate; import java.util.HashMap; import java.util.Map; @@ -141,40 +141,24 @@ private void setLanguage(net.sf.launch4j.config.VersionInfo ret) { ret.setLanguage(languageID); } - // po zmianach zrobić git amend aby usunąć te komenty public void tryFillOutByDefaults(MavenProject project) { if(project == null) { throw new IllegalArgumentException("'project' is required, but it is null."); } - final String defaultVersion = generateDefaultVersion(project.getVersion()); + final String defaultFileVersion = Launch4jFileVersionGenerator.generate(project.getVersion()); + fileVersion = getDefaultWhenOriginalIsBlank(fileVersion, defaultFileVersion); + productVersion = getDefaultWhenOriginalIsBlank(productVersion, defaultFileVersion); + + final String defaultCopyright = CopyrightGenerator.generate(project.getInceptionYear(), project.getOrganization()); + copyright = getDefaultWhenOriginalIsBlank(copyright, defaultCopyright); - fileVersion = getDefaultWhenOriginalIsBlank(fileVersion, defaultVersion); - productVersion = getDefaultWhenOriginalIsBlank(productVersion, defaultVersion); txtFileVersion = getDefaultWhenOriginalIsBlank(txtFileVersion, project.getVersion()); - fileDescription = getDefaultWhenOriginalIsBlank(fileDescription, project.getDescription()); - copyright = getDefaultWhenOriginalIsBlank(copyright, generateDefaultCopyright(project)); - productName = getDefaultWhenOriginalIsBlank(productName, project.getName()); - internalName = getDefaultWhenOriginalIsBlank(internalName, project.getArtifactId()); txtProductVersion = getDefaultWhenOriginalIsBlank(txtProductVersion, project.getVersion()); - } - private String generateDefaultVersion(String originalVersion) { - /** - * jeśli -SNAPSHOT jest to go wydzielić do innej zmiennej - * podzielić x.x.x.x.x string.split "." na array/liste - * brac tyle x-ów ile jest wypełnione (1, 1.1, 1.2.3, 1.2.3.4) ale max 4 liczby, dla wiekszych (1.2.3.4.5 olać resztę) - * jeśli x-ów jest mniej niż 4 to wypełnić pozostałem zerami np. dla 1.2 będzie to 1.2.0.0, - * jesli był wcześniej snapshot to dokleić go na koniec (sprawdzić czy się nie wysypie oryginalna wtyczka, być może nie można używać Snapshot?) - * - * errTitle + orginalFilename też zrobić - * opisać komentarze na temat jak dizalaja te defaulty do wersji itp. ma być full opisane - * - * podzielić ta klase na mniejsze klasy z samą tylko generacją defaultów - * napisać testy do tej klasy i do klas od defaultów - * - */ - return ".0"; + productName = getDefaultWhenOriginalIsBlank(productName, project.getName()); + internalName = getDefaultWhenOriginalIsBlank(internalName, project.getArtifactId()); + fileDescription = getDefaultWhenOriginalIsBlank(fileDescription, project.getDescription()); } private String getDefaultWhenOriginalIsBlank(final String originalValue, final String defaultValue) { @@ -185,30 +169,6 @@ private String getDefaultWhenOriginalIsBlank(final String originalValue, final S return originalValue; } - private String generateDefaultCopyright(MavenProject project) { - int buildYear = LocalDate.now().getYear(); - String inceptionYear = generateDefaultInceptionYear(project.getInceptionYear()); - String organizationName = generateDefaultOrganizationName(project.getOrganization()); - - return String.format("Copyright © %s%d%s. All rights reserved.", inceptionYear, buildYear, organizationName); - } - - private String generateDefaultInceptionYear(String inceptionYear) { - if(StringUtils.isNotBlank(inceptionYear)) { - return inceptionYear + "-"; - } - - return ""; - } - - private String generateDefaultOrganizationName(Organization organization) { - if(organization != null && organization.getName() != null) { - return " " + organization.getName(); - } - - return ""; - } - @Override public String toString() { return "VersionInfo{" + diff --git a/src/main/java/com/akathist/maven/plugins/launch4j/generators/CopyrightGenerator.java b/src/main/java/com/akathist/maven/plugins/launch4j/generators/CopyrightGenerator.java new file mode 100644 index 00000000..69a6fbfa --- /dev/null +++ b/src/main/java/com/akathist/maven/plugins/launch4j/generators/CopyrightGenerator.java @@ -0,0 +1,32 @@ +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 { + public static String generate(String originalInceptionYear, Organization organization) { + int buildYear = LocalDate.now().getYear(); + String inceptionYear = generateDefaultInceptionYear(originalInceptionYear); + String organizationName = generateDefaultOrganizationName(organization); + + return String.format("Copyright © %s%d%s. All rights reserved.", inceptionYear, buildYear, organizationName); + } + + private static String generateDefaultInceptionYear(String inceptionYear) { + if(StringUtils.isNotBlank(inceptionYear)) { + return inceptionYear + "-"; + } + + return ""; + } + + private static String generateDefaultOrganizationName(Organization organization) { + if(organization != null && organization.getName() != null) { + return " " + organization.getName(); + } + + return ""; + } +} \ No newline at end of file diff --git a/src/main/java/com/akathist/maven/plugins/launch4j/generators/Launch4jFileVersionGenerator.java b/src/main/java/com/akathist/maven/plugins/launch4j/generators/Launch4jFileVersionGenerator.java new file mode 100644 index 00000000..aab8aa87 --- /dev/null +++ b/src/main/java/com/akathist/maven/plugins/launch4j/generators/Launch4jFileVersionGenerator.java @@ -0,0 +1,58 @@ +package com.akathist.maven.plugins.launch4j.generators; + +import java.util.regex.Pattern; + +public class Launch4jFileVersionGenerator { + // todo comment on top which will describe + + /** + * Valid examples: + * a + * Not valid: + * b + */ + 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); + + /** + * Converts original version 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 at the end "x.x.x.0". + * Every text flags and variations like "-SNAPSHOT" or "-alpha" will be cut off. + * + * @param originalVersion + * @return + */ + public static String generate(String originalVersion) { + if(originalVersion == null) { + return null; + } + + if(!simpleProjectVersionPattern.matcher(originalVersion).matches()) { + throw new IllegalArgumentException("'project.version' is in invalid format. Regex pattern: " + SIMPLE_PROJECT_VERSION_REGEX); + } + + String versionNumbers = originalVersion; + + if(originalVersion.contains("-")) { + String[] split = originalVersion.split("-"); + versionNumbers = split[0]; + } + + StringBuilder version = new StringBuilder(); + String[] split = versionNumbers.split("\\."); + + for (int i = 0; i < 4; i++) { + if(i > 0) { + version.append("."); + } + + if(i >= split.length) { + version.append("0"); + } else { + version.append(split[i]); + } + } + + return version.toString(); + } +} From 6cb55942ac12f523b32d7fe9699933d8037a7198 Mon Sep 17 00:00:00 2001 From: Mateusz Palichleb <22062466+koksyn@users.noreply.github.com> Date: Thu, 29 Dec 2022 14:55:43 +0100 Subject: [PATCH 07/33] Unit tests for Copyright generator --- .../generators/CopyrightGenerator.java | 18 ++-- .../generators/CopyrightGeneratorTest.java | 97 +++++++++++++++++++ 2 files changed, 106 insertions(+), 9 deletions(-) create mode 100644 src/test/java/com/akathist/maven/plugins/launch4j/generators/CopyrightGeneratorTest.java diff --git a/src/main/java/com/akathist/maven/plugins/launch4j/generators/CopyrightGenerator.java b/src/main/java/com/akathist/maven/plugins/launch4j/generators/CopyrightGenerator.java index 69a6fbfa..b47dcc82 100644 --- a/src/main/java/com/akathist/maven/plugins/launch4j/generators/CopyrightGenerator.java +++ b/src/main/java/com/akathist/maven/plugins/launch4j/generators/CopyrightGenerator.java @@ -6,25 +6,25 @@ import java.time.LocalDate; public class CopyrightGenerator { - public static String generate(String originalInceptionYear, Organization organization) { + public static String generate(String projectInceptionYear, Organization projectOrganization) { + String inceptionYear = generateInceptionYear(projectInceptionYear); int buildYear = LocalDate.now().getYear(); - String inceptionYear = generateDefaultInceptionYear(originalInceptionYear); - String organizationName = generateDefaultOrganizationName(organization); + String organizationName = generateOrganizationName(projectOrganization); return String.format("Copyright © %s%d%s. All rights reserved.", inceptionYear, buildYear, organizationName); } - private static String generateDefaultInceptionYear(String inceptionYear) { - if(StringUtils.isNotBlank(inceptionYear)) { - return inceptionYear + "-"; + private static String generateInceptionYear(String projectInceptionYear) { + if(StringUtils.isNotBlank(projectInceptionYear)) { + return projectInceptionYear + "-"; } return ""; } - private static String generateDefaultOrganizationName(Organization organization) { - if(organization != null && organization.getName() != null) { - return " " + organization.getName(); + private static String generateOrganizationName(Organization projectOrganization) { + if(projectOrganization != null && StringUtils.isNotBlank(projectOrganization.getName())) { + return " " + projectOrganization.getName(); } return ""; diff --git a/src/test/java/com/akathist/maven/plugins/launch4j/generators/CopyrightGeneratorTest.java b/src/test/java/com/akathist/maven/plugins/launch4j/generators/CopyrightGeneratorTest.java new file mode 100644 index 00000000..734725f8 --- /dev/null +++ b/src/test/java/com/akathist/maven/plugins/launch4j/generators/CopyrightGeneratorTest.java @@ -0,0 +1,97 @@ +package com.akathist.maven.plugins.launch4j.generators; + +import org.apache.maven.model.Organization; +import org.junit.Before; +import org.junit.Test; + +import java.time.LocalDate; + +import static org.junit.Assert.*; + +public class CopyrightGeneratorTest { + private static final String COPYRIGHT_PREFIX = "Copyright © "; + private static final String COPYRIGHT_POSTFIX = ". All rights reserved."; + + private String buildYear; + + @Before + public void initializeBuildYear() { + buildYear = String.valueOf( + LocalDate.now().getYear() + ); + } + + @Test + public void shouldContain_BuildYear() { + // when + final String copyright = CopyrightGenerator.generate(null, null); + + // then + String expected = concatAndWrapWithCopyright(buildYear); + assertEquals(expected, copyright); + } + + @Test + public void shouldContain_InceptionYear_And_BuildYear() { + // given + final String projectInceptionYear = "2019"; + + // when + final String copyright = CopyrightGenerator.generate(projectInceptionYear, null); + + // then + String expected = concatAndWrapWithCopyright( + projectInceptionYear, "-", buildYear + ); + assertEquals(expected, copyright); + } + + @Test + public void shouldContain_BuildYear_And_OrganizationName() { + // given + final String organizationName = "SoftwareMill"; + + Organization projectOrganization = new Organization(); + projectOrganization.setName(organizationName); + + // when + final String copyright = CopyrightGenerator.generate(null, projectOrganization); + + // then + String expected = concatAndWrapWithCopyright( + buildYear, " ", organizationName + ); + assertEquals(expected, copyright); + } + + @Test + public void shouldContain_InceptionYear_And_BuildYear_And_OrganizationName() { + // given + final String projectInceptionYear = "2020"; + final String organizationName = "Orphan OSS"; + + Organization projectOrganization = new Organization(); + projectOrganization.setName(organizationName); + + // when + final String copyright = CopyrightGenerator.generate(projectInceptionYear, projectOrganization); + + // then + String expected = concatAndWrapWithCopyright( + projectInceptionYear, "-", buildYear, " ", organizationName + ); + assertEquals(expected, copyright); + } + + private String concatAndWrapWithCopyright(String... elements) { + StringBuilder builder = new StringBuilder(COPYRIGHT_PREFIX); + + for (String element : elements) { + builder.append(element); + } + + builder.append(COPYRIGHT_POSTFIX); + + return builder.toString(); + } +} \ No newline at end of file From 54be52f83a2565c4a58f71c28237c0aa9b0971ac Mon Sep 17 00:00:00 2001 From: Mateusz Palichleb <22062466+koksyn@users.noreply.github.com> Date: Thu, 29 Dec 2022 15:07:11 +0100 Subject: [PATCH 08/33] Copyright generator description --- .../plugins/launch4j/generators/CopyrightGenerator.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main/java/com/akathist/maven/plugins/launch4j/generators/CopyrightGenerator.java b/src/main/java/com/akathist/maven/plugins/launch4j/generators/CopyrightGenerator.java index b47dcc82..0d9e13aa 100644 --- a/src/main/java/com/akathist/maven/plugins/launch4j/generators/CopyrightGenerator.java +++ b/src/main/java/com/akathist/maven/plugins/launch4j/generators/CopyrightGenerator.java @@ -6,6 +6,11 @@ import java.time.LocalDate; public class CopyrightGenerator { + /** + * Parameters should be taken from MavenProject properties: + * @param projectInceptionYear from {project.inceptionYear} + * @param projectOrganization from {project.organization} + */ public static String generate(String projectInceptionYear, Organization projectOrganization) { String inceptionYear = generateInceptionYear(projectInceptionYear); int buildYear = LocalDate.now().getYear(); From c53a7950530ee18983ff4b439bc1d45f62c92d1f Mon Sep 17 00:00:00 2001 From: Mateusz Palichleb <22062466+koksyn@users.noreply.github.com> Date: Thu, 29 Dec 2022 15:32:12 +0100 Subject: [PATCH 09/33] JUnitParams lib added to POM.xml --- pom.xml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pom.xml b/pom.xml index 867da99c..5a615a3e 100644 --- a/pom.xml +++ b/pom.xml @@ -125,6 +125,12 @@ 4.13.2 test + + pl.pragmatists + JUnitParams + 1.1.1 + test + org.apache.maven.plugin-testing maven-plugin-testing-harness From 3a06542e56092325be81571cfe6035e8c60f1aec Mon Sep 17 00:00:00 2001 From: Mateusz Palichleb <22062466+koksyn@users.noreply.github.com> Date: Thu, 29 Dec 2022 15:32:45 +0100 Subject: [PATCH 10/33] Unit tests for Launch4j fileVersion generator --- .../Launch4jFileVersionGeneratorTest.java | 70 +++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 src/test/java/com/akathist/maven/plugins/launch4j/generators/Launch4jFileVersionGeneratorTest.java diff --git a/src/test/java/com/akathist/maven/plugins/launch4j/generators/Launch4jFileVersionGeneratorTest.java b/src/test/java/com/akathist/maven/plugins/launch4j/generators/Launch4jFileVersionGeneratorTest.java new file mode 100644 index 00000000..40413d8d --- /dev/null +++ b/src/test/java/com/akathist/maven/plugins/launch4j/generators/Launch4jFileVersionGeneratorTest.java @@ -0,0 +1,70 @@ +package com.akathist.maven.plugins.launch4j.generators; + +import junitparams.JUnitParamsRunner; +import junitparams.Parameters; +import org.junit.Test; +import org.junit.runner.RunWith; + +import static org.junit.Assert.*; + +@RunWith(JUnitParamsRunner.class) +public class Launch4jFileVersionGeneratorTest { + @Test + public void shouldReturnNull_WhenProjectVersionIsNull() { + // given + String projectVersion = null; + + // expect + assertNull(Launch4jFileVersionGenerator.generate(projectVersion)); + } + + @Test(expected = IllegalArgumentException.class) + @Parameters({ + "", + " ", + "null", + "alpha-1.2.3", + "1a.2.3", + "1.X.3", + "1.2.3_11", + "1.2.3;4", + "1.2.3.4SNAPSHOT", + "1.2.3.4.SNAPSHOT" + }) + public void shouldThrowException_WhenProjectVersion_HaveWrongFormat(String projectVersion) { + // expect throws + Launch4jFileVersionGenerator.generate(projectVersion); + } + + @Test + @Parameters({ + "0, 0.0.0.0", + "1, 1.0.0.0", + "2, 2.0.0.0", + "3.14, 3.14.0.0", + "4.0.1, 4.0.1.0", + "55.44.33, 55.44.33.0" + }) + public void shouldFillMissingPlacesByZeros(String projectVersion, String expected) { + // when + final String launch4jFileVersion = Launch4jFileVersionGenerator.generate(projectVersion); + + // then + assertEquals(expected, launch4jFileVersion); + } + + @Test + @Parameters({ + "1-SNAPSHOT, 1.0.0.0", + "1.2.1-alpha, 1.2.1.0", + "1.2.3.4-beta, 1.2.3.4", + "0.0.1-snapshot, 0.0.1.0", + }) + public void shouldCutOffTextFlags(String projectVersion, String expected) { + // when + final String launch4jFileVersion = Launch4jFileVersionGenerator.generate(projectVersion); + + // then + assertEquals(expected, launch4jFileVersion); + } +} \ No newline at end of file From 8930ec08acb6701fffb7c2a980f30ccdc8182e1e Mon Sep 17 00:00:00 2001 From: Mateusz Palichleb <22062466+koksyn@users.noreply.github.com> Date: Thu, 29 Dec 2022 15:37:43 +0100 Subject: [PATCH 11/33] Additional Unit tests for Launch4j fileVersion generator --- .../Launch4jFileVersionGeneratorTest.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/test/java/com/akathist/maven/plugins/launch4j/generators/Launch4jFileVersionGeneratorTest.java b/src/test/java/com/akathist/maven/plugins/launch4j/generators/Launch4jFileVersionGeneratorTest.java index 40413d8d..962275ee 100644 --- a/src/test/java/com/akathist/maven/plugins/launch4j/generators/Launch4jFileVersionGeneratorTest.java +++ b/src/test/java/com/akathist/maven/plugins/launch4j/generators/Launch4jFileVersionGeneratorTest.java @@ -67,4 +67,19 @@ public void shouldCutOffTextFlags(String projectVersion, String expected) { // then assertEquals(expected, launch4jFileVersion); } + + @Test + @Parameters({ + "0.0.0.0.1, 0.0.0.0", + "1.22.333.4444.55555.666666, 1.22.333.4444", + "9.8.7.6.5-SNAPSHOT, 9.8.7.6", + "3.0.1.12.44.62.1.0.0.0.1-alpha, 3.0.1.12", + }) + public void shouldCutOffTooManyNestedDigits(String projectVersion, String expected) { + // when + final String launch4jFileVersion = Launch4jFileVersionGenerator.generate(projectVersion); + + // then + assertEquals(expected, launch4jFileVersion); + } } \ No newline at end of file From 15abdd30fc92c658ebfb05395dd29a97af8fac86 Mon Sep 17 00:00:00 2001 From: Mateusz Palichleb <22062466+koksyn@users.noreply.github.com> Date: Thu, 29 Dec 2022 16:12:11 +0100 Subject: [PATCH 12/33] Refactoring of Launch4j fileVersion generator --- .../generators/CopyrightGenerator.java | 4 +- .../Launch4jFileVersionGenerator.java | 81 +++++++++++-------- 2 files changed, 48 insertions(+), 37 deletions(-) diff --git a/src/main/java/com/akathist/maven/plugins/launch4j/generators/CopyrightGenerator.java b/src/main/java/com/akathist/maven/plugins/launch4j/generators/CopyrightGenerator.java index 0d9e13aa..6fd1b6be 100644 --- a/src/main/java/com/akathist/maven/plugins/launch4j/generators/CopyrightGenerator.java +++ b/src/main/java/com/akathist/maven/plugins/launch4j/generators/CopyrightGenerator.java @@ -8,8 +8,8 @@ public class CopyrightGenerator { /** * Parameters should be taken from MavenProject properties: - * @param projectInceptionYear from {project.inceptionYear} - * @param projectOrganization from {project.organization} + * @param projectInceptionYear as ${project.inceptionYear} + * @param projectOrganization as ${project.organization} */ public static String generate(String projectInceptionYear, Organization projectOrganization) { String inceptionYear = generateInceptionYear(projectInceptionYear); diff --git a/src/main/java/com/akathist/maven/plugins/launch4j/generators/Launch4jFileVersionGenerator.java b/src/main/java/com/akathist/maven/plugins/launch4j/generators/Launch4jFileVersionGenerator.java index aab8aa87..0aebf4a3 100644 --- a/src/main/java/com/akathist/maven/plugins/launch4j/generators/Launch4jFileVersionGenerator.java +++ b/src/main/java/com/akathist/maven/plugins/launch4j/generators/Launch4jFileVersionGenerator.java @@ -1,58 +1,69 @@ package com.akathist.maven.plugins.launch4j.generators; +import java.util.Arrays; +import java.util.List; import java.util.regex.Pattern; public class Launch4jFileVersionGenerator { - // todo comment on top which will describe - - /** - * Valid examples: - * a - * Not valid: - * b - */ + 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 static final Pattern simpleProjectVersionPattern = Pattern.compile( + SIMPLE_PROJECT_VERSION_REGEX, Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE + ); /** - * Converts original version 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 at the end "x.x.x.0". - * Every text flags and variations like "-SNAPSHOT" or "-alpha" will be cut off. + * 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 originalVersion - * @return + * Param should be taken from MavenProject property: + * @param projectVersion as ${project.version} */ - public static String generate(String originalVersion) { - if(originalVersion == null) { + public static String generate(String projectVersion) { + if(projectVersion == null) { return null; } - - if(!simpleProjectVersionPattern.matcher(originalVersion).matches()) { + if(!simpleProjectVersionPattern.matcher(projectVersion).matches()) { throw new IllegalArgumentException("'project.version' is in invalid format. Regex pattern: " + SIMPLE_PROJECT_VERSION_REGEX); } - String versionNumbers = originalVersion; + String versionLevels = removeTextFlags(projectVersion); + String limitedVersionLevels = cutOffTooManyNestedLevels(versionLevels); + + return appendMissingNestedLevelsByZeros(limitedVersionLevels); + } - if(originalVersion.contains("-")) { - String[] split = originalVersion.split("-"); - versionNumbers = split[0]; + private static String removeTextFlags(String version) { + if(version.contains("-")) { + String[] parts = version.split("-"); + return parts[0]; } - StringBuilder version = new StringBuilder(); - String[] split = versionNumbers.split("\\."); + return version; + } + + private static String cutOffTooManyNestedLevels(String versionLevels) { + String[] levels = versionLevels.split("\\."); + + if(levels.length > REQUIRED_NESTED_VERSION_LEVELS) { + List limitedLevels = Arrays.asList(levels) + .subList(0, REQUIRED_NESTED_VERSION_LEVELS); + return String.join(".", limitedLevels); + } + + return versionLevels; + } - for (int i = 0; i < 4; i++) { - if(i > 0) { - version.append("."); - } + private static String appendMissingNestedLevelsByZeros(String versionLevels) { + String[] levels = versionLevels.split("\\."); - if(i >= split.length) { - version.append("0"); - } else { - version.append(split[i]); - } + StringBuilder filledLevels = new StringBuilder(versionLevels); + for (int i = levels.length; i < REQUIRED_NESTED_VERSION_LEVELS; i++) { + filledLevels.append(".0"); } - return version.toString(); + return filledLevels.toString(); } -} +} \ No newline at end of file From 0217cca25258336eb50d4ba3ed6d2ca7e01906a4 Mon Sep 17 00:00:00 2001 From: Mateusz Palichleb <22062466+koksyn@users.noreply.github.com> Date: Thu, 29 Dec 2022 16:19:29 +0100 Subject: [PATCH 13/33] "errTitle" default value provided --- .../java/com/akathist/maven/plugins/launch4j/Launch4jMojo.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/akathist/maven/plugins/launch4j/Launch4jMojo.java b/src/main/java/com/akathist/maven/plugins/launch4j/Launch4jMojo.java index 3d0ae06b..bad09f9e 100644 --- a/src/main/java/com/akathist/maven/plugins/launch4j/Launch4jMojo.java +++ b/src/main/java/com/akathist/maven/plugins/launch4j/Launch4jMojo.java @@ -174,7 +174,7 @@ public class Launch4jMojo extends AbstractMojo { * like if java can't be found. If this is a console app and not a gui, then this value * is used to prefix any error messages, as in ${errTitle}: ${errorMessage}. */ - @Parameter + @Parameter(defaultValue = "${project.name}") private String errTitle; /** From e2976d01ee2f1b2e611a8662be293f391458cdb8 Mon Sep 17 00:00:00 2001 From: Mateusz Palichleb <22062466+koksyn@users.noreply.github.com> Date: Thu, 29 Dec 2022 16:22:24 +0100 Subject: [PATCH 14/33] "errTitle" default value in docs --- src/main/resources/MOJO.md | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/resources/MOJO.md b/src/main/resources/MOJO.md index 558a091f..fc8a121c 100644 --- a/src/main/resources/MOJO.md +++ b/src/main/resources/MOJO.md @@ -75,6 +75,7 @@ The title of the error popup if something goes wrong trying to run your program, * **Type**: `java.lang.String` * **Required**: `No` +* **Default**: `${project.name}` * * * From 0d2c9957b1ad21f300cf714ce518bd59e079635e Mon Sep 17 00:00:00 2001 From: Mateusz Palichleb <22062466+koksyn@users.noreply.github.com> Date: Thu, 29 Dec 2022 16:57:29 +0100 Subject: [PATCH 15/33] "versionInfo -> originalFilename" default value added --- .../com/akathist/maven/plugins/launch4j/Launch4jMojo.java | 2 +- .../com/akathist/maven/plugins/launch4j/VersionInfo.java | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/akathist/maven/plugins/launch4j/Launch4jMojo.java b/src/main/java/com/akathist/maven/plugins/launch4j/Launch4jMojo.java index bad09f9e..9cf953e1 100644 --- a/src/main/java/com/akathist/maven/plugins/launch4j/Launch4jMojo.java +++ b/src/main/java/com/akathist/maven/plugins/launch4j/Launch4jMojo.java @@ -348,7 +348,7 @@ private void doExecute() throws MojoExecutionException { if (!disableVersionInfoDefaults) { try { - versionInfo.tryFillOutByDefaults(project); + versionInfo.tryFillOutByDefaults(project, outfile); } catch (RuntimeException exception) { throw new MojoExecutionException("Cannot fill out VersionInfo by defaults", exception); } diff --git a/src/main/java/com/akathist/maven/plugins/launch4j/VersionInfo.java b/src/main/java/com/akathist/maven/plugins/launch4j/VersionInfo.java index f1c570f3..07db319c 100644 --- a/src/main/java/com/akathist/maven/plugins/launch4j/VersionInfo.java +++ b/src/main/java/com/akathist/maven/plugins/launch4j/VersionInfo.java @@ -25,6 +25,7 @@ import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.project.MavenProject; +import java.io.File; import java.util.HashMap; import java.util.Map; @@ -141,10 +142,13 @@ private void setLanguage(net.sf.launch4j.config.VersionInfo ret) { ret.setLanguage(languageID); } - public void tryFillOutByDefaults(MavenProject project) { + public void tryFillOutByDefaults(MavenProject project, File outfile) { if(project == null) { throw new IllegalArgumentException("'project' is required, but it is null."); } + if(outfile == null) { + throw new IllegalArgumentException("'outfile' is required, but it is null."); + } final String defaultFileVersion = Launch4jFileVersionGenerator.generate(project.getVersion()); fileVersion = getDefaultWhenOriginalIsBlank(fileVersion, defaultFileVersion); @@ -159,6 +163,8 @@ public void tryFillOutByDefaults(MavenProject project) { productName = getDefaultWhenOriginalIsBlank(productName, project.getName()); internalName = getDefaultWhenOriginalIsBlank(internalName, project.getArtifactId()); fileDescription = getDefaultWhenOriginalIsBlank(fileDescription, project.getDescription()); + + originalFilename = getDefaultWhenOriginalIsBlank(originalFilename, outfile.getName()); } private String getDefaultWhenOriginalIsBlank(final String originalValue, final String defaultValue) { From 234974f4032e5b5d8118ad6adcfba5c417b5592a Mon Sep 17 00:00:00 2001 From: Mateusz Palichleb <22062466+koksyn@users.noreply.github.com> Date: Thu, 29 Dec 2022 17:20:54 +0100 Subject: [PATCH 16/33] release version notes Resolves #98 --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index a22a66f0..e5a66999 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,10 @@ The full list of all the parameters is available [here](src/main/resources/MOJO. # Version Notes +## Version notes 2.3.0 - 2022-12-30 +- provides default values for plugin configuration, especially for ``, see Issue [#98](../../issues/98) +- adds a `disableVersionInfoDefaults` parameter to be able to disable provided defaults, see PR [#205](../../pull/205) + ## Version notes 2.2.0 - 2022-11-24 - upgrades Launch4j to version 3.50 and adopts config to the bew requirements, see Issue [#199](../../issues/199) and PR [#200](../../pull/200) for more details what has to be changed From e6c5d21c661111da2a6653b9b739899a14409366 Mon Sep 17 00:00:00 2001 From: Mateusz Palichleb <22062466+koksyn@users.noreply.github.com> Date: Thu, 29 Dec 2022 17:24:35 +0100 Subject: [PATCH 17/33] Line added to MOJO doc --- src/main/resources/MOJO.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/resources/MOJO.md b/src/main/resources/MOJO.md index fc8a121c..07dbcafd 100644 --- a/src/main/resources/MOJO.md +++ b/src/main/resources/MOJO.md @@ -284,6 +284,8 @@ Lots of information you can attach to the windows process. * **Type**: `com.akathist.maven.plugins.launch4j.VersionInfo` * **Required**: `No` +* * * + #### **\** If `disableVersionInfoDefaults` is set to true, it will prevent filling out the VersionInfo params with default values. From e9ffe5f9b1d214ebfad3f4ad49942438956ed86e Mon Sep 17 00:00:00 2001 From: Mateusz Palichleb <22062466+koksyn@users.noreply.github.com> Date: Fri, 30 Dec 2022 11:55:32 +0100 Subject: [PATCH 18/33] trademarks & companyName also filled by defaults --- .../akathist/maven/plugins/launch4j/VersionInfo.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/akathist/maven/plugins/launch4j/VersionInfo.java b/src/main/java/com/akathist/maven/plugins/launch4j/VersionInfo.java index 07db319c..8657ce8e 100644 --- a/src/main/java/com/akathist/maven/plugins/launch4j/VersionInfo.java +++ b/src/main/java/com/akathist/maven/plugins/launch4j/VersionInfo.java @@ -22,6 +22,7 @@ import com.akathist.maven.plugins.launch4j.generators.Launch4jFileVersionGenerator; import net.sf.launch4j.config.LanguageID; import org.apache.commons.lang3.StringUtils; +import org.apache.maven.model.Organization; import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.project.MavenProject; @@ -154,9 +155,16 @@ public void tryFillOutByDefaults(MavenProject project, File outfile) { fileVersion = getDefaultWhenOriginalIsBlank(fileVersion, defaultFileVersion); productVersion = getDefaultWhenOriginalIsBlank(productVersion, defaultFileVersion); - final String defaultCopyright = CopyrightGenerator.generate(project.getInceptionYear(), project.getOrganization()); + Organization projectOrganization = project.getOrganization(); + + final String defaultCopyright = CopyrightGenerator.generate(project.getInceptionYear(), projectOrganization); copyright = getDefaultWhenOriginalIsBlank(copyright, defaultCopyright); + if(projectOrganization != null) { + companyName = getDefaultWhenOriginalIsBlank(companyName, projectOrganization.getName()); + trademarks = getDefaultWhenOriginalIsBlank(companyName, projectOrganization.getName()); + } + txtFileVersion = getDefaultWhenOriginalIsBlank(txtFileVersion, project.getVersion()); txtProductVersion = getDefaultWhenOriginalIsBlank(txtProductVersion, project.getVersion()); From b38f942eb2f3049319c26f956c74e104f9b52813 Mon Sep 17 00:00:00 2001 From: Mateusz Palichleb <22062466+koksyn@users.noreply.github.com> Date: Fri, 30 Dec 2022 14:03:24 +0100 Subject: [PATCH 19/33] Mockito Core library added --- pom.xml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pom.xml b/pom.xml index 5a615a3e..b6bf0d99 100644 --- a/pom.xml +++ b/pom.xml @@ -131,6 +131,12 @@ 1.1.1 test + + org.mockito + mockito-core + 4.11.0 + test + org.apache.maven.plugin-testing maven-plugin-testing-harness From b1ede4d4e9b2e3bf7d454510db51c115e6059404 Mon Sep 17 00:00:00 2001 From: Mateusz Palichleb <22062466+koksyn@users.noreply.github.com> Date: Fri, 30 Dec 2022 14:03:58 +0100 Subject: [PATCH 20/33] VersionInfo refactoring --- .../maven/plugins/launch4j/VersionInfo.java | 79 ++++++++++++++----- 1 file changed, 60 insertions(+), 19 deletions(-) diff --git a/src/main/java/com/akathist/maven/plugins/launch4j/VersionInfo.java b/src/main/java/com/akathist/maven/plugins/launch4j/VersionInfo.java index 8657ce8e..96af2790 100644 --- a/src/main/java/com/akathist/maven/plugins/launch4j/VersionInfo.java +++ b/src/main/java/com/akathist/maven/plugins/launch4j/VersionInfo.java @@ -34,7 +34,6 @@ * Information that appears in the Windows Explorer. */ public class VersionInfo { - private static final Map LANGUAGE_TO_LANGUAGE_ID; static { @@ -116,6 +115,27 @@ public class VersionInfo { @Parameter String trademarks; + public VersionInfo() { + } + + public VersionInfo(String fileVersion, String txtFileVersion, String fileDescription, + String copyright, String productVersion, String txtProductVersion, + String productName, String companyName, String internalName, + String originalFilename, String language, String trademarks) { + this.fileVersion = fileVersion; + this.txtFileVersion = txtFileVersion; + this.fileDescription = fileDescription; + this.copyright = copyright; + this.productVersion = productVersion; + this.txtProductVersion = txtProductVersion; + this.productName = productName; + this.companyName = companyName; + this.internalName = internalName; + this.originalFilename = originalFilename; + this.language = language; + this.trademarks = trademarks; + } + net.sf.launch4j.config.VersionInfo toL4j() { net.sf.launch4j.config.VersionInfo ret = new net.sf.launch4j.config.VersionInfo(); @@ -144,39 +164,60 @@ private void setLanguage(net.sf.launch4j.config.VersionInfo ret) { } public void tryFillOutByDefaults(MavenProject project, File outfile) { - if(project == null) { + if (project == null) { throw new IllegalArgumentException("'project' is required, but it is null."); } - if(outfile == null) { + if (outfile == null) { throw new IllegalArgumentException("'outfile' is required, but it is null."); } - final String defaultFileVersion = Launch4jFileVersionGenerator.generate(project.getVersion()); + String version = project.getVersion(); + Organization organization = project.getOrganization(); + + tryFillOutByDefaultVersionInL4jFormat(version); + tryFillOutCopyrightByDefaults(project.getInceptionYear(), organization); + tryFillOutOrganizationRelatedDefaults(organization); + tryFillOutSimpleValuesByDefaults( + version, + project.getName(), + project.getArtifactId(), + project.getDescription() + ); + + originalFilename = getDefaultWhenOriginalIsBlank(originalFilename, outfile.getName()); + } + + private void tryFillOutByDefaultVersionInL4jFormat(String version) { + final String defaultFileVersion = Launch4jFileVersionGenerator.generate(version); fileVersion = getDefaultWhenOriginalIsBlank(fileVersion, defaultFileVersion); productVersion = getDefaultWhenOriginalIsBlank(productVersion, defaultFileVersion); + } - Organization projectOrganization = project.getOrganization(); - - final String defaultCopyright = CopyrightGenerator.generate(project.getInceptionYear(), projectOrganization); + private void tryFillOutCopyrightByDefaults(String inceptionYear, Organization organization) { + final String defaultCopyright = CopyrightGenerator.generate(inceptionYear, organization); copyright = getDefaultWhenOriginalIsBlank(copyright, defaultCopyright); + } - if(projectOrganization != null) { - companyName = getDefaultWhenOriginalIsBlank(companyName, projectOrganization.getName()); - trademarks = getDefaultWhenOriginalIsBlank(companyName, projectOrganization.getName()); + private void tryFillOutOrganizationRelatedDefaults(Organization organization) { + if (organization != null) { + companyName = getDefaultWhenOriginalIsBlank(companyName, organization.getName()); + trademarks = getDefaultWhenOriginalIsBlank(trademarks, organization.getName()); } + } - txtFileVersion = getDefaultWhenOriginalIsBlank(txtFileVersion, project.getVersion()); - txtProductVersion = getDefaultWhenOriginalIsBlank(txtProductVersion, project.getVersion()); - - productName = getDefaultWhenOriginalIsBlank(productName, project.getName()); - internalName = getDefaultWhenOriginalIsBlank(internalName, project.getArtifactId()); - fileDescription = getDefaultWhenOriginalIsBlank(fileDescription, project.getDescription()); - - originalFilename = getDefaultWhenOriginalIsBlank(originalFilename, outfile.getName()); + private void tryFillOutSimpleValuesByDefaults(String version, + String name, + String artifactId, + String description) { + txtFileVersion = getDefaultWhenOriginalIsBlank(txtFileVersion, version); + txtProductVersion = getDefaultWhenOriginalIsBlank(txtProductVersion, version); + productName = getDefaultWhenOriginalIsBlank(productName, name); + internalName = getDefaultWhenOriginalIsBlank(internalName, artifactId); + fileDescription = getDefaultWhenOriginalIsBlank(fileDescription, description); } private String getDefaultWhenOriginalIsBlank(final String originalValue, final String defaultValue) { - if(StringUtils.isBlank(originalValue) && StringUtils.isNotBlank(defaultValue)) { + if (StringUtils.isBlank(originalValue) && StringUtils.isNotBlank(defaultValue)) { return defaultValue; } From 4b7a24583f300128aee245f515edff90e0c8aad2 Mon Sep 17 00:00:00 2001 From: Mateusz Palichleb <22062466+koksyn@users.noreply.github.com> Date: Fri, 30 Dec 2022 14:04:16 +0100 Subject: [PATCH 21/33] VersionInfo unit tests --- .../plugins/launch4j/VersionInfoTest.java | 303 ++++++++++++++++++ 1 file changed, 303 insertions(+) create mode 100644 src/test/java/com/akathist/maven/plugins/launch4j/VersionInfoTest.java diff --git a/src/test/java/com/akathist/maven/plugins/launch4j/VersionInfoTest.java b/src/test/java/com/akathist/maven/plugins/launch4j/VersionInfoTest.java new file mode 100644 index 00000000..16fb7f7d --- /dev/null +++ b/src/test/java/com/akathist/maven/plugins/launch4j/VersionInfoTest.java @@ -0,0 +1,303 @@ +package com.akathist.maven.plugins.launch4j; + +import net.sf.launch4j.config.LanguageID; +import org.apache.maven.model.Organization; +import org.apache.maven.project.MavenProject; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.junit.MockitoJUnitRunner; + +import java.io.File; + +import static org.junit.Assert.*; +import static org.mockito.Mockito.doReturn; + +@RunWith(MockitoJUnitRunner.class) +public class VersionInfoTest { + // VersionInfo test params + private String fileVersion = "1.0.0.0"; + private String txtFileVersion = "1.0.0.0"; + private String fileDescription = "Launch4j Test Application"; + private String copyright = "Copyright Orphan OSS"; + private String productVersion = "1.0.0.0"; + private String txtProductVersion = "1.0.0.0"; + private String productName = "Test App"; + private String companyName = "Orphan OSS Company"; + private String internalName = "app"; + private String originalFilename = "app.exe"; + private String language = LanguageID.ENGLISH_US.name(); + private String trademarks = "Test ™"; + + // Mocks + @Mock + Organization organization; + @Mock + MavenProject project; + @Mock + File outfile; + + // Subject + private VersionInfo versionInfo; + + @Before + public void buildVersionInfoFromTestParams() { + versionInfo = new VersionInfo(fileVersion, txtFileVersion, fileDescription, + copyright, productVersion, txtProductVersion, + productName, companyName, internalName, + originalFilename, language, trademarks); + } + + @Test + public void shouldFillOut_ByDefaultVersion_InL4jFormat_When_VersionInfoPropsWere_Empty() { + // given + String projectVersion = "1.2.3.4"; + doReturn(projectVersion).when(project).getVersion(); + + versionInfo.fileVersion = null; + versionInfo.productVersion = null; + + // when + versionInfo.tryFillOutByDefaults(project, outfile); + + // then + assertEquals(projectVersion, versionInfo.fileVersion); + assertNotEquals(fileVersion, versionInfo.fileVersion); + assertEquals(projectVersion, versionInfo.productVersion); + assertNotEquals(productVersion, versionInfo.productVersion); + } + + @Test + public void should_Not_FillOut_Copyright_ByDefault_When_ItWas_Filled() { + // given + String projectInceptionYear = "2017"; + doReturn(projectInceptionYear).when(project).getInceptionYear(); + + String organizationName = "Another OSS"; + doReturn(organizationName).when(organization).getName(); + doReturn(organization).when(project).getOrganization(); + + // when + versionInfo.tryFillOutByDefaults(project, outfile); + + // then + assertNotNull(versionInfo.copyright); + assertEquals(copyright, versionInfo.copyright); + assertFalse(versionInfo.copyright.contains(projectInceptionYear)); + assertFalse(versionInfo.copyright.contains(organizationName)); + } + + @Test + public void shouldFillOut_Copyright_ByDefault_When_ItWas_Empty() { + // given + String projectInceptionYear = "2019"; + doReturn(projectInceptionYear).when(project).getInceptionYear(); + + String organizationName = "Some OSS"; + doReturn(organizationName).when(organization).getName(); + doReturn(organization).when(project).getOrganization(); + + versionInfo.copyright = null; + + // when + versionInfo.tryFillOutByDefaults(project, outfile); + + // then + assertNotNull(versionInfo.copyright); + assertNotEquals(copyright, versionInfo.copyright); + assertTrue(versionInfo.copyright.contains(projectInceptionYear)); + assertTrue(versionInfo.copyright.contains(organizationName)); + } + + @Test + public void should_Not_FillOutByDefaults_From_MavenProject_OrganizationName_When_OrganizationWas_Empty() { + // given + versionInfo.companyName = null; + versionInfo.trademarks = null; + + // when + versionInfo.tryFillOutByDefaults(project, outfile); + + // then + assertNull(versionInfo.companyName); + assertNull(versionInfo.trademarks); + } + + @Test + public void should_Not_FillOutByDefaults_From_OrganizationName_When_VersionInfoPropsWere_Filled() { + // given + String organizationName = "Example OSS"; + doReturn(organizationName).when(organization).getName(); + + // when + versionInfo.tryFillOutByDefaults(project, outfile); + + // then + assertNotEquals(organizationName, versionInfo.companyName); + assertEquals(companyName, versionInfo.companyName); + assertNotEquals(organizationName, versionInfo.trademarks); + assertEquals(trademarks, versionInfo.trademarks); + } + + @Test + public void shouldFillOutByDefaults_From_OrganizationName_When_OrganizationWas_Filled() { + // given + String organizationName = "Other OSS"; + doReturn(organizationName).when(organization).getName(); + + versionInfo.companyName = null; + versionInfo.trademarks = null; + + // when + versionInfo.tryFillOutByDefaults(project, outfile); + + // then + assertEquals(organizationName, versionInfo.companyName); + assertEquals(organizationName, versionInfo.trademarks); + } + + @Test + public void should_Not_FillOutByDefaults_SimpleValues_From_MavenProject_When_ProjectPropsWere_Empty() { + // given + doReturn(null).when(project).getVersion(); + versionInfo.txtFileVersion = null; + versionInfo.txtProductVersion = null; + + doReturn(null).when(project).getName(); + versionInfo.productName = null; + + doReturn(null).when(project).getArtifactId(); + versionInfo.internalName = null; + + doReturn(null).when(project).getDescription(); + versionInfo.fileDescription = null; + + // when + versionInfo.tryFillOutByDefaults(project, outfile); + + // then + assertNull(versionInfo.txtFileVersion); + assertNull(versionInfo.txtProductVersion); + assertNull(versionInfo.productName); + assertNull(versionInfo.internalName); + assertNull(versionInfo.fileDescription); + } + + @Test + public void should_Not_FillOutByDefaults_SimpleValues_From_MavenProject_When_VersionInfoPropsWere_Filled() { + // given + String projectVersion = "1.21.1"; + doReturn(projectVersion).when(project).getVersion(); + + String projectName = "launch4j-test-app"; + doReturn(projectName).when(project).getName(); + + String projectArtifactId = "launch4j-test"; + doReturn(projectArtifactId).when(project).getArtifactId(); + + String projectDescription = "Launch4j Test App"; + doReturn(projectDescription).when(project).getDescription(); + + // when + versionInfo.tryFillOutByDefaults(project, outfile); + + // then + assertNotEquals(projectVersion, versionInfo.txtFileVersion); + assertEquals(txtFileVersion, versionInfo.txtFileVersion); + assertNotEquals(projectVersion, versionInfo.txtProductVersion); + assertEquals(txtProductVersion, versionInfo.txtProductVersion); + assertNotEquals(projectName, versionInfo.productName); + assertEquals(productName, versionInfo.productName); + assertNotEquals(projectArtifactId, versionInfo.internalName); + assertEquals(internalName, versionInfo.internalName); + assertNotEquals(projectDescription, versionInfo.fileDescription); + assertEquals(fileDescription, versionInfo.fileDescription); + } + + @Test + public void shouldFillOutByDefaults_SimpleValues_From_MavenProject_When_VersionInfoPropsWere_Empty() { + // given + String projectVersion = "1.21.1"; + doReturn(projectVersion).when(project).getVersion(); + versionInfo.txtFileVersion = null; + versionInfo.txtProductVersion = null; + + String projectName = "launch4j-test-app"; + doReturn(projectName).when(project).getName(); + versionInfo.productName = null; + + String projectArtifactId = "launch4j-test"; + doReturn(projectArtifactId).when(project).getArtifactId(); + versionInfo.internalName = null; + + String projectDescription = "Launch4j Test App"; + doReturn(projectDescription).when(project).getDescription(); + versionInfo.fileDescription = null; + + // when + versionInfo.tryFillOutByDefaults(project, outfile); + + // then + assertEquals(projectVersion, versionInfo.txtFileVersion); + assertEquals(projectVersion, versionInfo.txtProductVersion); + assertEquals(projectName, versionInfo.productName); + assertEquals(projectArtifactId, versionInfo.internalName); + assertEquals(projectDescription, versionInfo.fileDescription); + } + + // TODO: exception tryFillOutOriginalFileNameByDefault + + @Test + public void should_Not_FillOut_ByDefault_LastSegmentOfOutfilePath_When_OriginalFilenameWas_Filled() { + // given + String outfileName = "testApp.exe"; + doReturn(outfileName).when(outfile).getName(); + + // when + versionInfo.tryFillOutByDefaults(project, outfile); + + // then + assertNotEquals(outfileName, versionInfo.originalFilename); + assertEquals(originalFilename, versionInfo.originalFilename); + } + + @Test + public void shouldFillOut_ByDefault_LastSegmentOfOutfilePath_When_OriginalFilenameWas_Empty() { + // given + String outfileName = "testApp.exe"; + doReturn(outfileName).when(outfile).getName(); + versionInfo.originalFilename = null; + + // when + versionInfo.tryFillOutByDefaults(project, outfile); + + // then + assertEquals(outfileName, versionInfo.originalFilename); + } + + @Test + public void shouldGenerateString_WithTestParams() { + // when + String result = versionInfo.toString(); + + // then + assertNotNull(result); + assertTrue(containsParam(result, "fileVersion", fileVersion)); + assertTrue(containsParam(result, "txtFileVersion", txtFileVersion)); + assertTrue(containsParam(result, "fileDescription", fileDescription)); + assertTrue(containsParam(result, "copyright", copyright)); + assertTrue(containsParam(result, "productVersion", productVersion)); + assertTrue(containsParam(result, "txtProductVersion", txtProductVersion)); + assertTrue(containsParam(result, "productName", productName)); + assertTrue(containsParam(result, "companyName", companyName)); + assertTrue(containsParam(result, "internalName", internalName)); + assertTrue(containsParam(result, "originalFilename", originalFilename)); + assertTrue(containsParam(result, "language", language)); + assertTrue(containsParam(result, "trademarks", trademarks)); + } + + private boolean containsParam(String result, String paramName, String paramValue) { + return result.contains(paramName + "='" + paramValue + "'"); + } +} \ No newline at end of file From f41b87015c88780f072699a2bc3c11abf8737e72 Mon Sep 17 00:00:00 2001 From: Mateusz Palichleb <22062466+koksyn@users.noreply.github.com> Date: Fri, 30 Dec 2022 14:22:27 +0100 Subject: [PATCH 22/33] Adds missing VersionInfo unit tests --- .../plugins/launch4j/VersionInfoTest.java | 66 ++++++++++++++++++- 1 file changed, 64 insertions(+), 2 deletions(-) diff --git a/src/test/java/com/akathist/maven/plugins/launch4j/VersionInfoTest.java b/src/test/java/com/akathist/maven/plugins/launch4j/VersionInfoTest.java index 16fb7f7d..b44cff35 100644 --- a/src/test/java/com/akathist/maven/plugins/launch4j/VersionInfoTest.java +++ b/src/test/java/com/akathist/maven/plugins/launch4j/VersionInfoTest.java @@ -49,6 +49,68 @@ public void buildVersionInfoFromTestParams() { originalFilename, language, trademarks); } + @Test + public void shouldConvertIntoL4jFormatProperly() { + // when + net.sf.launch4j.config.VersionInfo l4jVersionInfo = versionInfo.toL4j(); + + // then + assertEquals(versionInfo.fileVersion, l4jVersionInfo.getFileVersion()); + assertEquals(versionInfo.txtFileVersion, l4jVersionInfo.getTxtFileVersion()); + assertEquals(versionInfo.fileDescription, l4jVersionInfo.getFileDescription()); + assertEquals(versionInfo.copyright, l4jVersionInfo.getCopyright()); + assertEquals(versionInfo.productVersion, l4jVersionInfo.getProductVersion()); + assertEquals(versionInfo.txtProductVersion, l4jVersionInfo.getTxtProductVersion()); + assertEquals(versionInfo.productName, l4jVersionInfo.getProductName()); + assertEquals(versionInfo.companyName, l4jVersionInfo.getCompanyName()); + assertEquals(versionInfo.internalName, l4jVersionInfo.getInternalName()); + assertEquals(versionInfo.originalFilename, l4jVersionInfo.getOriginalFilename()); + assertEquals(versionInfo.trademarks, l4jVersionInfo.getTrademarks()); + assertEquals(versionInfo.language, l4jVersionInfo.getLanguage().name()); + } + + @Test + public void shouldConvertIntoL4jFormat_For_All_Languages() { + for (LanguageID languageId : LanguageID.values()) { + // given + versionInfo.language = languageId.name(); + + // when + net.sf.launch4j.config.VersionInfo l4jVersionInfo = versionInfo.toL4j(); + + // then + assertEquals(languageId, l4jVersionInfo.getLanguage()); + } + } + + @Test(expected = IllegalArgumentException.class) + public void shouldThrowException_WhenTryingToFillOutDefaults_WithEmptyProject() { + // expect throws + versionInfo.tryFillOutByDefaults(null, outfile); + } + + @Test(expected = IllegalArgumentException.class) + public void shouldThrowException_WhenTryingToFillOutDefaults_WithEmptyOutfile() { + // expect throws + versionInfo.tryFillOutByDefaults(project, null); + } + + @Test + public void should_Not_FillOut_ByDefaultVersion_InL4jFormat_When_VersionInfoPropsWere_Filled() { + // given + String projectVersion = "4.3.2.1"; + doReturn(projectVersion).when(project).getVersion(); + + // when + versionInfo.tryFillOutByDefaults(project, outfile); + + // then + assertNotEquals(projectVersion, versionInfo.fileVersion); + assertEquals(fileVersion, versionInfo.fileVersion); + assertNotEquals(projectVersion, versionInfo.productVersion); + assertEquals(productVersion, versionInfo.productVersion); + } + @Test public void shouldFillOut_ByDefaultVersion_InL4jFormat_When_VersionInfoPropsWere_Empty() { // given @@ -129,6 +191,7 @@ public void should_Not_FillOutByDefaults_From_OrganizationName_When_VersionInfoP // given String organizationName = "Example OSS"; doReturn(organizationName).when(organization).getName(); + doReturn(organization).when(project).getOrganization(); // when versionInfo.tryFillOutByDefaults(project, outfile); @@ -145,6 +208,7 @@ public void shouldFillOutByDefaults_From_OrganizationName_When_OrganizationWas_F // given String organizationName = "Other OSS"; doReturn(organizationName).when(organization).getName(); + doReturn(organization).when(project).getOrganization(); versionInfo.companyName = null; versionInfo.trademarks = null; @@ -246,8 +310,6 @@ public void shouldFillOutByDefaults_SimpleValues_From_MavenProject_When_VersionI assertEquals(projectDescription, versionInfo.fileDescription); } - // TODO: exception tryFillOutOriginalFileNameByDefault - @Test public void should_Not_FillOut_ByDefault_LastSegmentOfOutfilePath_When_OriginalFilenameWas_Filled() { // given From c4891579717f8fe3191a61968d210498bdc3d169 Mon Sep 17 00:00:00 2001 From: Mateusz Palichleb <22062466+koksyn@users.noreply.github.com> Date: Fri, 30 Dec 2022 14:26:13 +0100 Subject: [PATCH 23/33] Adds missing Mojo param to MojoTest --- .../com/akathist/maven/plugins/launch4j/Launch4jMojoTest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/test/java/com/akathist/maven/plugins/launch4j/Launch4jMojoTest.java b/src/test/java/com/akathist/maven/plugins/launch4j/Launch4jMojoTest.java index 0e9bee22..4f5b8025 100644 --- a/src/test/java/com/akathist/maven/plugins/launch4j/Launch4jMojoTest.java +++ b/src/test/java/com/akathist/maven/plugins/launch4j/Launch4jMojoTest.java @@ -66,6 +66,7 @@ public void testMojoGoal() throws Exception { "language='ENGLISH_US', " + "trademarks='Luk ™'" + "}, " + + "disableVersionInfoDefaults=false, " + "messages=Messages{" + "startupErr='null', " + "jreVersionErr='null', " + From 65cafe9ec4be645c03b4e2912b0105b39ce54b67 Mon Sep 17 00:00:00 2001 From: Mateusz Palichleb <22062466+koksyn@users.noreply.github.com> Date: Fri, 30 Dec 2022 14:51:34 +0100 Subject: [PATCH 24/33] Refactoring MojoTest --- .../maven/plugins/launch4j/Launch4jMojoTest.java | 10 ++++------ .../launch4j-full-plugin-config.xml} | 3 ++- 2 files changed, 6 insertions(+), 7 deletions(-) rename src/test/resources/unit/{launch4j-default/launch4j-default-plugin-config.xml => launch4j-config/launch4j-full-plugin-config.xml} (96%) diff --git a/src/test/java/com/akathist/maven/plugins/launch4j/Launch4jMojoTest.java b/src/test/java/com/akathist/maven/plugins/launch4j/Launch4jMojoTest.java index 4f5b8025..6c6134ee 100644 --- a/src/test/java/com/akathist/maven/plugins/launch4j/Launch4jMojoTest.java +++ b/src/test/java/com/akathist/maven/plugins/launch4j/Launch4jMojoTest.java @@ -5,9 +5,8 @@ import java.io.File; public class Launch4jMojoTest extends AbstractMojoTestCase { - - public void testMojoGoal() throws Exception { - File testPom = new File(getBasedir(), "src/test/resources/unit/launch4j-default/launch4j-default-plugin-config.xml"); + public void testPrintOutFulfilledConfiguration() throws Exception { + File testPom = new File(getBasedir(), "src/test/resources/unit/launch4j-config/launch4j-full-plugin-config.xml"); Launch4jMojo mojo = (Launch4jMojo) lookupMojo("launch4j", testPom); @@ -66,7 +65,7 @@ public void testMojoGoal() throws Exception { "language='ENGLISH_US', " + "trademarks='Luk ™'" + "}, " + - "disableVersionInfoDefaults=false, " + + "disableVersionInfoDefaults=true, " + "messages=Messages{" + "startupErr='null', " + "jreVersionErr='null', " + @@ -81,5 +80,4 @@ public void testMojoGoal() throws Exception { "skip=false" + "}", mojo.toString()); } - -} +} \ No newline at end of file diff --git a/src/test/resources/unit/launch4j-default/launch4j-default-plugin-config.xml b/src/test/resources/unit/launch4j-config/launch4j-full-plugin-config.xml similarity index 96% rename from src/test/resources/unit/launch4j-default/launch4j-default-plugin-config.xml rename to src/test/resources/unit/launch4j-config/launch4j-full-plugin-config.xml index 59b25602..45136800 100644 --- a/src/test/resources/unit/launch4j-default/launch4j-default-plugin-config.xml +++ b/src/test/resources/unit/launch4j-config/launch4j-full-plugin-config.xml @@ -7,7 +7,7 @@ 1.0-SNAPSHOT jar - launch4j-default + launch4j-full @@ -35,6 +35,7 @@ -Dname=Lukasz + true Test bundledJreErr From d34d506aa100ee7d625fdc1bbb7e2ac6864e0c8f Mon Sep 17 00:00:00 2001 From: Mateusz Palichleb <22062466+koksyn@users.noreply.github.com> Date: Fri, 30 Dec 2022 15:05:36 +0100 Subject: [PATCH 25/33] Missing dependency added to POM --- pom.xml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pom.xml b/pom.xml index b6bf0d99..ce78d96c 100644 --- a/pom.xml +++ b/pom.xml @@ -119,6 +119,11 @@ maven-artifact-transfer 0.13.1 + + org.apache.commons + commons-lang3 + 3.12.0 + junit junit From 63673e55f7bb630037700a65de5684ec7ec4dd06 Mon Sep 17 00:00:00 2001 From: Mateusz Palichleb <22062466+koksyn@users.noreply.github.com> Date: Fri, 30 Dec 2022 15:06:31 +0100 Subject: [PATCH 26/33] Possibility of not filling out VersionInfo in XML at all --- .../java/com/akathist/maven/plugins/launch4j/Launch4jMojo.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/com/akathist/maven/plugins/launch4j/Launch4jMojo.java b/src/main/java/com/akathist/maven/plugins/launch4j/Launch4jMojo.java index 9cf953e1..354e91db 100644 --- a/src/main/java/com/akathist/maven/plugins/launch4j/Launch4jMojo.java +++ b/src/main/java/com/akathist/maven/plugins/launch4j/Launch4jMojo.java @@ -348,6 +348,9 @@ private void doExecute() throws MojoExecutionException { if (!disableVersionInfoDefaults) { try { + if(versionInfo == null) { + versionInfo = new VersionInfo(); + } versionInfo.tryFillOutByDefaults(project, outfile); } catch (RuntimeException exception) { throw new MojoExecutionException("Cannot fill out VersionInfo by defaults", exception); From 8764598e911c11a16c1385f308493aff8021c039 Mon Sep 17 00:00:00 2001 From: Mateusz Palichleb <22062466+koksyn@users.noreply.github.com> Date: Fri, 30 Dec 2022 16:33:31 +0100 Subject: [PATCH 27/33] Documentation for VersionInfo defaults added --- README.md | 1 + src/main/resources/MOJO.md | 2 + src/main/resources/VERSIONINFO.md | 143 ++++++++++++++++++++++++++++++ 3 files changed, 146 insertions(+) create mode 100644 src/main/resources/VERSIONINFO.md diff --git a/README.md b/README.md index e5a66999..38eb0c03 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,7 @@ The full list of all the parameters is available [here](src/main/resources/MOJO. ## Version notes 2.3.0 - 2022-12-30 - provides default values for plugin configuration, especially for ``, see Issue [#98](../../issues/98) - adds a `disableVersionInfoDefaults` parameter to be able to disable provided defaults, see PR [#205](../../pull/205) +- adds documentation notes regarding a new defaults, see [VERSIONINFO.md](src/main/resources/VERSIONINFO.md) ## Version notes 2.2.0 - 2022-11-24 - upgrades Launch4j to version 3.50 and adopts config to the bew requirements, see Issue [#199](../../issues/199) diff --git a/src/main/resources/MOJO.md b/src/main/resources/MOJO.md index 07dbcafd..befd5fa5 100644 --- a/src/main/resources/MOJO.md +++ b/src/main/resources/MOJO.md @@ -284,6 +284,8 @@ Lots of information you can attach to the windows process. * **Type**: `com.akathist.maven.plugins.launch4j.VersionInfo` * **Required**: `No` +The full list of all the `VersionInfo` parameters is available [here](./VERSIONINFO.md). + * * * #### **\** diff --git a/src/main/resources/VERSIONINFO.md b/src/main/resources/VERSIONINFO.md new file mode 100644 index 00000000..6141e2ec --- /dev/null +++ b/src/main/resources/VERSIONINFO.md @@ -0,0 +1,143 @@ +# VersionInfo parameters + +### Description. + +This file describes the `VersionInfo` parameters. + +* **Type**: `com.akathist.maven.plugins.launch4j.VersionInfo` + +Every parameter (including their parent `VersionInfo`) have a default value defined. +To fulfill them by default values you need to make sure that **\** inside plugin configuration is set to `false`. + +### Parameter Details + +#### **\** + +Version number in `x.x.x.x` format. + +* **Type**: `java.lang.String` +* **Required**: `Yes` +* **Default**: `${project.version}` converted into a `x.x.x.x` format. + +Conversion into a `x.x.x.x` format have specific constraints: +* `x` as a number +* shorter project versions like `x.x.x` will have appended zeros (to the 4th level) like `x.x.x.0` +* every text flag like "-SNAPSHOT" or "-alpha" will be cut off +* too many nested levels (>4) will be cut off as well. Example input: `1.2.3.4.5.6`, output: `1.2.3.4`. + +* * * + +#### **\** + +Free-form version number, like "1.20.RC1." + +* **Type**: `java.lang.String` +* **Required**: `Yes` +* **Default**: `${project.version}` + +* * * + +#### **\** + +File description shown to the user. + +* **Type**: `java.lang.String` +* **Required**: `Yes` +* **Default**: `${project.description}` + +* * * + +#### **\** + +Legal copyright. + +* **Type**: `java.lang.String` +* **Required**: `Yes` +* **Default**: `Copyright © ${project.inceptionYear}-${currentYear} ${project.organization.name}. All rights reserved.`. + +Where: +* `${project.inceptionYear}` is not mandatory. +* `${currentYear}` is generated programmatically. +* `${project.organization.name}` is not mandatory. + +* * * + +#### **\** + +Version number in `x.x.x.x` format. + +* **Type**: `java.lang.String` +* **Required**: `Yes` +* **Default**: `${project.version}` converted into a `x.x.x.x` format. The same conversion such the one described regarding `fileVersion` parameter above. + +* * * + +#### **\** + +Free-form version number, like "1.20.RC1." + +* **Type**: `java.lang.String` +* **Required**: `Yes` +* **Default**: `${project.version}` + +* * * + +#### **\** + +The product name. + +* **Type**: `java.lang.String` +* **Required**: `Yes` +* **Default**: `${project.name}` + +* * * + +#### **\** + +The company name. + +* **Type**: `java.lang.String` +* **Required**: `Yes` +* **Default**: `${project.organization.name}` + +* * * + +#### **\** + +The internal name. For instance, you could use the filename without extension or the module name. + +* **Type**: `java.lang.String` +* **Required**: `Yes` +* **Default**: `${project.artifactId}` + +* * * + +#### **\** + +The original filename without path. Setting this lets you determine whether a user has renamed the file. + +* **Type**: `java.lang.String` +* **Required**: `Yes` +* **Default**: last path segment of the `${outfile}` configuration + +* * * + +#### **\** + +Language to be used during installation. + +* **Type**: `java.lang.String` +* **Required**: `Yes` +* **Default**: `ENGLISH_US` + +* * * + +#### **\** + +Trademarks of author. + +* **Type**: `java.lang.String` +* **Required**: `Yes` +* **Default**: `${project.organization.name}` + +* * * \ No newline at end of file From b66d97e7eb8c93c186605f9e2d04ddd03f33bb3a Mon Sep 17 00:00:00 2001 From: Mateusz Palichleb <22062466+koksyn@users.noreply.github.com> Date: Fri, 30 Dec 2022 17:08:48 +0100 Subject: [PATCH 28/33] Throwing exception datailed descriptions --- README.md | 1 + .../maven/plugins/launch4j/VersionInfo.java | 36 +++++++++++-------- .../plugins/launch4j/VersionInfoTest.java | 11 ++---- 3 files changed, 25 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index 38eb0c03..fd606a01 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,7 @@ The full list of all the parameters is available [here](src/main/resources/MOJO. - provides default values for plugin configuration, especially for ``, see Issue [#98](../../issues/98) - adds a `disableVersionInfoDefaults` parameter to be able to disable provided defaults, see PR [#205](../../pull/205) - adds documentation notes regarding a new defaults, see [VERSIONINFO.md](src/main/resources/VERSIONINFO.md) +- throwing exceptions with detailed description of default values formula, when cannot fulfill default values (no configuration data for formula), it helps plugin user with debugging what is wrong ## Version notes 2.2.0 - 2022-11-24 - upgrades Launch4j to version 3.50 and adopts config to the bew requirements, see Issue [#199](../../issues/199) diff --git a/src/main/java/com/akathist/maven/plugins/launch4j/VersionInfo.java b/src/main/java/com/akathist/maven/plugins/launch4j/VersionInfo.java index 96af2790..aee9aa8a 100644 --- a/src/main/java/com/akathist/maven/plugins/launch4j/VersionInfo.java +++ b/src/main/java/com/akathist/maven/plugins/launch4j/VersionInfo.java @@ -184,24 +184,24 @@ public void tryFillOutByDefaults(MavenProject project, File outfile) { project.getDescription() ); - originalFilename = getDefaultWhenOriginalIsBlank(originalFilename, outfile.getName()); + originalFilename = getDefaultWhenOriginalIsBlank(originalFilename, outfile.getName(), "originalFilename", "${project.version}"); } private void tryFillOutByDefaultVersionInL4jFormat(String version) { final String defaultFileVersion = Launch4jFileVersionGenerator.generate(version); - fileVersion = getDefaultWhenOriginalIsBlank(fileVersion, defaultFileVersion); - productVersion = getDefaultWhenOriginalIsBlank(productVersion, defaultFileVersion); + fileVersion = getDefaultWhenOriginalIsBlank(fileVersion, defaultFileVersion, "fileVersion", "${project.version}"); + productVersion = getDefaultWhenOriginalIsBlank(productVersion, defaultFileVersion, "productVersion", "${project.version}"); } private void tryFillOutCopyrightByDefaults(String inceptionYear, Organization organization) { final String defaultCopyright = CopyrightGenerator.generate(inceptionYear, organization); - copyright = getDefaultWhenOriginalIsBlank(copyright, defaultCopyright); + copyright = getDefaultWhenOriginalIsBlank(copyright, defaultCopyright, "copyright", "${project.inceptionYear},${project.organization.name}"); } private void tryFillOutOrganizationRelatedDefaults(Organization organization) { if (organization != null) { - companyName = getDefaultWhenOriginalIsBlank(companyName, organization.getName()); - trademarks = getDefaultWhenOriginalIsBlank(trademarks, organization.getName()); + companyName = getDefaultWhenOriginalIsBlank(companyName, organization.getName(), "companyName", "${project.organization.name}"); + trademarks = getDefaultWhenOriginalIsBlank(trademarks, organization.getName(), "trademarks", "${project.organization.name}"); } } @@ -209,16 +209,24 @@ private void tryFillOutSimpleValuesByDefaults(String version, String name, String artifactId, String description) { - txtFileVersion = getDefaultWhenOriginalIsBlank(txtFileVersion, version); - txtProductVersion = getDefaultWhenOriginalIsBlank(txtProductVersion, version); - productName = getDefaultWhenOriginalIsBlank(productName, name); - internalName = getDefaultWhenOriginalIsBlank(internalName, artifactId); - fileDescription = getDefaultWhenOriginalIsBlank(fileDescription, description); + txtFileVersion = getDefaultWhenOriginalIsBlank(txtFileVersion, version, "txtFileVersion", "${project.version}"); + txtProductVersion = getDefaultWhenOriginalIsBlank(txtProductVersion, version, "txtProductVersion", "${project.version}"); + productName = getDefaultWhenOriginalIsBlank(productName, name, "productName", "${project.name}"); + internalName = getDefaultWhenOriginalIsBlank(internalName, artifactId, "internalName", "${project.artifactId}"); + fileDescription = getDefaultWhenOriginalIsBlank(fileDescription, description, "fileDescription", "${project.description}"); } - private String getDefaultWhenOriginalIsBlank(final String originalValue, final String defaultValue) { - if (StringUtils.isBlank(originalValue) && StringUtils.isNotBlank(defaultValue)) { - return defaultValue; + private String getDefaultWhenOriginalIsBlank(final String originalValue, + final String defaultValue, + final String originalParameterName, + final String defaultValueFormulaParams) { + if (StringUtils.isBlank(originalValue)) { + if(StringUtils.isNotBlank(defaultValue)) { + return defaultValue; + } + + throw new IllegalStateException("Please fill the missing configuration values. " + + "Error when trying to fulfill default value for VersionInfo parameter:'" + originalParameterName + "' with formula params:'" + defaultValueFormulaParams + "'."); } return originalValue; diff --git a/src/test/java/com/akathist/maven/plugins/launch4j/VersionInfoTest.java b/src/test/java/com/akathist/maven/plugins/launch4j/VersionInfoTest.java index b44cff35..e8eaa883 100644 --- a/src/test/java/com/akathist/maven/plugins/launch4j/VersionInfoTest.java +++ b/src/test/java/com/akathist/maven/plugins/launch4j/VersionInfoTest.java @@ -221,7 +221,7 @@ public void shouldFillOutByDefaults_From_OrganizationName_When_OrganizationWas_F assertEquals(organizationName, versionInfo.trademarks); } - @Test + @Test(expected = IllegalStateException.class) public void should_Not_FillOutByDefaults_SimpleValues_From_MavenProject_When_ProjectPropsWere_Empty() { // given doReturn(null).when(project).getVersion(); @@ -237,15 +237,8 @@ public void should_Not_FillOutByDefaults_SimpleValues_From_MavenProject_When_Pro doReturn(null).when(project).getDescription(); versionInfo.fileDescription = null; - // when + // expect throws versionInfo.tryFillOutByDefaults(project, outfile); - - // then - assertNull(versionInfo.txtFileVersion); - assertNull(versionInfo.txtProductVersion); - assertNull(versionInfo.productName); - assertNull(versionInfo.internalName); - assertNull(versionInfo.fileDescription); } @Test From d019663e8bc58f5704505ef1d87dd4d2cf56f4b7 Mon Sep 17 00:00:00 2001 From: Mateusz Palichleb <22062466+koksyn@users.noreply.github.com> Date: Fri, 30 Dec 2022 17:16:54 +0100 Subject: [PATCH 29/33] Release version without snapshot --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index e0c56189..78800b33 100644 --- a/pom.xml +++ b/pom.xml @@ -22,7 +22,7 @@ com.akathist.maven.plugins.launch4j launch4j-maven-plugin maven-plugin - 2.3.0-SNAPSHOT + 2.3.0 Maven Launch4j Plugin This plugin creates Windows executables from Java jar files using the Launch4j utility. From 98b1c652596c37fa2d61dc21c777b42df4518f4d Mon Sep 17 00:00:00 2001 From: Mateusz Palichleb <22062466+koksyn@users.noreply.github.com> Date: Mon, 2 Jan 2023 19:21:24 +0100 Subject: [PATCH 30/33] Revert "Release version without snapshot" This reverts commit d019663e8bc58f5704505ef1d87dd4d2cf56f4b7. --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 78800b33..e0c56189 100644 --- a/pom.xml +++ b/pom.xml @@ -22,7 +22,7 @@ com.akathist.maven.plugins.launch4j launch4j-maven-plugin maven-plugin - 2.3.0 + 2.3.0-SNAPSHOT Maven Launch4j Plugin This plugin creates Windows executables from Java jar files using the Launch4j utility. From ba82667641c3f8efe22fd52e4398f20e3c4ca43c Mon Sep 17 00:00:00 2001 From: Mateusz Palichleb <22062466+koksyn@users.noreply.github.com> Date: Mon, 2 Jan 2023 19:40:40 +0100 Subject: [PATCH 31/33] default scope for filling out defaults inside VersionInfo --- .../java/com/akathist/maven/plugins/launch4j/VersionInfo.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/akathist/maven/plugins/launch4j/VersionInfo.java b/src/main/java/com/akathist/maven/plugins/launch4j/VersionInfo.java index aee9aa8a..8adfc363 100644 --- a/src/main/java/com/akathist/maven/plugins/launch4j/VersionInfo.java +++ b/src/main/java/com/akathist/maven/plugins/launch4j/VersionInfo.java @@ -163,7 +163,7 @@ private void setLanguage(net.sf.launch4j.config.VersionInfo ret) { ret.setLanguage(languageID); } - public void tryFillOutByDefaults(MavenProject project, File outfile) { + void tryFillOutByDefaults(MavenProject project, File outfile) { if (project == null) { throw new IllegalArgumentException("'project' is required, but it is null."); } From 79337bd80bbddb4f24aa9b259838a5fe99140074 Mon Sep 17 00:00:00 2001 From: Mateusz Palichleb <22062466+koksyn@users.noreply.github.com> Date: Mon, 2 Jan 2023 19:48:09 +0100 Subject: [PATCH 32/33] Newline's at the end of the files --- .../maven/plugins/launch4j/generators/CopyrightGenerator.java | 2 +- .../launch4j/generators/Launch4jFileVersionGenerator.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/akathist/maven/plugins/launch4j/generators/CopyrightGenerator.java b/src/main/java/com/akathist/maven/plugins/launch4j/generators/CopyrightGenerator.java index 6fd1b6be..305627b2 100644 --- a/src/main/java/com/akathist/maven/plugins/launch4j/generators/CopyrightGenerator.java +++ b/src/main/java/com/akathist/maven/plugins/launch4j/generators/CopyrightGenerator.java @@ -34,4 +34,4 @@ private static String generateOrganizationName(Organization projectOrganization) return ""; } -} \ No newline at end of file +} diff --git a/src/main/java/com/akathist/maven/plugins/launch4j/generators/Launch4jFileVersionGenerator.java b/src/main/java/com/akathist/maven/plugins/launch4j/generators/Launch4jFileVersionGenerator.java index 0aebf4a3..7ae81bc2 100644 --- a/src/main/java/com/akathist/maven/plugins/launch4j/generators/Launch4jFileVersionGenerator.java +++ b/src/main/java/com/akathist/maven/plugins/launch4j/generators/Launch4jFileVersionGenerator.java @@ -66,4 +66,4 @@ private static String appendMissingNestedLevelsByZeros(String versionLevels) { return filledLevels.toString(); } -} \ No newline at end of file +} From e7f2bb85f8c04afb5823e44fcca7077be30c9ead Mon Sep 17 00:00:00 2001 From: Mateusz Palichleb <22062466+koksyn@users.noreply.github.com> Date: Mon, 2 Jan 2023 19:53:41 +0100 Subject: [PATCH 33/33] Private constructors for utility classes added --- .../maven/plugins/launch4j/generators/CopyrightGenerator.java | 3 +++ .../launch4j/generators/Launch4jFileVersionGenerator.java | 3 +++ 2 files changed, 6 insertions(+) diff --git a/src/main/java/com/akathist/maven/plugins/launch4j/generators/CopyrightGenerator.java b/src/main/java/com/akathist/maven/plugins/launch4j/generators/CopyrightGenerator.java index 305627b2..7e9df9a5 100644 --- a/src/main/java/com/akathist/maven/plugins/launch4j/generators/CopyrightGenerator.java +++ b/src/main/java/com/akathist/maven/plugins/launch4j/generators/CopyrightGenerator.java @@ -6,6 +6,9 @@ import java.time.LocalDate; public class CopyrightGenerator { + private CopyrightGenerator() { + } + /** * Parameters should be taken from MavenProject properties: * @param projectInceptionYear as ${project.inceptionYear} diff --git a/src/main/java/com/akathist/maven/plugins/launch4j/generators/Launch4jFileVersionGenerator.java b/src/main/java/com/akathist/maven/plugins/launch4j/generators/Launch4jFileVersionGenerator.java index 7ae81bc2..40f3a43c 100644 --- a/src/main/java/com/akathist/maven/plugins/launch4j/generators/Launch4jFileVersionGenerator.java +++ b/src/main/java/com/akathist/maven/plugins/launch4j/generators/Launch4jFileVersionGenerator.java @@ -11,6 +11,9 @@ public class Launch4jFileVersionGenerator { 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. *