Skip to content

Commit

Permalink
Merge branch 'apache-3.2' into 3.2.0-beta.2-release
Browse files Browse the repository at this point in the history
  • Loading branch information
AlbumenJ committed Nov 22, 2022
2 parents a8af2fe + 5f6a514 commit ced5b71
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -232,14 +232,14 @@ private void refreshInvoker(List<URL> invokerUrls) {
}
// use local reference to avoid NPE as this.cachedInvokerUrls will be set null by destroyAllInvokers().
Set<URL> localCachedInvokerUrls = this.cachedInvokerUrls;
if (invokerUrls.isEmpty() && localCachedInvokerUrls != null) {

// 1-4 Empty address.
logger.warn(REGISTRY_EMPTY_ADDRESS, "configuration ", "",
"Service" + serviceKey + " received empty address list with no EMPTY protocol set, trigger empty protection.");

invokerUrls.addAll(localCachedInvokerUrls);
if (invokerUrls.isEmpty()) {
if(CollectionUtils.isNotEmpty(localCachedInvokerUrls)){
// 1-4 Empty address.
logger.warn(REGISTRY_EMPTY_ADDRESS, "configuration ", "",
"Service" + serviceKey + " received empty address list with no EMPTY protocol set, trigger empty protection.");

invokerUrls.addAll(localCachedInvokerUrls);
}
} else {
localCachedInvokerUrls = new HashSet<>();
localCachedInvokerUrls.addAll(invokerUrls);//Cached invoker urls, convenient for comparison
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ void checkDubboBom() throws DocumentException {
.sorted()
.collect(Collectors.toList());

String dubboBomPath = "dubbo-distribution/dubbo-bom/pom.xml";
String dubboBomPath = "dubbo-distribution" + File.separator + "dubbo-bom" + File.separator + "pom.xml";
Document dubboBom = reader.read(new File(getBaseFile(), dubboBomPath));
List<String> artifactIdsInDubboBom = dubboBom.getRootElement()
.element("dependencyManagement")
Expand Down Expand Up @@ -120,7 +120,7 @@ void checkDubboDependenciesAll() throws DocumentException {
.sorted()
.collect(Collectors.toList());

String dubboDependenciesAllPath = "dubbo-test/dubbo-dependencies-all/pom.xml";
String dubboDependenciesAllPath = "dubbo-test" + File.separator + "dubbo-dependencies-all" + File.separator + "pom.xml";
Document dubboDependenciesAll = reader.read(new File(getBaseFile(), dubboDependenciesAllPath));
List<String> artifactIdsInDubboDependenciesAll = dubboDependenciesAll.getRootElement()
.element("dependencies")
Expand Down Expand Up @@ -177,7 +177,7 @@ void checkDubboAllDependencies() throws DocumentException {
.sorted()
.collect(Collectors.toList());

String dubboAllPath = "dubbo-distribution/dubbo-all/pom.xml";
String dubboAllPath = "dubbo-distribution" + File.separator + "dubbo-all" + File.separator + "pom.xml";
Document dubboAll = reader.read(new File(getBaseFile(), dubboAllPath));
List<String> artifactIdsInDubboAll = dubboAll.getRootElement()
.element("dependencies")
Expand All @@ -191,12 +191,12 @@ void checkDubboAllDependencies() throws DocumentException {
expectedArtifactIds.removeIf(artifactId -> ignoredModules.stream().anyMatch(pattern -> pattern.matcher(artifactId).matches()));
expectedArtifactIds.removeIf(artifactId -> ignoredModulesInDubboAll.stream().anyMatch(pattern -> pattern.matcher(artifactId).matches()));

Assertions.assertTrue(expectedArtifactIds.isEmpty(), "Newly created modules must be added to dubbo-all(dubbo-distribution/dubbo-all/pom.xml). Found modules: " + expectedArtifactIds);
Assertions.assertTrue(expectedArtifactIds.isEmpty(), "Newly created modules must be added to dubbo-all(dubbo-distribution" + File.separator + "dubbo-all" + File.separator + "pom.xml). Found modules: " + expectedArtifactIds);

List<String> unexpectedArtifactIds = new LinkedList<>(artifactIdsInDubboAll);
unexpectedArtifactIds.removeIf(artifactId -> !artifactIds.contains(artifactId));
unexpectedArtifactIds.removeAll(deployedArtifactIds);
Assertions.assertTrue(unexpectedArtifactIds.isEmpty(), "Undeploy dependencies should not be added to dubbo-all(dubbo-distribution/dubbo-all/pom.xml). Found modules: " + unexpectedArtifactIds);
Assertions.assertTrue(unexpectedArtifactIds.isEmpty(), "Undeploy dependencies should not be added to dubbo-all(dubbo-distribution" + File.separator + "dubbo-all" + File.separator + "pom.xml). Found modules: " + unexpectedArtifactIds);

unexpectedArtifactIds = new LinkedList<>();
for (String artifactId : artifactIdsInDubboAll) {
Expand All @@ -210,7 +210,7 @@ void checkDubboAllDependencies() throws DocumentException {
unexpectedArtifactIds.add(artifactId);
}
}
Assertions.assertTrue(unexpectedArtifactIds.isEmpty(), "Unexpected dependencies should not be added to dubbo-all(dubbo-distribution/dubbo-all/pom.xml). Found modules: " + unexpectedArtifactIds);
Assertions.assertTrue(unexpectedArtifactIds.isEmpty(), "Unexpected dependencies should not be added to dubbo-all(dubbo-distribution" + File.separator + "dubbo-all" + File.separator + "pom.xml). Found modules: " + unexpectedArtifactIds);
}

@Test
Expand Down Expand Up @@ -254,7 +254,7 @@ void checkDubboAllShade() throws DocumentException {
.sorted()
.collect(Collectors.toList());

String dubboAllPath = "dubbo-distribution/dubbo-all/pom.xml";
String dubboAllPath = "dubbo-distribution" + File.separator + "dubbo-all" + File.separator + "pom.xml";
Document dubboAll = reader.read(new File(getBaseFile(), dubboAllPath));
List<String> artifactIdsInDubboAll = dubboAll.getRootElement()
.element("build")
Expand All @@ -281,12 +281,12 @@ void checkDubboAllShade() throws DocumentException {
expectedArtifactIds.removeIf(artifactId -> ignoredModules.stream().anyMatch(pattern -> pattern.matcher(artifactId).matches()));
expectedArtifactIds.removeIf(artifactId -> ignoredModulesInDubboAll.stream().anyMatch(pattern -> pattern.matcher(artifactId).matches()));

Assertions.assertTrue(expectedArtifactIds.isEmpty(), "Newly created modules must be added to dubbo-all (dubbo-distribution/dubbo-all/pom.xml in shade plugin). Found modules: " + expectedArtifactIds);
Assertions.assertTrue(expectedArtifactIds.isEmpty(), "Newly created modules must be added to dubbo-all (dubbo-distribution" + File.separator + "dubbo-all" + File.separator + "pom.xml in shade plugin). Found modules: " + expectedArtifactIds);

List<String> unexpectedArtifactIds = new LinkedList<>(artifactIdsInDubboAll);
unexpectedArtifactIds.removeIf(artifactId -> !artifactIds.contains(artifactId));
unexpectedArtifactIds.removeAll(deployedArtifactIds);
Assertions.assertTrue(unexpectedArtifactIds.isEmpty(), "Undeploy dependencies should not be added to dubbo-all (dubbo-distribution/dubbo-all/pom.xml in shade plugin). Found modules: " + unexpectedArtifactIds);
Assertions.assertTrue(unexpectedArtifactIds.isEmpty(), "Undeploy dependencies should not be added to dubbo-all (dubbo-distribution" + File.separator + "dubbo-all" + File.separator + "pom.xml in shade plugin). Found modules: " + unexpectedArtifactIds);

unexpectedArtifactIds = new LinkedList<>();
for (String artifactId : artifactIdsInDubboAll) {
Expand All @@ -300,7 +300,7 @@ void checkDubboAllShade() throws DocumentException {
unexpectedArtifactIds.add(artifactId);
}
}
Assertions.assertTrue(unexpectedArtifactIds.isEmpty(), "Unexpected dependencies should not be added to dubbo-all (dubbo-distribution/dubbo-all/pom.xml in shade plugin). Found modules: " + unexpectedArtifactIds);
Assertions.assertTrue(unexpectedArtifactIds.isEmpty(), "Unexpected dependencies should not be added to dubbo-all (dubbo-distribution" + File.separator + "dubbo-all" + File.separator + "pom.xml in shade plugin). Found modules: " + unexpectedArtifactIds);
}

@Test
Expand All @@ -309,7 +309,7 @@ void checkDubboAllTransform() throws DocumentException {
List<String> spis = new LinkedList<>();
readSPI(baseFile, spis);

String dubboAllPath = "dubbo-distribution/dubbo-all/pom.xml";
String dubboAllPath = "dubbo-distribution" + File.separator + "dubbo-all" + File.separator + "pom.xml";

SAXReader reader = new SAXReader();
Document dubboAll = reader.read(new File(baseFile, dubboAllPath));
Expand All @@ -335,11 +335,11 @@ void checkDubboAllTransform() throws DocumentException {

List<String> expectedSpis = new LinkedList<>(spis);
expectedSpis.removeAll(transformsInDubboAll);
Assertions.assertTrue(expectedSpis.isEmpty(), "Newly created SPI interface must be added to dubbo-all(dubbo-distribution/dubbo-all/pom.xml in shade plugin) to being transformed. Found spis: " + expectedSpis);
Assertions.assertTrue(expectedSpis.isEmpty(), "Newly created SPI interface must be added to dubbo-all(dubbo-distribution" + File.separator + "dubbo-all" + File.separator + "pom.xml in shade plugin) to being transformed. Found spis: " + expectedSpis);

List<String> unexpectedSpis = new LinkedList<>(transformsInDubboAll);
unexpectedSpis.removeAll(spis);
Assertions.assertTrue(unexpectedSpis.isEmpty(), "Class without `@SPI` declaration should not be added to dubbo-all(dubbo-distribution/dubbo-all/pom.xml in shade plugin) to being transformed. Found spis: " + unexpectedSpis);
Assertions.assertTrue(unexpectedSpis.isEmpty(), "Class without `@SPI` declaration should not be added to dubbo-all(dubbo-distribution" + File.separator + "dubbo-all" + File.separator + "pom.xml in shade plugin) to being transformed. Found spis: " + unexpectedSpis);
}

@Test
Expand All @@ -356,8 +356,8 @@ void checkSpiFiles() {

List<File> unexpectedSpis = new LinkedList<>();
readSPIUnexpectedResource(baseFile, unexpectedSpis);
unexpectedSpis.removeIf(file -> file.getAbsolutePath().contains("dubbo-common/src/main/resources/META-INF/services/org.apache.dubbo.common.extension.LoadingStrategy"));
Assertions.assertTrue(unexpectedSpis.isEmpty(), "Dubbo native provided spi profiles must filed in `META-INF/dubbo/internal`. Please move to proper folder . Found spis: " + unexpectedSpis);
unexpectedSpis.removeIf(file -> file.getAbsolutePath().contains("dubbo-common" + File.separator + "src" + File.separator + "main" + File.separator + "resources" + File.separator + "META-INF" + File.separator + "services" + File.separator + "org.apache.dubbo.common.extension.LoadingStrategy"));
Assertions.assertTrue(unexpectedSpis.isEmpty(), "Dubbo native provided spi profiles must filed in `META-INF" + File.separator + "dubbo" + File.separator + "internal`. Please move to proper folder . Found spis: " + unexpectedSpis);
}

private static File getBaseFile() {
Expand Down Expand Up @@ -404,7 +404,7 @@ public void readSPI(File path, List<String> spis) {
if (path.getAbsolutePath().contains("target")) {
return;
}
if (path.getAbsolutePath().contains("src/main/java")) {
if (path.getAbsolutePath().contains("src" + File.separator + "main" + File.separator + "java")) {
String content;
try {
content = FileUtils.readFileToString(path, StandardCharsets.UTF_8);
Expand All @@ -413,9 +413,10 @@ public void readSPI(File path, List<String> spis) {
}
if (content != null && content.contains("@SPI")) {
String absolutePath = path.getAbsolutePath();
absolutePath = absolutePath.substring(absolutePath.lastIndexOf("src/main/java/") + "src/main/java/".length());
absolutePath = absolutePath.substring(absolutePath.lastIndexOf("src" + File.separator + "main" + File.separator + "java" + File.separator)
+ ("src" + File.separator + "main" + File.separator + "java" + File.separator).length());
absolutePath = absolutePath.substring(0, absolutePath.lastIndexOf(".java"));
absolutePath = absolutePath.replaceAll("/", ".");
absolutePath = absolutePath.replaceAll(File.separator, ".");
spis.add(absolutePath);
}
}
Expand All @@ -434,10 +435,11 @@ public void readSPIResource(File path, Map<File, String> spis) {
if (path.getAbsolutePath().contains("target")) {
return;
}
if (path.getAbsolutePath().contains("src/main/resources/META-INF/dubbo/internal/")) {
if (path.getAbsolutePath().contains("src" + File.separator + "main" + File.separator + "resources" + File.separator + "META-INF" + File.separator + "dubbo" + File.separator + "internal" + File.separator)) {
String absolutePath = path.getAbsolutePath();
absolutePath = absolutePath.substring(absolutePath.lastIndexOf("src/main/resources/META-INF/dubbo/internal/") + "src/main/resources/META-INF/dubbo/internal/".length());
absolutePath = absolutePath.replaceAll("/", ".");
absolutePath = absolutePath.substring(absolutePath.lastIndexOf("src" + File.separator + "main" + File.separator + "resources" + File.separator + "META-INF" + File.separator + "dubbo" + File.separator + "internal" + File.separator)
+ ("src" + File.separator + "main" + File.separator + "resources" + File.separator + "META-INF" + File.separator + "dubbo" + File.separator + "internal" + File.separator).length());
absolutePath = absolutePath.replaceAll( File.separator, ".");
spis.put(path, absolutePath);
}
}
Expand All @@ -455,35 +457,35 @@ public void readSPIUnexpectedResource(File path, List<File> spis) {
if (path.getAbsolutePath().contains("target")) {
return;
}
if (path.getAbsolutePath().contains("src/main/resources/META-INF/dubbo/org.apache.dubbo")) {
if (path.getAbsolutePath().contains("src" + File.separator + "main" + File.separator + "resources" + File.separator + "META-INF" + File.separator + "dubbo" + File.separator + "org.apache.dubbo")) {
spis.add(path);
}
if (path.getAbsolutePath().contains("src/main/resources/META-INF/dubbo/com.alibaba.dubbo")) {
if (path.getAbsolutePath().contains("src" + File.separator + "main" + File.separator + "resources" + File.separator + "META-INF" + File.separator + "dubbo" + File.separator + "com.alibaba.dubbo")) {
spis.add(path);
}
if (path.getAbsolutePath().contains("src/main/resources/META-INF/services/org.apache.dubbo")) {
if (path.getAbsolutePath().contains("src" + File.separator + "main" + File.separator + "resources" + File.separator + "META-INF" + File.separator + "services" + File.separator + "org.apache.dubbo")) {
spis.add(path);
}
if (path.getAbsolutePath().contains("src/main/resources/META-INF/services/com.alibaba.dubbo")) {
if (path.getAbsolutePath().contains("src" + File.separator + "main" + File.separator + "resources" + File.separator + "META-INF" + File.separator + "services" + File.separator + "com.alibaba.dubbo")) {
spis.add(path);
}

if (path.getAbsolutePath().contains("src/main/resources/META-INF.dubbo/org.apache.dubbo")) {
if (path.getAbsolutePath().contains("src" + File.separator + "main" + File.separator + "resources" + File.separator + "META-INF.dubbo" + File.separator + "org.apache.dubbo")) {
spis.add(path);
}
if (path.getAbsolutePath().contains("src/main/resources/META-INF.dubbo/com.alibaba.dubbo")) {
if (path.getAbsolutePath().contains("src" + File.separator + "main" + File.separator + "resources" + File.separator + "META-INF.dubbo" + File.separator + "com.alibaba.dubbo")) {
spis.add(path);
}
if (path.getAbsolutePath().contains("src/main/resources/META-INF.services/org.apache.dubbo")) {
if (path.getAbsolutePath().contains("src" + File.separator + "main" + File.separator + "resources" + File.separator + "META-INF.services" + File.separator + "org.apache.dubbo")) {
spis.add(path);
}
if (path.getAbsolutePath().contains("src/main/resources/META-INF.services/com.alibaba.dubbo")) {
if (path.getAbsolutePath().contains("src" + File.separator + "main" + File.separator + "resources" + File.separator + "META-INF.services" + File.separator + "com.alibaba.dubbo")) {
spis.add(path);
}
if (path.getAbsolutePath().contains("src/main/resources/META-INF.dubbo.internal/org.apache.dubbo")) {
if (path.getAbsolutePath().contains("src" + File.separator + "main" + File.separator + "resources" + File.separator + "META-INF.dubbo.internal" + File.separator + "org.apache.dubbo")) {
spis.add(path);
}
if (path.getAbsolutePath().contains("src/main/resources/META-INF.dubbo.internal/com.alibaba.dubbo")) {
if (path.getAbsolutePath().contains("src" + File.separator + "main" + File.separator + "resources" + File.separator + "META-INF.dubbo.internal" + File.separator + "com.alibaba.dubbo")) {
spis.add(path);
}
}
Expand Down

0 comments on commit ced5b71

Please sign in to comment.