diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/dom/converters/MavenArtifactCoordinatesConverter.java b/plugins/maven/src/main/java/org/jetbrains/idea/maven/dom/converters/MavenArtifactCoordinatesConverter.java index 9e39a34c52db..4c6f27aca790 100644 --- a/plugins/maven/src/main/java/org/jetbrains/idea/maven/dom/converters/MavenArtifactCoordinatesConverter.java +++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/dom/converters/MavenArtifactCoordinatesConverter.java @@ -82,7 +82,7 @@ public abstract class MavenArtifactCoordinatesConverter extends ResolvingConvert return result != null ? result : super.resolve(o, context); } - private Project getProject(ConvertContext context) { + private static Project getProject(ConvertContext context) { return context.getFile().getProject(); } @@ -126,7 +126,7 @@ public abstract class MavenArtifactCoordinatesConverter extends ResolvingConvert return new ConverterStrategy(); } - private class MyUpdateIndicesFix implements LocalQuickFix { + private static class MyUpdateIndicesFix implements LocalQuickFix { @NotNull public String getFamilyName() { return MavenDomBundle.message("inspection.group"); diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/indices/MavenIndex.java b/plugins/maven/src/main/java/org/jetbrains/idea/maven/indices/MavenIndex.java index 4c7ffc6b531d..06365744fb9e 100644 --- a/plugins/maven/src/main/java/org/jetbrains/idea/maven/indices/MavenIndex.java +++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/indices/MavenIndex.java @@ -15,13 +15,12 @@ */ package org.jetbrains.idea.maven.indices; -import com.intellij.openapi.util.Condition; import com.intellij.openapi.util.io.FileUtil; -import com.intellij.util.containers.ContainerUtil; import com.intellij.util.io.*; import gnu.trove.THashMap; import gnu.trove.THashSet; import org.apache.lucene.search.Query; +import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.TestOnly; import org.jetbrains.idea.maven.model.MavenArtifactInfo; import org.jetbrains.idea.maven.model.MavenId; @@ -128,7 +127,7 @@ public class MavenIndex { String timestamp = props.getProperty(TIMESTAMP_KEY); if (timestamp != null) myUpdateTimestamp = Long.parseLong(timestamp); } - catch (Exception e) { + catch (Exception ignored) { } myDataDirName = props.getProperty(DATA_DIR_NAME_KEY); @@ -347,9 +346,14 @@ public class MavenIndex { myUpdateTimestamp = System.currentTimeMillis(); oldData.close(true); - for (File each : getAllDataDirs()) { - if (each.getName().equals(newDataDirName)) continue; - FileUtil.delete(each); + + File[] children = myDir.listFiles(); + if (children != null) { + for (File each : children) { + if (each.getName().startsWith(DATA_DIR_PREFIX) && !each.getName().equals(newDataDirName)) { + FileUtil.delete(each); + } + } } } } @@ -416,13 +420,13 @@ public class MavenIndex { return result; } - private void persist(Map map, PersistentHashMap persistentMap) throws IOException { + private static void persist(Map map, PersistentHashMap persistentMap) throws IOException { for (Map.Entry each : map.entrySet()) { persistentMap.put(each.getKey(), each.getValue()); } } - private void persist(Set groups, PersistentStringEnumerator persistent) throws IOException { + private static void persist(Set groups, PersistentStringEnumerator persistent) throws IOException { for (String each : groups) { persistent.enumerate(each); } @@ -448,7 +452,7 @@ public class MavenIndex { return new File(myDir, dataDirName); } - private File getDataContextDir(File dataDir) { + private static File getDataContextDir(File dataDir) { return new File(dataDir, "context"); } @@ -456,16 +460,6 @@ public class MavenIndex { return MavenIndices.findAvailableDir(myDir, DATA_DIR_PREFIX, 100).getName(); } - private Iterable getAllDataDirs() { - File[] children = myDir.listFiles(); - if (children == null) return ContainerUtil.emptyIterable(); - return ContainerUtil.iterate(children, new Condition() { - public boolean value(File file) { - return file.getName().startsWith(DATA_DIR_PREFIX); - } - }); - } - public synchronized void addArtifact(final File artifactFile) { doIndexTask(new IndexTask() { public Object doTask() throws Exception { @@ -496,7 +490,7 @@ public class MavenIndex { }, null); } - private void addToCache(PersistentHashMap> cache, String key, String value) throws IOException { + private static void addToCache(PersistentHashMap> cache, String key, String value) throws IOException { Set values = cache.get(key); if (values == null) values = new THashSet(); values.add(value); @@ -673,7 +667,7 @@ public class MavenIndex { if (exceptions[0] != null) throw exceptions[0]; } - private void safeClose(Closeable enumerator, MavenIndexException[] exceptions) { + private void safeClose(@Nullable Closeable enumerator, MavenIndexException[] exceptions) { try { if (enumerator != null) enumerator.close(); } diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/indices/MavenIndices.java b/plugins/maven/src/main/java/org/jetbrains/idea/maven/indices/MavenIndices.java index acf3cf8ad7af..68554ed62af5 100644 --- a/plugins/maven/src/main/java/org/jetbrains/idea/maven/indices/MavenIndices.java +++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/indices/MavenIndices.java @@ -16,6 +16,7 @@ package org.jetbrains.idea.maven.indices; import com.intellij.openapi.util.io.FileUtil; +import org.jetbrains.annotations.Nullable; import org.jetbrains.idea.maven.project.MavenGeneralSettings; import org.jetbrains.idea.maven.server.MavenIndexerWrapper; import org.jetbrains.idea.maven.utils.MavenLog; @@ -45,8 +46,6 @@ public class MavenIndices { } private void load() { - if (!myIndicesDir.exists()) return; - File[] indices = myIndicesDir.listFiles(); if (indices == null) return; Arrays.sort(indices); @@ -90,6 +89,7 @@ public class MavenIndices { return index; } + @Nullable public MavenIndex find(String repositoryId, String repositoryPathOrUrl, MavenIndex.Kind kind) { for (MavenIndex each : myIndices) { if (each.isFor(kind, repositoryId, repositoryPathOrUrl)) return each; @@ -116,7 +116,7 @@ public class MavenIndices { } } - public void updateOrRepair(MavenIndex index, boolean fullUpdate, MavenGeneralSettings settings, MavenProgressIndicator progress) + public static void updateOrRepair(MavenIndex index, boolean fullUpdate, MavenGeneralSettings settings, MavenProgressIndicator progress) throws MavenProcessCanceledException { index.updateOrRepair(fullUpdate, settings, progress); }