use of org.eclipse.titan.designer.properties.data.ProjectFileHandler in project titan.EclipsePlug-ins by eclipse.
the class Activator method batchedEventHandler.
/**
* Handle the resource changes that has been batched.
*/
protected void batchedEventHandler() {
projects = new HashMap<IProject, IResourceDelta>();
for (final IResourceChangeEvent event : BATCHED_EVENTS) {
final IResourceDelta resourceDelta = event.getDelta();
if (resourceDelta == null) {
switch(event.getType()) {
case IResourceChangeEvent.PRE_CLOSE:
case IResourceChangeEvent.PRE_DELETE:
GlobalParser.clearAllInformation(event.getResource().getProject());
break;
default:
break;
}
} else {
try {
resourceDelta.accept(projectAdder);
} catch (CoreException e) {
ErrorReporter.logExceptionStackTrace(e);
}
MarkerHandler.handleResourceChanges(event);
}
}
BATCHED_EVENTS.clear();
final IPreferencesService prefs = Platform.getPreferencesService();
// for every project check if the TITANProperties file was changed or need to be changed
for (final IProject project : projects.keySet()) {
// which can be handled
if (project != null && project.isAccessible() && projects.get(project) != null) {
final IResourceDelta projectDelta = projects.get(project);
if (projectDelta.getKind() == IResourceDelta.ADDED) {
// new project appeared load the settings
final ProjectFileHandler pfHandler = new ProjectFileHandler(project);
pfHandler.loadProjectSettings();
PropertyNotificationManager.firePropertyChange(project);
continue;
}
try {
final IResourceDelta propertiesDelta = projectDelta.findMember(new Path(ProjectFileHandler.XML_TITAN_PROPERTIES_FILE));
final DeltaVisitor visitor = new DeltaVisitor();
projectDelta.accept(visitor);
if (visitor.hasNewOrRemovedResources()) {
final ProjectFileHandler pfHandler = new ProjectFileHandler(project);
if (propertiesDelta == null || propertiesDelta.getKind() == IResourceDelta.REMOVED) {
// project setting file does not exist
pfHandler.saveProjectSettings();
} else {
// the project settings have changed and we have new resources, the project was updated by the user
pfHandler.loadProjectSettings();
PropertyNotificationManager.firePropertyChange(project);
}
} else {
if (propertiesDelta != null) {
final ProjectFileHandler pfHandler = new ProjectFileHandler(project);
if (propertiesDelta.getKind() == IResourceDelta.REMOVED) {
// save the settings if the only change was that it was removed externally
pfHandler.saveProjectSettings();
} else {
// load the settings if it changed
pfHandler.loadProjectSettings();
PropertyNotificationManager.firePropertyChange(project);
}
}
}
} catch (CoreException e) {
ErrorReporter.logExceptionStackTrace(e);
}
// check if it needs to be built, if full analysis is needed, and that the working directory is always set as derived
final IProject[] referencingProjects = ProjectBasedBuilder.getProjectBasedBuilder(project).getReferencingProjects();
for (int i = 0; i < referencingProjects.length; i++) {
ProjectBasedBuilder.setForcedBuild(referencingProjects[i]);
}
if ((projectDelta.getFlags() & IResourceDelta.DESCRIPTION) != 0) {
TITANBuilder.markProjectForRebuild(project);
}
if (projectDelta.getKind() == IResourceDelta.ADDED) {
final WorkspaceJob derivedSetter = new WorkspaceJob("Derived flag setter") {
@Override
public IStatus runInWorkspace(final IProgressMonitor monitor) {
final IContainer[] workingDirectories = ProjectBasedBuilder.getProjectBasedBuilder(project).getWorkingDirectoryResources(true);
for (IContainer workingDirectory : workingDirectories) {
if (workingDirectory != null && workingDirectory.isAccessible()) {
try {
workingDirectory.setDerived(true, monitor);
} catch (CoreException e) {
ErrorReporter.logExceptionStackTrace(e);
}
}
}
return Status.OK_STATUS;
}
};
derivedSetter.setPriority(Job.LONG);
derivedSetter.setUser(false);
derivedSetter.setSystem(true);
derivedSetter.setRule(project.getWorkspace().getRuleFactory().modifyRule(project));
derivedSetter.setProperty(IProgressConstants.ICON_PROPERTY, ImageCache.getImageDescriptor("titan.gif"));
derivedSetter.schedule();
}
}
}
// we need to invoke the analyzer to refresh the information databases.
if (prefs.getBoolean(ProductConstants.PRODUCT_ID_DESIGNER, PreferenceConstants.USEONTHEFLYPARSING, true, null)) {
for (final IProject project : projects.keySet()) {
// which can be handled
if (project != null && project.isAccessible() && projects.get(project) != null) {
final IResourceDelta projectDelta = projects.get(project);
final DeltaVisitor visitor = new DeltaVisitor();
try {
projectDelta.accept(visitor);
if (!visitor.hasNewOrRemovedResources() && (projectDelta.getFlags() & IResourceDelta.DESCRIPTION) == 0) {
continue;
}
} catch (CoreException e) {
ErrorReporter.logExceptionStackTrace(e);
}
final WorkspaceJob buildStarter = new WorkspaceJob("Build starter") {
@Override
public IStatus runInWorkspace(final IProgressMonitor monitor) {
GlobalDeltaVisitor tempVisitor = new GlobalDeltaVisitor(project);
try {
projectDelta.accept(tempVisitor);
} catch (CoreException e) {
ErrorReporter.logExceptionStackTrace(e);
}
final WorkspaceJob[] outdatingJobs = tempVisitor.reportOutdatedFiles();
WorkspaceJob analyzeAfterOutdating = new WorkspaceJob("analyzeAfterOutdating") {
@Override
public IStatus runInWorkspace(final IProgressMonitor monitor) throws CoreException {
// Wait for reportOutdatedFiles() to finish
try {
for (WorkspaceJob job : outdatingJobs) {
if (job != null) {
job.join();
}
}
} catch (InterruptedException e) {
ErrorReporter.logExceptionStackTrace(e);
}
GlobalParser.getProjectSourceParser(project).analyzeAll(false);
if (ProjectBuildPropertyData.useAutomaticMakefilegeneration(project)) {
TITANBuilder.markProjectForRebuild(project);
TITANBuilder.regenerateMakefile(project);
}
return Status.OK_STATUS;
}
};
analyzeAfterOutdating.setPriority(Job.LONG);
analyzeAfterOutdating.setUser(false);
analyzeAfterOutdating.setSystem(true);
analyzeAfterOutdating.setProperty(IProgressConstants.ICON_PROPERTY, ImageCache.getImageDescriptor("titan.gif"));
analyzeAfterOutdating.schedule();
return Status.OK_STATUS;
}
};
buildStarter.setPriority(Job.LONG);
buildStarter.setUser(false);
buildStarter.setSystem(true);
buildStarter.setRule(project.getWorkspace().getRuleFactory().refreshRule(project));
buildStarter.setProperty(IProgressConstants.ICON_PROPERTY, ImageCache.getImageDescriptor("titan.gif"));
buildStarter.schedule();
}
}
}
}
use of org.eclipse.titan.designer.properties.data.ProjectFileHandler in project titan.EclipsePlug-ins by eclipse.
the class WorkspaceHandlingLibrary method importProjectIntoWorkspace.
/**
* Imports a "source directory"and all sub elements into the workspace as a project.
* <p>
* The source directory should be a valid project.
* <p>
* Please note that the name of the project can be different from the name of the directory.
*
* @param projectName the name of the project to be created
* @param sourceLocation the location of the directory to be imported
*
* @return the imported project
*/
public static IProject importProjectIntoWorkspace(final String projectName, final URI sourceLocation) throws CoreException {
assertNotNull(projectName);
assertNotNull(sourceLocation);
IProject project = workspace.getRoot().getProject(projectName);
IProjectDescription description = workspace.newProjectDescription(projectName);
description.setLocationURI(sourceLocation);
project.create(description, null);
project.open(null);
org.eclipse.titan.designer.properties.data.ProjectFileHandler handler = new ProjectFileHandler(project);
handler.loadProjectSettings();
return project;
}
use of org.eclipse.titan.designer.properties.data.ProjectFileHandler in project titan.EclipsePlug-ins by eclipse.
the class GUIProjectImporter method importProjectfromPrj.
/**
* Imports a project from .prj file in headless mode
*
* @param projectFile
* file name with full path
* @return true if the import was successful
*/
public static boolean importProjectfromPrj(final String projectFile) {
final IWorkspace workspace = ResourcesPlugin.getWorkspace();
List<String> processedProjectFiles = new ArrayList<String>();
List<IPath> projectFilesToBeProcessed = new ArrayList<IPath>();
projectFilesToBeProcessed.add(new Path(projectFile));
while (!projectFilesToBeProcessed.isEmpty()) {
IPath tempPath = projectFilesToBeProcessed.remove(projectFilesToBeProcessed.size() - 1);
if (processedProjectFiles.contains(tempPath.toOSString())) {
continue;
}
processedProjectFiles.add(tempPath.toOSString());
GUIProjectImporter importer = new GUIProjectImporter();
// true: headless
ProjectInformation tempProjectInformation = importer.loadProjectFile(tempPath.toOSString(), null, true);
if (tempProjectInformation == null) {
continue;
}
IPath tempPath2 = tempPath.removeFileExtension();
String includedProjectName = tempPath2.lastSegment();
IProject tempProject = workspace.getRoot().getProject(includedProjectName);
if (tempProject.exists()) {
continue;
}
tempProject = createNewProject(tempProject, tempProjectInformation, null);
if (tempProject == null) {
continue;
}
try {
TITANNature.addTITANBuilderToProject(tempProject);
} catch (CoreException e) {
ErrorReporter.logExceptionStackTrace(e);
}
ProjectFileHandler pfHandler = new ProjectFileHandler(tempProject);
pfHandler.saveProjectSettings();
try {
tempProject.refreshLocal(IResource.DEPTH_INFINITE, null);
} catch (CoreException e) {
ErrorReporter.logExceptionStackTrace(e);
}
List<IncludedProject> includedProjects = tempProjectInformation.getIncludedProjects();
for (IncludedProject includedProject : includedProjects) {
IPath temp = includedProject.getAbsolutePath();
if (temp != null) {
projectFilesToBeProcessed.add(temp);
}
}
}
return true;
}
use of org.eclipse.titan.designer.properties.data.ProjectFileHandler in project titan.EclipsePlug-ins by eclipse.
the class NewASN1ModuleWizard 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_ASN1_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 NewConfigFileWizard 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_CONFIG_FILE_EXTENSIONS[0]);
}
final IFile newConfigFile = mainPage.createNewFile();
if (newConfigFile != null) {
try {
final ProjectFileHandler pfHandler = new ProjectFileHandler(newConfigFile.getProject());
pfHandler.saveProjectSettings();
newConfigFile.touch(new NullProgressMonitor());
PropertyNotificationManager.firePropertyChange(newConfigFile);
selectAndRevealNewModule(newConfigFile);
} catch (CoreException e) {
ErrorReporter.logExceptionStackTrace(e);
}
}
return true;
}
Aggregations