Пример #1
0
    def maven(self, clone_repo=False, local_repo=None, **kwargs):
        """Invokes the Maven command-line interface.

        Note: when cloning the Maven local repository, the command must run synchronously.

        Args:
            clone_repo: Whether to clone the Maven local repository.
            local_repo: Optional explicit Maven local repository. Default to the workspace's repo.
            args: List of command-line arguments for the Maven invocation.
            recursive: Whether to enable the Maven reactor. Default is non-recursive.
            snapshot_updates: Whether to update snapshot artifacts. Default is no.
        Returns:
            The Command instance for the specified Maven invocation.
        """
        if local_repo is None:
            local_repo = self.workspace.maven_local_repo

        if clone_repo:
            source_local_repo = local_repo
            os.makedirs(self._maven_cloned_repo_dir, exist_ok=True)
            local_repo = os.path.join(self._maven_cloned_repo_dir, base.random_alpha_num_word(20))
            logging.debug("Cloning Maven local repo %s into %s", source_local_repo, local_repo)
            clone_maven_repo(source=source_local_repo, target=local_repo)

        try:
            return self._maven(local_repo=local_repo, **kwargs)
        finally:
            if clone_repo:
                logging.debug("Back-porting cloned Maven repo %s to %s",
                              local_repo, source_local_repo)
                backport_updates_from_cloned_repo(source=source_local_repo, clone=local_repo)
                shutil.rmtree(local_repo)
Пример #2
0
 def test_touch(self):
     path = base.random_alpha_num_word(16)
     try:
         self.assertFalse(os.path.exists(path))
         base.touch(path)
         self.assertTrue(os.path.exists(path))
         base.touch(path)
         self.assertTrue(os.path.exists(path))
     finally:
         base.remove(path)
Пример #3
0
 def test_touch(self):
     path = base.random_alpha_num_word(16)
     try:
         self.assertFalse(os.path.exists(path))
         base.touch(path)
         self.assertTrue(os.path.exists(path))
         base.touch(path)
         self.assertTrue(os.path.exists(path))
     finally:
         base.remove(path)
Пример #4
0
    def testPersistentTaskRunCreateFile(self):
        """Running a persistent task with success creates the output file."""

        class PTask(workflow.LocalFSPersistentTask):
            def run(self):
                return self.SUCCESS

        flow = workflow.Workflow()
        file_path = base.random_alpha_num_word(16)
        try:
            task = PTask(output_file_path=file_path, task_id="task", workflow=flow)
            flow.build()
            self.assertFalse(os.path.exists(file_path))
            self.assertTrue(flow.process())
            self.assertTrue(os.path.exists(file_path))
        finally:
            base.remove(file_path)
Пример #5
0
    def testPersistentTaskRunNoFile(self):
        """Persistent task runs if output file does not exist.

        No output file is created if task fails.
        """

        class PTask(workflow.LocalFSPersistentTask):
            def run(self):
                return self.FAILURE

        flow = workflow.Workflow()
        file_path = base.random_alpha_num_word(16)
        task = PTask(output_file_path=file_path, task_id="task", workflow=flow)
        flow.build()
        self.assertFalse(os.path.exists(file_path))
        self.assertFalse(flow.process())
        self.assertFalse(os.path.exists(file_path))
Пример #6
0
    def testPersistentTaskNoRunIfFile(self):
        """Persistent task does not run if output file already exists."""

        class PTask(workflow.LocalFSPersistentTask):
            def run(self):
                return self.FAILURE

        flow = workflow.Workflow()
        file_path = base.random_alpha_num_word(16)
        base.touch(file_path)
        try:
            task = PTask(output_file_path=file_path, task_id="task", workflow=flow)
            flow.build()
            self.assertTrue(os.path.exists(file_path))
            self.assertTrue(flow.process())
            self.assertTrue(os.path.exists(file_path))
        finally:
            base.remove(file_path)
Пример #7
0
    def testPersistentTaskRunCreateFile(self):
        """Running a persistent task with success creates the output file."""
        class PTask(workflow.LocalFSPersistentTask):
            def run(self):
                return self.SUCCESS

        flow = workflow.Workflow()
        file_path = base.random_alpha_num_word(16)
        try:
            task = PTask(
                output_file_path=file_path,
                task_id='task',
                workflow=flow,
            )
            flow.build()
            self.assertFalse(os.path.exists(file_path))
            self.assertTrue(flow.process())
            self.assertTrue(os.path.exists(file_path))
        finally:
            base.remove(file_path)
Пример #8
0
    def testPersistentTaskRunNoFile(self):
        """Persistent task runs if output file does not exist.

        No output file is created if task fails.
        """
        class PTask(workflow.LocalFSPersistentTask):
            def run(self):
                return self.FAILURE

        flow = workflow.Workflow()
        file_path = base.random_alpha_num_word(16)
        task = PTask(
            output_file_path=file_path,
            task_id='task',
            workflow=flow,
        )
        flow.build()
        self.assertFalse(os.path.exists(file_path))
        self.assertFalse(flow.process())
        self.assertFalse(os.path.exists(file_path))
Пример #9
0
    def testPersistentTaskNoRunIfFile(self):
        """Persistent task does not run if output file already exists."""
        class PTask(workflow.LocalFSPersistentTask):
            def run(self):
                return self.FAILURE

        flow = workflow.Workflow()
        file_path = base.random_alpha_num_word(16)
        base.touch(file_path)
        try:
            task = PTask(
                output_file_path=file_path,
                task_id='task',
                workflow=flow,
            )
            flow.build()
            self.assertTrue(os.path.exists(file_path))
            self.assertTrue(flow.process())
            self.assertTrue(os.path.exists(file_path))
        finally:
            base.remove(file_path)