use of org.apache.netbeans.modules.python4nb.editor.file.PythonPackage in project python4nb by ebresie.
the class PythonPlatformProvider method projectNameChanged.
void projectNameChanged(Project project, final String newName) {
final String projectDir = project.getProjectDirectory().getNameExt();
PythonSupport pythonSupport = PythonSupport.forProject(project);
final PythonPreferences preferences = pythonSupport.getPreferences();
if (!preferences.isEnabled()) {
LOGGER.log(Level.FINE, "Project name change ignored in project {0}, python not enabled", projectDir);
return;
}
if (!preferences.isSyncEnabled()) {
LOGGER.log(Level.FINE, "Project name change ignored in project {0}, sync not enabled", projectDir);
return;
}
final PythonPackage packageJson = pythonSupport.getPythonPackage();
if (!packageJson.exists()) {
LOGGER.log(Level.FINE, "Project name change ignored in project {0}, package.json not exist", projectDir);
return;
}
LOGGER.log(Level.FINE, "Processing project name change in project {0}", projectDir);
Map<String, Object> content = packageJson.getContent();
if (content == null) {
LOGGER.log(Level.FINE, "Project name change ignored in project {0}, package.json has no or invalid content", projectDir);
return;
}
if (!StringUtils.hasText(newName)) {
LOGGER.log(Level.FINE, "Project name change ignored in project {0}, new name is empty", projectDir);
return;
}
String name = (String) content.get(PythonPackage.FIELD_NAME);
if (Objects.equals(name, newName)) {
LOGGER.log(Level.FINE, "Project name change ignored in project {0}, new name same as current name in package.json", projectDir);
return;
}
final String projectName = PythonUtils.getProjectDisplayName(project);
if (preferences.isAskSyncEnabled()) {
Notifications.askSyncChanges(project, new Runnable() {
@Override
public void run() {
RP.post(new Runnable() {
@Override
public void run() {
changeProjectName(packageJson, newName, projectName, projectDir);
}
});
}
}, new Runnable() {
@Override
public void run() {
preferences.setSyncEnabled(false);
LOGGER.log(Level.FINE, "Project name change ignored in project {0}, cancelled by user", projectDir);
}
});
} else {
changeProjectName(packageJson, newName, projectName, projectDir);
}
}
use of org.apache.netbeans.modules.python4nb.editor.file.PythonPackage in project python4nb by ebresie.
the class PythonExecutable method getWorkDir.
private File getWorkDir() {
if (project == null) {
return FileUtils.TMP_DIR;
}
PythonPackage packageJson = PythonSupport.forProject(project).getPythonPackage();
if (packageJson.exists()) {
return new File(packageJson.getPath()).getParentFile();
}
File sourceRoot = PythonUtils.getSourceRoot(project);
if (sourceRoot != null) {
return sourceRoot;
}
File workDir = FileUtil.toFile(project.getProjectDirectory());
assert workDir != null : project.getProjectDirectory();
return workDir;
}
use of org.apache.netbeans.modules.python4nb.editor.file.PythonPackage in project python4nb by ebresie.
the class PythonPlatformProvider method detectPython.
private void detectPython(Project project) {
PythonSupport pythonSupport = PythonSupport.forProject(project);
PythonPreferences preferences = pythonSupport.getPreferences();
if (preferences.isEnabled()) {
// already enabled => noop
return;
}
PythonPackage packageJson = pythonSupport.getPythonPackage();
if (!packageJson.exists()) {
return;
}
Map<String, Object> content = packageJson.getContent();
if (content == null) {
// some error
return;
}
Object engines = content.get(PythonPackage.FIELD_ENGINES);
if (engines instanceof Map) {
@SuppressWarnings("unchecked") Map<String, Object> engines2 = (Map<String, Object>) engines;
if (engines2.containsKey(PythonPackage.FIELD_NODE)) {
Notifications.notifyPythonDetected(project);
}
}
}
Aggregations