Skip to content

Commit 8258618

Browse files
committed
Merge remote-tracking branch 'upstream/master'
2 parents 244360d + 12eba7f commit 8258618

File tree

16 files changed

+376
-27
lines changed

16 files changed

+376
-27
lines changed

.gitignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,4 @@ build/
99
*.project
1010
*.processors
1111
*/bin/
12-
*.editorconfig
13-
*.Module
12+

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.11</version>
8+
<version>8.12-RC4</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111

blackbox-other/pom.xml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
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">
5+
<modelVersion>4.0.0</modelVersion>
6+
<parent>
7+
<artifactId>avaje-inject-parent</artifactId>
8+
<groupId>io.avaje</groupId>
9+
<version>8.12-RC4</version>
10+
</parent>
11+
12+
<artifactId>blackbox-other</artifactId>
13+
14+
<dependencies>
15+
<dependency>
16+
<groupId>io.avaje</groupId>
17+
<artifactId>avaje-inject</artifactId>
18+
<version>${project.version}</version>
19+
<scope>provided</scope>
20+
</dependency>
21+
22+
<!-- annotation processor -->
23+
<dependency>
24+
<groupId>io.avaje</groupId>
25+
<artifactId>avaje-inject-generator</artifactId>
26+
<version>${project.version}</version>
27+
<scope>provided</scope>
28+
</dependency>
29+
30+
</dependencies>
31+
32+
</project>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package org.other.one;
2+
3+
import io.avaje.inject.Component;
4+
5+
@Component
6+
public class OtherComponent {
7+
8+
}

blackbox-test-inject/pom.xml

Lines changed: 34 additions & 2 deletions
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.11</version>
8+
<version>8.12-RC4</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111

@@ -24,6 +24,18 @@
2424
<version>${project.version}</version>
2525
</dependency>
2626

27+
<dependency>
28+
<groupId>io.avaje</groupId>
29+
<artifactId>blackbox-other</artifactId>
30+
<version>${project.version}</version>
31+
</dependency>
32+
33+
<dependency>
34+
<groupId>io.avaje</groupId>
35+
<artifactId>avaje-jsonb</artifactId>
36+
<version>1.2-RC2</version>
37+
</dependency>
38+
2739
<dependency>
2840
<groupId>io.avaje</groupId>
2941
<artifactId>avaje-inject</artifactId>
@@ -42,6 +54,14 @@
4254
<version>1.7.1</version>
4355
</dependency>
4456

57+
<!-- annotation processor -->
58+
<dependency>
59+
<groupId>io.avaje</groupId>
60+
<artifactId>avaje-inject-generator</artifactId>
61+
<version>${project.version}</version>
62+
<scope>provided</scope>
63+
</dependency>
64+
4565
<!-- test dependencies -->
4666
<dependency>
4767
<groupId>io.avaje</groupId>
@@ -67,7 +87,19 @@
6787
</dependencies>
6888
<build>
6989
<plugins>
70-
<!-- Add Compiler args for loom and errorprone -->
90+
<plugin>
91+
<groupId>io.avaje</groupId>
92+
<artifactId>avaje-inject-maven-plugin</artifactId>
93+
<version>1.0-SNAPSHOT</version>
94+
<executions>
95+
<execution>
96+
<phase>process-sources</phase>
97+
<goals>
98+
<goal>provides</goal>
99+
</goals>
100+
</execution>
101+
</executions>
102+
</plugin>
71103
<plugin>
72104
<groupId>org.apache.maven.plugins</groupId>
73105
<artifactId>maven-compiler-plugin</artifactId>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package org.example.myapp.external;
2+
3+
import io.avaje.inject.Component;
4+
import io.avaje.jsonb.Jsonb;
5+
import org.example.external.aspect.MyExternalAspect;
6+
import org.other.one.OtherComponent;
7+
8+
@Component
9+
public class HasExternalDependencies {
10+
11+
// plugin
12+
public final Jsonb fromPlugin;
13+
// component from other module
14+
public final OtherComponent fromExternal;
15+
16+
public HasExternalDependencies(Jsonb jsonb, OtherComponent otherComponent) {
17+
this.fromPlugin = jsonb;
18+
this.fromExternal = otherComponent;
19+
}
20+
21+
@MyExternalAspect
22+
public String doStuff() {
23+
return "hello";
24+
}
25+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package org.example.myapp.external;
2+
3+
import io.avaje.inject.BeanScope;
4+
import io.avaje.jsonb.Jsonb;
5+
import org.junit.jupiter.api.Test;
6+
import org.other.one.OtherComponent;
7+
8+
import static org.assertj.core.api.Assertions.assertThat;
9+
10+
class HasExternalDependenciesTest {
11+
12+
@Test
13+
void doStuff() {
14+
try (BeanScope beanScope = BeanScope.builder().build()) {
15+
16+
final var jsonb = beanScope.get(Jsonb.class);
17+
assertThat(jsonb).isNotNull();
18+
final var other = beanScope.get(OtherComponent.class);
19+
assertThat(other).isNotNull();
20+
21+
var hasExternalDependencies = beanScope.get(HasExternalDependencies.class);
22+
assertThat(hasExternalDependencies.doStuff()).isEqualTo("hello");
23+
assertThat(hasExternalDependencies.fromPlugin).isSameAs(jsonb);
24+
assertThat(hasExternalDependencies.fromExternal).isSameAs(other);
25+
}
26+
27+
}
28+
}

inject-generator/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<parent>
55
<groupId>io.avaje</groupId>
66
<artifactId>avaje-inject-parent</artifactId>
7-
<version>8.11</version>
7+
<version>8.12-RC4</version>
88
</parent>
99

1010
<artifactId>avaje-inject-generator</artifactId>
@@ -16,7 +16,7 @@
1616
<dependency>
1717
<groupId>io.avaje</groupId>
1818
<artifactId>avaje-inject</artifactId>
19-
<version>8.11</version>
19+
<version>8.12-RC4</version>
2020
</dependency>
2121

2222
<!-- test dependencies -->

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

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@
66

77
/**
88
* The types provided by other modules in the classpath at compile time.
9-
* <p>
10-
* When we depend on these types they add to the module autoRequires() classes.
9+
*
10+
* <p>When we depend on these types they add to the module autoRequires() classes.
1111
*/
1212
final class ExternalProvider {
1313

1414
private final Set<String> providedTypes = new HashSet<>();
1515

16-
void init() {
16+
void init(Set<String> moduleFileProvided) {
17+
providedTypes.addAll(moduleFileProvided);
1718
ServiceLoader<Module> load = ServiceLoader.load(Module.class, ExternalProvider.class.getClassLoader());
1819
Iterator<Module> iterator = load.iterator();
1920
while (iterator.hasNext()) {
@@ -22,21 +23,21 @@ void init() {
2223
for (final Class<?> provide : module.provides()) {
2324
providedTypes.add(provide.getCanonicalName());
2425
}
25-
for (Class<?> provide : module.autoProvides()) {
26+
for (final Class<?> provide : module.autoProvides()) {
2627
providedTypes.add(provide.getCanonicalName());
2728
}
2829
for (final Class<?> provide : module.autoProvidesAspects()) {
2930
providedTypes.add(Util.wrapAspect(provide.getCanonicalName()));
3031
}
31-
} catch (ServiceConfigurationError expected) {
32+
} catch (final ServiceConfigurationError expected) {
3233
// ignore expected error reading the module that we are also writing
3334
}
3435
}
3536
}
3637

3738
/**
38-
* Return true if this type is provided by another module in the classpath.
39-
* We will add it to autoRequires().
39+
* Return true if this type is provided by another module in the classpath. We will add it to
40+
* autoRequires().
4041
*/
4142
boolean provides(String type) {
4243
return providedTypes.contains(type);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,13 @@ final class ProcessingContext {
3030
private final Set<String> uniqueModuleNames = new HashSet<>();
3131
private final ExternalProvider externalProvide = new ExternalProvider();
3232

33-
ProcessingContext(ProcessingEnvironment processingEnv) {
33+
ProcessingContext(ProcessingEnvironment processingEnv, Set<String> moduleFileProvided) {
3434
this.processingEnv = processingEnv;
3535
this.messager = processingEnv.getMessager();
3636
this.filer = processingEnv.getFiler();
3737
this.elementUtils = processingEnv.getElementUtils();
3838
this.typeUtils = processingEnv.getTypeUtils();
39-
externalProvide.init();
39+
externalProvide.init(moduleFileProvided);
4040
}
4141

4242
/**

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

Lines changed: 46 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import jakarta.inject.Singleton;
1111

1212
import javax.annotation.processing.AbstractProcessor;
13+
import javax.annotation.processing.Filer;
1314
import javax.annotation.processing.ProcessingEnvironment;
1415
import javax.annotation.processing.RoundEnvironment;
1516
import javax.lang.model.SourceVersion;
@@ -18,9 +19,14 @@
1819
import javax.lang.model.element.ElementKind;
1920
import javax.lang.model.element.TypeElement;
2021
import javax.lang.model.util.Elements;
21-
import java.util.LinkedHashSet;
22-
import java.util.ServiceLoader;
23-
import java.util.Set;
22+
import javax.tools.StandardLocation;
23+
import java.io.BufferedReader;
24+
import java.io.IOException;
25+
import java.io.InputStreamReader;
26+
import java.net.URL;
27+
import java.util.*;
28+
import java.util.stream.Collectors;
29+
import java.util.stream.Stream;
2430

2531
public final class Processor extends AbstractProcessor {
2632

@@ -29,9 +35,8 @@ public final class Processor extends AbstractProcessor {
2935
private ScopeInfo defaultScope;
3036
private AllScopes allScopes;
3137
private boolean readModuleInfo;
32-
33-
public Processor() {
34-
}
38+
private final Set<String> pluginFileProvided = new HashSet<>();
39+
private final Set<String> moduleFileProvided = new HashSet<>();
3540

3641
@Override
3742
public SourceVersion getSupportedSourceVersion() {
@@ -41,13 +46,45 @@ public SourceVersion getSupportedSourceVersion() {
4146
@Override
4247
public synchronized void init(ProcessingEnvironment processingEnv) {
4348
super.init(processingEnv);
44-
this.context = new ProcessingContext(processingEnv);
49+
loadProvidedFiles(processingEnv.getFiler());
50+
this.context = new ProcessingContext(processingEnv, moduleFileProvided);
4551
this.elementUtils = processingEnv.getElementUtils();
4652
this.allScopes = new AllScopes(context);
4753
this.defaultScope = allScopes.defaultScope();
4854
registerPluginProvidedTypes();
4955
}
5056

57+
/**
58+
* Loads provider files generated by avaje-inject-maven-plugin
59+
*/
60+
void loadProvidedFiles(Filer filer) {
61+
targetProvidesLines(filer, "target/avaje-plugin-provides.txt")
62+
.forEach(pluginFileProvided::add);
63+
64+
targetProvidesLines(filer, "target/avaje-module-provides.txt")
65+
.forEach(moduleFileProvided::add);
66+
}
67+
68+
private static List<String> targetProvidesLines(Filer filer, String relativeName) {
69+
try {
70+
final String resource = targetProvides(filer, relativeName);
71+
try (var inputStream = new URL(resource).openStream();
72+
var reader = new BufferedReader(new InputStreamReader(inputStream))) {
73+
return reader.lines().collect(Collectors.toList());
74+
}
75+
} catch (final IOException e) {
76+
return Collections.emptyList();
77+
}
78+
}
79+
80+
private static String targetProvides(Filer filer, String relativeName) throws IOException {
81+
return filer
82+
.getResource(StandardLocation.CLASS_OUTPUT, "", relativeName)
83+
.toUri()
84+
.toString()
85+
.replace("/target/classes", "");
86+
}
87+
5188
/**
5289
* Register types provided by the plugin so no compiler error when we have a dependency
5390
* on these types and the only thing providing them is the plugin.
@@ -58,6 +95,7 @@ private void registerPluginProvidedTypes() {
5895
defaultScope.pluginProvided(provide.getCanonicalName());
5996
}
6097
}
98+
pluginFileProvided.forEach(defaultScope::pluginProvided);
6199
}
62100

63101
@Override
@@ -66,6 +104,7 @@ public Set<String> getSupportedAnnotationTypes() {
66104
annotations.add(InjectModule.class.getCanonicalName());
67105
annotations.add(Factory.class.getCanonicalName());
68106
annotations.add(Singleton.class.getCanonicalName());
107+
annotations.add(Component.class.getCanonicalName());
69108
annotations.add(Prototype.class.getCanonicalName());
70109
annotations.add(Scope.class.getCanonicalName());
71110
annotations.add(Constants.TESTSCOPE);

0 commit comments

Comments
 (0)