private List<String> getRelativeFiles(List<File> files) { List<String> fs = new ArrayList<String>(); for (File file : files) { String s = PropertyUtils.relativizeFile(baseFolder, file); if (s != null) { fs.add(s); } } return fs; }
private String getRelativeRootPath(File inputFile, File outputFile) { String relativePath = PropertyUtils.relativizeFile(outputFile.getParentFile(), inputFile.getParentFile()); assert relativePath != null : "input: " + inputFile + " ==> output: " + outputFile; return relativePath; }
/** * Produce a machine-independent relativized version of a filename from a dir. * If path cannot be relative, the full path of the given file is returned. * @param dir base directory * @param file file to be relativized * @return relativized version of a filename from a dir or full path of the given file if the path cannot be relativized * @see PropertyUtils#relativizeFile(File, File) */ public static String relativizeFile(File dir, File file) { String relativePath = PropertyUtils.relativizeFile(dir, file); if (relativePath == null) { // path cannot be relativized => use absolute path (any VCS can be hardly use, of course) relativePath = file.getAbsolutePath(); } return relativePath; }
private boolean isBrandingForModuleEntry(final File srcDir, final BrandableModule mEntry) { return mEntry.getRelativePath().equals(PropertyUtils.relativizeFile(brandingDir, srcDir)); }
private void configFilesFolderBrowseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_configFilesFolderBrowseActionPerformed JFileChooser chooser = new JFileChooser(); FileUtil.preventFileChooserSymlinkTraversal(chooser, null); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); File fileName = new File(jTextFieldConfigFilesFolder.getText()); File configFiles = fileName.isAbsolute() ? fileName : new File(projectFld, fileName.getPath()); if (configFiles.isAbsolute()) { chooser.setSelectedFile(configFiles); } else { chooser.setSelectedFile(projectFld); } if ( JFileChooser.APPROVE_OPTION == chooser.showOpenDialog(this)) { File selected = FileUtil.normalizeFile(chooser.getSelectedFile()); String newConfigFiles; if (CollocationQuery.areCollocated(projectFld, selected)) { newConfigFiles = PropertyUtils.relativizeFile(projectFld, selected); } else { newConfigFiles = selected.getPath(); } jTextFieldConfigFilesFolder.setText(newConfigFiles); } }//GEN-LAST:event_configFilesFolderBrowseActionPerformed
private void loadBrandedFiles(final BrandableModule mEntry, final File file) throws IOException { String entryPath = PropertyUtils.relativizeFile(getModuleEntryDirectory(mEntry),file); BrandedFile bf = new BrandedFile(mEntry, Utilities.toURI(file).toURL(), entryPath); brandedFiles.add(bf); }
private void jButtonBrowseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonBrowseActionPerformed JFileChooser chooser = new JFileChooser(); FileUtil.preventFileChooserSymlinkTraversal(chooser, null); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); File fileName = new File(jTextFieldConfigFilesFolder.getText()); File configFiles = fileName.isAbsolute() ? fileName : new File(projectFld, fileName.getPath()); if (configFiles.isAbsolute()) { chooser.setSelectedFile(configFiles); } else { chooser.setSelectedFile(projectFld); } if ( JFileChooser.APPROVE_OPTION == chooser.showOpenDialog(this)) { File selected = FileUtil.normalizeFile(chooser.getSelectedFile()); String newConfigFiles; if (CollocationQuery.areCollocated(projectFld, selected)) { newConfigFiles = PropertyUtils.relativizeFile(projectFld, selected); } else { newConfigFiles = selected.getPath(); } jTextFieldConfigFilesFolder.setText(newConfigFiles); } }//GEN-LAST:event_jButtonBrowseActionPerformed
String computeExcludes(File root) { StringBuilder buffer = new StringBuilder(100); for (File file : project.getIgnoredFiles()) { String relPath = PropertyUtils.relativizeFile(root, file); if (isUnderneath(relPath)) { assert relPath != null; // #170570 & #185607 - no way to escape space in file path String pattern = relPath.replace(" ", "*"); // NOI18N if (file.isDirectory()) { pattern += "/"; // NOI18N } if (buffer.length() > 0) { buffer.append(","); // NOI18N } buffer.append(pattern); } } ignoreTests(buffer, root, tests); ignoreTests(buffer, root, selenium); return buffer.toString(); }
public void run() { EditableProperties props = project.getAntProjectHelper().getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH); String path = props.getProperty(property); if (path == null) { return; } if (path.startsWith(originalPath.getAbsolutePath())) { String relative = PropertyUtils.relativizeFile(originalPath, new File(path)); String fixedPath = new File(projectDir, relative).getAbsolutePath(); props.setProperty(property, fixedPath); project.getAntProjectHelper().putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, props); } } });
protected final @CheckForNull String getIconLocation() { if (icon48 == null) { return null; } File prj = getProjectDirectoryFile(); String relativePath = PropertyUtils.relativizeFile(prj, icon48.getFileLocation()); return relativePath; }
public void run() { EditableProperties props = project.getAntProjectHelper().getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH); String path = props.getProperty(property); if (path == null) { return; } if (path.startsWith(originalPath.getAbsolutePath())) { String relative = PropertyUtils.relativizeFile(originalPath, new File(path)); if (relative != null) { String fixedPath = new File(projectDir, relative).getAbsolutePath(); props.setProperty(property, fixedPath); project.getAntProjectHelper().putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, props); } } } });
private void ignoreTests(StringBuilder buffer, File root, SourceRoots tests) { if (tests == null) { return; } assert tests.isTest() : "Not test source roots provided: " + Arrays.toString(tests.getRoots()); for (FileObject fo : tests.getRoots()) { File test = FileUtil.toFile(fo); if (test != null) { assert test.isDirectory() : test; String relPath = PropertyUtils.relativizeFile(root, test); if (isUnderneath(relPath)) { String pattern = relPath + "/"; // NOI18N if (buffer.length() > 0) { buffer.append(","); // NOI18N } buffer.append(pattern); } } } }
private void setWebRoot(PhpProjectGenerator.ProjectProperties createProperties, EditableProperties projectProperties, EditableProperties privateProperties, List<PhpModuleProperties> phpModuleProperties) { for (PhpModuleProperties properties : phpModuleProperties) { FileObject webRoot = properties.getWebRoot(); if (webRoot != null) { String relPath = PropertyUtils.relativizeFile(createProperties.getSourcesDirectory(), FileUtil.toFile(webRoot)); assert relPath != null && !relPath.startsWith("../") : "WebRoot must be underneath Sources"; projectProperties.setProperty(PhpProjectProperties.WEB_ROOT, relPath); break; // 1st wins } } }
private void updateReference(String value, String key, boolean main) { File absFile = ahelper.resolveFile(value); String newVal = relative ? PropertyUtils.relativizeFile(FileUtil.toFile(ahelper.getProjectDirectory()), absFile) : absFile.getAbsolutePath(); if (newVal == null) { //fallback newVal = absFile.getAbsolutePath(); } if (!newVal.equals(value)) { if (main) { refhelper.createForeignFileReferenceAsIs(newVal, key); } else { refhelper.createExtraForeignFileReferenceAsIs(newVal, key); } } } }
/** * Browse for a file from the given directory and return the relative path or <code>null</code> if nothing selected. * @param folder folder to browse files from. * @param preselected the preselected value, can be null. * @return the relative path to folder or <code>null</code> if nothing selected. */ public static String browseFolderFile(PhpVisibilityQuery phpVisibilityQuery, FileObject folder, String preselected) throws FileNotFoundException { if (folder == null) { throw new FileNotFoundException(); } FileObject selected = BrowseFolders.showDialog(phpVisibilityQuery, new FileObject[] {folder}, DataObject.class, securePreselected(preselected, true)); if (selected != null) { return PropertyUtils.relativizeFile(FileUtil.toFile(folder), FileUtil.toFile(selected)); } return null; }
private void setTests(PhpProjectGenerator.ProjectProperties createProperties, EditableProperties projectProperties, EditableProperties privateProperties, List<PhpModuleProperties> phpModuleProperties) { if (phpModuleProperties.isEmpty()) { return; } File projectDir = createProperties.getProjectDirectory(); if (projectDir == null) { projectDir = createProperties.getSourcesDirectory(); } assert projectDir != null; for (PhpModuleProperties properties : phpModuleProperties) { FileObject tests = properties.getTests(); if (tests != null) { File testDir = FileUtil.toFile(tests); // relativize path String testPath = PropertyUtils.relativizeFile(projectDir, testDir); if (testPath == null) { // path cannot be relativized => use absolute path (any VCS can be hardly use, of course) testPath = testDir.getAbsolutePath(); } projectProperties.setProperty(PhpProjectProperties.TEST_SRC_DIR, testPath); break; // 1st wins } } }
@CheckForNull static File resolveTarget(File root, List<Pair<String, String>> mappings, File file, String name) { for (Pair<String, String> mapping : mappings) { File from = resolveFile(root, mapping.first()); String relpath; try { relpath = PropertyUtils.relativizeFile(from, file.getParentFile()); } catch (IllegalArgumentException ex) { // #237525 LOGGER.log(Level.INFO, "Incorrect mapping [existing file set]", ex); return null; } if (relpath != null && !relpath.startsWith("..")) { // NOI18N // path match File to = resolveFile(root, mapping.second()); to = PropertyUtils.resolveFile(to, relpath); return resolveFile(to, makeCssFilename(name)); } } // no mapping return null; }
/** * Doesn't check given arguments. Be sure they are valid as supposed by * {@link PropertyUtils#relativizeFile(File, File)} method. */ private String getProjectPath(FileObject file) { return PropertyUtils.relativizeFile( FileUtil.toFile(getProject().getProjectDirectory()), FileUtil.normalizeFile(FileUtil.toFile(file))); } }
private static String browseSource(PhpProject project, String preselected, boolean selectDirectory) { FileObject rootFolder = ProjectPropertiesSupport.getSourcesDirectory(project); assert rootFolder != null; FileObject selected = BrowseFolders.showDialog(PhpVisibilityQuery.forProject(project), new FileObject[] {rootFolder}, selectDirectory ? DataFolder.class : DataObject.class, securePreselected(preselected, !selectDirectory)); if (selected != null) { return PropertyUtils.relativizeFile(FileUtil.toFile(rootFolder), FileUtil.toFile(selected)); } return null; }
private static void configureSources(AntProjectHelper helper, ProjectProperties projectProperties, EditableProperties sharedProperties, EditableProperties privateProperties) { File srcDir = projectProperties.getSourcesDirectory(); File projectDirectory = FileUtil.toFile(helper.getProjectDirectory()); String srcPath = PropertyUtils.relativizeFile(projectDirectory, srcDir); if (srcPath == null) { // path cannot be relativized => use absolute path (any VCS can be hardly use, of course) srcPath = srcDir.getAbsolutePath(); } sharedProperties.setProperty(PhpProjectProperties.SRC_DIR, srcPath); sharedProperties.setProperty(PhpProjectProperties.WEB_ROOT, "."); // NOI18N sharedProperties.setProperty(PhpProjectProperties.PHP_VERSION, projectProperties.getPhpVersion().name()); // NOI18N }