Esempio n. 1
0
  @Override
  public void updateBundleVersion(
      long bundleId, String groupId, String artifactId, String version) {
    Bundle bundle = context.getBundle(bundleId);
    if (bundle == null) {
      logger.warn(String.format("bundle %d not found", bundleId));
      throw new IllegalStateException("bundle " + bundleId + " not found");
    }

    MavenResolver resolver =
        new MavenResolver(
            getLocalRepository(), config.getRepositories(), null, 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");

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

      bundle.update(new FileInputStream(file));
    } catch (Exception e) {
      throw new IllegalStateException("bundleId: " + bundleId + ", version: " + version, e);
    }
  }
Esempio n. 2
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);
    }
  }
Esempio n. 3
0
  /*
   * (non-Javadoc)
   *
   * @see org.araqne.bundle.BundleManager#updateBundle(long)
   */
  @Override
  public void updateBundle(long bundleId) {
    Bundle bundle = context.getBundle(bundleId);
    if (bundle == null) {
      logger.warn(String.format("bundle %d not found", bundleId));
      throw new IllegalStateException("bundle " + bundleId + " not found");
    }

    try {
      if (!isLocalJar(bundle)) {
        try {
          File before = new File(bundle.getLocation().replace("file://", ""));
          if (before.exists()) {
            File temp = File.createTempFile(before.getName(), "", before.getParentFile());
            temp.delete();
            if (before.renameTo(temp)) {
              MavenResolver resolver =
                  new MavenResolver(
                      getLocalRepository(), config.getRepositories(), null, getKeyStoreManager());
              MavenArtifact artifact = getArtifact(bundle);
              File after = resolver.resolve(artifact);
              if (after.exists()) temp.delete();
              else temp.renameTo(before);
            }
          } else {
            before.getParentFile().mkdirs();
            MavenResolver resolver =
                new MavenResolver(
                    getLocalRepository(), config.getRepositories(), null, getKeyStoreManager());
            MavenArtifact artifact = getArtifact(bundle);
            resolver.resolve(artifact);
          }
        } catch (MavenResolveException e) {
          logger.error("araqne core: maven resolve failed.", e);
          throw new RuntimeException("maven resolve failed. (" + e.getMessage() + ")");
        } catch (IOException e) {
          logger.error("araqne core: create temp file failed.", e);
          throw new RuntimeException("create temp file failed.");
        }
      }
      bundle.update();
    } catch (BundleException e) {
      logger.error("araqne core: updating bundle failed.", e);
    }
  }