Do a maven build in a python script
Question: I am checking out a source for a given url using a python script and I want to
go to the downloadedFoler/src directory and perform a `mvn clean install`. I
want to do it in the same script. Thank in advance.


Answer: You can do the following:

    
    
    import os
    import subprocess
    
    # Context Manager to change current directory.
    # I looked at this implementation on stackoverflow but unfortunately do not have the link
    # to credit the user who wrote this part of the code.
    class changeDir:
      def __init__(self, newPath):
        self.newPath = os.path.expanduser(newPath)
    
      # Change directory with the new path
      def __enter__(self):
        self.savedPath = os.getcwd()
        os.chdir(self.newPath)
    
      # Return back to previous directory
      def __exit__(self, etype, value, traceback):
        os.chdir(self.savedPath)
    
    # folderPath = path of the folder you want to run mvn clean install on
    with changeDir(folderPath):
      # ****** NOTE ******: using shell=True is strongly discouraged since it possesses security risks
      subprocess.call(["mvn", "clean", "install"], shell=True)
    

