Java Code Examples for org.netbeans.api.project.Project

The following are top voted examples for showing how to use org.netbeans.api.project.Project. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: incubator-netbeans   File: Classpaths.java   View source code 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 2
Project: incubator-netbeans   File: DefaultPlugin.java   View source code 6 votes vote down vote up
/**
 * Finds a Java source group the given file belongs to.
 * 
 * @param  file  {@code FileObject} to find a {@code SourceGroup} for
 * @return  the found {@code SourceGroup}, or {@code 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 3
Project: incubator-netbeans   File: LayerNode.java   View source code 6 votes vote down vote up
@Messages({"LBL_this_layer=<this layer>", "LBL_this_layer_in_context=<this layer in context>"})
@Override protected boolean createKeys(List<DataObject> keys) {
    handle.setAutosave(true);
    FileObject layer = handle.getLayerFile();
    if (layer == null) { // #180872, #212541
        return true;
    }
    Project p = FileOwnerQuery.getOwner(layer);
    if (p == null) { // #175861: inside JAR etc.
        return true;
    }
    FileSystem layerfs = handle.layer(false);
    try {
        if (layerfs != null) {
            keys.add(DataObject.find(badge(layerfs, handle.getLayerFile(), LBL_this_layer(), null).getRoot()));
        }
        LayerHandle h = LayerHandle.forProject(p);
        if (layer.equals(h.getLayerFile())) {
            h.setAutosave(true); // #135376
            keys.add(DataObject.find(badge(LayerUtils.getEffectiveSystemFilesystem(p), handle.getLayerFile(), LBL_this_layer_in_context(), handle.layer(false)).getRoot()));
        }
    } catch (IOException e) {
        Util.err.notify(ErrorManager.INFORMATIONAL, e);
    }
    return true;
}
 
Example 4
Project: incubator-netbeans   File: FileChooser.java   View source code 6 votes vote down vote up
/**
 * Create chooser for given AntProjectHelper. Standard file chooser is shown
 * if project is not sharable.
 * 
 * @param helper ant project helper; cannot be null
 * @param copyAllowed is file copying allowed
 */
public FileChooser(AntProjectHelper helper, boolean copyAllowed) {
    super();
    FileObject projectFolder = helper.getProjectDirectory();
    Project p = projectFolder != null ? FileOwnerQuery.getOwner(projectFolder): null;
    LibraryManager lm = p != null ? ReferenceHelper.getProjectLibraryManager(p) : null;
    if (lm != null) {
        URL u = lm.getLocation();
        if (u != null) {
            File libBase = Utilities.toFile(URI.create(u.toExternalForm())).getParentFile();
            accessory = new FileChooserAccessory(this, FileUtil.toFile(helper.getProjectDirectory()), 
                libBase, copyAllowed);
            setAccessory(accessory);
        }
    }
}
 
Example 5
Project: incubator-netbeans   File: SimpleFileOwnerQueryImplementation.java   View source code 6 votes vote down vote up
/** @see FileOwnerQuery#markExternalOwner */
public static void markExternalOwnerTransient(URI root, Project owner) {
    externalRootsIncludeNonFolders |= !root.getPath().endsWith("/");
    if (owner != null) {
        FileObject fo = owner.getProjectDirectory();
        URI foUri = owner == FileOwnerQuery.UNOWNED ? UNOWNED_URI : fo.toURI();
        synchronized (cacheLock) {
            cacheInvalid = true;
            externalOwners.put(root, foUri);
            deserializedExternalOwners.remove(root);
        }
    } else {
        synchronized (cacheLock) {
            cacheInvalid = true;
            externalOwners.remove(root);
        }
    }
}
 
Example 6
Project: incubator-netbeans   File: Util.java   View source code 6 votes vote down vote up
/**
 * Creates a persistence unit using the PU wizard and adds the created
 * persistence unit to the given project's <code>PUDataObject</code> and saves it.
 *
 * @param project the project to which the created persistence unit is to be created.
 * @param preselectedDB the name of the db connection that should be preselected, or null if none needs
 * to be preselected.
 * @param tableGeneration the table generation strategy for the persistence unit.
 *
 * @return true if the creation of the persistence unit was successful, false otherwise.
 *
 * @throws InvalidPersistenceXmlException if the persistence.xml file in the given
 * project is not valid.
 *
 */
public static boolean createPersistenceUnitUsingWizard(Project project,
        String preselectedDB, TableGeneration tableGeneration) throws InvalidPersistenceXmlException {

    PersistenceUnit punit = buildPersistenceUnitUsingWizard(project, preselectedDB, tableGeneration);
    if (punit == null) {
        return false;
    }
    String version = Persistence.VERSION_1_0;
    if(punit instanceof org.netbeans.modules.j2ee.persistence.dd.persistence.model_2_1.PersistenceUnit) {
        version = Persistence.VERSION_2_1;
    } else if(punit instanceof org.netbeans.modules.j2ee.persistence.dd.persistence.model_2_0.PersistenceUnit) {
        version = Persistence.VERSION_2_0;
    }
    PUDataObject pud = ProviderUtil.getPUDataObject(project, version);
    if (pud == null) {
        return false;
    }
    pud.addPersistenceUnit(punit);
    pud.save();
    return true;
}
 
Example 7
Project: incubator-netbeans   File: ProjectXMLManagerTest.java   View source code 6 votes vote down vote up
private static void checkDependenciesOrder(final Project proj) throws Exception {
    FileObject projectXML = proj.getProjectDirectory().getFileObject("nbproject/project.xml");
    BufferedReader r = new BufferedReader(new InputStreamReader(projectXML.getInputStream()));
    try {
        String previousCNB = null;
        String line;
        while ((line = r.readLine()) != null) {
            line = line.trim();
            if (line.matches("<code-name-base>.+</code-name-base>")) {
                String currentCNB = line.substring(16, line.length() - 17);
                assertTrue("dependencies order, previous = \"" + previousCNB + "\", current = \"" + currentCNB + "\"",
                        previousCNB == null || previousCNB.compareTo(currentCNB) < 0);
                previousCNB = currentCNB;
            }
        }
    } finally {
        r.close();
    }
}
 
Example 8
Project: incubator-netbeans   File: JUnitProjectOpenedHook.java   View source code 6 votes vote down vote up
private void updateProjectProperties(Project project) throws IOException {
    final FileObject projectDir = project.getProjectDirectory();
    ProjectManager.mutex().postWriteRequest(new Runnable() {
        @Override
        public void run() {
            try {
                FileObject projectProperties = FileUtil.createData(projectDir, AntProjectHelper.PROJECT_PROPERTIES_PATH);
                Properties props = getProjectProperties(projectDir);

                if (isJUnit3specific) {
                    String testClasspath = props.getProperty(PROP_JAVAC_TEST_CLASSPATH);
                    props.put(PROP_JAVAC_TEST_CLASSPATH, testClasspath.replace("${libs.junit.classpath}", ""));
                }
                props.put(PROP_JUNIT_SELECTED_VERSION, isJUnit3specific ? "3" : "4");
                OutputStream propertiesOS = projectProperties.getOutputStream();
                props.store(propertiesOS, null);
                propertiesOS.close();
            } catch (IOException ex) {
                Exceptions.printStackTrace(ex);
            }
        }
    });
}
 
Example 9
Project: chipKIT-importer   File: ProjectSetupStep.java   View source code 6 votes vote down vote up
private void checkForExistingProject() {
    //if project already exists, enable the check box
    if ("".equalsIgnoreCase(view.projectNameField.getText().trim())) {
        view.overwriteCheckBox.setEnabled(false);
    } else {
        File projFolder = FileUtil.normalizeFile( new File( readLocationStringFromField(view.projectDirectoryField) ) );
        FileObject dirFO = FileUtil.toFileObject(projFolder);
        Project proj = null;
        if (dirFO != null) {
            try {
                proj = ProjectManager.getDefault().findProject(dirFO);
            } catch (IOException | IllegalArgumentException ex) {
                view.overwriteCheckBox.setEnabled(false);
            }
        }
        if (proj == null) {
            view.overwriteCheckBox.setEnabled(false);
        } else {
            view.overwriteCheckBox.setEnabled(true);
        }
    }
}
 
Example 10
Project: incubator-netbeans   File: PackagesPanelProvider.java   View source code 6 votes vote down vote up
@Override
public Category createCategory(Lookup context) {
    Project project = context.lookup(Project.class);
    NbMavenProject watcher = project.getLookup().lookup(NbMavenProject.class);
    String effPackaging = watcher.getPackagingType();
    String[] types = PluginPropertyUtils.getPluginPropertyList(project, OSGiConstants.GROUPID_FELIX, OSGiConstants.ARTIFACTID_BUNDLE_PLUGIN, "supportedProjectTypes", "supportedProjectType", /*"bundle" would not work for GlassFish parent POM*/null);
    if (types != null) {
        for (String type : types) {
            if (effPackaging.equals(type)) {
                effPackaging = NbMavenProject.TYPE_OSGI;
            }
        }
    }
    if (NbMavenProject.TYPE_OSGI.equalsIgnoreCase(effPackaging)) {
        return ProjectCustomizer.Category.create(
                ModelHandle2.PANEL_COMPILE,
                org.openide.util.NbBundle.getMessage(PackagesPanelProvider.class, "TIT_Packages"),
                null);
    }
    return null;
}
 
Example 11
Project: incubator-netbeans   File: OpenSubprojects.java   View source code 6 votes vote down vote up
private void getSubProjects() {
    try {
        if(activatedNodes != null) {
            for( int i = 0; i < activatedNodes.length; i++ ) {
                Project p = activatedNodes[i].getLookup().lookup(Project.class);
                if ( p != null ) {
                    ProjectContainerProvider pcp = p.getLookup().lookup(ProjectContainerProvider.class);
                    if (pcp != null) {
                        subProjects = pcp.getContainedProjects().getProjects();
                    } else {
                        SubprojectProvider spp = p.getLookup().lookup(SubprojectProvider.class);
                        if(spp != null) {
                            subProjects = spp.getSubprojects();
                        }
                    }
                }
            }
        }
    } finally {
        initialized = true;
    }
}
 
Example 12
Project: incubator-netbeans   File: BaseProcessor.java   View source code 6 votes vote down vote up
private void processFile(Project project, FileObject fileObject, String originalName, String originalExtension) {
    assert fileObject.isData() : "File expected: " + fileObject;
    if (!isSupportedFile(fileObject)) {
        // unsupported file
        return;
    }
    if (!processedFiles.add(fileObject)) {
        // already processed
        return;
    }
    if (fileObject.isValid()) {
        fileChanged(project, fileObject);
        if (originalName != null) {
            // file renamed
            fileRenamed(project, fileObject, originalName, originalExtension);
        }
    } else {
        // deleted file
        fileDeleted(project, fileObject);
    }
}
 
Example 13
Project: incubator-netbeans   File: RetoucheUtils.java   View source code 6 votes vote down vote up
public static boolean isOnSourceClasspath(FileObject fo) {
    Project p = FileOwnerQuery.getOwner(fo);
    if (p==null) return false;
    Project[] opened = OpenProjects.getDefault().getOpenProjects();
    for (int i = 0; i<opened.length; i++) {
        if (p.equals(opened[i]) || opened[i].equals(p)) {
            SourceGroup[] gr = ProjectUtils.getSources(p).getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
            for (int j = 0; j < gr.length; j++) {
                if (fo==gr[j].getRootFolder()) return true;
                if (FileUtil.isParentOf(gr[j].getRootFolder(), fo))
                    return true;
            }
            return false;
        }
    }
    return false;
}
 
Example 14
Project: incubator-netbeans   File: TestSingleMethodSupport.java   View source code 6 votes vote down vote up
public static boolean isTestClass(Node activatedNode) {
    FileObject fileObject = org.netbeans.modules.gsf.testrunner.ui.api.UICommonUtils.getFileObjectFromNode(activatedNode);
    if (fileObject != null && CommonTestUtil.isJavaFile(fileObject)) {
        Project project = FileOwnerQuery.getOwner(fileObject);
        if (project != null) {
            SourceGroup[] javaSGs = new JavaUtils(project).getJavaSourceGroups();
            for (int i = 0; i < javaSGs.length; i++) {
                SourceGroup javaSG = javaSGs[i];
                FileObject rootFolder = javaSG.getRootFolder();
                URL[] testRoots = UnitTestForSourceQuery.findUnitTests(rootFolder);
                URL[] sourceRoots = UnitTestForSourceQuery.findSources(rootFolder);
                if (((fileObject == rootFolder) || FileUtil.isParentOf(rootFolder, fileObject)) && javaSG.contains(fileObject)) {
                    // activated FO is contained in the javaSG source group
                    if (testRoots.length == 0 && sourceRoots.length > 0) {
                        // javaSG has corresponding source root but no corresponding test root,
                        // thus the activated FO is a test class, so activate action
                        return true;
                    }
                }
            }
        }
    }
    return false;
}
 
Example 15
Project: incubator-netbeans   File: OpenProjectListTest.java   View source code 6 votes vote down vote up
public void testListenerOpenClose () throws Exception {
    assertTrue ("No project is open.", OpenProjectList.getDefault ().getOpenProjects ().length == 0); 
    ChangeListener list = new ChangeListener();
    OpenProjectList.getDefault().addPropertyChangeListener(list);
    CharSequence log = Log.enable("org.netbeans.ui", Level.FINE);
    OpenProjectList.getDefault ().open (project1, true);
    Pattern p = Pattern.compile("Opening.*1.*TestProject", Pattern.MULTILINE | Pattern.DOTALL);
    Matcher m = p.matcher(log);
    if (!m.find()) {
        fail("There should be TestProject\n" + log.toString());
    }
    assertEquals(0, list.oldCount);
    assertEquals(1, list.newCount);
    OpenProjectList.getDefault ().open (project2, true);
    assertEquals(1, list.oldCount);
    assertEquals(2, list.newCount);
    OpenProjectList.getDefault().close(new Project[] {project1}, false);
    assertEquals(2, list.oldCount);
    assertEquals(1, list.newCount);
    OpenProjectList.getDefault().close(new Project[] {project2}, false);
    assertEquals(1, list.oldCount);
    assertEquals(0, list.newCount);
}
 
Example 16
Project: incubator-netbeans   File: ProjectUtilities.java   View source code 6 votes vote down vote up
public static boolean hasAction(Project project, String actionName) {
    ActionProvider ap = project.getLookup().lookup(ActionProvider.class);

    if (ap == null) {
        return false; // return false if no ActionProvider available
    }

    String[] actions = ap.getSupportedActions();

    for (int i = 0; i < actions.length; i++) {
        if ((actions[i] != null) && actionName.equals(actions[i])) {
            return true;
        }
    }

    return false;
}
 
Example 17
Project: incubator-netbeans   File: InstallToPaletteAction.java   View source code 6 votes vote down vote up
@Override
protected boolean enable(Node[] activatedNodes) {
    if (activatedNodes.length == 0) {
        return false;
    }
    for (Node n: activatedNodes) {
        FileObject fobj = n.getLookup().lookup(FileObject.class);
        if (fobj == null || JavaSource.forFileObject(fobj) == null) {
            return false;
        }
        // Issue 73641
        Project project = FileOwnerQuery.getOwner(fobj);
        if (project != null) {
            RecommendedTemplates info = project.getLookup().lookup(RecommendedTemplates.class);
            if ((info != null) && !Arrays.asList(info.getRecommendedTypes()).contains("java-forms")) { // NOI18N
                return false;
            }
        }
    }
    
    return true;
}
 
Example 18
Project: incubator-netbeans   File: WizardUtils.java   View source code 6 votes vote down vote up
/**
 * Returns {@link ComboBoxModel} containing {@link LayerItemPresenter}s
 * wrapping all folders under the given <code>sfsRoot</code>.
 *
 * @param excludeAttrs {@link Map} of pairs String - Object used to filter
 *                     out folders which have one or more attribute(key)
 *                     with a corresponding value.
 */
public static ComboBoxModel createLayerPresenterComboModel(
        final Project project, final String sfsRoot, final Map<String,Object> excludeAttrs) {
    DefaultComboBoxModel model = new DefaultComboBoxModel();
    try {
        FileSystem sfs = project.getLookup().lookup(NbModuleProvider.class).getEffectiveSystemFilesystem();
        FileObject root = sfs.getRoot().getFileObject(sfsRoot);
        if (root != null) {
            SortedSet<LayerItemPresenter> presenters = new TreeSet<LayerItemPresenter>();
            for (FileObject subFolder : getFolders(root, excludeAttrs)) {
                presenters.add(new LayerItemPresenter(subFolder, root));
            }
            for (LayerItemPresenter presenter : presenters) {
                model.addElement(presenter);
            }
        }
    } catch (IOException exc) {
        Logger.getLogger(UIUtil.class.getName()).log(Level.INFO, "Failed to create model of " + sfsRoot, exc);
    }
    return model;
}
 
Example 19
Project: incubator-netbeans   File: MavenRunOptions.java   View source code 5 votes vote down vote up
/**
 * Creates new form MavenRunOptions
 */
public MavenRunOptions(Project project, Category category, ModelHandle2 handle) {
    this.project = project;
    this.category = category;
    this.handle = handle;
    
    initComponents();

    cbConfiguration.setEditable(false);
    cbConfiguration.setRenderer(new DefaultListCellRenderer() {
        @Override
        public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
            Component com = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
            if (com instanceof JLabel) {
                if (value == handle.getActiveConfiguration()) {
                    com.setFont(com.getFont().deriveFont(Font.BOLD));
                }
            }
            return com;
        }
    });
    
    nestedOptions = (JShellOptions2)pOptions;
    
    setupConfigurations();
    
    loadOptions(null);
    
    nestedOptions.setConfigChangeListener(this::optionsChanged);
    cbConfiguration.addActionListener(this::loadOptions);
}
 
Example 20
Project: incubator-netbeans   File: EntityComparator.java   View source code 5 votes vote down vote up
/**
 * Returns names of all projects opened in the IDE's GUI.
 * @return a collection of the names.
 */
private static Collection<String> getNamesOfOpenProjects() {
    ArrayList<String> names = new ArrayList<String>(10);
    for(Project p: OpenProjects.getDefault().getOpenProjects()) {
        String pName = ProjectUtils.getInformation(p).getDisplayName();
        names.add(pName);
    }
    return names;
}
 
Example 21
Project: incubator-netbeans   File: UpdateTrackingFileOwnerQueryTest.java   View source code 5 votes vote down vote up
private void assertOwnership(String project, String file) throws Exception {
    FileObject projectFO = FileUtil.toFileObject(PropertyUtils.resolveFile(nbRootFile(), project));
    assertNotNull("have project " + project, projectFO);
    Project p = ProjectManager.getDefault().findProject(projectFO);
    assertNotNull("have a project in " + project, p);
    // This has the side effect of forcing a scan of the module universe:
    ClassPath.getClassPath(projectFO.getFileObject("src"), ClassPath.COMPILE);
    FileObject fileFO = FileUtil.toFileObject(PropertyUtils.resolveFile(nbRootFile(), file));
    if (fileFO != null) { // OK if not currently built
        assertEquals("correct owner by FileObject of " + file, p, FileOwnerQuery.getOwner(fileFO));
    }
    assertEquals("correct owner by URI of " + file, p, FileOwnerQuery.getOwner(
            Utilities.toURI(PropertyUtils.resolveFile(nbRootFile(), file))));
}
 
Example 22
Project: incubator-netbeans   File: JavaFileFilterListener.java   View source code 5 votes vote down vote up
private boolean verify(final URL root) throws IOException, URISyntaxException {
    boolean result = true;
    final Project p = FileOwnerQuery.getOwner(root.toURI());
    if (p != null) {
        final ProjectConfigurationProvider cp = p.getLookup().lookup(ProjectConfigurationProvider.class);
        if (cp != null) {
            final ProjectConfiguration cfg = cp.getActiveConfiguration();
            if (cfg != null) {
                String name = cfg.getDisplayName();
                result = !JavaIndex.ensureAttributeValue(root, ATTR_FILTER_CFG, name);
            }
        }
    }
    return result;
}
 
Example 23
Project: incubator-netbeans   File: HibernateMappingWizardPanel.java   View source code 5 votes vote down vote up
public String[] getConfigFilesFromProject(Project project) {
    List<String> configFiles = new ArrayList<String>();
    configFileObjects = env.getAllHibernateConfigFileObjects();
    for (FileObject fo : configFileObjects) {
        configFiles.add(fo.getNameExt());
    }
    return configFiles.toArray(new String[]{});
}
 
Example 24
Project: incubator-netbeans   File: JFXGeneratedFilesInterceptor.java   View source code 5 votes vote down vote up
@Override
public void fileGenerated(
        final Project project,
        final String path) {
    if (reenter.get() == Boolean.TRUE) {
        return;
    }
    if (GeneratedFilesHelper.BUILD_IMPL_XML_PATH.equals(path)) {
        final AntBuildExtender extender = project.getLookup().lookup(AntBuildExtender.class);
        if (extender == null) {
            LOG.log(
                Level.WARNING,
                "The project {0} ({1}) does not support AntBuildExtender.",     //NOI18N
                new Object[] {
                    ProjectUtils.getInformation(project).getDisplayName(),
                    FileUtil.getFileDisplayName(project.getProjectDirectory())
                });
            return;
        }
        runDeferred(new Runnable() {
            @Override
            public void run() {
                updateIfNeeded(project, extender);
            }
        });
    }
}
 
Example 25
Project: incubator-netbeans   File: Util.java   View source code 5 votes vote down vote up
public static Provider getDefaultProvider(Project project) {
    PersistenceProviderSupplier providerSupplier = project.getLookup().lookup(PersistenceProviderSupplier.class);
    if ((providerSupplier != null && providerSupplier.supportsDefaultProvider())) {
        List<Provider> providers = providerSupplier.getSupportedProviders();
        if (providers.size() > 0) {
            return providers.get(0);
        }
        Logger.getLogger(RelatedCMPWizard.class.getName()).log(Level.WARNING, "Default provider support is reported without any supported providers. See: {0}", providerSupplier);
    }
    return null;
}
 
Example 26
Project: incubator-netbeans   File: Utilities.java   View source code 5 votes vote down vote up
/**
 * Open project <code>projectName</code> located in <code>dir</code>
 * directory.
 *
 * @param projectName           project name to open
 * @param dir                   project's enclosing directory
 * @return file-object          representing project
 * @throws java.io.IOException  when project cannot be opened
 */
public static FileObject openProject(String projectName, File dir) throws IOException {
    File projectsDir = FileUtil.normalizeFile(dir);
    FileObject projectsDirFO = FileUtil.toFileObject(projectsDir);
    FileObject projdir = projectsDirFO.getFileObject(projectName);
    Project p = ProjectManager.getDefault().findProject(projdir);
    OpenProjects.getDefault().open(new Project[]{p}, false);
    if (p == null) {
        throw new IOException("Project is not opened " + projectName);
    }
    return projdir;
}
 
Example 27
Project: incubator-netbeans   File: ProjectWhiteListQueryImpl.java   View source code 5 votes vote down vote up
@Override
public WhiteListImplementation getWhiteList(FileObject file) {
    final Project project = FileOwnerQuery.getOwner(file);
    if (project != null) {
        final WhiteListQueryImplementation delegate = project.getLookup().lookup(WhiteListQueryImplementation.class);
        if (delegate != null) {
            return delegate.getWhiteList(file);
        }
    }
    return null;
}
 
Example 28
Project: incubator-netbeans   File: FacadeGenerator.java   View source code 5 votes vote down vote up
Set<FileObject> generate(final Project project,
final Map<String, String> entityNames,
final FileObject targetFolder,
final String entityFQN,
final String idClass,
final String pkg,
final boolean hasRemote,
final boolean hasLocal,
boolean overrideExisting) throws IOException;
 
Example 29
Project: incubator-netbeans   File: BookmarkUtils.java   View source code 5 votes vote down vote up
public static Project findProject(URI projectURI) {
    if (projectURI != null) {
        try {
            FileObject prjFO = URLMapper.findFileObject(projectURI.toURL());
            if (prjFO != null && prjFO.isFolder()) {
                return ProjectManager.getDefault().findProject(prjFO);
            }
        } catch (IOException ex) {
            // Cannot load project -> return null
        }
    }
    return null;
}
 
Example 30
Project: incubator-netbeans   File: JAXBBindingSupportFileNode.java   View source code 5 votes vote down vote up
private static Lookup createLookup(FileObject xsdFileObject, 
                                    Project prj) {
    return Lookups.fixed( new Object[] {
        xsdFileObject,
        prj
    } );
}
 
Example 31
Project: incubator-netbeans   File: SelectorUtils.java   View source code 5 votes vote down vote up
private static String getDisplayName(FileObject fo, Project owner, boolean incPrjName) {
    if (owner != null) {
        SourceGroup grp = getSourceGroup(fo, owner);
        String n = (grp!=null)?grp.getDisplayName():FileUtil.getFileDisplayName(fo);
        if (incPrjName) {
            ProjectInformation pi = ProjectUtils.getInformation(owner);
            n  += " [" + pi.getDisplayName() + "]";
        }
        return n;
    } else 
        return FileUtil.getFileDisplayName(fo);
}
 
Example 32
Project: incubator-netbeans   File: CompilerPluginVersionError.java   View source code 5 votes vote down vote up
@Override
public List<ErrorDescription> getErrorsForDocument(POMModel model, Project prj) {
    assert model != null;
    List<ErrorDescription> toRet = new ArrayList<ErrorDescription>();
    
    if(prj == null) {
        return toRet;
    }
    
    if(ModuleInfoUtils.checkModuleInfoAndCompilerFit(prj)) {
        return toRet;
    }
            
    int pos = -1;
    org.netbeans.modules.maven.model.pom.Project p = model.getProject();
    Build bld = p.getBuild();
    if (bld != null) {
        Plugin plg = bld.findPluginById(Constants.GROUP_APACHE_PLUGINS, Constants.PLUGIN_COMPILER);
        if (plg != null) {
            pos = plg.findPosition();
        }
    }    
    
    if(pos == -1) {
        pos = p.findPosition();
    }
    
    if(pos == -1) {
        return toRet;
    }        
           
    Document baseDocument = model.getBaseDocument();        
    Line line = NbEditorUtilities.getLine(baseDocument, pos, false);
    toRet.add(ErrorDescriptionFactory.createErrorDescription(Severity.ERROR, Bundle.DESC_ModulesNotSupported(), Collections.<Fix>singletonList(new UpdatePluginVersion(model)), baseDocument, line.getLineNumber() + 1));
    
    return toRet;
}
 
Example 33
Project: incubator-netbeans   File: PaletteUtils.java   View source code 5 votes vote down vote up
public static synchronized void removePaletteListener(PropertyChangeListener listener,
                                                      FileObject context)
{
    Project project = FileOwnerQuery.getOwner(context);
    ProjectPaletteInfo pInfo = palettes.get(project);
    if (pInfo != null && pInfo.paletteListeners != null) {
        pInfo.paletteListeners.remove(listener);
        pInfo.getPalette().removePropertyChangeListener(listener);
    }
}
 
Example 34
Project: NBANDROID-V2   File: GradleAndroidSources.java   View source code 5 votes vote down vote up
public GradleAndroidSources(Project project, BuildVariant buildConfig) {
    this.project = Preconditions.checkNotNull(project);
    this.buildConfig = Preconditions.checkNotNull(buildConfig);
    buildConfig.addChangeListener(new ChangeListener() {

        @Override
        public void stateChanged(ChangeEvent e) {
            cs.fireChange();
        }
    });
}
 
Example 35
Project: incubator-netbeans   File: JFXProjectProperties.java   View source code 5 votes vote down vote up
/** Getter method */
public static JFXProjectProperties getInstanceIfExists(Project proj) {
    assert proj != null;
    String projDir = proj.getProjectDirectory().getPath();
    JFXProjectProperties prop = propInstance.get(projDir);
    if(prop != null) {
        return prop;
    }
    return null;
}
 
Example 36
Project: incubator-netbeans   File: J2SECategoryExtensionProviderTest.java   View source code 5 votes vote down vote up
@Override
public JComponent createComponent(Project proj, ConfigChangeListener listener) {
    extender = new MockupComponent("MockupRunExtender2");
    extender.setState(false);
    extender.addListener(listener);
    return extender;
}
 
Example 37
Project: incubator-netbeans   File: FreeformSourcesTest.java   View source code 5 votes vote down vote up
public void testNonExistentRoot() throws Exception {
    clearWorkDir();
    final File d = getWorkDir();
    final File proj = new File (d,"proj");
    final File extSrcDir = new File (d,"ext");
    proj.mkdir();
    AntProjectHelper helper = FreeformProjectGenerator.createProject(proj, proj, "prj", null);
    Project p = ProjectManager.getDefault().findProject(helper.getProjectDirectory());

    Element data = Util.getPrimaryConfigurationData(helper);
    Document doc = data.getOwnerDocument();
    Element sf = (Element) data.insertBefore(doc.createElementNS(Util.NAMESPACE, "folders"), XMLUtil.findElement(data, "view", Util.NAMESPACE)).
            appendChild(doc.createElementNS(Util.NAMESPACE, "source-folder"));
    sf.appendChild(doc.createElementNS(Util.NAMESPACE, "label")).appendChild(doc.createTextNode("Sources"));
    sf.appendChild(doc.createElementNS(Util.NAMESPACE, "location")).appendChild(doc.createTextNode("../ext"));
    Util.putPrimaryConfigurationData(helper, data);
    ProjectManager.getDefault().saveProject(p);

    final Sources src = ProjectUtils.getSources(p);
    SourceGroup[] sgs = src.getSourceGroups(Sources.TYPE_GENERIC);
    assertEquals(1,sgs.length);
    assertEquals(p.getProjectDirectory(), sgs[0].getRootFolder());
    final FileObject extFo = FileUtil.createFolder(extSrcDir);
    sgs = src.getSourceGroups(Sources.TYPE_GENERIC);
    assertSourceGroupsEquals(new FileObject[] {p.getProjectDirectory(), extFo}, sgs);
    assertEquals(p, FileOwnerQuery.getOwner(extFo));
}
 
Example 38
Project: incubator-netbeans   File: Selenium2MavenSupportImpl.java   View source code 5 votes vote down vote up
@Override
public boolean isActionEnable(String action, Project project, Lookup lookup) {
    if (action.startsWith("selenium2.")) { //NOI18N
        return true;
    }
    return super.isActionEnable(action, project, lookup);
}
 
Example 39
Project: incubator-netbeans   File: WebServerTest.java   View source code 5 votes vote down vote up
@Override
public Project getOwner(FileObject file) {
    if (file.getParent().equals(testProject1.getProjectDirectory())) {
        return testProject1;
    }
    if (file.getParent().equals(testProject2.getProjectDirectory())) {
        return testProject2;
    }
    return null;
}
 
Example 40
Project: incubator-netbeans   File: JWSProjectProperties.java   View source code 5 votes vote down vote up
/** Factory method */
public static JWSProjectProperties getInstance(Lookup context) {
    Project proj = context.lookup(Project.class);
    String projDir = proj.getProjectDirectory().getPath();
    JWSProjectProperties prop = propInstance.get(projDir);
    if(prop == null) {
        prop = new JWSProjectProperties(context);
        propInstance.put(projDir, prop);
    }
    return prop;
}