ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Svetlin Stanchev" <stanc...@360t.com>
Subject RE: Using JBuilder9 settings (e.g. libraries, paths) in Ant
Date Wed, 27 Aug 2003 12:16:53 GMT
> [...] I need to use the classpath used by
> JBuilder when it compiled the project.

I was in the same situation, but -- with an earlier version of JBuilder.

> So far, I've tried the ant script from an earlier discussion,
> http://marc.theaimsgroup.com/?l=ant-user&m=105912755106595&w=2
> but I haven't been able to get it to generate anything. 

If you are willing to go this way, I am attaching below my script(s)
with explanation. It is also based on the first Jan's version.
 
> Another solution might be to call the Ant buildfile and
> import a property/path id back to the calling Ant task - is 
> this possible? I also consider building a task that extracts 
> the data I need from the XML in the autogenerated build.xml file.

I think I would prefer this approach had I been in your situation
(having the build file generated by JBuilder) -- as Dominique and Jan
advise you.

Nevertheless, here are my circumstances. We have a number of projects
divided into project groups. One of the projects (its .jpx file) in the
group contains nothing but common settings for other projects, including
shared libraries. The libraries themselves are described in .library
files one level up in the file hierarchy. All these files are stored in
CVS. The script checks out a (project group's) .jpx file from CVS (the
.library files should also be checked out along with libraries
themselves), processes its libs in a number of steps each time producing
a temp file, finally constructs a compile classpath and stores it in a
XML file in the directory of the project. The script depends on settings
in a number of other configuration files. An important point is that our
projects are interdependent, but we include in the compile class path
the .jar (and not /classes) of the project on which the current one is
depending. The script needs to be called with the name and group of the
project being set.

The additional target do-cvs-checkout-to-dir is needed because the Linux
CVS client is broken and cannot checkout to more than one subdirectory
(with a different than the CVS module name).

If you have more questions, please feel free to ask :-)!
--
Svetlin



--------------------------extract-libpaths.xml------------------------
<?xml version="1.0" encoding="ISO-8859-1"?>
<project name="extract-libpaths" default="getProjectLibs" basedir=".">

  <target name="init">
    <!-- Load environment settings -->
    <property environment="env"/>
    <property name="build.root" location="${env.BUILD_ROOT}"/>
    <!-- Load mountpoints -->
    <property file="${build.root}/mountpoint.properties"/>
    <!-- Load global properties -->
    <property file="${build.root}/build.properties"/>
    <!-- Load cvs description -->
    <property file="${build.root}/cvs.properties"/>
    <taskdef resource="net/sf/antcontrib/antcontrib.properties"/>
    <taskdef name="xmltask" 
      classname="com.oopsconsultancy.xmltask.ant.XmlTask"/>
    <!-- convert Win paths to mountpoints into regexp-compliant ones -->
    <path id="temp-mountpointprojects">
      <pathelement location="${mountpoint.projects}"/>
    </path>
    <pathconvert 
      dirsep="/" 
      property="regexp-compliant.mountpointprojects"
      refid="temp-mountpointprojects"/>
    <path id="temp-mountpointlibs">
      <pathelement location="${mountpoint.libs}"/>
    </path>
    <pathconvert 
      dirsep="/" 
      property="regexp-compliant.mountpointlibs"
      refid="temp-mountpointlibs"/>
    <!-- Temp files -->
    <property name="tmp" 
      value="${mountpoint.projects}/${project.name}/tmp.xml"/>
    <property name="tmp1" 
      value="${mountpoint.projects}/${project.name}/tmp1.xml"/>
    <property name="tmp2" 
      value="${mountpoint.projects}/${project.name}/tmp2.xml"/>
    <property name="tmp3" 
      value="${mountpoint.projects}/${project.name}/tmp3.xml"/>
  </target>

  <target name="checkoutProjectConfig"
    depends="init"
    description="Checks out the JBuilder group config files">
    <propertycopy name="libConfig" 
      from="${project.group}.cvs.libconfig.file"/>
    <ant dir="${build.root}" antfile="build.xml"
target="do-cvs-checkout-to-dir">
      <property name="cvs-dest-dir"
value="${mountpoint.projects}/${project.name}/${project.group}"/>
      <property name="cvs-package" value="${libConfig}"/>
      <property name="recurse" value="-l"/>
    </ant>
  </target>

  <target name="getProjectLibs" 
    depends="init, checkoutProjectConfig"
    description="Create a classpath from JBuilder project file">

    <!-- JBuilder file to analyze -->
    <property name="projectLibs.file" 
 
value="${mountpoint.projects}/${project.name}/${project.group}/${project
.group}.jpx"/>

    <!-- get the Libraries entry from JBuilder .jpx -->
    <xmltask source="${projectLibs.file}">
      <copy path="/project/property[@category='sys'][@name='Libraries']"
	buffer="usedlibs"/>
    </xmltask>

    <!-- store it into own file -->
    <xmltask dest="${tmp}">
      <insert path="/" buffer="usedlibs"/>
    </xmltask>

    <!-- load used libs from temp as a sequence of ant properties -->
    <xmlproperty file="${tmp}" />

    <!-- iterate over used library files 
    and extract their classpath into a libs.classpath buffer -->
    <foreach target="processLibFile" 
      param="libfile" 
      list="${property(value)}" 
      delimiter=";"/>

    <!-- store the libs.classpath result in a new temp xml file -->
    <xmltask dest="${tmp1}">
      <insert path="/"><![CDATA[ <root/> ]]></insert>
      <insert path="/root" buffer="${project.name}.libs.classpath"/>
    </xmltask>

    <copy file="${tmp1}" tofile="${tmp2}"/>
    <replace file="${tmp2}">
      <replacefilter token="\" value="/"/>
    </replace>

    <!-- redirect location of internal projects -->
    <replaceregexp file="${tmp2}"
      match="../(.*)/(.*)/Implementation/java/classes"
      replace="${regexp-compliant.mountpointprojects}/\2/dist/\2.jar"
      flags="g"/>

    <copy file="${tmp2}" tofile="${tmp3}"/>
    <!-- redirect location of external projects, remove garbage -->
    <replace file="${tmp3}">
      <replacefilter token="&lt;path&gt;" />
      <replacefilter token="[" 
	value="${regexp-compliant.mountpointlibs}/"/>
      <replacefilter token="]"/>
      <replacefilter token="&lt;/path&gt;" value=";"/>
      <replacefilter token="${line.separator}"/>
    </replace>

    <!-- read the  valid paths into a property from tmp file -->
    <loadfile property="libpaths" srcFile="${tmp3}"/>

    <!-- remove the <root> tag for a valid path -->
    <propertyregex property="pathvalue" 
      input="${libpaths}" 
      regexp="&lt;root&gt;(.*)&lt;/root&gt;" 
      select="\1"/>

    <!-- create the xml file with the compile path -->
    <xmltask dest="${mountpoint.projects}/${project.name}/project.xml">
      <insert path="/">
	<![CDATA[
	<path id="${project.name}.compile.classpath">
	<pathelement path="${pathvalue}"/>
      </path>
	]]>
      </insert>
    </xmltask>
  </target>

  <!-- Extract the classpath from one library file -->
  <target name="processLibFile" 
    depends="init"
    if="libfile">
    <xmltask source="${mountpoint.libs}/${libfile}.library">
      <copy path="/library/class/path" 
	buffer="${project.name}.libs.classpath"
	append="true"/>
    </xmltask>
  </target>

</project>
------------------------End-extract-libpaths.xml------------------------

------------------------cvs.properties----------------------------------
# Fixed build hierarchy modules 
# These modules need be defined in CVSROOT/modules!
cvs.libs.dir=JbuilderLibraries
<!-- ... -->

# Group modules
3rdParty.cvs.dir=3rdParty
<!-- ... -->

# Group lib config
3rdParty.cvs.libconfig.file=${3rdParty.cvs.dir}/3rdParty.jpx
<!-- ... -->
-----------------------End-cvs.properties-------------------------------

-----------------------mountpoint.properties----------------------------
# Logical Names of independent mountable structures ########
# If you want to use another set of libs/projects etc, then 
# better change the mountpoints below.

masterbuild.dir=masterbuild
libs.dir=libs
projects.dir=projects
<!-- ... -->

# Mountpoints: #############################################

# build.root is given by env, the global build resides there
# masterbuild is where the masterbuild resided
mountpoint.masterbuild=${build.root}/${masterbuild.dir}

# libs contains the libraries shared between all projects
mountpoint.libs=${build.root}/${libs.dir}

# individual projects reside here
mountpoint.projects=${mountpoint.masterbuild}/${projects.dir}
<!-- ... -->
-----------------------End-mountpoint.properties-----------------------

-----------------------checking-out-to-dir-----------------------------
  <target name="do-cvs-checkout-to-dir" 
    depends="setrootproperties"
    description="Wrapper for the cvs checkout to dir (-d) command">
    <dirname property="cvs-dirname" file="${cvs-dest-dir}"/>
    <basename property="cvs-basename" file="${cvs-dest-dir}"/>
    <echo message="Checkout module: ${cvs-package}"/>
    <echo message="             to: ${cvs-dest-dir}"/>
    <exec executable="cvs" dir="${cvs-dirname}">
      <arg value="${cvs.info.mode}"/>
      <arg value="-d${CVSROOT}"/>
      <arg value="checkout"/>
      <arg value="-d${cvs-basename}"/>
      <arg value="${recurse}"/>
      <arg value="${cvs-package}"/>
    </exec>
    <echo message="Done."/>
  </target>
--------------------End-checking-out-to-dir---------------------------


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Mime
View raw message