⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 resourcedeltabuilder.java

📁 eclipseme的最新版本的source,欢迎j2me程序员使用
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
		} else {
			requirePreverify = isSourceNewerThanTarget(srcFile, tgtFile);
		}
		
		return requirePreverify;
	}

	/**
	 * Get the output locations (IPath instances) for the specified
	 * java project.
	 * 
	 * @param javaProject
	 * @param monitor
	 * @return
	 * @throws CoreException
	 */
	private IPath[] getOutputLocations(IJavaProject javaProject, IProgressMonitor monitor)
		throws CoreException 
	{
		OutputLocationsCollectionVisitor visitor = new OutputLocationsCollectionVisitor();
		visitor.getRunner().run(javaProject, visitor, monitor);
		
		// Collect the unique output locations
		Set outputLocations = visitor.getOutputLocations();
		return (IPath[]) outputLocations.toArray(new IPath[outputLocations.size()]);
	}

	/**
	 * Get the method based on the method information.
	 * 
	 * @param type
	 * @param methodInfo
	 * @return
	 */
	private IMethod getTypeMethod(IType type, IMethodErrorInformation methodInfo) {
		Type[] argTypes = Type.getArgumentTypes(methodInfo.getTypeDescription());
		String[] argTypeStrings = new String[argTypes.length];
		for (int i = 0; i < argTypes.length; i++) {
			argTypeStrings[i] = argTypes[i].getInternalName();
		}
		
		return type.getMethod(methodInfo.getName(), argTypeStrings);
	}
	
	/**
	 * Handle class file additions and changes by preverifying
	 * the new and changed classes.
	 * 
	 * @param classFiles
	 * @param monitor
	 */
	private void handleClassAddsAndChanges(
		List classFiles, 
		IProgressMonitor monitor) 
			throws CoreException 
	{
		if (buildLoggingConfig.isPreverifierTraceEnabled()) {
			BuildConsoleProxy.instance.traceln("> ResourceDeltaBuilder.handleClassAddsAndChanges; classFiles count = " + classFiles.size()); 
		}

		if (classFiles.size() > 0) {
			IResource[] resources =
				(IResource[]) classFiles.toArray(new IResource[classFiles.size()]);
				
			try {
				// Run the preverification
				IFolder outputFolder = buildInfo.getVerifiedClassesFolder(monitor);
				PreverificationError[] errors =
					buildInfo.getMidletSuite().preverify(resources, outputFolder, monitor);
				outputFolder.refreshLocal(IResource.DEPTH_INFINITE, monitor);
				
				for (int i = 0; i < errors.length; i++) {
					PreverificationError error = errors[i];
					createErrorMarkerFor(error);
				}

				// Now, place the results into the deployed jar
				for (int i = 0; i < resources.length; i++) {
					IFile file = (IFile) resources[i];
					
					IPath relativePath = Utils.extractsSourceFolderRelativePath(
						buildInfo.getCurrentJavaProject(), 
						file);
					IFile outputFile = outputFolder.getFile(relativePath);
					if (outputFile.exists()) {
						addFileToRuntimeJar(relativePath, outputFile, monitor);
					}
				}
				
				buildInfo.setPackageDirty(true);

			} catch (IOException e) {
				EclipseMECorePlugin.throwCoreException(IStatus.ERROR, -999, e);
			}
		}
		
		if (buildLoggingConfig.isPreverifierTraceEnabled()) {
			BuildConsoleProxy.instance.traceln("< ResourceDeltaBuilder.handleClassAddsAndChanges"); 
		}
	}

	/**
	 * Handle resource file additions and changes by copying
	 * the new and changed classes.
	 * 
	 * @param resourceFiles
	 * @param monitor
	 */
	private void handleNonClassAddsAndChanges(
		List resourceFiles, 
		IProgressMonitor monitor) 
			throws CoreException 
	{
		if (buildLoggingConfig.isPreverifierTraceEnabled()) {
			BuildConsoleProxy.instance.traceln("> ResourceDeltaBuilder.handleResourceAddsAndChanges; resource count = " + resourceFiles.size()); 
		}
		
		if (resourceFiles.size() > 0) {
			Iterator iter = resourceFiles.iterator();
			while (iter.hasNext()) {
				IFile file = (IFile) iter.next();
				handleNonClassAddOrChange(file, monitor);
			}
		}
		
		if (buildLoggingConfig.isPreverifierTraceEnabled()) {
			BuildConsoleProxy.instance.traceln("< ResourceDeltaBuilder.handleResourceAddsAndChanges"); 
		}
	}

	/**
	 * Handle the addition of a single resource to the deployed jar file.
	 * 
	 * @param file
	 * @throws CoreException
	 */
	private void handleNonClassAddOrChange(IFile file, IProgressMonitor monitor) 
		throws CoreException 
	{
		if (file.exists() && buildInfo.getResourceFilter().shouldBeIncluded(file)) {
			// Calculate the path		
			IPath relativePath = Utils.extractsSourceFolderRelativePath(
				buildInfo.getCurrentJavaProject(), 
				file);
			
			if (relativePath != null) {
				addFileToRuntimeJar(relativePath, file, monitor);
				buildInfo.setPackageDirty(true);
			}
		}
	}

	/**
	 * Handle a null delta for the specified project.
	 * 
	 * @param monitor
	 */
	private void handleNullDelta(IProgressMonitor monitor) 
		throws CoreException 
	{
		if (buildLoggingConfig.isPreverifierTraceEnabled()) {
			BuildConsoleProxy.instance.traceln("> ResourceDeltaBuilder.handleNullDelta"); 
		}

		// Collect the unique output locations
		IPath[] outputLocations = 
			getOutputLocations(buildInfo.getCurrentJavaProject(), monitor); 

		// We don't want stuff from the library folders at this point
		IPath[] libraryFolderPaths = collectLibraryFolderPaths(monitor);
		
		// Now collect up the classes in the output locations
		List classes = new ArrayList();
		List resources = new ArrayList();
		
		for (int i = 0; i < outputLocations.length; i++) {
			IPath path = outputLocations[i];
			IResource resource = workspaceRoot.findMember(path.makeAbsolute());
			collectClassesAndResources(classes, resources, resource, libraryFolderPaths);				
		}			
		
		// Do the adds
		handleClassAddsAndChanges(classes, monitor);
		handleNonClassAddsAndChanges(resources, monitor);
		
		if (buildLoggingConfig.isPreverifierTraceEnabled()) {
			BuildConsoleProxy.instance.traceln("< ResourceDeltaBuilder.handleNullDelta"); 
		}
	}
	
	/**
	 * Handle class file removals by removing them from the
	 * preverified directory.
	 * 
	 * @param list
	 * @param monitor
	 */
	private void handleRemoves(List removals, IProgressMonitor monitor) 
		throws CoreException 
	{
		if (buildLoggingConfig.isPreverifierTraceEnabled()) {
			BuildConsoleProxy.instance.traceln("> ResourceDeltaBuilder.handleRemoves; resource count = " + removals.size()); 
		}

		// Only do this if there is really anything to do
		if (removals.size() > 0) {
			IFolder outputFolder = buildInfo.getVerifiedClassesFolder(monitor);
				
			// Remove one by one...
			Iterator iter = removals.iterator();
			while (iter.hasNext()) {
				// Find the verified class for the specified
				// resource and delete it if found.
				IResource resource = (IResource) iter.next();
				removeVerifiedResource(
					buildInfo.getCurrentJavaProject(),
					outputFolder,
					resource,
					monitor);
			}
		}
		
		if (buildLoggingConfig.isPreverifierTraceEnabled()) {
			BuildConsoleProxy.instance.traceln("< ResourceDeltaBuilder.handleRemoves"); 
		}
	}

	/**
	 * Handle a non-null resource delta build.
	 * 
	 * @param project
	 * @param delta
	 * @param monitor
	 * @return
	 * @throws CoreException
	 */
	private void handleResourceDelta(IProgressMonitor monitor)
			throws CoreException 
	{
		if (buildLoggingConfig.isPreverifierTraceEnabled()) {
			BuildConsoleProxy.instance.traceln("> ResourceDeltaBuilder.handleResourceDelta"); 
		}

		// Collect class file deltas
		ResourceDeltaVisitor visitor = new ResourceDeltaVisitor(monitor); 
		buildInfo.getCurrentResourceDelta().accept(visitor, false);
		
		if (buildInfo.areClassesPreverified()) {
			// Handle the class deltas
			handleRemoves(visitor.getRemovedClasses(), monitor);
			handleClassAddsAndChanges(visitor.getAddedOrChangedClasses(), monitor);
		}
		
		if (buildLoggingConfig.isPreverifierTraceEnabled()) {
			BuildConsoleProxy.instance.traceln("< ResourceDeltaBuilder.handleResourceDelta"); 
		}
	}

	/**
	 * Remove the specified relative path from the deployed jar file.
	 * 
	 * @param relativePath
	 * @throws CoreException 
	 */
	private void removeFileFromRuntimeJar(IPath relativePath, IProgressMonitor monitor) 
		throws CoreException 
	{
		if (relativePath != null) {
			File deployedFile = new File(buildInfo.getRuntimeJarFile(monitor), relativePath.toString());
			deployedFile.delete();
		}
	}

	/**
	 * Remove the specified verified resource.
	 * 
	 * @param javaProject
	 * @param outputFolder
	 * @param resource
	 * @param monitor
	 * @throws CoreException
	 */
	private void removeVerifiedResource(
		IJavaProject javaProject,
		IFolder outputFolder,
		IResource resource,
		IProgressMonitor monitor)
			throws CoreException 
	{
		IPath pathToResource = Utils.extractsSourceFolderRelativePath(javaProject, resource);
		
		if (buildLoggingConfig.isPreverifierTraceEnabled()) {
			BuildConsoleProxy.instance.traceln("> ResourceDeltaBuilder.deleteVerifiedResource; resource = " +
				resource +
				"; pathToResource = " +
				pathToResource); 
		}
		
		if (pathToResource != null) {
			IResource verifiedResource = outputFolder.findMember(pathToResource);
			
			if ((verifiedResource != null) && verifiedResource.exists()) {
				verifiedResource.delete(true, monitor);
			}
			
			removeFileFromRuntimeJar(pathToResource, monitor);
			buildInfo.setPackageDirty(true);
		}
		
		if (buildLoggingConfig.isPreverifierTraceEnabled()) {
			BuildConsoleProxy.instance.traceln("< ResourceDeltaBuilder.deleteVerifiedResource"); 
		}
	}

	/**
	 * Set the attributes for character range on the marker.
	 * 
	 * @param marker
	 * @param error
	 * @param type
	 * @throws CoreException
	 */
	private void setMarkerRangeAttributes(IMarker marker, PreverificationError error, IType type) 
		throws CoreException 
	{
		int start = 1;
		int end = 1;
		
		IMethodErrorInformation methodInfo = error.getLocation().getMethodInformation();
		IFieldErrorInformation fieldInfo = error.getLocation().getFieldInformation();
		
		switch (error.getLocation().getLocationType().getTypeCode()) {
			case PreverificationErrorLocationType.CLASS_DEFINITION_CODE:
				{
					ISourceRange sourceRange = type.getNameRange();
					start = sourceRange.getOffset();
					end = start + sourceRange.getLength();
				}
				break;

			case PreverificationErrorLocationType.CLASS_FIELD_CODE:
				{
					IField field = type.getField(fieldInfo.getName());
					if ((field != null) && (field.exists())) {
						ISourceRange sourceRange = field.getNameRange();
						start = sourceRange.getOffset();
						end = start + sourceRange.getLength();
					}
				}
				break;

			case PreverificationErrorLocationType.METHOD_SIGNATURE_CODE:
			case PreverificationErrorLocationType.METHOD_FIELD_CODE:
			case PreverificationErrorLocationType.METHOD_INSTRUCTION_CODE:
				{
					IMethod method = getTypeMethod(type, methodInfo);
					if ((method != null) && (method.exists())) {
						ISourceRange sourceRange = method.getNameRange();
						start = sourceRange.getOffset();
						end = start + sourceRange.getLength();
					}
				}
				break;
		}
		
		// Final fallback...
		marker.setAttribute(IMarker.CHAR_START, start);
		marker.setAttribute(IMarker.CHAR_END, end);
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -