org.netbeans.api.project.SourceGroup Java Examples

The following examples show how to use org.netbeans.api.project.SourceGroup. 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: JspPGPanel.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private void browseButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_browseButton3ActionPerformed
    try {
        SourceGroup[] groups = DDUtils.getDocBaseGroups(dObj);
        org.openide.filesystems.FileObject fo = BrowseFolders.showDialog(groups);
        if (fo!=null) {
            String fileName = "/"+DDUtils.getResourcePath(groups,fo,'/',true);
            String oldValue = codaTF.getText();
            if (fileName.length()>0) {
                String newValue = DDUtils.addItem(oldValue,fileName,false);
                if (!oldValue.equals(newValue)) {
                    dObj.modelUpdatedFromUI();
                    dObj.setChangedFromUI(true);
                    codaTF.setText(newValue);
                    setCodas(newValue);
                    dObj.setChangedFromUI(false);
                }
            }
        }
    } catch (java.io.IOException ex) {}
}
 
Example #2
Source File: GeneratedSourceRootTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void testSourceRoots() throws Exception {
    Project p = createTestProject(true);
    FileObject d = p.getProjectDirectory();
    FileObject src = d.getFileObject("src");
    FileObject stuff = d.getFileObject("build/generated-sources/stuff");
    SourceGroup[] groups = ProjectUtils.getSources(p).getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
    assertEquals(2, groups.length);
    assertEquals(src, groups[0].getRootFolder());
    assertEquals(d.getFileObject("test"), groups[1].getRootFolder());
    ClassPath sourcePath = ClassPath.getClassPath(src, ClassPath.SOURCE);
    assertEquals(Arrays.asList(src, stuff), Arrays.asList(sourcePath.getRoots()));
    FileObject moreStuff = FileUtil.createFolder(d, "build/generated-sources/morestuff");
    final Set<FileObject> expected = new TreeSet<FileObject>(new FOComparator());
    expected.addAll(Arrays.asList(src, stuff, moreStuff));
    final Set<FileObject> result = new TreeSet<FileObject>(new FOComparator());
    result.addAll(Arrays.asList(sourcePath.getRoots()));
    assertEquals(expected, result);
    ClassPath compile = ClassPath.getClassPath(src, ClassPath.COMPILE);
    assertEquals(compile, ClassPath.getClassPath(stuff, ClassPath.COMPILE));
    assertEquals(compile, ClassPath.getClassPath(moreStuff, ClassPath.COMPILE));
    assertEquals(ClassPath.getClassPath(src, ClassPath.EXECUTE), ClassPath.getClassPath(stuff, ClassPath.EXECUTE));
    assertEquals(ClassPath.getClassPath(src, ClassPath.BOOT), ClassPath.getClassPath(stuff, ClassPath.BOOT));
    d.getFileObject("build").delete();
    assertEquals(Arrays.asList(src), Arrays.asList(sourcePath.getRoots()));
}
 
Example #3
Source File: RefactoringUtils.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * Is given file on any source classpath?
 *
 * @param fo
 * @return
 * @deprecated 
 */
@Deprecated
public static boolean isOnSourceClasspath(FileObject fo) {
    Project pr = FileOwnerQuery.getOwner(fo);
    if (pr == null) {
        return false;
    }

    //workaround for 143542
    for (String type : new String[]{JavaProjectConstants.SOURCES_TYPE_JAVA, JavaProjectConstants.SOURCES_TYPE_RESOURCES}) {
        for (SourceGroup sg : ProjectUtils.getSources(pr).getSourceGroups(type)) {
            if (fo == sg.getRootFolder() || (FileUtil.isParentOf(sg.getRootFolder(), fo) && sg.contains(fo))) {
                return ClassPath.getClassPath(fo, ClassPath.SOURCE) != null;
            }
        }
    }
    return false;
    //end of workaround
    //return ClassPath.getClassPath(fo, ClassPath.SOURCE)!=null;
}
 
Example #4
Source File: ProjectJAXWSView.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public Node createJAXWSView(Project project) {
    if (project != null) {
        JaxWsModel model = (JaxWsModel) project.getLookup().lookup(JaxWsModel.class);
        
        if (model != null) {
            Sources sources = (Sources)project.getLookup().lookup(Sources.class);
            if (sources!=null) {
                SourceGroup[] groups = sources.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
                if (groups!=null) {
                    List<FileObject> roots = new ArrayList<FileObject>();
                    for (SourceGroup group: groups) {
                        roots.add(group.getRootFolder());
                    }
                    FileObject[] srcRoots = new FileObject[roots.size()];
                    roots.toArray(srcRoots);
                    return new JaxWsRootNode(project, model,srcRoots);
                }   
            }
        }
    }
    return null;
}
 
Example #5
Source File: ResourceHyperlinkProcessor.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private static boolean openFromClasspath(FileObject fo, String value) {
    int colonOffset = value.indexOf(":");   //NOI18N
    String subPath = value.substring(colonOffset + 1);
    Project project = FileOwnerQuery.getOwner(fo);
    if (project != null) {
        List<SourceGroup> groups = new ArrayList<>();
        Sources sources = ProjectUtils.getSources(project);
        groups.addAll(Arrays.asList(sources.getSourceGroups("doc_root"))); //NOI18N
        groups.addAll(Arrays.asList(sources.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA)));
        for (SourceGroup sourceGroup : groups) {
            FileObject fileObject = sourceGroup.getRootFolder().getFileObject(subPath);
            if (fileObject != null) {
                openFile(fileObject);
                return true;
            }
        }
    }
    return false;
}
 
Example #6
Source File: TargetEvaluator.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * Used by the ObjectNameWizard panel to set the target folder
 * gotten from the system wizard initially. 
 */
void setInitialFolder(DataFolder selectedFolder, Project p) {
    if (selectedFolder == null) {
        return;
    }
    FileObject targetFolder = selectedFolder.getPrimaryFile();
    Sources sources = ProjectUtils.getSources(p);
    SourceGroup[] groups = sources.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
    String packageName = null;
    for (int i = 0; i < groups.length && packageName == null; i++) {
        packageName = org.openide.filesystems.FileUtil.getRelativePath(groups[i].getRootFolder(), targetFolder);
        deployData.setWebApp(DeployData.getWebAppFor(groups[i].getRootFolder()));
    }
    if (packageName == null) {
        packageName = "";
    }
    setInitialPath(packageName);
}
 
Example #7
Source File: J2SESourcesTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void testIncludesExcludes() throws Exception {
    SourceGroup g = ProjectUtils.getSources(project).getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA)[0];
    assertEquals(sources, g.getRootFolder());
    FileObject objectJava = FileUtil.createData(sources, "java/lang/Object.java");
    FileObject jcJava = FileUtil.createData(sources, "javax/swing/JComponent.java");
    FileObject doc = FileUtil.createData(sources, "javax/swing/doc-files/index.html");
    assertTrue(g.contains(objectJava));
    assertTrue(g.contains(jcJava));
    assertTrue(g.contains(doc));
    Method projectOpened = ProjectOpenedHook.class.getDeclaredMethod("projectOpened");
    projectOpened.setAccessible(true);
    projectOpened.invoke(project.getLookup().lookup(ProjectOpenedHook.class));
    EditableProperties ep = helper.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH);
    assertEquals("includes/excludes were initialized to defaults", "**", ep.getProperty(ProjectProperties.INCLUDES));
    assertEquals("includes/excludes were initialized to defaults", "", ep.getProperty(ProjectProperties.EXCLUDES));
    ep.setProperty(ProjectProperties.INCLUDES, "javax/swing/");
    ep.setProperty(ProjectProperties.EXCLUDES, "**/doc-files/");
    helper.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, ep);
    pm.saveProject(project);
    assertFalse(g.contains(objectJava));
    assertTrue(g.contains(jcJava));
    assertFalse(g.contains(doc));
}
 
Example #8
Source File: AndroidFileTypesImpl.java    From NBANDROID-V2 with Apache License 2.0 6 votes vote down vote up
@Override
public boolean isLayoutFile(@Nullable final FileObject fo) {
    if (fo == null || !"xml".equals(fo.getExt())) {
        return false;
    }
    Project p = FileOwnerQuery.getOwner(fo);
    if (p.getLookup().lookup(AndroidClassPathProvider.class) == null) {
        return false;
    }
    return Iterables.any(
            Arrays.asList(ProjectUtils.getSources(p).getSourceGroups(AndroidConstants.SOURCES_TYPE_ANDROID_RES)),
            new Predicate<SourceGroup>() {
        @Override
        public boolean apply(SourceGroup t) {
            FileObject folder = fo.getParent();
            if (folder == null) {
                return false;
            }
            return FileUtil.isParentOf(t.getRootFolder(), fo)
                    && "xml".equals(fo.getExt())
                    && ("layout".equals(folder.getNameExt()) || folder.getNameExt().startsWith("layout-"));
        }
    });
}
 
Example #9
Source File: JSEApplicationClassChooser.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private void initCombos() {
        Sources sources = ProjectUtils.getSources(project);
        SourceGroup[] sourceGroupsJava = sources.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
        if (sourceGroupsJava == null) {
            throw new IllegalStateException(
                    NbBundle.getMessage(FXMLTemplateWizardIterator.class,
                    "MSG_ConfigureFXMLPanel_SGs_Error")); // NOI18N
        }
        support = new SourceGroupSupport(JavaProjectConstants.SOURCES_TYPE_JAVA);
        support.addSourceGroups(sourceGroupsJava); //must exist

        comboBoxSourceRoot.setModel(new DefaultComboBoxModel(support.getSourceGroups().toArray()));
//        SourceGroupSupport.SourceGroupProxy preselectedGroup = support.getParent().getCurrentSourceGroup();
//        ignoreRootCombo = true;
//        comboBoxSourceRoot.setSelectedItem(preselectedGroup);
//        ignoreRootCombo = false;
//        comboBoxPackage.getEditor().setItem(support.getParent().getCurrentPackageName());
        updatePackages();
        updateText();
        updateResult();
    }
 
Example #10
Source File: CdiUtil.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private static FileObject getDefaultBeansTargetFolder( SourceGroup[] sourceGroups,
        boolean create )
{
    if ( sourceGroups.length >0 ){
        FileObject metaInf = sourceGroups[0].getRootFolder().getFileObject( META_INF );
        if ( metaInf == null && create ){
            try {
                metaInf = FileUtil.createFolder(
                    sourceGroups[0].getRootFolder(), META_INF);
            }
            catch( IOException e ){
                Logger.getLogger( CdiUtil.class.getName() ).log( 
                        Level.WARNING, null, e );
            }
        }
        return metaInf;
    }
    return null;
}
 
Example #11
Source File: I18nServiceImpl.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private static FileObject getResourcesRoot(FileObject srcFile) {
    FileObject root = null;
    Project owner = FileOwnerQuery.getOwner(srcFile);
    if (owner != null) {
        // this is for projects that have split sources/resources folder structures.
        Sources srcs = ProjectUtils.getSources(owner);
        SourceGroup[] grps = srcs.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_RESOURCES);
        if (grps != null && grps.length > 0) {
            root = grps[0].getRootFolder();
        }
    }
    if (root == null) {
        root = ClassPath.getClassPath(srcFile, ClassPath.SOURCE).getRoots()[0];
    }
    return root;
}
 
Example #12
Source File: ServletPanel.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private void browseButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_browseButtonActionPerformed
    try {
        SourceGroup[] groups = DDUtils.getJavaSourceGroups(dObj);
        org.openide.filesystems.FileObject fo = BrowseFolders.showDialog(groups);
        if (fo!=null) {
            String className = DDUtils.getResourcePath(groups,fo);
            if (className.length()>0 && !className.equals(servletClassTF.getText())) {
                dObj.modelUpdatedFromUI();
                servletClassTF.setText(className);
                dObj.setChangedFromUI(true);
                servlet.setServletClass(className);
                dObj.setChangedFromUI(false);
                getSectionView().checkValidity();
            }
        }
    } catch (java.io.IOException ex) {}
}
 
Example #13
Source File: MainProjectManager.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("DMI_COLLECTION_OF_URLS")
private static Set<URL> getProjectRoots(Project p) {
    Set<URL> projectRoots = new HashSet<URL>(); // roots
    Sources sources = ProjectUtils.getSources(p);
    SourceGroup[] sgs = sources.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
    for (SourceGroup sg : sgs) {
        URL root;
        try {
            root = sg.getRootFolder().toURL();
            projectRoots.add(root);
        } catch (NullPointerException npe) {
            // http://www.netbeans.org/issues/show_bug.cgi?id=148076
            if (sg == null) {
                npe = Exceptions.attachMessage(npe, "Null source group returned from "+sources+" of class "+sources.getClass());
            } else if (sg.getRootFolder() == null) {
                npe = Exceptions.attachMessage(npe, "Null root folder returned from "+sg+" of class "+sg.getClass());
            }
            Exceptions.printStackTrace(npe);
        }
    }
    return projectRoots;
}
 
Example #14
Source File: J2SEPersistenceProviderTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void setUp() throws Exception {
    // in an attempt to find the cause of issue 90762
    Logger.getLogger(PersistenceScopesHelper.class.getName()).setLevel(Level.FINEST);
    // setup the project
    FileObject scratch = TestUtil.makeScratchDir(this);
    final FileObject projdir = scratch.createFolder("proj");
    MockLookup.setLayersAndInstances();
    // issue 90762: prevent AntProjectHelper from firing changes in a RP thread, which interferes with tests
    // see APH.fireExternalChange
    ProjectManager.mutex().writeAccess(new Mutex.ExceptionAction<Void>() {
        public Void run() throws Exception{
            J2SEProjectGenerator.setDefaultSourceLevel(new SpecificationVersion ("1.6"));
            J2SEProjectGenerator.createProject(FileUtil.toFile(projdir), "proj", "foo.Main", "manifest.mf", null, false);
            J2SEProjectGenerator.setDefaultSourceLevel(null);
            return null;
        }
    });
    project = ProjectManager.getDefault().findProject(projdir);
    Sources src = project.getLookup().lookup(Sources.class);
    SourceGroup[] groups = src.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
    root = groups[0].getRootFolder();
    provider = project.getLookup().lookup(J2SEPersistenceProvider.class);
    persistenceLocation = new File(FileUtil.toFile(project.getProjectDirectory().getFileObject("src")), "META-INF");
}
 
Example #15
Source File: ManagerUtil.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * Convenience method to obtain the source root folder.
 * @param project the Project object
 * @return the FileObject of the source root folder
 */
public static FileObject getSourceRoot(Project project) {
    if (project == null) {
        return null;
    }

    // Search the ${src.dir} Source Package Folder first, use the first source group if failed.
    Sources src = ProjectUtils.getSources(project);
    SourceGroup[] grp = src.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
    for (int i = 0; i < grp.length; i++) {
        if ("${src.dir}".equals(grp[i].getName())) { // NOI18N
            return grp[i].getRootFolder();
        }
    }
    if (grp.length != 0) {
        return grp[0].getRootFolder();
    }

    return null;
}
 
Example #16
Source File: SimpleTargetChooserPanelGUI.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("LeakingThisInConstructor")
@Messages("LBL_SimpleTargetChooserPanel_Name=Name and Location")
public SimpleTargetChooserPanelGUI( @NullAllowed Project project, @NonNull SourceGroup[] folders, Component bottomPanel, boolean isFolder, boolean freeFileExtension) {
    this.project = project;
    this.folders = folders.clone();
    this.isFolder = isFolder;
    this.freeFileExtension = freeFileExtension;
    this.separatorChar = getPathNameSeparator(project, folders);
    initComponents();
    
    locationComboBox.setRenderer( CELL_RENDERER );
    
    if ( bottomPanel != null ) {
        bottomPanelContainer.add( bottomPanel, java.awt.BorderLayout.CENTER );
    }
    initValues( null, null, null , true);

    setPreferredSize(PREF_DIM);

    browseButton.addActionListener( this );
    locationComboBox.addActionListener( this );
    documentNameTextField.getDocument().addDocumentListener( this );
    folderTextField.getDocument().addDocumentListener( this );
    
    setName(LBL_SimpleTargetChooserPanel_Name());
}
 
Example #17
Source File: SrcNodeTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void testSubfolderLookup() throws Exception {
    PhpProject phpProject = TestUtils.createPhpProject(getWorkDir());
    FileObject sources = ProjectPropertiesSupport.getSourcesDirectory(phpProject);
    final FileObject subfolder = sources.createFolder("emptyFolder");
    NodeList<SourceGroup> nodes = new SourcesNodeFactory().createNodes(phpProject);
    List<SourceGroup> sourceGroups = nodes.keys();
    assertFalse("Source groups should be found", sourceGroups.isEmpty());
    for (SourceGroup sourceGroup : sourceGroups) {
        Node node = nodes.node(sourceGroup);
        Lookup lookup = node.getLookup();
        assertNotNull("Fileobject should be found", lookup.lookup(FileObject.class));
        Children children = node.getChildren();
        assertTrue("Should have subnodes", children.getNodesCount(true) > 0);
        for (Node subnode : children.getNodes(true)) {
            Lookup sublookup = subnode.getLookup();
            FileObject fileObject = sublookup.lookup(FileObject.class);
            assertNotNull("Fileobject should be found", fileObject);
            assertEquals("Fileobjects should be same", subfolder, fileObject);
        }
    }
}
 
Example #18
Source File: DocBaseNodeFactory.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public VisibilityQueryDataFilter(SourceGroup sourceGroup) {
    this.sourceGroup = sourceGroup;
    if (this.sourceGroup != null) {
        this.sourceGroup.addPropertyChangeListener(this);
    }
    VisibilityQuery defaultQuery = VisibilityQuery.getDefault();
    defaultQuery.addChangeListener(WeakListeners.change(this, defaultQuery));
}
 
Example #19
Source File: FreeformSourcesTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testSources() throws Exception {
    Sources s = ProjectUtils.getSources(simple);
    SourceGroup[] groups = s.getSourceGroups(Sources.TYPE_GENERIC);
    assertEquals("one generic group", 1, groups.length);
    assertEquals("right root folder", simple.getProjectDirectory(), groups[0].getRootFolder());
    assertEquals("right display name", "Simple Freeform Project", groups[0].getDisplayName());
    groups = s.getSourceGroups("java");
    assertEquals("two Java groups", 2, groups.length);
    assertEquals("right root folder #1", simple.getProjectDirectory().getFileObject("src"), groups[0].getRootFolder());
    assertEquals("right display name #1", "Main Sources", groups[0].getDisplayName());
    assertEquals("right root folder #2", simple.getProjectDirectory().getFileObject("antsrc"), groups[1].getRootFolder());
    assertEquals("right display name #2", "Ant Task Sources", groups[1].getDisplayName());
}
 
Example #20
Source File: JaxWsServiceCreator.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private ClassPath getClassPathForFile(Project project, FileObject file) {
    SourceGroup[] srcGroups = ProjectUtils.getSources(project).getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
    for (SourceGroup srcGroup: srcGroups) {
        FileObject srcRoot = srcGroup.getRootFolder();
        if (FileUtil.isParentOf(srcRoot, file)) {
            return ClassPath.getClassPath(srcRoot, ClassPath.SOURCE);
        }
    }
    return null;
}
 
Example #21
Source File: ReactRestControllerWizardIterator.java    From nb-springboot with Apache License 2.0 5 votes vote down vote up
@Override
public void initialize(WizardDescriptor wizard) {
    this.wizard = wizard;
    wizard.putProperty(WIZ_CRUD_METHODS, false);
    wizard.putProperty(WIZ_ERROR_HANDLING, 0);
    Project project = Templates.getProject(wizard);
    Sources src = ProjectUtils.getSources(project);
    SourceGroup[] groups = src.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
    panel = JavaTemplates.createPackageChooser(project, groups, new RestControllerWizardPanel1(), true);
    // force creation of visual part
    JComponent cmp = (JComponent) panel.getComponent();
    cmp.putClientProperty(WizardDescriptor.PROP_CONTENT_SELECTED_INDEX, 0);
    cmp.putClientProperty(WizardDescriptor.PROP_CONTENT_DATA, TemplateUtils.createSteps(wizard, new String[]{cmp.getName()}));
}
 
Example #22
Source File: PackageViewFilterNode.java    From netbeans with Apache License 2.0 5 votes vote down vote up
PackageViewFilterNode(
        @NonNull final SourceGroup sourceGroup,
        @NonNull final Project project,
        @NonNull final String customizerNodeName,
        @NullAllowed final String customizerPanelName,
        final boolean generated) {
    super(PackageView.createPackageView(sourceGroup));
    this.project = project;
    this.customizerNodeName = customizerNodeName;
    this.customizerPanelName = customizerPanelName;
    this.trueSource = !generated;
}
 
Example #23
Source File: GenericSources.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public SourceGroup[] getSourceGroups(String type) {
    if (type.equals(Sources.TYPE_GENERIC)) {
        return new SourceGroup[] {
            group(p, p.getProjectDirectory(), "generic", // NOI18N
                  ProjectUtils.getInformation(p).getDisplayName(),
                  null, null),
        };
    } else {
        return new SourceGroup[0];
    }
}
 
Example #24
Source File: ProjectsRootNodePhysicalViewModeSourcesTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public TestSources(Project p) throws IOException {
    FileObject internal = FileUtil.createFolder(p.getProjectDirectory(), "src");
    FileObject external = FileUtil.createFolder(p.getProjectDirectory().getParent(), "src" + p.getProjectDirectory().getNameExt());
    
    this.arr = new SourceGroup[] {
        new TestGroup(p.getProjectDirectory()),
        new TestGroup(internal),
        new TestGroup(external),
    };
}
 
Example #25
Source File: Util.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public static SourceGroup[] getJavaSourceGroups(PUDataObject dObj) throws java.io.IOException {
    Project proj = FileOwnerQuery.getOwner(dObj.getPrimaryFile());
    if (proj == null) {
        return new SourceGroup[]{};
    }
    Sources sources = ProjectUtils.getSources(proj);
    SourceGroup[] toRet = sources.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_RESOURCES);
    if (toRet != null && toRet.length != 0) {
        return toRet;
    }
    return sources.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
}
 
Example #26
Source File: RefactoringUtil.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public static boolean isOnSourceClasspath(FileObject fo) {
    Project p = FileOwnerQuery.getOwner(fo);
    if (p==null) return false;
    if (OpenProjects.getDefault().isProjectOpen(p)) {
        SourceGroup[] gr = ProjectUtils.getSources(p).getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
        for (int j = 0; j < gr.length; j++) {
            if (fo==gr[j].getRootFolder()) return true;
            if (FileUtil.isParentOf(gr[j].getRootFolder(), fo))
                return true;
        }
        return false;
    }
    return false;
}
 
Example #27
Source File: Analyzer.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static Collection<? extends FileObject> toAnalyze(Lookup l) {
    Set<FileObject> result = new LinkedHashSet<FileObject>();

    for (FileObject fo : l.lookupAll(FileObject.class)) {
        if (fo.getMIMEType().equals(JAVA_MIME_TYPE)) {
            result.add(fo);
        }
        if (fo.isFolder()) {
            if (containsJavaFiles(fo)) {
                result.add(fo);
            }
        }
    }

    for (DataObject od : l.lookupAll(DataObject.class)) {
        FileObject primaryFile = od.getPrimaryFile();
        if (primaryFile.getMIMEType().equals(JAVA_MIME_TYPE)) {
            result.add(primaryFile);
        }
        if (primaryFile.isFolder()) {
            if (containsJavaFiles(primaryFile)) {
                result.add(primaryFile);
            }
        }
    }
    
    for (Project p : l.lookupAll(Project.class)) {
        Sources s = ProjectUtils.getSources(p);
        
        for (SourceGroup sg : s.getSourceGroups("java")) { // NOI18N
            result.add(sg.getRootFolder());
        }
    }
    
    return result;
}
 
Example #28
Source File: DependenciesScopeProvider.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public boolean initialize(Lookup context, AtomicBoolean cancel) {
    if (!JavaWhereUsedQueryPlugin.DEPENDENCIES) {
        return false;
    }
    Future<Project[]> openProjects = OpenProjects.getDefault().openProjects();

    Project[] projects;
    try {
        projects = openProjects.get();
    } catch (InterruptedException | ExecutionException ex) {
        return false;
    }

    if (projects == null || projects.length == 0) {
        return false;
    }

    Set<FileObject> srcRoots = new HashSet<>();

    for (Project project : projects) {
        ProjectInformation pi = ProjectUtils.getInformation(project);
        final SourceGroup[] sourceGroups = ProjectUtils.getSources(pi.getProject()).getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
        for (int i = 0; i < sourceGroups.length; i++) {
            srcRoots.add(sourceGroups[i].getRootFolder());
        }
    }
    if (srcRoots.isEmpty()) {
        return false;
    }
    scope = Scope.create(srcRoots, null, null, true);
    return true;
}
 
Example #29
Source File: SourcesImpl.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public SourceGroupModifierImplementation relativeTo(SourceGroup existingGroup, String... projectPart) {
    if (sgmi instanceof SourceGroupRelativeModifierImplementation) {
        return ((SourceGroupRelativeModifierImplementation)sgmi).relativeTo(existingGroup, projectPart);
    } else {
        return this;
    }
}
 
Example #30
Source File: JpaControllerSetupPanelVisual.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void updateSourceGroupPackages() {
    SourceGroup sourceGroup = (SourceGroup)locationComboBox.getSelectedItem();
    ComboBoxModel model = PackageView.createListView(sourceGroup);
    if (model.getSelectedItem()!= null && model.getSelectedItem().toString().startsWith("META-INF")
            && model.getSize() > 1) { // NOI18N
        model.setSelectedItem(model.getElementAt(1));
    }
    packageComboBox.setModel(model);
}