mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
copyright: insert copyrights for new files created in IDEA only (IDEA-105188)
This commit is contained in:
@@ -16,7 +16,6 @@
|
||||
|
||||
package com.maddyhome.idea.copyright;
|
||||
|
||||
import com.intellij.openapi.Disposable;
|
||||
import com.intellij.openapi.application.Application;
|
||||
import com.intellij.openapi.application.ModalityState;
|
||||
import com.intellij.openapi.components.*;
|
||||
@@ -76,6 +75,8 @@ public class CopyrightManager extends AbstractProjectComponent implements JDOMEx
|
||||
@NotNull StartupManager startupManager) {
|
||||
super(project);
|
||||
if (!myProject.isDefault()) {
|
||||
final NewFileTracker newFileTracker = NewFileTracker.getInstance();
|
||||
Disposer.register(myProject, newFileTracker);
|
||||
startupManager.runWhenProjectIsInitialized(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
@@ -85,7 +86,7 @@ public class CopyrightManager extends AbstractProjectComponent implements JDOMEx
|
||||
final Document document = e.getDocument();
|
||||
final VirtualFile virtualFile = fileDocumentManager.getFile(document);
|
||||
if (virtualFile == null) return;
|
||||
if (!NewFileTracker.getInstance().poll(virtualFile)) return;
|
||||
if (!newFileTracker.poll(virtualFile)) return;
|
||||
if (!fileTypeUtil.isSupportedFile(virtualFile)) return;
|
||||
final Module module = projectRootManager.getFileIndex().getModuleForFile(virtualFile);
|
||||
if (module == null) return;
|
||||
@@ -109,16 +110,6 @@ public class CopyrightManager extends AbstractProjectComponent implements JDOMEx
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// make sure there is no huge pile of new files in tests
|
||||
if (application.isUnitTestMode()) {
|
||||
Disposer.register(myProject, new Disposable() {
|
||||
@Override
|
||||
public void dispose() {
|
||||
NewFileTracker.getInstance().clear();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@NonNls
|
||||
|
||||
@@ -16,18 +16,15 @@
|
||||
|
||||
package com.maddyhome.idea.copyright.util;
|
||||
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.openapi.vfs.VirtualFileAdapter;
|
||||
import com.intellij.openapi.vfs.VirtualFileEvent;
|
||||
import com.intellij.openapi.vfs.VirtualFileManager;
|
||||
import com.intellij.openapi.Disposable;
|
||||
import com.intellij.openapi.vfs.*;
|
||||
import gnu.trove.THashSet;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.TestOnly;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
|
||||
public class NewFileTracker {
|
||||
public class NewFileTracker implements Disposable{
|
||||
public static NewFileTracker getInstance() {
|
||||
return instance;
|
||||
}
|
||||
@@ -37,19 +34,21 @@ public class NewFileTracker {
|
||||
}
|
||||
|
||||
private NewFileTracker() {
|
||||
VirtualFileManager.getInstance().addVirtualFileListener(new VirtualFileAdapter() {
|
||||
final VirtualFileManager virtualFileManager = VirtualFileManager.getInstance();
|
||||
virtualFileManager.addVirtualFileListener(new VirtualFileAdapter() {
|
||||
@Override
|
||||
public void fileCreated(VirtualFileEvent event) {
|
||||
if (event.isFromRefresh()) return;
|
||||
newFiles.add(event.getFile());
|
||||
}
|
||||
});
|
||||
}, this);
|
||||
}
|
||||
|
||||
private final Set<VirtualFile> newFiles = Collections.synchronizedSet(new THashSet<VirtualFile>());
|
||||
private static final NewFileTracker instance = new NewFileTracker();
|
||||
|
||||
@TestOnly
|
||||
public void clear() {
|
||||
@Override
|
||||
public void dispose() {
|
||||
newFiles.clear();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user