Search in sources :

Example 1 with AlternateJdkLoader

use of org.eclipse.xtext.util.internal.AlternateJdkLoader in project xtext-xtend by eclipse.

the class ProcessorInstanceForJvmTypeProvider method getClassLoader.

public ClassLoader getClassLoader(final EObject ctx) {
    final ResourceSet resourceSet = ctx.eResource().getResourceSet();
    final ProcessorInstanceForJvmTypeProvider.ProcessorClassloaderAdapter adapter = IterableExtensions.<ProcessorInstanceForJvmTypeProvider.ProcessorClassloaderAdapter>head(Iterables.<ProcessorInstanceForJvmTypeProvider.ProcessorClassloaderAdapter>filter(resourceSet.eAdapters(), ProcessorInstanceForJvmTypeProvider.ProcessorClassloaderAdapter.class));
    if ((adapter != null)) {
        return adapter.getClassLoader();
    }
    boolean _matched = false;
    if (resourceSet instanceof XtextResourceSet) {
        _matched = true;
        final Object classLoaderCtx = ((XtextResourceSet) resourceSet).getClasspathURIContext();
        ClassLoader _switchResult_1 = null;
        boolean _matched_1 = false;
        if (classLoaderCtx instanceof ClassLoader) {
            _matched_1 = true;
            _switchResult_1 = ((ClassLoader) classLoaderCtx);
        }
        if (!_matched_1) {
            if (classLoaderCtx instanceof Class) {
                _matched_1 = true;
                _switchResult_1 = ((Class<?>) classLoaderCtx).getClassLoader();
            }
        }
        final ClassLoader jvmTypeLoader = _switchResult_1;
        ClassLoader _xifexpression = null;
        if ((jvmTypeLoader instanceof URLClassLoader)) {
            URLClassLoader _xblockexpression = null;
            {
                final ArrayList<URL> urls = CollectionLiterals.<URL>newArrayList();
                URL[] _uRLs = ((URLClassLoader) jvmTypeLoader).getURLs();
                Iterables.<URL>addAll(urls, ((Iterable<? extends URL>) Conversions.doWrapArray(_uRLs)));
                final ClassLoader bootClassloader = ((URLClassLoader) jvmTypeLoader).getParent();
                if ((bootClassloader instanceof AlternateJdkLoader)) {
                    URL[] _uRLs_1 = ((AlternateJdkLoader) bootClassloader).getURLs();
                    Iterables.<URL>addAll(urls, ((Iterable<? extends URL>) Conversions.doWrapArray(_uRLs_1)));
                }
                ClassLoader _classLoader = TransformationContext.class.getClassLoader();
                final FilteringClassLoader filtered = new FilteringClassLoader(_classLoader, Collections.<String>unmodifiableList(CollectionLiterals.<String>newArrayList("org.eclipse.xtext.xbase.lib", "org.eclipse.xtend.lib", "org.eclipse.xtend2.lib", "com.google.common")));
                _xblockexpression = new URLClassLoader(((URL[]) Conversions.unwrapArray(urls, URL.class)), filtered);
            }
            _xifexpression = _xblockexpression;
        } else {
            _xifexpression = jvmTypeLoader;
        }
        final ClassLoader processorClassLoader = _xifexpression;
        if ((processorClassLoader != null)) {
            EList<Adapter> _eAdapters = ((XtextResourceSet) resourceSet).eAdapters();
            ProcessorInstanceForJvmTypeProvider.ProcessorClassloaderAdapter _processorClassloaderAdapter = new ProcessorInstanceForJvmTypeProvider.ProcessorClassloaderAdapter(processorClassLoader);
            _eAdapters.add(_processorClassloaderAdapter);
            return processorClassLoader;
        }
    }
    ProcessorInstanceForJvmTypeProvider.logger.info("No class loader configured. Trying with this class classloader.");
    return this.getClass().getClassLoader();
}
Also used : AlternateJdkLoader(org.eclipse.xtext.util.internal.AlternateJdkLoader) ArrayList(java.util.ArrayList) Adapter(org.eclipse.emf.common.notify.Adapter) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) TransformationContext(org.eclipse.xtend.lib.macro.TransformationContext) URL(java.net.URL) XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) URLClassLoader(java.net.URLClassLoader) FilteringClassLoader(org.eclipse.xtend.core.macro.FilteringClassLoader) URLClassLoader(java.net.URLClassLoader) FilteringClassLoader(org.eclipse.xtend.core.macro.FilteringClassLoader) EObject(org.eclipse.emf.ecore.EObject)

Example 2 with AlternateJdkLoader

use of org.eclipse.xtext.util.internal.AlternateJdkLoader in project xtext-xtend by eclipse.

the class XtendBatchCompiler method internalInstallJvmTypeProvider.

/**
 * Performs the actual installation of the JvmTypeProvider.
 */
private void internalInstallJvmTypeProvider(ResourceSet resourceSet, File tmpClassDirectory, boolean skipIndexLookup) {
    Iterable<String> classPathEntries = concat(getClassPathEntries(), getSourcePathDirectories(), asList(tmpClassDirectory.toString()));
    classPathEntries = filter(classPathEntries, new Predicate<String>() {

        @Override
        public boolean apply(String input) {
            return !Strings.isEmpty(input.trim());
        }
    });
    Iterable<File> classpath = transform(classPathEntries, TO_FILE);
    if (log.isDebugEnabled()) {
        log.debug("classpath used for Xtend compilation : " + classpath);
    }
    ClassLoader parentClassLoader;
    if (useCurrentClassLoaderAsParent) {
        parentClassLoader = currentClassLoader;
    } else {
        if (isEmpty(bootClassPath)) {
            parentClassLoader = ClassLoader.getSystemClassLoader().getParent();
        } else {
            Iterable<File> bootClassPathEntries = transform(getBootClassPathEntries(), TO_FILE);
            parentClassLoader = new AlternateJdkLoader(bootClassPathEntries);
        }
    }
    jvmTypesClassLoader = createClassLoader(classpath, parentClassLoader);
    new ClasspathTypeProvider(jvmTypesClassLoader, resourceSet, skipIndexLookup ? null : indexedJvmTypeAccess, null);
    ((XtextResourceSet) resourceSet).setClasspathURIContext(jvmTypesClassLoader);
    // for annotation processing we need to have the compiler's classpath as a parent.
    annotationProcessingClassLoader = createClassLoader(classpath, currentClassLoader);
    resourceSet.eAdapters().add(new ProcessorInstanceForJvmTypeProvider.ProcessorClassloaderAdapter(annotationProcessingClassLoader));
}
Also used : AlternateJdkLoader(org.eclipse.xtext.util.internal.AlternateJdkLoader) ProcessorInstanceForJvmTypeProvider(org.eclipse.xtend.core.macro.ProcessorInstanceForJvmTypeProvider) XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) URLClassLoader(java.net.URLClassLoader) XtendFile(org.eclipse.xtend.core.xtend.XtendFile) File(java.io.File) ClasspathTypeProvider(org.eclipse.xtext.common.types.access.impl.ClasspathTypeProvider) Predicate(com.google.common.base.Predicate)

Aggregations

URLClassLoader (java.net.URLClassLoader)2 XtextResourceSet (org.eclipse.xtext.resource.XtextResourceSet)2 AlternateJdkLoader (org.eclipse.xtext.util.internal.AlternateJdkLoader)2 Predicate (com.google.common.base.Predicate)1 File (java.io.File)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 Adapter (org.eclipse.emf.common.notify.Adapter)1 EObject (org.eclipse.emf.ecore.EObject)1 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)1 FilteringClassLoader (org.eclipse.xtend.core.macro.FilteringClassLoader)1 ProcessorInstanceForJvmTypeProvider (org.eclipse.xtend.core.macro.ProcessorInstanceForJvmTypeProvider)1 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)1 TransformationContext (org.eclipse.xtend.lib.macro.TransformationContext)1 ClasspathTypeProvider (org.eclipse.xtext.common.types.access.impl.ClasspathTypeProvider)1