private static String getSelectedPackageName(FileObject targetFolder) { Project project = FileOwnerQuery.getOwner(targetFolder); Sources sources = ProjectUtils.getSources(project); SourceGroup[] groups = sources.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA); String packageName = null; for (int i = 0; i < groups.length && packageName == null; i++) { packageName = FileUtil.getRelativePath(groups[i].getRootFolder(), targetFolder); } if (packageName != null) { packageName = packageName.replaceAll("/", "."); // NOI18N } return packageName; }
protected void setProjectFiles(Project project) { Sources sources = ProjectUtils.getSources(project); // returns singleton if (sourcesListener == null) { sourcesListener = WeakListeners.change(this, sources); sources.addChangeListener(sourcesListener); } setGroups(Arrays.asList(sources.getSourceGroups(Sources.TYPE_GENERIC))); }
@Override public void removeNotify() { Sources srcs = ProjectUtils.getSources(project); srcs.removeChangeListener(this); }
@Override public synchronized SourceGroup[] getSourceGroups(String type) { if (delegate == null) { delegate = initSources(); delegate.addChangeListener(this); } return delegate.getSourceGroups(type); }
static boolean isValidRoot (File file, File[] relatedRoots, File projectFolder) { Project p; if ((p = FileOwnerQuery.getOwner(file.toURI()))!=null && !file.getAbsolutePath().startsWith(projectFolder.getAbsolutePath()+File.separatorChar)) { final Sources 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; final FileObject sgRoot = groups[i].getRootFolder(); if (fileObject.equals(sgRoot)) { return false; if (!projectDirectory.equals(sgRoot) && FileUtil.isParentOf(sgRoot, fileObject)) { return false;
for (PathRecognizer pr : Lookup.getDefault().lookupAll(PathRecognizer.class)) { Set<String> ids = pr.getSourcePathIds(); Set<FileObject> nonRecursiveRoots = new HashSet<FileObject>(); for (NonRecursiveFolder f : context.lookupAll(NonRecursiveFolder.class)) { if (cancel.get()) return; nonRecursiveRoots.add(f.getFolder()); for (FileObject c : f.getFolder().getChildren()) { if (!c.isData()) continue; toFormat.add(c); for (SourceGroup sg : context.lookupAll(SourceGroup.class)) { if (cancel.get()) return; addRecursivelly(sg.getRootFolder(), toFormat, sourceIds, null, sg, cancel); for (FileObject root : sCP.getRoots()) { if (cancel.get()) return; Project owner = FileOwnerQuery.getOwner(root); for (SourceGroup sg : ProjectUtils.getSources(prj).getSourceGroups(Sources.TYPE_GENERIC)) { if (cancel.get()) return; addRecursivelly(sg.getRootFolder(), toFormat, sourceIds, null, sg, cancel); handle.progress(Bundle.LBL_Formatting(FileUtil.getFileDisplayName(current)));
@Override public Map<String,String> createReplacements(String action, Lookup lookup) { FileObject f = lookup.lookup(FileObject.class); if (f == null) { SingleMethod m = lookup.lookup(SingleMethod.class); if (m != null) { f = m.getFile(); } } if (f != null && "text/x-scala".equals(f.getMIMEType())) { for (SourceGroup g : ProjectUtils.getSources(project).getSourceGroups(ScalaSourcesImpl.TYPE_SCALA)) { String relPath = FileUtil.getRelativePath(g.getRootFolder(), f); if (relPath != null) { Map<String,String> replaceMap = new HashMap<String,String>(); replaceMap.put(CLASSNAME_EXT, f.getNameExt()); replaceMap.put(CLASSNAME, f.getName()); String pack = FileUtil.getRelativePath(g.getRootFolder(), f.getParent()); if (pack != null) { //#141175 replaceMap.put(PACK_CLASSNAME, (pack + (pack.length() > 0 ? "." : "") + f.getName()).replace('/', '.')); } else { replaceMap.put(PACK_CLASSNAME, f.getName()); } replaceMap.put(CLASSPATHSCOPE, g.getName().equals(ScalaSourcesImpl.NAME_SCALATESTSOURCE) ? "test" : "runtime"); return replaceMap; } } } return Collections.emptyMap(); }
if (FileType.FILTER.equals(fileType) && ((WrapperSelection)customPanel).isWrapper()) { template = Templates.getTemplate(wizard); FileObject templateParent = template.getParent(); template = templateParent.getFileObject("AdvancedFilter","java"); //NOI18N ContainerClassPathModifier modifier = project.getLookup().lookup(ContainerClassPathModifier.class); if (modifier != null) { modifier.extendClasspath(dobj.getPrimaryFile(), new String[] { FileObject webInf = wm.getWebInf(); if (webInf == null) { webInf = FileUtil.createFolder(wm.getDocumentBase(), "WEB-INF"); //NOI18N FileObject targetFolder = Templates.getTargetFolder(wizard); String packageName = null; Sources sources = ProjectUtils.getSources(project); SourceGroup[] groups = sources.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA); for (int i = 0; i < groups.length && packageName == null; i++) { if (WebModule.getWebModule (groups [i].getRootFolder ()) != null) { packageName = FileUtil.getRelativePath (groups [i].getRootFolder (), targetFolder); dobj.getPrimaryFile().setAttribute("org.netbeans.modules.web.IsServletFile",
public void processLine(String line, OutputVisitor visitor) { Matcher match = failPattern.matcher(line); if (match.matches()) { String clazz = match.group(1); String lineNum = match.group(2); String text = match.group(4); visitor.setOutputListener(new CompileAnnotation(clazz, lineNum, text), text.indexOf("[deprecation]") < 0); //NOI18N File clazzfile = new File(clazz + ".java"); //NOI18N FileObject file = FileUtilities.toFileObject(FileUtil.normalizeFile(clazzfile)); String newclazz = clazz; if (file != null) { Project prj = FileOwnerQuery.getOwner(file); if (prj != null) { Sources srcs = prj.getLookup().lookup(Sources.class); if (srcs != null) { for (SourceGroup grp : srcs.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA)) { if (FileUtil.isParentOf(grp.getRootFolder(), file)) { newclazz = FileUtil.getRelativePath(grp.getRootFolder(), file); } } } } } line = line.replace(clazz, newclazz); visitor.setLine(line); } }
j2eeProfile, createData.getLibrariesDefinition(), createData.skipTests()); FileObject srcFO = projectDir.createFolder(DEFAULT_SRC_FOLDER); FileObject confFolderFO = null; srcFO.createFolder(DEFAULT_JAVA_FOLDER); confFolderFO = srcFO.createFolder(DEFAULT_CONF_FOLDER); FileObject manifest = FileUtil.createData(confFolderFO, "MANIFEST.MF"); //NOI18N FileLock lock = manifest.lock(); BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(manifest.getOutputStream(lock), FileEncodingQuery.getEncoding(manifest))); FileUtil.createFolder(projectDir, DEFAULT_TEST_FOLDER); ProjectWebModule pwm = (ProjectWebModule) p.getLookup().lookup(ProjectWebModule.class); if (pwm != null) { //should not be null pwm.setContextPath(contextPath); ProjectUtils.getSources(p).getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
public static ActionManager getActionManager(Project project) { Sources srcs = project.getLookup().lookup(Sources.class); if(srcs == null) return null; SourceGroup groups[] = srcs.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA); if(groups != null && groups.length > 0) { return ActionManager.getActionManager(groups[0].getRootFolder()); } else { return null; } }
private DeclarationLocation findFileLocation(FileObject fo, String endPartName) { Project project = FileOwnerQuery.getOwner(fo); if (project == null) { return DeclarationLocation.NONE; Sources sources = project.getLookup().lookup(Sources.class); SourceGroup[] sourceGroups = sources.getSourceGroups(Sources.TYPE_GENERIC); for (SourceGroup sourceGroup : sourceGroups) { Collection<FileObject> filesInGroup = new ArrayList<>(); findFilesWithEndPath(endPath, sourceGroup.getRootFolder(), filesInGroup); int rootPathLength = sourceGroup.getRootFolder().getPath().length(); for (FileObject fileObject : filesInGroup) { if (SearchInfoUtils.SHARABILITY_FILTER.searchFile(fileObject)) { String shortPathName = fileObject.getPath(); shortPathName = shortPathName.substring(rootPathLength + 1); files.put(shortPathName, fileObject);
/** Creates a new instance of NewFileDescriptorData */ public BasicDataModel(WizardDescriptor wiz) { Project tmpProject = Templates.getProject(wiz); if (tmpProject == null) { throw new IllegalArgumentException(); } module = tmpProject.getLookup().lookup(NbModuleProvider.class); if (module == null) { throw new IllegalArgumentException(tmpProject.getClass().toString()); } project = tmpProject; // #66339 need to prefetch the packagename and populate data with it.. FileObject fo = Templates.getTargetFolder(wiz); if (fo != null) { Sources srcs = ProjectUtils.getSources(project); // #63247: don't use lookup directly SourceGroup[] grps = srcs.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA); for (int i = 0; i < grps.length; i++) { if (FileUtil.isParentOf(grps[i].getRootFolder(), fo)) { String relPath = FileUtil.getRelativePath(grps[i].getRootFolder(), fo); relPath = relPath.replace('/', '.'); setPackageName(relPath); break; } } } }
public void run() { final Set<File> result = new HashSet<File>(); for (SourceGroup group : ProjectUtils.getSources(project).getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA)) { for (FileObject fo : NbCollections.iterable(group.getRootFolder().getChildren(true))) { if (Thread.currentThread().isInterrupted()) { return; if (!SpringConstants.CONFIG_MIME_TYPE.equals(fo.getMIMEType())) { continue; File file = FileUtil.toFile(fo); if (file == null) { continue; for (SpringConfigFileProvider provider : project.getLookup().lookupAll(SpringConfigFileProvider.class)) { if (Thread.currentThread().isInterrupted()) { return;
String lineNum = match.group(2); String text = match.group(3); File clazzfile = FileUtil.normalizeFile(new File(clazz + ".scala")); //NOI18N visitor.setOutputListener(new CompileAnnotation(clazzfile, lineNum, text), true); FileUtil.refreshFor(clazzfile); FileObject file = FileUtil.toFileObject(clazzfile); String newclazz = clazz; if (file != null) { Project prj = FileOwnerQuery.getOwner(file); if (prj != null) { Sources srcs = ProjectUtils.getSources(prj); if (srcs != null) { for (SourceGroup grp : srcs.getSourceGroups(ScalaSourcesImpl.TYPE_SCALA)) { if (FileUtil.isParentOf(grp.getRootFolder(), file)) { newclazz = FileUtil.getRelativePath(grp.getRootFolder(), file); if (newclazz.endsWith(".scala")) { //NOI18N newclazz = newclazz.substring(0, newclazz.length() -".scala".length()); //NOI18N
private Iterable<? extends FileObject> getRoots() { Sources _src = null; synchronized (this) { if (this.roots != null) { return this.roots; } if (this.src == null) { this.src = this.project.getLookup().lookup(Sources.class); this.src.addChangeListener(sourcesChangeListener); } _src = this.src; } assert _src != null; final SourceGroup[] sgs = _src.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA); final List<FileObject> _roots = new ArrayList<FileObject>(sgs.length); for (SourceGroup sg : sgs) { final FileObject root = sg.getRootFolder(); if (UnitTestForSourceQuery.findSources(root).length == 0) { _roots.add(root); } } synchronized (this) { if (this.roots == null) { this.roots = _roots; } return this.roots; } }
private static Collection<? extends FileObject> toAnalyze(Lookup l) { Set<FileObject> result = new LinkedHashSet<FileObject>(); for (FileObject fo : l.lookupAll(FileObject.class)) { if (fo.getMIMEType().equals(JAVA_MIME_TYPE)) { result.add(fo); if (fo.isFolder()) { if (containsJavaFiles(fo)) { result.add(fo); for (DataObject od : l.lookupAll(DataObject.class)) { FileObject primaryFile = od.getPrimaryFile(); if (primaryFile.getMIMEType().equals(JAVA_MIME_TYPE)) { result.add(primaryFile); for (Project p : l.lookupAll(Project.class)) { Sources s = ProjectUtils.getSources(p); for (SourceGroup sg : s.getSourceGroups("java")) { // NOI18N result.add(sg.getRootFolder());
public static ClassPath getClassPath(Project project, String type) { ClassPathProvider provider = project.getLookup().lookup(ClassPathProvider.class); if (provider == null) { return null; } Sources sources = project.getLookup().lookup(Sources.class); if (sources == null) { return null; } SourceGroup[] sourceGroups = sources.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA); List<ClassPath> classPaths = new ArrayList<ClassPath>(sourceGroups.length); for (SourceGroup sourceGroup : sourceGroups) { String sourceGroupId = sourceGroup.getName(); if (sourceGroupId != null && sourceGroupId.contains("test")) { // NOI18N continue; } FileObject rootFolder = sourceGroup.getRootFolder(); ClassPath path = provider.findClassPath(rootFolder, type); classPaths.add(path); } return ClassPathSupport.createProxyClassPath(classPaths.toArray(new ClassPath[classPaths.size()])); }
DocBaseNodeList(WebProject proj) { project = proj; evaluator = project.evaluator(); helper = project.getUpdateHelper(); Sources s = project.getLookup().lookup(Sources.class); assert s != null; // assert s.getSourceGroups(WebProjectConstants.TYPE_DOC_ROOT).length > 0; if(s.getSourceGroups(WebProjectConstants.TYPE_DOC_ROOT).length > 0) { webDocRoot = s.getSourceGroups(WebProjectConstants.TYPE_DOC_ROOT)[0]; } else { String name = ProjectUtils.getInformation( proj ).getDisplayName(); NotifyDescriptor nd = new NotifyDescriptor.Message(NbBundle.getMessage(DocBaseNodeList.class, "LBL_No_Source_Groups_Found", name), NotifyDescriptor.INFORMATION_MESSAGE); DialogDisplayer.getDefault().notify(nd); } }
private String getPackageName(FileObject file){ FileObject parent = file.getParent(); Sources sources = ProjectUtils.getSources(project); SourceGroup[] groups = sources.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA); String packageName = null; for (int i = 0; i < groups.length && packageName == null; i++) { packageName = FileUtil.getRelativePath(groups[i].getRootFolder(), parent); if (packageName != null) { packageName = groups[i].getName() + "/" + packageName; // NOI18N } } return packageName + ""; // NOI18N }