11

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

4 回答 4

12

通过阅读这个线程P2 Publisher 文档,它应该在org.eclipse.equinox.launcher_*.jar

仅用于参数的 P2 任务示例(此处不是 ant 任务)-jar

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

此处和Eclipse 帮助中描述了P2 Ant 任务


OP Anthony43在评论中补充道:

我只想在 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 /path/to/scripts/partialMirrorFromRepo.xml 

但是Andrew Niefer(PDE/Build、p2 和 Equinox 框架上的 Eclipse 提交者)补充道:

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


马丁·雅库比克提到:

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

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

请注意,我无法弄清楚是什么<targetProductFolder>,所以我<eclipse-install...>改用了。

于 2010-02-24T16:42:21.600 回答
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>
于 2013-11-05T09:07:55.500 回答
1

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

绕过它的唯一方法是分析 eclipse 代码,提取所需内容并使用它创建自己的构建系统。

于 2012-04-28T22:03:27.903 回答
1

只是为了完成Jarek Przygódzki的示例,这里是我的解决方案,使用他的 ant 文件。我不太熟悉使用 ant,所以可能有优化的潜力。这种方法在没有 GUI 的服务器上无头使用,但我必须安装 eclipse。使用 apt-get 安装不起作用,因此最好手动安装(下载并解压缩)。

  1. 第一个 antfile 组装名称、版本等...
  2. 第二个 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>
于 2018-03-20T08:51:53.380 回答