Skip to content

Commit

Permalink
Back down the minimum required java version for running Pants tools t…
Browse files Browse the repository at this point in the history
…o java 7

The pants 1.2.0rc1 release requried java8 to run tests.  This backs down that requirement to java7 for all the pants tools.  (Square has hadoop dependencies that we still want to test under the Java 7 jvm.)

The change to require java 8 was introduced in:

https://rbcommons.com/s/twitter/r/4127/
https://rbcommons.com/s/twitter/r/4253/

This will also require a subsequent update to re-publish the artifacts and bump the junit-runner verison.

Testing Done:
Passed junit tests locally
Tested the runner locally in Square's java repo

CI running at https://travis-ci.org/pantsbuild/pants/builds/168153814

Bugs closed: 3980

Reviewed at https://rbcommons.com/s/twitter/r/4314/
  • Loading branch information
ericzundel committed Oct 18, 2016
1 parent 127867b commit d0566df
Show file tree
Hide file tree
Showing 19 changed files with 51 additions and 34 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ At a minimum, pants requires the following to run properly:

Additionally, if you use the jvm backend to work with java or scala code (installed by default):

* OpenJDK or Oracle JDK version 8 or greater
* OpenJDK or Oracle JDK version 7 or greater
3 changes: 1 addition & 2 deletions examples/src/java/org/pantsbuild/example/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,7 @@ should design your bootclasspath to reference the union of all possible jars
you might need to pull in from different JVMs (any paths that aren't available
will simply be ignored by java).

**Note:** Currently, pants is known to work with OpenJDK version 7 or greater,
and Oracle JDK version 6 or greater.
**Note:** Currently, pants is known to work with OpenJDK and Oracle JDK version 7 or greater.


<a pantsmark="jvm_bundles"></a>
Expand Down
9 changes: 5 additions & 4 deletions src/docs/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ Installing Pants
There are a few ways to get a runnable version of pants set up for your workspace. Before
beginning, make sure your machine fits the requirements. At a minimum, pants requires the following to run properly:

* Linux or Mac OS X
* Python 2.7.x (the latest stable version of 2.7 is recommended)
* A C compiler, system headers, Python headers (to compile native Python modules)
* OpenJDK 7 or greater, Oracle JDK 6 or greater
* Linux or Mac OS X.
* Python 2.7.x (the latest stable version of 2.7 is recommended).
* A C compiler, system headers, Python headers (to compile native Python modules) and the libffi
library and headers (to compile and link modules that use CFFI to access native code).
* OpenJDK or Oracle JDK 7 or greater.
* Internet access (so that pants can fully bootstrap itself)

After you have pants installed, you'll need to
Expand Down
1 change: 1 addition & 0 deletions src/java/com/sun/tools/javac/api/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ java_library(
sources=globs('*.java'),
dependencies=[
],
platform='java7',
provides=artifact(
org='org.pantsbuild',
name='custom_javactool_for_testing',
Expand Down
1 change: 1 addition & 0 deletions src/java/org/pantsbuild/args4j/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ java_library(
'3rdparty:guava',
'3rdparty:jsr305',
],
platform='java7',
provides=artifact(
org='org.pantsbuild',
name='args4j',
Expand Down
3 changes: 2 additions & 1 deletion src/java/org/pantsbuild/junit/annotations/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ java_library(
Annotations for use with org.pantsbuild#junit-runner that support running tests in parallel.
""")
),
sources=globs('*.java')
sources=globs('*.java'),
platform='java7',
)
3 changes: 2 additions & 1 deletion src/java/org/pantsbuild/testing/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ java_library(
'3rdparty:guava',
'3rdparty:guava-testlib',
'3rdparty:junit'
]
],
platform='java7',
)
4 changes: 3 additions & 1 deletion src/java/org/pantsbuild/tools/jar/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ java_library(
'3rdparty:jsr305',
'src/java/org/pantsbuild/args4j'
],
platform='java7',
provides=artifact(
org='org.pantsbuild',
name='jar-tool',
Expand All @@ -25,5 +26,6 @@ jvm_binary(
main='org.pantsbuild.tools.jar.Main',
dependencies=[
':jar',
]
],
platform='java7',
)
4 changes: 3 additions & 1 deletion src/java/org/pantsbuild/tools/junit/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ java_library(
'src/java/org/pantsbuild/junit/annotations',
'src/java/org/pantsbuild/tools/junit/withretry',
],
sources=globs('*.java', 'impl/*.java', 'impl/experimental/*.java')
sources=globs('*.java', 'impl/*.java', 'impl/experimental/*.java'),
platform='java7',
)

jvm_binary(
Expand All @@ -30,6 +31,7 @@ jvm_binary(
dependencies=[
':junit',
],
platform='java7',
description="""
A replacement for org.junit.runner.JUnitCore.main that adds:
+ support for running individual test methods using [classname]#[methodname]
Expand Down
3 changes: 2 additions & 1 deletion src/java/org/pantsbuild/tools/junit/impl/Spec.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@
class Spec {
private final Class<?> clazz;
private final ImmutableSet<String> methods;
private static final ImmutableSet<String> empty = ImmutableSet.of(); // To get around java7 quirk

Spec(Class<?> clazz) {
this(clazz, ImmutableSet.of());
this(clazz, Spec.empty);
}

private Spec(Class<?> clazz, ImmutableSet<String> methods) {
Expand Down
21 changes: 13 additions & 8 deletions src/java/org/pantsbuild/tools/junit/impl/SpecParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@

package org.pantsbuild.tools.junit.impl;

import com.google.common.base.Optional;
import java.lang.reflect.Method;
import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.Optional;

import com.google.common.base.Preconditions;
import com.google.common.collect.Iterables;
Expand Down Expand Up @@ -54,12 +54,13 @@ Collection<Spec> parse() throws SpecException {
addMethod(specString);
} else {
Optional<Spec> spec = getOrCreateSpec(specString, specString);
spec.ifPresent(s -> {
if (spec.isPresent()) {
Spec s = spec.get();
if (specs.containsKey(s.getSpecClass()) && !s.getMethods().isEmpty()) {
throw new SpecException(specString,
"Request for entire class already requesting individual methods");
}
});
}
}
}
return specs.values();
Expand All @@ -77,10 +78,13 @@ private Optional<Spec> getOrCreateSpec(String className, String specString) thro
try {
Class<?> clazz = getClass().getClassLoader().loadClass(className);
if (Util.isTestClass(clazz)) {
return Optional.of(specs.computeIfAbsent(clazz, Spec::new));
} else {
return Optional.empty();
if (!specs.containsKey(clazz)) {
Spec newSpec = new Spec(clazz);
specs.put(clazz, newSpec);
}
return Optional.of(specs.get(clazz));
}
return Optional.absent();
} catch (ClassNotFoundException | NoClassDefFoundError e) {
throw new SpecException(specString,
String.format("Class %s not found in classpath.", className), e);
Expand Down Expand Up @@ -110,7 +114,8 @@ private void addMethod(String specString) throws SpecException {
String methodName = results[1];

Optional<Spec> spec = getOrCreateSpec(className, specString);
spec.ifPresent(s -> {
if (spec.isPresent()) {
Spec s = spec.get();
for (Method clazzMethod : s.getSpecClass().getMethods()) {
if (clazzMethod.getName().equals(methodName)) {
Spec specWithMethod = s.withMethod(methodName);
Expand All @@ -121,6 +126,6 @@ private void addMethod(String specString) throws SpecException {
// TODO(John Sirois): Introduce an Either type to make this function total.
throw new SpecException(specString,
String.format("Method %s not found in class %s", methodName, className));
});
}
}
}
3 changes: 2 additions & 1 deletion src/java/org/pantsbuild/tools/junit/withretry/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ java_library(
dependencies=[
'3rdparty:junit',
],
sources=globs('*.java')
sources=globs('*.java'),
platform='java7',
)
4 changes: 3 additions & 1 deletion src/java/org/pantsbuild/tools/runner/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ java_library(
dependencies=[
'3rdparty:guava',
],
sources=globs('*.java')
sources=globs('*.java'),
platform='java7',
)

jvm_binary(
Expand All @@ -24,6 +25,7 @@ jvm_binary(
dependencies=[
':runner-library',
],
platform='java7',
description="""
A command line tool for fixing problems with custom classloading and synthetic jar.
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
jvm_binary(
main='org.pantsbuild.testproject.targetlevels.unspecified.Unspecified',
dependencies=[
':java6',
':java7',
':lib',
],
)
Expand All @@ -13,8 +13,8 @@ java_library(name='lib',
sources=globs('Unspecified.java'),
)

java_library(name='java6',
sources=globs('Six.java'),
platform='java6',
java_library(name='java7',
sources=globs('Seven.java'),
platform='java7',
dependencies=[':lib'],
)
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@

package org.pantsbuild.testproject.targetlevels.unspecified;

public class Six {
public class Seven {
public static void main(String[] args) {
Unspecified.main(args);
System.out.println("Java target level six.");
System.out.println("Java target level seven.");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class SpecParserTest {

@Test(expected = IllegalArgumentException.class)
public void testEmptySpecsThrows() {
new SpecParser(new ArrayList<>());
new SpecParser(new ArrayList<String>());
}

@Test public void testParserClass() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,11 @@ def test_compile_java7on6(self):
def test_compile_target_coercion(self):
target_spec = 'testprojects/src/java/org/pantsbuild/testproject/targetlevels/unspecified'
self.assert_class_versions({
'org/pantsbuild/testproject/targetlevels/unspecified/Unspecified.class': '1.7',
'org/pantsbuild/testproject/targetlevels/unspecified/Six.class': '1.6',
'org/pantsbuild/testproject/targetlevels/unspecified/Unspecified.class': '1.8',
'org/pantsbuild/testproject/targetlevels/unspecified/Seven.class': '1.7',
}, self._get_compiled_class_versions(target_spec, more_args=[
'--jvm-platform-validate-check=warn',
'--jvm-platform-default-platform=java7',
'--jvm-platform-default-platform=java8',
]))

def _test_compile(self, target_level, class_name, source_contents, platform_args=None):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ def test_all_targets(self):
# they explicitly include jersey.jersey's source jar.
'--exclude-target-regexp=testprojects/3rdparty/managed:jersey.jersey.sources',
'--exclude-target-regexp=testprojects/3rdparty/managed:example-dependee',
'--jvm-platform-default-platform=java6'
'--jvm-platform-default-platform=java7'
])

def test_ivy_classifiers(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def test_testprojects(self):
timeout_targets + deliberately_conflicting_targets)
exclude_opts = map(lambda target: '--exclude-target-regexp={}'.format(target),
targets_to_exclude)
pants_run = self.pants_test(['testprojects::', '--jvm-platform-default-platform=java6'] + exclude_opts)
pants_run = self.pants_test(['testprojects::', '--jvm-platform-default-platform=java7'] + exclude_opts)
self.assert_success(pants_run)

# This is a special case that we split into 2 tests instead of using ensure_engine.
Expand Down

0 comments on commit d0566df

Please sign in to comment.