Skip to content

Commit

Permalink
Reproduces problem with deploy_excludes()
Browse files Browse the repository at this point in the history
This defines a test that reproduces the problem noted in github issue 2359.  I went ahead and marked it 'xfail' for now so we could patch it in and experiment with different strategies to fix the problem.

Testing Done:
passed CI at https://travis-ci.org/pantsbuild/pants/builds/84784374

Bugs closed: 2359, 2360

Reviewed at https://rbcommons.com/s/twitter/r/2961/
  • Loading branch information
ericzundel committed Oct 11, 2015
1 parent 7c59ebc commit 5c73023
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Copyright 2015 Pants project contributors (see CONTRIBUTORS.md).
# Licensed under the Apache License, Version 2.0 (see LICENSE).

jvm_binary(name='deployexcludes',
main='org.pantsbuild.testproject.deployexcludes.DeployExcludesMain',
dependencies=[
':lib',
],
deploy_excludes=[
exclude(org='com.google.guava', name='guava'),
],
)

java_library(name='lib',
sources=['DeployExcludesMain.java'],
dependencies=[
'3rdparty:guava',
],
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright 2015 Pants project contributors (see CONTRIBUTORS.md).
// Licensed under the Apache License, Version 2.0 (see LICENSE).

package org.pantsbuild.testproject.deployexcludes;

import com.google.common.base.Joiner;
import com.google.common.collect.ImmutableSortedSet;
import java.util.Set;

public class DeployExcludesMain {
public static void main(String[] args) {
Set values = ImmutableSortedSet.of("Hello", "World");
System.out.println("DeployExcludes " + Joiner.on(" ").join(values));
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@
import os
import subprocess

import pytest

from pants.base.build_environment import get_buildroot
from pants.util.contextutil import open_zip
from pants.util.dirutil import safe_delete
from pants_test.pants_run_integration_test import PantsRunIntegrationTest


Expand Down Expand Up @@ -49,6 +53,43 @@ def test_manifest_entries_bundle(self):
expected_output='Hello World! Version: 4.5.6',
)

# This test passes as of 0.0.51, but fails in subsequent releases with guava being
# bundled in the resulting .jar
@pytest.mark.xfail
def test_deploy_excludes(self):
jar_filename = os.path.join('dist', 'deployexcludes.jar')
safe_delete(jar_filename)
pants_run = self.run_pants(['binary',
'testprojects/src/java/org/pantsbuild/testproject/deployexcludes'], {})
self.assert_success(pants_run)
# The resulting binary should not contain any guava classes
with open_zip(jar_filename) as jar_file:
self.assertEquals({'META-INF/',
'META-INF/MANIFEST.MF',
'org/',
'org/pantsbuild/',
'org/pantsbuild/testproject/',
'org/pantsbuild/testproject/deployexcludes/',
'org/pantsbuild/testproject/deployexcludes/DeployExcludesMain.class'},
set(jar_file.namelist()))

# This jar should not run by itself, missing symbols
java_run = subprocess.Popen(['java', '-jar', jar_filename], stderr=subprocess.PIPE)
java_retcode = java_run.wait()
java_stderr = java_run.stderr.read()
self.assertEquals(java_retcode, 1)
self.assertIn("java.lang.NoClassDefFoundError: com/google/common/collect/ImmutableSortedSet", java_stderr)

java_run = subprocess.Popen([
'java', '-cp',
jar_filename + ':' + '.pants.d/ivy/jars/com.google.guava/guava/bundles/guava-18.0.jar',
'org.pantsbuild.testproject.deployexcludes.DeployExcludesMain'],
stdout=subprocess.PIPE)
java_retcode = java_run.wait()
java_stdout = java_run.stdout.read()
self.assertEquals(java_retcode, 0)
self.assertIn("DeployExcludes Hello World", java_stdout)

def build_and_run(self, pants_args, rel_out_path, java_args, expected_output):
self.assert_success(self.run_pants(['clean-all']))
pants_run = self.run_pants(pants_args, {})
Expand Down

0 comments on commit 5c73023

Please sign in to comment.