Fix jacoco arg line not work in jdk17 (#10994)
This commit is contained in:
parent
2b8537f3f4
commit
4e37fa0c01
|
|
@ -199,12 +199,12 @@ jobs:
|
|||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
run: |
|
||||
source ${{ github.workspace }}/.tmp/decrypted-sonarcloud-token
|
||||
./mvnw --batch-mode --no-snapshot-updates -e --no-transfer-progress --fail-fast clean test verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Pjacoco,jdk15ge-simple,'!jdk15ge' -Dsonar.host.url=https://sonarcloud.io -Dsonar.organization=apache -Dsonar.projectKey=apache_dubbo -Dmaven.wagon.httpconnectionManager.ttlSeconds=120 -Dmaven.wagon.http.retryHandler.count=5 -DskipTests=false -DskipIntegrationTests=false -Dcheckstyle.skip=false -Dcheckstyle_unix.skip=false -Drat.skip=false -Dmaven.javadoc.skip=true -DembeddedZookeeperPath=${{ github.workspace }}/.tmp/zookeeper -Dsonar.coverage.jacoco.xmlReportPaths=dubbo-test/dubbo-dependencies-all/target/site/jacoco-aggregate/jacoco.xml -Dsonar.login=${SONAR_TOKEN}
|
||||
./mvnw --batch-mode --no-snapshot-updates -e --no-transfer-progress --fail-fast clean test verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Pjacoco,jdk15ge-simple,'!jdk15ge',jacoco089 -Dsonar.host.url=https://sonarcloud.io -Dsonar.organization=apache -Dsonar.projectKey=apache_dubbo -Dmaven.wagon.httpconnectionManager.ttlSeconds=120 -Dmaven.wagon.http.retryHandler.count=5 -DskipTests=false -DskipIntegrationTests=false -Dcheckstyle.skip=false -Dcheckstyle_unix.skip=false -Drat.skip=false -Dmaven.javadoc.skip=true -DembeddedZookeeperPath=${{ github.workspace }}/.tmp/zookeeper -Dsonar.coverage.jacoco.xmlReportPaths=dubbo-test/dubbo-dependencies-all/target/site/jacoco-aggregate/jacoco.xml -Dsonar.login=${SONAR_TOKEN}
|
||||
- name: "Test with Maven without SonarCloud Scan"
|
||||
if: ${{ github.repository != 'apache/dubbo' }}
|
||||
timeout-minutes: 70
|
||||
run: |
|
||||
./mvnw --batch-mode --no-snapshot-updates -e --no-transfer-progress --fail-fast clean test verify -Dmaven.wagon.httpconnectionManager.ttlSeconds=120 -Pjacoco,jdk15ge-simple,'!jdk15ge' -Dmaven.wagon.http.retryHandler.count=5 -DskipTests=false -DskipIntegrationTests=false -Dcheckstyle.skip=false -Dcheckstyle_unix.skip=false -Drat.skip=false -Dmaven.javadoc.skip=true -DembeddedZookeeperPath=${{ github.workspace }}/.tmp/zookeeper
|
||||
./mvnw --batch-mode --no-snapshot-updates -e --no-transfer-progress --fail-fast clean test verify -Dmaven.wagon.httpconnectionManager.ttlSeconds=120 -Pjacoco,jdk15ge-simple,'!jdk15ge',jacoco089 -Dmaven.wagon.http.retryHandler.count=5 -DskipTests=false -DskipIntegrationTests=false -Dcheckstyle.skip=false -Dcheckstyle_unix.skip=false -Drat.skip=false -Dmaven.javadoc.skip=true -DembeddedZookeeperPath=${{ github.workspace }}/.tmp/zookeeper
|
||||
- name: "Upload coverage to Codecov"
|
||||
uses: codecov/codecov-action@v3
|
||||
|
||||
|
|
|
|||
|
|
@ -27,14 +27,24 @@ public class EnvironmentConfiguration implements Configuration {
|
|||
|
||||
@Override
|
||||
public Object getInternalProperty(String key) {
|
||||
String value = System.getenv(key);
|
||||
String value = getenv(key);
|
||||
if (StringUtils.isEmpty(value)) {
|
||||
value = System.getenv(StringUtils.toOSStyleKey(key));
|
||||
value = getenv(StringUtils.toOSStyleKey(key));
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
public Map<String, String> getProperties() {
|
||||
return getenv();
|
||||
}
|
||||
|
||||
// Adapt to System api, design for unit test
|
||||
|
||||
protected String getenv(String key) {
|
||||
return System.getenv(key);
|
||||
}
|
||||
|
||||
protected Map<String, String> getenv() {
|
||||
return System.getenv();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,13 +16,9 @@
|
|||
*/
|
||||
package org.apache.dubbo.common.config;
|
||||
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
|
|
@ -34,71 +30,33 @@ class EnvironmentConfigurationTest {
|
|||
private static final String MOCK_KEY = "DUBBO_KEY";
|
||||
private static final String MOCK_VALUE = "mockValue";
|
||||
|
||||
/**
|
||||
* Init.
|
||||
*/
|
||||
@BeforeEach
|
||||
public void init() {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGetInternalProperty() {
|
||||
Map<String, String> map = new HashMap<>();
|
||||
map.put(MOCK_KEY, MOCK_VALUE);
|
||||
try {
|
||||
setEnv(map);
|
||||
EnvironmentConfiguration configuration = new EnvironmentConfiguration();
|
||||
// this UT maybe only works on particular platform, assert only when value is not null.
|
||||
Assertions.assertEquals(MOCK_VALUE, configuration.getInternalProperty("dubbo.key"));
|
||||
Assertions.assertEquals(MOCK_VALUE, configuration.getInternalProperty("key"));
|
||||
Assertions.assertEquals(MOCK_VALUE, configuration.getInternalProperty("dubbo_key"));
|
||||
Assertions.assertEquals(MOCK_VALUE, configuration.getInternalProperty(MOCK_KEY));
|
||||
} catch (Exception e) {
|
||||
// skip test.
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
protected static void setEnv(Map<String, String> newenv) throws Exception {
|
||||
try {
|
||||
Class<?> processEnvironmentClass = Class.forName("java.lang.ProcessEnvironment");
|
||||
Field theEnvironmentField = processEnvironmentClass.getDeclaredField("theEnvironment");
|
||||
theEnvironmentField.setAccessible(true);
|
||||
Map<String, String> env = (Map<String, String>) theEnvironmentField.get(null);
|
||||
env.putAll(newenv);
|
||||
Field theCaseInsensitiveEnvironmentField = processEnvironmentClass.getDeclaredField("theCaseInsensitiveEnvironment");
|
||||
theCaseInsensitiveEnvironmentField.setAccessible(true);
|
||||
Map<String, String> cienv = (Map<String, String>) theCaseInsensitiveEnvironmentField.get(null);
|
||||
cienv.putAll(newenv);
|
||||
} catch (NoSuchFieldException e) {
|
||||
Class[] classes = Collections.class.getDeclaredClasses();
|
||||
Map<String, String> env = System.getenv();
|
||||
for (Class cl : classes) {
|
||||
if ("java.util.Collections$UnmodifiableMap".equals(cl.getName())) {
|
||||
Field field = cl.getDeclaredField("m");
|
||||
field.setAccessible(true);
|
||||
Object obj = field.get(env);
|
||||
Map<String, String> map = (Map<String, String>) obj;
|
||||
map.clear();
|
||||
map.putAll(newenv);
|
||||
}
|
||||
EnvironmentConfiguration configuration = new EnvironmentConfiguration() {
|
||||
@Override
|
||||
protected String getenv(String key) {
|
||||
return map.get(key);
|
||||
}
|
||||
}
|
||||
};
|
||||
// this UT maybe only works on particular platform, assert only when value is not null.
|
||||
Assertions.assertEquals(MOCK_VALUE, configuration.getInternalProperty("dubbo.key"));
|
||||
Assertions.assertEquals(MOCK_VALUE, configuration.getInternalProperty("key"));
|
||||
Assertions.assertEquals(MOCK_VALUE, configuration.getInternalProperty("dubbo_key"));
|
||||
Assertions.assertEquals(MOCK_VALUE, configuration.getInternalProperty(MOCK_KEY));
|
||||
}
|
||||
|
||||
private static void updateEnv(String name, String val) throws ReflectiveOperationException {
|
||||
Map<String, String> env = System.getenv();
|
||||
Field field = env.getClass().getDeclaredField("m");
|
||||
field.setAccessible(true);
|
||||
((Map<String, String>) field.get(env)).put(name, val);
|
||||
@Test
|
||||
void testGetProperties() {
|
||||
Map<String, String> map = new HashMap<>();
|
||||
map.put(MOCK_KEY, MOCK_VALUE);
|
||||
EnvironmentConfiguration configuration = new EnvironmentConfiguration() {
|
||||
@Override
|
||||
protected Map<String, String> getenv() {
|
||||
return map;
|
||||
}
|
||||
};
|
||||
Assertions.assertEquals(map, configuration.getProperties());
|
||||
}
|
||||
/**
|
||||
* Clean.
|
||||
*/
|
||||
@AfterEach
|
||||
public void clean(){
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
27
pom.xml
27
pom.xml
|
|
@ -538,7 +538,7 @@
|
|||
<configuration>
|
||||
<useSystemClassLoader>true</useSystemClassLoader>
|
||||
<forkMode>once</forkMode>
|
||||
<argLine>${argline}
|
||||
<argLine>${argline} ${jacocoArgLine}
|
||||
</argLine>
|
||||
<systemProperties>
|
||||
<!-- common shared -->
|
||||
|
|
@ -567,6 +567,31 @@
|
|||
</plugins>
|
||||
</build>
|
||||
</profile>
|
||||
|
||||
<profile>
|
||||
<id>jacoco089</id>
|
||||
<properties>
|
||||
<maven_jacoco_version>0.8.9-SNAPSHOT</maven_jacoco_version>
|
||||
</properties>
|
||||
<pluginRepositories>
|
||||
<pluginRepository>
|
||||
<id>apache.snapshots</id>
|
||||
<name>Apache Snapshot Repository</name>
|
||||
<url>https://repository.apache.org/snapshots</url>
|
||||
<releases>
|
||||
<enabled>false</enabled>
|
||||
</releases>
|
||||
</pluginRepository>
|
||||
<pluginRepository>
|
||||
<id>oss.snapshots</id>
|
||||
<name>Oss Repository</name>
|
||||
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
|
||||
<releases>
|
||||
<enabled>false</enabled>
|
||||
</releases>
|
||||
</pluginRepository>
|
||||
</pluginRepositories>
|
||||
</profile>
|
||||
</profiles>
|
||||
|
||||
<build>
|
||||
|
|
|
|||
Loading…
Reference in New Issue