Skip to content

Commit 064d8be

Browse files
committed
Squashed commit of the following:
commit 2b20e1b Author: Josiah Noel <[email protected]> Date: Wed Feb 8 18:45:55 2023 -0500 order constants commit 80dcb5c Author: Josiah Noel <[email protected]> Date: Wed Feb 8 18:35:12 2023 -0500 Update pom.xml commit a4e0de9 Author: Josiah Noel <[email protected]> Date: Wed Feb 8 17:47:57 2023 -0500 use avaje prism (it works, but is not deployed) commit e051806 Author: Josiah Noel <[email protected]> Date: Tue Feb 7 19:04:25 2023 -0500 Update module-info.java commit df99f4b Author: Josiah Noel <[email protected]> Date: Tue Feb 7 19:04:09 2023 -0500 Update module-info.java commit ce72b23 Merge: ad3f269 df12d0c Author: Josiah Noel <[email protected]> Date: Tue Feb 7 18:57:45 2023 -0500 Merge branch 'prism' of https://github.com/SentryMan/avaje-inject into prism commit ad3f269 Author: Josiah Noel <[email protected]> Date: Tue Feb 7 18:57:29 2023 -0500 static inject commit df12d0c Author: Josiah Noel <[email protected]> Date: Tue Feb 7 18:48:12 2023 -0500 static requires commit d09c0e2 Author: Josiah Noel <[email protected]> Date: Tue Feb 7 18:14:25 2023 -0500 don't need prism module commit b23e7f0 Author: Josiah Noel <[email protected]> Date: Tue Feb 7 18:04:34 2023 -0500 Update ExternalProvider.java commit 84da34b Author: Josiah Noel <[email protected]> Date: Tue Feb 7 17:57:38 2023 -0500 fix module commit 2e9008e Merge: 6e65622 91c5da2 Author: Josiah Noel <[email protected]> Date: Tue Feb 7 17:55:29 2023 -0500 Merge branch 'prism2' into prism commit 91c5da2 Merge: 2ee8553 2b0f8d4 Author: Josiah Noel <[email protected]> Date: Tue Feb 7 17:55:04 2023 -0500 Merge pull request #3 from agentgt/prism Switch to generating module-info for prisms commit 6e65622 Author: Josiah Noel <[email protected]> Date: Tue Feb 7 17:47:15 2023 -0500 rc5 commit 2b0f8d4 Author: Adam Gent <[email protected]> Date: Tue Feb 7 17:30:33 2023 -0500 Switch to generating module-info for prisms commit ca6c9e5 Author: Josiah Noel <[email protected]> Date: Tue Feb 7 17:01:32 2023 -0500 minor stuff commit 6f896d7 Author: Josiah Noel <[email protected]> Date: Tue Feb 7 16:52:31 2023 -0500 fix test commit 5f8b4bf Author: Josiah Noel <[email protected]> Date: Tue Feb 7 16:45:17 2023 -0500 compiles commit e7577ca Merge: b932fd8 2ee8553 Author: Josiah Noel <[email protected]> Date: Tue Feb 7 15:42:27 2023 -0500 Merge remote-tracking branch 'origin/prism2' into prism commit 2ee8553 Merge: 8258618 a121495 Author: Josiah Noel <[email protected]> Date: Tue Feb 7 15:34:49 2023 -0500 Merge pull request #2 from agentgt/prism Merge prism changes commit b932fd8 Author: Josiah Noel <[email protected]> Date: Tue Feb 7 15:01:46 2023 -0500 Update pom.xml commit 585e707 Author: Josiah Noel <[email protected]> Date: Tue Feb 7 15:01:29 2023 -0500 Update pom.xml commit f876306 Author: Josiah Noel <[email protected]> Date: Tue Feb 7 14:49:31 2023 -0500 external commit a121495 Author: Adam Gent <[email protected]> Date: Tue Feb 7 14:53:57 2023 -0500 Move prisms to new module commit 13c8300 Author: Josiah Noel <[email protected]> Date: Tue Feb 7 13:21:45 2023 -0500 working commit 65c022e Author: Josiah Noel <[email protected]> Date: Mon Feb 6 21:48:57 2023 -0500 Update pom.xml commit 264d51d Author: Josiah Noel <[email protected]> Date: Mon Feb 6 21:47:12 2023 -0500 sorta work commit 8258618 Merge: 244360d 12eba7f Author: Josiah Noel <[email protected]> Date: Mon Feb 6 09:56:59 2023 -0500 Merge remote-tracking branch 'upstream/master' commit 244360d Author: Josiah Noel <[email protected]> Date: Thu Feb 2 18:17:12 2023 -0500 Update pom.xml
1 parent 12eba7f commit 064d8be

28 files changed

+297
-304
lines changed

blackbox-aspect/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<artifactId>avaje-inject-parent</artifactId>
77
<groupId>io.avaje</groupId>
8-
<version>8.12-RC4</version>
8+
<version>8.12-RC5</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111

blackbox-other/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<artifactId>avaje-inject-parent</artifactId>
88
<groupId>io.avaje</groupId>
9-
<version>8.12-RC4</version>
9+
<version>8.12-RC5</version>
1010
</parent>
1111

1212
<artifactId>blackbox-other</artifactId>

blackbox-test-inject/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<artifactId>avaje-inject-parent</artifactId>
77
<groupId>io.avaje</groupId>
8-
<version>8.12-RC4</version>
8+
<version>8.12-RC5</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111

inject-generator/pom.xml

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,33 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<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">
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
35
<modelVersion>4.0.0</modelVersion>
46
<parent>
57
<groupId>io.avaje</groupId>
68
<artifactId>avaje-inject-parent</artifactId>
7-
<version>8.12-RC4</version>
9+
<version>8.12-RC5</version>
810
</parent>
911

1012
<artifactId>avaje-inject-generator</artifactId>
1113
<name>avaje inject generator</name>
1214
<description>annotation processor generating di as source code</description>
13-
1415
<dependencies>
1516

1617
<dependency>
1718
<groupId>io.avaje</groupId>
1819
<artifactId>avaje-inject</artifactId>
19-
<version>8.12-RC4</version>
20+
<version>${project.version}</version>
21+
<optional>true</optional>
22+
<scope>provided</scope>
23+
</dependency>
24+
25+
<dependency>
26+
<groupId>io.avaje</groupId>
27+
<artifactId>avaje-prisms</artifactId>
28+
<version>1.0</version>
29+
<optional>true</optional>
30+
<scope>provided</scope>
2031
</dependency>
2132

2233
<!-- test dependencies -->
@@ -40,8 +51,13 @@
4051
<configuration>
4152
<source>11</source>
4253
<target>11</target>
43-
<!-- Turn off annotation processing for building -->
44-
<compilerArgument>-proc:none</compilerArgument>
54+
<annotationProcessorPaths>
55+
<path>
56+
<groupId>io.avaje</groupId>
57+
<artifactId>avaje-prisms</artifactId>
58+
<version>1.0</version>
59+
</path>
60+
</annotationProcessorPaths>
4561
</configuration>
4662
</plugin>
4763

@@ -54,8 +70,6 @@
5470
</argLine>
5571
</configuration>
5672
</plugin>
57-
5873
</plugins>
5974
</build>
60-
6175
</project>

inject-generator/src/main/java/io/avaje/inject/generator/AllScopes.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
package io.avaje.inject.generator;
22

3-
import io.avaje.inject.InjectModule;
3+
import java.util.HashMap;
4+
import java.util.List;
5+
import java.util.Map;
46

57
import javax.annotation.processing.RoundEnvironment;
68
import javax.lang.model.element.Element;
79
import javax.lang.model.element.TypeElement;
8-
import java.util.HashMap;
9-
import java.util.List;
10-
import java.util.Map;
10+
1111

1212
final class AllScopes {
1313

@@ -59,7 +59,7 @@ void readModules(List<String> customScopeModules) {
5959
for (String customScopeModule : customScopeModules) {
6060
final TypeElement module = context.element(customScopeModule);
6161
if (module != null) {
62-
final InjectModule injectModule = module.getAnnotation(InjectModule.class);
62+
InjectModulePrism injectModule = InjectModulePrism.getInstanceOn(module);
6363
if (injectModule != null) {
6464
final String customScopeType = injectModule.customScopeType();
6565
final TypeElement scopeType = context.element(customScopeType);

inject-generator/src/main/java/io/avaje/inject/generator/AspectAnnotationReader.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package io.avaje.inject.generator;
22

3-
import io.avaje.inject.aop.Aspect;
43

54
import javax.lang.model.element.*;
5+
66
import java.util.ArrayList;
77
import java.util.List;
88
import java.util.Map;
@@ -27,7 +27,7 @@ List<AspectPair> read() {
2727
List<AspectPair> aspects = new ArrayList<>();
2828
for (AnnotationMirror annotationMirror : element.getAnnotationMirrors()) {
2929
Element anElement = annotationMirror.getAnnotationType().asElement();
30-
Aspect aspect = anElement.getAnnotation(Aspect.class);
30+
AspectPrism aspect = AspectPrism.getInstanceOn(anElement);
3131
if (aspect != null) {
3232
Meta meta = readTarget(anElement);
3333
if (meta != null) {

inject-generator/src/main/java/io/avaje/inject/generator/BeanReader.java

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
package io.avaje.inject.generator;
22

3-
import io.avaje.inject.Primary;
4-
import io.avaje.inject.Prototype;
5-
import io.avaje.inject.Secondary;
6-
import io.avaje.inject.spi.Proxy;
3+
import java.util.ArrayList;
4+
import java.util.Collections;
5+
import java.util.LinkedHashSet;
6+
import java.util.List;
7+
import java.util.Set;
78

89
import javax.lang.model.element.Element;
910
import javax.lang.model.element.TypeElement;
10-
import java.util.*;
11+
1112

1213
final class BeanReader {
1314

@@ -40,10 +41,10 @@ final class BeanReader {
4041
this.beanType = beanType;
4142
this.type = beanType.getQualifiedName().toString();
4243
this.shortName = shortName(beanType);
43-
this.prototype = (beanType.getAnnotation(Prototype.class) != null);
44-
this.primary = (beanType.getAnnotation(Primary.class) != null);
45-
this.secondary = !primary && (beanType.getAnnotation(Secondary.class) != null);
46-
this.proxy = (beanType.getAnnotation(Proxy.class) != null);
44+
this.prototype = (PrototypePrism.getInstanceOn(beanType) != null);
45+
this.primary = (PrimaryPrism.getInstanceOn(beanType) != null);
46+
this.secondary = !primary && (SecondaryPrism.getInstanceOn(beanType) != null);
47+
this.proxy = (ProxyPrism.getInstanceOn(beanType) != null);
4748
this.typeReader = new TypeReader(GenericType.parse(type), beanType, context, importTypes, factory);
4849
typeReader.process();
4950
this.requestParams = new BeanRequestParams(type);
@@ -319,7 +320,7 @@ boolean isRequestScopedController() {
319320
}
320321

321322
String suffix() {
322-
return isRequestScopedController() ? Constants.FACTORY : Constants.DI;
323+
return isRequestScopedController() ? Constants.DOLLAR_FACTORY : Constants.DI;
323324
}
324325

325326
/**

inject-generator/src/main/java/io/avaje/inject/generator/Constants.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,19 @@ final class Constants {
44

55
static final int ORDERING_DEFAULT = 1000;
66

7-
static final String FACTORY = "$Factory";
7+
static final String DOLLAR_FACTORY = "$Factory";
88
static final String DI = "$DI";
99
static final String IO_CLOSEABLE = "java.io.Closeable";
1010
static final String AUTO_CLOSEABLE = "java.lang.AutoCloseable";
1111
static final String OPTIONAL = "java.util.Optional";
1212
static final String KOTLIN_METADATA = "kotlin.Metadata";
1313
static final String TYPE = "java.lang.reflect.Type";
1414

15-
static final String PROVIDER = "jakarta.inject.Provider";
1615
static final String SINGLETON = "jakarta.inject.Singleton";
1716
static final String INJECT = "jakarta.inject.Inject";
17+
static final String SCOPE = "jakarta.inject.Scope";
18+
static final String QUALIFIER = "jakarta.inject.Qualifier";
19+
static final String NAMED = "jakarta.inject.Named";
1820

1921
static final String PATH = "io.avaje.http.api.Path";
2022
static final String CONTROLLER = "io.avaje.http.api.Controller";
@@ -30,10 +32,16 @@ final class Constants {
3032
static final String BEANSCOPE = "io.avaje.inject.BeanScope";
3133
static final String INJECTMODULE = "io.avaje.inject.InjectModule";
3234
static final String TESTSCOPE = "io.avaje.inject.test.TestScope";
35+
static final String PRIMARY = "io.avaje.inject.Primary";
36+
static final String SECONDARY = "io.avaje.inject.Secondary";
37+
static final String PROTOTYPE = "io.avaje.inject.Prototype";
38+
static final String COMPONENT = "io.avaje.inject.Component";
39+
static final String FACTORY = "io.avaje.inject.Factory";
40+
static final String BEAN = "io.avaje.inject.Bean";
3341

3442
static final String REFLECT_METHOD = "java.lang.reflect.Method";
3543
static final String ASPECT = "io.avaje.inject.aop.Aspect";
36-
static final String ASPECT_PROVIDER ="io.avaje.inject.aop.AspectProvider";
44+
static final String ASPECT_PROVIDER = "io.avaje.inject.aop.AspectProvider";
3745
static final String INVOCATION = "io.avaje.inject.aop.Invocation";
3846
static final String INVOCATION_EXCEPTION = "io.avaje.inject.aop.InvocationException";
3947
static final String METHOD_INTERCEPTOR = "io.avaje.inject.aop.MethodInterceptor";
@@ -46,5 +54,4 @@ final class Constants {
4654
static final String DEPENDENCYMETA = "io.avaje.inject.spi.DependencyMeta";
4755
static final String MODULE = "io.avaje.inject.spi.Module";
4856
static final String GENERICTYPE = "io.avaje.inject.spi.GenericType";
49-
5057
}

inject-generator/src/main/java/io/avaje/inject/generator/ExternalProvider.java

Lines changed: 40 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
package io.avaje.inject.generator;
22

3-
import io.avaje.inject.spi.Module;
3+
import java.util.Iterator;
4+
import java.util.ServiceConfigurationError;
5+
import java.util.ServiceLoader;
6+
import java.util.Set;
47

5-
import java.util.*;
8+
import io.avaje.inject.spi.Module;
9+
import io.avaje.inject.spi.Plugin;
610

711
/**
812
* The types provided by other modules in the classpath at compile time.
@@ -11,13 +15,29 @@
1115
*/
1216
final class ExternalProvider {
1317

14-
private final Set<String> providedTypes = new HashSet<>();
18+
private static final boolean injectAvailable = moduleCP();
19+
20+
private ExternalProvider() {}
21+
22+
private static boolean moduleCP() {
23+
try {
24+
Class.forName(Constants.MODULE);
25+
return true;
26+
} catch (final ClassNotFoundException e) {
27+
28+
return false;
29+
}
30+
}
31+
32+
public static void registerModuleProvidedTypes(Set<String> providedTypes) {
33+
34+
if (!injectAvailable) return;
35+
36+
Iterator<Module> iterator =
37+
ServiceLoader.load(Module.class, ExternalProvider.class.getClassLoader()).iterator();
1538

16-
void init(Set<String> moduleFileProvided) {
17-
providedTypes.addAll(moduleFileProvided);
18-
ServiceLoader<Module> load = ServiceLoader.load(Module.class, ExternalProvider.class.getClassLoader());
19-
Iterator<Module> iterator = load.iterator();
2039
while (iterator.hasNext()) {
40+
2141
try {
2242
Module module = iterator.next();
2343
for (final Class<?> provide : module.provides()) {
@@ -36,10 +56,19 @@ void init(Set<String> moduleFileProvided) {
3656
}
3757

3858
/**
39-
* Return true if this type is provided by another module in the classpath. We will add it to
40-
* autoRequires().
59+
* Register types provided by the plugin so no compiler error when we have a dependency on these
60+
* types and the only thing providing them is the plugin.
61+
*
62+
* @param defaultScope
4163
*/
42-
boolean provides(String type) {
43-
return providedTypes.contains(type);
64+
public static void registerPluginProvidedTypes(ScopeInfo defaultScope) {
65+
66+
if (!injectAvailable) return;
67+
68+
for (final Plugin plugin : ServiceLoader.load(Plugin.class, Processor.class.getClassLoader())) {
69+
for (final Class<?> provide : plugin.provides()) {
70+
defaultScope.pluginProvided(provide.getCanonicalName());
71+
}
72+
}
4473
}
4574
}

inject-generator/src/main/java/io/avaje/inject/generator/GenericTypeParser.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
package io.avaje.inject.generator;
22

3-
import java.util.Stack;
3+
import java.util.ArrayDeque;
4+
import java.util.Deque;
45

56
final class GenericTypeParser {
67

78
private final String raw;
89
private StringBuilder buf = new StringBuilder();
9-
private final Stack<GenericType> stack = new Stack<>();
10+
private final Deque<GenericType> stack = new ArrayDeque<>();
1011

1112
GenericTypeParser(String raw) {
1213
this.raw = raw;

inject-generator/src/main/java/io/avaje/inject/generator/MetaData.java

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
package io.avaje.inject.generator;
22

3-
import io.avaje.inject.spi.DependencyMeta;
43

54
import java.util.ArrayList;
6-
import java.util.Arrays;
75
import java.util.List;
86
import java.util.Set;
97
import java.util.stream.Collectors;
10-
import java.util.stream.Stream;
8+
119

1210
/**
1311
* Holds the data as per <code>@DependencyMeta</code>
@@ -41,14 +39,14 @@ final class MetaData {
4139
private boolean usesExternalDependency;
4240
private String externalDependency;
4341

44-
MetaData(DependencyMeta meta) {
42+
MetaData(DependencyMetaPrism meta) {
4543
this.type = meta.type();
4644
this.name = trimName(meta.name());
4745
this.shortType = Util.shortName(type);
4846
this.method = meta.method();
4947
this.providesAspect = meta.providesAspect();
50-
this.provides = asList(meta.provides());
51-
this.dependsOn = Stream.of(meta.dependsOn()).map(Dependency::new).collect(Collectors.toList());
48+
this.provides = meta.provides();
49+
this.dependsOn = meta.dependsOn().stream().map(Dependency::new).collect(Collectors.toList());
5250
this.autoProvides = meta.autoProvides();
5351
}
5452

@@ -113,13 +111,6 @@ void setWired() {
113111
this.wired = true;
114112
}
115113

116-
private List<String> asList(String[] content) {
117-
if (content == null || content.length == 0) {
118-
return new ArrayList<>();
119-
}
120-
return Arrays.asList(content);
121-
}
122-
123114
void update(BeanReader beanReader) {
124115
this.provides = beanReader.provides();
125116
this.dependsOn = beanReader.dependsOn();

0 commit comments

Comments
 (0)