当前位置: 首页>>代码示例>>Java>>正文


Java FileObject类代码示例

本文整理汇总了Java中org.openide.filesystems.FileObject的典型用法代码示例。如果您正苦于以下问题:Java FileObject类的具体用法?Java FileObject怎么用?Java FileObject使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


FileObject类属于org.openide.filesystems包,在下文中一共展示了FileObject类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testMoveWithInnerProjectComplex

import org.openide.filesystems.FileObject; //导入依赖的package包/类
public void testMoveWithInnerProjectComplex() throws Exception {
    TestUtil.createFileFromContent(DefaultProjectOperationsImplementationTest.class.getResource("data/test.txt"), projdir, "lib/test.txt");
    FileObject projdir2 = projdir.getFileObject("lib").createFolder("proj2");
    
    createProject(projdir2);
    
    ProgressHandle handle = ProgressHandleFactory.createHandle("test-handle");
    handle.start(DefaultProjectOperationsImplementation.MAX_WORK);
    
    FileObject oldProject     = prj.getProjectDirectory();
    File       oldProjectFile = FileUtil.toFile(oldProject);
    FileObject newTarget      = oldProject.getParent();
    
    DefaultProjectOperationsImplementation.doMoveProject(handle, prj, "projMove", "projMove", newTarget, "ERR_Cannot_Move");
    
    File newProject = new File(FileUtil.toFile(newTarget), "projMove");
    
    assertTrue(newProject.isDirectory());
    assertTrue(new File(newProject, "nbproject").isDirectory());
    assertTrue(new File(newProject, "src").isDirectory());
    assertTrue(new File(newProject, "lib").isDirectory());
    assertTrue(new File(new File(newProject, "lib"), "proj2").isDirectory());
    assertFalse(new File(new File(oldProjectFile, "lib"), "proj2").exists());
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:25,代码来源:DefaultProjectOperationsImplementationTest.java

示例2: optionsExportNotEmpty

import org.openide.filesystems.FileObject; //导入依赖的package包/类
/** Returns true if some non hidden files are registered under OptionsExport
 * folder.
 * @return true if something is registered under OptionsExport, false otherwise
 */
private boolean optionsExportNotEmpty() {
    FileObject optionsExportFO = doGetConfigFile("OptionsExport");  //NOI18N
    if(optionsExportFO != null) {
        FileObject[] categories = optionsExportFO.getChildren();
        for (FileObject category : categories) {
            Object hiddenCategory = category.getAttribute("hidden");  //NOI18N
            if (hiddenCategory != null && (Boolean)hiddenCategory) {
                // skip hidden category folder
                continue;
            }
            FileObject[] items = category.getChildren();
            for (FileObject item : items) {
                Object hiddenItem = item.getAttribute("hidden");  //NOI18N
                if(hiddenItem == null || !(Boolean)hiddenItem) {
                    return true;
                }
            }
        }
    }
    return false;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:26,代码来源:OptionsDisplayerImpl.java

示例3: get

import org.openide.filesystems.FileObject; //导入依赖的package包/类
@Override
public FileObject get() {
    if (aProject != null) {
        File manifestFile = aProject.getDefaultConfig().getSourceProvider().getManifestFile();

        BuildTypeContainer buildTypeContainer = buildConfig.getCurrentBuildTypeContainer();
        File buildManifestFile = buildTypeContainer != null
                ? buildTypeContainer.getSourceProvider().getManifestFile()
                : null;
        File m = Iterables.find(Lists.newArrayList(manifestFile, buildManifestFile), Predicates.notNull(), null);
        if (m != null) {
            return FileUtil.toFileObject(m);
        }
    }
    return null;
}
 
开发者ID:NBANDROIDTEAM,项目名称:NBANDROID-V2,代码行数:17,代码来源:GradleAndroidManifest.java

示例4: findMixins

import org.openide.filesystems.FileObject; //导入依赖的package包/类
public static Collection<RefactoringElement> findMixins(RefactoringElementContext context) throws IOException, ParseException {
    Collection<RefactoringElement> elements = new ArrayList<>();
    String mixinName = context.getElementName();

    //all files linked from the base file with their CP models
    Map<FileObject, CPCssIndexModel> indexModels = CPUtils.getIndexModels(context.getFileObject(), DependencyType.REFERRING_AND_REFERRED, false);
    for (Map.Entry<FileObject, CPCssIndexModel> entry : indexModels.entrySet()) {
        CPCssIndexModel im = entry.getValue();
        FileObject file = entry.getKey();
        CPModel cpModel = CPModel.getModel(file);
        for (CPElementHandle var : im.getMixins()) {
            //change both declarations and usages
            if (var.getName().equals(mixinName)) {
                CPElement cpElement = var.resolve(cpModel);
                if (cpElement != null) {
                    OffsetRange elementRange = cpElement.getRange();
                    elements.add(new RefactoringElement(file, elementRange, mixinName));
                }
            }
        }
    }
    
    return elements;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:25,代码来源:CPWhereUsedQueryPlugin.java

示例5: canDecodeFile

import org.openide.filesystems.FileObject; //导入依赖的package包/类
private boolean canDecodeFile(FileObject fo, String encoding) {
    CharsetDecoder decoder = Charset.forName(encoding).newDecoder().onUnmappableCharacter(CodingErrorAction.REPORT).onMalformedInput(CodingErrorAction.REPORT);
    try {
        BufferedInputStream bis = new BufferedInputStream(fo.getInputStream());
        //I probably have to create such big buffer since I am not sure
        //how to cut the file to smaller byte arrays so it cannot happen
        //that an encoded character is divided by the arrays border.
        //In such case it might happen that the method woult return
        //incorrect value.
        byte[] buffer = new byte[(int) fo.getSize()];
        bis.read(buffer);
        bis.close();
        decoder.decode(ByteBuffer.wrap(buffer));
        return true;
    } catch (CharacterCodingException ex) {
        //return false
    } catch (IOException ioe) {
        Logger.getLogger("global").log(Level.WARNING, "Error during charset verification", ioe);
    }
    return false;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:22,代码来源:HtmlEditorSupport.java

示例6: testAddRemovePomLib

import org.openide.filesystems.FileObject; //导入依赖的package包/类
@RandomlyFails // frequently fails in NB-Core-Build; [CPExtender] checkLibraryForPoms on Library[Stuff] -> true and [Utilities] WORKDIR/o.n.m.m.c.C/testAddRemovePomLib/[email protected]:2: CHILD_REMOVED:[email protected] yet [Utilities] no changes in [email protected][WORKDIR/o.n.m.m.c.C/testAddRemovePomLib/[email protected]:2] where modified=true
public void testAddRemovePomLib() throws Exception {
    Library lib = LibraryManager.getDefault().createLibrary("j2se", "Stuff", Collections.singletonMap("maven-pom", Collections.singletonList(new URL("http://repo1.maven.org/maven2/grp/stuff/1.0/stuff-1.0.pom"))));
    Library lib2 = LibraryManager.getDefault().createLibrary("j2se", "Stuff2", Collections.singletonMap("maven-pom", Collections.singletonList(new URL("http://repo1.maven.org/maven2/grp/stuff/2.0/stuff-2.0.pom"))));
    FileObject d = FileUtil.toFileObject(getWorkDir());
    TestFileUtils.writeFile(d, "pom.xml", "<project><modelVersion>4.0.0</modelVersion>"
            + "<groupId>test</groupId><artifactId>prj</artifactId>"
            + "<packaging>jar</packaging><version>1.0</version></project>");
    FileObject java = TestFileUtils.writeFile(d, "src/main/java/p/C.java", "package p; class C {}");
    Project p = ProjectManager.getDefault().findProject(d);
    NbMavenProject mp = p.getLookup().lookup(NbMavenProject.class);
    assertEquals("[]", mp.getMavenProject().getDependencies().toString());
    assertTrue(ProjectClassPathModifier.addLibraries(new Library[] {lib}, java, ClassPath.COMPILE));
    assertFalse(ProjectClassPathModifier.addLibraries(new Library[] {lib}, java, ClassPath.COMPILE));
    NbMavenProject.fireMavenProjectReload(p); // XXX why is this necessary?
    assertEquals("[Dependency {groupId=grp, artifactId=stuff, version=1.0, type=jar}]", mp.getMavenProject().getDependencies().toString());
    assertFalse(ProjectClassPathModifier.removeLibraries(new Library[] {lib2}, java, ClassPath.COMPILE));
    assertTrue(ProjectClassPathModifier.removeLibraries(new Library[] {lib}, java, ClassPath.COMPILE));
    assertFalse(ProjectClassPathModifier.removeLibraries(new Library[] {lib}, java, ClassPath.COMPILE));
    NbMavenProject.fireMavenProjectReload(p);
    assertEquals("[]", mp.getMavenProject().getDependencies().toString());
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:23,代码来源:CPExtenderTest.java

示例7: testShowItIsPossibleToPassInBeansWrappedObject

import org.openide.filesystems.FileObject; //导入依赖的package包/类
public void testShowItIsPossibleToPassInBeansWrappedObject() throws Exception {
    FileObject root = FileUtil.createMemoryFileSystem().getRoot();
    FileObject fo = FileUtil.createData(root, "simpleObject.txt");
    OutputStream os = fo.getOutputStream();
    String txt = "<#if (classInfo.getMethods().size() > 0) >The size is greater than 0.</#if>";
    os.write(txt.getBytes());
    os.close();       
    
    
    StringWriter w = new StringWriter();
                    
    Map<String,Object> parameters = Collections.<String,Object>singletonMap(
        "classInfo", BeansWrapper.getDefaultInstance().wrap(new ClassInfo())
    );
    apply(fo, w, parameters);
    assertEquals("The size is greater than 0.", w.toString());
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:18,代码来源:ProcessorTest.java

示例8: setUp

import org.openide.filesystems.FileObject; //导入依赖的package包/类
@Override
protected void setUp() throws Exception {
    clearWorkDir();
    f = new File(getWorkDir(), "m.jar");
    
    Manifest man = new Manifest();
    Attributes attr = man.getMainAttributes();
    attr.putValue("OpenIDE-Module", "m.test");
    attr.putValue("OpenIDE-Module-Public-Packages", "-");
    attr.putValue("Manifest-Version", "1.0");
    JarOutputStream os = new JarOutputStream(new FileOutputStream(f), man);
    os.putNextEntry(new JarEntry("META-INF/namedservices/ui/javax.swing.JComponent"));
    os.write("javax.swing.JButton\n".getBytes("UTF-8"));
    os.closeEntry();
    os.close();
    
    FileObject fo = FileUtil.createData(FileUtil.getConfigRoot(), "ui/ch/my/javax-swing-JPanel.instance");
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:19,代码来源:RecognizeInstanceObjectsOnModuleEnablementTest.java

示例9: writeFile

import org.openide.filesystems.FileObject; //导入依赖的package包/类
@NonNull
private static FileObject writeFile(
        @NonNull final FileObject root,
        @NonNull final String folder,
        @NonNull final String name,
        @NonNull final String content) throws IOException {
    final FileObject fld;
    if (!folder.isEmpty()) {
        fld = FileUtil.createFolder(root, folder);
    } else {
        fld = root;
    }
    final FileObject file = FileUtil.createData(fld, name);
    try(PrintWriter out = new PrintWriter(new OutputStreamWriter(file.getOutputStream(), "UTF-8"))) {   //NOI18N
        out.println(content);
    }
    return file;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:19,代码来源:ModuleOraculumTest.java

示例10: getFileObject

import org.openide.filesystems.FileObject; //导入依赖的package包/类
/**
 * Grabs and checks a <code>FileObject</code> from the given node.
 * If either the file could not be grabbed or the file does not pertain
 * to any project, a message is displayed.
 *
 * @param  node  node to get a <code>FileObject</code> from.
 * @return  the grabbed <code>FileObject</code>,
 *          or <code>null</code> in case of failure
 */
@NbBundle.Messages({"# {0} - selected node's display name",
    "MSG_file_from_node_failed=File cannot be found for selected node: {0}.",
    "# {0} - source file",
    "MSG_no_project=Source file {0} does not belong to any project."})
private static FileObject getFileObject(final Node node, boolean justLogIt) {
    final FileObject fo = getFileObjectFromNode(node);
    if (fo == null) {
        if(justLogIt) {
            LOG.info(Bundle.MSG_file_from_node_failed(node.getDisplayName()));
        } else {
            notifyUser(Bundle.MSG_file_from_node_failed(node.getDisplayName()));
        }
        return null;
    }
    Project owner = FileOwnerQuery.getOwner(fo);
    if (owner == null) {
        if(justLogIt) {
            LOG.info(Bundle.MSG_no_project(fo));
        } else {
            notifyUser(Bundle.MSG_no_project(fo));
        }
        return null;
    }
    return fo;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:35,代码来源:UICommonUtils.java

示例11: testCachedMultiFS

import org.openide.filesystems.FileObject; //导入依赖的package包/类
public void testCachedMultiFS() throws Exception {
    clearWorkDir();
    LayerCacheManager m = LayerCacheManager.manager(true);
    // b-layer.xml overrides a-layer.xml now and then:
    List<File> files = new ArrayList<File>(Arrays.asList(
            new File(getDataDir(), "layers/b-layer.xml"),
            new File(getDataDir(), "layers/a-layer.xml")
            ));

    FileSystem cfs = memoryStoreAndLoad(m, files);
    assertNotNull(cfs.findResource("Menu/File"));
    assertNotNull(cfs.findResource("Menu/A Folder"));
    assertNull(cfs.findResource("Menu/A Folder/org-example-a-AAction.shadow"));  // hidden by b-layer
    FileObject mf = cfs.findResource("Actions/File");
    assertEquals(2, mf.getChildren().length);
    FileObject ba = cfs.findResource("Actions/File/org-example-b-BAction.instance");
    assertEquals("BBBBB", ba.getAttribute("displayName"));
    FileObject aa = cfs.findResource("Actions/File/org-example-a-AAction.instance");
    assertEquals("AAAA", aa.getAttribute("displayName"));
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:21,代码来源:LayerUtilsTest.java

示例12: testIsRecursiveSymbolicLinkIndirect

import org.openide.filesystems.FileObject; //导入依赖的package包/类
/**
 * Test isRecursiveSymbolicLink method. Use this folder tree:
 * <pre>
 * - workdir
 *   - a
 *     - b
 *       - c (symlink to d)
 *   - d (symlink to a)
 * </pre>
 *
 * @throws java.io.IOException
 */
public void testIsRecursiveSymbolicLinkIndirect() throws IOException {
    if (!checkSymlinksSupported()) {
        return;
    }
    File dir = getWorkDir();
    File a = new File(dir, "a");
    File b = new File(a, "b");
    File c = new File(b, "c");
    File d = new File(dir, "d");
    b.mkdirs();
    Files.createSymbolicLink(d.toPath(), a.toPath());
    Files.createSymbolicLink(c.toPath(), d.toPath());
    FileObject dirFO = FileUtil.toFileObject(dir);
    FileObject cFO = dirFO.getFileObject("a/b/c");
    assertTrue(FileUtil.isRecursiveSymbolicLink(cFO));
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:29,代码来源:FileObjSymlinkTest.java

示例13: createClassPath

import org.openide.filesystems.FileObject; //导入依赖的package包/类
private static ClassPath createClassPath(URL[] urls) {
    List<PathResourceImplementation> pris = new ArrayList<PathResourceImplementation> ();
    for (URL url : urls) {
        FileObject fo = URLMapper.findFileObject(url);
        if (fo != null && fo.canRead()) {
            try {
                pris.add(ClassPathSupport.createResource(url));
            } catch (IllegalArgumentException iaex) {
                // Can be thrown from ClassPathSupport.createResource()
                // Ignore - bad source root
                //logger.log(Level.INFO, "Invalid source root = "+fo, iaex);
                logger.warning(iaex.getLocalizedMessage());
            }
        }
    }
    return ClassPathSupport.createClassPath(pris);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:18,代码来源:SourcePathProviderImpl.java

示例14: closeMemoryToolbar

import org.openide.filesystems.FileObject; //导入依赖的package包/类
/**
     * Close Memory Toolbar.
     */
    public static void closeMemoryToolbar(){
        // View|Toolbars|Memory        
        try {  // workaround for Issue #213828
            FileObject fo = FileUtil.getConfigFile("Toolbars/Memory");
            if (fo!=null) {
                fo.delete();
            }
        } catch (IOException ex) {
            Exceptions.printStackTrace(ex);
        }        
//        closeToolbar(Bundle.getStringTrimmed("org.openide.actions.Bundle","View") + "|" +
//                Bundle.getStringTrimmed("org.netbeans.core.windows.actions.Bundle", "CTL_ToolbarsListAction") + "|" +
//                "Memory");
        maximizeWholeNetbeansWindow();
    }
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:19,代码来源:CommonUtilities.java

示例15: initApplication

import org.openide.filesystems.FileObject; //导入依赖的package包/类
private static void initApplication(FileObject dirFO, String platformID) throws IOException  {
    SuiteProject project = (SuiteProject) ProjectManager.getDefault().findProject(dirFO);
    SuiteProperties suiteProps = new SuiteProperties(project, project.getHelper(), project.getEvaluator(), Collections.<NbModuleProject>emptySet());
    BrandingModel branding = suiteProps.getBrandingModel();
    branding.setBrandingEnabled(true);
    branding.setName(branding.getName());
    branding.setTitle(branding.getTitle());
    branding.store();
    NbPlatform plaf = NbPlatform.getPlatformByID(platformID);
    if (plaf != null) {
        ModuleEntry bootstrapModule = plaf.getModule("org.netbeans.bootstrap");
        if (bootstrapModule != null) {
            if (plaf.getHarnessVersion().compareTo(HarnessVersion.V65) <= 0) {
                // Will be stripped of version suffix if appropriate for the platform.
                suiteProps.setEnabledClusters(new String[] {bootstrapModule.getClusterDirectory().getName()});
            } else {
                suiteProps.setClusterPath(Collections.singletonList(
                        ClusterInfo.create(bootstrapModule.getClusterDirectory(), true, true)));
            }
        }
    }
    suiteProps.setDisabledModules(SuiteCustomizerLibraries.DISABLED_PLATFORM_MODULES.toArray(new String[0]));
    suiteProps.storeProperties();
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:25,代码来源:SuiteProjectGenerator.java


注:本文中的org.openide.filesystems.FileObject类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。