@@ -39,7 +39,6 @@ function! javacomplete#classpath#ant#Generate(force) abort
39
39
let g: JavaComplete_ProjectKey = substitute (g: JavaComplete_AntPath , ' [\\/:;.]' , ' _' , ' g' )
40
40
let path = javacomplete#util#GetBase (" classpath" . g: FILE_SEP ). g: JavaComplete_ProjectKey
41
41
42
- call s: Log (path )
43
42
if filereadable (path )
44
43
if a: force == 0 && getftime (path ) >= getftime (g: JavaComplete_AntPath )
45
44
call s: Log (" get libs from cache file" )
@@ -48,33 +47,109 @@ function! javacomplete#classpath#ant#Generate(force) abort
48
47
call javacomplete#util#RemoveFile (javacomplete#util#GetBase (' cache' ). g: FILE_SEP . ' class_packages_' . g: JavaComplete_ProjectKey . ' .dat' )
49
48
endif
50
49
51
- let hasInitTarget = ! empty (system (" ant -projecthelp -v | grep '^ init\\ >'" ))
52
- let tmpFile = []
50
+ let s: antPath = path
51
+ let s: antOutput = []
52
+ let cmd = " ant -projecthelp -v | grep '^ init\\ >'"
53
+ call javacomplete#util#RunSystem (
54
+ \ cmd, " ant check 'init' target process" ,
55
+ \ " javacomplete#classpath#ant#CheckInitTargetHandler" )
56
+ return ' .'
57
+ endfunction
58
+
59
+ function ! javacomplete#classpath#ant#CheckInitTargetHandler (data, event )
60
+ if a: event == ' exit'
61
+ if a: data == " 0"
62
+ let hasInitTarget = ! empty (s: antOutput )
63
+ let s: antOutput = []
64
+ call s: BuildAntClasspath (hasInitTarget)
65
+ else
66
+ echohl WarningMsg | echomsg " Failed to check 'init' target" | echohl None
67
+ endif
68
+ elseif a: event == ' stdout'
69
+ for data in filter (a: data ,' v:val =~ "^ init\\>.*$"' )
70
+ if g: JavaComplete_ShowExternalCommandsOutput
71
+ echomsg data
72
+ endif
73
+ if exists (' s:antOutput' )
74
+ call add (s: antOutput , data)
75
+ endif
76
+ endfor
77
+ elseif a: event == ' stderr'
78
+ for data in filter (a: data ,' v:val !~ "^\\s*$"' )
79
+ echoerr data
80
+ endfor
81
+ endif
82
+ endfunction
83
+
84
+ function ! s: BuildAntClasspath (hasInitTarget)
85
+ let tmpBuildFile = []
53
86
for line in readfile (g: JavaComplete_AntPath )
54
87
if stridx (line , ' </project>' ) >= 0
55
- if hasInitTarget
88
+ if a: hasInitTarget
56
89
let xmlTemplate = s: antXmlTemplate
57
90
let xmlTemplate[0 ] = xmlTemplate[0 ][:-2 ]. ' depends="init">'
58
- call extend (tmpFile , xmlTemplate)
91
+ call extend (tmpBuildFile , xmlTemplate)
59
92
else
60
- call extend (tmpFile , s: antXmlTemplate )
93
+ call extend (tmpBuildFile , s: antXmlTemplate )
61
94
endif
62
95
endif
63
- call add (tmpFile, line )
64
- endfor
65
- let s: temporaryAntFile = " vjc-ant-build.xml"
66
- call writefile (tmpFile, s: temporaryAntFile )
67
-
68
- let antCmd = [' ant' , ' -f' , s: temporaryAntFile , ' -q' , ' vjc-printclasspath' ]
69
- call delete (s: temporaryAntFile )
70
- let result = system (join (antCmd, " " ))
71
- for line in split (result, ' \n' )
72
- let matches = matchlist (line , ' \m^\s\+\[echo\]\s\+\(.*\)' )
73
- if ! empty (matches)
74
- return matches[1 ]
75
- endif
96
+ call add (tmpBuildFile, line )
76
97
endfor
77
- return ' .'
98
+ let s: tmpAntFileName = " vjc-ant-build.xml"
99
+ call writefile (tmpBuildFile, s: tmpAntFileName )
100
+
101
+ let s: antOutput = []
102
+ let antCmd = [' ant' , ' -f' , s: tmpAntFileName , ' -q' , ' vjc-printclasspath' ]
103
+ call javacomplete#util#RunSystem (
104
+ \ antCmd, " ant classpath build process" ,
105
+ \ " javacomplete#classpath#ant#BuildClasspathHandler" )
78
106
endfunction
79
107
108
+ function ! javacomplete#classpath#ant#BuildClasspathHandler (data, event )
109
+ if a: event == ' exit'
110
+ if a: data == " 0"
111
+ for line in s: antOutput
112
+ let matches = matchlist (line , ' \m^\s\+\[echo\]\s\+\(.*\)' )
113
+ if ! empty (matches)
114
+ let cp = matches[1 ]
115
+ break
116
+ endif
117
+ endfor
118
+ if cp != ' .'
119
+ call writefile ([cp ], s: antPath )
120
+ endif
121
+
122
+ let g: JavaComplete_LibsPath .= ' :' . cp
123
+
124
+ call javacomplete#util#RemoveFile (javacomplete#util#GetBase (' cache' ). g: FILE_SEP . ' class_packages_' . g: JavaComplete_ProjectKey . ' .dat' )
125
+
126
+ call javacomplete#server#UnblockStart ()
127
+ call javacomplete#server#Terminate ()
128
+ call javacomplete#server#Start ()
129
+
130
+ echomsg " Ant classpath built successfully"
131
+ else
132
+ echohl WarningMsg | echomsg " Failed to build ant classpath" | echohl None
133
+ endif
134
+
135
+ call delete (s: tmpAntFileName )
136
+
137
+ unlet s: antOutput
138
+ unlet s: tmpAntFileName
139
+
140
+ elseif a: event == ' stdout'
141
+ for data in filter (a: data ,' v:val !~ "^\\s*$"' )
142
+ if g: JavaComplete_ShowExternalCommandsOutput
143
+ echomsg data
144
+ endif
145
+ endfor
146
+ if exists (' s:antOutput' )
147
+ call extend (s: antOutput , a: data )
148
+ endif
149
+ elseif a: event == ' stderr'
150
+ for data in filter (a: data ,' v:val !~ "^\\s*$"' )
151
+ echoerr data
152
+ endfor
153
+ endif
154
+ endfunction
80
155
" vim:set fdm = marker sw = 2 nowrap :
0 commit comments