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

The following examples show how to use org.netbeans.api.project.FileOwnerQuery. 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: OperationEditorDrop.java    License: Apache License 2.0 6 votes vote down vote up
public boolean handleTransfer(JTextComponent targetComponent) {
    Object mimeType = targetComponent.getDocument().getProperty("mimeType"); //NOI18N
    if (mimeType!=null && ("text/x-java".equals(mimeType) || "text/x-jsp".equals(mimeType) )) { //NOI18N
        
        try {
            Node clientNode = operationNode.getParentNode().getParentNode().getParentNode();
            FileObject srcRoot = clientNode.getLookup().lookup(FileObject.class);
            Project clientProject = FileOwnerQuery.getOwner(srcRoot);
            FileObject targetFo = NbEditorUtilities.getFileObject(targetComponent.getDocument());
            if (JaxWsUtils.addProjectReference(clientProject, targetFo)) {
                JaxWsCodeGenerator.insertMethod(targetComponent.getDocument(), targetComponent.getCaret().getDot(), operationNode);

                // logging usage of action
                Object[] params = new Object[2];
                params[0] = LogUtils.WS_STACK_JAXWS;
                params[1] = "DRAG & DROP WS OPERATION"; // NOI18N
                LogUtils.logWsAction(params);
                
                return true;
            }
        } catch (Exception ex) {
            ErrorManager.getDefault().log(ex.getLocalizedMessage());
        }
    }
    return false;
}
 
Example 2
Source Project: netbeans   Source File: SpringWebModuleExtender.java    License: Apache License 2.0 6 votes vote down vote up
protected boolean addLibrariesToWebModule(List<Library> libraries, WebModule webModule) throws IOException, UnsupportedOperationException {
    FileObject fileObject = webModule.getDocumentBase();
    Project project = FileOwnerQuery.getOwner(fileObject);
    if (project == null) {
        return false;
    }
    boolean addLibraryResult = false;
    try {
        SourceGroup[] groups = SourceGroups.getJavaSourceGroups(project);
        if (groups.length == 0) {
            return false;
        }
        addLibraryResult = ProjectClassPathModifier.addLibraries(libraries.toArray(new Library[libraries.size()]), groups[0].getRootFolder(), ClassPath.COMPILE);
    } catch (IOException e) {
        LOGGER.log(Level.WARNING, "Libraries required for the Spring MVC project not added", e); // NOI18N
    } catch (UnsupportedOperationException uoe) {
        LOGGER.log(Level.WARNING, "This project does not support adding these types of libraries to the classpath", uoe); // NOI18N
    }
    return addLibraryResult;
}
 
Example 3
Source Project: netbeans   Source File: RunSeleniumAction.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void actionPerformed(final ActionEvent e) {
    RP.post(new Runnable() {
        @Override
        public void run() {
            Project p = FileOwnerQuery.getOwner(activatedFOs[0]);
            if (p == null) {
                return;
            }
            FileSensitiveActions.fileCommandAction(ActionProvider.COMMAND_TEST_SINGLE, Bundle.SeleniumTestFileAction_name(), null).actionPerformed(e);
            SeleniumTestingProvider provider = SeleniumTestingProviders.getDefault().getSeleniumTestingProvider(p, true);
            if (provider != null) {
                provider.runTests(activatedFOs);
            }
        }
    });
}
 
Example 4
Source Project: netbeans   Source File: Utils.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Checks if the target is Java SE class.
 * <p>
 * <i>Note: Should run outside EDT!</i>
 * @return true if given <code>target</code> is defined in a Java SE environment.
 */
public static boolean isTargetJavaSE(FileObject fileObject, final String className) throws IOException{
    Project owner = FileOwnerQuery.getOwner(fileObject);
    if (owner.getLookup().lookup(J2eeModuleProvider.class) == null){
        return true;
    }
    JavaSource javaSource = JavaSource.forFileObject(fileObject);
    if (javaSource == null) {
        return false;
    }
    final boolean[] result = new boolean[] { false };
    javaSource.runUserActionTask(new Task<CompilationController>() {
        public void run(CompilationController controller) throws IOException {
            controller.toPhase(JavaSource.Phase.ELEMENTS_RESOLVED);
            TypeElement typeElement = controller.getElements().getTypeElement(className);
            TypeElement junitTestCase = controller.getElements().getTypeElement("junit.framework.TestCase");
            if (junitTestCase != null && typeElement != null) {
                result[0] = controller.getTypes().isSubtype(typeElement.asType(), junitTestCase.asType());
            }
        }
    }, true);
    return result[0];
}
 
Example 5
Source Project: netbeans   Source File: WebModules.java    License: Apache License 2.0 6 votes vote down vote up
public WebModule findWebModule (final FileObject file) {
    Project owner = FileOwnerQuery.getOwner (file);
    if (project.equals (owner)) {
        // read modules under project READ access to prevent issues like #119734
        return ProjectManager.mutex().readAccess(new Mutex.Action<WebModule>() {
            public WebModule run() {
                synchronized (WebModules.this) {
                    List<FFWebModule> mods = getModules();
                    for (FFWebModule ffwm : mods) {
                        if (ffwm.contains (file)) {
                            WebModule wm = cache.get (ffwm);
                            if (wm == null) {
                                wm = WebModuleFactory.createWebModule (ffwm);
                                cache.put (ffwm, wm);
                            }
                            return wm;
                        }
                    }
                    return null;
                }
            }});
    }
    return null;
}
 
Example 6
Source Project: netbeans   Source File: CallStackModel.java    License: Apache License 2.0 6 votes vote down vote up
private String getFile( Stack stack ){
    String fileName = stack.getFileName();
    FileObject fileObject = getSessionId().toSourceFile( fileName );
    if ( fileObject == null ){
        // TODO inform somehow about local file is not found , output remote file
        return fileName;
    }
    else {
        Project project = FileOwnerQuery.getOwner( fileObject );
        if (project != null) {
            String retval = FileUtil.getRelativePath(project.getProjectDirectory() ,fileObject );
            if (retval != null) {
                return retval;
            }
        }
        File f = FileUtil.toFile(fileObject);
        return f != null ? f.getAbsolutePath() : fileName;
    }
}
 
Example 7
Source Project: netbeans   Source File: ActionProviderImplTest.java    License: Apache License 2.0 6 votes vote down vote up
public void testImages2() throws Exception {
    createFile("modules.xml");
    createDir("jdk/src/java.base/share/classes");
    createDir("build/conf/jdk");
    createDir("build/conf/images/jdk");
    createDir("langtools/src/java.compiler/share/classes");
    FileObject testFile = createFile("langtools/test/Test.java");

    createDir("").setAttribute(BuildUtils.NB_JDK_PROJECT_BUILD, FileUtil.toFile(createDir("build/conf")));

    FileOwnerQuery.markExternalOwner(testFile.getParent(), FileOwnerQuery.getOwner(createDir("langtools/src/java.compiler")), FileOwnerQuery.EXTERNAL_ALGORITHM_TRANSIENT);

    File target = BuildUtils.findTargetJavaHome(testFile);

    assertEquals("/build/conf/jdk", target.getAbsolutePath().substring(getWorkDir().getAbsolutePath().length()));
}
 
Example 8
Source Project: netbeans   Source File: OpenProject.java    License: Apache License 2.0 6 votes vote down vote up
public @Override void actionPerformed(ActionEvent evt) {
    JFileChooser chooser = ProjectChooserAccessory.createProjectChooser( true ); // Create the jFileChooser
    chooser.setMultiSelectionEnabled( true );
    
    // Check to see if the current selection matches a file/folder owned by a non-open project;
    // if so, use that as the starting directory, as a convenience in case that is what should be opened.
    // XXX may also want to check lookup for FileObject
    for (DataObject d : Utilities.actionsGlobalContext().lookupAll(DataObject.class)) {
        Project selected = FileOwnerQuery.getOwner(d.getPrimaryFile());
        if (selected != null && !OpenProjectList.getDefault().isOpen(selected)) {
            File dir = FileUtil.toFile(selected.getProjectDirectory());
            if (dir != null) {
                chooser.setCurrentDirectory(dir.getParentFile());
                chooser.setSelectedFiles(new File[] {dir});
                break;
            }
        }
    }
    show(chooser);
}
 
Example 9
Source Project: netbeans   Source File: StandardAntArtifactQueryImpl.java    License: Apache License 2.0 6 votes vote down vote up
public AntArtifact findArtifact(File file) {
    Project p = FileOwnerQuery.getOwner(BaseUtilities.toURI(file));
    if (p == null) {
        return null;
    }
    AntArtifactProvider prov = p.getLookup().lookup(AntArtifactProvider.class);
    if (prov == null) {
        return null;
    }
    AntArtifact[] artifacts = prov.getBuildArtifacts();
    for (int i = 0; i < artifacts.length; i++) {
        URI uris[] = artifacts[i].getArtifactLocations();
        for (int y = 0; y < uris.length; y++) {
            File testFile = BaseUtilities.toFile(BaseUtilities.toURI(artifacts[i].getScriptLocation()).resolve(uris[y]));
            if (file.equals(testFile)) {
                return artifacts[i];
            }
        }
    }
    return null;
}
 
Example 10
Source Project: netbeans   Source File: ProjectsRootNode.java    License: Apache License 2.0 6 votes vote down vote up
@CheckForNull
private static Project findProject(@NonNull final FileObject target) {
    Project owner = FileOwnerQuery.getOwner(target);
    if (owner != null && ProjectConvertors.isConvertorProject(owner)) {
        FileObject dir = owner.getProjectDirectory().getParent();
        while (dir != null) {
            Project p = FileOwnerQuery.getOwner(dir);
            if (p != null && !ProjectConvertors.isConvertorProject(p)) {
                owner = p;
                break;
            }
            dir = dir.getParent();
        }
    }
    return owner;
}
 
Example 11
Source Project: netbeans   Source File: SetKarmaConfAction.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public Action createContextAwareInstance(Lookup context) {
    FileObject file = context.lookup(FileObject.class);
    if (file == null) {
        DataObject dataObject = context.lookup(DataObject.class);
        if (dataObject != null) {
            file = dataObject.getPrimaryFile();
        }
    }
    if (file == null) {
        return this;
    }
    Project owner = FileOwnerQuery.getOwner(file);
    if (owner == null) {
        return this;
    }
    if (!KarmaPreferences.isEnabled(owner)) {
        return this;
    }
    return new SetKarmaConfAction(owner, file);
}
 
Example 12
Source Project: netbeans   Source File: DefaultPlugin.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Finds a Java source group the given file belongs to.
 * 
 * @param  file  {@literal FileObject} to find a {@literal SourceGroup} for
 * @return  the found {@literal SourceGroup}, or {@literal 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 13
Source Project: netbeans   Source File: DelegateToOwnerLookupTest.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected void setUp() throws Exception {
    super.setUp();
    clearWorkDir();
    final FileObject wd = FileUtil.toFileObject(FileUtil.normalizeFile(getWorkDir()));
    final FileObject enclosingProjectHome = FileUtil.createFolder(wd, "enclosing");    //NOI18N
    TestProject.Factory.LOOKUP_FACTORY = new Callable<Lookup>() {
        @Override
        public Lookup call() throws Exception {
            return Lookups.fixed(
                new SourcesImpl(enclosingProjectHome),
                new ProjectOpenedHookImpl(),
                new ProjectInformationImpl(enclosingProjectHome));
        }
    };
    automaticProjectHome = FileUtil.createFolder(enclosingProjectHome, "automatic");   //NOI18N
    FileUtil.createFolder(enclosingProjectHome, TestProject.PROJECT_MARKER);
    owner = FileOwnerQuery.getOwner(enclosingProjectHome);
}
 
Example 14
Source Project: netbeans   Source File: Selenium2PhpTestWizardIterator.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public Set instantiate() throws IOException {
    FileObject createdFile = null;
    FileObject targetFolder = Templates.getTargetFolder(wiz);
    Selenium2SupportImpl selenium2Support = Selenium2Support.findSelenium2Support(FileOwnerQuery.getOwner(targetFolder));
    if (selenium2Support == null) {
        return Collections.singleton(createdFile);
    }
    selenium2Support.configureProject(targetFolder);
    TestCreatorProvider.Context context = new TestCreatorProvider.Context(new FileObject[]{targetFolder});
    context.setSingleClass(true);
    context.setTargetFolder(targetFolder);
    context.setTestClassName(Templates.getTargetName(wiz));
    ArrayList<FileObject> createTests = Selenium2Support.createTests(context);
    if (!createTests.isEmpty()) {
        createdFile = createTests.get(0);
    }

    return Collections.singleton(createdFile);
}
 
Example 15
Source Project: netbeans   Source File: ActionsUtil.java    License: Apache License 2.0 6 votes vote down vote up
/** In given lookup will find all FileObjects owned by given project
 * with given command supported.
 */    
public static FileObject[] getFilesFromLookup( Lookup lookup, Project project ) {
    HashSet<FileObject> result = new HashSet<FileObject>();
    for (DataObject dObj : lookup.lookupAll(DataObject.class)) {
        FileObject fObj = dObj.getPrimaryFile();
        Project p = FileOwnerQuery.getOwner(fObj);
        if ( p != null && p.equals( project ) ) {
            result.add( fObj );                                        
        }

    }
    
    FileObject[] fos = new FileObject[ result.size() ];
    result.toArray( fos );        
    return fos;
}
 
Example 16
Source Project: nb-springboot   Source File: MissingPomDependencies.java    License: Apache License 2.0 6 votes vote down vote up
private static ErrorDescription annotationWarning(HintContext ctx, String artifactId, String hintMex, boolean optional) {
    final TreePath tp = ctx.getPath();
    final TreePath tpParent = tp.getParentPath();
    if (tpParent != null) {
        if (tpParent.getLeaf().getKind() == ANNOTATION) {
            Project prj = FileOwnerQuery.getOwner(ctx.getInfo().getFileObject());
            if (prj != null) {
                SpringBootService sbs = prj.getLookup().lookup(SpringBootService.class);
                if (sbs != null) {
                    // check first if the pom has at least one spring boot dependencies
                    if (sbs.hasPomDependency("spring-boot") && !sbs.hasPomDependency(artifactId)) {
                        NbMavenProject mPrj = prj.getLookup().lookup(NbMavenProject.class);
                        if (mPrj != null) {
                            return ErrorDescriptionFactory
                                    .forName(ctx, tp, hintMex, new AddDepFix(mPrj, artifactId, optional));
                        } else {
                            return ErrorDescriptionFactory.forName(ctx, tp, hintMex);
                        }
                    }
                }
            }
        }
    }
    return null;
}
 
Example 17
Source Project: netbeans   Source File: JaxWsAddOperation.java    License: Apache License 2.0 6 votes vote down vote up
private String getPackageName(FileObject fo) {
    Project project = FileOwnerQuery.getOwner(fo);
    Sources sources = project.getLookup().lookup(Sources.class);
    if (sources!=null) {
        SourceGroup[] groups = sources.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
        if (groups!=null) {
            for (SourceGroup group: groups) {
                FileObject rootFolder = group.getRootFolder();
                if (FileUtil.isParentOf(rootFolder, fo)) {
                    String relativePath = FileUtil.getRelativePath(rootFolder, fo).replace('/', '.');
                    return (relativePath.endsWith(".java")? //NOI18N
                        relativePath.substring(0,relativePath.length()-5):
                        relativePath);
                }
            }
        }
    }
    return null;
}
 
Example 18
Source Project: netbeans   Source File: Classpaths.java    License: Apache License 2.0 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 19
Source Project: netbeans   Source File: I18nServiceImpl.java    License: Apache License 2.0 6 votes vote down vote up
static boolean isNbBundleAvailable(FileObject srcFile) {
    // is there a good way to recognize that NbBundle is available?
    // - execution CP may not work if everything is cleaned
    // - looking for NbBundle.java in sources of execution CP roots is expensive
    // - checking project impl. class name is ugly
    // - don't know how to check if there is "org.openide.util" module
    ClassPath classPath = ClassPath.getClassPath(srcFile, ClassPath.EXECUTE);
    if (classPath != null && classPath.findResource("org/openide/util/NbBundle.class") != null) // NOI18N
        return true;

    // hack: check project impl. class name
    Project p = FileOwnerQuery.getOwner(srcFile);
    if (p != null && p.getClass().getName().startsWith("org.netbeans.modules.apisupport.") // NOI18N
            && p.getClass().getName().endsWith("Project")) // NOI18N
        return true;

    return false;
}
 
Example 20
Source Project: netbeans   Source File: SetExecutionUriAction.java    License: Apache License 2.0 5 votes vote down vote up
private static boolean checkScanFinished(WebModule webModule, FileObject fileObject) {
    Project project = FileOwnerQuery.getOwner( fileObject );
    if ( project != null ){
        final ProjectWebModule prjWebModule = project.getLookup().lookup( 
                ProjectWebModule.class);
        if (prjWebModule != null) {
            MarkerClass marker = prjWebModule.getLookup().lookup(
                    MarkerClass.class );
            return marker!=null && marker!=MARKER;
        }
    }
    return true;
}
 
Example 21
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 22
Source Project: netbeans   Source File: ELDeclarationFinder.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public String getDisplayHtml(HtmlFormatter formatter) {
    StringBuilder b = new StringBuilder();

    b.append("<font color=007c00>");//NOI18N
    b.append("<b>"); //NOI18N
    b.append(file.getName());
    b.append("</b>"); //NOI18N
    b.append("</font> in "); //NOI18N

    //add a link to the file relative to the web root
    FileObject pathRoot = ProjectWebRootQuery.getWebRoot(file);
    String path = null;
    if (pathRoot != null) {
        path = FileUtil.getRelativePath(pathRoot, file); //this may also return null
    }
    if (path == null) {
        Project project = FileOwnerQuery.getOwner(file);
        if (project != null) {
            pathRoot = project.getProjectDirectory();
            path = FileUtil.getRelativePath(pathRoot, file); //this may also return null
        }
    }
    if (path == null) {
        //if everything fails, just use the absolute path
        path = file.getPath();
    }

    b.append("<i>"); //NOI18N
    b.append(path);
    b.append("</i>"); //NOI18N
    if (offset > 0) {
        b.append(":"); //NOI18N
        b.append(offset + 1); //line offsets are counted from zero, but in editor lines starts with one.
    }
    return b.toString();
}
 
Example 23
Source Project: netbeans   Source File: RunSeleniumAction.java    License: Apache License 2.0 5 votes vote down vote up
@CheckForNull
private FileObject[] lookupSeleniumTestOnly(Lookup context) {
    Collection<? extends FileObject> fileObjects = context.lookupAll(FileObject.class);
    if (fileObjects.isEmpty()) {
        return null;
    }
    Project p = null;
    Iterator<? extends FileObject> iterator = fileObjects.iterator();
    while (iterator.hasNext()) {
        FileObject fo = iterator.next();
        Project project = FileOwnerQuery.getOwner(fo);
        if (project == null) {
            return null;
        }
        if(p == null) {
            p = project;
        }
        if(!p.equals(project)) { // selected FileObjects belong to different projects
            return null;
        }
        Sources sources = ProjectUtils.getSources(project);
        SourceGroup[] sourceGroups = sources.getSourceGroups(WebClientProjectConstants.SOURCES_TYPE_HTML5_TEST_SELENIUM);
        if (sourceGroups.length != 1) { // no Selenium Tests Folder set yet
            return null;
        }
        FileObject rootFolder = sourceGroups[0].getRootFolder();
        if (!FileUtil.isParentOf(rootFolder, fo)) { // file in not under Selenium Tests Folder
            return null;
        }
    }
    return fileObjects.toArray(new FileObject[fileObjects.size()]);
}
 
Example 24
Source Project: netbeans   Source File: FixPlatform.java    License: Apache License 2.0 5 votes vote down vote up
final Future<ProjectProblemsProvider.Result> resolve() {
    final JavaPlatform selected = (JavaPlatform) platforms.getSelectedItem();
    if (selected == null) {
        return ProjectProblemsProviders.future(
                ProjectProblemsProvider.Result.create(ProjectProblemsProvider.Status.UNRESOLVED));
    }
    final String antName = getJavaPlatformAntName(selected);
    if (requiredPlatformId.equals(antName)) {
        return ProjectProblemsProviders.future(
                ProjectProblemsProvider.Result.create(ProjectProblemsProvider.Status.RESOLVED));
    }
    return WORKER.submit(() -> {
        return ProjectManager.mutex().writeAccess(() -> {
            try {
                final EditableProperties ep = helper.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH);
                ep.setProperty(propertName, antName);
                helper.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, ep);
                if (callback != null) {
                    callback.platformPropertyUpdated(selected);
                }
                final Project p = FileOwnerQuery.getOwner(helper.getProjectDirectory());
                ProjectManager.getDefault().saveProject(p);
                return ProjectProblemsProvider.Result.create(ProjectProblemsProvider.Status.RESOLVED);
            } catch (IOException ioe) {
                Exceptions.printStackTrace(ioe);
                return ProjectProblemsProvider.Result.create(ProjectProblemsProvider.Status.UNRESOLVED);
            }
        });
    });
}
 
Example 25
Source Project: netbeans   Source File: StartProfilerTask.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void execute() throws BuildException {
    ProfilerLauncher.Session s = ProfilerLauncher.getLastSession();
    if (s == null && isFreeForm) {
        File baseDir = getProject().getBaseDir();
        if (baseDir != null) {
            Project p = FileOwnerQuery.getOwner(FileUtil.toFileObject(baseDir));
            if (p != null) {
                s = ProfilerLauncher.Session.createSession(p);
            }
        }
        
    }
    if (s != null) {
        Map<String, String> props = s.getProperties();
        if (props != null) {
            for(Map.Entry<String, String> e : props.entrySet()) {
                getProject().setProperty(e.getKey(), e.getValue());
            }
            if (isFreeForm) {
                getProject().setProperty("profiler.configured", "true"); // NOI18N
            }
            
            getProject().addBuildListener(new BuildEndListener(connectionCancel));
            
            if (!NetBeansProfiler.getDefaultNB().startEx(s.getProfilingSettings(), s.getSessionSettings(), connectionCancel)) {
                throw new BuildException("User abort"); // NOI18N
            }
        }
    }
}
 
Example 26
Source Project: netbeans   Source File: RemoteJavaAntLogger.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void buildStarted(AntEvent event) {
    final AntSession session = event.getSession();
    final SessionData data = getSessionData(session);
    final String path = event.evaluate("${basedir}");   //NOI18N
    if (path != null) {
        final File projectDir = FileUtil.normalizeFile(new File (path));
        final FileObject projectFolder = FileUtil.toFileObject(projectDir);
        if (projectFolder != null) {
            final Project prj = FileOwnerQuery.getOwner(projectFolder);
            if (prj != null) {
                ClassPath runCP = null;
                ClassPath bootCP = null;
                for (SourceGroup sg : ProjectUtils.getSources(prj).getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA)) {
                    final FileObject root = sg.getRootFolder();
                    if (!isTest(root)) {
                        runCP = ClassPath.getClassPath(root, ClassPath.EXECUTE);
                        bootCP = ClassPath.getClassPath(root, ClassPath.BOOT);
                        break;
                    }
                }
                if (runCP != null) {
                    data.setClasspath(runCP);
                }
                if (bootCP != null) {
                    final ClassPath platformSources = findPlatformSources(bootCP);
                    if (platformSources != null) {
                        data.setPlatformSources(platformSources);
                    }
                }
            }
        }
    }
}
 
Example 27
Source Project: NBANDROID-V2   Source File: AndroidProjects.java    License: Apache License 2.0 5 votes vote down vote up
public static final Project findRootProject(Project current) {
    if (current instanceof NbAndroidRootProjectImpl) {
        return current;
    }
    Project owner = FileOwnerQuery.getOwner(current.getProjectDirectory().getParent());
    if (owner instanceof NbAndroidRootProjectImpl) {
        return owner;
    } else {
        throw new IllegalStateException("Gradle root projec not found!");
    }
}
 
Example 28
Source Project: netbeans   Source File: WLIncrementalDeployment.java    License: Apache License 2.0 5 votes vote down vote up
public static String computeModuleID(J2eeModule module) {
        String moduleID = null;
        FileObject fo = null;
        try {
            fo = module.getContentDirectory();
            if (null != fo) {
                moduleID = ProjectUtils.getInformation(FileOwnerQuery.getOwner(fo)).getDisplayName();
            }
        } catch (IOException ex) {
            LOGGER.log(Level.FINER, null, ex);
        }

//        if (null == moduleID || moduleID.trim().length() < 1) {
//            J2eeModuleHelper j2eeModuleHelper = J2eeModuleHelper.getSunDDModuleHelper(module.getType());
//            if(j2eeModuleHelper != null) {
//                RootInterface rootDD = j2eeModuleHelper.getStandardRootDD(module);
//                if(rootDD != null) {
//                    try {
//                        moduleID = rootDD.getDisplayName(null);
//                    } catch (VersionNotSupportedException ex) {
//                        // ignore, handle as null below.
//                    }
//                }
//            }
//        }

        return moduleID;
    }
 
Example 29
Source Project: netbeans   Source File: SourceLevelQueryImplTest.java    License: Apache License 2.0 5 votes vote down vote up
public void testModuleInfoOldLayout() throws IOException {
    FileObject javaBase = FileUtil.createFolder(root, "jdk/src/java.base");
    FileObject jlObject = FileUtil.createData(javaBase, "share/classes/java/lang/Object.java");
    copyString2File(jlObject, "");
    copyString2File(FileUtil.createData(javaBase, "share/classes/module-info.java"), "module java.base {}");
    copyString2File(FileUtil.createData(root, "langtools/src/java.compiler/share/classes/module-info.java"), "module java.compiler {}");
    copyString2File(FileUtil.createData(root, "langtools/src/java.compiler/share/classes/javax/lang/model/SourceVersion.java"), "RELEASE_3 RELEASE_12");

    Project javaBaseProject = FileOwnerQuery.getOwner(javaBase);

    assertNotNull(javaBaseProject);

    assertEquals("12", SourceLevelQuery.getSourceLevel(jlObject));
}
 
Example 30
Source Project: netbeans   Source File: StatusProvider.java    License: Apache License 2.0 5 votes vote down vote up
private void initializeModel() {
    FileObject fo = NbEditorUtilities.getFileObject(document);
    if (fo != null) {
        //#236116 passing document protects from looking it up later and causing a deadlock.
        ModelSource ms = Utilities.createModelSource(fo, null, document instanceof BaseDocument ? (BaseDocument)document : null);
        model = POMModelFactory.getDefault().createFreshModel(ms);
        project = FileOwnerQuery.getOwner(fo);
        fo.addFileChangeListener(FileUtil.weakFileChangeListener(listener, fo));
    }
}