本文整理匯總了Java中org.openide.util.Utilities.toFile方法的典型用法代碼示例。如果您正苦於以下問題:Java Utilities.toFile方法的具體用法?Java Utilities.toFile怎麽用?Java Utilities.toFile使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.openide.util.Utilities
的用法示例。
在下文中一共展示了Utilities.toFile方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: findForCPExt
import org.openide.util.Utilities; //導入方法依賴的package包/類
/**
* Find Javadoc roots for classpath extensions ("wrapped" JARs) of the project
* added by naming convention <tt><jar name>-javadoc(.zip)</tt>
* See issue #66275
* @param binaryRoot
* @return
*/
private Result findForCPExt(URL binaryRoot) {
URL jar = FileUtil.getArchiveFile(binaryRoot);
if (jar == null)
return null; // not a class-path-extension
File binaryRootF = Utilities.toFile(URI.create(jar.toExternalForm()));
// XXX this will only work for modules following regular naming conventions:
String n = binaryRootF.getName();
if (!n.endsWith(".jar")) { // NOI18N
// ignore
return null;
}
// convention-over-cfg per mkleint's suggestion: <jarname>-javadoc(.zip) folder or ZIP
File jFolder = new File(binaryRootF.getParentFile(),
n.substring(0, n.length() - ".jar".length()) + "-javadoc");
if (jFolder.isDirectory()) {
return new R(new URL[]{FileUtil.urlForArchiveOrDir(jFolder)});
} else {
File jZip = new File(jFolder.getAbsolutePath() + ".zip");
if (jZip.isFile()) {
return new R(new URL[]{FileUtil.urlForArchiveOrDir(jZip)});
}
}
return null;
}
示例2: testBrokenShadow55115
import org.openide.util.Utilities; //導入方法依賴的package包/類
public void testBrokenShadow55115 () throws Exception {
FileObject brokenShadow = FileUtil.createData(FileUtil.getConfigRoot(),"brokenshadows/brokon.shadow");
assertNotNull (brokenShadow);
// intentionally not set attribute "originalFile" to let that shadow be broken
//brokenShadow.setAttribute("originalFile", null);
BrokenDataShadow bds = (BrokenDataShadow)DataObject.find(brokenShadow);
assertNotNull (bds);
URL url = bds.getUrl();
//this call proves #55115 - but just in case if there is reachable masterfs
// - probably unwanted here
bds.refresh();
//If masterfs isn't reachable - second test crucial for URL,File, FileObject conversions
// not necessary to be able to convert - but at least no IllegalArgumentException is expected
if ("file".equals(url.getProtocol())) {
Utilities.toFile(URI.create(url.toExternalForm()));
}
}
示例3: addWatchedPath
import org.openide.util.Utilities; //導入方法依賴的package包/類
/**
*
* @param uri
*/
public void addWatchedPath(URI uri) {
//#110599
boolean addListener = false;
File fil = Utilities.toFile(uri);
synchronized (files) {
//#216001 addWatchedPath appeared to accumulate files forever on each project reload.
//that's because source roots get added repeatedly but never get removed and listening to changed happens elsewhere.
//the imagined fix for 216001 is to keep each item just once. That would break once multiple sources add a given file and one of them removes it
//as a hotfix this solution is ok, if we don't get some data updated, we should remove the watchedPath pattern altogether.
if (files.add(fil)) {
addListener = true;
}
}
if (addListener) {
FileUtil.addFileChangeListener(listener, fil);
}
}
示例4: keys
import org.openide.util.Utilities; //導入方法依賴的package包/類
public List<String> keys() {
List<String> result = new ArrayList<String>();
result.add(LIBRARIES);
URL[] testRoots = project.getTestSourceRoots().getRootURLs();
boolean addTestSources = false;
for (int i = 0; i < testRoots.length; i++) {
File f = Utilities.toFile(URI.create(testRoots[i].toExternalForm()));
if (f.exists()) {
addTestSources = true;
break;
}
}
if (addTestSources) {
result.add(TEST_LIBRARIES);
}
return result;
}
示例5: createModel
import org.openide.util.Utilities; //導入方法依賴的package包/類
public static DefaultTableModel createModel( ModuleRoots roots ) {
URL[] rootURLs = roots.getRootURLs(false);
String[] rootPaths = roots.getRootPathProperties();
Object[][] data = new Object[rootURLs.length] [2];
for (int i = 0; i < rootURLs.length; i++) {
data[i][0] = Utilities.toFile(URI.create (rootURLs[i].toExternalForm()));
data[i][1] = roots.getRootPath(rootPaths[i]);
}
return new SourceRootsModel(data);
}
示例6: getOrCreateFolder
import org.openide.util.Utilities; //導入方法依賴的package包/類
/**
* creates or finds FileObject according to
*
* @param url
* @return FileObject
*/
private FileObject getOrCreateFolder(URL url) throws IOException {
try {
FileObject result = URLMapper.findFileObject(url);
if (result != null) {
return result;
}
File f = Utilities.toFile(url.toURI());
result = FileUtil.createFolder(f);
return result;
} catch (URISyntaxException ex) {
throw new IOException(ex);
}
}
示例7: run
import org.openide.util.Utilities; //導入方法依賴的package包/類
private void run(File workDir, String... args) throws Exception {
URL u = Lookup.class.getProtectionDomain().getCodeSource().getLocation();
File f = Utilities.toFile(u.toURI());
assertTrue("file found: " + f, f.exists());
File nbexec = Utilities.isWindows() ? new File(f.getParent(), "nbexec.exe") : new File(f.getParent(), "nbexec");
assertTrue("nbexec found: " + nbexec, nbexec.exists());
URL tu = MainCallback.class.getProtectionDomain().getCodeSource().getLocation();
File testf = Utilities.toFile(tu.toURI());
assertTrue("file found: " + testf, testf.exists());
LinkedList<String> allArgs = new LinkedList<String>(Arrays.asList(args));
allArgs.addFirst("-J-Dnetbeans.mainclass=" + MainCallback.class.getName());
allArgs.addFirst(System.getProperty("java.home"));
allArgs.addFirst("--jdkhome");
allArgs.addFirst(getWorkDirPath());
allArgs.addFirst("--userdir");
allArgs.addFirst(testf.getPath());
allArgs.addFirst("-cp:p");
if (!Utilities.isWindows()) {
allArgs.addFirst(nbexec.getPath());
allArgs.addFirst("-x");
allArgs.addFirst("/bin/sh");
} else {
allArgs.addFirst(nbexec.getPath());
}
StringBuffer sb = new StringBuffer();
Process p = Runtime.getRuntime().exec(allArgs.toArray(new String[allArgs.size()]), new String[0], workDir);
int res = readOutput(sb, p);
String output = sb.toString();
assertEquals("Execution is ok: " + output, 0, res);
}
示例8: save
import org.openide.util.Utilities; //導入方法依賴的package包/類
public void save() {
synchronized (this) {
if (lastSave >= modificationCount) return ; //already saved
lastSave = modificationCount;
}
File file = Utilities.toFile(settings); //XXX: non-file:// scheme
try (OutputStream out = new BufferedOutputStream(new FileOutputStream(file))) {
XMLUtil.write(doc, out, "UTF-8");
} catch (IOException ex) {
Exceptions.printStackTrace(ex);
}
}
示例9: getAttachementData
import org.openide.util.Utilities; //導入方法依賴的package包/類
@Override
public void getAttachementData (final OutputStream os) {
try {
File f = Utilities.toFile(new URI(uri));
FileUtils.copyStreamsCloseAll(os, FileUtils.createInputStream(f));
} catch (URISyntaxException | IOException ex) {
Exceptions.printStackTrace(ex);
}
}
示例10: setUp
import org.openide.util.Utilities; //導入方法依賴的package包/類
@Override
protected void setUp() throws Exception {
super.setUp();
URL urlToFile = DefaultTestCase.class.getResource ("data/org-yourorghere-depending.nbm");
NBM_FILE = Utilities.toFile(urlToFile.toURI ());
assertNotNull ("data/org-yourorghere-depending.nbm file must found.", NBM_FILE);
}
示例11: from
import org.openide.util.Utilities; //導入方法依賴的package包/類
public static HintPreferencesProviderImpl from(@NonNull URI settings) {
Reference<HintPreferencesProviderImpl> ref = uri2Cache.get(settings);
HintPreferencesProviderImpl cachedResult = ref != null ? ref.get() : null;
if (cachedResult != null) return cachedResult;
Document doc = null;
File file = Utilities.toFile(settings); //XXX: non-file:// scheme
if (file.canRead()) {
try(InputStream in = new BufferedInputStream(new FileInputStream(file))) {
doc = XMLUtil.parse(new InputSource(in), false, false, null, EntityCatalog.getDefault());
} catch (SAXException | IOException ex) {
LOG.log(Level.FINE, null, ex);
}
}
if (doc == null) {
doc = XMLUtil.createDocument("configuration", null, "-//NetBeans//DTD Tool Configuration 1.0//EN", "http://www.netbeans.org/dtds/ToolConfiguration-1_0.dtd");
}
synchronized (uri2Cache) {
ref = uri2Cache.get(settings);
cachedResult = ref != null ? ref.get() : null;
if (cachedResult != null) return cachedResult;
uri2Cache.put(settings, new CleaneableSoftReference(cachedResult = new HintPreferencesProviderImpl(settings, doc), settings));
}
return cachedResult;
}
示例12: invokeNbExecAndCreateCluster
import org.openide.util.Utilities; //導入方法依賴的package包/類
private void invokeNbExecAndCreateCluster(File workDir, StringBuffer sb, String... args) throws Exception {
URL u = Lookup.class.getProtectionDomain().getCodeSource().getLocation();
File f = Utilities.toFile(u.toURI());
assertTrue("file found: " + f, f.exists());
File nbexec = org.openide.util.Utilities.isWindows() ? new File(f.getParent(), "nbexec.exe") : new File(f.getParent(), "nbexec");
assertTrue("nbexec found: " + nbexec, nbexec.exists());
LOG.log(Level.INFO, "nbexec: {0}", nbexec);
URL tu = NewClustersRebootCallback.class.getProtectionDomain().getCodeSource().getLocation();
File testf = Utilities.toFile(tu.toURI());
assertTrue("file found: " + testf, testf.exists());
LinkedList<String> allArgs = new LinkedList<String>(Arrays.asList(args));
allArgs.addFirst("-J-Dnetbeans.mainclass=" + NewClustersRebootCallback.class.getName());
allArgs.addFirst(System.getProperty("java.home"));
allArgs.addFirst("--jdkhome");
allArgs.addFirst(getWorkDirPath());
allArgs.addFirst("--userdir");
allArgs.addFirst(testf.getPath());
allArgs.addFirst("-cp:p");
allArgs.addFirst("--nosplash");
if (!org.openide.util.Utilities.isWindows()) {
allArgs.addFirst(nbexec.getPath());
allArgs.addFirst("-x");
allArgs.addFirst("/bin/sh");
} else {
allArgs.addFirst(nbexec.getPath());
}
LOG.log(Level.INFO, "About to execute {0}@{1}", new Object[]{allArgs, workDir});
Process p = Runtime.getRuntime().exec(allArgs.toArray(new String[0]), new String[0], workDir);
LOG.log(Level.INFO, "Process created {0}", p);
int res = readOutput(sb, p);
LOG.log(Level.INFO, "Output read: {0}", res);
String output = sb.toString();
// System.out.println("nbexec output is: " + output);
assertEquals("Execution is ok: " + output, 0, res);
}
示例13: isCluster
import org.openide.util.Utilities; //導入方法依賴的package包/類
static boolean isCluster(String name) throws URISyntaxException {
URL where = NbModuleSuite.class.getProtectionDomain().getCodeSource().getLocation();
File nbjunitJAR = Utilities.toFile(where.toURI());
assertTrue(nbjunitJAR.exists());
File harness = nbjunitJAR.getParentFile().getParentFile();
assertEquals("harness", harness.getName());
File root = harness.getParentFile();
return new File(root, "extide").isDirectory();
}
示例14: testUsingNbfsProtocol
import org.openide.util.Utilities; //導入方法依賴的package包/類
/** Ensure that a user-mode class can at least use findResource() to access
* resources in filesystems.
* @see "#13038"
*/
public void testUsingNbfsProtocol() throws Exception {
System.setProperty("org.netbeans.core.Plain.CULPRIT", "true");
File here = Utilities.toFile(getClass().getProtectionDomain().getCodeSource().getLocation().toURI());
assertTrue("Classpath really contains " + here,
new File(new File(new File(new File(here, "org"), "openide"), "execution"), "NbClassLoaderTest.class").canRead());
File dataDir = new File(new File(new File(new File(here, "org"), "openide"), "execution"), "data");
if(!dataDir.exists()) {
dataDir.mkdir();
}
File fooFile = new File(dataDir, "foo.xml");
if(!fooFile.exists()) {
fooFile.createNewFile();
}
LocalFileSystem lfs = new LocalFileSystem();
lfs.setRootDirectory(here);
lfs.setReadOnly(true);
ClassLoader cl = new NbClassLoader(new FileObject[] {lfs.getRoot()}, ClassLoader.getSystemClassLoader().getParent(), null);
System.setSecurityManager(new MySecurityManager());
// Ensure this class at least has free access:
System.getProperty("foo");
Class c = cl.loadClass("org.openide.execution.NbClassLoaderTest$User");
assertEquals(cl, c.getClassLoader());
try {
c.newInstance();
} catch (ExceptionInInitializerError eiie) {
Throwable t = eiie.getException();
if (t instanceof IllegalStateException) {
fail(t.getMessage());
} else if (t instanceof Exception) {
throw (Exception)t;
} else {
throw new Exception(t.toString());
}
}
}
示例15: isReset
import org.openide.util.Utilities; //導入方法依賴的package包/類
@Override
protected boolean isReset(PropertyChangeEvent evt) {
boolean reset = false;
if( (NbMavenProject.PROP_RESOURCE.equals(evt.getPropertyName()) && evt.getNewValue() instanceof URI)) {
File file = Utilities.toFile((URI) evt.getNewValue());
MavenProject mp = proj.getOriginalMavenProject();
reset = mp.getCompileSourceRoots().stream().anyMatch((sourceRoot) -> (file.equals(new File(sourceRoot, MODULE_INFO_JAVA)))) ||
mp.getTestCompileSourceRoots().stream().anyMatch((sourceRoot) -> (file.equals(new File(sourceRoot, MODULE_INFO_JAVA))));
if(reset) {
LOGGER.log(Level.FINER, "TestPathSelector {0} for project {1} resource changed: {2}", new Object[]{logDesc, proj.getProjectDirectory().getPath(), evt});
}
}
return reset;
}