File tree Expand file tree Collapse file tree 14 files changed +422
-43
lines changed
api/maven-api-di/src/main/java/org/apache/maven/api/di
maven-di/src/main/java/org/apache/maven/di
maven-impl/src/main/java/org/apache/maven/impl/di Expand file tree Collapse file tree 14 files changed +422
-43
lines changed Original file line number Diff line number Diff line change 2727import static java .lang .annotation .ElementType .METHOD ;
2828import static java .lang .annotation .RetentionPolicy .RUNTIME ;
2929
30+ /**
31+ * Marks a dependency injection point for constructor, method, or field injection.
32+ * <p>
33+ * This annotation is used to identify injection points where the container should
34+ * provide an instance of the requested type. It can be applied to:
35+ * <ul>
36+ * <li>Constructors</li>
37+ * <li>Methods</li>
38+ * <li>Fields</li>
39+ * </ul>
40+ * <p>
41+ * Example usage:
42+ * <pre>
43+ * public class MyService {
44+ * private final Repository repository;
45+ *
46+ * {@literal @}Inject
47+ * public MyService(Repository repository) {
48+ * this.repository = repository;
49+ * }
50+ * }
51+ * </pre>
52+ *
53+ * @see Named
54+ * @since 4.0.0
55+ */
3056@ Target ({FIELD , CONSTRUCTOR , METHOD })
3157@ Retention (RUNTIME )
3258@ Documented
Original file line number Diff line number Diff line change 2323
2424import static java .lang .annotation .RetentionPolicy .RUNTIME ;
2525
26+ /**
27+ * Provides a unique identifier for dependencies when multiple implementations
28+ * of the same type are available.
29+ * <p>
30+ * This annotation can be used in conjunction with {@link Inject} to specify
31+ * which implementation should be injected when multiple candidates exist.
32+ * The value represents a unique identifier for the dependency.
33+ * <p>
34+ * Example usage:
35+ * <pre>
36+ * {@literal @}Inject
37+ * {@literal @}Named("mysql")
38+ * private Repository mysqlRepository;
39+ * </pre>
40+ *
41+ * @see Inject
42+ * @see Qualifier
43+ * @since 4.0.0
44+ */
2645@ Qualifier
2746@ Retention (RUNTIME )
2847@ Documented
2948public @interface Named {
49+ /**
50+ * The name identifier for the annotated element.
51+ * <p>
52+ * If no value is specified, the default empty string will be used.
53+ * When used as a qualifier, this value helps distinguish between different
54+ * implementations or instances of the same type.
55+ *
56+ * @return the name that identifies this component
57+ */
3058 String value () default "" ;
3159}
Original file line number Diff line number Diff line change 2626import static java .lang .annotation .ElementType .TYPE ;
2727import static java .lang .annotation .RetentionPolicy .RUNTIME ;
2828
29+ /**
30+ * Specifies the priority of a bean implementation when multiple implementations
31+ * of the same type are available.
32+ * <p>
33+ * Higher values indicate higher priority. When multiple implementations of the same
34+ * type exist, the one with the highest priority will be selected for injection.
35+ * <p>
36+ * Example usage:
37+ * <pre>
38+ * {@literal @}Priority(100)
39+ * public class PreferredImplementation implements Service {
40+ * // Implementation
41+ * }
42+ * </pre>
43+ *
44+ * @since 4.0.0
45+ */
2946@ Target ({TYPE , METHOD })
3047@ Retention (RUNTIME )
3148@ Documented
3249public @interface Priority {
50+ /**
51+ * The priority value for the annotated element.
52+ * <p>
53+ * Higher values indicate higher priority. When multiple implementations
54+ * of the same type exist in the container, the one with the highest
55+ * priority value will be selected for injection.
56+ * <p>
57+ * There are no predefined minimum or maximum values, but it's recommended
58+ * to use values that allow for future adjustments (e.g., using values
59+ * like 100, 200, 300 rather than consecutive numbers).
60+ *
61+ * @return the priority value for ordering
62+ */
3363 int value ();
3464}
Original file line number Diff line number Diff line change 2626import static java .lang .annotation .RetentionPolicy .RUNTIME ;
2727
2828/**
29- * Can be used on a static method to provide a bean.
29+ * Marks a method as a provider of beans for dependency injection.
30+ * <p>
31+ * This annotation can be used on static methods to programmatically create and configure
32+ * beans that will be managed by the dependency injection container. It's particularly
33+ * useful when the bean creation requires complex logic or when the bean needs to be
34+ * configured based on runtime conditions.
35+ * <p>
36+ * Example usage:
37+ * <pre>
38+ * public class Providers {
39+ * {@literal @}Provides
40+ * {@literal @}Singleton
41+ * public static Configuration provideConfiguration() {
42+ * return Configuration.load();
43+ * }
44+ * }
45+ * </pre>
46+ *
47+ * @since 4.0.0
3048 */
3149@ Target (METHOD )
3250@ Retention (RUNTIME )
Original file line number Diff line number Diff line change 2525import static java .lang .annotation .ElementType .ANNOTATION_TYPE ;
2626import static java .lang .annotation .RetentionPolicy .RUNTIME ;
2727
28+ /**
29+ * Meta-annotation that marks other annotations as qualifier annotations.
30+ * <p>
31+ * Qualifiers are used to distinguish between multiple beans of the same type,
32+ * allowing for more precise control over which implementation should be injected.
33+ * Custom qualifier annotations should be annotated with {@code @Qualifier}.
34+ * <p>
35+ * Example of creating a custom qualifier:
36+ * <pre>
37+ * {@literal @}Qualifier
38+ * {@literal @}Retention(RUNTIME)
39+ * public @interface Database {
40+ * String value();
41+ * }
42+ * </pre>
43+ *
44+ * @see Named
45+ * @since 4.0.0
46+ */
2847@ Target (ANNOTATION_TYPE )
2948@ Retention (RUNTIME )
3049@ Documented
Original file line number Diff line number Diff line change 2525import static java .lang .annotation .ElementType .ANNOTATION_TYPE ;
2626import static java .lang .annotation .RetentionPolicy .RUNTIME ;
2727
28+ /**
29+ * Meta-annotation that marks other annotations as scope annotations.
30+ * <p>
31+ * Scopes define the lifecycle and visibility of objects in the dependency injection
32+ * system. Custom scope annotations should be annotated with {@code @Scope}.
33+ * <p>
34+ * Built-in scopes include:
35+ * <ul>
36+ * <li>{@link Singleton} - One instance per container</li>
37+ * <li>{@link SessionScoped} - One instance per Maven session</li>
38+ * <li>{@link MojoExecutionScoped} - One instance per plugin execution</li>
39+ * </ul>
40+ *
41+ * @see Singleton
42+ * @see SessionScoped
43+ * @see MojoExecutionScoped
44+ * @since 4.0.0
45+ */
2846@ Target (ANNOTATION_TYPE )
2947@ Retention (RUNTIME )
3048@ Documented
Original file line number Diff line number Diff line change 2323
2424import static java .lang .annotation .RetentionPolicy .RUNTIME ;
2525
26+ /**
27+ * Denotes that a bean should be created as a singleton instance.
28+ * <p>
29+ * Singleton-scoped beans are instantiated once and reused throughout the entire
30+ * Maven execution. This scope should be used for stateless services or components
31+ * that can be safely shared across the entire build process.
32+ * <p>
33+ * Example usage:
34+ * <pre>
35+ * {@literal @}Singleton
36+ * public class GlobalConfiguration {
37+ * // Implementation
38+ * }
39+ * </pre>
40+ *
41+ * @see Scope
42+ * @since 4.0.0
43+ */
2644@ Scope
2745@ Documented
2846@ Retention (RUNTIME )
Original file line number Diff line number Diff line change 2727import static java .lang .annotation .ElementType .TYPE ;
2828import static java .lang .annotation .RetentionPolicy .RUNTIME ;
2929
30+ /**
31+ * Explicitly specifies the types that should be used for dependency injection.
32+ * <p>
33+ * This annotation allows you to limit which types of a bean should be available
34+ * for injection. It can be used to prevent unintended automatic binding of implemented
35+ * interfaces or extended classes.
36+ * <p>
37+ * Example usage:
38+ * <pre>
39+ * {@literal @}Typed(ServiceImpl.class)
40+ * public class ServiceImpl implements Service {
41+ * // Implementation
42+ * }
43+ * </pre>
44+ *
45+ * @since 4.0.0
46+ */
3047@ Target ({FIELD , METHOD , TYPE })
3148@ Retention (RUNTIME )
3249@ Documented
3350public @interface Typed {
51+ /**
52+ * Specifies the types that should be considered for dependency injection.
53+ * <p>
54+ * When specified, only the listed types will be available for injection,
55+ * even if the class implements or extends other types. If empty, the
56+ * default behavior is to make all supertypes available for injection.
57+ * <p>
58+ * Example:
59+ * <pre>
60+ * {@literal @}Typed({Service.class, Monitored.class})
61+ * public class ServiceImpl implements Service, Monitored, Logging {
62+ * // Only Service and Monitored will be available for injection,
63+ * // Logging interface will be ignored
64+ * }
65+ * </pre>
66+ *
67+ * @return an array of classes that should be considered for injection
68+ */
3469 Class <?>[] value () default {};
3570}
Original file line number Diff line number Diff line change 1+ /**
2+ * A dependency injection framework for Maven that provides JSR-330 style annotations
3+ * for managing object lifecycle and dependencies within Maven's build process.
4+ * <p>
5+ * This package provides a set of annotations that control how objects are created,
6+ * managed and injected throughout Maven's execution lifecycle. The framework is designed
7+ * to be lightweight yet powerful, supporting various scopes of object lifecycle from
8+ * singleton instances to mojo-execution-scoped beans.
9+ * <p>
10+ * Key features include:
11+ * <ul>
12+ * <li>Constructor, method, and field injection</li>
13+ * <li>Qualifiers for distinguishing between beans of the same type</li>
14+ * <li>Multiple scopes (Singleton, Session, and MojoExecution)</li>
15+ * <li>Priority-based implementation selection</li>
16+ * <li>Type-safe dependency injection</li>
17+ * </ul>
18+ *
19+ * @since 4.0.0
20+ */
21+ package org .apache .maven .api .di ;
You can’t perform that action at this time.
0 commit comments