<?xml version='1.0' encoding='ISO-8859-1' ?>
<!--
  The contents of this file are subject to the terms of the Common Development
  and Distribution License (the License). You may not use this file except in
  compliance with the License.

  You can obtain a copy of the License at http://www.netbeans.org/cddl.html
  or http://www.netbeans.org/cddl.txt.

  When distributing Covered Code, include this CDDL Header Notice in each file
  and include the License file at http://www.netbeans.org/cddl.txt.
  If applicable, add the following below the CDDL Header, with the fields
  enclosed by brackets [] replaced by your own identifying information:
  "Portions Copyrighted [year] [name of copyright owner]"

  The Original Software is NetBeans. The Initial Developer of the Original
  Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
  Microsystems, Inc. All Rights Reserved.
-->
<project name="firststart" default="firststart" basedir=".">
  <import file="default-properties.xml"/>

  <!-- Arguments for first start of IDE, should not be changed for now -->
  <property name="firststart.args.additional" value=""/>
  <property name="args_en" value=" -J-Dnetbeans.close=true -J-Dnetbeans.debug.exceptions=true"/>
  <property name="firststart.args" value="${args_en} ${firststart.args.additional}"/>

  <target name="firststart" unless="nofirststart">
    <echo>BUILDRESULTS_TYPE=firststart</echo>
    <echo>Starting the IDE with locale ${locale} ...</echo>
    <echo>(This both acts as a test, and primes some files</echo>
    <echo>to make the first user start faster and better.)</echo>
    <mkdir dir="${test.user.dir}"/>
    <!-- XXX should perhaps preset JAVA_PATH to ${java.home} or something? -->
    <!-- XXX better would be to scan first start log for stacktraces and just show those; -->
    <!-- possibly after filtering for duplicates or something like this. -->
    <exec os="Windows NT Windows 95 Windows 98 Windows 2000 Windows XP"
          dir="${start.dir}/bin"
          executable="${start.dir}/bin/nb.exe"
          failonerror="true"
          timeout="600000">
          <arg line="${firststart.args} -userdir ${test.user.dir}"/>
    </exec>
    <exec os="Linux SunOS Solaris"
          dir="${start.dir}/bin"
          executable="sh"
          failonerror="true"
          timeout="600000">
          <arg line="netbeans ${firststart.args} -userdir ${test.user.dir}"/>
    </exec>

    <echo message="Successfully started, cleaning up detritus..."/>
    <move file="${test.user.dir}/var/log/messages.log" 
          tofile="${dist.dir}/ide-start-${branchname}-${buildnumber}.log"
          failonerror="false"/>

    <delete dir="${test.user.dir}"/>
    <delete file="${start.dir}/platform5/system/serial.dat"/>

    <loadfile srcFile="${dist.dir}/ide-start-${branchname}-${buildnumber}.log" property="firststart.error.txt"/>
    <condition property="firststart.error">
      <or>
        <contains string="${firststart.error.txt}" substring="exception occurred" casesensitive="false"/>
        <contains string="${firststart.error.txt}" substring="stack trace" casesensitive="false"/>
        <contains string="${firststart.error.txt}" substring="Exception" casesensitive="true"/>
      </or>
    </condition>
    <fail message="Firststart had errors.  review ${dist.dir}/ide-start-${branchname}-${buildnumber}.log" if="firststart.error"/>
  </target>
</project>
