Skip to content
This repository has been archived by the owner on Apr 3, 2018. It is now read-only.

Commit

Permalink
DeeProjectWizard - create hello world app. (Fix #58)
Browse files Browse the repository at this point in the history
  • Loading branch information
bruno-medeiros committed Sep 2, 2014
1 parent 62f74fa commit 54e7b06
Show file tree
Hide file tree
Showing 10 changed files with 67 additions and 36 deletions.
3 changes: 3 additions & 0 deletions documentation/ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
## DDT release ChangeLog

### DDT 0.10.x
* Changed: Creating a new DUB project now creates a Hello World app. (fix problem mentioned in #58)

### DDT 0.10.2
* Updated minimum required CDT version to 8.4.
* For more info on new CDT debug features, see: https://wiki.eclipse.org/CDT/User/NewIn84#Debug
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import static melnorme.utilbox.core.Assert.AssertNamespace.assertFail;
import static melnorme.utilbox.core.Assert.AssertNamespace.assertTrue;

import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
Expand Down Expand Up @@ -145,11 +144,7 @@ public static String readFileContents(IFile file) throws CoreException, IOExcept
public static void writeStringToFile(IProject project, String filePath, String contents)
throws CoreException {
IFile file = project.getFile(filePath);
writeStringToFile(file, contents);
}

public static void writeStringToFile(IFile file, String contents) throws CoreException {
ResourceUtils.writeToFile(file, new ByteArrayInputStream(contents.getBytes(StringUtil.UTF8)));
ResourceUtils.writeStringToFile(file, contents);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@

import static melnorme.utilbox.core.Assert.AssertNamespace.assertFail;

import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.nio.charset.Charset;

import melnorme.utilbox.misc.StringUtil;

import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile;
Expand Down Expand Up @@ -49,6 +53,14 @@ public static void writeToFile(IFile file, InputStream is) throws CoreException
}
}

public static void writeStringToFile(IFile file, String contents) throws CoreException {
writeStringToFile(file, contents, StringUtil.UTF8);
}

public static void writeStringToFile(IFile file, String contents, Charset charset) throws CoreException {
writeToFile(file, new ByteArrayInputStream(contents.getBytes(charset)));
}

public static void createFolder(IFolder folder, boolean force, boolean local, IProgressMonitor monitor)
throws CoreException {
if (folder.exists()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@
package melnorme.lang.ide.ui.editor.text;

import static melnorme.utilbox.core.Assert.AssertNamespace.assertTrue;

import java.io.IOException;

import melnorme.lang.ide.ui.CodeFormatterConstants;
import melnorme.lang.ide.ui.CodeFormatterConstants.IndentMode;
import melnorme.lang.ide.ui.text.BlockHeuristicsScannner;
Expand All @@ -36,11 +33,7 @@ public class LangAutoEditStrategyTest extends Scanner_BaseTest {
public static final String NEUTRAL_SRCX;

static {
try {
NEUTRAL_SRCX = MiscUtil.getClassResourceAsString(LangAutoEditStrategyTest.class, "sample_block_code");
} catch (IOException e) {
throw melnorme.utilbox.core.ExceptionAdapter.unchecked(e);
}
NEUTRAL_SRCX = MiscUtil.getClassResourceAsString(LangAutoEditStrategyTest.class, "sample_block_code");
}

public static final String PENDING_WS1 = " ";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ private DeeNewWizardMessages() {
"Create a DUB project.";
public static String LangNewProject_Page1_pageDescription =
"Create a DUB project in the workspace or in an external location.";


public static String LangNewProject_Page1_NameGroup_label =
"&Project name:";
Expand All @@ -41,6 +41,9 @@ private DeeNewWizardMessages() {
public static String LangNewProject_Page1_LocationGroup_browseButton_desc =
"B&rowse...";

public static final String DltkNewProject_Page1_Location_workspaceDesc =
"Create new \"Hello World\" project in workspace";

public static String LangNewProject_Page1_Message_enterProjectName =
"Enter a project name.";
public static String LangNewProject_Page1_Message_projectAlreadyExists =
Expand Down
31 changes: 12 additions & 19 deletions plugin_ide.ui/src/mmrnmhrm/ui/wizards/DeeProjectWizard.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package mmrnmhrm.ui.wizards;


import static melnorme.utilbox.misc.MiscUtil.getClassResourceAsString;

import java.io.ByteArrayInputStream;
import java.lang.reflect.InvocationTargetException;
import java.nio.charset.Charset;

import melnorme.lang.ide.core.utils.ResourceUtils;
import melnorme.lang.ide.ui.utils.WorkbenchUtils;
import melnorme.utilbox.misc.StringUtil;
import mmrnmhrm.core.DeeCore;
import mmrnmhrm.ui.DeeUIPlugin;

Expand Down Expand Up @@ -43,6 +44,12 @@ public class DeeProjectWizard extends ProjectWizardExtension {

public static final String WIZARD_ID = DeeUIPlugin.PLUGIN_ID + ".wizards.deeProjectWizard";

protected static final String HelloWorld_DubJsonTemplate = getClassResourceAsString(
DeeProjectWizard.class, "hello_world.dub.json");
protected static final String HelloWorld_ModuleContents = getClassResourceAsString(
DeeProjectWizard.class, "hello_world.d");


protected final ProjectWizardFirstPage fFirstPage = new DeeProjectWizardPage1(this);
protected final DeeProjectWizardBuildSettingsPage fBuildSettingsPage =
new DeeProjectWizardBuildSettingsPage(this);
Expand Down Expand Up @@ -104,9 +111,9 @@ protected void configureProjectBuildpath(IProject project, IProgressMonitor moni

final IFolder folder = project.getFolder("source");
ResourceUtils.createFolder(folder, true, true, null);
ResourceUtils.writeStringToFile(folder.getFile("app.d"), HelloWorld_ModuleContents);

String dubManifestSource = getDefaultDubJSon();
ResourceUtils.writeToFile(dubManifest, createInputStream(dubManifestSource, StringUtil.UTF8));
ResourceUtils.writeStringToFile(dubManifest, getDefaultDubJSon());
}
}

Expand All @@ -115,25 +122,11 @@ protected ByteArrayInputStream createInputStream(String string, Charset charset)
}

protected String getDefaultDubJSon() {
return
"{\n" +
jsEntry("name", getProject().getName()) +",\n"+
jsEntry("description", "A minimal D bundle.") +",\n"+
jsEntryValue("dependencies", "{\n\t}") +"\n"+
"}";
}

protected String jsEntry(String idString, String valueString) {
return "\t" + '"' +idString+ '"' + " : " + '"' +valueString+ '"';
}

protected String jsEntryValue(String idString, String valueString) {
return "\t" + '"' +idString+ '"' + " : " + valueString;
return HelloWorld_DubJsonTemplate.replace("%BUNDLE_NAME%", getProject().getName());
}

@Override
protected void finishPage(IProgressMonitor monitor)
throws InterruptedException, CoreException {
protected void finishPage(IProgressMonitor monitor) throws InterruptedException, CoreException {
getProjectCreator().performFinish(monitor);
}

Expand Down
17 changes: 17 additions & 0 deletions plugin_ide.ui/src/mmrnmhrm/ui/wizards/DeeProjectWizardPage1.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,26 @@ public DeeProjectWizardPage1(DeeProjectWizard deeNewProjectWizard) {
this.deeNewProjectWizard = deeNewProjectWizard;
}

@Override
public void createControl(Composite parent) {
super.createControl(parent);
}

@Override
protected LocationGroup createLocationGroup() {
return new LocationGroup() {

@Override
public void createControls(Composite composite) {
super.createControls(composite);
}

@Override
protected void createModeControls(Composite group, int numColumns) {
super.createModeControls(group, numColumns);
fWorkspaceRadio.setLabelText(DeeNewWizardMessages.DltkNewProject_Page1_Location_workspaceDesc);
}

@Override
protected void createEnvironmentControls(Composite group, int numColumns) {
//super.createEnvironmentControls(group, numColumns);
Expand Down
5 changes: 5 additions & 0 deletions plugin_ide.ui/src/mmrnmhrm/ui/wizards/hello_world.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import std.stdio;

void main() {
writeln("Hello World.");
}
6 changes: 6 additions & 0 deletions plugin_ide.ui/src/mmrnmhrm/ui/wizards/hello_world.dub.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name" : "%BUNDLE_NAME%",
"description" : "Hello World - A minimal DUB bundle.",
"dependencies" : {
}
}
8 changes: 6 additions & 2 deletions plugin_tooling/src-util/melnorme/utilbox/misc/MiscUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,12 @@ public static boolean isUncheckedException(Throwable throwable) {
return throwable instanceof RuntimeException || throwable instanceof Error;
}

public static String getClassResourceAsString(Class<?> klass, String resourceName) throws IOException {
return readAllBytesFromStream(klass.getResourceAsStream(resourceName)).toString(StringUtil.UTF8);
public static String getClassResourceAsString(Class<?> klass, String resourceName) {
try {
return readAllBytesFromStream(klass.getResourceAsStream(resourceName)).toString(StringUtil.UTF8);
} catch (IOException e) {
throw melnorme.utilbox.core.ExceptionAdapter.unchecked(e);
}
}

}

0 comments on commit 54e7b06

Please sign in to comment.