Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Eclipse project.properties backslash paths considered harmful

I am working in a team that is developing Android software. Some team members use Windows, some use Macs, and I have been known to use Linux. Everyone uses Eclipse.

Eclipse writes a file called project.properties; here's an example. The important part is the last three lines, the android library reference paths.

# This file is automatically generated by Android Tools.
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
#
# This file must be checked in Version Control Systems.
#
# To customize properties used by the Ant build system edit
# "ant.properties", and override values to adapt the script to your
# project structure.
#
# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt

# Project target.
target=android-17
android.library.reference.1=../private-code/lib/SomeLibrary
android.library.reference.2=../google-play-services_lib
android.library.reference.3=../FacebookSDK

The above is what the file looks like when Eclipse on Mac or Linux writes it. When Eclipse on Windows writes it, the library reference lines are written with backslashes.

Of course on Windows, backslashes are acceptable path separators. But on Mac and Linux such paths do not work. The thing is, on Windows, forward slashes work perfectly well. So, our policy now is always to commit the file with forward slashes, so that it will work for everyone.

But this is a pain for our Windows users, and it's a pain for the rest of us when the Windows users make a mistake, so I'm looking for a technical solution. I have two ideas:

  • Find a setting somewhere in Eclipse on Windows, telling it to use forward slashes when saving paths in files like project.properties. (Why the heck isn't that the default?!?)

  • We use Mercurial, so: install some sort of "hooks" that will solve the problem.

    • Install a commit hook on the Windows computers, so that the file is committed into the repository with the backslashes replaced by forward slashes.
    • Install a pull hook on the Mac and Linux computers; so if the file gets committed with backslashes, they get fixed up by the time the files are written.

The commit hook seems cleaner, so if both are available I'd take a commit hook over a pull hook.

I found a Mercurial extension that edits tabs to spaces, which is at least sort of similar to what I want. It's complex enough that I'm a bit leery of trying to modify it into what I need.

https://www.mercurial-scm.org/wiki/CheckFilesExtension

The other strategy is to add a hook that detects backslashes in the paths, and simply aborts the commit, forcing the Windows user to fix the file by hand before committing. That would be better than nothing.

like image 772
steveha Avatar asked Oct 18 '13 05:10

steveha


1 Answers

I would keep both versions in the project (as project.properties.windows and project.properties.linux) and create a symbolic link pointing to the right file depending on the OS. Call this symbolic link project.properties and let it be ignored by the version control.

Obviously the disadvantage of this setup is that when windows users update their project.properties file (which points to project.properties.windows), the linux version must be updated manually, and vice-versa, but it doesn't sound like a big deal tho, I presume you don't update this file very often.

- To create the links -

Create a file make_link.sh to setup Linux environments, with the following command:

ln -s $(readlink -m project.properties.linux) $(readlink . -m)/project.properties

Create a file make_link.bat to setup Windows environments, with the following command:

mklink project.properties project.properties.windows

You can commit those scripts as well.

like image 150
Paulo Amaral Avatar answered Oct 30 '22 08:10

Paulo Amaral