1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-22 22:22:11 +02:00

Bug 437065 - Import executable wizard will not warn user that there's

already such file in existing project

Change-Id: Id75e97943f6f5a82bd1e731fd4e64a89eeb54fbf
Signed-off-by: Iulia Vasii <IuliaMadalina.Vasii@freescale.com>
Reviewed-on: https://git.eclipse.org/r/28344
Tested-by: Hudson CI
Reviewed-by: Teodor Madan <teodor.madan@freescale.com>
Tested-by: Teodor Madan <teodor.madan@freescale.com>
This commit is contained in:
Iulia Vasii 2014-06-20 19:23:29 +03:00 committed by Teodor Madan
parent f81b783269
commit 13c929ccdf
6 changed files with 56 additions and 9 deletions

View file

@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-SymbolicName: org.eclipse.cdt.debug.ui; singleton:=true
Bundle-Version: 7.4.0.qualifier
Bundle-Version: 7.5.0.qualifier
Bundle-Activator: org.eclipse.cdt.debug.ui.CDebugUIPlugin
Bundle-Vendor: %providerName
Bundle-Localization: plugin

View file

@ -11,7 +11,7 @@
<relativePath>../../pom.xml</relativePath>
</parent>
<version>7.4.0-SNAPSHOT</version>
<version>7.5.0-SNAPSHOT</version>
<artifactId>org.eclipse.cdt.debug.ui</artifactId>
<packaging>eclipse-plugin</packaging>
</project>

View file

@ -70,6 +70,8 @@ public abstract class AbstractImportExecutableWizard extends Wizard implements I
/**
* Adds the executables to a new or existing project. The executables are
* added as external links.
* If an executable of the same name already exists then the existing linked
* resource's location is replaced by the local location's value.
*
* @param project -
* project receiving the executables
@ -83,13 +85,10 @@ public abstract class AbstractImportExecutableWizard extends Wizard implements I
IPath location = Path.fromOSString(executables[i]);
String executableName = location.toFile().getName();
IFile exeFile = project.getProject().getFile(executableName);
if (!exeFile.exists())
{
try {
exeFile.createLink(location, 0, null);
} catch (Exception e) {
this.getImportExecutablePage2().setErrorMessage("Error importing: " + executables[i]);
}
try {
exeFile.createLink(location, IResource.REPLACE, null);
} catch (Exception e) {
this.getImportExecutablePage2().setErrorMessage("Error importing: " + executables[i]);
}
}
}

View file

@ -11,24 +11,31 @@
package org.eclipse.cdt.debug.ui.importexecutable;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.ICDescriptor;
import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.parser.util.StringUtil;
import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants;
import org.eclipse.cdt.debug.internal.ui.ICDebugHelpContextIds;
import org.eclipse.cdt.debug.ui.CDebugUIPlugin;
import org.eclipse.cdt.ui.CElementLabelProvider;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.debug.core.ILaunchConfigurationType;
import org.eclipse.debug.core.ILaunchManager;
import org.eclipse.jface.dialogs.IMessageProvider;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.window.Window;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.osgi.util.NLS;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
@ -400,6 +407,7 @@ public class ImportExecutablePageTwo extends WizardPage {
@Override
public boolean isPageComplete() {
setErrorMessage(null);
setWarningMessage(null);
if (isCreateNewProjectSelected()) {
if (getNewProjectName().length() == 0) {
@ -421,6 +429,20 @@ public class ImportExecutablePageTwo extends WizardPage {
setErrorMessage(Messages.ImportExecutablePageTwo_BadProjectName);
return false;
}
// check if executables with same names already exist in the existing project
String[] executables = wizard.getImportExecutablePage().getSelectedExecutables();
List<String> existingNames = new ArrayList<String>();
for (String executable : executables) {
IFile exeFile = getExecutableFile(project.getProject(), executable);
if (exeFile.exists()) {
existingNames.add(exeFile.getName());
}
}
if (!existingNames.isEmpty()) {
setWarningMessage(NLS.bind(Messages.ImportExecutablePageTwo_ExecutableAlreadyExists,
StringUtil.join(existingNames, ", "))); //$NON-NLS-1$
}
}
if (isCreateLaunchConfigurationSelected() && getNewConfigurationName().length() == 0) {
@ -430,6 +452,26 @@ public class ImportExecutablePageTwo extends WizardPage {
}
return super.isPageComplete();
}
/**
* Returns the executable resource having the specified path within the project.
* @param project - the project of the executable file
* @param executable - the string path of the executable
* @return the executable file
*/
private IFile getExecutableFile(IProject project, String executable) {
IPath location = Path.fromOSString(executable);
String name = location.toFile().getName();
return project.getFile(name);
}
/**
* Sets or clears the warning message for this page.
* @param message - the message, or <code>null</code> to clear the message
*/
private void setWarningMessage(String message) {
setMessage(message, IMessageProvider.WARNING);
}
}

View file

@ -48,6 +48,10 @@ public class Messages extends NLS {
public static String ImportExecutablePageTwo_CreateLaunch;
public static String ImportExecutablePageTwo_Name;
public static String ImportExecutablePageTwo_DefaultProjectPrefix;
/**
* @since 7.5
*/
public static String ImportExecutablePageTwo_ExecutableAlreadyExists;
private Messages() {
}

View file

@ -18,6 +18,8 @@ ImportExecutablePageTwo_EnterProjectName=Enter a project name.
ImportExecutablePageOne_ProcessingResults=Processing results
ImportExecutablePageTwo_EnterLaunchConfig=Enter a launch configuration name.
ImportExecutablePageTwo_ProjectAlreadyExists=That project already exists, enter a new name.
ImportExecutablePageTwo_ExecutableAlreadyExists=Project already contains {0} executable(s). \
If you continue the file(s) will be replaced.
ImportExecutablePageTwo_DefaultProjectPrefix=Debug_
ImportExecutableWizard_executableListLabel=C/C++ Executable Files:
ImportExecutableWizard_fileDialogTitle=Choose an executable file