@Nullable private Project findProject(String file) { LocalFileSystem localFileSystem = LocalFileSystem.getInstance(); ProjectLocator projectLocator = ProjectLocator.getInstance(); AtomicReference<Project> ret = new AtomicReference<>(); FileUtil.processFilesRecursively( new File(file), (f) -> { VirtualFile vf = localFileSystem.findFileByIoFile(f); if (vf != null) { ret.set(projectLocator.guessProjectForFile(vf)); return false; } return true; }); return ret.get(); }
public static final List<String> parseScripts(File f) { List<String> list = new ArrayList<>(); if(!f.exists()) { return list; } try { JsonObject result = new Gson().fromJson(FileUtil.loadFile(f, "UTF-8"), JsonObject.class); JsonObject scripts = result.getAsJsonObject("scripts"); if(scripts == null) { return list;// Fix NPE when there is an empty or no scripts package.json file } for (Map.Entry<String, JsonElement> obj: scripts.entrySet()) { list.add(obj.getKey()); } } catch (Exception e) { e.printStackTrace(); } return list; }
private void getVirtualFile(String sourceName, VirtualFile virtualFile[], String compileRoot) throws Exception { if (!ArrayUtils.isEmpty(virtualFile)) { VirtualFile arr$[] = virtualFile; int len$ = arr$.length; for (int i$ = 0; i$ < len$; i$++) { VirtualFile vf = arr$[i$]; String srcName; if (StringUtils.indexOf(vf.toString(), "$") != -1) srcName = StringUtils.substring(vf.toString(), StringUtils.lastIndexOf(vf.toString(), "/") + 1, StringUtils.indexOf(vf.toString(), "$")); else srcName = StringUtils.substring(vf.toString(), StringUtils.lastIndexOf(vf.toString(), "/") + 1, StringUtils.length(vf.toString()) - 6); String dstName = StringUtils.substring(sourceName, 0, StringUtils.length(sourceName) - 5); if (StringUtils.equals(srcName, dstName)) { String outRoot = (new StringBuilder()).append(StringUtils.substring(compileRoot, 0, StringUtils.lastIndexOf(compileRoot, "/"))).append("/out").toString(); String packagePath = StringUtils.substring(vf.getPath(), StringUtils.length(compileRoot), StringUtils.length(vf.getPath())); File s = new File(vf.getPath()); File t = new File((new StringBuilder()).append(outRoot).append(packagePath).toString()); FileUtil.copy(s, t); } if (!ArrayUtils.isEmpty(virtualFile)) getVirtualFile(sourceName, vf.getChildren(), compileRoot); } } }
private void findAntResult(final Map<Project, AntGenResult> resultMap) { for (Project project : ProjectManager.getInstance().getOpenProjects()) { final HybrisProjectSettings hybrisProjectSettings = HybrisProjectSettingsComponent.getInstance(project).getState(); if (!hybrisProjectSettings.isHybrisProject()) { continue; } final File file = new File(project.getBasePath() + "/" + hybrisProjectSettings.getHybrisDirectory() + "/temp/ant.ser"); if (file.exists()) { AntGenResult result = null; try ( final FileInputStream fileIn = new FileInputStream(file); final ObjectInputStream in = new ObjectInputStream(fileIn) ) { result = (AntGenResult) in.readObject(); } catch (IOException | ClassNotFoundException e) { e.printStackTrace(); } FileUtil.delete(file); resultMap.put(project, result); return; } } }
@Override public void removeAllFiles(@NotNull final Collection<File> files) throws IOException { Validate.notNull(files); if (files.isEmpty()) { return; } final LocalFileSystem localFileSystem = LocalFileSystem.getInstance(); for (File file : files) { final VirtualFile virtualFile = localFileSystem.findFileByIoFile(file); if (null != virtualFile) { ApplicationManager.getApplication().runWriteAction(new RemoveFileComputable(virtualFile)); } else { FileUtil.delete(file); } } }
private static void transformTestFile(@NotNull Project project, int toSubtaskIndex, VirtualFile taskDir) { String subtaskTestFileName = getTestFileName(project, toSubtaskIndex); if (subtaskTestFileName == null) { return; } String nameWithoutExtension = FileUtil.getNameWithoutExtension(subtaskTestFileName); String extension = FileUtilRt.getExtension(subtaskTestFileName); VirtualFile subtaskTestFile = taskDir.findChild(nameWithoutExtension + ".txt"); if (subtaskTestFile != null) { ApplicationManager.getApplication().runWriteAction(() -> { try { subtaskTestFile.rename(project, nameWithoutExtension + "." + extension); } catch (IOException e) { LOG.error(e); } }); } }
/** * @param wrap if true, text will be wrapped with ancillary information (e.g. to display latex) */ public String getTaskDescription(boolean wrap) { String fileName = getTaskDescriptionName(); //TODO: replace this with simple get after implementing migration for taskTexts Map.Entry<String, String> entry = EntryStream.of(taskTexts).findFirst(e -> FileUtil.getNameWithoutExtension(e.getKey()).equals(fileName)).orElse(null); if (entry == null) { return null; } String taskText = entry.getValue(); if (!wrap) { return taskText; } taskText = StudyUtils.wrapTextToDisplayLatex(StudyUtils.convertToHtml(taskText)); if (getLesson().getCourse().isAdaptive()) { taskText = EduAdaptiveStepicConnector.wrapAdaptiveCourseText(this, taskText); } return taskText; }
private void updateTestHelper() { StartupManager.getInstance(myProject).runWhenProjectIsInitialized(() -> ApplicationManager.getApplication().runWriteAction(() -> { final VirtualFile baseDir = myProject.getBaseDir(); if (baseDir == null) { return; } final VirtualFile testHelper = baseDir.findChild(EduNames.TEST_HELPER); if (testHelper != null) { StudyUtils.deleteFile(testHelper); } final FileTemplate template = FileTemplateManager.getInstance(myProject).getInternalTemplate(FileUtil.getNameWithoutExtension(EduNames.TEST_HELPER)); try { final PsiDirectory projectDir = PsiManager.getInstance(myProject).findDirectory(baseDir); if (projectDir != null) { FileTemplateUtil.createFromTemplate(template, EduNames.TEST_HELPER, null, projectDir); } } catch (Exception e) { LOG.warn("Failed to create new test helper"); } })); }
public static int getSubtaskIndex(@NotNull Project project, @NotNull VirtualFile file) { String fileName = file.getName(); String name = FileUtil.getNameWithoutExtension(fileName); if (!isTestsFile(project, file)) { return -1; } if (!name.contains(EduNames.SUBTASK_MARKER)) { return 0; } int markerIndex = name.indexOf(EduNames.SUBTASK_MARKER); String index = name.substring(markerIndex + EduNames.SUBTASK_MARKER.length()); if (index.isEmpty()) { return -1; } try { return Integer.valueOf(index); } catch (NumberFormatException e) { return -1; } }
private static void transformFiles(Course course, Project project) { List<VirtualFile> files = getAllAnswerTaskFiles(course, project); for (VirtualFile answerFile : files) { ApplicationManager.getApplication().runWriteAction(() -> { String answerName = answerFile.getName(); String nameWithoutExtension = FileUtil.getNameWithoutExtension(answerName); String name = FileUtil.getNameWithoutExtension(nameWithoutExtension) + "." + FileUtilRt.getExtension(answerName); VirtualFile parent = answerFile.getParent(); VirtualFile file = parent.findChild(name); try { if (file != null) { file.delete(CCProjectComponent.class); } VirtualFile windowsDescrFile = parent.findChild(FileUtil.getNameWithoutExtension(name) + EduNames.WINDOWS_POSTFIX); if (windowsDescrFile != null) { windowsDescrFile.delete(CCProjectComponent.class); } answerFile.rename(CCProjectComponent.class, name); } catch (IOException e) { LOG.error(e); } }); } }
private static List<VirtualFile> getAllAnswerTaskFiles(@NotNull Course course, @NotNull Project project) { List<VirtualFile> result = new ArrayList<>(); for (Lesson lesson : course.getLessons()) { for (Task task : lesson.getTaskList()) { for (Map.Entry<String, TaskFile> entry : task.getTaskFiles().entrySet()) { String name = entry.getKey(); String answerName = FileUtil.getNameWithoutExtension(name) + CCUtils.ANSWER_EXTENSION_DOTTED + FileUtilRt.getExtension(name); String taskPath = FileUtil.join(project.getBasePath(), EduNames.LESSON + lesson.getIndex(), EduNames.TASK + task.getIndex()); VirtualFile taskFile = LocalFileSystem.getInstance().findFileByPath(FileUtil.join(taskPath, answerName)); if (taskFile == null) { taskFile = LocalFileSystem.getInstance().findFileByPath(FileUtil.join(taskPath, EduNames.SRC, answerName)); } if (taskFile != null) { result.add(taskFile); } } } } return result; }
public CreateCourseArchivePanel(@NotNull final Project project, CreateCourseArchiveDialog dlg, String name) { setLayout(new BorderLayout()); add(myPanel, BorderLayout.CENTER); myErrorIcon.setIcon(AllIcons.Actions.Lightning); setState(false); myDlg = dlg; String sanitizedName = FileUtil.sanitizeFileName(name); myNameField.setText(sanitizedName.startsWith("_") ? EduNames.COURSE : sanitizedName); myLocationField.setText(project.getBasePath()); FileChooserDescriptor descriptor = FileChooserDescriptorFactory.createSingleFolderDescriptor(); myLocationField.addBrowseFolderListener("Choose Location Folder", null, project, descriptor); myLocationField.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { String location = myLocationField.getText(); File file = new File(location); if (!file.exists() || !file.isDirectory()) { myDlg.enableOKAction(false); setError("Invalid location"); } myDlg.enableOKAction(true); } }); }
private static StepicWrappers.StepOptions doStepOptionsCreationTest(String fileName) throws IOException { String responseString = FileUtil.loadFile(new File(getTestDataPath(), fileName)); StepicWrappers.StepSource stepSource = EduStepicClient.deserializeStepicResponse(StepicWrappers.StepContainer.class, responseString).steps.get(0); StepicWrappers.StepOptions options = stepSource.block.options; List<TaskFile> files = options.files; assertTrue("Wrong number of task files", files.size() == 1); List<AnswerPlaceholder> placeholders = files.get(0).getAnswerPlaceholders(); assertTrue("Wrong number of placeholders", placeholders.size() == 1); Map<Integer, AnswerPlaceholderSubtaskInfo> infos = placeholders.get(0).getSubtaskInfos(); assertNotNull(infos); assertEquals(Collections.singletonList("Type your name here."), infos.get(0).getHints()); assertEquals("Liana", infos.get(0).getPossibleAnswer()); return options; }
@Nullable @Override protected VirtualFile getTestsFile() { String testFileName = EduJavaPluginConfigurator.TEST_JAVA; if (myTask instanceof TaskWithSubtasks) { int activeSubtaskIndex = ((TaskWithSubtasks) myTask).getActiveSubtaskIndex(); testFileName = FileUtil.getNameWithoutExtension(testFileName) + EduNames.SUBTASK_MARKER + activeSubtaskIndex + "." + FileUtilRt.getExtension(EduJavaPluginConfigurator.TEST_JAVA); } VirtualFile taskDir = myTask.getTaskDir(myProject); if (taskDir == null) { return null; } VirtualFile srcDir = taskDir.findChild(EduNames.SRC); if (srcDir != null) { taskDir = srcDir; } VirtualFile virtualFile = taskDir.findChild(testFileName); if (virtualFile != null) { return virtualFile; } return null; }
@NotNull @Override public Module createModule(@NotNull ModifiableModuleModel moduleModel) throws InvalidDataException, IOException, ModuleWithNameAlreadyExists, JDOMException, ConfigurationException { Module baseModule = super.createModule(moduleModel); Project project = baseModule.getProject(); EduProjectGenerator generator = new EduProjectGenerator(); if (myCourse == null) { File courseRoot = StudyUtils.getBundledCourseRoot(DEFAULT_COURSE_NAME, EduKotlinKoansModuleBuilder.class); final Course course = generator.addLocalCourse(FileUtil.join(courseRoot.getPath(), DEFAULT_COURSE_NAME)); if (course == null) { LOG.info("Failed to find course " + DEFAULT_COURSE_NAME); return baseModule; } } myCourse.setLanguage("kotlin"); EduModuleBuilderUtils.createCourseFromCourseInfo(moduleModel, project, generator, myCourse, getModuleFileDirectory()); return baseModule; }
public Map<String, HotSwapFile> scanForModifiedClasses( DebuggerSession session, HotSwapProgress progress ) { DebuggerManagerThreadImpl.assertIsManagerThread(); Map<String, HotSwapFile> modifiedClasses = new HashMap<>(); List<File> outputRoots = new ArrayList<>(); ApplicationManager.getApplication().runReadAction( () -> { VirtualFile[] allDirs = OrderEnumerator.orderEntries( getIjProject() ).getAllSourceRoots(); for( VirtualFile dir : allDirs ) { outputRoots.add( new File( dir.getPath() ) ); } } ); long timeStamp = getTimeStamp( session ); for( File root : outputRoots ) { String rootPath = FileUtil.toCanonicalPath( root.getPath() ); collectModifiedClasses( root, rootPath, modifiedClasses, progress, timeStamp ); } setTimeStamp( session, System.currentTimeMillis() ); return modifiedClasses; }
private static String createNotSignApk(File apkFile, String tempPath, String apkNameWithoutExtension) throws FileNotFoundException { String tempApkPath = tempPath + File.separator + apkNameWithoutExtension + "-unsigned.apk"; File tempApk = new File(tempApkPath); FileUtil.createIfDoesntExist(tempApk); //delete signature boolean success = ZipHelper.update(new FileInputStream(apkFile), new FileOutputStream(tempApk), new HashMap<>(0)); if (!success) { String message = "create tempApk failed, please try again"; NotificationHelper.error(message); throw new RuntimeException(message); } return tempApkPath; }
public void test() throws IOException { File dir = Files.createTempDir(); try { assertNotNull(FileResourceRepository.get(dir)); // We shouldn't clear it out immediately on GC *eligibility*: System.gc(); assertNotNull(FileResourceRepository.getCached(dir)); // However, in low memory conditions we should: try { PlatformTestUtil.tryGcSoftlyReachableObjects(); } catch (Throwable t) { // The above method can throw java.lang.OutOfMemoryError; that's fine for this test } System.gc(); assertNull(FileResourceRepository.getCached(dir)); } finally { FileUtil.delete(dir); } }
@Override public void resolve(Project project, MavenProject mavenProject, NativeMavenProjectHolder nativeMavenProject, MavenEmbedderWrapper embedder, ResolveContext context) throws MavenProcessCanceledException { String version = getVersion(mavenProject); if (version != null) { List<MavenRemoteRepository> repos = mavenProject.getRemoteRepositories(); MavenArtifactInfo artifactInfo = new MavenArtifactInfo("com.google.appengine", "appengine-java-sdk", version, "zip", null); MavenArtifact artifact = embedder.resolve(artifactInfo, repos); File file = artifact.getFile(); File unpackedSdkPath = new File(file.getParentFile(), "appengine-java-sdk"); if (file.exists() && !AppEngineSdkUtil.checkPath(FileUtil.toSystemIndependentName(unpackedSdkPath.getAbsolutePath())).isOk()) { try { ZipUtil.extract(file, unpackedSdkPath, null, false); } catch (IOException e) { MavenLog.LOG.warn("cannot unpack AppEngine SDK", e); } } } }
@Test public void testDirIsIgnored() throws Exception { //final String dirPath1 = myClientRoot.getPath() + "/a"; final File dir = new File(myClientRoot, "a"); dir.mkdir(); final File innerDir = new File(dir, "innerDir"); innerDir.mkdir(); final File file1 = new File(innerDir, "file1"); final File file2 = new File(innerDir, "file2"); file1.createNewFile(); file2.createNewFile(); final VirtualFile innerVf = myLocalFileSystem.refreshAndFindFileByIoFile(innerDir); final VirtualFile vf1 = myLocalFileSystem.refreshAndFindFileByIoFile(file1); final VirtualFile vf2 = myLocalFileSystem.refreshAndFindFileByIoFile(file2); final IgnoredFileBean ignoredFileBean = IgnoredBeanFactory.ignoreUnderDirectory(FileUtil.toSystemIndependentName(dir.getPath()), myProject); myChangeListManager.addFilesToIgnore(ignoredFileBean); dirty(); assertFoundAndIgnored(innerVf); assertFoundAndIgnored(vf1); assertFoundAndIgnored(vf2); }
private String shortenName(@NotNull String name) { final Matcher matcher = PYTHON_PATTERN.matcher(name); if (matcher.matches()) { String path = matcher.group(2); if (path != null) { name = matcher.group(1) + " at " + path; } else { path = matcher.group(4); final int index = path.lastIndexOf(File.separator); if (index > 0) { path = path.substring(index); } name = matcher.group(3) + " at ..." + path; } } else if (new File(name).exists()) { name = FileUtil.getLocationRelativeToUserHome(name); } return name; }
public String getFullLog(final File... baseDirs) { return StringUtil.join(myLogLines, new Function<String, String>() { @Override public String fun(String s) { for (File dir : baseDirs) { if (dir != null) { String path = FileUtil.toSystemIndependentName(dir.getAbsolutePath()) + "/"; if (s.startsWith(path)) { return s.substring(path.length()); } } } return s; } }, "\n"); }
private static void damageFile(MavenIndex index, String fileName, boolean fullDamage) throws IOException { File cachesDir = index.getCurrentDataDir(); File file = new File(cachesDir, fileName); assertTrue(file.exists()); if (fullDamage) { FileWriter w = new FileWriter(file); w.write("bad content"); w.close(); } else { byte[] content = FileUtil.loadFileBytes(file); for (int i = 0; i < content.length; i+=2) { content[i] = -1; } FileUtil.writeToFile(file, content); } }
/** * Return true if there is executable code in the class */ private boolean collectNonCoveredClassInfo(final File classFile, @Nullable PsiClass psiClass, final ClassCoverageInfo classCoverageInfo, final PackageCoverageInfo packageCoverageInfo) { final byte[] content = myCoverageManager.doInReadActionIfProjectOpen(new Computable<byte[]>() { public byte[] compute() { try { return FileUtil.loadFileBytes(classFile); } catch (IOException e) { return null; } } }); final CoverageSuitesBundle coverageSuite = CoverageDataManager.getInstance(myProject).getCurrentSuitesBundle(); if (coverageSuite == null) return false; return SourceLineCounterUtil .collectNonCoveredClassInfo(classCoverageInfo, packageCoverageInfo, content, coverageSuite.isTracingEnabled(), psiClass); }
protected String loadFile(String name, String resultNumber) throws Exception { String fullName = getTestDataPath() + File.separatorChar + getBasePath() + File.separatorChar + name; String text = FileUtil.loadFile(new File(fullName)); text = StringUtil.convertLineSeparators(text); if (resultNumber == null) { return prepareText(text); } else { String beginLine = "<<<" + resultNumber + ">>>"; String endLine = "<<</" + resultNumber + ">>>"; int beginPos = text.indexOf(beginLine); assertTrue(beginPos >= 0); int endPos = text.indexOf(endLine); assertTrue(endPos >= 0); return prepareText(text.substring(beginPos + beginLine.length(), endPos).trim()); } }
private static List<IdeaPluginDescriptor> process(@Nullable String repositoryUrl, List<IdeaPluginDescriptor> list) { for (Iterator<IdeaPluginDescriptor> i = list.iterator(); i.hasNext(); ) { PluginNode node = (PluginNode)i.next(); if (node.getPluginId() == null || repositoryUrl != null && node.getDownloadUrl() == null) { LOG.warn("Malformed plugin record (id:" + node.getPluginId() + " repository:" + repositoryUrl + ")"); i.remove(); continue; } if (repositoryUrl != null) { node.setRepositoryName(repositoryUrl); } if (node.getName() == null) { String url = node.getDownloadUrl(); String name = FileUtil.getNameWithoutExtension(url.substring(url.lastIndexOf('/') + 1)); node.setName(name); } } return list; }
private File testCheckoutImpl(final String url) throws IOException { final File root = FileUtil.createTempDirectory("checkoutRoot", ""); root.deleteOnExit(); Assert.assertTrue(root.exists()); SvnCheckoutProvider .checkout(myProject, root, url, SVNRevision.HEAD, Depth.INFINITY, false, new CheckoutProvider.Listener() { @Override public void directoryCheckedOut(File directory, VcsKey vcs) { } @Override public void checkoutCompleted() { } }, WorkingCopyFormat.ONE_DOT_SEVEN); final int[] cnt = new int[1]; cnt[0] = 0; FileUtil.processFilesRecursively(root, new Processor<File>() { @Override public boolean process(File file) { ++ cnt[0]; return ! (cnt[0] > 1); } }); Assert.assertTrue(cnt[0] > 1); return root; }
/** * @param files the first file will be loaded in editor */ protected VirtualFile configureByFiles(@Nullable String projectRoot, @NotNull String... files) throws Exception { if (files.length == 0) return null; final VirtualFile[] vFiles = new VirtualFile[files.length]; for (int i = 0; i < files.length; i++) { String path = files[i]; final String fullPath = FileUtil.toSystemIndependentName(getTestDataPath() + path); allowRootAccess(fullPath); VirtualFile vFile = LocalFileSystem.getInstance().findFileByPath(fullPath); vFiles[i] = vFile; assertNotNull("file " + fullPath + " not found", vFile); } File projectFile = projectRoot == null ? null : new File(getTestDataPath() + projectRoot); return configureByFiles(projectFile, vFiles); }
public void uninstall(@NotNull List<PyPackage> packages) throws ExecutionException { final List<String> args = new ArrayList<String>(); try { args.add(UNINSTALL); boolean canModify = true; for (PyPackage pkg : packages) { if (canModify) { final String location = pkg.getLocation(); if (location != null) { canModify = FileUtil.ensureCanCreateFile(new File(location)); } } args.add(pkg.getName()); } getHelperResult(PACKAGING_TOOL, args, !canModify, true, null); } catch (PyExecutionException e) { throw new PyExecutionException(e.getMessage(), "pip", args, e.getStdout(), e.getStderr(), e.getExitCode(), e.getFixes()); } finally { clearCaches(); } }
@Nullable @Override public List<File> getProguardConfigFiles(@NotNull JpsModule module) throws IOException { final JpsSdk<JpsSimpleElement<JpsAndroidSdkProperties>> sdk = module.getSdk(JpsAndroidSdkType.INSTANCE); final String sdkHomePath = sdk != null ? FileUtil.toSystemIndependentName(sdk.getHomePath()) : null; final List<String> urls = myProperties.myProGuardCfgFiles; if (urls == null) { return null; } if (urls.isEmpty()) { return Collections.emptyList(); } final List<File> result = new ArrayList<File>(); for (String url : urls) { if (sdkHomePath != null) { url = StringUtil.replace(url, AndroidCommonUtils.SDK_HOME_MACRO, sdkHomePath); } result.add(JpsPathUtil.urlToFile(url)); } return result; }
public void setValueAt(Object value, int rowIndex, int columnIndex) { if (columnIndex == DIRNAME_COLUMN_INDEX) { final Module module = myElements.get(rowIndex); if (value != null) { String dir = FileUtil.toSystemIndependentName((String)value); while (dir.startsWith("/")) { dir = dir.substring(1); } if (dir.length() > 0) { myDirNameMap.put(module, dir); } else { myDirNameMap.remove(module); } } else { myDirNameMap.remove(module); } fireTableRowsUpdated(rowIndex, rowIndex); } }
public void saveMaps() throws IOException{ File dir = getMapDirectory(); if (dir == null) { return; } File[] files = getMapFiles(); @NonNls String[] filePaths = new String[myMaps.size()]; Document[] documents = new Document[myMaps.size()]; UniqueNameGenerator namesProvider = new UniqueNameGenerator(); for(int i = 0; i < myMaps.size(); i++){ MigrationMap map = myMaps.get(i); filePaths[i] = dir + File.separator + namesProvider.generateUniqueName(FileUtil.sanitizeFileName(map.getName(), false)) + ".xml"; documents[i] = saveMap(map); } JDOMUtil.updateFileSet(files, filePaths, documents, CodeStyleSettingsManager.getSettings(null).getLineSeparator()); }
private static List<VirtualFile> getBundledGdslFiles() { final List<VirtualFile> result = ContainerUtil.newArrayList(); for (File file : getBundledScriptFolders()) { if (file.exists()) { File[] children = file.listFiles(); if (children != null) { for (File child : children) { final String fileName = child.getName(); if (fileName.endsWith(".gdsl")) { String path = FileUtil.toSystemIndependentName(child.getPath()); String url = VirtualFileManager.constructUrl(URLUtil.FILE_PROTOCOL, path); ContainerUtil.addIfNotNull(result, VirtualFileManager.getInstance().refreshAndFindFileByUrl(url)); } } } } } return result; }
private void extractTests(final File traceFile, final DataInputStream in, final Set<String> tests) throws IOException { long traceSize = in.readInt(); for (int i = 0; i < traceSize; i++) { final String className = in.readUTF(); final int linesSize = in.readInt(); for(int l = 0; l < linesSize; l++) { final int line = in.readInt(); if (Comparing.strEqual(className, myClassFQName)) { if (myLineData.getLineNumber() == line) { tests.add(FileUtil.getNameWithoutExtension(traceFile)); return; } } } } }
@Override public void choose(@Nullable final VirtualFile toSelect, @NotNull final Consumer<List<VirtualFile>> callback) { ExtensionsInitializer.initialize(); myCallback = callback; myModalityState = ModalityState.current(); final VirtualFile lastOpenedFile = FileChooserUtil.getLastOpenedFile(myProject); final VirtualFile selectFile = FileChooserUtil.getFileToSelect(myChooserDescriptor, myProject, toSelect, lastOpenedFile); final String selectPath = selectFile != null ? FileUtil.toSystemDependentName(selectFile.getPath()) : null; //noinspection SSBasedInspection SwingUtilities.invokeLater(new Runnable() { @Override public void run() { showNativeChooserAsSheet(MacFileChooserDialogImpl.this, selectPath); } }); }
public void storeNonexistentOutputRoots(CompileContext context) throws IOException { Collection<File> outputRoots = myTarget.getOutputRoots(context); List<String> nonexistentOutputRoots = new SmartList<String>(); for (File root : outputRoots) { if (!root.exists()) { nonexistentOutputRoots.add(root.getAbsolutePath()); } } File file = getNonexistentOutputsFile(); if (nonexistentOutputRoots.isEmpty()) { file.delete(); } else { FileUtil.writeToFile(file, StringUtil.join(nonexistentOutputRoots, "\n")); } }
@Override public void configure( @NotNull final ModifiableFacetModel modifiableFacetModel, @NotNull final HybrisModuleDescriptor moduleDescriptor, @NotNull final Module javaModule, @NotNull final ModifiableRootModel modifiableRootModel ) { final File webRoot = moduleDescriptor.getWebRoot(); if (null == webRoot) { return; } WebFacet webFacet = modifiableFacetModel.getFacetByType(WebFacet.ID); if (webFacet == null) { final FacetType<WebFacet, FacetConfiguration> webFacetType = FacetTypeRegistry.getInstance().findFacetType( WebFacet.ID ); if (!webFacetType.isSuitableModuleType(ModuleType.get(javaModule))) { return; } webFacet = FacetManager.getInstance(javaModule).createFacet( webFacetType, webFacetType.getDefaultFacetName(), null ); modifiableFacetModel.addFacet(webFacet); } else { webFacet.removeAllWebRoots(); webFacet.getDescriptorsContainer().getConfiguration().removeConfigFiles( DeploymentDescriptorsConstants.WEB_XML_META_DATA ); } webFacet.setWebSourceRoots(modifiableRootModel.getSourceRootUrls(false)); webFacet.addWebRootNoFire(VfsUtil.pathToUrl(FileUtil.toSystemIndependentName(webRoot.getAbsolutePath())), "/"); this.setupFacetDeploymentDescriptor(webFacet, moduleDescriptor); }
@Override public <T extends RunConfigurationBase> void updateJavaParameters( final T configuration, final JavaParameters params, final RunnerSettings runnerSettings ) throws ExecutionException { if (runnerSettings != null || !isApplicableFor(configuration)) { return; } final Project project = configuration.getProject(); final ParametersList vmParameters = params.getVMParametersList(); if (!vmParameters.hasParameter("-ea")) { vmParameters.add("-ea"); } if (vmParameters.getParameters().stream().noneMatch(param -> param.startsWith("-Dplatformhome="))) { final VirtualFile platformRootDirectory = findPlatformRootDirectory(project); if (platformRootDirectory != null) { vmParameters.add("-Dplatformhome=" + platformRootDirectory.getPath()); } } if (!params.getEnv().containsKey(HYBRIS_DATA_DIR_ENV)) { final HybrisProjectSettings settings = HybrisProjectSettingsComponent.getInstance(project).getState(); final String hybrisDataDirPath = FileUtil.toCanonicalPath( project.getBasePath() + '/' + settings.getHybrisDirectory() + '/' + HybrisConstants.HYBRIS_DATA_DIRECTORY); if (hybrisDataDirPath != null) { params.addEnv(HYBRIS_DATA_DIR_ENV, hybrisDataDirPath); } } }
@Override @Nullable public File findFileByNameInDirectory( @NotNull final File directory, @NotNull final String fileName, @Nullable final TaskProgressProcessor<File> progressListenerProcessor ) throws InterruptedException { Validate.notNull(directory); Validate.isTrue(directory.isDirectory()); Validate.notNull(fileName); final Ref<File> result = Ref.create(); final Ref<Boolean> interrupted = Ref.create(false); FileUtil.processFilesRecursively(directory, file -> { if (progressListenerProcessor != null && !progressListenerProcessor.shouldContinue(directory)) { interrupted.set(true); return false; } if (StringUtils.endsWith(file.getAbsolutePath(), fileName)) { result.set(file); return false; } return true; }); if (interrupted.get()) { throw new InterruptedException("Modules scanning has been interrupted."); } return result.get(); }