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.
Summary: | Project Template wizard - generated iterator does not substitute <name> | ||
---|---|---|---|
Product: | apisupport | Reporter: | Geertjan Wielenga <geertjan> |
Component: | Templates | Assignee: | Milos Kleint <mkleint> |
Status: | RESOLVED FIXED | ||
Severity: | blocker | CC: | jglick, sigalduek, teenshark |
Priority: | P3 | ||
Version: | 5.x | ||
Hardware: | All | ||
OS: | All | ||
Issue Type: | DEFECT | Exception Reporter: |
Description
Geertjan Wielenga
2005-10-01 11:42:08 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. 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. Please file one bug per issue. Part (a) I am ignoring (assuming unreproducible). Changing to be (b) only. OK. 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. 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. agree with Jesse. IMHO a rather minor cosmetic issue. 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 Upon further thought: usually I fix the project name by using "Rename Project". Wouldn't it be possible to perform this renaming programmatically? 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. 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. 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; Workaround is undestood. However, any plans to fix it for 5.5? No fix is expected for 5.5. apisupport is not under active development. Only serious bugs (esp. regressions) are being fixed for 5.5. 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. 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. 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. 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. 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? For general questions not directly related to this issue please use dev@openide.netbeans.org. 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. 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. 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 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. |