Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running P2 Ant tasks outside Eclipse

Tags:

eclipse

ant

p2

I got ant script running fine inside Eclipse Here is a piece of it :

<p2.composite.repository failOnExists="true">
            <repository location="file:/${basedir}/compRepo" name="Repository description goes here" />
            <add>
                <repository location="http://url/Eclipse/repo/Galileo-3.5.1/" />
                <repository location="http://another-url/Java/repo/4.0/" />
                <repository location="${diag.location}" />
            </add>
        </p2.composite.repository>

But I would like Hudson CI server to be able to run it, but, no matter all the jars I put in ANT_HOME/lib I can't get this task to run in a simple command line ant... I got stuck with this error :

C:\workspaces\workspace\project\junit.script\createCompRepo.xml:10: Problem: failed to create task or type p2.composite.repository
Cause: The name is undefined.
Action: Check the spelling.
Action: Check that any custom tasks/types have been declared.
Action: Check that any <presetdef>/<macrodef> declarations have taken place.

Where are defined the p2 ant tasks ? Is there a way to run them outside Eclipse ? Thank you very much for you help ! Anthony

like image 372
Anthony Dahanne Avatar asked Feb 24 '10 15:02

Anthony Dahanne


1 Answers

Just to complete the example of Jarek Przygódzki here is my solution, using his ant-file. I'm not well versed in using ant, so there might be potential for optimisation. This aproach is used headless on a server without GUI, nevertheless I had to install eclipse. Installation with apt-get wasn't working, so it's better to install manual (download and untar).

  1. First antfile assembles names, versions, etc...
  2. Second antfile is called from first antfile and creates composite repositories.

First antfile:

<project name="project">

<!-- ....do some other stuff...-->

<target name="p2.composite.add">

<!--Call macro for child repo-->
 <antRunner
    name="${site.composite.name}"
    location="${composite.repository.directory}"
    child="${child.repository}"
/>  

<!--Call macro for main repo-->
<antRunner
    name="${main.site.composite.name}"
    location="${main.composite.repository.directory}"
    child="${majorMinorVersion}"
/> 

</target>

<!--Eclipse installation path-->
<path id="equinox.launcher.path">
    <fileset dir="/usr/share/eclipse/plugins">
        <include name="org.eclipse.equinox.launcher_1.3.201.v20161025-1711.jar" />
    </fileset>
</path>

<macrodef name="antRunner">

    <attribute name="name"/>    
    <attribute name="location"/>
    <attribute name="child"/>

    <sequential>

        <java 
            classname="org.eclipse.equinox.launcher.Main" 
            fork="true" 
            failonerror="true">

            <arg line="-application org.eclipse.ant.core.antRunner" />
            <arg line="-f addCompositeInternal.ant run" />
            <arg line="-Dcomposite.name=@{name}"/>
            <arg line="-Dcomposite.location=@{location}"/>
            <arg line="-Dcomposite.child=@{child}"/>
            <classpath refid="equinox.launcher.path" />
        </java> 
    </sequential>
</macrodef>

</project>   

Second Antfile, named addCompositeInternal.ant

<project name="composite">
<target name="run">
            <add.composite.repository.internal
                composite.repository.location="${composite.location}"
                composite.repository.name="${composite.name}"
                composite.repository.child="${composite.child}"
            />
</target>      

<!-- = = = = = = = = = = = = = = = = =
      macrodef: add.composite.repository.internal          
     = = = = = = = = = = = = = = = = = -->
<macrodef name="add.composite.repository.internal">
    <attribute name="composite.repository.location" />
    <attribute name="composite.repository.name" />
    <attribute name="composite.repository.child" />
    <sequential>

        <echo message=" " />
        <echo message="Composite repository       : @{composite.repository.location}" />
        <echo message="Composite name             : @{composite.repository.name}" />
        <echo message="Adding child repository    : @{composite.repository.child}" />

        <p2.composite.repository>
            <repository compressed="false" location="@{composite.repository.location}" name="@{composite.repository.name}" />
            <add>
                <repository location="@{composite.repository.child}" />
            </add>
        </p2.composite.repository>

        <echo file="@{composite.repository.location}/p2.index">version=1
   metadata.repository.factory.order=compositeContent.xml,\!
   artifact.repository.factory.order=compositeArtifacts.xml,\!
   </echo>

    </sequential>
</macrodef>

</project>
like image 73
Vincent Avatar answered Oct 22 '22 16:10

Vincent