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 duplicate folder names in SmartImport wizard #1294 #1297

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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 @@ -22,6 +22,7 @@
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.SortedMap;
import java.util.SortedSet;
Expand Down Expand Up @@ -570,20 +571,27 @@ private IProject projectAlreadyExistsInWorkspace(File directory) {
return null;
}

private IProject createOrImportProject(File directory, IProgressMonitor progressMonitor) throws Exception {
IProjectDescription desc = null;
static Optional<IProjectDescription> getOptionalProjectDescription(File directory) throws CoreException {
File expectedProjectDescriptionFile = new File(directory, IProjectDescription.DESCRIPTION_FILE_NAME);
if (expectedProjectDescriptionFile.exists()) {
desc = ResourcesPlugin.getWorkspace().loadProjectDescription(IPath.fromOSString(expectedProjectDescriptionFile.getAbsolutePath()));
String expectedName = desc.getName();
IProject projectWithSameName = this.workspaceRoot.getProject(expectedName);
return Optional.ofNullable(ResourcesPlugin.getWorkspace()
.loadProjectDescription(IPath.fromOSString(expectedProjectDescriptionFile.getAbsolutePath())));
}
return Optional.empty();
}

private IProject createOrImportProject(File directory, IProgressMonitor progressMonitor) throws Exception {
IProjectDescription desc = getOptionalProjectDescription(directory).orElse(null);
if (desc != null) {
IProject projectWithSameName = this.workspaceRoot.getProject(desc.getName());
if (projectWithSameName.exists()) {
if (directory.equals(SmartImportWizard.toFile(projectWithSameName))) {
// project seems already there
return projectWithSameName;
}
throw new CouldNotImportProjectException(directory,
NLS.bind(DataTransferMessages.SmartImportProposals_anotherProjectWithSameNameExists_description, expectedName));
NLS.bind(DataTransferMessages.SmartImportProposals_anotherProjectWithSameNameExists_description,
desc.getName()));
}
} else {
String projectName = generateNewProjectName(directory, this.workspaceRoot);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@
import java.util.function.Supplier;

import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IProjectDescription;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.Assert;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
Expand Down Expand Up @@ -712,8 +714,14 @@ protected boolean isExistingProject(File element) {
}

protected boolean isExistingProjectName(File element) {
String name = element.getName();
return !name.isEmpty() && ResourcesPlugin.getWorkspace().getRoot().getProject(name).exists();
try {
String name = SmartImportJob.getOptionalProjectDescription(element).map(IProjectDescription::getName)
.orElse(""); //$NON-NLS-1$
return !name.isEmpty() && ResourcesPlugin.getWorkspace().getRoot().getProject(name).exists();
} catch (CoreException e) {
StatusManager.getManager().handle(e.getStatus(), StatusManager.LOG | StatusManager.SHOW);
return false;
}
}

protected void validatePage() {
Expand Down
Loading