Search in sources :

Example 6 with MarkerData

use of org.bndtools.build.api.MarkerData in project bndtools by bndtools.

the class DSAnnotationErrorHandler method generateMarkerData.

@Override
public List<MarkerData> generateMarkerData(IProject project, Project model, Location location) throws Exception {
    List<MarkerData> result = new ArrayList<MarkerData>();
    DeclarativeServicesAnnotationError dsError = (DeclarativeServicesAnnotationError) location.details;
    IJavaProject javaProject = JavaCore.create(project);
    Map<String, Object> attribs = new HashMap<String, Object>();
    attribs.put(IMarker.MESSAGE, location.message.trim());
    MarkerData md = null;
    if (dsError.className != null) {
        if (dsError.methodName != null && dsError.methodSignature != null) {
            md = createMethodMarkerData(javaProject, dsError.className, dsError.methodName, dsError.methodSignature, attribs, false);
        }
        if (dsError.fieldName != null) {
            md = createFieldMarkerData(javaProject, dsError.className, dsError.fieldName, attribs, false);
        }
        if (md == null) {
            md = createTypeMarkerData(javaProject, dsError.className, attribs, false);
        }
    }
    if (md == null) {
        // No other marker could be created, so add a marker to the bnd file
        result.add(new MarkerData(getDefaultResource(project), attribs, false));
    }
    result.add(md);
    return result;
}
Also used : MarkerData(org.bndtools.build.api.MarkerData) IJavaProject(org.eclipse.jdt.core.IJavaProject) HashMap(java.util.HashMap) DeclarativeServicesAnnotationError(aQute.bnd.component.error.DeclarativeServicesAnnotationError) ArrayList(java.util.ArrayList)

Example 7 with MarkerData

use of org.bndtools.build.api.MarkerData in project bndtools by bndtools.

the class BaselineErrorHandler method generateAddedMethodMarker.

/*
    List<MarkerData> generateAddedTypeMarker(IJavaProject javaProject, String name, Delta ifAdded) {
        // TODO Auto-generated method stub
        return null;
    }
    */
List<MarkerData> generateAddedMethodMarker(IJavaProject javaProject, String className, final String methodName, final Delta requiresDelta) throws JavaModelException {
    final List<MarkerData> markers = new LinkedList<MarkerData>();
    final CompilationUnit ast = createAST(javaProject, className);
    if (ast != null) {
        ast.accept(new ASTVisitor() {

            @Override
            public boolean visit(MethodDeclaration methodDecl) {
                String signature = ASTUtil.buildMethodSignature(methodDecl);
                if (signature.equals(methodName)) {
                    // Create the marker attribs here
                    Map<String, Object> attribs = new HashMap<String, Object>();
                    attribs.put(IMarker.CHAR_START, methodDecl.getStartPosition());
                    attribs.put(IMarker.CHAR_END, methodDecl.getStartPosition() + methodDecl.getLength());
                    String message = String.format("This method was added, which requires a %s change to the package.", requiresDelta);
                    attribs.put(IMarker.MESSAGE, message);
                    markers.add(new MarkerData(ast.getJavaElement().getResource(), attribs, false));
                }
                return false;
            }
        });
    }
    return markers;
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) CompilationUnit(org.eclipse.jdt.core.dom.CompilationUnit) MarkerData(org.bndtools.build.api.MarkerData) MethodDeclaration(org.eclipse.jdt.core.dom.MethodDeclaration) Map(java.util.Map) HashMap(java.util.HashMap) LinkedList(java.util.LinkedList) ASTVisitor(org.eclipse.jdt.core.dom.ASTVisitor)

Example 8 with MarkerData

use of org.bndtools.build.api.MarkerData in project bndtools by bndtools.

the class BundleActivatorErrorHandler method generateMarkerData.

@Override
public List<MarkerData> generateMarkerData(IProject project, Project model, Location location) throws Exception {
    List<MarkerData> result = new ArrayList<MarkerData>();
    BundleActivatorError baError = (BundleActivatorError) location.details;
    IJavaProject javaProject = JavaCore.create(project);
    Map<String, Object> attribs = createMessageMarkerAttributes(baError, location.message);
    //Eclipse line numbers are 1 indexed
    attribs.put(IMarker.LINE_NUMBER, location.line + 1);
    // Add a marker to the bnd file on the BundleActivator line
    result.add(new MarkerData(getDefaultResource(project), attribs, false));
    MarkerData md;
    switch(baError.errorType) {
        case NO_SUITABLE_CONSTRUCTOR:
            md = createMethodMarkerData(javaProject, baError.activatorClassName, "<init>", "()V", createMessageMarkerAttributes(baError, location.message), false);
            if (md != null) {
                result.add(md);
                break;
            }
        //$FALL-THROUGH$
        case IS_INTERFACE:
        case IS_ABSTRACT:
        case NOT_PUBLIC:
        case NOT_AN_ACTIVATOR:
        case DEFAULT_PACKAGE:
        case IS_IMPORTED:
            md = createTypeMarkerData(javaProject, baError.activatorClassName, createMessageMarkerAttributes(baError, location.message), false);
            if (md != null)
                result.add(md);
            break;
        case NOT_ACCESSIBLE:
        default:
            //No file to mark
            break;
    }
    return result;
}
Also used : MarkerData(org.bndtools.build.api.MarkerData) IJavaProject(org.eclipse.jdt.core.IJavaProject) BundleActivatorError(aQute.bnd.osgi.Verifier.BundleActivatorError) ArrayList(java.util.ArrayList)

Example 9 with MarkerData

use of org.bndtools.build.api.MarkerData in project bndtools by bndtools.

the class MarkerSupport method createMarker.

void createMarker(Processor model, int severity, String formatted, String markerType) throws Exception {
    Location location = model != null ? model.getLocation(formatted) : null;
    if (location != null) {
        String type = location.details != null ? location.details.getClass().getName() : null;
        BuildErrorDetailsHandler handler = BuildErrorDetailsHandlers.INSTANCE.findHandler(type);
        List<MarkerData> markers = handler.generateMarkerData(project, model, location);
        for (MarkerData markerData : markers) {
            IResource resource = markerData.getResource();
            if (resource != null && resource.exists()) {
                String typeOverride = markerData.getTypeOverride();
                IMarker marker = resource.createMarker(typeOverride != null ? typeOverride : markerType);
                marker.setAttribute(IMarker.SEVERITY, severity);
                marker.setAttribute("$bndType", type);
                // Set location information
                if (location.header != null)
                    marker.setAttribute(BNDTOOLS_MARKER_HEADER_ATTR, location.header);
                if (location.context != null)
                    marker.setAttribute(BNDTOOLS_MARKER_CONTEXT_ATTR, location.context);
                if (location.file != null)
                    marker.setAttribute(BNDTOOLS_MARKER_FILE_ATTR, location.file);
                if (location.reference != null)
                    marker.setAttribute(BNDTOOLS_MARKER_REFERENCE_ATTR, location.reference);
                marker.setAttribute(BuildErrorDetailsHandler.PROP_HAS_RESOLUTIONS, markerData.hasResolutions());
                for (Entry<String, Object> attrib : markerData.getAttribs().entrySet()) marker.setAttribute(attrib.getKey(), attrib.getValue());
            }
        }
        return;
    }
    String defaultResource = model instanceof Project ? Project.BNDFILE : model instanceof Workspace ? Workspace.BUILDFILE : null;
    IResource resource = DefaultBuildErrorDetailsHandler.getDefaultResource(project, defaultResource);
    if (resource.exists()) {
        IMarker marker = resource.createMarker(markerType);
        marker.setAttribute(IMarker.SEVERITY, severity);
        marker.setAttribute(IMarker.MESSAGE, formatted);
    }
}
Also used : DefaultBuildErrorDetailsHandler(org.bndtools.build.api.DefaultBuildErrorDetailsHandler) BuildErrorDetailsHandler(org.bndtools.build.api.BuildErrorDetailsHandler) IProject(org.eclipse.core.resources.IProject) Project(aQute.bnd.build.Project) MarkerData(org.bndtools.build.api.MarkerData) IMarker(org.eclipse.core.resources.IMarker) IResource(org.eclipse.core.resources.IResource) SetLocation(aQute.service.reporter.Reporter.SetLocation) Location(aQute.service.reporter.Report.Location) Workspace(aQute.bnd.build.Workspace)

Aggregations

MarkerData (org.bndtools.build.api.MarkerData)9 LinkedList (java.util.LinkedList)6 HashMap (java.util.HashMap)5 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)3 IJavaProject (org.eclipse.jdt.core.IJavaProject)3 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 IFile (org.eclipse.core.resources.IFile)2 ASTVisitor (org.eclipse.jdt.core.dom.ASTVisitor)2 CompilationUnit (org.eclipse.jdt.core.dom.CompilationUnit)2 Project (aQute.bnd.build.Project)1 Workspace (aQute.bnd.build.Workspace)1 DeclarativeServicesAnnotationError (aQute.bnd.component.error.DeclarativeServicesAnnotationError)1 BundleInfo (aQute.bnd.differ.Baseline.BundleInfo)1 Info (aQute.bnd.differ.Baseline.Info)1 Builder (aQute.bnd.osgi.Builder)1 BundleActivatorError (aQute.bnd.osgi.Verifier.BundleActivatorError)1 Delta (aQute.bnd.service.diff.Delta)1 Diff (aQute.bnd.service.diff.Diff)1 Tree (aQute.bnd.service.diff.Tree)1