<< Creating the workspace definition | ^ Site index ^ | ^ Tutorial index ^ | Using ant cli instead of bash >>

This chapter continues from where Creating the workspace definition left us.

Hello world with Eclipse

Next, as the wizard advised after defining the workspace, we'll generate eclipse settings. This is a mutation to the workspace, and iwant does not have full control over the files (eclipse is also able to modify them), so this wish needs to be a side-effect.

~/iwant-tutorial $ as-iwant-tutorial-developer/with/bash/iwant/side-effect/eclipse-settings/effective
(0/1 D! net.sf.iwant.api.core.Concatenated eclipse-settings.bin-refs)
(as-iwant-tutorial-developer/i-have/wsdef)
( .project)
( .classpath)
( .settings/org.eclipse.jdt.core.prefs)
( .settings/org.eclipse.jdt.ui.prefs)
(as-iwant-tutorial-developer/i-have/wsdefdef)
( .project)
( .classpath)
( .settings/org.eclipse.jdt.core.prefs)
( .settings/org.eclipse.jdt.ui.prefs)
Output asserted

Now we can import the projects to eclipse (without copying them to the workspace!) and study what we have. In fact, let's even make the first edit: another hello target alongside with the existing one.

~/iwant-tutorial $ $EDITOR "as-iwant-tutorial-developer/i-have/wsdef/src/main/java/com/example/wsdef/IwanttutorialWorkspace.java"
package com.example.wsdef;
import java.util.Arrays;
import java.util.List;
import net.sf.iwant.api.core.HelloTarget;
import net.sf.iwant.api.model.SideEffect;
import net.sf.iwant.api.model.Target;
import net.sf.iwant.api.wsdef.IwantWorkspace;
import net.sf.iwant.api.wsdef.SideEffectDefinitionContext;
import net.sf.iwant.eclipsesettings.EclipseSettings;
public class IwanttutorialWorkspace implements IwantWorkspace {
@Override
public List<? extends Target> targets() {
return Arrays.asList(new HelloTarget("hello", "hello from iwant\n"));
return Arrays.asList(new HelloTarget("hello", "hello from iwant\n"),
hello2());
}
private static Target hello2() {
return new HelloTarget("hello2", "hello from my first target\n");
}
@Override
public List<? extends SideEffect> sideEffects(
SideEffectDefinitionContext ctx) {
return Arrays
.asList(EclipseSettings
.with()
.name("eclipse-settings")
.modules(ctx.wsdefdefJavaModule(),
ctx.wsdefJavaModule()).end());
}
}

We can see our new target in the list of targets.

~/iwant-tutorial $ as-iwant-tutorial-developer/with/bash/iwant/list-of/targets
(0/1 S~ net.sf.iwant.api.javamodules.JavaClasses iwant-tutorial-wsdef-main-classes)
hello
hello2
Output asserted

Building a target means wishing for a path to a file that contains the fresh content of the target. Let's try that for the two targets we have.

~/iwant-tutorial $ as-iwant-tutorial-developer/with/bash/iwant/target/hello/as-path
(0/1 D! net.sf.iwant.api.core.HelloTarget hello)
/home/hacker/iwant-tutorial/as-iwant-tutorial-developer/.i-cached/target/hello
Output asserted
~/iwant-tutorial $ as-iwant-tutorial-developer/with/bash/iwant/target/hello2/as-path
(0/1 D! net.sf.iwant.api.core.HelloTarget hello2)
/home/hacker/iwant-tutorial/as-iwant-tutorial-developer/.i-cached/target/hello2
Output asserted

iwant only prints the requested path to stdout, all diagnostic output goes to stderr. This means we can redirect the path to further processing. This is a convenient idiom for showing the content of a target:

~/iwant-tutorial $ as-iwant-tutorial-developer/with/bash/iwant/target/hello2/as-path | xargs cat
hello from my first target
Output asserted
<< Creating the workspace definition | ^ Site index ^ | ^ Tutorial index ^ | Using ant cli instead of bash >>