开发者

How to share files among several Eclipse projects using SVN?

A bit of context: I am practicing with the former editions of the Google Code Jam, and trying to solve a lot of these puzzles in Java. For each puzzle I create a specific project in Eclipse.

I also built a little "Sample" solver project containing usual operations on input/output files, handling of test cases, script files to run the program on a file quickly, and so on. Now I am using this framework on every pu开发者_如何学Pythonzzle, simply modifying a core "Solver" class which contain the main algorithm. All other files stay the same on every project.

My problem is, I am versioning my work but clearly the only relevant source code to version for each project is this Solver class (and some input/output files). All the rest is duplicated and I would like it to be easily updated when I modify something in the sample project.

On the other hand, I want to be able to easily checkout a project and get it fully working.

I was thinking of using SVN externals to do this but external definitions apply only to subdirectories - and my relevant files are in the same folders as the duplicated ones.

Also SVN ignore does not fulfill my purposes because I would still have to manually replicate any change to my sample project throughout each project.

Do you know of a good way to handle this? Thanks!


Code reuse is typically not accomplished using the version control system, but using polymorphism or libraries. One disadvantage of using the version control system is that you have to do a svn update to pull the new externals from the repository, which strikes me as awkward if you have many projects checked out. Another thing to consider is the development workflow when modifying the reused code. To test your changes, you will probably want to run them with a particular solver, but to do that, you need to svn update - and I am pretty sure you will forget to every once in while, and wonder why your bugfix has no effect ... Therefore I recommend one of the following two approaches:

Polymorphism

Put all your solvers in the same project, making reuse rather trivial. To invoke the right solver, you could do something like:

interface Solver {
    // your methods
}

class Ex1Solver implements Solver {
    // your solution
}

public static void main(String[] args) throws Exception {
    Solver solver = (Solver) Class.forName(args[0]).newInstance();

    // work with solver
}

Library

Define an eclipse project for the reused test harness, and a project for each solution. Declare the reused project as dependency of the solution project (In eclipse, right click on the project -> build path -> configure build path -> projects -> add). The test harness would create the solver in the same way as in the polymorphism solution.


You can use svn:externals with files (starting with 1.6) as well, but i would think about a solution on base of a library, cause it's sound like your "framework" is such a kind of thing.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜