Lines 70-76
Link Here
|
70 |
/** Default base prefix: {@value} */ |
70 |
/** Default base prefix: {@value} */ |
71 |
private static final String BASE_PREFIX_DEFAULT = "~/"; // $NON-NLS-1$ |
71 |
private static final String BASE_PREFIX_DEFAULT = "~/"; // $NON-NLS-1$ |
72 |
|
72 |
|
73 |
private static final String BASE_PREFIX = |
73 |
private static final String BASE_PREFIX = |
74 |
JMeterUtils.getPropDefault("jmeter.save.saveservice.base_prefix", // $NON-NLS-1$ |
74 |
JMeterUtils.getPropDefault("jmeter.save.saveservice.base_prefix", // $NON-NLS-1$ |
75 |
BASE_PREFIX_DEFAULT); |
75 |
BASE_PREFIX_DEFAULT); |
76 |
|
76 |
|
Lines 89-95
Link Here
|
89 |
|
89 |
|
90 |
// Cannot be instantiated |
90 |
// Cannot be instantiated |
91 |
private FileServer() { |
91 |
private FileServer() { |
92 |
base = new File(DEFAULT_BASE); |
92 |
setBase(new File(DEFAULT_BASE)); |
93 |
log.info("Default base='"+DEFAULT_BASE+"'"); |
93 |
log.info("Default base='"+DEFAULT_BASE+"'"); |
94 |
} |
94 |
} |
95 |
|
95 |
|
Lines 104-112
Link Here
|
104 |
* Resets the current base to {@link #DEFAULT_BASE}. |
104 |
* Resets the current base to {@link #DEFAULT_BASE}. |
105 |
*/ |
105 |
*/ |
106 |
public synchronized void resetBase() { |
106 |
public synchronized void resetBase() { |
107 |
checkForOpenFiles(); |
107 |
setBase(new File(DEFAULT_BASE)); |
108 |
base = new File(DEFAULT_BASE); |
108 |
log.info("Reset base to'"+base+"'"); |
109 |
log.info("Reset base to'"+base+"'"); |
|
|
110 |
} |
109 |
} |
111 |
|
110 |
|
112 |
/** |
111 |
/** |
Lines 113-131
Link Here
|
113 |
* Sets the current base directory for relative file names from the provided path. |
112 |
* Sets the current base directory for relative file names from the provided path. |
114 |
* If the path does not refer to an existing directory, then its parent is used. |
113 |
* If the path does not refer to an existing directory, then its parent is used. |
115 |
* Normally the provided path is a file, so using the parent directory is appropriate. |
114 |
* Normally the provided path is a file, so using the parent directory is appropriate. |
116 |
* |
115 |
* |
117 |
* @param basedir the path to set, or {@code null} if the GUI is being cleared |
116 |
* @param basedir the path to set, or {@code null} if the GUI is being cleared |
118 |
* @throws IllegalStateException if files are still open |
117 |
* @throws IllegalStateException if files are still open |
119 |
*/ |
118 |
*/ |
120 |
public synchronized void setBasedir(String basedir) { |
119 |
public synchronized void setBasedir(String basedir) { |
121 |
checkForOpenFiles(); // TODO should this be called if basedir == null? |
|
|
122 |
if (basedir != null) { |
120 |
if (basedir != null) { |
123 |
File newBase = new File(basedir); |
121 |
File newBase = new File(basedir); |
124 |
if (!newBase.isDirectory()) { |
122 |
if (!newBase.isDirectory()) { |
125 |
newBase = newBase.getParentFile(); |
123 |
newBase = newBase.getParentFile(); |
126 |
} |
124 |
} |
127 |
base = newBase; |
125 |
setBase(newBase); |
128 |
log.info("Set new base='"+base+"'"); |
|
|
129 |
} |
126 |
} |
130 |
} |
127 |
} |
131 |
|
128 |
|
Lines 133-139
Link Here
|
133 |
* Sets the current base directory for relative file names from the provided script file. |
130 |
* Sets the current base directory for relative file names from the provided script file. |
134 |
* The parameter is assumed to be the path to a JMX file, so the base directory is derived |
131 |
* The parameter is assumed to be the path to a JMX file, so the base directory is derived |
135 |
* from its parent. |
132 |
* from its parent. |
136 |
* |
133 |
* |
137 |
* @param scriptPath the path of the script file; must be not be {@code null} |
134 |
* @param scriptPath the path of the script file; must be not be {@code null} |
138 |
* @throws IllegalStateException if files are still open |
135 |
* @throws IllegalStateException if files are still open |
139 |
* @throws IllegalArgumentException if scriptPath parameter is null |
136 |
* @throws IllegalArgumentException if scriptPath parameter is null |
Lines 149-155
Link Here
|
149 |
|
146 |
|
150 |
/** |
147 |
/** |
151 |
* Sets the current base directory for relative file names. |
148 |
* Sets the current base directory for relative file names. |
152 |
* |
149 |
* |
153 |
* @param jmxBase the path of the script file base directory, cannot be null |
150 |
* @param jmxBase the path of the script file base directory, cannot be null |
154 |
* @throws IllegalStateException if files are still open |
151 |
* @throws IllegalStateException if files are still open |
155 |
* @throws IllegalArgumentException if {@code basepath} is null |
152 |
* @throws IllegalArgumentException if {@code basepath} is null |
Lines 160-165
Link Here
|
160 |
} |
157 |
} |
161 |
checkForOpenFiles(); |
158 |
checkForOpenFiles(); |
162 |
base = jmxBase; |
159 |
base = jmxBase; |
|
|
160 |
System.setProperty("base.dir", base.getAbsolutePath()); // $NON-NLS-1$ |
163 |
log.info("Set new base='"+base+"'"); |
161 |
log.info("Set new base='"+base+"'"); |
164 |
} |
162 |
} |
165 |
|
163 |
|
Lines 168-174
Link Here
|
168 |
* <p> |
166 |
* <p> |
169 |
* Caller must ensure that access to the files map is single-threaded as |
167 |
* Caller must ensure that access to the files map is single-threaded as |
170 |
* there is a window between checking the files Map and clearing it. |
168 |
* there is a window between checking the files Map and clearing it. |
171 |
* |
169 |
* |
172 |
* @throws IllegalStateException if there are any entries still in use |
170 |
* @throws IllegalStateException if there are any entries still in use |
173 |
*/ |
171 |
*/ |
174 |
private void checkForOpenFiles() throws IllegalStateException { |
172 |
private void checkForOpenFiles() throws IllegalStateException { |
Lines 189-195
Link Here
|
189 |
/** |
187 |
/** |
190 |
* Calculates the relative path from {@link #DEFAULT_BASE} to the current base, |
188 |
* Calculates the relative path from {@link #DEFAULT_BASE} to the current base, |
191 |
* which must be the same as or a child of the default. |
189 |
* which must be the same as or a child of the default. |
192 |
* |
190 |
* |
193 |
* @return the relative path, or {@code "."} if the path cannot be determined |
191 |
* @return the relative path, or {@code "."} if the path cannot be determined |
194 |
*/ |
192 |
*/ |
195 |
public synchronized File getBaseDirRelative() { |
193 |
public synchronized File getBaseDirRelative() { |
Lines 197-203
Link Here
|
197 |
File parent = new File(DEFAULT_BASE).getAbsoluteFile(); |
195 |
File parent = new File(DEFAULT_BASE).getAbsoluteFile(); |
198 |
File f = base.getAbsoluteFile(); |
196 |
File f = base.getAbsoluteFile(); |
199 |
ArrayStack l = new ArrayStack(); |
197 |
ArrayStack l = new ArrayStack(); |
200 |
while (f != null) { |
198 |
while (f != null) { |
201 |
if (f.equals(parent)){ |
199 |
if (f.equals(parent)){ |
202 |
if (l.isEmpty()){ |
200 |
if (l.isEmpty()){ |
203 |
break; |
201 |
break; |
Lines 209-215
Link Here
|
209 |
return rel; |
207 |
return rel; |
210 |
} |
208 |
} |
211 |
l.push(f.getName()); |
209 |
l.push(f.getName()); |
212 |
f = f.getParentFile(); |
210 |
f = f.getParentFile(); |
213 |
} |
211 |
} |
214 |
return new File("."); |
212 |
return new File("."); |
215 |
} |
213 |
} |
Lines 317-323
Link Here
|
317 |
* @return String containing the next line in the file (null if EOF reached and not recycle) |
315 |
* @return String containing the next line in the file (null if EOF reached and not recycle) |
318 |
* @throws IOException |
316 |
* @throws IOException |
319 |
*/ |
317 |
*/ |
320 |
public synchronized String readLine(String filename, boolean recycle, |
318 |
public synchronized String readLine(String filename, boolean recycle, |
321 |
boolean firstLineIsNames) throws IOException { |
319 |
boolean firstLineIsNames) throws IOException { |
322 |
FileEntry fileEntry = files.get(filename); |
320 |
FileEntry fileEntry = files.get(filename); |
323 |
if (fileEntry != null) { |
321 |
if (fileEntry != null) { |
Lines 345-351
Link Here
|
345 |
} |
343 |
} |
346 |
|
344 |
|
347 |
/** |
345 |
/** |
348 |
* |
346 |
* |
349 |
* @param alias the file name or alias |
347 |
* @param alias the file name or alias |
350 |
* @param recycle whether the file should be re-started on EOF |
348 |
* @param recycle whether the file should be re-started on EOF |
351 |
* @param firstLineIsNames whether the file contains a file header |
349 |
* @param firstLineIsNames whether the file contains a file header |
Lines 367-373
Link Here
|
367 |
if (firstLineIsNames) { |
365 |
if (firstLineIsNames) { |
368 |
// read first line and forget |
366 |
// read first line and forget |
369 |
reader.readLine(); |
367 |
reader.readLine(); |
370 |
} |
368 |
} |
371 |
} else if (!(fileEntry.inputOutputObject instanceof Reader)) { |
369 |
} else if (!(fileEntry.inputOutputObject instanceof Reader)) { |
372 |
throw new IOException("File " + alias + " already in use"); |
370 |
throw new IOException("File " + alias + " already in use"); |
373 |
} else { |
371 |
} else { |
Lines 382-388
Link Here
|
382 |
if (firstLineIsNames) { |
380 |
if (firstLineIsNames) { |
383 |
// read first line and forget |
381 |
// read first line and forget |
384 |
reader.readLine(); |
382 |
reader.readLine(); |
385 |
} |
383 |
} |
386 |
} else { // OK, we still have some data, restore it |
384 |
} else { // OK, we still have some data, restore it |
387 |
reader.reset(); |
385 |
reader.reset(); |
388 |
} |
386 |
} |
Lines 493-499
Link Here
|
493 |
private static class FileEntry{ |
491 |
private static class FileEntry{ |
494 |
private String headerLine; |
492 |
private String headerLine; |
495 |
private final File file; |
493 |
private final File file; |
496 |
private Closeable inputOutputObject; |
494 |
private Closeable inputOutputObject; |
497 |
private final String charSetEncoding; |
495 |
private final String charSetEncoding; |
498 |
FileEntry(File f, Closeable o, String e){ |
496 |
FileEntry(File f, Closeable o, String e){ |
499 |
file=f; |
497 |
file=f; |
Lines 501-513
Link Here
|
501 |
charSetEncoding=e; |
499 |
charSetEncoding=e; |
502 |
} |
500 |
} |
503 |
} |
501 |
} |
504 |
|
502 |
|
505 |
/** |
503 |
/** |
506 |
* Resolve a file name that may be relative to the base directory. |
504 |
* Resolve a file name that may be relative to the base directory. |
507 |
* If the name begins with the value of the JMeter property |
505 |
* If the name begins with the value of the JMeter property |
508 |
* "jmeter.save.saveservice.base_prefix" |
506 |
* "jmeter.save.saveservice.base_prefix" |
509 |
* - default "~/" - then the name is assumed to be relative to the basename. |
507 |
* - default "~/" - then the name is assumed to be relative to the basename. |
510 |
* |
508 |
* |
511 |
* @param relativeName |
509 |
* @param relativeName |
512 |
* @return the updated file |
510 |
* @return the updated file |
513 |
*/ |
511 |
*/ |