Search in sources :

Example 11 with ProjectFileHandler

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);
                    }
                }
            }
        });
    }
}
Also used : ProjectFileHandler(org.eclipse.titan.designer.properties.data.ProjectFileHandler) CoreException(org.eclipse.core.runtime.CoreException) PreferenceDialog(org.eclipse.jface.preference.PreferenceDialog) QualifiedName(org.eclipse.core.runtime.QualifiedName) IProjectDescription(org.eclipse.core.resources.IProjectDescription) WorkspaceJob(org.eclipse.core.resources.WorkspaceJob)

Example 12 with ProjectFileHandler

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;
}
Also used : NamedNodeMap(org.w3c.dom.NamedNodeMap) CoreException(org.eclipse.core.runtime.CoreException) ProjectFileHandler(org.eclipse.titan.designer.properties.data.ProjectFileHandler) Node(org.w3c.dom.Node) QualifiedName(org.eclipse.core.runtime.QualifiedName) NodeList(org.w3c.dom.NodeList) Element(org.w3c.dom.Element) Document(org.w3c.dom.Document)

Example 13 with ProjectFileHandler

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;
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) ProjectFileHandler(org.eclipse.titan.designer.properties.data.ProjectFileHandler) PreferenceDialog(org.eclipse.jface.preference.PreferenceDialog) QualifiedName(org.eclipse.core.runtime.QualifiedName) WorkspaceJob(org.eclipse.core.resources.WorkspaceJob)

Example 14 with ProjectFileHandler

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;
}
Also used : IPath(org.eclipse.core.runtime.IPath) ArrayList(java.util.ArrayList) ProjectInformation(org.eclipse.titan.designer.wizards.GUIProjectImporter.ProjectInformation) URI(java.net.URI) IProject(org.eclipse.core.resources.IProject) IncludedProject(org.eclipse.titan.designer.wizards.GUIProjectImporter.IncludedProject) IWorkspaceDescription(org.eclipse.core.resources.IWorkspaceDescription) CoreException(org.eclipse.core.runtime.CoreException) ProjectFileHandler(org.eclipse.titan.designer.properties.data.ProjectFileHandler) PreferenceDialog(org.eclipse.jface.preference.PreferenceDialog) IWorkspace(org.eclipse.core.resources.IWorkspace)

Example 15 with ProjectFileHandler

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;
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) TTCN3Editor(org.eclipse.titan.designer.editors.ttcn3editor.TTCN3Editor) IFile(org.eclipse.core.resources.IFile) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) WorkspaceJob(org.eclipse.core.resources.WorkspaceJob) IProject(org.eclipse.core.resources.IProject) ProjectFileHandler(org.eclipse.titan.designer.properties.data.ProjectFileHandler) CoreException(org.eclipse.core.runtime.CoreException) WizardDialog(org.eclipse.jface.wizard.WizardDialog) HashSet(java.util.HashSet)

Aggregations

ProjectFileHandler (org.eclipse.titan.designer.properties.data.ProjectFileHandler)17 CoreException (org.eclipse.core.runtime.CoreException)14 IProject (org.eclipse.core.resources.IProject)9 WorkspaceJob (org.eclipse.core.resources.WorkspaceJob)8 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)7 QualifiedName (org.eclipse.core.runtime.QualifiedName)7 IFile (org.eclipse.core.resources.IFile)6 IProjectDescription (org.eclipse.core.resources.IProjectDescription)5 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)5 HashSet (java.util.HashSet)4 IWorkspace (org.eclipse.core.resources.IWorkspace)4 URI (java.net.URI)3 IPath (org.eclipse.core.runtime.IPath)3 PreferenceDialog (org.eclipse.jface.preference.PreferenceDialog)3 ArrayList (java.util.ArrayList)2 Path (org.eclipse.core.runtime.Path)2 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)2 WizardDialog (org.eclipse.jface.wizard.WizardDialog)2 Document (org.w3c.dom.Document)2 Node (org.w3c.dom.Node)2