1 11 12 package org.eclipse.jdt.apt.core.internal; 13 14 import java.util.ArrayList ; 15 import java.util.List ; 16 17 import org.eclipse.core.resources.IMarker; 18 import org.eclipse.core.resources.IProject; 19 import org.eclipse.core.runtime.CoreException; 20 import org.eclipse.core.runtime.IStatus; 21 import org.eclipse.jdt.core.IJavaProject; 22 23 34 public class LoadFailureHandler { 35 36 private final IProject _project; 37 private final List <String > _missingLibraries = new ArrayList <String >(); 38 private final List <String > _failedFactories = new ArrayList <String >(); 39 40 public LoadFailureHandler(IJavaProject proj) { 41 _project = proj.getProject(); 42 } 43 44 public void addMissingLibrary(String lib) { 45 _missingLibraries.add(lib); 46 } 47 48 public void addFailedFactory(String factory) { 49 _failedFactories.add(factory); 50 } 51 52 public void reportFailureMarkers() { 53 reportFailureToLoadFactories(); 54 reportMissingLibraries(); 55 } 56 57 63 private void reportMissingLibraries() { 64 for (String fc : _missingLibraries) { 65 try { 66 String message = Messages.bind( 67 Messages.AnnotationProcessorFactoryLoader_factorypath_missingLibrary, 68 new String [] {fc, _project.getName()}); 69 IMarker marker = _project.createMarker(AptPlugin.APT_LOADER_PROBLEM_MARKER); 70 marker.setAttributes( 71 new String [] { 72 IMarker.MESSAGE, 73 IMarker.SEVERITY, 74 IMarker.LOCATION 75 }, 76 new Object [] { 77 message, 78 IMarker.SEVERITY_ERROR, 79 Messages.AnnotationProcessorFactoryLoader_factorypath 80 } 81 ); 82 } catch (CoreException e) { 83 AptPlugin.log(e, "Unable to create APT build problem marker on project " + _project.getName()); } 85 } 86 } 87 88 97 private void reportFailureToLoadFactories() { 98 for (String factoryName : _failedFactories) { 99 try { 100 String message = Messages.bind( 101 Messages.AnnotationProcessorFactoryLoader_unableToLoadFactoryClass, 102 new String [] {factoryName, _project.getName()}); 103 IMarker marker = _project.createMarker(AptPlugin.APT_LOADER_PROBLEM_MARKER); 104 marker.setAttributes( 105 new String [] { 106 IMarker.MESSAGE, 107 IMarker.SEVERITY, 108 IMarker.LOCATION 109 }, 110 new Object [] { 111 message, 112 IStatus.ERROR, 113 Messages.AnnotationProcessorFactoryLoader_factorypath 114 } 115 ); 116 } catch (CoreException e) { 117 AptPlugin.log(e, "Unable to create build problem marker"); } 119 } 120 } 121 122 @Override 123 public int hashCode() { 124 return _project.hashCode(); 125 } 126 127 @Override 128 public boolean equals(Object o) { 129 if (!(o instanceof LoadFailureHandler)) return false; 130 LoadFailureHandler otherHandler = (LoadFailureHandler)o; 131 return _project.equals(otherHandler._project); 132 } 133 134 } 135 | Popular Tags |