Skip to content

Commit

Permalink
Added information about excludes to export goal
Browse files Browse the repository at this point in the history
The IntelliJ plugin will use this information for better classpath construction.

Testing Done:
https://travis-ci.org/fkorotkov/pants/builds/62959733

Bugs closed: 1565

Reviewed at https://rbcommons.com/s/twitter/r/2238/
  • Loading branch information
fkorotkov authored and fkorotkov committed May 18, 2015
1 parent 9f26b09 commit 7fc1b3c
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 2 deletions.
14 changes: 13 additions & 1 deletion src/python/pants/backend/project_info/tasks/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from pants.backend.jvm.ivy_utils import IvyModuleRef
from pants.backend.jvm.targets.jar_library import JarLibrary
from pants.backend.jvm.targets.jvm_app import JvmApp
from pants.backend.jvm.targets.jvm_target import JvmTarget
from pants.backend.jvm.targets.scala_library import ScalaLibrary
from pants.backend.project_info.tasks.projectutils import get_jar_infos
from pants.base.build_environment import get_buildroot
Expand All @@ -41,7 +42,7 @@ class Export(ConsoleTask):
#
# Note format changes in src/python/pants/docs/export.md and update the Changelog section.
#
DEFAULT_EXPORT_VERSION='1.0.0'
DEFAULT_EXPORT_VERSION='1.0.1'

class SourceRootTypes(object):
"""Defines SourceRoot Types Constants"""
Expand All @@ -67,6 +68,14 @@ def _jar_id(jar):
else:
return '{0}:{1}'.format(jar.org, jar.name)

@staticmethod
def _exclude_id(jar):
"""Create a string identifier for the Exclude key.
:param Exclude jar: key for an excluded jar
:returns: String representing the key as a maven coordinate
"""
return '{0}:{1}'.format(jar.org, jar.name)

@staticmethod
def _address(address):
"""
Expand Down Expand Up @@ -172,6 +181,9 @@ def get_transitive_jars(jar_lib):
info['targets'].append(self._address(dep.address))
process_target(dep)

if isinstance(current_target, JvmTarget):
info['excludes'] = [self._exclude_id(exclude) for exclude in current_target.excludes]

info['roots'] = map(lambda (source_root, package_prefix): {
'source_root': source_root,
'package_prefix': package_prefix
Expand Down
4 changes: 4 additions & 0 deletions src/python/pants/docs/export.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ The following is an abbreviated export file from the command in the pants repo:

# Export Format Changes

## 1.0.1

Information about excludes

## 1.0.0

Initial Version
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ def test_version(self):
result = get_json(self.execute_console_task(
targets=[self.target('project_info:first')]
))
self.assertEqual('1.0.0', result['version'])
self.assertEqual('1.0.1', result['version'])

def test_sources(self):
result = get_json(self.execute_console_task(
Expand Down Expand Up @@ -237,6 +237,7 @@ def test_jvm_target(self):
))
jvm_target = result['targets']['project_info:jvm_target']
expected_jmv_target = {
'excludes': [],
'globs': {'globs': ['project_info/this/is/a/source/Foo.scala',
'project_info/this/is/a/source/Bar.scala']},
'libraries': ['org.apache:apache-jar:12.12.2012'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,16 @@ def test_export_jar_path_with_excludes(self):
test_target = 'testprojects/src/java/org/pantsbuild/testproject/exclude:foo'
json_data = self.run_export(test_target, workdir, ['resolve'])
self.assertIsNone(json_data.get('libraries').get('com.typesafe.sbt:incremental-compiler:0.13.7'))
foo_target = json_data.get('targets').get('testprojects/src/java/org/pantsbuild/testproject/exclude:foo')
self.assertTrue('com.typesafe.sbt:incremental-compiler' in foo_target.get('excludes'))

def test_export_jar_path_with_excludes_soft(self):
with temporary_dir(root_dir=self.workdir_root()) as workdir:
test_target = 'testprojects/src/java/org/pantsbuild/testproject/exclude:'
json_data = self.run_export(test_target, workdir, ['resolve', '--resolve-ivy-soft-excludes'])
self.assertIsNotNone(json_data.get('libraries').get('com.martiansoftware:nailgun-server:0.9.1'))
foo_target = json_data.get('targets').get('testprojects/src/java/org/pantsbuild/testproject/exclude:foo')
self.assertTrue('com.typesafe.sbt:incremental-compiler' in foo_target.get('excludes'))

def test_export_jar_path(self):
with temporary_dir(root_dir=self.workdir_root()) as workdir:
Expand Down

0 comments on commit 7fc1b3c

Please sign in to comment.