Search in sources :

Example 1 with Location

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();
    }
}
Also used : Builder(aQute.bnd.osgi.Builder) File(java.io.File) Location(aQute.service.reporter.Report.Location)

Example 2 with Location

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.");
    }
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) Collection(java.util.Collection) IO.getFile(aQute.lib.io.IO.getFile) ZipFile(java.util.zip.ZipFile) File(java.io.File) Location(aQute.service.reporter.Report.Location)

Example 3 with Location

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));
}
Also used : ReporterAdapter(aQute.libg.reporter.ReporterAdapter) Location(aQute.service.reporter.Report.Location)

Example 4 with Location

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;
    }
}
Also used : Formatter(java.util.Formatter) Attrs(aQute.bnd.header.Attrs) Collection(java.util.Collection) List(java.util.List) Location(aQute.service.reporter.Report.Location)

Example 5 with Location

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);
    }
}
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

Location (aQute.service.reporter.Report.Location)5 File (java.io.File)2 Collection (java.util.Collection)2 Project (aQute.bnd.build.Project)1 Workspace (aQute.bnd.build.Workspace)1 Attrs (aQute.bnd.header.Attrs)1 Builder (aQute.bnd.osgi.Builder)1 IO.getFile (aQute.lib.io.IO.getFile)1 ReporterAdapter (aQute.libg.reporter.ReporterAdapter)1 SetLocation (aQute.service.reporter.Reporter.SetLocation)1 Formatter (java.util.Formatter)1 List (java.util.List)1 ZipFile (java.util.zip.ZipFile)1 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)1 BuildErrorDetailsHandler (org.bndtools.build.api.BuildErrorDetailsHandler)1 DefaultBuildErrorDetailsHandler (org.bndtools.build.api.DefaultBuildErrorDetailsHandler)1 MarkerData (org.bndtools.build.api.MarkerData)1 IMarker (org.eclipse.core.resources.IMarker)1 IProject (org.eclipse.core.resources.IProject)1 IResource (org.eclipse.core.resources.IResource)1