Eclipse and the SVN command line client - eclipse

For a number of good reasons (I think), I find myself wanting to use the SVN command line client rather than the plugin for particular Eclipse-based Android project, and I'd like to verify some assumptions and observations I've made so far:
Don't check-in derivative folders such as: bin, gen, obj, and libs
Do check in source folders such as: assets, jni, res, and src
Do check in .project and .cproject configuration files
This leaves the question of what to do with .classpaths and .settings? Although I've seen some recommend that I don't, I currently do check in .classpaths but not .settings (just discovered it - I'm an Eclipse noob). Any advice from people who've found themselves needing to use SVN outside of Eclipse?

If you are using similar environments (like similar Windows 7 clients where everything is installed and organized in a similar fashion) you can add project specific settings (.classpath, .settings) to version control too. However if your project is checked out in different OS'es, then most probably you would want to keep them out of versioın control.
Eclipse can guide you to what to do. Import the project into SVN by using Eclipse plugin. Then you can switch to the command line tool on prepared repository.

Related

How to share Eclipse workspace and project settings across a team? [duplicate]

Which Eclipse files is it appropriate to put under source control, aside from the sources obviously?
In my project, specifically, I'm wondering about:
.metadata/*
project-dir/.project
project-dir/.classpath
project-dir/.settings/*
If there are any of these for which it depends, please explain your guidelines.
Metadata should not be managed in source control. They contain mostly data relevant to your workspace.
The only exception is the .launch XML files (launcher definition).
They are found in
[eclipse-workspace]\.metadata\.plugins\org.eclipse.debug.core\.launches
And they should be copied into your project directory: When your project is refreshed, those configurations will be displayed in the "Run configuration" dialog.
That way, those launch parameter files can be also managed into the SCM.
(Warning: Do uncheck the option "Delete configurations when associated resource is deleted" in the Run/Launching/Launch Configuration preference panel: It is common to soft-delete a project in order to import it back again - to force a reinitialization of the eclipse metadata. But this option, if checked, will remove your detailed launch parameters!)
project-dir/.project
project-dir/.classpath
project-dir/.settings/*
should be in your SCM (especially .project and .classpath according to the Eclipse documentation).
The goal is that anyone can checkout/update his/her SCM workspace and import the Eclipse project into the Eclipse workspace.
For that, you want to use only relative paths in your .classpath, using linked resources.
Note: it is better if project-dir refers to an "external" project directory, not a directory created under the eclipse workspace. That way, the two notions (eclipse workspace vs. SCM workspace) are clearly separated.
As ipsquiggle mentions in the comment, and as I have alluded to in an old answer, you can actually save the launching configuration as shared file directly in your project directory. All launching configuration can then be versioned like the other project files.
(From the blog post Tip: Creating and Sharing Launch Configurations from KD)
I am currently working on a project where we have the .project and .cproject files under source control. The idea was that settings related to library paths and link directives would propagate across the team.
In practice it hasn't worked very well, merges almost always come back in a conflicted state which need to be deconflicted outside of eclipse and then the project closed and reopened for the changes to take effect.
I wouldn't recommend keeping them in source control.
It's worth nothing that CDT configuration files are not source-control-friendly. There's a bug filed for .cproject files changing very frequently and causing conflicts, see Sharing cdt-project files in repository always causes conflicts.
Some projects, like those using Maven, like to generate the .project files based on POMs.
That said, other than that - .metadata should NOT be in source control. Your project will have to make a determination about whether projectdir/.settings does, based on how you plan to manage standards and such. If you can honestly trust your developers to set up their environment based on the standard, and you don't have to customize anything special for any project, then you don't need to put them in. Me, I recommend configuring every project specifically. This allows devs to work on multiple projects' stuff in the same workspace without having to change default settings back and forth, and it makes the settings very explicit, overriding whatever their default settings are to match the project's standards.
Only difficult part is making sure they all stay in sync. But in most cases you can copy the .settings files from project to project. If there are any you specifically don't want in source control, do the equivalent of setting svn:ignore for them, if your SCM supports it.
The .classpath file is definitively a good candidate for checking into scm as setting it by hand can be a lot of work and will be difficult for new devs getting into the project. It is true it can be generated from other sources, in which case you would check in the other source.
As for .settings, it depends on the settings. This is a grey area, but some settings are almost mandatory and it is convenient to be able to check out a project, import it in Eclipse and have everything set up and good to go.
At our project, we therefore maintain a copy of the .settings folder called CVS.settings and we have an ant task to copy it to .settings. When you get the project from CVS, you call the 'eclipsify' ant task to copy the default settings to the new .settings folder. When you configure settings that are needed by everyone developing on the project, you merge those back into the CVS.settings folder and commit that to CVS. This way saving settings in SCM becomes a conscious process. It does require devs to merge those settings back into their .settings folders from time to time when big changes are checked in. But it's a simple system that works surprisingly well.
I'd say none of them. They most likely contain information that is relevant only to your workstation (I'm thinking about paths for libraries and all). Also what if someone in your team is not using Eclipse?
Consider:
.classpath
.project
.launch
These SHOULD be in version control as long as you stick to using project-relative paths. This allows other developers to check out the project and start working right away without having to go through all the setup pain that other developers went through as well.
You might be tempted to include .metadata in version control as well so Eclipse developers can check out an entire workspace and have it preconfigured with all the right projects, but it includes a lot of user specific information that anytime anybody works on it, it will change, so I would advise to NOT INCLUDE .metadata. It's easy to build a local workspace just by importing all existing Eclipse projects.
I have spent too many hours configuring eclipse workspace settings for new colleagues (and myself). What I ended up doing eventually was copying my own .metadata to the new developer machine.
If you are working on a team, then I think the following are very good candidates to keep under version control:
Installed JREs and their names
Server Runtime Environments
Java Editor Templates
Version Control Keyboard Shortcuts
Plugin settings that do not provide project specific settings
Maven settings
Preconfigured Perspectives
...
I haven't tried to put anything in .metadata under version control, but I'm using version control for these files for ten years now:
project-dir/.project
project-dir/.classpath
project-dir/.settings/*
The main reason is that Eclipse sometimes damages those files. Without version control, you will get weird and hard to track errors. With version control, you can immediately see "Why is it trying to deploy test classes???" or "Why is Maven and Eclipse using the same classpath?" (leading to https://bugs.eclipse.org/bugs/show_bug.cgi?id=430605).
With version control, you can see when it happens and easily go back to a working set of config files.
If you use m2e: You can import the project now with the fast "Import existing project" instead of the slow "Import Maven project".
The drawback of this approach is that Eclipse seems to randomly change some of those files. Most plugins keep them stable but some use HashMap instead of, say, LinkedHashMap so the order of elements changes all the time. This means there is an additional step when you commit: Check for any modified settings and handle them, first.
It also means that the whole team has to agree on some standards: Like which warnings should be enabled. It's interesting that many people see this as a additional problem - as if they weren't working together.
In my experience, it takes a couple of weeks until those files stabilize. Partly because you gradually learn how to tweak Eclipse, partly because people learn what not to touch. You can think of this as lost time or time spent to improve the quality of your work environment (like keeping your desk uncluttered).
There is a bonus advantage of the "Commit settings first": It gets people to commit more often and in smaller pieces (i.e. more like "one thought at a time" instead of "on feature at a time plus a thousand of other, unrelated things that I just happened to stumble upton ... what was I working on again?").
As a seasoned developer, I've come to prefer the "small commits" way of working; it's just easier to stay on track and you tend to sort your thoughts and changes into smaller, more manageable steps. This helps to reduce the level of complexity. Everyone can juggle with one ball, no one can juggle with 20.
PS: For certain setting files, I have unit tests to make sure known errors don't creep in like the "trying to deploy tests" in WTP. That helps in the initial phase "commit everything, I'm too busy" phase.

Separating source and build ouptut in Eclipse

Recently, my work computer was suffering hardware failures so I had the pleasure of migrating data over to a new computer. A project itself is much smaller than the generated output and a significant portion of time was spent moving those generated output.
Currently:
C:\workspace\Project\src\...
C:\workspace\Project\bin\...
Ideally:
C:\workspace\Project\src\...
C:\workspace_output\Project\bin\...
NOTE: For me the source is linked so they don't actually exist within the project.
I was able to change one particular project by following the directions here. However, I have numerous projects and it would be a fairly time-consuming to apply that change to each project (create an "output folder" then point the project to that folder).
Is there a better way to define this behavior within Eclipse? I couldn't find a ${PROJECT_NAME} system variable that I could use (e.g. something like this). I'm fine if the answer is NO as it appears that I have to manually set this for each project. Maybe the next best thing is to write a script to automatically create folders and modify the .project and .classpath.
An alternative like:
Start Eclipse on new machine, point it to the old workspace
Clean projects
Then copy projects onto new machine
Use Eclipse on new machine.
where I can cut out the work of "cleaning" the projects because they are already separate.
In general you'd want to use some kind of version control system or source code management, such as cvs, svn, git, Perforce, Visual SourceSafe, etc. Barring that, you can also use File > Export (or right-click on projects) to export a project or group of projects from Eclipse and it will, by default, exclude any derived content (such as compiled code). Then you can import those projects into another Eclipse workspace.

Sharing eclipse project over SVN

We want to share an eclipse Qt project via an SVN repository.
Of course we need to share the .pro file of Qt to be able to build the project.
The problem is, that without the project files you can not handle the project in eclipse but we cannot use the same as they contain local references.
Also it would be nice to use the Eclipse SVN plugin to manage this.
I already tried to check out the project and create a Qt project on Checkout but this overwrites the checked-out project file.
Any suggestion would be appreciated.
These are some lines from the .cproject file that are autogenerated, so I can not change the absolute paths:
<storageModule moduleId="org.eclipse.cdt.core.pathentry">
<pathentry base-path="/usr/include/qt4" include="" kind="inc" path="" system="true"/>
<pathentry base-path="/usr/include/qt4" include="QtWebKit" kind="inc" path="" system="true"/>
...
There are 2 rules for Subversion (independent of Eclipse, should be the same all the time):
If the tool will regenerate a file, and you don't have to change it:
==> don't check it in your version management (may it Subversion, Git, CVS, ...).
If the file contains parts that are manually changed by a user
==> it should be checked into version management.
If you have the second case (not clear from your question), you should try to change the paths to be relative, so that others could use your project at the same location.
If you cannot change that, stick to the location in the file system. Every developer has to use an identical setup.
If you have to support different operating systems, and the files generated by the tooling are not compliant (shame on the tool makers), you should hold templates for all operating systems in your version management, and should initially (manually) make a copy, depending on the operating system you are working in.
If you have to change that file for some purpose, you have to change the templates as well and should remember that all developers have to make a new copy after that.
Sorry, I don't know Qt and have never developed in a C-environment on different platforms, so my tips are pretty vague.
Finally I found following solution:
No .cproject .project file in SVN!
Import the code files from SVN (also the .pro file for Qt)
Eclipse will ask you to create a project, so create a Qt Project with the same name (or some else, but you will then have to delete the files)
When the project was created, revert it (right MB on the Project in Project Explorer -> Team -> Revert) to the state of the repo checkout
Done, now you can work with the project

Should we commit IDE settings in the VCS?

We're working mainly in Java, using both Eclipse and Intellij in the team.
We had a discussion in the team about committing IDE settings (.iml, .project) on our git.
I'm against this practice, but someone pointed me the fact that would be much easier for everyone to be aligned on the same settings like code style and warnings.
Also they showed me as modern browsers do a good job of separating local machine specific stuff from project specific ones.
Is there are reason why we shouldn't commit them?
The only reason why you could avoid version those files is if they contains developer-specific data (paths that are only valid for one developer and not others, some value which are only relevant on one workstation and not others).
Any other files that:
can be reused by any developer
help get back an environment able to re-build the program with identical settings
should be put in the VCS.
And that include any IDE setting files, as I mention in "Do you keep your project files under version control?", or "Which eclipse files belong under Version Control".

Which Eclipse files belong under version control?

Which Eclipse files is it appropriate to put under source control, aside from the sources obviously?
In my project, specifically, I'm wondering about:
.metadata/*
project-dir/.project
project-dir/.classpath
project-dir/.settings/*
If there are any of these for which it depends, please explain your guidelines.
Metadata should not be managed in source control. They contain mostly data relevant to your workspace.
The only exception is the .launch XML files (launcher definition).
They are found in
[eclipse-workspace]\.metadata\.plugins\org.eclipse.debug.core\.launches
And they should be copied into your project directory: When your project is refreshed, those configurations will be displayed in the "Run configuration" dialog.
That way, those launch parameter files can be also managed into the SCM.
(Warning: Do uncheck the option "Delete configurations when associated resource is deleted" in the Run/Launching/Launch Configuration preference panel: It is common to soft-delete a project in order to import it back again - to force a reinitialization of the eclipse metadata. But this option, if checked, will remove your detailed launch parameters!)
project-dir/.project
project-dir/.classpath
project-dir/.settings/*
should be in your SCM (especially .project and .classpath according to the Eclipse documentation).
The goal is that anyone can checkout/update his/her SCM workspace and import the Eclipse project into the Eclipse workspace.
For that, you want to use only relative paths in your .classpath, using linked resources.
Note: it is better if project-dir refers to an "external" project directory, not a directory created under the eclipse workspace. That way, the two notions (eclipse workspace vs. SCM workspace) are clearly separated.
As ipsquiggle mentions in the comment, and as I have alluded to in an old answer, you can actually save the launching configuration as shared file directly in your project directory. All launching configuration can then be versioned like the other project files.
(From the blog post Tip: Creating and Sharing Launch Configurations from KD)
I am currently working on a project where we have the .project and .cproject files under source control. The idea was that settings related to library paths and link directives would propagate across the team.
In practice it hasn't worked very well, merges almost always come back in a conflicted state which need to be deconflicted outside of eclipse and then the project closed and reopened for the changes to take effect.
I wouldn't recommend keeping them in source control.
It's worth nothing that CDT configuration files are not source-control-friendly. There's a bug filed for .cproject files changing very frequently and causing conflicts, see Sharing cdt-project files in repository always causes conflicts.
Some projects, like those using Maven, like to generate the .project files based on POMs.
That said, other than that - .metadata should NOT be in source control. Your project will have to make a determination about whether projectdir/.settings does, based on how you plan to manage standards and such. If you can honestly trust your developers to set up their environment based on the standard, and you don't have to customize anything special for any project, then you don't need to put them in. Me, I recommend configuring every project specifically. This allows devs to work on multiple projects' stuff in the same workspace without having to change default settings back and forth, and it makes the settings very explicit, overriding whatever their default settings are to match the project's standards.
Only difficult part is making sure they all stay in sync. But in most cases you can copy the .settings files from project to project. If there are any you specifically don't want in source control, do the equivalent of setting svn:ignore for them, if your SCM supports it.
The .classpath file is definitively a good candidate for checking into scm as setting it by hand can be a lot of work and will be difficult for new devs getting into the project. It is true it can be generated from other sources, in which case you would check in the other source.
As for .settings, it depends on the settings. This is a grey area, but some settings are almost mandatory and it is convenient to be able to check out a project, import it in Eclipse and have everything set up and good to go.
At our project, we therefore maintain a copy of the .settings folder called CVS.settings and we have an ant task to copy it to .settings. When you get the project from CVS, you call the 'eclipsify' ant task to copy the default settings to the new .settings folder. When you configure settings that are needed by everyone developing on the project, you merge those back into the CVS.settings folder and commit that to CVS. This way saving settings in SCM becomes a conscious process. It does require devs to merge those settings back into their .settings folders from time to time when big changes are checked in. But it's a simple system that works surprisingly well.
I'd say none of them. They most likely contain information that is relevant only to your workstation (I'm thinking about paths for libraries and all). Also what if someone in your team is not using Eclipse?
Consider:
.classpath
.project
.launch
These SHOULD be in version control as long as you stick to using project-relative paths. This allows other developers to check out the project and start working right away without having to go through all the setup pain that other developers went through as well.
You might be tempted to include .metadata in version control as well so Eclipse developers can check out an entire workspace and have it preconfigured with all the right projects, but it includes a lot of user specific information that anytime anybody works on it, it will change, so I would advise to NOT INCLUDE .metadata. It's easy to build a local workspace just by importing all existing Eclipse projects.
I have spent too many hours configuring eclipse workspace settings for new colleagues (and myself). What I ended up doing eventually was copying my own .metadata to the new developer machine.
If you are working on a team, then I think the following are very good candidates to keep under version control:
Installed JREs and their names
Server Runtime Environments
Java Editor Templates
Version Control Keyboard Shortcuts
Plugin settings that do not provide project specific settings
Maven settings
Preconfigured Perspectives
...
I haven't tried to put anything in .metadata under version control, but I'm using version control for these files for ten years now:
project-dir/.project
project-dir/.classpath
project-dir/.settings/*
The main reason is that Eclipse sometimes damages those files. Without version control, you will get weird and hard to track errors. With version control, you can immediately see "Why is it trying to deploy test classes???" or "Why is Maven and Eclipse using the same classpath?" (leading to https://bugs.eclipse.org/bugs/show_bug.cgi?id=430605).
With version control, you can see when it happens and easily go back to a working set of config files.
If you use m2e: You can import the project now with the fast "Import existing project" instead of the slow "Import Maven project".
The drawback of this approach is that Eclipse seems to randomly change some of those files. Most plugins keep them stable but some use HashMap instead of, say, LinkedHashMap so the order of elements changes all the time. This means there is an additional step when you commit: Check for any modified settings and handle them, first.
It also means that the whole team has to agree on some standards: Like which warnings should be enabled. It's interesting that many people see this as a additional problem - as if they weren't working together.
In my experience, it takes a couple of weeks until those files stabilize. Partly because you gradually learn how to tweak Eclipse, partly because people learn what not to touch. You can think of this as lost time or time spent to improve the quality of your work environment (like keeping your desk uncluttered).
There is a bonus advantage of the "Commit settings first": It gets people to commit more often and in smaller pieces (i.e. more like "one thought at a time" instead of "on feature at a time plus a thousand of other, unrelated things that I just happened to stumble upton ... what was I working on again?").
As a seasoned developer, I've come to prefer the "small commits" way of working; it's just easier to stay on track and you tend to sort your thoughts and changes into smaller, more manageable steps. This helps to reduce the level of complexity. Everyone can juggle with one ball, no one can juggle with 20.
PS: For certain setting files, I have unit tests to make sure known errors don't creep in like the "trying to deploy tests" in WTP. That helps in the initial phase "commit everything, I'm too busy" phase.