Example #1
0
 public Image decorateImage(Image baseImage, Object object) {
   IResource objectResource = (IResource) object;
   if (objectResource == null) {
     return null;
   }
   if (objectResource.getType() != IResource.PROJECT) {
     // Only projects are decorated
     return null;
   }
   IProject project = (IProject) objectResource;
   boolean isJava = false;
   try {
     if (project.hasNature(X10DTCorePlugin.X10_CPP_PRJ_NATURE_ID)) {
       isJava = false;
     } else if (project.hasNature(X10DTCorePlugin.X10_PRJ_JAVA_NATURE_ID)) {
       isJava = true;
     } else {
       return null;
     }
   } catch (CoreException e) {
     X10DTUIPlugin.getInstance().getLog().log(e.getStatus());
   }
   // Overlay custom image over base image
   ImageDescriptor[] desc = new ImageDescriptor[5];
   desc[1] = X10PluginImages.DESC_OVR_X10; // This is the X10 project decoration.
   if (isJava) desc[0] = X10PluginImages.DESC_OVR_JAVA;
   DecorationOverlayIcon overlayIcon = new DecorationOverlayIcon(baseImage, desc);
   return overlayIcon.createImage();
 }
  /**
   * Method returns nature of project.
   *
   * @param proj
   * @return
   */
  public static ProjExportType getProjectNature(IProject proj) {
    ProjExportType type = null;
    try {
      if (proj.hasNature(Messages.natJavaEMF)
          && proj.hasNature(Messages.natMdCore)
          && proj.hasNature(Messages.natFctCore)
          && proj.hasNature(Messages.natJava)
          && proj.hasNature(Messages.natJs)) {
        type = ProjExportType.WAR;
      } else if (proj.hasNature(Messages.natFctCore) && proj.hasNature(Messages.natMdCore)) {
        if (proj.hasNature(Messages.natJs)
            || proj.hasNature(Messages.natJava)
            || proj.hasNature(Messages.natJavaEMF)) {

          type = ProjExportType.JAR;
        } else {
          type = ProjExportType.EAR;
        }
      } else {
        type = ProjExportType.JAR;
      }
    } catch (CoreException e) {
      Activator.getDefault().log(e.getMessage(), e);
    }
    return type;
  }
 private void updateNature() throws CoreException {
   if (natureButton.getSelection()) {
     if (!project.hasNature(TeaVMEclipsePlugin.NATURE_ID)) {
       addNature(project);
     }
   } else {
     if (project.hasNature(TeaVMEclipsePlugin.NATURE_ID)) {
       removeNature(project);
     }
   }
 }
  /**
   * Processes a {@link IClasspathEntry} and add it to one of the list if applicable.
   *
   * @param entry the entry to process
   * @param javaProject the {@link IJavaProject} from which this entry came.
   * @param wsRoot the {@link IWorkspaceRoot}
   * @param projects the project list to add to
   * @param jarFiles the jar list to add to
   * @param includeJarFiles whether to include jar files or just projects. This is useful when
   *     calling on an Android project (value should be <code>false</code>)
   */
  private static void processCPE(
      IClasspathEntry entry,
      IJavaProject javaProject,
      IWorkspaceRoot wsRoot,
      Set<IProject> projects,
      Set<File> jarFiles,
      boolean includeJarFiles) {

    // if this is a classpath variable reference, we resolve it.
    if (entry.getEntryKind() == IClasspathEntry.CPE_VARIABLE) {
      entry = JavaCore.getResolvedClasspathEntry(entry);
    }

    if (entry.getEntryKind() == IClasspathEntry.CPE_PROJECT) {
      IProject refProject = wsRoot.getProject(entry.getPath().lastSegment());
      try {
        // ignore if it's an Android project, or if it's not a Java Project
        if (refProject.hasNature(JavaCore.NATURE_ID)
            && refProject.hasNature(AndmoreAndroidConstants.NATURE_DEFAULT) == false) {
          // add this project to the list
          projects.add(refProject);

          // also get the dependency from this project.
          getDependencyListFromClasspath(refProject, projects, jarFiles, true /*includeJarFiles*/);
        }
      } catch (CoreException exception) {
        // can't query the project nature? ignore
      }
    } else if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
      if (includeJarFiles) {
        handleClasspathLibrary(entry, wsRoot, jarFiles);
      }
    } else if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
      // get the container and its content
      try {
        IClasspathContainer container =
            JavaCore.getClasspathContainer(entry.getPath(), javaProject);
        // ignore the system and default_system types as they represent
        // libraries that are part of the runtime.
        if (container != null && container.getKind() == IClasspathContainer.K_APPLICATION) {
          IClasspathEntry[] entries = container.getClasspathEntries();
          for (IClasspathEntry cpe : entries) {
            processCPE(cpe, javaProject, wsRoot, projects, jarFiles, includeJarFiles);
          }
        }
      } catch (JavaModelException jme) {
        // can't resolve the container? ignore it.
        AndmoreAndroidPlugin.log(jme, "Failed to resolve ClasspathContainer: %s", entry.getPath());
      }
    }
  }
  @Override
  protected Control createContents(Composite parent) {
    project = (IProject) getElement().getAdapter(IProject.class);
    settings = TeaVMEclipsePlugin.getDefault().getSettings(project);

    Composite container = new Composite(parent, SWT.NONE);
    GridLayout layout = new GridLayout(1, false);
    layout.verticalSpacing = 10;
    layout.marginWidth = 10;
    container.setLayout(layout);

    natureButton = new Button(container, SWT.CHECK);
    natureButton.setText("Enable TeaVM");
    natureButton.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));

    Control profilesContainer = createProfilesContainer(container);
    profilesContainer.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

    try {
      natureButton.setSelection(project.hasNature(TeaVMEclipsePlugin.NATURE_ID));
    } catch (CoreException e) {
      reportStatus(e.getStatus());
    }
    loadProfiles();

    return container;
  }
  public static ESBArtifact getESBArtifactFromFile(
      IFile refactoredFile, String projectNatureFilter) {
    IProject esbProject = refactoredFile.getProject();
    try {
      esbProject.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());

      if (esbProject.isOpen() && esbProject.hasNature(projectNatureFilter)) {

        ESBProjectArtifact esbProjectArtifact = new ESBProjectArtifact();
        esbProjectArtifact.fromFile(esbProject.getFile("artifact.xml").getLocation().toFile());
        List<ESBArtifact> allESBArtifacts = esbProjectArtifact.getAllESBArtifacts();

        String originalFileRelativePath =
            FileUtils.getRelativePath(
                    esbProject.getLocation().toFile(), refactoredFile.getLocation().toFile())
                .replaceAll(Pattern.quote(File.separator), "/");

        for (ESBArtifact esbArtifact : allESBArtifacts) {
          if (esbArtifact.getFile().equals(originalFileRelativePath)) {
            return esbArtifact;
          }
        }
      }
    } catch (CoreException e) {
      log.error("Error while reading ESB Project", e);
    } catch (FactoryConfigurationError e) {
      log.error("Error while reading ESB Project", e);
    } catch (Exception e) {
      log.error("Error while reading ESB Project", e);
    }

    return null;
  }
  /**
   * Returns true for: - non-hidden projects - non-RDT projects - projects that does not have remote
   * systems temporary nature - projects that are located remotely
   */
  public boolean isCandidate(IProject project) {
    boolean a = false;
    boolean b = false;
    boolean c = false;
    boolean d = false;
    a = !project.isHidden();
    try {
      // b = !project.hasNature(RemoteNature.REMOTE_NATURE_ID);
      try {
        ServiceModelManager.getInstance().getConfigurations(project);
      } catch (ProjectNotConfiguredException e) {
        b = true;
      }
      c = !project.hasNature("org.eclipse.rse.ui.remoteSystemsTempNature"); // $NON-NLS-1$

      IHost host = RSEUtils.getConnection(project.getLocationURI());
      if (host != null) {
        d = !host.getSystemType().isLocal();
      } else {
        IFileStore fileStore = EFS.getStore(project.getLocationURI());
        if (fileStore != null) {
          if (!(fileStore instanceof LocalFile)) {
            d = true;
          }
        }
      }

    } catch (CoreException e) {
      RDTLog.logError(e);
    }

    return a && b && c && d;
  }
  /** {@inheritDoc} */
  public void setElement(IAdaptable element) {
    super.setElement(element);

    IProject project = null;

    try {

      //
      // Get the project.
      //

      IResource resource = (IResource) element;
      if (resource.getType() == IResource.PROJECT) {
        project = (IProject) resource;
      }

      IProjectConfiguration projectConfig = ProjectConfigurationFactory.getConfiguration(project);
      mProjectConfig = new ProjectConfigurationWorkingCopy(projectConfig);

      mCheckstyleInitiallyActivated = project.hasNature(CheckstyleNature.NATURE_ID);
    } catch (CoreException e) {
      handleConfigFileError(e, project);
    } catch (CheckstylePluginException e) {
      handleConfigFileError(e, project);
    }
  }
  @Override
  protected void setVersionNumber(
      final IProject project, final String newVersion, String notManagedProjectNames) {
    if (project.isOpen()) {
      try {
        if (project.hasNature(Utils.FEATURE_NATURE)) { // for features
          try {
            final IFeatureProjectEditor editor = new FeatureProjectEditor(project);
            editor.init();
            editor.setVersion(newVersion);
            editor.save();
          } catch (final ParserConfigurationException e) {
            Activator.log.error(e);
            notManagedProjectNames += NLS.bind("- {0} \n", project.getName());
          } catch (final SAXException e) {
            Activator.log.error(e);
            notManagedProjectNames += NLS.bind("- {0} \n", project.getName());
          } catch (final IOException e) {
            Activator.log.error(e);
            notManagedProjectNames += NLS.bind("- {0} \n", project.getName());
          } catch (final Throwable e) {
            Activator.log.error(e);
            notManagedProjectNames += NLS.bind("- {0} \n", project.getName());
          }

        } else {
          notManagedProjectNames += NLS.bind("- {0} \n", project.getName());
        }
      } catch (final CoreException e) {
        Activator.log.error(e);
      }
    } else {
      notManagedProjectNames += NLS.bind("- {0} \n", project.getName());
    }
  }
  public void decorate(Object element, IDecoration decoration) {
    if (!(element instanceof IResource)) return;
    IResource resource = (IResource) element;
    if (!resource.exists()) return;
    IProject project = resource.getProject();
    if (project == null) {
      Log.error(
          Messages.getString("ErrorDecorator.PROJECT_FOR")
              + resource.getName()
              + Messages.getString("ErrorDecorator.IS_NULL"),
          new Throwable()); //$NON-NLS-1$ //$NON-NLS-2$
      return;
    }
    try {
      if (!project.isOpen()) return;
      project.open(null);
      if (project.hasNature(LSLProjectNature.ID)) {
        LSLProjectNature nature = (LSLProjectNature) project.getNature(LSLProjectNature.ID);

        if (nature == null) return;

        IMarker[] m =
            resource.findMarkers("lslforge.problem", true, IResource.DEPTH_INFINITE); // $NON-NLS-1$

        if (m == null || m.length == 0) return;
      } else {
        return;
      }
    } catch (CoreException e) {
      Log.error("exception caught trying to determine project nature!", e); // $NON-NLS-1$
      return;
    }

    decoration.addOverlay(descriptor, IDecoration.BOTTOM_LEFT);
  }
  /**
   * 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 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();
      }
    }
  }
Example #13
0
  public static void addEGLPathToJavaPathIfNecessary(
      IJavaProject javaProject, IProject currProject, Set<IProject> seen, List<String> classpath) {
    if (seen.contains(currProject)) {
      return;
    }
    seen.add(currProject);

    try {
      if (currProject.hasNature(EGLCore.NATURE_ID)) {
        IEGLProject eglProject = EGLCore.create(currProject);
        for (IEGLPathEntry pathEntry : eglProject.getResolvedEGLPath(true)) {
          if (pathEntry.getEntryKind() == IEGLPathEntry.CPE_PROJECT) {
            IPath path = pathEntry.getPath();
            IResource resource = ResourcesPlugin.getWorkspace().getRoot().findMember(path);
            try {
              if (resource != null
                  && resource.getType() == IResource.PROJECT
                  && !seen.contains(resource)
                  && ((IProject) resource).hasNature(JavaCore.NATURE_ID)
                  && !javaProject.isOnClasspath(resource)) {
                classpath.add(getWorkspaceProjectClasspathEntry(resource.getName()));
                addEGLPathToJavaPathIfNecessary(javaProject, (IProject) resource, seen, classpath);
              }
            } catch (CoreException ce) {
            }
          }
        }
      }
    } catch (EGLModelException e) {
    } catch (CoreException e) {
    }
  }
  protected List<String> getSourceFolders(IProject project) {
    List<String> result = new ArrayList<String>();
    IJavaProject javaProject = JavaCore.create(project);
    IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();

    try {
      for (IPackageFragmentRoot packageFragmentRoot : javaProject.getPackageFragmentRoots()) {
        if (packageFragmentRoot.getKind() == IPackageFragmentRoot.K_SOURCE) {
          IPath path = packageFragmentRoot.getPath();
          IFolder folder = root.getFolder(path);
          String location = folder.getLocation().toString();

          if (!location.contains("src-gen")) {
            result.add(location);
          }
        }
      }

      for (IProject referencedProject : javaProject.getProject().getReferencedProjects()) {
        if (referencedProject.isAccessible() && referencedProject.hasNature(JavaCore.NATURE_ID)) {
          result.addAll(getSourceFolders(referencedProject));
        }
      }

    } catch (JavaModelException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();

    } catch (CoreException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }

    return result;
  }
  @Override
  public void execute(
      IProject project, IProjectFacetVersion version, Object object, IProgressMonitor progress)
      throws CoreException {
    if (!project.hasNature(PHPNature.ID)) {
      return;
    }

    progress.subTask("Installing composer nature");

    // add the composer nature
    ResourceUtil.addNature(project, progress, ComposerNature.NATURE_ID);

    progress.subTask("Installing composer buildpath");

    // maybe comment out this one:
    // create composer buildpath entry

    //		if (ComposerPlugin.getDefault().isBuildpathContainerEnabled()) {
    //			IScriptProject scriptProject = DLTKCore.create(project);
    //			IBuildpathContainer composerContainer = new ComposerBuildpathContainer(
    //					new Path(ComposerBuildpathContainerInitializer.CONTAINER),
    //					scriptProject);
    //			List<IBuildpathEntry> entries = new ArrayList<IBuildpathEntry>();
    //			entries.add(DLTKCore.newContainerEntry(composerContainer.getPath()));
    //
    //			// add the composer buildpathentry to the project
    //			BuildPathUtils.addEntriesToBuildPath(scriptProject, entries);
    //
    //			BuildpathUtil.setupVendorBuildpath(scriptProject, progress);
    //
    //		}
  }
Example #16
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;
  }
 private boolean canAddExportedPackages() {
   // Ensure model is editable
   if (isEditable() == false) {
     return false;
   }
   // Get the model
   IPluginModelBase model = getModel();
   // Ensure model is defined
   if (model == null) {
     return false;
   }
   // Get the underlying resource
   IResource resource = model.getUnderlyingResource();
   // Ensure resource is defined
   if (resource == null) {
     return false;
   }
   // Get the project
   IProject project = resource.getProject();
   // Ensure the project is defined
   if (project == null) {
     return false;
   }
   // Ensure the project is a Java project
   try {
     if (project.hasNature(JavaCore.NATURE_ID) == false) {
       return false;
     }
   } catch (CoreException e) {
     return false;
   }
   return true;
 }
  /**
   * Add a Java Nature to a project when creating
   *
   * @param project
   * @throws CoreException
   */
  private static void addJavaNature(final IProject project) throws CoreException {
    if (!project.hasNature(JavaCore.NATURE_ID)) {
      final IProjectDescription description = project.getDescription();
      final String[] prevNatures = description.getNatureIds();
      final String[] newNatures = new String[prevNatures.length + 1];
      System.arraycopy(prevNatures, 0, newNatures, 0, prevNatures.length);
      newNatures[prevNatures.length] = JavaCore.NATURE_ID;
      description.setNatureIds(newNatures);
      project.setDescription(description, null);
      IFolder sourceFolder = project.getFolder("/src");
      sourceFolder.create(true, true, null);

      IJavaProject javaProject = JavaCore.create(project);
      javaProject.setRawClasspath(
          new IClasspathEntry[] {
            JavaCore.newSourceEntry(sourceFolder.getFullPath()),
            JavaCore.newContainerEntry(new Path("org.eclipse.jdt.launching.JRE_CONTAINER"))
          },
          null);

      @SuppressWarnings("unchecked")
      Hashtable<String, String> javaOptions = JavaCore.getOptions();
      javaOptions.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_5);
      javaOptions.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_5);
      javaOptions.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_5);
      javaProject.setOptions(javaOptions);
    }
  }
 /**
  * Test sample project with a virtual folder that points to configure scripts. Tests Bug 434275 -
  * Autotools configuration in subfolder not found
  *
  * @throws Exception
  */
 @Test
 public void testAutotoolsVirtualFolder() throws Exception {
   Path p = new Path("zip/project2.zip");
   IWorkspaceRoot root = ProjectTools.getWorkspaceRoot();
   IPath rootPath = root.getLocation();
   IPath configPath = rootPath.append("config");
   File configDir = configPath.toFile();
   configDir.deleteOnExit();
   assertTrue(configDir.mkdir());
   ProjectTools.createLinkedFolder(
       testProject, "src", URIUtil.append(root.getLocationURI(), "config"));
   ProjectTools.addSourceContainerWithImport(testProject, "src", p);
   assertTrue(testProject.hasNature(AutotoolsNewProjectNature.AUTOTOOLS_NATURE_ID));
   assertTrue(exists("src/ChangeLog"));
   ProjectTools.setConfigDir(testProject, "src");
   ProjectTools.markExecutable(testProject, "src/autogen.sh");
   assertFalse(exists("src/configure"));
   assertFalse(exists("src/Makefile.in"));
   assertFalse(exists("src/sample/Makefile.in"));
   assertFalse(exists("src/aclocal.m4"));
   assertTrue(ProjectTools.build());
   assertTrue(exists("src/configure"));
   assertTrue(exists("src/Makefile.in"));
   assertTrue(exists("src/sample/Makefile.in"));
   assertTrue(exists("src/aclocal.m4"));
   assertTrue(exists("config.status"));
   assertTrue(exists("Makefile"));
   String extension = Platform.getOS().equals(Platform.OS_WIN32) ? ".exe" : "";
   assertTrue(exists("sample/a.out" + extension));
   assertTrue(exists("sample/Makefile"));
 }
  public boolean select(Viewer viewer, Object parentElement, Object element) {
    if (element instanceof IFolder) {
      IFolder folder = (IFolder) element;
      IProject project = folder.getProject();
      try {
        if (project.hasNature(IMavenConstants.NATURE_ID)) {
          IMavenProjectRegistry projectManager = MavenPlugin.getMavenProjectRegistry();

          IMavenProjectFacade projectFacade = projectManager.create(project, null);
          if (projectFacade != null) {
            // XXX implement corner cases
            // modules have ".." in the path
            // modules have more then one segment in the path
            // modules not imported in workspace
            MavenProject mavenProject = projectFacade.getMavenProject(null);
            IPath folderPath = folder.getFullPath();

            // workspace-relative path sans project name
            String folderName = folderPath.removeFirstSegments(1).toPortableString();

            if (mavenProject.getModules().contains(folderName)) {
              return false;
            }
          }
        }
      } catch (CoreException ex) {
        log.error(ex.getMessage(), ex);
      }
    }
    return true;
  }
  private void refresh(IAction action) {

    action.setEnabled(false);

    IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();

    /*
     *  check whether there is at least one disconnected ispyb project
     *  in order to enable the sweep icat button
     */
    IProject[] projectsList = root.getProjects();
    for (int count = 0; count < projectsList.length; count++) {

      IProject currentProject = ((IProject) projectsList[count]);

      boolean isDiscICATProject = false;
      try {
        isDiscICATProject = currentProject.hasNature(DISC_ICAT_NATURE);
      } catch (CoreException e) {
        logger.error("problem retrieving project nature");
      }

      if (isDiscICATProject) {
        action.setEnabled(true);
        break;
      }
    }
  }
  private IProject guessProject(IStructuredSelection selection) {
    if (selection == null) {
      return null;
    }

    for (Object element : selection.toList()) {
      if (element instanceof IAdaptable) {
        IResource res = (IResource) ((IAdaptable) element).getAdapter(IResource.class);
        IProject project = res != null ? res.getProject() : null;

        // Is this an Android project?
        try {
          if (project == null || !project.hasNature(AdtConstants.NATURE_DEFAULT)) {
            continue;
          }
        } catch (CoreException e) {
          // checking the nature failed, ignore this resource
          continue;
        }

        return project;
      } else if (element instanceof Pair<?, ?>) {
        // Pair of Project/String
        @SuppressWarnings("unchecked")
        Pair<IProject, String> pair = (Pair<IProject, String>) element;
        return pair.getFirst();
      }
    }

    // Try to figure out the project from the active editor
    IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    if (window != null) {
      IWorkbenchPage page = window.getActivePage();
      if (page != null) {
        IEditorPart activeEditor = page.getActiveEditor();
        if (activeEditor instanceof AndroidXmlEditor) {
          Object input = ((AndroidXmlEditor) activeEditor).getEditorInput();
          if (input instanceof FileEditorInput) {
            FileEditorInput fileInput = (FileEditorInput) input;
            return fileInput.getFile().getProject();
          }
        }
      }
    }

    IJavaProject[] projects =
        BaseProjectHelper.getAndroidProjects(
            new IProjectFilter() {
              public boolean accept(IProject project) {
                return project.isAccessible();
              }
            });

    if (projects != null && projects.length == 1) {
      return projects[0].getProject();
    }

    return null;
  }
        public Map<String, IStatus> validate(Object value, Object context) {

          if (value == null || "".equals(value)) { // $NON-NLS-1$
            return createErrormessage(
                new Status(
                    IStatus.ERROR,
                    SeamCorePlugin.PLUGIN_ID,
                    SeamCoreMessages.VALIDATOR_FACTORY_PRJ_NOT_SELECTED));
          }
          IResource project = ResourcesPlugin.getWorkspace().getRoot().findMember(value.toString());

          if (project == null || !(project instanceof IProject) || !project.exists()) {
            return createErrormessage(
                new Status(
                    IStatus.ERROR,
                    SeamCorePlugin.PLUGIN_ID,
                    NLS.bind(SeamCoreMessages.VALIDATOR_FACTORY_PROJECT_DOES_NOT_EXIST, value)));
          } else {
            IProject selection = (IProject) project;
            try {
              if (!selection.hasNature(ISeamProject.NATURE_ID)
                  || SeamCorePlugin.getSeamPreferences(selection) == null
                  // ||
                  // selection.getAdapter(IFacetedProject.class)==null
                  // || !((IFacetedProject)selection.getAdapter(
                  // IFacetedProject
                  // .class)).hasProjectFacet(ProjectFacetsManager
                  // .getProjectFacet("jst.web"))
                  || ""
                      .equals(
                          SeamCorePlugin.getSeamPreferences(selection)
                              .get(
                                  ISeamFacetDataModelProperties.JBOSS_AS_DEPLOY_AS,
                                  ""))) { //$NON-NLS-1$
                return createErrormessage(
                    new Status(
                        IStatus.ERROR,
                        SeamCorePlugin.PLUGIN_ID,
                        NLS.bind(
                            SeamCoreMessages
                                .VALIDATOR_FACTORY_SELECTED_PROJECT_IS_NOT_A_SEAM_WEB_PROJECT,
                            project.getName())));
              } else {
                // TODO validate project(s) structure
              }
            } catch (CoreException e) {
              // it might happen only if project is closed and project
              // name typed by hand
              return createErrormessage(
                  new Status(
                      IStatus.ERROR,
                      SeamCorePlugin.PLUGIN_ID,
                      NLS.bind(
                          SeamCoreMessages.VALIDATOR_FACTORY_SELECTED_PRJ_IS_CLOSED,
                          project.getName())));
            }
          }
          return NO_ERRORS;
        }
Example #24
0
 /**
  * Return if the project has the given nature.
  *
  * @param project
  * @param natureId
  * @return <code>true</code> if project has given nature
  * @since 1.0.0
  */
 public static boolean hasRuntime(IProject project, String natureId) {
   if (project == null || !project.isAccessible()) return false;
   try {
     return project.hasNature(natureId);
   } catch (CoreException e) {
     return false;
   }
 }
 private boolean isJavaProject(IProject project) {
   try {
     return project.isAccessible() && project.hasNature(JavaCore.NATURE_ID);
   } catch (CoreException e) {
     SpringPropertiesEditorPlugin.log(e);
   }
   return false;
 }
Example #26
0
 public static boolean hasTapestryNature(IProject project) {
   try {
     return project.hasNature(TapestryCorePlugin.NATURE_ID);
   } catch (CoreException e) {
     // eat it
   }
   return false;
 }
 protected void applyNatures(String[] natures, IProject project, IProgressMonitor monitor)
     throws CoreException {
   for (String nature : natures) {
     if (!project.hasNature(nature)) {
       ResourceUtil.addNature(project, monitor, nature);
     }
   }
 }
  public ImplementationModel createImplementationModel(IProject project) {
    try {
      if (project.hasNature(JavaAC.NATURE_ID)) return new JavaModel(JavaCore.create(project));
    } catch (CoreException e) {
      e.printStackTrace();
    }

    return null;
  }
  /**
   * Process reference projects from the main projects to add indirect dependencies coming from Java
   * project.
   *
   * @param project the main project
   * @param projects the project list to add to
   * @param jarFiles the jar list to add to.
   */
  private static void processReferencedProjects(
      IProject project, Set<IProject> projects, Set<File> jarFiles) {
    try {
      IProject[] refs = project.getReferencedProjects();
      for (IProject p : refs) {
        // ignore if it's an Android project, or if it's not a Java
        // Project
        if (p.hasNature(JavaCore.NATURE_ID)
            && p.hasNature(AndmoreAndroidConstants.NATURE_DEFAULT) == false) {

          // process this project's dependencies
          getDependencyListFromClasspath(p, projects, jarFiles, true /*includeJarFiles*/);
        }
      }
    } catch (CoreException e) {
      // can't get the referenced projects? ignore
    }
  }
  public static boolean hasNature(IProject project) {

    try {
      return project.isOpen() && project.hasNature(NATURE_ID);
    } catch (CoreException e) {
      JsonLog.logError("Error determining if project has nature.: ", e);
      return false;
    }
  }