Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-27169

Patch parameter plugin's patch code is OS dependent which fails to patch cross platform files

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Major Major
    • patch-parameter-plugin
    • None
    • JDK 7, windows 7

      The test case in someTest class (https://github.com/jenkinsci/patch-parameter-plugin/commit/02c684a6e9d9fe40548c839ab15d2231306eb239 ) fails on windows. I am trying to use a patch file created on Unix machine on a windows machine. The code uses cloudbees/diff4j/ContextualPatch which internally uses BufferedReader to read files. BufferedReader does OS specific reading operation. So the end of file is causing the problem for the test case to pass when run on windows machine. Kindly see the attached images.

      Here is the link of ContextualPatch implementation https://github.com/cloudbees/diff4j/blob/master/src/main/java/com/cloudbees/diff/ContextualPatch.java

      Thank you for the help.
      H Shah

          [JENKINS-27169] Patch parameter plugin's patch code is OS dependent which fails to patch cross platform files

          Harsh Shah created issue -

          Charles Chan added a comment - - edited

          Charles Chan added a comment - - edited Submitted PR: https://github.com/jenkinsci/patch-parameter-plugin/pull/2
          Charles Chan made changes -
          Summary Original: Patch paramter plugin's patch code is OS dependent which fails to patch cross platform files New: Patch parameter plugin's patch code is OS dependent which fails to patch cross platform files

          Charles Chan added a comment -

          H Shah,

          I updated the test case to take care of line endings, but I am not sure if it fixes the "real" problem.

          Are you trying to use patch file created on Unix on a Windows machine, or vice versa? If so, could you please update the description above?

          Charles Chan added a comment - H Shah, I updated the test case to take care of line endings, but I am not sure if it fixes the "real" problem. Are you trying to use patch file created on Unix on a Windows machine, or vice versa? If so, could you please update the description above?

          Harsh Shah added a comment -

          Hi Charles

          The problem lies with the diff4j jar. I tried using System.lineSeparator() and the test case passed but I am concerned with ContextualPatch. It reads a file using bufferedReader which is OS dependent and so will create a problem.

          I am trying to use a patch file created on Unix machine on a windows machine.

          Harsh Shah added a comment - Hi Charles The problem lies with the diff4j jar. I tried using System.lineSeparator() and the test case passed but I am concerned with ContextualPatch. It reads a file using bufferedReader which is OS dependent and so will create a problem. I am trying to use a patch file created on Unix machine on a windows machine.
          Harsh Shah made changes -
          Description Original: The test case in someTest class (https://github.com/jenkinsci/patch-parameter-plugin/commit/02c684a6e9d9fe40548c839ab15d2231306eb239 ) fails on windows. The code uses cloudbees/diff4j/ContextualPatch which internally uses BufferedReader to read files. BufferedReader does OS specific reading operation. So the end of file is causing the problem for the test case to pass when run on windows machine. Kindly see the attached images.

          Here is the link of ContextualPatch implementation https://github.com/cloudbees/diff4j/blob/master/src/main/java/com/cloudbees/diff/ContextualPatch.java

          Thank you for the help.
          H Shah
          New: The test case in someTest class (https://github.com/jenkinsci/patch-parameter-plugin/commit/02c684a6e9d9fe40548c839ab15d2231306eb239 ) fails on windows. I am trying to use a patch file created on Unix machine on a windows machine. The code uses cloudbees/diff4j/ContextualPatch which internally uses BufferedReader to read files. BufferedReader does OS specific reading operation. So the end of file is causing the problem for the test case to pass when run on windows machine. Kindly see the attached images.

          Here is the link of ContextualPatch implementation https://github.com/cloudbees/diff4j/blob/master/src/main/java/com/cloudbees/diff/ContextualPatch.java

          Thank you for the help.
          H Shah

          Charles Chan added a comment -

          Hi H Shah,

          I pushed some changes to my local branch and updated the tests cases:
          https://github.com/charleswhchan/patch-parameter-plugin/tree/JENKINS-27169/src/test/resources/org/jenkinsci/plugins/patch

          Specifically, I created 2 patch files. One file for UNIX platform (LF line ending) and the other for Windows (CRLF line ending).

          $ file unix-gitstyle.patch 
          unix-gitstyle.patch: unified diff output, ASCII text
          
          $ file windows-gitstyle.patch 
          windows-gitstyle.patch: unified diff output, ASCII text, with CRLF line terminators
          

          Then each patch is applied against foo.txt and verifies the output ends up in the native line ending format.
          https://github.com/charleswhchan/patch-parameter-plugin/blob/JENKINS-27169/src/test/java/org/jenkinsci/plugins/patch/SomeTest.java

          So base on the tests, your scenario should work?

          Feel free to run and modify the test and let me know of your result.

          Charles Chan added a comment - Hi H Shah, I pushed some changes to my local branch and updated the tests cases: https://github.com/charleswhchan/patch-parameter-plugin/tree/JENKINS-27169/src/test/resources/org/jenkinsci/plugins/patch Specifically, I created 2 patch files. One file for UNIX platform (LF line ending) and the other for Windows (CRLF line ending). $ file unix-gitstyle.patch unix-gitstyle.patch: unified diff output, ASCII text $ file windows-gitstyle.patch windows-gitstyle.patch: unified diff output, ASCII text, with CRLF line terminators Then each patch is applied against foo.txt and verifies the output ends up in the native line ending format. https://github.com/charleswhchan/patch-parameter-plugin/blob/JENKINS-27169/src/test/java/org/jenkinsci/plugins/patch/SomeTest.java So base on the tests, your scenario should work? Feel free to run and modify the test and let me know of your result.

          Charles Chan added a comment -

          H Shah, any updates?

          Charles Chan added a comment - H Shah, any updates?

          Harsh Shah added a comment -

          Not yet will update once I work on it again.

          Harsh Shah added a comment - Not yet will update once I work on it again.

          Code changed in jenkins
          User: Charles Chan
          Path:
          src/test/java/org/jenkinsci/plugins/patch/SomeTest.java
          http://jenkins-ci.org/commit/patch-parameter-plugin/f35bfbe04b1db0839e79c915910e6cdd13aaeb43
          Log:
          CC - JENKINS-27169 - Modified the test to use System.lineSeparator() to ensure it pass on both Unix ("\n") and Windows ("\r\n") platforms.

          SCM/JIRA link daemon added a comment - Code changed in jenkins User: Charles Chan Path: src/test/java/org/jenkinsci/plugins/patch/SomeTest.java http://jenkins-ci.org/commit/patch-parameter-plugin/f35bfbe04b1db0839e79c915910e6cdd13aaeb43 Log: CC - JENKINS-27169 - Modified the test to use System.lineSeparator() to ensure it pass on both Unix ("\n") and Windows ("\r\n") platforms.

            Unassigned Unassigned
            hshah Harsh Shah
            Votes:
            1 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated: