예제 #1
0
  /**
   * retrieves the version from the install uri
   *
   * @param uri
   * @param packaging
   * @return
   */
  public static String getBundleVersionFromURI(String uri, String packaging) {
    String version = null;

    if (uri != null && uri.indexOf("Bundle-Version=") != -1) {
      version = uri.substring(uri.indexOf("Bundle-Version=") + "Bundle-Version=".length());
    } else if (uri != null && uri.endsWith(KarafUtils.getFileExtensionForPackaging(packaging))) {
      String s = uri.substring(uri.lastIndexOf(File.separatorChar) + 1);
      String pack = KarafUtils.getFileExtensionForPackaging(packaging);
      boolean versionDigitsFound = false;
      int pointCount = 0;
      version = "";
      for (int i = s.length() - pack.length() - 1; i >= 0; i--) {
        char c = s.charAt(i);
        if (Character.isAlphabetic(c)) {
          if (versionDigitsFound) break;
        } else if (Character.isDigit(c)) {
          versionDigitsFound = true;
        } else if (c == '-') {
          if (versionDigitsFound) break;
        } else if (c == '.') {
          pointCount++;
          if (pointCount > 2) break;
        }
        version = c + version;
      }
      // finally replace a possible - with a . to be OSGi compliant
      if (version.indexOf("-") != -1) version = version.replaceAll("-", ".");
    }

    return version;
  }
예제 #2
0
 /**
  * @param module
  * @return
  */
 public static String getBundleFilePath(final IModule module) throws CoreException {
   final String packaging = getPackaging(module);
   final String artifactId = getArtifactId(module);
   File projectTargetPath = module.getProject().getLocation().append("target").toFile();
   File[] jars =
       projectTargetPath.listFiles(
           new FileFilter() {
             /*
              * (non-Javadoc)
              * @see java.io.FileFilter#accept(java.io.File)
              */
             @Override
             public boolean accept(File pathname) {
               return pathname.exists()
                   && pathname.isFile()
                   && (pathname
                           .getName()
                           .toLowerCase()
                           .startsWith(module.getProject().getName().toLowerCase())
                       || pathname.getName().toLowerCase().startsWith(artifactId.toLowerCase()))
                   && pathname
                       .getName()
                       .toLowerCase()
                       .endsWith(getFileExtensionForPackaging(packaging));
             }
           });
   if (jars != null && jars.length > 0) {
     if (packaging.equalsIgnoreCase(PACKAGING_BUNDLE)) {
       return String.format("%sfile:%s", getProtocolPrefixForModule(module), jars[0].getPath());
     } else if (packaging.equalsIgnoreCase(PACKAGING_JAR)) {
       return String.format(
           "%sfile:%s$Bundle-SymbolicName=%s&Bundle-Version=%s",
           getProtocolPrefixForModule(module),
           jars[0].getPath(),
           KarafUtils.getBundleSymbolicName(module),
           getBundleVersion(module, jars[0]));
     } else if (packaging.equalsIgnoreCase(PACKAGING_WAR)) {
       return String.format(
           "%sfile:%s?Bundle-SymbolicName=%s&Bundle-Version=%s",
           getProtocolPrefixForModule(module),
           jars[0].getPath(),
           KarafUtils.getBundleSymbolicName(module),
           getBundleVersion(module, jars[0]));
     }
   }
   return null;
 }