This commit is contained in:
Alexey Kudravtsev
2017-10-09 14:32:28 +03:00
parent c38e46db88
commit 650cd506d4
4 changed files with 38 additions and 43 deletions

View File

@@ -131,7 +131,7 @@ public class FTManager {
}
@NotNull
public FileTemplateBase addTemplate(String name, String extension) {
public FileTemplateBase addTemplate(@NotNull String name, @NotNull String extension) {
final String qName = FileTemplateBase.getQualifiedName(name, extension);
FileTemplateBase template = getTemplate(qName);
if (template == null) {
@@ -238,7 +238,7 @@ public class FTManager {
}
}
private void addTemplateFromFile(String fileName, File file) {
private void addTemplateFromFile(@NotNull String fileName, @NotNull File file) {
Pair<String,String> nameExt = decodeFileName(fileName);
final String extension = nameExt.second;
final String templateQName = nameExt.first;
@@ -365,7 +365,8 @@ public class FTManager {
return myName + " file template manager";
}
static String encodeFileName(String templateName, String extension) {
@NotNull
static String encodeFileName(@NotNull String templateName, @NotNull String extension) {
String nameExtDelimiter = extension.contains(".") ? ENCODED_NAME_EXT_DELIMITER : ".";
return templateName + nameExtDelimiter + extension;
}

View File

@@ -491,9 +491,7 @@ public class FileTemplateManagerImpl extends FileTemplateManager implements Pers
return text;
}
});
Disposer.register(parentDisposable, () -> {
templates.put(qName, oldTemplate);
});
Disposer.register(parentDisposable, () -> templates.put(qName, oldTemplate));
}
public static class State {

View File

@@ -21,11 +21,11 @@ import com.intellij.history.utils.LocalHistoryLog;
import com.intellij.ide.BrowserUtil;
import com.intellij.ide.actions.ShowFilePathAction;
import com.intellij.notification.Notification;
import com.intellij.notification.NotificationListener;
import com.intellij.notification.NotificationType;
import com.intellij.notification.Notifications;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.application.PathManager;
import com.intellij.openapi.util.Disposer;
import com.intellij.openapi.util.Pair;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.vfs.newvfs.ManagingFS;
@@ -50,7 +50,7 @@ public class ChangeListStorageImpl implements ChangeListStorage {
private LocalHistoryStorage myStorage;
private long myLastId;
private boolean isCompletelyBroken = false;
private boolean isCompletelyBroken;
public ChangeListStorageImpl(File storageDir) throws IOException {
myStorageDir = storageDir;
@@ -76,7 +76,7 @@ public class ChangeListStorageImpl implements ChangeListStorage {
"local history version mismatch (was: {0}, expected: {1}), rebuilding...", storedVersion, VERSION));
}
if (timestampMismatch) LocalHistoryLog.LOG.info("FS has been rebuild, rebuilding local history...");
result.dispose();
Disposer.dispose(result);
if (!FileUtil.delete(storageDir)) {
throw new IOException("cannot clear storage dir: " + storageDir);
}
@@ -109,11 +109,13 @@ public class ChangeListStorageImpl implements ChangeListStorage {
LocalHistoryLog.LOG.error("Local history is broken" +
"(version:" + VERSION +
",current timestamp:" + DateFormat.getDateTimeInstance().format(timestamp) +
",storage timestamp:" + DateFormat.getDateTimeInstance().format(storageTimestamp) +
",vfs timestamp:" + DateFormat.getDateTimeInstance().format(vfsTimestamp) + ")\n" + message, e);
", current timestamp: " + DateFormat.getDateTimeInstance().format(timestamp) +
", storage timestamp: " + DateFormat.getDateTimeInstance().format(storageTimestamp) +
", vfs timestamp: " + DateFormat.getDateTimeInstance().format(vfsTimestamp) +
", path: "+myStorageDir+
")\n" + message, e);
myStorage.dispose();
Disposer.dispose(myStorage);
try {
FileUtil.delete(myStorageDir);
initStorage(myStorageDir);
@@ -127,7 +129,7 @@ public class ChangeListStorageImpl implements ChangeListStorage {
}
public static void notifyUser(String message) {
private static void notifyUser(String message) {
final String logFile = PathManager.getLogPath();
/*String createIssuePart = "<br>" +
"<br>" +
@@ -137,31 +139,30 @@ public class ChangeListStorageImpl implements ChangeListStorage {
"Local History is broken",
message /*+ createIssuePart*/,
NotificationType.ERROR,
new NotificationListener() {
@Override
public void hyperlinkUpdate(@NotNull Notification notification,
@NotNull HyperlinkEvent event) {
if (event.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
if ("url".equals(event.getDescription())) {
BrowserUtil.browse("http://youtrack.jetbrains.net/issue/IDEA-71270");
}
else {
File file = new File(logFile);
ShowFilePathAction.openFile(file);
}
(notification, event) -> {
if (event.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
if ("url".equals(event.getDescription())) {
BrowserUtil.browse("http://youtrack.jetbrains.net/issue/IDEA-71270");
}
else {
File file = new File(logFile);
ShowFilePathAction.openFile(file);
}
}
}), null);
}
@Override
public synchronized void close() {
myStorage.dispose();
Disposer.dispose(myStorage);
}
@Override
public synchronized long nextId() {
return ++myLastId;
}
@Override
@Nullable
public synchronized ChangeSetHolder readPrevious(int id, TIntHashSet recursionGuard) {
if (isCompletelyBroken) return null;
@@ -200,26 +201,19 @@ public class ChangeListStorageImpl implements ChangeListStorage {
@NotNull
private ChangeSetHolder doReadBlock(int id) throws IOException {
DataInputStream in = myStorage.readStream(id);
try {
try (DataInputStream in = myStorage.readStream(id)) {
return new ChangeSetHolder(id, new ChangeSet(in));
}
finally {
in.close();
}
}
@Override
public synchronized void writeNextSet(ChangeSet changeSet) {
if (isCompletelyBroken) return;
try {
AbstractStorage.StorageDataOutput out = myStorage.writeStream(myStorage.createNextRecord(), true);
try {
try (AbstractStorage.StorageDataOutput out = myStorage.writeStream(myStorage.createNextRecord(), true)) {
changeSet.write(out);
}
finally {
out.close();
}
myStorage.setLastId(myLastId);
myStorage.force();
}
@@ -228,6 +222,7 @@ public class ChangeListStorageImpl implements ChangeListStorage {
}
}
@Override
public synchronized void purge(long period, int intervalBetweenActivities, Consumer<ChangeSet> processor) {
if (isCompletelyBroken) return;

View File

@@ -18,6 +18,8 @@ package com.intellij.openapi.vcs.contentAnnotation;
import com.intellij.openapi.components.*;
import com.intellij.openapi.project.Project;
import java.util.concurrent.TimeUnit;
/**
* @author Irina.Chernushina
* @since 3.08.2011
@@ -27,9 +29,8 @@ import com.intellij.openapi.project.Project;
storages = {@Storage(StoragePathMacros.WORKSPACE_FILE)}
)
public class VcsContentAnnotationSettings implements PersistentStateComponent<VcsContentAnnotationSettings.State> {
public static final long ourMillisecondsInDay = 24 * 60 * 60 * 1000L;
public static final int ourMaxDays = 31; // approx
public static final long ourAbsoluteLimit = ourMillisecondsInDay * ourMaxDays;
public static final long ourAbsoluteLimit = TimeUnit.DAYS.toMillis(ourMaxDays);
private State myState = new State();
{
@@ -41,7 +42,7 @@ public class VcsContentAnnotationSettings implements PersistentStateComponent<Vc
}
public static class State {
public boolean myShow1 = false;
public boolean myShow1;
public long myLimit;
}
@@ -60,11 +61,11 @@ public class VcsContentAnnotationSettings implements PersistentStateComponent<Vc
}
public int getLimitDays() {
return (int) (myState.myLimit / ourMillisecondsInDay);
return (int)TimeUnit.MILLISECONDS.toDays(myState.myLimit);
}
public void setLimit(int limit) {
myState.myLimit = ourMillisecondsInDay * limit;
public void setLimit(int days) {
myState.myLimit = TimeUnit.DAYS.toMillis(days);
}
public boolean isShow() {