Partial Maven clean install after Git pull











up vote
2
down vote

favorite












I had searched for a solution to mvn clean install on my changed projects after a git pull. I even asked a question over at SO about the same thing. The answer I got pointed me into creating my own script to achieve what I wanted to accomplish. So I went, I saw, and I conquered the script that I wanted. However, it is probably not efficient, and could use refactoring. I am new to bash scripting and learned a bit while doing this.



The structure I was targeting is a Maven POM Project. That project contains several sub-POM Projects, which in turn contain Maven Java Projects.



Example Structure:



-Parent
|-Sub_Parent_A
|-Child_1
|-Child_2
|-Sub_Parent_B
|-Child_3
|-Child_4


I wanted to only call mvn clean install if a project had files that changed in the child projects. This would reduce time on going to each project by hand and calling the command or by just calling the command on the parent project.



The code can also be found on GitHub



################################################################################
#
# 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 question




























    up vote
    2
    down vote

    favorite












    I had searched for a solution to mvn clean install on my changed projects after a git pull. I even asked a question over at SO about the same thing. The answer I got pointed me into creating my own script to achieve what I wanted to accomplish. So I went, I saw, and I conquered the script that I wanted. However, it is probably not efficient, and could use refactoring. I am new to bash scripting and learned a bit while doing this.



    The structure I was targeting is a Maven POM Project. That project contains several sub-POM Projects, which in turn contain Maven Java Projects.



    Example Structure:



    -Parent
    |-Sub_Parent_A
    |-Child_1
    |-Child_2
    |-Sub_Parent_B
    |-Child_3
    |-Child_4


    I wanted to only call mvn clean install if a project had files that changed in the child projects. This would reduce time on going to each project by hand and calling the command or by just calling the command on the parent project.



    The code can also be found on GitHub



    ################################################################################
    #
    # 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 question


























      up vote
      2
      down vote

      favorite









      up vote
      2
      down vote

      favorite











      I had searched for a solution to mvn clean install on my changed projects after a git pull. I even asked a question over at SO about the same thing. The answer I got pointed me into creating my own script to achieve what I wanted to accomplish. So I went, I saw, and I conquered the script that I wanted. However, it is probably not efficient, and could use refactoring. I am new to bash scripting and learned a bit while doing this.



      The structure I was targeting is a Maven POM Project. That project contains several sub-POM Projects, which in turn contain Maven Java Projects.



      Example Structure:



      -Parent
      |-Sub_Parent_A
      |-Child_1
      |-Child_2
      |-Sub_Parent_B
      |-Child_3
      |-Child_4


      I wanted to only call mvn clean install if a project had files that changed in the child projects. This would reduce time on going to each project by hand and calling the command or by just calling the command on the parent project.



      The code can also be found on GitHub



      ################################################################################
      #
      # 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 question















      I had searched for a solution to mvn clean install on my changed projects after a git pull. I even asked a question over at SO about the same thing. The answer I got pointed me into creating my own script to achieve what I wanted to accomplish. So I went, I saw, and I conquered the script that I wanted. However, it is probably not efficient, and could use refactoring. I am new to bash scripting and learned a bit while doing this.



      The structure I was targeting is a Maven POM Project. That project contains several sub-POM Projects, which in turn contain Maven Java Projects.



      Example Structure:



      -Parent
      |-Sub_Parent_A
      |-Child_1
      |-Child_2
      |-Sub_Parent_B
      |-Child_3
      |-Child_4


      I wanted to only call mvn clean install if a project had files that changed in the child projects. This would reduce time on going to each project by hand and calling the command or by just calling the command on the parent project.



      The code can also be found on GitHub



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






      bash git installer






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited yesterday

























      asked yesterday









      CodeMonkey

      264139




      264139



























          active

          oldest

          votes











          Your Answer





          StackExchange.ifUsing("editor", function () {
          return StackExchange.using("mathjaxEditing", function () {
          StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
          StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
          });
          });
          }, "mathjax-editing");

          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: "196"
          };
          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: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          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%2fcodereview.stackexchange.com%2fquestions%2f207685%2fpartial-maven-clean-install-after-git-pull%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown






























          active

          oldest

          votes













          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















           

          draft saved


          draft discarded



















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f207685%2fpartial-maven-clean-install-after-git-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

          Quarter-circle Tiles

          build a pushdown automaton that recognizes the reverse language of a given pushdown automaton?

          Mont Emei