Skip to content

Commit 20588a0

Browse files
committed
basic manifest method
1 parent 3b7be87 commit 20588a0

File tree

1 file changed

+91
-68
lines changed

1 file changed

+91
-68
lines changed

src/cfml/system/util/CompileDSL.cfc

Lines changed: 91 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@ component accessors=true {
2323
property name='verbose' type='boolean';
2424
property name='encode' type='string';
2525
property name='sourcePaths' type='array';
26-
property name='recursive' type='boolean';
2726
property name='createJar' type='boolean';
2827
property name='jarNameString' type='string';
2928
property name='libsDir' type='string';
3029
property name='compileOptionsString' type='string';
3130
property name='jarOptionsString' type='string';
3231
property name='javaBinFolder' type='string';
32+
property name='customManifest' type='string';
3333

3434
//DI
3535
property name="packageService" inject="PackageService";
@@ -47,16 +47,16 @@ component accessors=true {
4747

4848
public function init() {
4949
setSourceDirectory( 'src\main\java\' );
50-
setClassOutputDirectory( 'classes\java\main\' );
50+
setClassOutputDirectory( 'classes\java\main' );
5151
setVerbose( false );
5252
setEncode( '' );
5353
setSourcePaths( [''] );
54-
setRecursive( false );
5554
setCreateJar( false );
5655
setLibsDir( 'libs' );
5756
setCompileOptionsString( '' );
5857
setJarOptionsString( '' );
59-
setJarNameString( 'output.jar' );
58+
setJarNameString( '' );
59+
setCustomManifest( '' );
6060
return this;
6161
}
6262

@@ -84,7 +84,7 @@ component accessors=true {
8484
return this;
8585
}
8686

87-
function withVerbose() {
87+
function verbose() {
8888
setVerbose( true );
8989
return this;
9090
}
@@ -94,11 +94,6 @@ component accessors=true {
9494
return this;
9595
}
9696

97-
function recursive() {
98-
setRecursive( true );
99-
return this;
100-
}
101-
10297
function toJar( string jarName='' ) {
10398
setJarNameString( jarName );
10499
setCreateJar( true );
@@ -120,21 +115,40 @@ component accessors=true {
120115
return this;
121116
}
122117

118+
function addToManifest( required string customManifest ) {
119+
setCustomManifest( fileSystemutil.resolvePath( customManifest, getProjectRoot() ) );
120+
return this;
121+
}
122+
123+
function withResources( string resourcesFolder ) {
124+
//if it has a resourcefolder it uses that one
125+
//if its empty then use java\main\resources
126+
}
127+
128+
function toFatJar( ) {
129+
//if it has a jarFolder use that one
130+
//if it does not have any use java\main\libs
131+
132+
//take all the jars in libs folder and unzip them
133+
//add them to the classoutputdirectory with the rest of then
134+
//make the jar
135+
}
136+
123137
function run() {
124138
job.start( 'Compiling' );
125139

126140
job.start( 'find jdk bin directory' );
127141
setJavaBinFolder( findJDKBinDirectory() );
128-
job.complete( getVerbose() );
142+
job.complete();
129143

130144
job.start( 'compiling the code' );
131145
compileCode();
132-
job.complete( getVerbose() );
146+
job.complete();
133147

134148
if( getCreateJar() ) {
135149
job.start( 'creating the jar' );
136150
buildJar();
137-
job.complete( getVerbose() );
151+
job.complete();
138152
}
139153

140154
job.complete( getVerbose() );
@@ -180,6 +194,8 @@ component accessors=true {
180194

181195
writeTempSourceFile( tempSrcFileName );
182196

197+
//job.addLog( " gJBF-->#getJavaBinFolder()#javac<-- " );
198+
//job.addLog( " cOD-> #variables.classOutputDirectory# " );
183199
var javacCommand = 'run "#getJavaBinFolder()#javac" "@#tempSrcFileName#" -d #variables.classOutputDirectory# #variables.compileOptionsString#';
184200

185201
/* if ( getVerbose() ) {
@@ -195,7 +211,7 @@ component accessors=true {
195211
command( javacCommand ).run();
196212

197213
} finally {
198-
if ( FileExists( tempSrcFileName ) ){
214+
if ( FileExists( tempSrcFileName ) ) {
199215
fileDelete( tempSrcFileName );
200216
}
201217

@@ -239,65 +255,56 @@ component accessors=true {
239255

240256
var tempSrcFileName = tempDir & 'temp#createUUID()#.txt';
241257

242-
//var currentLibsDir = fileSystemutil.resolvePath( getLibsDir(), getProjectRoot() );
243-
//shell.printString( ' cLD-> ' & currentLibsDir );
258+
var sourceFolders = [];
259+
buildJarSourceFolders = fileSystemutil.resolvePath( variables.classOutputDirectory, getProjectRoot() );
260+
sourceFolders.append( buildJarSourceFolders & "**.class" );
244261

245-
// if the jarname is empty
246-
// we check if the current libs is a package
247-
// if its a package
248-
// get name from package
249-
// if not get name from folder
250-
// if its root
251-
// give default name
262+
job.addLog( "currLibsDir-> #currentLibsDir#" );
252263

253264
job.start( ' for build jar check jarName ' );
254-
if( jarName.len() == 0 ){
265+
if( !jarName.len() ){
255266
// jarName is empty
256-
//shell.printString( ' jarName is empty ' );
257-
job.addLog( ' jarName is empty ' );
258-
job.addLog( ' currentLibsDir-> #currentLibsDir# ' );
259-
job.addLog( ' currentProjectRoot-> #currentProjectRoot# ' );
260-
if( packageService.isPackage( currentProjectRoot ) ) {
261-
// its a package
262-
//shell.printString( ' dir is a package ' );
263-
job.addLog( ' dir is a package ' );
264-
job.start( ' get jarName From Package ' );
265-
jarName = getJarNameFromPackage( currentProjectRoot );
266-
job.complete( getVerbose() );
267-
} else {
267+
//job.addLog( ' jarName is empty ' );
268+
job.start( ' get jarName From Package ' );
269+
jarName = getJarNameFromPackage( currentProjectRoot );
270+
job.complete();
271+
272+
if( !jarName.len() ) {
268273
// it is not a package its a normal folder
269-
//shell.printString( ' dir is not a package ' );
270-
job.addLog( ' dir is not a package ' );
271-
var word = ListLast( getProjectRoot(), "\/" );
272-
if( fileSystemUtil.isWindows() ) {
273-
//filesys is windows
274-
//shell.printString( ' filesys is windows #word# ' );
275-
job.addLog( ' filesys is windows #word# ' );
276-
} else {
277-
//linux or mac
278-
//shell.printString( ' filesys is linux/mac #word# ' );
279-
job.addLog( ' filesys is linux/mac #word# ' );
280-
}
274+
var word = '';
275+
if( ListLen( getProjectRoot(), "\/" ) >= 1 ) {
276+
word = ListLast( getProjectRoot(), "\/" );
277+
278+
} else {
279+
word = "output";
280+
281+
}
282+
jarName &= word & ".jar";
283+
//job.addLog( ' jarName= #jarName# ' );
284+
281285
}
282-
} else {
283-
// jarName is not empty
284-
shell.printString( ' jarName not is empty ' );
285-
job.addLog( ' jarName not is empty ' );
286+
286287
}
287-
job.complete( getVerbose() );
288+
289+
job.complete();
288290

289291
try{
290-
writeTempSourceFile( tempSrcFileName,['D:\Javatest\greetings\classes\**.class'], ".class" );
292+
//writeTempSourceFile( tempSrcFileName,['D:\Javatest\greetings\classes\**.class'], ".class" );
293+
writeTempSourceFile( tempSrcFileName, sourceFolders, ".class" );
291294

292295
//j = 'run "#getJavaBinFolder()#jar" --file #currentLibsDir##jarName# #getJarOptionsString()#';
293296
//j = 'run "#getJavaBinFolder()#jar" --create --file #currentLibsDir#testX.jar "@#tempSrcFileName#" #getJarOptionsString()#';
294-
j = 'run jar --create --file "#currentLibsDir##jarName#" "@#tempSrcFileName#" #getJarOptionsString()# ';
297+
if( !getCustomManifest().len() ) {
298+
j = 'run jar cf "#currentLibsDir#\#jarName#" "@#tempSrcFileName#" #getJarOptionsString()# ';
299+
} else {
300+
j = 'run jar cfm "#currentLibsDir#\#jarName#" "#variables.customManifest#" "@#tempSrcFileName#" #getJarOptionsString()# ';
301+
}
295302
//shell.printString( " " & j & " " );
296303
job.addLog( " " & j & " " );
297-
//command( j ).run();
304+
command( j ).run();
298305

299306
} finally {
300-
if ( FileExists( tempSrcFileName ) ){
307+
if ( FileExists( tempSrcFileName ) ) {
301308
fileDelete( tempSrcFileName );
302309
}
303310
}
@@ -306,18 +313,34 @@ component accessors=true {
306313
}
307314

308315
function getJarNameFromPackage( string currentFolder ){
309-
job.addLog( ' inside getJarNameFromPackage() ' );
310-
var boxJSON = packageService.readPackageDescriptor( currentFolder );
311-
var packageName = "";
312-
var packageVersion = "";
313-
if( len( Evaluate( "boxJSON.slug" ) ) != 0 ) {
314-
packageName = boxJSON.slug;
315-
}
316-
if( len( Evaluate( "boxJSON.version" ) ) != 0 ){
317-
packageVersion = boxJSON.version;
316+
//job.addLog( ' jarName is empty ' );
317+
//job.addLog( ' currentProjectRoot-> #currentFolder# ' );
318+
jarName = '';
319+
320+
if( packageService.isPackage( currentFolder ) ) {
321+
322+
//job.addLog( ' dir is a package ' );
323+
//job.addLog( ' inside getJarNameFromPackage() ' );
324+
var boxJSON = packageService.readPackageDescriptor( currentFolder );
325+
var packageName = "";
326+
var packageVersion = "";
327+
328+
if( len( boxJSON.slug ) ) {
329+
packageName = boxJSON.slug;
330+
jarName &= packageName;
331+
332+
if( len( boxJSON.version ) ) {
333+
packageVersion = boxJSON.version;
334+
jarName &= "-" & packageVersion;
335+
}
336+
337+
jarName &= ".jar"
338+
339+
}
340+
318341
}
319-
jarName = packageName&"-"&packageVersion&".jar";
320-
job.addLog( ' jarName for this package is: #jarName# ' );
342+
343+
//job.addLog( ' jarName for this package is: #jarName# ' );
321344
return jarName;
322345
}
323346

0 commit comments

Comments
 (0)