Skip to content

Commit

Permalink
Polish #34 : Add microsphere-spring-compatible module
Browse files Browse the repository at this point in the history
  • Loading branch information
mercyblitz committed Dec 27, 2024
1 parent bb5c7c2 commit 2fe7f5e
Show file tree
Hide file tree
Showing 17 changed files with 7,896 additions and 12 deletions.
52 changes: 52 additions & 0 deletions microsphere-spring-compatible/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<groupId>io.github.microsphere-projects</groupId>
<artifactId>microsphere-spring-parent</artifactId>
<version>${revision}</version>
<relativePath>../microsphere-spring-parent/pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>

<groupId>io.github.microsphere-projects</groupId>
<artifactId>microsphere-spring-compatible</artifactId>
<version>${revision}</version>
<packaging>jar</packaging>

<name>Microsphere :: Spring :: Compatible</name>
<description>Microsphere Spring Compatible</description>

<dependencies>

<!-- JSR 305 -->
<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>jsr305</artifactId>
<optional>true</optional>
</dependency>

<!-- Servlet API -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<scope>provided</scope>
</dependency>

</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
</plugins>
</build>


</project>
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@

package org.springframework.core.env;

import org.springframework.util.Assert;
import org.springframework.util.StringUtils;

import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
Expand All @@ -29,8 +25,9 @@
import java.util.StringTokenizer;
import java.util.function.Predicate;

import static io.microsphere.util.Assert.assertNotEmpty;
import static io.microsphere.util.Assert.assertTrue;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;

/**
* Internal parser used by {@link Profiles#of}.
Expand All @@ -44,8 +41,9 @@ final class ProfilesParser {
private ProfilesParser() {
}


static Profiles parse(String... expressions) {
assertNotEmpty(expressions, "Must specify at least one profile expression");
Assert.notEmpty(expressions, "Must specify at least one profile expression");
Profiles[] parsed = new Profiles[expressions.length];
for (int i = 0; i < expressions.length; i++) {
parsed[i] = parseExpression(expressions[i]);
Expand All @@ -54,7 +52,7 @@ static Profiles parse(String... expressions) {
}

private static Profiles parseExpression(String expression) {
assertNotEmpty(expression, () -> "Invalid profile expression [" + expression + "]: must contain text");
Assert.hasText(expression, () -> "Invalid profile expression [" + expression + "]: must contain text");
StringTokenizer tokens = new StringTokenizer(expression, "()&|!", true);
return parseTokens(expression, tokens);
}
Expand Down Expand Up @@ -120,7 +118,7 @@ private static Profiles merge(String expression, List<Profiles> elements, @Nulla
}

private static void assertWellFormed(String expression, boolean wellFormed) {
assertTrue(wellFormed, () -> "Malformed profile expression [" + expression + "]");
Assert.isTrue(wellFormed, () -> "Malformed profile expression [" + expression + "]");
}

private static Profiles or(Profiles... profiles) {
Expand All @@ -144,9 +142,9 @@ private static Predicate<Profiles> isMatch(Predicate<String> activeProfiles) {
}


private enum Operator {AND, OR}
private enum Operator { AND, OR }

private enum Context {NONE, NEGATE, PARENTHESIS}
private enum Context { NONE, NEGATE, PARENTHESIS }


private static class ParsedProfiles implements Profiles {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Copyright 2002-2019 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.
*/

package org.springframework.lang;

import javax.annotation.Nonnull;
import javax.annotation.meta.TypeQualifierNickname;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
* A common Spring annotation to declare that annotated elements cannot be {@code null}.
*
* <p>Leverages JSR-305 meta-annotations to indicate nullability in Java to common
* tools with JSR-305 support and used by Kotlin to infer nullability of Spring API.
*
* <p>Should be used at parameter, return value, and field level. Method overrides should
* repeat parent {@code @NonNull} annotations unless they behave differently.
*
* <p>Use {@code @NonNullApi} (scope = parameters + return values) and/or {@code @NonNullFields}
* (scope = fields) to set the default behavior to non-nullable in order to avoid annotating
* your whole codebase with {@code @NonNull}.
*
* @author Sebastien Deleuze
* @author Juergen Hoeller
* @since 5.0
* @see NonNullApi
* @see NonNullFields
* @see Nullable
*/
@Target({ElementType.METHOD, ElementType.PARAMETER, ElementType.FIELD})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Nonnull
@TypeQualifierNickname
public @interface NonNull {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Copyright 2002-2019 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.
*/

package org.springframework.lang;

import javax.annotation.Nonnull;
import javax.annotation.meta.TypeQualifierNickname;
import javax.annotation.meta.When;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
* A common Spring annotation to declare that annotated elements can be {@code null} under
* some circumstance.
*
* <p>Leverages JSR-305 meta-annotations to indicate nullability in Java to common
* tools with JSR-305 support and used by Kotlin to infer nullability of Spring API.
*
* <p>Should be used at parameter, return value, and field level. Methods override should
* repeat parent {@code @Nullable} annotations unless they behave differently.
*
* <p>Can be used in association with {@code @NonNullApi} or {@code @NonNullFields} to
* override the default non-nullable semantic to nullable.
*
* @author Sebastien Deleuze
* @author Juergen Hoeller
* @since 5.0
* @see NonNullApi
* @see NonNullFields
* @see NonNull
*/
@Target({ElementType.METHOD, ElementType.PARAMETER, ElementType.FIELD})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Nonnull(when = When.MAYBE)
@TypeQualifierNickname
public @interface Nullable {
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
* limitations under the License.
*/
/**
* The classes in this package or sub-packages are used to be compatible with the different versions of Spring Framework
* The classes in this package or sub-packages are forked from the Spring Framework 5.3.x(latest),
* which will be used to be compatible with the lower versions of Spring Framework.
*
* @author <a href="mailto:mercyblitz@gmail.com">Mercy<a/>
* @since 1.0.0
Expand Down
Loading

0 comments on commit 2fe7f5e

Please sign in to comment.