org.eclipse.core.resources.IProjectNature Java Examples

The following examples show how to use org.eclipse.core.resources.IProjectNature. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SiriusServiceConfigurator.java    From M2Doc with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Gets the {@link ModelingProject} for the given {@link IProject}.
 * 
 * @param project
 *            the {@link IProject}
 * @return the {@link ModelingProject} for the given {@link IProject} if any, <code>null</code> otherwise
 */
private ModelingProject getModelingProject(IProject project) {
    ModelingProject modelingProject = null;
    try {
        for (String natureId : project.getDescription().getNatureIds()) {
            IProjectNature nature = project.getNature(natureId);
            if (nature instanceof ModelingProject) {
                modelingProject = (ModelingProject) nature;
                break;
            }
        }
    } catch (CoreException e) {
        /* does nothing */
    }
    return modelingProject;
}
 
Example #2
Source File: XdsModel.java    From xds-ide with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public XdsProject getXdsProjectBy(IProject p) {
    IProjectNature nature;
    try {
        nature = p.isOpen() ? p.getNature(NatureIdRegistry.MODULA2_SOURCE_PROJECT_NATURE_ID) : null;
        if (nature == null){
            return null;
        }
    } catch (CoreException e) {
        LogHelper.logError(e);
        return null;
    }
    Lock readLock = instanceLock.readLock();
    try{
    	readLock.lock();
    	return name2XdsProject.get(p.getName());
    }
    finally {
    	readLock.unlock();
    }
}
 
Example #3
Source File: ActionUtil.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public static boolean isOnBuildPath(IJavaElement element) {
       //fix for bug http://dev.eclipse.org/bugs/show_bug.cgi?id=20051
       if (element.getElementType() == IJavaElement.JAVA_PROJECT)
           return true;
	IJavaProject project= element.getJavaProject();
	try {
		if (!project.isOnClasspath(element))
			return false;
		IProject resourceProject= project.getProject();
		if (resourceProject == null)
			return false;
		IProjectNature nature= resourceProject.getNature(JavaCore.NATURE_ID);
		// We have a Java project
		if (nature != null)
			return true;
	} catch (CoreException e) {
	}
	return false;
}
 
Example #4
Source File: JavaUtils.java    From developer-studio with Apache License 2.0 6 votes vote down vote up
public static IJavaProject addJavaNature(IProject project, boolean rawClasspath) throws CoreException, JavaModelException {
 
	 IProjectNature nature = project.getNature(ProjectConstants.JAVA_NATURE_ID);
	 if(nature==null){
	    ProjectUtils.addNatureToProject(project, true, ProjectConstants.JAVA_NATURE_ID);
	 }
	IJavaProject javaProject = JavaCore.create(project);
	IFolder targetFolder = project.getFolder("target");
	targetFolder.create(false, true, null);
	javaProject.setOutputLocation(targetFolder.getFullPath(), null);
	Set<IClasspathEntry> entries = new HashSet<IClasspathEntry>();
	if(rawClasspath){
		entries.addAll(Arrays.asList(getClasspathEntries(javaProject)));
	}
	if(nature==null){
		entries.add(JavaRuntime.getDefaultJREContainerEntry());
	 }
	javaProject.setRawClasspath(entries.toArray(new IClasspathEntry[entries.size()]), null);
	return javaProject;
}
 
Example #5
Source File: RadlCreator.java    From RADL with Apache License 2.0 6 votes vote down vote up
public IFile createRadlFile(String folderName, String serviceName, IProgressMonitor monitor,
    IWorkspaceRoot root) throws CoreException {
  IFolder folder = root.getFolder(new Path(folderName));
  if (!folder.exists()) {
    ensureFolder(monitor, folder);
  }
  final IFile result = folder.getFile(serviceNameToFileName(serviceName));
  try (InputStream stream = getRadlSkeleton(serviceName)) {
    if (result.exists()) {
      result.setContents(stream, true, true, monitor);
    } else {
      result.create(stream, true, monitor);
    }
  } catch (IOException e) { // NOPMD EmptyCatchBlock
  }
  IProjectNature nature = new RadlNature();
  nature.setProject(folder.getProject());
  nature.configure();
  return result;
}
 
Example #6
Source File: DocumentUimaImpl.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
/**
 * Gets the project class loader.
 *
 * @param project the project
 * @return the project class loader
 * @throws CoreException the core exception
 */
public static ClassLoader getProjectClassLoader(IProject project) throws CoreException {
  IProjectNature javaNature = project.getNature(JAVA_NATURE);
  if (javaNature != null) {
    JavaProject javaProject = (JavaProject) JavaCore.create(project);
    
    String[] runtimeClassPath = JavaRuntime.computeDefaultRuntimeClassPath(javaProject);
    List<URL> urls = new ArrayList<>();
    for (String cp : runtimeClassPath) {
      try {
        urls.add(Paths.get(cp).toUri().toURL());
      } catch (MalformedURLException e) {
        CasEditorPlugin.log(e);
      }
    }
    return new URLClassLoader(urls.toArray(new URL[0]));
  } 
  return null;
}
 
Example #7
Source File: DjangoNature.java    From Pydev with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * @param project the project we want to know about (if it is null, null is returned)
 * @return the django nature for a project (or null if it does not exist for the project)
 * 
 * @note: it's synchronized because more than 1 place could call getDjangoNature at the same time and more
 * than one nature ended up being created from project.getNature().
 */
public static DjangoNature getDjangoNature(IProject project) {
    if (project != null && project.isOpen()) {
        try {
            if (project.hasNature(DJANGO_NATURE_ID)) {
                synchronized (lockGetNature) {
                    IProjectNature n = project.getNature(DJANGO_NATURE_ID);
                    if (n instanceof DjangoNature) {
                        return (DjangoNature) n;
                    }
                }
            }
        } catch (CoreException e) {
            Log.logInfo(e);
        }
    }
    return null;
}
 
Example #8
Source File: AbstractProjectPreferencesPage.java    From uml2solidity with Eclipse Public License 1.0 5 votes vote down vote up
public void setElement(IAdaptable element) {
	if (element instanceof IProject) {
		project = (IProject) element;
	} else if (element instanceof IProjectNature) {
		IProjectNature pn = (IProjectNature) element;
		project = pn.getProject();
	}
}
 
Example #9
Source File: JavaProjectModulesManagerCreator.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * This method will check the given project and if it's a java project, will create a project modules manager
 * that can be used to get things from it as we need in pydev.
 */
public static IModulesManager createJavaProjectModulesManagerIfPossible(IProject project) {
    if (JDTSupported == false) {
        return null;
    }

    try {
        if (project.isOpen()) {
            IProjectNature nature = project.getNature(JavaCore.NATURE_ID);
            if (nature instanceof IJavaProject) {
                IJavaProject javaProject = (IJavaProject) nature;
                return new JavaProjectModulesManager(javaProject);
            }
        }
    } catch (Throwable e) {
        if (JythonModulesManagerUtils.isOptionalJDTClassNotFound(e)) {
            //ignore it at this point: we don't have JDT... set the static variable to it and don't even
            //try to get to this point again (no need to log it or anything).
            JDTSupported = false;
            return null;
        } else {
            Log.log(e);
        }
    }

    return null;
}
 
Example #10
Source File: ProjectStub.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public IProjectNature getNature(String natureId) throws CoreException {
    if (nature == null) {
        throw new RuntimeException("not expected");
    }
    return nature;
}
 
Example #11
Source File: ProjectStub.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public IProjectNature getNature(String natureId) throws CoreException {
    if (nature == null) {
        throw new RuntimeException("not expected");
    }
    return nature;
}
 
Example #12
Source File: ProjectStub.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
public ProjectStub(File file, IProjectNature nature, boolean addNullChild, List<Object> additionalChildren) {
    Assert.isTrue(file.exists() && file.isDirectory());
    this.projectRoot = file;
    this.nature = nature;
    this.addNullChild = addNullChild;
    this.additionalChildren = additionalChildren;
}
 
Example #13
Source File: ProjectStub.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public IProjectNature getNature(String natureId) throws CoreException {
    if (nature == null) {
        throw new RuntimeException("not expected");
    }
    return nature;
}
 
Example #14
Source File: ProjectStub.java    From Pydev with Eclipse Public License 1.0 4 votes vote down vote up
public ProjectStub(File file, IProjectNature nature) {
    this(file, nature, false);
}
 
Example #15
Source File: ProjectStub.java    From Pydev with Eclipse Public License 1.0 4 votes vote down vote up
public ProjectStub(File file, IProjectNature nature, boolean addNullChild) {
    this(file, nature, addNullChild, new ArrayList<Object>());
}
 
Example #16
Source File: ProjectStub.java    From Pydev with Eclipse Public License 1.0 4 votes vote down vote up
public ProjectStub(File file, IProjectNature nature, boolean addNullChild, List<Object> additionalChildren) {
    Assert.isTrue(file.exists() && file.isDirectory());
    this.projectRoot = file;
    this.nature = nature;
}
 
Example #17
Source File: ProjectStub.java    From Pydev with Eclipse Public License 1.0 4 votes vote down vote up
public ProjectStub(File file, IProjectNature nature, boolean addNullChild) {
    this(file, nature, addNullChild, new ArrayList<Object>());
}
 
Example #18
Source File: ProjectStub.java    From Pydev with Eclipse Public License 1.0 4 votes vote down vote up
public ProjectStub(File file, IProjectNature nature) {
    this(file, nature, false);
}
 
Example #19
Source File: ProjectMock.java    From Pydev with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public IProjectNature getNature(String natureId) throws CoreException {
    return this.nature;
}
 
Example #20
Source File: ProjectMock.java    From Pydev with Eclipse Public License 1.0 4 votes vote down vote up
public void setNature(IProjectNature pythonNatureStub) {
    this.nature = pythonNatureStub;
}
 
Example #21
Source File: AbstractIProjectStub.java    From Pydev with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public IProjectNature getNature(String natureId) throws CoreException {
    return null;
}