下面列出了怎么用org.springframework.boot.info.BuildProperties的API类实例代码及写法,或者点击链接到github查看源代码。
public MenuTemplate(BuildProperties buildProperties) {
getModel().setVersion(buildProperties.getVersion());
addCategoryName("RadMan");
addNavigation(UsersView.class, "Users");
addNavigation(UserGroupsView.class, "User groups");
addNavigation(AttributesView.class, "Attributes");
addSeparator();
addCategoryName("Radius");
addNavigation(NasView.class, "NAS");
addNavigation(NasGroupsView.class, "NAS groups");
addNavigation(AuthView.class, "Auth (AA)");
addNavigation(AccountingView.class, "Accounting");
addNavigation(UserToGroupView.class, "User/Group");
addSeparator();
addCategoryName("System");
addNavigation(SystemUsersView.class, "System users");
}
public LoggingConfiguration(@Value("${spring.application.name}") String appName, @Value("${server.port}") String serverPort,
Optional<BuildProperties> buildProperties, JHipsterProperties jHipsterProperties) {
this.appName = appName;
this.serverPort = serverPort;
this.version = buildProperties.isPresent() ? buildProperties.get().getVersion() : "";
this.jHipsterProperties = jHipsterProperties;
if (this.jHipsterProperties.getLogging().isUseJsonFormat()) {
addJsonConsoleAppender(context);
}
if (this.jHipsterProperties.getLogging().getLogstash().isEnabled()) {
addLogstashTcpSocketAppender(context);
}
if (this.jHipsterProperties.getLogging().isUseJsonFormat() || this.jHipsterProperties.getLogging().getLogstash().isEnabled()) {
addContextListener(context);
}
if (this.jHipsterProperties.getMetrics().getLogs().isEnabled()) {
setMetricsMarkerLogbackFilter(context);
}
}
public LoggingConfiguration(@Value("${spring.application.name}") String appName, @Value("${server.port}") String serverPort,
Optional<BuildProperties> buildProperties, JHipsterProperties jHipsterProperties) {
this.appName = appName;
this.serverPort = serverPort;
this.version = buildProperties.isPresent() ? buildProperties.get().getVersion() : "";
this.jHipsterProperties = jHipsterProperties;
if (this.jHipsterProperties.getLogging().isUseJsonFormat()) {
addJsonConsoleAppender(context);
}
if (this.jHipsterProperties.getLogging().getLogstash().isEnabled()) {
addLogstashTcpSocketAppender(context);
}
if (this.jHipsterProperties.getLogging().isUseJsonFormat() || this.jHipsterProperties.getLogging().getLogstash().isEnabled()) {
addContextListener(context);
}
if (this.jHipsterProperties.getMetrics().getLogs().isEnabled()) {
setMetricsMarkerLogbackFilter(context);
}
}
public LoggingConfiguration(@Value("${spring.application.name}") String appName, @Value("${server.port}") String serverPort,
Optional<BuildProperties> buildProperties, JHipsterProperties jHipsterProperties) {
this.appName = appName;
this.serverPort = serverPort;
this.version = buildProperties.isPresent() ? buildProperties.get().getVersion() : "";
this.jHipsterProperties = jHipsterProperties;
if (this.jHipsterProperties.getLogging().isUseJsonFormat()) {
addJsonConsoleAppender(context);
}
if (this.jHipsterProperties.getLogging().getLogstash().isEnabled()) {
addLogstashTcpSocketAppender(context);
}
if (this.jHipsterProperties.getLogging().isUseJsonFormat() || this.jHipsterProperties.getLogging().getLogstash().isEnabled()) {
addContextListener(context);
}
if (this.jHipsterProperties.getMetrics().getLogs().isEnabled()) {
setMetricsMarkerLogbackFilter(context);
}
}
@Autowired
public KmsService(
AwsIamRoleDao awsIamRoleDao,
UuidSupplier uuidSupplier,
KmsClientFactory kmsClientFactory,
KmsPolicyService kmsPolicyService,
DateTimeSupplier dateTimeSupplier,
AwsIamRoleArnParser awsIamRoleArnParser,
@Value("${cerberus.auth.kms.policy.validation.interval.millis:300000}")
int kmsKeyPolicyValidationInterval,
@Value("${cerberus.environmentName}") String environmentName,
Slugger slugger,
BuildProperties buildProperties) {
this.awsIamRoleDao = awsIamRoleDao;
this.uuidSupplier = uuidSupplier;
this.kmsClientFactory = kmsClientFactory;
this.kmsPolicyService = kmsPolicyService;
this.dateTimeSupplier = dateTimeSupplier;
this.awsIamRoleArnParser = awsIamRoleArnParser;
this.kmsKeyPolicyValidationInterval = kmsKeyPolicyValidationInterval;
this.environmentName = environmentName;
this.slugger = slugger;
this.buildProperties = buildProperties;
}
private String generatePrefix(GitProperties gitProperties, BuildProperties buildProperties) {
String shortCommitId = null;
if (Objects.nonNull(gitProperties)) {
shortCommitId = gitProperties.getShortCommitId();
}
Instant time = null;
String version = null;
if (Objects.nonNull(buildProperties)) {
time = buildProperties.getTime();
version = buildProperties.getVersion();
}
Object p = ObjectUtils.firstNonNull(shortCommitId, time, version, RandomStringUtils.randomAlphanumeric(12));
if (p instanceof Instant) {
return DateTimeFormatter.ISO_INSTANT.format((Instant) p);
}
return p.toString();
}
@Autowired
public AuditLoggingFilter(
SdbAccessRequest sdbAccessRequest,
AuditLoggingFilterDetails auditLoggingFilterDetails,
BuildProperties buildProperties,
ApplicationEventPublisher applicationEventPublisher) {
this.sdbAccessRequest = sdbAccessRequest;
this.auditLoggingFilterDetails = auditLoggingFilterDetails;
this.buildProperties = buildProperties;
this.applicationEventPublisher = applicationEventPublisher;
}
@Before
public void setup() {
awsIamRoleDao = mock(AwsIamRoleDao.class);
uuidSupplier = mock(UuidSupplier.class);
kmsClientFactory = mock(KmsClientFactory.class);
kmsPolicyService = mock(KmsPolicyService.class);
dateTimeSupplier = mock(DateTimeSupplier.class);
slugger = new Slugger();
var props = new Properties();
props.setProperty("artifact", ARTIFACT);
props.setProperty("version", VERSION);
var buildProps = new BuildProperties(props);
kmsService =
new KmsService(
awsIamRoleDao,
uuidSupplier,
kmsClientFactory,
kmsPolicyService,
dateTimeSupplier,
new AwsIamRoleArnParser(),
3000,
ENV,
slugger,
buildProps);
}
public LoggingConfiguration(@Value("${spring.application.name}") String appName,
@Value("${server.port}") String serverPort,
JHipsterProperties jHipsterProperties,
ObjectProvider<BuildProperties> buildProperties,
ObjectMapper mapper) throws JsonProcessingException {
LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
Map<String, String> map = new HashMap<>();
map.put("app_name", appName);
map.put("app_port", serverPort);
buildProperties.ifAvailable(it -> map.put("version", it.getVersion()));
String customFields = mapper.writeValueAsString(map);
JHipsterProperties.Logging loggingProperties = jHipsterProperties.getLogging();
JHipsterProperties.Logging.Logstash logstashProperties = loggingProperties.getLogstash();
if (loggingProperties.isUseJsonFormat()) {
addJsonConsoleAppender(context, customFields);
}
if (logstashProperties.isEnabled()) {
addLogstashTcpSocketAppender(context, customFields, logstashProperties);
}
if (loggingProperties.isUseJsonFormat() || logstashProperties.isEnabled()) {
addContextListener(context, customFields, loggingProperties);
}
if (jHipsterProperties.getMetrics().getLogs().isEnabled()) {
setMetricsMarkerLogbackFilter(context, loggingProperties.isUseJsonFormat());
}
}
@Autowired
public SystemInfoService(BuildProperties buildProperties, Environment environment, Optional<GitProperties> gitProperties) {
this.buildProperties = buildProperties;
this.environment = environment;
this.gitProperties = gitProperties;
addStaticProperties();
}
@Bean
public BuildProperties buildProperties() {
Properties props = new Properties();
props.put("version", "test");
return new BuildProperties(props);
}
@GetMapping
public BuildProperties getBuildProperties(HttpServletRequest request) throws HttpClientErrorException {
return buildProperties;
}
@Test
public void generatePrefixFromBuildVersion() {
Properties buildProperties = new Properties();
buildProperties.put("version", "1.0.0");
PrefixedKeyGenerator prefixedKeyGenerator = new PrefixedKeyGenerator(null, new BuildProperties(buildProperties));
assertThat(prefixedKeyGenerator.getPrefix()).isEqualTo("1.0.0");
}
@Test
public void generatePrefixFromBuildTime() {
Properties buildProperties = new Properties();
buildProperties.put("time", "1583955265");
PrefixedKeyGenerator prefixedKeyGenerator = new PrefixedKeyGenerator(null, new BuildProperties(buildProperties));
assertThat(prefixedKeyGenerator.getPrefix()).isEqualTo("1970-01-19T07:59:15.265Z");
}
/**
* Instantiates a new Feast Serving properties.
*
* @param buildProperties the build properties
*/
@Autowired
public FeastProperties(BuildProperties buildProperties) {
setVersion(buildProperties.getVersion());
}
/**
* Instantiates a new Feast properties.
*
* @param buildProperties Feast build properties
*/
@Autowired
public FeastProperties(BuildProperties buildProperties) {
setVersion(buildProperties.getVersion());
}
public BuildInfo fromProperties(BuildProperties properties) {
return new BuildInfo(properties.getVersion(), properties.getTime());
}
public PrefixedKeyGenerator(GitProperties gitProperties, BuildProperties buildProperties) {
this.prefix = generatePrefix(gitProperties, buildProperties);
}