diff --git a/flow-plugins/flow-maven-plugin/src/it/vaadin-skip-test/invoker.properties b/flow-plugins/flow-maven-plugin/src/it/vaadin-skip-test/invoker.properties new file mode 100644 index 00000000000..3fdd07db953 --- /dev/null +++ b/flow-plugins/flow-maven-plugin/src/it/vaadin-skip-test/invoker.properties @@ -0,0 +1,18 @@ +# +# Copyright 2000-2025 Vaadin Ltd. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may not +# use this file except in compliance with the License. You may obtain a copy of +# the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations under +# the License. +# + +invoker.goals=clean flow:prepare-frontend +invoker.buildResult=success diff --git a/flow-plugins/flow-maven-plugin/src/it/vaadin-skip-test/pom.xml b/flow-plugins/flow-maven-plugin/src/it/vaadin-skip-test/pom.xml new file mode 100644 index 00000000000..68a040577fc --- /dev/null +++ b/flow-plugins/flow-maven-plugin/src/it/vaadin-skip-test/pom.xml @@ -0,0 +1,54 @@ + + + 4.0.0 + + com.vaadin.test.maven + vaadin-skip-test + 1.0 + jar + + + Tests the vaadin.skip parameter functionality. + + + + UTF-8 + 21 + ${maven.compiler.release} + ${maven.compiler.release} + true + @project.version@ + + + + + com.vaadin + flow-server + ${flow.version} + + + com.vaadin + flow-client + ${flow.version} + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.13.0 + + + com.vaadin + flow-maven-plugin + ${flow.version} + + true + + + + + diff --git a/flow-plugins/flow-maven-plugin/src/it/vaadin-skip-test/src/main/java/com/vaadin/test/SkipTestView.java b/flow-plugins/flow-maven-plugin/src/it/vaadin-skip-test/src/main/java/com/vaadin/test/SkipTestView.java new file mode 100644 index 00000000000..7fb10fd9eef --- /dev/null +++ b/flow-plugins/flow-maven-plugin/src/it/vaadin-skip-test/src/main/java/com/vaadin/test/SkipTestView.java @@ -0,0 +1,9 @@ +package com.vaadin.test; + +import com.vaadin.flow.component.Component; +import com.vaadin.flow.router.Route; + +@Route +public class SkipTestView extends Component { + +} diff --git a/flow-plugins/flow-maven-plugin/src/it/vaadin-skip-test/verify.bsh b/flow-plugins/flow-maven-plugin/src/it/vaadin-skip-test/verify.bsh new file mode 100644 index 00000000000..3ca21e0deeb --- /dev/null +++ b/flow-plugins/flow-maven-plugin/src/it/vaadin-skip-test/verify.bsh @@ -0,0 +1,13 @@ +import java.nio.file.*; + +flowTsx = basedir.toPath().resolve("build.log"); +if ( !Files.exists(flowTsx, new LinkOption[0]) ) +{ + throw new RuntimeException("build.log not found"); +} + +lines = Files.readString(flowTsx); +if ( !lines.contains("Skipping Vaadin build") ) +{ + throw new RuntimeException("Vaadin build not skipped"); +} diff --git a/flow-plugins/flow-maven-plugin/src/main/java/com/vaadin/flow/plugin/maven/FlowModeAbstractMojo.java b/flow-plugins/flow-maven-plugin/src/main/java/com/vaadin/flow/plugin/maven/FlowModeAbstractMojo.java index 5988b490213..8b0d0e8f44e 100644 --- a/flow-plugins/flow-maven-plugin/src/main/java/com/vaadin/flow/plugin/maven/FlowModeAbstractMojo.java +++ b/flow-plugins/flow-maven-plugin/src/main/java/com/vaadin/flow/plugin/maven/FlowModeAbstractMojo.java @@ -313,6 +313,12 @@ public abstract class FlowModeAbstractMojo extends AbstractMojo + InitParameters.COMMERCIAL_WITH_BANNER, defaultValue = "false") private boolean commercialWithBanner; + /** + * Skip the execution of this plugin. + */ + @Parameter(property = "vaadin.skip", defaultValue = "false") + private boolean skip; + static final String CLASSFINDER_FIELD_NAME = "classFinder"; private ClassFinder classFinder; @@ -325,6 +331,11 @@ void setBuildContext(BuildContext buildContext) { @Override public void execute() throws MojoExecutionException, MojoFailureException { + if (skip) { + getLog().info("Skipping Vaadin build"); + return; + } + PluginDescriptor pluginDescriptor = mojoExecution.getMojoDescriptor() .getPluginDescriptor(); checkFlowCompatibility(pluginDescriptor); diff --git a/flow-plugins/flow-maven-plugin/src/test/java/com/vaadin/flow/plugin/maven/SkipExecutionTest.java b/flow-plugins/flow-maven-plugin/src/test/java/com/vaadin/flow/plugin/maven/SkipExecutionTest.java new file mode 100644 index 00000000000..c42513ae3d0 --- /dev/null +++ b/flow-plugins/flow-maven-plugin/src/test/java/com/vaadin/flow/plugin/maven/SkipExecutionTest.java @@ -0,0 +1,87 @@ +/* + * Copyright 2000-2025 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.flow.plugin.maven; + +import java.io.File; + +import org.apache.maven.plugin.logging.Log; +import org.codehaus.plexus.util.ReflectionUtils; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.TemporaryFolder; +import org.mockito.Mockito; + +import static com.vaadin.flow.plugin.maven.BuildFrontendMojoTest.setProject; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.verify; + +public class SkipExecutionTest { + + @Rule + public TemporaryFolder temporaryFolder = new TemporaryFolder(); + + private PrepareFrontendMojo mojo; + private Log mockLog; + private File projectBase; + + @Before + public void setup() throws Exception { + mojo = new PrepareFrontendMojo(); + mockLog = Mockito.mock(Log.class); + projectBase = temporaryFolder.getRoot(); + + // Set up the mojo with basic configuration + ReflectionUtils.setVariableValueInObject(mojo, "projectBasedir", + projectBase); + ReflectionUtils.setVariableValueInObject(mojo, "frontendDirectory", + new File(projectBase, "src/main/frontend")); + + setProject(mojo, projectBase); + + // Use reflection to set the mock logger + ReflectionUtils.setVariableValueInObject(mojo, "log", mockLog); + } + + @Test + public void testSkipExecutionWhenVaadinSkipIsTrue() throws Exception { + // Set the skip parameter to true + ReflectionUtils.setVariableValueInObject(mojo, "skip", true); + + // Execute the mojo + mojo.execute(); + + // Verify that the skip message was logged + verify(mockLog).info("Skipping Vaadin build"); + } + + @Test + public void testNormalExecutionWhenVaadinSkipIsFalse() throws Exception { + // Set the skip parameter to false (default) + ReflectionUtils.setVariableValueInObject(mojo, "skip", false); + + try { + // Execute the mojo - this might fail due to missing dependencies in + // test env + mojo.execute(); + } catch (Exception e) { + // Expected - we're just testing that skip message is not logged + } + + // Verify that the skip message was NOT logged + verify(mockLog, never()).info("Skipping Vaadin build"); + } +}