Skip to content

Commit

Permalink
fixed IDEA class version detection in IDEA SDK: don't require write a…
Browse files Browse the repository at this point in the history
…ccess to openapi.jar
  • Loading branch information
chashnikov committed Jul 13, 2015
1 parent 5393475 commit 4b263a0
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions plugins/devkit/src/projectRoots/IdeaJdk.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@
import com.intellij.psi.PsiManager;
import com.intellij.psi.impl.compiled.ClsParsingUtil;
import com.intellij.util.ArrayUtil;
import com.intellij.util.io.zip.JBZipEntry;
import com.intellij.util.io.zip.JBZipFile;
import icons.DevkitIcons;
import org.jdom.Element;
import org.jetbrains.annotations.NonNls;
Expand All @@ -45,12 +43,15 @@
import org.jetbrains.idea.devkit.DevKitBundle;

import javax.swing.*;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileFilter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;

/**
* @author anna
Expand Down Expand Up @@ -283,21 +284,28 @@ private static JavaSdkVersion getRequiredJdkVersion(Sdk ideaSdk) {

private static int getIdeaClassFileVersion(File apiJar) {
try {
JBZipFile zipFile = new JBZipFile(apiJar);
ZipFile zipFile = new ZipFile(apiJar);
try {
JBZipEntry entry = zipFile.getEntry(PsiManager.class.getName().replace('.', '/') + ".class");
ZipEntry entry = zipFile.getEntry(PsiManager.class.getName().replace('.', '/') + ".class");
if (entry != null) {
byte[] bytes = entry.getData();
if (bytes != null && bytes.length > 8) {
return ((int)bytes[6] << 8) + (int)bytes[7];
DataInputStream stream = new DataInputStream(zipFile.getInputStream(entry));
try {
if (stream.skip(6) == 6) {
return stream.readUnsignedShort();
}
}
finally {
stream.close();
}
}
}
finally {
zipFile.close();
}
}
catch (IOException ignored) { }
catch (IOException e) {
LOG.info(e);
}

return -1;
}
Expand Down

0 comments on commit 4b263a0

Please sign in to comment.