public void execute(PersistentCache cache) {
      File jarFile = jarFile(cache);
      LOGGER.debug("Generating worker process classes to {}.", jarFile);

      URL currentClasspath = getClass().getProtectionDomain().getCodeSource().getLocation();
      JarJarTask task = new JarJarTask();
      task.setDestFile(jarFile);

      // TODO - calculate this list of classes dynamically
      final List<Resource> classResources = new ArrayList<Resource>();
      List<Class<?>> renamedClasses =
          Arrays.asList(
              GradleWorkerMain.class,
              BootstrapSecurityManager.class,
              EncodedStream.EncodedInput.class,
              FilteringClassLoader.class,
              FilteringClassLoader.Spec.class,
              ClassLoaderHierarchy.class,
              ClassLoaderVisitor.class,
              ClassLoaderSpec.class,
              JavaReflectionUtil.class,
              JavaMethod.class,
              GradleException.class,
              NoSuchPropertyException.class,
              NoSuchMethodException.class,
              UncheckedException.class,
              PropertyAccessor.class,
              PropertyMutator.class,
              Factory.class,
              Spec.class);
      List<Class<?>> classes = new ArrayList<Class<?>>();
      classes.addAll(renamedClasses);
      for (Class<?> aClass : classes) {
        final String fileName = aClass.getName().replace('.', '/') + ".class";

        // Prefer the class from the same classpath as the current class. This is for the case where
        // we're running in a test under an older
        // version of Gradle, whose worker classes will be visible to us.
        // TODO - remove this once we have upgraded to a wrapper with these changes in it
        Enumeration<URL> resources;
        try {
          resources = WorkerProcessClassPathProvider.class.getClassLoader().getResources(fileName);
        } catch (IOException e) {
          throw new UncheckedIOException(e);
        }
        URL resource = null;
        while (resources.hasMoreElements()) {
          URL url = resources.nextElement();
          resource = url;
          if (url.toString().startsWith(currentClasspath.toString())) {
            break;
          }
        }
        URLResource urlResource =
            new URLResource(resource) {
              @Override
              public synchronized String getName() {
                return fileName;
              }
            };
        classResources.add(urlResource);
      }

      task.add(
          new ResourceCollection() {
            public Iterator iterator() {
              return classResources.iterator();
            }

            public int size() {
              return classResources.size();
            }

            public boolean isFilesystemOnly() {
              return true;
            }
          });

      // Don't rename references to this class
      Rule rule = new Rule();
      rule.setPattern(SystemApplicationClassLoaderWorker.class.getName());
      rule.setResult(SystemApplicationClassLoaderWorker.class.getName());
      task.addConfiguredRule(rule);

      // Rename everything else
      rule = new Rule();
      rule.setPattern("org.gradle.**");
      rule.setResult("jarjar.@0");
      task.addConfiguredRule(rule);

      AntUtil.execute(task);
    }
Пример #2
0
 public void addSetMethod(Method method) {
   setMethods.add(method);
 }
Пример #3
0
 public void addSetter(Method method) {
   setters.add(method);
 }
Пример #4
0
 public void addGetter(Method method) {
   if (getters.add(method) && method.getAnnotation(Inject.class) != null) {
     injector = true;
   }
 }
Пример #5
0
 public void addCandidateSetMethod(Method method) {
   setMethods.add(method);
 }
Пример #6
0
 public void addActionMethod(Method method) {
   actionMethods.add(method);
 }