org.netbeans.spi.project.support.GenericSources Java Examples

The following examples show how to use org.netbeans.spi.project.support.GenericSources. 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: JavaEESourcesImpl.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private List<SourceGroup> getWebSourceGroups() {
    List<SourceGroup> sourceGroups = new ArrayList<>();

    ProjectWebRootProvider webRootProvider = project.getLookup().lookup(ProjectWebRootProvider.class);
    GradleWebProject wp = GradleWebProject.get(project);
    if (webRootProvider != null && wp != null) {
        Collection<FileObject> webRoots = webRootProvider.getWebRoots();
        String projectDirPath = wp.getWebAppDir().getAbsolutePath();
        for (FileObject webRoot : webRoots) {
            boolean isDefault = webRoot.getPath().equals(projectDirPath);
            SourceGroup g = GenericSources.group(project, webRoot, TYPE_DOC_ROOT, getDisplayName(webRoot, isDefault), null, null);
            if (isDefault) {
                sourceGroups.add(0, g);
            } else {
                sourceGroups.add(g);
            }
        }
    }
    return sourceGroups;
}
 
Example #2
Source File: PackageRenameHandlerTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public @Override void setUp() throws Exception {
    final FileObject root = TestUtil.makeScratchDir(this);
    root.createFolder("testproject");
    MockLookup.setInstances(TestUtil.testProjectFactory());
    
    SourceGroup group = GenericSources.group(ProjectManager.getDefault().findProject(root), root.createFolder("src"), "testGroup", "Test Group", null, null);
    Children ch = PackageView.createPackageView(group).getChildren();
    
    // Create folder
    FileUtil.createFolder(root, "src/foo");
    n = ch.findChild("foo");
    
    assertNotNull(n);
}
 
Example #3
Source File: MavenSourcesImpl.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * consult the SourceGroup cache, return true if anything changed..
 */
private boolean checkSourceGroupCache(@NullAllowed File rootF, String name, String displayName, Map<String, SourceGroup> groups, NbMavenProject watcher) {
    FileObject root;
    if (rootF != null) {
        watcher.addWatchedPath(Utilities.toURI(rootF));
        root = FileUtil.toFileObject(rootF);
    } else {
        root = null;
    }
    SourceGroup group = groups.get(name);
    if ((root == null || root.isData()) && group != null) {
        groups.remove(name);
        return true;
    }
    if (root == null || root.isData()) {
        return false;
    }
    boolean changed = false;
    if (group == null) {
        group = GenericSources.group(proj, root, name, displayName, null, null);
        groups.put(name, group);
        changed = true;
    } else {
        if (!group.getRootFolder().equals(root)) {
            group = GenericSources.group(proj, root, name, displayName, null, null);
            groups.put(name, group);
            changed = true;
        }
    }
    return changed;
}
 
Example #4
Source File: SourcesNodeFactory.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private SourceGroup makeJavadocDocfilesSourceGroup() {
    String propname = "javadoc.docfiles"; // NOI18N
    FileObject root = resolveFileObjectFromProperty(propname);
    if(root == null) {
        return null;
    }
    return GenericSources.group(project, root, propname, NbBundle.getMessage(ModuleLogicalView.class, "LBL_extra_javadoc_files"), null, null);
}
 
Example #5
Source File: Selenium2PhpSupportImpl.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@NbBundle.Messages("sources_display_name=Selenium Sources")
private SourceGroup getSeleniumSourceGroup(Project project) {
    FileObject dir = getSeleniumDir(project, true);
    if (dir == null) {
        return ProjectUtils.getSources(project).getSourceGroups(Sources.TYPE_GENERIC)[0];
    }
    String sourcesDisplayName = Bundle.sources_display_name();
    return GenericSources.group(project, dir, "SeleniumDir", sourcesDisplayName, null, null);
}
 
Example #6
Source File: ProjectUtils.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Get a list of sources for a project.
 * If the project has a {@link Sources} instance in its lookup,
 * that is used. Otherwise, a basic implementation is returned
 * using {@link GenericSources#genericOnly}.
 * @param p a project
 * @return a list of sources for it
 * @see Project#getLookup
 */
public static Sources getSources(@NonNull Project p) {
    Parameters.notNull("p", p); //NOI18N
    Lookup l = p.getLookup();
    Sources s = l.lookup(Sources.class);
    if (s != null) {
        return s;
    } else {
        return GenericSources.genericOnly(p);
    }
}
 
Example #7
Source File: AndroidSources.java    From NBANDROID-V2 with Apache License 2.0 5 votes vote down vote up
private SourceGroup[] groupManifest() {
    List<SourceGroup> grps = new ArrayList<>();
    File manifestFile = androidProjectModel.getDefaultConfig().getSourceProvider().getManifestFile();
    if (manifestFile != null) {
        File rootFolder = manifestFile.getParentFile();
        FileObject rootFo = FileUtil.toFileObject(rootFolder);
        grps.add(GenericSources.group(project, rootFo, AndroidConstants.ANDROID_MANIFEST_XML, AndroidConstants.ANDROID_MANIFEST_XML, null, null));
    }
    return grps.toArray(new SourceGroup[grps.size()]);
}
 
Example #8
Source File: MMKnowledgeSources.java    From netbeans-mmd-plugin with Apache License 2.0 5 votes vote down vote up
private static SourceGroup[] getSourceGroups(final Project project) {
  final String klazz = project.getClass().getName();
  LOGGER.info("Request sources for project type " + klazz);

  SourceGroup knowledgeSrc = null;
  try {
    FileObject knowledgeFolder = project.getProjectDirectory().getFileObject(KNOWLEDGE_FOLDER_NAME);
    if (knowledgeFolder == null && isKnowledgeFolderAllowedForCreation()) {
      knowledgeFolder = project.getProjectDirectory().createFolder(KNOWLEDGE_FOLDER_NAME);
    }
    if (knowledgeFolder != null) {
      final String rootKnowledgeFolderName = BUNDLE.getString("KnowledgeSourceGroup.displayName");
      knowledgeSrc = GenericSources.group(project, knowledgeFolder, KNOWLEDGE_FOLDER_NAME, rootKnowledgeFolderName, new ImageIcon(BadgeIcons.BADGED_FOLDER), new ImageIcon(BadgeIcons.BADGED_FOLDER_OPEN));
    }
    else {
      LOGGER.info("Knowledge folder is not presented in " + project);
    }
  }
  catch (IOException ex) {
    LOGGER.error("Can't make source group for knowledge folder", ex);
  }

  final SourceGroup[] result;
  if (knowledgeSrc == null) {
    result = new SourceGroup[0];
  }
  else {
    result = new SourceGroup[]{knowledgeSrc};
  }

  return result;
}
 
Example #9
Source File: SourcesImpl.java    From netbeans with Apache License 2.0 4 votes vote down vote up
/**
 * Returns an array of SourceGroup of given type. It delegates to {@link SourcesHelper}.
 * This method firstly acquire the {@link ProjectManager#mutex} in read mode then it enters
 * into the synchronized block to ensure that just one instance of the {@link SourcesHelper}
 * is created. These instance is cleared also in the synchronized block by the
 * {@link J2SESources#fireChange} method.
 */
@Override
public SourceGroup[] getSourceGroups(final String type) {
    final SourceGroup[] _cachedGroups = this.cachedGroups.get(type);
    if (_cachedGroups != null) {
        return _cachedGroups;
    }
    return ProjectManager.mutex().readAccess(new Mutex.Action<SourceGroup[]>() {
        public SourceGroup[] run() {
            Sources _delegate;
            long myEventId;
            synchronized (SourcesImpl.this) {
                if (dirty) {
                    delegate.removeChangeListener(SourcesImpl.this);
                    SourcesHelper sh = initSources();
                    sgmi = sh.createSourceGroupModifierImplementation();
                    delegate = sh.createSources();
                    delegate.addChangeListener(SourcesImpl.this);
                    dirty = false;
                }
                _delegate = delegate;
                myEventId = ++eventId;
            }
            SourceGroup[] groups = _delegate.getSourceGroups(type);
            if (type.equals(Sources.TYPE_GENERIC)) {
                FileObject libLoc = getSharedLibraryFolderLocation();
                if (libLoc != null) {
                    //#204232 only return as separate source group if not inside the default project one.
                    boolean isIncluded = false;
                    for (SourceGroup sg : groups) {
                        if (FileUtil.isParentOf(sg.getRootFolder(), libLoc)) {
                            isIncluded = true;
                            break;
                        }
                    }
                    if (!isIncluded) {
                    SourceGroup[] grps = new SourceGroup[groups.length + 1];
                    System.arraycopy(groups, 0, grps, 0, groups.length);
                    grps[grps.length - 1] = GenericSources.group(project, libLoc,
                            "sharedlibraries", // NOI18N
                            NbBundle.getMessage(SourcesImpl.class, "LibrarySourceGroup_DisplayName"),
                            null, null);
                    groups = grps;
                    }
                }
            }
            synchronized (SourcesImpl.this) {
                if (myEventId == eventId) {
                    SourcesImpl.this.cachedGroups.put(type, groups);
                }
            }
            return groups;
        }
    });
}
 
Example #10
Source File: GroovySourcesImpl.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private void addGroupIfRootExists(List<SourceGroup> groups, String rootType, String name, String displayName) {
    FileObject root = project.getProjectDirectory().getFileObject("src/" + rootType + "/groovy");
    if (root != null) {
        groups.add(GenericSources.group(project, root, name, displayName, null, null));
    }
}
 
Example #11
Source File: J2eeMavenSourcesImpl.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private WebResourceGroup(Project project, FileObject webRoot, String name, String displayName) {
    this.project = project;
    this.group = GenericSources.group(project, webRoot, name, displayName, null, null);
}