Java Code Examples for org.netbeans.api.project.Project#equals()

The following examples show how to use org.netbeans.api.project.Project#equals() . 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: CopyResourcesOnSave.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private Project getOwningMavenProject(FileObject file) {
    Project prj = FileOwnerQuery.getOwner(file);
    if (prj == null || !prj.equals(project)) {
        return null;
    }
    //#180447
    if (!prj.getProjectDirectory().isValid()) {
        return null;
    }
    NbMavenProject mvn = prj.getLookup().lookup(NbMavenProject.class);
    if (mvn == null) {
        return null;
    }
    if (RunUtils.isCompileOnSaveEnabled(prj)) {
        return prj;
    }
    return null;
}
 
Example 2
Source File: LogicalViewProviderImpl.java    From netbeans with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example 3
Source File: AbstractLogicalViewProvider.java    From netbeans with Apache License 2.0 6 votes vote down vote up
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;
    }
    final Sources sources = ProjectUtils.getSources(owner);
    if (isInSourceGroup(fo, sources.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA))) {
        return true;
    }
    if (isInSourceGroup(fo, sources.getSourceGroups(WebProjectConstants.TYPE_DOC_ROOT))) {
        return true;
    }
    if (isInSourceGroup(fo, sources.getSourceGroups(WebProjectConstants.TYPE_WEB_INF))) {
        return true;
    }
    return false;
}
 
Example 4
Source File: RefactoringUtils.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public static boolean isOnSourceClasspath(FileObject fo) {
    Project p = ProjectConvertors.getNonConvertorOwner(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(JsProject.SOURCES_TYPE_Js);
            SourceGroup[] gr = ProjectUtils.getSources(p).getSourceGroups(Sources.TYPE_GENERIC);
            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;
}
 
Example 5
Source File: WebModules.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public ClassPath findClassPath (final FileObject file, final String type) {
    Project owner = FileOwnerQuery.getOwner (file);
    if (owner != null && owner.equals (project)) {
        // read modules under project READ access to prevent issues like #119734
        return ProjectManager.mutex().readAccess(new Mutex.Action<ClassPath>() {
            public ClassPath run() {
                synchronized (WebModules.this) {
                    List<FFWebModule> mods = getModules();
                    for (FFWebModule ffwm : mods) {
                        if (ffwm.contains (file)) {
                            return ffwm.findClassPath (file, type);
                        }
                    }
                }
                return null;
            }
        });
    }
    return null;
}
 
Example 6
Source File: SrcNode.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private Image getIcon(int type, boolean opened) {
    FileObject folder = getOriginal().getLookup().lookup(FileObject.class);
    Project owner = FileOwnerQuery.getOwner(folder);
    Image originalIcon;
    if (owner != null
            && !owner.equals(project)
            && owner.getProjectDirectory().equals(folder)) {
        originalIcon = ImageUtilities.icon2Image(ProjectUtils.getInformation(owner).getIcon());
        try {
            final Set<FileObject> clds = new HashSet<>();
            Collections.addAll(clds, owner.getProjectDirectory().getChildren());
            originalIcon = FileUIUtils.getImageDecorator(owner.getProjectDirectory().getFileSystem())
                    .annotateIcon(originalIcon, type, clds);
        } catch (FileStateInvalidException e) {
            LOGGER.log(Level.INFO, null, e);
        }
    } else {
        originalIcon = opened ? super.getOpenedIcon(type) : super.getIcon(type);
    }
    if (folder.equals(ProjectPropertiesSupport.getWebRootDirectory(project))
            && !folder.equals(ProjectPropertiesSupport.getSourcesDirectory(project))) {
        return ImageUtilities.mergeImages(originalIcon, ImageUtilities.loadImage(WEB_ROOT_BADGE_IMAGE, false), 7, 7);
    }
    return originalIcon;
}
 
Example 7
Source File: MainProjectScanningScope.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public boolean isInScope( FileObject resource ) {
    Project p = null;
    synchronized( this ) {
        p = currentProject;
    }

    if( null == resource || null == p )
        return false;
    
    Project owner = FileOwnerQuery.getOwner( resource );
    if( null == owner )
        return false;
    
    if( owner.equals( p ) )
        return true;
    
    return false;
}
 
Example 8
Source File: CallEjbGenerator.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static void addProjectToClassPath(final Project enterpriseProject, final EjbReference ref, FileObject refFO, EjbRefIType refIType) throws IOException {
        
        Project target = Utils.getProject(ref, refIType);
        
        boolean differentProject = target != null && !enterpriseProject.equals(target);
        if (differentProject) {
//            Sources sg = ProjectUtils.getSources(target);
//            SourceGroup[] grp = sg.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
            if (isJEEModule(target)) {
                ProjectClassPathModifier.addProjects(new Project[] {target} , refFO, JavaClassPathConstants.COMPILE_ONLY);
            } else {
                ProjectClassPathModifier.addProjects(new Project[] {target} , refFO, ClassPath.COMPILE);
            }
        }
    }
 
Example 9
Source File: JSFMoveClassPlugin.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private boolean isTargetOtherProject(FileObject localFileObject, MoveRefactoring ref) {
    boolean targetOtherProject = false;

    try {
        Project targetProject = FileOwnerQuery.getOwner(ref.getTarget().lookup(URL.class).toURI());
        Project srcProject = FileOwnerQuery.getOwner(localFileObject);
        targetOtherProject = !targetProject.equals(srcProject);
    } catch (Exception e) {
        LOGGER.log(Level.WARNING, "Exception in JSFMoveClassPlugin", e); //NOI18N
    }

    return targetOtherProject;
}
 
Example 10
Source File: SessionEJBWizardPanel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public static List<Project> getProjectsList(Project project) {
    List<Project> names = new ArrayList<Project>();
    boolean maven = isMaven(project);

    Set<Project> allProjects = new HashSet<Project>();
    // include all opened projects
    allProjects.addAll(Arrays.asList(OpenProjects.getDefault().getOpenProjects()));
    // include projects from given projects CP
    allProjects.addAll(getProjectsFromClasspath(project));

    for (Project p : allProjects) {
        if (p.equals(project)) {
            continue;
        }
        if (maven) {
            // if project is maven then only list maven projects which produce JARs
            if (p.getLookup().lookup(AntArtifactProvider.class) != null) {
                continue;
            }
        } else {
            // if project is ant then only list ant projects which produce JARs
            if (p.getLookup().lookup(AntArtifactProvider.class) == null
                    || AntArtifactQuery.findArtifactsByType(p, JavaProjectConstants.ARTIFACT_TYPE_JAR).length == 0) {
                continue;
            }
        }
        // list only projects which have java source root
        if (ProjectUtils.getSources(p).getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA).length == 0) {
            continue;
        }
        // skip the j2ee projects
        if (p.getLookup().lookup(J2eeModuleProvider.class) != null) {
            continue;
        }
        names.add(p);
    }
    return names;
}
 
Example 11
Source File: Utils.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/** Returns list of all EJB projects that can be called from the caller project.
 *
 * @param enterpriseProject the caller enterprise project
 */
public static Project [] getCallableEjbProjects(Project enterpriseProject) {
    Project[] allProjects = OpenProjects.getDefault().getOpenProjects();

    // TODO: HACK - this must be solved by freeform's own implementation of EnterpriseReferenceContainer, see issue 57003
    // call ejb should not make this check, all should be handled in EnterpriseReferenceContainer
    boolean isCallerFreeform = enterpriseProject.getClass().getName().equals("org.netbeans.modules.ant.freeform.FreeformProject");

    boolean isCallerEE6WebProject = isEE6WebProject(enterpriseProject);

    List<Project> filteredResults = new ArrayList<Project>(allProjects.length);
    for (int i = 0; i < allProjects.length; i++) {
        boolean isEJBModule = false;
        J2eeModuleProvider j2eeModuleProvider = allProjects[i].getLookup().lookup(J2eeModuleProvider.class);
        if (j2eeModuleProvider != null){
                Type type = j2eeModuleProvider.getJ2eeModule().getType();
                EjbJar[] ejbJars = EjbJar.getEjbJars(allProjects[i]);
                Profile profile = ejbJars.length > 0 ? ejbJars[0].getJ2eeProfile() : null;

                if (J2eeModule.Type.EJB.equals(type) || (J2eeModule.Type.WAR.equals(type) &&
                            (Profile.JAVA_EE_6_WEB.equals(profile) || Profile.JAVA_EE_6_FULL.equals(profile) ||
                            Profile.JAVA_EE_7_WEB.equals(profile) || Profile.JAVA_EE_7_FULL.equals(profile) ||
                            Profile.JAVA_EE_8_WEB.equals(profile) || Profile.JAVA_EE_8_FULL.equals(profile)))){
                    isEJBModule = true;
                }
        }

        // If the caller project is NOT a freeform project, include all EJB modules
        // If the caller project is a freeform project, include caller itself only
        // If the caller project is a Java EE 6 web project, include itself in the list
        if ((isEJBModule && !isCallerFreeform) ||
                (enterpriseProject.equals(allProjects[i]) && (isCallerFreeform || isCallerEE6WebProject) ) ) {
            filteredResults.add(allProjects[i]);
        }
    }
    return filteredResults.toArray(new Project[filteredResults.size()]);
}
 
Example 12
Source File: AndroidProjects.java    From NBANDROID-V2 with Apache License 2.0 5 votes vote down vote up
public static final Project findRootProject(FileObject root, Project current) {
    Project owner = FileOwnerQuery.getOwner(root.getParent());
    if ((owner instanceof NbAndroidRootProjectImpl) && !owner.equals(current)) {
        return findRootProject(root.getParent(), owner);
    } else {
        return current;
    }
}
 
Example 13
Source File: RepositoryForBinaryQueryImpl.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void checkChanges(boolean fireChanges) {
    // use MFOQI to determine what is the current project owning our coordinates in local repository.
    Project owner = null;
    if (groupId != null && artifactId != null && version != null) {
        owner = MavenFileOwnerQueryImpl.getInstance().getOwner(groupId, artifactId, version);
        if (owner != null && owner.getLookup().lookup(NbMavenProject.class) == null) {
            owner = null;
        }
    }
    synchronized (this) {
        if (currentProject != null && !currentProject.equals(owner)) {
            currentProject.getLookup().lookup(NbMavenProject.class).removePropertyChangeListener(projectListener);
        }
        if (owner != null && !owner.equals(currentProject)) {
            owner.getLookup().lookup(NbMavenProject.class).addPropertyChangeListener(projectListener);
        }
        currentProject = owner;
        if (fireChanges && !needsFiring.get()) { //only do check if interested in changes and when no known change occured
            avoidScheduling = true;
            try {
                getRoots();
                preferSources();
            } finally {
                avoidScheduling = false;
            }
        }
    }

    if (fireChanges && needsFiring.get()) {
        support.fireChange();
    }
}
 
Example 14
Source File: SessionManager.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public static SessionId getSessionId(Project project) {
    Session[] sessions = DebuggerManager.getDebuggerManager().getSessions();
    for (Session session : sessions) {
        SessionId sessionId = session.lookupFirst(null, SessionId.class);
        if (sessionId != null) {
            Project sessionProject = sessionId.getProject();
            if (project.equals(sessionProject)) {
                return sessionId;
            }
        }
    }
    return null;
}
 
Example 15
Source File: ClassPathProviderImpl.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@CheckForNull
private ClassPath getBootClassPath(@NonNull final FileObject artefact) {
    int type = getType(artefact);
    switch (type) {
        case -1:
            //Some old code rely on the existence of BootCP on any project file, mainly project folder.
            //For compatibily reasons simulate this behavior even it's not correct.
            //Cannot be done for multi module project, but there are no compatibility reasons as it's new.
            final Project prj = getProject();
            if (prj != null && prj.equals(FileOwnerQuery.getOwner(artefact))) {
                type = 0;
                break;
            } else {
                return null;
            }
        case 0:
        case 2:
        case 4:
            type = 0;
            break;
        case 1:
        case 3:
            type = 1;
            break;
        default:
            throw new IllegalArgumentException(Integer.toString(type));
    }
    return this.getBootClassPath(type);
}
 
Example 16
Source File: CssPreprocessorsSupport.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
public void customizerChanged(Project project, CssPreprocessor cssPreprocessor) {
    if (project.equals(project)) {
        recompileSources(cssPreprocessor);
    }
}
 
Example 17
Source File: CssPreprocessorsProblemProvider.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
public void customizerChanged(Project project, CssPreprocessor cssPreprocessor) {
    if (project.equals(project)) {
        problemsProviderSupport.fireProblemsChange();
    }
}
 
Example 18
Source File: EarImpl.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
public List<Project> getProjects() {
    MavenProject mp = mavenproject().getMavenProject();
    @SuppressWarnings("unchecked")
    Set<Artifact> artifactSet = mp.getArtifacts();
    @SuppressWarnings("unchecked")
    List<Dependency> deps = mp.getRuntimeDependencies();
    List<Project> toRet = new ArrayList<Project>();
    EarImpl.MavenModule[] mm = readPomModules();
    //#162173 order by dependency list, artifacts is unsorted set.
    for (Dependency d : deps) {
        if ("war".equals(d.getType()) || "ejb".equals(d.getType()) || "app-client".equals(d.getType())) {//NOI18N
            for (Artifact a : artifactSet) {
                if (a.getGroupId().equals(d.getGroupId()) &&
                        a.getArtifactId().equals(d.getArtifactId()) &&
                        StringUtils.equals(a.getClassifier(), d.getClassifier())) {
                    URI uri = Utilities.toURI(FileUtil.normalizeFile(a.getFile()));
                    //#174744 - it's of essence we use the URI based method. items in local repo might not be available yet.
                    Project owner = FileOwnerQuery.getOwner(uri);
                    if (owner != null) {
                        EarImpl.MavenModule m = findMavenModule(a, mm);
                        //#162173 respect order in pom configuration.. shall we?
                        if (m.pomIndex > -1 && toRet.size() > m.pomIndex) {
                            toRet.add(m.pomIndex, owner);
                        } else {
                            toRet.add(owner);
                        }
                        
                    }
                }
            }
        }
    }
    // This might happened if someone calls getProjects() before the EAR childs were actually opened
    // Typically if childs are needed during the project creation
    if (toRet.isEmpty()) {
        FileObject parentFO = project.getProjectDirectory().getParent();
        for (FileObject childFO : parentFO.getChildren()) {
            if (childFO.isData()) {
                continue;
            }
            
            try {
                Project childProject = ProjectManager.getDefault().findProject(childFO);
                if (childProject != null && !childProject.equals(project)) {
                    toRet.add(childProject);
                }
            } catch (IOException | IllegalArgumentException ex) {
                Exceptions.printStackTrace(ex);
            }
        }
    }
    return toRet;
}
 
Example 19
Source File: CssPreprocessorsSupport.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
public void customizerChanged(Project project, CssPreprocessor cssPreprocessor) {
    if (project.equals(project)) {
        recompileSources(cssPreprocessor);
    }
}
 
Example 20
Source File: CssPreprocessorsProblemProvider.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
public void processingErrorOccured(Project project, CssPreprocessor cssPreprocessor, String error) {
    if (project.equals(project)) {
        problemsProviderSupport.fireProblemsChange();
    }
}