Skip to content

Commit

Permalink
Fix OptimizedWalker to skip condition if the nested node is skipped (#…
Browse files Browse the repository at this point in the history
…995)

- Overload ArchetypeV2.generate to expose a variant that accepts externalValues, externalDefaults and directorySupplier
  This allows to avoid creating a new instance of the engine for every project generation

Fixes #994
  • Loading branch information
romain-grecourt authored Oct 23, 2023
1 parent 0dcc796 commit 6cc827a
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,15 @@ private ArchetypeEngineV2(Builder builder) {
/**
* Generate a project.
*
* @param externalValues external values
* @param externalDefaults external defaults
* @param directorySupplier directory supplier
* @return output directory
*/
public Path generate() {
public Path generate(Map<String, String> externalValues,
Map<String, String> externalDefaults,
Function<String, Path> directorySupplier) {

Context context = Context.builder()
.cwd(cwd)
.externalValues(externalValues)
Expand Down Expand Up @@ -94,6 +100,15 @@ public Path generate() {
return directory;
}

/**
* Generate a project.
*
* @return output directory
*/
public Path generate() {
return generate(externalValues, externalDefaults, directorySupplier);
}

/**
* Create a new builder.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

import io.helidon.build.archetype.engine.v2.Walker;
import io.helidon.build.archetype.engine.v2.ast.Block;
import io.helidon.build.archetype.engine.v2.ast.Condition;
import io.helidon.build.archetype.engine.v2.ast.DeclaredBlock;
import io.helidon.build.archetype.engine.v2.ast.Invocation;
import io.helidon.build.archetype.engine.v2.ast.Node;
Expand Down Expand Up @@ -116,6 +117,14 @@ public Node.VisitResult postVisitBlock(Block block, Void arg) {
}
}

@Override
public Node.VisitResult visitCondition(Condition condition, Void arg) {
if (isSkipped(condition.then())) {
return Node.VisitResult.SKIP_SUBTREE;
}
return condition.accept(visitor, this.visitorArg);
}

@Override
public Node.VisitResult visitAny(Node node, Void arg) {
if (isSkipped(node)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2022 Oracle and/or its affiliates.
Copyright (c) 2022, 2023 Oracle and/or its affiliates.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -24,7 +24,7 @@
<inputs>
<enum id="enum1" name="Enum1">
<option value="enum1-value1" name="Enum1Value1">
<exec src="script1.xml"/>
<exec src="script1.xml" if="true"/>
</option>
<option value="enum1-value2" name="Enum1Value2"/>
</enum>
Expand Down

0 comments on commit 6cc827a

Please sign in to comment.