Project name does not change when editing / changing the .project file
When the .project file changes (e.g. because of update from version control or edit by hand) it seems the label for the project is not updated.
Could you please elaborate the issue ? what is the expected behavior ?
Whenever you change the name attribute within the .project file, this change is not reflected in the project's description and thus not displayed in, e.g., the package explorer or project explorer. At the same time, changes of other attributes in the .project file are observed and processed, such as changing a project's nature.
From my point of view, the name within the .project file should always be consistent with what the in-memory ProjectDescription says. However, there is further conflicting behavior, which also has an impact on the original issue: the project name is only taken from the .project file during an import if the project is not placed in the default location within the workspace. Otherwise, the directory name is used a project name, see the import code of Platform UI
if (projectName == null) {
IPath path = IPath.fromOSString(projectSystemFile.getPath());
// if the file is in the default location, use the directory
// name as the project name
if (isDefaultLocation(path)) {
projectName = path.segment(path.segmentCount() - 2);
description = IDEWorkbenchPlugin.getPluginWorkspace()
.newProjectDescription(projectName);
} else {
description = IDEWorkbenchPlugin.getPluginWorkspace()
.loadProjectDescription(path);
projectName = description.getName();
}
}
I don't know about the reasons for that behavior, but my naive expectation would be as follows:
- When importing a project, the information in
.projectis used if present, otherwise the directory name is used as name - When changing the name in the
.projectfile, it is reflected in the in-memoryProjectDescriptionand everything related to it (such as workspace metadata and its visualization in the UI).
I agree with @HeikoKlare regarding the expected behavior .
Any conflicting opinion for below 1st expectation which would change existing behavior ?
- When importing a project, the information in .project is used if present, otherwise the directory name is used as name
and a concluded expectation will help any contributor to go ahead with a PR .
@HeikoKlare @lathapatil I think the problem is how the resource API works, you can only have a different name when you import a project from "outside", where the folder is still named like the project but then the name is taken from the project file see for example here:
- https://github.com/eclipse-m2e/m2e-core/issues/1504#issuecomment-1678996868
I see. Although I understand the (technical) reasons for the different behaviors of projects inside and outside of the workspace folder, it concerns me from a user experience perspective. You need to have quite some special knowledge to understand under which circumstances project name changes apply to the project description and/or project folder name and vice versa. It also looks rather inconsistent that the effect of a name change depends on where you have placed the project folder.
In fact, you can have a project in your workspace that has a different name persisted in .project than the displayed project name (which conforms to the project folder name). This is always the case if folder name and project name in .project do not match during import, since the .project entry is simply ignored. When importing the same project into an Eclipse with a workspace set to a different location, the project name will match the one present in .project, i.e., be different.
I am not sure what a proper improvement could be, but to me the behavior when importing from other locations than the workspace folder is the "default"/expected one. So I would at least expect some warning when importing a project from the workspace folder and the folder name and the .project name entry do not match, as the behavior differs from the default one in this case. In addition, changing the project name could lead to the question whether the project folder shall also be renamed (which is or has to be enforced when the project folder is placed within the workspace folder).
The best case would be to only have a "single source of truth" for the name information (either the .project entry or the folder name), but I see that there are probably uses cases where either of them is required.
For the reported issue, I would first assume that the name is just updated as if I would have imported the project, currently one needs to do:
- remove the project from workspace
- change the name in project file
- import it again
that should just work. For the special case I would expect that at at least something similar that happens when you edit the name of a java class file then JDT complains that the Java source must be named like the class and gives me the choice to either:
- rename the source file to match the class name
- change the class name to match the source file name
something similar can be implemented here as well for projects inside the workspace.
I have a similar issue with my Eclipse with Maven projects. Upon import, for some projects it uses the project name from pom.xml (either by artifactId or name, I'm not sure which, as they are the same in my poms), and for other projects it just uses the directory name. All of these projects are inside the same workspace folder.
I tried deleting the project, changing the name in the .project file and reimporting again, but Eclipse is ignoring the changed name and imports it the same way as before.