1111import static org .twdata .maven .mojoexecutor .MojoExecutor .version ;
1212
1313import java .io .File ;
14- import java .io .IOException ;
15- import java .net .MalformedURLException ;
16- import java .net .URL ;
1714import java .nio .file .InvalidPathException ;
1815import java .nio .file .Paths ;
1916import java .util .ArrayList ;
2421
2522import org .apache .commons .lang3 .StringUtils ;
2623import org .apache .commons .lang3 .SystemUtils ;
27- import org .apache .maven .model .License ;
2824
2925import io .github .fvarrui .javapackager .maven .MavenContext ;
3026import io .github .fvarrui .javapackager .model .Platform ;
@@ -85,6 +81,18 @@ public File createRunnableJar() {
8581 return createRunnableJarFunction .apply (this );
8682 }
8783
84+ // resolve license
85+
86+ protected Function <Packager , File > resolveLicenseFunction ;
87+
88+ public Function <Packager , File > getResolveLicenseFunction () {
89+ return resolveLicenseFunction ;
90+ }
91+
92+ public void setResolveLicenseFunction (Function <Packager , File > resolveLicenseFunction ) {
93+ this .resolveLicenseFunction = resolveLicenseFunction ;
94+ }
95+
8896 // ===============================================
8997
9098 public Packager () {
@@ -154,7 +162,7 @@ public void resolveResources() throws Exception {
154162 Logger .infoIndent ("Resolving resources ..." );
155163
156164 // locates license file
157- licenseFile = resolveLicense (licenseFile , MavenContext . getEnv (). getMavenProject (). getLicenses () );
165+ licenseFile = resolveLicense (licenseFile );
158166
159167 // locates icon file
160168 iconFile = resolveIcon (iconFile , name , assetsFolder );
@@ -169,11 +177,6 @@ public void resolveResources() throws Exception {
169177 Logger .infoUnindent ("Resources resolved!" );
170178
171179 }
172-
173- protected String getLicenseName () {
174- List <License > licenses = MavenContext .getEnv ().getMavenProject ().getLicenses ();
175- return licenses != null && !licenses .isEmpty () && licenses .get (0 ) != null ? licenses .get (0 ).getName () : "" ;
176- }
177180
178181 /**
179182 * Copies all dependencies to app folder
@@ -468,35 +471,21 @@ protected String getRequiredModules(File libsFolder, boolean customizedJre, File
468471 /**
469472 * Locates license file
470473 * @param licenseFile Specified license file
471- * @param licenses Licenses list from POM
472474 * @return Resolved license file
473475 */
474- protected File resolveLicense (File licenseFile , List < License > licenses ) {
476+ protected File resolveLicense (File licenseFile ) {
475477
476- // if default license file doesn't exist and there's a license specified in
477- // pom.xml file, gets this last one
478+ // if default license file doesn't exist
478479 if (licenseFile != null && !licenseFile .exists ()) {
479480 Logger .warn ("Specified license file doesn't exist: " + licenseFile .getAbsolutePath ());
480481 licenseFile = null ;
481482 }
482- // if license not specified, gets from pom
483- if (licenseFile == null && !licenses .isEmpty ()) {
484-
485- String urlStr = null ;
486- try {
487- urlStr = licenses .get (0 ).getUrl ();
488- URL licenseUrl = new URL (urlStr );
489- licenseFile = new File (assetsFolder , "LICENSE" );
490- FileUtils .downloadFromUrl (licenseUrl , licenseFile );
491- } catch (MalformedURLException e ) {
492- Logger .error ("Invalid license URL specified: " + urlStr );
493- licenseFile = null ;
494- } catch (IOException e ) {
495- Logger .error ("Cannot download license from " + urlStr );
496- licenseFile = null ;
497- }
498-
483+
484+ // invokes custom license resolver if exists
485+ if (resolveLicenseFunction != null ) {
486+ licenseFile = resolveLicenseFunction .apply (this );
499487 }
488+
500489 // if license is still null, looks for LICENSE file
501490 if (licenseFile == null || !licenseFile .exists ()) {
502491 licenseFile = new File (MavenContext .getEnv ().getMavenProject ().getBasedir (), "LICENSE" );
@@ -521,13 +510,23 @@ protected File resolveLicense(File licenseFile, List<License> licenses) {
521510 * @throws Exception Process failed
522511 */
523512 protected File resolveIcon (File iconFile , String name , File assetsFolder ) throws Exception {
513+
514+ // searchs for specific icons
515+ switch (platform ) {
516+ case linux : iconFile = FileUtils .exists (linuxConfig .getPngFile ()) ? linuxConfig .getPngFile () : null ; break ;
517+ case mac : iconFile = FileUtils .exists (macConfig .getIcnsFile ()) ? macConfig .getIcnsFile () : null ; break ;
518+ case windows : iconFile = FileUtils .exists (winConfig .getIcoFile ()) ? winConfig .getIcoFile () : null ; break ;
519+ default :
520+ }
524521
525- String iconExtension = IconUtils .getIconFileExtensionByPlatform (platform );
522+ String iconExtension = IconUtils .getIconFileExtensionByPlatform (platform );
526523
524+ // if not specific icon specified for target platform, searchs for an icon in "${assetsDir}" folder
527525 if (iconFile == null ) {
528526 iconFile = new File (assetsDir , platform + "/" + name + iconExtension );
529527 }
530528
529+ // if there's no icon yet, uses default one
531530 if (!iconFile .exists ()) {
532531 iconFile = new File (assetsFolder , iconFile .getName ());
533532 FileUtils .copyResourceToFile ("/" + platform + "/default-icon" + iconExtension , iconFile );
@@ -538,7 +537,6 @@ protected File resolveIcon(File iconFile, String name, File assetsFolder) throws
538537 return iconFile ;
539538 }
540539
541-
542540 /**
543541 * Bundling app folder in tarball and/or zipball
544542 * @throws Exception Process failed
0 commit comments