Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ public JUnitPlansProvider(Class<?> testClass) {
public List<StepClassParserResult> getTestPlans(ExecutionEngine executionEngine) {
try {
AutomationPackageManager automationPackageManager = executionEngine.getExecutionEngineContext().require(AutomationPackageManager.class);
AutomationPackageFromClassLoaderProvider automationPackageProvider = new AutomationPackageFromClassLoaderProvider(testClass.getClassLoader());
AutomationPackageFromClassLoaderProvider automationPackageProvider = new AutomationPackageFromClassLoaderProvider();
AutomationPackageUpdateParameter localCreateParameters = new AutomationPackageUpdateParameterBuilder().withCreateOnly()
.forLocalExecution().withClasspathBased(true).build();
.forLocalExecution().build();
ObjectId automationPackageId = automationPackageManager.createOrUpdateAutomationPackage(
automationPackageProvider, new NoAutomationPackageLibraryProvider(), localCreateParameters).getId();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
import step.parameter.automation.AutomationPackageParametersRegistration;
import step.resources.ResourceManager;

import static step.core.execution.OperationMode.isLocal;

/**
* Registers the automation package manager for local executions in execution engine context
*/
Expand All @@ -39,7 +41,7 @@ public class AutomationPackageLocalOSPlugin extends AbstractExecutionEnginePlugi

@Override
public void initializeExecutionEngineContext(AbstractExecutionEngineContext parentContext, ExecutionEngineContext context) {
if (context.getOperationMode() == OperationMode.LOCAL) {
if (isLocal(context.getOperationMode())) {
FunctionAccessor functionAccessor = context.require(FunctionAccessor.class);
ResourceManager resourceManager = context.getResourceManager();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
import step.parameter.ParameterManager;
import step.plugins.parametermanager.ParameterManagerPlugin;

import static step.core.execution.OperationMode.isLocal;

@Plugin(dependencies= {BasePlugin.class})
public class ParameterManagerLocalPlugin extends ParameterManagerPlugin {

Expand All @@ -42,7 +44,7 @@ public ParameterManagerLocalPlugin() {

@Override
public void initializeExecutionEngineContext(AbstractExecutionEngineContext parentContext, ExecutionEngineContext executionEngineContext) {
if (executionEngineContext.getOperationMode() != OperationMode.LOCAL) {
if (!isLocal(executionEngineContext.getOperationMode())) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import step.automation.packages.junit.*;
import step.core.execution.ExecutionContext;
import step.core.execution.ExecutionEngine;
import step.core.execution.OperationMode;
import step.engine.plugins.AbstractExecutionEnginePlugin;

public class Step extends AbstractStepRunner {
Expand All @@ -30,7 +31,9 @@ public Step(Class<?> klass) throws InitializationError {
super(klass, klass);

try {
executionEngine = ExecutionEngine.builder().withPlugin(new AbstractExecutionEnginePlugin() {
executionEngine = ExecutionEngine.builder()
.withOperationMode(OperationMode.LOCAL_AUTOMATION_PACKAGE)
.withPlugin(new AbstractExecutionEnginePlugin() {
@Override
public void afterExecutionEnd(ExecutionContext context) {
resourceManager = context.getResourceManager();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import step.automation.packages.junit.JUnitPlansProvider;
import step.cli.ExecuteAutomationPackageTool;
import step.core.execution.ExecutionEngine;
import step.core.execution.OperationMode;
import step.core.plans.runner.PlanRunnerResult;
import step.junit.runner.StepClassParserResult;

Expand All @@ -37,7 +38,9 @@ public abstract class StepJUnit5 {

@BeforeAll
public static void setupExecutionEngine() {
executionEngine = ExecutionEngine.builder().withPluginsFromClasspath().build();
executionEngine = ExecutionEngine.builder()
.withOperationMode(OperationMode.LOCAL_AUTOMATION_PACKAGE)
.withPluginsFromClasspath().build();
}

@AfterAll
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,13 @@

public class AutomationPackageFromClassLoaderProvider implements AutomationPackageArchiveProvider {

private final ClassLoader classLoader;

public AutomationPackageFromClassLoaderProvider(ClassLoader classLoader) {
this.classLoader = classLoader;
public AutomationPackageFromClassLoaderProvider() {
}

@Override
public AutomationPackageArchive getAutomationPackageArchive() throws AutomationPackageReadingException {
return new JavaAutomationPackageArchive(classLoader);
return new JavaAutomationPackageArchive();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ public AutomationPackageUpdateResult createOrUpdateAutomationPackage(AutomationP
AtomicReference<AutomationPackageStaging> staging = new AtomicReference<>(null);
try (AutomationPackageArchive automationPackageArchive = automationPackageProvider.getAutomationPackageArchive()) {
AutomationPackage newPackage;
AutomationPackageContent packageContent = readAutomationPackage(automationPackageArchive, parameters.versionName, parameters.isClasspathBased);
AutomationPackageContent packageContent = readAutomationPackage(automationPackageArchive, parameters.versionName);

AutomationPackage oldPackage = findOldPackage(parameters.explicitOldId, parameters.objectPredicate, packageContent);

Expand Down Expand Up @@ -1077,10 +1077,10 @@ protected AutomationPackage createNewInstance(String fileName, AutomationPackage
return newPackage;
}

protected <A extends AutomationPackageArchive> AutomationPackageContent readAutomationPackage(A automationPackageArchive, String apVersion, boolean isClasspathBased) throws AutomationPackageReadingException {
protected <A extends AutomationPackageArchive> AutomationPackageContent readAutomationPackage(A automationPackageArchive, String apVersion) throws AutomationPackageReadingException {
AutomationPackageContent packageContent;
AutomationPackageReader<A> reader = automationPackageReaderRegistry.getReader(automationPackageArchive);
packageContent = reader.readAutomationPackage(automationPackageArchive, apVersion, isClasspathBased);
packageContent = reader.readAutomationPackage(automationPackageArchive, apVersion);
if (packageContent == null) {
throw new AutomationPackageManagerException("Automation package descriptor is missing, allowed names: " + METADATA_FILES);
} else if (packageContent.getName() == null || packageContent.getName().isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,28 +85,22 @@ public AutomationPackageArchive createAutomationPackageArchive(File automationPa

abstract public List<String> getSupportedFileTypes();

/**
* @param isClasspathBased true if the automation package is located in current classloader (i.e. all annotated keywords
* can be read as {@link step.engine.plugins.LocalFunctionPlugin.LocalFunction}, but not as {@link GeneralScriptFunction}
*/
public AutomationPackageContent readAutomationPackage(T automationPackageArchive, String apVersion, boolean isClasspathBased) throws AutomationPackageReadingException {
return this.readAutomationPackage(automationPackageArchive, apVersion, isClasspathBased, true);
public AutomationPackageContent readAutomationPackage(T automationPackageArchive, String apVersion) throws AutomationPackageReadingException {
return this.readAutomationPackage(automationPackageArchive, apVersion, true);
}

/**
* @param isClasspathBased true if the automation package is located in current classloader (i.e. all annotated keywords
* can be read as {@link step.engine.plugins.LocalFunctionPlugin.LocalFunction}, but not as {@link GeneralScriptFunction}
* @param scanAnnotations true if it is required to include annotated java keywords and plans as well as located in yaml descriptor
*/
public AutomationPackageContent readAutomationPackage(T automationPackageArchive, String apVersion, boolean isClasspathBased, boolean scanAnnotations) throws AutomationPackageReadingException {
public AutomationPackageContent readAutomationPackage(T automationPackageArchive, String apVersion, boolean scanAnnotations) throws AutomationPackageReadingException {
try {
if (automationPackageArchive.hasAutomationPackageDescriptor()) {
try (InputStream yamlInputStream = automationPackageArchive.getDescriptorYaml()) {
AutomationPackageDescriptorYaml descriptorYaml = getOrCreateDescriptorReader().readAutomationPackageDescriptor(yamlInputStream, automationPackageArchive.getOriginalFileName());
return buildAutomationPackage(descriptorYaml, automationPackageArchive, apVersion, isClasspathBased, scanAnnotations);
AutomationPackageDescriptorYaml descriptorYaml = getOrCreateDescriptorReader().readAutomationPackageDescriptor(yamlInputStream, automationPackageArchive.getAutomationPackageName());
return buildAutomationPackage(descriptorYaml, automationPackageArchive, apVersion, scanAnnotations);
}
} else if (scanAnnotations) {
return buildAutomationPackage(null, automationPackageArchive, apVersion, isClasspathBased, scanAnnotations);
return buildAutomationPackage(null, automationPackageArchive, apVersion, scanAnnotations);
} else {
return null;
}
Expand All @@ -116,14 +110,14 @@ public AutomationPackageContent readAutomationPackage(T automationPackageArchive
}

protected AutomationPackageContent buildAutomationPackage(AutomationPackageDescriptorYaml descriptor, T archive, String apVersion,
boolean isClasspathBased, boolean scanAnnotations) throws AutomationPackageReadingException {
boolean scanAnnotations) throws AutomationPackageReadingException {
AutomationPackageContent res = newContentInstance();
String baseName = resolveName(descriptor, archive);
res.setBaseName(baseName);
res.setName(resolveUniqueName(baseName, apVersion));

if (scanAnnotations) {
fillAutomationPackageWithAnnotatedKeywordsAndPlans(archive, isClasspathBased, res);
fillAutomationPackageWithAnnotatedKeywordsAndPlans(archive, res);
}

// apply imported fragments recursively
Expand Down Expand Up @@ -177,7 +171,7 @@ protected AutomationPackageContent newContentInstance(){
return new AutomationPackageContent();
}

abstract protected void fillAutomationPackageWithAnnotatedKeywordsAndPlans(T archive, boolean isClasspathBased, AutomationPackageContent res) throws AutomationPackageReadingException;
abstract protected void fillAutomationPackageWithAnnotatedKeywordsAndPlans(T archive, AutomationPackageContent res) throws AutomationPackageReadingException;

public void fillAutomationPackageWithImportedFragments(AutomationPackageContent targetPackage, AutomationPackageFragmentYaml fragment, T archive) throws AutomationPackageReadingException {
fillContentSections(targetPackage, fragment, archive);
Expand All @@ -187,7 +181,7 @@ public void fillAutomationPackageWithImportedFragments(AutomationPackageContent
List<URL> resources = archive.getResourcesByPattern(importedFragmentReference);
for (URL resource : resources) {
try (InputStream fragmentYamlStream = resource.openStream()) {
fragment = getOrCreateDescriptorReader().readAutomationPackageFragment(fragmentYamlStream, importedFragmentReference, archive.getOriginalFileName());
fragment = getOrCreateDescriptorReader().readAutomationPackageFragment(fragmentYamlStream, importedFragmentReference, archive.getAutomationPackageName());
fillAutomationPackageWithImportedFragments(targetPackage, fragment, archive);
} catch (IOException e) {
throw new AutomationPackageReadingException("Unable to read fragment in automation package: " + importedFragmentReference, e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,14 +188,6 @@ public Resource uploadOrReuseApResource(AutomationPackageArchiveProvider apProvi
boolean allowToReuseOldResource, boolean allowUpdateContent) {
String origin = Optional.ofNullable(apProvider.getOrigin()).map(ResourceOrigin::toStringRepresentation).orElse(null);
File originalFile = automationPackageArchive.getOriginalFile();
if (originalFile == null) {
// When running an AP locally using the JUnit runner, we do not set the automation package resource
// This causes the methods that require it (like AbstractKeyword#retrieveAndExtractAutomationPackage) to fail
// In the future we should support this properly. An idea would e to use the ClassLoaderArchiver to create an
// archive out of the classloader.
return null;
}

Resource resource = null;

Optional<Resource> existingResource = Optional.empty();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,6 @@ public class AutomationPackageUpdateParameter extends AutomationPackageAccessPar
* whether creation of a new package is allowed, set to false when an update is expected
*/
public final boolean allowCreate;
/**
* Whether the package is embedded in the classpath of the runner (i.e. Step Junit runner)
*/
public final boolean isClasspathBased;
/**
* Id of the existing package that has to be updated, should be combined with allowUpdate true and allowCreate false
*/
Expand Down Expand Up @@ -94,7 +90,7 @@ public class AutomationPackageUpdateParameter extends AutomationPackageAccessPar
*/
public final boolean reloading;

public AutomationPackageUpdateParameter(boolean allowUpdate, boolean allowCreate, boolean isClasspathBased, ObjectId explicitOldId,
public AutomationPackageUpdateParameter(boolean allowUpdate, boolean allowCreate, ObjectId explicitOldId,
AutomationPackageFileSource apSource, AutomationPackageFileSource apLibrarySource,
String versionName, String activationExpression, ObjectEnricher enricher,
ObjectPredicate objectPredicate, WriteAccessValidator writeAccessValidator, boolean async,
Expand All @@ -105,7 +101,6 @@ public AutomationPackageUpdateParameter(boolean allowUpdate, boolean allowCreate
super(enricher, objectPredicate, writeAccessValidator, actorUser);
this.allowUpdate = allowUpdate;
this.allowCreate = allowCreate;
this.isClasspathBased = isClasspathBased;
this.explicitOldId = explicitOldId;
this.apSource = apSource;
this.apLibrarySource = apLibrarySource;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
public class AutomationPackageUpdateParameterBuilder {
private boolean allowUpdate = true;
private boolean allowCreate = true;
private boolean isClasspathBased = false;
private ObjectId explicitOldId = null;
private AutomationPackageFileSource apSource;
private AutomationPackageFileSource apLibrarySource;
Expand Down Expand Up @@ -40,12 +39,6 @@ public AutomationPackageUpdateParameterBuilder withAllowCreate(boolean allowCrea
return this;
}

public AutomationPackageUpdateParameterBuilder withClasspathBased(boolean isClasspathBased) {
this.isClasspathBased = isClasspathBased;
return this;
}


public AutomationPackageUpdateParameterBuilder withExplicitOldId(ObjectId explicitOldId) {
this.explicitOldId = explicitOldId;
return this;
Expand Down Expand Up @@ -130,7 +123,6 @@ public AutomationPackageUpdateParameterBuilder forRedeployPackage(ObjectHookRegi
this.allowUpdate = true;
this.allowCreate = false;
this.explicitOldId = oldPackage.getId();
this.isClasspathBased = parentParameters.isClasspathBased;
String automationPackageResource = oldPackage.getAutomationPackageResource();
if (FileResolver.isResource(automationPackageResource)) {
this.apSource = AutomationPackageFileSource.withResourceId(FileResolver.resolveResourceId(automationPackageResource));
Expand Down Expand Up @@ -204,7 +196,7 @@ public AutomationPackageUpdateParameterBuilder forLocalExecution() {
}

public AutomationPackageUpdateParameter build() {
return new AutomationPackageUpdateParameter(allowUpdate, allowCreate, isClasspathBased, explicitOldId, apSource,
return new AutomationPackageUpdateParameter(allowUpdate, allowCreate, explicitOldId, apSource,
apLibrarySource, versionName, activationExpression, enricher, objectPredicate, writeAccessValidator,
async, actorUser, forceRefreshOfSnapshots, checkForSameOrigin, functionsAttributes, plansAttributes,
tokenSelectionCriteria, executeFunctionsLocally, reloading);
Expand Down
Loading