diff --git a/bundles/com.salesforce.bazel.eclipse.core/src/main/java/com/salesforce/bazel/eclipse/projectimport/flow/CreateRootProjectFlow.java b/bundles/com.salesforce.bazel.eclipse.core/src/main/java/com/salesforce/bazel/eclipse/projectimport/flow/CreateRootProjectFlow.java index a32055a5..c7898107 100644 --- a/bundles/com.salesforce.bazel.eclipse.core/src/main/java/com/salesforce/bazel/eclipse/projectimport/flow/CreateRootProjectFlow.java +++ b/bundles/com.salesforce.bazel.eclipse.core/src/main/java/com/salesforce/bazel/eclipse/projectimport/flow/CreateRootProjectFlow.java @@ -25,13 +25,14 @@ import java.io.ByteArrayInputStream; import java.io.File; +import java.io.InputStream; import java.util.Collections; import java.util.List; import java.util.Objects; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IProject; -import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.SubMonitor; import com.salesforce.bazel.eclipse.BazelPluginActivator; @@ -94,9 +95,17 @@ private static void writeProjectViewFile(File bazelWorkspaceRootDirectory, IProj new ProjectView(bazelWorkspaceRootDirectory, importedBazelPackages, Collections.emptyList()); IFile f = BazelPluginActivator.getResourceHelper().getProjectFile(project, ProjectViewConstants.PROJECT_VIEW_FILE_NAME); - try { - f.create(new ByteArrayInputStream(projectView.getContent().getBytes()), false, null); - } catch (CoreException e) { + String projectViewContent = projectView.getContent(); + IProgressMonitor monitor = null; + boolean forceWrite = true; + try (InputStream bis = new ByteArrayInputStream(projectViewContent.getBytes())) { + if (f.exists()) { + boolean keepHistory = true; + f.setContents(bis, forceWrite, keepHistory, monitor); + } else { + f.create(bis, forceWrite, monitor); + } + } catch (Exception e) { throw new IllegalStateException(e); } } diff --git a/bundles/com.salesforce.bazel.eclipse.core/src/main/java/com/salesforce/bazel/eclipse/projectimport/flow/EclipseFileLinker.java b/bundles/com.salesforce.bazel.eclipse.core/src/main/java/com/salesforce/bazel/eclipse/projectimport/flow/EclipseFileLinker.java index a578300a..9e9c5a01 100644 --- a/bundles/com.salesforce.bazel.eclipse.core/src/main/java/com/salesforce/bazel/eclipse/projectimport/flow/EclipseFileLinker.java +++ b/bundles/com.salesforce.bazel.eclipse.core/src/main/java/com/salesforce/bazel/eclipse/projectimport/flow/EclipseFileLinker.java @@ -56,7 +56,7 @@ boolean link(String packageFSPath, IProject eclipseProject, String fileName) { if (f.exists()) { IFile projectFile = resourceHelper.getProjectFile(eclipseProject, fileName); try { - resourceHelper.createFileLink(projectFile, Path.fromOSString(f.getCanonicalPath()), IResource.NONE, + resourceHelper.createFileLink(projectFile, Path.fromOSString(f.getCanonicalPath()), IResource.REPLACE, null); } catch (Exception anyE) { // TODO throwing this exception just writes a log message, we need a modal error popup for this error diff --git a/bundles/com.salesforce.bazel.eclipse.core/src/main/java/com/salesforce/bazel/eclipse/projectimport/flow/SetupClasspathContainersFlow.java b/bundles/com.salesforce.bazel.eclipse.core/src/main/java/com/salesforce/bazel/eclipse/projectimport/flow/SetupClasspathContainersFlow.java index c14da97a..0b67d4ba 100644 --- a/bundles/com.salesforce.bazel.eclipse.core/src/main/java/com/salesforce/bazel/eclipse/projectimport/flow/SetupClasspathContainersFlow.java +++ b/bundles/com.salesforce.bazel.eclipse.core/src/main/java/com/salesforce/bazel/eclipse/projectimport/flow/SetupClasspathContainersFlow.java @@ -101,7 +101,7 @@ private static void createClasspath(IPath bazelWorkspacePath, String bazelPackag IFolder projectSourceFolder = createFoldersForRelativePackagePath(eclipseProject.getProject(), bazelPackageFSPath, path); try { - resourceHelper.createFolderLink(projectSourceFolder, realSourceDir, IResource.NONE, null); + resourceHelper.createFolderLink(projectSourceFolder, realSourceDir, IResource.REPLACE, null); } catch (Exception anyE) { // this can happen in degenerate cases such as source directory is the root of the project LOG.error("error creating classpath", anyE);