Вызвать муравья внутри плагина затмения - PullRequest
0 голосов
/ 13 декабря 2011

У меня есть плагин Eclipse, и мне нужно вызвать ant внутри этого плагина, чтобы сделать некоторые вещи, такие как запустить тест junit и получить покрытие этого теста (используя плагин jacoco для этой цели) ...

My build.xml

<project name="Calculadora" default="rebuild" basedir="." xmlns:jacoco="antlib:org.jacoco.ant">
   <property name="src" location="./src"/>
   <property name="bin.dir" location="./bin"/>
   <property name="bin.report.dir" location="${bin.dir}/report"/>
   <property name="bin.exec.file" location="${bin.dir}/jacoco.exec"/>
   <property name="junit.out.dir" location="${bin.report.dir}/junit/xml"/>
   <taskdef uri="antlib:org.jacoco.ant" resource="org/jacoco/ant/antlib.xml">
      <classpath path="/tmp/jacocoant4002041518230825590.jar"/>
   </taskdef>
   <path id="classpath">
      <pathelement location="${bin.dir}"/>
      <pathelement location="${src}"/>
      <pathelement location="/usr/lib/eclipse/plugins/org.junit4_4.5.0.v20090824/junit.jar"/>
   </path>
   <target name="clean">
      <mkdir dir="${bin.report.dir}"/>
      <mkdir dir="${junit.out.dir}"/>
   </target>
   <target name="test" depends="clean">
      <jacoco:coverage destfile="${bin.exec.file}">
         <junit fork="true" forkmode="once">
            <classpath refid="classpath"/>
            <formatter type="xml" usefile="true"/>
            <test name="functions.test.ReadFile" todir="${junit.out.dir}"/>
         </junit>
      </jacoco:coverage>
   </target>
   <target name="report" depends="test">
      <jacoco:report>
         <executiondata>
            <file file="${bin.exec.file}"/>
         </executiondata>
         <structure name="">
            <classfiles>
               <fileset dir="${bin.dir}"/>
            </classfiles>
            <sourcefiles encoding="UTF-8">
               <fileset dir="${src}"/>
            </sourcefiles>
         </structure>
         <xml destfile="${bin.report.dir}/report.xml"/>
      </jacoco:report>
      <junitreport todir="${junit.out.dir}">
         <fileset dir="${junit.out.dir}">
            <include name="TEST-*.xml"/>
         </fileset>
      </junitreport>
   </target>
   <target name="rebuild" depends="clean,test,report"/>
</project>

Код для вызова Ant в Java:

// Creates a new Project object
Project p = new Project();
p.setUserProperty("ant.file", buildFile.getAbsolutePath());
p.init();

ProjectHelper helper = ProjectHelper.getProjectHelper();
p.addReference("ant.projectHelper", helper);
helper.parse(p, buildFile);

DefaultLogger consoleLogger = new DefaultLogger();
consoleLogger.setErrorPrintStream(System.err);
consoleLogger.setOutputPrintStream(System.out);
consoleLogger.setMessageOutputLevel(Project.MSG_INFO);
p.addBuildListener(consoleLogger);

p.executeTarget(p.getDefaultTarget());

Но когда я запускаю свой плагин, я получаю эту ошибку:

build.xml: 34: java.lang.ClassNotFoundException: org.apache.tools.ant.taskdefs.optional.junit.JUnitTaskMirrorImpl в org.apache.tools.ant.taskdefs.optional.junit.kj.createMirror (JUnitTask.java:708) в org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.setupJUnitDelegate (JUnitTask.java:745) в org.apache.tools.ant.itastjitfun.execute (JUnitTask.java:755) в org.apache.tools.ant.UnknownElement.execute (UnknownElement.java:291)
в org.jacoco.ant.CoverageTask.execute (CoverageTask.java:95) в org.apache.tools.ant.UnknownElement.execute (UnknownElement.java:291)
at sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method) в sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:57) в sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.javaflan.ho.in.Mo.et.Mo.Egn.Go.Eg.Java: 616) в org.apache.tools.ant.dispatch.DispatchUtils.execute (DispatchUtils.java:106) в org.apache.tools.ant.Task.perform (Task.java:348) в org.apache.tools.ant.Target.execute (Target.java:390) в org.apache.tools.ant.Target.performTasks (Target.java:411) в org.apache.tools.ant.Project.executeSortedTargets (Project.java:1360).)
at org.apache.tools.ant.Project.executeTarget (Project.java:1329) Вызывается: java.lang.ClassNotFoundException: org.apache.tools.ant.taskdefs.optional.junit.JUnitTaskMirrorImpl в org.apache.tools.ant.AntClassLoader.findClassInComponents (AntClassLoader.java:1386) в org.apache.tools.ant.AntClassLoader.findClass (AntClassLoader.java:1336) в org.apache.tools.ant.util.SaderClassLoSplitClassLoader.java:52) на Java.lang.ClassLoader.loadClass (ClassLoader.java:266) в org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.createMirror (JUnitTask.java:701) ... еще 19

Что происходит?Что я делаю не так?

Заранее спасибо

...