Skip to content

Commit

Permalink
Replace rather than delete existing .settings
Browse files Browse the repository at this point in the history
Update Eclipse Plugin so that a Gradle refresh will replace contents,
rather than attempting to delete the file and recreate it.

Closes gh-119
  • Loading branch information
philwebb committed Jun 26, 2019
1 parent a7212ca commit b93af6e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package io.spring.javaformat.eclipse.projectsettings;

import java.io.InputStream;
import java.util.Collections;

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

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,6 @@
<extension
point="org.eclipse.m2e.core.lifecycleMappingMetadataSource">
</extension>
<extension
point="org.eclipse.ui.startup">
<startup
class="io.spring.javaformat.eclipse.Startup">
</startup>
</extension>
<extension
point="net.sf.eclipsecs.core.checkstyleAddonProvider">
</extension>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;

Expand Down Expand Up @@ -65,16 +66,14 @@ public Iterator<ProjectSettingsFile> iterator() {
public void applyToProject(IProject project, IProgressMonitor monitor) throws IOException, CoreException {
for (ProjectSettingsFile file : this) {
IFile destination = project.getFile(".settings/" + file.getName());
if (destination.exists()) {
try {
destination.delete(true, monitor);
try (InputStream content = this.projectProperties.getModifiedContent(file)) {
if (!destination.exists()) {
destination.create(new BufferedInputStream(content), true, monitor);
}
catch (CoreException ex) {
else {
destination.setContents(new BufferedInputStream(content), IResource.FORCE, monitor);
}
}
try (InputStream content = this.projectProperties.getModifiedContent(file)) {
destination.create(new BufferedInputStream(content), true, monitor);
}
}
}

Expand Down

0 comments on commit b93af6e

Please sign in to comment.