11

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

Anthony Dahanne
  • 4,823
  • 2
  • 40
  • 39
  • I have updated my answer to reflect what you have found. Note: Andrew Niefer (Eclipse committer on PDE/Build, p2, & Equinox Framework) did make an interesting comment you might want to read (I have included it in my answer as well) – VonC Feb 25 '10 at 06:34

4 Answers4

13

By reading this thread and the P2 Publisher documentation, it should be in org.eclipse.equinox.launcher_*.jar

Example of a P2 task (not an ant task here) just for the -jar argument:

java -jar <targetProductFolder>/plugins/org.eclipse.equinox.launcher_*.jar
 -application org.eclipse.equinox.p2.publisher.UpdateSitePublisher
 -metadataRepository file:/<some location>/repository
 -artifactRepository file:/<some location>/repository
 -source /<location with a site.xml>
 -configs gtk.linux.x86
 -compress 
 -publishArtifacts

The P2 Ant tasks are described here, and in the Eclipse help.


The OP Anthony43 adds in the comments:

I just want to run an an ant target with p2 taskdefs, outside of eclipse.
I found out that I should use antRunner, using such a command line :

./eclipse -vm /opt/sun-java2-6.0/bin/java -nosplash \
-data ${java.io.tmpdir}/workspace -consolelog       \
-application org.eclipse.ant.core.antRunner         \
-f /path/to/scripts/partialMirrorFromRepo.xml 

But Andrew Niefer (Eclipse committer on PDE/Build, p2, & Equinox Framework) adds:

The p2 tasks need to be run inside an osgi environment and won't work in a normal ant run.
That is why you need to use the org.eclipse.ant.core.antRunner application.
Starting with "java -jar launcher.jar" is just an alternate method to invoking the eclipse executable.


martin jakubik mentions:

I would have liked to see a command that I could cut&paste and that put everything together.
What I used was:

java -jar <eclipse-install-directory>\eclipse\plugins\org.eclipse.equinox.launcher_*.jar -application org.eclipse.ant.core.antRunner. 

Note that I could not figure out what <targetProductFolder> was, so I used <eclipse-install...> instead.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • See also http://aniefer.blogspot.com/2009/08/versioning-p2-slides-from-eclipsecon.html – VonC Feb 24 '10 at 16:44
  • Hello ! thank you for your answer, but... I just want to run an an ant target with p2 taskdefs, outside of eclipse. I found out that I should use antRunner, using such a command line : ./eclipse -vm /opt/sun-java2-6.0/bin/java -nosplash -data ${java.io.tmpdir}/workspace -consolelog -application org.eclipse.ant.core.antRunner \ -f /home/nboldt/eclipse/workspace-jboss/org.eclipse.dash.common.releng/tools/scripts/partialMirrorFromRepo.xml Thnaks anyway ! – Anthony Dahanne Feb 24 '10 at 19:15
  • The p2 tasks need to be run inside an osgi environment and won't work in a normal ant run. That is why you need to use the org.eclipse.ant.core.antRunner application. Starting with "java -jar launcher.jar" is just an alternate method to invoking the eclipse executable. – Andrew Niefer Feb 25 '10 at 06:00
  • Yep, I totally agree, to finish with, launching an ant target with p2 tasks, one must use Eclipse or antRunner in an Equinox container. Thank you VonC, Anthony – Anthony Dahanne Feb 25 '10 at 19:20
  • Hi, good answer, which ended up working for me. And I learned a lot reading the linked pages. But I would have liked to see a command that I could cut&paste and that put everything together. What I used was java -jar \eclipse\plugins\org.eclipse.equinox.launcher_*.jar -application org.eclipse.ant.core.antRunner. Note that I could not figure out what was, so I used instead. I'll vote up if you can add this to your answer. – martin jakubik Sep 23 '11 at 15:46
  • @martinjakubik: I have updated the answer with your command line. – VonC Sep 23 '11 at 17:58
  • I still don't see a complete answer that will work in an ant script of my own. I assume this is the point since if I don't care about launching this from another ant task, I could just use the java command line solution above. @Jarek's macrodef solution below is good but I want to see a full example so I can know for instance what build file is meant to be referenced - some build file in the eclipse plugins, or the current build file (mine) assuming that antrunner finds the eclipse build files.?? – Rhubarb Jan 10 '14 at 17:37
  • @Rhubarb That would be better addressed as a question of its own, with a link back to this answer in order to explain the context. – VonC Jan 10 '14 at 21:24
2

I created a small Ant macro for that exact purpose

<path id="equinox.launcher.path">
    <fileset dir="${eclipse.home}/plugins">
        <include name="org.eclipse.equinox.launcher_*.jar" />
    </fileset>
</path>

<macrodef name="antRunner">
    <!-- Ant script location -->
    <attribute name="antFile" />
    <!-- the arguments for the script that is executed -->
    <attribute name="args" default=""/>
    <sequential>
        <java 
            classname="org.eclipse.equinox.launcher.Main" 
            fork="true" 
            failonerror="true">

            <arg line="-application org.eclipse.ant.core.antRunner" />
            <arg line="-f @{antFile}" />
            <arg line="@{args}"/>
            <classpath refid="equinox.launcher.path" />
        </java> 
    </sequential>
</macrodef>
Jarek Przygódzki
  • 4,284
  • 2
  • 31
  • 41
  • plus one for showing how to do it from withIN an ant script, but I dont get the purpose of @antFile. Do we have to specify the antfile in eclipse or does antrunner find that for me? How do I know where to find the ant files for the common tasks? – Rhubarb Jan 10 '14 at 17:39
1

All the p2 tasks NEED the eclipse runtime (as explicitly stated in the eclipse help mentioned above), so you definitely need to use eclipse.

The only way to get round of it would be to analyze the eclipse code, extract what is needed and create your own build system with it.

user
  • 86,916
  • 18
  • 197
  • 190
Robert
  • 11
  • 1
1

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>
Vincent
  • 199
  • 1
  • 14