Skip to content

Commit b93af6e

Browse files
committed
Replace rather than delete existing .settings
Update Eclipse Plugin so that a Gradle refresh will replace contents, rather than attempting to delete the file and recreate it. Closes gh-119
1 parent a7212ca commit b93af6e

File tree

3 files changed

+8
-15
lines changed

3 files changed

+8
-15
lines changed

spring-javaformat-eclipse/io.spring.javaformat.eclipse.tests/src/io/spring/javaformat/eclipse/projectsettings/ProjectSettingsFilesTests.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package io.spring.javaformat.eclipse.projectsettings;
1818

19+
import java.io.InputStream;
1920
import java.util.Collections;
2021

2122
import org.eclipse.core.resources.IFile;
@@ -59,8 +60,7 @@ public void applyToProjectCopiesToDotSettings() throws Exception {
5960
given(project.getFile(".settings/foo.prefs")).willReturn(projectFile);
6061
given(projectFile.exists()).willReturn(true);
6162
files.applyToProject(project, monitor);
62-
verify(projectFile).delete(true, monitor);
63-
verify(projectFile).create(any(), eq(true), eq(monitor));
63+
verify(projectFile).setContents((InputStream) any(), eq(1), eq(monitor));
6464
}
6565

6666
}

spring-javaformat-eclipse/io.spring.javaformat.eclipse/plugin.xml

-6
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,6 @@
1919
<extension
2020
point="org.eclipse.m2e.core.lifecycleMappingMetadataSource">
2121
</extension>
22-
<extension
23-
point="org.eclipse.ui.startup">
24-
<startup
25-
class="io.spring.javaformat.eclipse.Startup">
26-
</startup>
27-
</extension>
2822
<extension
2923
point="net.sf.eclipsecs.core.checkstyleAddonProvider">
3024
</extension>

spring-javaformat-eclipse/io.spring.javaformat.eclipse/src/io/spring/javaformat/eclipse/projectsettings/ProjectSettingsFiles.java

+6-7
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
import org.eclipse.core.resources.IFile;
2828
import org.eclipse.core.resources.IProject;
29+
import org.eclipse.core.resources.IResource;
2930
import org.eclipse.core.runtime.CoreException;
3031
import org.eclipse.core.runtime.IProgressMonitor;
3132

@@ -65,16 +66,14 @@ public Iterator<ProjectSettingsFile> iterator() {
6566
public void applyToProject(IProject project, IProgressMonitor monitor) throws IOException, CoreException {
6667
for (ProjectSettingsFile file : this) {
6768
IFile destination = project.getFile(".settings/" + file.getName());
68-
if (destination.exists()) {
69-
try {
70-
destination.delete(true, monitor);
69+
try (InputStream content = this.projectProperties.getModifiedContent(file)) {
70+
if (!destination.exists()) {
71+
destination.create(new BufferedInputStream(content), true, monitor);
7172
}
72-
catch (CoreException ex) {
73+
else {
74+
destination.setContents(new BufferedInputStream(content), IResource.FORCE, monitor);
7375
}
7476
}
75-
try (InputStream content = this.projectProperties.getModifiedContent(file)) {
76-
destination.create(new BufferedInputStream(content), true, monitor);
77-
}
7877
}
7978
}
8079

0 commit comments

Comments
 (0)