Bug 95399 - After switching to FreeMarker default package name is no longer replaced by one from wizard
After switching to FreeMarker default package name is no longer replaced by o...
Status: RESOLVED FIXED
Product: java
Classification: Unclassified
Component: Unsupported
6.x
All All
: P2 (vote)
: 6.x
Assigned To: Jan Pokorsky
issues@java
: API_REVIEW_FAST
Depends on: 97974 98011 98874
Blocks: 92595 99232 99233 99234 99235 105744
  Show dependency treegraph
 
Reported: 2007-02-13 13:43 UTC by Martin Adamek
Modified: 2011-08-16 13:54 UTC (History)
6 users (show)

See Also:
Issue Type: DEFECT
:


Attachments
Proposed Class template (309 bytes, text/plain)
2007-03-01 16:12 UTC, Jan Pokorsky
Details
prototype (45.10 KB, text/plain)
2007-03-16 00:06 UTC, Jan Pokorsky
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Martin Adamek 2007-02-13 13:43:11 UTC
After switching my wizard to FreeMarker template engine, the default package
name defined in template is not replaced by package name actually defined in the
wizard. Java infrastructure should take care of this operation.
Comment 1 Jaroslav Tulach 2007-02-13 14:16:06 UTC
Maybe we need some meeting to discuss the future of templating support for 
Java files and Java based projects. Original plan for java/project module was 
to provide an implementation of 
http://www.netbeans.org/download/dev/javadoc/org-openide-loaders/org/openide/loaders/CreateFromTemplateAttributesProvider.html
that would add the Java related properties - package, classname, etc.
Comment 2 Jan Pokorsky 2007-03-01 10:52:27 UTC
I have done some prototyping and here are my observations:

JP1: IMO CreateFromTemplateAttributesProvider should be placed into the
java/source module where is the JavaDataLoader. package, classname, ... has
nothing to do with project.

JP2: java/project should provide template attribute like licence.

JP3: Jardo, are you going to provide some editor support(own loader?) for
freemaker templates? Nowadays it is an editor taken from e.g. JavaDataLoader.
But freemaker templates are not regular java sources so I will have to prevent
to recognize them by the JavaDataLoader. The template editor could offer
available template attributes via
Map<String/*name*/,String/*html_description*/>CreateFromTemplateAttributesProvider.availableAttributes(FileObject),
syntax highlighting, ...

JP4: Is there any naming convention for template attributes like
${package}|${java.package}|${org.netbeans.modules.java.package}? Should
attributes be exported as API? The arch has not supported this yet.

JP5: Compatibility. I guess there will be none. Modified templates will not be
copied from previous release. Otherwise we would have to provide a transformer.

JP6: Present refactoring post-processing will be replaced with template attributes.

Comment 3 Jaroslav Tulach 2007-03-01 14:25:40 UTC
JP1 - ok.

JP2 - I have prototyped 
http://www.netbeans.org/nonav/issues/showattachment.cgi/37844/X.diff but it 
needs few changes. A few ideas would include - we might write an 
CreateFromTemplateAttributesProvider that would make all properties in 
nbproject/project.properties available to the scripting engine. Then the users 
could specify license=GPL in their project.properties and then the license.txt 
file would contain if (${project.license} == GPL) { 
#include("license-gpl.txt" }. We might predefine few most common licenses GPL, 
CDDL, apache, bsd - the users could of course define their own and modify 
license.txt to suite their needs. How does this sound?

JP3 - Imho your loader shall check for javax.script.ScriptEngine attribute of 
the file and if present then set mime type to "text/x-freemarker". Hanz 
promised to deliver syntax coloring for it. Mixed coloring (java + freemarker) 
is out of scope for 6.0 according to Hrebejk.

JP4 - java.package is the best imho.

JP5 - no import, imho. keep that in mind for list of files to skip/include for 
6.0 or just change ide/upgrader 

JP6 - I've heard about problems with guarded blocks - imho solution should not 
overcomplicate the templates itself, as that is an API we expose to end users 
and we should not scare them. Better to enhance indentation engine, imho.
Comment 4 Jan Pokorsky 2007-03-01 16:08:30 UTC
JP2 - I like the idea of licence from project.properties

JP3 - I could register MIME Resolver for java + freemarker

JP4 - I tend rather to just package. It should not clash in java world. I was
asking if there will be some recommendation like for system properties.
So java will introduce just 'package' attribute and reuse 'name' attribute as
the class name.

JP6 - Yep, I mentioned guarded blocks use case. You can read more about the
problem in issue #72396. AFAIK this relates just to some mobility templates
where //GEN tag follows straight '{'. The template would look like

public void mobile() <#if !nlbeforebrace>{// GEN-LINE:head<#else>//GEN-BEGIN:head
    {//GEN-END:head</#if>
    }

${nlbeforebrace} would represent JavaIndentEngine option. Not nice but it is a
way for them now. Later we can tweak the java indent engine.
Comment 5 Jan Pokorsky 2007-03-01 16:12:19 UTC
Created attachment 39061 [details]
Proposed Class template
Comment 6 Jan Pokorsky 2007-03-01 17:01:51 UTC
JP2 - I think the licence.txt template should be placed in openide/loaders. It
is a kind of default like name, date, time, ...
Comment 7 Jan Pokorsky 2007-03-02 11:39:51 UTC
DK1 - dkaspar proposes not to include the constructor in Class template. I
agree.   Any objections? 
Comment 8 Martin Adamek 2007-03-02 12:21:23 UTC
I don't have strong opinion on presence of constructor, but if it is going to
stay, at least the comment: /** Creates a new instance of ${name} */ should be
removed.
Comment 9 Jaroslav Tulach 2007-03-12 16:37:14 UTC
JP2 - openide/loaders does not have any layer.xml and it should not have as it 
is an autoload module. The license has to be somewhere else. Imho potentially 
in ide cluster and not platform cluster as licenses are more IDE oriented then 
something for every platform user.
Comment 10 Jan Pokorsky 2007-03-13 14:01:16 UTC
JP2 - what is appropriate then? ide/defaults, core/ide, ...? I would have to
declare a dependency on such a module, right?
Comment 11 Jaroslav Tulach 2007-03-14 00:25:34 UTC
JP2 - btw. the license has to be in ide cluster, as the freemarker engine is 
in ide cluster as well. I am not sure what module is the best. Here are 
possible candidates:

org-netbeans-core-ide.jar - I do not like that, we want to vanish the module
org-netbeans-libs-freemarker.jar - actually it is freemarker template, so it 
could be in freemarker itself!?
org-netbeans-modules-editor-plain.jar - probably not, it does not have 
knowledge of templates
org-netbeans-modules-projectuiapi.jar - my preferred, the templates are 
project related (especially if we parse the project.properties to find 
preferred license), and this is the lowest module that deals with projects and 
provides some API and is related to UI
org-netbeans-modules-utilities.jar - brrrr... usual place where to put garbage

I am unsure, my advice is, please try to prototype solution with projectuiapi 
or freemarker itself.
Comment 12 Jan Pokorsky 2007-03-16 00:05:19 UTC
Follows the java templates prototype.
* I chose org-netbeans-modules-projectui.jar to place license templates as
Licenses/license-[default|cddl|...].txt.
* org-netbeans-modules-java-j2seproject.jar registers the template attributes
provider for ${project.license} attribute. Other project types should provide
the same.
* org-netbeans-modules-java-project.jar contains rewritten java templates.
* org-netbeans-modules-java-source.jar registers provider for ${package} attribute.

Blocker is issue #98011 since freemarker is not customized properly to handle
file paths.
Comment 13 Jan Pokorsky 2007-03-16 00:06:27 UTC
Created attachment 39569 [details]
prototype
Comment 14 Jan Pokorsky 2007-03-20 11:08:37 UTC
There are no objections so I am going to integrate it. Thanks for review.
Comment 15 Jaroslav Tulach 2007-03-20 16:48:20 UTC
Y01 Add arch.xml documentation for locations of layer files (content of 
Licences folder), for properties that one can use and expect (project.license, 
package, etc.)

Y02 Increment spec version of java/project, write apichange.xml 

Otherwise very nice.
Comment 16 Jan Pokorsky 2007-03-26 22:08:18 UTC
implemented in

/cvs/ide/golden/cluster-deps.txt,v  <--  cluster-deps.txt
new revision: 1.81; previous revision: 1.80
/cvs/ide/golden/deps.txt,v  <--  deps.txt
new revision: 1.489; previous revision: 1.488
/cvs/java/j2seproject/src/org/netbeans/modules/java/j2seproject/J2SEProject.java,v
 <--  J2SEProject.java
new revision: 1.80; previous revision: 1.79
/cvs/java/j2seproject/src/org/netbeans/modules/java/j2seproject/J2SETemplateAttributesProvider.java,v
 <--  J2SETemplateAttributesProvider.java
initial revision: 1.1
/cvs/java/project/manifest.mf,v  <--  manifest.mf
new revision: 1.23; previous revision: 1.22
/cvs/java/project/nbproject/project.xml,v  <--  project.xml
new revision: 1.36; previous revision: 1.35
/cvs/java/project/src/org/netbeans/modules/java/project/layer.xml,v  <--  layer.xml
new revision: 1.26; previous revision: 1.25
/cvs/java/project/src/org/netbeans/modules/java/project/resources/AnnotationType.template,v
 <--  AnnotationType.template
new revision: 1.5; previous revision: 1.4
/cvs/java/project/src/org/netbeans/modules/java/project/resources/Applet.template,v
 <--  Applet.template
new revision: 1.2; previous revision: 1.1
/cvs/java/project/src/org/netbeans/modules/java/project/resources/Class.template,v
 <--  Class.template
new revision: 1.2; previous revision: 1.1
/cvs/java/project/src/org/netbeans/modules/java/project/resources/Enum.template,v
 <--  Enum.template
new revision: 1.5; previous revision: 1.4
/cvs/java/project/src/org/netbeans/modules/java/project/resources/Exception.template,v
 <--  Exception.template
new revision: 1.2; previous revision: 1.1
/cvs/java/project/src/org/netbeans/modules/java/project/resources/Interface.template,v
 <--  Interface.template
new revision: 1.2; previous revision: 1.1
/cvs/java/project/src/org/netbeans/modules/java/project/resources/JApplet.template,v
 <--  JApplet.template
new revision: 1.2; previous revision: 1.1
/cvs/java/project/src/org/netbeans/modules/java/project/resources/Main.template,v
 <--  Main.template
new revision: 1.2; previous revision: 1.1
/cvs/java/project/src/org/netbeans/modules/java/project/resources/package-info.template,v
 <--  package-info.template
new revision: 1.2; previous revision: 1.1
/cvs/java/source/apichanges.xml,v  <--  apichanges.xml
new revision: 1.5; previous revision: 1.4
/cvs/java/source/arch.xml,v  <--  arch.xml
new revision: 1.5; previous revision: 1.4
/cvs/java/source/nbproject/project.properties,v  <--  project.properties
new revision: 1.13; previous revision: 1.12
/cvs/java/source/src/org/netbeans/modules/java/JavaDataLoader.java,v  <-- 
JavaDataLoader.java
new revision: 1.4; previous revision: 1.3
/cvs/java/source/src/org/netbeans/modules/java/JavaTemplateAttributesProvider.java,v
 <--  JavaTemplateAttributesProvider.java
initial revision: 1.1
/cvs/java/source/src/META-INF/services/org.openide.loaders.CreateFromTemplateAttributesProvider,v
 <--  org.openide.loaders.CreateFromTemplateAttributesProvider
initial revision: 1.1
/cvs/java/source/test/unit/src/org/netbeans/modules/java/JavaTemplateAttributesProviderTest.java,v
 <--  JavaTemplateAttributesProviderTest.java
initial revision: 1.1
/cvs/projects/projectui/src/org/netbeans/modules/project/ui/resources/license-cddl.txt,v
 <--  license-cddl.txt
initial revision: 1.1
/cvs/projects/projectui/src/org/netbeans/modules/project/ui/resources/license-default.txt,v
 <--  license-default.txt
initial revision: 1.1
/cvs/projects/projectui/src/org/netbeans/modules/project/ui/resources/layer.xml,v
 <--  layer.xml
new revision: 1.75; previous revision: 1.74
/cvs/projects/projectuiapi/src/META-INF/services/org.openide.loaders.CreateFromTemplateAttributesProvider,v
 <--  org.openide.loaders.CreateFromTemplateAttributesProvider
initial revision: 1.1
/cvs/projects/projectuiapi/src/org/netbeans/modules/project/uiapi/ProjectTemplateAttributesProvider.java,v
 <--  ProjectTemplateAttributesProvider.java
initial revision: 1.1
/cvs/projects/projectui/src/org/netbeans/modules/project/ui/Bundle.properties,v
 <--  Bundle.properties
new revision: 1.87; previous revision: 1.86
/cvs/projects/projectuiapi/apichanges.xml,v  <--  apichanges.xml
new revision: 1.30; previous revision: 1.29
/cvs/projects/projectuiapi/arch.xml,v  <--  arch.xml
new revision: 1.17; previous revision: 1.16
/cvs/projects/projectuiapi/nbproject/project.properties,v  <--  project.properties
new revision: 1.31; previous revision: 1.30
Comment 17 Jesse Glick 2007-03-27 22:59:17 UTC
Just reopening temporarily as a reminder that this fix only handled j2seproject.
Please file issues for other project types and then reclose.
Comment 18 Tomas Zezula 2007-03-28 08:50:21 UTC
Agree with Jesse. I found the same problems on JPanel template. I've fixed the
IndentEntry to use encoding, probably fixes Jesse's problems. But for JPanel
having the guarded section it doesn't help since form editor overrides the
readFromStreamToKit and uses GuardedSectionsProvider.createGuardedReader which
takes InputStream and returns a Reader, it should be changed to Reader -> Reader.
Comment 19 Jan Pokorsky 2007-03-28 11:17:29 UTC
And what do you agree with? Jesse wants me to file issues for other project
types. They should provide project.license content in their lookup. JPanel
template (from module) has not been migrated to scripting so it cannot relate to
this issue. It does not use FreeMarker at all.
Comment 20 Jan Pokorsky 2007-03-28 12:50:58 UTC
I filed issues for project types in apisupport/project, j2ee, mobility,
web/project and made them dependent on this issue. If you know about others feel
free to add them.
Comment 21 Quality Engineering 2011-08-16 13:54:49 UTC
Integrated into 'main-golden'
Changeset: http://hg.netbeans.org/main-golden/rev/ce2877ccc1d4
User: Jesse Glick <jglick@netbeans.org>
Log: Removing noisy comment blurb from form templates which was long ago (#95399) removed from other Java templates.


By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo