本文整理匯總了Java中com.intellij.openapi.util.io.FileUtil.isJarOrZip方法的典型用法代碼示例。如果您正苦於以下問題:Java FileUtil.isJarOrZip方法的具體用法?Java FileUtil.isJarOrZip怎麽用?Java FileUtil.isJarOrZip使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.intellij.openapi.util.io.FileUtil
的用法示例。
在下文中一共展示了FileUtil.isJarOrZip方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: addLibraries
import com.intellij.openapi.util.io.FileUtil; //導入方法依賴的package包/類
private static void addLibraries(Collection<URL> classPath, File fromDir, URL selfRootUrl) throws MalformedURLException {
File[] files = fromDir.listFiles();
if (files == null) return;
for (File file : files) {
if (FileUtil.isJarOrZip(file)) {
URL url = file.toURI().toURL();
if (!selfRootUrl.equals(url)) {
classPath.add(url);
}
}
}
}
示例2: loadDescriptor
import com.intellij.openapi.util.io.FileUtil; //導入方法依賴的package包/類
@Nullable
public static IdeaPluginDescriptorImpl loadDescriptor(@NotNull final File file, @NotNull String fileName) {
IdeaPluginDescriptorImpl descriptor = null;
if (file.isDirectory()) {
descriptor = loadDescriptorFromDir(file, fileName);
if (descriptor == null) {
File libDir = new File(file, "lib");
if (!libDir.isDirectory()) {
return null;
}
final File[] files = libDir.listFiles();
if (files == null || files.length == 0) {
return null;
}
Arrays.sort(files, new Comparator<File>() {
@Override
public int compare(@NotNull File o1, @NotNull File o2) {
if (o2.getName().startsWith(file.getName())) return Integer.MAX_VALUE;
if (o1.getName().startsWith(file.getName())) return -Integer.MAX_VALUE;
if (o2.getName().startsWith("resources")) return -Integer.MAX_VALUE;
if (o1.getName().startsWith("resources")) return Integer.MAX_VALUE;
return 0;
}
});
for (final File f : files) {
if (FileUtil.isJarOrZip(f)) {
descriptor = loadDescriptorFromJar(f, fileName);
if (descriptor != null) {
descriptor.setPath(file);
break;
}
// getLogger().warn("Cannot load descriptor from " + f.getName() + "");
}
else if (f.isDirectory()) {
IdeaPluginDescriptorImpl descriptor1 = loadDescriptorFromDir(f, fileName);
if (descriptor1 != null) {
if (descriptor != null) {
getLogger().info("Cannot load " + file + " because two or more plugin.xml's detected");
return null;
}
descriptor = descriptor1;
descriptor.setPath(file);
}
}
}
}
}
else if (StringUtil.endsWithIgnoreCase(file.getName(), ".jar") && file.exists()) {
descriptor = loadDescriptorFromJar(file, fileName);
}
if (descriptor != null) {
resolveOptionalDescriptors(fileName, descriptor, new Function<String, IdeaPluginDescriptorImpl>() {
@Override
public IdeaPluginDescriptorImpl fun(String optionalDescriptorName) {
IdeaPluginDescriptorImpl optionalDescriptor = loadDescriptor(file, optionalDescriptorName);
if (optionalDescriptor == null && !FileUtil.isJarOrZip(file)) {
for (URL url : getClassLoaderUrls()) {
if ("file".equals(url.getProtocol())) {
optionalDescriptor = loadDescriptor(new File(decodeUrl(url.getFile())), optionalDescriptorName);
if (optionalDescriptor != null) {
break;
}
}
}
}
return optionalDescriptor;
}
});
}
return descriptor;
}