This is an automated email from the ASF dual-hosted git repository. lukaszlenart pushed a commit to branch feat/WW-5864-struts-maven-plugin-watch in repository https://gitbox.apache.org/repos/asf/struts.git
commit cf10e4632b02d11593be71ffa041647f832f7d74 Author: Lukasz Lenart <[email protected]> AuthorDate: Sat Nov 14 08:38:07 2026 +0100 WW-5864 build(tools): add struts-maven-plugin module skeleton Co-Authored-By: Claude Sonnet 5.5 <[email protected]> --- pom.xml | 1 + tools/pom.xml | 38 ++++++ tools/struts-maven-plugin/pom.xml | 105 +++++++++++++++++ .../maven/watch/ResourcesPluginSettings.java | 130 +++++++++++++++++++++ .../maven/watch/ResourcesPluginSettingsTest.java | 88 ++++++++++++++ 5 files changed, 362 insertions(+) diff --git a/pom.xml b/pom.xml index d94f5aeb0..19d190ee0 100644 --- a/pom.xml +++ b/pom.xml @@ -88,6 +88,7 @@ <module>core</module> <module>plugins</module> <module>boot</module> + <module>tools</module> <module>apps</module> </modules> diff --git a/tools/pom.xml b/tools/pom.xml new file mode 100644 index 000000000..2f52cfe49 --- /dev/null +++ b/tools/pom.xml @@ -0,0 +1,38 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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. + */ +--> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.apache.struts</groupId> + <artifactId>struts2-parent</artifactId> + <version>7.5.0-SNAPSHOT</version> + <relativePath>../parent/pom.xml</relativePath> + </parent> + + <artifactId>struts2-tools</artifactId> + <packaging>pom</packaging> + <name>Struts 2 Tools</name> + + <modules> + <module>struts-maven-plugin</module> + </modules> +</project> diff --git a/tools/struts-maven-plugin/pom.xml b/tools/struts-maven-plugin/pom.xml new file mode 100644 index 000000000..44809796e --- /dev/null +++ b/tools/struts-maven-plugin/pom.xml @@ -0,0 +1,105 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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. + */ +--> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.apache.struts</groupId> + <artifactId>struts2-tools</artifactId> + <version>7.5.0-SNAPSHOT</version> + <relativePath>../pom.xml</relativePath> + </parent> + + <artifactId>struts-maven-plugin</artifactId> + <packaging>maven-plugin</packaging> + <name>Struts 2 Maven Plugin</name> + + <properties> + <maven.api.version>3.9.16</maven.api.version> + <maven.plugin.tools.version>3.16.0</maven.plugin.tools.version> + </properties> + + <build> + <plugins> + <plugin> + <artifactId>maven-jar-plugin</artifactId> + <configuration> + <archive combine.self="override"/> + </configuration> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-plugin-plugin</artifactId> + <version>${maven.plugin.tools.version}</version> + <configuration> + <goalPrefix>struts</goalPrefix> + </configuration> + <executions> + <execution> + <id>help-mojo</id> + <goals> + <goal>helpmojo</goal> + </goals> + <configuration> + <helpPackageName>org.apache.struts2.maven.watch</helpPackageName> + </configuration> + </execution> + </executions> + </plugin> + </plugins> + </build> + + <dependencies> + <dependency> + <groupId>org.apache.maven</groupId> + <artifactId>maven-plugin-api</artifactId> + <version>${maven.api.version}</version> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>org.apache.maven</groupId> + <artifactId>maven-core</artifactId> + <version>${maven.api.version}</version> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>org.apache.maven.plugin-tools</groupId> + <artifactId>maven-plugin-annotations</artifactId> + <version>${maven.plugin.tools.version}</version> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>org.apache.maven.shared</groupId> + <artifactId>maven-filtering</artifactId> + <version>3.5.1</version> + </dependency> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.assertj</groupId> + <artifactId>assertj-core</artifactId> + <scope>test</scope> + </dependency> + </dependencies> +</project> diff --git a/tools/struts-maven-plugin/src/main/java/org/apache/struts2/maven/watch/ResourcesPluginSettings.java b/tools/struts-maven-plugin/src/main/java/org/apache/struts2/maven/watch/ResourcesPluginSettings.java new file mode 100644 index 000000000..8640f5c77 --- /dev/null +++ b/tools/struts-maven-plugin/src/main/java/org/apache/struts2/maven/watch/ResourcesPluginSettings.java @@ -0,0 +1,130 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 org.apache.struts2.maven.watch; + +import org.apache.maven.model.Plugin; +import org.apache.maven.model.PluginExecution; +import org.apache.maven.project.MavenProject; +import org.codehaus.plexus.util.xml.Xpp3Dom; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.LinkedHashSet; +import java.util.List; + +public final class ResourcesPluginSettings { + + private static final String RESOURCES_PLUGIN_KEY = "org.apache.maven.plugins:maven-resources-plugin"; + private static final String RESOURCES_EXECUTION_ID = "default-resources"; + + private final String encoding; + private final String propertiesEncoding; + private final LinkedHashSet<String> delimiters; + private final boolean useDefaultDelimiters; + private final String escapeString; + private final List<String> nonFilteredFileExtensions; + private final boolean addDefaultExcludes; + + private ResourcesPluginSettings(String encoding, String propertiesEncoding, LinkedHashSet<String> delimiters, + boolean useDefaultDelimiters, String escapeString, + List<String> nonFilteredFileExtensions, boolean addDefaultExcludes) { + this.encoding = encoding; + this.propertiesEncoding = propertiesEncoding; + this.delimiters = delimiters; + this.useDefaultDelimiters = useDefaultDelimiters; + this.escapeString = escapeString; + this.nonFilteredFileExtensions = Collections.unmodifiableList(nonFilteredFileExtensions); + this.addDefaultExcludes = addDefaultExcludes; + } + + public static ResourcesPluginSettings from(Xpp3Dom configuration, String projectEncoding) { + return new ResourcesPluginSettings( + text(configuration, "encoding", projectEncoding), + text(configuration, "propertiesEncoding", null), + new LinkedHashSet<>(texts(configuration, "delimiters")), + flag(configuration, "useDefaultDelimiters"), + text(configuration, "escapeString", null), + texts(configuration, "nonFilteredFileExtensions"), + flag(configuration, "addDefaultExcludes")); + } + + public static Xpp3Dom effectiveResourcesConfiguration(MavenProject project) { + Plugin plugin = project.getBuild().getPluginsAsMap().get(RESOURCES_PLUGIN_KEY); + if (plugin == null) { + return null; + } + Xpp3Dom pluginConfiguration = (Xpp3Dom) plugin.getConfiguration(); + PluginExecution execution = plugin.getExecutionsAsMap().get(RESOURCES_EXECUTION_ID); + Xpp3Dom executionConfiguration = execution == null ? null : (Xpp3Dom) execution.getConfiguration(); + if (executionConfiguration == null) { + return pluginConfiguration; + } + return Xpp3Dom.mergeXpp3Dom(new Xpp3Dom(executionConfiguration), pluginConfiguration); + } + + private static String text(Xpp3Dom configuration, String name, String fallback) { + Xpp3Dom child = configuration == null ? null : configuration.getChild(name); + return child == null || child.getValue() == null ? fallback : child.getValue(); + } + + private static boolean flag(Xpp3Dom configuration, String name) { + return Boolean.parseBoolean(text(configuration, name, "true")); + } + + private static List<String> texts(Xpp3Dom configuration, String name) { + List<String> values = new ArrayList<>(); + Xpp3Dom parent = configuration == null ? null : configuration.getChild(name); + if (parent != null) { + for (Xpp3Dom child : parent.getChildren()) { + if (child.getValue() != null) { + values.add(child.getValue()); + } + } + } + return values; + } + + public String getEncoding() { + return encoding; + } + + public String getPropertiesEncoding() { + return propertiesEncoding; + } + + public LinkedHashSet<String> getDelimiters() { + return new LinkedHashSet<>(delimiters); + } + + public boolean isUseDefaultDelimiters() { + return useDefaultDelimiters; + } + + public String getEscapeString() { + return escapeString; + } + + public List<String> getNonFilteredFileExtensions() { + return nonFilteredFileExtensions; + } + + public boolean isAddDefaultExcludes() { + return addDefaultExcludes; + } +} diff --git a/tools/struts-maven-plugin/src/test/java/org/apache/struts2/maven/watch/ResourcesPluginSettingsTest.java b/tools/struts-maven-plugin/src/test/java/org/apache/struts2/maven/watch/ResourcesPluginSettingsTest.java new file mode 100644 index 000000000..a7e05ed66 --- /dev/null +++ b/tools/struts-maven-plugin/src/test/java/org/apache/struts2/maven/watch/ResourcesPluginSettingsTest.java @@ -0,0 +1,88 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 org.apache.struts2.maven.watch; + +import org.apache.maven.model.Plugin; +import org.apache.maven.model.PluginExecution; +import org.apache.maven.project.MavenProject; +import org.codehaus.plexus.util.xml.Xpp3Dom; +import org.codehaus.plexus.util.xml.Xpp3DomBuilder; +import org.junit.Test; + +import java.io.StringReader; +import java.util.List; + +import static org.assertj.core.api.Assertions.assertThat; + +public class ResourcesPluginSettingsTest { + + @Test + public void defaultsWhenNoConfiguration() { + ResourcesPluginSettings settings = ResourcesPluginSettings.from(null, "UTF-8"); + + assertThat(settings.getEncoding()).isEqualTo("UTF-8"); + assertThat(settings.getDelimiters()).isEmpty(); + assertThat(settings.isUseDefaultDelimiters()).isTrue(); + assertThat(settings.isAddDefaultExcludes()).isTrue(); + assertThat(settings.getNonFilteredFileExtensions()).isEmpty(); + assertThat(settings.getEscapeString()).isNull(); + } + + @Test + public void readsAllFilteringSettings() throws Exception { + Xpp3Dom configuration = Xpp3DomBuilder.build(new StringReader( + "<configuration><encoding>ISO-8859-1</encoding>" + + "<propertiesEncoding>UTF-8</propertiesEncoding>" + + "<delimiters><delimiter>@</delimiter></delimiters>" + + "<useDefaultDelimiters>false</useDefaultDelimiters>" + + "<escapeString>\\</escapeString>" + + "<nonFilteredFileExtensions><nonFilteredFileExtension>png</nonFilteredFileExtension></nonFilteredFileExtensions>" + + "<addDefaultExcludes>false</addDefaultExcludes></configuration>")); + + ResourcesPluginSettings settings = ResourcesPluginSettings.from(configuration, "UTF-8"); + + assertThat(settings.getEncoding()).isEqualTo("ISO-8859-1"); + assertThat(settings.getPropertiesEncoding()).isEqualTo("UTF-8"); + assertThat(settings.getDelimiters()).containsExactly("@"); + assertThat(settings.isUseDefaultDelimiters()).isFalse(); + assertThat(settings.getEscapeString()).isEqualTo("\\"); + assertThat(settings.getNonFilteredFileExtensions()).isEqualTo(List.of("png")); + assertThat(settings.isAddDefaultExcludes()).isFalse(); + } + + @Test + public void executionConfigurationOverridesPluginConfiguration() throws Exception { + Plugin plugin = new Plugin(); + plugin.setGroupId("org.apache.maven.plugins"); + plugin.setArtifactId("maven-resources-plugin"); + plugin.setConfiguration(Xpp3DomBuilder.build(new StringReader( + "<configuration><encoding>A</encoding></configuration>"))); + PluginExecution execution = new PluginExecution(); + execution.setId("default-resources"); + execution.setConfiguration(Xpp3DomBuilder.build(new StringReader( + "<configuration><encoding>B</encoding></configuration>"))); + plugin.addExecution(execution); + MavenProject project = new MavenProject(); + project.getBuild().addPlugin(plugin); + + Xpp3Dom effective = ResourcesPluginSettings.effectiveResourcesConfiguration(project); + + assertThat(effective.getChild("encoding").getValue()).isEqualTo("B"); + } +}
