Skip to content

Commit

Permalink
Merge 9284e55 into f89df72
Browse files Browse the repository at this point in the history
  • Loading branch information
ericzundel committed Oct 1, 2014
2 parents f89df72 + 9284e55 commit 752a540
Show file tree
Hide file tree
Showing 11 changed files with 50 additions and 62 deletions.
4 changes: 2 additions & 2 deletions BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ source_root('tests/python', page, python_library, python_tests, python_test_suit
# Projects used by tests to exercise pants functionality
source_root('testprojects/src/antlr', page, java_antlr_library, python_antlr_library)
source_root('testprojects/src/java', annotation_processor, jvm_binary, java_library, page)
source_root('testprojects/src/protobuf', java_protobuf_library, page)
source_root('testprojects/src/protobuf', java_protobuf_library, jar_library, page)
source_root('testprojects/src/scala', jvm_binary, page, scala_library, benchmark)
source_root('testprojects/src/thrift', java_thrift_library, page, python_thrift_library)

Expand All @@ -25,7 +25,7 @@ source_root('testprojects/tests/scala', page, junit_tests, scala_library, scala_
# Example code intended to demonstrate to end users how to use Pants BUILD configuration
source_root('examples/src/android', page, android_resources, android_binary)
source_root('examples/src/java', annotation_processor, jvm_binary, java_library, page)
source_root('examples/src/protobuf', java_protobuf_library, page)
source_root('examples/src/protobuf', java_protobuf_library, jar_library, page)
source_root('examples/src/python', page, python_binary, python_library, resources)
source_root('examples/src/resources', page, resources, jaxb_library)
source_root('examples/src/scala', jvm_binary, page, scala_library, benchmark)
Expand Down
29 changes: 0 additions & 29 deletions examples/src/java/com/pants/examples/protobuf/BUILD

This file was deleted.

13 changes: 13 additions & 0 deletions examples/src/java/com/pants/examples/protobuf/distance/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright 2014 Pants project contributors (see CONTRIBUTORS.md).
# Licensed under the Apache License, Version 2.0 (see LICENSE).

jvm_binary(name='distance',
basename='protobuf-example',
dependencies=[
'examples/src/protobuf/com/pants/examples/distance',
'3rdparty:protobuf-java',
],
source='ExampleProtobuf.java',
main='com.pants.examples.protobuf.distance.ExampleProtobuf',
)

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2014 Pants project contributors (see CONTRIBUTORS.md).
// Licensed under the Apache License, Version 2.0 (see LICENSE).

package com.pants.examples.protobuf;
package com.pants.examples.protobuf.distance;

import com.pants.examples.distance.Distances;

Expand Down
12 changes: 12 additions & 0 deletions examples/src/java/com/pants/examples/protobuf/imports/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Copyright 2014 Pants project contributors (see CONTRIBUTORS.md).
# Licensed under the Apache License, Version 2.0 (see LICENSE).

jvm_binary(name='imports',
basename='protobuf-imports-example',
dependencies=[
'examples/src/protobuf/com/pants/examples/imports',
'3rdparty:protobuf-java',
],
source='ExampleProtobufImports.java',
main='com.pants.examples.protobuf.imports.ExampleProtobufImports',
)
8 changes: 7 additions & 1 deletion examples/src/protobuf/com/pants/examples/imports/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ java_protobuf_library(name='imports',
sources=['test_imports.proto',],
imports=[
'3rdparty:protobuf-test-import',
jar(org='com.squareup.testing.protolib', name='protolib-test', rev='1.0.1'),
':jars',
],
)

jar_library(name='jars',
dependencies=[
'examples/src/protobuf/com/pants/examples/imports',
]
)
2 changes: 1 addition & 1 deletion examples/tests/java/com/pants/examples/useproto/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ junit_tests(name='useproto',
sources=['UseProtoTest.java',],
dependencies=[
'3rdparty:junit',
'examples/src/java/com/pants/examples/protobuf',
'examples/src/java/com/pants/examples/protobuf/distance',
],
)
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ junit_tests(name='useprotoimports',
sources=['UseImportsTest.java',],
dependencies=[
'3rdparty:junit',
'examples/src/java/com/pants/examples/protobuf:protobuf-imports-example',
'examples/src/java/com/pants/examples/protobuf/imports'
],
)
25 changes: 10 additions & 15 deletions src/python/pants/backend/codegen/targets/java_protobuf_library.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,25 @@
print_function, unicode_literals)

from hashlib import sha1

import six
import logging

from twitter.common.collections import OrderedSet
from twitter.common.lang import Compatibility

from pants.backend.jvm.targets.exportable_jvm_library import ExportableJvmLibrary
from pants.backend.jvm.targets.jar_dependency import JarDependency
from pants.backend.jvm.targets.jar_library import JarLibrary
from pants.backend.jvm.targets.jvm_target import JvmTarget
from pants.base.address import SyntheticAddress
from pants.base.payload import Payload
from pants.base.payload_field import combine_hashes, PayloadField

logger = logging.getLogger(__name__)


class ImportsField(OrderedSet, PayloadField):
def _compute_fingerprint(self):
def hashes_iter():
for item in self:
if isinstance(item, six.text_type):
yield sha1(item.encode('utf-8')).hexdigest()
elif isinstance(item, six.binary_type):
yield sha1(item).hexdigest()
elif isinstance(item, JarDependency):
yield sha1(item.cache_key()).hexdigest()
yield sha1(item.encode('utf-8')).hexdigest()
return combine_hashes(hashes_iter())


Expand All @@ -45,16 +39,18 @@ class PrematureImportPokeError(Exception):
def __init__(self, payload=None, buildflags=None, imports=None, **kwargs):
"""
:param buildflags: Unused, and will be removed in a future release.
:param imports: List of external :class:`pants.backend.jvm.targets.jar_dependency.JarDependency`
objects and addresses of :class:`pants.backend.jvm.targets.jar_library.JarLibrary` targets
which contain .proto definitions.
:param imports: List of addresses of :class:`pants.backend.jvm.targets.jar_library.JarLibrary`
targets which contain .proto definitions.
"""
payload = payload or Payload()
# TODO(pl, zundel): Enforce either address specs or JarDependencies for this type, not either.
payload.add_fields({
'raw_imports': ImportsField(imports or ())
})
super(JavaProtobufLibrary, self).__init__(payload=payload, **kwargs)
if buildflags is not None:
logger.warn(" Target definition at {address} references attribute `buildfiles` which is "
"ignored and will be removed in a future release".format(address=self.address.spec))
self.add_labels('codegen')
if imports:
self.add_labels('has_imports')
Expand All @@ -70,8 +66,7 @@ def traversable_specs(self):
@property
def _library_imports(self):
for dep in self.payload.raw_imports:
if isinstance(dep, Compatibility.string):
yield dep
yield dep

@property
def imports(self):
Expand Down
9 changes: 0 additions & 9 deletions src/python/pants/base/payload.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,7 @@
from __future__ import (nested_scopes, generators, division, absolute_import, with_statement,
print_function, unicode_literals)

from abc import abstractmethod
from hashlib import sha1
import os

from twitter.common.collections import OrderedSet
from twitter.common.lang import AbstractClass

from pants.base.build_environment import get_buildroot
from pants.base.validation import assert_list


class PayloadFieldAlreadyDefinedError(Exception): pass

Expand Down
6 changes: 3 additions & 3 deletions tests/python/pants_test/tasks/test_protobuf_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
class ProtobufIntegrationTest(PantsRunIntegrationTest):
def test_bundle_protobuf_normal(self):
pants_run = self.run_pants(
['goal', 'bundle', 'examples/src/java/com/pants/examples/protobuf:protobuf-example',
['goal', 'bundle', 'examples/src/java/com/pants/examples/protobuf/distance',
'--bundle-deployjar', '--print-exception-stacktrace',])
self.assertEquals(pants_run.returncode, self.PANTS_SUCCESS_CODE,
"goal bundle run expected success, got {0}\n"
Expand All @@ -26,7 +26,7 @@ def test_bundle_protobuf_normal(self):
pants_run.stdout_data))
out_path = os.path.join(get_buildroot(), 'dist', 'protobuf-example-bundle')
java_run = subprocess.Popen(['java', '-cp', 'protobuf-example.jar',
'com.pants.examples.protobuf.ExampleProtobuf'],
'com.pants.examples.protobuf.distance.ExampleProtobuf'],
stdout=subprocess.PIPE,
cwd=out_path)
java_retcode = java_run.wait()
Expand All @@ -36,7 +36,7 @@ def test_bundle_protobuf_normal(self):

def test_bundle_protobuf_imports(self):
pants_run = self.run_pants(
['goal', 'bundle', 'examples/src/java/com/pants/examples/protobuf:protobuf-imports-example',
['goal', 'bundle', 'examples/src/java/com/pants/examples/protobuf/imports',
'--bundle-deployjar', '--print-exception-stacktrace',])
self.assertEquals(pants_run.returncode, self.PANTS_SUCCESS_CODE,
"goal bundle run expected success, got {0}\n"
Expand Down

0 comments on commit 752a540

Please sign in to comment.