本文整理汇总了Java中org.netbeans.api.java.project.JavaProjectConstants类的典型用法代码示例。如果您正苦于以下问题:Java JavaProjectConstants类的具体用法?Java JavaProjectConstants怎么用?Java JavaProjectConstants使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
JavaProjectConstants类属于org.netbeans.api.java.project包,在下文中一共展示了JavaProjectConstants类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: isOnSourceClasspath
import org.netbeans.api.java.project.JavaProjectConstants; //导入依赖的package包/类
public static boolean isOnSourceClasspath(FileObject fo) {
Project p = FileOwnerQuery.getOwner(fo);
if (p==null) {
return false;
}
if (OpenProjects.getDefault().isProjectOpen(p)) {
SourceGroup[] gr = ProjectUtils.getSources(p).getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
for (int j = 0; j < gr.length; j++) {
if (fo==gr[j].getRootFolder()) {
return true;
}
if (FileUtil.isParentOf(gr[j].getRootFolder(), fo)) {
return true;
}
}
return false;
}
return false;
}
示例2: initCombos
import org.netbeans.api.java.project.JavaProjectConstants; //导入依赖的package包/类
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();
}
示例3: getJPAVersion
import org.netbeans.api.java.project.JavaProjectConstants; //导入依赖的package包/类
/**
* method check target compile classpath for presence of persitence classes of certain version
* returns max supported specification
* @param project
* @return
*/
public static String getJPAVersion(Project target)
{
String version=null;
Sources sources=ProjectUtils.getSources(target);
SourceGroup groups[]=sources.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
SourceGroup firstGroup=groups[0];
FileObject fo=firstGroup.getRootFolder();
ClassPath compile=ClassPath.getClassPath(fo, ClassPath.COMPILE);
if(compile.findResource("javax/persistence/criteria/CriteriaUpdate.class")!=null) {
version=Persistence.VERSION_2_1;
} else if(compile.findResource("javax/persistence/criteria/JoinType.class")!=null) {
version=Persistence.VERSION_2_0;
} else if(compile.findResource("javax/persistence/Entity.class")!=null) {
version=Persistence.VERSION_1_0;
}
return version;
}
示例4: getSourceRoots
import org.netbeans.api.java.project.JavaProjectConstants; //导入依赖的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);
}
}
}
}
}
}
示例5: getProjectClassPath
import org.netbeans.api.java.project.JavaProjectConstants; //导入依赖的package包/类
/**
* Returns the project classpath including project build paths.
* Can be used to set classpath for custom classloader.
*
* @param projectFile may not be used in method realization
* @return List of java.io.File objects representing each entry on the classpath.
*/
@Override
public List<URL> getProjectClassPath(FileObject projectFile) {
List<URL> projectClassPathEntries = new ArrayList<URL>();
SourceGroup[] sgs = ProjectUtils.getSources(project).getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
if (sgs.length < 1) {
return projectClassPathEntries;
}
FileObject sourceRoot = sgs[0].getRootFolder();
ClassPathProvider cpProv = project.getLookup().lookup(ClassPathProvider.class);
ClassPath cp = cpProv.findClassPath(sourceRoot, ClassPath.EXECUTE);
if(cp == null){
cp = cpProv.findClassPath(sourceRoot, ClassPath.COMPILE);
}
for (ClassPath.Entry cpEntry : cp.entries()) {
if(cpEntry.isValid()){
//if project isn't build, there may be number of invalid entries and may be in some other cases
projectClassPathEntries.add(cpEntry.getURL());
}
}
return projectClassPathEntries;
}
示例6: getSourceGroups
import org.netbeans.api.java.project.JavaProjectConstants; //导入依赖的package包/类
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);
}
示例7: getTestParameter
import org.netbeans.api.java.project.JavaProjectConstants; //导入依赖的package包/类
private String getTestParameter(FileObject[] activatedFOs, Project project, FileObject testDir) {
if(activatedFOs.length == 1 && project.getProjectDirectory().equals(activatedFOs[0])) {
return Utils.RUN_SELENIUM_TESTS_REGEXP;
}
String testParameter = "";
SourceGroup[] sourceGroups = ProjectUtils.getSources(project).getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
SourceGroup sourceGroup = findGroup(sourceGroups, activatedFOs);
if (sourceGroup != null) {
for (FileObject fo : activatedFOs) {
String relativePath = FileUtil.getRelativePath(sourceGroup.getRootFolder(), fo);
if (relativePath == null) {
continue;
}
if (!testParameter.isEmpty()) {
testParameter = testParameter.concat(",");
}
testParameter = testParameter + relativePath + "/" + Utils.RUN_SELENIUM_TESTS_REGEXP;
}
}
return testParameter;
}
示例8: getDataFiles
import org.netbeans.api.java.project.JavaProjectConstants; //导入依赖的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;
}
示例9: testJARFileIsProduced
import org.netbeans.api.java.project.JavaProjectConstants; //导入依赖的package包/类
public void testJARFileIsProduced() throws Exception {
AntArtifact[] arts = AntArtifactQuery.findArtifactsByType(loadersProject, JavaProjectConstants.ARTIFACT_TYPE_JAR);
assertEquals("one artifact produced", 1, arts.length);
assertEquals("correct project", loadersProject, arts[0].getProject());
assertEquals("correct type", JavaProjectConstants.ARTIFACT_TYPE_JAR, arts[0].getType());
assertEquals("correct ID", "module", arts[0].getID());
assertEquals("correct location",
Collections.singletonList(URI.create("../nbbuild/netbeans/" + TestBase.CLUSTER_PLATFORM + "/modules/org-openide-loaders.jar")),
Arrays.asList(arts[0].getArtifactLocations()));
assertEquals("correct script", nbRoot().getFileObject("openide.loaders/build.xml"), arts[0].getScriptFile());
assertEquals("correct build target", "netbeans", arts[0].getTargetName());
assertEquals("correct clean target", "clean", arts[0].getCleanTargetName());
assertEquals("no properties", new Properties(), arts[0].getProperties());
arts = AntArtifactQuery.findArtifactsByType(javaProjectProject, JavaProjectConstants.ARTIFACT_TYPE_JAR);
assertEquals("one artifact produced", 1, arts.length);
assertEquals("correct location",
Collections.singletonList(URI.create("../nbbuild/netbeans/" + TestBase.CLUSTER_JAVA + "/modules/org-netbeans-modules-java-project.jar")),
Arrays.asList(arts[0].getArtifactLocations()));
}
示例10: getClassChooserPanel
import org.netbeans.api.java.project.JavaProjectConstants; //导入依赖的package包/类
/**
* Returns a panel for choosing name and target location of the test
* class. If the panel already exists, returns the existing panel,
* otherwise creates a new panel.
*
* @return existing panel or a newly created panel if it did not exist
*/
private WizardDescriptor.Panel<WizardDescriptor> getClassChooserPanel() {
final Project project = Templates.getProject(wizard);
if (classChooserPanel == null || project != lastSelectedProject) {
SourceGroupModifier.createSourceGroup(project, JavaProjectConstants.SOURCES_TYPE_JAVA, JavaProjectConstants.SOURCES_HINT_TEST);
final JUnitUtils utils = new JUnitUtils(project);
if (utils.getSourcesToTestsMap(true).isEmpty()) {
classChooserPanel = new StepProblemMessage(
project,
NbBundle.getMessage(EmptyTestCaseWizardIterator.class,
"MSG_NoTestSourceGroup")); //NOI18N
} else {
if (classChooserPanel == null) {
classChooserPanel = new SimpleTestStepLocation();
}
((SimpleTestStepLocation) classChooserPanel).setUp(utils);
}
}
lastSelectedProject = project;
return classChooserPanel;
}
示例11: testIncludesExcludes
import org.netbeans.api.java.project.JavaProjectConstants; //导入依赖的package包/类
public void testIncludesExcludes() throws Exception {
SourceGroup g = ProjectUtils.getSources(project).getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA)[0];
assertEquals(sources, g.getRootFolder());
FileObject objectJava = FileUtil.createData(sources, "java/lang/Object.java");
FileObject jcJava = FileUtil.createData(sources, "javax/swing/JComponent.java");
FileObject doc = FileUtil.createData(sources, "javax/swing/doc-files/index.html");
assertTrue(g.contains(objectJava));
assertTrue(g.contains(jcJava));
assertTrue(g.contains(doc));
Method projectOpened = ProjectOpenedHook.class.getDeclaredMethod("projectOpened");
projectOpened.setAccessible(true);
projectOpened.invoke(project.getLookup().lookup(ProjectOpenedHook.class));
EditableProperties ep = helper.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH);
assertEquals("includes/excludes were initialized to defaults", "**", ep.getProperty(ProjectProperties.INCLUDES));
assertEquals("includes/excludes were initialized to defaults", "", ep.getProperty(ProjectProperties.EXCLUDES));
ep.setProperty(ProjectProperties.INCLUDES, "javax/swing/");
ep.setProperty(ProjectProperties.EXCLUDES, "**/doc-files/");
helper.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, ep);
pm.saveProject(project);
assertFalse(g.contains(objectJava));
assertTrue(g.contains(jcJava));
assertFalse(g.contains(doc));
}
示例12: findProjectImportedModules
import org.netbeans.api.java.project.JavaProjectConstants; //导入依赖的package包/类
/**
* Returns set of modules imported by the project. Adds to the passed collection
* if not null. Module names from `required' clause will be returned
*
* @param project the project
* @param in optional; the collection
* @return original collection or a new one with imported modules added
*/
public static Collection<String> findProjectImportedModules(Project project, Collection<String> in) {
Collection<String> result = in != null ? in : new HashSet<>();
if (project == null) {
return result;
}
for (SourceGroup sg : org.netbeans.api.project.ProjectUtils.getSources(project).getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA)) {
if (isNormalRoot(sg)) {
ClasspathInfo cpi = ClasspathInfo.create(sg.getRootFolder());
ClassPath mcp = cpi.getClassPath(PathKind.COMPILE);
for (FileObject r : mcp.getRoots()) {
URL u = URLMapper.findURL(r, URLMapper.INTERNAL);
String modName = SourceUtils.getModuleName(u);
if (modName != null) {
result.add(modName);
}
}
}
}
return result;
}
示例13: isOnSourceClasspath
import org.netbeans.api.java.project.JavaProjectConstants; //导入依赖的package包/类
public static boolean isOnSourceClasspath(FileObject fo) {
Project p = FileOwnerQuery.getOwner(fo);
if (p==null) return false;
Project[] opened = OpenProjects.getDefault().getOpenProjects();
for (int i = 0; i<opened.length; i++) {
if (p.equals(opened[i]) || opened[i].equals(p)) {
SourceGroup[] gr = ProjectUtils.getSources(p).getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
for (int j = 0; j < gr.length; j++) {
if (fo==gr[j].getRootFolder()) return true;
if (FileUtil.isParentOf(gr[j].getRootFolder(), fo))
return true;
}
return false;
}
}
return false;
}
示例14: getClasspathInfo
import org.netbeans.api.java.project.JavaProjectConstants; //导入依赖的package包/类
public ClasspathInfo getClasspathInfo() {
if (cpi != null) {
return cpi;
}
FileObject fileObject = project.getProjectDirectory();
SourceGroup[] grp = org.netbeans.api.project.ProjectUtils.getSources(project).getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
List<FileObject> roots = new ArrayList<>(grp.length);
for (SourceGroup sg : grp) {
roots.add(sg.getRootFolder());
}
return cpi = ClasspathInfo.create(
ClassPath.getClassPath(fileObject, ClassPath.BOOT), // JDK classes
ClassPath.EMPTY,
ClassPathSupport.createClassPath(roots.toArray(new FileObject[roots.size()]))
);
}
示例15: areSourceRootsOwned
import org.netbeans.api.java.project.JavaProjectConstants; //导入依赖的package包/类
/**
* Checks whether any of Eclipse source roots is already owned by a project.
* If it is then abort import and tell user to open that project instead.
* Internal source roots beneath the project directory do not pose this problem, as
* {@link FileOwnerQuery} should consider the new project to be the default owner of anything
* underneath it.
* @param model a model of the project being considered for import
* @param nbProjectDir the proposed directory to use as the NetBeans {@linkplain Project#getProjectDirectory project directory}
* @param importProblems problems to append to in case this returns true
* @return true if the import would be blocked by ownership issues; false normally
*/
public static boolean areSourceRootsOwned(ProjectImportModel model, File nbProjectDir, List<String> importProblems) {
for (File sourceRootFile : model.getEclipseSourceRootsAsFileArray()) {
if (sourceRootFile.getAbsolutePath().startsWith(nbProjectDir.getAbsolutePath())) {
continue;
}
FileObject fo = FileUtil.toFileObject(sourceRootFile);
if (fo == null) { // #148256
continue;
}
Project p = FileOwnerQuery.getOwner(fo);
if (p != null) {
for (SourceGroup sg : ProjectUtils.getSources(p).getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA)) {
if (fo.equals(sg.getRootFolder())) {
importProblems.add(NbBundle.getMessage(EclipseProject.class, "MSG_SourceRootOwned", // NOI18N
model.getProjectName(), sourceRootFile.getPath(),
FileUtil.getFileDisplayName(p.getProjectDirectory())));
return true;
}
}
}
}
return false;
}