本文整理汇总了Java中org.netbeans.api.project.ProjectUtils.getSources方法的典型用法代码示例。如果您正苦于以下问题:Java ProjectUtils.getSources方法的具体用法?Java ProjectUtils.getSources怎么用?Java ProjectUtils.getSources使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.netbeans.api.project.ProjectUtils
的用法示例。
在下文中一共展示了ProjectUtils.getSources方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: findSourceGroup
import org.netbeans.api.project.ProjectUtils; //导入方法依赖的package包/类
/**
* 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(JavaProjectConstants.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;
}
示例2: getSourceRoots
import org.netbeans.api.project.ProjectUtils; //导入方法依赖的package包/类
private static void getSourceRoots(final Lookup.Provider project, final boolean traverse, Set<Lookup.Provider> projects, Set<FileObject> roots) {
if (project instanceof Project) {
final Sources sources = ProjectUtils.getSources((Project)project);
for (SourceGroup sg : sources.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA)) {
roots.add(sg.getRootFolder());
}
if (traverse) {
// process possible subprojects
//mkleint: see subprojectprovider for official contract, maybe classpath should be checked instead? see #210465
SubprojectProvider spp = project.getLookup().lookup(SubprojectProvider.class);
if (spp != null) {
for (Project p : spp.getSubprojects()) {
if (projects.add(p)) {
getSourceRoots(p, traverse, projects, roots);
}
}
}
}
}
}
示例3: createData
import org.netbeans.api.project.ProjectUtils; //导入方法依赖的package包/类
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));
}
}
示例4: getProjectRoots
import org.netbeans.api.project.ProjectUtils; //导入方法依赖的package包/类
@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;
}
示例5: isValidPanel
import org.netbeans.api.project.ProjectUtils; //导入方法依赖的package包/类
@Override
public boolean isValidPanel() {
setErrorMessage("");
Sources sources=ProjectUtils.getSources(project);
SourceGroup groups[]=sources.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
if(groups == null || groups.length == 0) {
setErrorMessage(NbBundle.getMessage(PersistenceUnitWizardDescriptor.class,"ERR_JavaSourceGroup")); //NOI18N
return false;
}
if( !providerCombo.isEnabled() ) {
setErrorMessage(NbBundle.getMessage(PersistenceUnitWizardPanelDS.class,"LBL_Wait")); //NOI18N
return false;
}
try{
if (!isNameValid()){
return false;
}
} catch (InvalidPersistenceXmlException ipx){
setErrorMessage(NbBundle.getMessage(PersistenceUnitWizardDescriptor.class,"ERR_InvalidPersistenceXml", ipx.getPath())); //NOI18N
return false;
}
return true;
}
示例6: getSourceRoot
import org.netbeans.api.project.ProjectUtils; //导入方法依赖的package包/类
/**
* 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("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;
}
示例7: getDataFiles
import org.netbeans.api.project.ProjectUtils; //导入方法依赖的package包/类
public List<FileObject> getDataFiles() {
List<FileObject> files = new ArrayList<FileObject>();
Sources srcs = ProjectUtils.getSources(project);
SourceGroup[] grps = srcs.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
for (int i = 0; i < grps.length; i++) {
FileObject srcRoot = grps[i].getRootFolder();
if (srcRoot.getPath().endsWith("test/unit/src")) { // NOI18N
addFile("test", files); // NOI18N
} else {
files.add(srcRoot);
}
}
return files;
}
示例8: testNewlyCreatedSourceGroup
import org.netbeans.api.project.ProjectUtils; //导入方法依赖的package包/类
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]);
}
示例9: sourcesNode
import org.netbeans.api.project.ProjectUtils; //导入方法依赖的package包/类
/**
* Prepare node structure showing sources
* @param prj the project to select from
* @param filter NodeFilter used to filter only relevant information
* @return root Node of source files from <code>prj</code> filtered
* by <code>filter</code>
**/
static public Node sourcesNode(Project prj, FilteredNode.NodeFilter filter) {
Sources src = ProjectUtils.getSources(prj);
SourceGroup[] srcgrps = src.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
java.util.List<Node> nodes = new ArrayList<Node>();
for (SourceGroup srcGrp : srcgrps) {
try {
FileObject rfo = srcGrp.getRootFolder();
FilteredNode node = new FilteredNode(DataObject.find(rfo).getNodeDelegate(),
filter);
// node.setName(srcGrp.getName());
node.setDisplayName(srcGrp.getDisplayName());
// node.setIcon(srcGrp.getIcon());
nodes.add(node);
} catch (org.openide.loaders.DataObjectNotFoundException ex) {}
}
return createRootFor(nodes, prj);
}
示例10: isInScope
import org.netbeans.api.project.ProjectUtils; //导入方法依赖的package包/类
@Override
public boolean isInScope( FileObject resource ) {
if( null == resource || null == currentProjects )
return false;
for( Project p : currentProjects ) {
Sources sources = ProjectUtils.getSources( p );
SourceGroup[] groups = sources.getSourceGroups( Sources.TYPE_GENERIC );
for( SourceGroup group : groups ) {
FileObject rootFolder = group.getRootFolder();
if( FileUtil.isParentOf( rootFolder, resource ) || rootFolder.equals( resource ) )
return true;
}
}
return false;
}
示例11: findFile
import org.netbeans.api.project.ProjectUtils; //导入方法依赖的package包/类
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);
}
示例12: getSourceGroup
import org.netbeans.api.project.ProjectUtils; //导入方法依赖的package包/类
private static SourceGroup getSourceGroup(FileObject file, Project prj) {
Sources src = ProjectUtils.getSources(prj);
SourceGroup[] srcgrps = src.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
for (SourceGroup srcGrp : srcgrps) {
if (file == srcGrp.getRootFolder())
return srcGrp;
}
return null;
}
示例13: getSourceRoot
import org.netbeans.api.project.ProjectUtils; //导入方法依赖的package包/类
private static FileObject getSourceRoot(Project prj) {
Sources sources = ProjectUtils.getSources(prj);
if (sources != null) {
SourceGroup[] srcGroups = sources.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
if (srcGroups != null && srcGroups.length>0) {
return srcGroups[0].getRootFolder();
}
}
return null;
}
示例14: getSourceGroups
import org.netbeans.api.project.ProjectUtils; //导入方法依赖的package包/类
public static SourceGroup[] getSourceGroups(FileObject fObj) {
Project proj = FileOwnerQuery.getOwner(fObj);
SourceGroup[] sg = new SourceGroup[] {};
if (proj != null) {
Sources sources = ProjectUtils.getSources(proj);
sg = sources.getSourceGroups("doc_root");
// if (sg.length == 0)
// sg = sources.getSourceGroups(Sources.TYPE_GENERIC);
}
return sg;
}
示例15: isValidPanel
import org.netbeans.api.project.ProjectUtils; //导入方法依赖的package包/类
public boolean isValidPanel() {
setErrorMessage("");
Sources sources=ProjectUtils.getSources(project);
SourceGroup groups[]=sources.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
if(groups == null || groups.length == 0) {
setErrorMessage(NbBundle.getMessage(PersistenceUnitWizardDescriptor.class,"ERR_JavaSourceGroup")); //NOI18N
return false;
}
if( !libraryCombo.isEnabled() ) {
setErrorMessage(NbBundle.getMessage(PersistenceUnitWizardPanelJdbc.class,"LBL_Wait")); //NOI18N
return false;
}
if (!(libraryCombo.getSelectedItem() instanceof Provider)) {
return false;
}
if (!(jdbcCombo.getSelectedItem() instanceof DatabaseConnection)) {
return false;
}
try{
if (!isNameValid()){
return false;
}
} catch (InvalidPersistenceXmlException ipx){
setErrorMessage(NbBundle.getMessage(PersistenceUnitWizardDescriptor.class,"ERR_InvalidPersistenceXml", ipx.getPath())); //NOI18N
return false;
}
return true;
}