Compare commits
6 Commits
e3e9f81f33
...
v0.0.3
| Author | SHA1 | Date | |
|---|---|---|---|
| 2020cb9111 | |||
|
|
8c5abdb149 | ||
| b686679014 | |||
|
|
1afc59dd12 | ||
|
|
97e07db838 | ||
|
|
b070950ed6 |
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,13 +6,13 @@
|
|||||||
|
|
||||||
<groupId>com.imyeyu.utils</groupId>
|
<groupId>com.imyeyu.utils</groupId>
|
||||||
<artifactId>timi-utils</artifactId>
|
<artifactId>timi-utils</artifactId>
|
||||||
<version>0.0.2</version>
|
<version>0.0.3</version>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
|
<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>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
<maven.test.skip>true</maven.test.skip>
|
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
@@ -26,29 +26,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>
|
||||||
@@ -95,7 +109,6 @@
|
|||||||
<groupId>org.projectlombok</groupId>
|
<groupId>org.projectlombok</groupId>
|
||||||
<artifactId>lombok</artifactId>
|
<artifactId>lombok</artifactId>
|
||||||
<version>1.18.34</version>
|
<version>1.18.34</version>
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
||||||
|
|||||||
@@ -82,7 +82,8 @@ public class OS {
|
|||||||
public static void run(String command) {
|
public static void run(String command) {
|
||||||
try {
|
try {
|
||||||
Runtime.getRuntime().exec(new String[] {command});
|
Runtime.getRuntime().exec(new String[] {command});
|
||||||
} catch (Exception ignored) {
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -76,6 +76,15 @@ public class Regex {
|
|||||||
/** 护照 */
|
/** 护照 */
|
||||||
public static final String PASSPORT = "^[a-zA-Z0-9]{5,17}$";
|
public static final String PASSPORT = "^[a-zA-Z0-9]{5,17}$";
|
||||||
|
|
||||||
|
// IPv4 正则表达式
|
||||||
|
public static final String IPv4 = "^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$";
|
||||||
|
|
||||||
|
// IPv6 正则表达式(简化版)
|
||||||
|
public static final String IPv6 = "^([0-9a-fA-F]{0,4}:){7}[0-9a-fA-F]{0,4}$|^::1$|^::$|^([0-9a-fA-F]{0,4}:){1,7}:$";
|
||||||
|
|
||||||
|
// 域名正则表达式(RFC 1123)
|
||||||
|
public static final String DOMAIN = "^([a-zA-Z0-9]([a-zA-Z0-9\\-]{0,61}[a-zA-Z0-9])?\\.)*[a-zA-Z0-9]([a-zA-Z0-9\\-]{0,61}[a-zA-Z0-9])?$";
|
||||||
|
|
||||||
public static boolean isMatch(String regex, String text) {
|
public static boolean isMatch(String regex, String text) {
|
||||||
if (TimiJava.isEmpty(regex) || TimiJava.isEmpty(text)) {
|
if (TimiJava.isEmpty(regex) || TimiJava.isEmpty(text)) {
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -3,6 +3,8 @@ package com.imyeyu.utils;
|
|||||||
import com.imyeyu.java.TimiJava;
|
import com.imyeyu.java.TimiJava;
|
||||||
import com.imyeyu.java.bean.CallbackArgReturn;
|
import com.imyeyu.java.bean.CallbackArgReturn;
|
||||||
import com.imyeyu.java.ref.Ref;
|
import com.imyeyu.java.ref.Ref;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -31,6 +33,8 @@ public class StringInterpolator {
|
|||||||
private final Map<String, CallbackArgReturn<String, String>> filterMap = new HashMap<>();
|
private final Map<String, CallbackArgReturn<String, String>> filterMap = new HashMap<>();
|
||||||
|
|
||||||
/** 空值处理策略 */
|
/** 空值处理策略 */
|
||||||
|
@Setter
|
||||||
|
@Getter
|
||||||
private boolean nullable = false;
|
private boolean nullable = false;
|
||||||
|
|
||||||
public StringInterpolator(String regex) {
|
public StringInterpolator(String regex) {
|
||||||
@@ -150,14 +154,6 @@ public class StringInterpolator {
|
|||||||
filterMap.clear();
|
filterMap.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setNullable(boolean nullable) {
|
|
||||||
this.nullable = nullable;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isNullable() {
|
|
||||||
return nullable;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** 表达式部分内部类 */
|
/** 表达式部分内部类 */
|
||||||
private record ExpressionParts(String variable, String[] filters) {
|
private record ExpressionParts(String variable, String[] filters) {
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -67,45 +67,6 @@ public class Text {
|
|||||||
return String.format("%0" + l + "d", number);
|
return String.format("%0" + l + "d", number);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 驼峰转下划线
|
|
||||||
*
|
|
||||||
* @param camelCaseStr 驼峰字符串
|
|
||||||
* @return 下划线字符串
|
|
||||||
*/
|
|
||||||
public static String camelCase2underscore(String camelCaseStr) {
|
|
||||||
return camelCaseStr.replaceAll("([a-z])([A-Z])", "$1_$2").toLowerCase();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 下划线转驼峰
|
|
||||||
*
|
|
||||||
* @param underscoreName 下划线字符串
|
|
||||||
* @return 驼峰字符串
|
|
||||||
*/
|
|
||||||
public static String underscore2camelCase(String underscoreName) {
|
|
||||||
if (TimiJava.isEmpty(underscoreName)) {
|
|
||||||
return underscoreName;
|
|
||||||
}
|
|
||||||
StringBuilder result = new StringBuilder();
|
|
||||||
boolean flag = false;
|
|
||||||
for (int i = 0; i < underscoreName.length(); i++) {
|
|
||||||
char c = underscoreName.charAt(i);
|
|
||||||
if ('_' == c) {
|
|
||||||
flag = true;
|
|
||||||
} else {
|
|
||||||
if (flag) {
|
|
||||||
result.append(Character.toUpperCase(c));
|
|
||||||
flag = false;
|
|
||||||
} else {
|
|
||||||
result.append(c);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 与多个字符串进行与比较
|
* 与多个字符串进行与比较
|
||||||
*
|
*
|
||||||
@@ -390,4 +351,56 @@ public class Text {
|
|||||||
}
|
}
|
||||||
return sb.toString();
|
return sb.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 驼峰转下划线
|
||||||
|
*
|
||||||
|
* @param camelCaseStr 驼峰字符串
|
||||||
|
* @return 下划线字符串
|
||||||
|
*/
|
||||||
|
public static String camelCase2underscore(String camelCaseStr) {
|
||||||
|
return camelCaseStr.replaceAll("([a-z])([A-Z])", "$1_$2").toLowerCase();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 下划线转驼峰
|
||||||
|
*
|
||||||
|
* @param underscoreName 下划线字符串
|
||||||
|
* @return 驼峰字符串
|
||||||
|
*/
|
||||||
|
public static String underscore2camelCase(String underscoreName) {
|
||||||
|
if (TimiJava.isEmpty(underscoreName)) {
|
||||||
|
return underscoreName;
|
||||||
|
}
|
||||||
|
StringBuilder result = new StringBuilder();
|
||||||
|
boolean flag = false;
|
||||||
|
for (int i = 0; i < underscoreName.length(); i++) {
|
||||||
|
char c = underscoreName.charAt(i);
|
||||||
|
if ('_' == c) {
|
||||||
|
flag = true;
|
||||||
|
} else {
|
||||||
|
if (flag) {
|
||||||
|
result.append(Character.toUpperCase(c));
|
||||||
|
flag = false;
|
||||||
|
} else {
|
||||||
|
result.append(c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取驼峰类名
|
||||||
|
*
|
||||||
|
* @param clazz 类
|
||||||
|
* @return 驼峰类名
|
||||||
|
*/
|
||||||
|
public static String camelCaseClassName(Class<?> clazz) {
|
||||||
|
return Character.toLowerCase(clazz.getSimpleName().charAt(0)) + clazz.getSimpleName().substring(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String underscoreClassName(Class<?> clazz) {
|
||||||
|
return camelCase2underscore(clazz.getSimpleName());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package com.imyeyu.utils;
|
package com.imyeyu.utils;
|
||||||
|
|
||||||
import com.imyeyu.java.TimiJava;
|
import com.imyeyu.java.TimiJava;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
@@ -386,77 +387,28 @@ public class Time {
|
|||||||
* @author 夜雨
|
* @author 夜雨
|
||||||
* @version 2022-10-12 14:46
|
* @version 2022-10-12 14:46
|
||||||
*/
|
*/
|
||||||
|
@Getter
|
||||||
public static class Between {
|
public static class Between {
|
||||||
|
|
||||||
|
/** 年 */
|
||||||
int year;
|
int year;
|
||||||
|
|
||||||
|
/** 月 */
|
||||||
int month;
|
int month;
|
||||||
|
|
||||||
|
/** 天 */
|
||||||
int day;
|
int day;
|
||||||
|
|
||||||
|
/** 小时 */
|
||||||
int hour;
|
int hour;
|
||||||
|
|
||||||
|
/** 分钟 */
|
||||||
int minute;
|
int minute;
|
||||||
|
|
||||||
|
/** 秒 */
|
||||||
int second;
|
int second;
|
||||||
|
|
||||||
|
/** 毫秒 */
|
||||||
int millis;
|
int millis;
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取年数
|
|
||||||
*
|
|
||||||
* @return 年数
|
|
||||||
*/
|
|
||||||
public int getYear() {
|
|
||||||
return year;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取月数
|
|
||||||
*
|
|
||||||
* @return 月数
|
|
||||||
*/
|
|
||||||
public int getMonth() {
|
|
||||||
return month;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取天数
|
|
||||||
*
|
|
||||||
* @return 天数
|
|
||||||
*/
|
|
||||||
public int getDay() {
|
|
||||||
return day;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取小时
|
|
||||||
*
|
|
||||||
* @return 小时
|
|
||||||
*/
|
|
||||||
public int getHour() {
|
|
||||||
return hour;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取分钟
|
|
||||||
*
|
|
||||||
* @return 分钟
|
|
||||||
*/
|
|
||||||
public int getMinute() {
|
|
||||||
return minute;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取秒
|
|
||||||
*
|
|
||||||
* @return 秒
|
|
||||||
*/
|
|
||||||
public int getSecond() {
|
|
||||||
return second;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取毫秒
|
|
||||||
*
|
|
||||||
* @return 毫秒
|
|
||||||
*/
|
|
||||||
public int getMillis() {
|
|
||||||
return millis;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user