<< (Code) from github | ^ Site index ^ | ^ Tutorial index ^ | Writing a custom Target >>

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

Using a module of the workspace in the build

~/iwant-tutorial $ $EDITOR "as-iwant-tutorial-developer/i-have/wsdefdef/src/main/java/com/example/wsdefdef/IwantTutorialWorkspaceProvider.java"
package com.example.wsdefdef;
import net.sf.iwant.api.javamodules.JavaSrcModule;
import net.sf.iwant.api.wsdef.IwantWorkspaceProvider;
import net.sf.iwant.api.wsdef.WorkspaceDefinitionContext;
public class IwantTutorialWorkspaceProvider implements IwantWorkspaceProvider {
@Override
public JavaSrcModule workspaceModule(WorkspaceDefinitionContext ctx) {
return JavaSrcModule.with().name("iwant-tutorial-wsdef")
return JavaSrcModule
.with()
.name("iwant-tutorial-wsdef")
.locationUnderWsRoot("as-iwant-tutorial-developer/i-have/wsdef")
.mainJava("src/main/java").mainDeps(ctx.iwantApiModules())
.mainDeps(ctx.wsdefdefModule()).end();
.mainDeps(exampleUtil(), ctx.wsdefdefModule()).end();
}
@Override
public String workspaceClassname() {
return "com.example.wsdef.IwanttutorialWorkspace";
}
public static JavaSrcModule exampleUtil() {
return JavaSrcModule.with().name("example-util")
.mainJava("src/main/java").end();
}
}
~/iwant-tutorial $ mkdir -p example-util/src/main/java/com/example/util
~/iwant-tutorial $ as-iwant-tutorial-developer/with/bash/iwant/side-effect/eclipse-settings/effective
(0/1 D! net.sf.iwant.api.javamodules.JavaClasses example-util-main-classes)
(0/1 S~ net.sf.iwant.api.javamodules.JavaClasses iwant-tutorial-wsdefdef-main-classes)
(0/1 D~ net.sf.iwant.api.javamodules.JavaClasses iwant-tutorial-wsdef-main-classes)
(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)

We import the new module to Eclipse and create a utility.

~/iwant-tutorial $ $EDITOR "example-util/src/main/java/com/example/util/ExampleUtil.java"
package com.example.util;
public class ExampleUtil {
public static String capitalize(String s) {
return s.toUpperCase();
}
}

Now the utility is available in our build as well as being served by it.

~/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;
import com.example.util.ExampleUtil;
import com.example.wsdefdef.IwantTutorialWorkspaceProvider;
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"),
targetUsingModuleFromSameWs());
}
private static Target targetUsingModuleFromSameWs() {
return new HelloTarget("targetUsingModuleFromSameWs",
ExampleUtil.capitalize("String made with ExampleUtil."));
}
@Override
public List<? extends SideEffect> sideEffects(
SideEffectDefinitionContext ctx) {
return Arrays
.asList(EclipseSettings
.with()
.name("eclipse-settings")
.modules(ctx.wsdefdefJavaModule(),
ctx.wsdefJavaModule()).end());
return Arrays.asList(EclipseSettings.with().name("eclipse-settings")
.modules(ctx.wsdefdefJavaModule(), ctx.wsdefJavaModule())
.modules(IwantTutorialWorkspaceProvider.exampleUtil()).end());
}
}
~/iwant-tutorial $ as-iwant-tutorial-developer/with/bash/iwant/list-of/targets
(0/1 S~ net.sf.iwant.api.javamodules.JavaClasses example-util-main-classes)
(0/1 S~ net.sf.iwant.api.javamodules.JavaClasses iwant-tutorial-wsdef-main-classes)
hello
targetUsingModuleFromSameWs
~/iwant-tutorial $ as-iwant-tutorial-developer/with/bash/iwant/target/targetUsingModuleFromSameWs/as-path | xargs cat
(0/1 D! net.sf.iwant.api.core.HelloTarget targetUsingModuleFromSameWs)
STRING MADE WITH EXAMPLEUTIL.
<< (Code) from github | ^ Site index ^ | ^ Tutorial index ^ | Writing a custom Target >>