0

I am writing a small framework to handle asychron calls. To show how the framework works, I created a showcase. Inside the showcase I want to show the code (from the Java source files) and and what will happen when the code is executed. Something similar to the GWT Showcase.

To show the code, I use an IncrementalGenerator to read the java source files and generate the code for a widget to represent the code. To do that, I used the same code to read the Java filed as I did before in other projects.

It looks like that:

InputStream in = classLoader.getResourceAsStream(path);
if (in == null) {
  logger.log(TreeLogger.ERROR, "Resource not found: " + path);
  throw new UnableToCompleteException();
}

where path is the relative path of the file I want to read. In case of SuperDevMode the InputStream is always null. I also tried to work with the old Generator class but this did not work also. It looks like the files are not available inside the classpath when the generator is executed in case the code server is started.

I tried the same code with Dev-Mode-Plugin and it works fine!

so, how can I access the Java source files of a project inside an IncrementalGenerator using SuperDevMode?

I use GWT 2.6.1, IntelliJ v13.1 Ultimate.

Thanks in advance

El Hoss
  • 3,767
  • 2
  • 18
  • 24

2 Answers2

1

If you're giving the sources to the CodeServer using its -src argument, then they won't be in the classpath; if you expect them in the ClassLoader, then they have to be in the classpath (like you give them to the GWT Compiler or DevMode). To make your generator robust, you should first try the ResourceOracle and then fallback to the ClassLoader.


FYI, some built-in generators are currently loading from the classpath and are being modified to load from the ResourceOracle for better incremental compilation: https://gwt-review.googlesource.com/8811

Thomas Broyer
  • 64,353
  • 7
  • 91
  • 164
  • Thanks for your response. I tried the CodeServer with and without the -src argument, tried to use ResourceOracle, but all did not give me a positive result. I will dig deeper. I you have any ideas, how to investigate in that problem, I would like to hear them. – El Hoss Aug 25 '14 at 12:43
  • Btw, I had always to enter an absolute path when using the -src argument. – El Hoss Aug 25 '14 at 12:44
  • Updated answer to be more precise: if you expect things in the `ClassLoader`, they have to be in the classpath; GWT doesn't create new class loaders itself (except for the service side of the webapp in DevMode, or DevMode's recompiling class loader) – Thomas Broyer Aug 25 '14 at 12:58
0

I spend another few hours to find a workaround for this problem.

At the end, it was not related to GWT. I discovered, that the -src argument has no impact on the content of the classpath. Inside the compiler settings of the IntelliJ project, I found a setting, which control the type of resources that are copy to the classpath. After I removed the pattern which let stop IntelliJ copying the *.java files to the classpath, everything works fine.

compiler resource pattern settingst looks

It looks like the output of the classpath could not be controlled with the -src argument in IntelliJ.

El Hoss
  • 3,767
  • 2
  • 18
  • 24