Java Code Examples for com.intellij.openapi.module.Module#getModuleFile()

The following examples show how to use com.intellij.openapi.module.Module#getModuleFile() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ArmaPlugin.java    From arma-intellij-plugin with MIT License 6 votes vote down vote up
/**
 * @return the path to Arma IntelliJ Plugin's temp directory for the given module,
 * or null if the .iml directory couldn't be located
 */
@Nullable
public static String getPathToTempDirectory(@NotNull Module module) {
	final String tempFolder = "/armaplugin-temp";

	//find a place to save parse data
	VirtualFile imlVirtFile = module.getModuleFile();
	if (imlVirtFile == null) {
		String projectBasePath = module.getProject().getBasePath();
		if (projectBasePath == null) {
			return null;
		}
		return projectBasePath + tempFolder;
	}
	VirtualFile imlDir = imlVirtFile.getParent();
	if (imlDir == null) {
		return null;
	}
	return imlDir.getPath() + tempFolder;
}
 
Example 2
Source File: FacetUtil.java    From aem-ide-tooling-4-intellij with Apache License 2.0 6 votes vote down vote up
public static Result checkFile(Module module, String filePath, boolean directory) {
    Result ret = Result.ok;
    if(filePath == null || filePath.length() == 0) {
        ret = Result.fileEmpty;
    } else {
        VirtualFile moduleFile = module.getModuleFile();
        VirtualFile file = moduleFile.getFileSystem().findFileByPath(filePath);
        if(file == null) {
            ret = Result.fileNotFound;
        } else if(directory) {
            if(!file.isDirectory()) {
                ret = Result.notDirectory;
            }
        } else {
            if(!file.isDirectory()) {
                ret = Result.notFile;
            }
        }
    }
    return ret;
}
 
Example 3
Source File: ArmaPlugin.java    From arma-intellij-plugin with MIT License 6 votes vote down vote up
/**
 * @return the path to Arma IntelliJ Plugin's temp directory for the given module,
 * or null if the .iml directory couldn't be located
 */
@Nullable
public static String getPathToTempDirectory(@NotNull Module module) {
	final String tempFolder = "/armaplugin-temp";

	//find a place to save parse data
	VirtualFile imlVirtFile = module.getModuleFile();
	if (imlVirtFile == null) {
		String projectBasePath = module.getProject().getBasePath();
		if (projectBasePath == null) {
			return null;
		}
		return projectBasePath + tempFolder;
	}
	VirtualFile imlDir = imlVirtFile.getParent();
	if (imlDir == null) {
		return null;
	}
	return imlDir.getPath() + tempFolder;
}
 
Example 4
Source File: Platform.java    From reasonml-idea-plugin with MIT License 5 votes vote down vote up
@Nullable
public static VirtualFile findFileByRelativePath(@NotNull Project project, @NotNull String path) {
    for (Module module : ModuleManager.getInstance(project).getModules()) {
        VirtualFile moduleFile = module.getModuleFile();
        VirtualFile baseDir = moduleFile == null ? null : moduleFile.getParent();
        VirtualFile file = baseDir == null ? null : baseDir.findFileByRelativePath(path);
        if (file != null) {
            return file;
        }
    }
    return null;
}
 
Example 5
Source File: IdeaUtils.java    From netbeans-mmd-plugin with Apache License 2.0 5 votes vote down vote up
@Nullable
public static VirtualFile findPotentialRootFolderForModule(@Nullable final Module module) {
  VirtualFile moduleRoot = module == null ? null : module.getModuleFile();
  if (moduleRoot != null) {
    moduleRoot = moduleRoot.isDirectory() ? moduleRoot : moduleRoot.getParent();
    if (moduleRoot.getName().equals(".idea")) {
      moduleRoot = moduleRoot.getParent();
    }
  }
  return moduleRoot;
}
 
Example 6
Source File: GhcMod.java    From intellij-haskforce with Apache License 2.0 5 votes vote down vote up
/** Infers the absolute path given a relative one and its enclosing module. */
@Nullable
private static String inferAbsolutePath(@NotNull Module module, @NotNull String path) {
    File file = new File(path);
    if (file.exists()) return file.getAbsolutePath();
    final VirtualFile moduleFile = module.getModuleFile();
    if (moduleFile == null) return null;
    final String inferredPath = FileUtil.join(moduleFile.getParent().getCanonicalPath(), path);
    if (new File(inferredPath).exists()) return inferredPath;
    return null;
}
 
Example 7
Source File: ExecUtil.java    From intellij-haskforce with Apache License 2.0 5 votes vote down vote up
@NotNull
public static String guessWorkDir(@NotNull Module module) {
    final VirtualFile moduleFile = module.getModuleFile();
    final VirtualFile moduleDir = moduleFile == null ? null : moduleFile.getParent();
    if (moduleDir != null) return moduleDir.getPath();
    return getProjectPath(module.getProject());
}
 
Example 8
Source File: HaxeCompiler.java    From intellij-haxe with Apache License 2.0 5 votes vote down vote up
private static int findProcessingItemIndexByModule(ProcessingItem[] items, RunConfigurationModule moduleConfiguration) {
  final Module module = moduleConfiguration.getModule();
  if (module == null || module.getModuleFile() == null) {
    return -1;
  }
  for (int i = 0; i < items.length; ++i) {
    if (module.getModuleFile().equals(items[i].getFile())) {
      return i;
    }
  }
  return -1;
}
 
Example 9
Source File: ConfigFileLocator.java    From EclipseCodeFormatter with Apache License 2.0 5 votes vote down vote up
@Override
public VirtualFile getModuleDirForFile(VirtualFile virtualFile, Project project) {
	Module moduleForFile = ModuleUtil.findModuleForFile(virtualFile, project);
	if (moduleForFile != null) {
		VirtualFile moduleFile = moduleForFile.getModuleFile();
		if (moduleFile != null) {
			return moduleFile.getParent();
		}
	}
	return null;
}
 
Example 10
Source File: CppCompiler.java    From CppTools with Apache License 2.0 5 votes vote down vote up
@NotNull
public ProcessingItem[] getProcessingItems(final CompileContext compileContext) {
  final List<ProcessingItem> processingItems = new ArrayList<ProcessingItem>();
  boolean doneSave = false;

  Module[] affectedModules = ApplicationManager.getApplication().runReadAction(new Computable<Module[]>() {
    public Module[] compute() {
      return compileContext.getCompileScope().getAffectedModules();
    }
  });

  for(Module module: affectedModules) {
    Sdk sdk = ModuleRootManager.getInstance(module).getSdk();
    if (ModuleType.get(module) == CppModuleType.getInstance() ||
       (sdk != null && sdk.getSdkType() == CppSdkType.getInstance())) {
      processingItems.add(new MyProcessingItem(module));

      if (!doneSave) {
        BuildState.saveDocuments();
        doneSave = true;
      }

      VirtualFile moduleFile = module.getModuleFile();
      if (moduleFile == null) {
        BuildState.saveAll();
      }
    }
  }
  return processingItems.toArray(new ProcessingItem[processingItems.size()]);
}