@NotNull public static String getBinaryFileNameForPath(@NotNull String path) { String resultBinaryName = FileUtil.getNameWithoutExtension(PathUtil.getFileName(path)); return SystemInfo.isWindows ? resultBinaryName + ".exe" : resultBinaryName; }
@Nullable private static String getGaeExecutablePath(@NotNull String sdkHomePath) { String goExecutablePath = PathUtil.toSystemIndependentName(sdkHomePath); goExecutablePath = StringUtil.trimEnd(goExecutablePath, GoConstants.APP_ENGINE_GO_ROOT_DIRECTORY_PATH); boolean gcloudInstallation = goExecutablePath.endsWith(GoConstants.GCLOUD_APP_ENGINE_DIRECTORY_PATH); if (gcloudInstallation) { LOG.debug("Detected gcloud GAE installation at " + goExecutablePath); goExecutablePath = FileUtil.join(StringUtil.trimEnd(goExecutablePath, GoConstants.GCLOUD_APP_ENGINE_DIRECTORY_PATH), "bin"); } String executablePath = FileUtil.join(goExecutablePath, GoEnvironmentUtil.getGaeExecutableFileName(gcloudInstallation)); return new File(executablePath).exists() ? executablePath : null; }
private void handleEvent(@NotNull VirtualFileEvent event) { if ("yaml".equals(PathUtil.getFileExtension(event.getFileName()))) { incModificationCount(); } } }, project);
private static boolean findCommunitySources(@NotNull Project project, List<File> result, String... urls) { String communitySrc = getCommunitySrcUrl(project); if (communitySrc == null) return false; List<String> roots = ContainerUtil.newArrayList(); for (String url : urls) { int idx = url.indexOf("/master/"); if (idx > -1) { roots.add(StringUtil.trimEnd(communitySrc, "/") + "/" + url.substring(idx + "/master/".length())); } else { String file = PathUtil.getFileName(url); roots.add(PathUtil.getParentPath(communitySrc) + "/tools/lexer/lib/" + file); } } return collectFiles(result, roots, urls); }
public GoRunConfigurationBase(String name, GoModuleBasedConfiguration configurationModule, ConfigurationFactory factory) { super(name, configurationModule, factory); Module module = configurationModule.getModule(); if (module == null) { Collection<Module> modules = getValidModules(); if (modules.size() == 1) { module = ContainerUtil.getFirstItem(modules); getConfigurationModule().setModule(module); } } if (module != null) { if (FileUtil.exists(module.getModuleFilePath())) { myWorkingDirectory = StringUtil.trimEnd(PathUtil.getParentPath(module.getModuleFilePath()), ".idea"); } } else { myWorkingDirectory = StringUtil.notNullize(configurationModule.getProject().getBasePath()); } }
@Nullable private VirtualFile findSingleFile(@NotNull String fileName) { if (PathUtil.isValidFileName(fileName)) { Collection<VirtualFile> files = FilenameIndex.getVirtualFilesByName(myProject, fileName, GlobalSearchScope.allScope(myProject)); if (files.size() == 1) { return ContainerUtil.getFirstItem(files); } } return null; }
indicator.setFraction((double)i / l); indicator.setText2(file.getPath()); String sourcePath = FileUtil.toSystemDependentName(PathUtil.getCanonicalPath(file.getParent().getPath())); VirtualFile target = rootMap.get(file); if (target == null) return;
public BallerinaRunConfigurationBase(String name, BallerinaModuleBasedConfiguration configurationModule, ConfigurationFactory factory) { super(name, configurationModule, factory); Module module = configurationModule.getModule(); if (module == null) { Collection<Module> modules = getValidModules(); if (modules.size() == 1) { module = ContainerUtil.getFirstItem(modules); getConfigurationModule().setModule(module); } } if (module != null) { if (FileUtil.exists(module.getModuleFilePath())) { myWorkingDirectory = StringUtil.trimEnd(PathUtil.getParentPath(module.getModuleFilePath()), BallerinaConstants.IDEA_CONFIG_DIRECTORY); } } else { myWorkingDirectory = StringUtil.notNullize(configurationModule.getProject().getBasePath()); } setFileOutputPath(myWorkingDirectory); }
@Nullable private VirtualFile findSingleFile(@NotNull String fileName) { if (PathUtil.isValidFileName(fileName)) { Collection<VirtualFile> files = FilenameIndex.getVirtualFilesByName(myProject, fileName, GlobalSearchScope.allScope(myProject)); if (files.size() == 1) { return ContainerUtil.getFirstItem(files); } if (!files.isEmpty()) { GlobalSearchScope goPathScope = GoPathResolveScope.create(myProject, myModule, null); files = ContainerUtil.filter(files, goPathScope::accept); if (files.size() == 1) { return ContainerUtil.getFirstItem(files); } } if (!files.isEmpty()) { GlobalSearchScope smallerScope = GoUtil.moduleScopeWithoutLibraries(myProject, myModule); files = ContainerUtil.filter(files, smallerScope::accept); if (files.size() == 1) { return ContainerUtil.getFirstItem(files); } } } return null; }
@NotNull public static String getBinaryFileNameForPath(@NotNull String path) { String resultBinaryName = FileUtil.getNameWithoutExtension(PathUtil.getFileName(path)); return SystemInfo.isWindows ? resultBinaryName + ".bat" : resultBinaryName; }
/** * Path will always contain forward slashes. */ @CheckForNull public String getPathRelativeToModuleBaseDir(Module module, VirtualFile file) { Path baseDir = Paths.get(module.getModuleFilePath()).getParent(); Path filePath = Paths.get(file.getPath()); if (!filePath.startsWith(baseDir)) { return null; } return PathUtil.toSystemIndependentName(baseDir.relativize(filePath).toString()); }
@NotNull @Override protected GoRunFileRunningState newRunningState(@NotNull ExecutionEnvironment env, @NotNull Module module) { String path = getFilePath(); if (!"go".equals(PathUtil.getFileExtension(path))) { VirtualFile f = LocalFileSystem.getInstance().refreshAndFindFileByPath(path); if (f != null && f.getFileType() == ScratchFileType.INSTANCE) { String suffixWithoutExt = "." + UUID.randomUUID().toString().substring(0, 4); String suffix = suffixWithoutExt + ".go"; String before = f.getName(); String beforeWithoutExt = FileUtil.getNameWithoutExtension(before); ApplicationManager.getApplication().runWriteAction(new Runnable() { @Override public void run() { try { f.rename(this, before + suffix); } catch (IOException ignored) { } } }); setFilePath(path + suffix); setName(getName().replace(beforeWithoutExt, beforeWithoutExt + suffixWithoutExt)); } } return new GoRunFileRunningState(env, module, this); } }
public static String getLocalPackageName(@NotNull String importPath) { String fileName = !StringUtil.endsWithChar(importPath, '/') && !StringUtil.endsWithChar(importPath, '\\') ? PathUtil.getFileName(importPath) : ""; StringBuilder name = null; for (int i = 0; i < fileName.length(); i++) { char c = fileName.charAt(i); if (!(Character.isLetter(c) || c == '_' || i != 0 && Character.isDigit(c))) { if (name == null) { name = new StringBuilder(fileName.length()); name.append(fileName, 0, i); } name.append('_'); } else if (name != null) { name.append(c); } } return name == null ? fileName : name.toString(); }
@Override protected void setUp() throws Exception { super.setUp(); final String mapstructLibPath = PathUtil.toSystemIndependentName( new File( BUILD_LIBS_DIRECTORY ) .getAbsolutePath() ); VfsRootAccess.allowRootAccess( mapstructLibPath ); PsiTestUtil.addLibrary( myFixture.getProjectDisposable(), getModule(), "Mapstruct", mapstructLibPath, "mapstruct.jar" ); }
@Override public void checkConfiguration() throws RuntimeConfigurationException { super.checkConfiguration(); Module module = getConfigurationModule().getModule(); if (module != null) { if (!GoSdkService.getInstance(module.getProject()).isAppEngineSdk(module)) { throw new RuntimeConfigurationWarning("Go SDK is not specified for module '" + module.getName() + "'"); } } checkPortValue(myPort, "Invalid port"); checkPortValue(myAdminPort, "Invalid admin port"); if (myConfigFile != null && !"yaml".equals(PathUtil.getFileExtension(myConfigFile))) { throw new RuntimeConfigurationException("Config file is not YAML"); } }
@Nullable public String suggestedName() { final String filePath = getdFilePath(); return filePath == null ? null : PathUtil.getFileName(filePath); } //
@Override public boolean isSupported(@NotNull File file) { return StringUtil.equalsIgnoreCase(PathUtil.getFileExtension(file.getName()), "jfr"); }
@Nullable @Override public PsiElement resolveInner() { final String referencedName = cmd.getReferencedCommandName(); if (referencedName == null) { return null; } String fileName = PathUtil.getFileName(referencedName); GlobalSearchScope scope = BashSearchScopes.moduleScope(cmd.getContainingFile()); PsiFileSystemItem[] files = FilenameIndex.getFilesByName(cmd.getProject(), fileName, scope, false); if (files.length == 0) { return null; } PsiFile currentFile = cmd.getContainingFile(); return BashPsiFileUtils.findRelativeFile(currentFile, referencedName); }