Eclipse project.properties反斜杠路径被认为是有害的 [英] Eclipse project.properties backslash paths considered harmful

查看:264
本文介绍了Eclipse project.properties反斜杠路径被认为是有害的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发Android软件的团队工作。一些团队成员使用Windows,有些使用Mac,而且我已经知道使用Linux。每个人都使用Eclipse。



Eclipse写入一个名为 project.properties 的文件;这是一个例子。最重要的部分是最后三行,Android库引用路径。

 #此文件由Android Tools自动生成。 
#不要修改此文件 - 您的更改将被删除!

#必须在版本控制系统中检查此文件。

#要自定义Ant构建系统使用的属性,编辑
#ant.properties,并覆盖值以使脚本适应
#项目结构。

#要使ProGuard缩小并模糊代码,请取消注释(可用属性:sdk.dir,user.home):
#proguard.config = $ {sdk.dir} /tools/proguard/proguard-android.txt:proguard-project.txt

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

以上是什么该文件看起来像在Mac或Linux上的Eclipse写入它。当Windows上的Eclipse写入它时,库引用行是用反斜杠写的。



当然在Windows上,反斜杠是可接受的路径分隔符。但是在Mac和Linux这样的路径上不行。事实是,在Windows上,正斜杠的工作非常好。所以,我们现在的策略是始终以正斜杠提交文件,以便它适用于所有人。



但这对我们的Windows用户来说是一个痛苦,它是当Windows用户出错时,对我们其他人来说是一个痛苦,所以我正在寻找一个技术解决方案。我有两个想法:




  • 在Windows中的某个地方找到一个设置,告诉它在文件中保存路径时使用正斜杠像 project.properties 。 (为什么这不是默认的?)?


  • 我们使用Mercurial,所以:安装一些可以解决问题的钩子




    • 在Windows计算机上安装提交钩子,以便将文件提交到存储库,反斜杠替换为正斜杠。 / li>
    • 在Mac和Linux电脑上安装拉钩;所以如果文件被提交为反斜杠,那么在写入文件的时候就会被修复。




提交钩子看起来更干净,所以如果两者都可用,我会采取一个提交钩钩钩。



我发现一个Mercurial扩展名编辑标签到空格,这至少与我想要的类似。这很复杂,我试图将它修改成我需要的东西。



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



其他策略是添加一个钩子来检测路径中的反斜杠,并简单地中止提交,强制Windows用户在提交之前手动修复文件。这将比没有更好。

解决方案

我将保留项目中的两个版本(如:em.properties.windows 和 project.properties.linux ),并根据操作系统创建一个指向正确文件的符号链接。调用这个符号链接 project.properties 让它被版本控制忽略。



显然,这个设置是当Windows用户更新他们的 project.properties 文件(指向 project.properties.windows )时,linux版本必须手动更新,反之亦然,但这听起来不是很大的事情,我假定你不要经常更新这个文件。



- 创建链接 -



使用以下命令创建文件 make_link.sh 来设置Linux环境:

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

使用以下命令创建文件 make_link.bat 来设置Windows环境:

  mklink project.properties project.properties.windows 

你可以提交这些脚本。


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.

解决方案

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.

这篇关于Eclipse project.properties反斜杠路径被认为是有害的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆