Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: testing "Maven plugin improvements" PR #20776

Draft
wants to merge 22 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions flow-plugins/flow-maven-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,6 @@
<version>3.4.2</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.google.gwt</groupId>
<artifactId>gwt-elemental</artifactId>
<exclusions>
<exclusion>
<groupId>com.google.gwt</groupId>
<artifactId>gwt-user</artifactId>
</exclusion>
</exclusions>
</dependency>

<dependency>
<groupId>org.apache.maven.plugin-tools</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// Temporary skipped, because of change in the plugin prevents the expected failure.
return false;
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.net.URISyntaxException;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.concurrent.TimeoutException;
import java.util.function.Consumer;

Expand Down Expand Up @@ -70,35 +71,35 @@ public class BuildFrontendMojo extends FlowModeAbstractMojo
* Whether to generate a bundle from the project frontend sources or not.
*/
@Parameter(defaultValue = "true")
private boolean generateBundle;
protected boolean generateBundle;

/**
* Whether to run <code>npm install</code> after updating dependencies.
*/
@Parameter(defaultValue = "true")
private boolean runNpmInstall;
protected boolean runNpmInstall;

/**
* Whether to generate embeddable web components from WebComponentExporter
* inheritors.
*/
@Parameter(defaultValue = "true")
private boolean generateEmbeddableWebComponents;
protected boolean generateEmbeddableWebComponents;

/**
* Defines the project frontend directory from where resources should be
* copied from for use with the frontend build tool.
*/
@Parameter(defaultValue = "${project.basedir}/"
+ Constants.LOCAL_FRONTEND_RESOURCES_PATH)
private File frontendResourcesDirectory;
protected File frontendResourcesDirectory;

/**
* Whether to use byte code scanner strategy to discover frontend
* components.
*/
@Parameter(defaultValue = "true")
private boolean optimizeBundle;
protected boolean optimizeBundle;

/**
* Setting this to true will run {@code npm ci} instead of
Expand All @@ -111,7 +112,7 @@ public class BuildFrontendMojo extends FlowModeAbstractMojo
* overwritten and production builds are reproducible.
*/
@Parameter(property = InitParameters.CI_BUILD, defaultValue = "false")
private boolean ciBuild;
protected boolean ciBuild;

/**
* Setting this to {@code true} will force a build of the production build
Expand All @@ -121,7 +122,7 @@ public class BuildFrontendMojo extends FlowModeAbstractMojo
* {@link #optimizeBundle} parameter.
*/
@Parameter(property = InitParameters.FORCE_PRODUCTION_BUILD, defaultValue = "false")
private boolean forceProductionBuild;
protected boolean forceProductionBuild;

/**
* Control cleaning of generated frontend files when executing
Expand All @@ -130,13 +131,30 @@ public class BuildFrontendMojo extends FlowModeAbstractMojo
* Mainly this is wanted to be true which it is by default.
*/
@Parameter(property = InitParameters.CLEAN_BUILD_FRONTEND_FILES, defaultValue = "true")
private boolean cleanFrontendFiles;
protected boolean cleanFrontendFiles;

/**
* <b>Only disable this if you have nothing from Vaadin to license!</b>
* <p>
* Otherwise there might be unexpected build problems and you will get into
* legal trouble.
* </p>
*/
@Parameter(defaultValue = "true")
protected boolean performLicenseCheck = true;

/**
* Determines if the runtime dependencies should be checked.
* <p>
* Usually the check is only required after a Vaadin version update.
* </p>
*/
@Parameter(defaultValue = "true")
protected boolean checkRuntimeDependency = true;

@Override
protected void executeInternal()
throws MojoExecutionException, MojoFailureException {
long start = System.nanoTime();

TaskCleanFrontendFiles cleanTask = new TaskCleanFrontendFiles(
npmFolder(), frontendDirectory(), getClassFinder());
try {
Expand All @@ -159,13 +177,14 @@ protected void executeInternal()
exception);
}
}
LicenseChecker.setStrictOffline(true);
boolean licenseRequired = BuildFrontendUtil.validateLicenses(this);

BuildFrontendUtil.updateBuildFile(this, licenseRequired);
if (performLicenseCheck) {
LicenseChecker.setStrictOffline(true);
}
boolean licenseRequired = performLicenseCheck
&& BuildFrontendUtil.validateLicenses(this);

long ms = (System.nanoTime() - start) / 1000000;
getLog().info("Build frontend completed in " + ms + " ms.");
BuildFrontendUtil.updateBuildFile(this, licenseRequired);
}

/**
Expand Down Expand Up @@ -195,31 +214,26 @@ protected boolean cleanFrontendFiles() {

@Override
public File frontendResourcesDirectory() {

return frontendResourcesDirectory;
}

@Override
public boolean generateBundle() {

return generateBundle;
}

@Override
public boolean generateEmbeddableWebComponents() {

return generateEmbeddableWebComponents;
}

@Override
public boolean optimizeBundle() {

return optimizeBundle;
}

@Override
public boolean runNpmInstall() {

return runNpmInstall;
}

Expand All @@ -241,45 +255,48 @@ public boolean compressBundle() {
@Override
public boolean checkRuntimeDependency(String groupId, String artifactId,
Consumer<String> missingDependencyMessage) {
if (!checkRuntimeDependency) {
getLog().info("Ignoring runtime dependency check");
return true;
}

Objects.requireNonNull(groupId, "groupId cannot be null");
Objects.requireNonNull(artifactId, "artifactId cannot be null");
if (missingDependencyMessage == null) {
missingDependencyMessage = text -> {
};
}

List<Artifact> deps = project.getArtifacts().stream()
final List<Artifact> deps = project.getArtifacts().stream()
.filter(artifact -> groupId.equals(artifact.getGroupId())
&& artifactId.equals(artifact.getArtifactId()))
.toList();
if (deps.isEmpty()) {
missingDependencyMessage.accept(String.format(
"""
The dependency %1$s:%2$s has not been found in the project configuration.
Please add the following dependency to your POM file:

<dependency>
<groupId>%1$s</groupId>
<artifactId>%2$s</artifactId>
<scope>runtime</scope>
</dependency>
""",
groupId, artifactId));
Optional.ofNullable(missingDependencyMessage)
.ifPresent(c -> c.accept(String.format(
"""
The dependency %1$s:%2$s has not been found in the project configuration.
Please add the following dependency to your POM file:

<dependency>
<groupId>%1$s</groupId>
<artifactId>%2$s</artifactId>
<scope>runtime</scope>
</dependency>
""",
groupId, artifactId)));
return false;
} else if (deps.stream().noneMatch(artifact -> !artifact.isOptional()
&& artifact.getArtifactHandler().isAddedToClasspath()
&& (Artifact.SCOPE_COMPILE.equals(artifact.getScope())
|| Artifact.SCOPE_PROVIDED.equals(artifact.getScope())
|| Artifact.SCOPE_RUNTIME
.equals(artifact.getScope())))) {
missingDependencyMessage.accept(String.format(
"""
The dependency %1$s:%2$s has been found in the project configuration,
but with a scope that does not guarantee its presence at runtime.
Please check that the dependency has 'compile', 'provided' or 'runtime' scope.
To check the current dependency scope, you can run 'mvn dependency:tree -Dincludes=%1$s:%2$s'
""",
groupId, artifactId));
Optional.ofNullable(missingDependencyMessage)
.ifPresent(c -> c.accept(String.format(
"""
The dependency %1$s:%2$s has been found in the project configuration,
but with a scope that does not guarantee its presence at runtime.
Please check that the dependency has 'compile', 'provided' or 'runtime' scope.
To check the current dependency scope, you can run 'mvn dependency:tree -Dincludes=%1$s:%2$s'
""",
groupId, artifactId)));
return false;
}
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,20 @@ public class ConvertPolymerMojo extends FlowModeAbstractMojo {
* folder.
*/
@Parameter(property = "vaadin.path")
private String path;
protected String path;

/**
* Whether to enforce Lit 1 compatible imports.
*/
@Parameter(property = "vaadin.useLit1", defaultValue = "${false}")
private boolean useLit1;
protected boolean useLit1;

/**
* Whether to disable the usage of the JavaScript optional chaining operator
* (?.) in the output.
*/
@Parameter(property = "vaadin.disableOptionalChaining", defaultValue = "${false}")
private boolean disableOptionalChaining;
protected boolean disableOptionalChaining;

@Override
protected void executeInternal() throws MojoFailureException {
Expand Down
Loading
Loading