This chapter continues from where Creating the workspace definition left us.
Using an iwant plugin (for untarring)
~/iwant-tutorial $ $EDITOR "as-iwant-tutorial-developer/i-have/wsdefdef/src/main/java/com/example/wsdefdef/IwantTutorialWorkspaceProvider.java"
package com.example.wsdefdef;
import org.fluentjava.iwant.api.javamodules.JavaSrcModule;
import org.fluentjava.iwant.api.wsdef.WorkspaceModuleContext;
import org.fluentjava.iwant.api.wsdef.WorkspaceModuleProvider;
public class IwantTutorialWorkspaceProvider implements WorkspaceModuleProvider {
@Override
public JavaSrcModule workspaceModule(WorkspaceModuleContext ctx) {
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(ctx.wsdefdefModule())
.mainDeps(ctx.iwantPlugin().ant().withDependencies()).end();
}
@Override
public String workspaceFactoryClassname() {
return "com.example.wsdef.IwanttutorialWorkspaceFactory";
}
}
We have to generate Eclipse settings before editing the workspace definition.
~/iwant-tutorial $ as-iwant-tutorial-developer/with/bash/iwant/side-effect/eclipse-settings/effective
(0/1 S~ org.fluentjava.iwant.api.javamodules.JavaClasses iwant-tutorial-wsdefdef-main-classes)
(0/1 D! org.fluentjava.iwant.core.download.GnvArtifact ant-1.10.1.jar)
(0/1 D! org.fluentjava.iwant.core.download.GnvArtifact ant-launcher-1.10.1.jar)
(0/1 D! org.fluentjava.iwant.api.javamodules.JavaClasses iwant-plugin-ant)
(0/1 D~ org.fluentjava.iwant.api.javamodules.JavaClasses iwant-tutorial-wsdef-main-classes)
(0/1 D! org.fluentjava.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)
Now we define an untarred target using iwant-plugin-ant.
~/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 org.fluentjava.iwant.api.core.HelloTarget;
import org.fluentjava.iwant.api.model.SideEffect;
import org.fluentjava.iwant.api.model.Source;
import org.fluentjava.iwant.api.model.Target;
import org.fluentjava.iwant.api.wsdef.SideEffectDefinitionContext;
import org.fluentjava.iwant.api.wsdef.TargetDefinitionContext;
import org.fluentjava.iwant.api.wsdef.Workspace;
import org.fluentjava.iwant.eclipsesettings.EclipseSettings;
import org.fluentjava.iwant.plugin.ant.Untarred;
public class IwanttutorialWorkspace implements Workspace {
@Override
public List<? extends Target> targets(TargetDefinitionContext ctx) {
return Arrays.asList(new HelloTarget("hello", "hello from iwant\n"));
return Arrays.asList(new HelloTarget("hello", "hello from iwant\n"),
untarredTest());
}
private static Target untarredTest() {
return Untarred.with().name("Untarred-test").gzCompression()
.from(Source.underWsroot("Untarred-test.tar.gz")).end();
}
@Override
public List<? extends SideEffect> sideEffects(
SideEffectDefinitionContext ctx) {
return Arrays.asList(EclipseSettings.with().name("eclipse-settings")
.modules(ctx.wsdefdefJavaModule(), ctx.wsdefJavaModule())
.end());
}
}
We create the source tar to be untarred.
~/iwant-tutorial $ mkdir Untarred-test
~/iwant-tutorial $ echo "hello" > Untarred-test/tarred-file
~/iwant-tutorial $ tar czf Untarred-test.tar.gz Untarred-test/
~/iwant-tutorial $ rm -rf Untarred-test
Finally we list the content of the untarred tar file.
~/iwant-tutorial $ as-iwant-tutorial-developer/with/bash/iwant/list-of/targets
(0/1 S~ org.fluentjava.iwant.api.javamodules.JavaClasses iwant-tutorial-wsdef-main-classes)
hello
Untarred-test
~/iwant-tutorial $ as-iwant-tutorial-developer/with/bash/iwant/target/Untarred-test/as-path | xargs -r find
(0/1 D! org.fluentjava.iwant.plugin.ant.Untarred Untarred-test)
Expanding: /home/hacker/iwant-tutorial/Untarred-test.tar.gz into /home/hacker/iwant-tutorial/as-iwant-tutorial-developer/.i-cached/target/Untarred-test
/home/hacker/iwant-tutorial/as-iwant-tutorial-developer/.i-cached/target/Untarred-test
/home/hacker/iwant-tutorial/as-iwant-tutorial-developer/.i-cached/target/Untarred-test/Untarred-test
/home/hacker/iwant-tutorial/as-iwant-tutorial-developer/.i-cached/target/Untarred-test/Untarred-test/tarred-file