Skip to content

Parse src/main/webapp resources for WAR projects#1103

Merged
timtebeek merged 1 commit intomainfrom
jkschneider/parse-webapp-for-war-projects
Jan 26, 2026
Merged

Parse src/main/webapp resources for WAR projects#1103
timtebeek merged 1 commit intomainfrom
jkschneider/parse-webapp-for-war-projects

Conversation

@Jenson3210
Copy link
Contributor

@Jenson3210 Jenson3210 commented Jan 26, 2026

Summary

  • Add parsing of src/main/webapp directory for projects with WAR packaging
  • Files in webapp directory now receive the JavaProject marker from the project's provenance

Problem

When building LSTs for Maven WAR projects, files in src/main/webapp (like web.xml) were not receiving the JavaProject marker. This caused recipes like WebXmlToWebApplicationInitializer to skip these files because they check for JavaProject to determine the target project context.

The root cause: MavenMojoProjectParser only parsed resources from mavenProject.getResources() (standard Maven resource directories like src/main/resources), but src/main/webapp is not a standard Maven resource directory - it's a special directory for WAR packaging.

Solution

After parsing standard Maven resources, check if the project has WAR packaging. If so, also parse src/main/webapp using the same OmniParser. These files then receive the correct JavaProject marker when provenance is applied.

// Also parse webapp resources (e.g., web.xml) for WAR projects
if ("war".equals(mavenProject.getPackaging())) {
    Path webappPath = mavenProject.getBasedir().toPath().resolve("src/main/webapp");
    if (Files.exists(webappPath) && !alreadyParsed.contains(webappPath)) {
        List<Path> accepted = omniParser.acceptedPaths(baseDir, webappPath);
        alreadyParsed.add(webappPath);
        sourceFiles = Stream.concat(sourceFiles, omniParser.parse(accepted, baseDir, ctx));
        alreadyParsed.addAll(accepted);
    }
}

Test plan

  • Existing tests pass

  • Manual testing with WAR project containing web.xml

  • Fixes moderneinc/customer-requests#1760

For WAR-packaged Maven projects, the src/main/webapp directory contains
web application resources like web.xml. These files were not being parsed
by MavenMojoProjectParser, which meant they didn't receive the JavaProject
marker. This caused recipes like WebXmlToWebApplicationInitializer to skip
them because they check for the JavaProject marker to determine the target
project context.

The fix adds webapp directory parsing after standard Maven resources are
processed, but only for projects with packaging="war".

Fixes moderneinc/customer-requests#1760
@timtebeek
Copy link
Member

Nice find! Good to finally understand why were were not seeing these changes.

@timtebeek timtebeek added the bug Something isn't working label Jan 26, 2026
@timtebeek timtebeek merged commit b37d4a4 into main Jan 26, 2026
1 of 3 checks passed
@timtebeek timtebeek deleted the jkschneider/parse-webapp-for-war-projects branch January 26, 2026 23:17
@github-project-automation github-project-automation bot moved this from In Progress to Done in OpenRewrite Jan 26, 2026
mergify bot added a commit to robfrank/linklift that referenced this pull request Feb 14, 2026
… 6.28.0 to 6.29.0 [skip ci]

Bumps [org.openrewrite.maven:rewrite-maven-plugin](https://github.com/openrewrite/rewrite-maven-plugin) from 6.28.0 to 6.29.0.
Release notes

*Sourced from [org.openrewrite.maven:rewrite-maven-plugin's releases](https://github.com/openrewrite/rewrite-maven-plugin/releases).*

> 6.29.0
> ------
>
> What's Changed
> --------------
>
> * Skip unresolved property placeholders when determining charset by [`@​timtebeek`](https://github.com/timtebeek) in [openrewrite/rewrite-maven-plugin#1105](https://redirect.github.com/openrewrite/rewrite-maven-plugin/pull/1105)
> * chore(ci): bump org.apache.maven.plugins:maven-compiler-plugin from 3.14.1 to 3.15.0 by [`@​dependabot`](https://github.com/dependabot)[bot] in [openrewrite/rewrite-maven-plugin#1106](https://redirect.github.com/openrewrite/rewrite-maven-plugin/pull/1106)
>
> **Full Changelog**: <openrewrite/rewrite-maven-plugin@v6.28.1...v6.29.0>
>
> 6.28.1
> ------
>
> What's Changed
> --------------
>
> * chore(ci): bump org.assertj:assertj-bom from 3.27.6 to 3.27.7 by [`@​dependabot`](https://github.com/dependabot)[bot] in [openrewrite/rewrite-maven-plugin#1101](https://redirect.github.com/openrewrite/rewrite-maven-plugin/pull/1101)
> * chore(ci): bump org.codehaus.plexus:plexus-xml from 4.1.0 to 4.1.1 by [`@​dependabot`](https://github.com/dependabot)[bot] in [openrewrite/rewrite-maven-plugin#1102](https://redirect.github.com/openrewrite/rewrite-maven-plugin/pull/1102)
> * Parse src/main/webapp resources for WAR projects by [`@​Jenson3210`](https://github.com/Jenson3210) in [openrewrite/rewrite-maven-plugin#1103](https://redirect.github.com/openrewrite/rewrite-maven-plugin/pull/1103)
>
> New Contributors
> ----------------
>
> * [`@​Jenson3210`](https://github.com/Jenson3210) made their first contribution in [openrewrite/rewrite-maven-plugin#1103](https://redirect.github.com/openrewrite/rewrite-maven-plugin/pull/1103)
>
> **Full Changelog**: <openrewrite/rewrite-maven-plugin@v6.28.0...v6.28.1>


Commits

* [`b4c30ba`](openrewrite/rewrite-maven-plugin@b4c30ba) [maven-release-plugin] prepare release v6.29.0
* [`184e927`](openrewrite/rewrite-maven-plugin@184e927) Bump rewrite.version property
* [`2c01af1`](openrewrite/rewrite-maven-plugin@2c01af1) OpenRewrite recipe best practices
* [`d2ec8a7`](openrewrite/rewrite-maven-plugin@d2ec8a7) Delete files
* [`5abd366`](openrewrite/rewrite-maven-plugin@5abd366) chore(ci): bump org.apache.maven.plugins:maven-compiler-plugin ([#1106](https://redirect.github.com/openrewrite/rewrite-maven-plugin/issues/1106))
* [`9792e32`](openrewrite/rewrite-maven-plugin@9792e32) Skip unresolved property placeholders when determining charset ([#1105](https://redirect.github.com/openrewrite/rewrite-maven-plugin/issues/1105))
* [`27684e2`](openrewrite/rewrite-maven-plugin@27684e2) Bump rewrite.version property
* [`a36a35d`](openrewrite/rewrite-maven-plugin@a36a35d) [maven-release-plugin] prepare for next development iteration
* [`01f3b70`](openrewrite/rewrite-maven-plugin@01f3b70) [maven-release-plugin] prepare release v6.28.1
* [`d1936af`](openrewrite/rewrite-maven-plugin@d1936af) Bump rewrite.version property
* Additional commits viewable in [compare view](openrewrite/rewrite-maven-plugin@v6.28.0...v6.29.0)
  
[![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility\_score?dependency-name=org.openrewrite.maven:rewrite-maven-plugin&package-manager=maven&previous-version=6.28.0&new-version=6.29.0)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)
Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`.
[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)
---
Dependabot commands and options
  
You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it
- `@dependabot show  ignore conditions` will show all of the ignore conditions of the specified dependency
- `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

2 participants