Skip to content
This repository has been archived by the owner on Feb 23, 2023. It is now read-only.

Duplicate entries in spring-aot generated resource-config.json #524

Closed
leccelecce opened this issue Feb 25, 2021 · 1 comment · Fixed by #546
Closed

Duplicate entries in spring-aot generated resource-config.json #524

leccelecce opened this issue Feb 25, 2021 · 1 comment · Fixed by #546
Labels
type: bug A general bug
Milestone

Comments

@leccelecce
Copy link
Contributor

This is a relatively minor issue as far as I can tell. My resource-config.json generated by spring-aot contains both wildcarded directories, and the complete listing of the directory contents as well. Presumably only one is necessary.

Near the top:

      {
        "pattern": "^static/.*"
      },
      {
        "pattern": "^templates/.*"
      }

Further down:

      {
        "pattern": "static/favicon.ico"
      },
      {
        "pattern": "static/font/roboto/Roboto-Bold.eot"
      },
      {
        "pattern": "static/font/roboto/Roboto-Bold.ttf"
      },
      {
        "pattern": "templates/admin/admin.html"
      },
      {
        "pattern": "templates/admin/cache.html"
      },
@sdeleuze sdeleuze added this to the 0.9.1 milestone Feb 26, 2021
@sdeleuze sdeleuze added the type: bug A general bug label Feb 26, 2021
@leccelecce
Copy link
Contributor Author

The actual regex values (i.e. ^static/.* and ^templates/.*) come from a @ResourceHint on CommonWebInfos (and there will be other equivalents elsewhere presumably).

The individual entries come from BootstrapCodeGenerator.generate() which seems to simply add everything present in the source resource folders.

		if (!resourceFolders.isEmpty()) {
			logger.debug("Processing resource folders: " + resourceFolders);
			for (Path resourceFolder : resourceFolders) {
				int resourceFolderLen = resourceFolder.toString().length() + 1;
				if (Files.exists(resourceFolder)) {
					Files.walk(resourceFolder).filter(p -> !p.toFile().isDirectory()).forEach(p -> {
						String resourcePattern = p.toString().substring(resourceFolderLen);
						if (!resourcePattern.startsWith("META-INF/native-image")) {
							String platformNormalisedResourcePattern = resourcePattern.replace("\\", "/");
							logger.debug("Resource pattern: " + platformNormalisedResourcePattern);
							// TODO recognize resource bundles?
							// TODO escape the patterns (add leading trailing Q and E sequences...)
							buildContext.describeResources(crd -> crd.add(platformNormalisedResourcePattern));
						}
					});
				}
			}
		}

This is interesting as it's not going to be straightforward to test every resource added through this method against every existing pattern that may or may not be a regex - that feels very CPU intensive. I might put up a PR with a simple regex check for now.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
type: bug A general bug
Development

Successfully merging a pull request may close this issue.

2 participants