-
Notifications
You must be signed in to change notification settings - Fork 54
dev 0.1.8 #233
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
mercyblitz
wants to merge
114
commits into
microsphere-projects:dev
Choose a base branch
from
mercyblitz:dev
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
dev 0.1.8 #233
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Updated the <revision> property in pom.xml to prepare for the next development iteration.
Introduce a new microsphere-jdk-tools Maven module. Adds pom.xml with dependencies (microsphere-java-core, JUnit, Mockito, Logback), maven-compiler config and maven-shade setup. Implements io.microsphere.jdk.tools.compiler.Compiler — a utility to programmatically compile Java sources, manage source/target paths, detect class/root/source locations, and configure processors/options/diagnostics. Includes unit tests (CompilerTest) covering constructors, default path detection, options, processors and compile flow, and a logback-test.xml for test logging.
Introduce Mockito to the parent POM: add a mockito.version property and a mockito-core dependency so tests can use Mockito. Also update JUnit versions: bump the root junit.version 6.0.1 → 6.0.2 and the profile's junit.version 5.13.4 → 5.14.2. The profile also sets mockito.version (4.11.0) to override the parent value.
Introduce a new microsphere-java-test Maven module providing testing utilities and fixtures. Adds pom.xml (compiler/shade configuration and test dependencies), a TestAnnotation and annotation-processing test infrastructure (AbstractAnnotationProcessingTest, AnnotationProcessingTestProcessor, CompilerInvocationInterceptor) that compiles test sources and runs processors during JUnit5 tests. Also adds a set of model classes, service interfaces/implementations, unit tests, logback-test.xml, and a service provider entry for annotation processors to support annotation-processing test cases.
Refactor annotation-processing test harness to use JUnit 5 reflective invocation API. AbstractAnnotationProcessingTest: remove ThreadLocal holder and @BeforeEach/@AfterEach, change beforeTest/afterTest signatures to accept ReflectiveInvocationContext and ExtensionContext (afterTest also receives result and failure), add necessary imports and reflection types. AnnotationProcessingTestProcessor: make package-private, use Invocation type directly, call beforeTest/afterTest with contexts and pass result/failure, and populate processingEnv, Elements/Types and test type information during prepare. CompilerInvocationInterceptor: make package-private, obtain test instance from invocationContext target, use the test class loader, and load SPI Processor implementations via ServiceLoader (merging them with the test processor). Also cleanup imports/usages in test class (remove assertion referencing removed holder). Overall adjusts lifecycle integration so the annotation processor drives the test invocation and reporting.
Add a new JUnit test class TestServiceImplTest (Mockito-based) to validate TestServiceImpl behavior (echo, close, constructors and DI). Make small API/encapsulation adjustments to the annotation-processing test infra: add Javadoc/comments for addCompiledClasses, beforeTest and afterTest in AbstractAnnotationProcessingTest; reduce visibility of AnnotationProcessingTestProcessor constructor and prepare method to package-private; and rename local variables in CompilerInvocationInterceptor to improve clarity and pass the test instance into the processor. These changes improve test coverage and tighten processor APIs.
Introduce io.microsphere.util.ThrowableUtils: a new utility class (with ASF license header and author info) providing getRootCause(Throwable) to traverse and return the deepest cause in a throwable chain. The class implements Utils and has a private constructor to prevent instantiation.
Add JUnit 5 tests for ThrowableUtils#getRootCause. The new test file verifies retrieving the root cause from a nested Throwable, checks behavior when using ThrowableAction.execute to handle thrown exceptions, and ensures rethrowing the root cause yields the expected NullPointerException.
Introduce a failing test and verify test lifecycle failure handling. Adds testOnFailure() which throws a RuntimeException("For testing") and overrides afterTest(ReflectiveInvocationContext<Method>, ExtensionContext, Object, Throwable) to assert the failure message when a failure is present. Also adds the required imports and an assertEquals assertion.
Add Microsphere test libraries to the module POM (microsphere-lang-model, microsphere-jdk-tools (test scope), and microsphere-java-test (test scope)). Update unit tests to extend AbstractAnnotationProcessingTest and adjust lifecycle hooks: beforeTest/afterTest signatures now accept ReflectiveInvocationContext<Method> and ExtensionContext (and afterTest includes result/failure). Import necessary classes (ReflectiveInvocationContext, ExtensionContext, Method) and update test setup/teardown to use the new testing extension API.
Delete the entire microsphere-annotation-processor module: remove source files under src/main/java (annotation model elements, visitors and various utility classes such as AnnotationUtils, ClassUtils, ConstructorUtils, ElementUtils, ExecutableElementComparator, FieldUtils, LoggerUtils, MemberUtils, MessagerUtils, MethodUtils, TypeUtils, etc.) and corresponding unit tests under src/test/java. This change removes the annotation processing implementation and its tests from the repository.
Introduce a new microsphere-lang-model Maven module. Adds pom.xml with dependencies and build configuration, core language-model classes (e.g. StringAnnotationValue) and a comprehensive set of utility classes for annotation/element processing (AnnotationUtils, ClassUtils, ConstructorUtils, ElementUtils, ExecutableElementComparator, FieldUtils, MethodUtils, TypeUtils, Resolvable/JSON visitors, LoggerUtils, MessagerUtils, MemberUtils, etc.). Includes unit tests for the added utilities and elements to validate behavior. This module provides reusable helpers for working with javax.lang.model types and annotation processing within the Microsphere project.
Replace references to io.microsphere.annotation.processor.util.* with the new io.microsphere.lang.model.util.* equivalents across the annotation processor (MessagerUtils, AnnotationUtils, ElementUtils, TypeUtils, ClassUtils, JSONElementVisitor). Update Javadoc and fully-qualified references where needed. Simplify ConfigurationPropertyAnnotationProcessorTest by using AbstractAnnotationProcessingTest and removing an unused lifecycle override. Update pom dependency management and dependencies to add microsphere-java-core and microsphere-lang-model, replace microsphere-java-core dependency usage with microsphere-jdk-tools, and add microsphere-java-test to reflect module relocations.
Add new modules to the parent POM and reorder existing entries. This commit introduces microsphere-jdk-tools, microsphere-java-test, and microsphere-lang-model to the <modules> section and moves microsphere-annotation-processor to the end of the list so the module ordering reflects the updated project structure.
Remove the <build> sections from microsphere-java-test, microsphere-jdk-tools, and microsphere-lang-model POMs. This deletes the maven-compiler-plugin configuration (compilerArgument -proc:none) and the maven-shade-plugin execution that shaded io.github.microsphere-projects:microsphere-java-core, consolidating/cleaning up module-level build configuration.
Move javax.ws.rs and jaxws-api version properties into the parent pom and add dependencyManagement entries for javax.ws.rs-api and jaxws-api. Remove duplicate properties and explicit version elements from module poms (annotation-processor, lang-model, java-test) so they inherit the parent-managed versions. Adjust microsphere-java-dependencies to reorder artifactIds (swap mappings between microsphere-lang-model, microsphere-jdk-tools, microsphere-annotation-processor, and microsphere-java-test). Delete the TestProcessor test class and its service registration (META-INF/services) from the java-test module.
Reorder and group static imports in FieldUtils for consistency and readability. Remove an unused import (AbstractAnnotationProcessingTest) from JSONElementVisitorTest to eliminate a compiler/IDE warning. No behavior changes.
Normalize and tidy imports across multiple modules: reorder static imports for consistency, remove unused imports (including AbstractAnnotationProcessingTest in tests), and fix minor formatting. Replace Mockito wildcard import with explicit mock import in TestServiceImplTest. These are code-cleanup changes to reduce warnings and improve import organization.
Create a new microsphere-java-annotations module and move annotation sources and tests from microsphere-java-core into it. Added a module POM (including jsr305 and JUnit test deps), new NonnullTest and NullableTest classes, and updated test Javadocs. Updated microsphere-java-core POM to depend on the new annotations artifact (replacing the previous direct jsr305 dependency), added the annotations artifact to dependencyManagement, and registered the new module in the root POM. Also removed an unused import in Since.java.
Update the project's parent POM from io.github.microsphere-projects:microsphere-build:0.2.2 to 0.2.3 to incorporate upstream build configuration changes and fixes.
Add JSR-305 (com.google.code.findbugs:jsr305) as a test-scoped dependency in microsphere-java-core/pom.xml. This brings in standard nullability annotations for use in tests and static analysis during the test phase.
Replace checked-in maven-wrapper binary with the newer wrapper scripts and properties. Removes .mvn/wrapper/maven-wrapper.jar, updates .mvn/wrapper/maven-wrapper.properties to wrapperVersion=3.3.4 and points distributionUrl to an aliyun mirror (apache-maven-3.9.9) using distributionType=only-script. Replaces mvnw and mvnw.cmd with revamped wrapper implementations that download/install Maven on demand, add support for MVNW_REPOURL/MVNW_USERNAME/MVNW_PASSWORD/MVNW_VERBOSE, improve Java detection and error handling, support checksum validation, and add mvnd handling.
Bump GitHub Actions steps to v5 (actions/checkout and actions/setup-java) and switch the build command to use the project Maven wrapper (./mvnw) instead of system mvn. Removed the setup-java cache configuration; this ensures the workflow uses the updated action versions and a consistent, project-provided Maven runtime for builds.
Bump actions/checkout and actions/setup-java from v4 to v5 in .github/workflows/maven-publish.yml. Java 11 (Temurin) configuration remains unchanged. Update brings the workflow to the latest major action releases for improvements, fixes, and security updates.
Provide a base beforeTest implementation in UtilTest that initializes testTypeElement from TestServiceImpl and add required imports (TestServiceImpl, ReflectiveInvocationContext, ExtensionContext, Method). Update several test classes (ElementUtilsTest, JSONAnnotationValueVisitorTest, MessagerUtilsTest, MethodUtilsTest, ResolvableAnnotationValueVisitorTest) to call super.beforeTest(invocationContext, extensionContext) at the start of their overridden beforeTest methods so the shared setup runs correctly.
Introduce initTestClass(Class<?>) to centralize initialization of test class metadata for annotation-processing tests. The new method sets testClass, testClassName, resolves testTypeElement via Elements, assigns testTypeMirror and casts it to testDeclaredType (DeclaredType). This consolidates repeated setup logic and prepares type information for subsequent processing.
Add unit tests to verify PackageNameClassFilter behavior when includedSubPackages is false: ensure a filter for a parent package (io.microsphere) does not accept classes in subpackages, while a filter for the exact package (io.microsphere.filter) does. Also apply minor whitespace cleanup in PackageNameClassFilter source.
Replace strict getClass check with an instanceof check in MultipleType.equals and add braces for readability. Update tests to reflect behavior: use this.multipleType references, add reflexive and null checks (assertTrue/assertFalse), and adjust assertions accordingly.
Change several helper methods in AccessibleObjectUtils from private to package-private (trySetAccessible, tryCanAccess, handleInaccessibleObjectExceptionIfFound) and add a new tryCanAccess(MethodHandle, ...) overload to allow direct invocation with a MethodHandle. Update unit tests to exercise these paths: import and call the newly-visible helpers, add null/failure cases for trySetAccessible and tryCanAccess, assert canAccess behavior on non-public members, and ensure handleInaccessibleObjectExceptionIfFound handles a non-related exception. These changes improve testability and allow invoking internal logic from tests.
Refactor LoggerFactory to use a Predicate for availability filtering and Predicate.negate() in loadAvailableFactories(), and replace explicit null check with Objects.nonNull() in isAvailable(). Added imports for java.util.function.Predicate and java.util.Objects.nonNull for readability.
Add a test LoggerFactory implementation (NoDelegateLoggerFactory) that reports a non-existent delegate logger class and returns null loggers. Register the implementation in test resources via META-INF/services/io.microsphere.logging.LoggerFactory to exercise service-loading and fallback behavior when the delegate logger class cannot be found.
Replace manual extension parsing with substringAfterLast(FILE_EXTENSION) in FileUtils.getFileExtension and update imports accordingly. Refactor FileUtilsTest to consolidate flaky concurrent directory-deletion tests into reusable helpers (handleDirectoryOnIOException and handleDirectoryOnIOException0), add makeLinkFile to create symlinks cross-platform, use ThrowableConsumer for injected handlers, improve status readability with named constants, simplify isSymlink test, and clean up threading/exception handling and logging. These changes make the extension logic simpler and the tests more robust and reusable.
Replace legacy File.delete logic with java.nio Files.delete in FileUtils.forceDelete and surface NoSuchFileException instead of FileNotFoundException. Simplify cleanDirectory to let deletion exceptions propagate immediately (removed exception aggregation). Add necessary imports for NIO deletion. Update tests: enable parallel execution for FileUtilsTest, add listFiles tests (null, not-found, directory, file), import EMPTY_FILE_ARRAY and listFiles utilities, add a symlink case to deleteDirectoryOnExit test, and shorten executor.awaitTermination from 3s to 1s. Remove the old test that handled cleanDirectory IOException.
Remove the JUnit Jupiter @execution(CONCURRENT) annotation from FileUtilsTest to disable class-level concurrent execution. This prevents potential flaky tests or resource contention when running this test class in parallel.
Delete unused org.junit.jupiter.api.parallel.Execution and ExecutionMode.CONCURRENT imports from FileUtilsTest to clean up the test file and avoid accidental parallel execution annotations. No functional changes.
Use TypeUtils helpers to simplify and null-safe type resolution in EventListener: replace manual instanceof/Class checks with isAssignableFrom and asClass, and add static imports for clarity. Adjust logic to handle null listener classes and non-Class type arguments more robustly. Add tests: verify findEventType returns null for null input and assert default listener priority equals NORMAL_PRIORITY.
Replace manual loops with Stream-based lookups for artifactId and version, simplify resolve methods, and move trace logging to the caller. Change resolveArtifactMetaInfoInManifest visibility to package-private to allow testing and add a unit test covering the not-found (empty Manifest) case.
Remove redundant logger.isTraceEnabled() guards and always emit trace messages in FieldUtils for field lookup and error handling. Add unit tests to cover null and Object.class cases (testFindFieldsOnNull, testFindFieldsOnObjectClass) and null field retrieval (testGetFieldValueOnNull), and strengthen assertions around setFieldValue to verify its return value. These changes improve traceability and increase test coverage for null-safety behavior.
Move the makeLinkFile helper from FileUtilsTest into AbstractTestCase as a protected method so tests can reuse it. Add ProcessExecutor and IS_OS_WINDOWS imports and implementation to create symlinks (ln -s) or Windows mklink accordingly. Remove the duplicate helper and unused imports from FileUtilsTest.
Handle jar:// protocol and improve class-path resolution; simplify file vs jar detection and improve trace logging. Optimize jar scanning by pre-sizing collections and adjust exception logging. Refactor simple name resolution (extract getSimpleName overload) and make isAsciiDigit package-visible; update getClass to return Class objects unchanged. Update javadoc reference to FileUtils#resolveRelativePath. Add comprehensive tests for class-path/jar edge cases, simple-name/malformed names, ASCII digit checks, and other utilities, and include two empty .sar test resources.
Make PriorityComparator more testable and flexible: use ClassUtils.getType to derive types, add a compare overload that accepts the priority annotation class, and expose getValue as package-visible static. Remove the private asClass helper and delegate annotation lookup to the provided priority class. Update unit tests to statically import and exercise the new compare overload, add cases for null priorityClass and null types, and rename an existing test for clarity. These changes improve testability and handling of null/undefined priority scenarios.
Remove an unnecessary try-catch block in the array type name construction. The method now iterates to the component type and appends the appropriate number of "[]" suffixes directly, simplifying control flow and reducing code size without changing behavior.
|
Eliminate the unnecessary initialization of the local variable `klass` in ClassLoaderUtils (declare Class<?> klass without assigning null). This is a no-op behavior change that cleans up the code and removes a redundant assignment (addresses style/lint warnings).
Refactor StandardURLStreamHandlerFactory to use utility helpers (FieldUtils.getStaticFieldValue, ClassLoaderUtils.resolveClass, ClassUtils.newInstance) instead of low-level reflection and Class.forName. Simplify handler creation flow by delegating to a new overloaded method and removing trySetAccessible/explicit exception swallowing. Add StandardURLStreamHandlerFactoryTest with basic assertions for creating the 'file' handler to increase test coverage.
Ensure handlerClass is non-null before calling newInstance to avoid a NullPointerException when resolveClass fails to find the handler class. This prevents attempting to instantiate a null handler and keeps behavior consistent when no default handler is available.
Call logger.trace unconditionally in IOUtils.copy by removing the surrounding isTraceEnabled() check. This simplifies the code and delegates enabled-level checks to the logging implementation. Affects microsphere-java-core/src/main/java/io/microsphere/io/IOUtils.java.
Refactor ProcessExecutor to run process I/O in a single-threaded ExecutorService with proper timeout handling and improved I/O buffering. Adds a configurable PROCESS_EXECUTION_TIMEOUT_PROPERTY_NAME (default 30000ms), DEFAULT_TIMEOUT, wrapping of execution into a Future, and uses FastByteArray streams + IO copy utilities. Removes the finished flag and isFinished API usage; execute now supports explicit TimeUnit and propagates TimeoutException and wrapped IOExceptions. Tests were updated to reflect the new API and behavior (method signatures changed to throw Exception, removed isFinished assertions, and added tests for not-found commands). Logging and graceful executor shutdown on JVM exit were also added.
Replace the previously static ExecutorService with a per-instance executor in ProcessExecutor to avoid a shared static thread pool and lifecycle/shutdown issues. Each ProcessExecutor now creates its own single-thread executor and is registered with shutdownOnExit. Also update junit-platform.properties to disable parallel test execution (junit.jupiter.execution.parallel.enabled = false) to reduce test flakiness.
Call process.waitFor(timeout, timeUnit) before reading process.exitValue() so the executor waits up to the configured timeout for the process to finish. This avoids attempting to read the exit value while the process may still be running.
Ensure the executor waits for the spawned process and surface a clearer error when it exits with a non-zero status. Added a static import for format and call process.waitFor(timeout, timeUnit) before checking exitValue; construct and throw an IOException with a formatted message that includes the command and exit code. Updated tests to use a reusable FastByteArrayOutputStream (with tearDown closing it), refactored tests to create local ProcessExecutor instances (using `javac --help`), and adjusted expectations for timeout and failure scenarios to match the new behavior.
Make ProcessManager non-instantiable by adding a private no-arg constructor and remove the public destroy(Process) method. Keeps existing unfinished process tracking methods and the unfinishedProcessesMap() accessor; this tightens the API and prevents external instantiation.
Remove redundant transient boolean flags used to track lazy resolution in ReflectiveDefinition, MemberDefinition, and ExecutableDefinition and rely on null checks for resolved fields. Replace some null/boolean checks with Objects.nonNull, and tighten equals implementations (add self-check and class-instance checks) for consistency. Update AbstractReflectiveDefinitionTest to use ArrayUtils.ofArray for constructing test inputs, expand test cases and assertions, and add a new skeleton ReflectiveDefinitionTest with empty test methods.
Enforce non-null Level in Deprecation by adding an assertNotNull check and changing the constructor parameter to @nonnull, removing the previous null-to-DEFAULT fallback. Simplify equals() with an identity check before instanceof. Update unit tests to use static imports, cover identity/equality/inequality cases, and reflect the DEFAULT Level behavior where appropriate.
Add the missing '{}' placeholder to the error message in ProcessExecutor so the exit value is included in the formatted string. Update the unit test to invoke `java -version` instead of `javac --help`, using a more reliable command that produces output in typical runtime environments.
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.







This pull request introduces several improvements and refactors to the annotation processor module, focusing on dependency updates, code structure simplification, and modernization of build and test workflows. The most important changes are grouped below by theme.
Dependency and Build Workflow Updates:
.github/workflows/maven-build.yml,.github/workflows/maven-publish.yml) to use newer versions ofactions/checkoutandactions/setup-java, switched Maven build to use the wrapper (./mvnw), and added-Dsurefire.useSystemClassLoader=falsefor improved test reliability. [1] [2].mvn/wrapper/maven-wrapper.propertiesto use Maven 3.9.9 from an Aliyun mirror, and simplified wrapper settings.Dependency Management in
microsphere-annotation-processor:javax.ws.rs.versionandjaxws-api.versionfrompom.xml, and replaced property-based versioning with direct dependency versions. [1] [2]microsphere-lang-model,microsphere-jdk-tools, andmicrosphere-java-testfor enhanced annotation processing and testing capabilities. [1] [2]Code Refactoring and Simplification:
ConfigurationPropertyJSONElementVisitorto the main package, made it package-private, and updated its usage throughout the codebase. Also refactored its logic to handle attribute processing more generically. [1] [2] [3] [4] [5] [6]microsphere.lang.model.utilfor annotation and messaging utilities. [1] [2] [3]Testing Improvements:
ConfigurationPropertyAnnotationProcessorTestto useAbstractAnnotationProcessingTestand modernized imports, improving test clarity and maintainability.Documentation and API Changes:
ConfigurationPropertyAnnotationProcessor. [1] [2] [3] [4]These changes collectively modernize the build and test setup, simplify annotation processor code, and enhance maintainability and extensibility for future development.