98 lines
3.0 KiB
Java
98 lines
3.0 KiB
Java
package com.spring.common.util;
|
|
|
|
import java.util.Arrays;
|
|
|
|
import org.springframework.core.env.Environment;
|
|
import org.springframework.stereotype.Component;
|
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
|
@Component
|
|
@RequiredArgsConstructor
|
|
public class ProfileUtils {
|
|
|
|
private final Environment environment;
|
|
|
|
/**
|
|
* 현재 활성화된 프로파일 목록을 반환합니다.
|
|
*
|
|
* @return 현재 활성화된 프로파일 배열
|
|
*/
|
|
public String[] getActiveProfiles() {
|
|
return environment.getActiveProfiles();
|
|
}
|
|
|
|
/**
|
|
* 현재 프로파일이 'prod'인지 확인하는 메소드.
|
|
*
|
|
* @return true if the current profile is 'prod', false otherwise.
|
|
*/
|
|
public boolean isProdProfile() {
|
|
return isProfileActive("prod");
|
|
}
|
|
|
|
/**
|
|
* 현재 프로파일이 'dev'인지 확인하는 메소드.
|
|
*
|
|
* @return true if the current profile is 'dev', false otherwise.
|
|
*/
|
|
public boolean isDevProfile() {
|
|
return isProfileActive("dev");
|
|
}
|
|
|
|
/**
|
|
* 특정 프로파일이 활성화되어 있는지 확인하는 메소드.
|
|
*
|
|
* @param profile 확인할 프로파일 이름
|
|
* @return true if the specified profile is active, false otherwise.
|
|
*/
|
|
public boolean isProfileActive(String profile) {
|
|
return Arrays.asList(environment.getActiveProfiles()).contains(profile);
|
|
}
|
|
|
|
/**
|
|
* 현재 활성화된 프로파일이 여러 개일 경우, 그 중 하나라도 주어진 프로파일이 포함되어 있는지 확인하는 메소드.
|
|
*
|
|
* @param profiles 확인할 프로파일 이름 배열
|
|
* @return true if any of the specified profiles are active, false otherwise.
|
|
*/
|
|
public boolean isAnyProfileActive(String... profiles) {
|
|
for (String profile : profiles) {
|
|
if (isProfileActive(profile)) {
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* 현재 활성화된 프로파일 중 가장 우선순위가 높은 프로파일을 반환합니다.
|
|
*
|
|
* @return 가장 우선순위가 높은 프로파일 이름, 없으면 null
|
|
*/
|
|
public String getHighestPriorityProfile() {
|
|
String[] activeProfiles = getActiveProfiles();
|
|
return activeProfiles.length > 0 ? activeProfiles[0] : null; // 첫 번째 프로파일이 가장 우선순위가 높다고 가정
|
|
}
|
|
|
|
/**
|
|
* 기본 프로파일이 설정되어 있는지 확인하는 메소드.
|
|
*
|
|
* @return true if the default profile is active, false otherwise.
|
|
*/
|
|
public boolean isDefaultProfileActive() {
|
|
return isProfileActive("default");
|
|
}
|
|
|
|
/**
|
|
* 주어진 프로파일이 활성화되어 있지 않은지 확인하는 메소드.
|
|
*
|
|
* @param profile 확인할 프로파일 이름
|
|
* @return true if the specified profile is not active, false otherwise.
|
|
*/
|
|
public boolean isProfileInactive(String profile) {
|
|
return !isProfileActive(profile);
|
|
}
|
|
|
|
}
|