Skip to content

Commit

Permalink
refresh light-psi generator
Browse files Browse the repository at this point in the history
  • Loading branch information
gregsh committed Jun 3, 2016
1 parent 00b9c0c commit 790503e
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 14 deletions.
6 changes: 3 additions & 3 deletions .idea/runConfigurations/LightPsi_All__classes.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions .idea/runConfigurations/LightPsi_All__package.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 28 additions & 9 deletions support/org/intellij/grammar/LightPsi.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
import com.intellij.openapi.util.Getter;
import com.intellij.openapi.util.Trinity;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.vfs.encoding.EncodingManager;
import com.intellij.openapi.vfs.encoding.EncodingManagerImpl;
import com.intellij.psi.*;
Expand Down Expand Up @@ -87,6 +88,7 @@

/**
* @author greg
* @noinspection UseOfSystemOutOrSystemErr
*/
public class LightPsi {

Expand Down Expand Up @@ -125,23 +127,40 @@ public static void main(String[] args) throws Throwable {
}

File dir = new File(args[0]);
BufferedReader reader = new BufferedReader(new FileReader(new File(args[1])));
String s;
File file = new File(args[1]);
File out = new File(dir, "light-psi-all.jar");
int count = mainImpl(file, out);
System.out.println(StringUtil.formatFileSize(out.length()) +
" and " + count + " classes written to " +
out.getName());
}

private static int mainImpl(File classesFile, File outJarFile) throws Throwable {
BufferedReader reader = new BufferedReader(new FileReader(classesFile));
Pattern pattern = Pattern.compile("\\[Loaded (.*) from (?:file:)?(.*)\\]");

JarOutputStream jarFile = new JarOutputStream(new FileOutputStream(new File(dir, "light-psi-all.jar")));
// JarOutputStream jarFile = new JarOutputStream(new FileOutputStream(new File(dir, "light-psi-min.jar")));
addJarEntry(jarFile, "misc/registry.properties");
JarOutputStream jar = new JarOutputStream(new FileOutputStream(outJarFile));
int count = 0;
String s;
addJarEntry(jar, "misc/registry.properties");
while ((s = reader.readLine()) != null) {
Matcher matcher = pattern.matcher(s);
if (!matcher.matches()) continue;
String className = matcher.group(1);
String path = matcher.group(2);
if (!path.startsWith("/Applications")) continue;
// if (!path.contains("light-psi-all.jar")) continue;
addJarEntry(jarFile, className.replace(".", "/") + ".class");
if (!shouldAddEntry(path)) continue;
addJarEntry(jar, className.replace(".", "/") + ".class");
count ++;
}
jarFile.close();
jar.close();
return count;
}

private static boolean shouldAddEntry(String path) {
if (!path.startsWith("/")) return false;
if (path.startsWith("/Library")) return false;
if (path.contains("/cglib-")) return false;
return true;
}

private static void addJarEntry(JarOutputStream jarFile, String resourceName) throws IOException {
Expand Down

0 comments on commit 790503e

Please sign in to comment.