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

The following examples show how to use org.netbeans.api.project.Project. These examples are extracted from open source projects. 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 Project: netbeans   Source File: MainProjectAction.java    License: Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("LeakingThisInConstructor")
MainProjectAction(String command, ProjectActionPerformer performer, String name, Icon icon, Lookup lookup) {
    super(icon, lookup, new Class<?>[] {Project.class, DataObject.class});
    this.command = command;
    this.performer = performer;
    this.name = name;

    String presenterName = "";
    if (name != null) {
        presenterName = MessageFormat.format(name, -1);
    }
    setDisplayName(presenterName);
    if ( icon != null ) {
        setSmallIcon( icon );
    }

    // Start listening on open projects list to correctly enable the action
    OpenProjectList.getDefault().addPropertyChangeListener( WeakListeners.propertyChange( this, OpenProjectList.getDefault() ) );
    // XXX #47160: listen to changes in supported commands on current project, when that becomes possible
}
 
Example 2
Source Project: netbeans   Source File: LogicalViewProviders.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public Node findPath(Node root, Object target) {
    Project prj = root.getLookup().lookup(Project.class);
    if (prj == null) {
        return null;
    }

    if (target instanceof FileObject) {
        FileObject fo = (FileObject) target;
        if (isOtherProjectSource(fo, prj)) {
            return null; // Don't waste time if project does not own the fo among sources
        }

        for (Node n : root.getChildren().getNodes(true)) {
            Node result = PackageView.findPath(n, target);
            if (result != null) {
                return result;
            }
        }
    }

    return null;
}
 
Example 3
Source Project: netbeans   Source File: ActionsUtilTest.java    License: Apache License 2.0 6 votes vote down vote up
public void testCanBeReclaimedWithSimpleLookup() throws Exception {
    Project prj1 = new DummyProject();
    Project prj2 = new DummyProject();
    Lookup projects = Lookups.fixed(new Object[] {
        prj1,
        prj2,
    });
    
    ActionsUtil.getProjectsFromLookup(projects, null);
    
    WeakReference<?> ref1 = new WeakReference<Object>(prj1);
    WeakReference<?> ref2 = new WeakReference<Object>(prj2);
    WeakReference<?> lookup = new WeakReference<Object>(projects);
    
    prj1 = null;
    prj2 = null;
    projects = null;
    
    assertGC("the projects can be reclaimed", ref1);
    assertGC("the projects can be reclaimed", ref2);
    assertGC("the lookup can be reclaimed", lookup);
}
 
Example 4
Source Project: jeddict   Source File: EntityClassesConfigurationPanel.java    License: Apache License 2.0 6 votes vote down vote up
public void initialize(Project project, FileObject targetFolder) {
    this.project = project;

    projectTextField.setText(ProjectUtils.getInformation(project).getDisplayName());

    SourceGroup[] sourceGroups = getJavaSourceGroups(project);
    SourceGroupUISupport.connect(locationComboBox, sourceGroups);

    packageComboBox.setRenderer(PackageView.listRenderer());

    updatePackageComboBox();

    if (targetFolder != null) {
        // set default source group and package cf. targetFolder
        SourceGroup targetSourceGroup = getFolderSourceGroup(sourceGroups, targetFolder);
        if (targetSourceGroup != null) {
            locationComboBox.setSelectedItem(targetSourceGroup);
            String targetPackage = getPackageForFolder(targetSourceGroup, targetFolder);
            if (targetPackage != null) {
                packageComboBoxEditor.setText(targetPackage);
            }
        }
    }
}
 
Example 5
public MissingNbInstallationProblemProvider(Project prj) {
    pchs = new PropertyChangeSupport(this);
    project = prj;
    propertyListener = new PropertyChangeListener() {
        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            if (OpenProjects.PROPERTY_OPEN_PROJECTS.equals(evt.getPropertyName()) && OpenProjects.getDefault().isProjectOpen(project)) {
                pchs.firePropertyChange(PROP_PROBLEMS, null, null);
            }
            if (NbMavenProject.PROP_PROJECT.equals(evt.getPropertyName())) {
                pchs.firePropertyChange(PROP_PROBLEMS, null, null);
            }
        }
    };
    weak = WeakListeners.propertyChange(propertyListener, this);
}
 
Example 6
Source Project: netbeans   Source File: MavenModelUtils.java    License: Apache License 2.0 6 votes vote down vote up
/** Detect JAX-WS Library in project.
 *
 * @param project Project
 * @return true if library was detected
 */
public static boolean hasJaxWsAPI(Project project) {
    SourceGroup[] srcGroups = ProjectUtils.getSources(project).getSourceGroups(
            JavaProjectConstants.SOURCES_TYPE_JAVA);
    if (srcGroups.length > 0) {
        ClassPath classPath = ClassPath.getClassPath(srcGroups[0].getRootFolder(), ClassPath.BOOT);
        FileObject wsFeature = classPath.findResource("javax/xml/ws/WebServiceFeature.class"); // NOI18N
        if (wsFeature == null) {
            classPath = ClassPath.getClassPath(srcGroups[0].getRootFolder(), ClassPath.COMPILE);
            wsFeature = classPath.findResource("javax/xml/ws/WebServiceFeature.class"); // NOI18N
            if (wsFeature == null) {
                return false;
            }
        }
    }
    return true;
}
 
Example 7
Source Project: netbeans   Source File: PageIteratorValidation.java    License: Apache License 2.0 6 votes vote down vote up
@NbBundle.Messages({
    "JsfJspValidatorPanel.warn.document.root=Project has no valid DocumentRoot"
})
@Override
public boolean isValid() {
    Project project = getProject();
    if (super.isValid()) {
        // check that that project has valid document root
        WebModule webModule = WebModule.getWebModule(project.getProjectDirectory());
        if (webModule != null && webModule.getDocumentBase() == null) {
            getWizardDescriptor().putProperty(WizardDescriptor.PROP_WARNING_MESSAGE, Bundle.JsfJspValidatorPanel_warn_document_root());
        }
        return true;
    }
    return false;
}
 
Example 8
Source Project: netbeans   Source File: MainProjectManager.java    License: Apache License 2.0 6 votes vote down vote up
public Project getMainProject () {
    final Project lastSelectedProject;
    final Project current;
    final boolean isMain;
    synchronized (this) {
        lastSelectedProject = lastSelectedProjectRef.get();
        current = currentProject.get();
        isMain = isMainProject;
    }
    if (isMain && lastSelectedProject != null &&
        lastSelectedProject != current &&
        !isDependent(lastSelectedProject, current)) {
        // If there's a main project set, but the current project has no
        // dependency on it, return the current project.
        //System.err.println("getMainProject() = (LS) "+lastSelectedProject);
        return lastSelectedProject;
    } else {
        return current;
    }
    //System.err.println("getMainProject() = "+currentProject);
}
 
Example 9
Source Project: netbeans   Source File: TestNGOutputReaderTest.java    License: Apache License 2.0 6 votes vote down vote up
public void testMsgLogged() throws IOException {
    FileObject root = FileUtil.toFileObject(getWorkDir());
    Project p = new ProjectImpl(root, Lookups.fixed(new LineConvertors.FileLocator() {

        public FileObject find(String filename) {
            return null;
        }
    }));
    TestNGTestSession ts = new TestNGTestSession("UnitTest", p, TestSession.SessionType.TEST);
    TestNGOutputReader r = new TestNGOutputReader(ts);

    BufferedReader br = new BufferedReader(
            new FileReader(new File(getDataDir(), "antOut/log.txt")));
    String line;
    while ((line = br.readLine()) != null) {
        if (line.startsWith(RegexpUtils.TEST_LISTENER_PREFIX)) {
            r.verboseMessageLogged(line);
        }
    }
    assertEquals(23115, ts.getSessionResult().getElapsedTime());
    assertEquals(0, ts.getSessionResult().getErrors());
    assertEquals(0, ts.getSessionResult().getFailed());
    System.out.println(ts.getSessionResult().getPassed());
    System.out.println(ts.getSessionResult().getTotal());
}
 
Example 10
Source Project: netbeans   Source File: FacesComponentPanel.java    License: Apache License 2.0 6 votes vote down vote up
@Messages({
    "FacesComponentPanel.err.jsf.version.not.suficient=Minimal required JSF version for this feature is JSF 2.2"
})
@Override
public boolean isValid() {
    getComponent();
    descriptor.putProperty(WizardDescriptor.PROP_ERROR_MESSAGE, " "); //NOI18N

    Project project = Templates.getProject(descriptor);
    WebModule webModule = WebModule.getWebModule(project.getProjectDirectory());
    if (webModule != null) {
        JSFVersion jsfVersion = JSFVersion.forWebModule(webModule);
        if (jsfVersion != null && !jsfVersion.isAtLeast(JSFVersion.JSF_2_2)) {
            descriptor.putProperty(WizardDescriptor.PROP_ERROR_MESSAGE, Bundle.FacesComponentPanel_err_jsf_version_not_suficient());
            return false;
        }
    }
    return true;
}
 
Example 11
Source Project: netbeans   Source File: JaxRsStackSupportImpl.java    License: Apache License 2.0 6 votes vote down vote up
private void removeLibraries(Project project, Collection<URL> urls) {
    if ( urls.size() >0 ){
        SourceGroup[] sourceGroups = ProjectUtils.getSources(project).getSourceGroups(
            JavaProjectConstants.SOURCES_TYPE_JAVA);
        if (sourceGroups == null || sourceGroups.length < 1) {
            return;
        }
        FileObject sourceRoot = sourceGroups[0].getRootFolder();
        String[] classPathTypes = new String[]{ ClassPath.COMPILE , ClassPath.EXECUTE };
        for (String type : classPathTypes) {
            try {
                ProjectClassPathModifier.removeRoots(urls.toArray( 
                    new URL[ urls.size()]), sourceRoot, type);
            }    
            catch(UnsupportedOperationException ex) {
                Logger.getLogger( JaxRsStackSupportImpl.class.getName() ).
                        log (Level.INFO, null , ex );
            }
            catch( IOException e ){
                Logger.getLogger( JaxRsStackSupportImpl.class.getName() ).
                        log(Level.INFO, null , e );
            }
        }     
    }
}
 
Example 12
Source Project: netbeans   Source File: CssPreprocessorsCustomizerPanel.java    License: Apache License 2.0 5 votes vote down vote up
public CssPreprocessorsCustomizerPanel(ProjectCustomizer.Category category, Project project) {
    assert category != null;
    assert project != null;

    this.category = category;
    this.project = project;

    customizers.addAll(getCustomizers());

    initComponents();
    init();
    validateCustomizers();
}
 
Example 13
Source Project: netbeans   Source File: PersistenceXmlRefactoring.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Problem prepare(RefactoringElementsBag refactoringElementsBag) {
    
    if (!shouldHandle()){
        return null;
    }
    
    Problem result = null;
    for (FileObject refactoringSource : getRefactoringSources()) {
        Project project = FileOwnerQuery.getOwner(refactoringSource);
        if (project == null) {
            continue;
        }
        if (!shouldHandle(refactoringSource)){
            continue;
        }
        String classNameFQN = JavaIdentifiers.getQualifiedName(refactoringSource);

        for (FileObject each : getPersistenceXmls(refactoringSource)){
            try {
                PUDataObject pUDataObject = ProviderUtil.getPUDataObject(each);
                List<PersistenceUnit> punits = getAffectedPersistenceUnits(pUDataObject, classNameFQN);
                for (PersistenceUnit persistenceUnit : punits) {
                    refactoringElementsBag.add(getRefactoring(), getRefactoringElement(persistenceUnit, refactoringSource, pUDataObject, each));
                }
            } catch (InvalidPersistenceXmlException ex) {
                Problem newProblem =
                        new Problem(false, NbBundle.getMessage(PersistenceXmlRefactoring.class, "TXT_PersistenceXmlInvalidProblem", ex.getPath()));

                result = RefactoringUtil.addToEnd(newProblem, result);
            }
        }
    }
    
    return result;
}
 
Example 14
Source Project: netbeans   Source File: AbstractLogicalViewProvider.java    License: Apache License 2.0 5 votes vote down vote up
protected AbstractLogicalViewProvider(Project project, UpdateHelper helper,
        PropertyEvaluator evaluator, ReferenceHelper resolver, J2eeModuleProvider j2eeModuleProvider) {
    this.project = project;
    assert project != null;
    this.helper = helper;
    assert helper != null;
    this.evaluator = evaluator;
    assert evaluator != null;
    this.resolver = resolver;
    assert j2eeModuleProvider != null;
    registerListeners(j2eeModuleProvider);
}
 
Example 15
Source Project: netbeans   Source File: ProjectHelper.java    License: Apache License 2.0 5 votes vote down vote up
private static void addJAXBLibrary(Project prj) {
    SourceGroup[] sgs = ProjectUtils.getSources(prj).getSourceGroups(
            JavaProjectConstants.SOURCES_TYPE_JAVA);
    ClassPath compileClassPath = ClassPath.getClassPath(sgs[0]
            .getRootFolder(), ClassPath.COMPILE);
    ClassPath bootClassPath = ClassPath.getClassPath(sgs[0]
            .getRootFolder(), ClassPath.BOOT);
    ClassPath classPath = ClassPathSupport.createProxyClassPath(
            new ClassPath[]{compileClassPath, bootClassPath});
    FileObject jaxbClass = classPath.findResource(
            JAXB_CONTEXT_CLASS_RES_PATH); 
    if (jaxbClass == null) {
        // Add JAXB jars if not in the classpath
        Library jaxbLib = LibraryManager.getDefault().getLibrary(
                JAXB_LIB_NAME);
        Sources srcs = ProjectUtils.getSources(prj);
        if (srcs != null) {
            SourceGroup[] srg = srcs.getSourceGroups(
                    JavaProjectConstants.SOURCES_TYPE_JAVA);
            if ((srg != null) && (srg.length > 0)) {
                try {
                    ProjectClassPathModifier.addLibraries(
                            new Library[]{jaxbLib}, srg[0].getRootFolder(), 
                            ClassPath.COMPILE);
                } catch (IOException ex) {
                    Exceptions.printStackTrace(ex);
                }
            }
        }
    }
}
 
Example 16
Source Project: netbeans   Source File: PreviewMultiViewDesc.java    License: Apache License 2.0 5 votes vote down vote up
public FileObject getFileObject(Project prj) {
    SourceGroup[] srcGroups = ProjectUtils.getSources(prj).getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
    String implClassResource = implementationClass.replace('.', '/') + ".java"; //NOI18N
    for (SourceGroup srcGroup : srcGroups) {
        FileObject implClassFo = srcGroup.getRootFolder().getFileObject(implClassResource);
        if (implClassFo != null) {
            return implClassFo;
        }
    }
    return null;
}
 
Example 17
Source Project: netbeans   Source File: FSCompletionUtils.java    License: Apache License 2.0 5 votes vote down vote up
public static FileObject findFileObject(final FileObject fromFO, final String path, boolean filesOnly) {
    FileObject parent = fromFO.getParent();
    FileObject targetFO;
    Project project = FileOwnerQuery.getOwner(fromFO);
    String projectDirectoryPath = ""; //NOI18N
    if (project != null) {
        FileObject projectDirectory = project.getProjectDirectory();
        projectDirectoryPath = projectDirectory.getPath();
    }
    if (parent != null && !path.isEmpty()) {
        while (parent != null && parent.getPath().contains(projectDirectoryPath)) {
            targetFO = parent.getFileObject(path);
            if (targetFO != null && (!filesOnly || (filesOnly && !targetFO.isFolder()))) {
                return targetFO;
            }
            targetFO = parent.getFileObject(path + ".js");
            if (targetFO != null) {
                return targetFO;
            }
            parent = parent.getParent();
        }
    }

    // try to find the file in other source root
    final List<FileObject> fromOtherRoots = findFileObjects(project, path, filesOnly);
    if (!fromOtherRoots.isEmpty()) {
        return fromOtherRoots.get(0);
    }

    return null;
}
 
Example 18
Source Project: netbeans   Source File: JaxWsClientCreator.java    License: Apache License 2.0 5 votes vote down vote up
private static Set<SourceGroup> getTestSourceGroups(Project project, SourceGroup[] sourceGroups) {
    Map<FileObject, SourceGroup> foldersToSourceGroupsMap = createFoldersToSourceGroupsMap(sourceGroups);
    Set<SourceGroup> testGroups = new HashSet<SourceGroup>();
    for (int i = 0; i < sourceGroups.length; i++) {
        testGroups.addAll(getTestTargets(sourceGroups[i], foldersToSourceGroupsMap));
    }
    return testGroups;
}
 
Example 19
Source Project: jeddict   Source File: JPQLEditorPanel.java    License: Apache License 2.0 5 votes vote down vote up
private void runJPQLButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_runJPQLButtonActionPerformed
    // Fix - 138856
    if(jpqlEditor.getText().trim().equals("")) {
        switchToResultView();
        setStatus(NbBundle.getMessage(JPQLEditorPanel.class, "emptyQuery"));
        return;
    }
    if (puComboBox.getSelectedItem() == null) {
        logger.info("hibernate configuration combo box is empty.");
        switchToResultView();
        setStatus(NbBundle.getMessage(JPQLEditorPanel.class, "emptyConfiguration"));
        return;
    }
    runJPQLButton.setEnabled(false);                                            
    try {
        ph = ProgressHandleFactory.createHandle(//GEN-HEADEREND:event_runJPQLButtonActionPerformed
NbBundle.getMessage(JPQLEditorPanel.class, "progressTaskname"));//GEN-LAST:event_runJPQLButtonActionPerformed
            isSqlTranslationProcessDone = true;//will be reparsed in execution thread
            if (hqlParserTask != null && !hqlParserTask.isFinished() && (hqlParserTask.getDelay() != 0)) {
                hqlParserTask.cancel();
            }
            FileObject pXml = puObject.getPrimaryFile();
            Project project = pXml != null ? FileOwnerQuery.getOwner(pXml) : null;
            PersistenceEnvironment pe = project != null ? project.getLookup().lookup(PersistenceEnvironment.class) : null;

            PersistenceUnit pu = (PersistenceUnit) puConfigMap.get(puComboBox.getSelectedItem());
            ph.start(100);
            getController().executeJPQLQuery(jpqlEditor.getText(),
                    pu,
                    pe,
                    getMaxRowCount(),
                    ph);
        } catch (Exception ex) {
            Exceptions.printStackTrace(ex);
        }
    }
 
Example 20
Source Project: netbeans   Source File: HyperlinkProviderImpl.java    License: Apache License 2.0 5 votes vote down vote up
private Project getProject(Document doc) {
    DataObject dobj = NbEditorUtilities.getDataObject(doc);
    if (dobj != null) {
        return FileOwnerQuery.getOwner(dobj.getPrimaryFile());
    }
    return null;
}
 
Example 21
Source Project: netbeans   Source File: EjbJarMultiViewDataObject.java    License: Apache License 2.0 5 votes vote down vote up
public SourceGroup[] getSourceGroups() {
    Project project = getProject();
    if (project != null) {
        return ProjectUtils.getSources(project).getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
    } else {
        return null;
    }
}
 
Example 22
Source Project: netbeans   Source File: ProjectsRootNode.java    License: Apache License 2.0 5 votes vote down vote up
private 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)), project.getProjectDirectory());
}
 
Example 23
Source Project: NBANDROID-V2   Source File: GoalsPanel.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void actionPerformed(ActionEvent e) {
    Project project = FileOwnerQuery.getOwner(Utilities.toURI(new File(gradleProject.getProjectPath())));
    if (project != null) {
        GradleCommandExecutor executor = project.getLookup().lookup(GradleCommandExecutor.class);
        if (executor != null) {
            executor.executeCommand(gradleTask);
        }
    }
}
 
Example 24
Source Project: netbeans   Source File: ProjectHelper.java    License: Apache License 2.0 5 votes vote down vote up
private static void saveProperty(Project prj, String filePath, String name, 
        String value) {
    AntProjectHelper aph = getAntProjectHelper(prj);
    EditableProperties ep = aph.getProperties(filePath);
    if (value != null) {
        ep.put(name, value);
        aph.putProperties(filePath, ep);
    }
}
 
Example 25
Source Project: netbeans   Source File: IncompleteClassPath.java    License: Apache License 2.0 5 votes vote down vote up
@Override
@NonNull
public List<Fix> run(CompilationInfo compilationInfo, String diagnosticKey, int offset, TreePath treePath, Data<Void> data) {
    final FileObject file = compilationInfo.getFileObject();
    if (file != null) {
        final Project prj = FileOwnerQuery.getOwner(file);
        if (prj != null) {
            return Collections.<Fix>singletonList (new ResolveFix(prj));
        }
    }
    return Collections.<Fix>emptyList();
}
 
Example 26
Source Project: netbeans   Source File: ResourcesHelper.java    License: Apache License 2.0 5 votes vote down vote up
static private J2eeModuleProvider getProvider(Project project) {
    J2eeModuleProvider provider = null;
    if (project != null) {
        org.openide.util.Lookup lookup = project.getLookup();
        provider = lookup.lookup(J2eeModuleProvider.class);
    }
    return provider;
}
 
Example 27
Source Project: netbeans   Source File: WSUtils.java    License: Apache License 2.0 5 votes vote down vote up
public static boolean isEJB(Project project) {
    J2eeModuleProvider j2eeModuleProvider = project.getLookup().lookup(J2eeModuleProvider.class);
    if (j2eeModuleProvider != null) {
        J2eeModule.Type moduleType = j2eeModuleProvider.getJ2eeModule().getType();
        if (J2eeModule.Type.EJB.equals(moduleType)) {
            return true;
        }
    }
    return false;
}
 
Example 28
Source Project: netbeans   Source File: SpringScope.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Returns the reference to the {@code MetadataModel<SpringModel>} of Spring
 * annotation support.
 * 
 * @param fo any file inside project; never null.
 * @return {@code MetadataModel<SpringModel>} of annotation model; never null
 */
public MetadataModel<SpringModel> getSpringAnnotationModel(FileObject fo) {
    if (springAnnotationModel == null) {
        Project project = getSpringProject(fo);
        if (project == null) {
            return null;
        }
        SpringMetaModelSupport metaModelSupport = new SpringMetaModelSupport(project);
        springAnnotationModel = metaModelSupport.getMetaModel();
    }
    return springAnnotationModel;
}
 
Example 29
/**
 * Creates new form ResourceLibraryIteratorPanelVisual.
 */
public ResourceLibraryIteratorPanelVisual(Project project, FileObject contractsParent, ProjectType projectType) {
    this.project = project;
    this.contractsParent = contractsParent;
    this.projectType = projectType;
    initComponents();
    initPanelDefaultValues();
    initTemplatesPanel();
    initListeners();
}
 
Example 30
@Override
public boolean isFileObjectSupported(FileObject file) {
    Project project = getProject();
    return ((WebProjectUtils.isJSP(file) && WebProjectUtils.isWebDocumentSource(file, project)) // jsp from /web directory               
              || (WebProjectUtils.isHttpServlet(file) && WebProjectUtils.isWebJavaSource(file, project)
              /*&& WebProjectUtils.isMappedServlet(file, project, true)*/) // mapped servlet from /src directory
              /*|| super.isFileObjectSupported(file)*/); // regular java file
}