Example usage for org.eclipse.jdt.core IJavaProject getUnderlyingResource

List of usage examples for org.eclipse.jdt.core IJavaProject getUnderlyingResource

Introduction

In this page you can find the example usage for org.eclipse.jdt.core IJavaProject getUnderlyingResource.

Prototype

IResource getUnderlyingResource() throws JavaModelException;

Source Link

Document

Returns the smallest underlying resource that contains this element, or null if this element is not contained in a resource.

Usage

From source file:com.google.gdt.eclipse.designer.wizards.model.common.ClientPackageSelectionDialogField.java

License:Open Source License

/**
 * Return strings presentation of package.
 *///from ww  w.  j a v  a2s. c o m
private static String getPackageString(IPackageFragment packageFragment) {
    try {
        if (packageFragment != null) {
            IPackageFragmentRoot packageFragmentRoot = (IPackageFragmentRoot) packageFragment.getParent();
            IJavaProject javaProject = packageFragmentRoot.getJavaProject();
            if (packageFragmentRoot.getUnderlyingResource() == javaProject.getUnderlyingResource()) {
                return javaProject.getElementName() + "/" + packageFragment.getElementName();
            } else {
                return javaProject.getElementName() + "/" + packageFragmentRoot.getElementName() + "/"
                        + packageFragment.getElementName();
            }
        }
        return "";
    } catch (Throwable e) {
        throw ReflectionUtils.propagate(e);
    }
}

From source file:org.eclipse.ajdt.ui.tests.builder.BuilderTest.java

License:Open Source License

/**
 * Test for bug 78579 - creating a new file (non java/aj) in a package
 * copies the file over to the bin directory - deleting it should
 * remove it from the bin directory/*from w  w  w . j av a  2s .  c o m*/
 * 
 * @throws CoreException
 */
public void testCopyAndRemoveNewNonSrcFile() throws CoreException {
    // test setup.....
    IProject simpleProject = createPredefinedProject("AnotherSimpleAJProject"); //$NON-NLS-1$
    IJavaProject javaProject = JavaCore.create(simpleProject);
    waitForJobsToComplete();
    String srcPath = javaProject.getUnderlyingResource().getLocation().toOSString() + File.separator + "src" //$NON-NLS-1$
            + File.separator + "p1" //$NON-NLS-1$
            + File.separator + "newFile.txt"; //$NON-NLS-1$

    String binPath = javaProject.getUnderlyingResource().getLocation().toOSString() + File.separator + "bin" //$NON-NLS-1$
            + File.separator + "p1" //$NON-NLS-1$
            + File.separator + "newFile.txt"; //$NON-NLS-1$

    assertFalse("newFile.txt should not exist under src tree! (path=" + srcPath + ")", //$NON-NLS-1$//$NON-NLS-2$
            new File(srcPath).exists());
    assertFalse("newFile.txt should not exist under bin tree! (path=" + binPath + ")", //$NON-NLS-1$//$NON-NLS-2$
            new File(binPath).exists());

    // start of test
    IFolder src = simpleProject.getFolder("src"); //$NON-NLS-1$
    if (!src.exists()) {
        src.create(true, true, null);
    }
    IFolder p1 = src.getFolder("p1"); //$NON-NLS-1$
    if (!p1.exists()) {
        p1.create(true, true, null);
    }
    assertNotNull("src folder should not be null", src); //$NON-NLS-1$
    assertNotNull("package p1 should not be null", p1); //$NON-NLS-1$

    waitForJobsToComplete();

    IFile newFile = null;

    IFile f = p1.getFile("newFile.txt"); //$NON-NLS-1$
    if (!f.exists()) {
        f.create(new ByteArrayInputStream(new byte[0]), true, null);
    }
    newFile = p1.getFile("newFile.txt"); //$NON-NLS-1$

    waitForJobsToComplete();
    simpleProject.refreshLocal(IResource.DEPTH_INFINITE, null);
    waitForJobsToComplete();
    simpleProject.refreshLocal(IResource.DEPTH_INFINITE, null);
    waitForJobsToComplete();

    // If either of these fail, then it's more likely than not to be
    // down to the timings of driving this programatically (this is
    // why there is a sleep above.
    assertTrue("newFile.txt should exist under src tree! (path=" + srcPath + ")", new File(srcPath).exists()); //$NON-NLS-1$ //$NON-NLS-2$
    assertTrue("newFile.txt should exist under bin tree! (path=" + binPath + ")", new File(binPath).exists()); //$NON-NLS-1$ //$NON-NLS-2$

    // check that the .java file hasn't been copied over...
    String binPathToMain = javaProject.getUnderlyingResource().getLocation().toOSString() + File.separator
            + "bin" + File.separator + "p1" //$NON-NLS-1$ //$NON-NLS-2$
            + File.separator + "Main.java"; //$NON-NLS-1$
    assertFalse("Main.java should not exist under bin tree! (path=" + binPathToMain + ")", //$NON-NLS-1$//$NON-NLS-2$
            new File(binPathToMain).exists());

    // now delete the file
    newFile.delete(true, null);
    waitForJobsToComplete();

    simpleProject.refreshLocal(IResource.DEPTH_INFINITE, null);
    waitForJobsToComplete();

    // If either of these fail, then it's more likely than not to be
    // down to the timings of driving this programatically (this is
    // why there is a sleep above.
    assertFalse("newFile.txt should NOT exist under src tree! (path=" + srcPath + ")", //$NON-NLS-1$//$NON-NLS-2$
            new File(srcPath).exists());
    waitForJobsToComplete();
    simpleProject.refreshLocal(IResource.DEPTH_INFINITE, null);
    waitForJobsToComplete();
    assertFalse("newFile.txt should NOT exist under bin tree! (path=" + binPath + ")", //$NON-NLS-1$//$NON-NLS-2$
            new File(binPath).exists());
}

From source file:org.eclipse.ajdt.ui.tests.builder.BuilderTest.java

License:Open Source License

/**
 * Test for bug 78579 - creating a new file (non java/aj) in the default package
 * copies the file over to the bin directory - deleting the file in the src tree
 * should then delete it from the bin dir.
 * /*from w  w w .j av  a  2s  . com*/
 * @throws CoreException
 */
public void testCreateAndRemoveNewNonSrcFileFromDefaultPackage() throws CoreException {
    IProject simpleProject = createPredefinedProject("AnotherSimpleAJProject"); //$NON-NLS-1$

    IJavaProject javaProject = JavaCore.create(simpleProject);
    waitForJobsToComplete();

    String srcPath = javaProject.getUnderlyingResource().getLocation().toOSString() + File.separator + "src" //$NON-NLS-1$
            + File.separator + "newFile2.txt"; //$NON-NLS-1$

    String binPath = javaProject.getUnderlyingResource().getLocation().toOSString() + File.separator + "bin" //$NON-NLS-1$
            + File.separator + "newFile2.txt"; //$NON-NLS-1$

    assertFalse("newFile2.txt should not exist under src tree! (path=" + srcPath + ")", //$NON-NLS-1$//$NON-NLS-2$
            new File(srcPath).exists());
    assertFalse("newFile2.txt should not exist under bin tree! (path=" + binPath + ")", //$NON-NLS-1$//$NON-NLS-2$
            new File(binPath).exists());

    IFolder src = simpleProject.getFolder("src"); //$NON-NLS-1$
    if (!src.exists()) {
        src.create(true, true, null);
    }
    assertNotNull("src folder should not be null", src); //$NON-NLS-1$

    waitForJobsToComplete();

    IFile newFile = null;
    IFile f = src.getFile("newFile2.txt"); //$NON-NLS-1$
    if (!f.exists()) {
        f.create(new ByteArrayInputStream(new byte[0]), true, null);
    }
    newFile = src.getFile("newFile2.txt"); //$NON-NLS-1$

    simpleProject.refreshLocal(IResource.DEPTH_INFINITE, null);
    waitForJobsToComplete();

    simpleProject.refreshLocal(IResource.DEPTH_INFINITE, null);
    waitForJobsToComplete();

    // If either of these fail, then it's more likely than not to be
    // down to the timings of driving this programatically (this is
    // why there is a sleep above.
    assertTrue("newFile2.txt should exist under src tree! (path=" + srcPath + ")", new File(srcPath).exists()); //$NON-NLS-1$ //$NON-NLS-2$
    waitForJobsToComplete();
    assertTrue("newFile2.txt should exist under bin tree! (path=" + binPath + ")", new File(binPath).exists()); //$NON-NLS-1$ //$NON-NLS-2$

    // check that the .java file hasn't been copied over...
    String binPathToMain = javaProject.getUnderlyingResource().getLocation().toOSString() + File.separator
            + "bin" + File.separator + "p1" //$NON-NLS-1$ //$NON-NLS-2$
            + File.separator + "Main.java"; //$NON-NLS-1$
    assertFalse("Main.java should not exist under bin tree! (path=" + binPathToMain + ")", //$NON-NLS-1$//$NON-NLS-2$
            new File(binPathToMain).exists());

    // now delete the file for cleanup
    newFile.delete(true, null);
    waitForJobsToComplete();

    // If either of these fail, then it's more likely than not to be
    // down to the timings of driving this programatically (this is
    // why there is a sleep above.
    assertFalse("newFile2.txt should NOT exist under src tree! (path=" + srcPath + ")", //$NON-NLS-1$//$NON-NLS-2$
            new File(srcPath).exists());
    waitForJobsToComplete();
    assertFalse("newFile2.txt should NOT exist under bin tree! (path=" + binPath + ")", //$NON-NLS-1$//$NON-NLS-2$
            new File(binPath).exists());
}

From source file:org.eclipse.ajdt.ui.tests.builder.BuilderTest.java

License:Open Source License

/**
 * Test for bug 78579 - creating a new file (non java/aj) in a package
 * copies the file over to the bin directory - when there are multiple
 * src dirs. Deleting this file should then remove it from the bin dir.
 * //from  www. ja va 2s  .co  m
 * @throws CoreException
 */
public void testCopyAndRemoveNewNonSrcFileWithMultipleSrcDirs() throws CoreException {
    IProject simpleProject = createPredefinedProject("MultipleSourceFolders"); //$NON-NLS-1$
    IJavaProject javaProject = JavaCore.create(simpleProject);
    waitForJobsToComplete();

    String srcPath = javaProject.getUnderlyingResource().getLocation().toOSString() + File.separator + "src2" //$NON-NLS-1$
            + File.separator + "pack" //$NON-NLS-1$
            + File.separator + "newFile.txt"; //$NON-NLS-1$

    String binPath = javaProject.getUnderlyingResource().getLocation().toOSString() + File.separator + "bin" //$NON-NLS-1$
            + File.separator + "pack" //$NON-NLS-1$
            + File.separator + "newFile.txt"; //$NON-NLS-1$
    assertFalse("newFile.txt should not exist under src tree! (path=" + srcPath + ")", //$NON-NLS-1$//$NON-NLS-2$
            new File(srcPath).exists());
    assertFalse("newFile.txt should not exist under bin tree! (path=" + binPath + ")", //$NON-NLS-1$//$NON-NLS-2$
            new File(binPath).exists());

    IFolder src2 = simpleProject.getFolder("src2"); //$NON-NLS-1$
    if (!src2.exists()) {
        src2.create(true, true, null);
    }
    IFolder pack = src2.getFolder("pack"); //$NON-NLS-1$
    if (!pack.exists()) {
        pack.create(true, true, null);
    }
    assertNotNull("src2 folder should not be null", src2); //$NON-NLS-1$
    assertNotNull("package pack should not be null", pack); //$NON-NLS-1$

    waitForJobsToComplete();

    IFile newFile = null;
    IFile f = pack.getFile("newFile.txt"); //$NON-NLS-1$
    if (!f.exists()) {
        f.create(new ByteArrayInputStream(new byte[0]), true, null);
    }
    newFile = pack.getFile("newFile.txt"); //$NON-NLS-1$

    waitForJobsToComplete();
    simpleProject.refreshLocal(IResource.DEPTH_INFINITE, null);
    waitForJobsToComplete();

    // If either of these fail, then it's more likely than not to be
    // down to the timings of driving this programatically (this is
    // why there is a sleep above.
    assertTrue("newFile.txt should exist under src2 tree! (path=" + srcPath + ")", new File(srcPath).exists()); //$NON-NLS-1$ //$NON-NLS-2$
    waitForJobsToComplete();
    assertTrue("newFile.txt should exist under bin tree! (path=" + binPath + ")", new File(binPath).exists()); //$NON-NLS-1$ //$NON-NLS-2$

    // check that the .java file hasn't been copied over...
    String binPathToMain = javaProject.getUnderlyingResource().getLocation().toOSString() + File.separator
            + "bin" + File.separator + "pack" //$NON-NLS-1$ //$NON-NLS-2$
            + File.separator + "Class3.java"; //$NON-NLS-1$
    assertFalse("Class3.java should not exist under bin tree! (path=" + binPathToMain + ")", //$NON-NLS-1$//$NON-NLS-2$
            new File(binPathToMain).exists());

    // now delete the file for cleanup
    newFile.delete(true, null);
    waitForJobsToComplete();

    // If either of these fail, then it's more likely than not to be
    // down to the timings of driving this programatically (this is
    // why there is a sleep above.
    assertFalse("newFile.txt should NOT exist under src tree! (path=" + srcPath + ")", //$NON-NLS-1$//$NON-NLS-2$
            new File(srcPath).exists());
    waitForJobsToComplete();
    assertFalse("newFile.txt should NOT exist under bin tree! (path=" + binPath + ")", //$NON-NLS-1$//$NON-NLS-2$
            new File(binPath).exists());
}

From source file:org.eclipse.ajdt.ui.tests.builder.BuilderTest.java

License:Open Source License

/**
 * Test for bug 78579 - creating a new file (non java/aj) in a package
 * copies the file over to the bin directory - when the output directory
 * is a non standard one (ie not called "bin").
 * /*from  w w w.ja v a  2  s .  c  om*/
 * @throws CoreException
 */
public void testCopyAndRemoveNewNonSrcFileWithNonStandardOutputDir() throws CoreException {
    IProject simpleProject = createPredefinedProject("NonStandardOutputLocation"); //$NON-NLS-1$

    IJavaProject javaProject = JavaCore.create(simpleProject);
    waitForJobsToComplete();

    String srcPath = javaProject.getUnderlyingResource().getLocation().toOSString() + File.separator + "src" //$NON-NLS-1$
            + File.separator + "pack" //$NON-NLS-1$
            + File.separator + "newFile.txt"; //$NON-NLS-1$

    String binPath = javaProject.getUnderlyingResource().getLocation().toOSString() + File.separator
            + "nonStandardBin" + File.separator + "pack" //$NON-NLS-1$ //$NON-NLS-2$
            + File.separator + "newFile.txt"; //$NON-NLS-1$
    assertFalse("newFile.txt should not exist under src tree! (path=" + srcPath + ")", //$NON-NLS-1$//$NON-NLS-2$
            new File(srcPath).exists());
    assertFalse("newFile.txt should not exist under bin tree! (path=" + binPath + ")", //$NON-NLS-1$//$NON-NLS-2$
            new File(binPath).exists());

    IFolder src = simpleProject.getFolder("src"); //$NON-NLS-1$
    if (!src.exists()) {
        src.create(true, true, null);
    }
    IFolder pack = src.getFolder("pack"); //$NON-NLS-1$
    if (!pack.exists()) {
        pack.create(true, true, null);
    }
    assertNotNull("src folder should not be null", src); //$NON-NLS-1$
    assertNotNull("package pack should not be null", pack); //$NON-NLS-1$

    waitForJobsToComplete();

    IFile newFile = null;
    IFile f = pack.getFile("newFile.txt"); //$NON-NLS-1$
    if (!f.exists()) {
        f.create(new ByteArrayInputStream(new byte[0]), true, null);
    }
    newFile = pack.getFile("newFile.txt"); //$NON-NLS-1$

    waitForJobsToComplete();
    simpleProject.refreshLocal(IResource.DEPTH_INFINITE, null);
    waitForJobsToComplete();

    // If either of these fail, then it's more likely than not to be
    // down to the timings of driving this programatically (this is
    // why there is a sleep above.
    assertTrue("newFile.txt should exist under src2 tree! (path=" + srcPath + ")", new File(srcPath).exists()); //$NON-NLS-1$ //$NON-NLS-2$
    waitForJobsToComplete();
    assertTrue("newFile.txt should exist under bin tree! (path=" + binPath + ")", new File(binPath).exists()); //$NON-NLS-1$ //$NON-NLS-2$

    // check that the .java file hasn't been copied over...
    String binPathToMain = javaProject.getUnderlyingResource().getLocation().toOSString() + File.separator
            + "nonStandardBin" + File.separator + "pack" //$NON-NLS-1$ //$NON-NLS-2$
            + File.separator + "Main.java"; //$NON-NLS-1$
    assertFalse("Main.java should not exist under bin tree! (path=" + binPathToMain + ")", //$NON-NLS-1$//$NON-NLS-2$
            new File(binPathToMain).exists());

    // now delete the file for cleanup
    newFile.delete(true, null);
    waitForJobsToComplete();

    // If either of these fail, then it's more likely than not to be
    // down to the timings of driving this programatically (this is
    // why there is a sleep above.
    assertFalse("newFile.txt should NOT exist under src tree! (path=" + srcPath + ")", //$NON-NLS-1$//$NON-NLS-2$
            new File(srcPath).exists());
    waitForJobsToComplete();
    assertFalse("newFile.txt should NOT exist under bin tree! (path=" + binPath + ")", //$NON-NLS-1$//$NON-NLS-2$
            new File(binPath).exists());
}

From source file:org.eclipse.ajdt.ui.tests.builder.BuilderTest.java

License:Open Source License

/**
 * Test for bug 78579 - updating a nonsrc file (non java/aj) in a package
 * copies over the updated version to the bin dir
 * //from   w  ww .j  a v  a 2  s  .  c o m
 * @throws CoreException
 */
public void testUpdateNonSrcFile() throws CoreException, IOException {
    // create the project and the new file
    IProject simpleProject = createPredefinedProject("AnotherSimpleAJProject"); //$NON-NLS-1$

    IJavaProject javaProject = JavaCore.create(simpleProject);
    waitForJobsToComplete();

    String srcPath = javaProject.getUnderlyingResource().getLocation().toOSString() + File.separator + "src" //$NON-NLS-1$
            + File.separator + "p1" //$NON-NLS-1$
            + File.separator + "newFile4.txt"; //$NON-NLS-1$

    String binPath = javaProject.getUnderlyingResource().getLocation().toOSString() + File.separator + "bin" //$NON-NLS-1$
            + File.separator + "p1" //$NON-NLS-1$
            + File.separator + "newFile4.txt"; //$NON-NLS-1$
    assertFalse("newFile4.txt should not exist under src tree! (path=" + srcPath + ")", //$NON-NLS-1$//$NON-NLS-2$
            new File(srcPath).exists());
    assertFalse("newFile4.txt should not exist under bin tree! (path=" + binPath + ")", //$NON-NLS-1$//$NON-NLS-2$
            new File(binPath).exists());

    IFolder src = simpleProject.getFolder("src"); //$NON-NLS-1$
    if (!src.exists()) {
        src.create(true, true, null);
    }
    IFolder p1 = src.getFolder("p1"); //$NON-NLS-1$
    if (!p1.exists()) {
        p1.create(true, true, null);
    }
    assertNotNull("src folder should not be null", src); //$NON-NLS-1$
    assertNotNull("package p1 should not be null", p1); //$NON-NLS-1$

    waitForJobsToComplete();

    IFile newFile = null;
    IFile f = p1.getFile("newFile4.txt"); //$NON-NLS-1$
    if (!f.exists()) {
        f.create(new ByteArrayInputStream(new byte[0]), true, null);
    }
    newFile = p1.getFile("newFile4.txt"); //$NON-NLS-1$
    simpleProject.refreshLocal(IResource.DEPTH_INFINITE, null);
    waitForJobsToComplete();

    // If either of these fail, then it's more likely than not to be
    // down to the timings of driving this programatically (this is
    // why there is a sleep above.
    assertTrue("newFile4.txt should exist under src tree! (path=" + srcPath + ")", new File(srcPath).exists()); //$NON-NLS-1$ //$NON-NLS-2$
    waitForJobsToComplete();

    assertTrue("newFile4.txt should exist under bin tree! (path=" + binPath + ")", new File(binPath).exists()); //$NON-NLS-1$ //$NON-NLS-2$

    // check that the .java file hasn't been copied over...
    String binPathToMain = javaProject.getUnderlyingResource().getLocation().toOSString() + File.separator
            + "bin" + File.separator + "p1" //$NON-NLS-1$ //$NON-NLS-2$
            + File.separator + "Main.java"; //$NON-NLS-1$
    assertFalse("Main.java should not exist under bin tree! (path=" + binPathToMain + ")", //$NON-NLS-1$//$NON-NLS-2$
            new File(binPathToMain).exists());

    IFolder bin = simpleProject.getFolder("bin"); //$NON-NLS-1$
    if (!bin.exists()) {
        bin.create(true, true, null);
    }
    IFolder binp1 = bin.getFolder("p1"); //$NON-NLS-1$
    if (!binp1.exists()) {
        binp1.create(true, true, null);
    }
    IFile binNewFile = binp1.getFile("newFile4.txt"); //$NON-NLS-1$

    // get the contents of the file - shouldn't be anything in there
    InputStream fileContents = newFile.getContents();
    BufferedReader reader = new BufferedReader(new InputStreamReader(fileContents));
    String line = reader.readLine();
    assertNull("File should not contain anything", line); //$NON-NLS-1$
    reader.close();
    fileContents.close();

    waitForJobsToComplete();

    // get the contents of the file under "bin" tree - should contain nothing
    InputStream fileContents4 = binNewFile.getContents();
    BufferedReader reader4 = new BufferedReader(new InputStreamReader(fileContents4));
    String line4 = reader4.readLine();
    assertNull("File should not contain anything", line4); //$NON-NLS-1$
    reader4.close();
    fileContents4.close();

    waitForJobsToComplete();

    // write "blah blah blah" to the file
    StringBuffer sb = new StringBuffer("blah blah blah"); //$NON-NLS-1$
    StringReader sr = new StringReader(sb.toString());
    newFile.setContents(new ReaderInputStream(sr), IResource.FORCE, null);
    sr.close();

    waitForJobsToComplete();

    // get the contents of the file under "src" tree - should contain "blah blah blah"
    InputStream fileContents2 = newFile.getContents();
    BufferedReader reader2 = new BufferedReader(new InputStreamReader(fileContents2));
    String line2 = reader2.readLine();
    assertEquals("file under src should contain 'blah blah blah'", "blah blah blah", line2); //$NON-NLS-1$ //$NON-NLS-2$
    reader2.close();
    fileContents2.close();

    waitForJobsToComplete();

    // get the contents of the file under "bin" tree - should contain "blah blah blah"
    InputStream fileContents3 = binNewFile.getContents();
    BufferedReader reader3 = new BufferedReader(new InputStreamReader(fileContents3));
    String line3 = reader3.readLine();
    assertEquals("file under bin should contain 'blah blah blah'", "blah blah blah", line3); //$NON-NLS-1$ //$NON-NLS-2$
    reader3.close();
    fileContents3.close();
    waitForJobsToComplete();

    // now delete the file for cleanup
    newFile.delete(true, null);
    waitForJobsToComplete();
    // If either of these fail, then it's more likely than not to be
    // down to the timings of driving this programatically (this is
    // why there is a sleep above.
    assertFalse("newFile4.txt should NOT exist under src tree! (path=" + srcPath + ")", //$NON-NLS-1$//$NON-NLS-2$
            new File(srcPath).exists());
    waitForJobsToComplete();
    assertFalse("newFile4.txt should NOT exist under bin tree! (path=" + binPath + ")", //$NON-NLS-1$//$NON-NLS-2$
            new File(binPath).exists());
}

From source file:org.eclipse.ajdt.ui.tests.builder.BuilderTest.java

License:Open Source License

/**
 * Test for bug 78579 - creating a nonsrc file (non java/aj) in a 
 * project which has the same output and src directories
 * //from  www  .j  a  va  2s .c o  m
 * @throws CoreException
 */
public void testCopyAndRemoveResourceWithoutSrcFolder() throws CoreException {
    IProject project = createPredefinedProject("WithoutSourceFolder"); //$NON-NLS-1$

    IJavaProject javaProject = JavaCore.create(project);
    waitForJobsToComplete();

    String path = javaProject.getUnderlyingResource().getLocation().toOSString() + File.separator
            + "newFile.txt"; //$NON-NLS-1$

    assertFalse("newFile.txt should not exist under src tree! (path=" + path + ")", new File(path).exists()); //$NON-NLS-1$ //$NON-NLS-2$

    waitForJobsToComplete();

    IFile newFile = null;
    IFile f = project.getFile("newFile.txt"); //$NON-NLS-1$
    if (!f.exists()) {
        f.create(new ByteArrayInputStream(new byte[0]), true, null);
    }
    newFile = project.getFile("newFile.txt"); //$NON-NLS-1$

    project.refreshLocal(IResource.DEPTH_INFINITE, null);
    waitForJobsToComplete();

    // If this fails, then it's more likely than not to be
    // down to the timings of driving this programatically (this is
    // why there is a sleep above.
    assertTrue("newFile.txt should exist in the top dir (path=" + path + ")", new File(path).exists()); //$NON-NLS-1$ //$NON-NLS-2$

    newFile.delete(true, null);
    waitForJobsToComplete();
    // If this fails, then it's more likely than not to be
    // down to the timings of driving this programatically (this is
    // why there is a sleep above.
    assertFalse("newFile.txt should NOT exist in the top dir(path=" + path + ")", new File(path).exists()); //$NON-NLS-1$ //$NON-NLS-2$
}

From source file:org.eclipse.ajdt.ui.tests.builder.BuilderTest.java

License:Open Source License

/**
 * Test for bug 78579 - when you create a package, this should be copied
 * over to the bin dir. Similarly, when you delete the package, the bin
 * dir should be updated./*from w w w  .j ava2 s. co m*/
 * 
 * @throws Exception
 */
public void testCreateAndDeleteNewPackage() throws Exception {
    IProject simpleProject = createPredefinedProject("AnotherSimpleAJProject"); //$NON-NLS-1$

    IJavaProject javaProject = JavaCore.create(simpleProject);
    waitForJobsToComplete();

    String srcPath = javaProject.getUnderlyingResource().getLocation().toOSString() + File.separator + "src" //$NON-NLS-1$
            + File.separator + "newPackage"; //$NON-NLS-1$

    String binPath = javaProject.getUnderlyingResource().getLocation().toOSString() + File.separator + "bin" //$NON-NLS-1$
            + File.separator + "newPackage"; //$NON-NLS-1$

    IFolder src = simpleProject.getFolder("src"); //$NON-NLS-1$
    if (!src.exists()) {
        src.create(true, true, null);
    }
    waitForJobsToComplete();

    IFolder newPackage = src.getFolder("newPackage"); //$NON-NLS-1$
    assertFalse("newPackage should not exist under src tree! (path=" + srcPath + ")", newPackage.exists()); //$NON-NLS-1$ //$NON-NLS-2$

    IFolder bin = simpleProject.getFolder("bin"); //$NON-NLS-1$
    if (!bin.exists()) {
        bin.create(true, true, null);
    }
    waitForJobsToComplete();
    IFolder newBinPackage = bin.getFolder("newPackage"); //$NON-NLS-1$
    assertFalse("newPackage should not exist under bin tree! (path=" + binPath + ")", newBinPackage.exists()); //$NON-NLS-1$ //$NON-NLS-2$

    waitForJobsToComplete();

    String str = "AnotherSimpleAJProject" + File.separator + "src"; //$NON-NLS-1$ //$NON-NLS-2$
    IPath path = new Path(str);
    IResource res = ResourcesPlugin.getWorkspace().getRoot().findMember(path);
    IPackageFragmentRoot root = javaProject.getPackageFragmentRoot(res);
    root.createPackageFragment("newPackage", true, null); //$NON-NLS-1$

    simpleProject.refreshLocal(IResource.DEPTH_INFINITE, null);
    waitForJobsToComplete();

    // If either of these fail, then it's more likely than not to be
    // down to the timings of driving this programatically (this is
    // why there is a sleep above.
    IFolder newPackage2 = src.getFolder("newPackage"); //$NON-NLS-1$
    assertTrue("newPackage should exist under src tree! (path=" + srcPath + ")", newPackage2.exists()); //$NON-NLS-1$ //$NON-NLS-2$
    waitForJobsToComplete();
    simpleProject.refreshLocal(IResource.DEPTH_INFINITE, null);
    waitForJobsToComplete();
    IFolder newBinPackage2 = bin.getFolder("newPackage"); //$NON-NLS-1$
    assertTrue("newPackage should exist under bin tree! (path=" + binPath + ")", newBinPackage2.exists()); //$NON-NLS-1$ //$NON-NLS-2$
    waitForJobsToComplete();

    newPackage.delete(true, null);
    waitForJobsToComplete();

    // If either of these fail, then it's more likely than not to be
    // down to the timings of driving this programatically (this is
    // why there is a sleep above.
    IFolder newPackage3 = src.getFolder("newPackage"); //$NON-NLS-1$
    assertFalse("newPackage should not exist under src tree! (path=" + srcPath + ")", newPackage3.exists()); //$NON-NLS-1$ //$NON-NLS-2$
    waitForJobsToComplete();
    simpleProject.refreshLocal(IResource.DEPTH_INFINITE, null);
    waitForJobsToComplete();
    IFolder newBinPackage3 = bin.getFolder("newPackage"); //$NON-NLS-1$
    assertFalse("newPackage should not exist under bin tree! (path=" + binPath + ")", newBinPackage3.exists()); //$NON-NLS-1$ //$NON-NLS-2$

    waitForJobsToComplete();
}

From source file:org.eclipse.ajdt.ui.tests.builder.BuilderTest.java

License:Open Source License

public void testCreateAndDeleteNewFolder() throws CoreException {
    IProject simpleProject = createPredefinedProject("AnotherSimpleAJProject"); //$NON-NLS-1$

    IJavaProject javaProject = JavaCore.create(simpleProject);
    waitForJobsToComplete();//from www  .  j a  va  2  s. c om

    String srcPath = javaProject.getUnderlyingResource().getLocation().toOSString() + File.separator + "src" //$NON-NLS-1$
            + File.separator + "newFolder"; //$NON-NLS-1$

    String binPath = javaProject.getUnderlyingResource().getLocation().toOSString() + File.separator + "bin" //$NON-NLS-1$
            + File.separator + "newFolder"; //$NON-NLS-1$
    IFolder src = simpleProject.getFolder("src"); //$NON-NLS-1$
    if (!src.exists()) {
        src.create(true, true, null);
    }
    waitForJobsToComplete();

    IFolder newFolder = src.getFolder("newFolder"); //$NON-NLS-1$
    assertFalse("newFolder should not exist under src tree! (path=" + srcPath + ")", newFolder.exists()); //$NON-NLS-1$ //$NON-NLS-2$

    IFolder bin = simpleProject.getFolder("bin"); //$NON-NLS-1$
    if (!bin.exists()) {
        bin.create(true, true, null);
    }
    waitForJobsToComplete();
    IFolder newBinFolder = bin.getFolder("newFolder"); //$NON-NLS-1$
    assertFalse("newFolder should not exist under bin tree! (path=" + binPath + ")", newBinFolder.exists()); //$NON-NLS-1$ //$NON-NLS-2$

    waitForJobsToComplete();

    IFolder f = src.getFolder("newFolder"); //$NON-NLS-1$
    if (!f.exists()) {
        f.create(true, true, null);
    }

    simpleProject.refreshLocal(IResource.DEPTH_INFINITE, null);
    waitForJobsToComplete();

    // If either of these fail, then it's more likely than not to be
    // down to the timings of driving this programatically (this is
    // why there is a sleep above.
    IFolder newFolder2 = src.getFolder("newFolder"); //$NON-NLS-1$
    assertTrue("newFolder should exist under src tree! (path=" + srcPath + ")", newFolder2.exists()); //$NON-NLS-1$ //$NON-NLS-2$
    waitForJobsToComplete();
    simpleProject.refreshLocal(IResource.DEPTH_INFINITE, null);
    //monitor.waitForCompletion();
    IFolder newBinFolder2 = bin.getFolder("newFolder"); //$NON-NLS-1$
    assertTrue("newFolder should exist under bin tree! (path=" + binPath + ")", newBinFolder2.exists()); //$NON-NLS-1$ //$NON-NLS-2$
    waitForJobsToComplete();

    newFolder.delete(true, null);
    waitForJobsToComplete();
    simpleProject.refreshLocal(IResource.DEPTH_INFINITE, null);
    // If either of these fail, then it's more likely than not to be
    // down to the timings of driving this programatically (this is
    // why there is a sleep above.
    IFolder newFolder3 = src.getFolder("newFolder"); //$NON-NLS-1$
    assertFalse("newFolder should not exist under src tree! (path=" + srcPath + ")", newFolder3.exists()); //$NON-NLS-1$ //$NON-NLS-2$
    waitForJobsToComplete();
    simpleProject.refreshLocal(IResource.DEPTH_INFINITE, null);
    //monitor.waitForCompletion();
    IFolder newBinFolder3 = bin.getFolder("newFolder"); //$NON-NLS-1$
    assertFalse("newFolder should not exist under bin tree! (path=" + binPath + ")", newBinFolder3.exists()); //$NON-NLS-1$ //$NON-NLS-2$
}