View Javadoc

1   /*
2    * This file is a part of CAST project.
3    * (c) Copyright 2007, AGH University of Science & Technology
4    * https://caribou.iisg.agh.edu.pl/trac/cast
5    *
6    * Licensed under the Eclipse Public License, Version 1.0 (the "License").
7    * You may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    * http://www.eclipse.org/legal/epl-v10.html
10   */
11  /*
12   * File: ProjectUtil.java
13   * Created: 2007-00-00
14   * Author: awos, tmilos
15   * $Id: ProjectUtil.java 3406 2009-09-30 15:05:28Z tmilos $
16   */
17  
18  package pl.edu.agh.cast.project;
19  
20  import java.beans.PropertyChangeEvent;
21  import java.beans.PropertyChangeListener;
22  import java.io.ByteArrayInputStream;
23  import java.io.File;
24  import java.io.FileInputStream;
25  import java.io.FileNotFoundException;
26  
27  import org.apache.log4j.Logger;
28  import org.eclipse.core.resources.IFile;
29  import org.eclipse.core.resources.IProject;
30  import org.eclipse.core.resources.IProjectDescription;
31  import org.eclipse.core.resources.IWorkspace;
32  import org.eclipse.core.resources.ProjectScope;
33  import org.eclipse.core.resources.ResourcesPlugin;
34  import org.eclipse.core.runtime.CoreException;
35  import org.eclipse.core.runtime.IPath;
36  import org.eclipse.core.runtime.Path;
37  import org.eclipse.core.runtime.Platform;
38  import org.eclipse.core.runtime.preferences.IEclipsePreferences;
39  import org.eclipse.osgi.util.NLS;
40  import org.eclipse.swt.SWT;
41  import org.eclipse.swt.widgets.Display;
42  import org.eclipse.ui.PlatformUI;
43  import org.osgi.service.prefs.BackingStoreException;
44  
45  import pl.edu.agh.cast.Activator;
46  import pl.edu.agh.cast.CastApplication;
47  import pl.edu.agh.cast.CoreServiceLocator;
48  import pl.edu.agh.cast.data.persistence.IPersistenceProvider;
49  import pl.edu.agh.cast.data.persistence.PersistenceException;
50  import pl.edu.agh.cast.data.persistence.PersistenceProviderLocator;
51  import pl.edu.agh.cast.ui.dialogs.ProjectStartupDialog;
52  import pl.edu.agh.cast.ui.util.MsgBoxHelper;
53  import pl.edu.agh.cast.util.Configuration;
54  import pl.edu.agh.cast.util.Messages;
55  
56  /**
57   * Utility methods for operating on projects.
58   *
59   * @author AGH CAST Team
60   */
61  public final class ProjectUtil implements PropertyChangeListener {
62  
63  	private static final Logger LOG = Activator.getLogger();
64  
65  	// BEGIN Constants
66  
67  	public static final String PROJECT_VERSION = "0.5.x"; //$NON-NLS-1$
68  
69  	/**
70  	 * List of characters that cannot be used in a project name.
71  	 */
72  	@SuppressWarnings("nls")
73  	public static final String[] PROJECT_BAD_CHARS = new String[] { "\\", "/", ":", "*", "?", "<", ">", "|", ",", "." };
74  
75  	/**
76  	 * Project display name property used.
77  	 */
78  	public static final String PROJECT_DISPLAY_NAME_PROPERTY = "project.displayName"; //$NON-NLS-1$
79  
80  	/**
81  	 * Project version property.
82  	 */
83  	public static final String PROJECT_VERSION_PROPERTY = "project.version"; //$NON-NLS-1$
84  
85  	/**
86  	 * Project id property.
87  	 */
88  	public static final String PROJECT_ID_PROPERTY = "project.id"; //$NON-NLS-1$
89  
90  	/**
91  	 * Project persistence provider id property.
92  	 */
93  	public static final String PERSISTENCE_PROVIDER_ID_PROPERTY = "persistence.id"; //$NON-NLS-1$
94  
95  	/**
96  	 * Project persistence provider config/store file property.
97  	 */
98  	public static final String PERSISTENCE_PROVIDER_CONFIG_PROPERTY = "persistence.file"; //$NON-NLS-1$
99  
100 	// END Constants
101 
102 	/**
103 	 * Enumeration of open project result statuses.
104 	 *
105 	 * @author AGH CAST Team
106 	 */
107 	public static enum ProjectOpenStatus {
108 		OPENED, LOCKED, INVALID_VERSION;
109 	}
110 
111 	// BEGIN Property Access
112 
113 	/**
114 	 * Reads projects properties using Eclipse Preferences mechanism.
115 	 *
116 	 * @param project
117 	 *            project which properties are read
118 	 * @param propertyId
119 	 *            id of property to read
120 	 * @return property with given id found for specified project
121 	 */
122 	public static String getProperty(IProject project, String propertyId) {
123 		ProjectScope ps = new ProjectScope(project);
124 		return ps.getNode(Activator.PLUGIN_ID).get(propertyId, null);
125 	}
126 
127 	/**
128 	 * Sets property for given project.
129 	 *
130 	 * @param project
131 	 *            project which property is to be set
132 	 * @param propertyId
133 	 *            property id
134 	 * @param value
135 	 *            new value of property
136 	 */
137 	public static void setProperty(IProject project, String propertyId, String value) {
138 		ProjectScope ps = new ProjectScope(project);
139 		IEclipsePreferences node = ps.getNode(Activator.PLUGIN_ID);
140 		node.put(propertyId, value);
141 		try {
142 			node.flush();
143 		} catch (BackingStoreException e) {
144 			Logger.getLogger(ProjectUtil.class).error("Failed to save property " + propertyId, e); //$NON-NLS-1$
145 		}
146 	}
147 
148 	// END Property Access
149 
150 	// BEGIN Singleton
151 
152 	/**
153 	 * Single instance holder.
154 	 *
155 	 * @author AGH CAST Team
156 	 */
157 	private static class ProjectUtilHolder {
158 		private static final ProjectUtil INSTANCE = new ProjectUtil();
159 	}
160 
161 	/**
162 	 * Private constructor.
163 	 */
164 	private ProjectUtil() {
165 		if (CastApplication.getPropertyChangeProvider() != null) {
166 			CastApplication.getPropertyChangeProvider().addPropertyChangeListener(this);
167 		}
168 	}
169 
170 	/**
171 	 * Returns single, shared instance of {@link ProjectUtil}.
172 	 *
173 	 * @return single, shared instance of {@link ProjectUtil}
174 	 */
175 	public static ProjectUtil getInstance() {
176 		return ProjectUtilHolder.INSTANCE;
177 	}
178 
179 	// END Singleton
180 
181 	// BEGIN Project Name Methods
182 
183 	/**
184 	 * Returns project's display name.
185 	 *
186 	 * @param project
187 	 *            the project
188 	 * @return project's display name
189 	 */
190 	public String getDisplayName(IProject project) {
191 		String displayName = getProperty(project, PROJECT_DISPLAY_NAME_PROPERTY);
192 		return displayName != null && displayName.length() > 0 ? displayName : project.getName();
193 	}
194 
195 	/**
196 	 * Sets project's display name.
197 	 *
198 	 * @param project
199 	 *            the project
200 	 * @param name
201 	 *            project's display name
202 	 */
203 	public void setDisplayName(final IProject project, final String name) {
204 		UserPreferences.getInstance().changeMostRecentlyProjectName(project, name);
205 		setProperty(project, PROJECT_DISPLAY_NAME_PROPERTY, name);
206 	}
207 
208 	/**
209 	 * Escapes non-standard characters in project's name.
210 	 *
211 	 * @param name
212 	 *            name to escape
213 	 * @return escaped name
214 	 */
215 	public String escapeName(String name) {
216 		String r = name.replaceAll("[\\\\//?:]", "_"); //$NON-NLS-1$ //$NON-NLS-2$
217 		String s = new File(r).toURI().getPath();
218 		if (s.lastIndexOf('/') == s.length() - 1) {
219 			s = s.substring(0, s.length() - 1);
220 		}
221 		s = s.substring(s.lastIndexOf('/') + 1);
222 		return s;
223 	}
224 
225 	// END Project Name Methods
226 
227 	// BEGIN Project Management
228 
229 	/**
230 	 * Create project of specified name if it does not exists.
231 	 *
232 	 * @param projectName
233 	 *            name of the project
234 	 * @param location
235 	 *            location of the project
236 	 * @return new instance of a project
237 	 * @throws CoreException
238 	 */
239 	public IProject createProject(String projectName, IPath location) throws CoreException {
240 
241 		IWorkspace workspace = ResourcesPlugin.getWorkspace();
242 		IProjectDescription pd = workspace.newProjectDescription(projectName);
243 		if (Platform.getLocation() != null && location != null && !Platform.getLocation().isPrefixOf(location)) {
244 			pd.setLocation(location);
245 		} else {
246 			pd.setLocation(null);
247 		}
248 
249 		IProject project = workspace.getRoot().getProject(projectName);
250 
251 		if (!project.exists()) {
252 			project.create(pd, null); // <-
253 			project.open(null); // <-
254 			// set cast project name
255 			if (getProperty(project, PROJECT_DISPLAY_NAME_PROPERTY) == null) {
256 				setDisplayName(project, projectName);
257 			}
258 			if (getProperty(project, PROJECT_ID_PROPERTY) == null) {
259 				setProperty(project, PROJECT_ID_PROPERTY, generateProjectId());
260 			}
261 			// create dummy file
262 			String dummyFileName = projectName + "." + Configuration.DUMMY_PROJECT_FILE_EXTENSION; //$NON-NLS-1$
263 			IFile dummyFile = project.getFile(dummyFileName);
264 			dummyFile.create(new ByteArrayInputStream(new byte[0]), true, null); // <-
265 
266 			init(project); // <-
267 		}
268 		if (!project.isOpen()) {
269 			project.open(null);
270 		}
271 
272 		return project;
273 	}
274 
275 	/**
276 	 * Initializes the new project.
277 	 *
278 	 * @param project
279 	 *            the new project
280 	 * @throws CoreException
281 	 */
282 	public void init(IProject project) throws CoreException {
283 		String id = getProperty(project, ProjectUtil.PROJECT_ID_PROPERTY);
284 		if (id == null) {
285 			id = generateProjectId();
286 			setProperty(project, ProjectUtil.PROJECT_ID_PROPERTY, id);
287 		}
288 
289 		setProperty(project, PROJECT_VERSION_PROPERTY, PROJECT_VERSION);
290 
291 		String providerId = getProperty(project, PERSISTENCE_PROVIDER_ID_PROPERTY);
292 		if (providerId == null) {
293 			providerId = PersistenceProviderLocator.selectPersistenceProvider();
294 			setProperty(project, PERSISTENCE_PROVIDER_ID_PROPERTY, providerId);
295 		}
296 
297 		String providerFile = getProperty(project, PERSISTENCE_PROVIDER_CONFIG_PROPERTY);
298 		if (providerFile == null) {
299 			providerFile = PersistenceProviderLocator.getPersistenceFilePath(providerId);
300 			setProperty(project, PERSISTENCE_PROVIDER_CONFIG_PROPERTY, providerFile);
301 		}
302 		IFile file = project.getFile(providerFile);
303 		if (!file.exists()) {
304 			file.create(new ByteArrayInputStream(new byte[0]), true, null);
305 		}
306 	}
307 
308 	/**
309 	 * Create project of specified name if it does not exists and activates created project.
310 	 *
311 	 * @param projectName
312 	 *            name of the project
313 	 * @param location
314 	 *            location of the project
315 	 * @return new instance of an activated project
316 	 * @throws CoreException
317 	 */
318 	public IProject createAndActivateProject(String projectName, IPath location) throws CoreException {
319 		IProject project = createProject(projectName, location);
320 
321 		CastApplication.setActiveProject(project);
322 		initializePersistenceProvider(project);
323 		return project;
324 	}
325 
326 	/**
327 	 * Opens existing project from specified directory.
328 	 *
329 	 * @param location
330 	 *            project location which contains <code>.project</code> description file
331 	 * @param force
332 	 *            if true opens project with the same name which exists in the workspace
333 	 * @return <b>true</b> if specified project has been opened; <b>false</b> otherwise: if the specified project exists
334 	 *         already in the workspace and force flag has been set to false
335 	 * @throws FileNotFoundException
336 	 *             if project description file (<code>.project</code>) is not found in specified location
337 	 * @throws CoreException
338 	 *             if loading description failed. Reasons include:
339 	 *             <ul>
340 	 *             <li>The stream could not be read.</li>
341 	 *             <li>The stream does not contain a legal project description.</li>
342 	 *             </ul>
343 	 *
344 	 */
345 	public ProjectOpenStatus openProject(String location, boolean force) throws FileNotFoundException, CoreException {
346 		ProjectOpenStatus res = ProjectOpenStatus.OPENED;
347 		IWorkspace workspace = ResourcesPlugin.getWorkspace();
348 		// check if description file exists
349 		IProjectDescription projectDescription = workspace.loadProjectDescription(new FileInputStream(location
350 		        + File.separator + IProjectDescription.DESCRIPTION_FILE_NAME));
351 
352 		if (!Platform.getLocation().isPrefixOf(Path.fromOSString(location))) {
353 			projectDescription.setLocation(Path.fromOSString(location));
354 		}
355 
356 		// check if project exists already in workspace
357 		IProject project = workspace.getRoot().getProject(projectDescription.getName());
358 
359 		if (project.exists()) {
360 			if (!force) {
361 				// fail if project exists in the workplace (i.e. it is locked)
362 				res = ProjectOpenStatus.LOCKED;
363 			} else {
364 				// remove locked project, reopen new project
365 				project.delete(false, false, null);
366 				project.create(projectDescription, null);
367 				res = ProjectOpenStatus.OPENED;
368 			}
369 		} else {
370 			project.create(projectDescription, null);
371 			res = ProjectOpenStatus.OPENED;
372 		}
373 
374 		if (res == ProjectOpenStatus.OPENED) {
375 			project.open(null);
376 			if (!PROJECT_VERSION.equals(getProperty(project, PROJECT_VERSION_PROPERTY))) {
377 				project.close(null);
378 				project.delete(false, false, null);
379 				return ProjectOpenStatus.INVALID_VERSION;
380 			}
381 			CastApplication.setActiveProject(project);
382 			initializePersistenceProvider(project);
383 		}
384 
385 		return res;
386 
387 	}
388 
389 	/**
390 	 * Removes project from workspace and adds project pointed to by newLocation. Project name is taken from project
391 	 * description stored in newLocation.
392 	 *
393 	 * @param newLocation
394 	 *            new project location
395 	 * @return moved project
396 	 */
397 	public IProject changeProjectLocation(String newLocation) {
398 		IWorkspace workspace = ResourcesPlugin.getWorkspace();
399 		try {
400 			// check if description file exists
401 			IProjectDescription projectDescription = workspace.loadProjectDescription(new FileInputStream(newLocation
402 			        + File.separator + IProjectDescription.DESCRIPTION_FILE_NAME));
403 
404 			IProject project = workspace.getRoot().getProject(projectDescription.getName());
405 
406 			if (!Platform.getLocation().isPrefixOf(Path.fromOSString(newLocation))) {
407 				projectDescription.setLocation(Path.fromOSString(newLocation));
408 			}
409 			project.delete(false, false, null);
410 			project.create(projectDescription, null);
411 			LOG.info("Project " + projectDescription.getName() + " moved to " //$NON-NLS-1$ //$NON-NLS-2$
412 			        + newLocation);
413 			return project;
414 		} catch (FileNotFoundException e) {
415 			e.printStackTrace();
416 		} catch (CoreException e) {
417 			e.printStackTrace();
418 		}
419 		return null;
420 	}
421 
422 	/**
423 	 * Create unique identifier for the project.
424 	 *
425 	 * @return unique project identifier
426 	 */
427 	public String generateProjectId() {
428 		return "CAST_project_" + //$NON-NLS-1$
429 		        System.currentTimeMillis();
430 	}
431 
432 	/**
433 	 * Tries to open a project described by {@link MostRecentlyUsedProject}.
434 	 *
435 	 * @param mrup
436 	 *            project to open
437 	 * @return true if project was correctly opened, or if the operation was cancelled by the user when closing
438 	 *         currently opened editors
439 	 */
440 	public boolean tryOpenRecentProject(MostRecentlyUsedProject mrup) {
441 		ProjectOpenStatus res = ProjectOpenStatus.OPENED;
442 		boolean foundSomewhere = false;
443 
444 		if (!ProjectUtil.getInstance().closeProject(CastApplication.getActiveProject())) {
445 			return true;
446 		}
447 
448 		for (IPath path : mrup.getLocations()) {
449 			try {
450 				res = ProjectUtil.getInstance().openProject(path.toOSString(), false);
451 				switch (res) {
452 					case LOCKED: {
453 						/*
454 						 * openProject returns false but doesn't throw - project can be opened, but exists in current
455 						 * workspace
456 						 */
457 						foundSomewhere = true;
458 						if (ProjectUtil.getInstance().handleExistingProjectAction(path.toOSString())) {
459 							res = ProjectOpenStatus.OPENED;
460 							break;
461 						}
462 						break;
463 					}
464 				}
465 			} catch (FileNotFoundException e) {
466 				LOG.warn("Failed to open project in location " //$NON-NLS-1$
467 				        + path.toOSString(), e);
468 			} catch (CoreException e) {
469 				LOG.warn("Failed to open project " + path.toOSString(), e); //$NON-NLS-1$
470 			}
471 		}
472 		if (res != ProjectOpenStatus.OPENED) {
473 			int rett = SWT.NO;
474 			if (res == ProjectOpenStatus.LOCKED && !foundSomewhere) {
475 				rett = MsgBoxHelper.showWarningQuestionBox(Display.getCurrent().getActiveShell(),
476 				        Messages.ProjectStartupDialog_9, NLS.bind(Messages.ProjectStartupDialog_10, mrup.getName()));
477 			} else if (res == ProjectOpenStatus.INVALID_VERSION) {
478 				rett = MsgBoxHelper.showWarningQuestionBox(Display.getCurrent().getActiveShell(),
479 				        Messages.ProjectUtil_WrongVersionTitle, NLS.bind(Messages.ProjectUtil_WrongVersionMRUMessage,
480 				                mrup.getName(), PROJECT_VERSION));
481 			}
482 			if (rett == SWT.YES) {
483 				UserPreferences.getInstance().removeMRUProject(mrup.getName());
484 			}
485 		}
486 
487 		return res == ProjectOpenStatus.OPENED;
488 	}
489 
490 	/**
491 	 * Closes a project, closing all editors as well. Asks the user for confirmation to save dirty editors.
492 	 *
493 	 * @param project
494 	 *            project to close
495 	 * @return true if all editors were closed
496 	 */
497 	public boolean closeProject(IProject project) {
498 		if (project != null) {
499 			// give the user a chance to save dirty editors
500 			if (PlatformUI.getWorkbench().getActiveWorkbenchWindow() != null) {
501 				if (!PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().closeAllEditors(true)) {
502 					return false;
503 				}
504 			}
505 			try {
506 				project.close(null);
507 				project.delete(false, false, null);
508 				destroyPersistenceProvider();
509 			} catch (CoreException e) {
510 				LOG.error("Failed to close project", e); //$NON-NLS-1$
511 			}
512 		}
513 		return true;
514 	}
515 
516 	public void removeProject(String projectName, IPath location) throws CoreException {
517 		IWorkspace workspace = ResourcesPlugin.getWorkspace();
518 		IProjectDescription pd = workspace.newProjectDescription(projectName);
519 		if (Platform.getLocation() != null && location != null && !Platform.getLocation().isPrefixOf(location)) {
520 			pd.setLocation(location);
521 		} else {
522 			pd.setLocation(null);
523 		}
524 
525 		IProject project = workspace.getRoot().getProject(projectName);
526 
527 		project.delete(true, null);
528 	}
529 
530 	// END Project Management
531 
532 	// BEGIN Project Handlers
533 
534 	/**
535 	 * Handles a situation when a project is already opened by another application.
536 	 *
537 	 * @param location
538 	 *            location of the project
539 	 * @return <code>true</code> if the project was successfully opened
540 	 */
541 	public boolean handleExistingProjectAction(String location) {
542 		int res = MsgBoxHelper.showQuestionBox(CastApplication.getActiveShell(),
543 		        Messages.ApplicationWorkbenchAdvisor_7, NLS.bind(Messages.ApplicationWorkbenchAdvisor_8, location));
544 		if (res == SWT.YES) {
545 			IProject project = changeProjectLocation(location);
546 			if (project != null) {
547 				try {
548 					project.open(null);
549 					CastApplication.setActiveProject(project);
550 					initializePersistenceProvider(project);
551 					return true;
552 				} catch (CoreException e) {
553 					LOG.error("Failed to open locked project", e); //$NON-NLS-1$
554 				}
555 
556 			}
557 		}
558 		return false;
559 	}
560 
561 	/**
562 	 * Handles a situation when no project was selected to be opened. In such case the MRU project is opened, and if
563 	 * that fails, the {@link ProjectStartupDialog} is shown.
564 	 */
565 	public void handleNoProjectAction() {
566 		CastApplication.setActiveProject(null);
567 		if (Boolean.toString(false).equals(
568 		        UserPreferences.getInstance().getPreference(UserPreferences.Pref.SHOW_PROJECT_STARTUP_DIALOG))) {
569 			// open most recent project
570 			MostRecentlyUsedProject mruProject = UserPreferences.getInstance().getMostRecentlyUsedProjects().get(0);
571 			tryOpenRecentProject(mruProject);
572 		} else {
573 			// show startup dialog
574 			ProjectStartupDialog projectStartupDialog = new ProjectStartupDialog(CastApplication.getActiveShell(),
575 			        SWT.APPLICATION_MODAL);
576 			projectStartupDialog.open();
577 		}
578 	}
579 
580 	/**
581 	 * Handles a situation when invalid project location is given.
582 	 *
583 	 * @param location
584 	 *            given project location
585 	 */
586 	public void handleWrongProjectLocationAction(String location) {
587 		MsgBoxHelper.showWarningBox(CastApplication.getActiveShell(), Messages.ApplicationWorkbenchAdvisor_3, NLS.bind(
588 		        Messages.ApplicationWorkbenchAdvisor_4, location));
589 		CastApplication.setActiveProject(null);
590 
591 	}
592 
593 	/**
594 	 * Handles a situation when invalid project is given.
595 	 */
596 	public void handleInvalidProjectAction() {
597 		MsgBoxHelper.showWarningBox(CastApplication.getActiveShell(), Messages.ProjectUtil_WrongVersionTitle, NLS.bind(
598 		        Messages.ProjectUtil_WrongVersionMessage, PROJECT_VERSION));
599 		CastApplication.setActiveProject(null);
600 	}
601 
602 	/**
603 	 * Handles a situation when project location does not contain <code>.project</code>file.
604 	 *
605 	 * @param location
606 	 *            project location
607 	 */
608 	public void handleMissingProjectFile(String location) {
609 		MsgBoxHelper.showWarningBox(CastApplication.getActiveShell(), Messages.ApplicationWorkbenchAdvisor_3, NLS.bind(
610 		        Messages.ApplicationWorkbenchAdvisor_9, location));
611 		CastApplication.setActiveProject(null);
612 
613 	}
614 
615 	/**
616 	 * Handles a situation when invalid project is given.
617 	 */
618 	public void handlePersistenceProviderInitializationError(IProject project) {
619 		MsgBoxHelper.showWarningBox(CastApplication.getActiveShell(), Messages.ProjectUtil_InitializationErrorTitle,
620 		        NLS.bind(Messages.ProjectUtil_InitializationErrorMessage_Persistence, project.getName()));
621 		CastApplication.setActiveProject(null);
622 	}
623 
624 	// END Project Handlers
625 
626 	/**
627 	 * Property change notification.
628 	 *
629 	 * {@inheritDoc}
630 	 *
631 	 * @see java.beans.PropertyChangeListener#propertyChange(java.beans.PropertyChangeEvent)
632 	 */
633 	public void propertyChange(PropertyChangeEvent evt) {
634 		if (CastApplication.PROPERTY_ACTIVE_PROJECT.equals(evt.getPropertyName())) {
635 			if (evt.getNewValue() != null) {
636 				UserPreferences.getInstance().registerMostRecentlyUsedProject((IProject)evt.getNewValue());
637 			}
638 		}
639 	}
640 
641 	// BEGIN Persistence Provider
642 
643 	/**
644 	 * Initializes persistence provider for given project.
645 	 *
646 	 * @param project
647 	 *            the project
648 	 */
649 	@SuppressWarnings("nls")
650 	public void initializePersistenceProvider(IProject project) {
651 		String providerId = getProperty(project, PERSISTENCE_PROVIDER_ID_PROPERTY);
652 		String providerConfig = getProperty(project, PERSISTENCE_PROVIDER_CONFIG_PROPERTY);
653 		IFile configFile = project.getFile(providerConfig);
654 		try {
655 			IPersistenceProvider provider = PersistenceProviderLocator.createPersistenceProvider(providerId, configFile
656 			        .getLocation().toOSString());
657 			CoreServiceLocator.getPersistenceProvider().setActualProvider(provider);
658 		} catch (PersistenceException e) {
659 			LOG.error(String.format("Failed to initialize persistence provider for project '{0}' ({1}). "
660 			        + "\r\nProviderId={2}\r\n persistence file:{3}", project.getName(), project.getLocation()
661 			        .toOSString(), providerId, providerConfig), e);
662 			handlePersistenceProviderInitializationError(project);
663 		}
664 	}
665 
666 	/**
667 	 * Destroys persistence provider for active project.
668 	 */
669 	public void destroyPersistenceProvider() {
670 		CoreServiceLocator.getPersistenceProvider().setActualProvider(null);
671 	}
672 
673 	// END Persistence Provider
674 
675 }