Search in sources :

Example 6 with ProjectFileHandler

use of org.eclipse.titan.designer.properties.data.ProjectFileHandler in project titan.EclipsePlug-ins by eclipse.

the class NewTITANProjectWizard method createNewProject.

/**
 * Creating a new project.
 *
 * @return the new project created.
 */
private IProject createNewProject() {
    final IProject tempProjectHandle = mainPage.getProjectHandle();
    URI location = null;
    if (!mainPage.useDefaults()) {
        location = mainPage.getLocationURI();
    }
    final IWorkspace workspace = ResourcesPlugin.getWorkspace();
    final String tempExecutableName = tempProjectHandle.getName();
    final IProject newProjectHandle = ResourcesPlugin.getWorkspace().getRoot().getProject(tempExecutableName);
    final IProjectDescription description = workspace.newProjectDescription(tempExecutableName);
    description.setLocationURI(location);
    TITANNature.addTITANNatureToProject(description);
    final WorkspaceModifyOperation op = new WorkspaceModifyOperation() {

        @Override
        protected void execute(final IProgressMonitor monitor) throws CoreException {
            createProject(description, newProjectHandle, monitor);
            String sourceFolder = optionsPage.getSourceFolder();
            if (!"".equals(sourceFolder)) {
                IFolder folder = newProjectHandle.getFolder(sourceFolder);
                if (!folder.exists()) {
                    try {
                        folder.create(true, true, null);
                    } catch (CoreException e) {
                        ErrorReporter.logExceptionStackTrace(e);
                    }
                }
                final SampleProject sample = contentPage.getSampleProject();
                if (sample != null) {
                    sample.setupProject(newProjectHandle.getProject(), folder);
                    ProjectFileHandler pfHandler = new ProjectFileHandler(newProjectHandle.getProject());
                    pfHandler.saveProjectSettings();
                }
                if (optionsPage.isExcludeFromBuildSelected()) {
                    folder.setPersistentProperty(new QualifiedName(FolderBuildPropertyData.QUALIFIER, FolderBuildPropertyData.EXCLUDE_FROM_BUILD_PROPERTY), TRUE);
                }
            }
            newProjectHandle.setPersistentProperty(new QualifiedName(ProjectBuildPropertyData.QUALIFIER, ProjectBuildPropertyData.GENERATE_MAKEFILE_PROPERTY), TRUE);
            newProjectHandle.setPersistentProperty(new QualifiedName(ProjectBuildPropertyData.QUALIFIER, TTCN3PreprocessorOptionsData.TTCN3_PREPROCESSOR_PROPERTY), "cpp");
            newProjectHandle.setPersistentProperty(new QualifiedName(ProjectBuildPropertyData.QUALIFIER, CCompilerOptionsData.CXX_COMPILER_PROPERTY), "g++");
        }
    };
    try {
        getContainer().run(true, true, op);
    } catch (InterruptedException e) {
        return null;
    } catch (final InvocationTargetException e) {
        final Throwable t = e.getTargetException();
        if (t != null) {
            ErrorReporter.parallelErrorDisplayInMessageDialog(CREATION_FAILED, t.getMessage());
        }
        return null;
    }
    newProject = newProjectHandle;
    return newProject;
}
Also used : SampleProject(org.eclipse.titan.designer.samples.SampleProject) WorkspaceModifyOperation(org.eclipse.ui.actions.WorkspaceModifyOperation) QualifiedName(org.eclipse.core.runtime.QualifiedName) URI(java.net.URI) IProject(org.eclipse.core.resources.IProject) InvocationTargetException(java.lang.reflect.InvocationTargetException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) ProjectFileHandler(org.eclipse.titan.designer.properties.data.ProjectFileHandler) IWorkspace(org.eclipse.core.resources.IWorkspace) IProjectDescription(org.eclipse.core.resources.IProjectDescription) IFolder(org.eclipse.core.resources.IFolder)

Example 7 with ProjectFileHandler

use of org.eclipse.titan.designer.properties.data.ProjectFileHandler in project titan.EclipsePlug-ins by eclipse.

the class NewTTCN3ModuleWizard method performFinish.

/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.jface.wizard.Wizard#performFinish()
	 */
@Override
public boolean performFinish() {
    if (mainPage.getContainerFullPath().append(mainPage.getFileName()).getFileExtension() == null) {
        mainPage.setFileName(mainPage.getFileName() + '.' + GlobalParser.SUPPORTED_TTCN3_EXTENSIONS[1]);
    }
    final IFile newModule = mainPage.createNewFile();
    if (newModule != null) {
        try {
            if (optionsPage.isExcludeFromBuildSelected()) {
                newModule.setPersistentProperty(new QualifiedName(FileBuildPropertyData.QUALIFIER, FileBuildPropertyData.EXCLUDE_FROM_BUILD_PROPERTY), TRUE);
            }
            final ProjectFileHandler pfHandler = new ProjectFileHandler(newModule.getProject());
            pfHandler.saveProjectSettings();
            newModule.touch(new NullProgressMonitor());
            final WorkspaceJob refreshJob = new WorkspaceJob("Refreshing built resources") {

                @Override
                public IStatus runInWorkspace(final IProgressMonitor monitor) {
                    boolean proceedingOK = SymbolicLinkHandler.createSymlinks(newModule);
                    if (proceedingOK) {
                        proceedingOK = TITANBuilder.regenerateMakefile(newModule.getProject());
                    }
                    if (proceedingOK) {
                        proceedingOK = TITANBuilder.removeExecutable(newModule.getProject());
                    }
                    if (proceedingOK) {
                        TITANBuilder.invokeBuild(newModule.getProject());
                    }
                    return Status.OK_STATUS;
                }
            };
            refreshJob.setPriority(Job.LONG);
            refreshJob.setUser(false);
            refreshJob.setSystem(true);
            refreshJob.setProperty(IProgressConstants.ICON_PROPERTY, ImageCache.getImageDescriptor("titan.gif"));
            refreshJob.schedule();
            selectAndRevealNewModule(newModule);
        } catch (CoreException e) {
            ErrorReporter.logExceptionStackTrace(e);
        }
    }
    return true;
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IFile(org.eclipse.core.resources.IFile) ProjectFileHandler(org.eclipse.titan.designer.properties.data.ProjectFileHandler) CoreException(org.eclipse.core.runtime.CoreException) QualifiedName(org.eclipse.core.runtime.QualifiedName) WorkspaceJob(org.eclipse.core.resources.WorkspaceJob)

Example 8 with ProjectFileHandler

use of org.eclipse.titan.designer.properties.data.ProjectFileHandler in project titan.EclipsePlug-ins by eclipse.

the class ExtractModuleParActionFromBrowser method performExtractModulePar.

private void performExtractModulePar() {
    // find selection: only a single project can be refactored
    if (!(selection instanceof IStructuredSelection)) {
        return;
    }
    final Set<IProject> sourceProjs = Utils.findAllProjectsInSelection((IStructuredSelection) selection);
    if (sourceProjs.isEmpty()) {
        return;
    }
    final IProject sourceProj = sourceProjs.iterator().next();
    final IStructuredSelection ssel = new StructuredSelection(sourceProj);
    // update AST before refactoring
    final Set<IProject> projsToUpdate = new HashSet<IProject>();
    projsToUpdate.add(sourceProj);
    Utils.updateASTBeforeRefactoring(projsToUpdate, "ExtractModulePar");
    Activator.getDefault().pauseHandlingResourceChanges();
    // create refactoring
    final ExtractModuleParRefactoring refactoring = new ExtractModuleParRefactoring(sourceProj);
    // open wizard
    final ExtractModuleParWizard wiz = new ExtractModuleParWizard();
    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("ExtractModuleParActionFromBrowser: Wizard returned a null project. ");
        return;
    }
    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.");
        }
    }
    final WorkspaceJob job = new WorkspaceJob("ExtractModulePar: writing to target project") {

        @Override
        public IStatus runInWorkspace(final IProgressMonitor monitor) throws CoreException {
            refactoring.perform();
            Activator.getDefault().resumeHandlingResourceChanges();
            return Status.OK_STATUS;
        }
    };
    job.schedule();
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IFile(org.eclipse.core.resources.IFile) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) WorkspaceJob(org.eclipse.core.resources.WorkspaceJob) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IProject(org.eclipse.core.resources.IProject) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ProjectFileHandler(org.eclipse.titan.designer.properties.data.ProjectFileHandler) CoreException(org.eclipse.core.runtime.CoreException) WizardDialog(org.eclipse.jface.wizard.WizardDialog) HashSet(java.util.HashSet)

Example 9 with ProjectFileHandler

use of org.eclipse.titan.designer.properties.data.ProjectFileHandler in project titan.EclipsePlug-ins by eclipse.

the class ExtractModuleParHeadless method run.

public void run(final IProject sourceProj, final String targetProjName, final boolean saveModuleParList) {
    final IWorkspace workspace = ResourcesPlugin.getWorkspace();
    final IProject newProj = workspace.getRoot().getProject(targetProjName);
    final IProjectDescription description = workspace.newProjectDescription(targetProjName);
    description.setLocationURI(location);
    TITANNature.addTITANNatureToProject(description);
    if (newProj == null) {
        ErrorReporter.logError("ExtractModuleParHeadless: Target project is null. ");
        return;
    }
    // update AST
    final Set<IProject> projsToUpdate = new HashSet<IProject>();
    projsToUpdate.add(sourceProj);
    Utils.updateASTBeforeRefactoring(projsToUpdate, "ExtractModulePar");
    try {
        if (Utils.createProject(description, newProj)) {
            try {
                TITANNature.addTITANBuilderToProject(newProj);
            } catch (CoreException ce) {
                ErrorReporter.logExceptionStackTrace(ce);
                return;
            }
            // 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("ExtractModuleParHeadless: Copying project settings to new project failed.");
                }
            }
            // executing refactoring
            final ExtractModuleParRefactoring refactoring = new ExtractModuleParRefactoring(sourceProj);
            refactoring.setOption_saveModuleParList(saveModuleParList);
            refactoring.setTargetProject(newProj);
            refactoring.perform();
        }
    } catch (CoreException e) {
        ErrorReporter.logError("ExtractModuleParHeadless: Target project creation was unsuccessful. ");
        ErrorReporter.logExceptionStackTrace(e);
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IFile(org.eclipse.core.resources.IFile) CoreException(org.eclipse.core.runtime.CoreException) ProjectFileHandler(org.eclipse.titan.designer.properties.data.ProjectFileHandler) IWorkspace(org.eclipse.core.resources.IWorkspace) IProjectDescription(org.eclipse.core.resources.IProjectDescription) IProject(org.eclipse.core.resources.IProject) HashSet(java.util.HashSet)

Example 10 with ProjectFileHandler

use of org.eclipse.titan.designer.properties.data.ProjectFileHandler in project titan.EclipsePlug-ins by eclipse.

the class ExtractModuleParWizard method performFinish.

@Override
public boolean performFinish() {
    if (!isCreated) {
        createNewProject();
    }
    if (newProject == null) {
        resetAutobuildOption();
        Activator.getDefault().resumeHandlingResourceChanges();
        return false;
    }
    try {
        TITANNature.addTITANBuilderToProject(newProject);
    } catch (CoreException ce) {
        ErrorReporter.logExceptionStackTrace(ce);
    }
    try {
        newProject.setPersistentProperty(new QualifiedName(ProjectBuildPropertyData.QUALIFIER, MakeAttributesData.TEMPORAL_WORKINGDIRECTORY_PROPERTY), WORKING_DIR);
        String tempExecutableName = newProject.getName();
        tempExecutableName = tempExecutableName.replace(' ', '_');
        String executable;
        if (newProject.getLocation() == null) {
            final URI projectURI = newProject.getLocationURI();
            final URI uri = TITANPathUtilities.resolvePath(WORKING_DIR, projectURI);
            executable = URIUtil.append(uri, tempExecutableName).toString();
        } else {
            final URI uri = TITANPathUtilities.resolvePathURI(WORKING_DIR, newProject.getLocation().toOSString());
            final IPath workingDir = org.eclipse.core.filesystem.URIUtil.toPath(uri);
            executable = workingDir.append(tempExecutableName).toOSString();
            if (Platform.OS_WIN32.equals(Platform.getOS())) {
                executable += ".exe";
            }
        }
        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);
    }
    try {
        newProject.refreshLocal(IResource.DEPTH_INFINITE, null);
    } catch (CoreException e) {
        ErrorReporter.logExceptionStackTrace(e);
    }
    Display.getDefault().asyncExec(new Runnable() {

        @Override
        public void run() {
            /*
				 		//popup project settings dialog
					Shell shell = new Shell(Display.getDefault());
					PreferenceDialog dialog = PreferencesUtil.createPropertyDialogOn(shell, newProject,
							GeneralConstants.PROJECT_PROPERTY_PAGE, null, null);
					if (dialog != null) {
						dialog.open();
					}
				*/
            resetAutobuildOption();
            Activator.getDefault().resumeHandlingResourceChanges();
            BasicNewProjectResourceWizard.updatePerspective(config);
            selectAndReveal(newProject);
        }
    });
    return true;
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) IPath(org.eclipse.core.runtime.IPath) ProjectFileHandler(org.eclipse.titan.designer.properties.data.ProjectFileHandler) QualifiedName(org.eclipse.core.runtime.QualifiedName) WorkspaceJob(org.eclipse.core.resources.WorkspaceJob) URI(java.net.URI)

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