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

Support CDATA section in ConfigurationBuilder #1260

Open
diablowu opened this issue Aug 23, 2021 · 6 comments
Open

Support CDATA section in ConfigurationBuilder #1260

diablowu opened this issue Aug 23, 2021 · 6 comments

Comments

@diablowu
Copy link

We need to use the original content of the XML in the plugin configuration buider, but when I use MavenPlugin.ConfigurationBuilder#add(name, xml), the content of xml will be escaped

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Aug 23, 2021
@wilkinsona
Copy link
Contributor

Thanks for the suggestion, but I am not sure that I understand what you are trying to do from what you have described thus far. Can you please provide an example? Ideally one that shows the code you are using, the output that you expect and the actual output that you currently get.

@wilkinsona wilkinsona added the status: waiting-for-feedback We need additional information before we can continue label Aug 23, 2021
@diablowu
Copy link
Author

For example:

<plugin>
  <groupId>com.diffplug.spotless</groupId>
  <artifactId>spotless-maven-plugin</artifactId>
  <configuration>
    <java>
      <licenseHeader>
        <content></content>
      </licenseHeader>
    </java>
  </configuration>
</plugin>

I want to add the licenseHeader via content . If the content part includes <![CDATA[, then < will be escaped

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Aug 23, 2021
@diablowu
Copy link
Author

And,

build.profiles().id("build").properties().property("maven.build.timestamp.format", "yyyy-MM-dd'T'HH:mm:ss'Z'");

I also want to be able to control the io.spring.initializr.generator.buildsystem.maven.MavenBuildWriter#writeSingleElement to be called without escaping the value part

@wilkinsona
Copy link
Contributor

build.profiles().id("build").properties().property("maven.build.timestamp.format", "yyyy-MM-dd'T'HH:mm:ss'Z'");

How does this relate to inserting CDATA? I'm struggling to see the connection.

@wilkinsona wilkinsona added status: waiting-for-feedback We need additional information before we can continue and removed status: feedback-provided Feedback has been provided labels Aug 24, 2021
@diablowu
Copy link
Author

Sorry, this may be another question. But I think this may be due to the method MavenBuildWriter#writeSingleElement without not determining whether the content needs to be encoded

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Aug 26, 2021
@mhalbritter
Copy link
Contributor

The problem is that something like this doesn't work:

		build.plugins().add("com.diffplug.spotless", "spotless-maven-plugin", (plugin) -> {
			plugin.configuration((configuration) -> {
				configuration.add("java", (java) -> {
					java.add("licenseHeader", (licenseHeader) -> {
						licenseHeader.add("content", """
							<![CDATA[
							Copyright 2012-2023 the original author or authors.
							
							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
							
								 https://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 impl
							See the License for the specific language governing permissions and
							limitations under the License.
							]]>""");
					});
				});
			});
		});

This creates a XML looking like this:

<?xml version="1.0" encoding="UTF-8"?>
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.example.demo</groupId>
    <artifactId>demo</artifactId>
    <version>1.0.1-SNAPSHOT</version>

    <build>
        <plugins>
            <plugin>
                <groupId>com.diffplug.spotless</groupId>
                <artifactId>spotless-maven-plugin</artifactId>
                <configuration>
                    <java>
                        <licenseHeader>
                            <content>&lt;![CDATA[
Copyright 2012-2023 the original author or authors.

Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

	 https://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 &quot;AS IS&quot; BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or impl
See the License for the specific language governing permissions and
limitations under the License.
]]&gt;</content>
                        </licenseHeader>
                    </java>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>

@mhalbritter mhalbritter added type: enhancement and removed status: feedback-provided Feedback has been provided status: waiting-for-triage An issue we've not yet triaged labels Feb 1, 2024
@mhalbritter mhalbritter added this to the General Backlog milestone Feb 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants