/** https://bugs.eclipse.org/bugs/show_bug.cgi?id=400193 */
  @Test
  public void testSourceRelativeOutput() throws Exception {
    IProject project = testHelper.getProject();
    String srcFolder = "/foo/bar/bug";
    JavaProjectSetupUtil.addSourceFolder(JavaCore.create(project), srcFolder);

    String path = srcFolder + "/Foo.xtend";
    String fullFileName = project.getName() + path;
    IFile sourceFile = testHelper.createFileImpl(fullFileName, "class Foo {}");
    assertTrue(sourceFile.exists());
    waitForBuild();

    IFile generatedFile = project.getFile("foo/bar/xtend-gen/Foo.java");
    assertTrue(generatedFile.exists());
    IFile traceFile = testHelper.getProject().getFile("foo/bar/xtend-gen/.Foo.java._trace");
    assertTrue(traceFile.exists());
    IFile classFile = testHelper.getProject().getFile("/bin/Foo.class");
    assertTrue(classFile.exists());

    List<IPath> traceFiles = traceMarkers.findTraceFiles(sourceFile);
    assertTrue(traceFiles.contains(traceFile.getFullPath()));

    sourceFile.delete(false, new NullProgressMonitor());
    waitForBuild();
    assertFalse(generatedFile.exists());
    assertFalse(traceFile.exists());
  }
 @Test
 public void testAddToPlugin() throws Exception {
   pluginProjectFactory.setProjectName("test");
   pluginProjectFactory.addFolders(Collections.singletonList("src"));
   pluginProjectFactory.addBuilderIds(
       JavaCore.BUILDER_ID,
       "org.eclipse.pde.ManifestBuilder",
       "org.eclipse.pde.SchemaBuilder",
       XtextProjectHelper.BUILDER_ID);
   pluginProjectFactory.addProjectNatures(
       JavaCore.NATURE_ID, "org.eclipse.pde.PluginNature", XtextProjectHelper.NATURE_ID);
   IProject project = pluginProjectFactory.createProject(null, null);
   IJavaProject javaProject = JavaCore.create(project);
   JavaProjectSetupUtil.makeJava5Compliant(javaProject);
   IFile file = project.getFile("src/Foo.xtend");
   file.create(
       new StringInputStream(
           "import org.eclipse.xtend.lib.annotations.Accessors class Foo { @Accessors int bar }"),
       true,
       null);
   syncUtil.waitForBuild(null);
   markerAssert.assertErrorMarker(file, IssueCodes.XBASE_LIB_NOT_ON_CLASSPATH);
   adder.addLibsToClasspath(javaProject, null);
   waitForAutoBuild();
   markerAssert.assertNoErrorMarker(file);
 }
 private IJavaProject xtendProject(final String name, final IJavaProject... upstreamProjects) {
   try {
     final IJavaProject result = JavaProjectSetupUtil.createJavaProject(name);
     IProject _project = result.getProject();
     IResourcesSetupUtil.addNature(_project, XtextProjectHelper.NATURE_ID);
     this.xtendLibs.addLibsToClasspath(result, null);
     final Procedure1<IJavaProject> _function =
         new Procedure1<IJavaProject>() {
           @Override
           public void apply(final IJavaProject it) {
             try {
               IPath _path = it.getPath();
               IClasspathEntry _newProjectEntry = JavaCore.newProjectEntry(_path, true);
               JavaProjectSetupUtil.addToClasspath(result, _newProjectEntry);
             } catch (Throwable _e) {
               throw Exceptions.sneakyThrow(_e);
             }
           }
         };
     IterableExtensions.<IJavaProject>forEach(
         ((Iterable<IJavaProject>) Conversions.doWrapArray(upstreamProjects)), _function);
     return result;
   } catch (Throwable _e) {
     throw Exceptions.sneakyThrow(_e);
   }
 }
Ejemplo n.º 4
0
  public static void setUp() throws Exception {
    if (javaProject != null) return;
    javaProject =
        createJavaProject(
            "projectWithoutSources",
            new String[] {JavaCore.NATURE_ID, "org.eclipse.pde.PluginNature"});
    String path = "/org/eclipse/xtext/common/types/testSetups";
    String jarFileName = "/testData.jar";
    IFile jarFile =
        PluginUtil.copyFileToWorkspace(
            AbstractActivator.getInstance(),
            path + jarFileName,
            javaProject.getProject(),
            jarFileName);
    JavaProjectSetupUtil.addJarToClasspath(javaProject, jarFile);

    javaProjectWithSources =
        createJavaProject(
            "projectWithSources",
            new String[] {JavaCore.NATURE_ID, "org.eclipse.pde.PluginNature"});
    IFolder sourceFolder = JavaProjectSetupUtil.addSourceFolder(javaProjectWithSources, "src");

    List<String> filesToCopy = readResource(path + "/files.list");
    IFolder srcFolder = sourceFolder.getFolder(new Path(path));
    createFolderRecursively(srcFolder);
    for (String fileToCopy : filesToCopy) {
      List<String> content = readResource(path + "/" + fileToCopy);
      String contentAsString = Strings.concat("\n", content);
      createFile(
          fileToCopy.substring(0, fileToCopy.length() - ".txt".length()),
          srcFolder,
          contentAsString);
    }
    createFile(
        "ClassWithDefaultPackage.java", sourceFolder, "public class ClassWithDefaultPackage {}");
    waitForAutoBuild();
  }
Ejemplo n.º 5
0
 @Override
 public void setUp() throws Exception {
   super.setUp();
   IJavaProject project = JavaProjectSetupUtil.createJavaProject(TEST_PROJECT);
   addNature(project.getProject(), XtextProjectHelper.NATURE_ID);
   Injector injector = Activator.getInstance().getInjector(getEditorId());
   injector.injectMembers(this);
   IFile fooFile =
       IResourcesSetupUtil.createFile(TEST_PROJECT + "/foo.refactoringtestlanguage", "foo");
   IFile barFile =
       IResourcesSetupUtil.createFile(
           TEST_PROJECT + "/bar.refactoringtestlanguage", "bar { ref foo }");
   waitForAutoBuild();
   fooEditor = openEditor(fooFile);
   barEditor = openEditor(barFile);
   assertTrue(refactoringPreferences.useInlineRefactoring());
 }
Ejemplo n.º 6
0
 private IFile createClientProjectFile(final String name, final CharSequence content) {
   try {
     IFile _xblockexpression = null;
     {
       IProject _createPluginProject = WorkbenchTestHelper.createPluginProject("test.client");
       this.clientProject = _createPluginProject;
       IJavaProject _create = JavaCore.create(this.clientProject);
       IProject _project = this.workbenchTestHelper.getProject();
       IJavaProject _create_1 = JavaCore.create(_project);
       JavaProjectSetupUtil.addProjectReference(_create, _create_1);
       Path _path = new Path((("test.client/src/" + name) + ".xtend"));
       String _string = content.toString();
       _xblockexpression = IResourcesSetupUtil.createFile(_path, _string);
     }
     return _xblockexpression;
   } catch (Throwable _e) {
     throw Exceptions.sneakyThrow(_e);
   }
 }
 public void createJavaProjectWithXtextNature() {
   try {
     IJavaProject _createJavaProject = JavaProjectSetupUtil.createJavaProject(this.TEST_PROJECT);
     final Procedure1<IJavaProject> _function =
         new Procedure1<IJavaProject>() {
           public void apply(final IJavaProject it) {
             try {
               IProject _project = it.getProject();
               IResourcesSetupUtil.addNature(_project, XtextProjectHelper.NATURE_ID);
               JavaProjectSetupUtil.addSourceFolder(it, "entities-gen");
             } catch (Throwable _e) {
               throw Exceptions.sneakyThrow(_e);
             }
           }
         };
     ObjectExtensions.<IJavaProject>operator_doubleArrow(_createJavaProject, _function);
   } catch (Throwable _e) {
     throw Exceptions.sneakyThrow(_e);
   }
 }