Lookup lookup = Utilities.actionsGlobalContext(); Project project = lookup.lookup(Project.class); FileObject projectDir = project.getProjectDirectory(); String projectLocation = projectDir.getPath();
/** * Get a PHP project for the given FileObject. * @return a PHP project or <code>null</code>. */ public static PhpProject getPhpProject(FileObject fo) { assert fo != null; Project project = FileOwnerQuery.getOwner(fo); if (project == null) { return null; } return project.getLookup().lookup(PhpProject.class); }
private FileObject pom(Project p) { if (p.getLookup().lookup(NbMavenProject.class) == null) { return null; } return p.getProjectDirectory().getFileObject("pom.xml"); // NOI18N }
@Override public void saveProject(final Project project) throws IOException, ClassCastException { FileObject projectRoot = project.getProjectDirectory(); FarmManager farmManager = Lookup.getDefault().lookup(FarmManager.class); Farm farm = project.getLookup().lookup(Farm.class); farmManager.save(farm, projectRoot.createData(FarmProject.FARM_FILE)); } }
public ConfigurationXMLCodec(String tag, FileObject projectDirectory, MakeConfigurationDescriptor projectDescriptor, String relativeOffset) { super(projectDescriptor, true); this.tag = tag; this.projectDirectory = projectDirectory; this.projectDescriptor = projectDescriptor; this.project = projectDescriptor.getProject(); this.remoteProject = project.getLookup().lookup(RemoteProject.class); if (this.remoteProject == null) { throw new IllegalStateException("RemoteProject not found in lookup for" + projectDescriptor.getProject().getProjectDirectory().getPath()); //NOI18N } this.relativeOffset = relativeOffset; }
public static Datasource getDatasource(Project p, String jndiName) { J2eeModuleProvider provider = (J2eeModuleProvider) p.getLookup().lookup(J2eeModuleProvider.class); try { return provider.getConfigSupport().findDatasource(jndiName); } catch (Exception ex) { Exceptions.printStackTrace(ex); } return null; }
/**ref by ModulesNode *todo : move to some api utils class */ public static Collection<MavenProject> getSubProjects(MavenProject project) { Collection<MavenProject> modules = new ArrayList<MavenProject>(); File base = project.getBasedir(); for (Iterator it = project.getModules().iterator(); it.hasNext();) { String elem = (String) it.next(); File projDir = FileUtil.normalizeFile(new File(base, elem)); FileObject fo = FileUtil.toFileObject(projDir); if (fo != null) { try { Project prj = ProjectManager.getDefault().findProject(fo); if (prj != null && prj.getLookup().lookup(NbMavenProject.class) != null) { modules.add(((NbMavenProject) prj).getOriginalMavenProject()); } } catch (IllegalArgumentException ex) { ex.printStackTrace(); } catch (IOException ex) { ex.printStackTrace(); } } } return modules; } }
if (outputDir != null) { File fl = FileUtil.normalizeFile(new File(outputDir)); outDir = FileUtilities.toFileObject(fl); return; outDir.refresh(); FileObject report = outDir.getFileObject(testname + ".txt"); //NOI18N Project prj = FileOwnerQuery.getOwner(outDir); if (prj != null) { NbMavenProject nbprj = prj.getLookup().lookup(org.codehaus.mevenide.netbeans.NbMavenProject.class); File testDir = new File(nbprj.getOriginalMavenProject().getBuild().getTestSourceDirectory());
public void rerun() { if (scriptFile.getName().equals(JUNIT_CUSTOM_FILENAME + ".xml")){ //NOI18N try { runAnt(FileUtil.toFileObject(scriptFile), targets, properties); } catch (IOException ex) { Exceptions.printStackTrace(ex); properties.setProperty("nb.wait.for.caches", "true"); //NOI18N properties.setProperty("nb.internal.action.name", ActionProvider.COMMAND_TEST); //NOI18N runAnt(FileUtil.toFileObject(scriptFile), targets, properties); } catch (IOException ex) { Exceptions.printStackTrace(ex); ActionProvider actionProvider = project.getLookup().lookup(ActionProvider.class); if (actionProvider != null) { if (Arrays.asList(actionProvider.getSupportedActions()).contains(targets[0])
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; 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; return false; if (!projectDirectory.equals(sgRoot) && FileUtil.isParentOf(sgRoot, fileObject)) { return false;
private void addJavaRootFolders(FileObject fo) { try { Project prj = ProjectManager.getDefault().findProject(fo); ProjectURLWatcher watch = prj.getLookup().lookup(ProjectURLWatcher.class); if (watch != null) { // do not create java/test for pom type projects.. most probably not relevant. if (! ProjectURLWatcher.TYPE_POM.equals(watch.getPackagingType())) { URI mainJava = FileUtilities.convertStringToUri(watch.getMavenProject().getBuild().getSourceDirectory()); URI testJava = FileUtilities.convertStringToUri(watch.getMavenProject().getBuild().getTestSourceDirectory()); File file = new File(mainJava); if (!file.exists()) { file.mkdirs(); } file = new File(testJava); if (!file.exists()) { file.mkdirs(); } } } } catch (IOException ex) { Exceptions.printStackTrace(ex); } catch (IllegalArgumentException ex) { Exceptions.printStackTrace(ex); } }
public static FileObject getResourceDirectory(FileObject fo){ Project holdingProj = FileOwnerQuery.getOwner(fo); FileObject resourceDir = null; if (holdingProj != null){ J2eeModuleProvider provider = (J2eeModuleProvider) holdingProj.getLookup().lookup(J2eeModuleProvider.class); if(provider != null){ File resourceLoc = provider.getJ2eeModule().getResourceDirectory(); if(resourceLoc != null){ if(resourceLoc.exists ()){ resourceDir = FileUtil.toFileObject (resourceLoc); }else{ try { resourceDir = FileUtil.createFolder(resourceLoc); } catch (IOException ex) { LOG.log(Level.SEVERE, "getResourceDirectory failed", ex); } } } } } return resourceDir; }
@Override public void readSettings(WizardDescriptor wiz) { try { final Project project = Templates.getProject(wiz); NbMavenProject nbProj = project.getLookup().lookup(NbMavenProject.class); final URI[] resources = nbProj.getResources(false); File resourceFolder = FileUtil.normalizeFile(FileUtil.archiveOrDirForURL(resources[0].toURL())); File addMeta = new File(resourceFolder, "META-INF/additional-spring-configuration-metadata.json"); if (addMeta.exists()) { wiz.putProperty(WizardDescriptor.PROP_WARNING_MESSAGE, "Existing additional metadata file will be overwritten!"); } } catch (Exception ex) { Exceptions.printStackTrace(Exceptions.attachSeverity(ex, Level.WARNING)); } getComponent().read(wiz); }
private static void doCopy(Project original, FileObject from, FileObject toParent) throws IOException { if (!VisibilityQuery.getDefault().isVisible(from)) { //Do not copy invisible files/folders. return ; } if (!original.getProjectDirectory().equals(FileOwnerQuery.getOwner(from).getProjectDirectory())) { return ; } //#109580 if (SharabilityQuery.getSharability(from) == SharabilityQuery.Sharability.NOT_SHARABLE) { return; } if (from.isFolder()) { FileObject copy = toParent.createFolder(from.getNameExt()); for (FileObject kid : from.getChildren()) { doCopy(original, kid, copy); } } else { assert from.isData(); FileObject target = FileUtil.copyFile(from, toParent, from.getName(), from.getExt()); } }
private static Node constructSemiLogicalView(Project p, Map<FileObject, List<ErrorDescription>> errors, Map<ErrorDescription, List<FixDescription>> errors2Fixes) { LogicalViewProvider lvp = p.getLookup().lookup(LogicalViewProvider.class); Node view; } else { try { view = DataObject.find(p.getProjectDirectory()).getNodeDelegate(); } catch (DataObjectNotFoundException ex) { Exceptions.printStackTrace(ex); return new AbstractNode(Children.LEAF);
/** * * @param pkg * @return */ @Override public Boolean isPubliclyAccessible(FileObject pkg) { FileObject srcdir = org.netbeans.modules.maven.api.FileUtilities.convertStringToFileObject(prj.getLookup().lookup(NbMavenProject.class).getMavenProject().getBuild().getSourceDirectory()); if (srcdir != null) { String path = FileUtil.getRelativePath(srcdir, pkg); if (path != null) { String name = path.replace('/', '.'); return check(name); } } return null; }
private void checkParentProject(FileObject projectDir, boolean delete, String newName, String oldName) throws IOException { String prjLoc = projectDir.getNameExt(); FileObject fo = projectDir.getParent(); Project possibleParent = ProjectManager.getDefault().findProject(fo); if (possibleParent != null) { NbMavenProject par = possibleParent.getLookup().lookup(NbMavenProject.class); if (par != null) { FileObject pomFO = par.getProjectDirectory().getFileObject("pom.xml"); //NOI18N Model mdl = WriterUtils.loadModel(pomFO); MavenProject prj = par.getOriginalMavenProject(); if ((prj.getModules() != null && prj.getModules().contains(prjLoc)) == delete) { //delete/add module from/to parent.. if (delete) { mdl.removeModule(prjLoc); } else { mdl.addModule(prjLoc); } } if (newName != null && oldName != null) { if (oldName.equals(mdl.getArtifactId())) { // is this condition necessary.. why not just overwrite the artifactID always.. mdl.setArtifactId(newName); } } WriterUtils.writePomModel(pomFO, mdl); } } }
public JobCreator(Project project, Configuration config) { this.project = project; this.config = config; this.shar = project.getLookup().lookup(ProjectSharability.class); scm = Helper.prepareSCM(FileUtil.toFile(project.getProjectDirectory())); checkboxen = initComponents(); }
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); } }
@Override protected boolean enable(Node[] activatedNodes) { if (activatedNodes.length == 0) { return false; } DataObject dataObject = activatedNodes[0].getLookup().lookup(DataObject.class); if (dataObject == null || dataObject.getFolder() == null) { return false; } Project prj = FileOwnerQuery.getOwner(dataObject.getFolder().getPrimaryFile()); if (prj == null) { return false; } FileObject domainDir = prj.getProjectDirectory().getFileObject(DOMAIN_DIR); if (domainDir == null) { return false; } return FileUtil.isParentOf(domainDir, dataObject.getPrimaryFile()); } }