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

          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 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.

          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.

          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/af3edaae7bcc7b6441348e3744c6fcc199ca3709
          Log:
          CC - JENKINS-27169 - Replace string concatenation with String.format().

          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/af3edaae7bcc7b6441348e3744c6fcc199ca3709 Log: CC - JENKINS-27169 - Replace string concatenation with String.format().

          Code changed in jenkins
          User: Charles Chan
          Path:
          src/test/java/org/jenkinsci/plugins/patch/SomeTest.java
          src/test/resources/org/jenkinsci/plugins/patch/.gitattributes
          src/test/resources/org/jenkinsci/plugins/patch/gitstyle.patch
          src/test/resources/org/jenkinsci/plugins/patch/unix-gitstyle.patch
          src/test/resources/org/jenkinsci/plugins/patch/windows-gitstyle.patch
          http://jenkins-ci.org/commit/patch-parameter-plugin/5309d4d92cd03317b7eab47f56065a721ca4955d
          Log:
          CC - JENKINS-27169 - Add test to verify ContextualPatch can work with patch files generated from either Windows or Unix platforms, each with their respective line endings (CRLF vs LF).

          Note: Add .gitattributes files to preserve line ending for *.patch files.

          SCM/JIRA link daemon added a comment - Code changed in jenkins User: Charles Chan Path: src/test/java/org/jenkinsci/plugins/patch/SomeTest.java src/test/resources/org/jenkinsci/plugins/patch/.gitattributes src/test/resources/org/jenkinsci/plugins/patch/gitstyle.patch src/test/resources/org/jenkinsci/plugins/patch/unix-gitstyle.patch src/test/resources/org/jenkinsci/plugins/patch/windows-gitstyle.patch http://jenkins-ci.org/commit/patch-parameter-plugin/5309d4d92cd03317b7eab47f56065a721ca4955d Log: CC - JENKINS-27169 - Add test to verify ContextualPatch can work with patch files generated from either Windows or Unix platforms, each with their respective line endings (CRLF vs LF). Note: Add .gitattributes files to preserve line ending for *.patch files.

          Code changed in jenkins
          User: Hugo Trippaers
          Path:
          src/test/java/org/jenkinsci/plugins/patch/SomeTest.java
          src/test/resources/org/jenkinsci/plugins/patch/.gitattributes
          src/test/resources/org/jenkinsci/plugins/patch/gitstyle.patch
          src/test/resources/org/jenkinsci/plugins/patch/unix-gitstyle.patch
          src/test/resources/org/jenkinsci/plugins/patch/windows-gitstyle.patch
          http://jenkins-ci.org/commit/patch-parameter-plugin/69d93611c42ab5a0c406781cfe543329645f90fe
          Log:
          Merge pull request #2 from charleswhchan/JENKINS-27169

          CC - JENKINS-27169 - Modified the test to use System.lineSeparator() to ...

          Compare: https://github.com/jenkinsci/patch-parameter-plugin/compare/eae05e713ad0...69d93611c42a

          SCM/JIRA link daemon added a comment - Code changed in jenkins User: Hugo Trippaers Path: src/test/java/org/jenkinsci/plugins/patch/SomeTest.java src/test/resources/org/jenkinsci/plugins/patch/.gitattributes src/test/resources/org/jenkinsci/plugins/patch/gitstyle.patch src/test/resources/org/jenkinsci/plugins/patch/unix-gitstyle.patch src/test/resources/org/jenkinsci/plugins/patch/windows-gitstyle.patch http://jenkins-ci.org/commit/patch-parameter-plugin/69d93611c42ab5a0c406781cfe543329645f90fe Log: Merge pull request #2 from charleswhchan/ JENKINS-27169 CC - JENKINS-27169 - Modified the test to use System.lineSeparator() to ... Compare: https://github.com/jenkinsci/patch-parameter-plugin/compare/eae05e713ad0...69d93611c42a

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

              Created:
              Updated: