Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix the apollo version logic by reading the server version instead of the apollo-core version #5105

Merged
merged 1 commit into from
Mar 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Copyright 2022 Apollo 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 com.ctrip.framework.apollo.common.constants;

/**
* @author Jason Song(song_s@ctrip.com)
*/
public class ApolloServer {
public final static String VERSION =
"java-" + ApolloServer.class.getPackage().getImplementationVersion();

Check warning on line 24 in apollo-common/src/main/java/com/ctrip/framework/apollo/common/constants/ApolloServer.java

View check run for this annotation

Codecov / codecov/patch

apollo-common/src/main/java/com/ctrip/framework/apollo/common/constants/ApolloServer.java#L22-L24

Added lines #L22 - L24 were not covered by tests
Comment on lines +22 to +24
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The introduction of ApolloServer.VERSION is a positive change for accurately representing the server version. However, consider adding a fallback mechanism or ensuring through documentation that the ImplementationVersion in the package metadata is always set to avoid the java-null scenario.

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@
*/
package com.ctrip.framework.apollo.common.controller;

import com.ctrip.framework.apollo.Apollo;
import com.ctrip.framework.apollo.common.constants.ApolloServer;
import com.ctrip.framework.foundation.Foundation;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

Expand All @@ -38,6 +37,6 @@

@RequestMapping("version")
public String getVersion() {
return Apollo.VERSION;
return ApolloServer.VERSION;

Check warning on line 40 in apollo-common/src/main/java/com/ctrip/framework/apollo/common/controller/ApolloInfoController.java

View check run for this annotation

Codecov / codecov/patch

apollo-common/src/main/java/com/ctrip/framework/apollo/common/controller/ApolloInfoController.java#L40

Added line #L40 was not covered by tests
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,16 @@
*/
package com.ctrip.framework.apollo.portal.controller;

import com.ctrip.framework.apollo.Apollo;
import com.ctrip.framework.apollo.portal.environment.PortalMetaDomainService;
import com.ctrip.framework.apollo.common.constants.ApolloServer;
import com.ctrip.framework.apollo.core.dto.ServiceDTO;
import com.ctrip.framework.apollo.portal.environment.Env;
import com.ctrip.framework.apollo.portal.component.PortalSettings;
import com.ctrip.framework.apollo.portal.component.RestTemplateFactory;
import com.ctrip.framework.apollo.portal.entity.vo.EnvironmentInfo;
import com.ctrip.framework.apollo.portal.entity.vo.SystemInfo;
import com.ctrip.framework.apollo.portal.environment.Env;
import com.ctrip.framework.apollo.portal.environment.PortalMetaDomainService;
import java.util.List;
import javax.annotation.PostConstruct;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.actuate.health.Health;
Expand All @@ -34,9 +36,6 @@
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import javax.annotation.PostConstruct;
import java.util.List;

@RestController
@RequestMapping("/system-info")
public class SystemInfoController {
Expand Down Expand Up @@ -70,7 +69,7 @@
public SystemInfo getSystemInfo() {
SystemInfo systemInfo = new SystemInfo();

String version = Apollo.VERSION;
String version = ApolloServer.VERSION;

Check warning on line 72 in apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/SystemInfoController.java

View check run for this annotation

Codecov / codecov/patch

apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/SystemInfoController.java#L72

Added line #L72 was not covered by tests
if (isValidVersion(version)) {
systemInfo.setVersion(version);
}
Expand Down
Loading