@SuppressWarnings("AssignmentToStaticFieldFromInstanceMethod") public void patchCompilationUnit(CompilationUnit compilationUnit, GroovyResourceLoader resourceLoader, File[] srcFiles) { File baseDir = guessBaseDir(srcFiles); if (baseDir == null) { return; } GriffonCompilerContext.basedir = baseDir.getPath(); GriffonCompilerContext.projectName = "IntelliJIDEARulezzzzz"; GriffonCompilerContext.setup(); if (!GriffonCompilerContext.getConfigOption(CommandLineConstants.KEY_DISABLE_AUTO_IMPORTS)) { DefaultImportCompilerCustomizer customizer = new DefaultImportCompilerCustomizer(); customizer.collectDefaultImportsPerArtifact(); compilationUnit.addPhaseOperation(customizer, customizer.getPhase().getPhaseNumber()); } }
private void setResLoader() { final GroovyResourceLoader rl = getResourceLoader(); setResourceLoader(new GroovyResourceLoader() { public URL loadGroovySource(String className) throws MalformedURLException { String filename; for (String extension : getConfig().getScriptExtensions()) { filename = className.replace('.', File.separatorChar) + "." + extension; try { URLConnection dependentScriptConn = rc.getResourceConnection(filename); return dependentScriptConn.getURL(); } catch (ResourceException e) { //TODO: maybe do something here? } } return rl.loadGroovySource(className); } }); }
protected GroovyClassLoader buildClassLoaderFor() { // GROOVY-5044 if (!fork && !getIncludeantruntime()) { throw new IllegalArgumentException("The includeAntRuntime=false option is not compatible with fork=false"); } final ClassLoader parent = AccessController.doPrivileged( new PrivilegedAction<ClassLoader>() { @Override public ClassLoader run() { return getIncludeantruntime() ? getClass().getClassLoader() : new AntClassLoader(new RootLoader(EMPTY_URL_ARRAY, null), getProject(), getClasspath()); } }); if (parent instanceof AntClassLoader) { AntClassLoader antLoader = (AntClassLoader) parent; String[] pathElm = antLoader.getClasspath().split(File.pathSeparator); List<String> classpath = configuration.getClasspath(); /* * Iterate over the classpath provided to groovyc, and add any missing path * entries to the AntClassLoader. This is a workaround, since for some reason * 'directory' classpath entries were not added to the AntClassLoader' classpath. */ for (String cpEntry : classpath) { boolean found = false; for (String path : pathElm) { if (cpEntry.equals(path)) { found = true; break; } } /* * fix for GROOVY-2284 * seems like AntClassLoader doesn't check if the file * may not exist in the classpath yet */ if (!found && new File(cpEntry).exists()) { try { antLoader.addPathElement(cpEntry); } catch (BuildException e) { log.warn("The classpath entry " + cpEntry + " is not a valid Java resource"); } } } } GroovyClassLoader loader = AccessController.doPrivileged( new PrivilegedAction<GroovyClassLoader>() { @Override public GroovyClassLoader run() { return new GroovyClassLoader(parent, configuration); } }); if (!forceLookupUnnamedFiles) { // in normal case we don't need to do script lookups loader.setResourceLoader(new GroovyResourceLoader() { public URL loadGroovySource(String filename) throws MalformedURLException { return null; } }); } return loader; }
public abstract void patchCompilationUnit(CompilationUnit compilationUnit, GroovyResourceLoader resourceLoader, File[] srcFiles);