Skip to content

Commit bd70cda

Browse files
authored
Merge pull request #210 from mercyblitz/dev
Dev 0.1.7
2 parents 7d9437f + dd09660 commit bd70cda

13 files changed

Lines changed: 304 additions & 71 deletions

File tree

.github/workflows/maven-build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ on:
1212
push:
1313
branches: [ "dev" ]
1414
pull_request:
15-
branches: [ "dev" , "main" , "release" ]
15+
branches: [ "main" , "dev" , "release" ]
1616

1717
jobs:
1818
build:

.github/workflows/maven-publish.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ on:
2121
jobs:
2222
build:
2323
runs-on: ubuntu-latest
24-
if: ${{ inputs.revision }}
24+
if: ${{ inputs.revision }}
2525
steps:
2626
- name: Checkout Source
2727
uses: actions/checkout@v4
@@ -48,6 +48,6 @@ jobs:
4848
env:
4949
MAVEN_USERNAME: ${{ secrets.OSS_SONATYPE_USERNAME }}
5050
MAVEN_PASSWORD: ${{ secrets.OSS_SONATYPE_PASSWORD }}
51-
SIGN_KEY_ID: ${{ secrets.OSS_SIGNING_KEY_ID_LONG }}
51+
SIGN_KEY_ID: ${{ secrets.OSS_SIGNING_KEY_ID_LONG }}
5252
SIGN_KEY: ${{ secrets.OSS_SIGNING_KEY }}
5353
SIGN_KEY_PASS: ${{ secrets.OSS_SIGNING_PASSWORD }}

microsphere-java-core/src/main/java/io/microsphere/classloading/MavenArtifactResourceResolver.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
* <ul>
3535
* <li>The resolver checks if a given resource path matches the pattern of a Maven POM properties file using the
3636
* {@link #isArtifactMetadata(String)} method. The pattern is typically:
37-
* <code>META-INF/maven/&lt;groupId&gt;/&lt;artifactId&gt;/pom.properties</code>.</li>
37+
* <code>META-INF/maven/<groupId>/<artifactId>/pom.properties</code>.</li>
3838
* <li>If a match is found, it reads the properties file via the
3939
* {@link #resolve(URL, InputStream, ClassLoader)} method and extracts key metadata: groupId, artifactId, and version.</li>
4040
* <li>It then constructs an {@link Artifact} object using these properties and associates it with the original URL.</li>

microsphere-java-core/src/main/java/io/microsphere/collection/AbstractDeque.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@
3333
*
3434
* <h3>Example Usage</h3>
3535
* <pre>{@code
36-
* public class SimpleDeque&lt;E&gt; extends AbstractDeque&lt;E&gt; {
37-
* private final List&lt;E&gt; list = new ArrayList&lt;&gt;();
36+
* public class SimpleDeque<E> extends AbstractDeque<E> {
37+
* private final List<E> list = new ArrayList<>();
3838
*
3939
* public void addFirst(E e) {
4040
* list.add(0, e);

microsphere-java-core/src/main/java/io/microsphere/collection/UnmodifiableIterator.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@
2828
*
2929
* <h3>Example Usage</h3>
3030
* <pre>
31-
* List&lt;String&gt; list = Arrays.asList("one", "two", "three");
32-
* Iterator&lt;String&gt; unmodifiableIterator = new UnmodifiableIterator&lt;&gt;(list.iterator());
31+
* List<String> list = Arrays.asList("one", "two", "three");
32+
* Iterator<String> unmodifiableIterator = new UnmodifiableIterator<>(list.iterator());
3333
*
3434
* while (unmodifiableIterator.hasNext()) {
3535
* System.out.println(unmodifiableIterator.next());

microsphere-java-core/src/main/java/io/microsphere/io/Serializer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
*
2727
* <h3>Example Usage</h3>
2828
* <pre>{@code
29-
* public class StringSerializer implements Serializer&lt;String&gt; {
29+
* public class StringSerializer implements Serializer<String> {
3030
* public byte[] serialize(String source) throws IOException {
3131
* return source.getBytes(StandardCharsets.UTF_8);
3232
* }

microsphere-java-core/src/main/java/io/microsphere/reflect/ExecutableDefinition.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
*
3939
* <h3>Example Usage</h3>
4040
* <pre>{@code
41-
* public class MethodDefinition extends ExecutableDefinition&lt;Method&gt; {
41+
* public class MethodDefinition extends ExecutableDefinition<Method> {
4242
* public MethodDefinition(Version since, String declaredClassName, String name, String... parameterClassNames) {
4343
* super(since, null, declaredClassName, name, parameterClassNames);
4444
* }

microsphere-java-core/src/main/java/io/microsphere/util/Version.java

Lines changed: 98 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -18,26 +18,30 @@
1818

1919
import io.microsphere.annotation.Immutable;
2020
import io.microsphere.annotation.Nonnull;
21+
import io.microsphere.annotation.Nullable;
2122
import io.microsphere.lang.ClassDataRepository;
2223

2324
import java.io.Serializable;
2425
import java.net.URL;
2526
import java.util.Objects;
26-
import java.util.StringTokenizer;
2727
import java.util.function.BiPredicate;
2828

2929
import static io.microsphere.constants.SymbolConstants.COMMA_CHAR;
3030
import static io.microsphere.constants.SymbolConstants.DOT;
3131
import static io.microsphere.constants.SymbolConstants.EQUAL;
3232
import static io.microsphere.constants.SymbolConstants.GREATER_THAN;
3333
import static io.microsphere.constants.SymbolConstants.GREATER_THAN_OR_EQUAL_TO;
34+
import static io.microsphere.constants.SymbolConstants.HYPHEN;
3435
import static io.microsphere.constants.SymbolConstants.LESS_THAN;
3536
import static io.microsphere.constants.SymbolConstants.LESS_THAN_OR_EQUAL_TO;
3637
import static io.microsphere.constants.SymbolConstants.QUOTE_CHAR;
3738
import static io.microsphere.constants.SymbolConstants.SPACE_CHAR;
39+
import static io.microsphere.lang.ClassDataRepository.INSTANCE;
3840
import static io.microsphere.text.FormatUtils.format;
3941
import static io.microsphere.util.Assert.assertNotBlank;
4042
import static io.microsphere.util.Assert.assertNotNull;
43+
import static io.microsphere.util.Assert.assertTrue;
44+
import static io.microsphere.util.StringUtils.split;
4145
import static io.microsphere.util.Version.Operator.EQ;
4246
import static io.microsphere.util.Version.Operator.GE;
4347
import static io.microsphere.util.Version.Operator.GT;
@@ -51,7 +55,15 @@
5155
* <p>
5256
* This class provides methods to compare versions using standard comparison operators such as greater than,
5357
* less than, and equal to. It also supports parsing version strings in the format "major.minor.patch".
58+
* The supported version patterns :
59+
* <ul>
60+
* <li>major</li>
61+
* <li>major.minor</li>
62+
* <li>major.minor.patch</li>
63+
* <li>major.minor.patch-preRelease</li>
64+
* </ul>
5465
* </p>
66+
* See <a href="https://semver.org/">Semantic Versioning</a> for more details.
5567
*
5668
* <h3>Example Usage</h3>
5769
* <pre>{@code
@@ -76,14 +88,17 @@
7688
@Immutable
7789
public class Version implements Comparable<Version>, Serializable {
7890

79-
private static final long serialVersionUID = -6434504483466016691L;
91+
private static final long serialVersionUID = 609463905158722630L;
8092

8193
private final int major;
8294

8395
private final int minor;
8496

8597
private final int patch;
8698

99+
@Nullable
100+
private final String preRelease;
101+
87102
public Version(int major) {
88103
this(major, 0);
89104
}
@@ -93,9 +108,18 @@ public Version(int major, int minor) {
93108
}
94109

95110
public Version(int major, int minor, int patch) {
111+
this(major, minor, patch, null);
112+
}
113+
114+
public Version(int major, int minor, int patch, String preRelease) {
115+
assertTrue(major >= 0, "The 'major' version must not be a non-negative integer!");
116+
assertTrue(minor >= 0, "The 'minor' version must not be a non-negative integer!");
117+
assertTrue(patch >= 0, "The 'patch' version must not be a non-negative integer!");
118+
assertTrue(major + minor + patch > 0, "The 'major', 'minor' and 'patch' must not be null at the same time!");
96119
this.major = major;
97120
this.minor = minor;
98121
this.patch = patch;
122+
this.preRelease = preRelease;
99123
}
100124

101125
/**
@@ -125,6 +149,16 @@ public int getPatch() {
125149
return patch;
126150
}
127151

152+
/**
153+
* The pre-release
154+
*
155+
* @return pre-release
156+
*/
157+
@Nullable
158+
public String getPreRelease() {
159+
return preRelease;
160+
}
161+
128162
/**
129163
* Current {@link Version} is greater than that
130164
*
@@ -251,6 +285,9 @@ public int hashCode() {
251285
int result = major;
252286
result = 31 * result + minor;
253287
result = 31 * result + patch;
288+
if (preRelease != null) {
289+
result = 31 * result + preRelease.hashCode();
290+
}
254291
return result;
255292
}
256293

@@ -270,17 +307,35 @@ public int compareTo(Version that) {
270307

271308
result = compare(this.patch, that.patch);
272309

310+
if (result != 0) {
311+
return result;
312+
}
313+
314+
result = comparePreRelease(this.preRelease, that.preRelease);
315+
273316
return result;
274317
}
275318

319+
/**
320+
* Compare pre-release
321+
*
322+
* @param v1
323+
* @param v2
324+
* @return
325+
*/
326+
static int comparePreRelease(String v1, String v2) {
327+
if (v1 == null) {
328+
return v2 == null ? 0 : 1;
329+
}
330+
if (v2 == null) {
331+
return -1;
332+
}
333+
return v1.compareTo(v2);
334+
}
276335

277336
@Override
278337
public String toString() {
279-
return "Version{" +
280-
"major=" + major +
281-
", minor=" + minor +
282-
", patch=" + patch +
283-
'}';
338+
return major + DOT + minor + DOT + patch + (preRelease == null ? "" : "-" + preRelease);
284339
}
285340

286341
public static Version of(int major) {
@@ -295,6 +350,10 @@ public static Version of(int major, int minor, int patch) {
295350
return ofVersion(major, minor, patch);
296351
}
297352

353+
public static Version of(int major, int minor, int patch, String preRelease) {
354+
return ofVersion(major, minor, patch, preRelease);
355+
}
356+
298357
public static Version of(String version) {
299358
return ofVersion(version);
300359
}
@@ -311,19 +370,27 @@ public static Version ofVersion(int major, int minor, int patch) {
311370
return new Version(major, minor, patch);
312371
}
313372

373+
public static Version ofVersion(int major, int minor, int patch, String preRelease) {
374+
return new Version(major, minor, patch, preRelease);
375+
}
376+
314377
public static Version ofVersion(String version) {
315378
assertNotNull(version, () -> "The 'version' argument must not be null!");
316379
assertNotBlank(version, () -> "The 'version' argument must not be blank!");
317380

318-
StringTokenizer st = new StringTokenizer(version.trim(), DOT);
381+
String[] coreAndPreRelease = split(version.trim(), HYPHEN);
382+
String core = coreAndPreRelease[0];
383+
String preRelease = coreAndPreRelease.length > 1 ? coreAndPreRelease[1] : null;
319384

320-
int major = getValue(st);
321-
int minor = getValue(st);
322-
int patch = getValue(st);
385+
String[] majorAndMinorAndPatch = split(core, DOT);
386+
int size = majorAndMinorAndPatch.length;
323387

324-
return of(major, minor, patch);
325-
}
388+
int major = getValue(majorAndMinorAndPatch[0]);
389+
int minor = size > 1 ? getValue(majorAndMinorAndPatch[1]) : 0;
390+
int patch = size > 2 ? getValue(majorAndMinorAndPatch[2]) : 0;
326391

392+
return of(major, minor, patch, preRelease);
393+
}
327394

328395
/**
329396
* Class that exposes the version. Fetches the "Implementation-Version" manifest attribute from the jar file.
@@ -337,21 +404,14 @@ public static Version getVersion(Class<?> targetClass) throws IllegalArgumentExc
337404
Package targetPackage = targetClass.getPackage();
338405
String version = targetPackage.getImplementationVersion();
339406
if (version == null) {
340-
ClassDataRepository repository = ClassDataRepository.INSTANCE;
407+
ClassDataRepository repository = INSTANCE;
341408
URL classResource = repository.getCodeSourceLocation(targetClass);
342409
String errorMessage = format("The 'Implementation-Version' manifest attribute can't be fetched from the jar file[class resource : '{}'] by the target class[name :'{}']", classResource, targetClass.getName());
343410
throw new IllegalArgumentException(errorMessage);
344411
}
345412
return of(version);
346413
}
347414

348-
static int getValue(StringTokenizer st) {
349-
if (st.hasMoreTokens()) {
350-
return getValue(st.nextToken());
351-
}
352-
return 0;
353-
}
354-
355415
static int getValue(String part) {
356416
final int value;
357417
try {
@@ -373,10 +433,10 @@ public boolean test(Version v1, Version v2) {
373433
if (v1 == v2) {
374434
return true;
375435
}
376-
if (v2 == null) return false;
377-
if (v1.major != v2.major) return false;
378-
if (v1.minor != v2.minor) return false;
379-
return v1.patch == v2.patch;
436+
if (v1 == null || v2 == null) {
437+
return false;
438+
}
439+
return v1.compareTo(v2) == 0;
380440
}
381441
},
382442

@@ -389,7 +449,9 @@ public boolean test(Version v1, Version v2) {
389449
if (v1 == v2) {
390450
return false;
391451
}
392-
if (v2 == null) return false;
452+
if (v1 == null || v2 == null) {
453+
return false;
454+
}
393455
return v1.compareTo(v2) < 0;
394456
}
395457
},
@@ -403,7 +465,9 @@ public boolean test(Version v1, Version v2) {
403465
if (v1 == v2) {
404466
return true;
405467
}
406-
if (v2 == null) return false;
468+
if (v1 == null || v2 == null) {
469+
return false;
470+
}
407471
return v1.compareTo(v2) <= 0;
408472
}
409473
},
@@ -417,7 +481,9 @@ public boolean test(Version v1, Version v2) {
417481
if (v1 == v2) {
418482
return false;
419483
}
420-
if (v2 == null) return false;
484+
if (v1 == null || v2 == null) {
485+
return false;
486+
}
421487
return v1.compareTo(v2) > 0;
422488
}
423489
},
@@ -431,7 +497,9 @@ public boolean test(Version v1, Version v2) {
431497
if (v1 == v2) {
432498
return true;
433499
}
434-
if (v2 == null) return false;
500+
if (v1 == null || v2 == null) {
501+
return false;
502+
}
435503
return v1.compareTo(v2) >= 0;
436504
}
437505
};
@@ -473,6 +541,5 @@ public static Operator of(String symbol) {
473541

474542
throw new IllegalArgumentException(messageBuilder.toString());
475543
}
476-
477544
}
478-
}
545+
}

microsphere-java-core/src/test/java/io/microsphere/reflect/generics/ParameterizedTypeImplTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@ class ParameterizedTypeImplTest {
2828
private static Type[] actualTypeArguments = new Type[]{String.class, Integer.class};
2929

3030
/**
31-
* The top-level type : Map&lt;String,Integer&gt;
31+
* The top-level type : Map<String,Integer>
3232
*/
3333
private ParameterizedTypeImpl topLevelType;
3434

3535
/**
36-
* The nested type : Map.Entry&lt;String,Integer&gt;
36+
* The nested type : Map.Entry<String,Integer>
3737
*/
3838
private ParameterizedTypeImpl nestedType;
3939

0 commit comments

Comments
 (0)