Skip to content

Commit 6f77cbe

Browse files
authored
Add a way to skip over dep labels (#150)
1 parent fcbdcdc commit 6f77cbe

File tree

5 files changed

+63
-55
lines changed

5 files changed

+63
-55
lines changed

README.md

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,17 +85,29 @@ pom_template_path=
8585
# Example value: tools/maven_install/*.json,another/path/to/mvn_install.json,
8686
maven_install_paths=
8787
88+
8889
[crawler]
89-
# A list of path prefixes that are not crawled by pomgen. Any dependency
90-
# that starts with one of the strings returned by this method is skipped
91-
# and not processed (and not included in the generated pom.xml).
90+
# A list of path prefixes that are not crawled by pomgen. Any source dependency
91+
# that starts with one of the specified paths is skipped and not processed
92+
# (and not included in the generated pom.xml).
9293
# These dependencies are similar to Maven's "provided" scope: if they are
9394
# needed at runtime, it is expected that the final runtime assembly
9495
# contains them.
95-
# Default value: ""
96+
# Default value: []
9697
# Example value: projects/protos/,
9798
excluded_dependency_paths=
9899
100+
# A list of labels that are skipped over by pomgen. Any dependency
101+
# that matches one of the specified strings is skipped and not processed
102+
# (and not included in the generated pom.xml).
103+
# These dependencies are similar to Maven's "provided" scope: if they are
104+
# needed at runtime, it is expected that the final runtime assembly
105+
# contains them.
106+
# Default value: []
107+
# Example value: @maven//:com_google_guava_guava,
108+
excluded_dependency_labels=
109+
110+
99111
[artifact]
100112
# Global toggle for change detection (docs/change_detection.md)
101113
# Default value: True

config/config.py

Lines changed: 11 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -5,56 +5,13 @@
55
For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
66
77
8-
Responsible for loading a config file of the following format:
9-
10-
[general]
11-
# Path to the pom template, used when generating pom.xml files for jar artifacts
12-
pom_template_path=
13-
# A list of paths to pinned maven_install json files.
14-
# Globs are supported, for example: tools/maven_install/*.json
15-
maven_install_paths=maven_install.json,
16-
17-
[crawler]
18-
# A list of path prefixes that are not crawled by pomgen. Any dependency
19-
# that starts with one of the strings returned by this method is skipped
20-
# and not processed (and not included in the generated pom.xml).
21-
# These dependencies are similar to Maven's "provided" scope: if they are
22-
# needed at runtime, it is expected that the final runtime assembly
23-
# contains them.
24-
excluded_dependency_paths=projects/protos/,
25-
26-
[artifact]
27-
# Globally toggles change detection, the default value is on (True).
28-
# See /docs/change_detection.md
29-
change_detection_enabled=True
30-
31-
# Paths not considered when determining whether an artifact has changed
32-
excluded_relative_paths=src/tests,
33-
34-
# File names not considered when determining whether an artifact has changed
35-
excluded_filenames=.gitignore,
36-
37-
# Ignored file extensions when determining whether an artifact has changed
38-
excluded_extensions=.md,
39-
40-
# query versioning mode for proposed next versions
41-
transitives_versioning_mode=semver|counter
42-
43-
# The classifier used for all jars artifacts assembled by pomgen
44-
# By default, no classifier is set
45-
# The same value can also be specified by setting the environment variable
46-
# POMGEN_JAR_CLASSIFIER - the environment variable takes precedence over the
47-
# value set in this cfg file
48-
jar_classifier=
8+
Responsible for loading a config file. For the config file format, see /README.md#configuration.
499
"""
5010

51-
try:
52-
import ConfigParser as configparser
53-
except ImportError:
54-
import configparser
5511

56-
from config import exclusions
5712
from common import logger
13+
from config import exclusions
14+
import configparser
5815
import os
5916

6017

@@ -92,6 +49,7 @@ def artifact(option, dflt, valid_values=None):
9249
pom_template_path_and_content=_read_files(repo_root, pom_template_p)[0],
9350
maven_install_paths=gen("maven_install_paths", ("maven_install.json",)),
9451
excluded_dependency_paths=crawl("excluded_dependency_paths", ()),
52+
excluded_dependency_labels=crawl("excluded_dependency_labels", ()),
9553
excluded_src_relpaths=artifact("excluded_relative_paths", ("src/test",)),
9654
excluded_src_file_names=artifact("excluded_filenames", (".gitignore",)),
9755
excluded_src_file_extensions=artifact("excluded_extensions", (".md",)),
@@ -124,6 +82,7 @@ def __init__(self,
12482
pom_template_path_and_content=("",""),
12583
maven_install_paths=(),
12684
excluded_dependency_paths=(),
85+
excluded_dependency_labels=(),
12786
excluded_src_relpaths=(),
12887
excluded_src_file_names=(),
12988
excluded_src_file_extensions=(),
@@ -137,6 +96,7 @@ def __init__(self,
13796

13897
# crawler
13998
self.excluded_dependency_paths = _add_pathsep(_to_tuple(excluded_dependency_paths))
99+
self.excluded_dependency_labels = _to_tuple(excluded_dependency_labels)
140100

141101
# artifact
142102
self.excluded_src_relpaths = _add_pathsep(_to_tuple(excluded_src_relpaths))
@@ -178,21 +138,25 @@ def __str__(self):
178138
179139
[crawler]
180140
excluded_dependency_paths=%s
141+
excluded_dependency_labels=%s
181142
182143
[artifact]
183144
excluded_relative_paths=%s
184145
excluded_filenames=%s
185146
excluded_extensions=%s
186147
transitives_versioning_mode=%s
187148
jar_artifact_classifier=%s
149+
change_detection_enabled=%s
188150
""" % (self.pom_template_path_and_content[0],
189151
self.maven_install_paths,
190152
self.excluded_dependency_paths,
153+
self.excluded_dependency_labels,
191154
self.excluded_src_relpaths,
192155
self.excluded_src_file_names,
193156
self.excluded_src_file_extensions,
194157
self.transitives_versioning_mode,
195-
self.jar_artifact_classifier)
158+
self.jar_artifact_classifier,
159+
self.change_detection_enabled)
196160

197161

198162
def _to_tuple(thing):

crawl/workspace.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ def __init__(self, repo_root_path, config, maven_install_info,
2424
pom_content, dependency_metadata, verbose=False):
2525
self.repo_root_path = repo_root_path
2626
self.excluded_dependency_paths = config.excluded_dependency_paths
27+
self.excluded_dependency_labels = config.excluded_dependency_labels
2728
self.source_exclusions = config.all_src_exclusions
2829
self.pom_content = pom_content
2930
self.verbose = verbose
@@ -116,6 +117,9 @@ def filter_artifact_producing_packages(self, packages):
116117
return [art_def.bazel_package for art_def in art_defs if art_def.pom_generation_mode.produces_artifact]
117118

118119
def _parse_dep_label(self, dep_label):
120+
if dep_label in self.excluded_dependency_labels:
121+
return None
122+
119123
if dep_label.startswith("@"):
120124
if dep_label not in self._name_to_ext_deps:
121125
print(self._name_to_ext_deps.values())

tests/configtest.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,20 @@ def test_change_detection__disabled(self):
166166

167167
self.assertFalse(cfg.change_detection_enabled)
168168

169+
def test_excluded_labels(self):
170+
repo_root = tempfile.mkdtemp("root")
171+
os.mkdir(os.path.join(repo_root, "config"))
172+
pom_template_path = self._write_file(repo_root, "WORKSPACE", "foo")
173+
pom_template_path = self._write_file(repo_root, "config/pom_template.xml", "foo")
174+
self._write_file(repo_root, ".pomgenrc", """
175+
[crawler]
176+
excluded_dependency_labels= 123 , 444
177+
""")
178+
179+
cfg = config.load(repo_root)
180+
181+
self.assertEquals(("123", "444"), cfg.excluded_dependency_labels)
182+
169183
def test_str(self):
170184
repo_root = tempfile.mkdtemp("root")
171185
pom_template_path = self._write_file(repo_root, "pom_template", "foo")

tests/workspacetest.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
from crawl import git
1818
from crawl import pomcontent
1919
from crawl import workspace
20-
2120
import os
2221
import tempfile
2322
import unittest
@@ -138,6 +137,22 @@ def test_excluded_dependency_paths(self):
138137
self.assertEqual("logback-classic", deps[0].artifact_id)
139138
self.assertEqual("1.2.3", deps[0].version)
140139
self.assertIsNone(deps[0].bazel_package)
140+
141+
def test_excluded_dependency_labels(self):
142+
"""
143+
Verifies that excluded dependency labels are not added to the list of
144+
dependencies.
145+
"""
146+
depmd = dependencym.DependencyMetadata(None)
147+
ws = workspace.Workspace("some/path",
148+
config=self._get_config(excluded_dependency_labels=["@maven//:ch_qos_logback_logback_classic",]),
149+
maven_install_info=self._mocked_mvn_install_info("maven"),
150+
pom_content=pomcontent.NOOP,
151+
dependency_metadata=depmd)
152+
153+
deps = ws.parse_dep_labels(["@maven//:ch_qos_logback_logback_classic"])
154+
155+
self.assertEqual(0, len(deps))
141156

142157
def test_parse_ext_dep_with_reserved_words(self):
143158
"""
@@ -486,9 +501,8 @@ def _write_basic_workspace_file(self, repo_root_path):
486501
with open(workspace_file_path, "w") as f:
487502
f.write(workspace_file)
488503

489-
def _get_config(self, excluded_dependency_paths=[]):
490-
return config.Config(
491-
excluded_dependency_paths=excluded_dependency_paths)
504+
def _get_config(self, **kwargs):
505+
return config.Config(**kwargs)
492506

493507

494508
if __name__ == '__main__':

0 commit comments

Comments
 (0)