private Class<?>[] compile() throws IOException { Class<?>[] compiledSources = this.compiler.compile(this.sources); if (compiledSources.length == 0) { throw new RuntimeException( "No classes found in '" + Arrays.toString(this.sources) + "'"); } return compiledSources; }
@Override public List<File> resolve(List<String> artifactIdentifiers) throws CompilationFailedException, IOException { GroovyCompiler groovyCompiler = new GroovyCompiler(this.configuration); List<File> artifactFiles = new ArrayList<>(); if (!artifactIdentifiers.isEmpty()) { List<URL> initialUrls = getClassPathUrls(groovyCompiler); groovyCompiler.compile(createSources(artifactIdentifiers)); List<URL> artifactUrls = getClassPathUrls(groovyCompiler); artifactUrls.removeAll(initialUrls); for (URL artifactUrl : artifactUrls) { artifactFiles.add(toFile(artifactUrl)); } } return artifactFiles; }
@Override protected ExitStatus run(OptionSet options) throws Exception { SourceOptions sourceOptions = new SourceOptions(options); List<RepositoryConfiguration> repositoryConfiguration = RepositoryConfigurationFactory .createDefaultRepositoryConfiguration(); GroovyCompilerConfiguration configuration = new OptionSetGroovyCompilerConfiguration( options, this, repositoryConfiguration); if (System.getProperty("grape.root") == null) { System.setProperty("grape.root", "."); } GroovyCompiler groovyCompiler = new GroovyCompiler(configuration); groovyCompiler.compile(sourceOptions.getSourcesArray()); return ExitStatus.OK; }
@Override protected ExitStatus run(OptionSet options) throws Exception { List<?> nonOptionArguments = new ArrayList<Object>( options.nonOptionArguments()); Assert.isTrue(nonOptionArguments.size() >= 2, () -> "The name of the " + "resulting " + this.type + " and at least one source file must be " + "specified"); File output = new File((String) nonOptionArguments.remove(0)); Assert.isTrue( output.getName().toLowerCase(Locale.ENGLISH) .endsWith("." + this.type), () -> "The output '" + output + "' is not a " + this.type.toUpperCase(Locale.ENGLISH) + " file."); deleteIfExists(output); GroovyCompiler compiler = createCompiler(options); List<URL> classpath = getClassPathUrls(compiler); List<MatchedResource> classpathEntries = findMatchingClasspathEntries( classpath, options); String[] sources = new SourceOptions(nonOptionArguments).getSourcesArray(); Class<?>[] compiledClasses = compiler.compile(sources); List<URL> dependencies = getClassPathUrls(compiler); dependencies.removeAll(classpath); writeJar(output, compiledClasses, classpathEntries, dependencies); return ExitStatus.OK; }