Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add dependency parser task for maven #536

Merged
merged 1 commit into from
Mar 1, 2018

Conversation

abs51295
Copy link
Contributor

@abs51295 abs51295 commented Feb 27, 2018

Resolves task 3 of #2326.

@abs51295 abs51295 force-pushed the dependency-parser branch 3 times, most recently from bca96f0 to 6d0d7a1 Compare February 27, 2018 20:56
@centos-ci
Copy link
Collaborator

@abs51295 Your image is available in the registry: docker pull registry.devshift.net/bayesian/cucos-worker:SNAPSHOT-PR-536

1 similar comment
@centos-ci
Copy link
Collaborator

@abs51295 Your image is available in the registry: docker pull registry.devshift.net/bayesian/cucos-worker:SNAPSHOT-PR-536

@centos-ci
Copy link
Collaborator

@abs51295 Your image is available in the registry: docker pull registry.devshift.net/bayesian/cucos-worker:SNAPSHOT-PR-536

@@ -42,13 +42,14 @@ def config():
"/usr/bin/true"])

@classmethod
def clone(cls, url, path, depth=None, branch=None, single_branch=False):
def clone(cls, url, path, timeout, depth=None, branch=None, single_branch=False):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

timeout should be optional

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changing it to keyword parameter with default value of 300 since that's the default for get_command_output as well.

github_repo = arguments.get('github_repo')
github_sha = arguments.get('github_sha')
self._strict_assert(arguments.get('github_repo'))
self._strict_assert(arguments.get('github_sha'))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You want to do the asserts first, i.e.

        self._strict_assert(arguments.get('github_repo'))
        self._strict_assert(arguments.get('github_sha'))
        github_repo = arguments['github_repo']
        github_sha = arguments['github_sha']

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. Missed that.

import re


class DependencyParserTask(BaseTask):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe GithubDependencyTreeTask ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not really sure about that. I think current name is good enough.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, we already have a DependencyParser, which is why I suggested the change, but I'll leave that up to you.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh thanks for pointing that out. Would change it accordingly.

return parse_maven_dependency_tree(f.readlines())


def parse_maven_dependency_tree(dependency_tree):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this and extract_dependencies() be (static) methods of the task class ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure :)

"-DappendOutput=true"]
timed_cmd = TimedCommand(cmd)
timed_cmd.run(timeout=3600)
with open("dependency-tree.txt") as f:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if timed_cmd.status != 0 or not os.path.isfile("dependency-tree.txt"):
    err="mvn dependency:tree failed"
    self.log.error(err)
    raise FatalTaskError(err)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just learned today that it's better to use pathlib instead of os.path. Would be updating accordingly.

group_id=artifact_coords.groupId,
artifact_id=artifact_coords.artifactId,
version=artifact_coords.version
))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be extracted into a function:

def add_name_to_set(matching_line, names_set):
    artifact_coords = MavenCoordinates.from_str(matching_line)
    names_set.add("{group_id}:{artifact_id}:{version}".format(
        group_id=artifact_coords.groupId,
        artifact_id=artifact_coords.artifactId,
        version=artifact_coords.version))

if len(matching_lines_list) == 1:
    add_name_to_set(matching_lines_list[0], set_pom_names)
else:
    for matching_line in matching_lines_list:
        add_name_to_set(matching_line, set_package_names)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense. Would refactor it :)

@centos-ci
Copy link
Collaborator

@abs51295 Your image is available in the registry: docker pull registry.devshift.net/bayesian/cucos-worker:SNAPSHOT-PR-536

@abs51295
Copy link
Contributor Author

[test]

@centos-ci
Copy link
Collaborator

@abs51295 Your image is available in the registry: docker pull registry.devshift.net/bayesian/cucos-worker:SNAPSHOT-PR-536

@centos-ci
Copy link
Collaborator

@abs51295 Your image is available in the registry: docker pull registry.devshift.net/bayesian/cucos-worker:SNAPSHOT-PR-536

@centos-ci
Copy link
Collaborator

@abs51295 Your image is available in the registry: docker pull registry.devshift.net/bayesian/cucos-worker:SNAPSHOT-PR-536

@centos-ci
Copy link
Collaborator

@abs51295 Your image is available in the registry: docker pull registry.devshift.net/bayesian/cucos-worker:SNAPSHOT-PR-536

@abs51295
Copy link
Contributor Author

[test]

2 similar comments
@msrb
Copy link
Member

msrb commented Feb 28, 2018

[test]

@abs51295
Copy link
Contributor Author

[test]

@centos-ci
Copy link
Collaborator

@abs51295 Your image is available in the registry: docker pull registry.devshift.net/bayesian/cucos-worker:SNAPSHOT-PR-536

@abs51295 abs51295 changed the title [WIP] Add dependency parser task for maven Add dependency parser task for maven Mar 1, 2018
@abs51295 abs51295 force-pushed the dependency-parser branch from f051e9f to 5fe8bf0 Compare March 1, 2018 11:19
GithubDependencyTreeTask performs dependency parsing currently for maven ecosystem by using mvn dependency:tree plugin.
@abs51295 abs51295 force-pushed the dependency-parser branch from 5fe8bf0 to 1a4c742 Compare March 1, 2018 11:22
@abs51295
Copy link
Contributor Author

abs51295 commented Mar 1, 2018

[test]

@jpopelka
Copy link
Contributor

jpopelka commented Mar 1, 2018

Would be nice to have some unit test(s), but LGTM in general. Do you want me to merge ?

@abs51295
Copy link
Contributor Author

abs51295 commented Mar 1, 2018

@jpopelka we are planning to add that. Would send a separate PR for that. Please merge this for now. Thanks :)

Copy link
Contributor

@jpopelka jpopelka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@jpopelka jpopelka merged commit fd818d8 into fabric8-analytics:master Mar 1, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants