Пример #1
0
 def testDependencyOrder(self):
     _configureLogger()
     finder = ProjectsFinder("^\\.", projectsRoot)
     pomFiles = finder.find()
     
     repositoryPath = os.path.join(resourcesPath, "repository")
     
     loader = ProjectsLoader(pomFiles, repositoryPath)
     loader.loadProjects()
     
     o = []
     
     for p in loader.ordenedProjects:
         o.append(p)
     
     p1 = o.index("sample-group:project-1:1.0-SNAPSHOT")
     self.assertTrue(p1 > -1)
     p2 = o.index("sample-group:project-2:1.0-SNAPSHOT")
     self.assertTrue(p2 > -1)
     p3 = o.index("sample-group:project-3:1.0-SNAPSHOT")
     self.assertTrue(p3 > -1)
     p3a = o.index("sample-group:project-3-sub-a:1.0-SNAPSHOT")
     self.assertTrue(p3a > -1)
     p3b = o.index("sample-group:project-3-sub-b:1.0-SNAPSHOT")
     self.assertTrue(p3b > -1)
     
     self.assertTrue(p2 > p3b)
     self.assertTrue(p3a > p3b)
     self.assertTrue(p3a > p2)
Пример #2
0
 def testExecuteInstall(self):
     _configureLogger()
     
     finder = ProjectsFinder("^\\.", projectsRoot)
     pomFiles = finder.find()
     
     if os.path.exists(repositoryPath):
         shutil.rmtree(repositoryPath)
         
     os.mkdir(repositoryPath)
     
     loader = ProjectsLoader(pomFiles, repositoryPath)
     loader.loadProjects()
     
     executor = MavenExecutor(loader.ordenedProjects, subprocess.PIPE)
     executor.removeRepository = False
     try:
         executor.execute(['mvn', "-Dmaven.repo.local=%s" % (repositoryPath,), 'clean', 'install'])
     finally:
         shutil.rmtree(repositoryPath)
Пример #3
0
def main(args=[]):
    parser = OptionParser(
        usage="usage: %prog [options] mvnArg1 [mvnArg ...]",
        version="1.0",
        formatter=Formatter())
    parser.add_option("--d",
                      default=os.getcwd(),
                      dest="PROJECTS_DIRECTORY",
                      help="The projects diretory to rum command. Default is CWD.")
    parser.add_option("--i",
                      dest="IGNORE_FILES",
                      help="Files do ignore on find projects using regex. Use pipe to separate expressions. "
                      "Ex.: '\\.git|\\.svn|\\.project|target'. Default is: " + DEFAULT_IGNORE,
                      default=DEFAULT_IGNORE,
                      type="string")
    parser.add_option("--r",
                      default=USER_M2_REPOSITORY,
                      dest="REPOSITORY",
                      help="The Maven Local Repository Path. Default is '" + USER_M2_REPOSITORY + "'")
    parser.add_option("--c",
                      default=False,
                      action="store_true",
                      dest="NO_REMOVE_CACHE",
                      help="Remove Maven Local Repository Cache in REPOSITORY/<groupId>/" + \
                        "<artifactId>/<version> of each proccessed project.")
    parser.add_option("--l",
                      default=False,
                      action="store_true",
                      dest="LIST",
                      help="List all projects.")
    parser.add_option("--s",
                      default=False,
                      action="store_true",
                      dest="SHOW",
                      help="Shown options values.")
    
    group = OptionGroup(parser, "Examples",
                    '''
    %prog clean package''')
    parser.add_option_group(group)
    
    group = OptionGroup(parser, "Exit Status",
'''
    0 - Successful
    1 - JAVA_HOME or M2_HOME enviroment variables does not be setted
    2 - Program options/arguments error"
    6 - The Apache Maven Error
''')
    parser.add_option_group(group)
    
    (options, args) = parser.parse_args(args)
    
    command = args
    
    options.PROJECTS_DIRECTORY = os.path.abspath(os.path.realpath(os.path.expanduser(options.PROJECTS_DIRECTORY)))
    
    command = _command(command)
    
    if options.SHOW:
        dc = dict(PROJECTS_DIRECTORY=options.PROJECTS_DIRECTORY, 
                  IGNORE_FILES=options.IGNORE_FILES, 
                  REPOSITORY=options.REPOSITORY, 
                  NO_REMOVE_CACHE=options.NO_REMOVE_CACHE, 
                  LIST=options.LIST, 
                  SHOW=options.SHOW, MAVEN_COMMAND=("'" + "' '".join([c.replace("\\", "\\\\").replace("'", "\\'") for c in command]) + "'" if command else ""))
        for k,v in dc.items():
            print("%s = %s" %(k, v))
        
        return
    
    projectsDirectory = options.PROJECTS_DIRECTORY
        
    logging.basicConfig(format="[%(levelname)s] [%(name)s] [%(asctime)s]: %(message)s", level=logging.INFO, stream=sys.stdout)
    
    logger = logging.getLogger("mvnr")
    
    finder = ProjectsFinder(options.IGNORE_FILES, projectsDirectory)
    
    projects = finder.find()
    
    if len(projects) == 0:
        logger.info("No Projects Found")
    else :
        loader = ProjectsLoader(projects, options.REPOSITORY)
    
        try:
            loader.loadProjects()
            
            if not options.LIST:
                executor = MavenExecutor(loader.ordenedProjects)
                executor.removeRepository = not options.NO_REMOVE_CACHE
    
                if command is None:
                    parser.error("No maven commands found.")
                    return;
                    
                executor.execute(command)
        
        except EnvVariableNotSet as e:
            logger.error(e)
            sys.exit(1)
        except DuplicateProjectDetected as e:
            logger.error(e)
            sys.exit(4)
        except CalledProcessError as e:
            logger.error(e)
            sys.exit(6)
        except KeyboardInterrupt as e:
            logger.info("done.")
            print("")