Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into report-builder-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
iantmoore committed Feb 17, 2017
2 parents 7ce03e9 + b870a7d commit 605cb48
Show file tree
Hide file tree
Showing 13 changed files with 145 additions and 30 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ Requirements
------------
* Java 8

1.0.6
-----
* Redacted some of the output of the config
* Passed the name of the running feature and scenario into the context.
* RemoteWebDriverFactory sets up additional information to pass though via capabilities (current git branch, version)

1.0.5
-----
* Single Maven plugin, glossary functionality moved into the same plugin that provides execution and report building,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@

package com.technophobia.substeps.model;

import com.typesafe.config.Config;
import com.typesafe.config.ConfigFactory;
import com.typesafe.config.ConfigRenderOptions;
import com.typesafe.config.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -71,8 +69,18 @@ public String getConfigurationInfo() {
ConfigRenderOptions options =
ConfigRenderOptions.defaults().setComments(false).setFormatted(true).setJson(false).setOriginComments(false);

return config.withoutPath("java")
.withoutPath("sun").withoutPath("awt").withoutPath("idea").withoutPath("line.separator").withoutPath("os").withoutPath("path.separator").root().render(options);
return config
.withoutPath("java")
.withoutPath("sun")
.withoutPath("awt")
.withoutPath("idea")
.withoutPath("line.separator")
.withoutPath("os")
.withoutPath("path.separator")
.withValue("remote.token", ConfigValueFactory.fromAnyRef("******"))
.withValue("remote.username", ConfigValueFactory.fromAnyRef("******"))

.root().render(options);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,14 @@ private Object getInternal(final Scope scope, final String key) {
}
return rtn;
}
public static void clear(final Scope scope, String key) {
ExecutionContext ec = executionContextThreadLocal.get();
Map<String, Object> map = ec.scopedData.get(scope);
if (map != null) {
map.remove(key);
}

}

public static void clear(final Scope scope) {
executionContextThreadLocal.get().scopedData.remove(scope);
Expand Down
11 changes: 11 additions & 0 deletions api/src/main/resources/reference.conf
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,15 @@ parameter{
}

}
}

substeps{
current {
branchname = ""
branchname = ${?SUBSTEPS_CURRENT_BRANCHNAME}

projectversion=""
projectversion = ${?SUBSTEPS_CURRENT_PROJECT_VERSION}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ private void afterExecute(final NODE_TYPE node, final boolean success, final Roo
private boolean runSetup(final NODE_TYPE node, final RootNodeExecutionContext context) {

try {
context.getSetupAndTeardown().runSetup(getScope());
context.getSetupAndTeardown().runSetup(getScope(), node);
return true;
} catch (final Throwable t) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
package com.technophobia.substeps.runner.setupteardown;

import com.technophobia.substeps.execution.MethodExecutor;
import com.technophobia.substeps.execution.node.IExecutionNode;
import com.technophobia.substeps.model.Scope;
import com.technophobia.substeps.runner.ExecutionContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.MDC;
Expand Down Expand Up @@ -123,9 +125,11 @@ private void removeLoggingConfig() {
}


public void runSetup(final Scope currentScope) throws Throwable {
public void runSetup(final Scope currentScope, IExecutionNode node) throws Throwable {
this.log.trace("running setup for scope: " + currentScope);

ExecutionContext.put(currentScope, "SCOPE_DESCRIPTION", node.getDescription());

switch (currentScope) {
case SUITE: {
runBeforeAll();
Expand All @@ -152,6 +156,7 @@ public void runSetup(final Scope currentScope) throws Throwable {
public void runTearDown(final Scope currentScope) throws Throwable {
this.log.trace("runTearDown: " + currentScope);


// TODO: could implement this as methods on Scope itself
switch (currentScope) {
case SUITE: {
Expand All @@ -177,5 +182,8 @@ public void runTearDown(final Scope currentScope) throws Throwable {
}
}

ExecutionContext.clear(currentScope, "SCOPE_DESCRIPTION");


}
}
1 change: 0 additions & 1 deletion core/src/test/resources/localhost.conf
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,3 @@ users{
}
}


6 changes: 5 additions & 1 deletion runner/Maven/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,11 @@
<artifactId>gson</artifactId>
</dependency>


<dependency>
<groupId>org.eclipse.jgit</groupId>
<artifactId>org.eclipse.jgit</artifactId>
<version>4.6.0.201612231935-r</version>
</dependency>
<!-- <dependency>
<groupId>org.apache.maven.shared</groupId>
<artifactId>maven-plugin-testing-harness</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import com.technophobia.substeps.runner.BaseSubstepsMojo;
import com.technophobia.substeps.runner.ExecutionConfig;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugin.descriptor.PluginDescriptor;
Expand Down Expand Up @@ -70,8 +69,8 @@ public class SubstepsGlossaryMojo extends BaseSubstepsMojo {

/**
*/
@Parameter(defaultValue = "${project}", required = true, readonly = true)
private MavenProject project;
// @Parameter(defaultValue = "${project}", required = true, readonly = true)
// private MavenProject project;

/**
*/
Expand Down Expand Up @@ -159,6 +158,8 @@ private String resolveClassToPath(final String classToDocument, final String dir
@Override
public void execute() throws MojoExecutionException, MojoFailureException {

setupBuildEnvironmentInfo();

final HashSet<String> loadedClasses = new HashSet<String>();

final List<StepImplementationsDescriptor> classStepTags = new ArrayList<StepImplementationsDescriptor>();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
package com.technophobia.substeps.runner;

import com.technophobia.substeps.model.Configuration;
import com.technophobia.substeps.report.ExecutionReportBuilder;
import com.typesafe.config.Config;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.project.MavenProject;
import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.storage.file.FileRepositoryBuilder;
import org.substeps.report.IExecutionResultsCollector;
import org.substeps.report.IReportBuilder;

Expand Down Expand Up @@ -51,7 +56,7 @@ public abstract class BaseSubstepsMojo extends AbstractMojo {

/**
*/
@Parameter(defaultValue = "${project}", readonly = true)
@Parameter(defaultValue = "${project}", readonly = true, required = true)
protected MavenProject project;

/**
Expand Down Expand Up @@ -112,4 +117,42 @@ public void setRunTestsInForkedVM(boolean runTestsInForkedVM) {
this.runTestsInForkedVM = runTestsInForkedVM;
}

public String getVersion(){
return project.getVersion();
}

protected void setupBuildEnvironmentInfo(){



MavenProject root = project;

while (root.hasParent()){
root = root.getParent();
}
System.setProperty("SUBSTEPS_CURRENT_PROJECT_VERSION", project.getVersion());


FileRepositoryBuilder builder = new FileRepositoryBuilder();
try {
Repository repository = builder.setGitDir(new File(root.getBasedir(), ".git"))
.readEnvironment() // scan environment GIT_* variables
.findGitDir() // scan up the file system tree
.build();

Git git = new Git(repository);

String branchName = git.getRepository().getBranch();

if (branchName != null) {
System.setProperty("SUBSTEPS_CURRENT_BRANCHNAME", branchName);
}
}
catch (Exception e){
// this is best efforts...
getLog().debug("Not important - Exception trying to get hold of the current branch", e);

}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,9 @@
*/
package com.technophobia.substeps.runner;

import com.technophobia.substeps.execution.node.RootNode;
import com.technophobia.substeps.report.ExecutionReportBuilder;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.DependencyResolutionRequiredException;
import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.resolver.ArtifactResolver;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.*;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.MavenProjectBuilder;
import org.substeps.report.IExecutionResultsCollector;
import org.substeps.report.IReportBuilder;

import java.io.File;
import java.util.List;
Expand All @@ -53,6 +40,7 @@ public class SubstepsReportBuilderMojo extends BaseSubstepsMojo {
@Override
public void execute() throws MojoExecutionException, MojoFailureException {

setupBuildEnvironmentInfo();

getLog().info("Building substeps report from data in: " + this.executionResultsCollector.getDataDir().toString());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,17 @@
package com.technophobia.substeps.runner;

import com.technophobia.substeps.execution.node.RootNode;
import com.technophobia.substeps.report.ExecutionReportBuilder;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.DependencyResolutionRequiredException;
import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.resolver.ArtifactResolver;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.*;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.MavenProjectBuilder;
import org.substeps.report.IExecutionResultsCollector;

import java.util.List;

Expand Down Expand Up @@ -104,7 +101,6 @@ public class SubstepsRunnerMojo extends BaseSubstepsMojo {
private List<Artifact> pluginDependencies;



/**
* // * at component
*/
Expand All @@ -118,6 +114,8 @@ public void execute() throws MojoExecutionException, MojoFailureException {

ensureValidConfiguration();

setupBuildEnvironmentInfo();

this.runner = this.runTestsInForkedVM ? createForkedRunner() : createInProcessRunner();

try {
Expand All @@ -131,6 +129,8 @@ public void execute() throws MojoExecutionException, MojoFailureException {
}




private ForkedRunner createForkedRunner() throws MojoExecutionException {

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,20 @@

import com.technophobia.substeps.execution.node.ExecutionNode;
import com.technophobia.substeps.execution.node.RootNode;
import com.technophobia.substeps.model.Configuration;
import com.technophobia.substeps.runner.BuildFailureManager;
import com.technophobia.substeps.runner.ExecutionConfig;
import com.technophobia.substeps.runner.SubstepsRunnerMojo;
import com.typesafe.config.Config;
import junit.framework.Assert;
import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.lib.Ref;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.storage.file.FileRepositoryBuilder;
import org.junit.Ignore;
import org.junit.Test;

import java.io.File;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
Expand Down Expand Up @@ -86,4 +93,36 @@ public void testCriticalNonCriticalFailures() throws SecurityException, NoSuchMe

}

@Test
public void testGitStuff(){

FileRepositoryBuilder builder = new FileRepositoryBuilder();
try {
Repository repository = builder.setGitDir(new File("/home/ian/projects/github/substeps-framework/.git"))
.readEnvironment() // scan environment GIT_* variables
.findGitDir() // scan up the file system tree
.build();

Git git = new Git(repository);

String branchName = git.getRepository().getBranch();
System.out.println("get branch: " + branchName);

if (branchName != null) {
System.setProperty("SUBSTEPS_CURRENT_BRANCHNAME", branchName);
}

Config cfg = Configuration.INSTANCE.getConfig();
//

System.out.println(cfg.getString("user.name"));

System.out.println(cfg.getString("substeps.current.branchname"));

}
catch (Exception e){
System.out.println("Exception trying to get hold of the current branch: " + e.getMessage());
}

}
}

0 comments on commit 605cb48

Please sign in to comment.