From: <jhs...@us...> - 2009-01-23 15:38:19
|
Revision: 118 http://flexotask.svn.sourceforge.net/flexotask/?rev=118&view=rev Author: jhspring Date: 2009-01-23 15:38:10 +0000 (Fri, 23 Jan 2009) Log Message: ----------- Changed resource visitors to report errors if classes could not be loaded during inspection. Builder will stop hereafter and report an error in the IDE. Modified Paths: -------------- trunk/flexotask-development/src/com/ibm/realtime/flexotask/development/builder/FlexotaskBuilder.java Modified: trunk/flexotask-development/src/com/ibm/realtime/flexotask/development/builder/FlexotaskBuilder.java =================================================================== --- trunk/flexotask-development/src/com/ibm/realtime/flexotask/development/builder/FlexotaskBuilder.java 2009-01-19 19:18:54 UTC (rev 117) +++ trunk/flexotask-development/src/com/ibm/realtime/flexotask/development/builder/FlexotaskBuilder.java 2009-01-23 15:38:10 UTC (rev 118) @@ -212,13 +212,18 @@ throw new CoreException(new Status(IStatus.ERROR, BUILDER_ID, IResourceStatus.INTERNAL_ERROR, ee.getMessage(), ee)); } - } else { + } else if (entry instanceof FieldViolation) { FieldViolation fv = (FieldViolation) entry; IType type = jproj.findType(Utils.convertInnerclass(fv .getDefiningClass().getName())); IField ifield = type.getField(fv.getFieldName()); reportTypeRuleViolation(fv.getDefiningClass(), entry, Utils .getLineNumber(ifield)); + } else { + IResource res = jproj.getResource(); + addMarkerToResource((entry.getSeverity() == Severity.ERROR) ? + IMarker.SEVERITY_ERROR : IMarker.SEVERITY_WARNING, res, -1, entry + .getMessage()); } } } @@ -244,13 +249,15 @@ protected Set flexotaskClasses = new HashSet(); /** The complete list of graph files found in the entire project */ protected Set templateIFiles = new HashSet(); + /** The set of problems following visitor traversal */ + protected Set visitorProblems = new HashSet(); /** * Returns the binary class name of the file represented by the provided file * object * @param file the file from which to return the binary class name * @return the binary class name of the provided file - * @throws JavaModelException if the output location cannot be read + * @throws CoreException if the binary name could not be returned */ protected String getBinaryClassName(IFile file) throws CoreException { IPath outputLocation = getOutputLocation(file); @@ -331,11 +338,12 @@ * @param f the file to be inspected. */ protected void collectClassFile(IFile f) { + String clazzName = null; try { if ("class".equals(f.getFileExtension()) && isInOutputLocation(f)) { // get the binary class name of file to investigate - String clazzName = getBinaryClassName(f); + clazzName = getBinaryClassName(f); // load the class and check if it is a Flexotask trace("loading class: " + clazzName); Class clazz = Class.forName(clazzName, false, cl); @@ -345,9 +353,13 @@ flexotaskClasses.add(clazz); } } - } catch (Exception e) { - e.printStackTrace(); - // TODO: handle exception + } catch (Throwable e) { + if (e instanceof CoreException) + visitorProblems.add(new TypeRuleViolation(Severity.ERROR, "Could not extract class name for file '" + f.getName() + "'!")); + else if ((e instanceof ClassNotFoundException) || (e instanceof NoClassDefFoundError)) + visitorProblems.add(new TypeRuleViolation(Severity.ERROR, "Error loading class '" + clazzName + "'. Missing class: " + e.getMessage())); + else + visitorProblems.add(new TypeRuleViolation(Severity.ERROR, "Exception occured during incremental build. Error: " + e.getMessage())); } } @@ -417,6 +429,7 @@ * </ul> */ private class ResourceDeltaVisitor extends ResourceVisitor implements IResourceDeltaVisitor { + /** * Loops through all the code analysis results of the previous run(s) and * marks any found templates or orphan flexotasks affected by the @@ -427,9 +440,10 @@ protected void collectClassFile(IFile f) { if ("class".equals(f.getFileExtension()) && isInOutputLocation(f)) { + String clazzName = null; try { // get the binary class name of file to investigate - String clazzName = getBinaryClassName(f); + clazzName = getBinaryClassName(f); // load the class and check if it is a Flexotask trace("loading class: " + clazzName); Class clazz = Class.forName(clazzName, false, cl); @@ -463,9 +477,13 @@ flexotaskClasses.add(clazz); } } - } catch (Exception e) { - e.printStackTrace(); - // TODO: handle exception + } catch (Throwable e) { + if (e instanceof CoreException) + visitorProblems.add(new TypeRuleViolation(Severity.ERROR, "Could not extract class name for file '" + f.getName() + "'!")); + else if ((e instanceof ClassNotFoundException) || (e instanceof NoClassDefFoundError)) + visitorProblems.add(new TypeRuleViolation(Severity.ERROR, "Error loading class '" + clazzName + "'. Missing class: " + e.getMessage())); + else + visitorProblems.add(new TypeRuleViolation(Severity.ERROR, "Exception occured during incremental build. Error: " + e.getMessage())); } } } @@ -685,6 +703,11 @@ ResourceVisitor visitor = new ResourceVisitor(); getProject().accept(visitor); + if (visitor.visitorProblems.size() > 0) { + reportTypeRuleViolationsInView(visitor.visitorProblems); + return; + } + if (checkCancel(monitor)) return; doBuild(args, monitor, visitor); @@ -706,6 +729,11 @@ ResourceDeltaVisitor visitor = new ResourceDeltaVisitor(); getDelta(getProject()).accept(visitor); + if (visitor.visitorProblems.size() > 0) { + reportTypeRuleViolationsInView(visitor.visitorProblems); + return; + } + if (visitor.getFlexotaskClasses().isEmpty() && visitor.getTemplateIFileSet().isEmpty()) return; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |