Skip to content

Commit

Permalink
🎨 Format
Browse files Browse the repository at this point in the history
  • Loading branch information
heliannuuthus committed Mar 26, 2024
1 parent 4856a4e commit e8e86a3
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 35 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ plugins {
id "com.diffplug.spotless" version "6.25.0"
}

apply from: "https://cdn.jsdelivr.net/gh/heliannuuthus/integration-deploy/gradle/multi-library.gradle"
apply from: "https://cdn.jsdelivr.net/gh/heliannuuthus/integrate-deploy/gradle/multi-library.gradle"


ext {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,47 +1,46 @@
package io.ghcr.heliannuuthus;

import com.ctrip.framework.apollo.core.ApolloClientSystemConsts;
import java.text.MessageFormat;
import java.util.Arrays;
import java.util.Optional;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ApplicationContextInitializer;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.Ordered;
import org.springframework.core.env.ConfigurableEnvironment;

import java.text.MessageFormat;
import java.util.Arrays;
import java.util.Optional;

@Slf4j
public class ApolloMetaServerInitializer
implements ApplicationContextInitializer<ConfigurableApplicationContext>, Ordered {
public static final int ORDER = -1;
private static final String SCHEMA = "config";
private static final String SPRING_APPLICATION_NAME_KEY = "spring.application.name";
private static final String DEFAULT_META_SERVER = "http://{0}.heliannuuthus.org";
private static final String DEFAULT_ENV = "dev";
private static final String PROD_ENV = "prod";
private static final String MIDDLE_LINE = "-";
implements ApplicationContextInitializer<ConfigurableApplicationContext>, Ordered {
public static final int ORDER = -1;
private static final String SCHEMA = "config";
private static final String SPRING_APPLICATION_NAME_KEY = "spring.application.name";
private static final String DEFAULT_META_SERVER = "http://{0}.heliannuuthus.org";
private static final String DEFAULT_ENV = "dev";
private static final String PROD_ENV = "prod";
private static final String MIDDLE_LINE = "-";

@Override
public int getOrder() {
return ORDER;
}
@Override
public int getOrder() {
return ORDER;
}

@Override
public void initialize(ConfigurableApplicationContext applicationContext) {
ConfigurableEnvironment environment = applicationContext.getEnvironment();
Optional.ofNullable(environment.getProperty(SPRING_APPLICATION_NAME_KEY))
.ifPresent(
applicationName ->
System.setProperty(ApolloClientSystemConsts.APP_ID, applicationName));
String env =
Optional.of(environment.getActiveProfiles())
.flatMap(profiles -> Arrays.stream(profiles).findFirst())
.orElse(DEFAULT_ENV);
System.setProperty("env", env);
System.setProperty(
ApolloClientSystemConsts.APOLLO_META,
MessageFormat.format(
DEFAULT_META_SERVER, PROD_ENV.equals(env) ? SCHEMA : SCHEMA + MIDDLE_LINE + env));
}
@Override
public void initialize(ConfigurableApplicationContext applicationContext) {
ConfigurableEnvironment environment = applicationContext.getEnvironment();
Optional.ofNullable(environment.getProperty(SPRING_APPLICATION_NAME_KEY))
.ifPresent(
applicationName ->
System.setProperty(ApolloClientSystemConsts.APP_ID, applicationName));
String env =
Optional.of(environment.getActiveProfiles())
.flatMap(profiles -> Arrays.stream(profiles).findFirst())
.orElse(DEFAULT_ENV);
System.setProperty("env", env);
System.setProperty(
ApolloClientSystemConsts.APOLLO_META,
MessageFormat.format(
DEFAULT_META_SERVER, PROD_ENV.equals(env) ? SCHEMA : SCHEMA + MIDDLE_LINE + env));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.info.License;
import java.time.Duration;
import lombok.extern.slf4j.Slf4j;
import org.springdoc.core.utils.SpringDocUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
Expand All @@ -13,6 +15,10 @@
@Configuration
public class OpenapiConfiguration {

static {
SpringDocUtils.getConfig().replaceWithClass(Duration.class, String.class);
}

@Value("${spring.application.name}")
private String application;

Expand All @@ -38,7 +44,7 @@ private ExternalDocumentation externalDocumentation() {

@Bean
public OpenAPI springShopOpenAPI() {
log.info("openapi: http://{}:{}/redoc.html", serverAddress, port);
log.info("openapi url: http://{}:{}/redoc.html", serverAddress, port);
return new OpenAPI().info(info()).externalDocs(externalDocumentation());
}
}

0 comments on commit e8e86a3

Please sign in to comment.