在Eclipse外部运行P2 Ant任务

时间:2010-02-24 15:57:51

标签: eclipse ant p2

我在Eclipse中运行了很好的ant脚本 这是它的一部分:

<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>

但我希望Hudson CI服务器能够运行它,但是,无论我放在ANT_HOME / lib中的所有jar都无法让这个任务在一个简单的命令行中运行ant ... 我遇到了这个错误:

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.

在哪里定义p2 ant任务?有没有办法在Eclipse之外运行它们? 非常感谢你的帮助! 安东尼

4 个答案:

答案 0 :(得分:12)

通过阅读this threadP2 Publisher documentation,它应该在org.eclipse.equinox.launcher_*.jar

仅针对-jar参数的P2任务示例(此处不是ant任务):

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

P2 Ant tasks are described hereEclipse help


OP Anthony43在评论中添加:

  

我只想在eclipse之外用p2 taskdef运行一个ant目标   我发现我应该使用antRunner,使用这样的命令行:

./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 

Andrew Niefer(PDE / Build,p2和Equinox Framework上的Eclipse提交者)补充道:

  

p2任务需要在osgi环境中运行,并且无法正常运行
  这就是您需要使用org.eclipse.ant.core.antRunner应用程序的原因   从“java -jar launcher.jar”开始只是调用eclipse可执行文件的另一种方法。


martin jakubik提及:

  

我本来希望看到一个可以剪切和粘贴的命令,并将所有内容组合在一起   我用的是:

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

请注意,我无法确定<targetProductFolder>是什么,所以我使用<eclipse-install...>代替。

答案 1 :(得分:2)

我为了这个目的创建了一个小的Ant宏

<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>

答案 2 :(得分:1)

所有p2任务都需要eclipse运行时(如上面提到的eclipse帮助中明确说明的那样),所以你肯定需要使用eclipse。

解决问题的唯一方法是分析日食代码,提取所需内容并使用它创建自己的构建系统。

答案 3 :(得分:1)

只是为了完成Jarek Przygódzki的示例,这是我的解决方案,使用他的ant文件。我不太熟悉使用ant,所以可能有优化的潜力。 这个aproach在没有GUI的服务器上无头使用,但我不得不安装eclipse。使用apt-get进行安装无效,因此最好安装手册(下载和解压缩)。

  1. 第一个antfile汇集名称,版本等......
  2. 从第一个antfile调用第二个antfile并创建复合存储库。
  3. 第一个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>   
    

    第二个Antfile,名为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>