Skip to content

Commit

Permalink
fix: reintroduce static methods used by Hilla (#20168) (#20172)
Browse files Browse the repository at this point in the history
Reintroduces static methods used by Hilla in FlowModeAbstractMojo,
preserving the ClassFinder creation improvements for Flow mojos.

Co-authored-by: Marco Collovati <[email protected]>
  • Loading branch information
vaadin-bot and mcollovati authored Oct 8, 2024
1 parent 957b789 commit 2ed1691
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ public void execute() throws MojoExecutionException, MojoFailureException {
* @return {@code true} to remove created files, {@code false} to keep files
*/
protected boolean cleanFrontendFiles() {
if (isHillaUsed(project, frontendDirectory())) {
if (isHillaUsed(frontendDirectory())) {
/*
* Override this to not clean generated frontend files after the
* build. For Hilla, the generated files can still be useful for
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public class ConvertPolymerMojo extends FlowModeAbstractMojo {

@Override
public void execute() throws MojoFailureException {
if (isHillaUsed(project, frontendDirectory())) {
if (isHillaUsed(frontendDirectory())) {
getLog().warn(
"""
The 'convert-polymer' goal is not meant to be used in Hilla projects as polymer templates are not supported.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,18 +270,42 @@ public static List<String> getClasspathElements(MavenProject project) {
}
}

/**
* Checks if Hilla is available based on the Maven project's classpath.
*
* @return true if Hilla is available, false otherwise
*/
public boolean isHillaAvailable() {
return getClassFinder().getResource(
"com/vaadin/hilla/EndpointController.class") != null;
}

/**
* Checks if Hilla is available based on the Maven project's classpath.
*
* @param mavenProject
* Target Maven project
* @return true if Hilla is available, false otherwise
*/
public boolean isHillaAvailable(MavenProject mavenProject) {
return getOrCreateClassFinder(mavenProject).getResource(
public static boolean isHillaAvailable(MavenProject mavenProject) {
return createClassFinder(mavenProject).getResource(
"com/vaadin/hilla/EndpointController.class") != null;
}

/**
* Checks if Hilla is available and Hilla views are used in the Maven
* project based on what is in routes.ts or routes.tsx file.
*
* @param frontendDirectory
* Target frontend directory.
* @return {@code true} if Hilla is available and Hilla views are used,
* {@code false} otherwise
*/
public boolean isHillaUsed(File frontendDirectory) {
return isHillaAvailable()
&& FrontendUtils.isHillaViewsUsed(frontendDirectory);
}

/**
* Checks if Hilla is available and Hilla views are used in the Maven
* project based on what is in routes.ts or routes.tsx file.
Expand All @@ -293,7 +317,7 @@ public boolean isHillaAvailable(MavenProject mavenProject) {
* @return {@code true} if Hilla is available and Hilla views are used,
* {@code false} otherwise
*/
public boolean isHillaUsed(MavenProject mavenProject,
public static boolean isHillaUsed(MavenProject mavenProject,
File frontendDirectory) {
return isHillaAvailable(mavenProject)
&& FrontendUtils.isHillaViewsUsed(frontendDirectory);
Expand Down Expand Up @@ -326,17 +350,17 @@ public File generatedTsFolder() {

@Override
public ClassFinder getClassFinder() {
return getOrCreateClassFinder(project);
}

private ClassFinder getOrCreateClassFinder(MavenProject project) {
if (classFinder == null) {
List<String> classpathElements = getClasspathElements(project);
classFinder = BuildFrontendUtil.getClassFinder(classpathElements);
classFinder = createClassFinder(project);
}
return classFinder;
}

private static ClassFinder createClassFinder(MavenProject project) {
List<String> classpathElements = getClasspathElements(project);
return BuildFrontendUtil.getClassFinder(classpathElements);
}

@Override
public Set<File> getJarFiles() {

Expand Down Expand Up @@ -515,7 +539,7 @@ public boolean isFrontendHotdeploy() {
return frontendHotdeploy;
}
File frontendDirectory = BuildFrontendUtil.getFrontendDirectory(this);
return isHillaUsed(project, frontendDirectory);
return isHillaUsed(frontendDirectory);
}

@Override
Expand Down

0 comments on commit 2ed1691

Please sign in to comment.