Uploaded image for project: 'Apache Avro'
  1. Apache Avro
  2. AVRO-3371

velocity fails to find file by absolute path on windows

    XMLWordPrintableJSON

Details

    Description

      when building master on windows, I get the following failure in the avro-maven-plugin java module:

      [INFO] Running org.apache.avro.mojo.TestIDLProtocolMojo
      [ERROR] Tests run: 2, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.2 s <<< FAILURE! - in org.apache.avro.mojo.TestIDLProtocolMojo
      [ERROR] org.apache.avro.mojo.TestIDLProtocolMojo.testSetCompilerVelocityAdditionalTools  Time elapsed: 0.06 s  <<< ERROR!
      java.lang.RuntimeException: org.apache.velocity.exception.ResourceNotFoundException: Unable to find resource 'C:\Users\radai\work\avro\lang\java\maven-plugin/src/test/resources/templates/enum.vm'
              at org.apache.avro.compiler.specific.SpecificCompiler.renderTemplate(SpecificCompiler.java:551)
              at org.apache.avro.compiler.specific.SpecificCompiler.compile(SpecificCompiler.java:629)
              at org.apache.avro.compiler.specific.SpecificCompiler.compileToDestination(SpecificCompiler.java:538)
              at org.apache.avro.mojo.IDLProtocolMojo.doCompile(IDLProtocolMojo.java:107)
              at org.apache.avro.mojo.AbstractAvroMojo.compileFiles(AbstractAvroMojo.java:281)
              at org.apache.avro.mojo.AbstractAvroMojo.execute(AbstractAvroMojo.java:231)
              at org.apache.avro.mojo.TestIDLProtocolMojo.testSetCompilerVelocityAdditionalTools(TestIDLProtocolMojo.java:68)
              at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
              at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
              at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
              at java.lang.reflect.Method.invoke(Method.java:498)
              at junit.framework.TestCase.runTest(TestCase.java:177)
              at junit.framework.TestCase.runBare(TestCase.java:142)
              at junit.framework.TestResult$1.protect(TestResult.java:122)
              at junit.framework.TestResult.runProtected(TestResult.java:142)
              at junit.framework.TestResult.run(TestResult.java:125)
              at junit.framework.TestCase.run(TestCase.java:130)
              at junit.framework.TestSuite.runTest(TestSuite.java:241)
              at junit.framework.TestSuite.run(TestSuite.java:236)
              at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:90)
              at org.junit.runners.Suite.runChild(Suite.java:128)
              at org.junit.runners.Suite.runChild(Suite.java:27)
              at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331)
              at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79)
              at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329)
              at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66)
              at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293)
              at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
              at org.junit.runners.ParentRunner.run(ParentRunner.java:413)
              at org.junit.runners.Suite.runChild(Suite.java:128)
              at org.junit.runners.Suite.runChild(Suite.java:27)
              at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331)
              at org.apache.maven.surefire.junitcore.pc.Scheduler$1.run(Scheduler.java:405)
              at org.apache.maven.surefire.junitcore.pc.InvokerStrategy.schedule(InvokerStrategy.java:54)
              at org.apache.maven.surefire.junitcore.pc.Scheduler.schedule(Scheduler.java:362)
              at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329)
              at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66)
              at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293)
              at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
              at org.junit.runners.ParentRunner.run(ParentRunner.java:413)
              at org.apache.maven.surefire.junitcore.pc.ParallelComputerBuilder$PC$1.run(ParallelComputerBuilder.java:590)
              at org.apache.maven.surefire.junitcore.JUnitCore.run(JUnitCore.java:55)
              at org.apache.maven.surefire.junitcore.JUnitCoreWrapper.createRequestAndRun(JUnitCoreWrapper.java:137)
              at org.apache.maven.surefire.junitcore.JUnitCoreWrapper.executeEager(JUnitCoreWrapper.java:107)
              at org.apache.maven.surefire.junitcore.JUnitCoreWrapper.execute(JUnitCoreWrapper.java:83)
              at org.apache.maven.surefire.junitcore.JUnitCoreWrapper.execute(JUnitCoreWrapper.java:75)
              at org.apache.maven.surefire.junitcore.JUnitCoreProvider.invoke(JUnitCoreProvider.java:157)
              at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:428)
              at org.apache.maven.surefire.booter.ForkedBooter.execute(ForkedBooter.java:162)
              at org.apache.maven.surefire.booter.ForkedBooter.run(ForkedBooter.java:562)
              at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:548)
      Caused by: org.apache.velocity.exception.ResourceNotFoundException: Unable to find resource 'C:\Users\radai\work\avro\lang\java\maven-plugin/src/test/resources/templates/enum.vm'
              at org.apache.velocity.runtime.resource.ResourceManagerImpl.loadResource(ResourceManagerImpl.java:465)
              at org.apache.velocity.runtime.resource.ResourceManagerImpl.getResource(ResourceManagerImpl.java:346)
              at org.apache.velocity.runtime.RuntimeInstance.getTemplate(RuntimeInstance.java:1677)
              at org.apache.velocity.runtime.RuntimeInstance.getTemplate(RuntimeInstance.java:1656)
              at org.apache.velocity.app.VelocityEngine.getTemplate(VelocityEngine.java:314)
              at org.apache.avro.compiler.specific.SpecificCompiler.renderTemplate(SpecificCompiler.java:549)
              ... 50 more 

      this fails 2 other tests in the same module as well:

      [ERROR] Errors:
      [ERROR]   TestIDLProtocolMojo.testSetCompilerVelocityAdditionalTools:68 ▒ Runtime org.ap...
      [ERROR]   TestProtocolMojo.testSetCompilerVelocityAdditionalTools:59 ▒ Runtime org.apach...
      [ERROR]   TestSchemaMojo.testSetCompilerVelocityAdditionalTools:59 ▒ Runtime org.apache.... 

      the root issue as far as i can tell seems to be this velocity configuration in SpecificCompiler:

      private void initializeVelocity() {
         ...
         velocityEngine.addProperty("resource.loader.file.path", "/, .");
         ...
      } 

      which defines 2 "root paths": "/" and "."

      however, under windows and given a path of the form "C:/<whatever>" this will try looking for either "/C:/<whatever>" or "./C:/<whatever>" - both are "wrong" for a windows absolute path.

      relevant code is in org.apache.velocity.runtime.resource.loader.FileResourceLoader.getFile():

      private File getFile(String path, String template) {
         File file = null; 
         if("".equals(path)) {
            file = new File( template );   <---- NEVER TAKEN
         } else {
            if (template.startsWith("/")) {
               template = template.substring(1);
            }
            file = new File ( path, template );
         }
         return file;
      }

      quickest fix i can think of is add "" as a 3rd possible root to velocity config in class SpecificCompiler

      Attachments

        Issue Links

          Activity

            People

              radai Radai Rosenblatt
              radai Radai Rosenblatt
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 0.5h
                  0.5h