/** * Get a PHP project for the given FileObject. * @return a PHP project or <code>null</code>. */ public static PhpProject getPhpProject(FileObject fo) { assert fo != null; Project project = FileOwnerQuery.getOwner(fo); if (project == null) { return null; } return project.getLookup().lookup(PhpProject.class); }
protected static Project getProject(Node node) { DataObject dataObject = node.getLookup().lookup(DataObject.class); if (dataObject != null) { FileObject fileObject = dataObject.getPrimaryFile(); if (fileObject != null) { return FileOwnerQuery.getOwner(fileObject); } } return null; }
@Override protected boolean enable(Node[] activatedNodes) { if (activatedNodes.length != 1) { return false; } Lookup l = activatedNodes[0].getLookup(); FileObject fo = l.lookup(FileObject.class); if (fo != null) { Project p = FileOwnerQuery.getOwner(fo); return TestNGSupport.isActionSupported(Action.DEBUG_TEST, p); } return false; }
static boolean isValidRoot (File file, File[] relatedRoots, File projectFolder) { Project p; if ((p = FileOwnerQuery.getOwner(file.toURI()))!=null && !file.getAbsolutePath().startsWith(projectFolder.getAbsolutePath()+File.separatorChar)) { final Sources sources = (Sources) p.getLookup().lookup(Sources.class); if (sources == null) { return false; final SourceGroup[] sourceGroups = sources.getSourceGroups(Sources.TYPE_GENERIC); final SourceGroup[] javaGroups = sources.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA); final SourceGroup[] groups = new SourceGroup [sourceGroups.length + javaGroups.length]; System.arraycopy(sourceGroups,0,groups,0,sourceGroups.length); System.arraycopy(javaGroups,0,groups,sourceGroups.length,javaGroups.length); final FileObject projectDirectory = p.getProjectDirectory(); final FileObject fileObject = FileUtil.toFileObject(file); if (projectDirectory == null || fileObject == null) { return false; return false; if (!projectDirectory.equals(sgRoot) && FileUtil.isParentOf(sgRoot, fileObject)) { return false;
@Override protected boolean enable(Node[] activatedNodes) { if (activatedNodes.length == 0) { return false; } DataObject dataObject = activatedNodes[0].getLookup().lookup(DataObject.class); if (dataObject == null || dataObject.getFolder() == null) { return false; } Project prj = FileOwnerQuery.getOwner(dataObject.getFolder().getPrimaryFile()); if (prj == null) { return false; } FileObject domainDir = prj.getProjectDirectory().getFileObject(DOMAIN_DIR); if (domainDir == null) { return false; } return FileUtil.isParentOf(domainDir, dataObject.getPrimaryFile()); } }
protected void performAction(Node[] activatedNodes) { final GrailsPlatform runtime = GrailsPlatform.getDefault(); if (!runtime.isConfigured()) { ConfigurationSupport.showConfigurationWarning(runtime); return; } DataObject dataObject = activatedNodes[0].getLookup().lookup(DataObject.class); GrailsProject prj = (GrailsProject) FileOwnerQuery.getOwner(dataObject.getFolder().getPrimaryFile()); FileObject domainDir = prj.getProjectDirectory().getFileObject(DOMAIN_DIR); if (domainDir == null) { return; } String relativePath = FileUtil.getRelativePath(domainDir, dataObject.getPrimaryFile()); if (relativePath == null) { return; } // replace slashes and cut off the extension StringBuilder builder = new StringBuilder(relativePath.replace('/', '.')); // NOI18N builder.setLength(builder.length() - dataObject.getPrimaryFile().getNameExt().length()); builder.append(dataObject.getPrimaryFile().getName()); ProjectInformation inf = prj.getLookup().lookup(ProjectInformation.class); String displayName = inf.getDisplayName() + " (" + command + ")"; // NOI18N Callable<Process> callable = ExecutionSupport.getInstance().createSimpleCommand( command, GrailsProjectConfig.forProject(prj), builder.toString()); // NOI18N ExecutionDescriptor descriptor = prj.getCommandSupport().getDescriptor(command); ExecutionService service = ExecutionService.newService(callable, descriptor, displayName); service.run(); }
public static FileObject getResourceDirectory(FileObject fo){ Project holdingProj = FileOwnerQuery.getOwner(fo); FileObject resourceDir = null; if (holdingProj != null){ J2eeModuleProvider provider = (J2eeModuleProvider) holdingProj.getLookup().lookup(J2eeModuleProvider.class); if(provider != null){ File resourceLoc = provider.getJ2eeModule().getResourceDirectory(); if(resourceLoc != null){ if(resourceLoc.exists ()){ resourceDir = FileUtil.toFileObject (resourceLoc); }else{ try { resourceDir = FileUtil.createFolder(resourceLoc); } catch (IOException ex) { LOG.log(Level.SEVERE, "getResourceDirectory failed", ex); } } } } } return resourceDir; }
private void createInterceptor( InterceptorPanel panel, FileObject targetFolder ) { FileObject templateFileObject = FileUtil.getConfigFile( "Templates/Classes/Class.java"); // NOI18N try { DataObject templateDataObject = DataObject .find(templateFileObject); DataFolder dataFolder = DataFolder.findFolder(targetFolder); DataObject createdDataObject = templateDataObject.createFromTemplate( dataFolder,panel.getInterceptorName(), Collections.<String, Object> emptyMap()); modifyClass( createdDataObject.getPrimaryFile() , getType(myBindingFileObject, ElementKind.ANNOTATION_TYPE)); Project project = FileOwnerQuery.getOwner(myBindingFileObject); if ( project != null ){ CdiUtil logger = project.getLookup().lookup(CdiUtil.class); if ( logger != null ){ logger.log("USG_CDI_GENERATE_INTERCEPTOR", // NOI18N InterceptorGenerator.class, new Object[]{project.getClass().getName()}); } } } catch (IOException e) { LOG.log(Level.WARNING , null , e ); } }
private static void doCopy(Project original, FileObject from, FileObject toParent) throws IOException { if (!VisibilityQuery.getDefault().isVisible(from)) { //Do not copy invisible files/folders. return ; } if (!original.getProjectDirectory().equals(FileOwnerQuery.getOwner(from).getProjectDirectory())) { return ; } //#109580 if (SharabilityQuery.getSharability(from) == SharabilityQuery.Sharability.NOT_SHARABLE) { return; } if (from.isFolder()) { FileObject copy = toParent.createFolder(from.getNameExt()); for (FileObject kid : from.getChildren()) { doCopy(original, kid, copy); } } else { assert from.isData(); FileObject target = FileUtil.copyFile(from, toParent, from.getName(), from.getExt()); } }
public void processLine(String line, OutputVisitor visitor) { Matcher match = failPattern.matcher(line); if (match.matches()) { String clazz = match.group(1); String lineNum = match.group(2); String text = match.group(4); visitor.setOutputListener(new CompileAnnotation(clazz, lineNum, text), text.indexOf("[deprecation]") < 0); //NOI18N File clazzfile = new File(clazz + ".java"); //NOI18N FileObject file = FileUtilities.toFileObject(FileUtil.normalizeFile(clazzfile)); String newclazz = clazz; if (file != null) { Project prj = FileOwnerQuery.getOwner(file); if (prj != null) { Sources srcs = prj.getLookup().lookup(Sources.class); if (srcs != null) { for (SourceGroup grp : srcs.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA)) { if (FileUtil.isParentOf(grp.getRootFolder(), file)) { newclazz = FileUtil.getRelativePath(grp.getRootFolder(), file); } } } } } line = line.replace(clazz, newclazz); visitor.setLine(line); } }
if (outputDir != null) { File fl = FileUtil.normalizeFile(new File(outputDir)); outDir = FileUtilities.toFileObject(fl); return; outDir.refresh(); FileObject report = outDir.getFileObject(testname + ".txt"); //NOI18N Project prj = FileOwnerQuery.getOwner(outDir); if (prj != null) { NbMavenProject nbprj = prj.getLookup().lookup(org.codehaus.mevenide.netbeans.NbMavenProject.class); File testDir = new File(nbprj.getOriginalMavenProject().getBuild().getTestSourceDirectory());
static NbModuleProvider findProject(FileObject f) { URL[] location = (URL[]) f.getAttribute("layers"); // NOI18N if (location == null || location.length != 1) { return null; } Project p = FileOwnerQuery.getOwner(URI.create(location[0].toExternalForm())); if (p == null) { return null; } return p.getLookup().lookup(NbModuleProvider.class); }
private void checkBuildTrigger(FileObject fo) { if (checkRoots(fo)) { Project prj = FileOwnerQuery.getOwner(fo); if (prj != null) { ProjectURLWatcher watch = prj.getLookup().lookup(ProjectURLWatcher.class); if (watch != null) { String name = fo.getNameExt(); boolean reset = "pom.xml".equals(name) || "profiles.xml".equals(name) || "nbactions.xml".equals(name); doPrepareProject(prj, reset); if (mainMavenProject != null) { SubprojectProvider subs = mainMavenProject.getLookup().lookup(SubprojectProvider.class); if (subs.getSubprojects().contains(prj)) { doPrepareProject(mainMavenProject, reset); } } } } } //TODO - check settings.xml and clear the cache.. }
protected void performAction(Node[] activatedNodes) { Lookup l = activatedNodes[0].getLookup(); Project p = l.lookup(Project.class); if (p == null) { FileObject fileObject = l.lookup(FileObject.class); if (fileObject != null) { p = FileOwnerQuery.getOwner(fileObject); } } TestExecutor exec = TestNGSupport.findTestNGSupport(p).createExecutor(p); assert exec.hasFailedTests(); TestConfig conf = TestNGUtils.getTestConfig(p.getProjectDirectory(), true, null, null, null); try { exec.execute(Action.RUN_FAILED, conf); } catch (IOException ex) { LOGGER.log(Level.SEVERE, null, ex); } }
/** Creates a new instance of CurrentProject */ private CurrentProject() { DataObject obj = Utilities.actionsGlobalContext().lookup(DataObject.class); OpenProjects.getDefault().addPropertyChangeListener(WeakListeners.create(PropertyChangeListener.class, changedProjectsListener, OpenProjects.getDefault())); if (obj != null) { FileObject fileObject = obj.getPrimaryFile(); project = FileOwnerQuery.getOwner(fileObject); } }
public Action createContextAwareInstance(Lookup context) { DataObject dob = (DataObject)context.lookup(DataObject.class); if (dob == null) { ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, new IllegalStateException("SetStartPageAction: missing DataObject instance in the context, context=" + context)); // NOI18N return null; } int type = TYPE_JSP; FileObject fo = dob.getPrimaryFile(); // check for jsp extension if ((fo != null) && "jsp".equalsIgnoreCase(fo.getExt())) { // NOI18N // check if this is a portlet project Project thisProj = FileOwnerQuery.getOwner(fo); if (JsfProjectUtils.getPortletSupport(thisProj) != null) { type = TYPE_PORTLET; } } return new SetStartPageAction(type, fo); }
CommonUtils.getInstance().setTestingFramework(CommonUtils.JUNIT_TF); this.sessionType = sessionInfo.getSessionType(); File antScript = FileUtil.normalizeFile(session.getOriginatingScript()); this.timeOfSessionStart = sessionInfo.getTimeOfTestTaskStart(); if (project == null){ FileObject fileObj = FileUtil.toFileObject(antScript); project = FileOwnerQuery.getOwner(fileObj); if (project == null) { project = new Project() { String sName = JUnitExecutionManager.JUNIT_CUSTOM_FILENAME.equals(FileUtil.toFileObject(antScript).getName()) ? NbBundle.getMessage(JUnitOutputReader.class, "LBL_RerunFailedTests") : //NOI18N methodName != null ? File projectFile = FileUtil.toFile(project.getProjectDirectory()); if(projectFile != null) { JUnitUtils.logJUnitUsage(Utilities.toURI(projectFile));
/** * * @return collection of local modules, that are obtained from the first node_modules folder */ public Collection<FileObject> getLocalModules(FileObject forFile) { HashSet<FileObject> modules = new HashSet<FileObject>(); Project project = FileOwnerQuery.getOwner(forFile); FileObject nodeModulesFolder = null; FileObject parent = forFile.getParent(); if (project != null) { FileObject projectDirectory = project.getProjectDirectory(); String pathToProject = projectDirectory.getPath(); while (parent.getPath().startsWith(pathToProject) && nodeModulesFolder == null) { nodeModulesFolder = parent.getFileObject(NodeJsUtils.NODE_MODULES_NAME); parent = parent.getParent(); } } if (nodeModulesFolder != null) { Enumeration<? extends FileObject> moduleFolders = nodeModulesFolder.getFolders(false); while (moduleFolders.hasMoreElements()) { FileObject moduleFolder = moduleFolders.nextElement(); if (moduleFolder.getFileObject(NodeJsUtils.PACKAGE_NAME, NodeJsUtils.JSON_EXT) != null) { modules.add(moduleFolder); } } } return modules; }
private void update() { project = null; TopComponent tc = TopComponent.getRegistry().getActivated(); if (tc != null) { FileObject fo = tc.getLookup().lookup(FileObject.class); if (fo == null) { DataObject dob = tc.getLookup().lookup(DataObject.class); if (dob != null) { fo = dob.getPrimaryFile(); } } if (fo != null) { Project p = FileOwnerQuery.getOwner(fo); if (p != null) { project = p; } } } if (project != null) { applicable = true; name = NbBundle.getMessage(SearchScopeCurrentProject.class, "SearchScopeCurrentProject", shortName(project)); //NOI18N icon = ProjectUtils.getInformation(project).getIcon(); } else { applicable = false; name = ""; //NOI18N icon = null; } notifyListeners(); }
public static String getPackageName(FileObject folder) { assert folder.isFolder() : "argument must be folder"; //NOI18N Project p = FileOwnerQuery.getOwner(folder); if (p != null) { Sources s = ProjectUtils.getSources(p); for(SourceGroup g : s.getSourceGroups(Sources.TYPE_GENERIC)) { String relativePath = FileUtil.getRelativePath(g.getRootFolder(), folder); if (relativePath != null) { return relativePath.replace('/', '.'); //NOI18N } } } return ""; //NOI18N }