本文整理汇总了Java中com.intellij.util.lang.JarMemoryLoader类的典型用法代码示例。如果您正苦于以下问题:Java JarMemoryLoader类的具体用法?Java JarMemoryLoader怎么用?Java JarMemoryLoader使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
JarMemoryLoader类属于com.intellij.util.lang包,在下文中一共展示了JarMemoryLoader类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testPluginXml
import com.intellij.util.lang.JarMemoryLoader; //导入依赖的package包/类
@Test
public void testPluginXml() throws Exception {
String path = getTestDataPath() + "/ide/plugins/reorderJars";
ReorderJarsMain.main(new String[] { path + "/zkmOrder.txt", path, myTempDirectory.getPath() } );
File[] files = myTempDirectory.listFiles();
assertNotNull(files);
File file = files[0];
assertEquals("zkm.jar", file.getName());
JBZipFile zipFile = new JBZipFile(file);
try {
List<JBZipEntry> entries = zipFile.getEntries();
System.out.println(entries);
assertEquals(JarMemoryLoader.SIZE_ENTRY, entries.get(0).getName());
assertEquals("META-INF/plugin.xml", entries.get(1).getName());
}
finally {
zipFile.close();
}
}
示例2: main
import com.intellij.util.lang.JarMemoryLoader; //导入依赖的package包/类
public static void main(String[] args) {
try {
final String orderTxtPath = args[0];
final String jarsPath = args[1];
final String destinationPath = args[2];
final String libPath = args.length > 3 ? args[3] : null;
final Map<String, List<String>> toReorder = getOrder(new File(orderTxtPath));
final Set<String> ignoredJars = libPath == null ? Collections.<String>emptySet() : loadIgnoredJars(libPath);
for (String jarUrl : toReorder.keySet()) {
if (ignoredJars.contains(StringUtil.trimStart(jarUrl, "/lib/"))) continue;
if (jarUrl.startsWith("/lib/ant")) continue;
final File jarFile = new File(jarsPath, jarUrl);
if (!jarFile.isFile()) continue;
final JBZipFile zipFile = new JBZipFile(jarFile);
final List<JBZipEntry> entries = zipFile.getEntries();
final List<String> orderedEntries = toReorder.get(jarUrl);
Collections.sort(entries, new Comparator<JBZipEntry>() {
public int compare(JBZipEntry o1, JBZipEntry o2) {
if ("META-INF/plugin.xml".equals(o2.getName())) return Integer.MAX_VALUE;
if ("META-INF/plugin.xml".equals(o1.getName())) return -Integer.MAX_VALUE;
if (orderedEntries.contains(o1.getName())) {
return orderedEntries.contains(o2.getName()) ? orderedEntries.indexOf(o1.getName()) - orderedEntries.indexOf(o2.getName()) : -1;
}
else {
return orderedEntries.contains(o2.getName()) ? 1 : 0;
}
}
});
final File tempJarFile = FileUtil.createTempFile("__reorder__", "__reorder__");
final JBZipFile file = new JBZipFile(tempJarFile);
final JBZipEntry sizeEntry = file.getOrCreateEntry(JarMemoryLoader.SIZE_ENTRY);
sizeEntry.setData(ZipShort.getBytes(orderedEntries.size()));
for (JBZipEntry entry : entries) {
final JBZipEntry zipEntry = file.getOrCreateEntry(entry.getName());
zipEntry.setData(entry.getData());
}
file.close();
final File resultJarFile = new File(destinationPath, jarUrl);
final File resultDir = resultJarFile.getParentFile();
if (!resultDir.isDirectory() && !resultDir.mkdirs()) {
throw new IOException("Cannot create: " + resultDir);
}
try {
FileUtil.rename(tempJarFile, resultJarFile);
}
catch (Exception e) {
FileUtil.delete(resultJarFile);
throw e;
}
FileUtil.delete(tempJarFile);
}
}
catch (Throwable t) {
t.printStackTrace();
System.exit(1);
}
}