This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 65595 - Project Template wizard - generated iterator does not substitute <name>
Summary: Project Template wizard - generated iterator does not substitute <name>
Status: RESOLVED FIXED
Alias: None
Product: apisupport
Classification: Unclassified
Component: Templates (show other bugs)
Version: 5.x
Hardware: All All
: P3 blocker with 3 votes (vote)
Assignee: Milos Kleint
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-10-01 11:42 UTC by Geertjan Wielenga
Modified: 2007-11-01 15:28 UTC (History)
3 users (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Geertjan Wielenga 2005-10-01 11:42:08 UTC
1. Use project template to register sample in New Project wizard.
2. Install/Reload in Target Platform.
3. Go to New Project wizard, find the sample, and use the wizard to create it.

Two problems:
(a) Newly created sample doesn't open in the IDE. (It's created on disk, but you
need to open it manually.)
(b) The name specified in the New Project wizard is the name of the folder on
disk, but the Display Name is unaffected. I would expect the Display Name to be
the same as the Project Name specified in the New Project wizard.
Comment 1 Geertjan Wielenga 2005-10-01 15:31:16 UTC
In addition, I changed the icon for the template and it was correctly shown in
the New Project wizard after the module was installed. But when I selected the
template, the changed icon was not shown in the Projects window.

By the way, problem (a) above (about sample not opening) doesn't seem to be
reproducable in all cases.
Comment 2 jimjonah 2005-10-02 13:19:15 UTC
I see the sample project open, but the Project Name (displayed in the Project
View) is not what I asked for. It's the name of the original project that was
used to create the nbm in the first place. The folder on disk is the name that I
asked for.
Comment 3 Jesse Glick 2005-10-03 23:03:46 UTC
Please file one bug per issue. Part (a) I am ignoring (assuming unreproducible).
Changing to be (b) only.
Comment 4 Geertjan Wielenga 2005-10-04 15:39:40 UTC
OK.
Comment 5 Milos Kleint 2005-10-05 15:32:33 UTC
well, the project name thing is kind of hard to achieve.

we have no clue about the type of project that we are going to wrap.
it can be webapp project, freeform project, maven project, c++ project.
I have no clue how to perform the project display name rename that would work
for all project types.

the display name is only used for the generated New Project Wizard

closing as wontfix.
Comment 6 Jesse Glick 2005-10-06 00:53:07 UTC
Despite the fact that implementation is not trivial for the reason Milos gave,
the user intention was clearly for the iterator to set the project's visible
name, and most people will see the current behavior as a bug. Possible
implementation options:

1. Check to see if the project contains a file nbproject/project.xml, and if so,
whether there is a match for the xpath
/p:project/p:configuration/*/*[local-name(.) = 'name' and . = $name] where
xmlns:p="http://www.netbeans.org/ns/project/1" and $name =
originalProject.getDisplayName(). Will work for many project types, such as
j2seproject, web, and freeform. If it doesn't work for Maven or C++ projects, oh
well - user will need to customize the iterator. But those are corner cases.

2. Check to see if the project's files contain matches for the string which is
the Project.displayName of the original project selected in the apisupport
wizard. If so, replace matches with e.g. __NAME__ and substitute in the
generated iterator. Will work for more project types, but risks oversubstituting
things (accidental matches for too-generic project names, etc.).

3. Do something like #1 but only for predefined project types.

You can shift some of the calculation to the apisupport wizard, to make the
generated code simpler - it would just need to unpack the ZIP while substituting
__NAME__ in a fixed list of files. If the user needs to customize the
substitution somehow, or if the file list to subst comes up empty (e.g. for a
Maven project under option #1), the user can pretty easily fix it by editing the
file list and using __NAME__ in the ZIP file where appropriate.

Ultimately the user is responsible for making the generated wizard do something
useful; the code generated by apisupport is just intended as a guide to help you
get started. This issue is a bug insofar as setting the project name is a pretty
basic thing that you would expect to happen correctly to begin with, before you
start playing with fancy options; and according to the use cases for Phase III,
some users of apisupport will want to make new project wizards just as a way of
creating simple project templates, and may have little interest in learning the
intricacies of NetBeans APIs.

Due to the difficulties, I would think this is waivable for 5.0, but second
opinions welcome.
Comment 7 Milos Kleint 2005-10-18 11:04:16 UTC
agree with Jesse. IMHO a rather minor cosmetic issue. 
Comment 8 giorgio42 2006-02-25 23:32:03 UTC
I am working on adding support for a proprietary web application framework
(guided by the project template tutorial) to NB5 and just ran into issue b). The
"wrong" project display name is really immediately obvious even to an average user.

Georg
Comment 9 giorgio42 2006-02-26 00:05:18 UTC
Upon further thought: usually I fix the project name by using "Rename Project".
Wouldn't it be possible to perform this renaming programmatically?
Comment 10 _ tboudreau 2006-03-04 21:25:53 UTC
Have a look at what I did in contrib/swingproject - that could be a template 
for how to do this, with a few minor tweaks.  Basically, what it does is, if 
there's a .properties file with the same name as the template, it will look 
for paths and strings in the properties file to substitute, using a few 
magical tokens to substitute values from the wizard - e.g.

src/sampleproject/Main.java=src/%basedir%/Main.java

will unpack Main into whatever package the user specified (%basedir% being 
resolved to a user-entered package name w/ slashes substituted for .'s).

It could be made simpler and just allow %someKeyForAvalueTheWizardHolds% to be 
used in substitution, and document the standard ones but let the person 
designing the UI collect and validate others (as they already do) and if they 
want, use them here.
Comment 11 cbr600f 2006-05-04 11:27:29 UTC
This opens the rename project dialog.

DefaultProjectOperations.performDefaultRenameOperation(ProjectManager.getDefault().findProject(dir),(String)
wiz.getProperty("name"));

Place it just at the end of your Instantiate method and it'll be renamed,
however, an annoying dialog appears. I'm trying to find a way to skip the dialog.

I've been looking at NB Api for less than a day (my firsts steps here, hi all!)
and I've been unable to find a way to rename a project from code.

I saw some example under DefaultProjectOperationsImplementation
(org.netbeans.modules.project.uiapi) that performs that renaming, but I'm not
sure if just calling 
((MoveOperationImplementation) ope).notifyMoved(project, projectDirectoryFile,
newName); 

will rename the project. I'm still uncertain but looking at the code it looks so.
Comment 12 cbr600f 2006-05-04 11:42:00 UTC
I finally made it, it's just a work arround but It should be added to new
project template.

I think I'm using an old NB Api since my Lookup interface lacks lookupAll method.

I'm new at remote cvs / opensource comunity patches but the attached code will
make a temporary patch.

It needs testing against new projects that contains subprojects, testing against
diferent kind (maven / c++) of projects etc.

PS: Plz forgive me for attaching the code here, but I cannot submit attachments
due to our company firewall/proxy


Add this code to new Project Wizzard Iterator template:

        //rename the project
        final Project project = ProjectManager.getDefault().findProject(dir);
        Project nue = null;
        final String newName = (String) wiz.getProperty("name");
        final FileObject projectDirectory = project.getProjectDirectory();
        final File   projectDirectoryFile =
FileUtil.toFile(project.getProjectDirectory());
        MoveOperationImplementation operation = (MoveOperationImplementation)
project.getLookup().lookup(MoveOperationImplementation.class);
        //start moving
        operation.notifyMoving();

        //end moving
        operation.notifyMoved(null, projectDirectoryFile, newName);

        //get new reference (shouldn't be the same?)
        nue = ProjectManager.getDefault().findProject(projectDirectory);

        assert nue != null;

        //notify moved on new reference
        final MoveOperationImplementation newOperation =
(MoveOperationImplementation)
nue.getLookup().lookup(MoveOperationImplementation.class);

        //Notify moved (as API says) must be called on both original and moved
projects
        newOperation.notifyMoved(project, projectDirectoryFile, newName);

        //Save project
        ProjectManager.getDefault().saveProject(nue);

        //do not need to change the returned dir because only renamed project,
not dir
        return resultSet;
Comment 13 sigalduek 2006-06-28 12:55:46 UTC
Workaround is undestood. However, any plans to fix it for 5.5?
Comment 14 Jesse Glick 2006-06-28 17:13:33 UTC
No fix is expected for 5.5. apisupport is not under active development. Only
serious bugs (esp. regressions) are being fixed for 5.5.
Comment 15 teenshark 2006-07-24 06:52:00 UTC
This is in reference to what has suggested as a workaround to this issue. But 
I am not able to figure out where to put this piece of code in my project.
I have created a template project and I am ataching my Project files snapshot 
with this mail.I have tried putting ur piece of code in 
QRProjectWizardIterator.java file
in the method instantiate() .
 
MoveOperationImplementation operation = (MoveOperationImplementation)
project.getLookup().lookup(MoveOperationImplementation.class);

I am getting operation as null. I am unable to proceed from here. It would be 
great help if you suggest me a way out.
 
I am using Netbeans 5.5 Beta Version.
Comment 16 Milos Kleint 2006-07-24 14:01:42 UTC
teenshark: what is the project type of the template you are trying to
instantiate? the project type has to implement the MoveOperationImplementation
for this to work.
Comment 17 teenshark 2006-07-25 07:50:30 UTC
I am trying to instantiate a BPEL Module Type. It doesn't have the rename 
options as such in the first place.Is the renaming functionality for that type 
of module going to be added. or is there any work around.
Comment 18 Jesse Glick 2006-07-27 20:33:36 UTC
The suggested workaround re. MoveOperationImpl sounds too complicated. More
simply: edit the generated wizard. Somewhere, it takes some ZIP entries and
expands them to disk. One or more of those entries presumably mention some dummy
project name; e.g. there might be a <name>sample</name> in project.xml. When it
extracts this ZIP entry, insert the correct name in place of the placeholder.
Nothing complicated. The problem is that the exact thing to replace is variable
across project types so it is hard for the metawizard to generate the right code
for an arbitrary project.
Comment 19 teenshark 2006-07-28 10:48:37 UTC
thank you very much . Now I am able to get the correct module name for the new 
project. I am getting hold of the Project.xml and modifying the name there. 
Does anybody know how to add the renaming functionality to the module?
Comment 20 Jesse Glick 2006-07-28 12:10:07 UTC
For general questions not directly related to this issue please use
dev@openide.netbeans.org.
Comment 21 Milos Kleint 2007-10-31 14:02:25 UTC
the generated code cannot account for any possible situation. Whoever implements the actual module that includes the
project template needs to do the fine tuning according to the requirements.


If possible, please consider using IDE independent means of project templating, eg. from Apache Maven based projects,
use the maven-archetype-plugin.
Comment 22 Jesse Glick 2007-10-31 19:43:28 UTC
This is a very commonly reported problem, and leaves a poor impression since most people will be using an Ant-based
project for the template. After all, the wizards are intended for beginning users of the platform, who probably do not
how to make such customizations yet, or do not even necessarily understand where in a project the name is configured.
Please reconsider providing special handling for nbproject/project.xml#//project/configuration/data/name, which would
address the problem for most people.
Comment 23 Milos Kleint 2007-11-01 10:08:56 UTC
oh well, integrated. However I don't believe that the templates are meant to be full blown, complex codebase that solves
all corner cases. I think it's contra-productive.


Checking in templateWizardIterator.javx;
/cvs/apisupport/project/src/org/netbeans/modules/apisupport/project/ui/wizard/project/templateWizardIterator.javx,v  <--
 templateWizardIterator.javx
new revision: 1.17; previous revision: 1.16
Comment 24 Jesse Glick 2007-11-01 15:28:24 UTC
Getting the name of a created project right is not a corner case; it is an obvious problem that most everyone who runs
the wizard notices and complains about. So I think adding special code for this issue is reasonable.