Dumping out the local history file

Okay, I got a bit further with this. I was able to compile the community edition, and move the jars into another application of my own and include the jars.

Then, I'm able to instantiate LocalHistoryStorage, and that works:

String path = "full path to local history file, including name - prefix";

LocalHistoryStorage lhs = new LocalHistoryStorage(path);

Getting all of the records and looping over them, getting lists of Change objects like so:

DataInputStream is = null;
         int record = lhs.getFirstRecord();

         while (record > 0) {

            System.out.println("--- Record # " + record);
            try {

               is = lhs.readStream(record);
               ChangeSet cd = new ChangeSet(is);

               //System.out.println("Change set: " + cd.toString());
               long timeStamp = cd.getTimestamp();
               Date dt = new Date(timeStamp);
               SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy hh:mm:ss");
               String date = sdf.format(dt);
               System.out.println(" Date: " + date);
               List<Change> changes = cd.getChanges();


               for (int i=0;i<changes.size();i++){
                  Change change = changes.get(i);
                  System.out.println("  Change: " + change.toString());
                  if (change instanceof ContentChange) {
                     ContentChange cc = (ContentChange)change;
                     Content content = cc.getOldContent();
                     //System.out.println("Content: " + content.toString());
                  }

               }

               is.close();

            }
            catch (Exception e) {
               e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
            }


               record = lhs.getNextRecord(record);
            }


         }
         catch (Exception e){

         }




And this works but now I want to get the content of instances of ContentChange. However, I get an exception thrown when I uncomment this line:


System.out.println("Content: " + content.toString());



Exception in thread "main" java.lang.ExceptionInInitializerError
    at com.intellij.openapi.vfs.newvfs.ManagingFS.getInstance(ManagingFS.java:38)
    at com.intellij.history.core.StoredContent.getFS(StoredContent.java:89)
    at com.intellij.history.core.StoredContent.getBytes(StoredContent.java:75)
    at com.intellij.history.core.Content.toString(Content.java:45)
    at com.intellij.util.io.storage.LocalHistoryDump.main(LocalHistoryDump.java:62)
Caused by: java.lang.NullPointerException
    at com.intellij.openapi.vfs.newvfs.ManagingFS$ManagingFSHolder.<clinit>(ManagingFS.java:34)
    ... 5 more


It seems this is because I'm not setting up ApplicationManager. Is there a way to init this, or at least stub it out enough to get this to work? I've tried using ApplicationManagerEx, but I'm not sure I'm using it correctly, as it doesn't seem to make a difference.

3 comments
Comment actions Permalink

Hello Sean,

The local history code is not designed to work outside of a fully initialized
IntelliJ IDEA environment. Your best option is not to use any of our code
but rather to write your own code to read the data.

Okay, I got a bit further with this. I was able to compile the
community edition, and move the jars into another application of my
own and include the jars.

Then, I'm able to instantiate LocalHistoryStorage, and that works:

String path = "full path to local history file, including name -
prefix";

LocalHistoryStorage lhs = new LocalHistoryStorage(path);

Getting all of the records and looping over them, getting lists of
Change objects like so:

DataInputStream is = null;
int record = lhs.getFirstRecord();
while (record > 0) {

System.out.println("--- Record # " + record);
try {
is = lhs.readStream(record);
ChangeSet cd = new ChangeSet(is);
//System.out.println("Change set: " + cd.toString());
long timeStamp = cd.getTimestamp();
Date dt = new Date(timeStamp);
SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy
hh:mm:ss");
String date = sdf.format(dt);
System.out.println(" Date: " + date);
List<Change> changes = cd.getChanges();
for (int i=0;i<changes.size();i++){
Change change = changes.get(i);
System.out.println("  Change: " +
change.toString());
if (change instanceof ContentChange) {
ContentChange cc = (ContentChange)change;
Content content = cc.getOldContent();
//System.out.println("Content: " +
content.toString());
}
}

is.close();

}
catch (Exception e) {
e.printStackTrace();  //To change body of catch
statement use File | Settings | File Templates.
}
record = lhs.getNextRecord(record);
}
}
catch (Exception e){
}

And this works but now I want to get the content of instances of
ContentChange. However, I get an exception thrown when I uncomment
this line:

System.out.println("Content: " + content.toString());

Exception in thread "main" java.lang.ExceptionInInitializerError
at
com.intellij.openapi.vfs.newvfs.ManagingFS.getInstance(ManagingFS.java
:38)
at
com.intellij.history.core.StoredContent.getFS(StoredContent.java:89)
at
com.intellij.history.core.StoredContent.getBytes(StoredContent.java:75
)
at com.intellij.history.core.Content.toString(Content.java:45)
at
com.intellij.util.io.storage.LocalHistoryDump.main(LocalHistoryDump.ja
va:62)
Caused by: java.lang.NullPointerException
at
com.intellij.openapi.vfs.newvfs.ManagingFS$ManagingFSHolder.<clinit>(M
anagingFS.java:34)
... 5 more
It seems this is because I'm not setting up ApplicationManager. Is
there a way to init this, or at least stub it out enough to get this
to work? I've tried using ApplicationManagerEx, but I'm not sure I'm
using it correctly, as it doesn't seem to make a difference.

---
Original message URL:
http://devnet.jetbrains.net/message/5297907#5297907


--
Dmitry Jemerov
Development Lead
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"


0
Comment actions Permalink

Thanks. Any chance I could rely on *some* of the existing classes?

I was trying something like this to get the address and size of the record in the data file, but I'm unsure of what the data format would have. Beyond reading the code, are there any guides I should go by?


LocalHistoryStorage lhs = new LocalHistoryStorage(path);
         DataTable myDataTable = new DataTable(new File(path + AbstractStorage.DATA_EXTENSION), PagePool.SHARED);


         AbstractRecordsTable myRecordsTable = new LocalHistoryRecordsTable(new File(path + AbstractStorage.INDEX_EXTENSION), PagePool.SHARED);
         final int count = myRecordsTable.getRecordsCount();
         for (int setNumber = 1; setNumber <= count; setNumber++) {

            try {
               DataInputStream is = lhs.readStream(setNumber);
               ChangeSet cd = new ChangeSet(is);


               String aboutChangeSet = cd.toString();

               if (aboutChangeSet.indexOf("sestus")>0) {
                  List<Change> changes = cd.getChanges();


                  for (Change change : changes) {
                     if (change instanceof ContentChange) {
                        // Read in change's id:
                        ByteArrayOutputStream baos = new ByteArrayOutputStream(8);

                        change.write(new DataOutputStream(baos));

                        DataInputStream inTemp = new DataInputStream(new ByteArrayInputStream(baos.toByteArray()));
                        //DataInputStream dis = new DataInputStream(new ByteArrayInputStream(byte []));
                        //int myId = 0;
                      int myId = (int)inTemp.readLong();



                        final long addr = myRecordsTable.getAddress(setNumber);
                        final int size = myRecordsTable.getSize(setNumber);

                        if (size > 0) {
                           assert addr > 0;

                           final byte[] bytes = new byte[size];

                           myDataTable.readBytes(addr, bytes);
                           DataInputStream in = new DataInputStream(new ByteArrayInputStream(bytes));

0
Comment actions Permalink

In Idea 14 it is possible to retrieve history dump with the following code:

try {
    ChangeList changeList =
            new ChangeList(new ChangeListStorageImpl(LocalHistoryImpl.getInstanceImpl().getStorageDir()));
    for (ChangeSet changeSet : changeList.iterChanges()) {
        LOG.warn("Change set: " + changeSet.toString());
        long timeStamp = changeSet.getTimestamp();
        Date dt = new Date(timeStamp);
        SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy hh:mm:ss");
        String date = sdf.format(dt);
        LOG.warn("Date: " + date);
        List<Change> changes = changeSet.getChanges();
        LOG.warn("Total changes: " + changes.size());

        for (Change change : changes) {
            String changeLabel = change.toString();
            if (!changeLabel.endsWith("java")) {
                continue;
            }
            LOG.info("  Change: " + changeLabel);
            if (change instanceof ContentChange) {
                ContentChange cc = (ContentChange) change;
                Content content = cc.getOldContent();
                LOG.info("   Content: " + content.toString());
            }
        }
    }
} catch (IOException e) {
    e.printStackTrace();
}

0

Please sign in to leave a comment.