/** We parse the -runremote and create sessions for each one of them */
  @Override
  public void prepare() throws Exception {
    if (prepared) return;

    prepared = true;

    updateFromProject();

    Map<String, Object> properties = new HashMap<String, Object>(getRunProperties());

    calculatedProperties(properties);

    Collection<String> embeddedActivators = getActivators();
    if (embeddedActivators != null && !embeddedActivators.isEmpty()) {
      properties.put("biz.aQute.remote.embedded", Strings.join(embeddedActivators));
    }

    for (Entry<String, Attrs> entry : runremote.entrySet()) {
      RunRemoteDTO dto = converter.convert(RunRemoteDTO.class, entry.getValue());
      dto.name = entry.getKey();

      Map<String, Object> sessionProperties = new HashMap<String, Object>(properties);
      sessionProperties.putAll(entry.getValue());
      sessionProperties.put("session.name", dto.name);

      if (dto.jmx != null) {
        tryJMXDeploy(dto.jmx, "biz.aQute.remote.agent");
      }

      RunSessionImpl session = new RunSessionImpl(this, dto, properties);
      sessions.add(session);
    }
  }
Exemplo n.º 2
0
 public static List<Capability> getCapabilitiesFrom(Parameters rr) throws Exception {
   List<Capability> capabilities = new ArrayList<>();
   for (Entry<String, Attrs> e : rr.entrySet()) {
     capabilities.add(
         getCapabilityFrom(Processor.removeDuplicateMarker(e.getKey()), e.getValue()));
   }
   return capabilities;
 }
Exemplo n.º 3
0
 public static List<Requirement> getRequirementsFrom(Parameters rr) throws Exception {
   List<Requirement> requirements = new ArrayList<Requirement>();
   for (Entry<String, Attrs> e : rr.entrySet()) {
     requirements.add(
         getRequirementFrom(Processor.removeDuplicateMarker(e.getKey()), e.getValue()));
   }
   return requirements;
 }
Exemplo n.º 4
0
  /** @throws Exception */
  File[] getBundleClasspathFiles() throws Exception {

    if (this.bundleClasspathExpansion != null) return bundleClasspathExpansion;

    File file = getFile();

    Manifest m = getManifest();
    String bundleClassPath;
    if (m == null
        || (bundleClassPath = m.getMainAttributes().getValue(Constants.BUNDLE_CLASSPATH)) == null) {
      this.bundleClasspathExpansion = new File[] {file};
    } else {

      File bundleClasspathDirectory =
          IO.getFile(file.getParentFile(), "." + file.getName() + "-bcp");
      Parameters header = new Parameters(bundleClassPath);
      this.bundleClasspathExpansion = new File[header.size()];
      bundleClasspathDirectory.mkdir();

      int n = 0;
      Jar jar = null;
      try {
        for (Map.Entry<String, Attrs> entry : header.entrySet()) {
          if (".".equals(entry.getKey())) {
            this.bundleClasspathExpansion[n] = file;
          } else {
            File member = new File(bundleClasspathDirectory, n + "-" + toName(entry.getKey()));
            if (!isCurrent(file, member)) {

              if (jar == null) {
                jar = new Jar(file);
              }

              Resource resource = jar.getResource(entry.getKey());
              if (resource == null) {
                warning += "Invalid bcp entry: " + entry.getKey() + "\n";
              } else {
                IO.copy(resource.openInputStream(), member);
                member.setLastModified(file.lastModified());
              }
            }
            this.bundleClasspathExpansion[n] = member;
          }
          n++;
        }
      } finally {
        if (jar != null) jar.close();
      }
    }

    return this.bundleClasspathExpansion;
  }
Exemplo n.º 5
0
  public CommandData parseCommandData(ArtifactData artifact) throws Exception {
    File source = new File(artifact.file);
    if (!source.isFile()) throw new FileNotFoundException();

    CommandData data = new CommandData();
    data.sha = artifact.sha;
    data.jpmRepoDir = repoDir.getCanonicalPath();
    JarFile jar = new JarFile(source);
    try {
      reporter.trace("Parsing %s", source);
      Manifest m = jar.getManifest();
      Attributes main = m.getMainAttributes();
      data.name = data.bsn = main.getValue("Bundle-SymbolicName");
      String version = main.getValue("Bundle-Version");
      if (version == null) data.version = Version.LOWEST;
      else data.version = new Version(version);

      data.main = main.getValue("Main-Class");
      data.description = main.getValue("Bundle-Description");
      data.title = main.getValue("JPM-Name");

      reporter.trace("name " + data.name + " " + data.main + " " + data.title);
      DependencyCollector path = new DependencyCollector(this);
      path.add(artifact);
      DependencyCollector bundles = new DependencyCollector(this);
      if (main.getValue("JPM-Classpath") != null) {
        Parameters requires = OSGiHeader.parseHeader(main.getValue("JPM-Classpath"));

        for (Map.Entry<String, Attrs> e : requires.entrySet()) {
          path.add(e.getKey(), e.getValue().get("name")); // coordinate
        }
      } else if (!artifact.local) { // No JPM-Classpath, falling back to
        // server's revision
        // Iterable<RevisionRef> closure =
        // library.getClosure(artifact.sha,
        // false);
        // System.out.println("getting closure " + artifact.url + " " +
        // Strings.join("\n",closure));

        // if (closure != null) {
        // for (RevisionRef ref : closure) {
        // path.add(Hex.toHexString(ref.revision));
        // }
        // }
      }

      if (main.getValue("JPM-Runbundles") != null) {
        Parameters jpmrunbundles = OSGiHeader.parseHeader(main.getValue("JPM-Runbundles"));

        for (Map.Entry<String, Attrs> e : jpmrunbundles.entrySet()) {
          bundles.add(e.getKey(), e.getValue().get("name"));
        }
      }

      reporter.trace("collect digests runpath");
      data.dependencies.addAll(path.getDigests());
      reporter.trace("collect digests bundles");
      data.runbundles.addAll(bundles.getDigests());

      Parameters command = OSGiHeader.parseHeader(main.getValue("JPM-Command"));
      if (command.size() > 1) reporter.error("Only one command can be specified");

      for (Map.Entry<String, Attrs> e : command.entrySet()) {
        data.name = e.getKey();

        Attrs attrs = e.getValue();

        if (attrs.containsKey("jvmargs")) data.jvmArgs = attrs.get("jvmargs");

        if (attrs.containsKey("title")) data.title = attrs.get("title");

        if (data.title != null) data.title = data.name;
      }
      return data;
    } finally {
      jar.close();
    }
  }
  private void _processURL(StringBundler sb, URL url, String[] ignoredFragments) {

    Manifest manifest = null;

    try {
      manifest = new Manifest(url.openStream());
    } catch (IOException ioe) {
      _log.error(ioe, ioe);

      return;
    }

    Attributes attributes = manifest.getMainAttributes();

    String bundleSymbolicName = attributes.getValue(Constants.BUNDLE_SYMBOLICNAME);

    if (Validator.isNull(bundleSymbolicName)) {
      String urlString = url.toString();

      if (urlString.contains(PropsValues.LIFERAY_LIB_PORTAL_DIR)) {
        manifest = _calculateManifest(url, manifest);

        attributes = manifest.getMainAttributes();

        bundleSymbolicName =
            attributes.getValue(new Attributes.Name(Constants.BUNDLE_SYMBOLICNAME));

        if (Validator.isNull(bundleSymbolicName)) {
          return;
        }
      } else {
        return;
      }
    }

    String rootBundleSymbolicName = bundleSymbolicName;

    int index = rootBundleSymbolicName.indexOf(StringPool.SEMICOLON);

    if (index != -1) {
      rootBundleSymbolicName = rootBundleSymbolicName.substring(0, index);
    }

    for (String ignoredFragment : ignoredFragments) {
      String ignoredFramentPrefix = ignoredFragment.substring(0, ignoredFragment.length() - 1);

      if (rootBundleSymbolicName.equals(ignoredFragment)
          || (ignoredFragment.endsWith(StringPool.STAR)
              && rootBundleSymbolicName.startsWith(ignoredFramentPrefix))) {

        return;
      }
    }

    String exportPackage = GetterUtil.getString(attributes.getValue(Constants.EXPORT_PACKAGE));

    Parameters parameters = OSGiHeader.parseHeader(exportPackage);

    for (Map.Entry<String, Attrs> entry : parameters.entrySet()) {
      String key = entry.getKey();

      List<URL> urls = _extraPackageMap.get(key);

      if (urls == null) {
        urls = new ArrayList<URL>();

        _extraPackageMap.put(key, urls);
      }

      urls.add(url);

      sb.append(key);

      Attrs value = entry.getValue();

      if (value.containsKey("version")) {
        sb.append(";version=\"");
        sb.append(value.get("version"));
        sb.append("\"");
      }

      sb.append(StringPool.COMMA);
    }
  }