How to know what sources have been changed since last compilation?
I tried to use PsiModificationManager but it hasn't any useful methods. I do want to find a way to determine what files have been changed since last compilation. Is it possible?
Please sign in to leave a comment.
Hello kb,
There is no API to do this directly (and PsiModificationManager actually
has nothing to do with compilation). What exactly do you want to achieve?
--
Dmitry Jemerov
Software Developer
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"
I'm sorry, but where PsiModificationManager can be found? I can't find it standart open api & idea.jar classes
Hello Andremoniy,
As stated in the thread, PsiModificationManager has nothing to do with the
original poster's question. So you don't need this class at all.
--
Dmitry Jemerov
Development Lead
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"
Hello, Dmitrij!
I need PsiModificationManager for antoher puproces... to know what files were changed
Hello Andremoniy,
What files were changed when? Why do you think that PsiModificationManager
would help you?
--
Dmitry Jemerov
Development Lead
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"
I'm sorry, Dmitriy! My quesiton is: I'd like to get at any moment (when user call my plugin's action) a list of changed files. I implement it using VirtualFileListener, but it works strange... only after saving project, IDEA calls contentsChanged() event of this listner...
Hello Andremoniy,
A list of files changed since what moment?
VirtualFileListener.contentsChanged() will not be called if the user made
some changes in an editor document but they weren't yet saved to disk.
--
Dmitry Jemerov
Development Lead
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"
Hello, Dimitriy :)
How can I get revision of older version of some file, before it was changed? I.e. I need it for understaning - what places in file were changed (IDEA highlights it in left border in editor). Can you help me?
Another, may be related, question is: how correctly I can backup some psiFile, that changes, while I'm operating with structure related to it (for example, I'm adding some new object to some list and they placed in this FILE physically, but I don't want to save this changes at all)...
Thank you very much.
Hello Andremoniy,
ChangeListManager.getInstance(project).getChange(VirtualFile).getBeforeRevision().getContent()
You can create a non-physical copy of a PsiFile using PsiElement.copy() and
perform operations on elements inside that copy.
--
Dmitry Jemerov
Development Lead
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"
Hi, Dmitriy!
Thank you for your reply.
May be I'm wrong, but I found, that, when I do copy of PsiFile (PsiElement.copy()), which references to "struts-config.xml", then ReferencesSearch.search(xmlElement).findAll()) - doesn't find anything. (xmlElement - it is action.getXmlElement(), where action - is member of ActionMappings list, got from StrutsConfig object...). But, if I use real psiFile of "struts-config.xml" (not copy!) - it works well.
Hello Andremoniy,
This is true. Because all of the references in the project resolve to the
real PsiFile and not to the non-physical copy you have created, you won't
find any usages of elements in the copied file.
--
Dmitry Jemerov
Development Lead
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"
Ok. Thank you. And what will you advice me for solving this problem?
I add to ActionMapping new Action, using method "addAction" and place in the new Action needed parameters. This is done to solve problem with template-based actions, such "type=com.company.Action". So, this changes influence to real struts-config file. But in this case I can find references to my new action.
I have tried to restore backuped PsiFile, but it leeds to NullPointerException :(
I found solution.
CommandProcessor.getInstance().executeCommand(project, new Runnable() {
public void run() {
ApplicationManager.getApplication().runWriteAction(new Runnable() {
public void run() {
try {
strtusConfigPsiFileRealFile.getVirtualFile().delete(null);
} catch (Exception e1) {
// nothing to do
}
}
});
ApplicationManager.getApplication().runWriteAction(new Runnable() {
public void run() {
try {
PsiDirectory directory = new PsiDirectoryImpl((PsiManagerImpl) psiManager, project.getBaseDir());
PsiDirectory webInfDirectory = directory.findSubdirectory("WEB-INF");
webInfDirectory.add(strtusConfigPsiFileCopy);
} catch (Exception e1) {
// nothing to do
}
}
});
}
}, "restoring struts-config", "restoring struts-config");