Changeset 3128
- Timestamp:
- Feb 9, 2007, 4:39:41 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/plugins/core/net/sf/basedb/plugins/Base1PluginExecuter.java
r3108 r3128 74 74 import java.io.BufferedInputStream; 75 75 import java.io.BufferedOutputStream; 76 import java.io.BufferedReader;77 76 import java.io.ByteArrayOutputStream; 78 77 import java.io.FileInputStream; … … 81 80 import java.io.IOException; 82 81 import java.io.InputStream; 83 import java.io.InputStreamReader; 84 import java.io.PrintWriter; 82 import java.io.OutputStream; 85 83 import java.sql.SQLException; 86 84 import java.util.ArrayList; … … 97 95 import java.util.regex.Pattern; 98 96 97 /** 98 * This plug-in executes a plug-in from the Base1 system. It takes a base1 configuration 99 * file to create its configuration. 100 * 101 * @author Johan Enell 102 * @version 2.2 103 * @base.modified $Date$ 104 */ 99 105 public class Base1PluginExecuter extends AbstractAnalysisPlugin implements InteractivePlugin 100 106 { 107 101 108 /** 102 109 * Plugin description … … 111 118 "http://base.thep.lu.se"); 112 119 120 /** 121 * The plug-ing permissions. 122 */ 113 123 private static final Set<Permissions> permissions = new HashSet<Permissions>(); 114 124 115 /** 116 * Parameter definition that asks for the file that should be imported. This 117 * is a required parameter for the job configuration. 125 /* Configuration parameters */ 126 127 /** 128 * Parameter definition that asks for the configuration file that should be imported. 118 129 */ 119 130 private static final PluginParameter<File> fileParameter = new PluginParameter<File>( … … 123 134 new FileParameterType(null, false, 1)); 124 135 136 /** 137 * The path to where the plug-in executer can find the executables. In Base1 this was 138 * default to /usr/local/base/plugins. 139 */ 125 140 private static PluginParameter<String> execPathParameter = new PluginParameter<String>( 126 141 "execPath", … … 128 143 "The path to the executables", 129 144 new StringParameterType(255, null, true)); 130 131 /* File configuration parameters */ 145 146 /** 147 * This parameter describes if the data should be exported in serial format or 148 * in matrix. 149 */ 132 150 private PluginParameter<Boolean> serialFormatParameter; 151 152 /** 153 * The version number of the plug-in. 154 */ 133 155 private PluginParameter<String> versionNumberParameter; 156 157 /** 158 * The name of the executable. 159 */ 134 160 private PluginParameter<String> execNameParameter; 161 162 /** 163 * If the data should be exported averaged per gene. 164 */ 135 165 private PluginParameter<Boolean> geneAveragesParameter; 166 167 /** 168 * The minimum number of channels. 169 */ 136 170 private PluginParameter<Integer> minChannelsParameter; 171 172 /** 173 * The maximu number of channels, 0 means unlimited. 174 */ 137 175 private PluginParameter<Integer> maxChannelsParameter; 176 177 /** 178 * If the plug-in should leave the stdin.txt after execution. 179 */ 138 180 private PluginParameter<Boolean> leaveStdinParameter; 181 182 /** 183 * If the plug-in should leave the stdout.txt after execution. 184 */ 139 185 private PluginParameter<Boolean> leaveStdoutParameter; 186 187 /** 188 * The reporter fields that should be exported as a tab separeated string 189 * of column headers. 190 */ 140 191 private PluginParameter<String> usedColumnsParameter; 192 193 /** 194 * The spot fields that should be exported as a tab separated string of 195 * column headres. 196 */ 141 197 private PluginParameter<String> usedFieldsParameter; 142 198 143 199 /* Job parameters */ 200 /** 201 * The directory where the plug-in will store it's output. 202 */ 144 203 private PluginParameter<String> pluginDirectoryParameter; 145 204 205 /** 206 * This command is used if the user decides to configure the plugin by hand. 207 */ 146 208 private static final String COMMAND_MANUAL_CONFIG = "COMMAND_MANUAL_CONFIG"; 147 209 210 /** 211 * Holds info about a job configuration request. 212 */ 148 213 private RequestInformation configureJob; 214 215 /** 216 * Holds information about a plugin configuration request. 217 */ 149 218 private RequestInformation configurePlugin; 219 220 /** 221 * Holds information about a manual plugin configuration request. 222 */ 150 223 private RequestInformation configureManual; 151 224 … … 162 235 /* From InteractivePlugin iterface */ 163 236 237 /** 238 * Checks if the BioAssaySet has the number of channels specified by the 239 * configuration and that it has the extra values. 240 * 241 * @param context The context from where the plugin is invoked. 242 * @param item The item that should be checked if it is in context. 243 * @return null if the the item is in context, otherwise an error messge. 244 * @see net.sf.basedb.core.plugin.AbstractAnalysisPlugin#isInContext(net.sf.basedb.core.plugin.GuiContext, java.lang.Object) 245 */ 164 246 @Override 165 247 public String isInContext(GuiContext context, Object item) … … 334 416 335 417 418 /** 419 * Copies the content from a File to a directory on the filesystem. 420 * 421 * @param f The file to be copied. 422 * @param d The directory where the file will be written. 423 * @throws IOException If there is any error with target. 424 */ 336 425 private void copy(File f, java.io.File d) 337 426 throws IOException … … 342 431 InputStream in = f.getDownloadStream(0); 343 432 FileOutputStream out = new FileOutputStream(target); 344 byte[] buf = new byte[1024]; 345 int i = 0; 346 while((i = in.read(buf)) != -1) 347 { 348 out.write(buf, 0, i); 349 } 350 in.close(); 351 out.close(); 352 } 353 } 354 355 433 434 StreamHandler sh = new StreamHandler(in, out); 435 sh.run(); 436 } 437 } 438 439 440 /** 441 * Creates the plugin directory specified by {@link Base1PluginExecuter#pluginDirectoryParameter}. 442 */ 356 443 private void createPluginDirectory() 357 444 { … … 379 466 380 467 381 /**382 */383 468 @Override 384 469 public Collection<Permissions> getPermissions() … … 491 576 492 577 578 /** 579 * Export the bioassay set to a file called 'stdin.txt' in the plugin directory. 580 * 581 * @param dc The DbControl used to connect to the database. 582 * @return The file where the data is exported to. 583 */ 493 584 private File exportData(DbControl dc) 494 585 { … … 540 631 541 632 633 /** 634 * Get the experimental factors connected to a experiment. 635 * 636 * @param dc The DbControl used to connect to the database. 637 * @param e The experiment. 638 * @return A list of {@link AnnotationType AnnotationTypes} 639 */ 542 640 private List<AnnotationType> getAnnotationTypes(DbControl dc, Experiment e) 543 641 { … … 549 647 550 648 551 649 /** 650 * Get the headers from a configuration file. 651 * 652 * @param f The file. 653 * @return A map of name->value pairs. 654 * @throws IOException If there i any problem reading from file. 655 */ 552 656 private Map<String, String> getBaseFileHeaders(File f) 553 657 throws IOException … … 572 676 573 677 678 /** 679 * Creates a boolean from a string. 680 * 681 * @param s The string. 682 * @return false if s.equals("0") else true. 683 */ 574 684 private Boolean getBoolean(String s) 575 685 { … … 577 687 } 578 688 689 /** 690 * Creates the information needed for manual configuration and initiates the 691 * parameters. The parameters added are: versionNumber, usedColumns, usedFields, execName, 692 * geneAverages, SerialFormat, leaveStdin, leaveStdout, minChannel and maxCannel. 693 * 694 * @return The RequestInformation. 695 */ 579 696 private RequestInformation getManualConfigureParameters() 580 697 { … … 667 784 668 785 786 /** 787 * Creates the information needed for job configuration and initiates the 788 * parameters. The parameters added are: bioAssaySet and the parameters 789 * found in the configuration file. 790 * 791 * @return The RequestInformation. 792 * @throws IOException If there is any error reading from the configuration file. 793 */ 669 794 private RequestInformation getConfigureJobParameters() 670 795 throws IOException … … 687 812 688 813 814 /** 815 * Creates the information needed for plugin configuration and initiates the 816 * parameters. The parameters added are: file and execPath. 817 * 818 * @return The RequestInformation. 819 */ 689 820 private RequestInformation getConfigurePluginParameters() 690 821 { … … 705 836 706 837 838 /** 839 * Get the exec directory as a java.io.File. The exec directory is a sudirectory in 840 * "java.io.tmpdir". 841 * 842 * @return the directory. 843 */ 707 844 private java.io.File getExecDirectory() 708 845 { … … 717 854 718 855 856 /** 857 * Creates a {@link FlatFileParser} for a plugin configuration file. 858 * 859 * @param stream The stream that the parser should read from. 860 * @return The initialized parser 861 */ 719 862 private FlatFileParser getInitializedFlatFileParser(InputStream stream) 720 throws BaseException721 863 { 722 864 FlatFileParser ffp = new FlatFileParser(); … … 731 873 732 874 875 /** 876 * Reads the configuration file an creates the parameters found there. 877 * 878 * @return A list of {@ling PluginParameter PluginsParameters} 879 * @throws IOException Thrown if there is any problem reading the configuration file. 880 */ 733 881 private List<PluginParameter<?>> getJobParameters() 734 882 throws IOException … … 886 1034 887 1035 1036 /** 1037 * Creates the {@link Path} to the plugin directory. 1038 * 1039 * @return The path 1040 */ 888 1041 private Path getPluginDirectoryPath() 889 1042 { … … 893 1046 894 1047 1048 /** 1049 * Imports the data from the file stdout.txt in the execution directory. 1050 * 1051 * @return The id of the transformation the data is connected to. 1052 * @throws IOException if there is any error reading from stdou.txt 1053 */ 895 1054 private int importData() 896 1055 throws IOException … … 1221 1380 } 1222 1381 } 1223 1224 1382 1383 1384 /** 1385 * This thread read everything from one input streat ant writes everything to an output stream. 1386 * 1387 * @author Johan Enell 1388 */ 1225 1389 private class StreamHandler extends Thread 1226 1390 { 1227 private BufferedInputStream is; 1228 1229 private BufferedOutputStream os; 1230 1231 StreamHandler(BufferedInputStream is, BufferedOutputStream redirect) 1391 /** 1392 * The input stream to read from; 1393 */ 1394 private InputStream is; 1395 1396 /** 1397 * The output stream to write to. 1398 */ 1399 private OutputStream os; 1400 1401 /** 1402 * Creates a steam handler connected to the specifiv streams. 1403 * 1404 * @param is The stream to read from. 1405 * @param redirect The stream to write to. 1406 */ 1407 StreamHandler(InputStream is, OutputStream redirect) 1232 1408 { 1233 1409 this.is = is; … … 1238 1414 public void run() 1239 1415 { 1240 PrintWriter out = new PrintWriter(os);1241 BufferedReader in = new BufferedReader(new InputStreamReader(is));1242 String line = null;1243 1416 try 1244 1417 { 1245 while ((line = in.readLine()) != null) 1246 { 1247 out.println(line); 1248 } 1249 out.close(); 1250 in.close(); 1418 byte[] buf = new byte[1024]; 1419 int i = 0; 1420 while((i = is.read(buf)) != -1) 1421 { 1422 os.write(buf, 0, i); 1423 } 1424 is.close(); 1425 os.close(); 1251 1426 } 1252 1427 catch (IOException e)
Note: See TracChangeset
for help on using the changeset viewer.