Skip to content

Commit

Permalink
allow Eclipse to reimport files overtop previous imported files #242
Browse files Browse the repository at this point in the history
  • Loading branch information
plaird committed Jun 19, 2021
1 parent 0996ec0 commit 8393f80
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 8393f80

Please sign in to comment.