private static SourceGroup getRubySourceGroup(FileObject file) { Project prj = FileOwnerQuery.getOwner(file); if (prj == null) return null; Sources src = ProjectUtils.getSources(prj); // SourceGroup[] rubygroups = src.getSourceGroups(RubyProject.SOURCES_TYPE_RUBY); SourceGroup[] rubygroups = src.getSourceGroups(Sources.TYPE_GENERIC); for(int i=0; i<rubygroups.length; i++) { if (rubygroups[i].getRootFolder().equals(file) || FileUtil.isParentOf(rubygroups[i].getRootFolder(), file)) return rubygroups[i]; } return null; }
public static String getLocationText(Object location) { String text = location instanceof SourceGroup ? ((SourceGroup) location).getDisplayName() : location instanceof FileObject ? FileUtil.getFileDisplayName((FileObject) location) : location.toString(); return text; }
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 }
/** */ static SourceGroup getSourceGroup(FileObject file, Project prj) { Sources src = ProjectUtils.getSources(prj); 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; }
@Override public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { if (value != null) { // apple jdk bug SourceGroup g = (SourceGroup) value; super.getListCellRendererComponent(list, g.getDisplayName(), index, isSelected, cellHasFocus); setIcon(g.getIcon(false)); } return this; }
@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(); }
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); } }
/** 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 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 static void populateLocations(FileObject activeFO) { Collection<? extends CommonTestUtilProvider> testUtilProviders = Lookup.getDefault().lookupAll(CommonTestUtilProvider.class); for (CommonTestUtilProvider provider : testUtilProviders) { locations = provider.getTestTargets(activeFO); break; } if (locations != null && locations.length == 0) { SourceGroup sourceGroupOwner = findSourceGroupOwner(activeFO); if (sourceGroupOwner != null) { // get URLs of target SourceGroup's roots locations = UnitTestForSourceQuery.findUnitTests(sourceGroupOwner.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()])); }
@Override public String getShortDescription() { if (g != null) { final DataObject doj = getLookup().lookup(DataObject.class); if (doj != null) { final FileObject f = doj.getPrimaryFile(); String rel = FileUtil.getRelativePath(g.getRootFolder(), f); if (rel != null) { return PackageDisplayUtils.getToolTip(f, rel.replace('/', '.')); //NOI18N } } } return super.getShortDescription(); }
private FileObject findSourceForBinary(FileObject artifact) { FileObject webClassesBase = buildClasses == null ? null : helper.resolveFileObject(buildClasses); FileObject webBuildBase = buildWeb == null ? null : helper.resolveFileObject(buildWeb); if (webClassesBase != null && FileUtil.isParentOf(webClassesBase, artifact)) { String path = FileUtil.getRelativePath(webClassesBase, artifact).replace(".class", ".java"); // NOI18N for (SourceGroup sg : ProjectUtils.getSources(WebProject.this).getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA)) { FileObject fo = sg.getRootFolder().getFileObject(path); if (fo != null) { return fo; } } return null; } if (docBase != null && webBuildBase != null) { if (FileUtil.isParentOf(webBuildBase, artifact)) { String path = FileUtil.getRelativePath(webBuildBase, artifact); return docBase.getFileObject(path); } } return null; } }
private boolean existsFolder(List<SourceGroup> groups, String suffix) { for (SourceGroup group : groups) { if (group.getRootFolder().getPath().endsWith(suffix)) { return true; } } return false; }
static FileObject createResourcesFolder(FileObject srcFile) throws IOException { Project owner = FileOwnerQuery.getOwner(srcFile); if (owner != null) { SourceGroup grp = SourceGroupModifier.createSourceGroup(owner, JavaProjectConstants.SOURCES_TYPE_RESOURCES, JavaProjectConstants.SOURCES_HINT_MAIN); if (grp != null) { //maven project with split sources/resources FileObject root = JavadocAndSourceRootDetection.findPackageRoot(srcFile); String path = FileUtil.getRelativePath(root, srcFile.getParent()); return FileUtil.createFolder(grp.getRootFolder(), path + "/resources"); } } return FileUtil.createFolder(srcFile.getParent(), "resources"); // NOI18N }
@Override public synchronized void setScope(TaskScanningScope scope, Callback callback) { //cancel all current operations: cancelAllCurrent(); this.scope = scope; this.callback = callback; if (scope == null || callback == null) { return; } for (FileObject file : scope.getLookup().lookupAll(FileObject.class)) { enqueue(new Work(file, callback)); } for (Project p : scope.getLookup().lookupAll(Project.class)) { for (SourceGroup generic : ProjectUtils.getSources(p).getSourceGroups(Sources.TYPE_GENERIC)) { enqueue(new Work(generic.getRootFolder(), callback)); } } }
@Override public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { if (value instanceof SourceGroup) { SourceGroup group = (SourceGroup) value; String projectDisplayName = ProjectUtils.getInformation(project).getDisplayName(); String groupDisplayName = group.getDisplayName(); if (projectDisplayName.equals(groupDisplayName)) { setText(groupDisplayName); } else { setText(MessageFormat.format("{1} - {0}", //NOI18N new Object[]{groupDisplayName, projectDisplayName, group.getRootFolder().getName()})); } setIcon(group.getIcon(false)); } else { setText(value.toString()); setIcon(null); } if (isSelected) { setBackground(list.getSelectionBackground()); setForeground(list.getSelectionForeground()); } else { setBackground(list.getBackground()); setForeground(list.getForeground()); } return this; } }
public void actionPerformed(java.awt.event.ActionEvent e) { if ( browseButton == e.getSource() ) { FileObject fo=null; // Show the browse dialog SourceGroup group = (SourceGroup)locationComboBox.getSelectedItem(); fo = BrowseFolders.showDialog( new SourceGroup[] { group }, project, folderTextField.getText().replace( File.separatorChar, '/' ) ); // NOI18N if ( fo != null && fo.isFolder() ) { String relPath = FileUtil.getRelativePath( group.getRootFolder(), fo ); folderTextField.setText( relPath.replace( '/', File.separatorChar ) ); // NOI18N } } else if ( locationComboBox == e.getSource() ) { updateCreatedFolder(); } }
private static FileObject getDefaultBeansTargetFolder( SourceGroup[] sourceGroups, boolean create ) { if ( sourceGroups.length >0 ){ FileObject metaInf = sourceGroups[0].getRootFolder().getFileObject( META_INF ); if ( metaInf == null && create ){ try { metaInf = FileUtil.createFolder( sourceGroups[0].getRootFolder(), META_INF); } catch( IOException e ){ Logger.getLogger( CdiUtil.class.getName() ).log( Level.WARNING, null, e ); } } return metaInf; } return null; }
private static FileObject getSourceRoot(Project project) { Sources sources = ProjectUtils.getSources(project); for (SourceGroup g : sources.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA)) { return g.getRootFolder(); } return null; }