1 /*
2 * Copyright (c) 1998-2004 The Jgroup Team.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License version 2 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
16 *
17 */
18
19 package jgroup.experiment.runnables;
20
21
22 import java.io.File;
23 import java.io.IOException;
24
25 import jgroup.core.ConfigurationException;
26 import jgroup.experiment.PropertyDefinition;
27 import jgroup.experiment.Runnable;
28 import jgroup.experiment.ShellCommand;
29 import jgroup.relacs.config.ExperimentConfig;
30
31
32 /**
33 * This runnable will check if the current experiment has already
34 * been started before and thus may already have results in its
35 * experiment directory. This is to avoid overwriting/mixing the
36 * results from several runs of the same experiment.
37 *
38 * @author Hein Meling
39 */
40 public class CheckExperimentDir
41 implements Runnable
42 {
43
44 ////////////////////////////////////////////////////////////////////////////////////////////
45 // Methods from Runnable
46 ////////////////////////////////////////////////////////////////////////////////////////////
47
48 /* (non-Javadoc)
49 * @see jgroup.experiment.Runnable#run()
50 */
51 public void run(ExperimentConfig ec)
52 throws ConfigurationException
53 {
54 /* Get the results/experiment directory */
55 String experimentDir = ec.getProperty(this, "results.dir")
56 + File.separator + ec.getExperimentName();
57 boolean delete = ec.getBooleanProperty(this, "delete.results.if.exists", false);
58 File resultsDir = new File(experimentDir);
59 if (resultsDir.exists()) {
60 if (delete) {
61 try {
62 ShellCommand.exec("rm -rf " + experimentDir);
63 } catch (IOException e) {
64 e.printStackTrace();
65 System.out.println("Could not delete experiment directory: " + experimentDir);
66 }
67 } else {
68 throw new ConfigurationException("Results directory for this experiment already exists: " + experimentDir);
69 }
70 }
71 }
72
73 /* (non-Javadoc)
74 * @see jgroup.experiment.Runnable#getProperties()
75 */
76 public PropertyDefinition[] getProperties() {
77 return null;
78 }
79
80 } // END DeleteRemoteLogs