Esempio n. 1
0
  private Set<Resource> addProjectBuildBundles(Resolver resolver) {
    if (!Project.BNDFILE.equals(runFile.getName())) return Collections.emptySet();

    Set<Resource> result = new HashSet<Resource>();
    try {

      Project model = Workspace.getProject(runFile.getProject().getLocation().toFile());
      for (Builder builder : model.getSubBuilders()) {
        File file = new File(model.getTarget(), builder.getBsn() + ".jar");
        if (file.isFile()) {
          JarInputStream stream = null;
          try {
            stream = new JarInputStream(new FileInputStream(file));
            Manifest manifest = stream.getManifest();

            Resource resource = helper.createResource(manifest.getMainAttributes());
            result.add(resource);
            resolver.add(resource);
          } catch (IOException e) {
            Plugin.logError("Error reading project bundle " + file, e);
          } finally {
            if (stream != null) stream.close();
          }
        }
      }
    } catch (Exception e) {
      Plugin.logError("Error getting builders for project: " + runFile.getProject(), e);
    }
    return result;
  }
Esempio n. 2
0
  public void testMandatoryPackages() throws Exception {
    RepositoryAdminImpl repoAdmin = createRepositoryAdmin();
    repoAdmin.addRepository(getClass().getResource("/repo_for_mandatory.xml"));

    Resolver resolver = repoAdmin.resolver();
    resolver.add(repoAdmin.getHelper().requirement("bundle", "(symbolicname=res2)"));
    assertFalse(resolver.resolve());

    resolver = repoAdmin.resolver();
    resolver.add(repoAdmin.getHelper().requirement("bundle", "(symbolicname=res3)"));
    assertTrue(resolver.resolve());

    resolver = repoAdmin.resolver();
    resolver.add(repoAdmin.getHelper().requirement("bundle", "(symbolicname=res4)"));
    assertFalse(resolver.resolve());
  }
Esempio n. 3
0
  public void testResolveReq() throws Exception {
    RepositoryAdminImpl repoAdmin = createRepositoryAdmin();
    repoAdmin.addRepository(getClass().getResource("/repo_for_resolvertest.xml"));

    Resolver resolver = repoAdmin.resolver();
    resolver.add(
        repoAdmin.getHelper().requirement("package", "(package=org.apache.felix.test.osgi)"));
    assertTrue(resolver.resolve());
  }
Esempio n. 4
0
  public void testOptionalResolution() throws Exception {
    RepositoryAdminImpl repoAdmin = createRepositoryAdmin();
    repoAdmin.addRepository(getClass().getResource("/repo_for_optional_resources.xml"));

    Resolver resolver = repoAdmin.resolver();
    resolver.add(repoAdmin.getHelper().requirement("bundle", "(symbolicname=res1)"));

    assertTrue(resolver.resolve());
    assertEquals(1, resolver.getRequiredResources().length);
    assertEquals(2, resolver.getOptionalResources().length);
  }
Esempio n. 5
0
  public void testResolveInterrupt() throws Exception {
    RepositoryAdminImpl repoAdmin = createRepositoryAdmin();
    repoAdmin.addRepository(getClass().getResource("/repo_for_resolvertest.xml"));

    Resolver resolver = repoAdmin.resolver();
    resolver.add(
        repoAdmin.getHelper().requirement("package", "(package=org.apache.felix.test.osgi)"));

    Thread.currentThread().interrupt();
    try {
      resolver.resolve();
      fail("An excepiton should have been thrown");
    } catch (org.apache.felix.bundlerepository.InterruptedResolutionException e) {
      // ok
    }
  }
Esempio n. 6
0
  public void testReferral1() throws Exception {

    URL url = getClass().getResource("/repo_for_resolvertest.xml");
    RepositoryAdminImpl repoAdmin = createRepositoryAdmin();
    RepositoryImpl repo = (RepositoryImpl) repoAdmin.addRepository(url);

    Resolver resolver = repoAdmin.resolver();

    Resource[] discoverResources =
        repoAdmin.discoverResources("(symbolicname=org.apache.felix.test*)");
    assertNotNull(discoverResources);
    assertEquals(1, discoverResources.length);

    resolver.add(discoverResources[0]);
    assertTrue(resolver.resolve());
  }
Esempio n. 7
0
  public void run(IProgressMonitor monitor) {
    SubMonitor progress = SubMonitor.convert(monitor, "Resolving...", 0);

    MultiStatus status =
        new MultiStatus(Plugin.PLUGIN_ID, 0, "Problems during OBR resolution", null);

    // Get the repositories
    List<OBRIndexProvider> indexProviders;
    try {
      indexProviders = loadIndexProviders();
    } catch (Exception e) {
      status.add(new Status(IStatus.ERROR, Plugin.PLUGIN_ID, 0, "Error loading OBR indexes.", e));
      result = createErrorResult(status);
      return;
    }

    // Create the dummy system bundle and repository admin
    File frameworkFile = findFramework(status);
    if (frameworkFile == null) {
      result = createErrorResult(status);
      return;
    }
    DummyBundleContext bundleContext;
    try {
      bundleContext = new DummyBundleContext(frameworkFile);
    } catch (IOException e) {
      status.add(
          new Status(
              IStatus.ERROR, Plugin.PLUGIN_ID, 0, "Error reading system bundle manifest.", e));
      result = createErrorResult(status);
      return;
    }

    // Load repository indexes
    List<Repository> repos = new LinkedList<Repository>();
    for (OBRIndexProvider prov : indexProviders) {
      String repoName;
      if (prov instanceof RepositoryPlugin) {
        RepositoryPlugin repo = (RepositoryPlugin) prov;
        repoName = repo.getName();
      } else {
        repoName = prov.toString();
      }

      File cacheDir;
      if (prov instanceof RemoteRepositoryPlugin) {
        cacheDir = ((RemoteRepositoryPlugin) prov).getCacheDirectory();
      } else {
        cacheDir = Plugin.getDefault().getStateLocation().toFile();
      }

      try {
        for (URL indexUrl : prov.getOBRIndexes()) {
          addRepository(indexUrl, repos, cacheDir);
        }
      } catch (Exception e) {
        status.add(
            new Status(
                IStatus.ERROR,
                Plugin.PLUGIN_ID,
                0,
                "Error processing index for repository " + repoName,
                e));
      }
    }

    RepositoryAdminImpl repoAdmin =
        new RepositoryAdminImpl(bundleContext, new Logger(Plugin.getDefault().getBundleContext()));

    repos.add(
        0,
        repoAdmin
            .getLocalRepository()); // BUG? Calling `resolver(Repository[])` excludes the local and
                                    // system repos!
    repos.add(0, repoAdmin.getSystemRepository());
    Resolver resolver = repoAdmin.resolver(repos.toArray(new Repository[repos.size()]));

    // Add project builders
    Set<Resource> projectBuildResources = addProjectBuildBundles(resolver);

    // Add EE capabilities
    EE ee = model.getEE();
    if (ee == null) ee = EE.J2SE_1_5; // TODO: read default from the workbench
    resolver.addGlobalCapability(createEeCapability(ee));
    for (EE compat : ee.getCompatible()) {
      resolver.addGlobalCapability(createEeCapability(compat));
    }

    // Add JRE package capabilities
    try {
      addJREPackageCapabilities(resolver, ee);
    } catch (IOException e) {
      status.add(
          new Status(
              IStatus.ERROR, Plugin.PLUGIN_ID, 0, "Error adding JRE package capabilities", e));
      result = createErrorResult(status);
      return;
    }

    // HACK: add capabilities for usual framework services (not all frameworks declare these
    // statically)
    String[] frameworkServices =
        new String[] {
          "org.osgi.service.packageadmin.PackageAdmin",
          "org.osgi.service.startlevel.StartLevel",
          "org.osgi.service.permissionadmin.PermissionAdmin"
        };
    for (String frameworkService : frameworkServices) {
      Map<String, String> props = new HashMap<String, String>();
      props.put(ObrConstants.FILTER_SERVICE, frameworkService);
      resolver.addGlobalCapability(helper.capability(ObrConstants.REQUIREMENT_SERVICE, props));
    }

    // Add system packages-extra capabilities (from -runsystempackages)
    List<ExportedPackage> systemPackages = model.getSystemPackages();
    if (systemPackages != null) addSystemPackagesExtraCapabilities(resolver, systemPackages);

    // Add requirements
    List<bndtools.api.Requirement> requirements = model.getRunRequire();
    if (requirements != null)
      for (bndtools.api.Requirement req : requirements) {
        resolver.add(helper.requirement(req.getName(), req.getFilter()));
      }

    boolean resolved = resolver.resolve();

    result =
        new ObrResolutionResult(
            resolved,
            Status.OK_STATUS,
            filterGlobalResource(resolver.getRequiredResources()),
            filterGlobalResource(resolver.getOptionalResources()),
            Arrays.asList(resolver.getUnsatisfiedRequirements()));
  }