1<?xml version="1.0" encoding="UTF-8"?>
2<!--
3
4    Licensed to the Apache Software Foundation (ASF) under one
5    or more contributor license agreements.  See the NOTICE file
6    distributed with this work for additional information
7    regarding copyright ownership.  The ASF licenses this file
8    to you under the Apache License, Version 2.0 (the
9    "License"); you may not use this file except in compliance
10    with the License.  You may obtain a copy of the License at
11
12      http://www.apache.org/licenses/LICENSE-2.0
13
14    Unless required by applicable law or agreed to in writing,
15    software distributed under the License is distributed on an
16    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17    KIND, either express or implied.  See the License for the
18    specific language governing permissions and limitations
19    under the License.
20
21-->
22<project name="run" basedir=".">
23
24    <target name="-init">
25        <property name="run.jdkhome" location="${nbjdk.home}"/>
26        <condition property="test.user.dir" value="${suite.build.dir}/testuserdir" else="${build.dir}/testuserdir">
27            <isset property="suite.build.dir"/>
28        </condition>
29        <property name="suite.dir" location="${basedir}"/>
30        <property name="run.args.common" value='--userdir "${test.user.dir}" -J-Dnetbeans.logger.console=true -J-ea'/>
31        <!-- In case run from a suite module, to get app.name and/or branding.token: -->
32        <property file="${suite.dir}/nbproject/private/platform-private.properties"/>
33        <property file="${suite.dir}/nbproject/platform.properties"/>
34        <property file="${suite.dir}/nbproject/private/private.properties"/>
35        <property file="${suite.dir}/nbproject/project.properties"/>
36        <!-- CP with id="cluster.path.id" is expected to be passed as parameter to run.xml -->
37        <pathconvert property="install">
38            <path refid="cluster.path.id"/>
39            <regexpmapper from="(.*[/\\])platform[0-9]*$$" to="\1"/>
40        </pathconvert>
41
42        <!-- clear modulename_hidden files from external clusters so they do not influence the availability of
43              modules selected by the current cluster -->
44        <!-- We'll clear only clusters under 'build' folder to avoid deleting
45             files in binary platform/clusters (e.g. user hacks), while
46             un-hiding modules hidden by depended-upon suites. Cf. issue #172727 -->
47        <pathconvert property="cluster.path.projects" refid="cluster.path.id">
48            <regexpmapper handledirsep="true" from="^.*/build/[^/]+$$" to="\0"/>
49        </pathconvert>
50        <delete>
51            <pathfileset include="config/Modules/*_hidden">
52                <path path="${cluster.path.projects}"/>
53            </pathfileset>
54        </delete>
55
56        <!-- architecture of jvm on which app will run -->
57        <condition property="jvm.arch.string" value="64" else="">
58            <available file="${run.jdkhome}\jre\lib\amd64" />
59        </condition>
60
61        <!-- use nb.exe if exists (old platform), netbeans.exe otherwise -->
62        <condition property="run.app.exe" value="bin\nb.exe" else="bin\netbeans${jvm.arch.string}.exe">
63            <available file="${install}\bin\nb.exe"/>
64        </condition>
65        <property name="run.app.sh" value="bin/netbeans"/>
66        <property name="run.exe.candidate" location="${install}\${run.app.exe}"/>
67        <property name="run.sh.candidate" location="${install}/${run.app.sh}"/>
68         <!-- #63976: if disabling things, better to treat as a platform-based app -->
69        <condition property="app.name" value="test">
70            <or>
71                <and>
72                    <isset property="disabled.modules"/>
73                    <length string="${disabled.modules}" when="greater" length="0"/>
74                </and>
75                <and>
76                    <isset property="enabled.clusters"/>
77                    <length string="${enabled.clusters}" when="greater" length="0"/>
78                </and>
79                <and>
80                    <isset property="disabled.clusters"/>
81                    <length string="${disabled.clusters}" when="greater" length="0"/>
82                </and>
83                <!-- #66793: also treat as a platform-based app if using platform and have no branding -->
84                <not>
85                    <or>
86                        <available file="${run.exe.candidate}"/>
87                        <available file="${run.sh.candidate}"/>
88                    </or>
89                </not>
90            </or>
91        </condition>
92    </target>
93
94    <target name="-prepare-as-app" depends="-init" unless="app.name">
95        <property name="run.exe" location="${run.exe.candidate}"/>
96        <property name="run.sh" location="${run.sh.candidate}"/>
97        <mkdir dir="${test.user.dir}/etc"/>
98        <pathconvert property="run.extra.clusters">
99            <path>
100                <pathelement location="${cluster}"/>
101                <path refid="cluster.path.id"/>
102            </path>
103            <!-- Exclude all clusters located in NB install dir;
104                 not exactly what netbeans.clusters specify, but good enough -->
105            <filtermapper>
106                <linecontains negate="true">
107                    <contains value="${install}"/>
108                </linecontains>
109            </filtermapper>
110        </pathconvert>
111        <echo file="${test.user.dir}/etc/netbeans.conf">netbeans_extraclusters="${run.extra.clusters}"</echo>
112        <property name="run.args.prepared" value=''/>
113    </target>
114
115    <target name="-prepare-as-platform" depends="-init" if="app.name">
116        <property name="disabled.modules" value=""/>
117        <fail message="Platform cluster is not present in cluster.path: '${cluster.path.final}'">
118            <condition>
119                <not>
120                    <matches string="${cluster.path.final}" pattern="[\\/]platform[0-9]*([;:]|$)"/>
121                </not>
122            </condition>
123        </fail>
124        <pathconvert property="run.platform.clusters">
125            <path>
126                <pathelement location="${cluster}"/>
127                <!-- Does not exclude clusters in which all modules are excluded, shouldn't be a problem -->
128                <path refid="cluster.path.id"/>
129            </path>
130        </pathconvert>
131        <pathconvert property="run.exe">
132            <path>
133                <fileset dir="${install}" includes="platform*/lib/nbexec${jvm.arch.string}.exe"/>
134            </path>
135        </pathconvert>
136        <pathconvert property="run.sh">
137            <path>
138                <fileset dir="${install}" includes="platform*/lib/nbexec"/>
139            </path>
140        </pathconvert>
141        <property name="branding.token" value="-"/> <!-- fallback value if not set -->
142        <property name="run.args.prepared" value='--branding ${branding.token} --clusters "${run.platform.clusters}"'/>
143    </target>
144
145    <target name="run" depends="-prepare-as-app,-prepare-as-platform">
146        <touch file="${cluster}/.lastModified"/> <!-- #138427 -->
147        <property name="run.args" value=""/>
148        <property name="run.args.ide" value=""/>
149        <property name="run.args.extra" value=""/>
150        <condition property="run.args.mac" value="-J-Xdock:name='${app.name}'" else="">
151            <os family="mac"/>
152        </condition>
153        <exec osfamily="windows" executable="${run.exe}" failonerror="no">
154            <arg value="--jdkhome"/>
155            <arg file="${run.jdkhome}"/>
156            <arg line="${run.args.common}"/>
157            <arg line="${run.args.prepared}"/>
158            <arg line="${run.args}"/>
159            <arg line="${run.args.extra}"/>
160            <arg line="${run.args.ide}"/>
161        </exec>
162        <exec osfamily="unix" dir="." executable="sh" failonerror="no">
163            <arg value="${run.sh}"/>
164            <arg value="--jdkhome"/>
165            <arg file="${run.jdkhome}"/>
166            <arg line="${run.args.common}"/>
167            <arg line="${run.args.prepared}"/>
168            <arg line="${run.args}"/>
169            <arg line="${run.args.extra}"/>
170            <arg line="${run.args.mac}"/>
171            <arg line="${run.args.ide}"/>
172        </exec>
173    </target>
174
175
176    <target name="debug">
177        <fail unless="netbeans.home">This target only works when run from inside the NetBeans IDE.</fail>
178        <nbjpdastart name="NetBeans" addressproperty="debug.port" transport="dt_socket">
179            <classpath>
180                <pathfileset include="**/*.jar">
181                    <path refid="cluster.path.id"/>
182                </pathfileset>
183                <fileset dir="${cluster}">
184                    <include name="**/*.jar"/>
185                </fileset>
186            </classpath>
187        </nbjpdastart>
188        <property name="debug.pause" value="y"/>
189        <property name="debug.args" value="-J-agentlib:jdwp=transport=dt_socket,suspend=${debug.pause},server=n,address=${debug.port}"/>
190        <antcall target="run">
191            <param name="run.args" value="${debug.args}"/>
192            <reference refid="cluster.path.id"/>
193        </antcall>
194    </target>
195
196    <target name="-profile-check" if="netbeans.home">
197        <condition property="profiler.configured">
198            <or>
199                <contains string="${run.args.ide}" substring="-agentpath:" casesensitive="true"/>
200                <contains string="${run.args.ide}" substring="-javaagent:" casesensitive="true"/>
201            </or>
202        </condition>
203    </target>
204
205    <target name="profile" depends="-profile-check,-profile-pre72" if="profiler.configured" unless="profiler.info.jvmargs.agent" description="Profile a project in the IDE.">
206        <startprofiler/>
207        <antcall target="run">
208            <reference refid="cluster.path.id"/>
209        </antcall>
210    </target>
211
212    <target name="-profile-pre72" description="Profile a project in the IDE." if="profiler.info.jvmargs.agent">
213        <fail unless="netbeans.home">This target only works when run from inside the NetBeans IDE.</fail>
214        <nbprofiledirect
215            jvmargsprefix="-J"
216            jvmargsproperty="profiler.jvmargs"
217            mainclass="org.netbeans.Main"
218        >
219            <classpath>
220                <pathfileset include="**/*.jar">
221                    <path refid="cluster.path.id"/>
222                </pathfileset>
223                <fileset dir="${cluster}">
224                    <include name="**/*.jar"/>
225                </fileset>
226            </classpath>
227            <rootspath>
228                <fileset dir="${cluster}">
229                    <include name="**/*.jar"/>
230                </fileset>
231            </rootspath>
232        </nbprofiledirect>
233
234        <antcall target="run">
235            <param name="run.args" value='"${profiler.jvmargs}"'/>
236            <reference refid="cluster.path.id"/>
237        </antcall>
238    </target>
239</project>
240