/** {@inheritDoc} */ @Override protected int run(List<String> nonFlagArgs) throws Exception { if (mDo.equals("dump")) { dumpLayout(); } else if (mDo.equals("set")) { Preconditions.checkArgument(!mLayout.isEmpty(), "Specify the layout with --layout=path/to/layout.json"); setLayout(mFiji); } else if (mDo.equals("history")) { history(); } else { System.err.println("Unknown layout action: " + mDo); System.err.println("Specify the action to perform with --do=(dump|set|history)"); return FAILURE; } return SUCCESS; }
/** * Loads a table layout descriptor from a JSON-encoded file. * * @param filePath Path to a JSON-encoded table layout descriptor. * @return the table layout descriptor decoded from the file. * @throws Exception on error. */ private TableLayoutDesc loadJsonTableLayoutDesc(String filePath) throws Exception { final Path path = new Path(filePath); final FileSystem fs = fileSystemSpecified(path) ? path.getFileSystem(getConf()) : FileSystem.getLocal(getConf()); final InputStream istream = fs.open(path); try { return FijiTableLayout.readTableLayoutDescFromJSON(istream); } finally { ResourceUtils.closeOrLog(istream); ResourceUtils.closeOrLog(fs); } }
/** * Implements the --do=set operation. * * @param fiji Fiji instance. * @throws Exception on error. */ private void setLayout(Fiji fiji) throws Exception { final TableLayoutDesc layoutDesc = loadJsonTableLayoutDesc(mLayout); Preconditions.checkArgument(mTableURI.getTable().equals(layoutDesc.getName()), "Descriptor table name '%s' does not match URI %s.", layoutDesc.getName(), mTableURI); fiji.modifyTableLayout(layoutDesc, mDryRun, getPrintStream()); }
/** * Program entry point. * * @param args The command-line arguments. * @throws Exception If there is an error. */ public static void main(String[] args) throws Exception { System.exit(new FijiToolLauncher().run(new LayoutTool(), args)); } }
/** {@inheritDoc} */ @Override protected void setup() throws Exception { super.setup(); mFiji = Fiji.Factory.open(mTableURI, getConf()); }