From 24e8cf107729df571ddf6da695eeb6a08ea30b9f Mon Sep 17 00:00:00 2001 From: junichi11 Date: Sun, 8 Dec 2013 12:43:59 +0900 Subject: [PATCH] Fix NPE #72 - Add @CheckForNull to CakePhpModule.forPhpModule and CakePhpModule.getCakePhpDirectory methods - Check whether return value is null --- .../netbeans/CakePhpFrameworkProvider.java | 6 +- .../netbeans/CakePhpModuleExtender.java | 21 ++++- .../cakephp/netbeans/commands/CakeScript.java | 33 ++++--- .../editor/CakePhpEditorExtender.java | 10 +- .../editor/codegenerator/MBHCFieldInfo.java | 7 +- .../codegenerator/ValidateFiledInfo.java | 3 + .../hyperlink/CakePhpHyperlinkProvider.java | 3 + .../netbeans/module/CakePhp3ModuleImpl.java | 3 + .../netbeans/module/CakePhpModule.java | 11 ++- .../ui/actions/CakePhpBaseMenuAction.java | 91 ++++++++++--------- .../ui/actions/CakePhpGoToViewAction.java | 7 +- .../ui/actions/CheckDefaultAction.java | 10 +- .../netbeans/ui/actions/ClearCacheAction.java | 3 + .../ui/actions/FixNamespaceAction.java | 3 + .../ui/actions/RunBakeTestAction.java | 6 ++ .../gotos/statuses/CakePhpGoToStatus.java | 3 + .../statuses/CakePhpModelGoToStatus.java | 3 + .../ui/logicalview/MVCNodeFactory.java | 16 ++-- .../wizards/InstallPluginsWizardAction.java | 21 +++-- .../cakephp/netbeans/util/CakePhpUtils.java | 33 ++++--- .../cakephp/netbeans/util/CakeVersion.java | 27 ++++-- 21 files changed, 217 insertions(+), 103 deletions(-) diff --git a/src/org/cakephp/netbeans/CakePhpFrameworkProvider.java b/src/org/cakephp/netbeans/CakePhpFrameworkProvider.java index c0e42cc..571aef0 100644 --- a/src/org/cakephp/netbeans/CakePhpFrameworkProvider.java +++ b/src/org/cakephp/netbeans/CakePhpFrameworkProvider.java @@ -119,8 +119,12 @@ public boolean isInPhpModule(PhpModule phpModule) { @Override public File[] getConfigurationFiles(PhpModule phpModule) { // return all php files from app/config + CakePhpModule cakeModule = CakePhpModule.forPhpModule(phpModule); + if (cakeModule == null) { + return new File[0]; + } List configFiles = new LinkedList(); - FileObject config = CakePhpModule.forPhpModule(phpModule).getConfigDirectory(DIR_TYPE.APP); + FileObject config = cakeModule.getConfigDirectory(DIR_TYPE.APP); assert config != null : "app/config or app/Config not found for CakePHP project " + phpModule.getDisplayName(); if (config.isFolder()) { Enumeration children = config.getChildren(true); diff --git a/src/org/cakephp/netbeans/CakePhpModuleExtender.java b/src/org/cakephp/netbeans/CakePhpModuleExtender.java index 514c50a..08f7d0d 100755 --- a/src/org/cakephp/netbeans/CakePhpModuleExtender.java +++ b/src/org/cakephp/netbeans/CakePhpModuleExtender.java @@ -199,7 +199,10 @@ public Set extend(PhpModule phpModule) throws ExtendingException { CakePreferences.setEnabled(phpModule, Boolean.TRUE); CakePhpModule module = CakePhpModule.forPhpModule(phpModule); - FileObject config = module.getConfigFile(); + FileObject config = null; + if (module != null) { + config = module.getConfigFile(); + } if (config != null) { // change security string @@ -250,11 +253,14 @@ private void createDBFile(PhpModule phpModule) { }) private void createDatabaseFile(PhpModule phpModule) { // create database.php file - FileObject configDirectory; NewProjectConfigurationPanel p = getPanel(); NewProjectConfigurationDetailPanel detailPanel = NewProjectConfigurationDetailPanel.getDefault(); if (p.isDatabasePhp()) { - configDirectory = CakePhpModule.forPhpModule(phpModule).getConfigDirectory(CakePhpModule.DIR_TYPE.APP); + CakePhpModule cakeModule = CakePhpModule.forPhpModule(phpModule); + if (cakeModule == null) { + return; + } + FileObject configDirectory = cakeModule.getConfigDirectory(CakePhpModule.DIR_TYPE.APP); if (configDirectory == null) { LOGGER.log(Level.WARNING, Bundle.CakePhpModuleExtender_not_found_configdir()); return; @@ -701,7 +707,11 @@ private void createComposerJson(FileObject targetDirectory) throws IOException { * @param phpModule */ private void addComposerAutoload(PhpModule phpModule) { - FileObject configDirectory = CakePhpModule.forPhpModule(phpModule).getConfigDirectory(CakePhpModule.DIR_TYPE.APP); + CakePhpModule cakeModule = CakePhpModule.forPhpModule(phpModule); + if (cakeModule == null) { + return; + } + FileObject configDirectory = cakeModule.getConfigDirectory(CakePhpModule.DIR_TYPE.APP); if (configDirectory == null) { return; } @@ -747,6 +757,9 @@ private void addComposerAutoload(PhpModule phpModule) { */ private void changeCoreIncludePath(PhpModule phpModule, String appName) { CakePhpModule cakeModule = CakePhpModule.forPhpModule(phpModule); + if (cakeModule == null) { + return; + } FileObject webrootDirectory = cakeModule.getWebrootDirectory(DIR_TYPE.APP); if (webrootDirectory == null) { LOGGER.log(Level.WARNING, "Not found: webroot directory({0})", phpModule.getDisplayName()); diff --git a/src/org/cakephp/netbeans/commands/CakeScript.java b/src/org/cakephp/netbeans/commands/CakeScript.java index a531109..f535ba2 100755 --- a/src/org/cakephp/netbeans/commands/CakeScript.java +++ b/src/org/cakephp/netbeans/commands/CakeScript.java @@ -169,6 +169,9 @@ public static CakeScript forComposer(PhpModule phpModule) throws InvalidPhpExecu private static FileObject getPath(PhpModule phpModule) { CakePhpModule module = CakePhpModule.forPhpModule(phpModule); + if (module == null) { + return null; + } FileObject consoleDirectory = module.getConsoleDirectory(CakePhpModule.DIR_TYPE.APP); if (consoleDirectory == null) { LOGGER.log(Level.WARNING, "Not found " + SCRIPT_NAME); @@ -188,6 +191,9 @@ public static String getOptionsPath() { public void runCommand(PhpModule phpModule, List parameters, Runnable postExecution) { CakePhpModule cakeModule = CakePhpModule.forPhpModule(phpModule); + if (cakeModule == null) { + return; + } FileObject app = cakeModule.getDirectory(CakePhpModule.DIR_TYPE.APP); appParams.add("-app"); // NOI18N appParams.add(app.getPath()); @@ -465,10 +471,13 @@ private List getFrameworkCommandsInternalConsole(PhpModule php } String[] shells = {CORE_SHELLS_DIRECTORY, VENDORS_SHELLS_DIRECTORY, cakeModule.getAppName() + "/" + VENDORS_SHELLS_DIRECTORY}; - for (String shell : shells) { - FileObject shellFileObject = CakePhpModule.getCakePhpDirectory(phpModule).getFileObject(shell); - if (shellFileObject != null) { - shellDirs.add(shellFileObject); + FileObject cakePhpDirectory = CakePhpModule.getCakePhpDirectory(phpModule); + if (cakePhpDirectory != null) { + for (String shell : shells) { + FileObject shellFileObject = cakePhpDirectory.getFileObject(shell); + if (shellFileObject != null) { + shellDirs.add(shellFileObject); + } } } @@ -494,14 +503,16 @@ private List getFrameworkCommandsInternalConsole(PhpModule php private String getShellsPlace(PhpModule phpModule, FileObject shellDir) { String place = ""; // NOI18N CakePhpModule cakeModule = CakePhpModule.forPhpModule(phpModule); - String app = cakeModule.getAppName(); FileObject source = CakePhpModule.getCakePhpDirectory(phpModule); - if (source.getFileObject(CORE_SHELLS_DIRECTORY) == shellDir) { - place = "CORE"; // NOI18N - } else if (source.getFileObject(app + "/" + VENDORS_SHELLS_DIRECTORY) == shellDir) { - place = "APP VENDOR"; // NOI18N - } else if (source.getFileObject(VENDORS_SHELLS_DIRECTORY) == shellDir) { - place = "VENDOR"; // NOI18N + if (cakeModule != null && source != null) { + String app = cakeModule.getAppName(); + if (source.getFileObject(CORE_SHELLS_DIRECTORY) == shellDir) { + place = "CORE"; // NOI18N + } else if (source.getFileObject(app + "/" + VENDORS_SHELLS_DIRECTORY) == shellDir) { + place = "APP VENDOR"; // NOI18N + } else if (source.getFileObject(VENDORS_SHELLS_DIRECTORY) == shellDir) { + place = "VENDOR"; // NOI18N + } } return place; } diff --git a/src/org/cakephp/netbeans/editor/CakePhpEditorExtender.java b/src/org/cakephp/netbeans/editor/CakePhpEditorExtender.java index 0ea60f7..0ce2d6c 100644 --- a/src/org/cakephp/netbeans/editor/CakePhpEditorExtender.java +++ b/src/org/cakephp/netbeans/editor/CakePhpEditorExtender.java @@ -108,10 +108,12 @@ public List getElementsForCodeCompletion(FileObject fo) { // get AppController CakePhpModule cakeModule = CakePhpModule.forPhpModule(phpModule); - FileObject appController = cakeModule.getFile(DIR_TYPE.APP, CakePhpModule.FILE_TYPE.CONTROLLER, "App", null); - if (appController != null) { - for (PhpClass phpClass : parseFields(appController)) { - elements.add(new PhpVariable("$this", phpClass, fo, 0)); // NOI18N + if (cakeModule != null) { + FileObject appController = cakeModule.getFile(DIR_TYPE.APP, CakePhpModule.FILE_TYPE.CONTROLLER, "App", null); + if (appController != null) { + for (PhpClass phpClass : parseFields(appController)) { + elements.add(new PhpVariable("$this", phpClass, fo, 0)); // NOI18N + } } } diff --git a/src/org/cakephp/netbeans/editor/codegenerator/MBHCFieldInfo.java b/src/org/cakephp/netbeans/editor/codegenerator/MBHCFieldInfo.java index 41b0906..6939007 100644 --- a/src/org/cakephp/netbeans/editor/codegenerator/MBHCFieldInfo.java +++ b/src/org/cakephp/netbeans/editor/codegenerator/MBHCFieldInfo.java @@ -208,9 +208,14 @@ private List getAllCommonNames(Type type) { if (fileType == FILE_TYPE.NONE) { return Collections.emptyList(); } - List list = new ArrayList(); + PhpModule phpModule = getPhpModule(); CakePhpModule module = CakePhpModule.forPhpModule(phpModule); + if (module == null) { + return Collections.emptyList(); + } + + List list = new ArrayList(); EditorSupport editorSupport = Lookup.getDefault().lookup(EditorSupport.class); FileObject appDir = module.getDirectory(DIR_TYPE.APP, fileType, null); list.addAll(getCommonNames(appDir, editorSupport, null)); diff --git a/src/org/cakephp/netbeans/editor/codegenerator/ValidateFiledInfo.java b/src/org/cakephp/netbeans/editor/codegenerator/ValidateFiledInfo.java index efd6fbb..27b936b 100644 --- a/src/org/cakephp/netbeans/editor/codegenerator/ValidateFiledInfo.java +++ b/src/org/cakephp/netbeans/editor/codegenerator/ValidateFiledInfo.java @@ -126,6 +126,9 @@ private List getAllValidations() { List validations = new ArrayList(); PhpModule phpModule = getPhpModule(); CakePhpModule cakeModule = CakePhpModule.forPhpModule(phpModule); + if (cakeModule == null) { + return validations; + } FileObject coreDirectory = cakeModule.getDirectory(DIR_TYPE.CORE); if (coreDirectory == null) { return validations; diff --git a/src/org/cakephp/netbeans/editor/hyperlink/CakePhpHyperlinkProvider.java b/src/org/cakephp/netbeans/editor/hyperlink/CakePhpHyperlinkProvider.java index 65e6e8a..ef747a7 100644 --- a/src/org/cakephp/netbeans/editor/hyperlink/CakePhpHyperlinkProvider.java +++ b/src/org/cakephp/netbeans/editor/hyperlink/CakePhpHyperlinkProvider.java @@ -166,6 +166,9 @@ private FileObject getTargetFile(Document doc, String methodName) { */ private FileObject getElementFile(Document doc) { CakePhpModule module = CakePhpModule.forPhpModule(PhpModule.inferPhpModule()); + if (module == null) { + return null; + } FileObject elementFile = null; // check plugin : Plugin.element diff --git a/src/org/cakephp/netbeans/module/CakePhp3ModuleImpl.java b/src/org/cakephp/netbeans/module/CakePhp3ModuleImpl.java index 4c6066c..61cb0f7 100644 --- a/src/org/cakephp/netbeans/module/CakePhp3ModuleImpl.java +++ b/src/org/cakephp/netbeans/module/CakePhp3ModuleImpl.java @@ -255,6 +255,9 @@ private String getNamespace(FileObject target) { } FileObject parent = target.getParent(); CakePhpModule cakeModule = CakePhpModule.forPhpModule(phpModule); + if (cakeModule == null) { + return namespace; + } FileObject appDirectory = cakeModule.getDirectory(CakePhpModule.DIR_TYPE.APP); FileObject coreDirectory = cakeModule.getDirectory(CakePhpModule.DIR_TYPE.CORE); if (appDirectory == null || coreDirectory == null || parent == null) { diff --git a/src/org/cakephp/netbeans/module/CakePhpModule.java b/src/org/cakephp/netbeans/module/CakePhpModule.java index d7ae9b2..ba1cdf8 100644 --- a/src/org/cakephp/netbeans/module/CakePhpModule.java +++ b/src/org/cakephp/netbeans/module/CakePhpModule.java @@ -50,6 +50,7 @@ import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; import org.cakephp.netbeans.preferences.CakePreferences; +import org.netbeans.api.annotations.common.CheckForNull; import org.netbeans.modules.php.api.editor.PhpBaseElement; import org.netbeans.modules.php.api.phpmodule.PhpModule; import org.netbeans.modules.php.api.util.StringUtils; @@ -292,7 +293,11 @@ public String getCurrentPluginName(FileObject currentFile) { return impl.getCurrentPluginName(currentFile); } + @CheckForNull public static FileObject getCakePhpDirectory(PhpModule phpModule) { + if (phpModule == null) { + return null; + } FileObject sourceDirectory = phpModule.getSourceDirectory(); if (sourceDirectory == null) { return null; @@ -301,7 +306,7 @@ public static FileObject getCakePhpDirectory(PhpModule phpModule) { String cakePhpDirRelativePath = CakePreferences.getCakePhpDirPath(phpModule); FileObject cakePhpDirectory; if (!StringUtils.isEmpty(cakePhpDirRelativePath)) { - cakePhpDirectory = sourceDirectory.getFileObject(CakePreferences.getCakePhpDirPath(phpModule)); + cakePhpDirectory = sourceDirectory.getFileObject(cakePhpDirRelativePath); } else { cakePhpDirectory = phpModule.getSourceDirectory(); } @@ -435,10 +440,14 @@ public Set getAllPluginNames() { return impl.getAllPluginNames(); } + @CheckForNull public static CakePhpModule forPhpModule(PhpModule phpModule) { if (phpModule == null) { phpModule = PhpModule.inferPhpModule(); } + if (phpModule == null) { + return null; + } CakePhpModuleFactory factory = CakePhpModuleFactory.getInstance(); return factory.create(phpModule); } diff --git a/src/org/cakephp/netbeans/ui/actions/CakePhpBaseMenuAction.java b/src/org/cakephp/netbeans/ui/actions/CakePhpBaseMenuAction.java index d7f1eea..7650211 100644 --- a/src/org/cakephp/netbeans/ui/actions/CakePhpBaseMenuAction.java +++ b/src/org/cakephp/netbeans/ui/actions/CakePhpBaseMenuAction.java @@ -41,15 +41,6 @@ */ package org.cakephp.netbeans.ui.actions; -import org.cakephp.netbeans.ui.actions.gotos.CakePhpGoToModelsAction; -import org.cakephp.netbeans.ui.actions.gotos.CakePhpGoToFixturesAction; -import org.cakephp.netbeans.ui.actions.gotos.CakePhpGoToSmartAction; -import org.cakephp.netbeans.ui.actions.gotos.CakePhpGoToBehaviorsAction; -import org.cakephp.netbeans.ui.actions.gotos.CakePhpGoToTestCasesAction; -import org.cakephp.netbeans.ui.actions.gotos.CakePhpGoToHelpersAction; -import org.cakephp.netbeans.ui.actions.gotos.CakePhpGoToViewsAction; -import org.cakephp.netbeans.ui.actions.gotos.CakePhpGoToComponentsAction; -import org.cakephp.netbeans.ui.actions.gotos.CakePhpGoToControllersAction; import java.awt.Component; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; @@ -59,6 +50,15 @@ import javax.swing.JPopupMenu; import javax.swing.text.StyledDocument; import org.cakephp.netbeans.CakePhp; +import org.cakephp.netbeans.ui.actions.gotos.CakePhpGoToBehaviorsAction; +import org.cakephp.netbeans.ui.actions.gotos.CakePhpGoToComponentsAction; +import org.cakephp.netbeans.ui.actions.gotos.CakePhpGoToControllersAction; +import org.cakephp.netbeans.ui.actions.gotos.CakePhpGoToFixturesAction; +import org.cakephp.netbeans.ui.actions.gotos.CakePhpGoToHelpersAction; +import org.cakephp.netbeans.ui.actions.gotos.CakePhpGoToModelsAction; +import org.cakephp.netbeans.ui.actions.gotos.CakePhpGoToSmartAction; +import org.cakephp.netbeans.ui.actions.gotos.CakePhpGoToTestCasesAction; +import org.cakephp.netbeans.ui.actions.gotos.CakePhpGoToViewsAction; import org.cakephp.netbeans.util.CakePhpUtils; import org.cakephp.netbeans.util.CakeVersion; import org.netbeans.modules.php.api.phpmodule.PhpModule; @@ -225,48 +225,51 @@ private class CakeToolbarPresenter extends JButton { private JPopupMenu popup; CakeToolbarPresenter() { - this.setIcon(ImageUtilities.loadImageIcon(CakePhp.CAKE_ICON_16, true)); - this.popup = new JPopupMenu(); + PhpModule phpModule = PhpModule.inferPhpModule(); + if (CakePhpUtils.isCakePHP(phpModule)) { + this.setIcon(ImageUtilities.loadImageIcon(CakePhp.CAKE_ICON_16, true)); + this.popup = new JPopupMenu(); - // add actions - // smart go to - popup.add(CakePhpGoToSmartAction.getInstance()); - popup.add(CakePhpGoToTestCasesAction.getInstance()); - popup.add(CakePhpGoToControllersAction.getInstance()); - popup.add(CakePhpGoToViewsAction.getInstance()); - popup.add(CakePhpGoToModelsAction.getInstance()); - popup.add(CakePhpGoToComponentsAction.getInstance()); - popup.add(CakePhpGoToHelpersAction.getInstance()); - popup.add(CakePhpGoToBehaviorsAction.getInstance()); - popup.add(CakePhpGoToFixturesAction.getInstance()); + // add actions + // smart go to + popup.add(CakePhpGoToSmartAction.getInstance()); + popup.add(CakePhpGoToTestCasesAction.getInstance()); + popup.add(CakePhpGoToControllersAction.getInstance()); + popup.add(CakePhpGoToViewsAction.getInstance()); + popup.add(CakePhpGoToModelsAction.getInstance()); + popup.add(CakePhpGoToComponentsAction.getInstance()); + popup.add(CakePhpGoToHelpersAction.getInstance()); + popup.add(CakePhpGoToBehaviorsAction.getInstance()); + popup.add(CakePhpGoToFixturesAction.getInstance()); - // format - popup.add(FormatPlusAction.getInstance()); + // format + popup.add(FormatPlusAction.getInstance()); - // create test - DataObject dataObject = getDataObject(); - if (dataObject != null) { - popup.add(new RunBakeTestAction(dataObject)); - } + // create test + DataObject dataObject = getDataObject(); + if (dataObject != null) { + popup.add(new RunBakeTestAction(dataObject)); + } - // run action - popup.add(RunActionAction.getInstance()); + // run action + popup.add(RunActionAction.getInstance()); - // fix namespace - if (CakeVersion.getInstance(PhpModule.inferPhpModule()).isCakePhp(3)) { - FileObject fileObject = getFileObject(); - if (fileObject != null && !CakePhpUtils.isCtpFile(fileObject)) { - popup.add(new FixNamespaceAction()); + // fix namespace + if (phpModule != null && CakeVersion.getInstance(phpModule).isCakePhp(3)) { + FileObject fileObject = getFileObject(); + if (fileObject != null && !CakePhpUtils.isCtpFile(fileObject)) { + popup.add(new FixNamespaceAction()); + } } - } - // add listener - this.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - CakeToolbarPresenter.this.popup.show(CakeToolbarPresenter.this, 0, CakeToolbarPresenter.this.getHeight()); - } - }); + // add listener + this.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + CakeToolbarPresenter.this.popup.show(CakeToolbarPresenter.this, 0, CakeToolbarPresenter.this.getHeight()); + } + }); + } } } } diff --git a/src/org/cakephp/netbeans/ui/actions/CakePhpGoToViewAction.java b/src/org/cakephp/netbeans/ui/actions/CakePhpGoToViewAction.java index f4e6db9..6f5cef2 100755 --- a/src/org/cakephp/netbeans/ui/actions/CakePhpGoToViewAction.java +++ b/src/org/cakephp/netbeans/ui/actions/CakePhpGoToViewAction.java @@ -52,10 +52,10 @@ import javax.swing.text.BadLocationException; import javax.swing.text.JTextComponent; import org.cakephp.netbeans.preferences.CakePreferences; -import org.cakephp.netbeans.ui.actions.gotos.items.GoToItem; import org.cakephp.netbeans.ui.GoToPopup; -import org.cakephp.netbeans.ui.actions.gotos.items.GoToViewItem; import org.cakephp.netbeans.ui.PopupUtil; +import org.cakephp.netbeans.ui.actions.gotos.items.GoToItem; +import org.cakephp.netbeans.ui.actions.gotos.items.GoToViewItem; import org.cakephp.netbeans.util.CakePhpUtils; import org.cakephp.netbeans.util.CakeVersion; import org.netbeans.api.editor.EditorRegistry; @@ -110,6 +110,9 @@ public boolean goToView() { // support for only app view file // TODO support for theme? PhpModule phpModule = PhpModule.forFileObject(controller); + if (phpModule == null) { + return false; + } if (CakePreferences.getAutoCreateView(phpModule)) { try { view = CakePhpUtils.createView(controller, phpElement); diff --git a/src/org/cakephp/netbeans/ui/actions/CheckDefaultAction.java b/src/org/cakephp/netbeans/ui/actions/CheckDefaultAction.java index 24f672c..c560db9 100644 --- a/src/org/cakephp/netbeans/ui/actions/CheckDefaultAction.java +++ b/src/org/cakephp/netbeans/ui/actions/CheckDefaultAction.java @@ -99,6 +99,9 @@ protected void actionPerformed(PhpModule phpModule) { CheckDefaultPanel verifyPanel = getPanel(); verifyPanel.reset(); CakePhpModule module = CakePhpModule.forPhpModule(phpModule); + if (module == null) { + return; + } FileObject webroot = module.getWebrootDirectory(CakePhpModule.DIR_TYPE.APP); // favicon.ico @@ -150,7 +153,6 @@ protected void actionPerformed(PhpModule phpModule) { } // Config/core.php :debug level - // open panel verifyPanel.showDialog(); } @@ -167,6 +169,9 @@ private boolean isChangedFavicon(PhpModule phpModule) { assert favicon != null; FileObject targetFavicon = null; CakePhpModule cakeModule = CakePhpModule.forPhpModule(phpModule); + if (cakeModule == null) { + return false; + } FileObject webrootDirectory = cakeModule.getWebrootDirectory(CakePhpModule.DIR_TYPE.APP); if (webrootDirectory != null) { targetFavicon = webrootDirectory.getFileObject("favicon.ico"); // NOI18N @@ -223,6 +228,9 @@ private boolean existFile(FileObject webroot, String path) { private boolean isChangedSessionName(PhpModule phpModule) { FileObject config = null; CakePhpModule cakeModule = CakePhpModule.forPhpModule(phpModule); + if (cakeModule == null) { + return false; + } // CakePHP 1.x, 2.x core.php // CakePHP 3.x session.php diff --git a/src/org/cakephp/netbeans/ui/actions/ClearCacheAction.java b/src/org/cakephp/netbeans/ui/actions/ClearCacheAction.java index cf5270b..aa0f190 100755 --- a/src/org/cakephp/netbeans/ui/actions/ClearCacheAction.java +++ b/src/org/cakephp/netbeans/ui/actions/ClearCacheAction.java @@ -111,6 +111,9 @@ public void actionPerformed(PhpModule phpModule) { */ private FileObject getTempCacheDirectory(PhpModule phpModule) { CakePhpModule module = CakePhpModule.forPhpModule(phpModule); + if (module == null) { + return null; + } FileObject tmpDirectory = module.getDirectory(DIR_TYPE.APP, FILE_TYPE.TMP, null); if (tmpDirectory == null) { return null; diff --git a/src/org/cakephp/netbeans/ui/actions/FixNamespaceAction.java b/src/org/cakephp/netbeans/ui/actions/FixNamespaceAction.java index b61e78a..a016cd9 100644 --- a/src/org/cakephp/netbeans/ui/actions/FixNamespaceAction.java +++ b/src/org/cakephp/netbeans/ui/actions/FixNamespaceAction.java @@ -148,6 +148,9 @@ private String getNamespace(FileObject target) { } FileObject parent = target.getParent(); CakePhpModule cakeModule = CakePhpModule.forPhpModule(phpModule); + if (cakeModule == null) { + return namespace; + } FileObject appDirectory = cakeModule.getDirectory(CakePhpModule.DIR_TYPE.APP); FileObject coreDirectory = cakeModule.getDirectory(CakePhpModule.DIR_TYPE.CORE); if (appDirectory == null || coreDirectory == null || parent == null) { diff --git a/src/org/cakephp/netbeans/ui/actions/RunBakeTestAction.java b/src/org/cakephp/netbeans/ui/actions/RunBakeTestAction.java index 65cb814..b446e10 100644 --- a/src/org/cakephp/netbeans/ui/actions/RunBakeTestAction.java +++ b/src/org/cakephp/netbeans/ui/actions/RunBakeTestAction.java @@ -202,6 +202,9 @@ private DIR_TYPE getDirType() { private String getPluginName(DIR_TYPE type) { if (type == DIR_TYPE.APP_PLUGIN || type == DIR_TYPE.PLUGIN) { CakePhpModule module = CakePhpModule.forPhpModule(phpModule); + if (module == null) { + return null; + } String path = module.getDirectory(type).getPath(); String targetPath = targetFile.getPath(); targetPath = targetPath.replace(path + "/", ""); // NOI18N @@ -215,6 +218,9 @@ private String getPluginName(DIR_TYPE type) { private boolean existTest() { CakePhpModule cakeModule = CakePhpModule.forPhpModule(phpModule); + if (cakeModule == null) { + return false; + } DIR_TYPE dirType = getDirType(); FILE_TYPE fileType = getFileType(); String pluginName = getPluginName(dirType); diff --git a/src/org/cakephp/netbeans/ui/actions/gotos/statuses/CakePhpGoToStatus.java b/src/org/cakephp/netbeans/ui/actions/gotos/statuses/CakePhpGoToStatus.java index 5dde2de..0516ab7 100644 --- a/src/org/cakephp/netbeans/ui/actions/gotos/statuses/CakePhpGoToStatus.java +++ b/src/org/cakephp/netbeans/ui/actions/gotos/statuses/CakePhpGoToStatus.java @@ -414,6 +414,9 @@ private FileObject getAppDirectory(FILE_TYPE fileType) { return null; } CakePhpModule cakeModule = CakePhpModule.forPhpModule(phpModule); + if (cakeModule == null) { + return null; + } return cakeModule.getDirectory(DIR_TYPE.APP, fileType, null); } diff --git a/src/org/cakephp/netbeans/ui/actions/gotos/statuses/CakePhpModelGoToStatus.java b/src/org/cakephp/netbeans/ui/actions/gotos/statuses/CakePhpModelGoToStatus.java index 7a6ae85..ba35498 100644 --- a/src/org/cakephp/netbeans/ui/actions/gotos/statuses/CakePhpModelGoToStatus.java +++ b/src/org/cakephp/netbeans/ui/actions/gotos/statuses/CakePhpModelGoToStatus.java @@ -164,6 +164,9 @@ public List getControllers() { // XXX more search? // only app directory CakePhpModule cakeModule = CakePhpModule.forPhpModule(getPhpModule()); + if (cakeModule == null) { + return Collections.emptyList(); + } FileObject controllerDirectory = cakeModule.getControllerDirectory(CakePhpModule.DIR_TYPE.APP); // scan controllers diff --git a/src/org/cakephp/netbeans/ui/logicalview/MVCNodeFactory.java b/src/org/cakephp/netbeans/ui/logicalview/MVCNodeFactory.java index a852295..a3deb35 100644 --- a/src/org/cakephp/netbeans/ui/logicalview/MVCNodeFactory.java +++ b/src/org/cakephp/netbeans/ui/logicalview/MVCNodeFactory.java @@ -88,13 +88,15 @@ public MVCNodeList(PhpModule phpModule) { public List keys() { if (CakePhpUtils.isCakePHP(phpModule)) { CakePhpModule cakeModule = CakePhpModule.forPhpModule(phpModule); - List list = new ArrayList(); - list.add(cakeModule.getControllerDirectory(DIR_TYPE.APP)); - list.add(cakeModule.getModelDirectory(DIR_TYPE.APP)); - list.add(cakeModule.getViewDirectory(DIR_TYPE.APP)); - list.add(cakeModule.getHelperDirectory(DIR_TYPE.APP)); - list.add(cakeModule.getWebrootDirectory(DIR_TYPE.APP)); - return list; + if (cakeModule != null) { + List list = new ArrayList(); + list.add(cakeModule.getControllerDirectory(DIR_TYPE.APP)); + list.add(cakeModule.getModelDirectory(DIR_TYPE.APP)); + list.add(cakeModule.getViewDirectory(DIR_TYPE.APP)); + list.add(cakeModule.getHelperDirectory(DIR_TYPE.APP)); + list.add(cakeModule.getWebrootDirectory(DIR_TYPE.APP)); + return list; + } } return Collections.emptyList(); } diff --git a/src/org/cakephp/netbeans/ui/wizards/InstallPluginsWizardAction.java b/src/org/cakephp/netbeans/ui/wizards/InstallPluginsWizardAction.java index ce821c8..288141a 100755 --- a/src/org/cakephp/netbeans/ui/wizards/InstallPluginsWizardAction.java +++ b/src/org/cakephp/netbeans/ui/wizards/InstallPluginsWizardAction.java @@ -57,7 +57,10 @@ import org.cakephp.netbeans.util.CakePhpFileUtils; import org.netbeans.modules.php.api.phpmodule.PhpModule; import org.netbeans.modules.php.spi.framework.actions.BaseAction; -import org.openide.*; +import org.openide.DialogDescriptor; +import org.openide.DialogDisplayer; +import org.openide.NotifyDescriptor; +import org.openide.WizardDescriptor; import org.openide.WizardDescriptor.Panel; import org.openide.awt.ActionID; import org.openide.awt.ActionRegistration; @@ -122,14 +125,20 @@ protected void actionPerformed(PhpModule pm) { Panel panel = (InstallPluginsWizardPanel) panels.get(0); InstallPluginsVisualPanel component = (InstallPluginsVisualPanel) panel.getComponent(); - String installPath = component.getInstallPathTextField(); - CakePhpModule module = CakePhpModule.forPhpModule(pm); + final String installPath = component.getInstallPathTextField(); FileObject cakePhpDirectory = CakePhpModule.getCakePhpDirectory(pm); + if (cakePhpDirectory == null) { + return; + } final FileObject installDirectory = cakePhpDirectory.getFileObject(installPath); - NotifyDescriptor descriptor = null; if (installDirectory == null) { - descriptor = new NotifyDescriptor.Message(installPath + " dosen't exist.", NotifyDescriptor.ERROR_MESSAGE); - DialogDisplayer.getDefault().notifyLater(descriptor); + SwingUtilities.invokeLater(new Runnable() { + @Override + public void run() { + NotifyDescriptor descriptor = new NotifyDescriptor.Message(installPath + " dosen't exist.", NotifyDescriptor.ERROR_MESSAGE); + DialogDisplayer.getDefault().notifyLater(descriptor); + } + }); return; } final List plugins = component.getCakePhpPluginList(); diff --git a/src/org/cakephp/netbeans/util/CakePhpUtils.java b/src/org/cakephp/netbeans/util/CakePhpUtils.java index 796b50a..b37605e 100644 --- a/src/org/cakephp/netbeans/util/CakePhpUtils.java +++ b/src/org/cakephp/netbeans/util/CakePhpUtils.java @@ -85,7 +85,8 @@ public static boolean isCakePHP(PhpModule phpModule) { public static boolean isView(FileObject fo) { PhpModule phpModule = PhpModule.forFileObject(fo); - return CakePhpModule.forPhpModule(phpModule).isView(fo); + CakePhpModule cakeModule = CakePhpModule.forPhpModule(phpModule); + return cakeModule == null ? false : cakeModule.isView(fo); } public static FileObject getView(FileObject controller, PhpBaseElement phpElement) { @@ -98,7 +99,8 @@ public static FileObject getView(FileObject controller, PhpBaseElement phpElemen public static FileObject getView(FileObject controller, String viewName) { PhpModule phpModule = PhpModule.forFileObject(controller); - return CakePhpModule.forPhpModule(phpModule).getView(controller, viewName); + CakePhpModule cakeModule = CakePhpModule.forPhpModule(phpModule); + return cakeModule == null ? null : cakeModule.getView(controller, viewName); } public static FileObject getView(FileObject controller, PhpBaseElement phpElement, FileObject theme) { @@ -111,7 +113,8 @@ public static FileObject getView(FileObject controller, PhpBaseElement phpElemen public static FileObject getView(FileObject controller, String viewName, FileObject theme) { PhpModule phpModule = PhpModule.forFileObject(controller); - return CakePhpModule.forPhpModule(phpModule).getView(controller, viewName, theme); + CakePhpModule cakeModule = CakePhpModule.forPhpModule(phpModule); + return cakeModule == null ? null : cakeModule.getView(controller, viewName, theme); } public static boolean isControllerName(String name) { @@ -123,12 +126,14 @@ public static boolean isController(FileObject fo) { return false; } PhpModule phpModule = PhpModule.forFileObject(fo); - return CakePhpModule.forPhpModule(phpModule).isController(fo); + CakePhpModule cakeModule = CakePhpModule.forPhpModule(phpModule); + return cakeModule == null ? false : cakeModule.isController(fo); } public static FileObject getController(FileObject view) { PhpModule phpModule = PhpModule.forFileObject(view); - return CakePhpModule.forPhpModule(phpModule).getController(view); + CakePhpModule cakeModule = CakePhpModule.forPhpModule(phpModule); + return cakeModule == null ? null : cakeModule.getController(view); } /** @@ -170,7 +175,8 @@ public static boolean isComponent(FileObject fo) { return false; } PhpModule phpModule = PhpModule.forFileObject(fo); - return CakePhpModule.forPhpModule(phpModule).isComponent(fo); + CakePhpModule cakeModule = CakePhpModule.forPhpModule(phpModule); + return cakeModule == null ? false : cakeModule.isComponent(fo); } /** @@ -184,7 +190,8 @@ public static boolean isHelper(FileObject fo) { return false; } PhpModule phpModule = PhpModule.forFileObject(fo); - return CakePhpModule.forPhpModule(phpModule).isHelper(fo); + CakePhpModule cakeModule = CakePhpModule.forPhpModule(phpModule); + return cakeModule == null ? false : cakeModule.isHelper(fo); } /** @@ -198,7 +205,8 @@ public static boolean isModel(FileObject fo) { return false; } PhpModule phpModule = PhpModule.forFileObject(fo); - return CakePhpModule.forPhpModule(phpModule).isModel(fo); + CakePhpModule cakeModule = CakePhpModule.forPhpModule(phpModule); + return cakeModule == null ? false : cakeModule.isModel(fo); } /** @@ -209,7 +217,8 @@ public static boolean isModel(FileObject fo) { */ public static boolean isBehavior(FileObject fo) { PhpModule phpModule = PhpModule.forFileObject(fo); - return CakePhpModule.forPhpModule(phpModule).isBehavior(fo); + CakePhpModule cakeModule = CakePhpModule.forPhpModule(phpModule); + return cakeModule == null ? false : cakeModule.isBehavior(fo); } public static String getActionName(FileObject view) { @@ -261,7 +270,8 @@ private static String toUnderscore(String input) { public static FileObject createView(FileObject controller, PhpBaseElement phpElement) throws IOException { PhpModule phpModule = PhpModule.forFileObject(controller); - return CakePhpModule.forPhpModule(phpModule).createView(controller, phpElement); + CakePhpModule cakeModule = CakePhpModule.forPhpModule(phpModule); + return cakeModule == null ? null : cakeModule.createView(controller, phpElement); } public static String getCamelCaseName(String name) { @@ -324,7 +334,8 @@ public static int getActionMethodOffset(FileObject controller, FileObject view) */ public static boolean isTest(FileObject fo) { PhpModule phpModule = PhpModule.forFileObject(fo); - return CakePhpModule.forPhpModule(phpModule).isTest(fo); + CakePhpModule cakeModule = CakePhpModule.forPhpModule(phpModule); + return cakeModule == null ? false : cakeModule.isTest(fo); } /** diff --git a/src/org/cakephp/netbeans/util/CakeVersion.java b/src/org/cakephp/netbeans/util/CakeVersion.java index e5f12c5..9554a59 100755 --- a/src/org/cakephp/netbeans/util/CakeVersion.java +++ b/src/org/cakephp/netbeans/util/CakeVersion.java @@ -69,6 +69,11 @@ public class CakeVersion { private static final Logger LOGGER = Logger.getLogger(CakeVersion.class.getName()); private CakeVersion(PhpModule pm) { + if (pm == null) { + setErrorVersion(); + return; + } + String[] split = getCakePhpVersionSplit(pm); if (split != null) { int length = split.length; @@ -86,23 +91,19 @@ private CakeVersion(PhpModule pm) { } if (length <= 0) { - major = -1; - minor = -1; - revision = -1; - notStable = ""; // NOI18N + setErrorVersion(); } CakeVersion.pm = pm; } else { - FileObject cakephpDirectory = CakePhpModule.getCakePhpDirectory(pm); - if (cakephpDirectory != null) { - FileObject cake = CakePhpModule.getCakePhpDirectory(pm).getFileObject("cake"); // NOI18N + FileObject cakePhpDirectory = CakePhpModule.getCakePhpDirectory(pm); + if (cakePhpDirectory != null) { + FileObject cake = cakePhpDirectory.getFileObject("cake"); // NOI18N if (cake != null) { major = 1; minor = -1; revision = -1; notStable = ""; // NOI18N } else { - FileObject cakePhpDirectory = CakePhpModule.getCakePhpDirectory(pm); cake = cakePhpDirectory.getFileObject("lib/Cake"); // NOI18N // installing with Composer @@ -111,7 +112,7 @@ private CakeVersion(PhpModule pm) { } if (cake != null) { - FileObject app = CakePhpModule.getCakePhpDirectory(pm).getFileObject("App"); // NOI18N + FileObject app = cakePhpDirectory.getFileObject("App"); // NOI18N if (app != null) { major = 3; } else { @@ -130,7 +131,6 @@ private CakeVersion(PhpModule pm) { } else { CakeVersion.pm = null; } - } } @@ -193,6 +193,13 @@ public boolean isCakePhp(int majorVersion) { return major == majorVersion; } + private void setErrorVersion() { + this.major = -1; + this.minor = -1; + this.revision = -1; + this.notStable = ""; // NOI18N + } + /** * Get CakePHP version. *