use of org.eclipse.core.resources.IProjectDescription in project tdi-studio-se by Talend.
the class ImportProjectsUtilities method importProject.
public static void importProject(String path) throws CoreException {
IProjectDescription description = ResourcesPlugin.getWorkspace().loadProjectDescription(new Path(path + File.separator + ".project"));
IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(description.getName());
if (!project.isOpen() && !project.isLinked()) {
project.create(description, null);
project.open(null);
project.refreshLocal(IResource.DEPTH_INFINITE, null);
}
}
use of org.eclipse.core.resources.IProjectDescription in project tdi-studio-se by Talend.
the class ComponentProjectManager method createNewProject.
/**
* Creates a new project resource with the selected name.
* <p>
* In normal usage, this method is invoked after the user has pressed Finish on the wizard; the enablement of the
* Finish button implies that all controls on the pages currently contain valid values.
* </p>
* <p>
* Note that this wizard caches the new project once it has been successfully created; subsequent invocations of
* this method will answer the same project resource without attempting to create it again.
* </p>
*
* @return the created project resource, or <code>null</code> if the project was not created
*/
public IProject createNewProject(String directroy, String projectName, Shell shell) {
if (projDir.equals(directroy)) {
return project;
}
final Shell currentShell = shell;
// get a project handle
final IProject newProjectHandle = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
if (newProjectHandle.getRawLocation() != null) {
if (newProjectHandle.getRawLocation().equals(directroy)) {
return newProjectHandle;
} else {
try {
newProjectHandle.delete(false, true, null);
} catch (CoreException e) {
// e.printStackTrace();
org.talend.componentdesigner.exception.ExceptionHandler.process(e);
}
}
}
// final IJavaProject javaProjHandle = JavaCore.create(newProjectHandle);
// get a project descriptor
URI location = null;
if (directroy == null || directroy.equals(PluginConstant.EMPTY_STRING)) {
return null;
} else {
location = new File(directroy).toURI();
}
IWorkspace workspace = ResourcesPlugin.getWorkspace();
final IProjectDescription description = workspace.newProjectDescription(newProjectHandle.getName());
description.setLocationURI(location);
// create the new project operation
IRunnableWithProgress op = new IRunnableWithProgress() {
public void run(IProgressMonitor monitor) throws InvocationTargetException {
CreateProjectOperation op = new CreateProjectOperation(description, //$NON-NLS-1$
Messages.getString("ComponentProjectManager.NewProject"));
try {
PlatformUI.getWorkbench().getOperationSupport().getOperationHistory().execute(op, monitor, WorkspaceUndoUtil.getUIInfoAdapter(currentShell));
} catch (ExecutionException e) {
throw new InvocationTargetException(e);
}
}
};
// run the new project creation o`peration
try {
ProgressUI.popProgressDialog(op, shell);
} catch (InterruptedException e) {
return null;
} catch (InvocationTargetException e) {
Throwable t = e.getTargetException();
if (t instanceof ExecutionException && t.getCause() instanceof CoreException) {
CoreException cause = (CoreException) t.getCause();
StatusAdapter status;
if (cause.getStatus().getCode() == IResourceStatus.CASE_VARIANT_EXISTS) {
status = new StatusAdapter(new Status(IStatus.WARNING, ComponentDesigenerPlugin.PLUGIN_ID, IStatus.WARNING, Messages.getString("ComponentProjectManager.WarningMsg", //$NON-NLS-1$
newProjectHandle.getName()), cause));
} else {
status = new StatusAdapter(new Status(cause.getStatus().getSeverity(), ComponentDesigenerPlugin.PLUGIN_ID, cause.getStatus().getSeverity(), Messages.getString("ComponentProjectManager.CreationProblems"), //$NON-NLS-1$
cause));
}
//$NON-NLS-1$
status.setProperty(StatusAdapter.TITLE_PROPERTY, Messages.getString("ComponentProjectManager.CreationProblems"));
StatusManager.getManager().handle(status, StatusManager.BLOCK);
} else {
StatusAdapter status = new StatusAdapter(new Status(IStatus.WARNING, ComponentDesigenerPlugin.PLUGIN_ID, 0, Messages.getString("ComponentProjectManager.InternalErrorMsg", t.getMessage()), //$NON-NLS-1$
t));
//$NON-NLS-1$
status.setProperty(StatusAdapter.TITLE_PROPERTY, Messages.getString("ComponentProjectManager.CreationProblems"));
StatusManager.getManager().handle(status, StatusManager.LOG | StatusManager.BLOCK);
}
return null;
}
project = newProjectHandle;
return project;
}
use of org.eclipse.core.resources.IProjectDescription in project bndtools by bndtools.
the class ProjectNatureChange method perform.
@Override
public final Change perform(IProgressMonitor pm) throws CoreException {
final IProjectDescription desc = project.getDescription();
Set<String> natures = new HashSet<String>(Arrays.asList(desc.getNatureIds()));
boolean changed = modifyNatures(natures);
if (changed) {
desc.setNatureIds(natures.toArray(new String[0]));
project.setDescription(desc, pm);
}
return createInverse();
}
use of org.eclipse.core.resources.IProjectDescription in project bndtools by bndtools.
the class ToggleNatureAction method toggleNature.
/**
* Toggles sample nature on a project
*
* @param project
* to have sample nature added or removed
*/
private static IStatus toggleNature(IJavaProject project) {
try {
/* Version control ignores */
VersionControlIgnoresManager versionControlIgnoresManager = Plugin.getDefault().getVersionControlIgnoresManager();
Set<String> enabledIgnorePlugins = new BndPreferences().getVersionControlIgnoresPluginsEnabled(versionControlIgnoresManager, project, null);
/* Headless build files */
HeadlessBuildManager headlessBuildManager = Plugin.getDefault().getHeadlessBuildManager();
Set<String> enabledPlugins = new BndPreferences().getHeadlessBuildPluginsEnabled(headlessBuildManager, null);
IProject iProject = project.getProject();
IProjectDescription description = iProject.getDescription();
String[] natures = description.getNatureIds();
List<String> headlessBuildWarnings = new LinkedList<>();
for (int i = 0; i < natures.length; ++i) {
if (BndtoolsConstants.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);
iProject.setDescription(description, null);
/* Remove the headless build files */
headlessBuildManager.setup(enabledPlugins, false, iProject.getLocation().toFile(), false, enabledIgnorePlugins, headlessBuildWarnings);
/* refresh the project; files were created outside of Eclipse API */
iProject.refreshLocal(IResource.DEPTH_INFINITE, null);
return createStatus("Obsolete build files may remain in the project. Please review the messages below.", Collections.<String>emptyList(), headlessBuildWarnings);
}
}
/* Add the headless build files */
headlessBuildManager.setup(enabledPlugins, false, iProject.getLocation().toFile(), true, enabledIgnorePlugins, headlessBuildWarnings);
// Add the nature
ensureBndBndExists(iProject);
String[] newNatures = new String[natures.length + 1];
System.arraycopy(natures, 0, newNatures, 0, natures.length);
newNatures[natures.length] = BndtoolsConstants.NATURE_ID;
description.setNatureIds(newNatures);
iProject.setDescription(description, null);
/* refresh the project; files were created outside of Eclipse API */
iProject.refreshLocal(IResource.DEPTH_INFINITE, null);
return createStatus("Some build files could not be generated. Please review the messages below.", Collections.<String>emptyList(), headlessBuildWarnings);
} catch (CoreException e) {
return new Status(IStatus.ERROR, Plugin.PLUGIN_ID, 0, "Error occurred while toggling Bnd project nature", e);
}
}
use of org.eclipse.core.resources.IProjectDescription in project sling by apache.
the class ProjectAdapter method addNatures.
public void addNatures(String... naturesToAdd) throws CoreException {
IProjectDescription desc = project.getDescription();
String[] natures = desc.getNatureIds();
String[] newNatures = new String[natures.length + naturesToAdd.length];
System.arraycopy(natures, 0, newNatures, 0, natures.length);
for (int i = 0; i < naturesToAdd.length; i++) {
newNatures[natures.length + i] = naturesToAdd[i];
}
desc.setNatureIds(newNatures);
project.setDescription(desc, new NullProgressMonitor());
}
Aggregations