use of org.eclipse.core.resources.IProjectDescription in project ow by vtst.
the class Utils method setProjectBuilder.
/**
* Set or remove a builder to a project.
* @param project The project.
* @param builderName The ID of the builder.
* @param status true to set the builder, false to remove it.
* @throws CoreException
*/
public static void setProjectBuilder(IProject project, String builderName, boolean status) throws CoreException {
IProjectDescription description = project.getDescription();
ICommand[] commands = description.getBuildSpec();
int i;
for (i = 0; i < commands.length; ++i) {
if (commands[i].getBuilderName().equals(builderName))
break;
}
if (status == (i < commands.length))
return;
ICommand[] newCommands;
if (status) {
newCommands = new ICommand[commands.length + 1];
System.arraycopy(commands, 0, newCommands, 0, commands.length);
ICommand command = description.newCommand();
command.setBuilderName(builderName);
newCommands[commands.length] = command;
} else {
newCommands = new ICommand[commands.length - 1];
System.arraycopy(commands, 0, newCommands, 0, i);
System.arraycopy(commands, i + 1, newCommands, i, commands.length - i - 1);
}
description.setBuildSpec(newCommands);
project.setDescription(description, null);
}
use of org.eclipse.core.resources.IProjectDescription in project dbeaver by serge-rider.
the class ProjectCreateWizard method createProject.
private void createProject(DBRProgressMonitor monitor) throws DBException, CoreException {
final IProgressMonitor nestedMonitor = RuntimeUtils.getNestedMonitor(monitor);
final IProject project = getNewProject();
final IProjectDescription description = project.getDescription();
if (!CommonUtils.isEmpty(data.getDescription())) {
description.setComment(data.getDescription());
}
description.setNatureIds(new String[] { DBeaverNature.NATURE_ID });
project.setDescription(description, nestedMonitor);
if (!project.isOpen()) {
project.open(nestedMonitor);
}
}
use of org.eclipse.core.resources.IProjectDescription in project sling by apache.
the class ProjectDescriptionManager method enableValidationBuilderAndCommand.
public void enableValidationBuilderAndCommand(IProject project, IProgressMonitor monitor) throws CoreException {
IProjectDescription description = project.getDescription();
ICommand[] builders = description.getBuildSpec();
for (ICommand builder : builders) {
if (builder.getBuilderName().equals(VALIDATION_BUILDER_NAME)) {
logger.trace("Validation builder already installed, skipping");
return;
}
}
logger.trace("Installing validation builder");
ICommand[] newBuilders = new ICommand[builders.length + 1];
System.arraycopy(builders, 0, newBuilders, 0, builders.length);
ICommand validationCommand = description.newCommand();
validationCommand.setBuilderName(VALIDATION_BUILDER_NAME);
newBuilders[newBuilders.length - 1] = validationCommand;
description.setBuildSpec(newBuilders);
project.setDescription(description, monitor);
logger.trace("Installed validation builder");
}
use of org.eclipse.core.resources.IProjectDescription in project bndtools by bndtools.
the class WorkspaceSetupWizard method performFinish.
@Override
public boolean performFinish() {
final IWorkspace workspace = ResourcesPlugin.getWorkspace();
final File targetDir = previewPage.getTargetDir();
final Set<String> checkedPaths = previewPage.getCheckedPaths();
final boolean cleanBuild = setupPage.isCleanBuild();
try {
// Expand the template
ResourceMap outputs = previewPage.getTemplateOutputs();
final Set<File> topLevelFolders = new HashSet<>();
for (Entry<String, Resource> entry : outputs.entries()) {
String path = entry.getKey();
if (checkedPaths.contains(path)) {
Resource resource = entry.getValue();
// Create the folder or file resource
File file = new File(targetDir, path);
switch(resource.getType()) {
case Folder:
Files.createDirectories(file.toPath());
break;
case File:
File parentDir = file.getParentFile();
Files.createDirectories(parentDir.toPath());
try (InputStream in = resource.getContent()) {
IO.copy(in, file);
}
break;
default:
throw new IllegalArgumentException("Unknown resource type " + resource.getType());
}
// Remember the top-level folders we create, for importing below
if (file.getParentFile().equals(targetDir))
topLevelFolders.add(file);
}
}
// Import anything that looks like an Eclipse project & do a full rebuild
final IWorkspaceRunnable importProjectsRunnable = new IWorkspaceRunnable() {
@Override
public void run(IProgressMonitor monitor) throws CoreException {
File[] children = targetDir.listFiles();
if (children != null) {
int work = children.length;
if (cleanBuild)
work += 2;
SubMonitor progress = SubMonitor.convert(monitor, work);
for (File folder : children) {
if (folder.isDirectory() && topLevelFolders.contains(folder)) {
String projectName = folder.getName();
File projectFile = new File(folder, IProjectDescription.DESCRIPTION_FILE_NAME);
if (projectFile.exists()) {
IProject project = workspace.getRoot().getProject(projectName);
if (!project.exists()) {
// No existing project in the workspace, so import the generated project.
SubMonitor subProgress = progress.newChild(1);
project.create(subProgress.newChild(1));
project.open(subProgress.newChild(1));
// Now make sure it is associated with the right location
IProjectDescription description = project.getDescription();
IPath path = Path.fromOSString(projectFile.getParentFile().getAbsolutePath());
description.setLocation(path);
project.move(description, IResource.REPLACE, progress);
} else {
// If a project with the same name exists, does it live in the same location? If not, we can't import the generated project.
File existingLocation = project.getLocation().toFile();
if (!existingLocation.equals(folder)) {
String message = String.format("Cannot import generated project from %s. A project named %s already exists in the workspace and is mapped to location %s", folder.getAbsolutePath(), projectName, existingLocation);
throw new CoreException(new Status(IStatus.ERROR, Plugin.PLUGIN_ID, 0, message, null));
}
SubMonitor subProgress = progress.newChild(1);
// Open it if closed
project.open(subProgress.newChild(1));
// Refresh, as the template may have generated new content
project.refreshLocal(IResource.DEPTH_INFINITE, subProgress.newChild(1));
}
}
}
}
if (cleanBuild)
workspace.build(IncrementalProjectBuilder.CLEAN_BUILD, progress.newChild(2));
}
}
};
getContainer().run(true, true, new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
try {
workspace.run(importProjectsRunnable, monitor);
} catch (CoreException e) {
throw new InvocationTargetException(e);
}
new WorkspaceJob("Load Repositories") {
@Override
public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException {
try {
Central.refreshPlugins();
} catch (Exception e) {
// There may be no workspace yet
}
return Status.OK_STATUS;
}
}.schedule();
}
});
// Prompt to switch to the bndtools perspective
IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
IPerspectiveDescriptor currentPerspective = window.getActivePage().getPerspective();
if (!"bndtools.perspective".equals(currentPerspective.getId())) {
if (MessageDialog.openQuestion(getShell(), "Bndtools Perspective", "Switch to the Bndtools perspective?")) {
workbench.showPerspective("bndtools.perspective", window);
}
}
return true;
} catch (InvocationTargetException e) {
ErrorDialog.openError(getShell(), "Error", null, new Status(IStatus.ERROR, Plugin.PLUGIN_ID, 0, "Error generating template output", e.getTargetException()));
return false;
} catch (Exception e) {
ErrorDialog.openError(getShell(), "Error", null, new Status(IStatus.ERROR, Plugin.PLUGIN_ID, 0, "Error generating template output", e));
return false;
}
}
use of org.eclipse.core.resources.IProjectDescription in project bndtools by bndtools.
the class NewBndProjectWizardPageTwo method configureJavaProject.
@Override
public void configureJavaProject(IProgressMonitor monitor) throws CoreException, InterruptedException {
super.configureJavaProject(monitor);
IProject project = getJavaProject().getProject();
IProjectDescription desc = project.getDescription();
String[] natures = desc.getNatureIds();
for (String nature : natures) {
if (BndtoolsConstants.NATURE_ID.equals(nature))
return;
}
String[] newNatures = new String[natures.length + 1];
System.arraycopy(natures, 0, newNatures, 0, natures.length);
newNatures[natures.length] = BndtoolsConstants.NATURE_ID;
desc.setNatureIds(newNatures);
project.setDescription(desc, null);
}
Aggregations