在Eclipse之外运行P2 Ant任务

在Eclipse之外运行P2 Ant任务,eclipse,ant,p2,Eclipse,Ant,P2,我让ant脚本在Eclipse中运行良好 以下是其中的一部分: <p2.composite.repository failOnExists="true"> <repository location="file:/${basedir}/compRepo" name="Repository description goes here" /> <add> <repository l

我让ant脚本在Eclipse中运行良好 以下是其中的一部分:

<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 server能够运行它,但是,无论我在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.
C:\workspaces\workspace\project\junit.script\createCompRepo.xml:10:问题:无法创建任务或类型p2.composite.repository
原因:名称未定义。
措施:检查拼写。
操作:检查是否已声明任何自定义任务/类型。
措施:检查是否发生了任何/声明。
p2 ant任务在哪里定义?有没有办法在Eclipse之外运行它们? 非常感谢你的帮助! Anthony

通过阅读和,它应该位于
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
但是(PDE/Build、p2和Equinox框架上的Eclipse提交人)添加了:

p2任务需要在osgi环境中运行,在正常的ant运行中无法运行
这就是为什么需要使用
org.eclipse.ant.core.antRunner
应用程序的原因。
从“java-jarlauncher.jar”开始只是调用eclipse可执行文件的替代方法


提到:

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

java-jar\eclipse\plugins\org.eclipse.equinox.launcher.*.jar-application org.eclipse.ant.core.antRunner。
请注意,我无法理解
是什么,所以我使用了


所有p2任务都需要eclipse运行时(如上面提到的eclipse帮助中明确说明的),因此您肯定需要使用eclipse


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

我创建了一个小型Ant宏,正是出于这个目的


这里的示例是我的解决方案,使用他的ant文件。我不太熟悉使用ant,所以可能有优化的潜力。 这个aproach在没有GUI的服务器上使用,但是我必须安装eclipse。apt get的安装不起作用,所以最好安装手册(下载并卸载)

  • 第一个文件集合名称、版本等
  • 从第一个antfile调用第二个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>
    
    
    版本=1
    metadata.repository.factory.order=compositeContent.xml,\!
    artifact.repository.factory.order=compositeArtifacts.xml,\!
    
    另请参见Hello!谢谢你的回答,但是。。。我只想在eclipse之外运行一个带有p2 taskdefs的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/home/nboldt/eclipse/workspace jboss/org.eclipse.dash.common.reling/tools/scripts/partialMirrorFromRepo.xml Thnaks!p2任务需要在osgi环境中运行,在正常的ant运行中无法工作。这就是为什么需要使用org.eclipse.ant.core.antRunner应用程序。从“java-jar launcher.jar”开始只是调用eclipse可执行文件的另一种方法。是的,我完全同意,要完成,用p2任务启动ant目标,必须在Equinox容器中使用eclipse或antRunner。谢谢你,安多尼希,回答得好,最后对我有用。通过阅读链接页面,我学到了很多。但我希望看到一个命令,我可以剪切和粘贴,并把所有的东西放在一起。我使用的是java-jar\eclipse\plugins\org.eclipse.equinox.launcher.*.jar-application org.eclipse.ant.core.antRunner。请注意,我无法找出是什么,所以我使用了。如果你能把这个添加到你的答案中,我会投赞成票。我已经更新了我的答案,以反映你的发现。注意:Andrew Niefer(PDE/Build、p2和Equinox框架上的Eclipse提交人)确实做了一个有趣的评论,你可能想读一读(我也在我的答案中包含了它),另外还有一个是为了说明如何从ant脚本中执行它,但我不明白@antFile的目的。我们必须在eclipse中指定antfile,还是antrunner为我找到了?我如何知道在哪里可以找到用于常见任务的ant文件?
    <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>   
    
    <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>