groovy jps builder initial

This commit is contained in:
peter
2011-10-25 19:41:01 +02:00
parent 9de7aff540
commit 578993d3d8
7 changed files with 142 additions and 6 deletions
+1
View File
@@ -28,6 +28,7 @@
</library>
</orderEntry>
<orderEntry type="library" name="jna" level="project" />
<orderEntry type="module" module-name="groovy-rt" />
</component>
</module>
@@ -1,5 +1,6 @@
package org.jetbrains.jps.incremental;
import org.jetbrains.jps.incremental.groovy.GroovyBuilder;
import org.jetbrains.jps.incremental.java.JavaBuilder;
import org.jetbrains.jps.incremental.resourses.ResourcesBuilder;
@@ -37,6 +38,7 @@ public class BuilderRegistry {
// todo: some builder registration mechanism needed
myBuilders.get(BuilderCategory.TRANSLATOR).add(new JavaBuilder(myTasksExecutor));
myBuilders.get(BuilderCategory.TRANSLATOR).add(new ResourcesBuilder());
myBuilders.get(BuilderCategory.TRANSLATOR).add(new GroovyBuilder());
}
@@ -1,9 +1,22 @@
package org.jetbrains.jps.incremental.groovy;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.util.SystemProperties;
import org.jetbrains.groovy.compiler.rt.GroovyCompilerWrapper;
import org.jetbrains.jps.ModuleChunk;
import org.jetbrains.jps.incremental.Builder;
import org.jetbrains.jps.incremental.CompileContext;
import org.jetbrains.jps.incremental.FilesCollector;
import org.jetbrains.jps.incremental.ProjectBuildException;
import org.jetbrains.jps.server.ClasspathBootstrap;
import java.io.*;
import java.net.MalformedURLException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
/**
* @author Eugene Zhuravlev
@@ -16,11 +29,126 @@ public class GroovyBuilder extends Builder {
return BUILDER_NAME;
}
public ExitCode build(CompileContext context, ModuleChunk chunk) throws ProjectBuildException {
public Builder.ExitCode build(CompileContext context, ModuleChunk chunk) throws ProjectBuildException {
FilesCollector collector = new FilesCollector(new FileFilter() {
@Override
public boolean accept(File pathname) {
return pathname.getPath().endsWith(".groovy"); //todo file type check
}
});
try {
context.processFiles(chunk, collector);
}
catch (Exception e) {
throw new ProjectBuildException(e);
}
if (collector.getFiles().isEmpty()) {
return Builder.ExitCode.OK;
}
List<String> cp = new ArrayList<String>();
try {
Collection<File> boot =
context.getProjectPaths().getPlatformCompilationClasspath(chunk, context.isCompilingTests(), context.isMake());
for (File file : boot) {
file.toURI().toURL();
}
Collection<File> main =
context.getProjectPaths().getCompilationClasspath(chunk, context.isCompilingTests(), context.isMake());
for (File file : main) {
cp.add(FileUtil.toSystemIndependentName(file.getPath()));
}
cp.add(ClasspathBootstrap.getResourcePath(GroovyCompilerWrapper.class).getPath()); //groovy_rt.jar
}
catch (MalformedURLException e) {
throw new ProjectBuildException(e);
}
try {
File tempFile = FileUtil.createTempFile("ideaGroovyToCompile", ".txt", true);
List<String> cmd = new ArrayList<String>();
cmd.add(SystemProperties.getJavaHome() + "/bin/java"); //todo module jdk path
// todo cmd.add("-bootclasspath");
cmd.add("-cp");
cmd.add(StringUtil.join(cp, File.pathSeparator));
cmd.add("org.jetbrains.groovy.compiler.rt.GroovycRunner");
cmd.add("groovyc");
cmd.add(tempFile.getPath());
File dir = context.getProjectPaths().getModuleOutputDir(chunk.getModules().iterator().next(), context.isCompilingTests());
assert dir != null;
fillFileWithGroovycParameters(collector, tempFile, dir.getPath());
Process process = Runtime.getRuntime().exec(cmd.toArray(new String[cmd.size()]));
StreamReader stdout = new StreamReader(process.getInputStream(), System.out);
stdout.start();
StreamReader stderr = new StreamReader(process.getErrorStream(), System.out);
stderr.start();
stdout.join();
stderr.join();
process.waitFor();
}
catch (Exception e) {
throw new ProjectBuildException(e);
}
return ExitCode.OK;
}
private static void fillFileWithGroovycParameters(FilesCollector collector, File tempFile, final String outputDir) throws IOException {
String fileText = "";
for (File file : collector.getFiles()) {
fileText += "src_file\n";
fileText += file.getPath() + "\n";
//todo file2Classes
fileText += "end" + "\n";
}
//todo patchers
fileText += "encoding\n";
fileText += "UTF-8\n"; //todo encoding
fileText += "outputpath\n";
fileText += outputDir + "\n";
fileText += "finaloutputpath\n";
fileText += outputDir + "\n";
FileWriter writer = new FileWriter(tempFile);
writer.write(fileText);
writer.close();
}
public String getDescription() {
return "Groovy builder";
}
static class StreamReader extends Thread {
private final BufferedReader myStream;
private final PrintStream myWriter;
StreamReader(InputStream stream, PrintStream writer) {
myStream = new BufferedReader(new InputStreamReader(stream));
myWriter = writer;
}
@Override
public void run() {
while (true) {
String line = null;
try {
line = myStream.readLine();
}
catch (IOException e) {
e.printStackTrace(); //todo change body of catch statement use File | Settings | File Templates.
}
if (line == null) {
break;
}
myWriter.println(line);
}
}
}
}
@@ -14,9 +14,9 @@
* limitations under the License.
*/
package org.jetbrains.plugins.groovy.compiler;
package org.jetbrains.jps.incremental.groovy;
import com.intellij.execution.process.OSProcessHandler;
import com.intellij.execution.process.BaseOSProcessHandler;
import com.intellij.execution.process.ProcessOutputTypes;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.util.Key;
@@ -28,6 +28,7 @@ import org.jetbrains.groovy.compiler.rt.GroovyCompilerWrapper;
import org.jetbrains.groovy.compiler.rt.GroovycRunner;
import java.io.File;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
@@ -37,16 +38,16 @@ import java.util.Set;
* @author: Dmitry.Krasilschikov
* @date: 16.04.2007
*/
public class GroovycOSProcessHandler extends OSProcessHandler {
public class GroovycOSProcessHandler extends BaseOSProcessHandler {
private final List<GroovyCompilerWrapper.OutputItem> myCompiledItems = new ArrayList<GroovyCompilerWrapper.OutputItem>();
private final Set<File> toRecompileFiles = new HashSet<File>();
private final List<CompilerMessage> compilerMessages = new ArrayList<CompilerMessage>();
private final StringBuffer stdErr = new StringBuffer();
private static final Logger LOG = Logger.getInstance("org.jetbrains.plugins.groovy.compiler.GroovycOSProcessHandler");
private static final Logger LOG = Logger.getInstance("org.jetbrains.jps.incremental.groovy.GroovycOSProcessHandler");
public GroovycOSProcessHandler(Process process, String s) {
super(process, s);
super(process, s, Charset.forName("UTF-8"));
}
public void notifyTextAvailable(final String text, final Key outputType) {
@@ -27,6 +27,7 @@ import gnu.trove.TIntHash;
import net.n3.nanoxml.IXMLBuilder;
import org.codehaus.groovy.GroovyException;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.groovy.compiler.rt.GroovyCompilerWrapper;
import org.jetbrains.jps.MacroExpander;
import org.objectweb.asm.ClassWriter;
@@ -84,6 +85,7 @@ public class ClasspathBootstrap {
cp.add(getResourcePath(CellConstraints.class)); // jgoodies-forms
cp.add(getResourcePath(NotNullVerifyingInstrumenter.class)); // not-null
cp.add(getResourcePath(IXMLBuilder.class)); // nano-xml
cp.add(getResourcePath(GroovyCompilerWrapper.class)); // groovy_rt
final Class<StandardJavaFileManager> optimizedFileManagerClass = getOptimizedFileManagerClass();
if (optimizedFileManagerClass != null) {
+1
View File
@@ -29,6 +29,7 @@
<orderEntry type="module" module-name="testFramework-java" scope="TEST" />
<orderEntry type="module" module-name="IntelliLang-java" scope="TEST" />
<orderEntry type="module" module-name="IntelliLang-xml" scope="TEST" />
<orderEntry type="module" module-name="jps-builders" />
</component>
</module>
@@ -72,6 +72,7 @@ import org.jetbrains.annotations.Nullable;
import org.jetbrains.groovy.compiler.rt.CompilerMessage;
import org.jetbrains.groovy.compiler.rt.GroovyCompilerWrapper;
import org.jetbrains.groovy.compiler.rt.GroovycRunner;
import org.jetbrains.jps.incremental.groovy.GroovycOSProcessHandler;
import org.jetbrains.plugins.groovy.GroovyFileType;
import org.jetbrains.plugins.groovy.config.GroovyConfigUtils;
import org.jetbrains.plugins.groovy.extensions.GroovyScriptType;