- 浏览: 27152 次
- 性别:
- 来自: 广州
文章分类
最新评论
org.eclipse.core.resources.builders用于提供一种操作,这种操作可以在IResource改变的时候自动去build,如同改变java文件,会自动进行build,显示错误一样,我们扩展这个builder,并且在自己的项目中使用。我们要做的就是实现build的过程,至于时机由eclipse控制
Builder的例子代码:
Nature的例子代码:
<extension id="builder的ID" name="builder的NAME" point="org.eclipse.core.resources.builders"> <builder hasNature="true"> <run class="builder的CLASS"> </run> </builder> </extension> <extension id="nature的ID" name="nature的NAME" point="org.eclipse.core.resources.natures"> <runtime> <run class="nature的CLASS"> </run> </runtime> <builder id="builder所在的插件ID+.+builder的ID"> </builder> </extension>
<extension id="builder的ID" name="builder的NAME" point="org.eclipse.core.resources.builders"> <builder hasNature="true"> <run class="builder的CLASS"> </run> </builder> </extension> <extension id="nature的ID" name="nature的NAME" point="org.eclipse.core.resources.natures"> <runtime> <run class="nature的CLASS"> </run> </runtime> <builder id="builder所在的插件ID+.+builder的ID"> </builder> </extension>
Builder的例子代码:
package project_builder.builder; import java.util.Map; import javax.xml.parsers.ParserConfigurationException; import javax.xml.parsers.SAXParser; import javax.xml.parsers.SAXParserFactory; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IMarker; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IResourceDelta; import org.eclipse.core.resources.IResourceDeltaVisitor; import org.eclipse.core.resources.IResourceVisitor; import org.eclipse.core.resources.IncrementalProjectBuilder; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; import org.xml.sax.SAXException; import org.xml.sax.SAXParseException; import org.xml.sax.helpers.DefaultHandler; public class SampleBuilder extends IncrementalProjectBuilder { class SampleDeltaVisitor implements IResourceDeltaVisitor { /* * (non-Javadoc) * * @see org.eclipse.core.resources.IResourceDeltaVisitor#visit(org.eclipse.core.resources.IResourceDelta) */ public boolean visit(IResourceDelta delta) throws CoreException { IResource resource = delta.getResource(); switch (delta.getKind()) { case IResourceDelta.ADDED: // handle added resource checkXML(resource); break; case IResourceDelta.REMOVED: // handle removed resource break; case IResourceDelta.CHANGED: // handle changed resource checkXML(resource); break; } //return true to continue visiting children. return true; } } class SampleResourceVisitor implements IResourceVisitor { public boolean visit(IResource resource) { checkXML(resource); //return true to continue visiting children. return true; } } class XMLErrorHandler extends DefaultHandler { private IFile file; public XMLErrorHandler(IFile file) { this.file = file; } private void addMarker(SAXParseException e, int severity) { SampleBuilder.this.addMarker(file, e.getMessage(), e .getLineNumber(), severity); } public void error(SAXParseException exception) throws SAXException { addMarker(exception, IMarker.SEVERITY_ERROR); } public void fatalError(SAXParseException exception) throws SAXException { addMarker(exception, IMarker.SEVERITY_ERROR); } public void warning(SAXParseException exception) throws SAXException { addMarker(exception, IMarker.SEVERITY_WARNING); } } public static final String BUILDER_ID = "Project_Builder.sampleBuilder"; private static final String MARKER_TYPE = "Project_Builder.xmlProblem"; private SAXParserFactory parserFactory; private void addMarker(IFile file, String message, int lineNumber, int severity) { try { IMarker marker = file.createMarker(MARKER_TYPE); marker.setAttribute(IMarker.MESSAGE, message); marker.setAttribute(IMarker.SEVERITY, severity); if (lineNumber == -1) { lineNumber = 1; } marker.setAttribute(IMarker.LINE_NUMBER, lineNumber); } catch (CoreException e) { } } /* * (non-Javadoc) * * @see org.eclipse.core.internal.events.InternalBuilder#build(int, * java.util.Map, org.eclipse.core.runtime.IProgressMonitor) */ protected IProject[] build(int kind, Map args, IProgressMonitor monitor) throws CoreException { if (kind == FULL_BUILD) { fullBuild(monitor); } else { IResourceDelta delta = getDelta(getProject()); if (delta == null) { fullBuild(monitor); } else { incrementalBuild(delta, monitor); } } return null; } void checkXML(IResource resource) { if (resource instanceof IFile && resource.getName().endsWith(".xml")) { IFile file = (IFile) resource; deleteMarkers(file); XMLErrorHandler reporter = new XMLErrorHandler(file); try { getParser().parse(file.getContents(), reporter); } catch (Exception e1) { } } } private void deleteMarkers(IFile file) { try { file.deleteMarkers(MARKER_TYPE, false, IResource.DEPTH_ZERO); } catch (CoreException ce) { } } protected void fullBuild(final IProgressMonitor monitor) throws CoreException { try { getProject().accept(new SampleResourceVisitor()); } catch (CoreException e) { } } private SAXParser getParser() throws ParserConfigurationException, SAXException { if (parserFactory == null) { parserFactory = SAXParserFactory.newInstance(); } return parserFactory.newSAXParser(); } protected void incrementalBuild(IResourceDelta delta, IProgressMonitor monitor) throws CoreException { // the visitor does the work. delta.accept(new SampleDeltaVisitor()); } }
Nature的例子代码:
package project_builder.builder; import org.eclipse.core.resources.ICommand; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IProjectDescription; import org.eclipse.core.resources.IProjectNature; import org.eclipse.core.runtime.CoreException; public class SampleNature implements IProjectNature { /** * ID of this project nature */ public static final String NATURE_ID = "Project_Builder.sampleNature"; private IProject project; /* * (non-Javadoc) * * @see org.eclipse.core.resources.IProjectNature#configure() */ public void configure() throws CoreException { IProjectDescription desc = project.getDescription(); ICommand[] commands = desc.getBuildSpec(); for (int i = 0; i < commands.length; ++i) { if (commands[i].getBuilderName().equals(SampleBuilder.BUILDER_ID)) { return; } } ICommand[] newCommands = new ICommand[commands.length + 1]; System.arraycopy(commands, 0, newCommands, 0, commands.length); ICommand command = desc.newCommand(); command.setBuilderName(SampleBuilder.BUILDER_ID); newCommands[newCommands.length - 1] = command; desc.setBuildSpec(newCommands); project.setDescription(desc, null); } /* * (non-Javadoc) * * @see org.eclipse.core.resources.IProjectNature#deconfigure() */ public void deconfigure() throws CoreException { IProjectDescription description = getProject().getDescription(); ICommand[] commands = description.getBuildSpec(); for (int i = 0; i < commands.length; ++i) { if (commands[i].getBuilderName().equals(SampleBuilder.BUILDER_ID)) { ICommand[] newCommands = new ICommand[commands.length - 1]; System.arraycopy(commands, 0, newCommands, 0, i); System.arraycopy(commands, i + 1, newCommands, i, commands.length - i - 1); description.setBuildSpec(newCommands); return; } } } /* * (non-Javadoc) * * @see org.eclipse.core.resources.IProjectNature#getProject() */ public IProject getProject() { return project; } /* * (non-Javadoc) * * @see org.eclipse.core.resources.IProjectNature#setProject(org.eclipse.core.resources.IProject) */ public void setProject(IProject project) { this.project = project; } }
发表评论
-
GEF简介与事件机制
2014-08-07 09:56 3494一、GEF简介 GEF(Graphica ... -
GEF入门参考
2014-08-07 09:37 568一些网站 http://www.ibm.com/develo ... -
SWT-GEF事件转义相关类
2014-08-07 09:35 788在Draw2d中,Lightweight是gef图形系统的”s ... -
GEF中Editor创建的时序图
2014-08-07 09:33 533以eclipse网站上例子A Shape Diagram Ed ... -
org.eclipse.ui.decorators 使用(转)
2013-10-12 14:24 595org.eclipse.ui.decorators这个扩展点可 ... -
org.eclipse.ui.menus扩展点
2013-06-06 11:17 1835eclipse插件开发中 ... -
Eclipse开发中的 NoClassDefFoundError
2013-03-26 16:18 1136在eclipse插件开发过程中,需要引入很多的第三方j ... -
Eclipse事件与通讯
2013-01-18 15:58 923在开发Eclipse插件开发rcp过程中需要用到很多的 ... -
使用代码生成插件工程,脱离eclipse本身的新建工程向导(3)
2012-11-22 10:58 1131在第二步中需要有个PluginClassCodeGen ... -
使用代码生成插件工程,脱离eclipse本身的新建工程向导(2)
2012-11-22 10:52 3704在第一步完成后,我从pde的向导代码入手看eclips ... -
使用代码生成插件工程,脱离eclipse本身的新建工程向导(1)
2012-11-22 10:43 1724第一步,新建一个普通的Java工程。在网上,我找到了网 ... -
从handler中获取全局状态
2012-09-27 15:16 1345当运用eclipse扩展点handler来使用comm ... -
过滤第三方插件扩展点
2012-09-26 09:57 1027在开发rcp过程中,不可避免的需要加入第三方插件,与此 ... -
插件开发基础类(转载)
2012-09-25 16:36 7481..IWorkbench: workbench是e ... -
获取需要平台的信息
2012-09-25 16:16 728开发rcp程序的时候,需要获取许多平台和编辑器的相关信 ...
相关推荐
org.junit.internal.builders.AllDefaultPossibilitiesBuilder.class org.junit.internal.builders.AnnotatedBuilder.class org.junit.internal.builders.IgnoredBuilder.class org.junit.internal.builders....
python库。 资源全名:cortex-python-builders-1.2.1.tar.gz
资源来自pypi官网。 资源全名:emmet-builders-0.8.0.tar.gz
Angular-angular-builders.zip,angular cli@angular builders的一组自定义生成器,Angularjs于2016年发布,是Angularjs的重写版。它专注于良好的移动开发、模块化和改进的依赖注入。angular的设计目的是全面解决开发...
│ │ org.eclipse.jdt.core.prefs │ │ │ └─src │ │ logging.properties │ │ │ └─com │ └─mine │ │ BigMap.java │ │ LogPack.java │ │ │ └─logging │ ConsoleHandler.java │ Error...
python库,解压后可用。 资源全名:cortex_python_builders-1.2.0-py3-none-any.whl
python库,解压后可用。 资源全名:aws_lambda_builders-0.7.0-py3-none-any.whl
资源来自pypi官网。 资源全名:cortex_python_builders-1.2.0-py3-none-any.whl
资源来自pypi官网。 资源全名:aws_lambda_builders-0.8.0-py2-none-any.whl
资源来自pypi官网。 资源全名:aws_lambda_builders-0.7.0-py3-none-any.whl
资源分类:Python库 所属语言:Python 资源全名:aws_lambda_builders-1.11.0-py3-none-any.whl 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059
webservice CXF 报错:java.lang.NoClassDefFoundError: org/apache/neethi/builders/AssertionBuilder 需要用到此jar文件 通过apache官网可获得。 文件位置\apache-cxf-2.7.13\lib
kotlinx.coroutines Library support for Kotlin coroutines with multiplatform support. This is a companion version for Kotlin 1.3.20 release. ...launch and async coroutine builders; Job and Defer
Cmake Error at builders/vpx.cmake:89 Cmake Error at builders/vpx.cmake:88 Cmake Error at builders/vpx.cmake:87 Cmake Error at builders/vpx.cmake:77 file not found WORK/desktop/cmake/windowsenv_libpath...
@ angular-builders 该存储库的目的是整合Angular构建立面的所有社区构建器。 所有构建器的最新版本都需要Angular CLI 11 建筑商 (替代ng eject ) (允许使用Jest运行ng test ) (来自示例助洗剂文章) 保持...
预构建的映像可在gcr.io/cloud-builders/... ,包括: bazel :运行工具 curl :运行工具 docker :运行工具 dotnet :运行工具 gcloud :运行工具 gcs-fetcher :从Google Cloud Storage有效地获取对象 git :...
前端开源库-Builders建设者,资产建设者:css,js,sprites。