Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow Eclipse to reimport files overtop previous imported files #242 #243

Merged
merged 1 commit into from
Jun 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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