Search in sources :

Example 6 with PythonPreferences

use of org.apache.netbeans.modules.python4nb.preferences.PythonPreferences in project python4nb by ebresie.

the class PythonUtils method getPythonSources.

// 
// @CheckForNull
// public static PackageJson getPackageJson(Lookup context) {
// return getProjectAndPackageJson(context).second();
// }
// 
// @CheckForNull
// public static Project getPackageJsonProject(Lookup context) {
// return getProjectAndPackageJson(context).first();
// }
// 
// public static Pair<Project, PackageJson> getProjectAndPackageJson(Lookup context) {
// Project project = context.lookup(Project.class);
// PackageJson packageJson = null;
// if (project != null) {
// // project action
// packageJson = new PackageJson(project.getProjectDirectory());
// } else {
// // package.json directly
// FileObject file = context.lookup(FileObject.class);
// if (file == null) {
// DataObject dataObject = context.lookup(DataObject.class);
// if (dataObject != null) {
// file = dataObject.getPrimaryFile();
// }
// }
// if (file != null) {
// packageJson = new PackageJson(file.getParent());
// project = FileOwnerQuery.getOwner(file);
// }
// }
// if (project == null) {
// return Pair.of(null, null);
// }
// if (packageJson == null) {
// return Pair.of(null, null);
// }
// if (!packageJson.exists()) {
// return Pair.of(null, null);
// }
// assert project != null;
// assert packageJson != null;
// return Pair.of(project, packageJson);
// }
@CheckForNull
public static File getPythonSources(Project project) {
    PythonPreferences preferences = PythonSupport.forProject(project).getPreferences();
    if (preferences.isDefaultPython()) {
        // default python
        String pythonSources = PythonOptions.getInstance().getPythonSources();
        if (pythonSources != null) {
            return new File(pythonSources);
        }
        PythonExecutable python = PythonExecutable.getDefault(project, false);
        if (python == null) {
            return null;
        }
        Version version = python.getVersion();
        if (version == null) {
            return null;
        }
        return getPythonSources(version);
    }
    // custom python
    String pythonSources = preferences.getPythonSources();
    if (pythonSources != null) {
        return new File(pythonSources);
    }
    PythonExecutable python = PythonExecutable.forProject(project, false);
    if (python == null) {
        return null;
    }
    Version version = python.getVersion();
    if (version == null) {
        return null;
    }
    return PythonUtils.getPythonSources(project);
}
Also used : PythonExecutable(org.apache.netbeans.modules.python4nb.exec.PythonExecutable) Version(org.apache.netbeans.modules.python4nb.util.Version) PythonPreferences(org.apache.netbeans.modules.python4nb.preferences.PythonPreferences) File(java.io.File) CheckForNull(org.netbeans.api.annotations.common.CheckForNull)

Aggregations

PythonPreferences (org.apache.netbeans.modules.python4nb.preferences.PythonPreferences)6 ActionEvent (java.awt.event.ActionEvent)2 ActionListener (java.awt.event.ActionListener)2 PythonPackage (org.apache.netbeans.modules.python4nb.editor.file.PythonPackage)2 CheckForNull (org.netbeans.api.annotations.common.CheckForNull)2 File (java.io.File)1 Map (java.util.Map)1 PythonExecutable (org.apache.netbeans.modules.python4nb.exec.PythonExecutable)1 PythonSupport (org.apache.netbeans.modules.python4nb.platform.PythonSupport)1 PythonPreferencesValidator (org.apache.netbeans.modules.python4nb.preferences.PythonPreferencesValidator)1 ValidationResult (org.apache.netbeans.modules.python4nb.util.ValidationResult)1 Version (org.apache.netbeans.modules.python4nb.util.Version)1