Skip to content
Browse files

Moved responsibility for project description creation.

  • Loading branch information...
1 parent 0674627 commit 4aee59ac625906b7de34305f00e7346a9b0d7de4 @ianbollinger committed Feb 26, 2012
View
9 plugins/org.rustlang.oxide/src/org/rustlang/oxide/model/RustNewProjectDelegate.java
@@ -4,6 +4,8 @@
import com.google.inject.Inject;
import com.google.inject.assistedinject.Assisted;
import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IProjectDescription;
+import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.jface.operation.IRunnableWithProgress;
@@ -18,6 +20,7 @@
private final RustNewProjectOperationFactory factory;
private final RustTemplateContextFactory templateContextFactory;
private final PerspectiveUpdater perspectiveUpdater;
+ private final IWorkspace workspace;
private final IWorkspaceRoot workspaceRoot;
private final RustProject element;
private final IConfigurationElement configuration;
@@ -27,13 +30,15 @@
RustNewProjectDelegate(final RustNewProjectOperationFactory factory,
final RustTemplateContextFactory templateContextFactory,
final PerspectiveUpdater perspectiveUpdater,
+ final IWorkspace workspace,
final IWorkspaceRoot workspaceRoot,
@Assisted final RustProject element,
@Assisted final IConfigurationElement configuration,
@Assisted final ProgressMonitor monitor) {
this.factory = factory;
this.templateContextFactory = templateContextFactory;
this.perspectiveUpdater = perspectiveUpdater;
+ this.workspace = workspace;
this.workspaceRoot = workspaceRoot;
this.element = element;
this.configuration = configuration;
@@ -54,8 +59,10 @@ public void run() {
.create(element);
final String projectName = element.getProjectName().getContent();
final IProject project = workspaceRoot.getProject(projectName);
+ final IProjectDescription description = workspace
+ .newProjectDescription(project.getName());
final IRunnableWithProgress operation = factory.create(project,
- templateContext);
+ description, templateContext);
try {
operation.run(ProgressMonitorBridge.create(monitor));
} catch (final Exception e) {
View
29 plugins/org.rustlang.oxide/src/org/rustlang/oxide/model/RustNewProjectOperation.java
@@ -11,6 +11,7 @@
import org.eclipse.core.resources.IProjectDescription;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IWorkspace;
+import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.OperationCanceledException;
@@ -30,20 +31,21 @@
private static final int NUMBER_OF_TASKS = 8;
private static final int WORK_SCALE = 1000;
private final OxideLogger logger;
- private final IWorkspace workspace;
private final TemplateStore templateStore;
private final IProject project;
+ private final IProjectDescription description;
private final TemplateContext templateContext;
@Inject
- RustNewProjectOperation(final OxideLogger logger,
- final IWorkspace workspace, final TemplateStore templateStore,
- @Assisted final IProject project,
+ RustNewProjectOperation(final OxideLogger logger, final IWorkspaceRoot root,
+ final TemplateStore templateStore, @Assisted final IProject project,
+ @Assisted final IProjectDescription description,
@Assisted final TemplateContext templateContext) {
+ super(root);
this.logger = logger;
- this.workspace = workspace;
this.templateStore = templateStore;
this.project = project;
+ this.description = description;
this.templateContext = templateContext;
}
@@ -53,28 +55,21 @@ protected void execute(
try {
monitor.beginTask("Creating Rust project", WORK_SCALE
* NUMBER_OF_TASKS);
- final IProjectDescription description = createProjectDescription();
- ceateAndOpenProject(description, monitor);
+ configureDescription();
+ ceateAndOpenProject(monitor);
createFiles(description.getName(), monitor);
} finally {
monitor.done();
}
}
- private IProjectDescription createProjectDescription() {
- final IProjectDescription description = workspace
- .newProjectDescription(project.getName());
- // TODO: handle this correctly.
- // if (location != null) {
- // description.setLocationURI(location);
- // }
+ private void configureDescription() {
final String[] newNatureIds = ObjectArrays.concat(
description.getNatureIds(), RustNature.ID);
description.setNatureIds(newNatureIds);
- return description;
}
- private void ceateAndOpenProject(final IProjectDescription description,
+ private void ceateAndOpenProject(
final IProgressMonitor monitor) throws CoreException {
// TODO: refactor.
project.create(provideSubProgressMonitor(monitor));
@@ -119,6 +114,7 @@ private void createFileFromTemplate(final String fileName,
final InputStream stream = getTemplateInputStream(templateName);
final boolean force = false;
final IProgressMonitor monitor2 = provideSubProgressMonitor(monitor);
+ // TODO: remove LoD violation.
project.getFile(fileName).create(stream, force, monitor2);
if (monitor.isCanceled()) {
throw new OperationCanceledException();
@@ -130,6 +126,7 @@ private InputStream getTemplateInputStream(final String name) {
final Template template = templateStore.findTemplate(name);
try {
final TemplateBuffer buffer = templateContext.evaluate(template);
+ // TODO: remove LoD violation.
return new ByteArrayInputStream(buffer.getString().getBytes(
Charsets.UTF_8));
} catch (final BadLocationException e) {
View
3 plugins/org.rustlang.oxide/src/org/rustlang/oxide/model/RustNewProjectOperationFactory.java
@@ -1,9 +1,10 @@
package org.rustlang.oxide.model;
import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IProjectDescription;
import org.eclipse.jface.text.templates.TemplateContext;
public interface RustNewProjectOperationFactory {
RustNewProjectOperation create(IProject project,
- TemplateContext templateContext);
+ IProjectDescription description, TemplateContext templateContext);
}

0 comments on commit 4aee59a

Please sign in to comment.
Something went wrong with that request. Please try again.