Added deps at runtime for JDK11, changed what gets verified in the output in integration tests
This commit is contained in:
@@ -17,6 +17,7 @@ package org.springframework.cloud.cli;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
|
import java.util.concurrent.Executors;
|
||||||
|
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
import org.junit.Rule;
|
import org.junit.Rule;
|
||||||
@@ -70,9 +71,9 @@ public class SampleIntegrationTests {
|
|||||||
@Test
|
@Test
|
||||||
public void configServerSample() throws Exception {
|
public void configServerSample() throws Exception {
|
||||||
String output = this.cli.run("configserver.groovy", "--",
|
String output = this.cli.run("configserver.groovy", "--",
|
||||||
"--spring.config.name=configserver");
|
"--spring.config.name=configserver", "--logging.level.org.springframework=DEBUG");
|
||||||
assertTrue("Wrong output: " + output,
|
assertTrue("Wrong output: " + output,
|
||||||
output.contains("[/{name}/{profiles}/{label:.*}],methods=[GET]"));
|
output.contains("ConfigServerAutoConfiguration matched"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -86,7 +87,7 @@ public class SampleIntegrationTests {
|
|||||||
public void stubRunnerSample() throws Exception {
|
public void stubRunnerSample() throws Exception {
|
||||||
String output = this.cli.run("stubrunner.groovy");
|
String output = this.cli.run("stubrunner.groovy");
|
||||||
assertTrue("Wrong output: " + output,
|
assertTrue("Wrong output: " + output,
|
||||||
output.contains("[/stubs],produces=[application/json]"));
|
output.contains("No stubs to download have been passed"));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,6 +38,11 @@ public class EurekaServerCompilerAutoConfiguration extends CompilerAutoConfigura
|
|||||||
dependencies.ifAnyMissingClasses(
|
dependencies.ifAnyMissingClasses(
|
||||||
"org.springframework.cloud.netflix.eureka.server.EnableEurekaServer")
|
"org.springframework.cloud.netflix.eureka.server.EnableEurekaServer")
|
||||||
.add("spring-cloud-starter-netflix-eureka-server");
|
.add("spring-cloud-starter-netflix-eureka-server");
|
||||||
|
if (JavaVersion.current().isJava11Compatible()) {
|
||||||
|
dependencies.add("jaxb-api")
|
||||||
|
.add("javax.activation-api")
|
||||||
|
.add("jaxb-runtime");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -0,0 +1,169 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2013-2014 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.springframework.cloud.cli.compiler;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TAKEN FROM GRADLE (https://github.com/gradle/gradle/blob/master/subprojects/base-services/src/main/java/org/gradle/api/JavaVersion.java)
|
||||||
|
*
|
||||||
|
* An enumeration of Java versions.
|
||||||
|
* Before 9: http://www.oracle.com/technetwork/java/javase/versioning-naming-139433.html
|
||||||
|
* 9+: http://openjdk.java.net/jeps/223
|
||||||
|
*/
|
||||||
|
enum JavaVersion {
|
||||||
|
VERSION_1_1, VERSION_1_2, VERSION_1_3, VERSION_1_4,
|
||||||
|
VERSION_1_5, VERSION_1_6, VERSION_1_7, VERSION_1_8,
|
||||||
|
VERSION_1_9, VERSION_1_10,
|
||||||
|
/**
|
||||||
|
* Java 11 major version.
|
||||||
|
*
|
||||||
|
* @since 4.7
|
||||||
|
*/
|
||||||
|
VERSION_11,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Java 12 major version.
|
||||||
|
*
|
||||||
|
* @since 5.0
|
||||||
|
*/
|
||||||
|
VERSION_12,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Higher version of Java.
|
||||||
|
* @since 4.7
|
||||||
|
*/
|
||||||
|
VERSION_HIGHER;
|
||||||
|
// Since Java 9, version should be X instead of 1.X
|
||||||
|
// However, to keep backward compatibility, we change from 11
|
||||||
|
private static final int FIRST_MAJOR_VERSION_ORDINAL = 10;
|
||||||
|
private static JavaVersion currentJavaVersion;
|
||||||
|
private final String versionName;
|
||||||
|
|
||||||
|
JavaVersion() {
|
||||||
|
this.versionName = ordinal() >= FIRST_MAJOR_VERSION_ORDINAL ? getMajorVersion() : "1." + getMajorVersion();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts the given object into a {@code JavaVersion}.
|
||||||
|
*
|
||||||
|
* @param value An object whose toString() value is to be converted. May be null.
|
||||||
|
* @return The version, or null if the provided value is null.
|
||||||
|
* @throws IllegalArgumentException when the provided value cannot be converted.
|
||||||
|
*/
|
||||||
|
public static JavaVersion toVersion(Object value) throws IllegalArgumentException {
|
||||||
|
if (value == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if (value instanceof JavaVersion) {
|
||||||
|
return (JavaVersion) value;
|
||||||
|
}
|
||||||
|
String name = value.toString();
|
||||||
|
int firstNonVersionCharIndex = findFirstNonVersionCharIndex(name);
|
||||||
|
String[] versionStrings = name.substring(0, firstNonVersionCharIndex)
|
||||||
|
.split("\\.");
|
||||||
|
List<Integer> versions = convertToNumber(name, versionStrings);
|
||||||
|
if (isLegacyVersion(versions)) {
|
||||||
|
assertTrue(name, versions.get(1) > 0);
|
||||||
|
return getVersionForMajor(versions.get(1));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return getVersionForMajor(versions.get(0));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the version of the current JVM.
|
||||||
|
*
|
||||||
|
* @return The version of the current JVM.
|
||||||
|
*/
|
||||||
|
public static JavaVersion current() {
|
||||||
|
if (currentJavaVersion == null) {
|
||||||
|
currentJavaVersion = toVersion(System.getProperty("java.version"));
|
||||||
|
}
|
||||||
|
return currentJavaVersion;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static JavaVersion getVersionForMajor(int major) {
|
||||||
|
return major >= values().length ? JavaVersion.VERSION_HIGHER : values()[major - 1];
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void assertTrue(String value, boolean condition) {
|
||||||
|
if (!condition) {
|
||||||
|
throw new IllegalArgumentException("Could not determine java version from '" + value + "'.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean isLegacyVersion(List<Integer> versions) {
|
||||||
|
return 1 == versions.get(0) && versions.size() > 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static List<Integer> convertToNumber(String value, String[] versionStrs) {
|
||||||
|
List<Integer> result = new ArrayList<Integer>();
|
||||||
|
for (String s : versionStrs) {
|
||||||
|
assertTrue(value, !isNumberStartingWithZero(s));
|
||||||
|
try {
|
||||||
|
result.add(Integer.parseInt(s));
|
||||||
|
}
|
||||||
|
catch (NumberFormatException e) {
|
||||||
|
assertTrue(value, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
assertTrue(value, !result.isEmpty() && result.get(0) > 0);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean isNumberStartingWithZero(String number) {
|
||||||
|
return number.length() > 1 && number.startsWith("0");
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int findFirstNonVersionCharIndex(String s) {
|
||||||
|
assertTrue(s, s.length() != 0);
|
||||||
|
|
||||||
|
for (int i = 0; i < s.length(); ++i) {
|
||||||
|
if (!isDigitOrPeriod(s.charAt(i))) {
|
||||||
|
assertTrue(s, i != 0);
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return s.length();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean isDigitOrPeriod(char c) {
|
||||||
|
return (c >= '0' && c <= '9') || c == '.';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns if the version is Java 11 compatible.
|
||||||
|
*
|
||||||
|
* @since 4.7
|
||||||
|
*/
|
||||||
|
public boolean isJava11Compatible() {
|
||||||
|
return this.compareTo(VERSION_11) >= 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return versionName;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public String getMajorVersion() {
|
||||||
|
return String.valueOf(ordinal() + 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user