Example #1
0
  private URI doReplacement(
      String pattern,
      String repoLocation,
      String classifier,
      String id,
      String version,
      String format) {
    try {
      // currently our mapping rules assume the repo URL is not "/" terminated.
      // This may be the case for repoURLs in the root of a URL space e.g. root of a jar file or
      // file:/c:/
      if (repoLocation.endsWith("/")) // $NON-NLS-1$
      repoLocation = repoLocation.substring(0, repoLocation.length() - 1);

      StringBuffer output = new StringBuffer(pattern);
      int index = 0;
      while (index < output.length()) {
        int beginning = output.indexOf("${", index); // $NON-NLS-1$
        if (beginning == -1) return URIUtil.fromString(output.toString());

        int end = output.indexOf("}", beginning); // $NON-NLS-1$
        if (end == -1) return URIUtil.fromString(pattern);

        String varName = output.substring(beginning + 2, end);
        String varValue = null;
        if (varName.equalsIgnoreCase(CLASSIFIER)) {
          varValue = classifier;
        } else if (varName.equalsIgnoreCase(ID)) {
          varValue = id;
        } else if (varName.equalsIgnoreCase(VERSION)) {
          varValue = version;
        } else if (varName.equalsIgnoreCase(REPOURL)) {
          varValue = repoLocation;
        } else if (varName.equalsIgnoreCase(FORMAT)) {
          varValue = format;
        }
        if (varValue == null) varValue = ""; // $NON-NLS-1$

        output.replace(beginning, end + 1, varValue);
        index = beginning + varValue.length();
      }
      return URIUtil.fromString(output.toString());
    } catch (URISyntaxException e) {
      return null;
    }
  }
Example #2
0
  public static IFileArtifactRepository getAggregatedBundleRepository(
      IProvisioningAgent agent, IProfile profile, int repoFilter) {
    List<IFileArtifactRepository> bundleRepositories = new ArrayList<IFileArtifactRepository>();

    // we check for a shared bundle pool first as it should be preferred over the user bundle pool
    // in a shared install
    IArtifactRepositoryManager manager = getArtifactRepositoryManager(agent);
    if ((repoFilter & AGGREGATE_SHARED_CACHE) != 0) {
      String sharedCache = profile.getProperty(IProfile.PROP_SHARED_CACHE);
      if (sharedCache != null) {
        try {
          URI repoLocation = new File(sharedCache).toURI();
          IArtifactRepository repository = manager.loadRepository(repoLocation, null);
          if (repository != null
              && repository instanceof IFileArtifactRepository
              && !bundleRepositories.contains(repository))
            bundleRepositories.add((IFileArtifactRepository) repository);
        } catch (ProvisionException e) {
          // skip repository if it could not be read
        }
      }
    }

    if ((repoFilter & AGGREGATE_CACHE) != 0) {
      IFileArtifactRepository bundlePool = Util.getBundlePoolRepository(agent, profile);
      if (bundlePool != null) bundleRepositories.add(bundlePool);
    }

    if ((repoFilter & AGGREGATE_CACHE_EXTENSIONS) != 0) {
      List<String> repos = getListProfileProperty(profile, CACHE_EXTENSIONS);
      for (String repo : repos) {
        try {
          URI repoLocation;
          try {
            repoLocation = new URI(repo);
          } catch (URISyntaxException e) {
            // in 1.0 we wrote unencoded URL strings, so try as an unencoded string
            repoLocation = URIUtil.fromString(repo);
          }
          IArtifactRepository repository = manager.loadRepository(repoLocation, null);
          if (repository != null
              && repository instanceof IFileArtifactRepository
              && !bundleRepositories.contains(repository))
            bundleRepositories.add((IFileArtifactRepository) repository);
        } catch (ProvisionException e) {
          // skip repositories that could not be read
        } catch (URISyntaxException e) {
          // unexpected, URLs should be pre-checked
          LogHelper.log(new Status(IStatus.ERROR, Activator.ID, e.getMessage(), e));
        }
      }
    }
    return new AggregatedBundleRepository(agent, bundleRepositories);
  }
Example #3
0
  protected void processParameter(String arg, String parameter, PublisherInfo pinfo)
      throws URISyntaxException {
    super.processParameter(arg, parameter, pinfo);

    this.append = true; // Always append, otherwise we will end up with nothing

    if (arg.equalsIgnoreCase("-categoryQualifier")) // $NON-NLS-1$
    categoryQualifier = parameter;

    if (arg.equalsIgnoreCase("-categoryDefinition")) // $NON-NLS-1$
    categoryDefinition = URIUtil.fromString(parameter);
  }
 /* (non-Javadoc)
  * @see org.eclipse.wst.jsdt.debug.core.jsdi.ScriptReference#sourceURI()
  */
 public synchronized URI sourceURI() {
   if (sourceuri == null) {
     try {
       sourceuri = URIUtil.fromString(url);
     } catch (IllegalArgumentException iae) {
       try {
         sourceuri = CrossFirePlugin.fileURI(new Path(url));
       } catch (URISyntaxException e) {
         CrossFirePlugin.log(e);
       }
     } catch (URISyntaxException urise) {
       CrossFirePlugin.log(urise);
     }
   }
   return sourceuri;
 }
 /**
  * Parse a URL from a String. This method first tries to treat <code>url</code> as a valid,
  * encoded URL. If that didn't work, it tries to recover from bad URLs, e.g. the unencoded form we
  * used to use in persistent storage.
  *
  * @param url a URL
  * @return the parsed URL or <code>null</code> if the URL couldn't be parsed
  * @since 3.9
  */
 public static URL parseURL(String url) {
   try {
     try {
       return new URI(url).toURL();
     } catch (URISyntaxException e) {
       try {
         // don't log, since we used to store bad (unencoded) URLs
         if (url.startsWith("file:/")) { // $NON-NLS-1$
           // workaround for a bug in the 3-arg URI constructor for paths that contain '[' or ']':
           return new URI("file", null, url.substring(5), null).toURL(); // $NON-NLS-1$
         } else {
           return URIUtil.fromString(url).toURL();
         }
       } catch (URISyntaxException e1) {
         // last try, not expected to happen
         JavaPlugin.log(e);
         return new URL(url);
       }
     }
   } catch (MalformedURLException e) {
     JavaPlugin.log(e);
     return null;
   }
 }
Example #6
0
 /*
  * Set the location of the child repository.
  */
 public void setChild(String value) throws URISyntaxException {
   child = URIUtil.fromString(value);
 }
Example #7
0
 /*
  * Set the location of the composite repository.
  */
 public void setLocation(String value) throws URISyntaxException {
   location = URIUtil.fromString(value);
 }