Skip to content

Commit d3a3491

Browse files
committed
plugin aspects
1 parent bca9e75 commit d3a3491

File tree

6 files changed

+55
-28
lines changed

6 files changed

+55
-28
lines changed

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

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

3-
import java.util.Iterator;
43
import java.util.ServiceConfigurationError;
54
import java.util.ServiceLoader;
65
import java.util.Set;
@@ -64,6 +63,9 @@ static void registerPluginProvidedTypes(ScopeInfo defaultScope) {
6463
for (final Class<?> provide : plugin.provides()) {
6564
defaultScope.pluginProvided(provide.getCanonicalName());
6665
}
66+
for (final Class<?> provide : plugin.providesAspects()) {
67+
defaultScope.pluginProvided(Util.wrapAspect(provide.getCanonicalName()));
68+
}
6769
}
6870
}
6971
}

inject-gradle-plugin/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ repositories {
1414
}
1515

1616
dependencies {
17-
implementation 'io.avaje:avaje-inject:9.0'
17+
implementation 'io.avaje:avaje-inject:9.4-SNAPSHOT'
1818
implementation gradleApi()
1919

2020
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.1'

inject-gradle-plugin/src/main/java/io/avaje/inject/plugin/AvajeInjectPlugin.java

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import org.gradle.api.*;
44

5+
import io.avaje.inject.spi.Plugin;
6+
57
import java.io.File;
68
import java.io.FileWriter;
79
import java.io.IOException;
@@ -54,13 +56,22 @@ private FileWriter createFileWriter(String dir, String file) throws IOException
5456
}
5557

5658
private void writeProvidedPlugins(ClassLoader cl, FileWriter pluginWriter) throws IOException {
57-
for (final io.avaje.inject.spi.Plugin plugin : ServiceLoader.load(io.avaje.inject.spi.Plugin.class, cl)) {
58-
for (final Class<?> providedType : plugin.provides()) {
59-
pluginWriter.write(providedType.getCanonicalName());
60-
pluginWriter.write("\n");
61-
}
62-
}
63-
}
59+
final Set<String> providedTypes = new HashSet<>();
60+
61+
for (final var plugin : ServiceLoader.load(Plugin.class, newClassLoader)) {
62+
for (final Class<?> provide : plugin.provides()) {
63+
providedTypes.add(provide.getCanonicalName());
64+
}
65+
for (final Class<?> provide : plugin.providesAspects()) {
66+
providedTypes.add(wrapAspect(provide.getCanonicalName()));
67+
}
68+
}
69+
70+
for (final var providedType : providedTypes) {
71+
pluginWriter.write(providedType);
72+
pluginWriter.write("\n");
73+
}
74+
}
6475

6576
private void writeProvidedModules(ClassLoader classLoader, FileWriter moduleWriter) throws IOException {
6677
final Set<String> providedTypes = new HashSet<>();

inject-maven-plugin/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
<dependency>
3030
<groupId>io.avaje</groupId>
3131
<artifactId>avaje-inject</artifactId>
32-
<version>8.12-RC4</version>
32+
<version>9.4-SNAPSHOT</version>
3333
</dependency>
3434
</dependencies>
3535

inject-maven-plugin/src/main/java/io/avaje/inject/mojo/AutoProvidesMojo.java

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -84,19 +84,28 @@ private FileWriter createFileWriter(String string) throws IOException {
8484

8585
private void writeProvidedPlugins(URLClassLoader newClassLoader, FileWriter pluginWriter)
8686
throws IOException {
87-
for (final var plugin : ServiceLoader.load(Plugin.class, newClassLoader)) {
88-
for (final Class<?> providedType : plugin.provides()) {
89-
pluginWriter.write(providedType.getCanonicalName());
90-
pluginWriter.write("\n");
91-
}
92-
}
93-
}
87+
final Set<String> providedTypes = new HashSet<>();
88+
89+
for (final var plugin : ServiceLoader.load(Plugin.class, newClassLoader)) {
90+
for (final Class<?> provide : plugin.provides()) {
91+
providedTypes.add(provide.getCanonicalName());
92+
}
93+
for (final Class<?> provide : plugin.providesAspects()) {
94+
providedTypes.add(wrapAspect(provide.getCanonicalName()));
95+
}
96+
}
97+
98+
for (final var providedType : providedTypes) {
99+
pluginWriter.write(providedType);
100+
pluginWriter.write("\n");
101+
}
102+
}
94103

95104
private void writeProvidedModules(URLClassLoader newClassLoader, FileWriter moduleWriter)
96105
throws IOException {
97106
final Set<String> providedTypes = new HashSet<>();
98107

99-
for (final Module module : ServiceLoader.load(Module.class, newClassLoader)) {
108+
for (final var module : ServiceLoader.load(Module.class, newClassLoader)) {
100109
for (final Class<?> provide : module.provides()) {
101110
providedTypes.add(provide.getCanonicalName());
102111
}

inject/src/main/java/io/avaje/inject/spi/Plugin.java

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,25 @@
66

77
/**
88
* A Plugin that can be applied when creating a bean scope.
9-
* <p>
10-
* Typically, a plugin might provide a default dependency via {@link BeanScopeBuilder#provideDefault(Type, java.util.function.Supplier)}.
9+
*
10+
* <p>Typically, a plugin might provide a default dependency via {@link
11+
* BeanScopeBuilder#provideDefault(Type, java.util.function.Supplier)}.
1112
*/
1213
public interface Plugin {
1314

14-
/**
15-
* Return the classes that the plugin provides.
16-
*/
15+
/** Apply the plugin to the scope builder. */
16+
void apply(BeanScopeBuilder builder);
17+
18+
/** Empty array of classes. */
19+
Class<?>[] EMPTY_CLASSES = {};
20+
21+
/** Return the classes that the plugin provides. */
1722
default Class<?>[] provides() {
18-
return new Class<?>[]{};
23+
return EMPTY_CLASSES;
1924
}
2025

21-
/**
22-
* Apply the plugin to the scope builder.
23-
*/
24-
void apply(BeanScopeBuilder builder);
26+
/** Return the aspect classes that the plugin provides. */
27+
default Class<?>[] providesAspects() {
28+
return EMPTY_CLASSES;
29+
}
2530
}

0 commit comments

Comments
 (0)