|
| 1 | +let s:antXmlTemplate = [ |
| 2 | + \ ' <target name="vjc-test-conditions">', |
| 3 | + \ ' <condition property="vjc-netbeans-condition">', |
| 4 | + \ ' <isset property="javac.classpath" />', |
| 5 | + \ ' </condition>', |
| 6 | + \ ' <condition property="vjc-project-condition">', |
| 7 | + \ ' <isreference refid="project.classpath"/>', |
| 8 | + \ ' </condition>', |
| 9 | + \ ' </target>', |
| 10 | + \ ' <target name="vjc-netbeans-classpath" depends="vjc-test-conditions" if="vjc-netbeans-condition">', |
| 11 | + \ ' <property name="javavi.classpath" value="${javac.classpath}" />', |
| 12 | + \ ' </target>', |
| 13 | + \ ' <target name="vjc-project-classpath" depends="vjc-test-conditions" if="vjc-project-condition">', |
| 14 | + \ ' <property name="javavi.classpath" refid="project.classpath"/>', |
| 15 | + \ ' </target>', |
| 16 | + \ ' <target name="vjc-printclasspath" depends="vjc-project-classpath,vjc-netbeans-classpath">', |
| 17 | + \ ' <echo message="${javavi.classpath}"/>', |
| 18 | + \ ' </target>'] |
| 19 | + |
| 20 | +function! s:Log(log) |
| 21 | + let log = type(a:log) == type("") ? a:log : string(a:log) |
| 22 | + call javacomplete#logger#Log("[classpath.ant] ". log) |
| 23 | +endfunction |
| 24 | + |
| 25 | +function! javacomplete#classpath#ant#IfAnt() |
| 26 | + if executable('ant') && g:JavaComplete_AntPath != "" |
| 27 | + return 1 |
| 28 | + endif |
| 29 | + return 0 |
| 30 | +endfunction |
| 31 | + |
| 32 | +function! javacomplete#classpath#ant#Generate(force) abort |
| 33 | + let g:JavaComplete_ProjectKey = substitute(g:JavaComplete_AntPath, '[\\/:;.]', '_', 'g') |
| 34 | + let path = javacomplete#util#GetBase("classpath". g:FILE_SEP). g:JavaComplete_ProjectKey |
| 35 | + |
| 36 | + call s:Log(path) |
| 37 | + if filereadable(path) |
| 38 | + if a:force == 0 && getftime(path) >= getftime(g:JavaComplete_AntPath) |
| 39 | + call s:Log("get libs from cache file") |
| 40 | + return join(readfile(path), '') |
| 41 | + endif |
| 42 | + call javacomplete#util#RemoveFile(javacomplete#util#GetBase('cache'). g:FILE_SEP. 'class_packages_'. g:JavaComplete_ProjectKey. '.dat') |
| 43 | + endif |
| 44 | + |
| 45 | + let hasInitTarget = !empty(system("ant -projecthelp -v | grep '^ init\\>'")) |
| 46 | + let tmpFile = [] |
| 47 | + for line in readfile(g:JavaComplete_AntPath) |
| 48 | + if stridx(line, '</project>') >= 0 |
| 49 | + if hasInitTarget |
| 50 | + let xmlTemplate = s:antXmlTemplate |
| 51 | + let xmlTemplate[0] = xmlTemplate[0][:-2]. ' depends="init">' |
| 52 | + call extend(tmpFile, xmlTemplate) |
| 53 | + else |
| 54 | + call extend(tmpFile, s:antXmlTemplate) |
| 55 | + endif |
| 56 | + endif |
| 57 | + call add(tmpFile, line) |
| 58 | + endfor |
| 59 | + let s:temporaryAntFile = "vjc-ant-build.xml" |
| 60 | + call writefile(tmpFile, s:temporaryAntFile) |
| 61 | + |
| 62 | + let antCmd = ['ant', '-f', s:temporaryAntFile, '-q', 'vjc-printclasspath'] |
| 63 | + call delete(s:temporaryAntFile) |
| 64 | + let result = system(join(antCmd, " ")) |
| 65 | + for line in split(result, '\n') |
| 66 | + let matches = matchlist(line, '\m^\s\+\[echo\]\s\+\(.*\)') |
| 67 | + if !empty(matches) |
| 68 | + return matches[1] |
| 69 | + endif |
| 70 | + endfor |
| 71 | + return '.' |
| 72 | +endfunction |
| 73 | + |
| 74 | +" vim:set fdm=marker sw=2 nowrap: |
0 commit comments