Skip to content

Commit

Permalink
Revert to 720e64f
Browse files Browse the repository at this point in the history
  • Loading branch information
dylanShark committed Apr 1, 2021
1 parent 7c6e838 commit 311dc71
Show file tree
Hide file tree
Showing 19 changed files with 129 additions and 513 deletions.
15 changes: 0 additions & 15 deletions BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ py_test(
py_test(
name = "buildpomtest",
srcs = ["common/code.py",
"common/common.py",
"common/mdfiles.py",
"common/pomgenmode.py",
"common/version.py",
Expand Down Expand Up @@ -209,7 +208,6 @@ py_test(
py_test(
name = "pomparsertest",
srcs = ["common/logger.py",
"common/common.py",
"crawl/dependency.py",
"crawl/pomparser.py",
"tests/pomparsertest.py"],
Expand All @@ -218,19 +216,6 @@ py_test(
python_version = python_version,
)

py_test(
name = "pompropertiestest",
srcs = ["common/common.py",
"common/logger.py",
"crawl/dependency.py",
"crawl/pomparser.py",
"crawl/pomproperties.py",
"tests/pompropertiestest.py"],
imports = ["."],
size = "small",
python_version = python_version,
)

py_test(
name = "workspacetest",
srcs = [":pomgen_files",
Expand Down
14 changes: 0 additions & 14 deletions common/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@

import os

INDENT = 4 # spaces

def get_repo_root(repo_root=None):
if repo_root is None:
repo_root = os.getcwd()
Expand All @@ -29,15 +27,3 @@ def get_repo_root(repo_root=None):
def _has_workspace_file(repo_root):
return os.path.exists(os.path.join(repo_root, "WORKSPACE"))

def xml(content, element, indent, value=None, close_element=False):
"""
Helper method used to generated xml.
"""
if value is None:
if close_element:
return "%s%s</%s>%s" % (content, ' '*(indent - INDENT), element, os.linesep), indent - INDENT
else:
return "%s%s<%s>%s" % (content, ' '*indent, element, os.linesep), indent + INDENT
else:
return "%s%s<%s>%s</%s>%s" % (content, ' '*indent, element, value, element, os.linesep), indent

22 changes: 1 addition & 21 deletions config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,6 @@ def artifact(option, dflt, valid_values=None):
cfg = Config(
pom_template_path_and_content=_read_files(repo_root, pom_template_p)[0],
maven_install_paths=gen("maven_install_paths", ("maven_install.json",)),
version_property_prefix=gen("version_property_prefix", ""),
version_property_suffix=gen("version_property_suffix", ""),
excluded_dependency_paths=crawl("excluded_dependency_paths", ()),
excluded_src_relpaths=artifact("excluded_relative_paths", ("src/test",)),
excluded_src_file_names=artifact("excluded_filenames", (".gitignore",)),
Expand Down Expand Up @@ -112,19 +110,15 @@ class Config:
def __init__(self,
pom_template_path_and_content=("",""),
maven_install_paths=(),
version_property_prefix="",
version_property_suffix="",
excluded_dependency_paths=(),
excluded_src_relpaths=(),
excluded_src_file_names=(),
excluded_src_file_extensions=(),
transitives_versioning_mode="semver"):

# general
self.pom_template_path_and_content = pom_template_path_and_content
self.pom_template_path_and_content=pom_template_path_and_content
self.maven_install_paths = _to_tuple(maven_install_paths)
self._version_property_prefix = version_property_prefix
self._version_property_suffix = version_property_suffix

# crawler
self.excluded_dependency_paths = _add_pathsep(_to_tuple(excluded_dependency_paths))
Expand All @@ -148,20 +142,6 @@ def all_src_exclusions(self):
self.excluded_src_file_names,
self.excluded_src_file_extensions)

@property
def version_property_prefix(self):
"""
Convenience method that returns the prefix to use for generated version properties.
"""
return self._version_property_prefix

@property
def version_property_suffix(self):
"""
Convenience method that returns the suffix to use for generated version properties.
"""
return self._version_property_suffix

def __str__(self):
return """[general]
pom_template_path=%s
Expand Down
1 change: 0 additions & 1 deletion config/pom_template.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
#{dependency_management_version_properties}
</properties>

#{dependencies}
Expand Down
223 changes: 80 additions & 143 deletions crawl/pom.py

Large diffs are not rendered by default.

40 changes: 3 additions & 37 deletions crawl/pomparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
from collections import defaultdict
from crawl import dependency
import os
from common import common
try:
from lxml import etree
except ImportError as ex:
Expand All @@ -24,7 +23,7 @@

# this is the indentation used when writing out pom content, including content
# for pom templates
_INDENT = common.INDENT # spaces
INDENT = 4 # spaces

def format_for_comparison(pom_content):
"""
Expand All @@ -36,7 +35,6 @@ def format_for_comparison(pom_content):
parser = etree.XMLParser(remove_blank_text=True)
tree = etree.XML(pom_content.encode().strip(), parser=parser)


# remove <description>, if it exists
description_el = tree.find(XML_NS + "description")
if description_el is not None:
Expand All @@ -58,46 +56,14 @@ def indent_xml(xml_content, indent):
line = line.strip()
handled_indent = False
if line.startswith("</"):
current_indent -= _INDENT
current_indent -= INDENT
handled_indent = True
indented_xml += (' '*current_indent) + line + os.linesep
if not handled_indent and line.startswith("<") and not "</" in line:
current_indent += _INDENT
current_indent += INDENT
handled_indent = True
return indented_xml

class ParsedProperty:

def __init__(self, property_name, property_value):
self._property_name = property_name
self._property_value = property_value

def get_property_name(self):
return self._property_name

def get_property_value(self):
return self._property_value

def parse_version_properties(pom_content):
"""
Parses the <properties> section in the specified pom_content.
Returns a list of ParsedProperty instances.
"""

parser = etree.XMLParser(remove_blank_text=True)
tree = etree.XML(pom_content.encode().strip(), parser=parser)
all_props = tree.xpath('/properties/*')

version_properties = []
for el in all_props:
property_name = el.tag
if (property_name.endswith(".version")):
property_value = el.text
version_properties.append(ParsedProperty(property_name, property_value))

return version_properties

class ParsedDependencies:

def __init__(self, dependencies=set(), dependency_to_exclusions=defaultdict(list), dependency_to_str_repr={}):
Expand Down
60 changes: 0 additions & 60 deletions crawl/pomproperties.py

This file was deleted.

4 changes: 1 addition & 3 deletions crawl/workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,13 @@ class Workspace:
"""

def __init__(self, repo_root_path, excluded_dependency_paths,
source_exclusions,
property_prefix_suffix,
source_exclusions,
maven_install_info,
pom_content,
verbose=False):
self.repo_root_path = repo_root_path
self.excluded_dependency_paths = excluded_dependency_paths
self.source_exclusions = source_exclusions
self.property_prefix_suffix = property_prefix_suffix
self.pom_content = pom_content
self.verbose = verbose
self.dependency_metadata = dependencymd.DependencyMetadata()
Expand Down
1 change: 0 additions & 1 deletion misc/extdeps_pomgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ def main(args):
ws = workspace.Workspace(repo_root,
cfg.excluded_dependency_paths,
cfg.all_src_exclusions,
(cfg.version_property_prefix, cfg.version_property_suffix),
mvn_install_info,
pomcontent.NOOP)
group_id = "all_ext_deps_group" if args.group_id is None else args.group_id
Expand Down
1 change: 0 additions & 1 deletion pomgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ def main(args):
ws = workspace.Workspace(repo_root,
cfg.excluded_dependency_paths,
cfg.all_src_exclusions,
(cfg.version_property_prefix, cfg.version_property_suffix),
mvn_install_info,
pom_content)
packages = argsupport.get_all_packages(repo_root, args.package)
Expand Down
1 change: 0 additions & 1 deletion query.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ def _matches_filter(maven_artifact, all_filters):
ws = workspace.Workspace(repo_root,
cfg.excluded_dependency_paths,
cfg.all_src_exclusions,
(cfg.version_property_prefix, cfg.version_property_suffix),
mvn_install_info,
pomcontent.NOOP,
args.verbose)
Expand Down
1 change: 1 addition & 0 deletions tests/buildpomupdatetest.py
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,7 @@ def test_add_pom_generation_mode_to_BUILD_pom(self):

with open(os.path.join(pack1_path, "MVN-INF", "BUILD.pom"), "r") as f:
content = f.read()
print(content)
self.assertIn('maven_artifact(', content)
self.assertIn(' group_id = "p1g"', content)
self.assertIn(' artifact_id = "p1a"', content)
Expand Down
2 changes: 1 addition & 1 deletion tests/crawlertest.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def setUp(self):
self.cwd = os.getcwd()
os.chdir(self.repo_root_path)
ws = workspace.Workspace(self.repo_root_path,
[], exclusions.src_exclusions(), ("",""),
[], exclusions.src_exclusions(),
maven_install_info=maveninstallinfo.NOOP,
pom_content=pomcontent.NOOP)
self.crawler = crawler.Crawler(ws, pom_template="")
Expand Down
8 changes: 4 additions & 4 deletions tests/crawlertest_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def test_default_package_ref(self):
self._add_artifact(repo_root_path, "lib/a2", "template", deps=["//lib/a1"])

ws = workspace.Workspace(repo_root_path, [],
exclusions.src_exclusions(), ("", ""),
exclusions.src_exclusions(),
maveninstallinfo.NOOP,
pomcontent.NOOP)
crawler = crawlerm.Crawler(ws, pom_template="")
Expand All @@ -63,7 +63,7 @@ def test_default_package_ref_explicit(self):
self._add_artifact(repo_root_path, "lib/a2", "template", deps=["//lib/a1:a1"])

ws = workspace.Workspace(repo_root_path, [],
exclusions.src_exclusions(), ("", ""),
exclusions.src_exclusions(),
maveninstallinfo.NOOP,
pomcontent.NOOP)
crawler = crawlerm.Crawler(ws, pom_template="")
Expand All @@ -86,7 +86,7 @@ def test_non_default_package_ref__not_allowed(self):
self._add_artifact(repo_root_path, "lib/a2", "template", deps=["//lib/a1:foo"])

ws = workspace.Workspace(repo_root_path, [],
exclusions.src_exclusions(), ("", ""),
exclusions.src_exclusions(),
maveninstallinfo.NOOP,
pomcontent.NOOP)
crawler = crawlerm.Crawler(ws, pom_template="")
Expand All @@ -108,7 +108,7 @@ def test_non_default_package_ref__allowed_for_skip_pom_gen_mode(self):
self._add_artifact(repo_root_path, "lib/a2", "template", deps=["//lib/a1:foo"])

ws = workspace.Workspace(repo_root_path, [],
exclusions.src_exclusions(), ("", ""),
exclusions.src_exclusions(),
maveninstallinfo.NOOP,
pomcontent.NOOP)
crawler = crawlerm.Crawler(ws, pom_template="")
Expand Down
2 changes: 1 addition & 1 deletion tests/crawlerunittest.py
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ def _get_3rdparty_dep(self, artifact_str, name):
def _get_workspace(self):
return workspace.Workspace(repo_root_path="a/b/c",
excluded_dependency_paths=[],
source_exclusions=[], property_prefix_suffix=("", ""),
source_exclusions=[],
maven_install_info=maveninstallinfo.NOOP,
pom_content="",)

Expand Down
1 change: 1 addition & 0 deletions tests/pomgentest.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ def _add_LIBRARY_root(self, package_rel_path):
self._write_file(package_rel_path, "MVN-INF", "LIBRARY.root", "")

def _write_file(self, package_rel_path, rel_path, filename, content):
print(content)
path = os.path.join(self.repo_root_path, package_rel_path, rel_path,
filename)
parent_dir = os.path.dirname(path)
Expand Down
Loading

0 comments on commit 311dc71

Please sign in to comment.