@@ -30,6 +30,7 @@ component accessors=true {
3030 property name = ' jarOptionsString' type = ' string' ;
3131 property name = ' javaBinFolder' type = ' string' ;
3232 property name = ' customManifest' type = ' string' ;
33+ property name = ' customManifestParams' type = ' struct' ;
3334 property name = ' resourcePath' type = ' string' ;
3435
3536 // DI
@@ -58,6 +59,7 @@ component accessors=true {
5859 setJarOptionsString ( ' ' );
5960 setJarNameString ( ' ' );
6061 setCustomManifest ( ' ' );
62+ setCustomManifestParams ( {} );
6163 setResourcePath ( ' src\main\resources\' );
6264 return this ;
6365 }
@@ -122,6 +124,11 @@ component accessors=true {
122124 return this ;
123125 }
124126
127+ function manifest ( required struct customParams ) {
128+ setCustomManifestParams ( customParams );
129+ return this ;
130+ }
131+
125132 function withResources ( string resourcesPath ) {
126133 // if it has a resourcefolder it uses that one
127134 // if its empty then use src\main\resources
@@ -149,15 +156,15 @@ component accessors=true {
149156 job .complete ();
150157
151158 if ( getCreateJar () ) {
159+ job .start ( ' update manifest file' );
160+ updateManifestFile ();
161+ job .complete ();
152162 job .start ( ' creating the jar' );
153163 buildJar ();
154164 job .complete ();
155165 job .start ( ' move resources to jar' );
156166 moveResources ();
157167 job .complete ();
158- job .start ( ' move resources to jar' );
159- updateManifestFile ();
160- job .complete ();
161168 }
162169
163170 job .complete ( getVerbose () );
@@ -344,6 +351,18 @@ component accessors=true {
344351
345352 function updateManifestFile () {
346353 /*
354+ the original is default
355+ if we want to send a struct of parameters to the manifest then use
356+ .manifest({})
357+ if we want to send parameters in the box.json add a "manifest"
358+ take the values that exist from the box.json then set the ones in the "manifest"
359+ like this:
360+ "manifest" : {
361+ "Manifest-Version": "1.0",
362+ "Main-Class": "foo.bar",
363+ "random": "attribute"
364+ }
365+
347366 1. check if the project has a box.json (we do that lets just set a flag)
348367 2. if it is a box.json
349368 2.1.
@@ -352,17 +371,115 @@ component accessors=true {
352371 4. independent of 2 or 3 check if we have a struct of values
353372 5. check if we override the original manifest
354373 */
374+
375+ var createUpdateManifestFile = false ;
376+
377+ // check if there are any params from a struct
378+ var paramStruct = getCustomManifestParams ();
379+ if ( paramStruct .len () ) {
380+ job .addLog ( " has values" );
381+ createUpdateManifestFile = true ;
382+ } else {
383+ job .addLog ( " is empty" );
384+ }
385+
386+ // check if project root is a package
387+ var currentProjectRoot = getProjectRoot ();
388+ if ( packageService .isPackage ( currentProjectRoot ) ) {
389+ job .addLog ( " its a package" );
390+ createUpdateManifestFile = true ;
391+ paramStruct = getParamsFromBoxJson ( currentProjectRoot , paramStruct );
392+ } else {
393+ job .addLog ( " its not a package" );
394+ }
395+
396+ if ( createUpdateManifestFile ) {
397+ job .addLog ( " creating the update manifest file" );
398+ var useTempDir = false ;
399+ var tempUpdateManifestFileName ;
400+ if ( useTempDir ) {
401+ tempUpdateManifestFileName = tempDir & ' updateManifest#createUUID () #.txt' ;
402+ } else {
403+ tempUpdateManifestFileName = currentProjectRoot & ' updateManifest#createUUID () #.txt' ;
404+ }
405+
406+ job .addLog ( " tempUpdManiFName: #tempUpdateManifestFileName #" );
407+ try {
408+ writeUpdateManifestFile ( tempUpdateManifestFileName , paramStruct );
409+ } finally {
410+ /* if ( FileExists( tempUpdateManifestFileName ) ) {
411+ fileDelete( tempUpdateManifestFileName );
412+ } */
413+ }
414+
415+ } else {
416+ job .addLog ( " no need to create the update manifest file" );
417+
418+ }
419+
420+ }
421+
422+ function writeUpdateManifestFile ( string filename , struct manifestParams ) {
423+ // var currentManifestParams = 'foo: bar';
424+ var updManifestOut = createObject ( " java" , " java.lang.StringBuilder" ).init (' ' );
425+ var lb = " #chr ( 13 ) ##chr ( 10 ) #" ;
426+
427+ for ( var itemKey in manifestParams ) {
428+ // job.addLog( '#itemKey#: #manifestParams[itemKey]#' );
429+ updManifestOut .append ( ' #itemKey #: #manifestParams [itemKey ] ##lb #' )
430+ }
431+
432+ filewrite ( filename , updManifestOut .toString () );
433+ }
434+
435+ function getParamsFromBoxJson ( string currentFolder , struct manifestParams ) {
436+ var boxJsonParams = {};
437+ var boxJSON = packageService .readPackageDescriptor ( currentFolder );
438+ // first check for all the regular info
439+ if ( len ( boxJSON .name ) ) {
440+ manifestParams [" Bundle-Name" ] = boxJSON .name ;
441+ }
442+ if ( len ( boxJSON .slug ) ) {
443+ manifestParams [" Bundle-SymbolicName" ] = boxJSON .slug ;
444+ }
445+ if ( len ( boxJSON .version ) ) {
446+ manifestParams [" Bundle-Version" ] = boxJSON .version ;
447+ }
448+ if ( len ( boxJSON .author ) ) {
449+ manifestParams [" Built-By" ] = boxJSON .author ;
450+ }
451+ if ( len ( boxJSON .shortDescription ) ) {
452+ manifestParams [" Bundle-Description" ] = boxJSON .shortDescription ;
453+ }
454+ if ( len ( boxJSON .ProjectURL ) ) {
455+ manifestParams [" Implementation-URL" ] = boxJSON .ProjectURL ;
456+ }
457+ if ( len ( boxJSON .Documentation ) ) {
458+ manifestParams [" Bundle-DocURL" ] = boxJSON .Documentation ;
459+ }
460+ if ( len ( boxJSON .License [1 ].URL ) ) {
461+ manifestParams [" Bundle-License" ] = boxJSON .License [1 ].URL ;
462+ }
463+ // after check for the manifest portion of the box.json
464+ // because if the manifest keys override the ones above in the normal box.json
465+ if ( len ( boxJSON .manifest ) ) {
466+ var boxJSonManifest = boxJSON .manifest ;
467+ for ( var itemKey in boxJSonManifest ) {
468+ manifestParams [itemKey ] = boxJSonManifest [itemKey ];
469+ }
470+ }
471+ return manifestParams ;
355472 }
356473
357474 function getJarNameFromPackage ( string currentFolder ){
358- job .addLog ( ' jarName is empty ' );
359- job .addLog ( ' currentProjectRoot-> #currentFolder # ' );
475+ // job.addLog( ' jarName is empty ' );
476+ // job.addLog( ' currentProjectRoot-> #currentFolder# ' );
360477 jarName = ' ' ;
361478
362479 if ( packageService .isPackage ( currentFolder ) ) {
363480
364- job .addLog ( ' dir is a package ' );
365- job .addLog ( ' inside getJarNameFromPackage() ' );
481+ // job.addLog( ' dir is a package ' );
482+ // job.addLog( ' inside getJarNameFromPackage() ' );
366483 var boxJSON = packageService .readPackageDescriptor ( currentFolder );
367484 var packageName = " " ;
368485 var packageVersion = " " ;
0 commit comments