Java Code Examples for org.eclipse.core.resources.IProject#getName()

The following examples show how to use org.eclipse.core.resources.IProject#getName() . 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: PlantUmlExportTestUtils.java    From txtUML with Eclipse Public License 1.0 6 votes vote down vote up
public static IProject getModelsProject() throws IOException, CoreException {
	String projectPath = new File(TEST_MODEL_PATH).getCanonicalPath();
	IWorkspace workspace = ResourcesPlugin.getWorkspace();

	IProjectDescription description = workspace
			.loadProjectDescription(new Path(projectPath + Path.SEPARATOR + PROJECT_FILE));
	IProject genericProject = workspace.getRoot().getProject(description.getName());

	if (!genericProject.exists()) {
		genericProject.create(description, new NullProgressMonitor());
	}

	genericProject.open(new NullProgressMonitor());
	if (!genericProject.isOpen()) {
		throw new RuntimeException("Couldn't open project: " + genericProject.getName());
	}
	project = JavaCore.create(genericProject);
	genericProject.refreshLocal(IProject.DEPTH_INFINITE, new NullProgressMonitor());

	return genericProject;
}
 
Example 2
Source File: QueuedBuildData.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
public void queueURI(URI uri) {
	Iterable<Pair<IStorage, IProject>> iterable = mapper.getStorages(uri);
	boolean associatedWithProject = false;
	for (Pair<IStorage, IProject> pair : iterable) {
		IProject project = pair.getSecond();
		if (XtextProjectHelper.hasNature(project) && XtextProjectHelper.hasBuilder(project)) {
			String projectName = project.getName();
			LinkedHashSetQueue<URI> list = projectNameToChangedResource.get(projectName);
			if (list == null) {
				list = new LinkedHashSetQueue<>();
				projectNameToChangedResource.put(projectName, list);
			}
			list.add(uri);
			associatedWithProject = true;
		}
	}
	if (!associatedWithProject) {
		this.uris.add(uri);
	}
}
 
Example 3
Source File: AppEngineLabelProvider.java    From google-cloud-eclipse with Apache License 2.0 6 votes vote down vote up
@VisibleForTesting
static StyledString getAppEngineProjectText(IProject project) {
  try {
    AppEngineProjectElement projectElement = AppEngineContentProvider.loadRepresentation(project);
    StyledString result = new StyledString(project.getName());
    String qualifier = getVersionTuple(projectElement);
    if (qualifier.length() > 0) {
      result.append(" [", StyledString.QUALIFIER_STYLER); //$NON-NLS-1$
      result.append(qualifier.toString(), StyledString.QUALIFIER_STYLER);
      result.append("]", StyledString.QUALIFIER_STYLER); //$NON-NLS-1$
    }
    return result;
  } catch (AppEngineException ex) {
    // ignore
  }
  return null; // carry onto the next label provider
}
 
Example 4
Source File: ResolveMainMethodHandler.java    From java-debug with Eclipse Public License 1.0 6 votes vote down vote up
private static MainMethod extractMainMethodInfo(ICompilationUnit typeRoot, IMethod method) throws JavaModelException {
    final Range range = getRange(typeRoot, method);
    IResource resource = typeRoot.getResource();
    if (resource != null) {
        IProject project = resource.getProject();
        if (project != null) {
            String mainClass = method.getDeclaringType().getFullyQualifiedName();
            IJavaProject javaProject = JdtUtils.getJavaProject(project);
            if (javaProject != null) {
                String moduleName = JdtUtils.getModuleName(javaProject);
                if (moduleName != null) {
                    mainClass = moduleName + "/" + mainClass;
                }
            }

            String projectName = ProjectsManager.DEFAULT_PROJECT_NAME.equals(project.getName()) ? null : project.getName();
            return new MainMethod(range, mainClass, projectName);
        }
    }

    return null;
}
 
Example 5
Source File: SimpleRunner.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Creates a string that can be passed as the PYTHONPATH
 *
 * @param project the project we want to get the settings from. If it is null, the system pythonpath is returned
 * @param interpreter this is the interpreter to be used to create the env.
 * @return a string that can be used as the PYTHONPATH env variable
 */
public static String makePythonPathEnvString(IPythonNature pythonNature, IInterpreterInfo interpreter,
        IInterpreterManager manager) {
    if (pythonNature == null) {
        if (interpreter == null) {
            return makePythonPathEnvFromPaths(new ArrayList<String>()); //no pythonpath can be gotten (set to empty, so that the default is gotten)
        } else {
            List<String> pythonPath = interpreter.getPythonPath();
            return makePythonPathEnvFromPaths(pythonPath);
        }
    }

    List<String> paths;

    //if we have a project, get its complete pythonpath
    IPythonPathNature pythonPathNature = pythonNature.getPythonPathNature();
    if (pythonPathNature == null) {
        IProject project = pythonNature.getProject();
        String projectName;
        if (project == null) {
            projectName = "null?";
        } else {
            projectName = project.getName();
        }
        throw new RuntimeException("The project " + projectName + " does not have the pythonpath configured, \n"
                + "please configure it correcly (please check the pydev getting started guide at \n"
                + "http://pydev.org/manual_101_root.html for better information on how to do it).");
    }
    paths = pythonPathNature.getCompleteProjectPythonPath(interpreter, manager);

    return makePythonPathEnvFromPaths(paths);
}
 
Example 6
Source File: LauncherTabMain.java    From xds-ide with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void setDefaults(ILaunchConfigurationWorkingCopy config) {
    String prjName = null;
    String exePath = null;
    IProject xdsPrj = getCurrentXdsProject();
    if (xdsPrj != null && xdsPrj.exists()) {
        prjName = xdsPrj.getName();
        XdsProjectConfiguration conf = new XdsProjectConfiguration(xdsPrj);
        exePath = conf.getExePath();
    }
    config.setAttribute(ILaunchConfigConst.ATTR_PROJECT_NAME, prjName);
    config.setAttribute(ILaunchConfigConst.ATTR_EXECUTABLE_PATH, exePath);
}
 
Example 7
Source File: DerbyServerUtils.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
public void startDerbyServer( IProject proj) throws CoreException {
	String args = CommonNames.START_DERBY_SERVER;
	String vmargs="";
	DerbyProperties dprop=new DerbyProperties(proj);
	//Starts the server as a Java app
	args+=" -h "+dprop.getHost()+ " -p "+dprop.getPort();
	
	//Set Derby System Home from the Derby Properties
	if((dprop.getSystemHome()!=null)&& !(dprop.getSystemHome().equals(""))){
		vmargs=CommonNames.D_SYSTEM_HOME+dprop.getSystemHome();
	}
	String procName="["+proj.getName()+"] - "+CommonNames.DERBY_SERVER+" "+CommonNames.START_DERBY_SERVER+" ("+dprop.getHost()+ ", "+dprop.getPort()+")";
	ILaunch launch = DerbyUtils.launch(proj, procName ,		
	CommonNames.DERBY_SERVER_CLASS, args, vmargs, CommonNames.START_DERBY_SERVER);
	IProcess ip=launch.getProcesses()[0];
	//set a name to be seen in the Console list
	ip.setAttribute(IProcess.ATTR_PROCESS_LABEL,procName);
	
	// saves the mapping between (server) process and project
	//servers.put(launch.getProcesses()[0], proj);
	servers.put(ip, proj);
	// register a listener to listen, when this process is finished
	DebugPlugin.getDefault().addDebugEventListener(listener);
	//Add resource listener
	IWorkspace workspace = ResourcesPlugin.getWorkspace();
	
	workspace.addResourceChangeListener(rlistener);
	setRunning(proj, Boolean.TRUE);
	Shell shell = new Shell();
	MessageDialog.openInformation(
		shell,
		CommonNames.PLUGIN_NAME,
		Messages.D_NS_ATTEMPT_STARTED+dprop.getPort()+".");

}
 
Example 8
Source File: ReorgPolicyFactory.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public final ChangeDescriptor getDescriptor() {
	final Map<String, String> arguments= new HashMap<>();
	final int length= fFiles.length + fFolders.length + fCus.length;
	final String description= length == 1 ? getDescriptionSingular() : getDescriptionPlural();
	final IProject resource= getSingleProject();
	final String project= resource != null ? resource.getName() : null;
	final String header= length == 1 ? Messages.format(getHeaderPatternSingular(), new String[] { getSingleElementName(), getDestinationLabel() }) : Messages.format(
			getHeaderPatternPlural(),
			new String[] { String.valueOf(length), getDestinationLabel() });
	int flags= JavaRefactoringDescriptor.JAR_MIGRATION | JavaRefactoringDescriptor.JAR_REFACTORING | RefactoringDescriptor.STRUCTURAL_CHANGE | RefactoringDescriptor.MULTI_CHANGE;
	final JDTRefactoringDescriptorComment comment= new JDTRefactoringDescriptorComment(project, this, header);
	arguments.put(ATTRIBUTE_POLICY, getPolicyId());
	arguments.put(ATTRIBUTE_FILES, new Integer(fFiles.length).toString());
	for (int offset= 0; offset < fFiles.length; offset++) {
		arguments.put(JavaRefactoringDescriptorUtil.ATTRIBUTE_ELEMENT + (offset + 1), JavaRefactoringDescriptorUtil.resourceToHandle(project, fFiles[offset]));
	}
	arguments.put(ATTRIBUTE_FOLDERS, new Integer(fFolders.length).toString());
	for (int offset= 0; offset < fFolders.length; offset++) {
		arguments.put(JavaRefactoringDescriptorUtil.ATTRIBUTE_ELEMENT + (offset + fFiles.length + 1), JavaRefactoringDescriptorUtil.resourceToHandle(project, fFolders[offset]));
	}
	arguments.put(ATTRIBUTE_UNITS, new Integer(fCus.length).toString());
	for (int offset= 0; offset < fCus.length; offset++) {
		arguments.put(JavaRefactoringDescriptorUtil.ATTRIBUTE_ELEMENT + (offset + fFolders.length + fFiles.length + 1), JavaRefactoringDescriptorUtil.elementToHandle(project, fCus[offset]));
	}
	arguments.putAll(getRefactoringArguments(project));
	final JavaRefactoringDescriptor descriptor= createRefactoringDescriptor(comment, arguments, description, project, flags);
	return new RefactoringChangeDescriptor(descriptor);
}
 
Example 9
Source File: DerbyUtils.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
public static void runIJ(IFile currentScript, IProject currentProject) throws CoreException {	

		String launchType="";
		String args="";
		
		//the above some times throws wrong 'create=true|false' errors
		String vmargs="";
		DerbyProperties dprop=new DerbyProperties(currentProject);
		if((dprop.getSystemHome()!=null)&& !(dprop.getSystemHome().equals(""))){
			vmargs+=CommonNames.D_SYSTEM_HOME+dprop.getSystemHome();
		}
		
		if(currentScript!=null){
			launchType=CommonNames.SQL_SCRIPT;
			
			//Preferable to use the full String with quotes to take care of spaces 
			//in file names
			args="\""+currentScript.getLocation().toOSString()+"\"";
		}else{
			launchType=CommonNames.IJ;
			args="";	
		}
		
		ILaunch launch=launch(currentProject,launchType,CommonNames.IJ_CLASS,args, vmargs, CommonNames.IJ);
		IProcess ip=launch.getProcesses()[0];
		String procName="["+currentProject.getName()+"] - "+CommonNames.IJ+" "+args;
		ip.setAttribute(IProcess.ATTR_PROCESS_LABEL,procName);
	}
 
Example 10
Source File: ShareProjectCommand.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
/**
    * if remoteDirName is null, the name of the project is used    
    */
public ShareProjectCommand(ISVNRepositoryLocation location,
		IProject project, String remoteDirName, boolean createDirectory) {
	this.location = location;
	this.project = project;

	if (remoteDirName == null) {
		this.remoteDirName = project.getName();
	} else {
		this.remoteDirName = remoteDirName;
	}
	this.createDirectory = createDirectory;
}
 
Example 11
Source File: DerbyServerUtils.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
public void startDerbyServer( IProject proj) throws CoreException {
	String args = CommonNames.START_DERBY_SERVER;
	String vmargs="";
	DerbyProperties dprop=new DerbyProperties(proj);
	//Starts the server as a Java app
	args+=" -h "+dprop.getHost()+ " -p "+dprop.getPort();
	
	//Set Derby System Home from the Derby Properties
	if((dprop.getSystemHome()!=null)&& !(dprop.getSystemHome().equals(""))){
		vmargs=CommonNames.D_SYSTEM_HOME+dprop.getSystemHome();
	}
	String procName="["+proj.getName()+"] - "+CommonNames.DERBY_SERVER+" "+CommonNames.START_DERBY_SERVER+" ("+dprop.getHost()+ ", "+dprop.getPort()+")";
	ILaunch launch = DerbyUtils.launch(proj, procName ,		
	CommonNames.DERBY_SERVER_CLASS, args, vmargs, CommonNames.START_DERBY_SERVER);
	IProcess ip=launch.getProcesses()[0];
	//set a name to be seen in the Console list
	ip.setAttribute(IProcess.ATTR_PROCESS_LABEL,procName);
	
	// saves the mapping between (server) process and project
	//servers.put(launch.getProcesses()[0], proj);
	servers.put(ip, proj);
	// register a listener to listen, when this process is finished
	DebugPlugin.getDefault().addDebugEventListener(listener);
	//Add resource listener
	IWorkspace workspace = ResourcesPlugin.getWorkspace();
	
	workspace.addResourceChangeListener(rlistener);
	setRunning(proj, Boolean.TRUE);
	Shell shell = new Shell();
	MessageDialog.openInformation(
		shell,
		CommonNames.PLUGIN_NAME,
		Messages.D_NS_ATTEMPT_STARTED+dprop.getPort()+".");

}
 
Example 12
Source File: WorkspaceSpecManager.java    From tlaplus with MIT License 5 votes vote down vote up
public Object getAdapter(final Object adaptableObject,
		@SuppressWarnings("rawtypes") final Class adapterType) {
	if (adaptableObject instanceof IProject) {
		final IProject project = (IProject) adaptableObject;
		final String key = project.getName();
		return specStorage.get(key);
	}
	return null;
}
 
Example 13
Source File: ExportUtil.java    From developer-studio with Apache License 2.0 5 votes vote down vote up
/**
 * Carbon application builder
 * 
 * @param project
 * @return
 * @throws Exception
 */
public static IResource buildCAppProject(IProject project) throws Exception {
	List<IResource> buildProject = new ArrayList<IResource>();
	if (!project.isOpen()) {
		throw new Exception("\"" + project.getName() + "\" project is not open!");
	}
	if (project.hasNature("org.wso2.developerstudio.eclipse.distribution.project.nature")) {
		buildProject = ExportUtil.buildProject(project, "carbon/application");
	} else {
		throw new Exception("\"" + project.getName() + "\" project is not a carbon application project");
	}
	return buildProject.get(0);
}
 
Example 14
Source File: AnalysisBuilderRunnableFactory.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * This will check if the nature is not null, related project is open and if the documentTime for the new request
 * is lower than one already in place (this can happen if we have a notification from a successful parse, but
 * it's only acknowledged after a build request, because the parse to finish can take some time, while the build
 * is 'automatic').
 *
 * @param nature the related nature
 * @param moduleName the name of the module we'll analyze
 * @param documentTime the time of the creation of the document we're about to analyze.
 * @param available the existing threads.
 * @param resourceModificationStamp
 * @param analysisCause
 *
 * @return The analysis key if all check were OK or null if some check failed.
 */
private static KeyForAnalysisRunnable areNatureAndProjectAndTimeOK(IPythonNature nature,
        String moduleName, long documentTime, Map<KeyForAnalysisRunnable, IAnalysisBuilderRunnable> available,
        long resourceModificationStamp, int analysisCause) {
    synchronized (lock) {
        if (nature == null) {
            return null;
        }

        IProject project = nature.getProject();
        if (project == null || !project.isOpen()) {
            return null;
        }

        KeyForAnalysisRunnable analysisKey = new KeyForAnalysisRunnable(project.getName(), moduleName,
                analysisCause);
        IAnalysisBuilderRunnable oldAnalysisBuilderThread = available.get(analysisKey);

        if (oldAnalysisBuilderThread != null) {
            if (!checkTimesOk(oldAnalysisBuilderThread, oldAnalysisBuilderThread.getDocumentTime(), documentTime,
                    oldAnalysisBuilderThread.getResourceModificationStamp(), resourceModificationStamp)) {
                return null;
            }
        }

        Tuple<Long, Long> lastTime = analysisTimeCache.getObj(analysisKey);
        if (lastTime != null) {
            long oldDocTime = lastTime.o1;
            long oldResourceTime = lastTime.o2;
            if (!checkTimesOk(oldAnalysisBuilderThread, oldDocTime, documentTime, oldResourceTime,
                    resourceModificationStamp)) {
                return null;
            }
        }
        analysisTimeCache.add(analysisKey, new Tuple<Long, Long>(documentTime, resourceModificationStamp));

        return analysisKey;
    }
}
 
Example 15
Source File: RunSimulatorDialog.java    From APICloud-Studio with GNU General Public License v3.0 4 votes vote down vote up
@Override
public String getText(Object element) {
	IProject p = (IProject)element;
	return p.getName();
}
 
Example 16
Source File: PreviewLabelProvider.java    From eclipse-extras with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public String getText( Object element ) {
  IProject project = ( IProject )element;
  return project.getName();
}
 
Example 17
Source File: ClearMarkersOperation.java    From goclipse with Eclipse Public License 1.0 4 votes vote down vote up
public ClearMarkersOperation(
	IProject project, IToolOperationMonitor opMonitor
) throws CommonException {
	this(ResourceUtils.getLocation(project), project.getName(), opMonitor);
}
 
Example 18
Source File: Builder.java    From cppcheclipse with Apache License 2.0 4 votes vote down vote up
/**
 * (re-)initialize checker if necessary (first use or different project)
 * 
 * @param currentProject
 * @throws CoreException
 */
private void initChecker(IProject currentProject) throws CoreException {
	if (!currentProject.equals(project)) {
		runChecker();
		try {
			// separate try for empty path exception (common exception
			// which needs special handling)
			try {
				checker = new Checker(console, CppcheclipsePlugin
						.getProjectPreferenceStore(currentProject),
						CppcheclipsePlugin
								.getWorkspacePreferenceStore(),
						currentProject, new ToolchainSettings(currentProject), problemReporter);
				project = currentProject;
			} catch (EmptyPathException e1) {
				Runnable runnable = new Runnable() {
					public void run() {
						Shell shell = PlatformUI.getWorkbench()
								.getActiveWorkbenchWindow().getShell();
						if (MessageDialog.openQuestion(shell,
								Messages.Builder_PathEmptyTitle,
								Messages.Builder_PathEmptyMessage)) {
							PreferenceDialog dialog = PreferencesUtil
									.createPreferenceDialogOn(
											shell,
											BinaryPathPreferencePage.PAGE_ID,
											null, null);
							dialog.open();
						}
					}
				};
				Display.getDefault().asyncExec(runnable);
				throw e1;
			}
		} catch (Exception e2) {
			// all exceptions in initialization lead to non-recoverable
			// errors, therefore throw them as CoreExceptions
			IStatus status = new Status(IStatus.ERROR,
					CppcheclipsePlugin.getId(),
					"Could not initialize cppcheck for project "+ currentProject.getName(), e2); //$NON-NLS-1$
			throw new CoreException(status);
		}
	}
}
 
Example 19
Source File: ExportServiceAction.java    From tesb-studio-se with Apache License 2.0 4 votes vote down vote up
private ITalendProcessJavaProject createSimpleProject(IProgressMonitor monitor, IProject p, Model model,
        ProjectImportConfiguration importConfiguration) throws CoreException {
    final String[] directories = getFolders();

    ProjectConfigurationManager projectConfigurationManager = (ProjectConfigurationManager) MavenPlugin
            .getProjectConfigurationManager();

    String projectName = p.getName();
    monitor.beginTask(NLS.bind(Messages.ProjectConfigurationManager_task_creating, projectName), 5);

    monitor.subTask(Messages.ProjectConfigurationManager_task_creating_workspace);

    ITalendProcessJavaProject javaProject = TalendJavaProjectManager.getTalendJobJavaProject(serviceItem.getProperty());
    // ITalendProcessJavaProject javaProject =
    // TalendJavaProjectManager.getTalendCodeJavaProject(ERepositoryObjectType.PROCESS);

    p.open(monitor);
    monitor.worked(1);

    // hideNestedProjectsFromParents(Collections.singletonList(p));

    monitor.worked(1);

    monitor.subTask(Messages.ProjectConfigurationManager_task_creating_pom);
    IFile pomFile = p.getFile(TalendMavenConstants.POM_FILE_NAME);
    if (!pomFile.exists()) {
        MavenPlugin.getMavenModelManager().createMavenModel(pomFile, model);
    }
    monitor.worked(1);

    monitor.subTask(Messages.ProjectConfigurationManager_task_creating_folders);
    for (int i = 0; i < directories.length; i++) {
        ProjectConfigurationManager.createFolder(p.getFolder(directories[i]), false);
    }
    monitor.worked(1);

    monitor.subTask(Messages.ProjectConfigurationManager_task_creating_project);
    projectConfigurationManager.enableMavenNature(p, importConfiguration.getResolverConfiguration(), monitor);
    monitor.worked(1);

    // if (this.pomFile == null) {
    // this.pomFile = pomFile;
    // }

    return javaProject;
}
 
Example 20
Source File: CloneForeignModelHandler.java    From tlaplus with MIT License 4 votes vote down vote up
private TreeMap<String, TreeSet<Model>> buildMap() {
       final Spec currentSpec = ToolboxHandle.getCurrentSpec();
       if (currentSpec == null) {
       	return null;
       }
       
	final IProject specProject = currentSpec.getProject();
	final TreeMap<String, TreeSet<Model>> projectModelMap = new TreeMap<>();
	
	try {
		final IWorkspace iws = ResourcesPlugin.getWorkspace();
		final IWorkspaceRoot root = iws.getRoot();
		final IProject[] projects = root.getProjects();
		
		for (final IProject project : projects) {
			if (!specProject.equals(project)) {
				projectModelMap.put(project.getName(), new TreeSet<>(MODEL_SORTER));
			}
		}
		
		final String currentProjectName = specProject.getName();
		final ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager();
		final ILaunchConfigurationType launchConfigurationType
				= launchManager.getLaunchConfigurationType(TLCModelLaunchDelegate.LAUNCH_CONFIGURATION_TYPE);
		final ILaunchConfiguration[] launchConfigurations
				= launchManager.getLaunchConfigurations(launchConfigurationType);
		for (final ILaunchConfiguration launchConfiguration : launchConfigurations) {
			final String projectName = launchConfiguration.getAttribute(IConfigurationConstants.SPEC_NAME, "-l!D!q_-l!D!q_-l!D!q_");
			if (!projectName.equals(currentProjectName)) {
				final TreeSet<Model> models = projectModelMap.get(projectName);
				
				if (models != null) {
					final Model model = launchConfiguration.getAdapter(Model.class);
					
					if (!model.isSnapshot()) {
						models.add(model);
					}
				} else {
					TLCUIActivator.getDefault().logError("Could not generate model map for [" + projectName + "]!");
				}
			}
		}
	} catch (final CoreException e) {
		TLCUIActivator.getDefault().logError("Building foreign model map.", e);
		
		return null;
	}
	
	return projectModelMap;
}