示例#1
0
  @Nullable
  public static String getAnnotationProcessorsGenerationPath(Module module) {
    final CompilerConfiguration config = CompilerConfiguration.getInstance(module.getProject());

    final String sourceDirName = config.getGeneratedSourceDirName(module);
    if (sourceDirName != null && sourceDirName.length() > 0) {
      final String[] roots = ModuleRootManager.getInstance(module).getContentRootUrls();
      if (roots.length == 0) {
        return null;
      }
      if (roots.length > 1) {
        Arrays.sort(roots, URLS_COMPARATOR);
      }
      return VirtualFileManager.extractPath(roots[0]) + "/" + sourceDirName;
    }

    final CompilerProjectExtension extension =
        CompilerProjectExtension.getInstance(module.getProject());
    if (extension == null) {
      return null;
    }
    final String url = extension.getCompilerOutputUrl();
    if (url == null) {
      return null;
    }
    return VirtualFileManager.extractPath(url)
        + "/"
        + DEFAULT_GENERATED_DIR_NAME
        + "/"
        + module.getName().toLowerCase();
  }
 @Nullable
 public static String getDefaultArtifactOutputPath(
     @NotNull String artifactName, final @NotNull Project project) {
   final CompilerProjectExtension extension = CompilerProjectExtension.getInstance(project);
   if (extension == null) return null;
   String outputUrl = extension.getCompilerOutputUrl();
   if (outputUrl == null || outputUrl.length() == 0) {
     final VirtualFile baseDir = project.getBaseDir();
     if (baseDir == null) return null;
     outputUrl = baseDir.getUrl() + "/out";
   }
   return VfsUtil.urlToPath(outputUrl) + "/artifacts/" + FileUtil.sanitizeFileName(artifactName);
 }
  @Nullable
  public static String findResourcesCacheDirectory(
      @NotNull Module module, boolean createIfNotFound, @Nullable CompileContext context) {
    final Project project = module.getProject();

    final CompilerProjectExtension extension = CompilerProjectExtension.getInstance(project);
    if (extension == null) {
      if (context != null) {
        context.addMessage(
            CompilerMessageCategory.ERROR,
            "Cannot get compiler settings for project " + project.getName(),
            null,
            -1,
            -1);
      }
      return null;
    }

    final String projectOutputDirUrl = extension.getCompilerOutputUrl();
    if (projectOutputDirUrl == null) {
      if (context != null) {
        context.addMessage(
            CompilerMessageCategory.ERROR,
            "Cannot find output directory for project " + project.getName(),
            null,
            -1,
            -1);
      }
      return null;
    }

    final String pngCacheDirPath =
        VfsUtil.urlToPath(projectOutputDirUrl)
            + '/'
            + RESOURCES_CACHE_DIR_NAME
            + '/'
            + module.getName();
    final String pngCacheDirOsPath = FileUtil.toSystemDependentName(pngCacheDirPath);

    final File pngCacheDir = new File(pngCacheDirOsPath);
    if (pngCacheDir.exists()) {
      if (pngCacheDir.isDirectory()) {
        return pngCacheDirOsPath;
      } else {
        if (context != null) {
          context.addMessage(
              CompilerMessageCategory.ERROR,
              "Cannot create directory " + pngCacheDirOsPath + " because file already exists",
              null,
              -1,
              -1);
        }
        return null;
      }
    }

    if (!createIfNotFound) {
      return null;
    }

    if (!pngCacheDir.mkdirs()) {
      if (context != null) {
        context.addMessage(
            CompilerMessageCategory.ERROR,
            "Cannot create directory " + pngCacheDirOsPath,
            null,
            -1,
            -1);
      }
      return null;
    }

    return pngCacheDirOsPath;
  }