private Map promptForOverwrite(List plugins, List locales) {
    Map overwrites = new HashMap();

    if (overwriteWithoutAsking) return overwrites;

    for (Iterator iter = plugins.iterator(); iter.hasNext(); ) {
      IPluginModelBase plugin = (IPluginModelBase) iter.next();
      for (Iterator it = locales.iterator(); it.hasNext(); ) {
        Locale locale = (Locale) it.next();
        IProject project = getNLProject(plugin, locale);

        if (project.exists() && !overwrites.containsKey(project.getName())) {
          boolean overwrite =
              MessageDialog.openConfirm(
                  PDEPlugin.getActiveWorkbenchShell(),
                  PDEUIMessages.InternationalizeWizard_NLSFragmentGenerator_overwriteTitle,
                  NLS.bind(
                      PDEUIMessages.InternationalizeWizard_NLSFragmentGenerator_overwriteMessage,
                      pluginName(plugin, locale)));
          overwrites.put(project.getName(), overwrite ? OVERWRITE : null);
        }
      }
    }

    return overwrites;
  }
예제 #2
0
  @Override
  public void doRun(ISelection selection, Event event, UIInstrumentationBuilder instrumentation) {
    instrumentation.metric("command", command);

    if (!(selection instanceof ITextSelection)) {
      instrumentation.metric("Problem", "Selection was not a TextSelection");
    }

    IWorkbenchPage page = DartToolsPlugin.getActivePage();
    if (page == null) {
      instrumentation.metric("Problem", "Page was null");
      return;
    }

    IEditorPart part = page.getActiveEditor();
    if (part == null) {
      instrumentation.metric("Problem", "Part was null");
      return;
    }

    IEditorInput editorInput = part.getEditorInput();
    IProject project = EditorUtility.getProject(editorInput);
    instrumentation.data("Project", project.getName());
    savePubspecFile(project);
    runPubJob(project);
  }
  /**
   * Adds a source container to a IJavaProject.
   *
   * @param jproject The parent project
   * @param containerName The name of the new source container
   * @param inclusionFilters Inclusion filters to set
   * @param exclusionFilters Exclusion filters to set
   * @param outputLocation The location where class files are written to, <b>null</b> for project
   *     output folder
   * @return The handle to the new source container
   * @throws CoreException Creation failed
   */
  public static IPackageFragmentRoot addSourceContainer(
      IJavaProject jproject,
      String containerName,
      IPath[] inclusionFilters,
      IPath[] exclusionFilters,
      String outputLocation)
      throws CoreException {
    IProject project = jproject.getProject();
    IContainer container = null;
    if (containerName == null || containerName.length() == 0) {
      container = project;
    } else {
      IFolder folder = project.getFolder(containerName);
      if (!folder.exists()) {
        CoreUtility.createFolder(folder, false, true, null);
      }
      container = folder;
    }
    IPackageFragmentRoot root = jproject.getPackageFragmentRoot(container);

    IPath outputPath = null;
    if (outputLocation != null) {
      IFolder folder = project.getFolder(outputLocation);
      if (!folder.exists()) {
        CoreUtility.createFolder(folder, false, true, null);
      }
      outputPath = folder.getFullPath();
    }
    IClasspathEntry cpe =
        JavaCore.newSourceEntry(root.getPath(), inclusionFilters, exclusionFilters, outputPath);
    addToClasspath(jproject, cpe);
    return root;
  }
예제 #4
0
  private void testBuilder(final BuilderTool builderTool) throws CoreException {
    ErlangNature.setErlangProjectBuilder(prj, builderTool);
    final String targetBeamPath = "ebin/mod.beam";

    final IResource beam0 = prj.findMember(targetBeamPath);
    assertThat("beam existed before test", beam0, nullValue());

    final ErlangBuilder builder = ErlangBuilderFactory.get(builderTool);
    final BuildNotifier notifier = new BuildNotifier(null, prj);
    final IErlProject erlProject = ErlangEngine.getInstance().getModel().getErlangProject(prj);

    builder.build(BuildKind.FULL, erlProject, notifier);
    prj.refreshLocal(IResource.DEPTH_INFINITE, null);
    waitJobsToFinish(ResourcesPlugin.FAMILY_MANUAL_REFRESH);

    final IResource beam = prj.findMember(targetBeamPath);
    assertThat("beam was not created", beam, notNullValue());

    builder.clean(erlProject, notifier);
    prj.refreshLocal(IResource.DEPTH_INFINITE, null);
    waitJobsToFinish(ResourcesPlugin.FAMILY_MANUAL_REFRESH);

    final IResource beam2 = prj.findMember(targetBeamPath);
    assertThat("beam was not removed", beam2, nullValue());
  }
 @Override
 public void fillContextMenu(IMenuManager aMenu) {
   IStructuredSelection selection = (IStructuredSelection) getContext().getSelection();
   if (selection.size() != 1) {
     return;
   }
   Object object = selection.getFirstElement();
   IFolder folder = Adapters.adapt(object, IFolder.class);
   if (folder == null) {
     return;
   }
   if (folder.getFile(IProjectDescription.DESCRIPTION_FILE_NAME).exists()) {
     for (IProject project : folder.getWorkspace().getRoot().getProjects()) {
       if (project.getLocation().equals(folder.getLocation())) {
         // project already in workspace
         SelectProjectForFolderAction action =
             new SelectProjectForFolderAction(project, this.viewer);
         aMenu.appendToGroup(ICommonMenuConstants.GROUP_OPEN, action);
         return;
       }
     }
     OpenFolderAsProjectAction action = new OpenFolderAsProjectAction(folder, this.viewer);
     aMenu.prependToGroup(ICommonMenuConstants.GROUP_PORT, action);
   }
 }
예제 #6
0
 /**
  * Return the project with the given root directory, loading it if it is not already loaded. This
  * method assumes that there is no conflict with project names.
  *
  * @param projectRootDirectory the root directory of the project
  * @return the project with the given root directory
  * @throws CoreException
  * @throws FileNotFoundException if a required file or directory does not exist
  * @throws IOException if a required file cannot be accessed
  * @throws SAXException if the .project file is not valid
  */
 public static DartProject loadDartProject(final IPath projectRootDirectory)
     throws CoreException, FileNotFoundException, IOException, SAXException {
   final String projectName = getProjectName(projectRootDirectory);
   final IWorkspace workspace = ResourcesPlugin.getWorkspace();
   final IProject project = workspace.getRoot().getProject(projectName);
   if (!project.exists()) {
     ResourcesPlugin.getWorkspace()
         .run(
             new IWorkspaceRunnable() {
               @Override
               public void run(IProgressMonitor monitor) throws CoreException {
                 IProjectDescription description = workspace.newProjectDescription(projectName);
                 if (!workspace.getRoot().getLocation().isPrefixOf(projectRootDirectory)) {
                   description.setLocation(projectRootDirectory);
                 }
                 project.create(description, null);
                 project.open(null);
               }
             },
             null);
   }
   DartProject dartProject = DartCore.create(project);
   // waitForJobs();
   return dartProject;
 }
예제 #7
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;
  }
예제 #8
0
  /**
   * {@inheritDoc}
   *
   * @see org.eclipse.ui.IWorkbenchWizard#init(org.eclipse.ui.IWorkbench,
   *     org.eclipse.jface.viewers.IStructuredSelection)
   */
  public void init(IWorkbench iWorkbench, IStructuredSelection iSelection) {
    this.workbench = iWorkbench;
    this.selection = iSelection;

    // load the ecore models from the workspace to ensure that all models are available in the
    // wizard
    IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
    for (IProject iProject : projects) {
      try {
        if (iProject.isAccessible()) {
          List<IFile> members = this.members(iProject, IAcceleoConstants.ECORE_FILE_EXTENSION);
          for (IFile iFile : members) {
            Map<String, String> dynamicEcorePackagePaths =
                AcceleoPackageRegistry.INSTANCE.getDynamicEcorePackagePaths();
            Collection<String> values = dynamicEcorePackagePaths.values();
            boolean contains = values.contains(iFile.getFullPath().toString());
            if (!contains) {
              AcceleoPackageRegistry.INSTANCE.registerEcorePackages(
                  iFile.getFullPath().toString(),
                  AcceleoDynamicMetamodelResourceSetImpl.DYNAMIC_METAMODEL_RESOURCE_SET);
            }
          }
        }
      } catch (CoreException e) {
        AcceleoUIActivator.log(e, false);
      }
    }
  }
  /**
   * Toggles sample nature on a project
   *
   * @param project to have sample nature added or removed
   */
  private void toggleNature(IProject project) {
    try {
      IProjectDescription description = project.getDescription();
      String[] natures = description.getNatureIds();

      for (int i = 0; i < natures.length; ++i) {
        if (QSARNature.NATURE_ID.equals(natures[i])) {
          // Remove the nature
          String[] newNatures = new String[natures.length - 1];
          System.arraycopy(natures, 0, newNatures, 0, i);
          System.arraycopy(natures, i + 1, newNatures, i, natures.length - i - 1);
          description.setNatureIds(newNatures);
          project.setDescription(description, null);
          return;
        }
      }

      // Add the nature
      String[] newNatures = new String[natures.length + 1];
      System.arraycopy(natures, 0, newNatures, 0, natures.length);
      newNatures[natures.length] = QSARNature.NATURE_ID;
      description.setNatureIds(newNatures);
      project.setDescription(description, null);
      project.hasNature(QSARNature.NATURE_ID);
    } catch (CoreException e) {
    }
  }
 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 void addProjectsSection(Composite parent) {
    Composite composite = createComposite(parent, 1, true);
    initializeDialogUnits(composite);

    Label label = new Label(composite, SWT.NONE);
    label.setText(PROJECTS_TEXT);

    projectList = CheckboxTableViewer.newCheckList(composite, SWT.BORDER);
    projectList.getTable().setLayoutData(new GridData(GridData.FILL_BOTH));
    projectList.setLabelProvider(
        new LabelProvider() {
          @Override
          public Image getImage(Object element) {
            return PlatformUI.getWorkbench()
                .getSharedImages()
                .getImage(IDE.SharedImages.IMG_OBJ_PROJECT);
          }

          @Override
          public String getText(Object element) {
            return ((IProject) element).getName();
          }
        });

    // Filter out closed projects!
    ArrayList<IProject> projects = new ArrayList<IProject>();
    for (IProject project : ResourcesPlugin.getWorkspace().getRoot().getProjects()) {
      if (project.isOpen()) projects.add(project);
    }
    projectList.setContentProvider(new ArrayContentProvider());
    projectList.setInput(projects);

    Dialog.applyDialogFont(composite);
  }
  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;
  }
예제 #13
0
  @Override
  public boolean performFinish() {
    try {
      // TODO Auto-generated method stub
      // See http://www.programcreek.com/2011/05/eclipse-jdt-tutorial-java-model/
      //

      IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
      // Crea un nuevo projecto
      final IProject project = root.getProject(page.getProjectName());
      project.create(null);
      project.open(null);

      // Map props = project.getPersistentProperties();

      /*			//Crear el proyecto Java
      			IProjectDescription description = project.getDescription();
      			//description.setLocation(page.getLocationPath());
      			//Associate nature
      			description.setNatureIds(new String[]{JavaCore.NATURE_ID});
      			project.setDescription(description, null);
      			IJavaProject javaProject = JavaCore.create(project);
      */
      IFolder folder = project.getFolder("models");
      folder.create(true, true, null);
      folder = project.getFolder("src-gen");
      folder.create(true, true, null);

      return true;
    } catch (CoreException e) {
      // TODO Auto-generated catch block
      MessageDialog.openError(getShell(), "Error", e.getMessage());
      return false;
    }
  }
  private IProject createProject(final GridProjectProperties props, final IProgressMonitor monitor)
      throws CoreException {

    monitor.subTask(Messages.getString("GridProjectCreationOperation.init_task")); // $NON-NLS-1$

    String projectName = props.getProjectName();
    IPath projectPath = props.getProjectLocation();
    IProject[] referencesProjects = props.getReferencesProjects();

    IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
    IProject project = workspaceRoot.getProject(projectName);

    IStatus status = ResourcesPlugin.getWorkspace().validateProjectLocation(project, projectPath);
    if (status.getSeverity() != IStatus.OK) {
      throw new CoreException(status);
    }

    IProjectDescription desc = project.getWorkspace().newProjectDescription(projectName);
    desc.setLocation(projectPath);
    if (referencesProjects != null) {
      desc.setReferencedProjects(referencesProjects);
    }
    project.create(desc, new SubProgressMonitor(monitor, 50));
    project.open(new SubProgressMonitor(monitor, 50));

    createProjectStructure(project, props);
    setProjectProperties(project, props);

    if (monitor.isCanceled()) {
      throw new OperationCanceledException();
    }

    return project;
  }
  private void addProjectNature(final IProject proj, final IProgressMonitor monitor)
      throws CoreException {

    monitor.subTask(Messages.getString("GridProjectCreationOperation.nature_task")); // $NON-NLS-1$

    IProjectDescription desc = proj.getDescription();
    String[] natureIDs = desc.getNatureIds();
    String gridNatureID = GridProjectNature.getID();

    boolean found = false;
    for (int i = 0; (i < natureIDs.length) && (!found); i++) {
      if (natureIDs[i].equals(gridNatureID)) {
        found = true;
      }
    }

    if (!found) {
      String[] newNatureIDs = new String[natureIDs.length + 1];
      System.arraycopy(natureIDs, 0, newNatureIDs, 1, natureIDs.length);
      newNatureIDs[0] = gridNatureID;
      desc.setNatureIds(newNatureIDs);
      proj.setDescription(desc, new SubProgressMonitor(monitor, 100));
    }

    if (monitor.isCanceled()) {
      throw new OperationCanceledException();
    }
  }
예제 #16
0
  public static void addNature(IProject project) {

    if (!project.isOpen()) {
      return;
    }

    // Get the description
    IProjectDescription description;
    try {
      description = project.getDescription();
    } catch (CoreException e) {
      JsonLog.logError("Error get project description: ", e);
      return;
    }

    List<String> newIds = new ArrayList<String>();
    String[] natureIds = description.getNatureIds();
    for (String natureId : natureIds) {
      if (natureId.equals(NATURE_ID)) {
        return;
      }
    }

    newIds.addAll(Arrays.asList(natureIds));
    newIds.add(NATURE_ID);

    // Save description
    description.setNatureIds(newIds.toArray(new String[newIds.size()]));
    try {
      project.setDescription(description, null);
    } catch (CoreException e) {
      JsonLog.logError("Error set project description: ", e);
    }
  }
  /** 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());
  }
예제 #18
0
  private boolean isDjangoHandledModule(
      String djangoModulesHandling, IEditorInput input, String lastSegment) {
    boolean handled = false;
    if (djangoModulesHandling
            == PyTitlePreferencesPage.TITLE_EDITOR_DJANGO_MODULES_SHOW_PARENT_AND_DECORATE
        || djangoModulesHandling == PyTitlePreferencesPage.TITLE_EDITOR_DJANGO_MODULES_DECORATE) {

      if (input instanceof IFileEditorInput) {
        IFileEditorInput iFileEditorInput = (IFileEditorInput) input;
        IFile file = iFileEditorInput.getFile();
        IProject project = file.getProject();
        try {
          if (project.hasNature(PythonNature.DJANGO_NATURE_ID)) {
            if (PyTitlePreferencesPage.isDjangoModuleToDecorate(lastSegment)) {
              // remove the module name.
              handled = true;
            }
          }
        } catch (CoreException e) {
          Log.log(e);
        }
      }
    }
    return handled;
  }
 /**
  * @see
  *     com.ibm.sse.editor.extensions.hyperlink.IHyperlinkPartitionRecognizer#recognize(org.eclipse.jface.text.IDocument,
  *     com.ibm.sse.editor.extensions.hyperlink.IHyperlinkRegion)
  */
 public boolean recognize(IDocument document, int offset, IHyperlinkRegion region) {
   StructuredModelWrapper smw = new StructuredModelWrapper();
   smw.init(document);
   try {
     IFile documentFile = smw.getFile();
     if (documentFile == null) {
       return false;
     }
     IProject project = documentFile.getProject();
     if (project == null) {
       return false;
     }
     if (EclipseResourceUtil.getModelNature(project) != null) {
       for (int i = 0; i < JSF_PROJECT_NATURES.length; i++) {
         if (project.getNature(JSF_PROJECT_NATURES[i]) != null) return true;
       }
       return false;
     }
     return true;
   } catch (CoreException x) {
     JSFExtensionsPlugin.log("", x); // $NON-NLS-1$
     return false;
   } finally {
     smw.dispose();
   }
 }
예제 #20
0
  public void testResourceDelta() throws CoreException {
    IProject[] prjs = new IProject[] {fProject};
    fProject.create(new NullProgressMonitor());
    fProject.open(new NullProgressMonitor());

    IFile[] files = ResourceLookup.findFilesByName(new Path("abc.h"), prjs, true);
    assertEquals(0, files.length);

    IFolder f1 = createFolder(fProject, "folder1");
    createFolder(fProject, "folder2");
    IFile f2 = createFile(fProject, "abc.h");
    files = ResourceLookup.findFilesByName(new Path("abc.h"), prjs, true);
    assertEquals(1, files.length);

    createFile(fProject, "folder1/abc.h");
    files = ResourceLookup.findFilesByName(new Path("abc.h"), prjs, true);
    assertEquals(2, files.length);

    createFile(fProject, "folder2/abC.h");
    files = ResourceLookup.findFilesByName(new Path("abc.h"), prjs, true);
    assertEquals(3, files.length);

    f1.delete(true, new NullProgressMonitor());
    files = ResourceLookup.findFilesByName(new Path("abc.h"), prjs, true);
    assertEquals(2, files.length);

    f2.delete(true, new NullProgressMonitor());
    files = ResourceLookup.findFilesByName(new Path("abc.h"), prjs, true);
    assertEquals(1, files.length);
  }
  @Override
  public Composite createContents(final Composite parent) {
    if (mainComposite != null) {
      return mainComposite;
    }

    mainComposite = new Composite(parent, SWT.NONE);
    mainComposite.setLayout(new GridLayout());
    mainComposite.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false));

    objects =
        new MyFileListControl(
            mainComposite,
            project.getLocation().toOSString(),
            "additional object files ",
            "object");
    libraries = new MyListControl(mainComposite, "Libraries (-l)", "library");
    librarySearchPath =
        new MyFolderListControl(
            mainComposite,
            project.getLocation().toOSString(),
            "Library search path (-L)",
            "search path");

    disablePredefinedExtrnalDirs = new Button(mainComposite, SWT.CHECK);
    disablePredefinedExtrnalDirs.setText("Disable the entries of predefined libraries");
    disablePredefinedExtrnalDirs.setToolTipText(
        "Right now the OPENSSL_DIR and XMLDIR entries.\n"
            + " Please note that these folders are mandatory for the proper operation of TITAN.");

    return mainComposite;
  }
예제 #22
0
  public void testFindFilesByLocation() throws Exception {
    fProject.create(new NullProgressMonitor());
    fProject.open(new NullProgressMonitor());
    createFolder(fProject, "folder1");
    createFolder(fProject, "folder2");
    IFile file = createFile(fProject, "abc.h");
    createFile(fProject, "folder1/abc.h");
    createFile(fProject, "folder2/abC.h");

    URI uri = file.getLocationURI();
    IPath path = file.getLocation();
    IFile[] files = ResourceLookup.findFilesForLocationURI(uri);
    assertEquals(1, files.length);
    files = ResourceLookup.findFilesForLocation(path);
    assertEquals(1, files.length);

    if (new File("a").equals(new File("A"))) {
      URI upperCase =
          new URI(uri.getScheme(), uri.getSchemeSpecificPart().toUpperCase(), uri.getFragment());
      IPath upperCasePath = new Path(path.toString().toUpperCase());
      files = ResourceLookup.findFilesForLocationURI(upperCase);
      assertEquals(1, files.length);
      files = ResourceLookup.findFilesForLocation(upperCasePath);
      assertEquals(1, files.length);
    }
  }
예제 #23
0
  /**
   * Populate properties with everything required for the SonarLint analysis in issues mode.
   *
   * @param monitor
   * @param properties
   * @return
   */
  public Properties configureAnalysis(
      final IProgressMonitor monitor, List<SonarLintProperty> extraProps) {
    Properties properties = new Properties();
    IProject project = request.getProject();
    final File baseDir = project.getLocation().toFile();
    IPath projectSpecificWorkDir = project.getWorkingLocation(SonarLintCorePlugin.PLUGIN_ID);

    // Preview mode by default
    properties.setProperty(
        SonarLintProperties.ANALYSIS_MODE, SonarLintProperties.ANALYSIS_MODE_ISSUES);

    // Configuration by configurators (common and language specific)
    configure(project, this.request.getOnlyOnFiles(), properties, monitor);

    // Append workspace and project properties
    for (SonarLintProperty sonarProperty : extraProps) {
      properties.put(sonarProperty.getName(), sonarProperty.getValue());
    }
    if (this.request.getOnlyOnFiles() != null) {
      Collection<String> paths = new ArrayList<>(this.request.getOnlyOnFiles().size());
      for (IFile file : this.request.getOnlyOnFiles()) {
        MarkerUtils.deleteIssuesMarkers(file);
        paths.add(file.getProjectRelativePath().toString());
      }
      ProjectConfigurator.setPropertyList(properties, "sonar.tests", paths);
      ProjectConfigurator.setPropertyList(properties, "sonar.sources", paths);
    } else {
      MarkerUtils.deleteIssuesMarkers(project);
    }

    properties.setProperty(SonarLintProperties.PROJECT_BASEDIR, baseDir.toString());
    properties.setProperty(SonarLintProperties.WORK_DIR, projectSpecificWorkDir.toString());

    return properties;
  }
  @Override
  public boolean performFinish() {
    if (!super.performFinish()) {
      return false;
    }

    IProject newProject = getNewProject();

    try {

      IProjectDescription description = newProject.getDescription();
      String[] newNatures = new String[2];
      newNatures[0] = JavaCore.NATURE_ID;
      newNatures[1] = ActivitiConstants.NATURE_ID;
      description.setNatureIds(newNatures);
      newProject.setDescription(description, null);

      IJavaProject javaProject = JavaCore.create(newProject);

      createSourceFolders(newProject);
      createOutputLocation(javaProject);

      IClasspathEntry[] entries = createClasspathEntries(javaProject);

      javaProject.setRawClasspath(entries, null);
    } catch (Exception e) {
      e.printStackTrace();
      return false;
    }

    return true;
  }
예제 #25
0
  public static SDK getSDK(IProject project) {
    SDK retval = null;

    // try to determine SDK based on project location
    IPath projectLocation = project.getRawLocation();

    if (projectLocation == null) {
      projectLocation = project.getLocation();
    }

    if (projectLocation != null) {
      IPath sdkLocation = projectLocation.removeLastSegments(2);

      retval = SDKManager.getInstance().getSDK(sdkLocation);

      if (retval == null) {
        retval = SDKUtil.createSDKFromLocation(sdkLocation);

        if (retval != null) {
          SDKManager.getInstance().addSDK(retval);
        }
      }
    }

    return retval;
  }
예제 #26
0
  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"));
  }
  private IStatus validateProject() {
    hostPageProject = null;

    String str = projectField.getText().trim();
    if (str.length() == 0) {
      return Util.newErrorStatus("Enter the project name");
    }

    IPath path = new Path(str);
    if (path.segmentCount() != 1) {
      return Util.newErrorStatus("Invalid project path");
    }

    IProject project = Util.getWorkspaceRoot().getProject(str);
    if (!project.exists()) {
      return Util.newErrorStatus("Project does not exist");
    }

    if (!project.isOpen()) {
      return Util.newErrorStatus("Project is not open");
    }

    if (!GWTNature.isGWTProject(project)) {
      return Util.newErrorStatus("Project is not a GWT project");
    }

    hostPageProject = project;
    return Status.OK_STATUS;
  }
  @Test
  public void testNewLiferayModuleProjectNewProperties() throws Exception {
    NewLiferayModuleProjectOp op = NewLiferayModuleProjectOp.TYPE.instantiate();

    op.setProjectName("test-properties-in-portlet");

    op.setProjectTemplateName("portlet");
    op.setComponentName("Test");

    PropertyKey pk = op.getPropertyKeys().insert();

    pk.setName("property-test-key");
    pk.setValue("property-test-value");

    Status exStatus =
        NewLiferayModuleProjectOpMethods.execute(
            op, ProgressMonitorBridge.create(new NullProgressMonitor()));

    assertEquals("OK", exStatus.message());

    IProject modPorject = CoreUtil.getProject(op.getProjectName().content());
    modPorject.open(new NullProgressMonitor());

    SearchFilesVisitor sv = new SearchFilesVisitor();
    List<IFile> searchFiles = sv.searchFiles(modPorject, "TestPortlet.java");
    IFile componentClassFile = searchFiles.get(0);

    assertEquals(componentClassFile.exists(), true);

    String actual = CoreUtil.readStreamToString(componentClassFile.getContents());

    assertTrue(actual, actual.contains("\"property-test-key=property-test-value\""));
  }
예제 #29
0
  /**
   * ************************************************************************ Get the database path
   * for this project
   *
   * @return ***********************************************************************
   */
  @SuppressWarnings("unchecked")
  public String getDatabasePath() {
    HashMap<QualifiedName, Object> properties = null;
    try {
      properties = new HashMap<QualifiedName, Object>(m_project.getPersistentProperties());
    } catch (CoreException e1) {
      System.err.println(
          "Cannot retrieve persistent properties for project " + m_project.getName());
      return null;
    }
    if (!properties.containsKey(ProjectDatabaseProperty.GCS_DATABASE.getKey())) {
      restoreProjectProperties(ProjectDatabaseProperty.GCS_DATABASE);
    }

    try {
      String path = m_project.getPersistentProperty(ProjectDatabaseProperty.GCS_DATABASE.getKey());
      // Relative path
      boolean absolute = true;
      if (!path.isEmpty()) {
        absolute = new File(path).isAbsolute();
      }
      if (!path.isEmpty() && !absolute) {
        IPath projAbsolute = m_project.getLocation();
        String projectPath = projAbsolute.toFile().getAbsolutePath();
        path = projectPath + File.separator + path;
      }
      return path;
    } catch (CoreException e) {
      return null;
    }
  }
  public void testResolutionOfArchetypeFromRepository() throws Exception {
    String oldSettings = mavenConfiguration.getUserSettingsFile();
    try {
      mavenConfiguration.setUserSettingsFile(
          new File("settingsWithDefaultRepos.xml").getAbsolutePath());

      Archetype archetype = new Archetype();
      archetype.setGroupId("org.eclipse.m2e.its");
      archetype.setArtifactId("mngeclipse-2110");
      archetype.setVersion("1.0");
      archetype.setRepository("http://bad.host"); // should be mirrored by settings

      IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject("mngeclipse-2110");
      ProjectImportConfiguration pic = new ProjectImportConfiguration(new ResolverConfiguration());

      IProjectConfigurationManager manager =
          MavenPlugin.getDefault().getProjectConfigurationManager();
      manager.createArchetypeProject(
          project,
          null,
          archetype,
          "m2e.its",
          "mngeclipse-2110",
          "1.0-SNAPSHOT",
          "jar",
          new Properties(),
          pic,
          monitor);

      assertTrue(project.isAccessible());
    } finally {
      mavenConfiguration.setUserSettingsFile(oldSettings);
    }
  }