another novice question, about compiling

So thanks to the answer to my previous question, I'm now relatively close to having my plugin working.

For the purposes of this plugin, I need to dynamically compile and then exectue a little bit of source code, which I specifically do not want to be permanent in any way, nor part of the project's module. In particular I'm implementing a more powerful search and replace where the replace feature will execute any java code that you'd like which returns a string.

So I generate a file which looks like this:
public class CompiledReplace implements Replace {
public String doReplace(String [] args) {
return "teest";
}
}

This winds up in my Intellij/bin directory by default.

So I'm mildly stuck on my next two steps, which I think are:

1) compile this file
2) find it with the classloader, make instance, call replace method

When I try to compile this I get the error given below this post.

Anyone have any experience / hints that will help me figure out how to get this to work?

Thanks!

ERROR - mpl.OneProjectItemCompileScope - Assertion failed: Module is null for file C:\gw\IntelliJ IDEA 5.0\bin\CompiledReplace.java
ERROR - mpl.OneProjectItemCompileScope - IntelliJ IDEA 5.0.2 Build #3542
ERROR - mpl.OneProjectItemCompileScope - JDK: 1.5.0_04
ERROR - mpl.OneProjectItemCompileScope - VM: Java HotSpot(TM) Client VM
ERROR - mpl.OneProjectItemCompileScope - Vendor: Sun Microsystems Inc.
ERROR - mpl.OneProjectItemCompileScope - OS: Windows XP
ERROR - mpl.OneProjectItemCompileScope - Last Action: SuperExpression
ERROR - mpl.OneProjectItemCompileScope - Assertion failed: Module is null for file C:\gw\IntelliJ IDEA 5.0\bin\CompiledReplace.java
java.lang.Throwable
at com.intellij.openapi.diagnostic.Logger.assertTrue(Logger.java:78)
at com.intellij.compiler.impl.OneProjectItemCompileScope.getAffectedModules(OneProjectItemCompileScope.java:4)
at com.intellij.compiler.impl.CompositeScope.getAffectedModules(CompositeScope.java:35)
at com.intellij.j2meplugin.compiler.J2MEPackagingCompiler$1.compute(J2MEPackagingCompiler.java:69)
at com.intellij.j2meplugin.compiler.J2MEPackagingCompiler$1.compute(J2MEPackagingCompiler.java:68)
at com.intellij.openapi.application.impl.ApplicationImpl$7.run(ApplicationImpl.java:2)
at com.intellij.openapi.application.impl.ApplicationImpl.runReadAction(ApplicationImpl.java:153)
at com.intellij.openapi.application.impl.ApplicationImpl.runReadAction(ApplicationImpl.java:218)
at com.intellij.j2meplugin.compiler.J2MEPackagingCompiler.getProcessingItems(J2MEPackagingCompiler.java:66)
at com.intellij.compiler.impl.FileProcessingCompilerAdapter.getProcessingItems(FileProcessingCompilerAdapter.java:4)
at com.intellij.compiler.impl.CompileDriver.a(CompileDriver.java:223)
at com.intellij.compiler.impl.CompileDriver.a(CompileDriver.java:144)
at com.intellij.compiler.impl.CompileDriver.a(CompileDriver.java:180)
at com.intellij.compiler.impl.CompileDriver.a(CompileDriver.java:176)
at com.intellij.compiler.impl.CompileDriver.access$400(CompileDriver.java:1)
at com.intellij.compiler.impl.CompileDriver$4$1.run(CompileDriver.java:9)
at com.intellij.openapi.progress.impl.ProgressManagerImpl.runProcess(ProgressManagerImpl.java:6)
at com.intellij.compiler.impl.CompileDriver$4.run(CompileDriver.java:3)

5 comments

You might want to look into Kiwi, BeanShell, or invoking javac yourself
using com.sun.tools...

Doug McCreary wrote:

So thanks to the answer to my previous question, I'm now relatively close to having my plugin working.

For the purposes of this plugin, I need to dynamically compile and then exectue a little bit of source code, which I specifically do not want to be permanent in any way, nor part of the project's module. In particular I'm implementing a more powerful search and replace where the replace feature will execute any java code that you'd like which returns a string.

So I generate a file which looks like this:
public class CompiledReplace implements Replace {
public String doReplace(String [] args) {
return "teest";
}
}

This winds up in my Intellij/bin directory by default.

So I'm mildly stuck on my next two steps, which I think are:

1) compile this file
2) find it with the classloader, make instance, call replace method

When I try to compile this I get the error given below this post.

Anyone have any experience / hints that will help me figure out how to get this to work?

Thanks!

ERROR - mpl.OneProjectItemCompileScope - Assertion failed: Module is null for file C:\gw\IntelliJ IDEA 5.0\bin\CompiledReplace.java
ERROR - mpl.OneProjectItemCompileScope - IntelliJ IDEA 5.0.2 Build #3542
ERROR - mpl.OneProjectItemCompileScope - JDK: 1.5.0_04
ERROR - mpl.OneProjectItemCompileScope - VM: Java HotSpot(TM) Client VM
ERROR - mpl.OneProjectItemCompileScope - Vendor: Sun Microsystems Inc.
ERROR - mpl.OneProjectItemCompileScope - OS: Windows XP
ERROR - mpl.OneProjectItemCompileScope - Last Action: SuperExpression
ERROR - mpl.OneProjectItemCompileScope - Assertion failed: Module is null for file C:\gw\IntelliJ IDEA 5.0\bin\CompiledReplace.java
java.lang.Throwable
at com.intellij.openapi.diagnostic.Logger.assertTrue(Logger.java:78)
at com.intellij.compiler.impl.OneProjectItemCompileScope.getAffectedModules(OneProjectItemCompileScope.java:4)
at com.intellij.compiler.impl.CompositeScope.getAffectedModules(CompositeScope.java:35)
at com.intellij.j2meplugin.compiler.J2MEPackagingCompiler$1.compute(J2MEPackagingCompiler.java:69)
at com.intellij.j2meplugin.compiler.J2MEPackagingCompiler$1.compute(J2MEPackagingCompiler.java:68)
at com.intellij.openapi.application.impl.ApplicationImpl$7.run(ApplicationImpl.java:2)
at com.intellij.openapi.application.impl.ApplicationImpl.runReadAction(ApplicationImpl.java:153)
at com.intellij.openapi.application.impl.ApplicationImpl.runReadAction(ApplicationImpl.java:218)
at com.intellij.j2meplugin.compiler.J2MEPackagingCompiler.getProcessingItems(J2MEPackagingCompiler.java:66)
at com.intellij.compiler.impl.FileProcessingCompilerAdapter.getProcessingItems(FileProcessingCompilerAdapter.java:4)
at com.intellij.compiler.impl.CompileDriver.a(CompileDriver.java:223)
at com.intellij.compiler.impl.CompileDriver.a(CompileDriver.java:144)
at com.intellij.compiler.impl.CompileDriver.a(CompileDriver.java:180)
at com.intellij.compiler.impl.CompileDriver.a(CompileDriver.java:176)
at com.intellij.compiler.impl.CompileDriver.access$400(CompileDriver.java:1)
at com.intellij.compiler.impl.CompileDriver$4$1.run(CompileDriver.java:9)
at com.intellij.openapi.progress.impl.ProgressManagerImpl.runProcess(ProgressManagerImpl.java:6)
at com.intellij.compiler.impl.CompileDriver$4.run(CompileDriver.java:3)

0

I meant Scrappy plugin, which uses Pizza Compiler at
http://pizzacompiler.sourceforge.net/

Keith Lea wrote:

You might want to look into Kiwi, BeanShell, or invoking javac yourself
using com.sun.tools...

Doug McCreary wrote:

>> So thanks to the answer to my previous question, I'm now relatively
>> close to having my plugin working.
>>
>> For the purposes of this plugin, I need to dynamically compile and
>> then exectue a little bit of source code, which I specifically do not
>> want to be permanent in any way, nor part of the project's module. In
>> particular I'm implementing a more powerful search and replace where
>> the replace feature will execute any java code that you'd like which
>> returns a string.
>>
>> So I generate a file which looks like this:
>> public class CompiledReplace implements Replace {
>> public String doReplace(String [] args) {
>> return "teest";
>> }
>> }
>>
>> This winds up in my Intellij/bin directory by default.
>>
>> So I'm mildly stuck on my next two steps, which I think are:
>>
>> 1) compile this file
>> 2) find it with the classloader, make instance, call replace method
>>
>> When I try to compile this I get the error given below this post.
>>
>> Anyone have any experience / hints that will help me figure out how to
>> get this to work?
>>
>> Thanks!
>>
>> ERROR - mpl.OneProjectItemCompileScope - Assertion failed:
>> Module is null for file C:\gw\IntelliJ IDEA
>> 5.0\bin\CompiledReplace.java ERROR -
>> mpl.OneProjectItemCompileScope - IntelliJ IDEA 5.0.2 Build #3542 [
>> 101812] ERROR - mpl.OneProjectItemCompileScope - JDK: 1.5.0_04 [
>> 101812] ERROR - mpl.OneProjectItemCompileScope - VM: Java HotSpot(TM)
>> Client VM ERROR - mpl.OneProjectItemCompileScope - Vendor:
>> Sun Microsystems Inc. ERROR -
>> mpl.OneProjectItemCompileScope - OS: Windows XP ERROR -
>> mpl.OneProjectItemCompileScope - Last Action: SuperExpression [
>> 101812] ERROR - mpl.OneProjectItemCompileScope - Assertion failed:
>> Module is null for file C:\gw\IntelliJ IDEA
>> 5.0\bin\CompiledReplace.java java.lang.Throwable
>> at com.intellij.openapi.diagnostic.Logger.assertTrue(Logger.java:78)
>> at
>> com.intellij.compiler.impl.OneProjectItemCompileScope.getAffectedModules(OneProjectItemCompileScope.java:4)
>>
>> at
>> com.intellij.compiler.impl.CompositeScope.getAffectedModules(CompositeScope.java:35)
>>
>> at
>> com.intellij.j2meplugin.compiler.J2MEPackagingCompiler$1.compute(J2MEPackagingCompiler.java:69)
>>
>> at
>> com.intellij.j2meplugin.compiler.J2MEPackagingCompiler$1.compute(J2MEPackagingCompiler.java:68)
>>
>> at
>> com.intellij.openapi.application.impl.ApplicationImpl$7.run(ApplicationImpl.java:2)
>>
>> at
>> com.intellij.openapi.application.impl.ApplicationImpl.runReadAction(ApplicationImpl.java:153)
>>
>> at
>> com.intellij.openapi.application.impl.ApplicationImpl.runReadAction(ApplicationImpl.java:218)
>>
>> at
>> com.intellij.j2meplugin.compiler.J2MEPackagingCompiler.getProcessingItems(J2MEPackagingCompiler.java:66)
>>
>> at
>> com.intellij.compiler.impl.FileProcessingCompilerAdapter.getProcessingItems(FileProcessingCompilerAdapter.java:4)
>>
>> at com.intellij.compiler.impl.CompileDriver.a(CompileDriver.java:223)
>> at com.intellij.compiler.impl.CompileDriver.a(CompileDriver.java:144)
>> at com.intellij.compiler.impl.CompileDriver.a(CompileDriver.java:180)
>> at com.intellij.compiler.impl.CompileDriver.a(CompileDriver.java:176)
>> at
>> com.intellij.compiler.impl.CompileDriver.access$400(CompileDriver.java:1)
>> at
>> com.intellij.compiler.impl.CompileDriver$4$1.run(CompileDriver.java:9)
>> at
>> com.intellij.openapi.progress.impl.ProgressManagerImpl.runProcess(ProgressManagerImpl.java:6)
>>
>> at
>> com.intellij.compiler.impl.CompileDriver$4.run(CompileDriver.java:3)
>>

0

Thanks, I will have a look at that. I was hoping that accessing the internal compiler might be faster. I've got it working using the sun.tools method (thanks again), but it's just horrifically slow (at least the first time). I'll have a look at the pizzacompiler and see if that helps me out. Anyway, at least it all works, and maybe I can find some trick to make it faster.

0

IDEA simply calls javac as well; there's no internal compiler.

Doug McCreary wrote:

Thanks, I will have a look at that. I was hoping that accessing the
internal compiler might be faster. I've got it working using the
sun.tools method (thanks again), but it's just horrifically slow (at
least the first time). I'll have a look at the pizzacompiler and see
if that helps me out. Anyway, at least it all works, and maybe I can
find some trick to make it faster.

0

Hmm, interesting, I will have to poke around and see if I can figure out why my use of the compiler seems so much slower than theirs.

0

Please sign in to leave a comment.