Skip to content
This repository has been archived by the owner on Nov 15, 2020. It is now read-only.

3.0.1 snapshot #40

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
8 changes: 7 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>ru.sbtqa.tag</groupId>
<artifactId>api-factory</artifactId>
<version>3.0-SNAPSHOT</version>
<version>3.0.1-SNAPSHOT</version>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

В ветке менять версию не надо. Это автоматически произойдет при релизе

<packaging>jar</packaging>
<name>api-factory</name>
<description>api-factory description</description>
Expand Down Expand Up @@ -48,6 +48,12 @@
</repository>
</distributionManagement>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>4.3.14.RELEASE</version>
<type>jar</type>
</dependency>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

стандартные отступ для xml - 2 пробела

<dependency>
<groupId>ru.sbtqa.tag</groupId>
<artifactId>datajack</artifactId>
Expand Down
35 changes: 35 additions & 0 deletions src/main/java/cucumber/runtime/io/CucumberStaticRunner.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package cucumber.runtime.io;

import static java.util.Arrays.asList;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Мне кажется, этого статик импорта можно избежать.


import java.io.IOException;
import java.util.ArrayList;

import cucumber.runtime.ClassFinder;
import cucumber.runtime.Runtime;
import cucumber.runtime.RuntimeOptions;

public class CucumberStaticRunner {

// private String status = "Finished: FAILURE";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Лучше убрать закомментированный код

private static String status = "\nFinished: SUCCESS";

public static void startTests(String[] argv) throws Throwable {
byte exitstatus = run(argv, Thread.currentThread().getContextClassLoader());
System.exit(exitstatus);
}

public static byte run(String[] argv, ClassLoader classLoader) throws IOException {
RuntimeOptions runtimeOptions = new RuntimeOptions(new ArrayList<String>(asList(argv)));

ResourceLoader resourceLoader = new CustomMultiLoader(classLoader);
ClassFinder classFinder = new ResourceLoaderClassFinder(resourceLoader, classLoader);
Runtime runtime = new Runtime(resourceLoader, classFinder, classLoader, runtimeOptions);
runtime.run();
if (runtime.getErrors().size() > 0 || runtime.getSnippets().size() > 0) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Мне кажется, здесь мы можем использовать метод isEmpty() вместо size() > 0

status = "Finished: FAILURE";
}
System.out.println(status);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

необходимо заменить все println и prinstacktrace на логирование

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Тут нужно проверить. Добавил вывод в консоль на уровне warn

Output to the console

log4j.rootLogger=WARN
log4j.appender.AF=org.apache.log4j.ConsoleAppender
log4j.appender.AF.layout=org.apache.log4j.SimpleLayout
но на 100 % не уверен.
LOG.warn(status);
Тут обязательно необходимо выводить статус в консоль. Джоба будет по нему орентироваться.

return runtime.exitStatus();
}
}
62 changes: 62 additions & 0 deletions src/main/java/cucumber/runtime/io/CustomMultiLoader.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package cucumber.runtime.io;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
public class CustomMultiLoader implements ResourceLoader {
public static final String CLASSPATH_SCHEME = "classpath*:";
public static final String CLASSPATH_SCHEME_TO_REPLACE = "classpath:";
private final ClasspathResourceLoader classpath;
private final FileResourceLoader fs;
public CustomMultiLoader(ClassLoader classLoader) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Нужно нормальное форматирование, newline и все такое

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

И сделать это нужно во всех новых файлах

classpath = new ClasspathResourceLoader(classLoader);
fs = new FileResourceLoader();
}
@Override
public Iterable<Resource> resources(String path, String suffix) {
if (isClasspathPath(path)) {
PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
String locationPattern = path.replace(CLASSPATH_SCHEME_TO_REPLACE, CLASSPATH_SCHEME) + "/**/*" + suffix;
org.springframework.core.io.Resource[] resources;
try {
resources = resolver.getResources(locationPattern);
} catch (IOException e) {
resources = null;
e.printStackTrace();
}
return convertToCucumberIterator(resources);
} else {
return fs.resources(path, suffix);
}
}
private Iterable<Resource> convertToCucumberIterator(org.springframework.core.io.Resource[] resources) {
List<Resource> results = new ArrayList<Resource>();
for (org.springframework.core.io.Resource resource : resources) {
results.add(new ResourceAdapter(resource));
}
return results;
}

public static String packageName(String gluePath) {
if (isClasspathPath(gluePath)) {
gluePath = stripClasspathPrefix(gluePath);
}
return gluePath.replace('/', '.').replace('\\', '.');
}

private static boolean isClasspathPath(String path) {
if (path.startsWith(CLASSPATH_SCHEME_TO_REPLACE)) {
path = path.replace(CLASSPATH_SCHEME_TO_REPLACE, CLASSPATH_SCHEME);
}
return path.startsWith(CLASSPATH_SCHEME);
}

private static String stripClasspathPrefix(String path) {
if (path.startsWith(CLASSPATH_SCHEME_TO_REPLACE)) {
path = path.replace(CLASSPATH_SCHEME_TO_REPLACE, CLASSPATH_SCHEME);
}
return path.substring(CLASSPATH_SCHEME.length());
}

}

50 changes: 50 additions & 0 deletions src/main/java/cucumber/runtime/io/ResourceAdapter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package cucumber.runtime.io;

import java.io.IOException;
import java.io.InputStream;

public class ResourceAdapter implements Resource {
org.springframework.core.io.Resource springResource;

public ResourceAdapter(org.springframework.core.io.Resource springResource) {
this.springResource = springResource;
}

public String getPath() {
try {
return springResource.getFile().getPath();
} catch (IOException e) {
try {
return springResource.getURL().toString();
} catch (IOException e1) {
e1.printStackTrace();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Может сюда логирование подключить?

return "";
}
}
}

public String getAbsolutePath() {
try {
return springResource.getFile().getAbsolutePath();
} catch (IOException e) {
return null;
}
}

public InputStream getInputStream() throws IOException {
return this.springResource.getInputStream();
}

public String getClassName(String extension) {

String path = this.getPath();
if (path.startsWith("jar:")) {
path = path.substring(path.lastIndexOf("!") + 2);
return path.substring(0, path.length() - extension.length()).replace('/', '.');
} else {
path = path.substring(path.lastIndexOf("classes") + 8);
return path.substring(0, path.length() - extension.length()).replace('\\', '.');
}

}
}
Loading