use of org.eclipse.core.resources.IMarker in project bndtools by bndtools.
the class ComponentMarker method findAndMarkComponentAnnotations.
private static void findAndMarkComponentAnnotations(ICompilationUnit c) throws CoreException, JavaModelException {
Document document = null;
boolean found = false;
String key = null;
for (IType t : c.getTypes()) {
for (IAnnotation annot : t.getAnnotations()) {
if ("Component".equals(annot.getElementName())) {
if (document == null)
document = new Document(c.getBuffer().getContents());
found = true;
key = getNameFromComponent(annot);
int lineNumber;
try {
lineNumber = document.getLineOfOffset(t.getSourceRange().getOffset()) + 1;
String message = key == null ? "OSGi Component" : key;
IMarker marker = c.getResource().createMarker(BndtoolsConstants.MARKER_COMPONENT);
marker.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_INFO);
marker.setAttribute(IMarker.MESSAGE, message);
marker.setAttribute(IMarker.LINE_NUMBER, lineNumber);
marker.setAttribute(IMarker.LOCATION, "line " + lineNumber);
} catch (BadLocationException e) {
logger.logError("Component Marker error", e);
lineNumber = -1;
}
}
}
}
if (!found) {
c.getResource().deleteMarkers(BndtoolsConstants.MARKER_COMPONENT, true, IResource.DEPTH_ONE);
}
}
use of org.eclipse.core.resources.IMarker in project bndtools by bndtools.
the class BaselineErrorHandler method getResolutions.
@Override
public List<IMarkerResolution> getResolutions(IMarker marker) {
List<IMarkerResolution> result = new LinkedList<IMarkerResolution>();
final String suggestedVersion = marker.getAttribute(PROP_SUGGESTED_VERSION, null);
if (suggestedVersion != null) {
result.add(new IMarkerResolution() {
@Override
public void run(IMarker marker) {
final IFile file = (IFile) marker.getResource();
final IWorkspace workspace = file.getWorkspace();
try {
workspace.run(new IWorkspaceRunnable() {
@Override
public void run(IProgressMonitor monitor) throws CoreException {
String input = "version " + suggestedVersion;
ByteArrayInputStream stream = new ByteArrayInputStream(input.getBytes());
file.setContents(stream, false, true, monitor);
}
}, null);
} catch (CoreException e) {
logger.logError("Error applying baseline version quickfix.", e);
}
}
@Override
public String getLabel() {
return "Change package version to " + suggestedVersion;
}
});
}
return result;
}
use of org.eclipse.core.resources.IMarker 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);
}
}
use of org.eclipse.core.resources.IMarker in project bndtools by bndtools.
the class MissingWorkspaceMarkerResolutionGenerator method getResolutions.
@Override
public IMarkerResolution[] getResolutions(IMarker marker) {
return new IMarkerResolution[] { new IMarkerResolution() {
@Override
public void run(IMarker marker) {
IWorkbench workbench = PlatformUI.getWorkbench();
IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
WorkspaceSetupWizard wizard = new WorkspaceSetupWizard();
wizard.init(workbench, StructuredSelection.EMPTY);
WizardDialog dialog = new WizardDialog(window.getShell(), wizard);
dialog.open();
}
@Override
public String getLabel() {
return "Open 'New Bnd OSGi Workspace' Wizard";
}
} };
}
use of org.eclipse.core.resources.IMarker in project sling by apache.
the class LegacyMavenBundleProjectTest method testLegacyMavenBundleProjectHasErrorMarker.
@Test
public void testLegacyMavenBundleProjectHasErrorMarker() throws Exception {
// create project
final IProject bundleProject = projectRule.getProject();
MavenProjectAdapter project = new MavenProjectAdapter(bundleProject);
project.createOrUpdateFile(Path.fromPortableString("pom.xml"), getClass().getResourceAsStream("legacy-pom.xml"));
project.convertToMavenProject();
// wait up to 1 minute for the build to succeed due to time needed to retrieve dependencies
Poller markerPoller = new Poller(TimeUnit.MINUTES.toMillis(1));
markerPoller.pollUntilSuccessful(new Runnable() {
@Override
public void run() {
try {
IMarker[] markers = bundleProject.findMarkers(null, true, IResource.DEPTH_ONE);
for (IMarker marker : markers) {
if (marker.getAttribute(IMarker.SEVERITY, IMarker.SEVERITY_INFO) != IMarker.SEVERITY_ERROR) {
continue;
}
if (marker.getAttribute(IMarker.MESSAGE, "").startsWith("Missing m2e incremental build support")) {
return;
}
}
throw new RuntimeException("Did not find error message starting with 'Missing m2e incremental support'");
} catch (CoreException e) {
throw new RuntimeException(e);
}
}
});
}
Aggregations