本文整理匯總了Java中org.openide.filesystems.FileUtil.archiveOrDirForURL方法的典型用法代碼示例。如果您正苦於以下問題:Java FileUtil.archiveOrDirForURL方法的具體用法?Java FileUtil.archiveOrDirForURL怎麽用?Java FileUtil.archiveOrDirForURL使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.openide.filesystems.FileUtil
的用法示例。
在下文中一共展示了FileUtil.archiveOrDirForURL方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: buildScript
import org.openide.filesystems.FileUtil; //導入方法依賴的package包/類
private static FileObject buildScript(String actionName, boolean forceCopy) throws IOException {
URL script = locateScript(actionName);
if (script == null) {
return null;
}
URL thisClassSource = ProjectRunnerImpl.class.getProtectionDomain().getCodeSource().getLocation();
File jarFile = FileUtil.archiveOrDirForURL(thisClassSource);
File scriptFile = Places.getCacheSubfile("executor-snippets/" + actionName + ".xml");
if (forceCopy || !scriptFile.canRead() || (jarFile != null && jarFile.lastModified() > scriptFile.lastModified())) {
try {
URLConnection connection = script.openConnection();
FileObject target = FileUtil.createData(scriptFile);
copyFile(connection, target);
return target;
} catch (IOException ex) {
Exceptions.printStackTrace(ex);
return null;
}
}
return FileUtil.toFileObject(scriptFile);
}
示例2: getJavacApiJarClasspath
import org.openide.filesystems.FileUtil; //導入方法依賴的package包/類
private static ClassPath getJavacApiJarClasspath() {
Reference<ClassPath> r = javacApiClasspath;
ClassPath res = r.get();
if (res != null) {
return res;
}
if (r == NONE) {
return null;
}
CodeSource codeSource = Modifier.class.getProtectionDomain().getCodeSource();
URL javacApiJar = codeSource != null ? codeSource.getLocation() : null;
if (javacApiJar != null) {
Logger.getLogger(DeclarativeHintsParser.class.getName()).log(Level.FINE, "javacApiJar={0}", javacApiJar);
File aj = FileUtil.archiveOrDirForURL(javacApiJar);
if (aj != null) {
res = ClassPathSupport.createClassPath(FileUtil.urlForArchiveOrDir(aj));
javacApiClasspath = new WeakReference<>(res);
return res;
}
}
javacApiClasspath = NONE;
return null;
}
示例3: toFiles
import org.openide.filesystems.FileUtil; //導入方法依賴的package包/類
private static Iterable<? extends File> toFiles(ClassPath cp) {
List<File> result = new LinkedList<File>();
for (Entry e : cp.entries()) {
File f = FileUtil.archiveOrDirForURL(e.getURL());
if (f == null) {
Logger.getLogger(Hacks.class.getName()).log(Level.INFO, "file == null, url={0}", e.getURL());
continue;
}
result.add(f);
}
return result;
}
示例4: append
import org.openide.filesystems.FileUtil; //導入方法依賴的package包/類
@NonNull
private static StringBuilder append (
@NonNull final StringBuilder builder,
@NonNull final URL url) {
final File f = FileUtil.archiveOrDirForURL(url);
if (f != null) {
if (builder.length() > 0) {
builder.append(File.pathSeparatorChar);
}
builder.append(f.getAbsolutePath());
} else {
if (builder.length() > 0) {
builder.append(File.pathSeparatorChar);
}
builder.append(url);
}
return builder;
}
示例5: accept
import org.openide.filesystems.FileUtil; //導入方法依賴的package包/類
@Override
public void accept(@NonNull final URL url) {
synchronized (this) {
load();
if (used == null || used == TOMBSTONE) {
used = new LongHashMap<>();
}
final File f = FileUtil.archiveOrDirForURL(url);
if (f != null) {
final long size = f.isFile() ?
f.length() :
-1;
if (!used.containsKey(f)) {
used.put(f, size);
saveTask.schedule(DEFERRED_SAVE);
}
}
}
}
示例6: addRoots
import org.openide.filesystems.FileUtil; //導入方法依賴的package包/類
public @Override boolean addRoots(final URL[] urls, SourceGroup grp, String type) throws IOException {
final AtomicBoolean added = new AtomicBoolean();
final String scope = findScope(grp, type);
ModelOperation<POMModel> operation = new ModelOperation<POMModel>() {
public @Override void performOperation(POMModel model) {
for (URL url : urls) {
File jar = FileUtil.archiveOrDirForURL(url);
if (jar != null && jar.isFile()) {
try {
added.compareAndSet(false, addRemoveJAR(jar, model, scope, true));
} catch (IOException ex) {
Exceptions.printStackTrace(ex);
}
} else {
Logger.getLogger(CPExtender.class.getName()).log(Level.INFO, "Adding non-jar root to Maven projects makes no sense. ({0})", url); //NOI18N
}
}
}
};
FileObject pom = project.getProjectDirectory().getFileObject(POM_XML);//NOI18N
org.netbeans.modules.maven.model.Utilities.performPOMModelOperations(pom, Collections.singletonList(operation));
if (added.get()) {
project.getLookup().lookup(NbMavenProject.class).triggerDependencyDownload();
}
return added.get();
}
示例7: pathToString
import org.openide.filesystems.FileUtil; //導入方法依賴的package包/類
@NonNull
private static String pathToString(@NonNull final ClassPath path) {
final StringBuilder cpBuilder = new StringBuilder();
for (ClassPath.Entry entry : path.entries()) {
final URL u = entry.getURL();
boolean folder = "file".equals(u.getProtocol());
File f = FileUtil.archiveOrDirForURL(u);
if (f != null) {
if (cpBuilder.length() > 0) {
cpBuilder.append(File.pathSeparatorChar);
}
cpBuilder.append(f.getAbsolutePath());
if (folder) {
cpBuilder.append(File.separatorChar);
}
}
}
return cpBuilder.toString();
}
示例8: getDisplayName
import org.openide.filesystems.FileUtil; //導入方法依賴的package包/類
@NonNull
private static String getDisplayName(@NonNull final URL root) {
final File f = FileUtil.archiveOrDirForURL(root);
return f == null ?
root.toString() :
f.isFile() ?
f.getName() :
f.getAbsolutePath();
}
示例9: getListCellRendererComponent
import org.openide.filesystems.FileUtil; //導入方法依賴的package包/類
public @Override Component getListCellRendererComponent(JList list, Object value,
int index, boolean isSelected, boolean cellHasFocus) {
URL u = (URL) value;
File f = FileUtil.archiveOrDirForURL(u);
String text = f != null ? f.getAbsolutePath() : u.toString();
return super.getListCellRendererComponent(list, text, index, isSelected, cellHasFocus);
}
示例10: listTests
import org.openide.filesystems.FileUtil; //導入方法依賴的package包/類
private static Collection<String> listTests(Class<?> clazz) {
File dirOrArchive = FileUtil.archiveOrDirForURL(clazz.getProtectionDomain().getCodeSource().getLocation());
assertTrue(dirOrArchive.exists());
if (dirOrArchive.isFile()) {
return listTestsFromJar(dirOrArchive);
} else {
Collection<String> result = new LinkedList<String>();
listTestsFromFilesystem(dirOrArchive, "", result);
return result;
}
}
示例11: checkFootprint
import org.openide.filesystems.FileUtil; //導入方法依賴的package包/類
/** Find the time the file this URL represents was last modified xor its size, if possible. */
private static long checkFootprint(URL u) {
File f = FileUtil.archiveOrDirForURL(u);
if (f != null) {
return f.lastModified() ^ f.length();
} else {
return 0L;
}
}
示例12: urlForMessage
import org.openide.filesystems.FileUtil; //導入方法依賴的package包/類
private String urlForMessage(URL currentlyScannedRoot) {
final File file = FileUtil.archiveOrDirForURL(currentlyScannedRoot);
final String msg = file != null?
file.getAbsolutePath():
currentlyScannedRoot.toExternalForm();
return msg;
}
示例13: findSourceRoots2
import org.openide.filesystems.FileUtil; //導入方法依賴的package包/類
@Override
public Result findSourceRoots2(final URL binaryRoot) {
Result r = findAarLibraryRoots(binaryRoot);
if (r != null) {
return r;
}
if (project == null) {
return null;
}
final File binRootDir = FileUtil.archiveOrDirForURL(binaryRoot);
if (binRootDir == null) {
return null;
}
Variant variant = Iterables.find(
project.getVariants(),
new Predicate<Variant>() {
@Override
public boolean apply(Variant input) {
return binRootDir.equals(input.getMainArtifact().getClassesFolder());
}
},
null);
if (variant != null) {
Iterable<FileObject> srcRoots = Iterables.filter(
Iterables.transform(
sourceRootsForVariant(variant),
new Function<File, FileObject>() {
@Override
public FileObject apply(File f) {
return FileUtil.toFileObject(f);
}
}),
Predicates.notNull());
return new GradleSourceResult(srcRoots);
}
return null;
}
示例14: getRoots
import org.openide.filesystems.FileUtil; //導入方法依賴的package包/類
public FileObject[] getRoots() {
final List<FileObject> candidates = new ArrayList<FileObject>();
try {
for (URL root : srp.getSourceRoots()) {
if (root.getProtocol().equals("jar")) { // NOI18N
// suppose zipped sources
File nbSrcF = FileUtil.archiveOrDirForURL(root);
if (nbSrcF == null || !nbSrcF.exists()) {
continue;
}
NetBeansSourcesParser nbsp;
try {
nbsp = NetBeansSourcesParser.getInstance(nbSrcF);
} catch (ZipException e) {
if (!quiet) {
Util.err.annotate(e, ErrorManager.UNKNOWN, nbSrcF + " does not seem to be a valid ZIP file.", null, null, null); // NOI18N
Util.err.notify(ErrorManager.INFORMATIONAL, e);
}
continue;
}
if (nbsp == null) {
continue;
}
String pathInZip = nbsp.findSourceRoot(cnb);
if (pathInZip == null) {
continue;
}
URL u = new URL(root, pathInZip);
FileObject entryFO = URLMapper.findFileObject(u);
if (entryFO != null) {
candidates.add(entryFO);
}
} else {
// Does not resolve nbjunit and similar from ZIPped
// sources. Not a big issue since the default distributed
// sources do not contain them anyway.
String relPath = resolveRelativePath(root);
if (relPath == null) {
continue;
}
URL url = new URL(root, relPath);
FileObject dir = URLMapper.findFileObject(url);
if (dir != null) {
candidates.add(dir);
} // others dirs are currently resolved by o.n.m.apisupport.project.queries.SourceForBinaryImpl
}
}
} catch (IOException ex) {
throw new AssertionError(ex);
}
return candidates.toArray(new FileObject[candidates.size()]);
}
示例15: doLoad
import org.openide.filesystems.FileUtil; //導入方法依賴的package包/類
private void doLoad(final AtomicBoolean cancel) {
URL[] urls = mojo.getClasspathURLs();
String impl = mojo.getImplementationClass();
if (urls != null) {
List<URL> normalizedUrls = new ArrayList<URL>();
//first download the source files for the binaries..
MavenSourceJavadocAttacher attacher = new MavenSourceJavadocAttacher();
for (URL url : urls) {
//the urls are not normalized and can contain ../ path parts
try {
url = FileUtil.urlForArchiveOrDir(FileUtil.normalizeFile(Utilities.toFile(url.toURI())));
if (url == null) {
continue; //#242324
}
normalizedUrls.add(url);
List<? extends URL> ret = attacher.getSources(url, new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
return cancel.get();
}
});
SourceForBinaryQuery.Result2 result = SourceForBinaryQuery.findSourceRoots2(url);
if (result.getRoots().length == 0 && !ret.isEmpty()) {
//binary not in repository, we need to hardwire the mapping here to have sfbq pick it up.
Set<File> fls = new HashSet<File>();
for (URL u : ret) {
File f = FileUtil.archiveOrDirForURL(u);
if (f != null) {
fls.add(f);
}
}
if (!fls.isEmpty()) {
SourceJavadocByHash.register(url, fls.toArray(new File[0]), false);
}
}
if (cancel.get()) {
return;
}
} catch (URISyntaxException ex) {
Exceptions.printStackTrace(ex);
}
}
if (cancel.get()) {
return;
}
ClassPath cp = Utils.convertToSourcePath(normalizedUrls.toArray(new URL[0]));
RunConfig clone = RunUtils.cloneRunConfig(config);
clone.setInternalProperty("jpda.additionalClasspath", cp);
clone.setInternalProperty("jpda.stopclass", impl);
//stop method sometimes doesn't exist when inherited
clone.setInternalProperty("jpda.stopmethod", "execute");
clone.setProperty(Constants.ACTION_PROPERTY_JPDALISTEN, "maven");
if (cancel.get()) {
return;
}
RunUtils.run(clone);
}
}