51 static final boolean debug = System.getProperty("module.debug") != null;
52
53 static EventChecker ec = new EventChecker();
54
55 private static void println(String s) {
56 if (debug) System.err.println(s);
57 }
58
59 private static File makeTestDir(String name) throws IOException {
60 File rc =
61 new File(
62 System.getProperty("test.scratch", "."), name).getCanonicalFile();
63 if (rc.exists() ) {
64 JamUtils.recursiveDelete(rc);
65 }
66 rc.mkdirs();
67 return rc;
68 }
69
70 public static void realMain(String[] args) throws Throwable {
71
72 // Enables shadow file copies in the repository if we're running
73 // on Windows. This is to prevent file locking in the
74 // source location.
75 if (System.getProperty("os.platform").equalsIgnoreCase("windows")) {
76 System.setProperty("java.module.repository.shadowcopyfiles", "true");
77 }
78
79 File srcDir =
80 new File(
81 System.getProperty("test.scratch", "."), "LocalRepoSrc").getCanonicalFile();
82 if (srcDir.exists()) {
83 JamUtils.recursiveDelete(srcDir);
84 }
85 File expandDir = makeTestDir("LocalRepoExpand");
86
87 // Check that getApplicationRepository() doesn't return null and is
88 // configured OK.
89 Repository appRepo = Repository.getApplicationRepository();
90 check(appRepo != null);
91
92 Map<String, String> config = new HashMap<String, String>();
93 config.put("sun.module.repository.LocalRepository.cacheDirectory",
94 expandDir.getAbsolutePath());
95 Repository repo = Modules.newLocalRepository(
160 // Verify that repository is now *not* read-only
161 check(repo.isReadOnly() == false);
162
163 // Check that find() and list() return nothing from repo, since its
164 // source dir is empty.
165 check(repo.list().size() == 0);
166 check(findModuleDefsInRepository(repo).size() == 0);
167
168 File jamDir = makeTestDir("LocalRepoJam");
169
170 // Create a JAM file in the LocalRepository's sourceLocation
171 File jamFile = JamBuilder.createJam(
172 "localrepotest", "LocalRepoTestA", "LocalRepoModuleA", "3.1",
173 null, null, false, srcDir);
174
175 // Verify that we can reload from a read-only location
176 boolean readOnlyChangeOK = (srcDir.setWritable(false) == true);
177 repo.reload();
178
179 if (readOnlyChangeOK) {
180 // check(repo.isReadOnly());
181 }
182
183 // Check initial module is installed
184 List<ModuleArchiveInfo> installed = repo.list();
185 println("=installed size " + installed.size());
186 check(installed.size() == 1);
187 ModuleArchiveInfo mai = installed.get(0);
188 check(mai.getName().equals("LocalRepoModuleA"));
189
190 // MODULE_ARCHIVE_INSTALLED event should be fired.
191 check(!ec.initializeEventExists(repo));
192 check(!ec.shutdownEventExists(repo));
193 check(ec.installEventExists(repo, mai));
194 check(!ec.uninstallEventExists(repo, null));
195
196 // Verify module is runnable from read-only source location
197 runModule(repo, "LocalRepoModuleA");
198
199 // Verify that we can reload from a writable directory
200 readOnlyChangeOK = (srcDir.setWritable(true) == true);
201 repo.reload();
|
51 static final boolean debug = System.getProperty("module.debug") != null;
52
53 static EventChecker ec = new EventChecker();
54
55 private static void println(String s) {
56 if (debug) System.err.println(s);
57 }
58
59 private static File makeTestDir(String name) throws IOException {
60 File rc =
61 new File(
62 System.getProperty("test.scratch", "."), name).getCanonicalFile();
63 if (rc.exists() ) {
64 JamUtils.recursiveDelete(rc);
65 }
66 rc.mkdirs();
67 return rc;
68 }
69
70 public static void realMain(String[] args) throws Throwable {
71 boolean onWindows = System.getProperty("os.platform").equalsIgnoreCase("windows");
72
73 // Enables shadow file copies in the repository if we're running
74 // on Windows. This is to prevent file locking in the
75 // source location.
76 if (onWindows) {
77 System.setProperty("java.module.repository.shadowcopyfiles", "true");
78 }
79
80 File srcDir =
81 new File(
82 System.getProperty("test.scratch", "."), "LocalRepoSrc").getCanonicalFile();
83 if (srcDir.exists()) {
84 JamUtils.recursiveDelete(srcDir);
85 }
86 File expandDir = makeTestDir("LocalRepoExpand");
87
88 // Check that getApplicationRepository() doesn't return null and is
89 // configured OK.
90 Repository appRepo = Repository.getApplicationRepository();
91 check(appRepo != null);
92
93 Map<String, String> config = new HashMap<String, String>();
94 config.put("sun.module.repository.LocalRepository.cacheDirectory",
95 expandDir.getAbsolutePath());
96 Repository repo = Modules.newLocalRepository(
161 // Verify that repository is now *not* read-only
162 check(repo.isReadOnly() == false);
163
164 // Check that find() and list() return nothing from repo, since its
165 // source dir is empty.
166 check(repo.list().size() == 0);
167 check(findModuleDefsInRepository(repo).size() == 0);
168
169 File jamDir = makeTestDir("LocalRepoJam");
170
171 // Create a JAM file in the LocalRepository's sourceLocation
172 File jamFile = JamBuilder.createJam(
173 "localrepotest", "LocalRepoTestA", "LocalRepoModuleA", "3.1",
174 null, null, false, srcDir);
175
176 // Verify that we can reload from a read-only location
177 boolean readOnlyChangeOK = (srcDir.setWritable(false) == true);
178 repo.reload();
179
180 if (readOnlyChangeOK) {
181 if (!onWindows) {
182 // I/O APIs are not completely honest about writability of
183 // directories on Windows; see 4939819 and 6728842.
184 check(repo.isReadOnly());
185 }
186 }
187
188 // Check initial module is installed
189 List<ModuleArchiveInfo> installed = repo.list();
190 println("=installed size " + installed.size());
191 check(installed.size() == 1);
192 ModuleArchiveInfo mai = installed.get(0);
193 check(mai.getName().equals("LocalRepoModuleA"));
194
195 // MODULE_ARCHIVE_INSTALLED event should be fired.
196 check(!ec.initializeEventExists(repo));
197 check(!ec.shutdownEventExists(repo));
198 check(ec.installEventExists(repo, mai));
199 check(!ec.uninstallEventExists(repo, null));
200
201 // Verify module is runnable from read-only source location
202 runModule(repo, "LocalRepoModuleA");
203
204 // Verify that we can reload from a writable directory
205 readOnlyChangeOK = (srcDir.setWritable(true) == true);
206 repo.reload();
|