当前位置: 首页>>代码示例>>Java>>正文


Java ProjectUtils类代码示例

本文整理汇总了Java中org.netbeans.api.project.ProjectUtils的典型用法代码示例。如果您正苦于以下问题:Java ProjectUtils类的具体用法?Java ProjectUtils怎么用?Java ProjectUtils使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ProjectUtils类属于org.netbeans.api.project包,在下文中一共展示了ProjectUtils类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: isOnSourceClasspath

import org.netbeans.api.project.ProjectUtils; //导入依赖的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;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:20,代码来源:RefactoringUtil.java

示例2: remove

import org.netbeans.api.project.ProjectUtils; //导入依赖的package包/类
boolean remove() {
    final ClassPathModifier cpm = project.getLookup().lookup(ClassPathModifier.class);
    boolean success = false;
    if (cpm != null) {
        try {
            cpm.removeAntArtifacts(
                    new AntArtifact[]{onArt},
                    new URI[] {onLoc},
                    root,
                    ClassPath.COMPILE);
            success = true;
        } catch (IOException | UnsupportedOperationException ex) {
            LOG.log(
                    Level.INFO,
                    "Cannot fix dependencies in project: {0}",  //NOI18N
                    ProjectUtils.getInformation(project).getDisplayName());
        }
    }
    return success;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:21,代码来源:ProjectOperations.java

示例3: isOtherProjectSource

import org.netbeans.api.project.ProjectUtils; //导入依赖的package包/类
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;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:18,代码来源:LogicalViewProviders.java

示例4: 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;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:25,代码来源:JavaUtils.java

示例5: getJPAVersion

import org.netbeans.api.project.ProjectUtils; //导入依赖的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;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:24,代码来源:PersistenceUtils.java

示例6: populateAccessory

import org.netbeans.api.project.ProjectUtils; //导入依赖的package包/类
/**
 * Set up GUI fields according to the requested project.
 * @param project a subproject, or null
 */
private void populateAccessory( Project project ) {
    
    DefaultListModel model = (DefaultListModel)jListArtifacts.getModel();
    model.clear();
    jTextFieldName.setText(project == null ? "" : ProjectUtils.getInformation(project).getDisplayName()); //NOI18N
    
    if ( project != null ) {
        
        List<AntArtifact> artifacts = new ArrayList<AntArtifact>();
        for (int i=0; i<artifactTypes.length; i++) {
            artifacts.addAll (Arrays.asList(AntArtifactQuery.findArtifactsByType(project, artifactTypes[i])));
        }
        
        for(AntArtifact artifact : artifacts) {
            URI uris[] = artifact.getArtifactLocations();
            for( int y = 0; y < uris.length; y++ ) {
                model.addElement( new AntArtifactItem(artifact, uris[y]));
            }
        }
        jListArtifacts.setSelectionInterval(0, model.size());
    }
    
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:28,代码来源:AntArtifactChooser.java

示例7: getListCellRendererComponent

import org.netbeans.api.project.ProjectUtils; //导入依赖的package包/类
public Component getListCellRendererComponent(
        JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
    // #93658: GTK needs name to render cell renderer "natively"
    setName("ComboBox.listRenderer"); // NOI18N

    String text = null;
    if (!(value instanceof Project)) {
        text = value.toString();
    } else {
        ProjectInformation pi = ProjectUtils.getInformation((Project) value);
        text = pi.getDisplayName();
        setIcon(pi.getIcon());
    }
    setText(text);

    if ( isSelected ) {
        setBackground(list.getSelectionBackground());
        setForeground(list.getSelectionForeground());
    }
    else {
        setBackground(list.getBackground());
        setForeground(list.getForeground());
    }

    return this;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:27,代码来源:WizardUtils.java

示例8: getCandidateName

import org.netbeans.api.project.ProjectUtils; //导入依赖的package包/类
/**
 *@return an initial name for a persistence unit, i.e. a name that
 * is unique.
 */
public static String getCandidateName(Project project) {
    String candidateNameBase = ProjectUtils.getInformation(project).getName() + "PU"; //NOI18N
    try {
        if (!ProviderUtil.persistenceExists(project)) {
            return candidateNameBase;
        }
        PUDataObject pudo = ProviderUtil.getPUDataObject(project);
        Persistence persistence = pudo.getPersistence();

        int suffix = 2;
        PersistenceUnit[] punits = persistence.getPersistenceUnit();
        String candidateName = candidateNameBase;
        while (!isUnique(candidateName, punits)) {
            candidateName = candidateNameBase + suffix++;
        }
        return candidateName;
    } catch (InvalidPersistenceXmlException ipex) {
        // just log, the user is notified about invalid persistence.xml when
        // the panel is validated
        Logger.getLogger("global").log(Level.FINE, "Invalid persistence.xml found", ipex); //NOI18N
    }
    return candidateNameBase;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:28,代码来源:Util.java

示例9: initialize

import org.netbeans.api.project.ProjectUtils; //导入依赖的package包/类
public void initialize(Project project, FileObject targetFolder) {
    this.project = project;
    
    projectTextField.setText(ProjectUtils.getInformation(project).getDisplayName());
    
    SourceGroup[] sourceGroups = SourceGroups.getJavaSourceGroups(project);
    SourceGroupUISupport.connect(locationComboBox, sourceGroups);
    
    packageComboBox.setRenderer(PackageView.listRenderer());
    
    updatePackageComboBox();
    
    if (targetFolder != null) {
        // set default source group and package cf. targetFolder
        SourceGroup targetSourceGroup = SourceGroups.getFolderSourceGroup(sourceGroups, targetFolder);
        if (targetSourceGroup != null) {
            locationComboBox.setSelectedItem(targetSourceGroup);
            String targetPackage = SourceGroups.getPackageForFolder(targetSourceGroup, targetFolder);
            if (targetPackage != null) {
                packageComboBoxEditor.setText(targetPackage);
            }
        }
    }
    createDropScriptCheckbox.setVisible(false);//isn't supported yet
    uniqueName();
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:27,代码来源:DBScriptPanel.java

示例10: getJavaSource

import org.netbeans.api.project.ProjectUtils; //导入依赖的package包/类
public static JavaSource getJavaSource(Document doc) {
    FileObject fileObject = NbEditorUtilities.getFileObject(doc);
    if (fileObject == null) {
        return null;
    }
    Project project = FileOwnerQuery.getOwner(fileObject);
    if (project == null) {
        return null;
    }
    // XXX this only works correctly with projects with a single sourcepath,
    // but we don't plan to support another kind of projects anyway (what about Maven?).
    // mkleint: Maven has just one sourceroot for java sources, the config files are placed under
    // different source root though. JavaProjectConstants.SOURCES_TYPE_RESOURCES
    SourceGroup[] sourceGroups = ProjectUtils.getSources(project).getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
    for (SourceGroup sourceGroup : sourceGroups) {
        return JavaSource.create(ClasspathInfo.create(sourceGroup.getRootFolder()));
    }
    return null;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:20,代码来源:HibernateEditorUtil.java

示例11: getProjectClassPath

import org.netbeans.api.project.ProjectUtils; //导入依赖的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;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:30,代码来源:PersistenceEnvironmentImpl.java

示例12: getSourceGroups

import org.netbeans.api.project.ProjectUtils; //导入依赖的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);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:17,代码来源:PersistenceEnvironmentImpl.java

示例13: getDisplayName

import org.netbeans.api.project.ProjectUtils; //导入依赖的package包/类
@NbBundle.Messages({
    "# {0} project directory",
    "LBL_ProjectShellName=Java Shell for {0}"
})
public synchronized String getDisplayName() {
    if (displayName != null) {
        return displayName;
    } else {
        String dn = ProjectUtils.getInformation(project).getDisplayName();
        if (dn != null) {
            return dn;
        } else {
            return Bundle.LBL_ProjectShellName(project.getProjectDirectory().getPath());
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:17,代码来源:ShellAgent.java

示例14: findProjectModules

import org.netbeans.api.project.ProjectUtils; //导入依赖的package包/类
public static Set<String>   findProjectModules(Project project, Set<String> in) {
    Set<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)) {
            FileObject fo = sg.getRootFolder().getFileObject("module-info.java");
            if (fo == null) {
                continue;
            }
            URL u = URLMapper.findURL(sg.getRootFolder(), URLMapper.INTERNAL);
            BinaryForSourceQuery.Result r = BinaryForSourceQuery.findBinaryRoots(u);
            for (URL u2 : r.getRoots()) {
                String modName = SourceUtils.getModuleName(u2, true);
                if (modName != null) {
                    result.add(modName);
                }
            }
        }
    }
    return result;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:25,代码来源:ShellProjectUtils.java

示例15: GroupNode

import org.netbeans.api.project.ProjectUtils; //导入依赖的package包/类
public GroupNode(Project project, SourceGroup group, boolean isProjectDir, DataFolder dataFolder ) {
    super( dataFolder.getNodeDelegate(),
           dataFolder.createNodeChildren( VISIBILITY_QUERY_FILTER ),                       
           createLookup(project, group, dataFolder, isProjectDir));

    this.pi = ProjectUtils.getInformation( project );
    this.group = group;
    this.isProjectDir = isProjectDir;
    
    if(isProjectDir) {
        LogicalViewProvider lvp = project.getLookup().lookup(LogicalViewProvider.class);
        // used to retrieve e.g. actions in case of a folder representing a project,
        // so that a projects context menu is the same is in a logical view
        this.projectDelegateNode = lvp != null ? lvp.createLogicalView() : null;
    } else {
        this.projectDelegateNode = null;
    }
    
    pi.addPropertyChangeListener(WeakListeners.propertyChange(this, pi));
    group.addPropertyChangeListener( WeakListeners.propertyChange( this, group ) );
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:22,代码来源:PhysicalView.java


注:本文中的org.netbeans.api.project.ProjectUtils类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。