Skip to content

Commit

Permalink
Merge 146ff7d into 2e165ea
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom Howland committed May 13, 2015
2 parents 2e165ea + 146ff7d commit 7f5beed
Show file tree
Hide file tree
Showing 7 changed files with 192 additions and 55 deletions.
18 changes: 8 additions & 10 deletions 3rdparty/jvm/com/typesafe/sbt/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,19 @@
SBT_REV='0.13.7'

jar_library(name = 'compiler-interface',
jars = [
jar(org = 'com.typesafe.sbt', name = 'compiler-interface', rev = SBT_REV,
classifier='sources')])
jars = [jar(org = 'com.typesafe.sbt', name = 'compiler-interface', rev = SBT_REV,
classifier='sources', intransitive=True)],
dependencies=['//:scala-library'])

jar_library(name = 'incremental-compiler',
jars = [
jar(org = 'com.typesafe.sbt', name = 'incremental-compiler', rev = SBT_REV,
intransitive=True)
],
jars = [jar(org = 'com.typesafe.sbt', name = 'incremental-compiler', rev = SBT_REV,
intransitive=True)],
dependencies=[
'//:scala-compiler',
'//:scala-library',
':sbt-interface'])

jar_library(name = 'sbt-interface',
jars = [
jar(org = 'com.typesafe.sbt', name = 'sbt-interface', rev = SBT_REV)
])
jars = [jar(org = 'com.typesafe.sbt', name = 'sbt-interface', rev = SBT_REV,
intransitive=True)],
dependencies=['//:scala-library'])
65 changes: 22 additions & 43 deletions src/python/pants/backend/jvm/tasks/jar_publish.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ def __init__(self, get_db, template_relpath, template_package_name=None):
self.template_package_name = template_package_name or __name__
self.template_relpath = template_relpath

def write(self, target, path, confs=None, extra_confs=None, classifier=None):
def write(self, target, path, confs=None, extra_confs=None):
# TODO(John Sirois): a dict is used here to de-dup codegen targets which have both the original
# codegen target - say java_thrift_library - and the synthetic generated target (java_library)
# Consider reworking codegen tasks to add removal of the original codegen targets when rewriting
Expand All @@ -165,33 +165,31 @@ def write(self, target, path, confs=None, extra_confs=None, classifier=None):
configurations = set(confs or [])
for internal_dep in target_internal_dependencies(target):
jar = self._as_versioned_jar(internal_dep)
dependencies[(jar.org, jar.name)] = self.internaldep(jar, internal_dep, classifier=classifier)
dependencies[(jar.org, jar.name)] = self.internaldep(jar, internal_dep)
if internal_dep.is_codegen:
internal_codegen[jar.name] = jar.name
for jar in target.jar_dependencies:
if jar.rev:
dependencies[(jar.org, jar.name, classifier)] = self.jardep(jar, classifier=classifier)
dependencies[(jar.org, jar.name)] = self.jardep(jar)
configurations |= set(jar._configurations)

target_jar = self.internaldep(self._as_versioned_jar(target),
target,
classifier=classifier,
target_jar = self.internaldep(self._as_versioned_jar(target), target,
configurations=list(configurations))
target_jar = target_jar.extend(dependencies=dependencies.values())

template_kwargs = self.templateargs(target_jar, confs, extra_confs, classifier)
template_kwargs = self.templateargs(target_jar, confs, extra_confs)
with safe_open(path, 'w') as output:
template = pkgutil.get_data(self.template_package_name, self.template_relpath)
Generator(template, **template_kwargs).write(output)

def templateargs(self, target_jar, confs=None, extra_confs=None, classifier=None):
def templateargs(self, target_jar, confs=None, extra_confs=None):
"""
Subclasses must return a dict for use by their template given the target jar template data
and optional specific ivy configurations.
"""
raise NotImplementedError()

def internaldep(self, jar_dependency, target, configurations=None, classifier=None):
def internaldep(self, jar_dependency, target, configurations=None):
"""
Subclasses must return a template data for the given internal target (provided in jar
dependency form).
Expand All @@ -205,7 +203,7 @@ def _as_versioned_jar(self, internal_target):
jar.rev = pushdb_entry.version().version()
return jar

def jardep(self, jar_dependency, classifier=None):
def jardep(self, jar_dependency):
"""Subclasses must return a template data for the given external jar dependency."""
raise NotImplementedError()

Expand All @@ -217,33 +215,20 @@ def __init__(self, get_db, tag):
os.path.join('templates', 'jar_publish', 'pom.mustache'))
self._tag = tag

def templateargs(self, target_jar, confs=None, extra_confs=None, classifier=None):
def templateargs(self, target_jar, confs=None, extra_confs=None):
return dict(project=target_jar)

def jardep(self, jar, classifier=None):
def jardep(self, jar):
return TemplateData(
classifiers=self.classifiers(classifier, jar.artifacts),
classifiers=[TemplateData(classifier=i.classifier) for i in jar.artifacts if i.classifier],
artifact_id=jar.name,
group_id=jar.org,
version=jar.rev,
scope='compile',
excludes=[self.create_exclude(exclude) for exclude in jar.excludes if exclude.name])

@staticmethod
def classifiers(classifier, artifacts):
"""Find a list of plausible classifiers.
:param classifier: the starting classifier
:param artifacts: a sequence of IvyArtifact's
:return: list like [TemplateData(classifier='sources'), TemplateData(classifier='javadoc')]
"""
r = []
if classifier:
r.append(TemplateData(classifier=classifier))
return r + [TemplateData(classifier=i) for i in map(lambda x: x.classifier, artifacts) if i]

def internaldep(self, jar_dependency, target, configurations=None, classifier=None):
template_data = self.jardep(jar_dependency, classifier=classifier)
def internaldep(self, jar_dependency, target, configurations=None):
template_data = self.jardep(jar_dependency)
if isinstance(target.provides.publication_metadata, OSSRHPublicationMetadata):
pom = target.provides.publication_metadata

Expand Down Expand Up @@ -272,13 +257,13 @@ def __init__(self, get_db):
IvyUtils.IVY_TEMPLATE_PATH,
template_package_name=IvyUtils.IVY_TEMPLATE_PACKAGE_NAME)

def templateargs(self, target_jar, confs=None, extra_confs=None, classifier=None):
def templateargs(self, target_jar, confs=None, extra_confs=None):
return dict(lib=target_jar.extend(
publications=set(confs or []),
extra_publications=extra_confs if extra_confs else {},
overrides=None))

def _jardep(self, jar, transitive=True, configurations='default', classifier=None):
def _jardep(self, jar, transitive=True, configurations='default'):
return TemplateData(
org=jar.org,
module=jar.name,
Expand All @@ -288,17 +273,13 @@ def _jardep(self, jar, transitive=True, configurations='default', classifier=Non
excludes=[self.create_exclude(exclude) for exclude in jar.excludes],
transitive=transitive,
artifacts=jar.artifacts,
classifier=classifier,
configurations=configurations)

def jardep(self, jar, classifier=None):
return self._jardep(jar,
transitive=jar.transitive,
configurations=jar._configurations,
classifier=classifier)
def jardep(self, jar):
return self._jardep(jar, transitive=jar.transitive, configurations=jar._configurations)

def internaldep(self, jar_dependency, target, configurations=None, classifier=None):
return self._jardep(jar_dependency, configurations=configurations, classifier=classifier)
def internaldep(self, jar_dependency, target, configurations=None):
return self._jardep(jar_dependency, configurations=configurations)


def coordinate(org, name, rev=None):
Expand Down Expand Up @@ -670,7 +651,7 @@ def fingerprint_internal(tgt):
return entry.fingerprint or '0.0.0'

def stage_artifact(tgt, jar, version, tag, changelog, confs=None, artifact_ext='',
extra_confs=None, classifier=''):
extra_confs=None):
def path(name=None, suffix='', extension='jar'):
return self.artifact_path(jar, version, name=name, suffix=suffix, extension=extension,
artifact_ext=artifact_ext)
Expand All @@ -680,10 +661,8 @@ def path(name=None, suffix='', extension='jar'):
changelog_file.write(changelog.encode('utf-8'))
ivyxml = path(name='ivy', extension='xml')

IvyWriter(get_pushdb).write(tgt, ivyxml, confs=confs, extra_confs=extra_confs,
classifier=classifier)
PomWriter(get_pushdb, tag).write(tgt, path(extension='pom'), extra_confs=extra_confs,
classifier=classifier)
IvyWriter(get_pushdb).write(tgt, ivyxml, confs=confs, extra_confs=extra_confs)
PomWriter(get_pushdb, tag).write(tgt, path(extension='pom'), extra_confs=extra_confs)

return ivyxml

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
scala_library(name='classifiers',
provides=artifact(
org='org.pantsbuild.testproject.publish',
name='classifiers',
repo=testing,
publication_metadata=pants_library('This is a test. This is only a test.')
),
dependencies=[
':compiler-interface',
':incremental-compiler',
':sbt-interface',
],
sources=['Hello.scala']
)

SBT_REV='0.13.7'

jar_library(name = 'compiler-interface',
jars = [jar(org = 'com.typesafe.sbt', name = 'compiler-interface', rev = SBT_REV,
classifier='sources', intransitive=True,
artifacts=[ivy_artifact(name='compiler-interface', classifier='javadoc')])])

jar_library(name = 'incremental-compiler',
jars = [jar(org = 'com.typesafe.sbt', name = 'incremental-compiler', rev = SBT_REV,
intransitive=True)])

jar_library(name = 'sbt-interface',
jars = [jar(org = 'com.typesafe.sbt', name = 'sbt-interface', rev = SBT_REV,
intransitive=True,
artifacts=[ivy_artifact(name='sbt-interface', classifier='javadoc')])])
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package org.pantsbuild.testproject.publish.classifiers

object Hello extends App {
println("hi there")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?xml version="1.0" encoding="UTF-8"?>

<!-- generated by pants! http://pantsbuild.github.io/ -->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">

<modelVersion>4.0.0</modelVersion>

<groupId>org.pantsbuild.testproject.publish</groupId>
<artifactId>classifiers</artifactId>
<packaging>jar</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>org.pantsbuild.testproject.publish:classifiers</name>
<description>This is a test. This is only a test.</description>
<url>http://pantsbuild.github.io/</url>
<licenses>
<license>
<name>Apache License, Version 2.0</name>
<url>http://www.apache.org/licenses/LICENSE-2.0</url>
<distribution>repo</distribution>
</license>
</licenses>
<scm>
<connection>scm:git:git@github.com:pantsbuild/pants.git</connection>
<developerConnection>scm:git:git@github.com:pantsbuild/pants.git</developerConnection>
<url>https://github.com/pantsbuild/pants</url>
</scm>
<developers>
<developer>
<name>The pants developers</name>
<email>pants-devel@googlegroups.com</email>
<url>https://github.com/pantsbuild/pants</url>
</developer>
</developers>
<dependencies>
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-library</artifactId>
<version>2.10.4</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.typesafe.sbt</groupId>
<artifactId>sbt-interface</artifactId>
<version>0.13.7</version>
<scope>compile</scope>
<classifier>javadoc</classifier>
</dependency>
<dependency>
<groupId>com.typesafe.sbt</groupId>
<artifactId>compiler-interface</artifactId>
<version>0.13.7</version>
<scope>compile</scope>
<classifier>javadoc</classifier>
</dependency>
<dependency>
<groupId>com.typesafe.sbt</groupId>
<artifactId>compiler-interface</artifactId>
<version>0.13.7</version>
<scope>compile</scope>
<classifier>sources</classifier>
</dependency>
<dependency>
<groupId>com.typesafe.sbt</groupId>
<artifactId>incremental-compiler</artifactId>
<version>0.13.7</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright 2014 Pants project contributors (see CONTRIBUTORS.md).
Licensed under the Apache License, Version 2.0 (see LICENSE).
-->
<!-- generated by pants! -->
<ivy-module version="2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://ant.apache.org/ivy/schemas/ivy.xsd" xmlns:m="http://ant.apache.org/ivy/maven">

<info organisation="org.pantsbuild.testproject.publish" module="classifiers" revision="0.0.1-SNAPSHOT" status="release" />

<configurations>
<conf name="default"/>
<conf name="sources"/>
<conf name="javadoc"/>
</configurations>

<publications>
<artifact conf="default" type="jar" ext="jar"/>
<artifact conf="default" type="pom" ext="pom"/>
<artifact conf="sources" type="source" m:classifier="sources" ext="jar"/>
<artifact conf="javadoc" type="javadoc" m:classifier="javadoc" ext="jar"/>
</publications>

<dependencies>
<dependency org="org.scala-lang" name="scala-library" rev="2.10.4">
<conf name="default" mapped="default"/>
</dependency>
<dependency org="com.typesafe.sbt" name="sbt-interface" rev="0.13.7" transitive="false">
<conf name="default" mapped="default"/>
<artifact name="sbt-interface" type="jar" m:classifier="javadoc"/>
</dependency>
<dependency org="com.typesafe.sbt" name="compiler-interface" rev="0.13.7" transitive="false">
<conf name="default" mapped="default"/>
<artifact name="compiler-interface" type="jar" m:classifier="javadoc"/>
<artifact name="compiler-interface" type="jar" m:classifier="sources"/>
</dependency>
<dependency org="com.typesafe.sbt" name="incremental-compiler" rev="0.13.7" transitive="false">
<conf name="default" mapped="default"/>
</dependency>
</dependencies>
</ivy-module>
16 changes: 14 additions & 2 deletions tests/python/pants_test/tasks/test_jar_publish_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import re

import pytest

from pants.base.build_environment import get_buildroot
from pants.util.contextutil import temporary_dir
from pants.util.dirutil import safe_rmtree
Expand Down Expand Up @@ -184,20 +183,33 @@ def test_publish_extras_invalid_args(self):
artifact_name='hello-greet-0.0.1-SNAPSHOT.jar',
success_expected=False)

@pytest.mark.skipif('not JarPublishIntegrationTest.SCALADOC',
reason='No scaladoc binary on the PATH.')
def test_scala_publish_classifiers(self):
self.publish_test('testprojects/src/scala/org/pantsbuild/testproject/publish/classifiers',
dict({
'org/pantsbuild/testproject/publish/classifiers/0.0.1-SNAPSHOT': [
'classifiers-0.0.1-SNAPSHOT.pom',
'ivy-0.0.1-SNAPSHOT.xml',
]}),
[],
assert_publish_config_contents=True)

def publish_test(self, target, artifacts, pushdb_files, extra_options=None, extra_config=None,
extra_env=None, expected_primary_artifact_count=1, success_expected=True,
assert_publish_config_contents=False):
"""Tests that publishing the given target results in the expected output.
:param target: Target to test.
:param artifacts: A map from directories to a list of expected filenames.
:param pushdb_files: list of pushdb files that would be created if this weren't a local publish
:param extra_options: Extra command-line options to the pants run.
:param extra_config: Extra pants.ini configuration for the pants run.
:param expected_primary_artifact_count: Number of artifacts we expect to be published.
:param extra_env: Extra environment variables for the pants run.
:param assert_publish_config_contents: Test the contents of the generated ivy and pom file.
If set to True, compares the generated ivy.xml and pom files in
tests/python/pants_test/tasks/jar_publish_resources/<pakage_name>/<artifact_name>/
tests/python/pants_test/tasks/jar_publish_resources/<package_name>/<artifact_name>/
"""

with temporary_dir() as publish_dir:
Expand Down

0 comments on commit 7f5beed

Please sign in to comment.