org.netbeans.api.project.FileOwnerQuery Java Examples

The following examples show how to use org.netbeans.api.project.FileOwnerQuery. 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: OperationEditorDrop.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public boolean handleTransfer(JTextComponent targetComponent) {
    Object mimeType = targetComponent.getDocument().getProperty("mimeType"); //NOI18N
    if (mimeType!=null && ("text/x-java".equals(mimeType) || "text/x-jsp".equals(mimeType) )) { //NOI18N
        
        try {
            Node clientNode = operationNode.getParentNode().getParentNode().getParentNode();
            FileObject srcRoot = clientNode.getLookup().lookup(FileObject.class);
            Project clientProject = FileOwnerQuery.getOwner(srcRoot);
            FileObject targetFo = NbEditorUtilities.getFileObject(targetComponent.getDocument());
            if (JaxWsUtils.addProjectReference(clientProject, targetFo)) {
                JaxWsCodeGenerator.insertMethod(targetComponent.getDocument(), targetComponent.getCaret().getDot(), operationNode);

                // logging usage of action
                Object[] params = new Object[2];
                params[0] = LogUtils.WS_STACK_JAXWS;
                params[1] = "DRAG & DROP WS OPERATION"; // NOI18N
                LogUtils.logWsAction(params);
                
                return true;
            }
        } catch (Exception ex) {
            ErrorManager.getDefault().log(ex.getLocalizedMessage());
        }
    }
    return false;
}
 
Example #2
Source File: Selenium2PhpTestWizardIterator.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public Set instantiate() throws IOException {
    FileObject createdFile = null;
    FileObject targetFolder = Templates.getTargetFolder(wiz);
    Selenium2SupportImpl selenium2Support = Selenium2Support.findSelenium2Support(FileOwnerQuery.getOwner(targetFolder));
    if (selenium2Support == null) {
        return Collections.singleton(createdFile);
    }
    selenium2Support.configureProject(targetFolder);
    TestCreatorProvider.Context context = new TestCreatorProvider.Context(new FileObject[]{targetFolder});
    context.setSingleClass(true);
    context.setTargetFolder(targetFolder);
    context.setTestClassName(Templates.getTargetName(wiz));
    ArrayList<FileObject> createTests = Selenium2Support.createTests(context);
    if (!createTests.isEmpty()) {
        createdFile = createTests.get(0);
    }

    return Collections.singleton(createdFile);
}
 
Example #3
Source File: JaxWsAddOperation.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private String getPackageName(FileObject fo) {
    Project project = FileOwnerQuery.getOwner(fo);
    Sources sources = project.getLookup().lookup(Sources.class);
    if (sources!=null) {
        SourceGroup[] groups = sources.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
        if (groups!=null) {
            for (SourceGroup group: groups) {
                FileObject rootFolder = group.getRootFolder();
                if (FileUtil.isParentOf(rootFolder, fo)) {
                    String relativePath = FileUtil.getRelativePath(rootFolder, fo).replace('/', '.');
                    return (relativePath.endsWith(".java")? //NOI18N
                        relativePath.substring(0,relativePath.length()-5):
                        relativePath);
                }
            }
        }
    }
    return null;
}
 
Example #4
Source File: MissingPomDependencies.java    From nb-springboot with Apache License 2.0 6 votes vote down vote up
private static ErrorDescription annotationWarning(HintContext ctx, String artifactId, String hintMex, boolean optional) {
    final TreePath tp = ctx.getPath();
    final TreePath tpParent = tp.getParentPath();
    if (tpParent != null) {
        if (tpParent.getLeaf().getKind() == ANNOTATION) {
            Project prj = FileOwnerQuery.getOwner(ctx.getInfo().getFileObject());
            if (prj != null) {
                SpringBootService sbs = prj.getLookup().lookup(SpringBootService.class);
                if (sbs != null) {
                    // check first if the pom has at least one spring boot dependencies
                    if (sbs.hasPomDependency("spring-boot") && !sbs.hasPomDependency(artifactId)) {
                        NbMavenProject mPrj = prj.getLookup().lookup(NbMavenProject.class);
                        if (mPrj != null) {
                            return ErrorDescriptionFactory
                                    .forName(ctx, tp, hintMex, new AddDepFix(mPrj, artifactId, optional));
                        } else {
                            return ErrorDescriptionFactory.forName(ctx, tp, hintMex);
                        }
                    }
                }
            }
        }
    }
    return null;
}
 
Example #5
Source File: Classpaths.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private List<URL> createExecuteClasspath(List<String> packageRoots, Element compilationUnitEl) {
    for (Element e : XMLUtil.findSubElements(compilationUnitEl)) {
        if (e.getLocalName().equals("classpath") && e.getAttribute("mode").equals("execute")) { // NOI18N
            return createClasspath(e, new RemoveSources(helper, sfbqImpl));
        }
    }
    // None specified; assume it is same as compile classpath plus (cf. #49113) <built-to> dirs/JARs
    // if there are any (else include the source dir(s) as a fallback for the I18N wizard to work).
    Set<URL> urls = new LinkedHashSet<>();
    urls.addAll(createCompileClasspath(compilationUnitEl));
    final Project prj = FileOwnerQuery.getOwner(helper.getProjectDirectory());
    if (prj != null) {
        for (URL src : createSourcePath(packageRoots)) {
            urls.addAll(sfbqImpl.findBinaryRoots(src));
        }
    }
    return new ArrayList<>(urls);
}
 
Example #6
Source File: SpringWebModuleExtender.java    From netbeans with Apache License 2.0 6 votes vote down vote up
protected boolean addLibrariesToWebModule(List<Library> libraries, WebModule webModule) throws IOException, UnsupportedOperationException {
    FileObject fileObject = webModule.getDocumentBase();
    Project project = FileOwnerQuery.getOwner(fileObject);
    if (project == null) {
        return false;
    }
    boolean addLibraryResult = false;
    try {
        SourceGroup[] groups = SourceGroups.getJavaSourceGroups(project);
        if (groups.length == 0) {
            return false;
        }
        addLibraryResult = ProjectClassPathModifier.addLibraries(libraries.toArray(new Library[libraries.size()]), groups[0].getRootFolder(), ClassPath.COMPILE);
    } catch (IOException e) {
        LOGGER.log(Level.WARNING, "Libraries required for the Spring MVC project not added", e); // NOI18N
    } catch (UnsupportedOperationException uoe) {
        LOGGER.log(Level.WARNING, "This project does not support adding these types of libraries to the classpath", uoe); // NOI18N
    }
    return addLibraryResult;
}
 
Example #7
Source File: ActionsUtil.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/** In given lookup will find all FileObjects owned by given project
 * with given command supported.
 */    
public static FileObject[] getFilesFromLookup( Lookup lookup, Project project ) {
    HashSet<FileObject> result = new HashSet<FileObject>();
    for (DataObject dObj : lookup.lookupAll(DataObject.class)) {
        FileObject fObj = dObj.getPrimaryFile();
        Project p = FileOwnerQuery.getOwner(fObj);
        if ( p != null && p.equals( project ) ) {
            result.add( fObj );                                        
        }

    }
    
    FileObject[] fos = new FileObject[ result.size() ];
    result.toArray( fos );        
    return fos;
}
 
Example #8
Source File: I18nServiceImpl.java    From netbeans with Apache License 2.0 6 votes vote down vote up
static boolean isNbBundleAvailable(FileObject srcFile) {
    // is there a good way to recognize that NbBundle is available?
    // - execution CP may not work if everything is cleaned
    // - looking for NbBundle.java in sources of execution CP roots is expensive
    // - checking project impl. class name is ugly
    // - don't know how to check if there is "org.openide.util" module
    ClassPath classPath = ClassPath.getClassPath(srcFile, ClassPath.EXECUTE);
    if (classPath != null && classPath.findResource("org/openide/util/NbBundle.class") != null) // NOI18N
        return true;

    // hack: check project impl. class name
    Project p = FileOwnerQuery.getOwner(srcFile);
    if (p != null && p.getClass().getName().startsWith("org.netbeans.modules.apisupport.") // NOI18N
            && p.getClass().getName().endsWith("Project")) // NOI18N
        return true;

    return false;
}
 
Example #9
Source File: RunSeleniumAction.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public void actionPerformed(final ActionEvent e) {
    RP.post(new Runnable() {
        @Override
        public void run() {
            Project p = FileOwnerQuery.getOwner(activatedFOs[0]);
            if (p == null) {
                return;
            }
            FileSensitiveActions.fileCommandAction(ActionProvider.COMMAND_TEST_SINGLE, Bundle.SeleniumTestFileAction_name(), null).actionPerformed(e);
            SeleniumTestingProvider provider = SeleniumTestingProviders.getDefault().getSeleniumTestingProvider(p, true);
            if (provider != null) {
                provider.runTests(activatedFOs);
            }
        }
    });
}
 
Example #10
Source File: DelegateToOwnerLookupTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
protected void setUp() throws Exception {
    super.setUp();
    clearWorkDir();
    final FileObject wd = FileUtil.toFileObject(FileUtil.normalizeFile(getWorkDir()));
    final FileObject enclosingProjectHome = FileUtil.createFolder(wd, "enclosing");    //NOI18N
    TestProject.Factory.LOOKUP_FACTORY = new Callable<Lookup>() {
        @Override
        public Lookup call() throws Exception {
            return Lookups.fixed(
                new SourcesImpl(enclosingProjectHome),
                new ProjectOpenedHookImpl(),
                new ProjectInformationImpl(enclosingProjectHome));
        }
    };
    automaticProjectHome = FileUtil.createFolder(enclosingProjectHome, "automatic");   //NOI18N
    FileUtil.createFolder(enclosingProjectHome, TestProject.PROJECT_MARKER);
    owner = FileOwnerQuery.getOwner(enclosingProjectHome);
}
 
Example #11
Source File: DefaultPlugin.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * 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(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;
}
 
Example #12
Source File: Utils.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * Checks if the target is Java SE class.
 * <p>
 * <i>Note: Should run outside EDT!</i>
 * @return true if given <code>target</code> is defined in a Java SE environment.
 */
public static boolean isTargetJavaSE(FileObject fileObject, final String className) throws IOException{
    Project owner = FileOwnerQuery.getOwner(fileObject);
    if (owner.getLookup().lookup(J2eeModuleProvider.class) == null){
        return true;
    }
    JavaSource javaSource = JavaSource.forFileObject(fileObject);
    if (javaSource == null) {
        return false;
    }
    final boolean[] result = new boolean[] { false };
    javaSource.runUserActionTask(new Task<CompilationController>() {
        public void run(CompilationController controller) throws IOException {
            controller.toPhase(JavaSource.Phase.ELEMENTS_RESOLVED);
            TypeElement typeElement = controller.getElements().getTypeElement(className);
            TypeElement junitTestCase = controller.getElements().getTypeElement("junit.framework.TestCase");
            if (junitTestCase != null && typeElement != null) {
                result[0] = controller.getTypes().isSubtype(typeElement.asType(), junitTestCase.asType());
            }
        }
    }, true);
    return result[0];
}
 
Example #13
Source File: WebModules.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public WebModule findWebModule (final FileObject file) {
    Project owner = FileOwnerQuery.getOwner (file);
    if (project.equals (owner)) {
        // read modules under project READ access to prevent issues like #119734
        return ProjectManager.mutex().readAccess(new Mutex.Action<WebModule>() {
            public WebModule run() {
                synchronized (WebModules.this) {
                    List<FFWebModule> mods = getModules();
                    for (FFWebModule ffwm : mods) {
                        if (ffwm.contains (file)) {
                            WebModule wm = cache.get (ffwm);
                            if (wm == null) {
                                wm = WebModuleFactory.createWebModule (ffwm);
                                cache.put (ffwm, wm);
                            }
                            return wm;
                        }
                    }
                    return null;
                }
            }});
    }
    return null;
}
 
Example #14
Source File: CallStackModel.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private String getFile( Stack stack ){
    String fileName = stack.getFileName();
    FileObject fileObject = getSessionId().toSourceFile( fileName );
    if ( fileObject == null ){
        // TODO inform somehow about local file is not found , output remote file
        return fileName;
    }
    else {
        Project project = FileOwnerQuery.getOwner( fileObject );
        if (project != null) {
            String retval = FileUtil.getRelativePath(project.getProjectDirectory() ,fileObject );
            if (retval != null) {
                return retval;
            }
        }
        File f = FileUtil.toFile(fileObject);
        return f != null ? f.getAbsolutePath() : fileName;
    }
}
 
Example #15
Source File: ActionProviderImplTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void testImages2() throws Exception {
    createFile("modules.xml");
    createDir("jdk/src/java.base/share/classes");
    createDir("build/conf/jdk");
    createDir("build/conf/images/jdk");
    createDir("langtools/src/java.compiler/share/classes");
    FileObject testFile = createFile("langtools/test/Test.java");

    createDir("").setAttribute(BuildUtils.NB_JDK_PROJECT_BUILD, FileUtil.toFile(createDir("build/conf")));

    FileOwnerQuery.markExternalOwner(testFile.getParent(), FileOwnerQuery.getOwner(createDir("langtools/src/java.compiler")), FileOwnerQuery.EXTERNAL_ALGORITHM_TRANSIENT);

    File target = BuildUtils.findTargetJavaHome(testFile);

    assertEquals("/build/conf/jdk", target.getAbsolutePath().substring(getWorkDir().getAbsolutePath().length()));
}
 
Example #16
Source File: SetKarmaConfAction.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public Action createContextAwareInstance(Lookup context) {
    FileObject file = context.lookup(FileObject.class);
    if (file == null) {
        DataObject dataObject = context.lookup(DataObject.class);
        if (dataObject != null) {
            file = dataObject.getPrimaryFile();
        }
    }
    if (file == null) {
        return this;
    }
    Project owner = FileOwnerQuery.getOwner(file);
    if (owner == null) {
        return this;
    }
    if (!KarmaPreferences.isEnabled(owner)) {
        return this;
    }
    return new SetKarmaConfAction(owner, file);
}
 
Example #17
Source File: ProjectsRootNode.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@CheckForNull
private static Project findProject(@NonNull final FileObject target) {
    Project owner = FileOwnerQuery.getOwner(target);
    if (owner != null && ProjectConvertors.isConvertorProject(owner)) {
        FileObject dir = owner.getProjectDirectory().getParent();
        while (dir != null) {
            Project p = FileOwnerQuery.getOwner(dir);
            if (p != null && !ProjectConvertors.isConvertorProject(p)) {
                owner = p;
                break;
            }
            dir = dir.getParent();
        }
    }
    return owner;
}
 
Example #18
Source File: OpenProject.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public @Override void actionPerformed(ActionEvent evt) {
    JFileChooser chooser = ProjectChooserAccessory.createProjectChooser( true ); // Create the jFileChooser
    chooser.setMultiSelectionEnabled( true );
    
    // Check to see if the current selection matches a file/folder owned by a non-open project;
    // if so, use that as the starting directory, as a convenience in case that is what should be opened.
    // XXX may also want to check lookup for FileObject
    for (DataObject d : Utilities.actionsGlobalContext().lookupAll(DataObject.class)) {
        Project selected = FileOwnerQuery.getOwner(d.getPrimaryFile());
        if (selected != null && !OpenProjectList.getDefault().isOpen(selected)) {
            File dir = FileUtil.toFile(selected.getProjectDirectory());
            if (dir != null) {
                chooser.setCurrentDirectory(dir.getParentFile());
                chooser.setSelectedFiles(new File[] {dir});
                break;
            }
        }
    }
    show(chooser);
}
 
Example #19
Source File: StandardAntArtifactQueryImpl.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public AntArtifact findArtifact(File file) {
    Project p = FileOwnerQuery.getOwner(BaseUtilities.toURI(file));
    if (p == null) {
        return null;
    }
    AntArtifactProvider prov = p.getLookup().lookup(AntArtifactProvider.class);
    if (prov == null) {
        return null;
    }
    AntArtifact[] artifacts = prov.getBuildArtifacts();
    for (int i = 0; i < artifacts.length; i++) {
        URI uris[] = artifacts[i].getArtifactLocations();
        for (int y = 0; y < uris.length; y++) {
            File testFile = BaseUtilities.toFile(BaseUtilities.toURI(artifacts[i].getScriptLocation()).resolve(uris[y]));
            if (file.equals(testFile)) {
                return artifacts[i];
            }
        }
    }
    return null;
}
 
Example #20
Source File: ProjectEarProvider.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public org.netbeans.modules.j2ee.api.ejbjar.Ear findEar (org.openide.filesystems.FileObject file) {
    Project project = FileOwnerQuery.getOwner (file);
    if (project != null) {
        EarProvider provider = (EarProvider) project.getLookup ().lookup (EarProvider.class);
        if (provider != null) {
            return provider.findEar (file);
        }
    }
    return null;
}
 
Example #21
Source File: FolderList.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public static boolean isValidRoot (File file, File[] relatedRoots, File projectFolder) {
    Project p;
    if ((p = FileOwnerQuery.getOwner(Utilities.toURI(file)))!=null
        && !file.getAbsolutePath().startsWith(projectFolder.getAbsolutePath()+File.separatorChar)) {
        final Sources sources = p.getLookup().lookup(Sources.class);
        if (sources == null) {
            return false;
        }
        final SourceGroup[] sourceGroups = sources.getSourceGroups(Sources.TYPE_GENERIC);
        final SourceGroup[] javaGroups = sources.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
        final SourceGroup[] groups = new SourceGroup [sourceGroups.length + javaGroups.length];
        System.arraycopy(sourceGroups,0,groups,0,sourceGroups.length);
        System.arraycopy(javaGroups,0,groups,sourceGroups.length,javaGroups.length);
        final FileObject projectDirectory = p.getProjectDirectory();
        final FileObject fileObject = FileUtil.toFileObject(file);
        if (projectDirectory == null || fileObject == null) {
            return false;
        }
        for (int i = 0; i< groups.length; i++) {
            final FileObject sgRoot = groups[i].getRootFolder();
            if (fileObject.equals(sgRoot)) {
                return false;
            }
            if (!projectDirectory.equals(sgRoot) && FileUtil.isParentOf(sgRoot, fileObject)) {
                return false;
            }
        }
        return true;
    }
    else if (contains (file, relatedRoots)) {
        return false;
    }
    return true;
}
 
Example #22
Source File: Configuration.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void handleIOEFromReload(IOException e) {
    Project project = FileOwnerQuery.getOwner(getProjectsConfigurationFile());
    String projectDisplayName = project != null ? ProjectUtils.getInformation(project).getDisplayName() : "???"; //NOI18N
    String msg = String.format("An error found in the configuration file %s in the project %s: %s", getProjectsConfigurationFile().getNameExt(), projectDisplayName, e.getMessage());

    NotifyDescriptor d = new NotifyDescriptor.Message(msg, NotifyDescriptor.INFORMATION_MESSAGE);
    DialogDisplayer.getDefault().notifyLater(d);
}
 
Example #23
Source File: SourcesHelperTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testExternalRootRegistration() throws Exception {
    FileObject f = maindir.getFileObject("readme");
    assertEquals("readme not yet registered", null, FileOwnerQuery.getOwner(f));
    f = projdir.getFileObject("projfile");
    assertEquals("projfile initially OK", project, FileOwnerQuery.getOwner(f));
    sh.registerExternalRoots(FileOwnerQuery.EXTERNAL_ALGORITHM_TRANSIENT);
    f = maindir.getFileObject("readme");
    assertEquals("readme now registered", project, FileOwnerQuery.getOwner(f));
    f = projdir.getFileObject("projfile");
    assertEquals("projfile still OK", project, FileOwnerQuery.getOwner(f));
    f = src1dir.getFileObject("src1file");
    assertEquals("src1file registered", project, FileOwnerQuery.getOwner(f));
    f = src2dir.getFileObject("src2file");
    assertEquals("src2file registered", project, FileOwnerQuery.getOwner(f));
    f = src3dir.getFileObject("src3file");
    assertEquals("src3file registered", project, FileOwnerQuery.getOwner(f));
    f = builddir.getFileObject("buildfile");
    assertEquals("buildfile registered", project, FileOwnerQuery.getOwner(f));
    f = extdir.getFileObject("extFile");
    assertEquals("extfile registered", project, FileOwnerQuery.getOwner(f));
    assertEquals("extdir not registered", null, FileOwnerQuery.getOwner(extdir));
    f = scratch.getFileObject("otherfile");
    assertEquals("otherfile not registered", null, FileOwnerQuery.getOwner(f));
    // Test the simpler project type.
    sh2.registerExternalRoots(FileOwnerQuery.EXTERNAL_ALGORITHM_TRANSIENT);
    f = proj2dir.getFileObject("proj2file");
    assertEquals("proj2file of course OK", project2, FileOwnerQuery.getOwner(f));
    f = proj2src1dir.getFileObject("proj2src1file");
    assertEquals("proj2src1file registered", project2, FileOwnerQuery.getOwner(f));
    f = proj2src2dir.getFileObject("proj2src2file");
    assertEquals("proj2src2file registered", project2, FileOwnerQuery.getOwner(f));
    f = ext2dir.getFileObject("ext2File");
    assertEquals("ext2File registered", project2, FileOwnerQuery.getOwner(f));
    assertEquals("ext2dir not registered", null, FileOwnerQuery.getOwner(ext2dir));
}
 
Example #24
Source File: ParsingErrorsFilter.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static Collection<SetFilterAction> getEnableFilterAction(@NonNull FileObject file) {
    FileObject source = file;
    Collection<SetFilterAction> actions = new ArrayList<>();
    for (; file != null && FileOwnerQuery.getOwner(file) != null; file = file.getParent()) {
        actions.add(new SetFileFilterAction(source, file, true));
    }
    return actions;
}
 
Example #25
Source File: ProjectAccessibilityQuery.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public Boolean isPubliclyAccessible(FileObject pkg) {
    Project project = FileOwnerQuery.getOwner(pkg);
    if (project != null) {
        AccessibilityQueryImplementation aqi = project.getLookup().lookup(AccessibilityQueryImplementation.class);
        if (aqi != null) {
            return aqi.isPubliclyAccessible(pkg);
        }
    }
    return null;
}
 
Example #26
Source File: ProjectEarProvider.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public Ear findEar (FileObject file) {
    Project project = FileOwnerQuery.getOwner (file);
    if (project != null && project instanceof EarProject) {
        EarProject ep = (EarProject) project;
        FileObject prjdir = ep.getProjectDirectory();
        if (prjdir != null && (prjdir.equals (file) || FileUtil.isParentOf(prjdir, file))) {
            return ep.getEar();
        }
    }
    return null;
}
 
Example #27
Source File: KOHtmlExtension.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private boolean isTagCustomKnockoutElement(FileObject fo, String tagName) {
    Project project = FileOwnerQuery.getOwner(fo);
    if (project == null) {
        return false;
    }
    KnockoutIndex knockoutIndex = null;
    try {
        knockoutIndex = KnockoutIndex.get(project);
    } catch (IOException ex) {
        Exceptions.printStackTrace(ex);
    }
    if (knockoutIndex != null) {
        Collection<KnockoutCustomElement> customElements = knockoutIndex.getCustomElements(tagName, false);
        if (customElements == null || customElements.isEmpty()) {
            return false;
        }
        boolean customTagFound = false;
        for (KnockoutCustomElement kce : customElements) {
            if (kce.getName().equals(tagName)) {
                customTagFound = true;
                break;
            }
        }
        return customTagFound;
    }
    return false;
}
 
Example #28
Source File: ProfilesAnalyzer.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@NonNull
private static Collection<FileObject> findOwnedRoots(@NonNull final FileObject file) {
    final Project p = FileOwnerQuery.getOwner(file);
    if (p == null || !file.equals(p.getProjectDirectory())) {
        return Collections.emptySet();
    }
    final Sources sources = ProjectUtils.getSources(p);
    final Collection<FileObject> res = new ArrayList<>();
    for (SourceGroup grp : sources.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA)) {
        res.add(grp.getRootFolder());
    }
    return res;
}
 
Example #29
Source File: Undeploy.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void execute() throws BuildException {

        ClassLoader originalLoader = null;

        try {
            // see issue #62448
            ClassLoader current = (ClassLoader)Lookup.getDefault().lookup(ClassLoader.class);
            if (current == null) {
                current = ClassLoader.getSystemClassLoader();
            }
            if (current != null) {
                originalLoader = Thread.currentThread().getContextClassLoader();
                Thread.currentThread().setContextClassLoader(current);
            }

            J2eeModuleProvider jmp = null;
            try {
                FileObject fob = FileUtil.toFileObject(getProject().getBaseDir());
                fob.refresh(); // without this the "build" directory is not found in filesystems
                jmp = (J2eeModuleProvider) FileOwnerQuery.getOwner(fob).getLookup().lookup(J2eeModuleProvider.class);
            } catch (Exception e) {
                throw new BuildException(e);
            }

            try {
                Deployment.getDefault ().undeploy(jmp, startServer, this);
            } catch (Exception ex) {
                if (failOnError) {
                    throw new BuildException(ex);
                }
            }
        } finally {
            if (originalLoader != null) {
                Thread.currentThread().setContextClassLoader(originalLoader);
            }
        }
    }
 
Example #30
Source File: NbMoveRefactoringPlugin.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void refactorProjectPropertyFiles(FileObject folder, RefactoringElementsBag refactoringElements) {
    Project project = FileOwnerQuery.getOwner(folder);
    NbModuleProvider moduleProvider = project.getLookup().lookup(NbModuleProvider.class);
    if (moduleProvider == null) {
        // take just netbeans module development into account..
        return;
    }
    
    Sources srcs = org.netbeans.api.project.ProjectUtils.getSources(project);
    SourceGroup[] srcGrps = srcs.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
    SourceGroup[] rscGrps = srcs.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_RESOURCES);
    StringBuffer relPath = new StringBuffer();
    String newName = ((RenameRefactoring)refactoring).getNewName().replace('.', '/');
    if(isProjectPropertiesFilePath(srcGrps, folder, relPath) 
        || isProjectPropertiesFilePath(rscGrps, folder, relPath)) {
        refactoringElements.add(refactoring, new ManifestMoveRefactoringElement(moduleProvider.getManifestFile(), 
        relPath.toString().replace('.', '/'), newName));
    }
    
    NbRefactoringProvider refactoringProvider = project.getLookup().lookup(NbRefactoringProvider.class);
    if(refactoringProvider == null) {
        return;
    }
    
    List<NbRefactoringProvider.ProjectFileRefactoring> projectFilesRefactoring = refactoringProvider.getProjectFilesRefactoring(
        new NbRefactoringContext(folder, newName, relPath.toString().replace('.', '/')));
    if(projectFilesRefactoring!=null) {
        for(NbRefactoringProvider.ProjectFileRefactoring projectFileRefIter : projectFilesRefactoring) {
            refactoringElements.add(refactoring, new ProjectFileMoveRefactoringElement(projectFileRefIter));
        }
    }
}