@Test
  public void shouldNotShowIgnoredFiles() throws Exception {
    // given
    resetRepositoryToCreateInitialTag();
    String ignoredName = "to-be-ignored.txt";

    IProject proj = ResourcesPlugin.getWorkspace().getRoot().getProject(PROJ1);

    IFile ignoredFile = proj.getFile(ignoredName);
    ignoredFile.create(
        new ByteArrayInputStream("content of ignored file".getBytes(proj.getDefaultCharset())),
        false,
        null);

    IFile gitignore = proj.getFile(".gitignore");
    gitignore.create(
        new ByteArrayInputStream(ignoredName.getBytes(proj.getDefaultCharset())), false, null);
    proj.refreshLocal(IResource.DEPTH_INFINITE, null);

    // when
    launchSynchronization(INITIAL_TAG, HEAD, true);

    // then
    SWTBotTree syncViewTree = bot.viewByTitle("Synchronize").bot().tree();
    SWTBotTreeItem projectTree = waitForNodeWithText(syncViewTree, PROJ1);
    projectTree.expand();
    assertEquals(1, projectTree.getItems().length);
  }
 /*
  * Assert EmployerType and dependent types are added to the wsdl
  */
 public void validateProjectArtifacts(String eBoxServiceName) throws IOException, CoreException {
   IProject project = WorkspaceUtil.getProject(eBoxServiceName);
   Assert.assertTrue(
       "TypeDepencies.xml didnot get generated",
       project
           .getFile(
               "meta-src"
                   + File.separator
                   + "META-INF"
                   + File.separator
                   + eBoxServiceName
                   + File.separator
                   + "TypeDependencies.xml")
           .exists());
   String sb =
       ServiceCreationFromExistingTypesTest1.readContentsFromIFile(
           project.getFile(
               "meta-src"
                   + File.separator
                   + "META-INF"
                   + File.separator
                   + "soa"
                   + File.separator
                   + "services"
                   + File.separator
                   + "wsdl"
                   + File.separator
                   + eBoxServiceName
                   + File.separator
                   + eBoxServiceName
                   + ".wsdl"));
   Assert.assertTrue(
       "WSDL file is not inlined with imported type - EmployerType",
       sb.indexOf("EmployerType") > -1);
 }
  public void testDependencyScopeChanged() throws Exception {
    // Changing the scope of a dependency should trigger a project update
    IProject p1 = createExisting("changedscope-p01");
    IProject p2 = createExisting("changedscope-p02");
    waitForJobsToComplete();

    IFile pom1 = p1.getFile("pom.xml");
    IFile pom2 = p2.getFile("pom.xml");

    {
      IMavenProjectFacade f = manager.create(pom2, false, null);
      Artifact[] a = getMavenProjectArtifacts(f).toArray(new Artifact[0]);
      assertEquals(2, a.length);
      assertEquals(
          pom1.getLocation().toFile().getCanonicalFile(), a[0].getFile().getCanonicalFile());
      assertEquals("junit-3.8.1.jar", a[1].getFile().getName());
    }

    copyContent(p1, "pom-scope-changed.xml", "pom.xml");

    {
      IMavenProjectFacade f = manager.create(pom2, false, null);
      Artifact[] a = getMavenProjectArtifacts(f).toArray(new Artifact[0]);
      assertEquals("provided scope dependency should disappear", 1, a.length);
      assertEquals(
          pom1.getLocation().toFile().getCanonicalFile(), a[0].getFile().getCanonicalFile());
    }
  }
  public void testOptionalDependencies() throws Exception {
    IProject p1 = createExisting("optionaldependency-p01");
    IProject p2 = createExisting("optionaldependency-p02");
    waitForJobsToComplete();

    IFile pom1 = p1.getFile("pom.xml");
    IFile pom2 = p2.getFile("pom.xml");

    {
      IMavenProjectFacade f = manager.create(pom2, false, null);
      Artifact[] a = getMavenProjectArtifacts(f).toArray(new Artifact[0]);
      assertEquals(2, a.length);
      assertEquals(
          pom1.getLocation().toFile().getCanonicalFile(), a[0].getFile().getCanonicalFile());
      assertEquals("junit-3.8.1.jar", a[1].getFile().getName());
    }

    copyContent(p1, "pom-changed.xml", "pom.xml");

    {
      IMavenProjectFacade f = manager.create(pom2, false, null);
      Artifact[] a = getMavenProjectArtifacts(f).toArray(new Artifact[0]);
      assertEquals(1, a.length);
      assertEquals(
          pom1.getLocation().toFile().getCanonicalFile(), a[0].getFile().getCanonicalFile());
    }
  }
  public void test008_staleMissingParent() throws Exception {
    // p1 does not have parent
    IProject p1 = createExisting("t008-p1");
    assertNotNull(p1);
    IProject p3 = createExisting("t008-p3");
    assertNotNull(p3);
    waitForJobsToComplete();

    IMavenProjectFacade f1 = manager.create(p1, monitor);
    assertNull(f1); // XXX should I return non-null facade that does not have MavenProject?

    // update p1 to have p3 parent
    InputStream contents = p1.getFile("pom_updated.xml").getContents();
    p1.getFile("pom.xml").setContents(contents, IResource.FORCE, monitor);
    contents.close();
    waitForJobsToComplete();

    f1 = manager.create(p1, monitor);
    assertEquals("t008-p3", getParentProject(f1).getArtifactId());

    events.clear();
    IProject p2 = createExisting("t008-p2");
    waitForJobsToComplete();

    assertEquals(1, events.size());
    MavenProjectChangedEvent event = events.get(0);
    assertEquals(p2.getFile(IMavenConstants.POM_FILE_NAME), event.getSource());
    assertEquals(MavenProjectChangedEvent.KIND_ADDED, event.getKind());
  }
  public void test007_changedVersion() throws Exception {
    // p1 depends on p2
    IProject p1 = createExisting("t007-p1");
    IProject p2 = createExisting("t007-p2");
    waitForJobsToComplete();

    IMavenProjectFacade f1 = manager.create(p1, monitor);
    List<Artifact> a1 = new ArrayList<Artifact>(f1.getMavenProject(monitor).getArtifacts());
    assertEquals(1, f1.getMavenProject(monitor).getArtifacts().size());
    assertEquals(
        p2.getFile(IMavenConstants.POM_FILE_NAME).getLocation().toFile(), a1.get(0).getFile());

    // update p2 to have new version
    copyContent(p2, "pom_newVersion.xml", "pom.xml");
    f1 = manager.create(p1, monitor);
    a1 = new ArrayList<Artifact>(f1.getMavenProject(monitor).getArtifacts());
    assertEquals(1, f1.getMavenProject(monitor).getArtifacts().size());
    assertStartWith(repo.getAbsolutePath(), a1.get(0).getFile().getAbsolutePath());

    // update p2 back to the original version
    copyContent(p2, "pom_original.xml", "pom.xml");
    f1 = manager.create(p1, monitor);
    a1 = new ArrayList<Artifact>(f1.getMavenProject(monitor).getArtifacts());
    assertEquals(1, f1.getMavenProject(monitor).getArtifacts().size());
    assertEquals(
        p2.getFile(IMavenConstants.POM_FILE_NAME).getLocation().toFile(), a1.get(0).getFile());
  }
  /**
   * Tries to delete an open project containing an irremovable file. Works only for Linux with
   * natives.
   */
  public void testDeleteOpenProjectLinux() {
    if (!(Platform.getOS().equals(Platform.OS_LINUX) && isReadOnlySupported())) return;

    IProject project = null;
    File projectRoot = null;
    IFolder folder = null;
    try {
      IWorkspace workspace = getWorkspace();
      project = workspace.getRoot().getProject(getUniqueString());
      folder = project.getFolder("a_folder");
      IFile file1 = folder.getFile("file1.txt");
      IFile file2 = project.getFile("file2.txt");

      ensureExistsInWorkspace(new IResource[] {file1, file2}, true);
      projectRoot = project.getLocation().toFile();

      // marks folder as read-only so its files cannot be deleted on Linux
      setReadOnly(folder, true);

      IFile projectFile = project.getFile(".project");
      assertTrue("1.2", projectFile.exists());
      assertTrue("1.3", projectFile.isSynchronized(IResource.DEPTH_INFINITE));

      try {
        project.delete(IResource.FORCE, getMonitor());
        fail("2.0 - should have failed");
      } catch (CoreException ce) {
        // success - a file couldn't be removed
      }
      assertTrue("2.1", project.exists());
      assertTrue("2.2", file1.exists());
      assertTrue("2.3", !file2.exists());
      assertTrue("2.5", folder.exists());
      assertTrue("2.6", projectFile.exists());
      assertTrue("2.7", project.isSynchronized(IResource.DEPTH_INFINITE));

      setReadOnly(folder, false);

      assertTrue("3.5", project.isSynchronized(IResource.DEPTH_INFINITE));
      try {
        project.delete(IResource.FORCE, getMonitor());
      } catch (CoreException ce) {
        ce.printStackTrace();
        fail("4.0", ce);
      }

      assertTrue("5.1", !project.exists());
      assertTrue("5.2", !file1.exists());
      assertTrue("5.3", file1.isSynchronized(IResource.DEPTH_INFINITE));
      assertTrue("5.4", project.isSynchronized(IResource.DEPTH_INFINITE));

      assertTrue("6.0", !projectRoot.exists());
    } finally {
      if (folder != null && folder.exists()) setReadOnly(folder, false);
      if (projectRoot != null) ensureDoesNotExistInFileSystem(projectRoot);
    }
  }
  public static IFile getDataFileForInput(final IEditorInput input) {
    final IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();

    if (input instanceof ToscaDiagramEditorInput) {
      final ToscaDiagramEditorInput tdei = (ToscaDiagramEditorInput) input;

      return tdei.getToscaFile();
    } else if (input instanceof DiagramEditorInput) {
      final DiagramEditorInput dei = (DiagramEditorInput) input;

      IPath path = new Path(dei.getUri().trimFragment().toPlatformString(true));

      return recreateDataFile(path);
    } else if (input instanceof FileEditorInput) {
      final FileEditorInput fei = (FileEditorInput) input;

      return fei.getFile();
    } else if (input instanceof IURIEditorInput) {
      // opened externally to Eclipse
      final IURIEditorInput uei = (IURIEditorInput) input;
      final java.net.URI uri = uei.getURI();
      final String path = uri.getPath();

      try {
        final IProject importProject = root.getProject("import"); // $NON-NLS-1$
        if (!importProject.exists()) {
          importProject.create(null);
        }

        importProject.open(null);

        final InputStream is = new FileInputStream(path);

        final String fileName;
        if (path.contains("/")) { // $NON-NLS-1$
          fileName = path.substring(path.lastIndexOf("/") + 1); // $NON-NLS-1$
        } else {
          fileName = path.substring(path.lastIndexOf("\\") + 1); // $NON-NLS-1$
        }

        IFile importFile = importProject.getFile(fileName);
        if (importFile.exists()) {
          importFile.delete(true, null);
        }

        importFile.create(is, true, null);

        return importProject.getFile(fileName);
      } catch (CoreException exception) {
        exception.printStackTrace();
      } catch (FileNotFoundException exception) {
        exception.printStackTrace();
      }
    }

    return null;
  }
  public void testRemoveErrorIndex() {
    SVCorePlugin.getDefault().enableDebug(false);
    List<SVDBMarker> markers;
    IProject p = TestUtils.createProject("error_index");
    addProject(p);

    String error_argfile = "missing_file1.sv\n" + "subdir/missing_file2.sv\n";

    String okay_argfile = "file1.sv\n";

    String file1_sv = "`include \"missing_file.svh\"\n" + "module m1;\n" + "endmodule\n";

    TestUtils.copy(error_argfile, p.getFile("error_argfile.f"));

    TestUtils.copy(okay_argfile, p.getFile("okay_argfile.f"));

    TestUtils.copy(file1_sv, p.getFile("file1.sv"));

    SVDBProjectData pdata = fProjMgr.getProjectData(p);
    SVDBIndexCollection p_index = pdata.getProjectIndexMgr();

    SVProjectFileWrapper w;

    w = pdata.getProjectFileWrapper();
    w.addArgFilePath("${workspace_loc}/error_index/error_argfile.f");

    pdata.setProjectFileWrapper(w);

    CoreReleaseTests.clearErrors();
    p_index.rebuildIndex(new NullProgressMonitor());
    p_index.loadIndex(new NullProgressMonitor());

    // Ensure that we see errors
    //		assertTrue(CoreReleaseTests.getErrors().size() > 0);
    markers = p_index.getMarkers("${workspace_loc}/error_index/error_argfile.f");
    assertNotNull(markers);
    assertTrue((markers.size() > 0));

    // Now, update the index settings and ensure that
    // no errors are seen
    CoreReleaseTests.clearErrors();

    w = pdata.getProjectFileWrapper();
    w.getArgFilePaths().clear();
    w.addArgFilePath("${workspace_loc}/error_index/okay_argfile.f");
    pdata.setProjectFileWrapper(w);

    //		p_index.rebuildIndex(new NullProgressMonitor());
    fIndexRgy.rebuildIndex(new NullProgressMonitor(), p.getName());
    p_index.loadIndex(new NullProgressMonitor());

    assertEquals(0, CoreReleaseTests.getErrors().size());
  }
  public void testManifestUnlinkedOnRevertToADTDefaults() throws Exception {
    IProject project = importAndroidTestProject("android-maven-plugin-4").into(workspace);

    project.getFile("pom.xml").delete(true, null);

    rename(project.getFile("pom_old_res.xml"), project.getFile("pom.xml"));
    rename(
        project.getLocation().append("src").append("main").append("AndroidManifest.xml"),
        project.getLocation().append("AndroidManifest.xml"));

    updateConfiguration(project);

    assertFalse("manifest is linked", project.getFile("AndroidManifest.xml").isLinked());
  }
 // CreateShortcut, LoadResource, InitDiagramFileAction
 public void testPredefinedActions() throws Exception {
   DiaGenSource s1 = createLibraryGen(false);
   final GenEditorGenerator editorGen = s1.getGenDiagram().getEditorGen();
   GenContextMenu menu = GMFGenFactory.eINSTANCE.createGenContextMenu();
   menu.getContext().add(s1.getGenDiagram());
   final CreateShortcutAction createShortcutAction =
       GMFGenFactory.eINSTANCE.createCreateShortcutAction();
   final LoadResourceAction loadResourceAction =
       GMFGenFactory.eINSTANCE.createLoadResourceAction();
   menu.getItems().add(createShortcutAction);
   menu.getItems().add(loadResourceAction);
   editorGen.getContextMenus().clear(); // make sure there's no other (default) menus
   editorGen.getContextMenus().add(menu);
   editorGen.getDiagram().getContainsShortcutsTo().add("ecore");
   assertTrue("sanity", editorGen.getDiagram().generateCreateShortcutAction());
   //
   generateAndCompile(s1);
   //
   IProject generatedProject =
       ResourcesPlugin.getWorkspace().getRoot().getProject(editorGen.getPlugin().getID());
   IFile generatedManifest = generatedProject.getFile("plugin.xml");
   assertTrue(generatedManifest.exists());
   DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder();
   Document parsedManifest = db.parse(new InputSource(generatedManifest.getContents()));
   XPath xf = XPathFactory.newInstance().newXPath();
   XPathExpression xe =
       xf.compile("/plugin/extension[@point = 'org.eclipse.ui.menus']/menuContribution/command");
   NodeList result = (NodeList) xe.evaluate(parsedManifest, XPathConstants.NODESET);
   assertEquals(2, result.getLength());
   xe = xf.compile("/plugin/extension[@point = 'org.eclipse.ui.commands']/command");
   result = (NodeList) xe.evaluate(parsedManifest, XPathConstants.NODESET);
   assertTrue(result.getLength() > 2);
   HashSet<String> allCommands = new HashSet<String>();
   for (int i = result.getLength() - 1; i >= 0; i--) {
     allCommands.add(result.item(i).getAttributes().getNamedItem("defaultHandler").getNodeValue());
   }
   assertTrue(allCommands.contains(createShortcutAction.getQualifiedClassName()));
   assertTrue(allCommands.contains(loadResourceAction.getQualifiedClassName()));
   IFile file1 =
       generatedProject.getFile(
           "/src/" + createShortcutAction.getQualifiedClassName().replace('.', '/') + ".java");
   IFile file2 =
       generatedProject.getFile(
           "/src/" + loadResourceAction.getQualifiedClassName().replace('.', '/') + ".java");
   assertTrue(file1.exists());
   assertTrue(file2.exists());
   //
   //		DiaGenSource s2 = createLibraryGen(true);
   //		fail("TODO");
 }
 /*
  * @see TestCase#setUp()
  */
 protected void setUp() throws Exception {
   super.setUp();
   setAutoBuilding(true);
   IWorkspaceRoot root = getWorkspace().getRoot();
   project1 = root.getProject("Project1");
   project2 = root.getProject("Project2");
   project3 = root.getProject("Project3");
   project4 = root.getProject("Project4");
   file1 = project1.getFile("File1");
   file2 = project2.getFile("File2");
   file3 = project3.getFile("File3");
   file4 = project4.getFile("File4");
   IResource[] resources = {project1, project2, project3, project4, file1, file2, file3, file4};
   ensureExistsInWorkspace(resources, true);
 }
 private SoftPkg getSoftPkg(final IProject project) {
   final ResourceSet set = ScaResourceFactoryUtil.createResourceSet();
   final IFile softPkgFile = project.getFile(project.getName() + ".spd.xml");
   final Resource resource =
       set.getResource(URI.createFileURI(softPkgFile.getLocation().toString()), true);
   return SoftPkg.Util.getSoftPkg(resource);
 }
  private DmdlParserWrapper createWrapper(IProject project) {
    IJavaProject jproject = JavaCore.create(project);
    if (jproject == null) {
      return null;
    }

    DmdlParserWrapper wrapper = null;
    try {
      IFile file = project.getFile(".classpath");
      long time = file.getLocalTimeStamp();
      Long cache = (Long) project.getSessionProperty(TIME_KEY);

      wrapper = (DmdlParserWrapper) project.getSessionProperty(PASER_KEY);
      if (wrapper == null || (cache != null && cache < time)) {
        wrapper = new DmdlParserWrapper(jproject);
        project.setSessionProperty(PASER_KEY, wrapper);
        project.setSessionProperty(TIME_KEY, time);
      }
    } catch (CoreException e) {
      if (wrapper == null) {
        wrapper = new DmdlParserWrapper(jproject);
      }
    }
    return wrapper.isValid() ? wrapper : null;
  }
 private ITraceabilityStorage getStorage(IProject p) {
   IFile file = p.getFile(new Path(TraceabilityAttributesManager.STORAGE_PATH));
   // get the storage for the file path
   String uri = file.getLocationURI().getPath();
   ITraceabilityStorage storage = storageProvider.getStorage(uri);
   return storage;
 }
  private void openFileWithDefaultEditor(String projectName, String path) {
    IWorkspace workspace = ResourcesPlugin.getWorkspace();
    IProject project = workspace.getRoot().getProject(projectName);

    String fileName = path;

    final IFile fbfile = project.getFile(fileName);

    Display.getDefault()
        .asyncExec(
            new Runnable() {
              @Override
              public void run() {
                IWorkbenchWindow activeWindow =
                    PlatformUI.getWorkbench().getActiveWorkbenchWindow();
                if (activeWindow != null) {
                  IWorkbenchPage page = activeWindow.getActivePage();
                  if (page != null) {
                    try {
                      IDE.openEditor(page, fbfile);
                    } catch (PartInitException e) {
                      throw new RuntimeException(e);
                    }
                  }
                }
              }
            });
  }
  public void updatePom() throws IOException, XmlPullParserException {
    File mavenProjectPomLocation = project.getFile("pom.xml").getLocation().toFile();
    MavenProject mavenProject = MavenUtils.getMavenProject(mavenProjectPomLocation);
    version = mavenProject.getVersion();

    // Skip changing the pom file if group ID and artifact ID are matched
    if (MavenUtils.checkOldPluginEntry(
        mavenProject, "org.wso2.maven", "wso2-esb-template-plugin")) {
      return;
    }

    Plugin plugin =
        MavenUtils.createPluginEntry(
            mavenProject,
            "org.wso2.maven",
            "wso2-esb-template-plugin",
            MavenConstants.WSO2_ESB_TEMPLATE_VERSION,
            true);
    PluginExecution pluginExecution = new PluginExecution();
    pluginExecution.addGoal("pom-gen");
    pluginExecution.setPhase("process-resources");
    pluginExecution.setId("template");

    Xpp3Dom configurationNode = MavenUtils.createMainConfigurationNode();
    Xpp3Dom artifactLocationNode = MavenUtils.createXpp3Node(configurationNode, "artifactLocation");
    artifactLocationNode.setValue(".");
    Xpp3Dom typeListNode = MavenUtils.createXpp3Node(configurationNode, "typeList");
    typeListNode.setValue("${artifact.types}");
    pluginExecution.setConfiguration(configurationNode);
    plugin.addExecution(pluginExecution);
    MavenUtils.saveMavenProject(mavenProject, mavenProjectPomLocation);
  }
  protected void addOrUpdateProjectToConf(EditorProject editorProject, IProject gemocProject) {
    IFile configFile = gemocProject.getFile(new Path(Activator.GEMOC_PROJECT_CONFIGURATION_FILE));
    if (configFile.exists()) {
      Resource.Factory.Registry reg = Resource.Factory.Registry.INSTANCE;
      Map<String, Object> m = reg.getExtensionToFactoryMap();
      m.put(Activator.GEMOC_PROJECT_CONFIGURATION_FILE_EXTENSION, new XMIResourceFactoryImpl());

      // Obtain a new resource set
      ResourceSet resSet = new ResourceSetImpl();

      // get the resource
      Resource resource =
          resSet.getResource(URI.createURI(configFile.getLocationURI().toString()), true);

      LanguageDefinition gemocLanguageWorkbenchConfiguration =
          (LanguageDefinition) resource.getContents().get(0);
      addOrUpdateProjectToConf(editorProject, gemocLanguageWorkbenchConfiguration);

      try {
        resource.save(null);
      } catch (IOException e) {
        Activator.error(e.getMessage(), e);
      }
    }
    try {
      configFile.refreshLocal(IResource.DEPTH_ZERO, new NullProgressMonitor());
    } catch (CoreException e) {
      Activator.error(e.getMessage(), e);
    }
  }
  /**
   * Populate the project using rpmstubby based on the eclipse-feature or maven-pom choice of user
   *
   * @param InputType type of the stubby project
   * @param File the external xml file uploaded from file system
   * @throws CoreException
   * @throws FileNotFoundException
   */
  public void create(InputType inputType, File stubby) throws FileNotFoundException, CoreException {
    IFile stubbyFile = project.getFile(stubby.getName());
    stubbyFile.create(new FileInputStream(stubby), false, monitor);

    Generator specfilegGenerator = new Generator(inputType);
    specfilegGenerator.generate(stubbyFile);
  }
Exemple #20
0
 /**
  * Creates new eclipse file-link from project root to EFS file.
  *
  * @param project - project where to create the file.
  * @param fileLink - filename of the link being created.
  * @param realFile - file on the EFS file system, the target of the link.
  * @return file handle.
  * @throws CoreException if something goes wrong.
  */
 public static IFile createEfsFile(IProject project, String fileLink, URI realFile)
     throws CoreException {
   IFile file = project.getFile(fileLink);
   file.createLink(realFile, IResource.ALLOW_MISSING_LOCAL, NULL_MONITOR);
   resourcesCreated.add(file);
   return file;
 }
  public void testTagLibsFromPlugin() throws Exception {

    IProject proj = ensureProject(TEST_PROJECT_NAME);
    ensureDefaultGrailsVersion(GrailsVersion.getGrailsVersion(proj));

    if (GrailsVersion.V_2_3_.compareTo(GrailsVersion.MOST_RECENT) > 0) {
      // below 2.3 install-plugin command works
      GrailsCommand cmd =
          GrailsCommand.forTest(proj, "install-plugin").addArgument("feeds").addArgument("1.6");
      cmd.synchExec();
    } else {
      // after 2.3, must edit build config
      IFile buildConfig = proj.getFile("grails-app/conf/BuildConfig.groovy");
      String origContents = GrailsTest.getContents(buildConfig);

      // Modify the props file add two plugins
      // A bit of a hack, but this is a simple way to add plugins to the build
      String newContents =
          origContents.replace("plugins {\n", "plugins {\n\t\tcompile \":feeds:1.6\"\n");
      GrailsTest.setContents(buildConfig, newContents);
    }
    refreshDependencies(proj);

    assertPluginSourceFolder(proj, "feeds-1.6", "src", "groovy");

    // now also check to see that the tag is available
    PerProjectTagProvider provider = GrailsCore.get().connect(proj, PerProjectTagProvider.class);
    assertNotNull("feeds:meta tag not installed", provider.getDocumentForTagName("feed:meta"));
  }
  /*
   * (non-Jsdoc)
   *
   * @see
   * org.talend.designer.codegen.ITalendSynchronizer#getRoutinesFile(org.talend.core.model.properties.RoutineItem)
   */
  @Override
  public IFile getRoutinesFile(Item item) throws SystemException {
    try {
      if (item instanceof BeanItem) {
        BeanItem routineItem = (BeanItem) item;
        ProjectManager projectManager = ProjectManager.getInstance();
        org.talend.core.model.properties.Project project = projectManager.getProject(routineItem);
        IProject iProject =
            ResourcesPlugin.getWorkspace().getRoot().getProject(project.getTechnicalLabel());
        String repositoryPath =
            ERepositoryObjectType.getFolderName(CamelRepositoryNodeType.repositoryBeansType);
        String folderPath =
            RepositoryNodeUtilities.getPath(routineItem.getProperty().getId()).toString();
        String fileName =
            routineItem.getProperty().getLabel()
                + '_'
                + routineItem.getProperty().getVersion()
                + JavaUtils.ITEM_EXTENSION;
        String path = null;
        if (folderPath != null && folderPath.trim().length() > 0) {
          path = repositoryPath + '/' + folderPath + '/' + fileName;
        } else {
          path = repositoryPath + '/' + fileName;
        }

        IFile file = iProject.getFile(path);
        return file;
      }

    } catch (Exception e) {
      throw new SystemException(e);
    }

    return null;
  }
  public ArrayList<IProject> getProjects() {
    final ArrayList<IProject> result = new ArrayList<IProject>();
    try {
      IProject featureProject = getFeatureProject();
      IFile featureXMLFile = featureProject.getFile("feature.xml");
      SAXParser parser = SAXParserFactory.newInstance().newSAXParser();

      DefaultHandler handler =
          new DefaultHandler() {
            @Override
            public void startElement(
                String uri, String localName, String qName, Attributes attributes)
                throws SAXException {
              if ("plugin".equals(qName)) {
                String id = attributes.getValue("id");
                IProject eachProject = ResourcesPlugin.getWorkspace().getRoot().getProject(id);
                if (!eachProject.exists()) {
                  throw new BuildException(
                      MessageFormat.format(
                          "아이디가 {0}인 프로젝틀르 찾지 못했습니다. 프로젝트 아이디와 프로젝트 명은 동일한 것으로 간주합니다.", id));
                }
                result.add(eachProject);
              }
            }
          };
      parser.parse(featureXMLFile.getContents(), handler);
    } catch (Exception e) {
      throw new BuildException(e.getMessage(), e);
    }

    return result;
  }
 /**
  * Deletes a set of files from the file system, and also their parent folders if those become
  * empty during this process.
  *
  * @param nameSet set of file paths
  * @param monitor progress monitor
  * @throws CoreException if an error occurs
  */
 private void deleteFiles(final Set<IPath> nameSet, IProgressMonitor monitor)
     throws CoreException {
   if (nameSet == null || nameSet.isEmpty()) {
     return;
   }
   Set<IContainer> subFolders = new HashSet<IContainer>();
   for (IPath filePath : nameSet) {
     // Generate new path
     IFile currentFile = project.getFile(filePath);
     if (currentFile.exists()) {
       // Retrieve parent folder and store for deletion
       IContainer folder = currentFile.getParent();
       subFolders.add(folder);
       currentFile.delete(true, monitor);
     }
     monitor.worked(1);
   }
   // Delete parent folders, if they are empty
   for (IContainer folder : subFolders) {
     if (folder.exists() && folder.members().length == 0) {
       folder.delete(true, monitor);
     }
     monitor.worked(1);
   }
 }
  /** 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);
 }
Exemple #27
0
  /**
   * Creates new symbolic file system link from file or folder on project root to another file
   * system file. The filename can include relative path as a part of the name but the the path has
   * to be present on disk.
   *
   * @param project - project where to create the file.
   * @param linkName - name of the link being created.
   * @param realPath - file or folder on the file system, the target of the link.
   * @return file handle.
   * @throws UnsupportedOperationException on Windows where links are not supported.
   * @throws IOException...
   * @throws CoreException...
   */
  public static IResource createSymbolicLink(IProject project, String linkName, IPath realPath)
      throws IOException, CoreException, UnsupportedOperationException {

    if (!isSymbolicLinkSupported()) {
      throw new UnsupportedOperationException("Windows links .lnk are not supported.");
    }

    Assert.assertTrue(
        "Path for symbolic link does not exist: [" + realPath.toOSString() + "]",
        new File(realPath.toOSString()).exists());

    IPath linkedPath = project.getLocation().append(linkName);
    createSymbolicLink(linkedPath, realPath);

    IResource resource = project.getFile(linkName);
    resource.refreshLocal(IResource.DEPTH_ZERO, null);

    if (!resource.exists()) {
      resource = project.getFolder(linkName);
      resource.refreshLocal(IResource.DEPTH_ZERO, null);
    }
    Assert.assertTrue("Failed to create resource form symbolic link", resource.exists());

    externalFilesCreated.add(linkedPath.toOSString());
    ResourcesPlugin.getWorkspace().getRoot().refreshLocal(IResource.DEPTH_INFINITE, NULL_MONITOR);
    return resource;
  }
  private void stackTracingWasChanged(boolean enabled) {
    IPreferenceStore store = CxxTestPlugin.getDefault().getPreferenceStore();
    String driverFile = store.getString(CxxTestPlugin.CXXTEST_PREF_DRIVER_FILENAME);

    IExtraOptionsUpdater updater = CxxTestPlugin.getDefault().getExtraOptionsUpdater();

    IWorkspace workspace = ResourcesPlugin.getWorkspace();
    IProject[] projects = workspace.getRoot().getProjects();

    for (IProject project : projects) {
      if (!project.isOpen()) {
        continue;
      }

      try {
        if (project.hasNature(CxxTestPlugin.CXXTEST_NATURE)) {
          IFile driver = project.getFile(driverFile);

          if (driver != null) {
            driver.delete(true, null);
          }

          updater.updateOptions(project);
        }
      } catch (CoreException e) {
        e.printStackTrace();
      }
    }
  }
  public static IFile LinkFile(String path) {
    IWorkspace ws = ResourcesPlugin.getWorkspace();
    IProject project = ws.getRoot().getProject("tmp");
    if (!project.exists())
      try {
        project.create(null);
      } catch (CoreException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
    if (!project.isOpen())
      try {
        project.open(null);
      } catch (CoreException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
    IPath location = new Path(path);
    IFile file = project.getFile(location.lastSegment());

    try {
      file.delete(true, null);
    } catch (CoreException e1) {
    }

    try {
      file.createLink(location, IResource.NONE, null);
    } catch (CoreException e) {
    }
    return file;
  }
 protected IFile createFile(IProject project, String fileName, String contents)
     throws CoreException {
   IFile file = project.getFile(fileName);
   ByteArrayInputStream source = new ByteArrayInputStream(contents.getBytes());
   file.create(source, true, new NullProgressMonitor());
   return file;
 }