org.netbeans.modules.php.api.phpmodule.PhpModule Java Examples

The following examples show how to use org.netbeans.modules.php.api.phpmodule.PhpModule. 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: SymfonyPhpFrameworkProvider.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public PhpModuleProperties getPhpModuleProperties(PhpModule phpModule) {
    PhpModuleProperties properties = new PhpModuleProperties();
    FileObject sourceDirectory = phpModule.getSourceDirectory();
    if (sourceDirectory == null) {
        // broken project
        return properties;
    }
    FileObject web = sourceDirectory.getFileObject("web"); // NOI18N
    if (web != null) {
        properties = properties.setWebRoot(web);
    }
    SymfonyVersion symfonyVersion = SymfonyVersion.forPhpModule(phpModule);
    if (symfonyVersion == null) {
        // #267818 - incorrect symfony installer file
        LOGGER.log(Level.INFO, "No Symfony version detected for project {0} - perhaps invalid Symfony installer selected in IDE Options?", phpModule.getDisplayName());
    } else {
        FileObject tests = symfonyVersion.getTests();
        if (tests != null) {
            properties = properties.setTests(tests);
        }
    }
    return properties;
}
 
Example #2
Source File: CompositePanelProviderImpl.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private void fillFrameworkCategories(PhpProject project) {
    frameworkCategories.clear();

    final PhpModule phpModule = project.getPhpModule();
    int i = 0;
    for (PhpFrameworkProvider frameworkProvider : PhpFrameworks.getFrameworks()) {
        PhpModuleCustomizerExtender extender = frameworkProvider.createPhpModuleCustomizerExtender(phpModule);
        if (extender != null) {
            String categoryName = extender.getDisplayName(phpModule);
            if (categoryName == null) {
                categoryName = frameworkProvider.getName();
            }
            ProjectCustomizer.Category category = ProjectCustomizer.Category.create(
                    FRAMEWORKS + i++,
                    categoryName,
                    null,
                    (ProjectCustomizer.Category[]) null);
            frameworkCategories.put(category, extender);
        }
    }
}
 
Example #3
Source File: BrowseFolderPanel.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public static String open(PhpModule phpModule) {
    String info = NbBundle.getMessage(BrowseFolderPanel.class, "LBL_SelectDocFolder", phpModule.getDisplayName());
    BrowseFolderPanel panel = new BrowseFolderPanel(info, phpModule);
    panel.dialogDescriptor = new DialogDescriptor(
            panel,
            NbBundle.getMessage(BrowseFolderPanel.class, "LBL_SelectDir"),
            true,
            DialogDescriptor.OK_CANCEL_OPTION,
            DialogDescriptor.OK_OPTION,
            null);
    panel.notificationLineSupport = panel.dialogDescriptor.createNotificationLineSupport();
    panel.notificationLineSupport.setInformationMessage(info);
    panel.dialogDescriptor.setValid(false);
    if (DialogDisplayer.getDefault().notify(panel.dialogDescriptor) == DialogDescriptor.OK_OPTION) {
        return panel.getDocFolder();
    }
    return null;
}
 
Example #4
Source File: Codecept.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@CheckForNull
private File getWorkingDirectory(PhpModule phpModule) {
    assert phpModule != null;
    List<FileObject> codeceptionYmls = getCodeceptionYmls(phpModule);
    if (!codeceptionYmls.isEmpty()) {
        FileObject parent = codeceptionYmls.get(0).getParent();
        if (parent != null) {
            return FileUtil.toFile(parent);
        }
    }
    FileObject sourceDirectory = phpModule.getSourceDirectory();
    if (sourceDirectory != null) {
        return FileUtil.toFile(sourceDirectory);
    }
    return null;
}
 
Example #5
Source File: BrowseFolderPanel.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@NbBundle.Messages({
    "# {0} - project name",
    "BrowseFolderPanel.docFolder.select=Select a directory for documentation for {0}",
    "BrowseFolderPanel.dir.select=Select a directory"
})
public static String open(PhpModule phpModule) {
    String info = Bundle.BrowseFolderPanel_docFolder_select(phpModule.getDisplayName());
    BrowseFolderPanel panel = new BrowseFolderPanel(info, phpModule);
    panel.dialogDescriptor = new DialogDescriptor(
            panel,
            Bundle.BrowseFolderPanel_dir_select(),
            true,
            DialogDescriptor.OK_CANCEL_OPTION,
            DialogDescriptor.OK_OPTION,
            null);
    panel.notificationLineSupport = panel.dialogDescriptor.createNotificationLineSupport();
    panel.notificationLineSupport.setInformationMessage(info);
    panel.dialogDescriptor.setValid(false);
    if (DialogDisplayer.getDefault().notify(panel.dialogDescriptor) == DialogDescriptor.OK_OPTION) {
        return panel.getDocFolder();
    }
    return null;
}
 
Example #6
Source File: CakePHP3ModuleCustomizerExtender.java    From cakephp3-netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public EnumSet<Change> save(PhpModule phpModule) {
    CakePHP3CustomizerPanel p = getPanel();
    CakePHP3Preferences.setEnabled(phpModule, p.isCakePHP3Enabled());
    CakePHP3Preferences.setRootPath(phpModule, p.getRoot());
    CakePHP3Preferences.setSrcName(phpModule, p.getSrc());
    CakePHP3Preferences.setNamespace(phpModule, p.getNamespace());
    CakePHP3Preferences.setWWWRootPath(phpModule, p.getWWWRoot());
    CakePHP3Preferences.setCssUrl(phpModule, p.getCss());
    CakePHP3Preferences.setImageUrl(phpModule, p.getImg());
    CakePHP3Preferences.setJsUrl(phpModule, p.getJs());
    CakePHP3Preferences.setDotcakePath(phpModule, p.getDotcakePath());
    // release CakePHP3Module
    CakePHP3ModuleFactory.getInstance().remove(phpModule);
    return EnumSet.of(Change.FRAMEWORK_CHANGE);
}
 
Example #7
Source File: Nette2PhpModuleExtender.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public Set<FileObject> extend(PhpModule phpModule) throws ExtendingException {
    Set<FileObject> result = new HashSet<>();
    FileObject sourceDirectory = phpModule.getSourceDirectory();
    if (sourceDirectory != null) {
        String projectDirectory = sourceDirectory.getPath();
        FileUtils.copyDirectory(new File(Nette2Options.getInstance().getSandbox()), new File(projectDirectory));
        File netteLibsDirectory = new File(projectDirectory, Constants.NETTE_LIBS_DIR);
        if (isValidNetteLibsDir(netteLibsDirectory) && getPanel().isCopyNetteCheckboxSelected()) {
            FileUtils.copyDirectory(new File(Nette2Options.getInstance().getNetteDirectory()), netteLibsDirectory);
        }
        FileObject bootstrap = FileUtil.toFileObject(new File(projectDirectory, Constants.COMMON_BOOTSTRAP_PATH));
        if (bootstrap != null && !bootstrap.isFolder() && bootstrap.isValid()) {
            result.add(bootstrap);
        }
        FileObject tempDir = sourceDirectory.getFileObject(Constants.NETTE_TEMP_DIR);
        if (tempDir != null) {
            FileUtils.chmod777Recursively(tempDir);
        }
    }
    return result;
}
 
Example #8
Source File: TemplateStatus.java    From cakephp3-netbeans with Apache License 2.0 6 votes vote down vote up
private void addElements(Set<String> elementPaths, PhpModule phpModule, FileObject fileObject) {
    CakePHP3Module cakeModule = CakePHP3Module.forPhpModule(phpModule);
    Base base = cakeModule.getBase(fileObject);
    for (String elementPath : elementPaths) {
        Pair<String, String> pluginElement = ModuleUtils.pluginSplit(elementPath);
        String pluginName = pluginElement.first();
        String relativePath = cakeModule.toPhpFileName(Category.ELEMENT, pluginElement.second());
        if (!StringUtils.isEmpty(pluginName)) {
            base = Base.PLUGIN;
        }
        FileObject element = cakeModule.getFile(base, Category.ELEMENT, relativePath, pluginName);
        // fallback core
        if (element == null && StringUtils.isEmpty(pluginName)) {
            element = cakeModule.getFile(Base.CORE, Category.ELEMENT, elementPath, pluginName);
        }
        if (element == null) {
            continue;
        }
        elements.add(GoToItemFactory.create(Category.ELEMENT, element, DEFAULT_OFFSET));
    }
}
 
Example #9
Source File: CustomizerDocumentation.java    From netbeans with Apache License 2.0 5 votes vote down vote up
CustomizerDocumentation(ProjectCustomizer.Category category, PhpModule phpModule) {
    assert EventQueue.isDispatchThread();
    assert category != null;
    assert phpModule != null;

    this.category = category;
    this.phpModule = phpModule;
    originalProvider = getOriginalProvider();

    providerPanels = createProviderPanels();

    initComponents();
    init();
}
 
Example #10
Source File: GenerateDocumentationActionFactory.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public Action createContextAwareInstance(Lookup actionContext) {
    Collection<? extends Project> projects = actionContext.lookupAll(Project.class);
    if (projects.size() != 1) {
        return this;
    }
    Project project = projects.iterator().next().getLookup().lookup(Project.class);
    if (project == null) {
        return this;
    }
    List<PhpDocumentationProvider> docProviders = PhpDocumentations.getDocumentations();
    if (docProviders.isEmpty()) {
        return this;
    }

    PhpModule phpModule = PhpModule.Factory.lookupPhpModule(project);
    if (phpModule == null) {
        return this;
    }
    List<PhpDocumentationProvider> projectDocProviders = new ArrayList<>(docProviders.size());
    for (PhpDocumentationProvider docProvider : docProviders) {
        if (docProvider.isInPhpModule(phpModule)) {
            projectDocProviders.add(docProvider);
        }
    }
    if (projectDocProviders.isEmpty()) {
        // no provider selected yet -> show all
        projectDocProviders.addAll(docProviders);
    }
    if (projectDocProviders.size() == 1) {
        return new PhpDocAction(phpModule, projectDocProviders.get(0));
    }
    return new DocumentationMenu(phpModule, projectDocProviders);
}
 
Example #11
Source File: ApiGenPanel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
ApiGenPanel(PhpModule phpModule) {
    assert EventQueue.isDispatchThread();
    assert phpModule != null;

    this.phpModule = phpModule;

    initComponents();
    init();
}
 
Example #12
Source File: PhpDocPreferences.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public static String getPhpDocTarget(PhpModule phpModule, boolean showPanel) {
    Preferences preferences = getPreferences(phpModule);
    String phpDocTarget = preferences.get(PHPDOC_TARGET, null);
    if ((phpDocTarget == null || phpDocTarget.isEmpty()) && showPanel) {
        phpDocTarget = BrowseFolderPanel.open(phpModule);
        if (phpDocTarget == null) {
            // cancelled
            return null;
        }
        setPhpDocTarget(phpModule, phpDocTarget);
    }
    return phpDocTarget;
}
 
Example #13
Source File: BrowseFolderPanel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private BrowseFolderPanel(String info, PhpModule phpModule) {
    assert info != null;
    assert phpModule != null;

    this.info = info;
    this.phpModule = phpModule;

    initComponents();

    targetFolderTextField.getDocument().addDocumentListener(new DocumentListener() {
        @Override
        public void insertUpdate(DocumentEvent e) {
            processUpdate();
        }
        @Override
        public void removeUpdate(DocumentEvent e) {
            processUpdate();
        }
        @Override
        public void changedUpdate(DocumentEvent e) {
            processUpdate();
        }
        private void processUpdate() {
            validateFolder();
        }
    });
}
 
Example #14
Source File: GoToActionOrViewAction.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private Action getGoToAction(FileObject fo, int offset) {
    if (fo == null) {
        return null;
    }
    PhpProject phpProject = PhpProjectUtils.getPhpProject(fo);
    if (phpProject == null) {
        return null;
    }

    // the 1st wins
    final PhpModule phpModule = phpProject.getPhpModule();
    for (PhpFrameworkProvider frameworkProvider : phpProject.getFrameworks()) {
        PhpModuleActionsExtender actionsExtender = frameworkProvider.getActionsExtender(phpModule);
        if (actionsExtender != null) {
            if (actionsExtender.isActionWithView(fo)) {
                GoToViewAction goToViewAction = actionsExtender.getGoToViewAction(fo, offset);
                if (goToViewAction == null) {
                    throw new IllegalStateException(fo.getPath() + " is action with view so GoToView instance must be returned by " + frameworkProvider.getIdentifier());
                }
                return goToViewAction;
            } else if (actionsExtender.isViewWithAction(fo)) {
                GoToActionAction goToActionAction = actionsExtender.getGoToActionAction(fo, offset);
                if (goToActionAction == null) {
                    throw new IllegalStateException(fo.getPath() + " is view with action so GoToAction instance must be returned by " + frameworkProvider.getIdentifier());
                }
                return goToActionAction;
            }
        }
    }
    return null;
}
 
Example #15
Source File: AnalysisUtils.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public static Map<FileObject, Integer> countPhpFiles(Scope scope) {
    Map<FileObject, Integer> counts = new HashMap<>();
    for (FileObject root : scope.getSourceRoots()) {
        counts.put(root, countPhpFiles(Queries.getVisibilityQuery(PhpModule.Factory.forFileObject(root)), root, true));
    }
    for (FileObject file : scope.getFiles()) {
        counts.put(file, countPhpFiles(Queries.getVisibilityQuery(PhpModule.Factory.forFileObject(file)), file, true));
    }
    for (NonRecursiveFolder nonRecursiveFolder : scope.getFolders()) {
        FileObject folder = nonRecursiveFolder.getFolder();
        counts.put(folder, countPhpFiles(Queries.getVisibilityQuery(PhpModule.Factory.forFileObject(folder)), folder, false));
    }
    return counts;
}
 
Example #16
Source File: PhpDocumentorProvider.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public void generateDocumentation(PhpModule phpModule) {
    try {
        PhpDocScript.getDefault().generateDocumentation(phpModule);
    } catch (InvalidPhpExecutableException ex) {
        UiUtils.invalidScriptProvided(ex.getLocalizedMessage(), PhpDocScript.OPTIONS_SUB_PATH);
    }
}
 
Example #17
Source File: TemplateStatus.java    From cakephp3-netbeans with Apache License 2.0 5 votes vote down vote up
private void addCells(Set<String> cells, PhpModule phpModule, FileObject fileObject) {
    CakePHP3Module cakeModule = CakePHP3Module.forPhpModule(phpModule);
    Base base = cakeModule.getBase(fileObject);
    for (String cell : cells) {
        Pair<String, String> pluginSplit = ModuleUtils.pluginSplit(cell);
        String pluginName = pluginSplit.first();
        String cellName = pluginSplit.second();
        Pair<String, String> cellMethodSplit = ModuleUtils.cellMethodSplit(cellName);
        cellName = cellMethodSplit.first();
        String cellMethod = cellMethodSplit.second();
        if (cellMethod.isEmpty()) {
            // default
            cellMethod = DEFAULT_CELL_METHOD;
        }

        // view
        String viewCellRelativePath = cakeModule.toPhpFileName(Category.VIEW_CELL, cellName);
        FileObject viewCell = cakeModule.getFile(base, Category.VIEW_CELL, viewCellRelativePath, pluginName);
        if (viewCell != null) {
            // XXX offset : a method exists
            viewCells.add(GoToItemFactory.create(Category.VIEW_CELL, viewCell, DEFAULT_OFFSET));
        }

        // template
        String templateCellRelativePath = cellName + "/" + cakeModule.toPhpFileName(Category.TEMPLATE_CELL, cellMethod); // NOI18N
        FileObject templateCell = cakeModule.getFile(base, Category.TEMPLATE_CELL, templateCellRelativePath, pluginName);
        if (templateCell != null) {
            templateCells.add(GoToItemFactory.create(Category.TEMPLATE_CELL, templateCell, DEFAULT_OFFSET));
        }
    }

}
 
Example #18
Source File: SmartyPhpFrameworkProvider.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@CheckForNull
@SuppressWarnings("NP_BOOLEAN_RETURN_NULL")
private static Boolean getSmartyPropertyEnabled(PhpModule phpModule) {
    Preferences preferences = phpModule.getPreferences(SmartyPhpFrameworkProvider.class, true);
    String available = preferences.get(PROP_SMARTY_AVAILABLE, null);
    if (available == null) {
        return null;
    } else {
        return Boolean.valueOf(available);
    }
}
 
Example #19
Source File: ZendCommand.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
protected String getHelpInternal() {
    PhpModule module = phpModule.get();
    if (module == null) {
        return ""; // NOI18N
    }
    try {
        return ZendScript.getDefault().getHelp(module, Arrays.<String>asList(getCommands()));
    } catch (InvalidPhpExecutableException ex) {
        UiUtils.invalidScriptProvided(ex.getLocalizedMessage(), ZendScript.getOptionsSubPath());
    }
    return ""; // NOI18N
}
 
Example #20
Source File: Doctrine2Script.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void runCommand(PhpModule phpModule, List<String> parameters, Runnable postExecution) {
    new PhpExecutable(doctrine2Path)
            .workDir(FileUtil.toFile(phpModule.getSourceDirectory()))
            .displayName(getDisplayName(phpModule))
            .additionalParameters(getAllParameters(parameters))
            .run(getDescriptor(postExecution));
}
 
Example #21
Source File: ControllerVisitor.java    From cakephp3-netbeans with Apache License 2.0 5 votes vote down vote up
public ControllerVisitor(PhpModule phpModule, FileObject targetFile, boolean isTemplate, int caretPosition) {
    super(phpModule);
    this.isTemplate = isTemplate;
    EditorSupport editorSupport = Lookup.getDefault().lookup(EditorSupport.class);
    PhpBaseElement phpElement = editorSupport.getElement(targetFile, caretPosition);
    if (phpElement != null && phpElement instanceof PhpClass.Method) {
        PhpClass.Method method = (PhpClass.Method) phpElement;
        templateName = method.getName();
        allTemplateNames.add(templateName);
    }
}
 
Example #22
Source File: Zend2PhpFrameworkProvider.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public boolean isInPhpModule(PhpModule phpModule) {
    if (phpModule.isBroken()) {
        // broken project
        return false;
    }
    FileObject sourceDirectory = phpModule.getSourceDirectory();
    if (sourceDirectory == null) {
        // broken project
        return false;
    }
    FileObject config = sourceDirectory.getFileObject("config/application.config.php"); // NOI18N
    return config != null && config.isData() && config.isValid();
}
 
Example #23
Source File: AddDependencyPanel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@NbBundle.Messages({
    "# {0} - project name",
    "AddDependencyPanel.panel.title=Composer Packages ({0})",
})
public static void open(PhpModule phpModule) {
    assert EventQueue.isDispatchThread();
    assert phpModule != null;

    final AddDependencyPanel addDependencyPanel = new AddDependencyPanel(phpModule);
    Object[] options = new Object[] {
        addDependencyPanel.requireButton,
        addDependencyPanel.requireDevButton,
        DialogDescriptor.CANCEL_OPTION,
    };

    final DialogDescriptor descriptor = new DialogDescriptor(
            addDependencyPanel,
            Bundle.AddDependencyPanel_panel_title(phpModule.getDisplayName()),
            false,
            options,
            addDependencyPanel.requireButton,
            DialogDescriptor.DEFAULT_ALIGN, null, null);
    descriptor.setClosingOptions(new Object[] {DialogDescriptor.CANCEL_OPTION});
    descriptor.setAdditionalOptions(new Object[] {addDependencyPanel.keepOpenCheckBox});
    final Dialog dialog = DialogDisplayer.getDefault().createDialog(descriptor);
    addDependencyPanel.dependenciesPanel.setDefaultAction(dialog, new Runnable() {
        @Override
        public void run() {
            if (addDependencyPanel.requireButton.isEnabled()) {
                addDependencyPanel.requireButton.doClick();
            }
        }
    });
    handleKeepOpen(dialog, addDependencyPanel);
    dialog.setVisible(true);
}
 
Example #24
Source File: Tester.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@CheckForNull
private static String validatePhpModule(PhpModule phpModule) {
    ValidationResult result = new TesterPreferencesValidator()
            .validate(phpModule)
            .getResult();
    return validateResult(result);
}
 
Example #25
Source File: SymfonyPhpModuleIgnoredFilesExtender.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public SymfonyPhpModuleIgnoredFilesExtender(PhpModule phpModule) {
    assert phpModule != null;

    this.phpModule = phpModule;

    File sources = FileUtil.toFile(phpModule.getSourceDirectory());
    FileObject cacheFO = SymfonyPhpFrameworkProvider.locate(phpModule, DIR_CACHE, true);
    if (cacheFO != null && cacheFO.isFolder()) {
        cache = FileUtil.toFile(cacheFO);
    } else {
        // cache not found, simply pretend that it's under sources
        cache = new File(sources, DIR_CACHE);
    }
    log = new File(sources, DIR_LOG);
}
 
Example #26
Source File: ApiGenProvider.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public void generateDocumentation(PhpModule phpModule) {
    try {
        ApiGenScript.getDefault().generateDocumentation(phpModule);
    } catch (InvalidPhpExecutableException ex) {
        UiUtils.invalidScriptProvided(ex.getLocalizedMessage(), ApiGenOptionsPanelController.OPTIONS_SUBPATH);
    }
}
 
Example #27
Source File: PhpUnitPreferences.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static String relativizePath(PhpModule phpModule, String filePath) {
    if (!StringUtils.hasText(filePath)) {
        return ""; // NOI18N
    }
    File file = new File(filePath);
    String path = PropertyUtils.relativizeFile(FileUtil.toFile(phpModule.getProjectDirectory()), file);
    if (path == null) {
        // sorry, cannot be relativized
        path = file.getAbsolutePath();
    }
    return path;
}
 
Example #28
Source File: CakePHP3OptionsPanel.java    From cakephp3-netbeans with Apache License 2.0 5 votes vote down vote up
private void notifyPropertyChanged() {
    Project[] openProjects = OpenProjects.getDefault().getOpenProjects();
    for (Project project : openProjects) {
        PhpModule phpModule = PhpModule.Factory.lookupPhpModule(project);
        if (phpModule != null) {
            if (CakePHP3Module.isCakePHP(phpModule)) {
                CakePHP3Module cakeModule = CakePHP3Module.forPhpModule(phpModule);
                if (cakeModule == null) {
                    continue;
                }
                cakeModule.notifyPropertyChanged(new PropertyChangeEvent(this, CakePHP3Module.PROPERTY_CHANGE_CAKE3, null, null));
            }
        }
    }
}
 
Example #29
Source File: Doctrine2Preferences.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private static Preferences getPreferences(PhpModule module) {
    return module.getPreferences(Doctrine2PhpFrameworkProvider.class, true);
}
 
Example #30
Source File: CodeceptionCustomizer.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public CodeceptionCustomizer(PhpModule phpModule) {
    assert phpModule != null;
    this.phpModule = phpModule;
}