cleanup: don't use File.list to find child file by name
authornik <Nikolay.Chashnikov@jetbrains.com>
Thu, 25 Jun 2015 09:06:22 +0000 (12:06 +0300)
committernik <Nikolay.Chashnikov@jetbrains.com>
Thu, 25 Jun 2015 09:06:22 +0000 (12:06 +0300)
plugins/gradle/src/org/jetbrains/plugins/gradle/service/project/GradleStartupActivity.java
plugins/maven/maven-server-api/src/org/jetbrains/idea/maven/server/MavenServerUtil.java
plugins/maven/src/main/java/org/jetbrains/idea/maven/project/MavenProjectsManager.java

index a45318c5b3f4cc14dbf2765caf4676e360d13881..a72045c694429f2409741aba019d4220cb63ef69 100644 (file)
@@ -31,11 +31,9 @@ import com.intellij.openapi.externalSystem.model.ExternalSystemDataKeys;
 import com.intellij.openapi.externalSystem.service.project.manage.ProjectDataManager;
 import com.intellij.openapi.project.Project;
 import com.intellij.openapi.startup.StartupActivity;
-import com.intellij.openapi.util.io.FileUtil;
 import com.intellij.openapi.vfs.VfsUtilCore;
 import org.jetbrains.annotations.NonNls;
 import org.jetbrains.annotations.NotNull;
-import org.jetbrains.idea.maven.project.MavenResourceCompilerConfigurationGenerator;
 import org.jetbrains.plugins.gradle.config.GradleResourceCompilerConfigurationGenerator;
 import org.jetbrains.plugins.gradle.service.GradleBuildClasspathManager;
 import org.jetbrains.plugins.gradle.service.project.wizard.GradleProjectImportBuilder;
@@ -46,7 +44,6 @@ import org.jetbrains.plugins.gradle.util.GradleConstants;
 
 import javax.swing.event.HyperlinkEvent;
 import java.io.File;
-import java.io.FilenameFilter;
 
 /**
  * @author Vladislav.Soroka
@@ -92,14 +89,8 @@ public class GradleStartupActivity implements StartupActivity {
     }
 
     File baseDir = VfsUtilCore.virtualToIoFile(project.getBaseDir());
-    final File[] files = baseDir.listFiles(new FilenameFilter() {
-      @Override
-      public boolean accept(File dir, String name) {
-        return FileUtil.namesEqual(GradleConstants.DEFAULT_SCRIPT_NAME, name);
-      }
-    });
-
-    if (files != null && files.length != 0) {
+    final File gradleFile = new File(baseDir, GradleConstants.DEFAULT_SCRIPT_NAME);
+    if (gradleFile.exists()) {
       String message = String.format("%s<br>\n%s",
                                      GradleBundle.message("gradle.notifications.unlinked.project.found.msg", IMPORT_EVENT_DESCRIPTION),
                                      GradleBundle.message("gradle.notifications.do.not.show"));
@@ -114,7 +105,7 @@ public class GradleStartupActivity implements StartupActivity {
               final ProjectDataManager projectDataManager = ServiceManager.getService(ProjectDataManager.class);
               GradleProjectImportBuilder gradleProjectImportBuilder = new GradleProjectImportBuilder(projectDataManager);
               final GradleProjectImportProvider gradleProjectImportProvider = new GradleProjectImportProvider(gradleProjectImportBuilder);
-              AddModuleWizard wizard = new AddModuleWizard(null, files[0].getPath(), gradleProjectImportProvider);
+              AddModuleWizard wizard = new AddModuleWizard(null, gradleFile.getPath(), gradleProjectImportProvider);
               if ((wizard.getStepCount() <= 0 || wizard.showAndGet())) {
                 ImportModuleAction.createFromWizard(project, wizard);
               }
index cb199abba069d0febdac3eb9eccb12884b97cd94..882943a59940b54266638bf2107e4cff23b0d93b 100644 (file)
@@ -19,9 +19,10 @@ import com.intellij.openapi.util.SystemInfo;
 import org.jetbrains.annotations.NotNull;
 
 import java.io.File;
-import java.io.FilenameFilter;
 import java.io.IOException;
-import java.util.*;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Properties;
 
 public class MavenServerUtil {
   private static final Properties mySystemPropertiesCache;
@@ -61,12 +62,7 @@ public class MavenServerUtil {
     File baseDir = workingDir;
     File dir = workingDir;
     while ((dir = dir.getParentFile()) != null) {
-      if (dir.listFiles(new FilenameFilter() {
-        @Override
-        public boolean accept(File dir, String name) {
-          return ".mvn".equals(name);
-        }
-      }).length > 0) {
+      if (new File(dir, ".mvn").exists()) {
         baseDir = dir;
         break;
       }
index 2d856c622da0db2da435a5b2199eb11c1a3aacec..45fef9a8e1fb7008af50dd3354277a6c1345a485 100644 (file)
@@ -64,7 +64,6 @@ import org.jetbrains.idea.maven.utils.*;
 
 import javax.swing.event.HyperlinkEvent;
 import java.io.File;
-import java.io.FilenameFilter;
 import java.io.IOException;
 import java.util.*;
 import java.util.concurrent.atomic.AtomicBoolean;
@@ -203,15 +202,10 @@ public class MavenProjectsManager extends MavenSimpleProjectComponent
     }
 
     File baseDir = VfsUtilCore.virtualToIoFile(project.getBaseDir());
-    final File[] files = baseDir.listFiles(new FilenameFilter() {
-      @Override
-      public boolean accept(File dir, String name) {
-        return FileUtil.namesEqual("pom.xml", name);
-      }
-    });
+    File pomXml = new File(baseDir, "pom.xml");
 
-    if (files != null && files.length != 0) {
-      final VirtualFile file = VfsUtil.findFileByIoFile(files[0], true);
+    if (pomXml.exists()) {
+      final VirtualFile file = VfsUtil.findFileByIoFile(pomXml, true);
       if (file == null) return;
 
       showBalloon(