1/*
2   Licensed to the Apache Software Foundation (ASF) under one or more
3   contributor license agreements.  See the NOTICE file distributed with
4   this work for additional information regarding copyright ownership.
5   The ASF licenses this file to You under the Apache License, Version 2.0
6   (the "License"); you may not use this file except in compliance with
7   the License.  You may obtain a copy of the License at
8
9       http://www.apache.org/licenses/LICENSE-2.0
10
11   Unless required by applicable law or agreed to in writing, software
12   distributed under the License is distributed on an "AS IS" BASIS,
13   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   See the License for the specific language governing permissions and
15   limitations under the License.
16
17    Run ant
18*/
19
20'@echo off'
21parse arg mode envarg '::' antarg
22
23if mode\='.' & mode\='..' & mode\='/' then do
24  envarg = mode envarg
25  mode = ''
26end
27
28if antarg = '' then do
29  antarg = envarg
30  envarg = ''
31end
32
33x = setlocal()
34
35env="OS2ENVIRONMENT"
36antenv = _getenv_('antenv')
37if _testenv_() = 0 then interpret 'call "' || antenv || '"' '"' || envarg || '"'
38
39if mode = '' then mode = _getenv_('ANT_MODE' '..')
40if mode \= '/' then do
41  runrc = _getenv_('runrc')
42  antrc = _getenv_('antrc' 'antrc.cmd')
43  if mode = '..' then mode = '-r'
44  else mode = ''
45  interpret 'call "' || runrc || '"' antrc '"' || mode || '"'
46end
47
48if _testenv_() = 0 then do
49  say 'Ant environment is not set properly'
50  x = endlocal()
51  exit 16
52end
53
54settings = '-Dant.home=' || ANT_HOME '-Djava.home=' || JAVA_HOME
55
56java = _getenv_('javacmd' 'java')
57opts = value('ANT_OPTS',,env)
58args = value('ANT_ARGS',,env)
59lcp = value('LOCALCLASSPATH',,env)
60cp = value('CLASSPATH',,env)
61if value('ANT_USE_CP',,env) \= '' then do
62  if lcp \= '' & right(lcp, 1) \= ';' then lcp = lcp || ';'
63  lcp = lcp || cp
64  'SET CLASSPATH='
65end
66if lcp\='' then lcp = '-classpath' lcp
67
68cmd = java opts lcp '-jar' ANT_HOME ||'\lib\ant-launcher.jar' settings args antarg
69launcher = stream(ANT_HOME ||'\lib\ant-launcher.jar', 'C', 'query exists')
70if launcher = '' then entry = 'org.apache.tools.ant.Main'
71else entry = 'org.apache.tools.ant.launch.Launcher'
72java opts lcp entry settings args antarg
73
74x = endlocal()
75
76return rc
77
78_testenv_: procedure expose env ANT_HOME JAVA_HOME
79ANT_HOME = value('ANT_HOME',,env)
80if ANT_HOME = '' then return 0
81JAVA_HOME = value('JAVA_HOME',,env)
82if JAVA_HOME = '' then return 0
83cp = translate(value('CLASSPATH',,env))
84if pos(translate(ANT_HOME), cp) = 0 then return 0
85if pos(translate(JAVA_HOME), cp) = 0 then return 0
86return 1
87
88_getenv_: procedure expose env
89parse arg envar default
90if default = '' then default = envar
91var = value(translate(envar),,env)
92if var = '' then var = default
93return var
94