List of usage examples for org.apache.commons.io FilenameUtils removeExtension
public static String removeExtension(String filename)
From source file:ffx.xray.DiffractionData.java
/** * write 2Fo-Fc and Fo-Fc maps for a datasets * * @param filename output root filename for Fo-Fc and 2Fo-Fc maps * @param i a int.//from ww w . j av a2s . c om */ public void writeMaps(String filename, int i) { if (!scaled[i]) { scaleBulkFit(i); } // Fo-Fc crs_fc[i].computeAtomicGradients(refinementData[i].fofc1, refinementData[i].freer, refinementData[i].rfreeflag, RefinementMode.COORDINATES); double[] densityGrid = crs_fc[i].getDensityGrid(); int extx = (int) crs_fc[i].getXDim(); int exty = (int) crs_fc[i].getYDim(); int extz = (int) crs_fc[i].getZDim(); CCP4MapWriter mapwriter = new CCP4MapWriter(extx, exty, extz, crystal[i], FilenameUtils.removeExtension(filename) + "_fofc.map"); mapwriter.write(densityGrid); // 2Fo-Fc crs_fc[i].computeAtomicGradients(refinementData[i].fofc2, refinementData[i].freer, refinementData[i].rfreeflag, RefinementMode.COORDINATES); densityGrid = crs_fc[i].getDensityGrid(); extx = (int) crs_fc[i].getXDim(); exty = (int) crs_fc[i].getYDim(); extz = (int) crs_fc[i].getZDim(); mapwriter = new CCP4MapWriter(extx, exty, extz, crystal[i], FilenameUtils.removeExtension(filename) + "_2fofc.map"); mapwriter.write(densityGrid); }
From source file:com.moviejukebox.tools.FileTools.java
/** * Look for any subtitle files for a file * * @param fileToScan//from w ww. j a v a2 s . c o m * @return */ public static File findSubtitles(File fileToScan) { String basename = FilenameUtils.removeExtension(fileToScan.getAbsolutePath().toUpperCase()); return findFileFromExtensions(basename, SUBTITLE_EXTENSIONS); }
From source file:ffx.xray.DiffractionData.java
/** * write bulk solvent mask for all datasets to a CNS map file * * @param filename output filename, or output root filename for multiple * datasets/*ww w . java2s . co m*/ */ public void writeSolventMaskCNS(String filename) { if (n == 1) { writeSolventMaskCNS(filename, 0); } else { for (int i = 0; i < n; i++) { writeSolventMaskCNS("" + FilenameUtils.removeExtension(filename) + "_" + i + ".map", i); } } }
From source file:ffx.xray.DiffractionData.java
/** * write bulk solvent mask for all datasets to a CCP4 map file * * @param filename output filename, or output root filename for multiple * datasets/*from w w w .j av a 2 s. co m*/ * @see CCP4MapWriter#write(double[], boolean) */ public void writeSolventMask(String filename) { if (n == 1) { writeSolventMask(filename, 0); } else { for (int i = 0; i < n; i++) { writeSolventMask("" + FilenameUtils.removeExtension(filename) + "_" + i + ".map", i); } } }
From source file:fr.fastconnect.factory.tibco.bw.maven.AbstractBWMojo.java
/** * This calls a TIBCO binary./*from w w w . j a v a2 s. co m*/ * * @param binary, the TIBCO binary file to execute * @param tras, the TRA files associated with the TIBCO binary * @param arguments, command-line arguments * @param workingDir, working directory from where the binary is launched * @param errorMsg, error message to display in case of a failure * @param fork, if true the chiild process will be detached from the caller * * @throws IOException * @throws MojoExecutionException */ protected int launchTIBCOBinary(File binary, List<File> tras, ArrayList<String> arguments, File workingDir, String errorMsg, boolean fork, boolean synchronous) throws IOException, MojoExecutionException { Integer result = 0; if (tras == null) { // no value specified as Mojo parameter, we use the .tra in the same directory as the binary String traPathFileName = binary.getAbsolutePath(); traPathFileName = FilenameUtils.removeExtension(traPathFileName); traPathFileName += ".tra"; tras = new ArrayList<File>(); tras.add(new File(traPathFileName)); } HashMap<File, File> trasMap = new HashMap<File, File>(); for (File tra : tras) { // copy of ".tra" file in the working directory File tmpTRAFile = new File(directory, tra.getName()); trasMap.put(tra, tmpTRAFile); copyFile(tra, tmpTRAFile); } for (File tra : trasMap.keySet()) { if (trasMap.containsKey(tibcoDesignerTRAPath) && ((tibcoBuildEARUseDesignerTRA && tra == tibcoBuildEARTRAPath) || (tibcoBuildLibraryUseDesignerTRA && tra == tibcoBuildLibraryTRAPath))) { if (tras.size() > 1) { ReplaceRegExp replaceRegExp = new ReplaceRegExp(); replaceRegExp.setFile(trasMap.get(tra)); replaceRegExp.setMatch("tibco.include.tra (.*/designer.tra)"); replaceRegExp.setReplace( "tibco.include.tra " + trasMap.get(tibcoDesignerTRAPath).toString().replace('\\', '/')); replaceRegExp.setByLine(true); replaceRegExp.execute(); } } if (tra == tibcoBuildEARTRAPath || tra == tibcoDesignerTRAPath || tra == tibcoBWEngineTRAPath) { // FIXME: should check more properly // append user.home at the end to force the use of custom Designer5.prefs PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(trasMap.get(tra), true))); out.println(""); out.println("java.property.user.home=" + directory.getAbsolutePath().replace("\\", "/")); out.close(); } } CommandLine cmdLine = new CommandLine(binary); for (String argument : arguments) { cmdLine.addArgument(argument); } getLog().debug("launchTIBCOBinary command line : " + cmdLine.toString()); getLog().debug("working dir : " + workingDir); DefaultExecutor executor = new DefaultExecutor(); executor.setWorkingDirectory(workingDir); if (timeOut > 0) { ExecuteWatchdog watchdog = new ExecuteWatchdog(timeOut * 1000); executor.setWatchdog(watchdog); } executor.setProcessDestroyer(new ShutdownHookProcessDestroyer()); ByteArrayOutputStream stdOutAndErr = new ByteArrayOutputStream(); executor.setStreamHandler(new PumpStreamHandler(stdOutAndErr)); if (fork) { CommandLauncher commandLauncher = CommandLauncherFactory.createVMLauncher(); commandLauncher.exec(cmdLine, null, workingDir); } else { try { if (synchronous) { result = executor.execute(cmdLine); } else { executor.execute(cmdLine, new DefaultExecuteResultHandler()); } } catch (ExecuteException e) { // TODO : grer erreurs des excutables (ventuellement parser les erreurs classiques) getLog().info(cmdLine.toString()); getLog().info(stdOutAndErr.toString()); getLog().info(result.toString()); throw new MojoExecutionException(errorMsg, e); } catch (IOException e) { throw new MojoExecutionException(e.getMessage(), e); } } return result; }
From source file:net.sf.firemox.DeckBuilder.java
/** * Set the working deck as saved./*w w w. j a va 2 s.c om*/ */ protected void setAsSaved() { isNew = false; modifiedSinceSave = false; String filename = FilenameUtils .removeExtension(FilenameUtils.getName(Configuration.getString("decks.deck(0)"))); setTitle("DeckBuilder : ".concat(filename)); deckNameTxt.setText(filename); }
From source file:com.photon.phresco.framework.rest.api.util.FrameworkServiceUtil.java
public ActionResponse mandatoryValidation(HttpServletRequest request, String goal, String rootModulePath, String subModuleName) throws PhrescoException { ActionResponse actionresponse = new ActionResponse(); ApplicationManager applicationManager = PhrescoFrameworkFactory.getApplicationManager(); try {//w w w. j av a2s . co m List<BuildInfo> builds = applicationManager .getBuildInfos(new File(getBuildInfosFilePath(rootModulePath, subModuleName))); File infoFile = new File(getPhrescoPluginInfoFilePath(goal, null, rootModulePath, subModuleName)); MojoProcessor mojo = new MojoProcessor(infoFile); if (Constants.PHASE_FUNCTIONAL_TEST.equals(goal)) { String functionalTestFramework = FrameworkServiceUtil.getFunctionalTestFramework(rootModulePath, subModuleName); goal = goal + HYPHEN + functionalTestFramework; } List<Parameter> parameters = getMojoParameters(mojo, goal); List<String> eventDependencies = new ArrayList<String>(); List<String> dropDownDependencies = null; Map<String, List<String>> validateMap = new HashMap<String, List<String>>(); if (CollectionUtils.isNotEmpty(parameters)) { for (Parameter parameter : parameters) { if (TYPE_BOOLEAN.equalsIgnoreCase(parameter.getType()) && StringUtils.isNotEmpty(parameter.getDependency())) { //To validate check box dependency controls eventDependencies = Arrays.asList(parameter.getDependency().split(CSV_PATTERN)); validateMap.put(parameter.getKey(), eventDependencies);//add checkbox dependency keys to map if (request.getParameter(parameter.getKey()) != null && dependentParamMandatoryChk(mojo, eventDependencies, goal, request, actionresponse)) { break;//break from loop if error exists } } else if (TYPE_LIST.equalsIgnoreCase(parameter.getType()) && !Boolean.parseBoolean(parameter.getMultiple()) && parameter.getPossibleValues() != null) { //To validate (Parameter type - LIST) single select list box dependency controls if (StringUtils.isNotEmpty(request.getParameter(parameter.getKey()))) { List<Value> values = parameter.getPossibleValues().getValue(); String allPossibleValueDependencies = fetchAllPossibleValueDependencies(values); eventDependencies = Arrays .asList(allPossibleValueDependencies.toString().split(CSV_PATTERN)); validateMap.put(parameter.getKey(), eventDependencies);//add psbl value dependency keys to map for (Value value : values) { dropDownDependencies = new ArrayList<String>(); if (value.getKey().equalsIgnoreCase(request.getParameter((parameter.getKey()))) && StringUtils.isNotEmpty(value.getDependency())) { //get currently selected option's dependency keys to validate and break from loop dropDownDependencies = Arrays.asList(value.getDependency().split(CSV_PATTERN)); break; } } if (dependentParamMandatoryChk(mojo, dropDownDependencies, goal, request, actionresponse)) { //break from loop if error exists break; } } } else if (Boolean.parseBoolean(parameter.getRequired())) { //comes here for other controls boolean alreadyValidated = fetchAlreadyValidatedKeys(validateMap, parameter); if ((parameter.isShow() || !alreadyValidated)) { ActionResponse paramsMandatoryCheck = paramsMandatoryCheck(parameter, request, actionresponse); if (paramsMandatoryCheck.isErrorFound()) { break; } } } else if (TYPE_STRING.equalsIgnoreCase(parameter.getType()) && BUILD_NAME.equalsIgnoreCase(parameter.getKey())) { List<String> platforms = new ArrayList<String>(); String buildName = request.getParameter((parameter.getKey())); String platform = request.getParameter((PLATFORM)); if (StringUtils.isNotEmpty(platform)) { String[] split = platform.split(COMMA); for (String plaform : split) { platforms.add(plaform.replaceAll("\\s+", "") + METRO_BUILD_SEPARATOR + buildName); } } if (!buildName.isEmpty()) { for (BuildInfo build : builds) { String bldName = FilenameUtils.removeExtension(build.getBuildName()); if (bldName.contains(METRO_BUILD_SEPARATOR) && CollectionUtils.isNotEmpty(platforms)) { for (String name : platforms) { if (name.equalsIgnoreCase(bldName)) { actionresponse.setParameterKey("buildName"); actionresponse.setErrorFound(true); actionresponse.setConfigErrorMsg("Build Name Already Exsist"); actionresponse.setStatus(RESPONSE_STATUS_FAILURE); actionresponse.setResponseCode(PHR710018); } } } else if (buildName .equalsIgnoreCase(FilenameUtils.removeExtension(build.getBuildName()))) { actionresponse.setErrorFound(true); actionresponse.setParameterKey("buildName"); actionresponse.setConfigErrorMsg("Build Name Already Exsist"); actionresponse.setStatus(RESPONSE_STATUS_FAILURE); actionresponse.setResponseCode(PHR710018); } } } } else if (TYPE_NUMBER.equalsIgnoreCase(parameter.getType()) && BUILD_NUMBER.equalsIgnoreCase(parameter.getKey())) { String buildNumber = request.getParameter(parameter.getKey()); if (!buildNumber.isEmpty()) { for (BuildInfo build : builds) { if (Integer.parseInt(buildNumber) == build.getBuildNo()) { actionresponse.setParameterKey(BUILD_NUMBER); actionresponse.setErrorFound(true); actionresponse.setConfigErrorMsg("Build Number Already Exsist"); actionresponse.setStatus(RESPONSE_STATUS_FAILURE); actionresponse.setResponseCode(PHR710019); } } } } } } } catch (Exception e) { throw new PhrescoException(e); } return actionresponse; }
From source file:es.ehu.si.ixa.qwn.ppv.CLI.java
private void ukb_compile(String execpath, String kbfile) { String graph = FilenameUtils.removeExtension(kbfile); graph = graph + ".bin"; try {// w w w . jav a 2s.co m String[] command = { execpath + File.separator + "compile_kb", "-o", graph, kbfile }; //System.err.println("UKB komandoa: "+Arrays.toString(command)); ProcessBuilder ukbBuilder = new ProcessBuilder().command(command); //.redirectErrorStream(true); Process compile_kb = ukbBuilder.start(); int success = compile_kb.waitFor(); //System.err.println("compile_kb succesful? "+success); if (success != 0) { BufferedReader bufferedReader = new BufferedReader( new InputStreamReader(compile_kb.getErrorStream()), 1); String line; while ((line = bufferedReader.readLine()) != null) { System.err.println(line); } } } catch (Exception e) { System.err.println("Graph compilation: error when calling compile_kb.\n"); e.printStackTrace(); System.exit(1); } }
From source file:ffx.algorithms.mc.RosenbluthChiAllMove.java
/** * For validation. Performs Monte Carlo chi moves WITHOUT biasing. * Randomly select one chi, give it a random theta. * Accept on the vanilla Metropolis criterion. *//*w w w .j a v a 2 s . c o m*/ private boolean engage_control() { report.append(String.format(" Rosenbluth Control Move: %4d %s\n", moveNumber, target)); double origEnergy = totalEnergy(); double origChi[] = RotamerLibrary.measureRotamer(target, false); int chiIndex = rand.nextInt(origChi.length); double theta = rand.nextDouble(360.0) - 180; double newChi[] = new double[origChi.length]; System.arraycopy(origChi, 0, newChi, 0, origChi.length); newChi[chiIndex] = theta; Rotamer newState = createRotamer(target, newChi); RotamerLibrary.applyRotamer(target, newState); double finalEnergy = totalEnergy(); double dU = finalEnergy - origEnergy; double criterion = FastMath.exp(-beta * dU); double rng = rand.nextDouble(); report.append(String.format(" move (chi,theta): %d %5.1f\n", chiIndex, theta)); report.append(String.format(" orig, final, dU: %.2g %.2g %.2g\n", origEnergy, finalEnergy, dU)); report.append(String.format(" crit, rng: %.2g %.2g\n", criterion, rng)); if (rng < criterion) { accepted = true; report.append(String.format(" Accepted!\n")); PDBFilter writer = new PDBFilter(mola.getFile(), mola, null, null); String filename = FilenameUtils.removeExtension(mola.getFile().toString()); filename = mola.getFile().getAbsolutePath(); if (!filename.contains("_mc")) { filename = FilenameUtils.removeExtension(filename) + "_mc.pdb"; } File file = new File(filename); writer.writeFile(file, false); } else { accepted = false; report.append(String.format(" Denied.\n")); target.revertState(origState); } updateAll(); if (verbose) { logger.info(report.toString()); } return (rng < criterion); }
From source file:com.github.maven_nar.cpptasks.CCTask.java
/** * This method collects a Hashtable, keyed by output file name, of * TargetInfo's for every source file that is specified in the filesets of * the <cc>and nested <compiler>elements. The TargetInfo's contain the * appropriate compiler configurations for their possible compilation * //from w w w. j a v a 2 s . c o m */ private Map<String, TargetInfo> getTargets(final LinkerConfiguration linkerConfig, final Vector<File> objectFiles, final VersionInfo versionInfo, final File outputFile) { // FREEHEP final List<String> order = new ArrayList<>(); final Map<String, TargetInfo> targets = new TreeMap<>(new Comparator<String>() { // Order according to "order" List followed by alphabetical order @Override public int compare(String f0, String f1) { if (order.isEmpty()) { return f0.compareTo(f1); } // Trimming the path and trailing file extension to allow for order // comparison String compf0 = FilenameUtils.getBaseName(f0); String compf1 = FilenameUtils.getBaseName(f1); // remove the hash // TODO: well we hope it's a hash compf0 = FilenameUtils.removeExtension(compf0); compf1 = FilenameUtils.removeExtension(compf1); // order according to list or alphabetical final int i0 = order.indexOf(compf0); final int i1 = order.indexOf(compf1); if (i0 < 0 && i1 < 0) { // none in list // compare original values return f0.compareTo(f1); } else { // make sure we use only one core CCTask.this.ordered = true; if (i0 > 0 && i1 > 0) { // both in list return i0 == i1 ? 0 : i0 < i1 ? -1 : +1; } else if (i1 < 0) { // i0 in list return -1; } else { // i1 in list return +1; } } } }); final TargetDef targetPlatform = getTargetPlatform(); // BEGINFREEHEP // a little trick here, the inner function needs the list to be final, // so that the map order doesn't change after we start adding items, // populate with all the ordered items from each compiler type order.clear(); for (int i = 0; i < this._compilers.size(); i++) { final CompilerDef currentCompilerDef = this._compilers.elementAt(i); if (currentCompilerDef.isActive()) { final List<String> compilerFileOrder = currentCompilerDef.getOrder(); if (compilerFileOrder != null) { order.addAll(compilerFileOrder); } } } // ENDFREEHEP // // find active (specialized) compilers // final Vector<ProcessorConfiguration> biddingProcessors = new Vector<>(this._compilers.size()); for (int i = 0; i < this._compilers.size(); i++) { final CompilerDef currentCompilerDef = this._compilers.elementAt(i); if (currentCompilerDef.isActive()) { final ProcessorConfiguration config = currentCompilerDef.createConfiguration(this, this.linkType, this.compilerDef, targetPlatform, versionInfo); // // see if this processor had a precompile child element // final PrecompileDef precompileDef = currentCompilerDef.getActivePrecompile(this.compilerDef); CommandLineCompilerConfiguration commandLineConfig = (CommandLineCompilerConfiguration) config; AbstractCompiler compiler = (AbstractCompiler) commandLineConfig.getCompiler(); compiler.setWorkDir(currentCompilerDef.getWorkDir()); ProcessorConfiguration[] localConfigs = new ProcessorConfiguration[] { config }; // // if it does then // if (precompileDef != null) { final File prototype = precompileDef.getPrototype(); // // will throw exceptions if prototype doesn't exist, etc // if (!prototype.exists()) { throw new BuildException("prototype (" + prototype.toString() + ") does not exist."); } if (prototype.isDirectory()) { throw new BuildException("prototype (" + prototype.toString() + ") is a directory."); } final String[] exceptFiles = precompileDef.getExceptFiles(); // // create a precompile building and precompile using // variants of the configuration // or return null if compiler doesn't support // precompilation final CompilerConfiguration[] configs = ((CompilerConfiguration) config) .createPrecompileConfigurations(prototype, exceptFiles); if (configs != null && configs.length == 2) { // // visit the precompiled file to add it into the // targets list (just like any other file if // compiler doesn't support precompilation) final TargetMatcher matcher = new TargetMatcher(this, this._objDir, new ProcessorConfiguration[] { configs[0] }, linkerConfig, objectFiles, targets, versionInfo); matcher.visit(new File(prototype.getParent()), prototype.getName()); // // only the configuration that uses the // precompiled header gets added to the bidding list biddingProcessors.addElement(configs[1]); localConfigs = new ProcessorConfiguration[2]; localConfigs[0] = configs[1]; localConfigs[1] = config; } } // // if the compiler has a fileset // then allow it to add its files // to the set of potential targets if (currentCompilerDef.hasFileSets()) { final TargetMatcher matcher = new TargetMatcher(this, this._objDir, localConfigs, linkerConfig, objectFiles, targets, versionInfo); currentCompilerDef.visitFiles(matcher); } biddingProcessors.addElement(config); } } // // add fallback compiler at the end // if (this._compilers.size() == 0) { final ProcessorConfiguration config = this.compilerDef.createConfiguration(this, this.linkType, null, targetPlatform, versionInfo); biddingProcessors.addElement(config); final ProcessorConfiguration[] bidders = new ProcessorConfiguration[biddingProcessors.size()]; biddingProcessors.copyInto(bidders); // // bid out the <fileset>'s in the cctask // final TargetMatcher matcher = new TargetMatcher(this, this._objDir, bidders, linkerConfig, objectFiles, targets, versionInfo); this.compilerDef.visitFiles(matcher); if (outputFile != null && versionInfo != null) { final boolean isDebug = linkerConfig.isDebug(); try { linkerConfig.getLinker().addVersionFiles(versionInfo, this.linkType, outputFile, isDebug, this._objDir, matcher); } catch (final IOException ex) { throw new BuildException(ex); } } } return targets; }