Пример #1
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);
  }
Пример #2
0
 /**
  * Send a result through, with necessary logging.
  *
  * @param result The result to send through
  * @return The same result/object
  * @checkstyle DesignForExtensionCheck (2 lines)
  */
 public Object through(final Object result) {
   final int hit = this.accessed.getAndIncrement();
   final Class<?> type = this.method.getDeclaringClass();
   if (hit > 0 && LogHelper.enabled(this.level, type)) {
     LogHelper.log(
         this.level,
         type,
         "%s: %s from cache (hit #%d, %[ms]s old)",
         this,
         Mnemos.toText(result, true, false),
         hit,
         System.currentTimeMillis() - this.start);
   }
   return result;
 }
Пример #3
0
 public static synchronized IFileArtifactRepository getBundlePoolRepository(
     IProvisioningAgent agent, IProfile profile) {
   URI location = getBundlePoolLocation(agent, profile);
   if (location == null) return null;
   IArtifactRepositoryManager manager = getArtifactRepositoryManager(agent);
   try {
     return (IFileArtifactRepository) manager.loadRepository(location, null);
   } catch (ProvisionException e) {
     // the repository doesn't exist, so fall through and create a new one
   }
   try {
     String repositoryName = Messages.BundlePool;
     Map<String, String> properties = new HashMap<String, String>(1);
     properties.put(IRepository.PROP_SYSTEM, Boolean.TRUE.toString());
     return (IFileArtifactRepository)
         manager.createRepository(location, repositoryName, REPOSITORY_TYPE, properties);
   } catch (ProvisionException e) {
     LogHelper.log(e);
     throw new IllegalArgumentException(NLS.bind(Messages.bundle_pool_not_writeable, location));
   }
 }
Пример #4
0
 /**
  * Flush cache.
  *
  * @param point Joint point
  * @param when When it happens
  * @since 0.7.18
  */
 private void flush(final JoinPoint point, final String when) {
   synchronized (this.tunnels) {
     for (final MethodCacher.Key key : this.tunnels.keySet()) {
       if (!key.sameTarget(point)) {
         continue;
       }
       final MethodCacher.Tunnel removed = this.tunnels.remove(key);
       final Method method = MethodSignature.class.cast(point.getSignature()).getMethod();
       if (LogHelper.enabled(key.getLevel(), method.getDeclaringClass())) {
         LogHelper.log(
             key.getLevel(),
             method.getDeclaringClass(),
             "%s: %s:%s removed from cache %s",
             Mnemos.toText(method, point.getArgs(), true, false),
             key,
             removed,
             when);
       }
     }
   }
 }
Пример #5
0
  public static BundleInfo createBundleInfo(File bundleFile, IInstallableUnit unit) {
    BundleInfo bundleInfo = new BundleInfo();
    if (bundleFile != null) bundleInfo.setLocation(bundleFile.toURI());

    Collection<IProvidedCapability> capabilities = unit.getProvidedCapabilities();
    for (IProvidedCapability capability : capabilities) {
      String nameSpace = capability.getNamespace();
      if (nameSpace.equals("osgi.bundle")) { // $NON-NLS-1$
        bundleInfo.setSymbolicName(capability.getName());
        bundleInfo.setVersion(capability.getVersion().toString());
      } else if (nameSpace.equals("osgi.fragment")) { // $NON-NLS-1$
        String fragmentName = capability.getName();
        String fragmentHost = getFragmentHost(unit, fragmentName);
        // shouldn't happen as long as the metadata is well-formed
        if (fragmentHost == null)
          LogHelper.log(createError("Unable to find fragment host for IU: " + unit)); // $NON-NLS-1$
        else bundleInfo.setFragmentHost(fragmentHost);
        bundleInfo.setVersion(capability.getVersion().toString());
      }
    }
    return bundleInfo;
  }
Пример #6
0
 /**
  * Get a result through the tunnel.
  *
  * @return The result
  * @throws Throwable If something goes wrong inside
  * @checkstyle IllegalThrows (5 lines)
  */
 @SuppressWarnings("PMD.AvoidSynchronizedAtMethodLevel")
 public synchronized Object through() throws Throwable {
   if (!this.executed) {
     final long start = System.currentTimeMillis();
     final Object result = this.point.proceed();
     this.hasresult = result != null;
     this.cached = new SoftReference<Object>(result);
     final Method method = MethodSignature.class.cast(this.point.getSignature()).getMethod();
     final Cacheable annot = method.getAnnotation(Cacheable.class);
     final String suffix;
     if (annot.forever()) {
       this.lifetime = Long.MAX_VALUE;
       suffix = "valid forever";
     } else if (annot.lifetime() == 0) {
       this.lifetime = 0L;
       suffix = "invalid immediately";
     } else {
       final long msec = annot.unit().toMillis((long) annot.lifetime());
       this.lifetime = start + msec;
       suffix = Logger.format("valid for %[ms]s", msec);
     }
     final Class<?> type = method.getDeclaringClass();
     if (LogHelper.enabled(this.key.getLevel(), type)) {
       LogHelper.log(
           this.key.getLevel(),
           type,
           "%s: %s cached in %[ms]s, %s",
           Mnemos.toText(method, this.point.getArgs(), true, false),
           Mnemos.toText(this.cached.get(), true, false),
           System.currentTimeMillis() - start,
           suffix);
     }
     this.executed = true;
   }
   return this.key.through(this.cached.get());
 }
Пример #7
0
 /** User-level log method ( called from a servlet) */
 public void logServlet(String msg, Throwable t) {
   msg = ("path=\"" + path + "\" :" + msg);
   loghelperServlet.log(msg, t);
 }
Пример #8
0
 /** Internal log method */
 public void log(String msg, Throwable t, int level) {
   loghelper.log(msg, t, level);
 }
Пример #9
0
 /** Internal log method */
 public void log(String msg, Throwable t) {
   loghelper.log(msg, t);
 }
Пример #10
0
 /** Internal log method */
 public final void log(String msg) {
   loghelper.log(msg);
 }