| /* |
| * Licensed to the Apache Software Foundation (ASF) under one |
| * or more contributor license agreements. See the NOTICE file |
| * distributed with this work for additional information |
| * regarding copyright ownership. The ASF licenses this file |
| * to you under the Apache License, Version 2.0 (the |
| * "License"); you may not use this file except in compliance |
| * with the License. You may obtain a copy of the License at |
| * |
| * http://www.apache.org/licenses/LICENSE-2.0 |
| * |
| * Unless required by applicable law or agreed to in writing, |
| * software distributed under the License is distributed on an |
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| * KIND, either express or implied. See the License for the |
| * specific language governing permissions and limitations |
| * under the License. |
| */ |
| |
| package org.netbeans.modules.php.symfony; |
| |
| import org.netbeans.modules.php.api.framework.BadgeIcon; |
| import org.netbeans.modules.php.api.phpmodule.PhpModule; |
| import org.netbeans.modules.php.api.phpmodule.PhpModuleProperties; |
| import org.netbeans.modules.php.spi.editor.EditorExtender; |
| import org.netbeans.modules.php.spi.framework.PhpFrameworkProvider; |
| import org.netbeans.modules.php.spi.framework.PhpModuleActionsExtender; |
| import org.netbeans.modules.php.spi.framework.PhpModuleCustomizerExtender; |
| import org.netbeans.modules.php.spi.framework.PhpModuleExtender; |
| import org.netbeans.modules.php.spi.framework.PhpModuleIgnoredFilesExtender; |
| import org.netbeans.modules.php.spi.phpmodule.ImportantFilesImplementation; |
| import org.netbeans.modules.php.symfony.commands.SymfonyCommandSupport; |
| import org.netbeans.modules.php.symfony.editor.SymfonyEditorExtender; |
| import org.openide.filesystems.FileObject; |
| import org.openide.util.ImageUtilities; |
| import org.openide.util.NbBundle; |
| |
| /** |
| * @author Tomas Mysik |
| */ |
| public final class SymfonyPhpFrameworkProvider extends PhpFrameworkProvider { |
| public static final String FILE_CONFIG = "config/ProjectConfiguration.class.php"; // NOI18N |
| |
| private static final String ICON_PATH = "org/netbeans/modules/php/symfony/ui/resources/symfony_badge_8.png"; // NOI18N |
| private static final SymfonyPhpFrameworkProvider INSTANCE = new SymfonyPhpFrameworkProvider(); |
| |
| private final BadgeIcon badgeIcon; |
| |
| @PhpFrameworkProvider.Registration(position=100) |
| public static SymfonyPhpFrameworkProvider getInstance() { |
| return INSTANCE; |
| } |
| |
| private SymfonyPhpFrameworkProvider() { |
| super("Symfony PHP Web Framework", // NOI18N |
| NbBundle.getMessage(SymfonyPhpFrameworkProvider.class, "LBL_FrameworkName"), |
| NbBundle.getMessage(SymfonyPhpFrameworkProvider.class, "LBL_FrameworkDescription")); |
| badgeIcon = new BadgeIcon( |
| ImageUtilities.loadImage(ICON_PATH), |
| SymfonyPhpFrameworkProvider.class.getResource("/" + ICON_PATH)); // NOI18N |
| } |
| |
| @Override |
| public BadgeIcon getBadgeIcon() { |
| return badgeIcon; |
| } |
| |
| /** |
| * Try to locate (find) a <code>relativePath</code> in source directory. |
| * Currently, it searches source dir and its subdirs (if <code>subdirs</code> equals {@code true}). |
| * @return {@link FileObject} or {@code null} if not found |
| */ |
| public static FileObject locate(PhpModule phpModule, String relativePath, boolean subdirs) { |
| FileObject sourceDirectory = phpModule.getSourceDirectory(); |
| if (sourceDirectory == null) { |
| // broken project |
| return null; |
| } |
| |
| FileObject fileObject = sourceDirectory.getFileObject(relativePath); |
| if (fileObject != null || !subdirs) { |
| return fileObject; |
| } |
| for (FileObject child : sourceDirectory.getChildren()) { |
| fileObject = child.getFileObject(relativePath); |
| if (fileObject != null) { |
| return fileObject; |
| } |
| } |
| return null; |
| } |
| |
| @Override |
| public boolean isInPhpModule(PhpModule phpModule) { |
| // #170775 |
| // first search "symfony", then "config/ProjectConfiguration.class.php" |
| FileObject symfony = locate(phpModule, SymfonyScript.SCRIPT_NAME, false); |
| if (symfony != null && symfony.isData()) { |
| return true; |
| } |
| FileObject config = locate(phpModule, FILE_CONFIG, true); |
| return config != null && config.isData(); |
| } |
| |
| @Override |
| public ImportantFilesImplementation getConfigurationFiles2(PhpModule phpModule) { |
| return new ConfigurationFiles(phpModule); |
| } |
| |
| @Override |
| public PhpModuleExtender createPhpModuleExtender(PhpModule phpModule) { |
| // return new SymfonyPhpModuleExtender(); |
| // legacy version, disable it |
| return null; |
| } |
| |
| @Override |
| public PhpModuleCustomizerExtender createPhpModuleCustomizerExtender(PhpModule phpModule) { |
| if (isInPhpModule(phpModule)) { |
| return new SymfonyPhpModuleCustomizerExtender(phpModule); |
| } |
| return null; |
| } |
| |
| @Override |
| public PhpModuleProperties getPhpModuleProperties(PhpModule phpModule) { |
| PhpModuleProperties properties = new PhpModuleProperties(); |
| FileObject web = locate(phpModule, "web", true); // NOI18N |
| if (web != null) { |
| properties = properties.setWebRoot(web); |
| } |
| FileObject testUnit = locate(phpModule, "test/unit", true); // NOI18N |
| if (testUnit != null) { |
| properties = properties.setTests(testUnit); |
| } |
| return properties; |
| } |
| |
| @Override |
| public PhpModuleActionsExtender getActionsExtender(PhpModule phpModule) { |
| return new SymfonyPhpModuleActionsExtender(); |
| } |
| |
| @Override |
| public PhpModuleIgnoredFilesExtender getIgnoredFilesExtender(PhpModule phpModule) { |
| return new SymfonyPhpModuleIgnoredFilesExtender(phpModule); |
| } |
| |
| @Override |
| public SymfonyCommandSupport getFrameworkCommandSupport(PhpModule phpModule) { |
| return new SymfonyCommandSupport(phpModule); |
| } |
| |
| @Override |
| public EditorExtender getEditorExtender(PhpModule phpModule) { |
| return new SymfonyEditorExtender(); |
| } |
| } |