Exemplo n.º 1
0
    def run(self, args):
        local_repo = self.flags.local_repo
        if local_repo is None:
            wkspc_root = workspace.find_workspace_root(os.getcwd())
            if wkspc_root is None:
                logging.warn("Not running within a workspace?")
                local_repo = os.path.join(os.environ["HOME"], ".m2", "repository")
            else:
                logging.info("Running in workspace %r", wkspc_root)
                local_repo = os.path.join(wkspc_root, "output", "maven_repository")

        command = [
            "mvn",
            "-Dmaven.repo.local=%s" % local_repo,
        ] + list(args)

        return subprocess.call(args=command)
Exemplo n.º 2
0
    def run(self, args):
        # Identify action to run:
        action_name = self.flags.do
        if (action_name is None) and (len(args) >= 1) and (args[0] in ACTIONS):
            action_name, args = args[0], args[1:]
        action_class = ACTIONS.get(action_name, Help)

        # Short-circuit action that do not require a workspace:
        if not issubclass(action_class, Action):
            action = action_class(parent_flags=self.flags)
            return action(args)

        # Locate workspace:
        wkspc = self.flags.workspace
        if wkspc is None:
            wkspc = os.getcwd()
        resolved_wkspc = workspace.find_workspace_root(path=wkspc)
        assert (resolved_wkspc
                is not None), ('Cannot locate workspace for %s.' % wkspc)
        wkspc = resolved_wkspc
        logging.info('Using workspace: %r' % wkspc)

        repo = None
        if self.flags.maven_repositories is not None:
            remotes = self.flags.maven_repositories.split(",")
            wkspc_maven_repo = os.path.join(wkspc, "output",
                                            "maven_repository")
            remotes.insert(0, "file://" + wkspc_maven_repo)

            # Remote Maven repositories:
            repo = maven_repo.MavenRepository(
                local=wkspc_maven_repo,
                remotes=remotes,
            )

        # Run action in configured workspace:
        wkspc = workspace.Workspace(
            path=wkspc,
            maven_repository=repo,
        )

        tool = action_class(workspace=wkspc, parent_flags=self.flags)
        return tool(args)
Exemplo n.º 3
0
    def run(self, args):
        # Identify action to run:
        action_name = self.flags.do
        if (action_name is None) and (len(args) >= 1) and (args[0] in ACTIONS):
            action_name, args = args[0], args[1:]
        action_class = ACTIONS.get(action_name, Help)

        # Short-circuit action that do not require a workspace:
        if not issubclass(action_class, Action):
            action = action_class(parent_flags=self.flags)
            return action(args)

        # Locate workspace:
        wkspc = self.flags.workspace
        if wkspc is None:
            wkspc = os.getcwd()
        resolved_wkspc = workspace.find_workspace_root(path=wkspc)
        assert (resolved_wkspc is not None), ('Cannot locate workspace for %s.' % wkspc)
        wkspc = resolved_wkspc
        logging.info('Using workspace: %r' % wkspc)

        repo = None
        if self.flags.maven_repositories is not None:
            remotes = self.flags.maven_repositories.split(",")
            wkspc_maven_repo = os.path.join(wkspc, "output", "maven_repository")
            remotes.insert(0, "file://" + wkspc_maven_repo)

            # Remote Maven repositories:
            repo = maven_repo.MavenRepository(
                local=wkspc_maven_repo,
                remotes=remotes,
            )

        # Run action in configured workspace:
        wkspc = workspace.Workspace(
            path=wkspc,
            maven_repository=repo,
        )

        tool = action_class(workspace=wkspc, parent_flags=self.flags)
        return tool(args)
Exemplo n.º 4
0
    def run(self, args):
        action = self.flags.do
        if (action is None) and (len(args) > 0):
            action, args = args[0], args[1:]
        if action is None:
            action = "classpath"
        assert (action is not None), ("Must specify an action to perform, eg. 'classpath'.")

        local_repo = self.flags.maven_local
        if local_repo == ":wkspc:":
            wkspc = workspace.find_workspace_root(path=os.getcwd())
            if wkspc is not None:
                local_repo = os.path.join(wkspc, "output", "maven_repository")
                log.info("Using workspace local repo {!r}", local_repo)
            else:
                local_repo = os.path.join(os.environ["HOME"], ".m2", "repository")
                log.info("No workspace found, using global repo {!r}", local_repo)
        assert os.path.exists(local_repo), \
            "Maven local repository not found: {!r}".format(local_repo)

        self._repo = maven_repo.MavenRepository(
            local = local_repo,
            remotes = self.flags.maven_remotes.split(","),
            exclusions = frozenset(self.flags.maven_remote_exclusions.split(",")),
        )

        self._scanner = maven_loader.ArtifactScanner(
            repo=self.repo,
            fetch_content=self.flags.fetch,
            force_unresolved=True,
        )

        targets = list(self.flags.targets.split(",")) + list(args)
        targets = list(filter(None, targets))
        target_artifacts = map(artifact.parse_artifact, targets)

        exclusions = self.flags.exclusions.split(",")
        exclusions = filter(None, exclusions)
        exclusion_artifacts = frozenset(map(artifact.parse_artifact_name, exclusions))

        deps = list()
        for target_artifact in target_artifacts:
            dep = maven_wrapper.Dependency(
                artifact=target_artifact,
                scope=self.flags.scope,
                exclusions=exclusion_artifacts,
            )
            deps.append(dep)

        log.debug("Scanning dependencies: {!r}", deps)
        classpath = self._scanner.scan(deps)

        list_file_path = self.flags.list_file
        if list_file_path is None:
            list_file_path = '/dev/null'
        with open(list_file_path, "wt") as ofile:
            self._scanner.write_dep_list(output=ofile)

        if action == "classpath":
            print(":".join(sorted(classpath)))

        elif action == "resolve":
            for artf, dep_chains in sorted(self._scanner.versions.items()):
                chain = dep_chains[0]
                selected = chain[0]
                print(selected.artifact)

        elif action == "explain":
            self._scanner.explain(artifact.parse_artifact_name(self.flags.explain))

        else:
            raise Error("Invalid action: {!r}".format(action))
Exemplo n.º 5
0
    def run(self, args):
        artifacts = list()
        if self.flags.artifacts is not None:
            artifacts.extend(self.flags.artifacts.split(","))
        if len(args) > 0:
            artifacts.extend(args)
            args = []
        artifacts = list(map(artifact.parse_artifact, artifacts))

        exclusions = tuple()
        if self.flags.exclusions is not None:
            exclusions = self.flags.exclusions.split(",")
            exclusions = filter(None, exclusions)
            exclusions = map(artifact.parse_artifact, exclusions)
            exclusions = frozenset(exclusions)

        assert (len(args) == 0
                ), "Unexpected command-line arguments: {!r}".format(args)

        # --------------------

        local_repo = self.flags.local_repo
        if local_repo == ":wkspc:":
            wkspc = workspace.find_workspace_root(path=os.getcwd())
            if wkspc is None:
                local_repo = os.path.join(os.environ["HOME"], ".m2",
                                          "repository")
                log.info("No workspace found, using global repo {!r}",
                         local_repo)
            else:
                local_repo = os.path.join(wkspc, "output", "maven_repository")
                log.info("Using workspace local repo {!r}", local_repo)
        assert os.path.exists(local_repo), \
            "Maven local repository not found: {!r}".format(local_repo)

        maven_remotes = self.flags.maven_remotes.split(",")
        repo = maven_repo.MavenRepository(local=local_repo,
                                          remotes=maven_remotes)

        # --------------------

        assert (self.flags.output is not None) and (len(self.flags.output) > 0), \
            "Must specify output path with --output=/path/to/java-binary"
        if self.flags.overwrite and os.path.exists(self.flags.output):
            os.remove(self.flags.output)

        # --------------------

        scanner = maven_loader.ArtifactScanner(repo=repo, fetch_content=True)
        deps = []
        for artf in artifacts:
            dep = maven_wrapper.Dependency(
                artifact=artf,
                scope=self.flags.scope,
                exclusions=exclusions,
            )
            deps.append(dep)
        scanner.scan(deps)
        assert (len(scanner.errors) == 0), \
            "{:d} errors while resolving Maven dependencies".format(len(scanner.errors))

        artifacts = list()
        for artf, dep_chains in scanner.versions.items():
            dep_chain = dep_chains[0]
            dep = dep_chain[0]
            artifacts.append(dep.artifact)

        # --------------------

        linker = java_linker.JavaLinker(
            output_path=self.flags.output,
            maven_repo=repo,
        )
        try:
            linker.link(
                artifacts=artifacts,
                main_class=self.flags.main_class,
            )
        finally:
            linker.close()

        return os.EX_OK
Exemplo n.º 6
0
    def run(self, args):
        action = self.flags.do
        if (action is None) and (len(args) > 0):
            action, args = args[0], args[1:]
        if action is None:
            action = "classpath"
        assert (action is not None), (
            "Must specify an action to perform, eg. 'classpath'.")

        local_repo = self.flags.maven_local
        if local_repo == ":wkspc:":
            wkspc = workspace.find_workspace_root(path=os.getcwd())
            if wkspc is not None:
                local_repo = os.path.join(wkspc, "output", "maven_repository")
                log.info("Using workspace local repo {!r}", local_repo)
            else:
                local_repo = os.path.join(os.environ["HOME"], ".m2",
                                          "repository")
                log.info("No workspace found, using global repo {!r}",
                         local_repo)
        assert os.path.exists(local_repo), \
            "Maven local repository not found: {!r}".format(local_repo)

        self._repo = maven_repo.MavenRepository(
            local=local_repo,
            remotes=self.flags.maven_remotes.split(","),
            exclusions=frozenset(
                self.flags.maven_remote_exclusions.split(",")),
        )

        self._scanner = maven_loader.ArtifactScanner(
            repo=self.repo,
            fetch_content=self.flags.fetch,
            force_unresolved=True,
        )

        targets = list(self.flags.targets.split(",")) + list(args)
        targets = list(filter(None, targets))
        target_artifacts = map(artifact.parse_artifact, targets)

        exclusions = self.flags.exclusions.split(",")
        exclusions = filter(None, exclusions)
        exclusion_artifacts = frozenset(
            map(artifact.parse_artifact_name, exclusions))

        deps = list()
        for target_artifact in target_artifacts:
            dep = maven_wrapper.Dependency(
                artifact=target_artifact,
                scope=self.flags.scope,
                exclusions=exclusion_artifacts,
            )
            deps.append(dep)

        log.debug("Scanning dependencies: {!r}", deps)
        classpath = self._scanner.scan(deps)

        list_file_path = self.flags.list_file
        if list_file_path is None:
            list_file_path = '/dev/null'
        with open(list_file_path, "wt") as ofile:
            self._scanner.write_dep_list(output=ofile)

        if action == "classpath":
            print(":".join(sorted(classpath)))

        elif action == "resolve":
            for artf, dep_chains in sorted(self._scanner.versions.items()):
                chain = dep_chains[0]
                selected = chain[0]
                print(selected.artifact)

        elif action == "explain":
            self._scanner.explain(
                artifact.parse_artifact_name(self.flags.explain))

        else:
            raise Error("Invalid action: {!r}".format(action))
Exemplo n.º 7
0
    def run(self, args):
        artifacts = list()
        if self.flags.artifacts is not None:
            artifacts.extend(self.flags.artifacts.split(","))
        if len(args) > 0:
            artifacts.extend(args)
            args = []
        artifacts = list(map(artifact.parse_artifact, artifacts))

        exclusions = tuple()
        if self.flags.exclusions is not None:
            exclusions = self.flags.exclusions.split(",")
            exclusions = filter(None, exclusions)
            exclusions = map(artifact.parse_artifact, exclusions)
            exclusions = frozenset(exclusions)

        assert (len(args) == 0), "Unexpected command-line arguments: {!r}".format(args)

        # --------------------

        local_repo = self.flags.local_repo
        if local_repo == ":wkspc:":
            wkspc = workspace.find_workspace_root(path=os.getcwd())
            if wkspc is None:
                local_repo = os.path.join(os.environ["HOME"], ".m2", "repository")
                log.info("No workspace found, using global repo {!r}", local_repo)
            else:
                local_repo = os.path.join(wkspc, "output", "maven_repository")
                log.info("Using workspace local repo {!r}", local_repo)
        assert os.path.exists(local_repo), \
            "Maven local repository not found: {!r}".format(local_repo)

        maven_remotes = self.flags.maven_remotes.split(",")
        repo = maven_repo.MavenRepository(local=local_repo, remotes=maven_remotes)

        # --------------------

        assert (self.flags.output is not None) and (len(self.flags.output) > 0), \
            "Must specify output path with --output=/path/to/java-binary"
        if self.flags.overwrite and os.path.exists(self.flags.output):
            os.remove(self.flags.output)

        # --------------------

        scanner = maven_loader.ArtifactScanner(repo=repo, fetch_content=True)
        deps = []
        for artf in artifacts:
            dep = maven_wrapper.Dependency(
                artifact=artf,
                scope=self.flags.scope,
                exclusions=exclusions,
            )
            deps.append(dep)
        scanner.scan(deps)
        assert (len(scanner.errors) == 0), \
            "{:d} errors while resolving Maven dependencies".format(len(scanner.errors))

        artifacts = list()
        for artf, dep_chains in scanner.versions.items():
            dep_chain = dep_chains[0]
            dep = dep_chain[0]
            artifacts.append(dep.artifact)

        # --------------------

        linker = java_linker.JavaLinker(
            output_path=self.flags.output,
            maven_repo=repo,
        )
        try:
            linker.link(
                artifacts=artifacts,
                main_class=self.flags.main_class,
            )
        finally:
            linker.close()

        return os.EX_OK