@SuppressWarnings("HardCodedStringLiteral")
  @NotNull
  public List<File> getClassPath() {
    if (myPath.isDirectory()) {
      final List<File> result = new ArrayList<File>();
      final File classesDir = new File(myPath, "classes");

      if (classesDir.exists()) {
        result.add(classesDir);
      }

      final File[] files = new File(myPath, "lib").listFiles();
      if (files != null && files.length > 0) {
        for (final File f : files) {
          if (f.isFile()) {
            final String name = f.getName();
            if (StringUtil.endsWithIgnoreCase(name, ".jar")
                || StringUtil.endsWithIgnoreCase(name, ".zip")) {
              result.add(f);
            }
          } else {
            result.add(f);
          }
        }
      }

      return result;
    } else {
      return Collections.singletonList(myPath);
    }
  }
 @SuppressWarnings({"HardCodedStringLiteral"})
 public static boolean isJarOrZip(File file) {
   if (file.isDirectory()) {
     return false;
   }
   final String name = file.getName();
   return StringUtil.endsWithIgnoreCase(name, ".jar")
       || StringUtil.endsWithIgnoreCase(name, ".zip");
 }
Пример #3
0
  private static String getPresentableName(final Project project) {
    if (project.isDefault()) {
      return project.getName();
    }

    String location = project.getLocation();
    if (location == null) return null;
    String projectName = FileUtil.toSystemIndependentName(location);
    if (projectName.endsWith("/")) {
      projectName = projectName.substring(0, projectName.length() - 1);
    }

    final int lastSlash = projectName.lastIndexOf('/');
    if (lastSlash >= 0 && lastSlash + 1 < projectName.length()) {
      projectName = projectName.substring(lastSlash + 1);
    }

    if (StringUtil.endsWithIgnoreCase(projectName, ProjectFileType.DOT_DEFAULT_EXTENSION)) {
      projectName =
          projectName.substring(
              0, projectName.length() - ProjectFileType.DOT_DEFAULT_EXTENSION.length());
    }

    projectName = projectName.toLowerCase(Locale.US);
    return projectName;
  }
  @SuppressWarnings({"HardCodedStringLiteral"})
  @Nullable
  public static IdeaPluginDescriptorImpl loadDescriptor(
      final File file, @NonNls final String fileName) {
    IdeaPluginDescriptorImpl descriptor = null;

    if (file.isDirectory()) {
      descriptor = loadDescriptorFromDir(file, fileName);

      if (descriptor == null) {
        File libDir = new File(file, "lib");
        if (!libDir.isDirectory()) {
          return null;
        }
        final File[] files = libDir.listFiles();
        if (files == null || files.length == 0) {
          return null;
        }
        Arrays.sort(
            files,
            new Comparator<File>() {
              @Override
              public int compare(File o1, File o2) {
                if (o2.getName().startsWith(file.getName())) return Integer.MAX_VALUE;
                if (o1.getName().startsWith(file.getName())) return -Integer.MAX_VALUE;
                if (o2.getName().startsWith("resources")) return -Integer.MAX_VALUE;
                if (o1.getName().startsWith("resources")) return Integer.MAX_VALUE;
                return 0;
              }
            });
        for (final File f : files) {
          if (FileUtil.isJarOrZip(f)) {
            descriptor = loadDescriptorFromJar(f, fileName);
            if (descriptor != null) {
              descriptor.setPath(file);
              break;
            }
            //           getLogger().warn("Cannot load descriptor from " + f.getName() + "");
          } else if (f.isDirectory()) {
            IdeaPluginDescriptorImpl descriptor1 = loadDescriptorFromDir(f, fileName);
            if (descriptor1 != null) {
              if (descriptor != null) {
                getLogger()
                    .info("Cannot load " + file + " because two or more plugin.xml's detected");
                return null;
              }
              descriptor = descriptor1;
              descriptor.setPath(file);
            }
          }
        }
      }
    } else if (StringUtil.endsWithIgnoreCase(file.getName(), ".jar") && file.exists()) {
      descriptor = loadDescriptorFromJar(file, fileName);
    }

    if (descriptor != null && !descriptor.getOptionalConfigs().isEmpty()) {
      final Map<PluginId, IdeaPluginDescriptorImpl> descriptors =
          new HashMap<PluginId, IdeaPluginDescriptorImpl>(descriptor.getOptionalConfigs().size());
      for (Map.Entry<PluginId, String> entry : descriptor.getOptionalConfigs().entrySet()) {
        String optionalDescriptorName = entry.getValue();
        assert !Comparing.equal(fileName, optionalDescriptorName)
            : "recursive dependency: " + fileName;

        IdeaPluginDescriptorImpl optionalDescriptor = loadDescriptor(file, optionalDescriptorName);
        if (optionalDescriptor == null && !FileUtil.isJarOrZip(file)) {
          for (URL url : getClassLoaderUrls()) {
            if ("file".equals(url.getProtocol())) {
              optionalDescriptor =
                  loadDescriptor(new File(decodeUrl(url.getFile())), optionalDescriptorName);
              if (optionalDescriptor != null) {
                break;
              }
            }
          }
        }
        if (optionalDescriptor != null) {
          descriptors.put(entry.getKey(), optionalDescriptor);
        } else {
          getLogger().info("Cannot find optional descriptor " + optionalDescriptorName);
        }
      }
      descriptor.setOptionalDescriptors(descriptors);
    }
    return descriptor;
  }
 @Contract("null -> false")
 private static boolean isPngFile(@Nullable VirtualFile file) {
   return file != null
       && SdkConstants.EXT_PNG.equalsIgnoreCase(file.getExtension())
       && !StringUtil.endsWithIgnoreCase(file.getName(), SdkConstants.DOT_9PNG);
 }
Пример #6
0
 public static boolean isArchiveName(String name) {
   return name.length() >= 4
       && name.charAt(name.length() - 4) == '.'
       && StringUtil.endsWithIgnoreCase(name, "ar");
 }
 public boolean accept(File file) {
   return StringUtil.endsWithIgnoreCase(file.getPath(), JAVA_EXTENSION);
 }