Skip to content

Commit 5c05eea

Browse files
committed
generate once only
1 parent 1fb013f commit 5c05eea

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

pom.xml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757

5858
<properties>
5959
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
60-
<java.version>17</java.version>
60+
<java.version>21</java.version>
6161
<releaseProfile>release-plugin-gen</releaseProfile>
6262
</properties>
6363

@@ -85,7 +85,8 @@
8585
<showDeprecation>true</showDeprecation>
8686
<!-- Disable annotation processing for ourselves.-->
8787
<compilerArgument>-proc:none</compilerArgument>
88-
<target>15</target>
88+
<target>21</target>
89+
<source>21</source>
8990
</configuration>
9091
</plugin>
9192
<plugin>

src/main/java/org/cubeengine/processor/PluginGenerator.java

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
import java.util.stream.Collectors;
3333

3434
import javax.annotation.processing.AbstractProcessor;
35+
import javax.annotation.processing.Messager;
36+
import javax.annotation.processing.ProcessingEnvironment;
3537
import javax.annotation.processing.RoundEnvironment;
3638
import javax.annotation.processing.SupportedAnnotationTypes;
3739
import javax.annotation.processing.SupportedOptions;
@@ -45,7 +47,7 @@
4547

4648
@SupportedOptions({"cubeengine.module.version", "cubeengine.module.sourceversion", "cubeengine.module.id", "cubeengine.module.name", "cubeengine.module.description", "cubeengine.module.team", "cubeengine.module.url", "cubeengine.module.libcube.version", "cubeengine.module.sponge.version"})
4749
@SupportedAnnotationTypes({ PLUGIN_ANNOTATION, CORE_ANNOTATION, DEP_ANNOTATION })
48-
@SupportedSourceVersion(SourceVersion.RELEASE_17)
50+
@SupportedSourceVersion(SourceVersion.RELEASE_21)
4951
public class PluginGenerator extends AbstractProcessor
5052
{
5153

@@ -54,6 +56,16 @@ public class PluginGenerator extends AbstractProcessor
5456
static final String CORE_ANNOTATION = PACKAGE + "Core";
5557
static final String DEP_ANNOTATION = PACKAGE + "Dependency";
5658

59+
private Messager messager;
60+
61+
@Override
62+
public synchronized void init(ProcessingEnvironment processingEnv) {
63+
super.init(processingEnv);
64+
messager = processingEnv.getMessager();
65+
}
66+
67+
private boolean generated = false;
68+
5769
@Override
5870
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv)
5971
{
@@ -62,8 +74,12 @@ public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment
6274
return false;
6375
}
6476

77+
if (this.generated) {
78+
return false;
79+
}
6580
generateModulePlugin(roundEnv);
6681
generateCorePlugin(roundEnv);
82+
this.generated = true;
6783

6884
return false;
6985
}
@@ -72,13 +88,18 @@ private void generateCorePlugin(RoundEnvironment roundEnv)
7288
{
7389
for (Element el : roundEnv.getElementsAnnotatedWith(Core.class))
7490
{
91+
messager.printNote("Generating core plugin");
7592
buildSource((TypeElement) el, new ArrayList<>(), true);
7693
}
7794
}
7895

7996
public void generateModulePlugin(RoundEnvironment roundEnv)
8097
{
81-
for (Element el : roundEnv.getElementsAnnotatedWith(Module.class))
98+
final Set<? extends Element> moduleSet = roundEnv.getElementsAnnotatedWith(Module.class);
99+
if (moduleSet.size() > 0) {
100+
messager.printNote("Generating %d modules".formatted(moduleSet.size()));
101+
}
102+
for (Element el : moduleSet)
82103
{
83104
final TypeElement element = (TypeElement) el;
84105

0 commit comments

Comments
 (0)