Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
mercyblitz committed Apr 15, 2024
2 parents 189c6bf + 65be1c0 commit 57da989
Show file tree
Hide file tree
Showing 17 changed files with 681 additions and 104 deletions.
32 changes: 32 additions & 0 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-maven

# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.

name: Java CI with Maven

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
java: [ '8' ,'11' ]
steps:
- uses: actions/checkout@v4
- name: Java ${{ matrix.Java }}
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: ${{ matrix.java }}
cache: maven
- name: Build with Maven
run: mvn --batch-mode --update-snapshots --file pom.xml -Drevision=0.0.1 clean install
Binary file added .mvn/wrapper/maven-wrapper.jar
Binary file not shown.
16 changes: 16 additions & 0 deletions .mvn/wrapper/maven-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Copyright 2013-2023 the original author or 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
#
# https://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.

distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.0/apache-maven-3.9.0-bin.zip
wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.1/maven-wrapper-3.1.1.jar
9 changes: 8 additions & 1 deletion microsphere-i18n-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,14 @@
<!-- Microsphere -->
<dependency>
<groupId>io.github.microsphere-projects</groupId>
<artifactId>microsphere-core</artifactId>
<artifactId>microsphere-java-core</artifactId>
</dependency>

<!-- Java API Dependencies -->
<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>jsr305</artifactId>
<optional>true</optional>
</dependency>

<!-- Servlet API -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ default String getMessage(String code, Object... args) {
/**
* Get the default {@link Locale}
*
* @return {@link Locale#SIMPLIFIED_CHINESE} as default
* @return {@link Locale#getDefault()} as default
*/
@Nonnull
default Locale getDefaultLocale() {
return Locale.SIMPLIFIED_CHINESE;
return Locale.getDefault();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
import io.microsphere.i18n.util.I18nUtils;
import org.junit.After;
import org.junit.Before;
import org.junit.BeforeClass;

import java.util.Locale;

/**
* Abstract Spring Test
Expand All @@ -28,6 +31,12 @@
*/
public abstract class AbstractI18nTest {

@BeforeClass
public static void beforeClass() {
// Set the simplified Chinese as the default Locale
Locale.setDefault(Locale.SIMPLIFIED_CHINESE);
}

@Before
public void before() {
I18nUtils.destroyServiceMessageSource();
Expand Down
6 changes: 6 additions & 0 deletions microsphere-i18n-dependencies/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@
<version>${revision}</version>
</dependency>

<dependency>
<groupId>io.github.microsphere-projects</groupId>
<artifactId>microsphere-i18n-openfeign</artifactId>
<version>${revision}</version>
</dependency>

<dependency>
<groupId>io.github.microsphere-projects</groupId>
<artifactId>microsphere-i18n-spring</artifactId>
Expand Down
85 changes: 6 additions & 79 deletions microsphere-i18n-parent/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,14 @@
<description>Microsphere Internationalisation Parent</description>

<properties>
<microsphere.version>${revision}</microsphere.version>
<microsphere-spring.version>${revision}</microsphere-spring.version>
<apache.commons.lang3.version>3.4</apache.commons.lang3.version>
<microsphere-spring-cloud.version>0.0.1</microsphere-spring-cloud.version>
<apache.commons.io.version>2.4</apache.commons.io.version>
<apache.commons.collections.version>3.2.2</apache.commons.collections.version>

<jsr305.version>3.0.1</jsr305.version>
<javax.ws.rs.version>2.1</javax.ws.rs.version>
<fastjson.version>1.2.83_noneautotype</fastjson.version>
<feign.version>10.2.3</feign.version>
<p6spy.version>3.9.1</p6spy.version>
<alibaba.sentinel.version>1.8.6</alibaba.sentinel.version>

<spring-boot.version>2.7.18</spring-boot.version>
<resilience4j.version>1.7.0</resilience4j.version>

<junit.version>4.7</junit.version>
<jmh.version>1.36</jmh.version>
<antlr.version>4.13.1</antlr.version>
</properties>
Expand All @@ -45,93 +36,29 @@

<dependencies>

<!-- Spring Boot Dependencies -->
<!-- Microsphere Spring Cloud Dependencies -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>${spring-boot.version}</version>
<groupId>io.github.microsphere-projects</groupId>
<artifactId>microsphere-spring-cloud-dependencies</artifactId>
<version>${microsphere-spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>

<!-- Java API Dependencies -->
<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>jsr305</artifactId>
<version>${jsr305.version}</version>
</dependency>

<!-- Apache Commons Dependencies -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>${apache.commons.lang3.version}</version>
</dependency>

<dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
<version>${apache.commons.collections.version}</version>
</dependency>

<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>${apache.commons.io.version}</version>
</dependency>

<!-- Third-Party Dependencies -->
<!-- Alibaba Fastjson Dependencies -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>${fastjson.version}</version>
</dependency>

<dependency>
<groupId>io.github.openfeign</groupId>
<artifactId>feign-core</artifactId>
<version>${feign.version}</version>
</dependency>

<!-- JAX-RS API -->
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
<version>${javax.ws.rs.version}</version>
</dependency>

<!-- JDBC -->
<dependency>
<groupId>p6spy</groupId>
<artifactId>p6spy</artifactId>
<version>${p6spy.version}</version>
</dependency>

<!-- Alibaba Sentinel -->
<dependency>
<groupId>com.alibaba.csp</groupId>
<artifactId>sentinel-core</artifactId>
<version>${alibaba.sentinel.version}</version>
</dependency>

<!-- Microsphere Dependencies -->
<dependency>
<groupId>io.github.microsphere-projects</groupId>
<artifactId>microsphere-dependencies</artifactId>
<version>${microsphere.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>

<!-- Microsphere Spring Dependencies -->
<dependency>
<groupId>io.github.microsphere-projects</groupId>
<artifactId>microsphere-spring-dependencies</artifactId>
<version>${microsphere-spring.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>

<!-- Testing -->
<dependency>
<groupId>org.openjdk.jmh</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@
import org.springframework.beans.factory.ListableBeanFactory;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.lang.NonNull;

import javax.annotation.Nonnull;
import java.nio.charset.Charset;
import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
import java.util.Set;

import static io.microsphere.i18n.spring.util.LocaleUtils.getLocaleFromLocaleContext;
import static org.springframework.core.annotation.AnnotationAwareOrderComparator.sort;

/**
Expand Down Expand Up @@ -59,7 +60,7 @@ public void afterPropertiesSet() throws Exception {
init();
}

@Nonnull
@NonNull
@Override
public String getMessage(String code, Locale locale, Object... args) {
return this.delegate.getMessage(code, locale, args);
Expand All @@ -70,20 +71,20 @@ public String getMessage(String code, Object... args) {
return this.delegate.getMessage(code, args);
}

@Nonnull
@NonNull
@Override
public Locale getLocale() {
Locale locale = LocaleContextHolder.getLocale();
Locale locale = getLocaleFromLocaleContext();
return locale == null ? this.delegate.getLocale() : locale;
}

@Nonnull
@NonNull
@Override
public Locale getDefaultLocale() {
return this.delegate.getDefaultLocale();
}

@Nonnull
@NonNull
@Override
public List<Locale> getSupportedLocales() {
return this.delegate.getSupportedLocales();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.core.env.Environment;
import org.springframework.core.env.PropertySources;
import org.springframework.lang.Nullable;

import javax.annotation.Nullable;
import java.io.IOException;
import java.io.Reader;
import java.io.StringReader;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,13 @@
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.ApplicationListener;
import org.springframework.context.EnvironmentAware;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.core.Ordered;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.Environment;
import org.springframework.lang.NonNull;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;

import javax.annotation.Nonnull;
import java.lang.reflect.Constructor;
import java.nio.charset.Charset;
import java.util.ArrayList;
Expand All @@ -34,6 +33,7 @@

import static io.microsphere.i18n.spring.constants.I18nConstants.DEFAULT_LOCALE_PROPERTY_NAME;
import static io.microsphere.i18n.spring.constants.I18nConstants.SUPPORTED_LOCALES_PROPERTY_NAME;
import static io.microsphere.i18n.spring.util.LocaleUtils.getLocaleFromLocaleContext;
import static io.microsphere.spring.util.BeanUtils.getSortedBeans;
import static io.microsphere.spring.util.BeanUtils.invokeAwareInterfaces;
import static java.util.Collections.emptyList;
Expand Down Expand Up @@ -71,7 +71,12 @@ public final class ServiceMessageSourceFactoryBean implements ReloadableResource
private int order;

public ServiceMessageSourceFactoryBean(String source) {
this(source, Ordered.LOWEST_PRECEDENCE);
}

public ServiceMessageSourceFactoryBean(String source, int order) {
this.source = source;
this.order = order;
this.delegate = new CompositeServiceMessageSource();
}

Expand Down Expand Up @@ -100,7 +105,7 @@ public void destroy() {
this.delegate.destroy();
}

@Nonnull
@NonNull
@Override
public String getMessage(String code, Locale locale, Object... args) {
return this.delegate.getMessage(code, locale, args);
Expand All @@ -111,23 +116,23 @@ public String getMessage(String code, Object... args) {
return this.delegate.getMessage(code, args);
}

@Nonnull
@NonNull
@Override
public Locale getLocale() {
Locale locale = LocaleContextHolder.getLocale();
Locale locale = getLocaleFromLocaleContext();
if (locale == null) {
locale = this.delegate.getLocale();
}
return locale;
}

@Nonnull
@NonNull
@Override
public Locale getDefaultLocale() {
return this.delegate.getDefaultLocale();
}

@Nonnull
@NonNull
@Override
public List<Locale> getSupportedLocales() {
return this.delegate.getSupportedLocales();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import java.util.Set;
import java.util.concurrent.ConcurrentSkipListSet;

import static io.microsphere.i18n.spring.context.I18nConfiguration.isEnabled;
import static org.springframework.util.ObjectUtils.toObjectArray;

/**
Expand All @@ -36,7 +37,7 @@ public void initialize(ConfigurableApplicationContext context) {
}

private boolean shouldInitialization(ConfigurableApplicationContext context) {
if (!I18nConfiguration.isEnabled(context)) {
if (!isEnabled(context)) {
return false;
}
if (isProcessed(context)) {
Expand Down
Loading

0 comments on commit 57da989

Please sign in to comment.