01: /* Copyright (C) 2004 - 2007 db4objects Inc. http://www.db4o.com
02:
03: This file is part of the db4o open source object database.
04:
05: db4o is free software; you can redistribute it and/or modify it under
06: the terms of version 2 of the GNU General Public License as published
07: by the Free Software Foundation and as clarified by db4objects' GPL
08: interpretation policy, available at
09: http://www.db4o.com/about/company/legalpolicies/gplinterpretation/
10: Alternatively you can write to db4objects, Inc., 1900 S Norfolk Street,
11: Suite 350, San Mateo, CA 94403, USA.
12:
13: db4o is distributed in the hope that it will be useful, but WITHOUT ANY
14: WARRANTY; without even the implied warranty of MERCHANTABILITY or
15: FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16: for more details.
17:
18: You should have received a copy of the GNU General Public License along
19: with this program; if not, write to the Free Software Foundation, Inc.,
20: 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
21: package com.db4o.db4ounit.common.migration;
22:
23: import java.io.*;
24:
25: import com.db4o.db4ounit.util.*;
26: import com.db4o.foundation.io.*;
27:
28: /**
29: * @sharpen.ignore
30: */
31: public class Db4oLibrarian {
32:
33: private final Db4oLibraryEnvironmentProvider _provider;
34:
35: public Db4oLibrarian(Db4oLibraryEnvironmentProvider provider) {
36: _provider = provider;
37: }
38:
39: public Db4oLibrary[] libraries() throws Exception {
40: final File[] libFiles = libFiles(archivesPath());
41: Db4oLibrary[] libraries = new Db4oLibrary[libFiles.length];
42: for (int i = 0; i < libFiles.length; i++) {
43: libraries[i] = forFile(libFiles[i].getCanonicalPath());
44: }
45: return libraries;
46: }
47:
48: public Db4oLibrary forVersion(String version) throws IOException {
49: return forFile(fileForVersion(version));
50: }
51:
52: private String fileForVersion(String version) {
53: return Path4.combine(archivesPath(), "db4o-" + version
54: + "-java1.2.jar");
55: }
56:
57: public Db4oLibrary forFile(final String fname) throws IOException {
58: if (!File4.exists(fname)) {
59: throw new FileNotFoundException(fname);
60: }
61: return new Db4oLibrary(fname, environmentFor(fname));
62: }
63:
64: private Db4oLibraryEnvironment environmentFor(String fname)
65: throws IOException {
66: return _provider.environmentFor(fname);
67: }
68:
69: private File[] libFiles(String libDir) {
70: return new File(libDir).listFiles(new FilenameFilter() {
71: public boolean accept(File file, String name) {
72: return name.endsWith(".jar");
73: }
74: });
75: }
76:
77: private String archivesPath() {
78: return IOServices.safeCanonicalPath(System.getProperty(
79: "db4o.archives.path", WorkspaceServices
80: .workspacePath("db4o.archives/java1.2")));
81: }
82: }
|