use of org.eclipse.titan.designer.properties.data.ProjectFileHandler in project titan.EclipsePlug-ins by eclipse.
the class NatureConverter method convertNatureOnProject.
private void convertNatureOnProject(final IProject tempProject) throws CoreException {
final IProjectDescription description = tempProject.getDescription();
if (!TITANNature.hasTITANNature(tempProject)) {
Activator.getDefault().pauseHandlingResourceChanges();
TITANNature.addTITANNatureToProject(description);
tempProject.setDescription(description, IResource.FORCE, null);
tempProject.setPersistentProperty(new QualifiedName(ProjectBuildPropertyData.QUALIFIER, ProjectBuildPropertyData.GENERATE_MAKEFILE_PROPERTY), "true");
tempProject.setPersistentProperty(new QualifiedName(ProjectBuildPropertyData.QUALIFIER, TTCN3PreprocessorOptionsData.TTCN3_PREPROCESSOR_PROPERTY), "cpp");
tempProject.setPersistentProperty(new QualifiedName(ProjectBuildPropertyData.QUALIFIER, CCompilerOptionsData.CXX_COMPILER_PROPERTY), "g++");
tempProject.setPersistentProperty(new QualifiedName(ProjectBuildPropertyData.QUALIFIER, TITANFlagsOptionsData.ADD_SOURCELINEINFO_PROPERTY), "true");
tempProject.setPersistentProperty(new QualifiedName(ProjectBuildPropertyData.QUALIFIER, MakeAttributesData.TEMPORAL_WORKINGDIRECTORY_PROPERTY), "bin");
final ProjectFileHandler pfHandler = new ProjectFileHandler(tempProject);
final WorkspaceJob job = pfHandler.saveProjectSettingsJob();
try {
job.join();
} catch (InterruptedException e) {
ErrorReporter.logExceptionStackTrace("Interrupted", e);
}
try {
tempProject.refreshLocal(IResource.DEPTH_INFINITE, null);
} catch (CoreException e) {
ErrorReporter.logExceptionStackTrace("Error while refreshing resources", e);
}
Activator.getDefault().resumeHandlingResourceChanges();
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
final PreferenceDialog dialog = PreferencesUtil.createPropertyDialogOn(null, tempProject, GeneralConstants.PROJECT_PROPERTY_PAGE, null, null);
if (dialog != null) {
dialog.open();
}
}
});
} else {
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
if (MessageDialog.openConfirm(null, NATURE_REMOVAL_TITLE, NATURE_REMOVAL_MESSAGE + tempProject.getName() + '?')) {
TITANNature.removeTITANNature(description);
try {
tempProject.setDescription(description, IResource.FORCE, null);
} catch (CoreException e) {
ErrorReporter.logExceptionStackTrace(e);
}
}
}
});
}
}
use of org.eclipse.titan.designer.properties.data.ProjectFileHandler in project titan.EclipsePlug-ins by eclipse.
the class TpdImporter method loadConfigurationData.
/**
* Loads the configuration related options onto the project from the
* document being loaded.
*
* @param project
* the project to load onto.
* @param mainNodes
* the mainNodes to check for the configuration related options.
*
* @return true if the import was successful, false otherwise.
*/
private boolean loadConfigurationData(final IProject project, final NodeList mainNodes) {
final Document targetDocument = ProjectDocumentHandlingUtility.getDocument(project);
Node activeConfigurationNode = ProjectFileHandler.getNodebyName(mainNodes, ProjectFormatConstants.ACTIVE_CONFIGURATION_NODE);
String activeConfiguration = ProjectFormatConstants.DEFAULT_CONFIGURATION_NAME;
if (activeConfigurationNode != null) {
activeConfiguration = activeConfigurationNode.getTextContent();
} else {
activeConfiguration = "Default";
}
try {
project.setPersistentProperty(new QualifiedName(ProjectBuildPropertyData.QUALIFIER, ProjectBuildPropertyData.ACTIVECONFIGURATION), activeConfiguration);
} catch (CoreException e) {
ErrorReporter.logExceptionStackTrace("While setting `" + activeConfiguration + "' as configuration for project `" + project.getName() + "'", e);
}
// Remove possible target configuration nodes in existence
removeConfigurationNodes(targetDocument.getDocumentElement());
Node targetActiveConfiguration = targetDocument.createElement(ProjectFormatConstants.ACTIVE_CONFIGURATION_NODE);
targetActiveConfiguration.appendChild(targetDocument.createTextNode(activeConfiguration));
targetDocument.getDocumentElement().appendChild(targetActiveConfiguration);
Node targetConfigurationsRoot = targetDocument.createElement(ProjectFormatConstants.CONFIGURATIONS_NODE);
targetDocument.getDocumentElement().appendChild(targetConfigurationsRoot);
Node configurationsNode = ProjectFileHandler.getNodebyName(mainNodes, ProjectFormatConstants.CONFIGURATIONS_NODE);
if (configurationsNode == null) {
ProjectDocumentHandlingUtility.saveDocument(project);
ProjectBuildPropertyData.setProjectAlreadyExported(project, false);
ProjectFileHandler handler = new ProjectFileHandler(project);
handler.loadProjectSettingsFromDocument(targetDocument);
return true;
}
NodeList configurationsNodeList = configurationsNode.getChildNodes();
for (int i = 0, size = configurationsNodeList.getLength(); i < size; i++) {
Node configurationNode = configurationsNodeList.item(i);
if (configurationNode.getNodeType() != Node.ELEMENT_NODE) {
continue;
}
NamedNodeMap attributeMap = configurationNode.getAttributes();
if (attributeMap == null) {
continue;
}
Node nameNode = attributeMap.getNamedItem(ProjectFormatConstants.CONFIGURATION_NAME_ATTRIBUTE);
if (nameNode == null) {
displayError("Import failed", "Error while importing project " + project.getName() + " the name attribute of a referenced project is missing");
return false;
}
String configurationName = nameNode.getTextContent();
if (ProjectFormatConstants.DEFAULT_CONFIGURATION_NAME.equals(configurationName)) {
copyConfigurationData(targetDocument.getDocumentElement(), configurationNode);
} else {
Element targetConfiguration = targetDocument.createElement(ProjectFormatConstants.CONFIGURATION_NODE);
targetConfiguration.setAttribute(ProjectFormatConstants.CONFIGURATION_NAME_ATTRIBUTE, configurationName);
targetConfigurationsRoot.appendChild(targetConfiguration);
copyConfigurationData(targetConfiguration, configurationNode);
}
}
ProjectDocumentHandlingUtility.saveDocument(project);
ProjectBuildPropertyData.setProjectAlreadyExported(project, false);
ProjectFileHandler handler = new ProjectFileHandler(project);
handler.loadProjectSettingsFromDocument(targetDocument);
return true;
}
use of org.eclipse.titan.designer.properties.data.ProjectFileHandler in project titan.EclipsePlug-ins by eclipse.
the class NewTITANProjectWizard method performFinish.
@Override
public boolean performFinish() {
Activator.getDefault().pauseHandlingResourceChanges();
if (!isCreated) {
createNewProject();
}
if (newProject == null) {
Activator.getDefault().resumeHandlingResourceChanges();
return false;
}
try {
newProject.setPersistentProperty(new QualifiedName(ProjectBuildPropertyData.QUALIFIER, MakeAttributesData.TEMPORAL_WORKINGDIRECTORY_PROPERTY), optionsPage.getWorkingFolder());
final String executable = MakefileCreationData.getDefaultTargetExecutableName(newProject);
newProject.setPersistentProperty(new QualifiedName(ProjectBuildPropertyData.QUALIFIER, MakefileCreationData.TARGET_EXECUTABLE_PROPERTY), executable);
} catch (CoreException ce) {
ErrorReporter.logExceptionStackTrace(ce);
}
ProjectDocumentHandlingUtility.createDocument(newProject);
ProjectFileHandler pfHandler;
pfHandler = new ProjectFileHandler(newProject);
final WorkspaceJob job = pfHandler.saveProjectSettingsJob();
try {
job.join();
} catch (InterruptedException e) {
ErrorReporter.logExceptionStackTrace(e);
}
Activator.getDefault().resumeHandlingResourceChanges();
try {
newProject.refreshLocal(IResource.DEPTH_INFINITE, null);
} catch (CoreException e) {
ErrorReporter.logExceptionStackTrace(e);
}
try {
TITANNature.addTITANBuilderToProject(newProject);
} catch (CoreException e) {
ErrorReporter.logExceptionStackTrace(e);
}
BasicNewProjectResourceWizard.updatePerspective(config);
selectAndReveal(newProject);
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
final PreferenceDialog dialog = PreferencesUtil.createPropertyDialogOn(null, newProject, GeneralConstants.PROJECT_PROPERTY_PAGE, null, null);
if (dialog != null) {
dialog.open();
}
}
});
return true;
}
use of org.eclipse.titan.designer.properties.data.ProjectFileHandler in project titan.EclipsePlug-ins by eclipse.
the class TITANProjectImportWizard method performFinish.
@Override
public boolean performFinish() {
URI targetLocation = null;
if (!newProjectPage.useDefaults()) {
targetLocation = newProjectPage.getLocationURI();
}
final IProject newProject = GUIProjectImporter.createNewProject(newProjectPage.getProjectHandle(), mainPage.getInformation(), targetLocation);
if (newProject == null) {
final IWorkspaceDescription description = ResourcesPlugin.getWorkspace().getDescription();
if (description.isAutoBuilding() != wasAutoBuilding) {
description.setAutoBuilding(wasAutoBuilding);
try {
ResourcesPlugin.getWorkspace().setDescription(description);
} catch (CoreException e) {
ErrorReporter.logExceptionStackTrace(e);
}
}
Activator.getDefault().resumeHandlingResourceChanges();
return true;
}
try {
TITANNature.addTITANBuilderToProject(newProject);
} catch (CoreException e) {
ErrorReporter.logExceptionStackTrace(e);
}
ProjectFileHandler pfHandler;
pfHandler = new ProjectFileHandler(newProject);
pfHandler.saveProjectSettings();
try {
newProject.refreshLocal(IResource.DEPTH_INFINITE, null);
} catch (CoreException e) {
ErrorReporter.logExceptionStackTrace(e);
}
BasicNewProjectResourceWizard.updatePerspective(config);
selectAndReveal(newProject);
final ProjectInformation information = mainPage.getInformation();
List<IncludedProject> includedProjects = information.getIncludedProjects();
if (!includedProjects.isEmpty() && (recursivelyPage == null || recursivelyPage.getRecursiveImport())) {
final IWorkspace workspace = ResourcesPlugin.getWorkspace();
final List<String> processedProjectFiles = new ArrayList<String>();
processedProjectFiles.add(information.getSourceFile());
final List<IPath> projectFilesToBeProcessed = new ArrayList<IPath>();
for (IncludedProject includedProject : includedProjects) {
final IPath temp = includedProject.getAbsolutePath();
if (temp != null) {
projectFilesToBeProcessed.add(temp);
}
}
while (!projectFilesToBeProcessed.isEmpty()) {
IPath tempPath = projectFilesToBeProcessed.remove(projectFilesToBeProcessed.size() - 1);
if (processedProjectFiles.contains(tempPath.toOSString())) {
continue;
}
final GUIProjectImporter importer = new GUIProjectImporter();
final ProjectInformation tempProjectInformation = importer.loadProjectFile(tempPath.toOSString(), null, // false: not headless
false);
final IPath tempPath2 = tempPath.removeFileExtension();
final String includedProjectName = tempPath2.lastSegment();
IProject tempProject = workspace.getRoot().getProject(includedProjectName);
if (tempProject.exists()) {
continue;
}
tempProject = GUIProjectImporter.createNewProject(tempProject, tempProjectInformation, targetLocation);
if (tempProject == null) {
continue;
}
try {
TITANNature.addTITANBuilderToProject(tempProject);
} catch (CoreException e) {
ErrorReporter.logExceptionStackTrace(e);
}
pfHandler = new ProjectFileHandler(tempProject);
pfHandler.saveProjectSettings();
try {
tempProject.refreshLocal(IResource.DEPTH_INFINITE, null);
} catch (CoreException e) {
ErrorReporter.logExceptionStackTrace(e);
}
includedProjects = tempProjectInformation.getIncludedProjects();
for (IncludedProject includedProject : includedProjects) {
final IPath temp = includedProject.getAbsolutePath();
if (temp != null) {
projectFilesToBeProcessed.add(temp);
}
}
}
}
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
final PreferenceDialog dialog = PreferencesUtil.createPropertyDialogOn(null, newProject, GeneralConstants.PROJECT_PROPERTY_PAGE, null, null);
if (dialog != null) {
dialog.open();
}
final IWorkspaceDescription description = ResourcesPlugin.getWorkspace().getDescription();
if (description.isAutoBuilding() != wasAutoBuilding) {
description.setAutoBuilding(wasAutoBuilding);
try {
ResourcesPlugin.getWorkspace().setDescription(description);
} catch (CoreException e) {
ErrorReporter.logExceptionStackTrace(e);
}
}
Activator.getDefault().resumeHandlingResourceChanges();
}
});
return true;
}
use of org.eclipse.titan.designer.properties.data.ProjectFileHandler in project titan.EclipsePlug-ins by eclipse.
the class ExtractModuleParActionFromEditor method execute.
@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
// getting the active editor
final TTCN3Editor targetEditor = Utils.getActiveEditor();
if (targetEditor == null) {
return null;
}
final IFile selectedFile = Utils.getSelectedFileInEditor("ExtractModulePar");
if (selectedFile == null) {
return null;
}
// getting current project
sourceProj = selectedFile.getProject();
if (sourceProj == null) {
ErrorReporter.logError("ExtractModuleParActionFromEditor: Source project is null. ");
return null;
}
// update AST
final Set<IProject> projsToUpdate = new HashSet<IProject>();
projsToUpdate.add(sourceProj);
Utils.updateASTBeforeRefactoring(projsToUpdate, "ExtractModulePar");
// create refactoring
final ExtractModuleParRefactoring refactoring = new ExtractModuleParRefactoring(sourceProj);
final ExtractModuleParWizard wiz = new ExtractModuleParWizard();
//
final StructuredSelection ssel = new StructuredSelection(sourceProj);
wiz.init(PlatformUI.getWorkbench(), ssel);
final WizardDialog dialog = new WizardDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), wiz);
dialog.open();
final boolean saveModuleParsOption = wiz.getSaveModuleParsOption();
final IProject newProj = wiz.getProject();
if (newProj == null) {
ErrorReporter.logError("ExtractModuleParActionFromEditor: Wizard returned a null project. ");
return null;
}
refactoring.setTargetProject(newProj);
refactoring.setOption_saveModuleParList(saveModuleParsOption);
// copy project settings to new project
final ProjectFileHandler pfh = new ProjectFileHandler(sourceProj);
if (pfh.projectFileExists()) {
// IResource.copy(...) is used because ProjectFileHandler.getDocumentFromFile(...) is not working
final IFile settingsFile = sourceProj.getFile("/" + ProjectFileHandler.XML_TITAN_PROPERTIES_FILE);
final IFile settingsCopy = newProj.getFile("/" + ProjectFileHandler.XML_TITAN_PROPERTIES_FILE);
try {
if (settingsCopy.exists()) {
settingsCopy.delete(true, new NullProgressMonitor());
}
settingsFile.copy(settingsCopy.getFullPath(), true, new NullProgressMonitor());
} catch (CoreException ce) {
ErrorReporter.logError("ExtractModuleParActionFromEditor: Copying project settings to new project failed.");
}
}
// performing the refactor operation
refactoring.perform();
// reanalyze project
final WorkspaceJob job = GlobalParser.getProjectSourceParser(newProj).analyzeAll();
if (job != null) {
try {
job.join();
} catch (InterruptedException e) {
ErrorReporter.logExceptionStackTrace(e);
}
}
return null;
}
Aggregations