use of aQute.service.reporter.Report.Location in project bnd by bndtools.
the class BuilderTest method testBadPackageInfo.
/**
* Using a package info without the version keyword gives strange results in
* the manifest, should generate an error.
*/
public void testBadPackageInfo() throws Exception {
Builder b = new Builder();
try {
b.addClasspath(new File("bin"));
b.setExportPackage("test.package_info_versioniskey");
b.build();
String message = b.getErrors().get(0);
assertTrue("The lacking version error first", message.contains("package info for test.package_info_versioniskey attribute [1.0.0=''],"));
Location location = b.getLocation(message);
assertNotNull("Supposed to have a location", location);
assertNotNull("And that must have a file", location.file);
assertEquals("Which should be the packaginfo file", "packageinfo", new File(location.file).getName());
assertEquals(4, location.line);
assertEquals(5, location.length);
assertTrue(b.check("package info for test.package_info_versioniskey attribute \\[1.0.0=''\\],"));
} finally {
b.close();
}
}
use of aQute.service.reporter.Report.Location in project bnd by bndtools.
the class BndMavenPlugin method reportErrorsAndWarnings.
private void reportErrorsAndWarnings(Builder builder) throws MojoExecutionException {
@SuppressWarnings("unchecked") Collection<File> markedFiles = (Collection<File>) buildContext.getValue(MARKED_FILES);
if (markedFiles == null) {
buildContext.removeMessages(propertiesFile);
markedFiles = builder.getIncluded();
}
if (markedFiles != null) {
for (File f : markedFiles) {
buildContext.removeMessages(f);
}
}
markedFiles = new HashSet<>();
List<String> warnings = builder.getWarnings();
for (String warning : warnings) {
Location location = builder.getLocation(warning);
if (location == null) {
location = new Location();
location.message = warning;
}
File f = location.file == null ? propertiesFile : new File(location.file);
markedFiles.add(f);
buildContext.addMessage(f, location.line, location.length, location.message, BuildContext.SEVERITY_WARNING, null);
}
List<String> errors = builder.getErrors();
for (String error : errors) {
Location location = builder.getLocation(error);
if (location == null) {
location = new Location();
location.message = error;
}
File f = location.file == null ? propertiesFile : new File(location.file);
markedFiles.add(f);
buildContext.addMessage(f, location.line, location.length, location.message, BuildContext.SEVERITY_ERROR, null);
}
buildContext.setValue(MARKED_FILES, markedFiles);
if (!builder.isOk()) {
if (errors.size() == 1)
throw new MojoExecutionException(errors.get(0));
else
throw new MojoExecutionException("Errors in bnd processing, see log for details.");
}
}
use of aQute.service.reporter.Report.Location in project bnd by bndtools.
the class UTF8PropertiesTest method assertError.
private void assertError(String string, String key, int line, String... check) throws IOException {
ReporterAdapter ra = new ReporterAdapter();
UTF8Properties up = new UTF8Properties();
up.load(string, IO.getFile("foo"), ra);
assertNotNull("No '" + key + "' property found", up.getProperty(key));
if (check.length == 0)
assertEquals(0, ra.getErrors().size());
else {
assertTrue(ra.getErrors().size() > 0);
Location location = ra.getLocation(ra.getErrors().get(0));
assertEquals("Faulty line number", line, location.line);
}
assertTrue(ra.check(check));
}
use of aQute.service.reporter.Report.Location in project bnd by bndtools.
the class Contracts method addToRequirements.
/**
* Called before we print the manifest. Should add any contracts that were
* actually used to the requirements.
*
* @param requirements
*/
void addToRequirements(Parameters requirements) {
for (Contract c : contracts) {
Attrs attrs = new Attrs(c.decorators);
attrs.put(ContractNamespace.CONTRACT_NAMESPACE, c.name);
String name = ContractNamespace.CONTRACT_NAMESPACE;
while (requirements.containsKey(name)) name += "~";
try (Formatter f = new Formatter()) {
f.format("(&(%s=%s)(version=%s))", ContractNamespace.CONTRACT_NAMESPACE, c.name, c.version);
// TODO : shall we also assert the attributes?
attrs.put("filter:", f.toString());
requirements.put(name, attrs);
}
}
for (Entry<Collection<Contract>, List<PackageRef>> oc : overlappingContracts.entrySet()) {
Location location = analyzer.error("Contracts %s declare the same packages in their uses: directive: %s. " + "Contracts are found in declaring bundles (see their 'from' field), it is possible to control the finding" + "with the -contract instruction", oc.getKey(), oc.getValue()).location();
location.header = Constants.CONTRACT;
}
}
use of aQute.service.reporter.Report.Location 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);
}
}
Aggregations