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;
}
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;
}
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();
}
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);
}
}
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;
}
Aggregations