Java Code Examples for org.netbeans.api.project.FileOwnerQuery#getOwner()

The following examples show how to use org.netbeans.api.project.FileOwnerQuery#getOwner() . 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: GenerateAction.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@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());
}
 
Example 2
Source File: JaxWsAddOperationProvider.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private String getPackageName(FileObject fo) {
    Project project = FileOwnerQuery.getOwner(fo);
    SourceGroup[] groups = ProjectUtils.getSources(project).getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
    if (groups!=null) {
        for (SourceGroup group: groups) {
            FileObject rootFolder = group.getRootFolder();
            if (FileUtil.isParentOf(rootFolder, fo)) {
                String relativePath = FileUtil.getRelativePath(rootFolder, fo).replace('/', '.');
                return (relativePath.endsWith(".java")? //NOI18N
                    relativePath.substring(0,relativePath.length()-5):
                    relativePath);
            }
        }
    }
    return null;
}
 
Example 3
Source File: JadeCodeCompletion.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private void completeCSSClasses(JadeCompletionItem.CompletionRequest request, List<CompletionProposal> resultList) {
    FileObject fo = request.parserResult.getSnapshot().getSource().getFileObject();
    if(fo == null) {
        return;
    }
    Project project = FileOwnerQuery.getOwner(fo);
    HashSet<String> unique = new HashSet<>();
    String prefix = request.prefix == null ? "" : request.prefix;
    try {
        CssIndex cssIndex = CssIndex.create(project);
        Map<FileObject, Collection<String>> findIdsByPrefix = cssIndex.findClassesByPrefix(prefix);

        for (Collection<String> ids : findIdsByPrefix.values()) {
            for (String id : ids) {
                unique.add(id);
            }
        }
    } catch (IOException ex) {
        Exceptions.printStackTrace(ex);
    }
    
    for(String className: unique) {
        resultList.add(JadeCompletionItem.createCssItem(request, className, CSS_CLASS_PREFIX));
    }
}
 
Example 4
Source File: Selenium2PhpSupportImpl.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public boolean isSupportEnabled(FileObject[] activatedFOs) {
    if (activatedFOs.length == 0) {
        return false;
    }
    
    Project p = FileOwnerQuery.getOwner(activatedFOs[0]);
    if (p == null) {
        return false;
    }
    PhpSeleniumProvider seleniumProvider = getSeleniumProvider(p);
    if(seleniumProvider == null) {
        return false;
    }
    return seleniumProvider.isSupportEnabled(activatedFOs);
}
 
Example 5
Source File: GlobalJavadocForBinaryImpl.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * Go through all registered platforms and tries to find Javadoc for the
 * given URL.
 * <p>
 * <em>TODO</em>: ideally should check module, or at least cluster, version.
 */
private Result findForSourceRoot(final URL root) throws MalformedURLException {
    Project p ;
    try {
        p = FileOwnerQuery.getOwner(root.toURI());
    } catch (URISyntaxException e) {
        throw new AssertionError(e);
    }
    if (p != null) {
        NbModuleProject module = p.getLookup().lookup(NbModuleProject.class);
        if (module != null) {
            String cnb = module.getCodeNameBase();
//  TODO C.P scan external clusters? Doesn't seem necessary, javadoc is built from source on the fly for clusters with sources
            NbPlatform plaf = module.getPlatform(false);
            if (plaf != null) {
                Util.err.log("Platform in " + plaf.getDestDir() + " claimed to have Javadoc roots "
                        + Arrays.asList(plaf.getJavadocRoots()));
                Result r = findByDashedCNB(cnb.replace('.', '-'), plaf.getJavadocRoots(), false);
                if (r != null) {
                    return r;
                }
            }
        }
    }
    return null;
}
 
Example 6
Source File: SourcesNodeFactory.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Messages({"# {0} - label of source group", "# {1} - project name", "ERR_WrongSG={0} is owned by project {1}, cannot be used here, see issue #138310 for details."})
@Override
public Node node(SourceGroup group) {
    Project owner = FileOwnerQuery.getOwner(group.getRootFolder());
    if (owner != project) {
        if (owner == null) {
            //#152418 if project for folder is not found, just look the other way..
            Logger.getLogger(SourcesNodeFactory.class.getName()).log(Level.INFO, "Cannot find a project owner for folder {0}", group.getRootFolder()); //NOI18N
            return null;
        }
        AbstractNode erroNode = new AbstractNode(Children.LEAF);
        String prjText = ProjectUtils.getInformation(owner).getDisplayName();
        erroNode.setDisplayName(ERR_WrongSG(group.getDisplayName(), prjText));
        return erroNode;
    }
    return PackageView.createPackageView(group);
}
 
Example 7
Source File: ProjectClassPathProvider.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public ClassPath findClassPath(FileObject file, String type) {
    Project p = FileOwnerQuery.getOwner(file);
    if (p != null) {
        ClassPathProvider cpp = p.getLookup().lookup(ClassPathProvider.class);
        if (cpp != null) {
            return cpp.findClassPath(file, type);
        } else {
            return null;
        }
    } else {
        return null;
    }
}
 
Example 8
Source File: JavaSourceHelper.java    From jeddict with Apache License 2.0 5 votes vote down vote up
public static String getSelectedPackageName(FileObject targetFolder) {
    Project project = FileOwnerQuery.getOwner(targetFolder);
    Sources sources = ProjectUtils.getSources(project);
    SourceGroup[] groups = sources.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
    String packageName = null;
    for (int i = 0; i < groups.length && packageName == null; i++) {
        packageName = FileUtil.getRelativePath(groups[i].getRootFolder(), targetFolder);
    }
    if (packageName != null) {
        packageName = packageName.replaceAll("/", ".");
    }
    return packageName + "";
}
 
Example 9
Source File: MissingPomDependencies.java    From nb-springboot with Apache License 2.0 5 votes vote down vote up
private static ErrorDescription importWarning(HintContext ctx, String artifactId, String hintMex, String[] fixArtifactIds) {
    final TreePath tp = ctx.getPath();
    final TreePath tpParent = tp.getParentPath();
    if (tpParent != null) {
        if (tpParent.getLeaf().getKind() == IMPORT) {
            Project prj = FileOwnerQuery.getOwner(ctx.getInfo().getFileObject());
            if (prj != null) {
                SpringBootService sbs = prj.getLookup().lookup(SpringBootService.class);
                if (sbs != null) {
                    // check first if the pom has at least one spring boot dependencies
                    if (sbs.hasPomDependency("spring-boot") && !sbs.hasPomDependency(artifactId)) {
                        NbMavenProject mPrj = prj.getLookup().lookup(NbMavenProject.class);
                        if (mPrj != null) {
                            Fix[] fixes = new Fix[fixArtifactIds.length];
                            for (int i = 0; i < fixArtifactIds.length; i++) {
                                fixes[i] = new AddDepFix(mPrj, fixArtifactIds[i], false);
                            }
                            return ErrorDescriptionFactory.forName(ctx, tp, hintMex, fixes);
                        } else {
                            return ErrorDescriptionFactory.forName(ctx, tp, hintMex);
                        }
                    }
                }
            }
        }
    }
    return null;
}
 
Example 10
Source File: PluginPropertyUtils.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Evaluator usable for interpolating variables in non resolved (interpolated) models.
 * Should not be necessary when dealing with the project's <code>MavenProject</code> instance accessed via<code>NbMavenProject.getMavenProject()</code>
 * Please NOTE that if you have access to <code>Project</code> instance, then
 * the variant with <code>Project</code> as parameter is preferable. Faster and less prone to deadlock.     
 * @since 2.32
 */
public static @NonNull ExpressionEvaluator createEvaluator(@NonNull MavenProject prj) {
    ExpressionEvaluator eval = (ExpressionEvaluator) prj.getContextValue(CONTEXT_EXPRESSION_EVALUATOR);
    if (eval != null) {
        return eval;
    }
    Map<? extends String,? extends String> sysprops = Collections.emptyMap();
    Map<? extends String,? extends String> userprops = Collections.emptyMap();
    File basedir = prj.getBasedir();
    if (basedir != null) {
    FileObject bsd = FileUtil.toFileObject(basedir);
    if (bsd != null) {
        Project p = FileOwnerQuery.getOwner(bsd);
        if (p != null) {
            NbMavenProjectImpl project = p.getLookup().lookup(NbMavenProjectImpl.class);
            if (project != null) {
                sysprops = project.createSystemPropsForPropertyExpressions();
                userprops = project.createUserPropsForPropertyExpressions();
            }
        }
    }
    }
    //ugly
    Settings ss = EmbedderFactory.getProjectEmbedder().getSettings();
    ss.setLocalRepository(EmbedderFactory.getProjectEmbedder().getLocalRepository().getBasedir());

    eval = new NBPluginParameterExpressionEvaluator(
            prj,
            ss,
            sysprops,
            userprops);
    prj.setContextValue(CONTEXT_EXPRESSION_EVALUATOR, eval);
    return eval;
}
 
Example 11
Source File: CommitAction.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void performAction (VCSContext context) {
    Set<File> rootFiles = context.getRootFiles();
    Set<Project> projects = new HashSet<Project>();
    for (File root : rootFiles) {
        FileObject fo = FileUtil.toFileObject(FileUtil.normalizeFile(root));
        if (fo != null) {
            Project owner = FileOwnerQuery.getOwner(fo);
            if (owner != null) {
                projects.add(owner);
            }
        }
    }
    if (projects.isEmpty()) {
        LOG.log(Level.FINE, "CommitProjectAction: no projects found for {0}", rootFiles); //NOI18N
    } else {
        List<Node> nodes = new ArrayList<Node>(projects.size());
        for (final Project p : projects) {
            nodes.add(new AbstractNode(Children.LEAF, Lookups.fixed(p)) {

                @Override
                public String getName () {
                    return p.getProjectDirectory().getName();
                }
                
            });
        }
        SystemAction.get(CommitAction.class).performAction(nodes.toArray(new Node[nodes.size()]));
    }
}
 
Example 12
Source File: PhpSourcePath.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static PhpSourcePathImplementation getPhpSourcePathForProjectFile(FileObject file) {
    Project project = FileOwnerQuery.getOwner(file);
    if (project == null) {
        return null;
    }
    PhpSourcePathImplementation phpSourcePath = project.getLookup().lookup(PhpSourcePathImplementation.class);
    // XXX disabled because of runtime.php underneath nbbuild directory
    //assert phpSourcePath != null : "Not PHP project (interface PhpSourcePath not found in lookup)! [" + project + "]";
    return phpSourcePath;
}
 
Example 13
Source File: ClientExplorerPanel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
protected Node getRootContext() {
    for (int i=0;i<projects.length;i++) {
        Project srcFileProject = FileOwnerQuery.getOwner(getTargetFile());
        if (srcFileProject!=null && JaxWsUtils.isProjectReferenceable(projects[i], srcFileProject)) {
            LogicalViewProvider logicalProvider = (LogicalViewProvider)projects[i].getLookup().lookup(LogicalViewProvider.class);
            if (logicalProvider!=null) {
                Node rootNode = logicalProvider.createLogicalView();
                Node[] servicesNodes = ProjectClientView.createClientView(projects[i]);
                if (servicesNodes!=null && servicesNodes.length>0) {
                    Children children = new Children.Array();
                    for(Node servicesNode:servicesNodes) {
                        Node[] nodes= servicesNode.getChildren().getNodes();
                        if (nodes!=null && nodes.length>0) {
                            Node[] filterNodes = new Node[nodes.length];
                            for (int j=0;j<nodes.length;j++) filterNodes[j] = new FilterNode(nodes[j]);
                            children.add(filterNodes);
                        }
                    }
                    if(children.getNodesCount()>0)
                        projectNodeList.add(new ProjectNode(children, rootNode));
                }
            }
        }

    }
    if (projectNodeList.size() > 0) {
        Node[] projectNodes = new Node[projectNodeList.size()];
        projectNodeList.<Node>toArray(projectNodes);
        rootChildren.add(projectNodes);
    } else {
        Node noClients = new NoServicesNode();
        rootChildren.add(new Node[]{noClients});
    }
    return explorerClientRoot;
}
 
Example 14
Source File: LayoutCompletionProvider.java    From NBANDROID-V2 with Apache License 2.0 5 votes vote down vote up
@Override
public int getAutoQueryTypes(JTextComponent component, String typedText) {
    BaseDocument doc = Utilities.getDocument(component);
    if (typedText == null || typedText.trim().length() == 0) {
        return 0;
    }
    // do not pop up if the end of text contains some whitespaces.
    if (Character.isWhitespace(typedText.charAt(typedText.length() - 1))) {
        return 0;
    }
    if (doc == null) {
        return 0;
    }
    XMLSyntaxSupport support = XMLSyntaxSupport.getSyntaxSupport(doc);
    if (support != null && CompletionUtil.noCompletion(component)
            || !CompletionUtil.canProvideCompletion(doc)) {
        return 0;
    }
    FileObject primaryFile = CompletionUtil.getPrimaryFile(component.getDocument());
    Project owner = FileOwnerQuery.getOwner(primaryFile);
    if (owner instanceof NbAndroidProject) {
        AndroidProject androidProject = owner.getLookup().lookup(AndroidProject.class);
        if (androidProject != null) {
            String next = androidProject.getBootClasspath().iterator().next();
            AndroidJavaPlatform findPlatform = AndroidJavaPlatformProvider.findPlatform(next, androidProject.getCompileTarget());
            if (findPlatform == null) {
                return 0;
            }
        } else {
            return 0;
        }
    } else {
        return 0;
    }

    return COMPLETION_QUERY_TYPE;
}
 
Example 15
Source File: ProjectWebModuleProvider.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public WebModule findWebModule (FileObject file) {
    Project project = FileOwnerQuery.getOwner (file);
    if (project != null) {
        WebModuleProvider provider = project.getLookup ().lookup (WebModuleProvider.class);
        if (provider != null) {
            return provider.findWebModule (file);
        }
    }
    return null;
}
 
Example 16
Source File: WhiteListTaskProvider.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public void run() {

    LOG.log(Level.FINE, "dequeued work for: {0}", fileOrRoot);
    final ClassPath cp = ClassPath.getClassPath(fileOrRoot, ClassPath.SOURCE);
    if (cp == null) {
        LOG.log(Level.FINE, "cp == null");
        return;
    }
    FileObject root = cp.findOwnerRoot(fileOrRoot);

    if (root == null) {
        Project p = FileOwnerQuery.getOwner(fileOrRoot);

        LOG.log(Level.WARNING,
                "file: {0} is not on its own source classpath: {1}, project: {2}",
                new Object[] {
                    FileUtil.getFileDisplayName(fileOrRoot),
                    cp.toString(ClassPath.PathConversionMode.PRINT),
                    p != null ? p.getClass() : "null"
                });

        return ;
    }

    if (fileOrRoot.isData()) {
        updateErrorsInFile(callback, root, fileOrRoot);
    } else {
        updateErrorsInRoot(callback, root, canceled);
    }
}
 
Example 17
Source File: NavigatorPanelSupportImpl.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public BuildTools.BuildToolSupport getBuildToolSupport(FileObject buildFile) {
    Project project = FileOwnerQuery.getOwner(buildFile);
    if (project == null) {
        return null;
    }
    if (GulpBuildTool.inProject(project) == null) {
        return null;
    }
    GulpBuildToolSupport support = new GulpBuildToolSupport(project, buildFile);
    support.addChangeListener(WeakListeners.change(this, support));
    return support;
}
 
Example 18
Source File: CatalogModelImpl.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void useSuitableCatalogFile(ModelSource modelSourceOfSourceDocument) {
    // if the modelSource's project has XMLCatalogProvider then use that to
    // see which catalog file to use for this modelSource
    if(modelSourceOfSourceDocument != null){
        FileObject msfo = (FileObject) modelSourceOfSourceDocument.getLookup().
                lookup(FileObject.class);
        if(msfo == null)
            return;
        Project prj = FileOwnerQuery.getOwner(msfo);
        if(prj == null)
            return;
        XMLCatalogProvider catPovider = (XMLCatalogProvider) prj.getLookup().
                lookup(XMLCatalogProvider.class);
        if(catPovider == null)
            return;
        URI caturi = catPovider.getCatalog(msfo);
        if(caturi == null)
            return;
        URI prjuri = FileUtil.toFile(prj.getProjectDirectory()).toURI();
        URI catFileURI = prjuri.resolve(caturi);
        if(catFileURI == null)
            return;
        File catFile = new File(catFileURI);
        if(!catFile.isFile()){
            try {
                catFile.createNewFile();
            } catch (IOException ex) {
                return;
            }
        }
        FileObject catFO = FileUtil.toFileObject(FileUtil.normalizeFile(catFile));
        if(catFO == null)
            return;
        //assign new catalog file that needs to be used for resolution
        this.catalogFileObject = catFO;
    }
}
 
Example 19
Source File: RefactoringUtils.java    From netbeans-mmd-plugin with Apache License 2.0 4 votes vote down vote up
public static boolean isFileInOpenProject(final FileObject fo) {
  final Project p = FileOwnerQuery.getOwner(fo);
  return OpenProjects.getDefault().isProjectOpen(p);
}
 
Example 20
Source File: OutputUtils.java    From netbeans with Apache License 2.0 3 votes vote down vote up
/**
 * Returns {@code ActionProvider} that is associated with a project
 * containing the specified {@code fileObject}.
 *
 * @param fileObject the file object.
 * @return an {@code ActionProvider}, or {@code null} if there is no
 *         known project containing the {@code fileObject}.
 *
 * @see ActionProvider
 * @see FileOwnerQuery#getOwner(org.openide.filesystems.FileObject)
 */
public static ActionProvider getActionProvider(FileObject fileObject) {
    Project owner = FileOwnerQuery.getOwner(fileObject);
    if(owner == null) { // #183586
        return null;
    }
    return owner.getLookup().lookup(ActionProvider.class);
}