Package org.osgi.service.indexer

Examples of org.osgi.service.indexer.ResourceAnalyzer


            for (ResourceAnalyzer analyzer : analyzers) {
                indexer.addAnalyzer(analyzer, null);
            }

            // Use an analyzer to add a marker capability to workspace resources
            indexer.addAnalyzer(new ResourceAnalyzer() {
                public void analyzeResource(Resource resource, List<Capability> capabilities, List<Requirement> requirements) throws Exception {
                    Capability cap = new Builder().setNamespace("bndtools.workspace").addAttribute("bndtools.workspace", workspaceRootUri.toString()).addAttribute("project.path", project.getFullPath().toString()).buildCapability();
                    capabilities.add(cap);
                }
            }, null);
View Full Code Here


            for (ResourceAnalyzer analyzer : analyzers) {
                indexer.addAnalyzer(analyzer, null);
            }

            // Use an analyzer to add a marker capability to workspace resources
            indexer.addAnalyzer(new ResourceAnalyzer() {
                public void analyzeResource(Resource resource, List<Capability> capabilities, List<Requirement> requirements) throws Exception {
                    Capability cap = new Builder().setNamespace("bndtools.workspace").addAttribute("bndtools.workspace", workspaceRootUri.toString()).addAttribute("project.path", project.getFullPath().toString()).buildCapability();
                    capabilities.add(cap);
                }
            }, null);
View Full Code Here

   
    // Iterate over the analyzers
    try {
      synchronized (analyzers) {
        for (Pair<ResourceAnalyzer, Filter> entry : analyzers) {
          ResourceAnalyzer analyzer = entry.getFirst();
          Filter filter = entry.getSecond();
         
          if (filter == null || filter.match(resource.getProperties())) {
            try {
              analyzer.analyzeResource(resource, caps, reqs);
            } catch (Exception e) {
              log(LogService.LOG_ERROR, MessageFormat.format("Error calling analyzer \"{0}\" on resource {1}.", analyzer.getClass().getName(), resource.getLocation()), e);
            }
          }
        }
      }
    } finally {
View Full Code Here

    // Register mock LogService, to receive notifications
    LogService mockLog = mock(LogService.class);
    ServiceRegistration mockLogReg = context.registerService(LogService.class.getName(), mockLog, null);

    // Register a broken analyzer that throws exceptions
    ResourceAnalyzer brokenAnalyzer = new ResourceAnalyzer() {
      public void analyzeResource(Resource resource, List<Capability> capabilities, List<Requirement> requirements) throws Exception {
        throw new Exception("Bang!");
      }
    };
    ServiceRegistration mockAnalyzerReg = context.registerService(ResourceAnalyzer.class.getName(), brokenAnalyzer, null);
View Full Code Here

    TrackingStruct struct = new TrackingStruct();
    try {
      String filterStr = (String) reference.getProperty(ResourceAnalyzer.FILTER);
      Filter filter = (filterStr != null) ? FrameworkUtil.createFilter(filterStr) : null;

      ResourceAnalyzer analyzer = (ResourceAnalyzer) context.getService(reference);
      if (analyzer == null)
        return null;

      struct = new TrackingStruct();
      struct.analyzer = analyzer;
View Full Code Here

   
    // Iterate over the analyzers
    try {
      synchronized (analyzers) {
        for (Pair<ResourceAnalyzer, Filter> entry : analyzers) {
          ResourceAnalyzer analyzer = entry.getFirst();
          Filter filter = entry.getSecond();
         
          if (filter == null || filter.match(resource.getProperties())) {
            try {
              analyzer.analyzeResource(resource, caps, reqs);
            } catch (Exception e) {
              log(LogService.LOG_ERROR, MessageFormat.format("Error calling analyzer \"{0}\" on resource {1}.", analyzer.getClass().getName(), resource.getLocation()), e);
            }
          }
        }
      }
    } finally {
View Full Code Here

    TrackingStruct struct = new TrackingStruct();
    try {
      String filterStr = (String) reference.getProperty(ResourceAnalyzer.FILTER);
      Filter filter = (filterStr != null) ? FrameworkUtil.createFilter(filterStr) : null;

      ResourceAnalyzer analyzer = (ResourceAnalyzer) context.getService(reference);
      if (analyzer == null)
        return null;

      struct = new TrackingStruct();
      struct.analyzer = analyzer;
View Full Code Here

   
    // Iterate over the analyzers
    try {
      synchronized (analyzers) {
        for (Pair<ResourceAnalyzer, Filter> entry : analyzers) {
          ResourceAnalyzer analyzer = entry.getFirst();
          Filter filter = entry.getSecond();
         
          if (filter == null || filter.match(resource.getProperties())) {
            try {
              analyzer.analyzeResource(resource, caps, reqs);
            } catch (Exception e) {
              log(LogService.LOG_ERROR, MessageFormat.format("Error calling analyzer \"{0}\" on resource {1}.", analyzer.getClass().getName(), resource.getLocation()), e);
            }
          }
        }
      }
    } finally {
View Full Code Here

    // Iterate over the analyzers
    try {
      synchronized (analyzers) {
        for (Pair<ResourceAnalyzer, Filter> entry : analyzers) {
          ResourceAnalyzer analyzer = entry.getFirst();
          Filter filter = entry.getSecond();
         
          if (filter == null || filter.match(resource.getProperties())) {
            try {
              analyzer.analyzeResource(resource, caps, reqs);
            } catch (Exception e) {
              log(LogService.LOG_ERROR, MessageFormat.format("Error calling analyzer \"{0}\" on resource {1}.", analyzer.getClass().getName(), resource.getLocation()), e);
            }
          }
        }
      }
    } finally {
View Full Code Here

    String expected = Utils.readStream(new FileInputStream("testdata/fragment-subdir2.txt"));
    assertEquals(expected, writer.toString().trim());
  }

  public void testLogErrorsFromAnalyzer() throws Exception {
    ResourceAnalyzer badAnalyzer = new ResourceAnalyzer() {
      public void analyzeResource(Resource resource, List<Capability> capabilities, List<Requirement> requirements) throws Exception {
        throw new Exception("Bang!");
      }
    };
    ResourceAnalyzer goodAnalyzer = mock(ResourceAnalyzer.class);

    LogService log = mock(LogService.class);
    RepoIndex indexer = new RepoIndex(log);
    indexer.addAnalyzer(badAnalyzer, null);
    indexer.addAnalyzer(goodAnalyzer, null);
View Full Code Here

TOP

Related Classes of org.osgi.service.indexer.ResourceAnalyzer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.