org.netbeans.api.project.Sources Java Examples

The following examples show how to use org.netbeans.api.project.Sources. 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: AntServices.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public Sources initSources(Project project, CommonProjectHelper h, Values e) {
    AntProjectHelperImpl ih = (AntProjectHelperImpl) h;
    PropertyEvaluatorImpl ip = (PropertyEvaluatorImpl) e;
    SourcesHelper sourcesHelper = new SourcesHelper(project, ih.delegate, ip.delegate);
    sourcesHelper.sourceRoot("${" + ClientSideProjectConstants.PROJECT_SOURCE_FOLDER + "}") //NOI18N
            .displayName(org.openide.util.NbBundle.getMessage(ClientSideProjectSources.class, "SOURCES"))
            .add() // adding as principal root, continuing configuration
            .type(WebClientProjectConstants.SOURCES_TYPE_HTML5).add(); // adding as typed root
    sourcesHelper.sourceRoot("${" + ClientSideProjectConstants.PROJECT_SITE_ROOT_FOLDER + "}") //NOI18N
            .displayName(org.openide.util.NbBundle.getMessage(ClientSideProjectSources.class, "SITE_ROOT"))
            .add() // adding as principal root, continuing configuration
            .type(WebClientProjectConstants.SOURCES_TYPE_HTML5_SITE_ROOT).add(); // adding as typed root
    sourcesHelper.sourceRoot("${" + ClientSideProjectConstants.PROJECT_TEST_FOLDER + "}") //NOI18N
            .displayName(org.openide.util.NbBundle.getMessage(ClientSideProjectSources.class, "UNIT_TESTS"))
            .add() // adding as principal root, continuing configuration
            .type(WebClientProjectConstants.SOURCES_TYPE_HTML5_TEST).add(); // adding as typed root
    sourcesHelper.sourceRoot("${" + ClientSideProjectConstants.PROJECT_TEST_SELENIUM_FOLDER + "}") //NOI18N
            .displayName(org.openide.util.NbBundle.getMessage(ClientSideProjectSources.class, "SELENIUM_TESTS"))
            .add() // adding as principal root, continuing configuration
            .type(WebClientProjectConstants.SOURCES_TYPE_HTML5_TEST_SELENIUM).add(); // adding as typed root
    sourcesHelper.registerExternalRoots(FileOwnerQuery.EXTERNAL_ALGORITHM_TRANSIENT);
    return sourcesHelper.createSources();
}
 
Example #2
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 #3
Source File: DefaultPlugin.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * Finds a Java source group the given file belongs to.
 * 
 * @param  file  {@code FileObject} to find a {@code SourceGroup} for
 * @return  the found {@code SourceGroup}, or {@code null} if the given
 *          file does not belong to any Java source group
 */
private static SourceGroup findSourceGroup(FileObject file) {
    final Project project = FileOwnerQuery.getOwner(file);
    if (project == null) {
        return null;
    }

    Sources src = ProjectUtils.getSources(project);
    SourceGroup[] srcGrps = src.getSourceGroups(SOURCES_TYPE_JAVA);
    for (SourceGroup srcGrp : srcGrps) {
        FileObject rootFolder = srcGrp.getRootFolder();
        if (((file == rootFolder) || FileUtil.isParentOf(rootFolder, file)) 
                && srcGrp.contains(file)) {
            return srcGrp;
        }
    }
    return null;
}
 
Example #4
Source File: PersistenceEnvironmentImpl.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private static SourceGroup[] getSourceGroups(Project project) {
    Sources projectSources = ProjectUtils.getSources(project);
    // first, try to get resources
    SourceGroup[] resources = projectSources.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_RESOURCES);
    if (resources.length > 0) {
        return resources;
    }
    // try to create it
    SourceGroup resourcesSourceGroup = SourceGroupModifier.createSourceGroup(
        project, JavaProjectConstants.SOURCES_TYPE_RESOURCES, JavaProjectConstants.SOURCES_HINT_MAIN);
    if (resourcesSourceGroup != null) {
        return new SourceGroup[] {resourcesSourceGroup};
    }
    // fallback to java sources
    return projectSources.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
}
 
Example #5
Source File: DefaultPlugin.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * Finds a Java source group the given file belongs to.
 * 
 * @param  file  {@literal FileObject} to find a {@literal SourceGroup} for
 * @return  the found {@literal SourceGroup}, or {@literal null} if the given
 *          file does not belong to any Java source group
 */
private static SourceGroup findSourceGroup(FileObject file) {
    final Project project = FileOwnerQuery.getOwner(file);
    if (project == null) {
        return null;
    }

    Sources src = ProjectUtils.getSources(project);
    SourceGroup[] srcGrps = src.getSourceGroups(SOURCES_TYPE_JAVA);
    for (SourceGroup srcGrp : srcGrps) {
        FileObject rootFolder = srcGrp.getRootFolder();
        if (((file == rootFolder) || FileUtil.isParentOf(rootFolder, file)) 
                && srcGrp.contains(file)) {
            return srcGrp;
        }
    }
    return null;
}
 
Example #6
Source File: AppClientPersistenceProviderTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public void setUp() throws Exception {
    MockLookup.setLayersAndInstances();

    // in an attempt to find the cause of issue 90762
    Logger.getLogger(PersistenceScopesHelper.class.getName()).setLevel(Level.FINEST);
    // setup the project
    File f = new File(getDataDir().getAbsolutePath(), "projects/ApplicationClient1");
    project = (Project) ProjectSupport.openProject(f);
    Sources src = project.getLookup().lookup(Sources.class);
    SourceGroup[] groups = src.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
    root = groups[0].getRootFolder();
    provider = project.getLookup().lookup(AppClientPersistenceProvider.class);
    persistenceLocation = project.getProjectDirectory().getFileObject("src/conf");

    FileObject persistenceXml = persistenceLocation.getFileObject("persistence.xml");
    if (persistenceXml != null) {
        persistenceXml.delete();
    }
}
 
Example #7
Source File: ProjectsRootNode.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private static Union2<LogicalViewProvider,org.openide.util.Pair<Sources,SourceGroup[]>> createData(
        final Project p,
        final int type) {
    switch (type) {
        case LOGICAL_VIEW:
            final LogicalViewProvider lvp = p.getLookup().lookup(LogicalViewProvider.class);
            if (lvp != null) {
                return Union2.createFirst(lvp);
            }
        case PHYSICAL_VIEW:
            final Sources s = ProjectUtils.getSources(p);
            final SourceGroup[] groups = s.getSourceGroups(Sources.TYPE_GENERIC);                
            return Union2.createSecond(org.openide.util.Pair.of(s, groups));
        default:
            throw new IllegalArgumentException(Integer.toString(type));
    }
}
 
Example #8
Source File: NewFileWizardIterator.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private SourceGroup[] getSourceGroups(Project project, FileObject file) {
    // #239027
    if (FileUtil.getMIMEType(file, JSON_MIME_TYPE, null) != null) {
        return ProjectUtils.getSources(project).getSourceGroups(Sources.TYPE_GENERIC);
    }
    ClientSideProject clientSideProject = getClientSideProject(project);
    if (clientSideProject == null) {
        // #231347
        return ProjectUtils.getSources(project).getSourceGroups(Sources.TYPE_GENERIC);
    }
    SourceGroup[] allGroups = ClientSideProjectUtilities.getSourceGroups(project);
    if (!FileUtilities.isHtmlFile(file)
            && !FileUtilities.isCssFile(file)) {
        // not html or css -> return all source groups
        return allGroups;
    }
    // html or css file -> return only sources or site root
    List<SourceGroup> groups = new ArrayList<>();
    groups.addAll(Arrays.asList(ClientSideProjectUtilities.getSourceGroups(project, WebClientProjectConstants.SOURCES_TYPE_HTML5_SITE_ROOT)));
    groups.addAll(Arrays.asList(ClientSideProjectUtilities.getSourceGroups(project, WebClientProjectConstants.SOURCES_TYPE_HTML5)));
    if (!groups.isEmpty()) {
        return groups.toArray(new SourceGroup[groups.size()]);
    }
    return allGroups;
}
 
Example #9
Source File: MavenSourcesImplTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void testManuallyDeletedSourceGroup() throws Exception { // #204545
    TestFileUtils.writeFile(d, "pom.xml", "<project><modelVersion>4.0.0</modelVersion><groupId>g</groupId><artifactId>a</artifactId><version>0</version></project>");
    FileObject main = FileUtil.createFolder(d, "src/main/java");
    FileObject test = FileUtil.createFolder(d, "src/test/java");
    Project p = ProjectManager.getDefault().findProject(d);
    Sources s = ProjectUtils.getSources(p);
    SourceGroup[] grps = s.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
    assertEquals(2, grps.length);
    assertEquals(main, grps[0].getRootFolder());
    assertEquals(test, grps[1].getRootFolder());
    MockChangeListener l = new MockChangeListener();
    s.addChangeListener(l);
    test.getParent().delete();
    l.assertEvent();
    grps = s.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
    assertEquals(1, grps.length);
    assertEquals(main, grps[0].getRootFolder());
}
 
Example #10
Source File: ProjectHelper.java    From jeddict with Apache License 2.0 6 votes vote down vote up
public static SourceGroup[] getSourceGroups(Project project) {
    SourceGroup[] sourceGroups = null;

    Sources sources = ProjectUtils.getSources(project);
    SourceGroup[] docRoot = sources.getSourceGroups(TYPE_DOC_ROOT);
    SourceGroup[] srcRoots = getJavaSourceGroups(project);

    if (docRoot != null && srcRoots != null) {
        sourceGroups = new SourceGroup[docRoot.length + srcRoots.length];
        System.arraycopy(docRoot, 0, sourceGroups, 0, docRoot.length);
        System.arraycopy(srcRoots, 0, sourceGroups, docRoot.length, srcRoots.length);
    }

    if (sourceGroups == null || sourceGroups.length == 0) {
        sourceGroups = sources.getSourceGroups(Sources.TYPE_GENERIC);
    }
    return sourceGroups;
}
 
Example #11
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 #12
Source File: GenerateDOMScannerAction.java    From netbeans with Apache License 2.0 6 votes vote down vote up
protected boolean enable(Node[] node) {
    if (node.length == 0) {
        return false;
    }
    DataObject dobj = node[0].getLookup().lookup(DataObject.class);
    if (dobj == null) {
        return false;
    }
    FileObject fo = dobj.getPrimaryFile();
    Project project = FileOwnerQuery.getOwner(fo);
    if(project == null)
        return false;
    Sources sources = ProjectUtils.getSources(project);
    SourceGroup[] srcGrps = sources.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
    if (srcGrps == null || srcGrps.length == 0) {
        return false;
    } else {
        return true;
    }
}
 
Example #13
Source File: EntityClassesConfigurationPanel.java    From jeddict with Apache License 2.0 6 votes vote down vote up
boolean isBeanValidationSupported() {
    if (project == null) {
        return false;
    }

    final String notNullAnnotation = "javax.validation.constraints.NotNull";    //NOI18N
    Sources sources = ProjectUtils.getSources(project);
    SourceGroup groups[] = sources.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
    if (groups == null || groups.length < 1) {
        return false;
    }
    SourceGroup firstGroup = groups[0];
    FileObject fo = firstGroup.getRootFolder();
    ClassPath compile = ClassPath.getClassPath(fo, ClassPath.COMPILE);
    if (compile == null) {
        return false;
    }
    return compile.findResource(notNullAnnotation.replace('.', '/') + ".class") != null;//NOI18N
}
 
Example #14
Source File: MiscPrivateUtilities.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public static ClassPath getClassPath(Project project, String type) {
    ClassPathProvider provider = project.getLookup().lookup(ClassPathProvider.class);
    if (provider == null) {
        return null;
    }
    Sources sources = project.getLookup().lookup(Sources.class);
    if (sources == null) {
        return null;
    }
    SourceGroup[] sourceGroups = sources.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
    List<ClassPath> classPaths = new ArrayList<ClassPath>(sourceGroups.length);
    for (SourceGroup sourceGroup : sourceGroups) {
        String sourceGroupId = sourceGroup.getName();
        if (sourceGroupId != null && sourceGroupId.contains("test")) {
            // NOI18N
            continue;
        }
        FileObject rootFolder = sourceGroup.getRootFolder();
        ClassPath path = provider.findClassPath(rootFolder, type);
        classPaths.add(path);
    }
    return ClassPathSupport.createProxyClassPath(classPaths.toArray(new ClassPath[classPaths.size()]));
}
 
Example #15
Source File: TaskProvider.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public synchronized void setScope(TaskScanningScope scope, Callback callback) {
    //cancel all current operations:
    cancelAllCurrent();
    
    this.scope = scope;
    this.callback = callback;
    
    if (scope == null || callback == null)
        return ;
    
    for (FileObject file : scope.getLookup().lookupAll(FileObject.class)) {
        enqueue(new Work(file, callback));
    }
    
    for (Project p : scope.getLookup().lookupAll(Project.class)) {
        for (SourceGroup generic : ProjectUtils.getSources(p).getSourceGroups(Sources.TYPE_GENERIC)) {
            for (FileObject root : Utilities.findIndexedRootsUnderDirectory(p, generic.getRootFolder())) {
                enqueue(new Work(root, callback));
            }
        }
    }
}
 
Example #16
Source File: AngularJsDelcarationFinderTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
protected void setUp() throws Exception {
    super.setUp();
    AbstractIndenter.inUnitTestRun = true;

    MockMimeLookup.setInstances(MimePath.parse("text/javascript"), JsTokenId.javascriptLanguage());
    HtmlIndentTaskFactory htmlReformatFactory = new HtmlIndentTaskFactory();
    MockMimeLookup.setInstances(MimePath.parse("text/html"), htmlReformatFactory, new HtmlKit("text/html"), HTMLTokenId.language());
    
    FileObject srcFo = getTestFile("angularTestProject");
    Sources sources = new TestSources(srcFo);
    ClassPathProvider classpathProvider = new TestClassPathProvider(srcFo, createClassPathsForTest());
    MockLookup.setInstances(new TestProjectFactory(classpathProvider, sources));
    
    IndexingManager.getDefault().refreshIndexAndWait(srcFo.getURL(), null, true);
    
}
 
Example #17
Source File: WSUtils.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public static void removeImplClass(Project project, String implClass) {
    Sources sources = project.getLookup().lookup(Sources.class);
    String resource = implClass.replace('.','/')+".java"; //NOI18N
    if (sources!=null) {
        SourceGroup[] srcGroup = sources.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
        for (int i=0;i<srcGroup.length;i++) {
            final FileObject srcRoot = srcGroup[i].getRootFolder();
            final FileObject implClassFo = srcRoot.getFileObject(resource);
            if (implClassFo!=null) {
                try {
                    FileSystem fs = implClassFo.getFileSystem();
                    fs.runAtomicAction(new AtomicAction() {
                        public void run() {
                            deleteFile(implClassFo);
                        }
                    });
                } catch (IOException ex) {
                    ErrorManager.getDefault().notify(ex);
                }
                return;
            }
        }
    }
}
 
Example #18
Source File: SourcesHelperTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void testSourceRootDeletion() throws Exception {
    // Cf. #40845. Need to fire a change if a root is deleted while project is open.
    Sources s = sh.createSources();
    SourceGroup[] groups = s.getSourceGroups("java");
    assertEquals("should have src1dir plus src3dir", 2, groups.length);
    assertEquals("group #1 is src1dir", src1dir, groups[0].getRootFolder());
    assertEquals("group #2 is src3dir", src3dir, groups[1].getRootFolder());
    MockChangeListener l = new MockChangeListener();
    s.addChangeListener(l);
    src3dir.delete();
    l.msg("got a change after src3dir deleted").assertEvent();
    groups = s.getSourceGroups("java");
    assertEquals("should have just src1dir", 1, groups.length);
    assertEquals("group #1 is src1dir", src1dir, groups[0].getRootFolder());
    src1dir.delete();
    l.msg("got a change after src1dir deleted").assertEvent();
    groups = s.getSourceGroups("java");
    assertEquals("should have no dirs", 0, groups.length);
    FileObject src5dir = scratch.createFolder("nonesuch");
    l.msg("got a change after src5dir created").assertEvent();
    groups = s.getSourceGroups("java");
    assertEquals("should have src15dir now", 1, groups.length);
    assertEquals("group #1 is src5dir", src5dir, groups[0].getRootFolder());
}
 
Example #19
Source File: LogicalHandlerWizard.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void initialize(WizardDescriptor wizard) {
        
        wiz = wizard;
        project = Templates.getProject(wiz);
        SourceGroup[] sourceGroups = SourceGroups.getJavaSourceGroups(project);
        
        //create the Java Project chooser
//        firstPanel = JavaTemplates.createPackageChooser(project, sourceGroups, new BottomPanel());
        
        if (sourceGroups.length == 0) {
            SourceGroup[] genericSourceGroups = ProjectUtils.getSources(project).getSourceGroups(Sources.TYPE_GENERIC);
            firstPanel = new FinishableProxyWizardPanel(Templates.createSimpleTargetChooser(project, genericSourceGroups, new BottomPanel()), sourceGroups, false);
        } else
            firstPanel = new FinishableProxyWizardPanel(JavaTemplates.createPackageChooser(project, sourceGroups, new BottomPanel(), true));
        
        JComponent c = (JComponent) firstPanel.getComponent();
        Utils.changeLabelInComponent(c, NbBundle.getMessage(LogicalHandlerWizard.class, "LBL_JavaTargetChooserPanelGUI_ClassName_Label"), //NOI18N
                NbBundle.getMessage(LogicalHandlerWizard.class, "LBL_LogicalHandler_Name") ); //NOI18N
        c.putClientProperty(WizardDescriptor.PROP_CONTENT_DATA, //NOI18N
                HANDLER_STEPS);
        c.putClientProperty(WizardDescriptor.PROP_CONTENT_SELECTED_INDEX, //NOI18N
                Integer.valueOf(0));
        c.getAccessibleContext().setAccessibleDescription
                (HANDLER_STEPS[0]);
        wizardPanels = new WizardDescriptor.Panel[] {firstPanel};
    }
 
Example #20
Source File: MavenWSITEditor.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public static FileObject getClientConfigFolder(Project p) {
    WsitProvider wsitProvider = p.getLookup().lookup(WsitProvider.class);
    if (wsitProvider != null) {
        return wsitProvider.getConfigFilesFolder(true);
    }

    // proceed with default folder (META-INF) if the provider is not found
    FileObject folder = null;
    Sources sources = ProjectUtils.getSources(p);
    if (sources == null) return null;
    SourceGroup[] sourceGroups = sources.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);        
    if ((sourceGroups != null) && (sourceGroups.length > 0)) {
        folder = sourceGroups[0].getRootFolder();
        if (folder != null) {
            folder = folder.getFileObject("META-INF");
        }
        if ((folder == null) || (!folder.isValid())) {
            try {
                folder = sourceGroups[0].getRootFolder().createFolder("META-INF");
            } catch (IOException ex) {
                logger.log(Level.SEVERE, null, ex);
            }
        }
    }
    return folder;
}
 
Example #21
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 #22
Source File: GenerateDocumentHandlerAction.java    From netbeans with Apache License 2.0 6 votes vote down vote up
protected boolean enable(Node[] node) {
    if (node.length == 0) {
        return false;
    }
    DataObject dobj = node[0].getLookup().lookup(DataObject.class);
    if (dobj == null) {
        return false;
    }
    FileObject fo = dobj.getPrimaryFile();
    Project project = FileOwnerQuery.getOwner(fo);
    if(project == null)
        return false;
    Sources sources = ProjectUtils.getSources(project);
    SourceGroup[] srcGrps = sources.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
    if (srcGrps == null || srcGrps.length == 0) {
        return false;
    } else {
        return true;
    }
}
 
Example #23
Source File: CustomClientPhpCodeGenerator.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private FileObject getSourceRootFolder() {
    Sources sources = ProjectUtils.getSources(getProject());
    SourceGroup[] groups = sources.getSourceGroups("PHPSOURCE");
    FileObject rootFolder = getProject().getProjectDirectory();
    if (groups != null && groups.length > 0 && groups[0] != null &&
            groups[0].getRootFolder() != null) {
        rootFolder = groups[0].getRootFolder();
    }
    return rootFolder;
}
 
Example #24
Source File: DelegateToOwnerLookupTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testDelegateLookup() throws IOException {
    //Assert we have enclosing project
    assertNotNull(owner);
    //Assert we have correct Lookup in enclosing project
    assertNotNull(owner.getLookup().lookup(Sources.class));
    assertNotNull(owner.getLookup().lookup(SourcesImpl.class));
    assertNotNull(owner.getLookup().lookup(ProjectOpenedHook.class));
    assertNotNull(owner.getLookup().lookup(ProjectOpenedHookImpl.class));
    assertNotNull(owner.getLookup().lookup(ProjectInformation.class));
    assertNotNull(owner.getLookup().lookup(ProjectInformationImpl.class));
    //Test delegating lookup
    final Lookup lkp = ProjectConvertors.createDelegateToOwnerLookup(automaticProjectHome);
    assertNotNull(lkp);
    //Test do not have black listed services
    assertNull(lkp.lookup(ProjectOpenedHook.class));
    assertNull(lkp.lookup(ProjectOpenedHookImpl.class));
    assertNull(lkp.lookup(ProjectInformation.class));
    assertNull(lkp.lookup(ProjectInformationImpl.class));
    //Test have other services
    assertNotNull(lkp.lookup(Sources.class));
    assertNotNull(lkp.lookup(SourcesImpl.class));
    //Close lookup
    ((Closeable)lkp).close();
    //Nothing should be in the Lookup
    assertNull(lkp.lookup(ProjectOpenedHook.class));
    assertNull(lkp.lookup(ProjectOpenedHookImpl.class));
    assertNull(lkp.lookup(ProjectInformation.class));
    assertNull(lkp.lookup(ProjectInformationImpl.class));
    assertNull(lkp.lookup(Sources.class));
    assertNull(lkp.lookup(SourcesImpl.class));
}
 
Example #25
Source File: FreeformSourcesTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testSourceRootChanges() throws Exception {
    FileObject top = FileUtil.toFileObject(copyFolder(FileUtil.toFile(egdirFO.getFileObject("extsrcroot"))));
    FreeformProject extsrcroot_ = (FreeformProject) ProjectManager.getDefault().findProject(top.getFileObject("proj"));
    Sources s = ProjectUtils.getSources(extsrcroot_);
    SourceGroup[] groups = s.getSourceGroups("java");
    assertEquals("one Java group", 1, groups.length);
    assertEquals("right root folder", top.getFileObject("src"), groups[0].getRootFolder());
    TestCL l = new TestCL();
    s.addChangeListener(l);
    Element data = extsrcroot_.getPrimaryConfigurationData();
    Element folders = XMLUtil.findElement(data, "folders", FreeformProjectType.NS_GENERAL);
    assertNotNull("have <folders>", folders);
    List<Element> sourceFolders = XMLUtil.findSubElements(folders);
    assertEquals("have 2 <source-folder>s", 2, sourceFolders.size());
    Element sourceFolder = sourceFolders.get(1);
    Element location = XMLUtil.findElement(sourceFolder, "location", FreeformProjectType.NS_GENERAL);
    assertNotNull("have <location>", location);
    NodeList nl = location.getChildNodes();
    assertEquals("one child (text)", 1, nl.getLength());
    location.removeChild(nl.item(0));
    location.appendChild(location.getOwnerDocument().createTextNode("../src2"));
    extsrcroot_.putPrimaryConfigurationData(data);
    assertEquals("got a change in Sources", 1, l.changeCount());
    groups = s.getSourceGroups("java");
    assertEquals("one Java group", 1, groups.length);
    assertEquals("right root folder", top.getFileObject("src2"), groups[0].getRootFolder());
}
 
Example #26
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 #27
Source File: ProjectJaxWsWebServiceView.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private Node[] createServiceNodes() {
    Service[] services = jaxWsModel.getServices();
    if (services == null || services.length <= 0) {
        return new Node[0];
    }
    Sources sources = (Sources) getProject().getLookup().lookup(Sources.class);
    ArrayList<FileObject> roots = new ArrayList<FileObject>();
    if (sources != null) {
        SourceGroup[] groups = sources.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
        if (groups != null) {
            for (SourceGroup group : groups) {
                roots.add(group.getRootFolder());
            }
        }
    }
    if (roots.isEmpty()) {
        return new Node[0];
    }
    ArrayList<Node> nodes = new ArrayList<Node>();
    for (Service service : services) {
        String implClass = service.getImplementationClass();
        if (implClass == null) {
            continue;
        }
        for (FileObject srcRoot : roots) {
            FileObject implClassFo = srcRoot.getFileObject(implClass.replace('.', '/') + ".java");
            if (implClassFo != null) {
                nodes.add(new JaxWsNode(jaxWsModel, service, srcRoot, implClassFo));
                break;
            }
        }
    }
    return nodes.toArray(new Node[nodes.size()]);
}
 
Example #28
Source File: ClientSideProjectUtilities.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public static SourceGroup[] getSourceGroups(Project project) {
    Sources sources = ProjectUtils.getSources(project);
    List<SourceGroup> res = new ArrayList<SourceGroup>();
    res.addAll(Arrays.asList(sources.getSourceGroups(WebClientProjectConstants.SOURCES_TYPE_HTML5)));
    res.addAll(Arrays.asList(sources.getSourceGroups(WebClientProjectConstants.SOURCES_TYPE_HTML5_SITE_ROOT)));
    res.addAll(Arrays.asList(sources.getSourceGroups(WebClientProjectConstants.SOURCES_TYPE_HTML5_TEST)));
    res.addAll(Arrays.asList(sources.getSourceGroups(WebClientProjectConstants.SOURCES_TYPE_HTML5_TEST_SELENIUM)));
    return res.toArray(new SourceGroup[res.size()]);
}
 
Example #29
Source File: AndroidProjects.java    From NBANDROID-V2 with Apache License 2.0 5 votes vote down vote up
public static FileObject findResFolder(Project project) {
    Sources sources = ProjectUtils.getSources(project);
    SourceGroup[] resGroup = sources.getSourceGroups(AndroidConstants.SOURCES_TYPE_ANDROID_RES);
    if (resGroup.length > 0) {
        return resGroup[0].getRootFolder();
    }
    return null;
}
 
Example #30
Source File: SelectHandlerPanel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
protected Node[] createNodes(String key) {
    Node n = null;
    List<Node> sourceNodes = new LinkedList<Node>();
    if (key == KEY_SOURCES) {
        Sources sources = ProjectUtils.getSources(project);
        SourceGroup[] groups = sources.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
        for(int i = 0; i < groups.length; i++){
            sourceNodes.add(PackageView.createPackageView(groups[i]));
        }
    }
    return sourceNodes.<Node>toArray(new Node[sourceNodes.size()]);
}