Skip to content

Commit df1556a

Browse files
committed
refactoring
1 parent 3a0b0d9 commit df1556a

1 file changed

Lines changed: 130 additions & 11 deletions

File tree

src/cfml/system/util/CompileDSL.cfc

Lines changed: 130 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,16 @@ component accessors=true {
2323
property name='verbose' type='boolean';
2424
property name='encode' type='string';
2525
property name='source' type='array';
26+
property name='recursive' type='boolean';
27+
property name='withJar' type='boolean';
28+
property name='defaultClassOutputDir' type='string';
2629

2730
//DI
2831
property name='wirebox' inject='wirebox';
2932
property name='fileSystemUtil' inject='FileSystem';
3033
property name='shell' inject='shell';
3134
property name='job' inject='interactiveJob';
35+
property name="tempDir" inject="tempDir@constants";
3236

3337
/*
3438
have a classpath
@@ -42,6 +46,9 @@ component accessors=true {
4246
setVerbose( false );
4347
setEncode( '' );
4448
setSource( [] );
49+
setRecursive( false );
50+
setWithJar( false );
51+
setDefaultClassOutputDir( 'classes\java\' );
4552
return this;
4653
}
4754

@@ -79,18 +86,90 @@ component accessors=true {
7986
return this;
8087
}
8188

82-
string function run() {
83-
j = generateJavacCommand();
84-
shell.printString( j );
85-
shell.callCommand( j );
89+
function recursive() {
90+
setRecursive( true );
91+
return this;
92+
}
93+
94+
function toJar() {
95+
setWithJar( true );
96+
}
97+
98+
function run() {
99+
runJavaCommands();
86100

87101
}
88102

89-
function generateJavacCommand() {
90-
var workingDirectory = getProjectRoot();
91-
var classOutputString = "";
92-
var verboseString = "";
103+
function runJavaCommands() {
104+
105+
compileCode();
106+
107+
if( withJar ) {
108+
creatingJar();
109+
}
110+
111+
/* var zipFileName = "D:\Javatest\greetings\test.jar";
112+
var tmpPath = "D:\Javatest\greetings\";
113+
cfzip(
114+
action = "zip",
115+
file = zipFileName,
116+
overwrite = true,
117+
source = tmpPath
118+
); */
119+
120+
/* shell.printString( " test filewrite-> " );
121+
var tempSrcFileName = "D:\Javatest\greetings\temp\temp.txt";
122+
var sourceDirs = "D:\Javatest\greetings\**.java";
123+
var fileName = 'temp#createUUID()#.zip';
124+
var fullPath = tempDir & '/' & fileName;
125+
var globber = wirebox.getInstance( 'globber' );
126+
fileWrite(
127+
tempSrcFileName,
128+
globber
129+
.setPattern( sourceDirs )
130+
.matches()
131+
.toList( chr(10) )
132+
); */
133+
134+
/* var globs = globber
135+
.setPattern( "D:\Javatest\greetings\**.java" )
136+
.matches()
137+
.toList( chr(10) );
138+
shell.printString( " glob out-> #serialize(globs)# " ); */
139+
140+
}
141+
142+
function compileCode() {
143+
shell.printString( " entering compileCode()... " );
144+
var workingDirectory = getProjectRoot();
145+
var classOutputString = "";
146+
var verboseString = "";
93147
var encodingString = "";
148+
var tempSrcFileName = "";
149+
var fileName = "";
150+
151+
if ( getRecursive() ) {
152+
153+
//creating the file path of the txt
154+
fileName = 'temp#createUUID()#.txt';
155+
var fullPath = tempDir & fileName;
156+
shell.printString( " fullpath-> #fullPath# " );
157+
158+
tempSrcFileName = fullPath;
159+
var sourceDirs = "D:\Javatest\greetings\**.java";
160+
var globber = wirebox.getInstance( 'globber' );
161+
fileWrite(
162+
tempSrcFileName,
163+
globber
164+
.setPattern( sourceDirs )
165+
.matches()
166+
.toList( chr(10) )
167+
);
168+
169+
//j = " run dir /s /B #workingDirectory#*.java > sources.txt ";
170+
//shell.printString( j );
171+
//shell.callCommand( j );
172+
}
94173

95174
if ( getSource().len() == 0 ){
96175
variables.source = listToArray( workingDirectory );
@@ -118,10 +197,16 @@ component accessors=true {
118197
workingDirectory = getSourceDirectory();
119198
}
120199

121-
if ( getClassOutputDirectory().len() ) {
122-
classOutputString = "-d #variables.classOutputDirectory#";
200+
if ( getSourceDirectory().len() ) {
201+
workingDirectory = getSourceDirectory();
123202
}
124203

204+
if ( getClassOutputDirectory().len() ) {
205+
classOutputString = "-d #variables.classOutputDirectory#";
206+
} else {
207+
classOutputString = "-d " & getProjectRoot() & getDefaultClassOutputDir();
208+
}
209+
125210
if ( getVerbose() ) {
126211
verboseString = "-verbose";
127212
}
@@ -130,6 +215,40 @@ component accessors=true {
130215
encodingString = "-encoding #variables.encode# ";
131216
}
132217

133-
return "run javac #workingDirectory# #classOutputString# #verboseString# #encodingString#";
218+
if( getRecursive() ){
219+
j = 'run javac "@#tempSrcFileName#" #classOutputString#';
220+
//j = 'run javac "@#testDir##fileName#"';
221+
} else {
222+
j = "run javac #workingDirectory# #classOutputString# #verboseString# #encodingString#";
223+
}
224+
shell.printString( " " & j & " " );
225+
shell.callCommand( j );
226+
fileDelete( tempSrcFileName );
227+
}
228+
229+
function creatingJar() {
230+
/* shell.printString( " test filewrite-> " );
231+
var tempSrcFileName = "D:\Javatest\greetings\temp\temp.txt";
232+
var sourceDirs = "D:\Javatest\greetings\**.java";
233+
var fileName = 'temp#createUUID()#.zip';
234+
var fullPath = tempDir & '/' & fileName;
235+
var globber = wirebox.getInstance( 'globber' );
236+
fileWrite(
237+
tempSrcFileName,
238+
globber
239+
.setPattern( sourceDirs )
240+
.matches()
241+
.toList( chr(10) )
242+
); */
243+
244+
j = "run jar ";
245+
shell.printString( " " & j & " " );
246+
//shell.callCommand( j );
247+
}
248+
249+
function combiningFatJar() {
250+
j = "run fat jar ";
251+
shell.printString( " " & j & " " );
252+
//shell.callCommand( j );
134253
}
135254
}

0 commit comments

Comments
 (0)