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

layers.xsd is out of sync with the documentation and implementation for including and excluding module dependencies #31126

Closed
wants to merge 1 commit into from

Conversation

abel533
Copy link
Contributor

@abel533 abel533 commented May 20, 2022

I found some inconsistencies between maven plugin documentation and code, which one should I use?

The contents of the document are as follows

<layers xmlns="http://www.springframework.org/schema/boot/layers"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://www.springframework.org/schema/boot/layers
                          https://www.springframework.org/schema/boot/layers/layers-2.6.xsd">
    <application>
        <into layer="spring-boot-loader">
            <include>org/springframework/boot/loader/**</include>
        </into>
        <into layer="application" />
    </application>
    <dependencies>
        <into layer="application">
            <includeModuleDependencies />
        </into>
        <into layer="snapshot-dependencies">
            <include>*:*:*SNAPSHOT</include>
        </into>
        <into layer="dependencies" />
    </dependencies>
    <layerOrder>
        <layer>dependencies</layer>
        <layer>spring-boot-loader</layer>
        <layer>snapshot-dependencies</layer>
        <layer>application</layer>
    </layerOrder>
</layers>

It also provides <includeModuleDependencies /> and <excludeModuleDependencies /> elements that can be used to include or exclude local module dependencies.

Code

layers-2.6.xsd

<xsd:complexType name="dependenciesIntoType">
<xsd:complexContent>
	<xsd:extension base="intoType">
		<xsd:choice minOccurs="0">
			<xsd:element type="xsd:string" name="includeProjectDependencies" minOccurs="0">
				<xsd:annotation>
					<xsd:documentation><![CDATA[
Include dependencies on other modules in the build.
					]]></xsd:documentation>
				</xsd:annotation>
			</xsd:element>
			<xsd:element type="xsd:string" name="excludeProjectDependencies" minOccurs="0">
				<xsd:annotation>
					<xsd:documentation><![CDATA[
Exclude dependencies on other modules in the build.
					]]></xsd:documentation>
				</xsd:annotation>
			</xsd:element>
		</xsd:choice>				
	</xsd:extension>
</xsd:complexContent>
</xsd:complexType>

Here is includeProjectDependencies and excludeProjectDependencies.

CustomLayersProvider.java

	private <T> ContentSelector<Library> getLibrarySelector(Element element,
			Function<String, ContentFilter<Library>> filterFactory) {
		Layer layer = new Layer(element.getAttribute("layer"));
		List<String> includes = getChildNodeTextContent(element, "include");
		List<String> excludes = getChildNodeTextContent(element, "exclude");
		Element includeModuleDependencies = getChildElement(element, "includeModuleDependencies");
		Element excludeModuleDependencies = getChildElement(element, "excludeModuleDependencies");
		List<ContentFilter<Library>> includeFilters = includes.stream().map(filterFactory).collect(Collectors.toList());
		if (includeModuleDependencies != null) {
			includeFilters = new ArrayList<>(includeFilters);
			includeFilters.add(Library::isLocal);
		}
		List<ContentFilter<Library>> excludeFilters = excludes.stream().map(filterFactory).collect(Collectors.toList());
		if (excludeModuleDependencies != null) {
			excludeFilters = new ArrayList<>(excludeFilters);
			excludeFilters.add(Library::isLocal);
		}
		return new IncludeExcludeContentSelector<>(layer, includeFilters, excludeFilters);
	}

Here is includeModuleDependencies and excludeModuleDependencies.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label May 20, 2022
@philwebb philwebb self-assigned this May 20, 2022
@philwebb philwebb changed the title Resolve the name error in layers.xsd, fixed #31115 layers.xsd is out of sync with the documentation and implementation for including and excluding module dependencies May 20, 2022
@philwebb philwebb added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged labels May 20, 2022
@philwebb philwebb added this to the 2.6.x milestone May 20, 2022
philwebb pushed a commit that referenced this pull request May 20, 2022
Update `layer-*.xsd` files with following fixes:

- Rename <includeProjectDependencies> to <includeModuleDependencies>
- Rename <excludeProjectDependencies> to <excludeModuleDependencies>

See gh-31126
philwebb added a commit that referenced this pull request May 20, 2022
Validate loaded `layer.xml` files against the XSD and additionally
update `<layers>` sub elements to have a 'minOccurs' of 0.

See gh-31126
@philwebb philwebb closed this in f185b07 May 20, 2022
@philwebb
Copy link
Member

Thanks very much @abel533 for your first Spring Boot contribution. I've applied this fix along with the @wilkinsona's suggestion of validating the XML files when it's loaded.

@philwebb philwebb modified the milestones: 2.6.x, 2.6.9 May 20, 2022
@wilkinsona
Copy link
Member

I wonder if we should validate against the version of the XSD declared in the XML file rather than always using the XSD that matches the version of the Maven plugin?

@wilkinsona wilkinsona added the for: team-meeting An issue we'd like to discuss as a team to make progress label May 20, 2022
@wilkinsona
Copy link
Member

I've just noticed that this was merged into 2.5.x. Was that intentional, @philwebb?

@philwebb
Copy link
Member

philwebb commented May 20, 2022

I've just noticed that this was merged into 2.5.x. Was that intentional, @philwebb?

No! I obviously have too many IDEs open and got confused. I'll move this one and we can use the forward-merge issue (#31127) for 2.6.

@philwebb philwebb modified the milestones: 2.6.9, 2.5.15 May 20, 2022
@philwebb philwebb added for: team-meeting An issue we'd like to discuss as a team to make progress and removed for: team-meeting An issue we'd like to discuss as a team to make progress labels May 20, 2022
@philwebb philwebb removed the for: team-meeting An issue we'd like to discuss as a team to make progress label Jun 1, 2022
@philwebb philwebb reopened this May 11, 2023
philwebb added a commit that referenced this pull request May 12, 2023
Revert layers.xsd fix to reduce risk of a regression since it has not
yet made it into a 2.5 release.

This reverts commit f185b07, reversing
changes made to bf3c6df.

See gh-31126
@philwebb philwebb removed this from the 2.5.15 milestone May 16, 2023
@philwebb philwebb removed the type: bug A general bug label May 16, 2023
@philwebb philwebb added the status: superseded An issue that has been superseded by another label May 16, 2023
@philwebb philwebb closed this May 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: superseded An issue that has been superseded by another
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants