2011-11-30 4 views
0

오늘 Maven에서 실행되는 Groovy 코드에 이상한 문제가 발생했습니다 (gmaven-plugin 사용). 나는 단위 테스트에서만 Groovy를 사용하고있다. Eclipse에서 모든 유닛 테스트가 통과되지만, Maven을 사용하여 유닛 테스트를 실행할 때 오류가 발생합니다.gmaven-plugin SAX 파서 오류

문제가되는 Groovy 코드에는 XML 조작이 필요합니다. XML 페이로드에 속성을 추가하는 카테고리 메소드입니다.

<error message="org.xml.sax.SAXParseException: Premature end of file." type="net.sf.saxon.trans.XPathException">net.sf.saxon.trans.XPathException: org.xml.sax.SAXParseException: Premature end of file. 
    at net.sf.saxon.event.Sender.sendSAXSource(Sender.java:418) 
    at net.sf.saxon.event.Sender.send(Sender.java:214) 
    at net.sf.saxon.event.Sender.send(Sender.java:50) 
    at net.sf.saxon.Controller.transform(Controller.java:1611) 
    at sun.reflect.GeneratedMethodAccessor18.invoke(Unknown Source) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 
    at java.lang.reflect.Method.invoke(Method.java:597) 
    at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite$PojoCachedMethodSiteNoUnwrapNoCoerce.invoke(PojoMetaMethodSite.java:229) 
    at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite.call(PojoMetaMethodSite.java:52) 
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:129) 
    at com.sabre.ticketing.mapper.xmlapproach.BaseLRecTest$_closure3.doCall(BaseLRecTest.groovy:56) 
    at sun.reflect.GeneratedMethodAccessor17.invoke(Unknown Source) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 
    at java.lang.reflect.Method.invoke(Method.java:597) 
    at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:86) 
    at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:234) 
    at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:272) 
    at groovy.lang.MetaClassImpl.invokePropertyOrMissing(MetaClassImpl.java:1101) 
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1064) 
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:893) 
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:719) 
    at com.sabre.ticketing.mapper.xmlapproach.BaseLRecTest.invokeMethod(BaseLRecTest.groovy) 
    at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeOnDelegationObjects(ClosureMetaClass.java:407) 
    at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:346) 
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:893) 
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:719) 
    at groovy.lang.GroovyObjectSupport.invokeMethod(GroovyObjectSupport.java:44) 
    at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeOnDelegationObjects(ClosureMetaClass.java:407) 
    at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:346) 
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:893) 
    at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.callCurrent(PogoMetaClassSite.java:66) 
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:47) 
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:143) 
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:151) 
    at com.sabre.ticketing.mapper.xmlapproach.LRecC4Test$_testFrequentFlyerAirlineCode_closure22_closure30.doCall(LRecC4Test.groovy:199) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 
    at java.lang.reflect.Method.invoke(Method.java:597) 
    at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:86) 
    at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:234) 
    at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:272) 
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:893) 
    at groovy.lang.Closure.call(Closure.java:279) 
    at org.codehaus.groovy.runtime.DefaultGroovyMethods.callClosureForMapEntry(DefaultGroovyMethods.java:1911) 
    at org.codehaus.groovy.runtime.DefaultGroovyMethods.each(DefaultGroovyMethods.java:1184) 
    at org.codehaus.groovy.runtime.dgm$88.invoke(Unknown Source) 
    at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite$PojoMetaMethodSiteNoUnwrapNoCoerce.invoke(PojoMetaMethodSite.java:270) 
    at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite.call(PojoMetaMethodSite.java:52) 
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:43) 
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:117) 
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125) 
    at com.sabre.ticketing.mapper.xmlapproach.LRecC4Test$_testFrequentFlyerAirlineCode_closure22.doCall(LRecC4Test.groovy:198) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 
    at java.lang.reflect.Method.invoke(Method.java:597) 
    at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:86) 
    at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:234) 
    at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:272) 
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:893) 
    at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.callCurrent(PogoMetaClassSite.java:66) 
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:47) 
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:143) 
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:151) 
    at com.sabre.ticketing.mapper.xmlapproach.LRecC4Test$_testFrequentFlyerAirlineCode_closure22.doCall(LRecC4Test.groovy) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 
    at java.lang.reflect.Method.invoke(Method.java:597) 
    at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:86) 
    at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:234) 
    at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:272) 
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:893) 
    at groovy.lang.Closure.call(Closure.java:279) 
    at groovy.lang.Closure.call(Closure.java:274) 
    at org.codehaus.groovy.runtime.GroovyCategorySupport$ThreadCategoryInfo.use(GroovyCategorySupport.java:92) 
    at org.codehaus.groovy.runtime.GroovyCategorySupport$ThreadCategoryInfo.access$200(GroovyCategorySupport.java:60) 
    at org.codehaus.groovy.runtime.GroovyCategorySupport.use(GroovyCategorySupport.java:202) 
    at org.codehaus.groovy.runtime.DefaultGroovyMethods.use(DefaultGroovyMethods.java:324) 
    at org.codehaus.groovy.runtime.dgm$613.invoke(Unknown Source) 
    at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite$PogoMetaMethodSiteNoUnwrapNoCoerce.invoke(PogoMetaMethodSite.java:307) 
    at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite.callCurrent(PogoMetaMethodSite.java:51) 
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:47) 
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:143) 
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:155) 
    at com.sabre.ticketing.mapper.xmlapproach.LRecC4Test.testFrequentFlyerAirlineCode(LRecC4Test.groovy:195) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 
    at java.lang.reflect.Method.invoke(Method.java:597) 
    at junit.framework.TestCase.runTest(TestCase.java:168) 
    at junit.framework.TestCase.runBare(TestCase.java:134) 
    at junit.framework.TestResult$1.protect(TestResult.java:110) 
    at junit.framework.TestResult.runProtected(TestResult.java:128) 
    at junit.framework.TestResult.run(TestResult.java:113) 
    at junit.framework.TestCase.run(TestCase.java:124) 
    at junit.framework.TestSuite.runTest(TestSuite.java:243) 
    at junit.framework.TestSuite.run(TestSuite.java:238) 
    at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:83) 
    at org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:62) 
    at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.executeTestSet(AbstractDirectoryTestSuite.java:140) 
    at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.execute(AbstractDirectoryTestSuite.java:127) 
    at org.apache.maven.surefire.Surefire.run(Surefire.java:177) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 
    at java.lang.reflect.Method.invoke(Method.java:597) 
    at org.apache.maven.surefire.booter.SurefireBooter.runSuitesInProcess(SurefireBooter.java:345) 
    at org.apache.maven.surefire.booter.SurefireBooter.main(SurefireBooter.java:1009) 
Caused by: org.xml.sax.SAXParseException: Premature end of file. 
    at org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source) 
    at org.apache.xerces.util.ErrorHandlerWrapper.fatalError(Unknown Source) 
    at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source) 
    at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source) 
    at org.apache.xerces.impl.XMLVersionDetector.determineDocVersion(Unknown Source) 
    at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source) 
    at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source) 
    at org.apache.xerces.parsers.XMLParser.parse(Unknown Source) 
    at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source) 
    at org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source) 
    at net.sf.saxon.event.Sender.sendSAXSource(Sender.java:404) 
    ... 109 more 

그리고 GMaven 플러그인 구성은 다음과 같습니다 :

<plugin> 
    <groupId>org.codehaus.gmaven</groupId> 
    <artifactId>gmaven-plugin</artifactId> 
    <version>1.3</version> 
    <extensions>true</extensions> 
    <executions> 
     <execution> 
      <goals> 
       <goal>testCompile</goal> 
      </goals> 
      <configuration> 
       <sources> 
        <fileset> 
         <directory>${pom.basedir}/src/test/groovy</directory> 
         <includes> 
          <include>**/*.groovy</include> 
         </includes> 
        </fileset> 
       </sources> 
      </configuration> 
     </execution> 
    </executions> 
</plugin> 

이 도와주세요

class BaseTestCategoryMethods { 
    private static XmlSlurper slurper = new XmlSlurper(false, false) 
    public static String schemaVersion(String self, String version) { 
    def root = slurper.parseText(self) 
    [email protected] = version 
    return XmlUtil.serialize(root) 
    } 
} 

나는 다음과 같은 오류를 받고 있어요. 나는 모든 것을 시도했다. 왜 Eclipse에서 작동합니까? 카테고리 메쏘드 때문에 문제가 아니라고 저는 확신합니다.

+0

아마도 이것이 단서를 줄 수 있습니다. http://www.danielschneller.com/2008/01/saxparseexception-1-1-premature-end-of.html – dhblah

답변

0

나는 잘못된 행동을하지만, 내가 XmlSlurper 대신 XmlParser를 사용하고 XML 결과 준비 XmlUtil.serialize()를 사용하지 않는 해결 방법을 찾기 위해 관리 한 것이 원인이 있었는지 찾을 수 없습니다 :

class BaseTestCategoryMethods { 
    public static String schemaVersion(String self, String version) { 
     def root = new XmlParser().parseText(self) 
     root.attributes().put("version", version) 
     StringWriter sw = new StringWriter() 
     def printer = new XmlNodePrinter(new PrintWriter(sw), "") 
     printer.setPreserveWhitespace(true) 
     printer.print(root); 
     return sw.toString().readLines().join() 
    } 
} 

이를 Eclipse 및 Maven 명령 행에서 작동합니다.

0

나는 이것이 진짜 대답이 아니라는 것을 알고 있지만, 몇 달 동안 GMaven과 혼잣말을했습니다. 그 다음 나는 gradle로 바꿨다. 그리고 갑자기 구름은 헤어졌다. Java 프로젝트를 빌드하고 테스트를 위해 Groovy를 사용하는 데 적합합니다. GMaven은 올해 초 죽은 것처럼 보였습니다. GMaven 사용을 주장한다면, GMaven 문서가 시대에 뒤떨어져있는 것 같아서 Spock을 Maven과 함께 사용하는 사례를 최대한 활용했다고 생각합니다.

행운을 빈다.