Partial Clean Install with Maven after Git Merge/Pull











up vote
2
down vote

favorite
1












Using the terminal, is it possible to clean and install the projects within a POM Project that have changes after a git merge/pull, in other words, changes since the last clean install?



EDIT



Thanks to VonC's answer, I have completed a script that does what I desired. See my answer bellow for details.










share|improve this question




























    up vote
    2
    down vote

    favorite
    1












    Using the terminal, is it possible to clean and install the projects within a POM Project that have changes after a git merge/pull, in other words, changes since the last clean install?



    EDIT



    Thanks to VonC's answer, I have completed a script that does what I desired. See my answer bellow for details.










    share|improve this question


























      up vote
      2
      down vote

      favorite
      1









      up vote
      2
      down vote

      favorite
      1






      1





      Using the terminal, is it possible to clean and install the projects within a POM Project that have changes after a git merge/pull, in other words, changes since the last clean install?



      EDIT



      Thanks to VonC's answer, I have completed a script that does what I desired. See my answer bellow for details.










      share|improve this question















      Using the terminal, is it possible to clean and install the projects within a POM Project that have changes after a git merge/pull, in other words, changes since the last clean install?



      EDIT



      Thanks to VonC's answer, I have completed a script that does what I desired. See my answer bellow for details.







      java git maven






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 14 at 22:06

























      asked Nov 13 at 23:38









      CrazyJane

      337




      337
























          2 Answers
          2






          active

          oldest

          votes

















          up vote
          1
          down vote



          accepted










          Since you can detect the list of pom.xml changes between two commits:



          git diff --name-status <commit1> <commit2>


          (see also "Detail change after Git pull")



          , you can make a script which would, for each module, do a mvn clean install.






          share|improve this answer





















          • Thanks to your answer, I was able to make a script that can achieve what I wanted. Thank you! I will add the script to my question.
            – CrazyJane
            Nov 14 at 21:44


















          up vote
          1
          down vote













          Thanks to VonC's answer, I have completed a script that does what I desired.



          The project is a POM Project that contains sub-POM Projects that house the main projects for the application. I achieved the desired result by getting the current working branch to call git diff --name-status HEAD@{1} <current_branch>.



          This got the list of the changed files within the project, which I then split into an array. Unfortunately I could not get the split to work well, so the array is organized as change type followed by file path.



          Then I checked string size, skipping single character strings. The next step was to split the string into an array, delimited by /. Checked if it exists in an array if root paths, adding if it does not.



          Lastly, loop over the root path array and do the maven calls.



          ################################################################################
          #
          # License:.....GNU General Public License v3.0
          # Author:......CodeMonkey
          # Date:........14 November 2018
          # Title:.......GitMavenCleanInstall.sh
          # Description: This script is designed to cd to a set Maven POM Project,
          # perform a git remote update and pull, and clean install the changed
          # files projects.
          # Notice:......The project structure this script was originally set to target
          # is structured as a Maven POM Project that contains several sub-POM Projects.
          # The sub-POM Projects contain Maven Java Application projects. The targets
          # should be easy to change, and allow for others to target other structures.
          #
          ################################################################################
          #
          # Change History: N/A
          #
          ################################################################################

          #!/bin/bash
          #Function to check if array has element
          containsElement () {
          local e match="$1"
          shift
          for e; do [[ "$e" == "$match" ]] && return 0; done
          return 1
          }

          #Navigate to the POM Project
          cd PATH/TO/POM/PROJECT
          #Remote update
          git remote update -p
          #Pull
          git pull

          #Get the current working branch
          CURRENT_BRANCH="$(git branch | sed -n -e 's/^* (.*)/1/p')"
          #Get the output of the command git diff
          GIT_DIFF_OUTPUT="$(git diff --name-status HEAD@{1} ${CURRENT_BRANCH})"

          #Split the diff output into an array
          read =a GIT_DIFF_OUTPUT_ARY <<< $GIT_DIF_OUTPUT
          #Declare empty array for root path
          declare -a GIT_DIFF_OUTPUT_ARY_ROOT_PATH=()
          FORWARD='/'
          #Loop diff output array
          for i in "$GIT_DIFF_OUTPUT_ARY[@]}"
          do
          #Check that the string is not 1 Character
          if [[ "$(echo -n $1 | wc -m)" != 1 ]]
          then
          #Split the file path by /
          IFS='/' read -ra SPLIT <<< $i
          #Concatenate first path + / + second path
          path=${SPLIT[0]}$FORWARD${SPLIT[1]}
          #Call function to see if it already exists in the root path array
          containsElement "$path" "${GIT_DIFF_OUTPUT_ARY_ROOT_PATH[@]}"
          if [[ $? != 0 ]]
          then
          #Add the path since it was not found
          GIT_DIFF_OUTPUT_ARY_ROOT_PATH+=($path)
          fi
          fi
          done

          #Loop root path array
          for val in ${GIT_DIFF_OUTPUT_ARY_ROOT_PATH[@]}
          do
          #CD into root path
          cd $val
          #Maven call to clean install
          mvn -DskipTests=true --errors -T 8 -e clean install
          #CD back up before next project
          cd ../../
          done





          share|improve this answer























          • Well done, and +1
            – VonC
            Nov 14 at 22:47











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53291073%2fpartial-clean-install-with-maven-after-git-merge-pull%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          2 Answers
          2






          active

          oldest

          votes








          2 Answers
          2






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          1
          down vote



          accepted










          Since you can detect the list of pom.xml changes between two commits:



          git diff --name-status <commit1> <commit2>


          (see also "Detail change after Git pull")



          , you can make a script which would, for each module, do a mvn clean install.






          share|improve this answer





















          • Thanks to your answer, I was able to make a script that can achieve what I wanted. Thank you! I will add the script to my question.
            – CrazyJane
            Nov 14 at 21:44















          up vote
          1
          down vote



          accepted










          Since you can detect the list of pom.xml changes between two commits:



          git diff --name-status <commit1> <commit2>


          (see also "Detail change after Git pull")



          , you can make a script which would, for each module, do a mvn clean install.






          share|improve this answer





















          • Thanks to your answer, I was able to make a script that can achieve what I wanted. Thank you! I will add the script to my question.
            – CrazyJane
            Nov 14 at 21:44













          up vote
          1
          down vote



          accepted







          up vote
          1
          down vote



          accepted






          Since you can detect the list of pom.xml changes between two commits:



          git diff --name-status <commit1> <commit2>


          (see also "Detail change after Git pull")



          , you can make a script which would, for each module, do a mvn clean install.






          share|improve this answer












          Since you can detect the list of pom.xml changes between two commits:



          git diff --name-status <commit1> <commit2>


          (see also "Detail change after Git pull")



          , you can make a script which would, for each module, do a mvn clean install.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 14 at 6:04









          VonC

          824k28425913117




          824k28425913117












          • Thanks to your answer, I was able to make a script that can achieve what I wanted. Thank you! I will add the script to my question.
            – CrazyJane
            Nov 14 at 21:44


















          • Thanks to your answer, I was able to make a script that can achieve what I wanted. Thank you! I will add the script to my question.
            – CrazyJane
            Nov 14 at 21:44
















          Thanks to your answer, I was able to make a script that can achieve what I wanted. Thank you! I will add the script to my question.
          – CrazyJane
          Nov 14 at 21:44




          Thanks to your answer, I was able to make a script that can achieve what I wanted. Thank you! I will add the script to my question.
          – CrazyJane
          Nov 14 at 21:44












          up vote
          1
          down vote













          Thanks to VonC's answer, I have completed a script that does what I desired.



          The project is a POM Project that contains sub-POM Projects that house the main projects for the application. I achieved the desired result by getting the current working branch to call git diff --name-status HEAD@{1} <current_branch>.



          This got the list of the changed files within the project, which I then split into an array. Unfortunately I could not get the split to work well, so the array is organized as change type followed by file path.



          Then I checked string size, skipping single character strings. The next step was to split the string into an array, delimited by /. Checked if it exists in an array if root paths, adding if it does not.



          Lastly, loop over the root path array and do the maven calls.



          ################################################################################
          #
          # License:.....GNU General Public License v3.0
          # Author:......CodeMonkey
          # Date:........14 November 2018
          # Title:.......GitMavenCleanInstall.sh
          # Description: This script is designed to cd to a set Maven POM Project,
          # perform a git remote update and pull, and clean install the changed
          # files projects.
          # Notice:......The project structure this script was originally set to target
          # is structured as a Maven POM Project that contains several sub-POM Projects.
          # The sub-POM Projects contain Maven Java Application projects. The targets
          # should be easy to change, and allow for others to target other structures.
          #
          ################################################################################
          #
          # Change History: N/A
          #
          ################################################################################

          #!/bin/bash
          #Function to check if array has element
          containsElement () {
          local e match="$1"
          shift
          for e; do [[ "$e" == "$match" ]] && return 0; done
          return 1
          }

          #Navigate to the POM Project
          cd PATH/TO/POM/PROJECT
          #Remote update
          git remote update -p
          #Pull
          git pull

          #Get the current working branch
          CURRENT_BRANCH="$(git branch | sed -n -e 's/^* (.*)/1/p')"
          #Get the output of the command git diff
          GIT_DIFF_OUTPUT="$(git diff --name-status HEAD@{1} ${CURRENT_BRANCH})"

          #Split the diff output into an array
          read =a GIT_DIFF_OUTPUT_ARY <<< $GIT_DIF_OUTPUT
          #Declare empty array for root path
          declare -a GIT_DIFF_OUTPUT_ARY_ROOT_PATH=()
          FORWARD='/'
          #Loop diff output array
          for i in "$GIT_DIFF_OUTPUT_ARY[@]}"
          do
          #Check that the string is not 1 Character
          if [[ "$(echo -n $1 | wc -m)" != 1 ]]
          then
          #Split the file path by /
          IFS='/' read -ra SPLIT <<< $i
          #Concatenate first path + / + second path
          path=${SPLIT[0]}$FORWARD${SPLIT[1]}
          #Call function to see if it already exists in the root path array
          containsElement "$path" "${GIT_DIFF_OUTPUT_ARY_ROOT_PATH[@]}"
          if [[ $? != 0 ]]
          then
          #Add the path since it was not found
          GIT_DIFF_OUTPUT_ARY_ROOT_PATH+=($path)
          fi
          fi
          done

          #Loop root path array
          for val in ${GIT_DIFF_OUTPUT_ARY_ROOT_PATH[@]}
          do
          #CD into root path
          cd $val
          #Maven call to clean install
          mvn -DskipTests=true --errors -T 8 -e clean install
          #CD back up before next project
          cd ../../
          done





          share|improve this answer























          • Well done, and +1
            – VonC
            Nov 14 at 22:47















          up vote
          1
          down vote













          Thanks to VonC's answer, I have completed a script that does what I desired.



          The project is a POM Project that contains sub-POM Projects that house the main projects for the application. I achieved the desired result by getting the current working branch to call git diff --name-status HEAD@{1} <current_branch>.



          This got the list of the changed files within the project, which I then split into an array. Unfortunately I could not get the split to work well, so the array is organized as change type followed by file path.



          Then I checked string size, skipping single character strings. The next step was to split the string into an array, delimited by /. Checked if it exists in an array if root paths, adding if it does not.



          Lastly, loop over the root path array and do the maven calls.



          ################################################################################
          #
          # License:.....GNU General Public License v3.0
          # Author:......CodeMonkey
          # Date:........14 November 2018
          # Title:.......GitMavenCleanInstall.sh
          # Description: This script is designed to cd to a set Maven POM Project,
          # perform a git remote update and pull, and clean install the changed
          # files projects.
          # Notice:......The project structure this script was originally set to target
          # is structured as a Maven POM Project that contains several sub-POM Projects.
          # The sub-POM Projects contain Maven Java Application projects. The targets
          # should be easy to change, and allow for others to target other structures.
          #
          ################################################################################
          #
          # Change History: N/A
          #
          ################################################################################

          #!/bin/bash
          #Function to check if array has element
          containsElement () {
          local e match="$1"
          shift
          for e; do [[ "$e" == "$match" ]] && return 0; done
          return 1
          }

          #Navigate to the POM Project
          cd PATH/TO/POM/PROJECT
          #Remote update
          git remote update -p
          #Pull
          git pull

          #Get the current working branch
          CURRENT_BRANCH="$(git branch | sed -n -e 's/^* (.*)/1/p')"
          #Get the output of the command git diff
          GIT_DIFF_OUTPUT="$(git diff --name-status HEAD@{1} ${CURRENT_BRANCH})"

          #Split the diff output into an array
          read =a GIT_DIFF_OUTPUT_ARY <<< $GIT_DIF_OUTPUT
          #Declare empty array for root path
          declare -a GIT_DIFF_OUTPUT_ARY_ROOT_PATH=()
          FORWARD='/'
          #Loop diff output array
          for i in "$GIT_DIFF_OUTPUT_ARY[@]}"
          do
          #Check that the string is not 1 Character
          if [[ "$(echo -n $1 | wc -m)" != 1 ]]
          then
          #Split the file path by /
          IFS='/' read -ra SPLIT <<< $i
          #Concatenate first path + / + second path
          path=${SPLIT[0]}$FORWARD${SPLIT[1]}
          #Call function to see if it already exists in the root path array
          containsElement "$path" "${GIT_DIFF_OUTPUT_ARY_ROOT_PATH[@]}"
          if [[ $? != 0 ]]
          then
          #Add the path since it was not found
          GIT_DIFF_OUTPUT_ARY_ROOT_PATH+=($path)
          fi
          fi
          done

          #Loop root path array
          for val in ${GIT_DIFF_OUTPUT_ARY_ROOT_PATH[@]}
          do
          #CD into root path
          cd $val
          #Maven call to clean install
          mvn -DskipTests=true --errors -T 8 -e clean install
          #CD back up before next project
          cd ../../
          done





          share|improve this answer























          • Well done, and +1
            – VonC
            Nov 14 at 22:47













          up vote
          1
          down vote










          up vote
          1
          down vote









          Thanks to VonC's answer, I have completed a script that does what I desired.



          The project is a POM Project that contains sub-POM Projects that house the main projects for the application. I achieved the desired result by getting the current working branch to call git diff --name-status HEAD@{1} <current_branch>.



          This got the list of the changed files within the project, which I then split into an array. Unfortunately I could not get the split to work well, so the array is organized as change type followed by file path.



          Then I checked string size, skipping single character strings. The next step was to split the string into an array, delimited by /. Checked if it exists in an array if root paths, adding if it does not.



          Lastly, loop over the root path array and do the maven calls.



          ################################################################################
          #
          # License:.....GNU General Public License v3.0
          # Author:......CodeMonkey
          # Date:........14 November 2018
          # Title:.......GitMavenCleanInstall.sh
          # Description: This script is designed to cd to a set Maven POM Project,
          # perform a git remote update and pull, and clean install the changed
          # files projects.
          # Notice:......The project structure this script was originally set to target
          # is structured as a Maven POM Project that contains several sub-POM Projects.
          # The sub-POM Projects contain Maven Java Application projects. The targets
          # should be easy to change, and allow for others to target other structures.
          #
          ################################################################################
          #
          # Change History: N/A
          #
          ################################################################################

          #!/bin/bash
          #Function to check if array has element
          containsElement () {
          local e match="$1"
          shift
          for e; do [[ "$e" == "$match" ]] && return 0; done
          return 1
          }

          #Navigate to the POM Project
          cd PATH/TO/POM/PROJECT
          #Remote update
          git remote update -p
          #Pull
          git pull

          #Get the current working branch
          CURRENT_BRANCH="$(git branch | sed -n -e 's/^* (.*)/1/p')"
          #Get the output of the command git diff
          GIT_DIFF_OUTPUT="$(git diff --name-status HEAD@{1} ${CURRENT_BRANCH})"

          #Split the diff output into an array
          read =a GIT_DIFF_OUTPUT_ARY <<< $GIT_DIF_OUTPUT
          #Declare empty array for root path
          declare -a GIT_DIFF_OUTPUT_ARY_ROOT_PATH=()
          FORWARD='/'
          #Loop diff output array
          for i in "$GIT_DIFF_OUTPUT_ARY[@]}"
          do
          #Check that the string is not 1 Character
          if [[ "$(echo -n $1 | wc -m)" != 1 ]]
          then
          #Split the file path by /
          IFS='/' read -ra SPLIT <<< $i
          #Concatenate first path + / + second path
          path=${SPLIT[0]}$FORWARD${SPLIT[1]}
          #Call function to see if it already exists in the root path array
          containsElement "$path" "${GIT_DIFF_OUTPUT_ARY_ROOT_PATH[@]}"
          if [[ $? != 0 ]]
          then
          #Add the path since it was not found
          GIT_DIFF_OUTPUT_ARY_ROOT_PATH+=($path)
          fi
          fi
          done

          #Loop root path array
          for val in ${GIT_DIFF_OUTPUT_ARY_ROOT_PATH[@]}
          do
          #CD into root path
          cd $val
          #Maven call to clean install
          mvn -DskipTests=true --errors -T 8 -e clean install
          #CD back up before next project
          cd ../../
          done





          share|improve this answer














          Thanks to VonC's answer, I have completed a script that does what I desired.



          The project is a POM Project that contains sub-POM Projects that house the main projects for the application. I achieved the desired result by getting the current working branch to call git diff --name-status HEAD@{1} <current_branch>.



          This got the list of the changed files within the project, which I then split into an array. Unfortunately I could not get the split to work well, so the array is organized as change type followed by file path.



          Then I checked string size, skipping single character strings. The next step was to split the string into an array, delimited by /. Checked if it exists in an array if root paths, adding if it does not.



          Lastly, loop over the root path array and do the maven calls.



          ################################################################################
          #
          # License:.....GNU General Public License v3.0
          # Author:......CodeMonkey
          # Date:........14 November 2018
          # Title:.......GitMavenCleanInstall.sh
          # Description: This script is designed to cd to a set Maven POM Project,
          # perform a git remote update and pull, and clean install the changed
          # files projects.
          # Notice:......The project structure this script was originally set to target
          # is structured as a Maven POM Project that contains several sub-POM Projects.
          # The sub-POM Projects contain Maven Java Application projects. The targets
          # should be easy to change, and allow for others to target other structures.
          #
          ################################################################################
          #
          # Change History: N/A
          #
          ################################################################################

          #!/bin/bash
          #Function to check if array has element
          containsElement () {
          local e match="$1"
          shift
          for e; do [[ "$e" == "$match" ]] && return 0; done
          return 1
          }

          #Navigate to the POM Project
          cd PATH/TO/POM/PROJECT
          #Remote update
          git remote update -p
          #Pull
          git pull

          #Get the current working branch
          CURRENT_BRANCH="$(git branch | sed -n -e 's/^* (.*)/1/p')"
          #Get the output of the command git diff
          GIT_DIFF_OUTPUT="$(git diff --name-status HEAD@{1} ${CURRENT_BRANCH})"

          #Split the diff output into an array
          read =a GIT_DIFF_OUTPUT_ARY <<< $GIT_DIF_OUTPUT
          #Declare empty array for root path
          declare -a GIT_DIFF_OUTPUT_ARY_ROOT_PATH=()
          FORWARD='/'
          #Loop diff output array
          for i in "$GIT_DIFF_OUTPUT_ARY[@]}"
          do
          #Check that the string is not 1 Character
          if [[ "$(echo -n $1 | wc -m)" != 1 ]]
          then
          #Split the file path by /
          IFS='/' read -ra SPLIT <<< $i
          #Concatenate first path + / + second path
          path=${SPLIT[0]}$FORWARD${SPLIT[1]}
          #Call function to see if it already exists in the root path array
          containsElement "$path" "${GIT_DIFF_OUTPUT_ARY_ROOT_PATH[@]}"
          if [[ $? != 0 ]]
          then
          #Add the path since it was not found
          GIT_DIFF_OUTPUT_ARY_ROOT_PATH+=($path)
          fi
          fi
          done

          #Loop root path array
          for val in ${GIT_DIFF_OUTPUT_ARY_ROOT_PATH[@]}
          do
          #CD into root path
          cd $val
          #Maven call to clean install
          mvn -DskipTests=true --errors -T 8 -e clean install
          #CD back up before next project
          cd ../../
          done






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 14 at 22:44

























          answered Nov 14 at 22:07









          CrazyJane

          337




          337












          • Well done, and +1
            – VonC
            Nov 14 at 22:47


















          • Well done, and +1
            – VonC
            Nov 14 at 22:47
















          Well done, and +1
          – VonC
          Nov 14 at 22:47




          Well done, and +1
          – VonC
          Nov 14 at 22:47


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53291073%2fpartial-clean-install-with-maven-after-git-merge-pull%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          How to change which sound is reproduced for terminal bell?

          Title Spacing in Bjornstrup Chapter, Removing Chapter Number From Contents

          Can I use Tabulator js library in my java Spring + Thymeleaf project?