sysgears / grain

Grain is a lightweight and powerful static website generator with custom themes to help create static, SEO-friendly websites or a blog in no time.
https://sysgears.com/grain
Other
160 stars 30 forks source link

Portability problems #14

Closed altavir closed 8 years ago

altavir commented 8 years ago

Grain works fine when one use one of given templates, but there a quite a lot of little annoying problems, when one tries to create his own template or move installation.

In my opinion, it would be good to add additional flexibility to plugin and completely remove this 'project in project' structure, storing all configuration in gradle file or in separate groovy configuration file.

larixer commented 8 years ago

project group can not be changed from com.sysgears.grain. Main class name is bound to it and it seams that some internal features as well, because project would not compile if group name is changed.

Nothing is bound to com.sysgears.grain group inside themes. Please clarify. How code compilation can be bound to any specific group? It's not possible at all. It's just plain Groovy code.

larixer commented 8 years ago

groovy source code classes are bound to com\sysgears\theme\ directory. I tried to move them to another directory and change imports in SiteConfig, but got some NPEs. It is not very easy to access these files and I do not see any reason for complicated directory structure since there are no name conflicts. I also do not understand the purpose of Launcher.java class since it just point to some internal launcher.

The fact that you weren't able to move something to another directory doesn't mean that anything is bound to specific directory layout. Nothing in Grain is bound to specific layout structure. Please read documentation carefully.

larixer commented 8 years ago

SiteConfig.groovy has direct class imports which is not very good idea if it is intended as a configuration file. If one moves this classes or uses custom ones, he should replace all imports? It is better to use fully qualified class names and reflects to invoke user classes.

SiteConfig.groovy is just a Groovy file. What is inside it is a responsibility of theme author. It can hold direct imports or can use qualified class names. What it has to do with Grain at all?

larixer commented 8 years ago

generally in gradle all temporary files and build results are stored inside build directory. Is there a reason to store target and caches in project root? If they are all in one directory, than it is easier to clean.

Grain is not a gradle plugin. Grain can work as a gradle plugin, but it can work standalone as well. Grain cache files have nothing to do with the build cycle. They are in the Grain rendering cycle and they are not build files, rather they are cache files.

larixer commented 8 years ago

For gradle plugin related issues, please open issue at: https://github.com/sysgears/grain-gradle-plugin

altavir commented 8 years ago

I mean that if I change the group, it won't compile. The obvious reason is that string: mainClassName = [project.group, 'Main'].join('.'). It references com.sysgears.grain.Main class which is not exposed to the user. It tried to set main class manually like mainClassName = com.sysgears.grain.Main. But it still won't work causing some NullPointerException.

SiteConfig.groovy is used by internal grain classes and so it is a part of grain framework. Can I create theme without this file? I tried to move classes referenced by SiteConfig to another directory and change imports but it throws

Caused by: java.lang.NullPointerException
        at org.eclipse.jetty.util.resource.ResourceCollection.<init>(ResourceCollection.java:98)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
        at org.codehaus.groovy.reflection.CachedConstructor.invoke(CachedConstructor.java:80)
        at org.codehaus.groovy.reflection.CachedConstructor.doConstructorInvoke(CachedConstructor.java:74)
        at org.codehaus.groovy.runtime.callsite.ConstructorSite.callConstructor(ConstructorSite.java:45)
        at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallConstructor(CallSiteArray.java:60)
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:235)
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:247)
        at com.sysgears.grain.preview.SitePreviewer.start(SitePreviewer.groovy:90)
larixer commented 8 years ago

I mean that if I change the group, it won't compile. The obvious reason is that string: mainClassName = [project.group, 'Main'].join('.'). It references com.sysgears.grain.Main class which is not exposed to the user. It tried to set main class manually like mainClassName = com.sysgears.grain.Main

Yes, it's the problem in the logic of the theme. mainClassName shouldn't be computed this way. I'm not sure though, why NPE if you set mainClassName directly. Have you set it as a string? i.e.:

mainClassName = "com.sysgears.grain.Main"
altavir commented 8 years ago

OK, tried that again, and this time it worked. Probably last time I changed source code directory as well or forgot the quotes.

larixer commented 8 years ago

SiteConfig.groovy is used by internal grain classes and so it is a part of grain framework. Can I create theme without this file? I tried to move classes referenced by SiteConfig to another directory and change imports but it throws

To what directory did you tried to move which imports? Please be more specific. Please keep in mind, that Grain is not bound to com.sysgears group, but general Groovy class finding rules still apply.

larixer commented 8 years ago

OK, tried that again, and this time it worked. Probably last time I changed source code directory as well or forgot the quotes.

Yep, I also thought, it's missing quotes...

altavir commented 8 years ago

I moved files directly to src (without changing source directory location in configuration). So import com.sysgears.theme.ResourceMapper should be transformed to ResourceMapper. Import from the same package is unnecessary, but it still should work.

larixer commented 8 years ago

You should still have some package name, not default one as your classes will be accessed by Grain, which has named package: http://stackoverflow.com/questions/283816/how-to-access-java-classes-in-the-default-package

It's a Java-thing, has nothing to do with Grain itself...

altavir commented 8 years ago

After some experimenting, I forced it to work.

What one need is:

I still do not understand, what Launcher.java does. Preview obviously works without it.

larixer commented 8 years ago

Launcher.java is for more convenient IDE integration. It's referenced in the docs. The purpose is to let user just import the gradle project with Grain theme, then right-click on Launcher.java and select Run to run the preview.

larixer commented 8 years ago

Some IDEs have poor support for Groovy, hence Launcher.java should be supported by most IDEs, even those that don't know about Groovy at all

altavir commented 8 years ago

OK, it solves most of problems. Still, constructing my own theme is not overwhelmingly convenient, but I suppose this is the opposite side of flexibility.

Currently, I am working on my second project using Grain (first one here), so I wish you luck in future development.

larixer commented 8 years ago

Yes, we are aware that it's cumbersome at times. But as you mentioned, the flexibility was the first priority. And wrapping flexibility into ease of use will require more effort.

Thanks for sharing info about your projects, feel free to ask questions. Please consider posting into Grain user group as well: https://groups.google.com/forum/#!forum/grain-user