Search in sources :

Example 6 with FileLine

use of aQute.bnd.osgi.Processor.FileLine in project bndtools by bndtools.

the class DefaultBuildErrorDetailsHandler method getMarkerData.

/**
 * Use the location object to find the line number and text part.
 */
public static MarkerData getMarkerData(IProject p, Processor model, Location location) throws Exception {
    File file = model.getPropertiesFile();
    if (file == null) {
        if (model instanceof Project) {
            file = model.getFile(Project.BNDFILE);
        } else if (model instanceof Workspace) {
            file = model.getFile(Workspace.BUILDFILE);
        }
    }
    if (location.file != null)
        file = new File(location.file);
    int start = -1, end = -1, line = location.line;
    if (location.header != null && location.line == 0) {
        Processor rover = model;
        if (location.file != null) {
            File props = new File(location.file);
            if (props.isFile() && !props.equals(model.getPropertiesFile())) {
                rover = new Processor(model);
                rover.setProperties(props);
            }
        }
        try {
            FileLine fl = rover.getHeader(location.header, location.context);
            if (fl != null) {
                file = fl.file;
                line = fl.line;
                start = fl.start;
                end = fl.end;
            }
        } catch (Exception e) {
        // ignore, this was a bug in bnd. It could not handle if certain
        // files were not there during starting
        }
    }
    IResource resource = Central.toResource(file);
    String extra = "";
    if (resource == null)
        resource = AbstractBuildErrorDetailsHandler.getDefaultResource(p);
    else if (resource.getProject() != p) {
        // 
        // Make sure we never escape our project
        // 
        extra = ": see " + resource + "#" + line + 1;
        resource = p;
        line = 1;
        end = start = -1;
    }
    Map<String, Object> attribs = new HashMap<String, Object>();
    attribs.put(IMarker.MESSAGE, location.message.trim() + extra);
    attribs.put(IMarker.LINE_NUMBER, line + 1);
    if (end != -1 && start != -1) {
        attribs.put(IMarker.CHAR_START, start);
        attribs.put(IMarker.CHAR_END, end);
    }
    return new MarkerData(resource, attribs, false);
}
Also used : Processor(aQute.bnd.osgi.Processor) HashMap(java.util.HashMap) FileLine(aQute.bnd.osgi.Processor.FileLine) Project(aQute.bnd.build.Project) IProject(org.eclipse.core.resources.IProject) File(java.io.File) IResource(org.eclipse.core.resources.IResource) Workspace(aQute.bnd.build.Workspace)

Aggregations

FileLine (aQute.bnd.osgi.Processor.FileLine)6 Project (aQute.bnd.build.Project)4 SetLocation (aQute.service.reporter.Reporter.SetLocation)2 ProjectBuilder (aQute.bnd.build.ProjectBuilder)1 Workspace (aQute.bnd.build.Workspace)1 Builder (aQute.bnd.osgi.Builder)1 Processor (aQute.bnd.osgi.Processor)1 File (java.io.File)1 HashMap (java.util.HashMap)1 IProject (org.eclipse.core.resources.IProject)1 IResource (org.eclipse.core.resources.IResource)1