`
salever
  • 浏览: 254642 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

Eclipse Property Testers (Test expression) 的使用

    博客分类:
  • RCP
阅读更多

Eclipse Resource Plugin里面很多值得一看的东西,其中一个就是Property Testers ,它在某些条件过滤的时候非常有用,先看一段jdt里面的使用

      <page
            objectClass="org.eclipse.core.resources.IProject"
            name="%javaCategoryPageName"
            class="org.eclipse.jdt.internal.ui.preferences.JavaCategoryPropertyPage"
            id="org.eclipse.jdt.ui.propertyPages.JavaCategoryPropertyPage">
         <enabledWhen>
		     <adapt type="org.eclipse.core.resources.IProject">
		          <test property="org.eclipse.core.resources.projectNature" value="org.eclipse.jdt.core.javanature"/>
		     </adapt>         
         </enabledWhen>
      </page>

 这里的

org.eclipse.core.resources.projectNature

就是eclipse已经定义好的property。

 

 

简介

扩展点:org.eclipse.core.expressions.propertyTesters

 

作用:用来给一个已知的类型添加属性测试支持,新添加的属性可以用于各种表达式条件判断。

 

扩展语法:

<!ELEMENT propertyTester EMPTY>

<!ATTLIST propertyTester
    id    CDATA #REQUIRED
    type   CDATA #REQUIRED
   namespace  CDATA #REQUIRED
   properties CDATA #REQUIRED
   class  CDATA #REQUIRED>

  引用一下Eclipse自己的解释:

  • id - unique identifier for the property tester
  • type - the type to be extended by this property tester
  • namespace - a unique id determining the name space the properties are added to
  • properties - a comma separated list of properties provided by this property tester
  • class - the name of the class that implements the testing methods. The class must be public and extend org.eclipse.core.expressions.PropertyTester with a public 0-argument constructor.

示例

     <extension
           point="org.eclipse.core.expressions.propertyTesters">
        <propertyTester
              id="org.eclipse.core.expressions.bundlePropertyTester"
              type="org.eclipse.core.runtime.Platform"
              namespace="org.eclipse.core.runtime"
              properties="product,isBundleInstalled,bundleState"
              class="org.eclipse.core.internal.expressions.propertytester.PlatformPropertyTester">
        </propertyTester>
     </extension>

 

很简单的一个使用,这些都在eclipse的文档里面说的很清楚了。

 

至于org.eclipse.core.expressions.PropertyTester 如何扩展,也很简单,一般只需要实现test (Object receiver, String property, Object[] args,  Object expectedValue)方法就行了。比如:

/*******************************************************************************
 * Copyright (c) 2006, 2008 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
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.core.internal.expressions.propertytester;

import org.osgi.framework.Bundle;

import org.eclipse.core.expressions.PropertyTester;

import org.eclipse.core.runtime.IProduct;
import org.eclipse.core.runtime.Platform;

/**
 * A property tester for testing platform properties. Can test whether or
 * not a given bundle is installed in the running environment, as well as
 * the id of the currently active product.
 * <p>
 * For example:<br />
 * &lt;test property="org.eclipse.core.runtime.product" value="org.eclipse.sdk.ide"/&gt; <br />
 * &lt;test property="org.eclipse.core.runtime.isBundleInstalled" args="org.eclipse.core.expressions"/&gt; <br />
 * &lt;test property="org.eclipse.core.runtime.bundleState" args="org.eclipse.core.expressions" value="ACTIVE"/&gt;
 * <p>
 */
public class PlatformPropertyTester extends PropertyTester {

	private static final String PROPERTY_PRODUCT = "product"; //$NON-NLS-1$
	private static final String PROPERTY_IS_BUNDLE_INSTALLED = "isBundleInstalled"; //$NON-NLS-1$
	private static final String PROPERTY_BUNDLE_STATE = "bundleState"; //$NON-NLS-1$

	/* (non-Javadoc)
	 * @see org.eclipse.core.expressions.IPropertyTester#test(java.lang.Object, java.lang.String, java.lang.Object[], java.lang.Object)
	 */
	public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
		if (Platform.class.equals(receiver)) {
			if (PROPERTY_PRODUCT.equals(property)) {
				IProduct product= Platform.getProduct();
				if (product != null) {
					return product.getId().equals(expectedValue);
				}
				return false;
			} else if (PROPERTY_IS_BUNDLE_INSTALLED.equals(property) && args.length >= 1 && args[0] instanceof String) {
				return Platform.getBundle((String)args[0]) != null;
			} else if (PROPERTY_BUNDLE_STATE.equals(property)
					&& args.length >= 1 && args[0] instanceof String) {
				Bundle b = Platform.getBundle((String) args[0]);
				if (b != null) {
					return bundleState(b.getState(), expectedValue);
				}
				return false;
			}
		}
		return false;
	}

	private boolean bundleState(int bundleState, Object expectedValue) {
		if ("UNINSTALLED".equals(expectedValue)) { //$NON-NLS-1$
			return bundleState == Bundle.UNINSTALLED;
		}
		if ("INSTALLED".equals(expectedValue)) { //$NON-NLS-1$
			return bundleState == Bundle.INSTALLED;
		}
		if ("RESOLVED".equals(expectedValue)) { //$NON-NLS-1$
			return bundleState == Bundle.RESOLVED;
		}
		if ("STARTING".equals(expectedValue)) { //$NON-NLS-1$
			return bundleState == Bundle.STARTING;
		}
		if ("STOPPING".equals(expectedValue)) { //$NON-NLS-1$
			return bundleState == Bundle.STOPPING;
		}
		if ("ACTIVE".equals(expectedValue)) { //$NON-NLS-1$
			return bundleState == Bundle.ACTIVE;
		}
		return false;
	}
}
 

 

分享到:
评论
1 楼 zxjlwt 2015-08-25  
学习了。

http://surenpi.com

相关推荐

    Python Unit Test Automation:for Python Developers and Testers

    All of which makes this book a great resource for software developers and testers who want to get started with unit test automation in Python 3 and compare the differences with Python 2. This short ...

    Google Hacking for Penetration Testers

    ### Google Hacking for Penetration Testers #### 一、基础知识:Google 搜索技巧入门 - **Web界面操作**:本书首先介绍了如何有效地利用Google的Web界面进行搜索,包括如何构建有效的查询语句以及如何理解Google...

    VSTS For Testers初探

    &lt;br&gt;一、概述 3 1)VSTT简介 3 2)测试类型 3 3)Team Test 命名空间 6 二、Web 测试 7 1)概述 7 2)测试引擎和测试记录器 7 3)录制WebTest 8 4)编辑WebTest 10 5)WebTest查看器...

    soapui-eclipse-plugin 3.0 part4

    soapUI is a desktop application for inspecting, invoking, mocking and testing (functional and load) of SOAP/WSDL and REST/EADL based Web Services over HTTP. It is mainly aimed at developers/testers ...

    fastlane-plugin-clean_testflight_testers.zip

    `fastlane-plugin-clean_testflight_testers` 插件是针对 `fastlane` 平台的一个扩展,专门用于解决TestFlight中的测试用户管理问题,特别是自动化删除用户这一任务,以配合“超级签”(Super Signature)的使用。...

    Effective Software Test Automation

    To ensure software quality, organizations encourage software developers and testers to achieve objectives such as these: Locating the source of defects faster and more precisely Detecting bugs ...

    TestComplete Cookbook(PACKT,2013)

    TestComplete is an automated testing tool, designed for advanced and novice testers alike, to create, manage and run tests for any desktop, Web or rich client software. It does not depend on any ...

    Agile Testing A Practical Guide for Testers and Agile Teams epub

    Agile Testing A Practical Guide for Testers and Agile Teams 英文epub 本资源转载自网络,如有侵权,请联系上传者或csdn删除

    跟我一起学Visual Studio 2005(23):Team Edition for Testers 介绍

    提供的资源包括PPT、视频和文档,这将帮助读者以多种方式学习和掌握Visual Studio 2005 Team Edition for Testers的使用方法和最佳实践。PPT可能包含了关键概念的概述和步骤说明,视频可能演示了具体的操作过程,而...

    Python Unit Test Automation 无水印pdf 0分

    Python Unit Test Automation Practical Techniques for Python Developers and Testers 英文无水印pdf pdf所有页面使用FoxitReader和PDF-XChangeViewer测试都可以打开

    Coding for Penetration Testers(2nd) epub

    Coding for Penetration Testers(2nd) 英文epub 第2版 本资源转载自网络,如有侵权,请联系上传者或csdn删除 本资源转载自网络,如有侵权,请联系上传者或csdn删除

    TestComplete7 基础培训

    如果要在Microsoft Visual Studio 2005环境中执行TestComplete测试项目,需要有Visual Studio 2005 Team Suite或Software Testers Team Edition的相应版本。安装TestComplete的Microsoft Visual Studio 2005 Team ...

    soapui-eclipse-plugin 3.0 part2

    soapUI is a desktop application for inspecting, invoking, mocking and testing (functional and load) of SOAP/WSDL and REST/EADL based Web Services over HTTP. It is mainly aimed at developers/testers ...

    soapui-eclipse-plugin 3.0 part3

    soapUI is a desktop application for inspecting, invoking, mocking and testing (functional and load) of SOAP/WSDL and REST/EADL based Web Services over HTTP. It is mainly aimed at developers/testers ...

    Metasploit a Penetration Testers Guide

    Metasploit - a Penetration Testers Guide.pdf 官方推荐,有爱的拿去. 官方介绍: http://www.backtrack-linux.org/backtrack/metasploit-a-penetration-testers-guide/

Global site tag (gtag.js) - Google Analytics