Example usage for org.eclipse.jgit.util FileUtils createNewFile

List of usage examples for org.eclipse.jgit.util FileUtils createNewFile

Introduction

In this page you can find the example usage for org.eclipse.jgit.util FileUtils createNewFile.

Prototype

public static void createNewFile(File f) throws IOException 

Source Link

Document

Atomically creates a new, empty file named by this abstract pathname if and only if a file with this name does not yet exist.

Usage

From source file:MySmartApply.java

License:Eclipse Distribution License

private File getFile(String path, boolean create) throws PatchApplyException {
    File f = new File(this.local_path + path);
    if (create)/*w ww  .  ja v  a  2s  . c  o  m*/
        try {
            File parent = f.getParentFile();
            FileUtils.mkdirs(parent, true);
            FileUtils.createNewFile(f);
        } catch (IOException e) {
            throw new PatchApplyException(MessageFormat.format(JGitText.get().createNewFileFailed, f), e);
        }
    return f;
}

From source file:org.eclipse.egit.core.test.op.CloneOperationTest.java

License:Open Source License

@Before
public void setUp() throws Exception {
    workdir = testUtils.createTempDir("Repository1");
    workdir2 = testUtils.createTempDir("Repository2");

    repository1 = new TestRepository(new File(workdir, Constants.DOT_GIT));

    File file = new File(workdir, "file1.txt");
    FileUtils.createNewFile(file);
    Git git = new Git(repository1.getRepository());
    git.add().addFilepattern("file1.txt").call();

    git.commit().setMessage("first commit").call();
}

From source file:org.eclipse.egit.ui.internal.synchronize.compare.LocalNonWorkspaceTypedElement.java

License:Open Source License

/** {@inheritDoc} */
@Override//from   w w w.ja  v a2  s  .com
public void commit(IProgressMonitor monitor) throws CoreException {
    if (isDirty()) {
        if (isConnected()) {
            super.commit(monitor);
        } else {
            FileOutputStream out = null;
            File file = path.toFile();
            try {
                if (!file.exists())
                    FileUtils.createNewFile(file);
                out = new FileOutputStream(file);
                out.write(getContent());
                fDirty = false;
            } catch (IOException e) {
                throw new CoreException(new Status(IStatus.ERROR, Activator.getPluginId(),
                        UIText.LocalNonWorkspaceTypedElement_errorWritingContents, e));
            } finally {
                fireContentChanged();
                RepositoryMapping mapping = RepositoryMapping.getMapping(path);
                if (mapping != null)
                    mapping.getRepository().fireEvent(new IndexChangedEvent());
                if (out != null)
                    try {
                        out.close();
                    } catch (IOException ex) {
                    }
            }
        }
    }
}

From source file:org.eclipse.emf.compare.diagram.papyrus.tests.egit.fixture.GitTestRepository.java

License:Open Source License

/**
 * Create a file or get an existing one//from ww w.j  a  va  2s.  c o  m
 *
 * @param project
 *            instance of project inside with file will be created
 * @param name
 *            name of file
 * @return nearly created file
 * @throws IOException
 */
public File createFile(IProject project, String name) throws IOException {
    String path = project.getLocation().append(name).toOSString();
    int lastSeparator = path.lastIndexOf(File.separator);
    FileUtils.mkdirs(new File(path.substring(0, lastSeparator)), true);

    File file = new File(path);
    if (!file.exists()) {
        FileUtils.createNewFile(file);
    }

    return file;
}

From source file:org.jboss.tools.openshift.egit.internal.test.util.TestRepository.java

License:Open Source License

/**
 * create an initial commit containing a file "dummy" in the
 * /*  w  ww .j  a v a  2  s.  c om*/
 * @param message
 *            commit message
 * @return commit object
 * @throws IOException
 * @throws JGitInternalException
 * @throws GitAPIException 
 */
public RevCommit createInitialCommit(String message)
        throws IOException, JGitInternalException, GitAPIException {
    String repoPath = repository.getWorkTree().getAbsolutePath();
    File file = new File(repoPath, "dummy");
    if (!file.exists())
        FileUtils.createNewFile(file);
    add(file);
    return commit(message);
}

From source file:org.jboss.tools.openshift.egit.internal.test.util.TestRepository.java

License:Open Source License

/**
 * Create a file or get an existing one/*  www.  j a  va 2s . c  om*/
 * 
 * @param project
 *            instance of project inside with file will be created
 * @param name
 *            name of file
 * @return nearly created file
 * @throws IOException
 */
public File createFile(IProject project, String name) throws IOException {
    String path = project.getLocation().append(name).toOSString();
    int lastSeparator = path.lastIndexOf(File.separator);
    FileUtils.mkdirs(new File(path.substring(0, lastSeparator)), true);

    File file = new File(path);
    if (!file.exists())
        FileUtils.createNewFile(file);

    return file;
}