mirror of
https://github.com/spring-projects/spring-boot.git
synced 2026-09-17 12:09:16 +00:00
Generate 'org.eclipse.core.resources.prefs' for UTF-8 encoding
Update `EclipseConventions` to generate a prefs file to force the project to use UTF-8 encoding. Closes gh-48974
This commit is contained in:
@@ -18,6 +18,7 @@ package org.springframework.boot.build;
|
||||
|
||||
import org.gradle.api.Project;
|
||||
import org.gradle.api.plugins.JavaBasePlugin;
|
||||
import org.gradle.api.tasks.TaskProvider;
|
||||
import org.gradle.plugins.ide.api.XmlFileContentMerger;
|
||||
import org.gradle.plugins.ide.eclipse.EclipsePlugin;
|
||||
import org.gradle.plugins.ide.eclipse.model.Classpath;
|
||||
@@ -35,12 +36,27 @@ import org.gradle.plugins.ide.eclipse.model.Library;
|
||||
class EclipseConventions {
|
||||
|
||||
void apply(Project project) {
|
||||
project.getPlugins()
|
||||
.withType(EclipsePlugin.class,
|
||||
(eclipse) -> project.getPlugins().withType(JavaBasePlugin.class, (javaBase) -> {
|
||||
EclipseModel eclipseModel = project.getExtensions().getByType(EclipseModel.class);
|
||||
eclipseModel.classpath(this::configureClasspath);
|
||||
}));
|
||||
project.getPlugins().withType(EclipsePlugin.class, (eclipse) -> configure(project, eclipse));
|
||||
}
|
||||
|
||||
private void configure(Project project, EclipsePlugin eclipse) {
|
||||
TaskProvider<?> synchronizeResourceSettings = registerEclipseSynchronizeResourceSettings(project);
|
||||
project.getPlugins().withType(JavaBasePlugin.class, (javaBase) -> {
|
||||
EclipseModel model = project.getExtensions().getByType(EclipseModel.class);
|
||||
model.synchronizationTasks(synchronizeResourceSettings);
|
||||
model.classpath(this::configureClasspath);
|
||||
});
|
||||
}
|
||||
|
||||
private TaskProvider<?> registerEclipseSynchronizeResourceSettings(Project project) {
|
||||
TaskProvider<EclipseSynchronizeResourceSettings> eclipseSynchronizateResource = project.getTasks()
|
||||
.register("eclipseSynchronizateResourceSettings", EclipseSynchronizeResourceSettings.class);
|
||||
eclipseSynchronizateResource.configure((task) -> {
|
||||
task.setDescription("Synchronizate the Eclipse resource settings file from Buildship.");
|
||||
task.setOutputFile(project.file(".settings/org.eclipse.core.resources.prefs"));
|
||||
task.setInputFile(project.file(".settings/org.eclipse.core.resources.prefs"));
|
||||
});
|
||||
return eclipseSynchronizateResource;
|
||||
}
|
||||
|
||||
private void configureClasspath(EclipseClasspath classpath) {
|
||||
|
||||
+56
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Copyright 2025 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 implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.build;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import org.gradle.api.Task;
|
||||
import org.gradle.api.internal.PropertiesTransformer;
|
||||
import org.gradle.plugins.ide.api.PropertiesGeneratorTask;
|
||||
|
||||
import org.springframework.boot.build.EclipseSynchronizeResourceSettings.Configuration;
|
||||
|
||||
/**
|
||||
* {@link Task} to synchronize Eclipse resource settings.
|
||||
*
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
public abstract class EclipseSynchronizeResourceSettings extends PropertiesGeneratorTask<Configuration> {
|
||||
|
||||
@Override
|
||||
protected Configuration create() {
|
||||
return new Configuration(getTransformer());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void configure(Configuration configuration) {
|
||||
}
|
||||
|
||||
public static class Configuration extends EmptyPropertiesPersistableConfigurationObject {
|
||||
|
||||
Configuration(PropertiesTransformer transformer) {
|
||||
super(transformer);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void store(Properties properties) {
|
||||
properties.put("encoding/<project>", "UTF-8");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
+57
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Copyright 2025 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 implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.build;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.gradle.api.internal.PropertiesTransformer;
|
||||
import org.gradle.internal.UncheckedException;
|
||||
import org.gradle.plugins.ide.internal.generator.PropertiesPersistableConfigurationObject;
|
||||
|
||||
/**
|
||||
* Base class for {@link PropertiesPersistableConfigurationObject} instances start empty
|
||||
* and have no default resource.
|
||||
*
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
abstract class EmptyPropertiesPersistableConfigurationObject extends PropertiesPersistableConfigurationObject {
|
||||
|
||||
EmptyPropertiesPersistableConfigurationObject(PropertiesTransformer transformer) {
|
||||
super(transformer);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getDefaultResourceName() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadDefaults() {
|
||||
try {
|
||||
load(new ByteArrayInputStream(new byte[0]));
|
||||
}
|
||||
catch (Exception ex) {
|
||||
throw UncheckedException.throwAsUncheckedException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void load(Properties properties) {
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user