Java源码示例:org.netbeans.spi.project.support.GenericSources

示例1
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;
}
 
示例2
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);
}
 
示例3
/**
 * 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;
}
 
示例4
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);
}
 
示例5
@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);
}
 
示例6
/**
 * 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);
    }
}
 
示例7
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()]);
}
 
示例8
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;
}
 
示例9
/**
 * 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;
        }
    });
}
 
示例10
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));
    }
}
 
示例11
private WebResourceGroup(Project project, FileObject webRoot, String name, String displayName) {
    this.project = project;
    this.group = GenericSources.group(project, webRoot, name, displayName, null, null);
}