1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-19 14:15:50 +02:00

[186640][api] Add IRSESystemType.testProperty()

This commit is contained in:
Martin Oberhuber 2007-05-14 08:52:32 +00:00
parent 9244d48204
commit 7270445898
2 changed files with 215 additions and 12 deletions

View file

@ -0,0 +1,179 @@
/********************************************************************************
* Copyright (c) 2006, 2007 IBM Corporation and others. All rights reserved.
* 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
* available at http://www.eclipse.org/legal/epl-v10.html
*
* Initial Contributors:
* The following IBM employees contributed to the Remote System Explorer
* component that contains this file: David McKnight, Kushal Munir,
* Michael Berger, David Dykstal, Phil Coulthard, Don Yantzi, Eric Simpson,
* Emily Bruner, Mazen Faraj, Adrian Storisteanu, Li Ding, and Kent Hawley.
*
* Contributors:
* Uwe Stieber (Wind River) - Dynamic system type provider extension.
* Martin Oberhuber (Wind River) - [184095] Replace systemTypeName by IRSESystemType
* Martin Oberhuber (Wind River) - [186640] Add IRSESystemType.testProperty()
********************************************************************************/
package org.eclipse.rse.core;
import java.util.HashMap;
import java.util.Map;
import org.eclipse.core.runtime.PlatformObject;
import org.osgi.framework.Bundle;
/**
* Abstract base class holding core functionality of a system type.
*
* Extenders must override {@link IRSESystemType#getSubsystemConfigurationIds()}
* according to their strategy of finding subsystem configuration id's that
* match their system type.
*
* Extenders may override any other method.
*/
public abstract class AbstractRSESystemType extends PlatformObject implements IRSESystemType {
protected String id = null;
protected String name = null;
protected String label = null;
protected String description = null;
protected Bundle definingBundle = null;
protected Map properties;
/**
* Default constructor.
* Only subclasses may call this if set the id, name, label,
* description and properties attributes themselves.
*/
protected AbstractRSESystemType()
{
super();
}
/**
* Constructor for an object representing a system type.
* @param id unique id of this system type. Must be system unique.
* @param name a name of this system type to be used for internal checks.
* @param label a user-visible label of this system type.
* May be <code>null</code> and falls back to the name in this case.
* @param description a user-visible description of this system type.
* May be <code>null</code> and falls back to the label in this case.
*/
public AbstractRSESystemType(String id, String name, String label, String description, Bundle definingBundle)
{
super();
this.id = id;
this.name = name;
this.label = label == null ? name : label;
this.description = description == null ? "" : description; //$NON-NLS-1$
this.definingBundle = definingBundle;
this.properties = new HashMap();
}
/**
* Checks whether two system types are the same.
*
* System types are considered the same if they have the same ID.
*/
public boolean equals(Object obj) {
if (obj instanceof IRSESystemType) {
return id.equals( ((IRSESystemType)obj).getId() );
}
return false;
}
/**
* Returns the hashCode for this system type.
*
* The hashCode is the hashCode of its ID.
*/
public int hashCode() {
return id.hashCode();
}
/* (non-Javadoc)
* @see org.eclipse.rse.core.IRSESystemType#getId()
*/
public String getId() {
return id;
}
/* (non-Javadoc)
* @see org.eclipse.rse.core.IRSESystemType#getLabel()
*/
public String getLabel() {
// For default RSE system types, the UI label is equal to the
// name. Therefore, fallback to the name if the label is not
// explicitly set.
if (label == null) return getName();
return label;
}
/*
* (non-Javadoc)
* @see org.eclipse.rse.core.IRSESystemType#getName()
*/
public String getName() {
return name;
}
/* (non-Javadoc)
* @see org.eclipse.rse.core.IRSESystemType#getDescription()
*/
public String getDescription() {
return description;
}
/*
* (non-Javadoc)
* @see org.eclipse.rse.core.IRSESystemType#getDefiningBundle()
*/
public Bundle getDefiningBundle() {
return definingBundle;
}
/* (non-Javadoc)
* @see org.eclipse.rse.core.IRSESystemType#getProperty(java.lang.String)
*/
public String getProperty(String key) {
return (String) (properties.get(key));
}
/* (non-Javadoc)
* @see org.eclipse.rse.core.IRSESystemType#getProperty(java.lang.String, boolean)
*/
public boolean testProperty(String key, boolean defaultValue) {
Object val = properties.get(key);
if (val instanceof String) {
return Boolean.valueOf((String)val).booleanValue();
}
return defaultValue;
}
/*
* (non-Javadoc)
* @see org.eclipse.rse.core.IRSESystemType#isLocal()
*/
public boolean isLocal() {
return IRSESystemType.SYSTEMTYPE_LOCAL_ID.equals(getId())
|| testProperty(IRSESystemType.PROPERTY_IS_LOCAL, true);
}
/*
* (non-Javadoc)
* @see org.eclipse.rse.core.IRSESystemType#isLocal()
*/
public boolean isWindows() {
return IRSESystemType.SYSTEMTYPE_WINDOWS_ID.equals(getId())
|| (isLocal() && System.getProperty("os.name").toLowerCase().startsWith("win")) //$NON-NLS-1$ //$NON-NLS-2$
|| testProperty(IRSESystemType.PROPERTY_IS_WINDOWS, true);
}
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
public String toString() {
return getLabel() + " (" + getId() + ")"; //$NON-NLS-1$ //$NON-NLS-2$
}
}

View file

@ -13,7 +13,7 @@
* Contributors: * Contributors:
* Uwe Stieber (Wind River) - Extended system type -> subsystemConfiguration association. * Uwe Stieber (Wind River) - Extended system type -> subsystemConfiguration association.
* Martin Oberhuber (Wind River) - [185098] Provide constants for all well-known system types * Martin Oberhuber (Wind River) - [185098] Provide constants for all well-known system types
* Martin Oberhuber (Wind River) - [186640] Add IRSESystemTyep.isLocal() * Martin Oberhuber (Wind River) - [186640] Add IRSESystemType.testProperty()
********************************************************************************/ ********************************************************************************/
package org.eclipse.rse.core; package org.eclipse.rse.core;
@ -26,7 +26,7 @@ import org.osgi.framework.Bundle;
* These constants are kept in sync with definitions in plugin.xml. * These constants are kept in sync with definitions in plugin.xml.
* *
* This interface is not intended to be implemented directly by clients. * This interface is not intended to be implemented directly by clients.
* Clients should extend the abstract base class {@link RSESystemType} instead. * Clients should extend the abstract base class {@link AbstractRSESystemType} instead.
*/ */
public interface IRSESystemType extends IAdaptable { public interface IRSESystemType extends IAdaptable {
@ -147,6 +147,19 @@ public interface IRSESystemType extends IAdaptable {
/** Telnet Only system type, "org.eclipse.rse.systemtype.telnet". */ /** Telnet Only system type, "org.eclipse.rse.systemtype.telnet". */
public static final String SYSTEMTYPE_TELNET_ONLY_ID = "org.eclipse.rse.systemtype.telnet"; //$NON-NLS-1$ public static final String SYSTEMTYPE_TELNET_ONLY_ID = "org.eclipse.rse.systemtype.telnet"; //$NON-NLS-1$
/**
* System type Property Key (value: "isLocal") indicating whether
* a system type is declared in plugin.xml to refers to the local
* system.
* On a the local system, the following properties are expected:
* <ul>
* <li>Subsystem Queries are fast and safe.</li>
* <li>Files in the file system can be converted to java.io.File.</li>
* </ul>
* @see #testProperty(String, boolean)
*/
public static final String PROPERTY_IS_LOCAL = "isLocal"; //$NON-NLS-1$
/** /**
* System type Property Key (value: "isWindows") indicating whether * System type Property Key (value: "isWindows") indicating whether
* a system type is declared in plugin.xml to refers to a Windows * a system type is declared in plugin.xml to refers to a Windows
@ -158,14 +171,14 @@ public interface IRSESystemType extends IAdaptable {
* <li>Symbolic links are not supported</li> * <li>Symbolic links are not supported</li>
* <li>"cmd" is used as the default shell</li> * <li>"cmd" is used as the default shell</li>
* </ul> * </ul>
* @see #getProperty(String, boolean) * @see #testProperty(String, boolean)
*/ */
public static final String PROPERTY_IS_WINDOWS = "isWindows"; //$NON-NLS-1$ public static final String PROPERTY_IS_WINDOWS = "isWindows"; //$NON-NLS-1$
/** /**
* System type Property Key (value: "isCaseSensitive") indicating * System type Property Key (value: "isCaseSensitive") indicating
* whether a given system type is in general case sensitive. * whether a given system type is in general case sensitive.
* @see #getProperty(String, boolean) * @see #testProperty(String, boolean)
*/ */
public static final String PROPERTY_IS_CASE_SENSITIVE = "isCaseSensitive"; //$NON-NLS-1$ public static final String PROPERTY_IS_CASE_SENSITIVE = "isCaseSensitive"; //$NON-NLS-1$
@ -206,18 +219,26 @@ public interface IRSESystemType extends IAdaptable {
public String getProperty(String key); public String getProperty(String key);
/** /**
* Returns the boolean property of this system type with the given key. * Tests whether the given boolean property matches the expected value
* The default value is returned if there is no such key. * for this system type.
* *
* @param key the name of the property to return * @param key the name of the property to return
* @param defaultValue the default value to expect if the property is not set * @param expectedValue the expected boolean value of the property.
* @return the boolean value associated with the given key or the specified default value * @return <code>true</code> if the Property is set on the system type and
* matches the expected value. Returns <code>false</code> if the property
* is not set or does not match.
*/ */
public boolean getProperty(String key, boolean defaultValue); public boolean testProperty(String key, boolean expectedValue);
/** /**
* Tests whether the system type refers to the local system. * Tests whether the system type refers to the local system.
* This is a shortcut for getId().equals(SYSTEMTYPE_LOCAL_ID) * This is a shortcut for
* <pre>
* getId().equals(SYSTEMTYPE_LOCAL_ID) ||
* || getProperty(PROPERTY_IS_LOCAL, false)
* </pre>
* See {@link #PROPERTY_IS_LOCAL} for properties expected on
* a Local system.
* Extenders (contributors of custom system types) may override. * Extenders (contributors of custom system types) may override.
* @return true if the system type refers to the local system. * @return true if the system type refers to the local system.
*/ */
@ -227,9 +248,12 @@ public interface IRSESystemType extends IAdaptable {
* Tests whether the system type refers to the Windows system. * Tests whether the system type refers to the Windows system.
* This is a shortcut for * This is a shortcut for
* <pre> * <pre>
* getId().equals(SYSTEMTYPE_WINDOWS_ID) || * getId().equals(SYSTEMTYPE_WINDOWS_ID)
* isLocal() && System.getProperty("os.name").toLowerCase().startsWith("win") * || isLocal() && System.getProperty("os.name").toLowerCase().startsWith("win")
* || getProperty(PROPERTY_IS_WINDOWS, false)
* </pre> * </pre>
* See {@link #PROPERTY_IS_WINDOWS} for properties expected on
* a Windows system.
* Extenders (contributors of custom system types) may override. * Extenders (contributors of custom system types) may override.
* @return true if the system type refers to a Windows system. * @return true if the system type refers to a Windows system.
*/ */