org.apache.tools.ant.types.resources.URLResource Java Examples

The following examples show how to use org.apache.tools.ant.types.resources.URLResource. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: WorkerProcessClassPathProvider.java    From pushfish-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
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);

    final List<Resource> classResources = new ArrayList<Resource>();
    List<Class<?>> renamedClasses = Arrays.asList(GradleWorkerMain.class,
            BootstrapSecurityManager.class,
            EncodedStream.EncodedInput.class);
    List<Class<?>> classes = new ArrayList<Class<?>>();
    classes.add(BootstrapClassLoaderWorker.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;
        }
    });

    for (Class<?> renamedClass : renamedClasses) {
        Rule rule = new Rule();
        rule.setPattern(renamedClass.getName());
        rule.setResult("jarjar.@0");
        task.addConfiguredRule(rule);
    }

    AntUtil.execute(task);
}
 
Example #2
Source File: WorkerProcessClassPathProvider.java    From pushfish-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
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);

    final List<Resource> classResources = new ArrayList<Resource>();
    List<Class<?>> renamedClasses = Arrays.asList(GradleWorkerMain.class,
            BootstrapSecurityManager.class,
            EncodedStream.EncodedInput.class);
    List<Class<?>> classes = new ArrayList<Class<?>>();
    classes.add(BootstrapClassLoaderWorker.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;
        }
    });

    for (Class<?> renamedClass : renamedClasses) {
        Rule rule = new Rule();
        rule.setPattern(renamedClass.getName());
        rule.setResult("jarjar.@0");
        task.addConfiguredRule(rule);
    }

    AntUtil.execute(task);
}
 
Example #3
Source File: WorkerProcessClassPathProvider.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
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);

    final List<Resource> classResources = new ArrayList<Resource>();
    List<Class<?>> renamedClasses = Arrays.asList(GradleWorkerMain.class,
            BootstrapSecurityManager.class,
            EncodedStream.EncodedInput.class);
    List<Class<?>> classes = new ArrayList<Class<?>>();
    classes.add(BootstrapClassLoaderWorker.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;
        }
    });

    for (Class<?> renamedClass : renamedClasses) {
        Rule rule = new Rule();
        rule.setPattern(renamedClass.getName());
        rule.setResult("jarjar.@0");
        task.addConfiguredRule(rule);
    }

    AntUtil.execute(task);
}
 
Example #4
Source File: WorkerProcessClassPathProvider.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
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);

    final List<Resource> classResources = new ArrayList<Resource>();
    List<Class<?>> renamedClasses = Arrays.asList(GradleWorkerMain.class,
            BootstrapSecurityManager.class,
            EncodedStream.EncodedInput.class);
    List<Class<?>> classes = new ArrayList<Class<?>>();
    classes.add(BootstrapClassLoaderWorker.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;
        }
    });

    for (Class<?> renamedClass : renamedClasses) {
        Rule rule = new Rule();
        rule.setPattern(renamedClass.getName());
        rule.setResult("jarjar.@0");
        task.addConfiguredRule(rule);
    }

    AntUtil.execute(task);
}