List of usage examples for java.io File isAbsolute
public boolean isAbsolute()
From source file:org.apache.hadoop.hdfs.server.datanode.fsdataset.impl.FsDatasetImpl.java
/** * Removes a set of volumes from FsDataset. * @param volumesToRemove a set of absolute root path of each volume. * @param clearFailure set true to clear failure information. * * DataNode should call this function before calling * {@link DataStorage#removeVolumes(java.util.Collection)}. *///from w w w .ja va 2 s. c om @Override public synchronized void removeVolumes(Set<File> volumesToRemove, boolean clearFailure) { // Make sure that all volumes are absolute path. for (File vol : volumesToRemove) { Preconditions.checkArgument(vol.isAbsolute(), String.format("%s is not absolute path.", vol.getPath())); } for (int idx = 0; idx < dataStorage.getNumStorageDirs(); idx++) { Storage.StorageDirectory sd = dataStorage.getStorageDir(idx); final File absRoot = sd.getRoot().getAbsoluteFile(); if (volumesToRemove.contains(absRoot)) { LOG.info("Removing " + absRoot + " from FsDataset."); // Disable the volume from the service. asyncDiskService.removeVolume(sd.getCurrentDir()); volumes.removeVolume(absRoot, clearFailure); // Removed all replica information for the blocks on the volume. Unlike // updating the volumeMap in addVolume(), this operation does not scan // disks. for (String bpid : volumeMap.getBlockPoolList()) { for (Iterator<ReplicaInfo> it = volumeMap.replicas(bpid).iterator(); it.hasNext();) { ReplicaInfo block = it.next(); final File absBasePath = new File(block.getVolume().getBasePath()).getAbsoluteFile(); if (absBasePath.equals(absRoot)) { invalidate(bpid, block); it.remove(); } } } storageMap.remove(sd.getStorageUuid()); } } }
From source file:com.izforge.izpack.compiler.CompilerConfig.java
private void processSingleFileChildren(File baseDir, IXMLElement packElement, PackInfo pack) throws CompilerException { for (IXMLElement singleFileNode : packElement.getChildrenNamed("singlefile")) { String src = xmlCompilerHelper.requireAttribute(singleFileNode, "src"); String target = xmlCompilerHelper.requireAttribute(singleFileNode, "target"); List<OsModel> osList = OsConstraintHelper.getOsList(singleFileNode); // TODO: unverified OverrideType override = getOverrideValue(singleFileNode); String overrideRenameTo = getOverrideRenameToValue(singleFileNode); Blockable blockable = getBlockableValue(singleFileNode, osList); Map additionals = getAdditionals(singleFileNode); String condition = singleFileNode.getAttribute("condition"); File file = new File(src); if (!file.isAbsolute()) { file = new File(compilerData.getBasedir(), src); }//from w w w. j av a 2 s. co m // if the path does not exist, maybe it contains variables if (!file.exists()) { try { file = new File(variableSubstitutor.substitute(file.getAbsolutePath())); } catch (Exception e) { assertionHelper.parseWarn(singleFileNode, e.getMessage()); } // next existance checking appears in pack.addFile } try { logger.info("Adding file: " + file + ", as target file=" + target); pack.addFile(baseDir, file, target, osList, override, overrideRenameTo, blockable, additionals, condition); } catch (IOException x) { assertionHelper.parseError(singleFileNode, x.getMessage(), x); } } }
From source file:com.izforge.izpack.compiler.CompilerConfig.java
private void processParsableChildren(PackInfo pack, List<IXMLElement> parsableChildren) throws CompilerException { for (IXMLElement parsableNode : parsableChildren) { String target = parsableNode.getAttribute("targetfile"); SubstitutionType type = SubstitutionType.lookup(parsableNode.getAttribute("type", "plain")); String encoding = parsableNode.getAttribute("encoding", null); List<OsModel> osList = OsConstraintHelper.getOsList(parsableNode); // TODO: unverified String condition = parsableNode.getAttribute("condition"); if (target != null) { ParsableFile parsable = new ParsableFile(target, type, encoding, osList); parsable.setCondition(condition); pack.addParsable(parsable);/*from w w w.j a v a 2s .c o m*/ } // FIXME Use different type of fileset to scan already added files instead of the local // filesystem for (IXMLElement fileSetElement : parsableNode.getChildrenNamed("fileset")) { String targetdir = xmlCompilerHelper.requireAttribute(fileSetElement, "targetdir"); String dir_attr = xmlCompilerHelper.requireAttribute(fileSetElement, "dir"); File dir = new File(dir_attr); if (!dir.isAbsolute()) { dir = new File(compilerData.getBasedir(), dir_attr); } if (!dir.isDirectory()) // also tests '.exists()' { assertionHelper.parseError(fileSetElement, "Invalid directory 'dir': " + dir_attr); } String[] includedFiles = getFilesetIncludedFiles(fileSetElement); if (includedFiles != null) { for (String filePath : includedFiles) { File file = new File(dir, filePath); if (file.exists() && file.isFile()) { String targetFile = new File(targetdir, filePath).getPath().replace(File.separatorChar, '/'); ParsableFile parsable = new ParsableFile(targetFile, type, encoding, osList); parsable.setCondition(condition); pack.addParsable(parsable); } } } } } }
From source file:com.izforge.izpack.compiler.CompilerConfig.java
private IXMLElement readRefPackData(String refFileName, boolean isselfcontained) throws CompilerException { File refXMLFile = new File(refFileName); if (!refXMLFile.isAbsolute()) { refXMLFile = new File(compilerData.getBasedir(), refFileName); }// w ww. j av a 2s . c o m if (!refXMLFile.canRead()) { throw new CompilerException("Invalid file: " + refXMLFile); } InputStream specin; if (isselfcontained) { if (!refXMLFile.getAbsolutePath().endsWith(".zip")) { throw new CompilerException( "Invalid file: " + refXMLFile + ". Selfcontained files can only be of type zip."); } ZipFile zip; try { zip = new ZipFile(refXMLFile, ZipFile.OPEN_READ); ZipEntry specentry = zip.getEntry("META-INF/izpack.xml"); specin = zip.getInputStream(specentry); } catch (IOException e) { throw new CompilerException("Error reading META-INF/izpack.xml in " + refXMLFile); } } else { try { specin = new FileInputStream(refXMLFile.getAbsolutePath()); } catch (FileNotFoundException e) { throw new CompilerException("FileNotFoundException exception while reading refXMLFile"); } } IXMLParser refXMLParser = new XMLParser(); // We get it IXMLElement refXMLData = refXMLParser.parse(specin, refXMLFile.getAbsolutePath()); // Now checked the loaded XML file for basic syntax // We check it if (!"installation".equalsIgnoreCase(refXMLData.getName())) { assertionHelper.parseError(refXMLData, "this is not an IzPack XML installation file"); } if (!CompilerData.VERSION.equalsIgnoreCase(xmlCompilerHelper.requireAttribute(refXMLData, "version"))) { assertionHelper.parseError(refXMLData, "the file version is different from the compiler version"); } // Read the properties and perform replacement on the rest of the tree substituteProperties(refXMLData); // call addResources to add the referenced XML resources to this installation addResources(refXMLData); try { specin.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return refXMLData; }
From source file:com.izforge.izpack.compiler.CompilerConfig.java
private String[] getFilesetIncludedFiles(IXMLElement fileSetElement) throws CompilerException { List<String> includedFiles = new ArrayList<String>(); String dir_attr = xmlCompilerHelper.requireAttribute(fileSetElement, "dir"); File dir = new File(dir_attr); if (!dir.isAbsolute()) { dir = new File(compilerData.getBasedir(), dir_attr); }//from ww w .j av a 2 s .co m if (!dir.isDirectory()) // also tests '.exists()' { assertionHelper.parseError(fileSetElement, "Invalid directory 'dir': " + dir_attr); } boolean casesensitive = xmlCompilerHelper.validateYesNoAttribute(fileSetElement, "casesensitive", YES); boolean defexcludes = xmlCompilerHelper.validateYesNoAttribute(fileSetElement, "defaultexcludes", YES); // get includes and excludes List<IXMLElement> xcludesList; String[] includes = null; xcludesList = fileSetElement.getChildrenNamed("include"); if (!xcludesList.isEmpty()) { includes = new String[xcludesList.size()]; for (int j = 0; j < xcludesList.size(); j++) { IXMLElement xclude = xcludesList.get(j); includes[j] = xmlCompilerHelper.requireAttribute(xclude, "name"); } } String[] excludes = null; xcludesList = fileSetElement.getChildrenNamed("exclude"); if (!xcludesList.isEmpty()) { excludes = new String[xcludesList.size()]; for (int j = 0; j < xcludesList.size(); j++) { IXMLElement xclude = xcludesList.get(j); excludes[j] = xmlCompilerHelper.requireAttribute(xclude, "name"); } } // parse additional fileset attributes "includes" and "excludes" String[] toDo = new String[] { "includes", "excludes" }; // use the existing containers filled from include and exclude // and add the includes and excludes to it String[][] containers = new String[][] { includes, excludes }; for (int j = 0; j < toDo.length; ++j) { String inex = fileSetElement.getAttribute(toDo[j]); if (inex != null && inex.length() > 0) { // This is the same "splitting" as ant PatternSet do ... StringTokenizer tokenizer = new StringTokenizer(inex, ", ", false); int newSize = tokenizer.countTokens(); String[] nCont = null; if (containers[j] != null && containers[j].length > 0) { // old container exist; create a new which can hold // all values // and copy the old stuff to the front newSize += containers[j].length; nCont = new String[newSize]; System.arraycopy(containers[j], 0, nCont, 0, containers[j].length); } if (nCont == null) // No container for old values created, create a new one. { nCont = new String[newSize]; } for (int k = 0; k < newSize; ++k) // Fill the new one or expand the existent container { nCont[k] = tokenizer.nextToken(); } containers[j] = nCont; } } includes = containers[0]; // push the new includes to the // local var excludes = containers[1]; // push the new excludes to the // local var // scan and add fileset DirectoryScanner directoryScanner = new DirectoryScanner(); directoryScanner.setIncludes(includes); directoryScanner.setExcludes(excludes); if (defexcludes) { directoryScanner.addDefaultExcludes(); } directoryScanner.setBasedir(dir); directoryScanner.setCaseSensitive(casesensitive); try { directoryScanner.scan(); String[] files = directoryScanner.getIncludedFiles(); String[] dirs = directoryScanner.getIncludedDirectories(); // Directory scanner has done recursion, add files and // directories Collections.addAll(includedFiles, files); Collections.addAll(includedFiles, dirs); } catch (Exception e) { throw new CompilerException(e.getMessage()); } return includedFiles.toArray(new String[includedFiles.size()]); }
From source file:cms.service.template.TemplateUtility.java
/**************************************************************************************** * the method getLogFileList take a file's path, and lists all files with .log extension * return a array of file names which matches the filter. ****************************************************************************************/ public String[] getLogFileList(String aPath) { String[] m_List;//from ww w . ja va 2 s. c o m String[] m_Log = null; int findex = 0; try { File m_File = new File(aPath); if (m_File.isAbsolute() && m_File.isDirectory()) { m_List = m_File.list(); for (int i = 0; i < m_List.length; i++) { int index = m_List[i].indexOf(".log"); if (m_List[i].substring(index + 1).equalsIgnoreCase("log")) { // m_Log[findex]=m_List[i]; findex++; } } if (findex > 0) { int k = 0; m_Log = new String[findex]; for (int i = 0; i < m_List.length; i++) { int index = m_List[i].indexOf(".log"); if (m_List[i].substring(index + 1).equalsIgnoreCase("log")) { m_Log[k] = m_List[i]; k++; } } } } } catch (Exception e) { e.printStackTrace(); logger.info(e.getMessage()); } return m_Log; }
From source file:com.izforge.izpack.compiler.CompilerConfig.java
/** * Add packs and their contents to the installer without checking the dependencies and includes. * <p/>//from www . j a v a 2s . c o m * Helper method to recursively add more packs from refpack XML packs definitions * * @param data The XML data * @throws CompilerException */ private void addPacksSingle(IXMLElement data) throws CompilerException { notifyCompilerListener("addPacksSingle", CompilerListener.BEGIN, data); // Initialisation IXMLElement root = xmlCompilerHelper.requireChildNamed(data, "packs"); // at least one pack is required List<IXMLElement> packElements = root.getChildrenNamed("pack"); List<IXMLElement> refPackElements = root.getChildrenNamed("refpack"); List<IXMLElement> refPackSets = root.getChildrenNamed("refpackset"); if (packElements.isEmpty() && refPackElements.isEmpty() && refPackSets.isEmpty()) { assertionHelper.parseError(root, "<packs> requires a <pack>, <refpack> or <refpackset>"); } File baseDir = new File(compilerData.getBasedir()); for (IXMLElement packElement : packElements) { // Trivial initialisations String name = xmlCompilerHelper.requireAttribute(packElement, "name"); String id = packElement.getAttribute("id"); String packImgId = packElement.getAttribute("packImgId"); boolean loose = Boolean.parseBoolean(packElement.getAttribute("loose", "false")); String description = xmlCompilerHelper.requireChildNamed(packElement, "description").getContent(); boolean required = xmlCompilerHelper.requireYesNoAttribute(packElement, "required"); String group = packElement.getAttribute("group"); String installGroups = packElement.getAttribute("installGroups"); String excludeGroup = packElement.getAttribute("excludeGroup"); boolean uninstall = "yes".equalsIgnoreCase(packElement.getAttribute("uninstall", "yes")); long size = xmlCompilerHelper.getLong(packElement, "size", 0); String parent = packElement.getAttribute("parent"); boolean hidden = Boolean.parseBoolean(packElement.getAttribute("hidden", "false")); String conditionid = packElement.getAttribute("condition"); if (required && excludeGroup != null) { assertionHelper.parseError(packElement, "Pack, which has excludeGroup can not be required.", new Exception("Pack, which has excludeGroup can not be required.")); } PackInfo pack = new PackInfo(name, id, description, required, loose, excludeGroup, uninstall, size); pack.setOsConstraints(OsConstraintHelper.getOsList(packElement)); // TODO: pack.setParent(parent); pack.setCondition(conditionid); pack.setHidden(hidden); // unverified // if the pack belongs to an excludeGroup it's not preselected by default if (excludeGroup == null) { pack.setPreselected(xmlCompilerHelper.validateYesNoAttribute(packElement, "preselected", YES)); } else { pack.setPreselected(xmlCompilerHelper.validateYesNoAttribute(packElement, "preselected", NO)); } // Set the pack group if specified if (group != null) { pack.setGroup(group); } // Set the pack install groups if specified if (installGroups != null) { StringTokenizer st = new StringTokenizer(installGroups, ","); while (st.hasMoreTokens()) { String igroup = st.nextToken(); pack.addInstallGroup(igroup); } } // Set the packImgId if specified if (packImgId != null) { pack.setPackImgId(packImgId); } List<IXMLElement> parsableChildren = packElement.getChildrenNamed("parsable"); processParsableChildren(pack, parsableChildren); List<IXMLElement> executableChildren = packElement.getChildrenNamed("executable"); processExecutableChildren(pack, executableChildren); processFileChildren(baseDir, packElement, pack); processSingleFileChildren(baseDir, packElement, pack); processFileSetChildren(baseDir, packElement, pack); processUpdateCheckChildren(packElement, pack); // We get the dependencies for (IXMLElement dependsNode : packElement.getChildrenNamed("depends")) { String depName = xmlCompilerHelper.requireAttribute(dependsNode, "packname"); pack.addDependency(depName); } for (IXMLElement validator : packElement.getChildrenNamed("validator")) { Class<PackValidator> type = classLoader.loadClass(xmlCompilerHelper.requireContent(validator), PackValidator.class); pack.addValidator(type.getName()); } // We add the pack packager.addPack(pack); } for (IXMLElement refPackElement : refPackElements) { // get the name of reference xml file String refFileName = xmlCompilerHelper.requireAttribute(refPackElement, "file"); String selfcontained = refPackElement.getAttribute("selfcontained"); boolean isselfcontained = Boolean.valueOf(selfcontained); // parsing ref-pack-set file IXMLElement refXMLData = this.readRefPackData(refFileName, isselfcontained); logger.info("Reading refpack from " + refFileName); // Recursively call myself to add all packs and refpacks from the reference XML addPacksSingle(refXMLData); } for (IXMLElement refPackSet : refPackSets) { // the directory to scan String dir_attr = xmlCompilerHelper.requireAttribute(refPackSet, "dir"); File dir = new File(dir_attr); if (!dir.isAbsolute()) { dir = new File(compilerData.getBasedir(), dir_attr); } if (!dir.isDirectory()) // also tests '.exists()' { assertionHelper.parseError(refPackSet, "Invalid refpackset directory 'dir': " + dir_attr); } // include pattern String includeString = xmlCompilerHelper.requireAttribute(refPackSet, "includes"); String[] includes = includeString.split(", "); // scan for refpack files DirectoryScanner ds = new DirectoryScanner(); ds.setIncludes(includes); ds.setBasedir(dir); ds.setCaseSensitive(true); // loop through all found fils and handle them as normal refpack files String[] files; try { ds.scan(); files = ds.getIncludedFiles(); for (String file : files) { String refFileName = new File(dir, file).toString(); // parsing ref-pack-set file IXMLElement refXMLData = this.readRefPackData(refFileName, false); // Recursively call myself to add all packs and refpacks from the reference XML addPacksSingle(refXMLData); } } catch (Exception e) { throw new CompilerException(e.getMessage()); } } notifyCompilerListener("addPacksSingle", CompilerListener.END, data); }
From source file:com.joliciel.talismane.TalismaneConfigImpl.java
private File getFile(String path) { File file = new File(path); if (!file.isAbsolute() && baseDir != null) { file = new File(baseDir, path); }// w ww. ja va2s.c o m return file; }
From source file:axiom.framework.core.Application.java
private synchronized void updateProperties() { // if so property file has been updated, re-read props. if (props.lastModified() > lastPropertyRead) { // force property update props.update();//from w w w .j a v a2 s .c o m // character encoding to be used for responses charset = props.getProperty("charset", "ISO-8859-1"); // debug flag debug = "true".equalsIgnoreCase(props.getProperty("debug")); // if rhino debugger is enabled use higher (10 min) default request timeout String defaultReqTimeout = "true".equalsIgnoreCase(props.getProperty("rhino.debug")) ? "600" : "60"; String reqTimeout = props.getProperty("requesttimeout", defaultReqTimeout); try { requestTimeout = Long.parseLong(reqTimeout) * 1000L; } catch (Exception ignore) { // go with default value requestTimeout = 60000L; } // default to 1hour String defaultSessionTimeout = "3600"; String sessionTimeout = props.getProperty("sessiontimeout", defaultSessionTimeout); try { this.sessionTimeout = Long.parseLong(sessionTimeout) * 1000L; } catch (Exception ignore) { // go with default value requestTimeout = 3600000L; } // set base URI String base = props.getProperty("baseuri"); if (base != null) { setBaseURI(base); } else if (baseURI == null) { baseURI = "/"; } hrefRootPrototype = props.getProperty("hrefrootprototype"); // if node manager exists, update it if (nmgr != null) { nmgr.updateProperties(props); } // update extensions if (Server.getServer() != null) { for (AxiomExtension ext : Server.getServer().getExtensions()) { try { ext.applicationUpdated(this); } catch (ConfigurationException e) { logEvent("Error updating extension " + ext + ": " + e); } } } logDir = props.getProperty("logdir"); if (logDir != null) { File dir = new File(logDir); System.setProperty("axiom.logdir", dir.getAbsolutePath()); } else { logDir = "log"; } String repos = props.getProperty("db.blob.dir"); if (repos == null) { File dir = new File(this.dbDir, "blob"); if (!dir.exists() || !dir.isDirectory()) { if (!dir.mkdir()) { throw new IllegalArgumentException("Could not create the blob dir for " + this.name); } } repos = dir.getPath(); } else { File dir = new File(repos); if (!dir.isAbsolute()) { ResourceProperties appProps = new ResourceProperties(this, "app.properties"); boolean definedInApp = appProps.getProperty("db.blob.dir") != null ? true : false; if (definedInApp) { dir = new File(appDir, repos); } else { dir = new File(axiomHome, repos); } } if (!dir.exists() || !dir.isDirectory()) { if (!dir.mkdirs()) { throw new IllegalArgumentException("Could not create the blob dir for " + this.name); } } repos = dir.getPath(); } this.blobDir = repos; this.autoUpdate = new Boolean(props.getProperty("automaticResourceUpdate", "true")).booleanValue(); // set log level for event log in case it is a axiom.util.Logger if (eventLog instanceof Logger) { ((Logger) eventLog).setLogLevel(debug ? Logger.DEBUG : Logger.INFO); } String onStart = props.getProperty("onStart"); if (onStart != null) { for (String funcs : onStart.split(",")) { this.onstartFunctions.add(funcs.trim()); } } // set prop read timestamp lastPropertyRead = props.lastModified(); } }
From source file:au.org.ala.delta.intkey.Intkey.java
@Override public void addToolbarButton(boolean advancedModeOnly, boolean normalModeOnly, boolean inactiveUnlessUsedCharacters, String imageFileName, List<String> commands, String shortHelp, String fullHelp) {/*w w w. jav a2s . c o m*/ Icon icon = null; // Is the image file an absolute file? File iconFile = new File(imageFileName); if (iconFile.exists() && iconFile.isAbsolute()) { try { icon = readImageIconFromFile(iconFile); } catch (IOException ex) { displayErrorMessage(UIUtils.getResourceString("ErrorReadingIconImageFromFile.error", iconFile.getAbsolutePath())); } } // Is the image file relative to the dataset directory? if (icon == null) { File relativeIconFile = new File(_context.getDatasetDirectory(), imageFileName); if (relativeIconFile.exists() && relativeIconFile.isAbsolute()) { try { icon = readImageIconFromFile(relativeIconFile); } catch (IOException ex) { displayErrorMessage(UIUtils.getResourceString("ErrorReadingIconImageFromFile.error", iconFile.getAbsolutePath())); } } } // try getting an icon with the exact image name from the icon resources if (icon == null) { try { icon = IconHelper.createImageIconFromAbsolutePath(INTKEY_ICON_PATH + "/" + imageFileName); } catch (Exception ex) { // do nothing } } if (icon == null && imageFileName.toLowerCase().endsWith(".bmp")) { // try substituting ".bmp" for ".png" and reading from the icon // resources. All the default // icons that come with Intkey have been convert to png format. String modifiedImageFileName = imageFileName.replaceFirst(".bmp$", ".png"); try { icon = IconHelper.createImageIconFromAbsolutePath(INTKEY_ICON_PATH + "/" + modifiedImageFileName); } catch (Exception ex) { // do nothing } } if (icon == null) { displayErrorMessage(UIUtils.getResourceString("CouldNotFromImage.error", imageFileName)); return; } JButton button = new JButton(icon); button.setToolTipText(shortHelp); button.setMargin(new Insets(0, 0, 0, 0)); _pnlDynamicButtons.add(button); final List<String> commandsCopy = new ArrayList<String>(commands); button.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { for (String command : commandsCopy) { _context.parseAndExecuteDirective(command); } } }); if (advancedModeOnly && !normalModeOnly) { _advancedModeOnlyDynamicButtons.add(button); } if (normalModeOnly && !advancedModeOnly) { _normalModeOnlyDynamicButtons.add(button); } if (inactiveUnlessUsedCharacters) { _activeOnlyWhenCharactersUsedButtons.add(button); } _dynamicButtonsFullHelp.put(button, fullHelp); updateDynamicButtons(); }