Skip to content

Commit

Permalink
Changed publish integration tests to use testprojects/*
Browse files Browse the repository at this point in the history
Copied the examples required by the test to testprojects so they can be changed independently of examples without making those more convoluted.

Testing Done:
ci.sh

Reviewed at https://rbcommons.com/s/twitter/r/1026/
  • Loading branch information
johanoskarsson authored and Stu Hood committed Sep 15, 2014
1 parent 657106c commit a32d0a2
Show file tree
Hide file tree
Showing 11 changed files with 167 additions and 6 deletions.
6 changes: 6 additions & 0 deletions testprojects/ivy/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import os

repo(name = 'testing',
url = 'http://maven.twttr.com',
push_db = os.path.join(buildfile_path(), 'pushdb', 'publish.properties'))

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

java_library(name = 'greet',
dependencies = [],
sources = globs('*.java'),
provides = artifact(org='com.pants.testproject.publish',
name='hello-greet',
repo='testprojects/ivy:testing',),
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Copyright 2014 Pants project contributors (see CONTRIBUTORS.md).
// Licensed under the Apache License, Version 2.0 (see LICENSE).

package com.pants.testproject.publish.hello.greet;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Scanner;

public final class Greeting {
public static String greetFromFile(String filename) throws IOException {
FileInputStream is = new FileInputStream(filename);
try {
return greetFromStream(is);
} finally {
is.close();
}
}

public static String greetFromResource(String resource) throws IOException {
InputStream is = Greeting.class.getClassLoader().getResourceAsStream(resource);
try {
return greetFromStream(is);
} finally {
is.close();
}
}

public static String greetFromStream(InputStream is) throws IOException {
return greet(new Scanner(is).useDelimiter("\\Z").next());
}

public static String greet(String greetee) {
return "Hello, " + greetee + "!";
}

private Greeting() {
// not called. placates checkstyle
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Copyright 2014 Pants project contributors (see CONTRIBUTORS.md).
# Licensed under the Apache License, Version 2.0 (see LICENSE).

# Like Hello World, but built with Pants.

jvm_app(name='main',
basename = 'hello-example',
dependencies = [
':main-bin'
],
)

# The binary, the "runnable" part:

jvm_binary(name = 'main-bin',
dependencies = [
'testprojects/src/java/com/pants/testproject/publish/hello/greet',
],
source = 'HelloMain.java',
main = 'com.pants.testproject.publish.hello.main.HelloMain',
basename = 'hello-example',
)

# README page:

page(name="readme",
source="README.md")

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

package com.pants.testproject.publish.hello.main;

import java.io.IOException;

import com.pants.testproject.publish.hello.greet.Greeting;

public class HelloMain {

public static void main(String[] args) throws IOException {
System.out.println("Hello");
}

private HelloMain() {
// not called. placates checkstyle
}
}
12 changes: 12 additions & 0 deletions testprojects/src/scala/com/pants/testproject/publish/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).

scala_library(name = 'jvm-run-example-lib',
dependencies = [
'testprojects/src/scala/com/pants/testproject/publish/hello/welcome',
],
sources = ['JvmRunExample.scala'],
provides = artifact(org='com.pants.testproject.publish',
name='jvm-example-lib',
repo='testprojects/ivy:testing',)
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright 2014 Pants project contributors (see CONTRIBUTORS.md).
// Licensed under the Apache License, Version 2.0 (see LICENSE).

package com.pants.testproject.publish

// A simple jvm binary to test the jvm_run task on. Try, e.g.,
// ./pants goal run src/scala/com/pants/example:jvm-run-example \\
// -ldebug --jvm-run-jvmargs=-Dfoo=bar --jvm-run-args="Foo Bar"

object JvmRunExample {
def main(args: Array[String]) {
println("Hello, World")
println("args: " + args.mkString(", "))
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Copyright 2014 Pants project contributors (see CONTRIBUTORS.md).
# Licensed under the Apache License, Version 2.0 (see LICENSE).

# Seq-friendly wrapper for Java "greet" library: greet everything in a seq.

scala_library(name='welcome',
dependencies=[
'testprojects/src/java/com/pants/testproject/publish/hello/greet:greet',
],
sources=globs('*.scala'),
provides = artifact(org='com.pants.testproject.publish.hello',
name='welcome',
repo='testprojects/ivy:testing',),
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright 2014 Pants project contributors (see CONTRIBUTORS.md).
// Licensed under the Apache License, Version 2.0 (see LICENSE).

package com.pants.testproject.publish.hello.welcome

import com.pants.testproject.publish.hello.greet.Greeting

// Welcome a collection of things.
// Given a seq of strings, return a seq of greetings for each of them
// Handy wrapper around the greet Java library.

object WelcomeEverybody {
def apply(everybody: Seq[String]): Seq[String] = {
everybody.map(x => Greeting.greet(x))
}
}
12 changes: 6 additions & 6 deletions tests/python/pants_test/tasks/test_jar_publish_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from pants_test.tasks.test_base import is_exe

def shared_artifacts(version):
return {'com/pants/examples/hello-greet/{0}/'.format(version):
return {'com/pants/testproject/publish/hello-greet/{0}/'.format(version):
['ivy-{0}.xml'.format(version),
'hello-greet-{0}.jar'.format(version),
'hello-greet-{0}.pom'.format(version),
Expand All @@ -27,30 +27,30 @@ class JarPublishIntegrationTest(PantsRunIntegrationTest):
@pytest.mark.skipif('not JarPublishIntegrationTest.SCALADOC',
reason='No scaladoc binary on the PATH.')
def test_scala_publish(self):
unique_artifacts = {'com/pants/example/jvm-example-lib/0.0.1-SNAPSHOT':
unique_artifacts = {'com/pants/testproject/publish/jvm-example-lib/0.0.1-SNAPSHOT':
['ivy-0.0.1-SNAPSHOT.xml',
'jvm-example-lib-0.0.1-SNAPSHOT.jar',
'jvm-example-lib-0.0.1-SNAPSHOT.pom',
'jvm-example-lib-0.0.1-SNAPSHOT-sources.jar'],
'com/pants/example/hello/welcome/0.0.1-SNAPSHOT':
'com/pants/testproject/publish/hello/welcome/0.0.1-SNAPSHOT':
['ivy-0.0.1-SNAPSHOT.xml',
'welcome-0.0.1-SNAPSHOT.jar',
'welcome-0.0.1-SNAPSHOT.pom',
'welcome-0.0.1-SNAPSHOT-sources.jar'],}
self.publish_test('examples/src/scala/com/pants/example:jvm-run-example-lib',
self.publish_test('testprojects/src/scala/com/pants/testproject/publish:jvm-run-example-lib',
dict(unique_artifacts.items() + shared_artifacts('0.0.1-SNAPSHOT').items()),
extra_options=['--doc-scaladoc-skip'],
expected_primary_artifact_count=3)

@pytest.mark.skipif('not JarPublishIntegrationTest.JAVADOC',
reason='No javadoc binary on the PATH.')
def test_java_publish(self):
self.publish_test('examples/src/java/com/pants/examples/hello/greet',
self.publish_test('testprojects/src/java/com/pants/testproject/publish/hello/greet',
shared_artifacts('0.0.1-SNAPSHOT'),)

def test_named_snapshot(self):
name = "abcdef0123456789"
self.publish_test('examples/src/java/com/pants/examples/hello/greet',
self.publish_test('testprojects/src/java/com/pants/testproject/publish/hello/greet',
shared_artifacts(name),
extra_options=['--publish-named-snapshot=%s' % name])

Expand Down

0 comments on commit a32d0a2

Please sign in to comment.