Java Code Examples for com.intellij.openapi.util.io.FileUtil#toSystemIndependentName()

The following examples show how to use com.intellij.openapi.util.io.FileUtil#toSystemIndependentName() . 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: ZipArchiveElementType.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public CompositePackagingElement<?> createComposite(CompositePackagingElement<?> parent,
                                                    @Nullable String baseName,
                                                    @Nonnull ArtifactEditorContext context) {
  final String initialValue = PackagingElementFactoryImpl.suggestFileName(parent, baseName != null ? baseName : "archive", ".zip");
  String path =
    Messages.showInputDialog(context.getProject(), "Enter archive name: ", "New Archive", null, initialValue, new FilePathValidator());
  if (path == null) {
    return null;
  }
  path = FileUtil.toSystemIndependentName(path);
  final String parentPath = PathUtil.getParentPath(path);
  final String fileName = PathUtil.getFileName(path);
  final PackagingElement<?> element = new ZipArchivePackagingElement(fileName);
  return (CompositePackagingElement<?>)PackagingElementFactory.getInstance(context.getProject()).createParentDirectories(parentPath, element);
}
 
Example 2
Source File: StateStorageManagerImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nonnull
private StateStorage createFileStateStorage(@Nonnull String fileSpec, @Nullable RoamingType roamingType) {
  String filePath = FileUtil.toSystemIndependentName(expandMacros(fileSpec));

  if (!ourHeadlessEnvironment && PathUtilRt.getFileName(filePath).lastIndexOf('.') < 0) {
    throw new IllegalArgumentException("Extension is missing for storage file: " + filePath);
  }

  if (roamingType == RoamingType.PER_USER && fileSpec.equals(StoragePathMacros.WORKSPACE_FILE)) {
    roamingType = RoamingType.DISABLED;
  }

  return myStateStorageFacade
          .createFileBasedStorage(filePath, fileSpec, roamingType, getMacroSubstitutor(fileSpec), myRootTagName, StateStorageManagerImpl.this, createStorageTopicListener(), myStreamProvider,
                                  isUseXmlProlog());
}
 
Example 3
Source File: PackagingElementFactoryImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nonnull
@Override
public List<? extends PackagingElement<?>> createLibraryElements(@Nonnull Library library) {
  final LibraryTable table = library.getTable();
  final String libraryName = library.getName();
  if (table != null) {
    return Collections.singletonList(createLibraryFiles(libraryName, table.getTableLevel(), null));
  }
  if (libraryName != null) {
    final Module module = ((LibraryImpl)library).getModule();
    if (module != null) {
      return Collections.singletonList(createLibraryFiles(libraryName, LibraryTableImplUtil.MODULE_LEVEL, module.getName()));
    }
  }
  final List<PackagingElement<?>> elements = new ArrayList<>();
  for (VirtualFile file : library.getFiles(BinariesOrderRootType.getInstance())) {
    final String path = FileUtil.toSystemIndependentName(PathUtil.getLocalPath(file));
    elements.add(file.isDirectory() && file.isInLocalFileSystem() ? new DirectoryCopyPackagingElement(path) : new FileCopyPackagingElement(path));
  }
  return elements;
}
 
Example 4
Source File: HaxeSdkUtilBase.java    From intellij-haxe with Apache License 2.0 6 votes vote down vote up
@Nullable
private static String getExecutablePathByFolderPath(String folderPath, String name) {
  if (!SystemInfo.isLinux) {
    final String candidatePath = folderPath + "/bin/" + getExecutableName(name);
    LOG.debug("candidatePath: " + candidatePath);
    if (fileExists(candidatePath)) {
      return FileUtil.toSystemIndependentName(candidatePath);
    }
  }

  final String resultPath = folderPath + "/" + getExecutableName(name);
  LOG.debug("resultPath: " + resultPath);
  if (fileExists(resultPath)) {
    return FileUtil.toSystemIndependentName(resultPath);
  }

  LOG.debug(name + " path: null");
  return null;
}
 
Example 5
Source File: ComponentWithBrowseButton.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nullable
protected VirtualFile getInitialFile() {
  String directoryName = getComponentText();
  if (StringUtil.isEmptyOrSpaces(directoryName)) {
    return null;
  }

  directoryName = FileUtil.toSystemIndependentName(directoryName);
  VirtualFile path = LocalFileSystem.getInstance().findFileByPath(expandPath(directoryName));
  while (path == null && directoryName.length() > 0) {
    int pos = directoryName.lastIndexOf('/');
    if (pos <= 0) break;
    directoryName = directoryName.substring(0, pos);
    path = LocalFileSystem.getInstance().findFileByPath(directoryName);
  }
  return path;
}
 
Example 6
Source File: SpringBootModuleBuilder.java    From crud-intellij-plugin with Apache License 2.0 5 votes vote down vote up
private void initMavenStructure() {
	String path = FileUtil.toSystemIndependentName(getContentEntryPath()) + "/";
	new File(path + "src/main/java").mkdirs();
	new File(path + "src/main/resources").mkdirs();
	new File(path + "src/test/java").mkdirs();
	new File(path + "src/test/resources").mkdirs();
}
 
Example 7
Source File: WSLDistributionLegacy.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
@Override
public String getWslPath(@Nonnull String windowsPath) {
  String wslRootInHost = WSL_ROOT_IN_WINDOWS_PROVIDER.getValue();
  if (wslRootInHost == null) {
    return null;
  }

  if (FileUtil.isAncestor(wslRootInHost, windowsPath, true)) {  // this is some internal WSL file
    return FileUtil.toSystemIndependentName(windowsPath.substring(wslRootInHost.length()));
  }

  return super.getWslPath(windowsPath);
}
 
Example 8
Source File: UrlUtil.java    From intellij with Apache License 2.0 5 votes vote down vote up
public static String pathToUrl(String filePath) {
  filePath = FileUtil.toSystemIndependentName(filePath);
  if (filePath.endsWith(".srcjar") || filePath.endsWith(".jar")) {
    return URLUtil.JAR_PROTOCOL + URLUtil.SCHEME_SEPARATOR + filePath + URLUtil.JAR_SEPARATOR;
  } else if (filePath.contains("src.jar!")) {
    return URLUtil.JAR_PROTOCOL + URLUtil.SCHEME_SEPARATOR + filePath;
  } else {
    return VirtualFileManager.constructUrl(
        VirtualFileSystemProvider.getInstance().getSystem().getProtocol(), filePath);
  }
}
 
Example 9
Source File: ResourceModuleContentRootCustomizer.java    From intellij with Apache License 2.0 5 votes vote down vote up
@NotNull
private static String pathToUrl(@NotNull String filePath) {
  filePath = FileUtil.toSystemIndependentName(filePath);
  if (filePath.endsWith(".srcjar") || filePath.endsWith(".jar")) {
    return URLUtil.JAR_PROTOCOL + URLUtil.SCHEME_SEPARATOR + filePath + URLUtil.JAR_SEPARATOR;
  } else if (filePath.contains("src.jar!")) {
    return URLUtil.JAR_PROTOCOL + URLUtil.SCHEME_SEPARATOR + filePath;
  } else {
    return VfsUtilCore.pathToUrl(filePath);
  }
}
 
Example 10
Source File: MavenTestCase.java    From intellij-quarkus with Eclipse Public License 2.0 4 votes vote down vote up
protected String getRepositoryPath() {
  String path = getRepositoryFile().getPath();
  return FileUtil.toSystemIndependentName(path);
}
 
Example 11
Source File: WinPathChooserDialog.java    From consulo with Apache License 2.0 4 votes vote down vote up
private VirtualFile fileToVirtualFile(File file) {
  final LocalFileSystem localFileSystem = LocalFileSystem.getInstance();
  final String vfsPath = FileUtil.toSystemIndependentName(file.getAbsolutePath());
  return localFileSystem.refreshAndFindFileByPath(vfsPath);
}
 
Example 12
Source File: CoreLocalVirtualFile.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
@Override
public String getPath() {
  return FileUtil.toSystemIndependentName(myIoFile.getAbsolutePath());
}
 
Example 13
Source File: MuleMavenModuleBuilder.java    From mule-intellij-plugins with Apache License 2.0 4 votes vote down vote up
private VirtualFile createAndGetContentEntry() {
    String path = FileUtil.toSystemIndependentName(this.getContentEntryPath());
    (new File(path)).mkdirs();
    return LocalFileSystem.getInstance().refreshAndFindFileByPath(path);
}
 
Example 14
Source File: TestLineMarkerContributor.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@NotNull
private static Icon getTestStateIcon(@NotNull PsiElement element, @NotNull Icon defaultIcon) {
  // SMTTestProxy maps test run data to a URI derived from a location hint produced by `package:test`.
  // If we can find corresponding data, we can provide state-aware icons. If not, we default to
  // a standard Run state.

  PsiFile containingFile;
  try {
    containingFile = element.getContainingFile();
  }
  catch (PsiInvalidElementAccessException e) {
    containingFile = null;
  }

  final Project project = element.getProject();
  final PsiDocumentManager psiDocumentManager = PsiDocumentManager.getInstance(project);

  final Document document = containingFile == null ? null : psiDocumentManager.getDocument(containingFile);
  if (document != null) {
    final int textOffset = element.getTextOffset();
    final int lineNumber = document.getLineNumber(textOffset);

    // e.g., dart_location:///Users/pq/IdeaProjects/untitled1298891289891/test/unit_test.dart,3,2,["my first unit test"]
    final String path = FileUtil.toSystemIndependentName(containingFile.getVirtualFile().getPath());
    final String testLocationPrefix = "dart_location://" + path + "," + lineNumber;

    final TestStateStorage storage = TestStateStorage.getInstance(project);
    if (storage != null) {
      final Map<String, TestStateStorage.Record> tests = storage.getRecentTests(SCANNED_TEST_RESULT_LIMIT, getSinceDate());
      if (tests != null) {
        // TODO(pq): investigate performance implications.
        for (Map.Entry<String, TestStateStorage.Record> entry : tests.entrySet()) {
          if (entry.getKey().startsWith(testLocationPrefix)) {
            final TestStateStorage.Record state = entry.getValue();
            final TestStateInfo.Magnitude magnitude = TestIconMapper.getMagnitude(state.magnitude);
            if (magnitude != null) {
              switch (magnitude) {
                case IGNORED_INDEX:
                  return AllIcons.RunConfigurations.TestState.Yellow2;
                case ERROR_INDEX:
                case FAILED_INDEX:
                  return AllIcons.RunConfigurations.TestState.Red2;
                case PASSED_INDEX:
                case COMPLETE_INDEX:
                  return AllIcons.RunConfigurations.TestState.Green2;
                default:
              }
            }
          }
        }
      }
    }
  }

  return defaultIcon;
}
 
Example 15
Source File: ChromeSettingsConfigurable.java    From consulo with Apache License 2.0 4 votes vote down vote up
private String getConfiguredUserDataDirPath() {
  return FileUtil.toSystemIndependentName(myUserDataDirField.getText());
}
 
Example 16
Source File: ExternalSystemImportingTestCase.java    From intellij-quarkus with Eclipse Public License 2.0 4 votes vote down vote up
protected static String getAbsolutePath(String path) {
  path = VfsUtilCore.urlToPath(path);
  path = PathUtil.getCanonicalPath(path);
  return FileUtil.toSystemIndependentName(path);
}
 
Example 17
Source File: PsiFileUtils.java    From crud-intellij-plugin with Apache License 2.0 4 votes vote down vote up
public static void createCrud(Project project, Selection selection, String moduleRootPath) {
	List<Table> tables = selection.getTables();
	for (Table table : tables) {
		//model生成
		List<Column> columns = table.getColumns();
		List<Field> fields = new ArrayList<>();
		for (Column column : columns) {
			Field field = new Field(column.getComment(), JavaTypeUtils.convertType(column.getType()), column.getName());
			field.setId(column.isId());
			fields.add(field);
		}
		String modelPackage = selection.getModelPackage();
		if (modelPackage == null) {
			return;
		}
		VirtualFile modelPackageDir = createPackageDir(modelPackage, moduleRootPath);
		if (!StringUtils.isBlank(modelPackage)) {
			modelPackage += ".";
		}
		Model model = new Model(table.getComment(), modelPackage + CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, table.getName()), table.getName(), fields);
		model.setOrmType(selection.getOrmType());
		PsiFileUtils.createModel(project, modelPackageDir, model);
		//dao生成
		String daoPackage = selection.getDaoPackage();
		if (daoPackage == null) {
			continue;
		}
		VirtualFile daoPackageDir = createPackageDir(daoPackage, moduleRootPath);
		if (!StringUtils.isBlank(daoPackage)) {
			daoPackage += ".";
		}
		Dao dao = new Dao(table.getComment(), daoPackage + CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, table.getName()) + "DAO", model);
		PsiFileUtils.createDao(project, daoPackageDir, dao);
		//mybatis生成mapper.xml
		if (selection.getOrmType() == SelectionContext.MYBATIS) {
			String mapperDir = selection.getMapperDir();
			if (StringUtils.isNotBlank(mapperDir)) {
				String path = FileUtil.toSystemIndependentName(mapperDir);
				new File(path).mkdirs();
				VirtualFile virtualFile = LocalFileSystem.getInstance().refreshAndFindFileByPath(path);
				PsiFileUtils.createMapper(project, virtualFile, dao);
			}
		}
		//service生成
		//接口
		String servicePackage = selection.getServicePackage();
		if (servicePackage == null) {
			continue;
		}
		VirtualFile servicePackageDir = createPackageDir(servicePackage, moduleRootPath);
		if (!StringUtils.isBlank(servicePackage)) {
			servicePackage += ".";
		}
		Service service = new Service(table.getComment(), servicePackage + CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, table.getName()) + "Service", dao);
		PsiFileUtils.createService(project, servicePackageDir, service);
		//实现
		String serviceImplPackage = servicePackage + "impl";
		VirtualFile serviceImplPackageDir = createPackageDir(serviceImplPackage, moduleRootPath);
		service.getImports().add(service.getDao().getName());
		service.getImports().add(service.getName());
		PsiFileUtils.createServiceImplJpa(project, serviceImplPackageDir, service);
		//controller生成
		String controllerPackage = selection.getControllerPackage();
		if (controllerPackage == null) {
			continue;
		}
		VirtualFile controllerPackageDir = createPackageDir(controllerPackage, moduleRootPath);
		if (!StringUtils.isBlank(controllerPackage)) {
			controllerPackage += ".";
		}
		Controller controller = new Controller(table.getComment(), controllerPackage + CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, table.getName()) + "Controller", service);
		PsiFileUtils.createController(project, controllerPackageDir, controller);
	}
}
 
Example 18
Source File: LocalFileSystemImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
@Nonnull
public String getRootPath() {
  return FileUtil.toSystemIndependentName(myFSRootPath);
}
 
Example 19
Source File: SpringBootModuleBuilder.java    From crud-intellij-plugin with Apache License 2.0 4 votes vote down vote up
private VirtualFile createPackageDir(String packageName) {
	packageName = "src/main/java/" + packageName;
	String path = FileUtil.toSystemIndependentName(getContentEntryPath() + "/" + StringUtil.replace(packageName, ".", "/"));
	new File(path).mkdirs();
	return LocalFileSystem.getInstance().refreshAndFindFileByPath(path);
}
 
Example 20
Source File: IntegrationTestCase.java    From consulo with Apache License 2.0 4 votes vote down vote up
protected String createDirectoryExternally(String name) throws IOException {
  File f = new File(myRoot.getPath(), name);
  f.mkdirs();
  return FileUtil.toSystemIndependentName(f.getPath());
}