1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-30 03:33:37 +02:00

[224671][api] Fix non-API leakage of ISystemResourceConstants

This commit is contained in:
Martin Oberhuber 2008-03-28 16:29:36 +00:00
parent e6d64d4104
commit 4e9af07bbc

View file

@ -1,5 +1,5 @@
/******************************************************************************** /********************************************************************************
* Copyright (c) 2006, 2007 IBM Corporation and others. All rights reserved. * Copyright (c) 2006, 2008 IBM Corporation and others. All rights reserved.
* This program and the accompanying materials are made available under the terms * This program and the accompanying materials are made available under the terms
* of the Eclipse Public License v1.0 which accompanies this distribution, and is * of the Eclipse Public License v1.0 which accompanies this distribution, and is
* available at http://www.eclipse.org/legal/epl-v10.html * available at http://www.eclipse.org/legal/epl-v10.html
@ -11,7 +11,7 @@
* Emily Bruner, Mazen Faraj, Adrian Storisteanu, Li Ding, and Kent Hawley. * Emily Bruner, Mazen Faraj, Adrian Storisteanu, Li Ding, and Kent Hawley.
* *
* Contributors: * Contributors:
* Dave McKnight (IBM) - [177155] Move from rse.ui/systems/org.eclipse.rse.core * David McKnight (IBM) - [177155] Move from rse.ui/systems/org.eclipse.rse.core
* Martin Oberhuber (Wind River) - Re-add missing methods for user actions * Martin Oberhuber (Wind River) - Re-add missing methods for user actions
* David Dykstal (IBM) - [189858] delayed the creation of the remote systems project * David Dykstal (IBM) - [189858] delayed the creation of the remote systems project
* removed unneeded first time logic and flags * removed unneeded first time logic and flags
@ -21,6 +21,7 @@
* API to the user actions plugin * API to the user actions plugin
* David Dykstal (IBM) - [191130] remove getRemoteSystemsProject() and getProfileFolder() * David Dykstal (IBM) - [191130] remove getRemoteSystemsProject() and getProfileFolder()
* as part of the work to removed the exception printed at startup. * as part of the work to removed the exception printed at startup.
* Martin Oberhuber (Wind River) - [224671] Fix non-API leakage of ISystemResourceConstants
********************************************************************************/ ********************************************************************************/
package org.eclipse.rse.core; package org.eclipse.rse.core;
@ -46,22 +47,26 @@ import org.eclipse.rse.internal.core.SystemResourceConstants;
/** /**
* Static methods that manage the workbench resource tree for the remote systems project. * Static methods that manage the workbench resource tree for the remote systems
* All code in the framework uses this to access the file system for save/restore purposes. * project. All code in the framework uses this to access the file system for
* By limiting all access to one place, we simply changes should we decide to change the * save/restore purposes. By limiting all access to one place, we simply changes
* underlying file system map. * should we decide to change the underlying file system map.
* <p> * <p>
* <b>Assumptions</b> * <b>Assumptions</b>
* <ul> * <ul>
* <li>Each SystemConnectionPool object manages the connections for a given system profile * <li>Each SystemConnectionPool object manages the connections for a given
* <li>Each SystemFilterPoolManager object manages the filter pools for a given subsystem factory, * system profile
* for a given system profile! * <li>Each SystemFilterPoolManager object manages the filter pools for a given
* <li>Each SystemFilterPool object is an arbitrary named collection of filters all stored * subsystem factory, for a given system profile!
* in one folder on disk with the same name as the pool. * <li>Each SystemFilterPool object is an arbitrary named collection of filters
* all stored in one folder on disk with the same name as the pool.
* </ul> * </ul>
* <p> * <p>
*
* @noextend This class is not intended to be subclassed by clients.
* @noinstantiate This class is not intended to be instantiated by clients.
*/ */
public class SystemResourceManager implements SystemResourceConstants public class SystemResourceManager
{ {
private static IProject remoteSystemsProject = null; private static IProject remoteSystemsProject = null;
@ -71,61 +76,61 @@ public class SystemResourceManager implements SystemResourceConstants
private static ISystemResourceListener _listener = null; private static ISystemResourceListener _listener = null;
/** /**
* Turn off event listening. Please call this before do anything that modifies resources and * Turn off event listening. Please call this before do anything that modifies resources and
* turn it on again after. * turn it on again after.
*/ */
public static void turnOffResourceEventListening() public static void turnOffResourceEventListening()
{ {
if (_listener != null) if (_listener != null)
_listener.turnOffResourceEventListening(); _listener.turnOffResourceEventListening();
} }
/** /**
* Turn off event listening. Please call this after modifying resources. * Turn off event listening. Please call this after modifying resources.
*/ */
public static void turnOnResourceEventListening() public static void turnOnResourceEventListening()
{ {
if (_listener != null) if (_listener != null)
_listener.turnOnResourceEventListening(); _listener.turnOnResourceEventListening();
} }
/** /**
* Ensure event listening is on. Called at start of team synch action to be safe. * Ensure event listening is on. Called at start of team synch action to be safe.
*/ */
public static void ensureOnResourceEventListening() public static void ensureOnResourceEventListening()
{ {
if (_listener != null) if (_listener != null)
_listener.ensureOnResourceEventListening(); _listener.ensureOnResourceEventListening();
} }
/** /**
* Start event listening. Requests to turn on and off are ignored until this is called, * Start event listening. Requests to turn on and off are ignored until this is called,
* which is at the appropriate point in the startup sequence. * which is at the appropriate point in the startup sequence.
*/ */
public static void startResourceEventListening(ISystemResourceListener listener) public static void startResourceEventListening(ISystemResourceListener listener)
{ {
_listener = listener; _listener = listener;
listener.turnOnResourceEventListening(); listener.turnOnResourceEventListening();
IWorkspace ws = remoteSystemsProject.getWorkspace(); IWorkspace ws = remoteSystemsProject.getWorkspace();
int eventMask = IResourceChangeEvent.POST_CHANGE; int eventMask = IResourceChangeEvent.POST_CHANGE;
// add listener for global events ; // add listener for global events ;
ws.addResourceChangeListener(listener, eventMask); ws.addResourceChangeListener(listener, eventMask);
} }
/** /**
* End event listening. Requests to turn on and off are ignored after this is called, * End event listening. Requests to turn on and off are ignored after this is called,
* which is at the appropriate point in the shutdown sequence. * which is at the appropriate point in the shutdown sequence.
*/ */
public static void endResourceEventListening() public static void endResourceEventListening()
{ {
if (_listener != null) if (_listener != null)
{ {
IWorkspace ws = remoteSystemsProject.getWorkspace(); IWorkspace ws = remoteSystemsProject.getWorkspace();
ws.removeResourceChangeListener(_listener); ws.removeResourceChangeListener(_listener);
_listener = null; _listener = null;
} }
} }
/** /**
* Register a listener for resource change events on objects in our remote system project. * Register a listener for resource change events on objects in our remote system project.
@ -139,7 +144,7 @@ public class SystemResourceManager implements SystemResourceConstants
public static void addResourceChangeListener(IResourceChangeListener l) public static void addResourceChangeListener(IResourceChangeListener l)
{ {
if (_listener != null) if (_listener != null)
_listener.addResourceChangeListener(l); _listener.addResourceChangeListener(l);
} }
/** /**
* Remove a listener for resource change events on an object in our remote system project. * Remove a listener for resource change events on an object in our remote system project.
@ -147,7 +152,7 @@ public class SystemResourceManager implements SystemResourceConstants
public static void removeResourceChangeListener(IResourceChangeListener l) public static void removeResourceChangeListener(IResourceChangeListener l)
{ {
if (_listener != null) if (_listener != null)
_listener.removeResourceChangeListener(l); _listener.removeResourceChangeListener(l);
} }
/** /**
@ -160,7 +165,7 @@ public class SystemResourceManager implements SystemResourceConstants
*/ */
public static IProject getRemoteSystemsProject(boolean force) { public static IProject getRemoteSystemsProject(boolean force) {
if (remoteSystemsProject == null) { if (remoteSystemsProject == null) {
remoteSystemsProject = ResourcesPlugin.getWorkspace().getRoot().getProject(RESOURCE_PROJECT_NAME); remoteSystemsProject = ResourcesPlugin.getWorkspace().getRoot().getProject(SystemResourceConstants.RESOURCE_PROJECT_NAME);
} }
if ((!remoteSystemsProject.exists() && force) || (remoteSystemsProject.exists() && !remoteSystemsProject.isOpen())) { if ((!remoteSystemsProject.exists() && force) || (remoteSystemsProject.exists() && !remoteSystemsProject.isOpen())) {
ensureRemoteSystemsProject(remoteSystemsProject); ensureRemoteSystemsProject(remoteSystemsProject);
@ -168,7 +173,7 @@ public class SystemResourceManager implements SystemResourceConstants
return remoteSystemsProject; return remoteSystemsProject;
} }
/** /**
* Get the default remote systems temp files project. * Get the default remote systems temp files project.
* @return IProject handle of the project. Use exists() to test existence. * @return IProject handle of the project. Use exists() to test existence.
*/ */
@ -176,17 +181,17 @@ public class SystemResourceManager implements SystemResourceConstants
{ {
if (remoteSystemsTempFilesProject == null) if (remoteSystemsTempFilesProject == null)
{ {
remoteSystemsTempFilesProject = ResourcesPlugin.getWorkspace().getRoot().getProject(RESOURCE_TEMPFILES_PROJECT_NAME); remoteSystemsTempFilesProject = ResourcesPlugin.getWorkspace().getRoot().getProject(SystemResourceConstants.RESOURCE_TEMPFILES_PROJECT_NAME);
} }
return remoteSystemsTempFilesProject; return remoteSystemsTempFilesProject;
} }
/** /**
* Create a remote systems project, plus the core subfolders required. * Create a remote systems project, plus the core subfolders required.
* @param proj the handle for the remote systems project * @param proj the handle for the remote systems project
* @return the IProject handle of the project (the argument) * @return the IProject handle of the project (the argument)
*/ */
private static IProject ensureRemoteSystemsProject(IProject proj) private static IProject ensureRemoteSystemsProject(IProject proj)
{ {
// Check first for the project to be closed. If yes, try to open it and if this fails, // Check first for the project to be closed. If yes, try to open it and if this fails,
// try to delete if first before failing here. The case is that the user removed the // try to delete if first before failing here. The case is that the user removed the
// directory in the workspace and we must be able to recover from it. // directory in the workspace and we must be able to recover from it.
@ -219,146 +224,146 @@ public class SystemResourceManager implements SystemResourceConstants
return proj; return proj;
} }
// ------------------- // -------------------
// FOLDER ACTIONS... // FOLDER ACTIONS...
// ------------------- // -------------------
/** /**
* Rename a folder * Rename a folder
*/ */
public static void renameFolder(IFolder folder, String newName) public static void renameFolder(IFolder folder, String newName)
{ {
getResourceHelpers().renameResource(folder, newName); getResourceHelpers().renameResource(folder, newName);
} }
/** /**
* Delete a folder * Delete a folder
*/ */
public static void deleteFolder(IFolder folder) public static void deleteFolder(IFolder folder)
{ {
getResourceHelpers().deleteResource(folder); getResourceHelpers().deleteResource(folder);
} }
// ------------------- // -------------------
// FILE ACTIONS... // FILE ACTIONS...
// ------------------- // -------------------
/** /**
* Rename a file * Rename a file
*/ */
public static void renameFile(IFolder folder, String oldName, String newName) public static void renameFile(IFolder folder, String oldName, String newName)
{ {
getResourceHelpers().renameResource( getResourceHelpers().renameResource(
getResourceHelpers().getFile(folder,oldName), newName); getResourceHelpers().getFile(folder,oldName), newName);
} }
/** /**
* Delete a file * Delete a file
*/ */
public static void deleteFile(IFolder folder, String fileName) public static void deleteFile(IFolder folder, String fileName)
{ {
getResourceHelpers().deleteResource( getResourceHelpers().deleteResource(
getResourceHelpers().getFile(folder, fileName)); getResourceHelpers().getFile(folder, fileName));
} }
// ------------------- // -------------------
// GENERIC HELPERS... // GENERIC HELPERS...
// ------------------- // -------------------
/** /**
* Map a connection pool name to a profile name. * Map a connection pool name to a profile name.
* Current algorith is that pool name equals profile name, but we use * Current algorith is that pool name equals profile name, but we use
* this method to allow flexibility in the future. * this method to allow flexibility in the future.
*/ */
public static String getProfileName(ISystemHostPool pool) public static String getProfileName(ISystemHostPool pool)
{ {
return pool.getName(); return pool.getName();
} }
/** /**
* Map a filter pool manager name to a profile name * Map a filter pool manager name to a profile name
* Current algorith is that manager name equals profile name, but we use * Current algorith is that manager name equals profile name, but we use
* this method to allow flexibility in the future. * this method to allow flexibility in the future.
*/ */
public static String getProfileName(ISystemFilterPoolManager mgr) public static String getProfileName(ISystemFilterPoolManager mgr)
{ {
return mgr.getName(); return mgr.getName();
} }
/** /**
* Map a filter pool name to a folder name * Map a filter pool name to a folder name
* Current algorith is that pool name equals folder name, but we use * Current algorith is that pool name equals folder name, but we use
* this method to allow flexibility in the future. * this method to allow flexibility in the future.
*/ */
public static String getFolderName(ISystemFilterPool pool) public static String getFolderName(ISystemFilterPool pool)
{ {
return pool.getName(); return pool.getName();
} }
/** /**
* Map a system connection object to a folder name * Map a system connection object to a folder name
*/ */
public static String getFolderName(IHost conn) public static String getFolderName(IHost conn)
{ {
return conn.getAliasName(); return conn.getAliasName();
} }
/** /**
* Map a subsystem factory object to a folder name * Map a subsystem factory object to a folder name
*/ */
public static String getFolderName(ISubSystemConfiguration ssFactory) public static String getFolderName(ISubSystemConfiguration ssFactory)
{ {
return ssFactory.getId(); // Should we use name instead?? Can we assume the name is unique? return ssFactory.getId(); // Should we use name instead?? Can we assume the name is unique?
} }
/** /**
* Given any folder, return its path as a string. * Given any folder, return its path as a string.
*/ */
public static String getFolderPath(IFolder folder) public static String getFolderPath(IFolder folder)
{ {
return getResourceHelpers().getFolderPath(folder); return getResourceHelpers().getFolderPath(folder);
} }
/** /**
* Given any folder, return its path as a string, and an ending '\' * Given any folder, return its path as a string, and an ending '\'
*/ */
public static String getFolderPathWithTerminator(IFolder folder) public static String getFolderPathWithTerminator(IFolder folder)
{ {
return addPathTerminator(getResourceHelpers().getFolderPath(folder)); return addPathTerminator(getResourceHelpers().getFolderPath(folder));
} }
/** /**
* Return singleton of resource helpers object * Return singleton of resource helpers object
*/ */
protected static SystemResourceHelpers getResourceHelpers() protected static SystemResourceHelpers getResourceHelpers()
{ {
if (helpers == null) if (helpers == null)
{ {
helpers = SystemResourceHelpers.getResourceHelpers(); helpers = SystemResourceHelpers.getResourceHelpers();
//helpers.setLogFile(RSEUIPlugin.getDefault().getLogFile()); //helpers.setLogFile(RSEUIPlugin.getDefault().getLogFile());
} }
return helpers; return helpers;
} }
/** /**
* Ensure given path ends with path separator. * Ensure given path ends with path separator.
*/ */
public static String addPathTerminator(String path) public static String addPathTerminator(String path)
{ {
if (!path.endsWith(File.separator)) if (!path.endsWith(File.separator))
path = path + File.separatorChar; path = path + File.separatorChar;
//else //else
// path = path; // path = path;
return path; return path;
} }
/** /**
* Test if a resource is in use, prior to attempting to rename or delete it. * Test if a resource is in use, prior to attempting to rename or delete it.
* @return true if it is in use or read only, false if it is not. * @return true if it is in use or read only, false if it is not.
*/ */
public static boolean testIfResourceInUse(IResource resource) public static boolean testIfResourceInUse(IResource resource)
{ {
return SystemResourceHelpers.testIfResourceInUse(resource); return SystemResourceHelpers.testIfResourceInUse(resource);
} }
} }