Compare commits
4 Commits
20bef9263b
...
v0.0.3
| Author | SHA1 | Date | |
|---|---|---|---|
| 7eebccc40a | |||
|
|
d9b52c9c62 | ||
| 8fb926a31e | |||
|
|
0cf2347036 |
111
.gitea/workflows/ci.yml
Normal file
111
.gitea/workflows/ci.yml
Normal file
@@ -0,0 +1,111 @@
|
|||||||
|
name: CI/CD
|
||||||
|
|
||||||
|
on:
|
||||||
|
pull_request:
|
||||||
|
branches:
|
||||||
|
- master
|
||||||
|
types:
|
||||||
|
- closed
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build-deploy:
|
||||||
|
runs-on: act_runner_java
|
||||||
|
if: ${{ github.event.pull_request.merged == true }}
|
||||||
|
env:
|
||||||
|
JAVA_HOME: /usr/lib/jvm/java-21-openjdk
|
||||||
|
steps:
|
||||||
|
- name: Checkout code
|
||||||
|
run: |
|
||||||
|
git clone ${{ github.server_url }}/${{ github.repository }}.git .
|
||||||
|
git checkout ${{ github.sha }}
|
||||||
|
- name: Set up environment
|
||||||
|
run: |
|
||||||
|
echo "PR #${{ github.event.number }} merged into master"
|
||||||
|
echo "Source branch: ${{ github.event.pull_request.head.ref }}"
|
||||||
|
echo "Target branch: ${{ github.event.pull_request.base.ref }}"
|
||||||
|
- name: Run tests
|
||||||
|
run: |
|
||||||
|
echo "Running test suite..."
|
||||||
|
- name: Build project
|
||||||
|
run: |
|
||||||
|
mvn -B -DskipTests clean package source:jar javadoc:jar
|
||||||
|
- name: Deploy to Nexus
|
||||||
|
if: success()
|
||||||
|
run: |
|
||||||
|
if [ -z "${{ secrets.NEXUS_USERNAME }}" ] || [ -z "${{ secrets.NEXUS_PASSWORD }}" ]; then
|
||||||
|
echo "Missing secrets.NEXUS_USERNAME or secrets.NEXUS_PASSWORD"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
mkdir -p ~/.m2
|
||||||
|
cat > ~/.m2/settings.xml <<EOF
|
||||||
|
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
|
||||||
|
<servers>
|
||||||
|
<server>
|
||||||
|
<id>timi-nexus</id>
|
||||||
|
<username>${{ secrets.NEXUS_USERNAME }}</username>
|
||||||
|
<password>${{ secrets.NEXUS_PASSWORD }}</password>
|
||||||
|
</server>
|
||||||
|
</servers>
|
||||||
|
</settings>
|
||||||
|
EOF
|
||||||
|
version=$(mvn -q -DforceStdout help:evaluate -Dexpression=project.version)
|
||||||
|
artifact_id=$(mvn -q -DforceStdout help:evaluate -Dexpression=project.artifactId)
|
||||||
|
main_jar="target/${artifact_id}-${version}.jar"
|
||||||
|
sources_jar="target/${artifact_id}-${version}-sources.jar"
|
||||||
|
javadoc_jar="target/${artifact_id}-${version}-javadoc.jar"
|
||||||
|
if [ ! -f "$main_jar" ] || [ ! -f "$sources_jar" ] || [ ! -f "$javadoc_jar" ]; then
|
||||||
|
echo "Missing build artifacts in target"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
mvn -B deploy:deploy-file \
|
||||||
|
-Dfile="$main_jar" \
|
||||||
|
-Dsources="$sources_jar" \
|
||||||
|
-Djavadoc="$javadoc_jar" \
|
||||||
|
-DpomFile="./pom.xml" \
|
||||||
|
-Durl="https://nexus.imyeyu.com/repository/maven-releases/" \
|
||||||
|
-DrepositoryId="timi-nexus" \
|
||||||
|
-Dhttps.protocols=TLSv1.2 \
|
||||||
|
-Djdk.tls.client.protocols=TLSv1.2
|
||||||
|
- name: Create release
|
||||||
|
if: ${{ success() && startsWith(github.event.pull_request.title, 'v') }}
|
||||||
|
env:
|
||||||
|
GITEA_TOKEN: ${{ secrets.RUNNER_TOKEN }}
|
||||||
|
GITEA_SERVER_URL: ${{ github.server_url }}
|
||||||
|
GITEA_REPOSITORY: ${{ github.repository }}
|
||||||
|
RELEASE_TAG: ${{ github.event.pull_request.title }}
|
||||||
|
RELEASE_TARGET: ${{ github.sha }}
|
||||||
|
run: |
|
||||||
|
if [ -z "$GITEA_TOKEN" ]; then
|
||||||
|
echo "Missing secrets.RUNNER_TOKEN"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
api_url="$GITEA_SERVER_URL/api/v1/repos/$GITEA_REPOSITORY/releases"
|
||||||
|
payload=$(cat <<EOF
|
||||||
|
{
|
||||||
|
"tag_name": "$RELEASE_TAG",
|
||||||
|
"name": "$RELEASE_TAG",
|
||||||
|
"target_commitish": "$RELEASE_TARGET",
|
||||||
|
"draft": false,
|
||||||
|
"prerelease": false
|
||||||
|
}
|
||||||
|
EOF
|
||||||
|
)
|
||||||
|
response=$(curl -sS -X POST "$api_url" \
|
||||||
|
-H "Authorization: token $GITEA_TOKEN" \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-d "$payload")
|
||||||
|
release_id=$(echo "$response" | grep -o '"id":[0-9]*' | head -n 1 | grep -o '[0-9]*')
|
||||||
|
if [ -z "$release_id" ] || echo "$response" | grep -q '"message"'; then
|
||||||
|
echo "Create release failed: $response"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
echo "Release created: id=$release_id"
|
||||||
|
for asset_path in target/*.jar; do
|
||||||
|
asset_name=$(basename "$asset_path")
|
||||||
|
curl -sS -X POST "$api_url/$release_id/assets?name=$asset_name" \
|
||||||
|
-H "Authorization: token $GITEA_TOKEN" \
|
||||||
|
-H "Content-Type: application/octet-stream" \
|
||||||
|
--data-binary @"$asset_path"
|
||||||
|
done
|
||||||
43
pom.xml
43
pom.xml
@@ -6,10 +6,11 @@
|
|||||||
|
|
||||||
<groupId>com.imyeyu.lang</groupId>
|
<groupId>com.imyeyu.lang</groupId>
|
||||||
<artifactId>timi-lang</artifactId>
|
<artifactId>timi-lang</artifactId>
|
||||||
<version>0.0.2</version>
|
<version>0.0.3</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
|
<java.version>21</java.version>
|
||||||
<maven.test.skip>true</maven.test.skip>
|
<maven.test.skip>true</maven.test.skip>
|
||||||
<maven.compiler.source>21</maven.compiler.source>
|
<maven.compiler.source>21</maven.compiler.source>
|
||||||
<maven.compiler.target>21</maven.compiler.target>
|
<maven.compiler.target>21</maven.compiler.target>
|
||||||
@@ -27,29 +28,43 @@
|
|||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-source-plugin</artifactId>
|
<artifactId>maven-source-plugin</artifactId>
|
||||||
<version>3.3.1</version>
|
<version>3.3.1</version>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.projectlombok</groupId>
|
||||||
|
<artifactId>lombok-maven-plugin</artifactId>
|
||||||
|
<version>1.18.20.0</version>
|
||||||
|
<configuration>
|
||||||
|
<sourceDirectory>${project.basedir}/src/main/java</sourceDirectory>
|
||||||
|
<outputDirectory>${project.build.directory}/delombok</outputDirectory>
|
||||||
|
<addOutputDirectory>false</addOutputDirectory>
|
||||||
|
<encoding>UTF-8</encoding>
|
||||||
|
</configuration>
|
||||||
<executions>
|
<executions>
|
||||||
<execution>
|
<execution>
|
||||||
<id>attach-sources</id>
|
<phase>generate-sources</phase>
|
||||||
<phase>package</phase>
|
|
||||||
<goals>
|
<goals>
|
||||||
<goal>jar-no-fork</goal>
|
<goal>delombok</goal>
|
||||||
</goals>
|
</goals>
|
||||||
</execution>
|
</execution>
|
||||||
</executions>
|
</executions>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.projectlombok</groupId>
|
||||||
|
<artifactId>lombok</artifactId>
|
||||||
|
<version>1.18.36</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-javadoc-plugin</artifactId>
|
<artifactId>maven-javadoc-plugin</artifactId>
|
||||||
<version>3.11.2</version>
|
<version>3.11.2</version>
|
||||||
<executions>
|
<configuration>
|
||||||
<execution>
|
<sourcepath>${project.build.directory}/delombok</sourcepath>
|
||||||
<id>attach-javadocs</id>
|
<encoding>UTF-8</encoding>
|
||||||
<phase>package</phase>
|
<charset>UTF-8</charset>
|
||||||
<goals>
|
<docencoding>UTF-8</docencoding>
|
||||||
<goal>jar</goal>
|
</configuration>
|
||||||
</goals>
|
|
||||||
</execution>
|
|
||||||
</executions>
|
|
||||||
</plugin>
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
@@ -78,7 +93,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.imyeyu.io</groupId>
|
<groupId>com.imyeyu.io</groupId>
|
||||||
<artifactId>timi-io</artifactId>
|
<artifactId>timi-io</artifactId>
|
||||||
<version>0.0.2</version>
|
<version>0.0.4</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.junit.jupiter</groupId>
|
<groupId>org.junit.jupiter</groupId>
|
||||||
|
|||||||
@@ -3,6 +3,8 @@ package com.imyeyu.lang.mapper;
|
|||||||
import com.imyeyu.java.bean.Language;
|
import com.imyeyu.java.bean.Language;
|
||||||
import com.imyeyu.java.bean.LanguageMapping;
|
import com.imyeyu.java.bean.LanguageMapping;
|
||||||
import com.imyeyu.utils.StringInterpolator;
|
import com.imyeyu.utils.StringInterpolator;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@@ -18,9 +20,11 @@ public abstract class AbstractLanguageMapper implements LanguageMapping {
|
|||||||
protected final StringInterpolator INTERPOLATOR = StringInterpolator.createDollarInterpolator();
|
protected final StringInterpolator INTERPOLATOR = StringInterpolator.createDollarInterpolator();
|
||||||
|
|
||||||
/** 当前映射器所属语言 */
|
/** 当前映射器所属语言 */
|
||||||
|
@Getter
|
||||||
protected final Language.Enum language;
|
protected final Language.Enum language;
|
||||||
|
|
||||||
/** 是否启用调试模式,启用后将抛出异常而不是返回默认值 */
|
/** true 为启用调试模式 */
|
||||||
|
@Setter
|
||||||
protected boolean isDebugging = false;
|
protected boolean isDebugging = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -32,24 +36,6 @@ public abstract class AbstractLanguageMapper implements LanguageMapping {
|
|||||||
this.language = language;
|
this.language = language;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取当前映射器所属语言
|
|
||||||
*
|
|
||||||
* @return 语言枚举
|
|
||||||
*/
|
|
||||||
public Language.Enum getLanguage() {
|
|
||||||
return language;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 设置调试模式,调试模式下,找不到映射时将抛出异常而不是返回默认值
|
|
||||||
*
|
|
||||||
* @param debugging true 为启用调试模式
|
|
||||||
*/
|
|
||||||
public void setDebugging(boolean debugging) {
|
|
||||||
isDebugging = debugging;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取文本
|
* 获取文本
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package com.imyeyu.lang.mapper;
|
package com.imyeyu.lang.mapper;
|
||||||
|
|
||||||
import com.imyeyu.java.TimiJava;
|
import com.imyeyu.java.TimiJava;
|
||||||
import com.imyeyu.java.bean.CallbackArgReturn;
|
|
||||||
import com.imyeyu.java.bean.Language;
|
import com.imyeyu.java.bean.Language;
|
||||||
import com.imyeyu.utils.Text;
|
import com.imyeyu.utils.Text;
|
||||||
|
|
||||||
|
|||||||
@@ -13,6 +13,9 @@ import com.imyeyu.lang.mapper.LanguageMap;
|
|||||||
*/
|
*/
|
||||||
public class FileMultilingual extends Multilingual {
|
public class FileMultilingual extends Multilingual {
|
||||||
|
|
||||||
|
public FileMultilingual() {
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 构造并批量加载所有支持的语言文件
|
* 构造并批量加载所有支持的语言文件
|
||||||
*
|
*
|
||||||
@@ -33,16 +36,16 @@ public class FileMultilingual extends Multilingual {
|
|||||||
*/
|
*/
|
||||||
public void addAll(String path) {
|
public void addAll(String path) {
|
||||||
Language.Enum[] values = Language.Enum.values();
|
Language.Enum[] values = Language.Enum.values();
|
||||||
for (int i = 0; i < values.length; i++) {
|
for (Language.Enum value : values) {
|
||||||
FileLanguageMap mapper = new FileLanguageMap(values[i]);
|
FileLanguageMap mapper = new FileLanguageMap(value);
|
||||||
mapper.load(path);
|
mapper.load(path);
|
||||||
if (multilingualMap.containsKey(values[i])) {
|
if (multilingualMap.containsKey(value)) {
|
||||||
AbstractLanguageMapper existMapper = multilingualMap.get(values[i]);
|
AbstractLanguageMapper existMapper = multilingualMap.get(value);
|
||||||
if (existMapper instanceof LanguageMap map) {
|
if (existMapper instanceof LanguageMap map) {
|
||||||
map.union(mapper);
|
map.union(mapper);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
add(values[i], mapper);
|
add(value, mapper);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import com.imyeyu.java.bean.Language;
|
|||||||
import com.imyeyu.java.bean.LanguageMapping;
|
import com.imyeyu.java.bean.LanguageMapping;
|
||||||
import com.imyeyu.java.ref.Ref;
|
import com.imyeyu.java.ref.Ref;
|
||||||
import com.imyeyu.lang.mapper.AbstractLanguageMapper;
|
import com.imyeyu.lang.mapper.AbstractLanguageMapper;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@@ -49,6 +50,7 @@ public class Multilingual implements LanguageMapping {
|
|||||||
protected final List<CallbackArg<Language.Enum>> updateActiveListeners;
|
protected final List<CallbackArg<Language.Enum>> updateActiveListeners;
|
||||||
|
|
||||||
/** 当前激活语言 */
|
/** 当前激活语言 */
|
||||||
|
@Getter
|
||||||
protected Language.Enum activated;
|
protected Language.Enum activated;
|
||||||
|
|
||||||
/** 是否启用调试模式 */
|
/** 是否启用调试模式 */
|
||||||
@@ -121,20 +123,11 @@ public class Multilingual implements LanguageMapping {
|
|||||||
String[] localSp = activated.toString().split("_");
|
String[] localSp = activated.toString().split("_");
|
||||||
Locale.setDefault(new Locale(localSp[0], localSp[1]));
|
Locale.setDefault(new Locale(localSp[0], localSp[1]));
|
||||||
|
|
||||||
for (int i = 0; i < updateActiveListeners.size(); i++) {
|
for (CallbackArg<Language.Enum> updateActiveListener : updateActiveListeners) {
|
||||||
updateActiveListeners.get(i).handler(activated);
|
updateActiveListener.handler(activated);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取当前激活的语言
|
|
||||||
*
|
|
||||||
* @return 当前激活语言
|
|
||||||
*/
|
|
||||||
public Language.Enum getActivated() {
|
|
||||||
return activated;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 设置调试模式
|
* 设置调试模式
|
||||||
* <p>
|
* <p>
|
||||||
|
|||||||
@@ -16,6 +16,9 @@ import com.imyeyu.lang.mapper.ResourcesLanguageMap;
|
|||||||
*/
|
*/
|
||||||
public class ResourcesMultilingual extends Multilingual {
|
public class ResourcesMultilingual extends Multilingual {
|
||||||
|
|
||||||
|
public ResourcesMultilingual() {
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 构造并批量加载所有支持的语言资源文件
|
* 构造并批量加载所有支持的语言资源文件
|
||||||
*
|
*
|
||||||
@@ -36,16 +39,16 @@ public class ResourcesMultilingual extends Multilingual {
|
|||||||
*/
|
*/
|
||||||
public void addAll(String path) {
|
public void addAll(String path) {
|
||||||
Language.Enum[] values = Language.Enum.values();
|
Language.Enum[] values = Language.Enum.values();
|
||||||
for (int i = 0; i < values.length; i++) {
|
for (Language.Enum value : values) {
|
||||||
ResourcesLanguageMap mapper = new ResourcesLanguageMap(values[i]);
|
ResourcesLanguageMap mapper = new ResourcesLanguageMap(value);
|
||||||
mapper.load(path);
|
mapper.load(path);
|
||||||
if (multilingualMap.containsKey(values[i])) {
|
if (multilingualMap.containsKey(value)) {
|
||||||
AbstractLanguageMapper existMapper = multilingualMap.get(values[i]);
|
AbstractLanguageMapper existMapper = multilingualMap.get(value);
|
||||||
if (existMapper instanceof LanguageMap map) {
|
if (existMapper instanceof LanguageMap map) {
|
||||||
map.union(mapper);
|
map.union(mapper);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
add(values[i], mapper);
|
add(value, mapper);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user