public void testIndexWithEmptyContent() throws Exception { File tmpDir = null; try { String src = "\n"; // Generate some files to index! tmpDir = new File( FileUtil.getTempDirectory().toOSString(), "testIndexWithEmptyContent" + System.currentTimeMillis()); tmpDir.mkdirs(); File coffeeFile = new File(tmpDir, "index_me.coffee"); IOUtil.write(new FileOutputStream(coffeeFile), src); IFileStore fileStore = EFS.getStore(coffeeFile.toURI()); BuildContext context = new FileStoreBuildContext(fileStore); IProgressMonitor monitor = new NullProgressMonitor(); indexer.index(context, null, monitor); } finally { // Clean up the generated files! FileUtil.deleteRecursively(tmpDir); } }
protected void perfValidate(String filename, int iterations) throws Exception { // read in the file InputStream in = FileLocator.openStream( Platform.getBundle(JSCorePlugin.PLUGIN_ID), Path.fromPortableString("performance/" + filename), false); IFile file = project.createFile(filename, IOUtil.read(in)); RebuildIndexJob job = new RebuildIndexJob(project.getURI()); job.run(null); // Ok now actually validate the thing, the real work for (int i = 0; i < iterations; i++) { EditorTestHelper.joinBackgroundActivities(); BuildContext context = new BuildContext(file); // Don't measure reading in string... context.getContents(); startMeasuring(); validator.buildFile(context, null); stopMeasuring(); } commitMeasurements(); assertPerformance(); }
/** * @param file the ChangedFile to generate a diff for. * @param staged Whether the file is staged or not * @param contextLines number of lines to show context for. default for underlying command is 3. * @return */ public String diffForFile(ChangedFile file, boolean staged, int contextLines) { if (hasBinaryAttributes(file)) { return Messages.GitIndex_BinaryDiff_Message; } String parameter = "-U" + contextLines; // $NON-NLS-1$ if (staged) { String indexPath = ":0:" + file.portablePath; // $NON-NLS-1$ if (file.status == ChangedFile.Status.NEW) { IStatus status = repository.execute(GitRepository.ReadWrite.READ, "show", indexPath); // $NON-NLS-1$ return status.getMessage(); } IStatus result = repository.execute( GitRepository.ReadWrite.READ, "diff-index", parameter, "--cached", //$NON-NLS-1$ //$NON-NLS-2$ GitRepository.HEAD, "--", file.portablePath); //$NON-NLS-1$ if (result == null || !result.isOK()) { return null; } return result.getMessage(); } // unstaged if (file.status == ChangedFile.Status.NEW) { try { return IOUtil.read( new FileInputStream(workingDirectory().append(file.portablePath).toFile()), IOUtil.UTF_8); // $codepro.audit.disable // closeWhereCreated } catch (FileNotFoundException e) { return null; } } IStatus result = repository.execute( GitRepository.ReadWrite.READ, "diff-files", parameter, "--", file.portablePath); //$NON-NLS-1$ //$NON-NLS-2$ return result.getMessage(); }
protected String getContent(String path) { try { InputStream stream = FileLocator.openStream( Platform.getBundle("com.aptana.xml.core.tests"), Path.fromPortableString(path), false); return IOUtil.read(stream); } catch (IOException e) { fail(e.getMessage()); // never reached... return StringUtil.EMPTY; } }
public void testMatchingRemoteBranchWithImplicitlyTrackedBranch() throws Exception { // Must be at least one file for us to be able to get branches and add them properly! testAddFileStageUnstageAndCommit(); GitRepository repo = getRepo(); assertCurrentBranch("master"); assertNull( "Expected to get no matching remote branch for 'master', but did", repo.matchingRemoteBranch("master")); // Grab HEAD SHA File masterSHA = repo.workingDirectory() .append(GitRepository.GIT_DIR) .append("refs") .append("heads") .append("master") .toFile(); String sha = IOUtil.read(new FileInputStream(masterSHA)); // Write that SHA to the remotes/origin/master ref File ref = repo.workingDirectory() .append(GitRepository.GIT_DIR) .append("refs") .append("remotes") .append("origin") .append("master") .toFile(); ref.getParentFile().mkdirs(); FileWriter writer = new FileWriter(ref, true); writer.append(sha); writer.close(); // Force reload of refs repo.hasChanged(); repo.lazyReload(); // Now make sure we try implicit tracking assertEquals( "Expected to get matching remote branch for 'master'", GitRef.refFromString(GitRef.REFS_REMOTES + "origin/master"), repo.matchingRemoteBranch("master")); }
public void testCommitMessageWithDoubleQuotes() throws Throwable { GitRepository repo = createRepo(); GitIndex index = repo.index(); assertTrue(index.changedFiles().isEmpty()); // Actually add a file to the location FileWriter writer = new FileWriter(fileToAdd()); writer.write("Hello World!"); writer.close(); // refresh the index index.refresh(new NullProgressMonitor()); // Now there should be a single file that's been changed! List<ChangedFile> changed = index.changedFiles(); assertEquals( "Repository changed file listing should contain one entry for the new file, but does not", 1, changed.size()); // Make sure it's shown as having unstaged changes only and is NEW assertNewUnstagedFile(changed.get(0)); // stage assertStageFiles(index, changed); assertNewStagedFile(changed.get(0)); // commit final String commitMessage = "Initial commit with \"double quotes\" inside the message!"; assertCommit(index, commitMessage); // now grab the resulting log to see if the message escaped the quotes too many times! File file = repo.gitFile(GitRepository.COMMIT_EDITMSG); FileInputStream stream = null; try { stream = new FileInputStream(file); String result = IOUtil.read(stream); assertEquals(commitMessage + "\n", result); } finally { if (stream != null) { stream.close(); } } }
public void testLongOneLiner() throws Exception { // read in the file InputStream stream = FileLocator.openStream( Platform.getBundle("com.aptana.editor.json.tests"), // $NON-NLS-1$ Path.fromPortableString("performance/api-aptana-format.json"), false); //$NON-NLS-1$ String src = IOUtil.read(stream); IDocument document = new Document(src); // Ok now actually scan the thing, the real work for (int i = 0; i < 15; i++) { startMeasuring(); fScanner.setRange(document, 0, src.length()); while (fScanner.nextToken() != Token.EOF) { fScanner.getTokenOffset(); fScanner.getTokenLength(); } stopMeasuring(); } commitMeasurements(); assertPerformance(); }
/** * getSource * * @param stream * @return * @throws IOException */ private String getSource(InputStream stream) throws IOException { return IOUtil.read(stream); }