This repository has been archived by the owner on Dec 10, 2020. It is now read-only.
forked from pantsbuild/pants
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Inject an automatic dep on junit for all junit_tests targets.
It's silly to require an explicit dep. This required creating a new "JUnit" subsystem. While there, I moved the junit runner tool to that subsystem, so the runner and the library are in the same place. It's still clunkier than it needs to be to inject deps onto targets, but that's a problem for another time. This change removes the explicit junit dep from one of our examples, to prove that this all works. A subsequent change will remove any other unnecessary explicit deps on junit. Testing Done: CI passes: https://travis-ci.org/pantsbuild/pants/builds/159432189 Reviewed at https://rbcommons.com/s/twitter/r/4228/
- Loading branch information
Showing
15 changed files
with
144 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
# coding=utf-8 | ||
# Copyright 2016 Pants project contributors (see CONTRIBUTORS.md). | ||
# Licensed under the Apache License, Version 2.0 (see LICENSE). | ||
|
||
from __future__ import (absolute_import, division, generators, nested_scopes, print_function, | ||
unicode_literals, with_statement) | ||
|
||
from pants.backend.jvm.subsystems.jvm_tool_mixin import JvmToolMixin | ||
from pants.backend.jvm.subsystems.shader import Shader | ||
from pants.backend.jvm.targets.jar_dependency import JarDependency | ||
from pants.backend.jvm.targets.jar_library import JarLibrary | ||
from pants.build_graph.address import Address | ||
from pants.subsystem.subsystem import Subsystem | ||
from pants.util.memo import memoized_method | ||
|
||
|
||
class JUnit(JvmToolMixin, Subsystem): | ||
options_scope = 'junit' | ||
|
||
LIBRARY_REV = '4.12' | ||
RUNNER_MAIN = 'org.pantsbuild.tools.junit.ConsoleRunner' | ||
|
||
_LIBRARY_JAR = JarDependency(org='junit', name='junit', rev=LIBRARY_REV) | ||
_RUNNER_JAR = JarDependency(org='org.pantsbuild', name='junit-runner', rev='1.0.13') | ||
|
||
@classmethod | ||
def register_options(cls, register): | ||
super(JUnit, cls).register_options(register) | ||
cls.register_jvm_tool(register, | ||
'junit_library', | ||
classpath=[ | ||
cls._LIBRARY_JAR, | ||
]) | ||
|
||
cls.register_jvm_tool(register, | ||
'junit', | ||
classpath=[ | ||
cls._RUNNER_JAR, | ||
], | ||
main=cls.RUNNER_MAIN, | ||
# TODO(John Sirois): Investigate how much less we can get away with. | ||
# Clearly both tests and the runner need access to the same @Test, | ||
# @Before, as well as other annotations, but there is also the Assert | ||
# class and some subset of the @Rules, @Theories and @RunWith APIs. | ||
custom_rules=[ | ||
Shader.exclude_package('junit.framework', recursive=True), | ||
Shader.exclude_package('org.junit', recursive=True), | ||
Shader.exclude_package('org.hamcrest', recursive=True), | ||
Shader.exclude_package('org.pantsbuild.junit.annotations', | ||
recursive=True), | ||
]) | ||
|
||
@memoized_method | ||
def library_spec(self, buildgraph): | ||
"""Returns a target spec for the junit library, useable as a dependency. | ||
:param pants.build_graph.build_graph.BuildGraph buildgraph: buildgraph object. | ||
:return: a target spec | ||
""" | ||
junit_addr = Address.parse(self.get_options().junit_library) | ||
if not buildgraph.contains_address(junit_addr): | ||
buildgraph.inject_synthetic_target(junit_addr, JarLibrary, jars=[self._LIBRARY_JAR], | ||
scope='forced') | ||
return junit_addr.spec | ||
|
||
def runner_classpath(self, context): | ||
"""Returns an iterable of classpath elements for the runner. | ||
""" | ||
return self.tool_classpath_from_products(context.products, 'junit', self.options_scope) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.