Skip to content

Commit

Permalink
* Implemented parts of #84 (and somewhat parts of #33);
Browse files Browse the repository at this point in the history
* Fixed update to pull syntax for SCMs
  • Loading branch information
benjboyer committed Apr 21, 2020
1 parent 53f108c commit a79ddf4
Show file tree
Hide file tree
Showing 25 changed files with 570 additions and 169 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ reports/
*.scm-sh
.gitcache/
node_modules/
/report.md
4 changes: 2 additions & 2 deletions examples/composer/scms/scmA.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ echo '${param4}'
git clone -b ${branch} ${src} .
"""

update """
pull """
git pull
"""
}
Expand All @@ -59,7 +59,7 @@ scm {
git clone -b ${branch} ${src} .
"""

update """
pull """
git pull
"""
}
Expand Down
4 changes: 2 additions & 2 deletions examples/composer/scms/scmB.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ scm {
git clone -b ${branch} ${src} .
"""

update """
pull """
git pull
"""
}
Expand All @@ -42,7 +42,7 @@ scm {
git clone -b ${branch} ${src} .
"""

update """
pull """
git pull
"""
}
Expand Down
4 changes: 2 additions & 2 deletions examples/composer/scms/scmC.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ scm {
git clone ${src} .
"""

update """
pull """
git pull
"""
}
Expand All @@ -34,7 +34,7 @@ scm {
git clone ${src} .
"""

update """
pull """
git pull
"""
}
Expand Down
24 changes: 17 additions & 7 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
<version>2.4.0</version>
</dependency>

<!-- Other stuff -->
<!-- Frameworks -->

<dependency>
<groupId>commons-lang</groupId>
Expand Down Expand Up @@ -94,18 +94,34 @@
<version>1.3.1</version>
</dependency>

<dependency>
<groupId>com.github.spullara.mustache.java</groupId>
<artifactId>compiler</artifactId>
<version>0.9.6</version>
</dependency>

<dependency>
<groupId>jakarta.xml.bind</groupId>
<artifactId>jakarta.xml.bind-api</artifactId>
<version>2.3.2</version>
</dependency>

<!-- Utils -->

<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-utils</artifactId>
<version>3.3.0</version>
</dependency>

<dependency>
<groupId>commons-validator</groupId>
<artifactId>commons-validator</artifactId>
<version>1.6</version>
</dependency>

<!-- Loggers -->

<dependency>
<groupId>org.tinylog</groupId>
<artifactId>tinylog-impl</artifactId>
Expand All @@ -118,12 +134,6 @@
<version>2.0.1</version>
</dependency>

<dependency>
<groupId>commons-validator</groupId>
<artifactId>commons-validator</artifactId>
<version>1.6</version>
</dependency>

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/io/peasoup/inv/run/BroadcastDescriptor.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ public BroadcastDescriptor using(@DelegatesTo(BroadcastUsingDescriptor.class) Cl
if (broadcastUsingDescriptor.getId() != null)
broadcastStatement.setId(broadcastUsingDescriptor.getId());


broadcastStatement.setMarkdown(broadcastUsingDescriptor.getMarkdown());
broadcastStatement.setReady(broadcastUsingDescriptor.getReady());

return this;
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/io/peasoup/inv/run/BroadcastStatement.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public class BroadcastStatement implements Statement {
public static final Manageable BROADCAST = new Broadcast();
private Object id;
private String name;
private String markdown;
private Closure<Map> ready;
private Inv inv;
private StatementStatus state = StatementStatus.NOT_PROCESSED;
Expand Down Expand Up @@ -38,6 +39,14 @@ public void setName(String name) {
this.name = name;
}

public String getMarkdown() {
return markdown;
}

public void setMarkdown(String markdown) {
this.markdown = markdown;
}

public Closure<Map> getReady() {
return ready;
}
Expand Down
20 changes: 20 additions & 0 deletions src/main/java/io/peasoup/inv/run/BroadcastUsingDescriptor.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package io.peasoup.inv.run;

import groovy.lang.Closure;
import org.apache.commons.lang.StringUtils;

import java.util.Map;

public class BroadcastUsingDescriptor {
private Object id;
private String markdown;
private Closure ready;

/**
Expand All @@ -30,6 +32,18 @@ public void id(Map id) {
this.id = id;
}

/**
* Defines the markdown documentation for this broadcast statement
* @param markdown the markdown string
*/
public void markdown(String markdown) {
if (StringUtils.isEmpty(markdown)) {
throw new IllegalArgumentException("Markdown is required");
}

this.markdown = markdown;
}

/**
* Event raised when broadcast is ready during the running cycle.
* <p>
Expand All @@ -47,7 +61,13 @@ public Object getId() {
return id;
}

public String getMarkdown() {
return markdown;
}

public Closure getReady() {
return ready;
}


}
112 changes: 100 additions & 12 deletions src/main/java/io/peasoup/inv/run/Inv.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

public class Inv {

private final NetworkValuablePool pool;
private final Context context;

private final Digestion digestionSummary;
private final InvDescriptor delegate;
Expand All @@ -31,12 +31,12 @@ public class Inv {
private final Queue<Statement> totalStatements;
private int stepCount;

public Inv(NetworkValuablePool pool) {
if (pool == null) {
throw new IllegalArgumentException("Pool is required");
private Inv(Context context) {
if (context == null) {
throw new IllegalArgumentException("Context is required");
}

this.pool = pool;
this.context = context;

this.digestionSummary = new Digestion();
this.properties = new InvDescriptor.Properties();
Expand All @@ -58,7 +58,7 @@ public synchronized boolean dumpDelegate() {
if (pop == null) pop = properties.isPop();
if (tags == null) tags = delegate.getTags();

Boolean dumpedSomething = pool.include(this);
Boolean dumpedSomething = context.pool.include(this);

// Transfer Statement(s) from delegate to INV
for (Statement statement : properties.getStatements()) {
Expand All @@ -69,7 +69,7 @@ public synchronized boolean dumpDelegate() {
this.totalStatements.add(statement);
this.remainingStatements.add(statement);

pool.checkAvailability(statement.getName());
context.pool.checkAvailability(statement.getName());

Logger.system("[STATEMENT] " + statement.toString() + " [INIT]");
}
Expand Down Expand Up @@ -114,7 +114,7 @@ public synchronized void addProperty(String propertyName, Object value) {
*/
@SuppressWarnings("squid:S135")
public Digestion digest() {
if (!pool.isDigesting()) {
if (!context.pool.isDigesting()) {
throw new IllegalArgumentException("digest() is only callable during its pool digest cycle");
}

Expand Down Expand Up @@ -158,10 +158,10 @@ private Digestion digestStatements() {
Statement statement = statementsLeft.poll();

// (try to) manage statement
statement.getMatch().manage(pool, statement);
statement.getMatch().manage(context.pool, statement);

// Process results for digestion
currentDigestion.checkStatementResult(pool, statement);
currentDigestion.checkStatementResult(context.pool, statement);

// Remove statement is completed
if (!currentDigestion.isInterrupted())
Expand All @@ -186,7 +186,7 @@ private boolean digestSteps() {
while (!steps.isEmpty() &&
!hasDumpedSomething &&
this.remainingStatements.isEmpty() &&
!pool.isHalting()) {
!context.pool.isHalting()) {

// Call next step
Step step = steps.poll();
Expand All @@ -213,7 +213,7 @@ private boolean digestWhensEvent() {
continue;

// Process When data
boolean processedPositively = whenData.getProcessor().qualify(pool, this) > 0;
boolean processedPositively = whenData.getProcessor().qualify(context.pool, this) > 0;

// If processed, raise callback and check for dumps
if (processedPositively) {
Expand Down Expand Up @@ -260,6 +260,10 @@ public boolean equals(Object o) {
return name.equals(invO.getName());
}

protected Context getContext() {
return context;
}

public String getName() {
return name;
}
Expand Down Expand Up @@ -313,6 +317,90 @@ public String toString() {
return "[" + name + "]";
}

public static class Context {

private final NetworkValuablePool pool;
private String defaultName;
private String defaultPath;
private String scm;
private String scriptFilename;

public Context(NetworkValuablePool pool) {
if (pool == null) {
throw new IllegalArgumentException("Pool is required");
}

this.pool = pool;
}

public Context setDefaultName(String name) {
if (StringUtils.isEmpty(name))
return this;

this.defaultName = name;

return this;
}

public Context setDefaultPath(String path) {
if (StringUtils.isEmpty(path))
return this;

this.defaultPath = path;

return this;
}

public Context setSCM(String scm) {
if (StringUtils.isEmpty(scm))
return this;

this.scm = scm;

return this;
}

public Context setScriptFilename(String scriptFilename) {
if (StringUtils.isEmpty(scriptFilename))
return this;

this.scriptFilename = scriptFilename;

return this;
}

public Inv build() {

Inv inv = new Inv(this);

// Set name from delegate - needs digestion to apply.
if (StringUtils.isNotEmpty(defaultName))
inv.delegate.name(defaultName);

// Set path from delegate - needs digestion to apply.
if (StringUtils.isNotEmpty(defaultPath))
inv.delegate.path(defaultPath);

return inv;
}

public String getDefaultName() {
return defaultName;
}

public String getDefaultPath() {
return defaultPath;
}

public String getScm() {
return scm;
}

public String getScriptFilename() {
return scriptFilename;
}
}

public static class Digestion {
private Integer requires = 0;
private Integer broadcasts = 0;
Expand Down
Loading

0 comments on commit a79ddf4

Please sign in to comment.