示例#1
0
  /*
   * (non-Javadoc)
   *
   * @see org.araqne.bundle.BundleManager#installBundle(org.araqne.pkg.
   * ProgressMonitor, java.lang.String, java.lang.String, java.lang.String)
   */
  @Override
  public long installBundle(
      ProgressMonitor monitor, String groupId, String artifactId, String version)
      throws MavenResolveException {
    MavenResolver resolver =
        new MavenResolver(
            getLocalRepository(), config.getRepositories(), monitor, getKeyStoreManager());
    Version v = (version != null) ? new Version(version) : null;
    MavenArtifact artifact = new MavenArtifact(groupId, artifactId, v);

    if (isBuiltinArtifact(artifact.getGroupId(), artifact.getArtifactId()))
      throw new IllegalStateException("provided in system bundle");

    if (monitor != null)
      monitor.writeln(
          String.format("Resolving %s/%s", artifact.getGroupId(), artifact.getArtifactId())
              + (artifact.getVersion() != null ? (" (" + artifact.getVersion() + ")") : ""));

    File file = resolver.resolve(artifact);
    if (!isBundleJar(file))
      throw new IllegalStateException(
          "invalid OSGi bundle: " + groupId + "/" + artifactId + " (" + version + ")");

    String filePath = file.getAbsolutePath();

    try {
      Bundle newBundle = context.installBundle(getPrefix() + filePath.replace('\\', '/'));
      if (newBundle.getSymbolicName() == null) newBundle.uninstall();

      return newBundle.getBundleId();
    } catch (BundleException e) {
      throw new IllegalStateException(e);
    }
  }