Skip to content

Commit a9d4e71

Browse files
committed
fix: cache ClassFinder for reuse in mojo execution
Creates ClassFinder once per mojo execution, preventing eccessive and useless scans. Fixes #19874
1 parent 179f04a commit a9d4e71

File tree

1 file changed

+19
-14
lines changed

1 file changed

+19
-14
lines changed

flow-plugins/flow-maven-plugin/src/main/java/com/vaadin/flow/plugin/maven/FlowModeAbstractMojo.java

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@
2727
import java.util.stream.Collectors;
2828
import java.util.stream.Stream;
2929

30+
import org.apache.maven.artifact.Artifact;
31+
import org.apache.maven.artifact.DependencyResolutionRequiredException;
32+
import org.apache.maven.plugin.AbstractMojo;
33+
import org.apache.maven.plugins.annotations.Parameter;
34+
import org.apache.maven.project.MavenProject;
35+
3036
import com.vaadin.flow.internal.StringUtil;
3137
import com.vaadin.flow.plugin.base.BuildFrontendUtil;
3238
import com.vaadin.flow.plugin.base.PluginAdapterBase;
@@ -37,11 +43,6 @@
3743
import com.vaadin.flow.server.frontend.installer.NodeInstaller;
3844
import com.vaadin.flow.server.frontend.installer.Platform;
3945
import com.vaadin.flow.server.frontend.scanner.ClassFinder;
40-
import org.apache.maven.artifact.Artifact;
41-
import org.apache.maven.artifact.DependencyResolutionRequiredException;
42-
import org.apache.maven.plugin.AbstractMojo;
43-
import org.apache.maven.plugins.annotations.Parameter;
44-
import org.apache.maven.project.MavenProject;
4546

4647
import static com.vaadin.flow.server.Constants.VAADIN_SERVLET_RESOURCES;
4748
import static com.vaadin.flow.server.Constants.VAADIN_WEBAPP_RESOURCES;
@@ -241,6 +242,8 @@ public abstract class FlowModeAbstractMojo extends AbstractMojo
241242
@Parameter(property = InitParameters.APPLICATION_IDENTIFIER)
242243
private String applicationIdentifier;
243244

245+
private ClassFinder classFinder;
246+
244247
/**
245248
* Generates a List of ClasspathElements (Run and CompileTime) from a
246249
* MavenProject.
@@ -274,10 +277,8 @@ public static List<String> getClasspathElements(MavenProject project) {
274277
* Target Maven project
275278
* @return true if Hilla is available, false otherwise
276279
*/
277-
public static boolean isHillaAvailable(MavenProject mavenProject) {
278-
List<String> classpathElements = FlowModeAbstractMojo
279-
.getClasspathElements(mavenProject);
280-
return BuildFrontendUtil.getClassFinder(classpathElements).getResource(
280+
public boolean isHillaAvailable(MavenProject mavenProject) {
281+
return getOrCreateClassFinder(mavenProject).getResource(
281282
"com/vaadin/hilla/EndpointController.class") != null;
282283
}
283284

@@ -292,7 +293,7 @@ public static boolean isHillaAvailable(MavenProject mavenProject) {
292293
* @return {@code true} if Hilla is available and Hilla views are used,
293294
* {@code false} otherwise
294295
*/
295-
public static boolean isHillaUsed(MavenProject mavenProject,
296+
public boolean isHillaUsed(MavenProject mavenProject,
296297
File frontendDirectory) {
297298
return isHillaAvailable(mavenProject)
298299
&& FrontendUtils.isHillaViewsUsed(frontendDirectory);
@@ -325,11 +326,15 @@ public File generatedTsFolder() {
325326

326327
@Override
327328
public ClassFinder getClassFinder() {
329+
return getOrCreateClassFinder(project);
330+
}
328331

329-
List<String> classpathElements = getClasspathElements(project);
330-
331-
return BuildFrontendUtil.getClassFinder(classpathElements);
332-
332+
private ClassFinder getOrCreateClassFinder(MavenProject project) {
333+
if (classFinder == null) {
334+
List<String> classpathElements = getClasspathElements(project);
335+
classFinder = BuildFrontendUtil.getClassFinder(classpathElements);
336+
}
337+
return classFinder;
333338
}
334339

335340
@Override

0 commit comments

Comments
 (0)