GeoTools
  1. GeoTools
  2. GEOT-2364

Build broken on Windows: unit test failure in imagemosaic-jdbc

    Details

    • Type: Bug Bug
    • Status: Closed Closed
    • Priority: Blocker Blocker
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 2.5.4, 2.6-M2
    • Component/s: imagemosaic plugin
    • Labels:
      None

      Description

      imagemosaic-jdbc H2Test fails on Windows, in AbstractTest.testImportParamList(), because of nonportable file path manipulation.

      1. AbstractTest.patch
        2 kB
        Christian Mueller
      2. imagemosaic-jdbc.patch
        5 kB
        Ben Caradoc-Davies

        Activity

        Hide
        Christian Mueller added a comment -
        Hi Ben, I attached a patch file. Since I have no possibility to test on a windows environment this week, can you please apply the patch and test it.

        If the patch does not work, I will remove the test and dig deeper in the next week

        thanks

        Show
        Christian Mueller added a comment - Hi Ben, I attached a patch file. Since I have no possibility to test on a windows environment this week, can you please apply the patch and test it. If the patch does not work, I will remove the test and dig deeper in the next week thanks
        Hide
        Christian Mueller added a comment -
        Attaching the patch
        Show
        Christian Mueller added a comment - Attaching the patch
        Hide
        Ben Caradoc-Davies added a comment -
        Christian, this patch will not work because OUTPUTDIR_RESOURCES already contains backslashes, so string comparison is doomed to fail. The first failure occurs at AbstractTest line 412, and your patch does not touch this line or any before it.

        I thought about converting the URLs to URIs and then to Files to use File.equals(), but the URLs have authority and a relative path so are invalid.
        Show
        Ben Caradoc-Davies added a comment - Christian, this patch will not work because OUTPUTDIR_RESOURCES already contains backslashes, so string comparison is doomed to fail. The first failure occurs at AbstractTest line 412, and your patch does not touch this line or any before it. I thought about converting the URLs to URIs and then to Files to use File.equals(), but the URLs have authority and a relative path so are invalid.
        Hide
        Ben Caradoc-Davies added a comment -
        And making the right hand side paths in
        assertTrue(importParamList.get(0).getSourceURL().getPath().contains(OUTPUTDIR_RESOURCES));
        into a File and then a URL makes them absolute, while the left hand side are relative.
        Show
        Ben Caradoc-Davies added a comment - And making the right hand side paths in assertTrue(importParamList.get(0).getSourceURL().getPath().contains(OUTPUTDIR_RESOURCES)); into a File and then a URL makes them absolute, while the left hand side are relative.
        Hide
        Christian Mueller added a comment -
        Ben, what exactly is the problem at line 412.

        OUPUTDIR_RESOURCES is "target/resources/" on Linux and should be "target\resources\" on Windows

        The getPath method of the URL class relies on File.seperator (according to java doc)

        importParamList.get(0).getSourceURL().getPath() is "target/resources/" on linux and should be "target\resources\" on Windows.

        What Strings do you get for

        1) OUPUTDIR_RESOURCES
        2) importParamList.get(0).getSourceURL().getPath() on line 412

        Show
        Christian Mueller added a comment - Ben, what exactly is the problem at line 412. OUPUTDIR_RESOURCES is "target/resources/" on Linux and should be "target\resources\" on Windows The getPath method of the URL class relies on File.seperator (according to java doc) importParamList.get(0).getSourceURL().getPath() is "target/resources/" on linux and should be "target\resources\" on Windows. What Strings do you get for 1) OUPUTDIR_RESOURCES 2) importParamList.get(0).getSourceURL().getPath() on line 412
        Hide
        Ben Caradoc-Davies added a comment -
        Christian, I have attached a patch that fixes the issue.

        On Windows, URL.getPath() returns a path with forward slashes, because it is the path component of a URL, not a filesystem path. As a consequence, on Windows the URL path cannot match the file path. The attached patch fixes this problem by creating two File objects and comparing their canonical paths to test if they are the same. It works on Windows.

        The patch adds a helper method, a unit test for the helper, and enables the test in H2Test.

        Show
        Ben Caradoc-Davies added a comment - Christian, I have attached a patch that fixes the issue. On Windows, URL.getPath() returns a path with forward slashes, because it is the path component of a URL, not a filesystem path. As a consequence, on Windows the URL path cannot match the file path. The attached patch fixes this problem by creating two File objects and comparing their canonical paths to test if they are the same. It works on Windows. The patch adds a helper method, a unit test for the helper, and enables the test in H2Test.
        Hide
        Ben Caradoc-Davies added a comment -
        And for ease of reading, I did not wrap the lines. Feel free to reformat the changes bits to conform to the GeoTools convention.
        Show
        Ben Caradoc-Davies added a comment - And for ease of reading, I did not wrap the lines. Feel free to reformat the changes bits to conform to the GeoTools convention.
        Hide
        Christian Mueller added a comment -
        Thanks Ben, applied your patch and it is working on linux too.
        Show
        Christian Mueller added a comment - Thanks Ben, applied your patch and it is working on linux too.

          People

          • Assignee:
            Christian Mueller
            Reporter:
            Ben Caradoc-Davies
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: