Java Code Examples for org.netbeans.spi.project.support.ant.PropertyUtils#resolveFile()

The following examples show how to use org.netbeans.spi.project.support.ant.PropertyUtils#resolveFile() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MakeSharableVisualPanel1.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Messages({
    "WARN_MakeSharable.absolutePath=<html>Please make sure that the absolute path in the Libraries Folder field is valid for all users.<html>",
    "WARN_makeSharable.relativePath=<html>Please make sure that the relative path in the Libraries Folder field is valid for all users.<html>"
})
boolean isValidPanel() {
    String location = getLibraryLocation();
    boolean wrong = false;
    if (new File(location).isAbsolute()) {
        settings.putProperty(WizardDescriptor.PROP_ERROR_MESSAGE, WARN_MakeSharable_absolutePath());
        wrong = true;
    } else {
        File projectLoc = FileUtil.toFile(helper.getProjectDirectory());
        File libLoc = PropertyUtils.resolveFile(projectLoc, location);
        if (!CollocationQuery.areCollocated(projectLoc, libLoc)) {
            settings.putProperty(WizardDescriptor.PROP_ERROR_MESSAGE, WARN_makeSharable_relativePath());
            wrong = true;
        }
    }
    if (!wrong) {
        settings.putProperty(WizardDescriptor.PROP_ERROR_MESSAGE, null);
    }

    return true;
}
 
Example 2
Source File: EjbJarProjectOperations.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private void rememberLibraryLocation() {
  libraryWithinProject = false;
    absolutesRelPath = null;
    libraryPath = project.getAntProjectHelper().getLibrariesLocation();
    if (libraryPath != null) {
        File prjRoot = FileUtil.toFile(project.getProjectDirectory());
        libraryFile = PropertyUtils.resolveFile(prjRoot, libraryPath);
        if (FileOwnerQuery.getOwner(libraryFile.toURI()) == project && 
                libraryFile.getAbsolutePath().startsWith(prjRoot.getAbsolutePath())) {
            //do not update the relative path if within the project..
            libraryWithinProject = true;
            FileObject fo = FileUtil.toFileObject(libraryFile);
            if (new File(libraryPath).isAbsolute() && fo != null) {
                // if absolte path within project, it will get moved/copied..
                absolutesRelPath = FileUtil.getRelativePath(project.getProjectDirectory(), fo);
            }
        }
    }
}
 
Example 3
Source File: ModuleList.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private static File resolveNbDestDir(File root, File customNbDestDir, PropertyEvaluator eval) throws IOException {
    File nbdestdir;
    if (customNbDestDir == null) {
        String nbdestdirS = eval.getProperty(NETBEANS_DEST_DIR);
        if (nbdestdirS == null) {
            throw new IOException("No netbeans.dest.dir defined in " + root); // NOI18N
        }
        nbdestdir = PropertyUtils.resolveFile(root, nbdestdirS);
    } else {
        nbdestdir = customNbDestDir;
    }
    if (! nbdestdir.exists()) {
        LOG.log(Level.INFO, "Project in " + root // NOI18N
                + " is missing its platform '" + eval.getProperty("nbplatform.active") + "', switching to default platform");    // NOI18N
        NbPlatform p2 = NbPlatform.getDefaultPlatform();
        if (p2 != null)
            nbdestdir = p2.getDestDir();
    }
    return nbdestdir;
}
 
Example 4
Source File: AppClientProjectOperations.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private void rememberLibraryLocation() {
    libraryWithinProject = false;
    absolutesRelPath = null;
    libraryPath = project.getAntProjectHelper().getLibrariesLocation();
    if (libraryPath != null) {
        File prjRoot = FileUtil.toFile(project.getProjectDirectory());
        libraryFile = PropertyUtils.resolveFile(prjRoot, libraryPath);
        if (FileOwnerQuery.getOwner(libraryFile.toURI()) == project && 
                libraryFile.getAbsolutePath().startsWith(prjRoot.getAbsolutePath())) {
            //do not update the relative path if within the project..
            libraryWithinProject = true;
            FileObject fo = FileUtil.toFileObject(libraryFile);
            if (new File(libraryPath).isAbsolute() && fo != null) {
                // if absolte path within project, it will get moved/copied..
                absolutesRelPath = FileUtil.getRelativePath(project.getProjectDirectory(), fo);
            }
        }
    }
}
 
Example 5
Source File: PhpUnit.java    From netbeans with Apache License 2.0 6 votes vote down vote up
static String processIncludePath(File bootstrap, String line, List<String> includePath, File projectDir) {
    String resolvedIncludePath = ""; // NOI18N
    if (!includePath.isEmpty()) {
        StringBuilder buffer = new StringBuilder(200);
        for (String path : includePath) {
            // XXX perhaps already resolved paths should be here?
            File reference = PropertyUtils.resolveFile(projectDir, path);
            buffer.append(".PATH_SEPARATOR"); // NOI18N
            buffer.append(getDirnameFile(bootstrap, reference));
        }
        resolvedIncludePath = buffer.toString();
    } else {
        // comment out the line
        line = "//" + line; // NOI18N
    }
    line = line.replace("%INCLUDE_PATH%", resolvedIncludePath); // NOI18N
    return line;
}
 
Example 6
Source File: ClusterUtils.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Resolves single cluster path entry with respect to project root and ${nbplatform.active} root.
 * @param rawEntry Single cluster.path entry as stored in platform.properties
 * @param root Project root
 * @param eval Project property evaluator
 * @param nbPlatformRoot Platform root used to replace ${nbplatform.active} references in the entry
 * @return Absolute path to entry
 */
public static File evaluateClusterPathEntry(String rawEntry, File root, PropertyEvaluator eval, File nbPlatformRoot) {
    // When cluster does not exist, it is either bare name or one with different number
    final Pattern pat = Pattern.compile("(?:.*[\\\\/])?([^/\\\\]*?)([0-9.]+)?[/\\\\]?$");
    final String nbDirProp = "${" + SuiteProperties.ACTIVE_NB_PLATFORM_DIR_PROPERTY + "}";
    if (rawEntry.startsWith(nbDirProp)) {
        rawEntry = nbPlatformRoot.getAbsolutePath()
                + rawEntry.substring(nbDirProp.length());
    }

    File path = PropertyUtils.resolveFile(root, eval.evaluate(rawEntry));
    if (! path.exists()) {
        // search for corresponding numbered cluster
        final Matcher cm = pat.matcher(path.getAbsolutePath());
        if (cm.matches()) {
            File parent = path.getParentFile();
            if (parent != null) {
                File[] alternate = parent.listFiles(new FilenameFilter() {
                    public @Override boolean accept(File dir, String name) {
                        Matcher am = pat.matcher(name);
                        return am.matches() && cm.group(1).equalsIgnoreCase(am.group(1));
                    }
                });
                if (alternate == null) {
                    // not found, just return what we have
                    return path;
                }
                if (alternate.length > 0 && alternate[0].isDirectory()) {
                    return alternate[0];
                }
            }
        }
    }
    return path;
}
 
Example 7
Source File: SuiteInstallerProjectProperties.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void store() throws IOException {
    Preferences prefs = prefs(suiteProject);
    prefs.putBoolean(GENERATE_FOR_WINDOWS, windowsModel.isSelected());
    prefs.putBoolean(GENERATE_FOR_LINUX, linuxModel.isSelected());
    prefs.putBoolean(GENERATE_FOR_SOLARIS, solarisModel.isSelected());
    prefs.putBoolean(GENERATE_FOR_MAC, macModel.isSelected());
    String licenseName = (String) licenseModel.getSelectedItem();
    if (licenseName != null) {
        int index = licenseModel.getNames().indexOf(licenseName);
        if (index != -1) {
            String type = licenseModel.getTypes().get(index);
            if (type.equals(LICENSE_TYPE_FILE)) {
                File suiteLocation = FileUtil.toFile(suiteProject.getProjectDirectory());
                File f = PropertyUtils.resolveFile(suiteLocation, licenseName);
                String rel = PropertyUtils.relativizeFile(suiteLocation, f);
                if (rel != null) {
                    prefs.put(LICENSE_FILE, rel);
                } else {
                    prefs.put(LICENSE_FILE, f.getAbsolutePath());
                }
                prefs.remove(LICENSE_TYPE);
            } else {
                prefs.put(LICENSE_TYPE, type);
                prefs.remove(LICENSE_FILE);
            }
        }
    }
}
 
Example 8
Source File: EarProject.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/** May return <code>null</code>. */
public FileObject getOrCreateMetaInfDir() {
    String metaInfProp = helper.getStandardPropertyEvaluator().
            getProperty(EarProjectProperties.META_INF);
    if (metaInfProp == null) {
        // IZ 91941
        // does project.properties exist? if yes, something is probably wrong...
        File projectProperties = helper.resolveFile(AntProjectHelper.PROJECT_PROPERTIES_PATH);
        if (projectProperties.exists()) {
            // file exists, log warning
            if (LOGGER.isLoggable(Level.WARNING)) {
                LOGGER.log(Level.WARNING,
                        "Cannot resolve {0} property for {1}", // NOI18N
                        new Object[] {EarProjectProperties.META_INF, this});
            }
        }
        metaInfProp = "src/conf"; // NOI18N
    }
    FileObject metaInfFO = null;
    try {
        File prjDirF = FileUtil.toFile(getProjectDirectory());
        File metaInfF = PropertyUtils.resolveFile(prjDirF, metaInfProp);
        metaInfFO = FileUtil.createFolder(metaInfF);
    } catch (IOException ex) {
        LOGGER.log(Level.INFO, null, ex);
    }
    return metaInfFO;
}
 
Example 9
Source File: SourceForBinaryImplTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void check(String srcS, File jarF) throws Exception {
    File srcF = PropertyUtils.resolveFile(nbRootFile(), srcS);
    FileObject src = FileUtil.toFileObject(srcF);
    assertNotNull("have " + srcF, src);
    URL u = FileUtil.getArchiveRoot(Utilities.toURI(jarF).toURL());
    assertEquals("right results for " + u,
        Collections.singletonList(src),
        trimGenerated(Arrays.asList(SourceForBinaryQuery.findSourceRoots(u).getRoots())));
}
 
Example 10
Source File: Zend2Utils.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public static File getController(File view) {
    String namespace = getNamespaceFromView(view);
    String controllerName = getControllerName(view);
    File controller = PropertyUtils.resolveFile(view.getParentFile(), String.format(CONTROLLER_RELATIVE_FILE, namespace, controllerName));
    if (controller.isFile()) {
        return controller;
    }
    return null;
}
 
Example 11
Source File: ClassPathSupport.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private RelativePath(@NonNull String filePath, @NonNull File base) {
    Parameters.notNull("filePath", filePath);
    Parameters.notNull("base", base);
    this.filePath = filePath;
    this.base = base;
    this.resolvedFile = PropertyUtils.resolveFile(base, filePath);
}
 
Example 12
Source File: Zend2Utils.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public static File getView(File controller, PhpBaseElement phpElement) {
    if (phpElement instanceof PhpClass.Method) {
        String namespace = getNamespaceFromController(controller);
        String viewFolderName = getViewFolderName(controller.getName());
        String viewName = getViewName(phpElement.getName());
        File view = PropertyUtils.resolveFile(controller.getParentFile(), String.format(VIEW_RELATIVE_FILE, dashize(namespace), viewFolderName, viewName));
        if (view.isFile()) {
            return view;
        }
    }
    return null;
}
 
Example 13
Source File: SymfonyUtils.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public static FileObject getAction(FileObject fo) {
    File parent = FileUtil.toFile(fo).getParentFile();
    File action = PropertyUtils.resolveFile(parent, FILE_ACTION_RELATIVE);
    if (action.isFile()) {
        return FileUtil.toFileObject(action);
    }
    return null;
}
 
Example 14
Source File: ProjectLibraryProvider.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public static File getLibrariesLocation(AuxiliaryConfiguration aux, File projectFolder) {
    String text = getLibrariesLocationText(aux);
    if (text != null) {
        return PropertyUtils.resolveFile(projectFolder, text);
    }
    return null;
}
 
Example 15
Source File: EclipseProjectReference.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public EclipseProjectReference(Project project, String eclipseProjectLocation, String eclipseWorkspaceLocation, long timestamp, String key) {
    this.eclipseProjectLocation = PropertyUtils.resolveFile(FileUtil.toFile(project.getProjectDirectory()), eclipseProjectLocation);
    if (eclipseWorkspaceLocation != null) {
        this.eclipseWorkspaceLocation = PropertyUtils.resolveFile(FileUtil.toFile(project.getProjectDirectory()), eclipseWorkspaceLocation);
    } else {
        this.eclipseWorkspaceLocation = null;
    }
    this.timestamp = timestamp;
    this.key = key;
    this.project = project;
}
 
Example 16
Source File: ZendUtils.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public static FileObject getAction(FileObject view) {
    File parent = FileUtil.toFile(view).getParentFile();
    File action = PropertyUtils.resolveFile(parent, String.format(FILE_CONTROLLER_RELATIVE, getControllerName(parent.getName())));
    if (action.isFile()) {
        return FileUtil.toFileObject(action);
    }
    return null;
}
 
Example 17
Source File: PanelOptionsVisual.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
boolean valid(WizardDescriptor settings) {
    
    if (cbSharable.isSelected()) {
        String location = txtLibFolder.getText();
        if (projectLocation != null) {
            if (new File(location).isAbsolute()) {
                settings.putProperty(WizardDescriptor.PROP_ERROR_MESSAGE,
                    NbBundle.getMessage(PanelOptionsVisual.class, "WARN_PanelOptionsVisual.absolutePath"));
            
            } else {
                File projectLoc = FileUtil.normalizeFile(new File(projectLocation));
                File libLoc = PropertyUtils.resolveFile(projectLoc, location);
                if (!CollocationQuery.areCollocated(projectLoc, libLoc)) {
                    settings.putProperty(WizardDescriptor.PROP_ERROR_MESSAGE,
                        NbBundle.getMessage(PanelOptionsVisual.class, "WARN_PanelOptionsVisual.relativePath")); 
                }
            }
        }
    }
    
    if (mainClassTextField.isVisible () && mainClassTextField.isEnabled ()) {
        if (!valid) {
            settings.putProperty(WizardDescriptor.PROP_ERROR_MESSAGE,
                NbBundle.getMessage(PanelOptionsVisual.class,"ERROR_IllegalMainClassName")); //NOI18N
        }
        return this.valid;
    }
    else {
        return true;
    }
}
 
Example 18
Source File: AntServices.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
public File resolveFile(File dir, String relative) {
    return PropertyUtils.resolveFile(dir, relative);
}
 
Example 19
Source File: ClassPathProviderImplTest.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private String urlForJar(String path) {
    File fp = new File(path);
    fp = fp.isAbsolute() ? fp : PropertyUtils.resolveFile(nbRootFile(), path);
    return FileUtil.urlForArchiveOrDir(fp).toExternalForm();
}
 
Example 20
Source File: WebLocationsPanel.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private File getAsFile(String filename) {
    return PropertyUtils.resolveFile(nbProjectFolder, filename);
}