org.netbeans.api.java.project.JavaProjectConstants Java Examples

The following examples show how to use org.netbeans.api.java.project.JavaProjectConstants. 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: 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 #2
Source File: ProjectWebModule.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public FileObject[] getSourceRoots() {
    Sources sources = ProjectUtils.getSources(project);
    SourceGroup[] groups = sources.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
    
    List<FileObject> roots = new LinkedList<FileObject>();
    FileObject documentBase = getDocumentBase();
    if (documentBase != null)
        roots.add(documentBase);
    
    for (int i = 0; i < groups.length; i++) {
        roots.add(groups[i].getRootFolder());
    }
    
    FileObject[] rootArray = new FileObject[roots.size()];
    return roots.toArray(rootArray);
}
 
Example #3
Source File: ManifestHyperlinkProvider.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private static @CheckForNull FileObject findFile(FileObject manifest, String path) {
    Project prj = FileOwnerQuery.getOwner(manifest);
    if (prj == null) {
        return null;
    }
    Sources srcs = ProjectUtils.getSources(prj);
    SourceGroup[] grps = srcs.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
    if (grps.length == 0)   // #143157: there needn't to be source group (yet)
        return null;
    ClassPath cp = ClassPath.getClassPath(grps[0].getRootFolder(), ClassPath.SOURCE);
    if (cp == null) {
        return null;
    }
    path = path.trim();
    return cp.findResource(path);
}
 
Example #4
Source File: ClientDataObject.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private void refreshSourceFolders() {
    ArrayList srcRootList = new ArrayList();
    
    Project project = FileOwnerQuery.getOwner(getPrimaryFile());
    if (project != null) {
        Sources sources = ProjectUtils.getSources(project);
        SourceGroup[] groups = sources.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
        for (int i = 0; i < groups.length; i++) {
            if (WebModule.getWebModule(groups [i].getRootFolder()) != null) {
                srcRootList.add(groups [i].getRootFolder());
                DataLoaderPool.getDefault().removeOperationListener(operationListener); //avoid being added multiple times
                DataLoaderPool.getDefault().addOperationListener(operationListener);
            }
        }
    }
    srcRoots = (FileObject []) srcRootList.toArray(new FileObject [srcRootList.size()]);
}
 
Example #5
Source File: RestConfigHint.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public ChangeInfo implement() throws Exception {
    RestSupport restSupport = getSupport();
    if ( isJersey ){
        restSupport.ensureRestDevelopmentReady(RestSupport.RestConfig.DD);
    } else {
        restSupport.ensureRestDevelopmentReady(RestSupport.RestConfig.IDE);
        // XXX : package and Application class is subject to configure via UI
        SourceGroup[] groups = ProjectUtils.getSources(getProject()).getSourceGroups(
                JavaProjectConstants.SOURCES_TYPE_JAVA);
        if ( groups.length == 0){
            return null;
        }
        FileObject folder = SourceGroupSupport.getFolderForPackage(groups[0], 
                "org.netbeans.rest.application.config", true);
        RestUtils.createApplicationConfigClass(restSupport, folder, "ApplicationConfig");   // NOI18N
    }
    
    super.implement();
    return null;
}
 
Example #6
Source File: ShellProjectUtils.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public static boolean isModularProject(Project project, boolean checkModuleInfo) {
    if (project == null) { 
        return false;
    }
    JavaPlatform platform = findPlatform(project);
    if (platform == null || !isModularJDK(platform)) {
        return false;
    }
    String s = SourceLevelQuery.getSourceLevel(project.getProjectDirectory());
    if (!(s != null && new SpecificationVersion("9").compareTo(new SpecificationVersion(s)) <= 0)) {
        return false;
    }
    if (!checkModuleInfo) {
        return true;
    }
    // find module-info.java
    for (SourceGroup sg : ProjectUtils.getSources(project).getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA)) {
        if (isNormalRoot(sg)) {
            if (sg.getRootFolder().getFileObject("module-info.java") != null) { // NOI18N
                return true;
            }
        }
    }
    return false;
}
 
Example #7
Source File: MavenWsitProvider.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public boolean isWsitSupported() {
    // check if the FI or TX class exists - this means we don't need to add the library
    SourceGroup[] sgs = ProjectUtils.getSources(project).getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
    if ((sgs != null) && (sgs.length > 0)) {
        ClassPath classPath = ClassPath.getClassPath(sgs[0].getRootFolder(),ClassPath.COMPILE);
        FileObject txFO = classPath.findResource("com/sun/xml/ws/api/pipe/helper/AbstractPipeImpl.class"); // NOI18N
        if (txFO != null) {
            return true;
        } else {
            txFO = classPath.findResource("com/sun/xml/ws/tx/service/TxServerPipe.class"); // NOI18N
            if (txFO != null) {
                return true;
            }
        }
    }
    return false;
}
 
Example #8
Source File: ProjectHelper.java    From jeddict with Apache License 2.0 6 votes vote down vote up
/**
 * Gets the {@link SourceGroup} of the given <code>project</code> which
 * contains the given <code>fqClassName</code>.
 *
 * @param project the project; must not be null.
 * @param fqClassName the fully qualified name of the class whose source
 * group to get; must not be empty or null.
 * @return the source group containing the given <code>fqClassName</code> or
 * <code>null</code> if the class was not found in the source groups of the
 * project.
 */
public static SourceGroup getClassSourceGroup(Project project, String fqClassName) {
    Parameters.notNull("project", project); //NOI18N
    Parameters.notEmpty("fqClassName", fqClassName); //NOI18N

    String classFile = fqClassName.replace('.', '/') + JAVA_EXT_SUFFIX; // NOI18N
    SourceGroup[] sourceGroups = ProjectUtils.getSources(project).getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);

    for (SourceGroup sourceGroup : sourceGroups) {
        FileObject classFO = sourceGroup.getRootFolder().getFileObject(classFile);
        if (classFO != null) {
            return sourceGroup;
        }
    }
    return null;
}
 
Example #9
Source File: LogicalViewProviderImpl.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private static boolean isOtherProjectSource(
        @NonNull final FileObject fo,
        @NonNull final Project me) {
    final Project owner = FileOwnerQuery.getOwner(fo);
    if (owner == null) {
        return false;
    }
    if (me.equals(owner)) {
        return false;
    }
    for (SourceGroup sg : ProjectUtils.getSources(owner).getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA)) {
        if (FileUtil.isParentOf(sg.getRootFolder(), fo)) {
            return true;
        }
    }
    return false;
}
 
Example #10
Source File: GradleSourcesImplTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void testGeneratedSources() throws Exception { // #187595
    FileObject d = createGradleProject(
            "apply plugin: 'java'\n" +
            "sourceSets { main { java { srcDirs = [ 'src', 'build/gen-src' ] }}}");
    FileObject src = FileUtil.createFolder(d, "src/");
    FileObject gsrc = FileUtil.createFolder(d, "build/gen-src");
    FileObject source = src.createData("Whatever.java");
    FileObject generated = gsrc.createData("WhateverGen.java");
    Project prj = openProject(d);
    Sources srcs = ProjectUtils.getSources(prj);
    SourceGroup[] groups = srcs.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
    assertEquals(2, groups.length);
    assertTrue(groups[0].contains(source));
    assertFalse(groups[0].contains(generated));
    assertTrue(groups[1].contains(generated));
    assertFalse(groups[1].contains(source));
}
 
Example #11
Source File: SourceGroups.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * Gets the {@link SourceGroup} of the given <code>project</code> which contains the
 * given <code>fqClassName</code>.
 * 
 * @param project the project; must not be null.
 * @param fqClassName the fully qualified name of the class whose 
 * source group to get; must not be empty or null.
 * @return the source group containing the given <code>fqClassName</code> or <code>null</code>
 * if the class was not found in the source groups of the project.
 */
public static SourceGroup getClassSourceGroup(Project project, String fqClassName) {
    Parameters.notNull("project", project); //NOI18N
    Parameters.notEmpty("fqClassName", fqClassName); //NOI18N

    String classFile = fqClassName.replace('.', '/') + ".java"; // NOI18N
    SourceGroup[] sourceGroups = ProjectUtils.getSources(project).getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
    
    for (SourceGroup sourceGroup : sourceGroups) {
        FileObject classFO = sourceGroup.getRootFolder().getFileObject(classFile);
        if (classFO != null) {
            return sourceGroup;
        }
    }
    return null;
}
 
Example #12
Source File: Utils.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
     */
    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 #13
Source File: MavenSourcesImplTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void testNewlyCreatedSourceGroup() throws Exception { // #200969
    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");
    Project p = ProjectManager.getDefault().findProject(d);
    Sources s = ProjectUtils.getSources(p);
    SourceGroup[] grps = s.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
    assertEquals(1, grps.length);
    assertEquals(main, grps[0].getRootFolder());
    MockChangeListener l = new MockChangeListener();
    s.addChangeListener(l);
    SourceGroup g2 = SourceGroupModifier.createSourceGroup(p, JavaProjectConstants.SOURCES_TYPE_JAVA, JavaProjectConstants.SOURCES_HINT_TEST);
    l.assertEvent();
    grps = s.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
    assertEquals(2, grps.length);
    assertEquals(main, grps[0].getRootFolder());
    assertEquals(g2, grps[1]);
}
 
Example #14
Source File: SourceGroups.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * Gets the {@link SourceGroup} of the given <code>project</code> which contains the
 * given <code>fqClassName</code>.
 * 
 * @param project the project; must not be null.
 * @param fqClassName the fully qualified name of the class whose 
 * source group to get; must not be empty or null.
 * @return the source group containing the given <code>fqClassName</code> or <code>null</code>
 * if the class was not found in the source groups of the project.
 */
public static SourceGroup getClassSourceGroup(Project project, String fqClassName) {
    Parameters.notNull("project", project); //NOI18N
    Parameters.notEmpty("fqClassName", fqClassName); //NOI18N

    String classFile = fqClassName.replace('.', '/') + ".java"; // NOI18N
    SourceGroup[] sourceGroups = ProjectUtils.getSources(project).getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
    
    for (SourceGroup sourceGroup : sourceGroups) {
        FileObject classFO = sourceGroup.getRootFolder().getFileObject(classFile);
        if (classFO != null) {
            return sourceGroup;
        }
    }
    return null;
}
 
Example #15
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 #16
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 #17
Source File: MetroConfigLoader.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
    * Loads the default definition from metro-default.xml file from the metro jars.
    * @param project
    * @return
    */
   public MetroConfig loadDefaultMetroConfig(Project project) {
       SourceGroup[] sgs = ProjectUtils.getSources(project).getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
       ClassPath classPath = ClassPath.getClassPath(sgs[0].getRootFolder(),ClassPath.COMPILE);
       if ( classPath == null ){
    return null;
}
       FileObject defFO = classPath.findResource("META-INF/metro-default.xml"); // NOI18N
       try {
           if (defFO != null) {
               return loadMetroConfig(defFO.getURL());
           }
       } catch (FileStateInvalidException ex) {
           Exceptions.printStackTrace(ex);
       }
       return null;
   }
 
Example #18
Source File: WhiteListUpdater.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * A helper which which is here only for lack of better place - shows dialog whether
 * deployment should continue when whitelist violations are present in project.
 * @param p
 * @return 
 */
@NbBundle.Messages({
        "MSG_WhitelistViolations=Whitelist violations were detected in project being deployed. Are you sure you want to continue deployment?",
        "MSG_Dialog_Title=Continue deployment?"
})
public static boolean isWhitelistViolated(Project p) {
    SourceGroup[] sgs = ProjectUtils.getSources(p).getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
    if (sgs.length == 0) {
        return false;
    }
    Collection problems = WhiteListIndex.getDefault().
            getWhiteListViolations(sgs[0].getRootFolder(), null, "oracle");
    if (problems.size() > 0) {
        if (DialogDisplayer.getDefault().notify(
                new Confirmation(Bundle.MSG_WhitelistViolations(), Bundle.MSG_Dialog_Title(), NotifyDescriptor.YES_NO_OPTION)) != NotifyDescriptor.YES_OPTION) {
            return true;
        }
    }
    return false;
}
 
Example #19
Source File: WSITRenamePackagePlugin.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private FileObject getJavaFile( String fqn, Project project ) {
    SourceGroup[] sourceGroups = ProjectUtils.getSources(project)
            .getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
    if (sourceGroups.length > 0) {
        ClassPath classPath = null;
        for (int i = 0; i < sourceGroups.length; i++) {
            classPath = ClassPath.getClassPath(
                    sourceGroups[i].getRootFolder(), ClassPath.SOURCE);
            if (classPath != null) {
                FileObject javaClass = classPath.findResource(fqn.replace(
                        '.', '/') + ".java"); // NOI18N
                if (javaClass != null) {
                    return javaClass;
                }
            }
        }
    }
    return null;
}
 
Example #20
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 #21
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 #22
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 #23
Source File: LogicalViewProviderImpl.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private static boolean isOtherProjectSource(
        @NonNull final FileObject fo,
        @NonNull final Project me) {
    final Project owner = FileOwnerQuery.getOwner(fo);
    if (owner == null) {
        return false;
    }
    if (me.equals(owner)) {
        return false;
    }
    for (SourceGroup sg : ProjectUtils.getSources(owner).getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA)) {
        if (FileUtil.isParentOf(sg.getRootFolder(), fo)) {
            return true;
        }
    }
    return false;
}
 
Example #24
Source File: AddDependencyAction.java    From NBANDROID-V2 with Apache License 2.0 6 votes vote down vote up
private void findCompileTimeDependencies(NbAndroidProject project, List<ArtifactData> compileDependecies) {
    final ClassPathProvider cpProvider = project.getLookup().lookup(ClassPathProvider.class);
    if (cpProvider != null) {
        Sources srcs = ProjectUtils.getSources(project);
        SourceGroup[] sourceGroups = srcs.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
        Set<FileObject> roots = Sets.newHashSet();
        for (SourceGroup sg : sourceGroups) {
            roots.add(sg.getRootFolder());
        }
        Iterable<ClassPath> compileCPs = Iterables.transform(roots, new Function<FileObject, ClassPath>() {

            @Override
            public ClassPath apply(FileObject f) {
                return cpProvider.findClassPath(f, ClassPath.COMPILE);
            }
        });
        ClassPath compileCP
                = ClassPathSupport.createProxyClassPath(Lists.newArrayList(compileCPs).toArray(new ClassPath[0]));
        if (cpProvider instanceof AndroidClassPath) {
            for (FileObject cpRoot : compileCP.getRoots()) {
                ArtifactData lib = ((AndroidClassPath) cpProvider).getArtifactData(cpRoot.toURL());
                compileDependecies.add(lib);
            }
        }
    }
}
 
Example #25
Source File: MoveMembersPanel.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private void updateRoots() {
    Sources sources = ProjectUtils.getSources(project);
    groups = sources.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);

    int preselectedItem = 0;
    for (int i = 0; i < groups.length; i++) {
        if (this.fileObject != null) {
            try {
                if (groups[i].contains(this.fileObject)) {
                    preselectedItem = i;
                }
            } catch (IllegalArgumentException e) {
                // XXX this is a poor abuse of exception handling
            }
        }
    }

    // Setup comboboxes 
    rootComboBox.setModel(new DefaultComboBoxModel(groups));
    if (groups.length > 0) {
        rootComboBox.setSelectedIndex(preselectedItem);
    }
}
 
Example #26
Source File: ProjectUtilities.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public static boolean isJavaProject(Project project) {
    if (project == null) return false;
    
    Sources sources = ProjectUtils.getSources(project);
    SourceGroup[] sourceGroups = sources.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);

    return sourceGroups.length > 0;
}
 
Example #27
Source File: Hk2JavaEEPlatformImpl.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private boolean addJars(final Project project, Collection<URL> jars ){
    final List<URL> urls = new ArrayList<>();
    for (URL url : jars) {
        if ( FileUtil.isArchiveFile( url)){
            urls.add(FileUtil.getArchiveRoot(url));
        }
    }
    final SourceGroup[] sourceGroups = ProjectUtils.getSources(project).getSourceGroups(
        JavaProjectConstants.SOURCES_TYPE_JAVA);
    if (sourceGroups == null || sourceGroups.length < 1) {
       return false;
    }
    final FileObject sourceRoot = sourceGroups[0].getRootFolder();
    try {
        final String classPathType;
        if ( hasJee6Profile() ){
            classPathType = JavaClassPathConstants.COMPILE_ONLY;
        }
        else {
            classPathType = ClassPath.COMPILE;
        }
        ProjectClassPathModifier.addRoots(urls.toArray( new URL[ urls.size()]), 
                sourceRoot, classPathType );
    } 
    catch (UnsupportedOperationException | IOException ex) {
        return false;
    }
    return true;
}
 
Example #28
Source File: WebSocketEndpointIterator.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private SourceGroup[] getJavaSourceGroups( Project project ) {
    SourceGroup[] sourceGroups = ProjectUtils.getSources(project).getSourceGroups(
            JavaProjectConstants.SOURCES_TYPE_JAVA);
    Set<FileObject> testRoots = getTestRoots(project);
    List<SourceGroup> list= new ArrayList<SourceGroup>(sourceGroups.length);
    for (SourceGroup sourceGroup : sourceGroups) {
        if ( !testRoots.contains( sourceGroup.getRootFolder())){
            list.add( sourceGroup );
        }
    }
    return list.toArray( new SourceGroup[list.size()]);
}
 
Example #29
Source File: GradleFileLocator.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private ClassPath getProjectClasspath(Project p) {
    ClassPath result;
    ClassPathProvider cpp = p.getLookup().lookup(ClassPathProvider.class);
    Set<FileObject> roots = new HashSet<>();
    Sources sources = ProjectUtils.getSources(p);
    if (sources != null) {
        SourceGroup[] groups = sources.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
        for (SourceGroup group : groups) {
            roots.add(group.getRootFolder());
        }
    }

    Set<ClassPath> setCP = new HashSet<>();
    if (cpp != null) {
        for (FileObject file : roots) {
            ClassPath path = cpp.findClassPath(file, ClassPath.COMPILE);
            setCP.add(path);
        }
    }

    for (ClassPath cp : setCP) {
        FileObject[] rootsCP = cp.getRoots();
        for (FileObject fo : rootsCP) {
            FileObject[] aaa = SourceForBinaryQuery.findSourceRoots(fo.toURL()).getRoots();
            roots.addAll(Arrays.asList(aaa));
        }
    }
    //TODO: Use something more specific in the future Ticket #81
    JavaPlatform platform = JavaPlatform.getDefault();

    if (platform != null) {
        roots.addAll(Arrays.asList(platform.getSourceFolders().getRoots()));
    }
    result = ClassPathSupport.createClassPath(roots.toArray(new FileObject[roots.size()]));
    return result;
}
 
Example #30
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 + "";
}