Java Code Examples for org.openide.filesystems.FileObject#equals()

The following examples show how to use org.openide.filesystems.FileObject#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: RenamePackagePlugin.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public Problem fastCheckParameters() {
    final String newName = refactoring.getNewName();
    if (!IdentifiersUtil.isValidPackageName(newName)) {
        return createProblem("ERR_InvalidPackage", newName); //NOI18N
    }

    final ClassPath projectClassPath = ClassPath.getClassPath(folder, ClassPath.SOURCE);
    final FileObject fo = projectClassPath.findResource(newName.replace('.','/'));
    if (fo != null) {
        final FileObject ownerRoot = projectClassPath.findOwnerRoot(folder);
        if(ownerRoot != null && ownerRoot.equals(projectClassPath.findOwnerRoot(fo))) {
            if (fo.isFolder() && fo.getChildren().length == 1) {
                final FileObject parent = fo.getChildren()[0];
                final String relativePath = FileUtil.getRelativePath(parent, folder);
                if (relativePath != null) {
                    return null;
                }
            }
            return createProblem("ERR_PackageExists", newName); //NOI18N
        }
    }
    return null;
}
 
Example 2
Source File: ClassPathProviderImpl.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
  * Find what a given file represents.
  * @param file a file in the project
  * @return one of FileType.* constants
  */
private FileType getType(FileObject file) {
     FileObject[] srcPath = getPrimarySrcPath();
     for (int i=0; i < srcPath.length; i++) {
         FileObject root = srcPath[i];
         if (root.equals(file) || FileUtil.isParentOf(root, file)) {
             return FileType.SOURCE;
         }
     }
     FileObject dir = getDocumentBaseDir();
     if (dir != null && (dir.equals(file) || FileUtil.isParentOf(dir,file))) {
         return FileType.WEB_SOURCE;
     }
     dir = getBuildClassesDir();
     if (dir != null && (dir.equals(file) || FileUtil.isParentOf(dir, file))) {
         return FileType.CLASS;
     }
     
     return FileType.UNKNOWN;
 }
 
Example 3
Source File: PackageDeleteRefactoringPlugin.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public void performChange() {
    FileObject root = srcGroup.getRootFolder();
    FileObject parent = folder.getFolder().getParent();
    dir = FileUtil.toFile(folder.getFolder());
    try {
        folder.getFolder().delete();
        while( !parent.equals( root ) && parent.getChildren().length == 0  ) {
            FileObject newParent = parent.getParent();
            parent.delete();
            parent = newParent;
        }
    } catch (IOException ioException) {
        ErrorManager.getDefault().notify(ioException);
    }
}
 
Example 4
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 5
Source File: BreakpointAnnotationManager.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private void annotate (final FileObject fo) {
        synchronized (breakpointAnnotations) {
//            if (annotatedFiles.contains(fo)) {
//                // Already annotated
//                return ;
//            }
            //Set<JSBreakpoint> annotatedBreakpoints = breakpointAnnotations.keySet();
            for (Breakpoint breakpoint : DebuggerManager.getDebuggerManager().getBreakpoints()) {
                if (isAnnotateable(breakpoint) && !breakpointAnnotations.containsKey(breakpoint)) {
                    JSLineBreakpoint b = (JSLineBreakpoint) breakpoint;
                    if (fo.equals(b.getFileObject())) {
                        logger.log(Level.FINE, "annotate({0} (ID={1})): b = {2}",
                                   new Object[] { fo, System.identityHashCode(fo), b });
                        b.addPropertyChangeListener(this);
                        annotationProcessor.post(new AnnotationRefresh(b, false, true));
                    }
                }
            }
            annotatedFiles.add(fo);
            logger.log(Level.FINE, "Annotated files = {0}", annotatedFiles);
        }
    }
 
Example 6
Source File: IndexerTransactionTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public ClassPath findClassPath(final FileObject file, final String type) {
    final FileObject[] roots = sourcePath.getRoots();
    for (FileObject root : roots) {
        if (root.equals(file) || FileUtil.isParentOf(root, file)) {
            if (type == ClassPath.SOURCE) {
                return sourcePath;
            }
            if (type == ClassPath.COMPILE) {
                return compilePath;
            }
            if (type == ClassPath.BOOT) {
                return bootPath;
            }
        }
    }
    if (libSrc2.equals(file) || FileUtil.isParentOf(libSrc2, file)) {
        if (type == ClassPath.SOURCE) {
                return ClassPathSupport.createClassPath(new FileObject[]{libSrc2});
            }
            if (type == ClassPath.COMPILE) {
                return ClassPathSupport.createClassPath(new URL[0]);
            }
            if (type == ClassPath.BOOT) {
                return bootPath;
            }
    }
    return null;
}
 
Example 7
Source File: JavaTargetChooserPanelGUI.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private SourceGroup getPreselectedGroup(FileObject folder) {
    for(int i = 0; folder != null && i < groups.length; i++) {
        FileObject root = groups[i].getRootFolder();
        if (root.equals(folder) || FileUtil.isParentOf(root, folder)) {
            return groups[i];
        }
    }
    return groups[0];
}
 
Example 8
Source File: ModuleTargetChooserPanelGUI.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private SourceGroup getPreselectedGroup(FileObject folder) {
    for(int i = 0; folder != null && i < groups.length; i++) {
        FileObject root = groups[i].getRootFolder();
        if (root.equals(folder) || FileUtil.isParentOf(root, folder)) {
            return groups[i];
        }
    }
    return groups[0];
}
 
Example 9
Source File: DiffStreamSource.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private boolean isPrimary() {
    FileObject fo = FileUtil.toFileObject(baseFile);
    if (fo != null) {
        try {
            DataObject dao = DataObject.find(fo);
            return fo.equals(dao.getPrimaryFile());
        } catch (DataObjectNotFoundException e) {
            // no dataobject, never mind
        }
    }
    return true;
}
 
Example 10
Source File: GrailsArtifacts.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public static SourceGroup getSourceGroupForCategory(Project project, List<SourceGroup> groups, SourceCategory category) {
    FileObject projectRoot = project.getProjectDirectory();
    for (SourceGroup group : groups) {
        FileObject folder = group.getRootFolder();
        if (category != null) {
            FileObject categoryFolder = projectRoot.getFileObject(category.getRelativePath());
            if (folder.equals(categoryFolder)) {
                return group;
            }
        }
    }

    return null;
}
 
Example 11
Source File: MavenSourcesImpl.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private Resource checkResource(FileObject rootFold, List<Resource> list) {
    for (Resource elem : list) {
        String dir = elem.getDirectory();
        if (dir == null) { // #203635
            continue;
        }
        URI uri = FileUtilities.getDirURI(project.getProjectDirectory(), dir);
        FileObject fo = FileUtilities.convertURItoFileObject(uri);
        if (fo != null && fo.equals(rootFold)) {
            return elem;
        }
    }
    return null;
}
 
Example 12
Source File: Loader.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private void loadTasks( FileObject[] roots, FileObject resource ) {
    ArrayList<Task> loadedTasks = null;
    try {
        QuerySupport qs = QuerySupport.forRoots(TaskIndexerFactory.INDEXER_NAME,
                TaskIndexerFactory.INDEXER_VERSION, roots);

        for( FileTaskScanner scanner : ScannerList.getFileScannerList().getScanners() ) {

            if( cancelled )
                return;

            if( !filter.isEnabled(scanner) )
                continue;

            String scannerId = ScannerDescriptor.getType( scanner );
            Collection<? extends IndexResult> cache = qs.query(TaskIndexer.KEY_SCANNER, scannerId, QuerySupport.Kind.EXACT, TaskIndexer.KEY_TASK);
            for( IndexResult ir : cache ) {
                if( cancelled )
                    return;
                FileObject fo = ir.getFile();
                if( null == fo )
                    continue;
                if( null != resource && !resource.equals(ir.getFile()) )
                    continue;
                if( null != loadedTasks )
                    loadedTasks.clear();
                String[] tasks = ir.getValues(TaskIndexer.KEY_TASK);
                for( String encodedTask : tasks ) {
                    if( cancelled )
                        return;

                    Task t = TaskIndexer.decode(fo, encodedTask);
                    if( null == loadedTasks ) {
                        loadedTasks = new ArrayList<Task>(1000);
                    }
                    loadedTasks.add(t);
                }
                if( cancelled )
                    return;
                if( null != loadedTasks && !loadedTasks.isEmpty() )
                    taskList.update(scanner, fo, loadedTasks, filter);
            }
        }
    } catch( IOException ioE ) {
        Logger.getLogger(TaskIndexer.class.getName()).log(Level.INFO,
                "Error while loading tasks from cache", ioE);
    }
}
 
Example 13
Source File: ClassPathProviderImpl.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
public String[] getPropertyName (SourceGroup sg, String type) {
    if (ClassPathSupport.ENDORSED.equals(type)) {
        return endorsedClasspath;
    }
    FileObject root = sg.getRootFolder();
    FileObject[] path = getPrimarySrcPath();
    for (int i=0; i<path.length; i++) {
        if (root.equals(path[i])) {
            switch (type) {
                case ClassPath.COMPILE:
                    return javacClasspath;
                case ClassPath.EXECUTE:
                    return runClasspath;
                case JavaClassPathConstants.PROCESSOR_PATH:
                    return processorClasspath;
                case JavaClassPathConstants.MODULE_COMPILE_PATH:
                    return modulePath;
                case JavaClassPathConstants.MODULE_EXECUTE_PATH:
                    return moduleExecutePath;
                case JavaClassPathConstants.MODULE_PROCESSOR_PATH:
                    return processorModulePath;
                default:
                    return null;
            }
        }
    }
    path = getTestSrcDir();
    for (int i=0; i<path.length; i++) {
        if (root.equals(path[i])) {
            switch (type) {
                case ClassPath.COMPILE:
                    return javacTestClasspath;
                case ClassPath.EXECUTE:
                    return runTestClasspath;
                case JavaClassPathConstants.PROCESSOR_PATH:
                    return processorTestClasspath;
                case JavaClassPathConstants.MODULE_COMPILE_PATH:
                    return testModulePath;
                case JavaClassPathConstants.MODULE_EXECUTE_PATH:
                    return moduleExecutePath;
                case JavaClassPathConstants.MODULE_PROCESSOR_PATH:
                    return processorTestModulepath;
                default:
                    return null;
            }
        }
    }
    return null;
}
 
Example 14
Source File: FormRefactoringUpdate.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
public void commit() {
    if (previewElement != null && !previewElement.isEnabled()) {
        return;
    }

    // As "transactions" we do updates for changes affecting only the
    // content of the source file, not changing the file's name or location.
    // Our transaction is called after retouche commits its changes to the
    // source. After all transactions are done, the source file is saved
    // automatically.

    for (FileObject originalFile : refInfo.getOriginalFiles()) {
        // (Actually more original files make only sense for this form if
        // they represent components used in this form and moved...)
        switch (refInfo.getChangeType()) {
        case VARIABLE_RENAME: // renaming a variable (just one)
            if (originalFile.equals(changingFile)) {
                renameMetaComponent(refInfo.getOldName(originalFile), refInfo.getNewName());
                transactionDone = true;
            }
            break;
        case CLASS_RENAME: // renaming a component class used in the form (just one)
            if (!originalFile.equals(changingFile)) {
                componentClassRename(originalFile);
                transactionDone = true;
            }
            break;
        case CLASS_MOVE: // moving a class used in the form (there can be more of them)
            if (!originalFile.equals(changingFile) && isGuardedCodeChanging()) {
                componentChange(refInfo.getOldName(originalFile), refInfo.getNewName(originalFile));
                transactionDone = !refInfo.containsOriginalFile(changingFile);
                // If a form is moved together with other java classes, it needs
                // to be checked here but also processed later in performChange
                // method. If it contained some of the moved components, we will
                // not be able to load it. But that is not for sure, so will try
                // anyway, at worst it won't be processed.
            }
            break;
        case CLASS_DELETE: // deleting form (more can be deleted, but here we only care about this form)
            if (originalFile.equals(changingFile)) {
                saveFormForUndo(); // we only need to backup the form file for undo
                transactionDone = true;
            }
            break;
        case PACKAGE_RENAME:
        case FOLDER_RENAME:  // renaming package of a component used in the form,
                             // but not the package of the form itself
                             // (just one package renamed)
            if (!changingFile.getParent().equals(originalFile)) {
                packageRename(originalFile);
                transactionDone = true;
            }
            break;
        default:
            // do nothing otherwise - could be just redundantly registered by the guarded handler
            return;
        }
    }
}
 
Example 15
Source File: FileOperationFactory.java    From netbeans with Apache License 2.0 4 votes vote down vote up
boolean isNbProjectMetadata(FileObject fo) {
    // #193869
    FileObject nbprojectDir = project.getProjectDirectory().getFileObject("nbproject"); // NOI18N
    return FileUtil.isParentOf(nbprojectDir, fo) || nbprojectDir.equals(fo);
}
 
Example 16
Source File: TargetChooserPanelGUI.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public void initValues(  ) {
    getPanel().getProvider().getUIManager().initValues( getPanel() , this );
    projectTextField.setText(ProjectUtils.getInformation(getPanel().getProject()).
            getDisplayName());
    // set the location field and find web module
    if (getPanel().getSourceGroups()!=null && 
            getPanel().getSourceGroups().length>0) 
    {
        locationCB.setModel(new javax.swing.DefaultComboBoxModel(
                getLocations(getPanel().getSourceGroups())));
    } else {
        locationCB.setModel(new javax.swing.DefaultComboBoxModel(
            new Object[]{new LocationItem(getPanel().getProject().
                    getProjectDirectory())}));
    }
    
    // filling the folder field
    String target=null;
    FileObject preselectedFolder =Templates.getTargetFolder( getPanel().
            getTemplateWizard() );
    if (preselectedFolder != null) {
        for(int item = 0; target == null && item < locationCB.getModel().getSize(); 
            item++) 
        {
            FileObject docBase = ((LocationItem)locationCB.getModel().
                        getElementAt(item)).getFileObject();
            if (preselectedFolder.equals(docBase) || 
                    FileUtil.isParentOf(docBase, preselectedFolder)) 
            {
                target = FileUtil.getRelativePath(docBase, preselectedFolder);
                locationCB.getModel().setSelectedItem(locationCB.getModel().
                        getElementAt(item));
                break;
            }
        }
    }
    
    getPanel().getProvider().getUIManager().initFolderValue( getPanel(), target ,
            folderTextField);
    
    //set default new file name
    String documentName = getPanel().getProvider().getNewFileName();
    String newDocumentName = documentName;
    File targetFolder = getFileCreationRoot();
    if (targetFolder != null) {
        FileObject folder = FileUtil.toFileObject(targetFolder);
        if (folder != null) {
            int index = 0;
            while (true) {
                FileObject _tmp = folder.getFileObject(documentName, 
                        getPanel().getProvider().getExpectedExtension(
                                getPanel()));
                if (_tmp == null) {
                    break;
                }
                documentName = newDocumentName + (++index);
            }
        }
    }
    documentNameTextField.setText(documentName);
}
 
Example 17
Source File: PhpProject.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
public boolean isSupportEnabled(FileObject[] activatedFOs) {
    if (activatedFOs.length == 0) {
        return false;
    }

    PhpProject onlyOneProjectAllowed = null;
    for (FileObject fileObj : activatedFOs) {
        if (fileObj == null) {
            return false;
        }

        // only php files or folders allowed
        if (fileObj.isData() && !FileUtils.isPhpFile(fileObj)) {
            return false;
        }

        PhpProject phpProject = PhpProjectUtils.getPhpProject(fileObj);
        if (phpProject == null) {
            return false;
        }
        if (PhpProjectValidator.isFatallyBroken(phpProject)) {
            return false;
        }
        if (onlyOneProjectAllowed == null) {
            onlyOneProjectAllowed = phpProject;
        } else {
            if (!onlyOneProjectAllowed.equals(phpProject)) {
                // tests can be generated only for one project at one time
                return false;
            }
        }

        if (fileObj == phpProject.getProjectDirectory()) { // "Run Selenium Tests" action should be active for the project node
            return true;
        }

        FileObject sources = ProjectPropertiesSupport.getSourcesDirectory(phpProject);
        if (sources == null || sources.equals(fileObj)) {
            return false;
        }

        if (!CommandUtils.isUnderSources(phpProject, fileObj)
                || CommandUtils.isUnderTests(phpProject, fileObj, false)
                || CommandUtils.isUnderSelenium(phpProject, fileObj, false)) {
            return false;
        }
    }
    return true;
}
 
Example 18
Source File: ModuleClassPathsTest.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private static boolean isArtifact(
        @NonNull final FileObject root,
        @NonNull final FileObject file) {
    return root.equals(file) || FileUtil.isParentOf(root, file);
}
 
Example 19
Source File: ProjectRunnerImplTest.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
public boolean isProject(FileObject projectDirectory) {
    FileObject fo = prjDir;
    return fo != null && fo.equals(projectDirectory);
}
 
Example 20
Source File: ProjectsRootNodePhysicalViewModeSourcesTest.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override public boolean contains(FileObject file) {
    return file.equals(root);
}