Skip to content

Commit

Permalink
Allow reading building blocks from jars. issue #297 issue #296
Browse files Browse the repository at this point in the history
  • Loading branch information
itaiag committed Jun 21, 2017
1 parent 4ac94df commit a203d91
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 24 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ testtimes.properties
jsystem-core-projects/jsystemCore/file.properties
!jsystem-assembly/jsystem-runner/src/main/etc/jsystem.properties
!jsystem-assembly/jsystem-runner/src/main/etc/.project
jsystem-core-projects/jsystemApp/.run.properties
jsystem.properties.bu
runnerState.properties
log
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,17 @@ public enum GUIFrameworkOptions {
"It will limit the source file analysis. Please be aware that you should enter the jar name\n" +
"without the '.jar' extention"
),

TESTS_JAR_NAME_PREFIX(
FrameworkOptions.TESTS_JAR_NAME_PREFIX,
true,
Group.ADVANCED,
"The name prefix of the jars that are located in the tests lib folder and will be \n" +
"scanned for building blocks. \n" +
"This is useful in cases in which we would like to create a system object with the \n" +
"basic system object building blocks included in the jar \n" +
"or when we want to create project with multiple building blocks modules \n"
),


/**
Expand Down Expand Up @@ -450,7 +461,7 @@ public enum GUIFrameworkOptions {
IGNORE_MEANINGFUL_NAME(
FrameworkOptions.IGNORE_MEANINGFUL_NAME,
true,
Group.BETA_FEATURES,
Group.ADVANCED,

"Tests annotations provide the JRunner additional information about how to present test metadata. \n" +
"Normally when adding a test to the scenario, the scenario includes the class name and the test name. \n" +
Expand All @@ -470,7 +481,7 @@ public enum GUIFrameworkOptions {
SCENARIO_AS_TEST(
FrameworkOptions.SCENARIO_AS_TEST,
true,
Group.BETA_FEATURES,
Group.ADVANCED,
"When set to true, root scenario can be marked as a test. A scenario which is marked as a test, will be visualized as a test"+
"when added as a sub scenario and in the HTML report. \n"+
"In JSystem reports server the scenario will be count as a test for the statiistics"
Expand All @@ -482,14 +493,14 @@ public enum GUIFrameworkOptions {
CMD_LINE_EXECUTER(
FrameworkOptions.CMD_LINE_EXECUTER,
true,
Group.BETA_FEATURES,
Group.ADVANCED,
"Indicates what command line executor engine should be chosen."
),

MAX_BUILDING_BLOCKS_NUMBER(
FrameworkOptions.MAX_BUILDING_BLOCKS_NUMBER,
true,
Group.BETA_FEATURES,
Group.ADVANCED,
"Set the maximum number of building blocks in a scenario"
),

Expand Down Expand Up @@ -805,7 +816,7 @@ public enum GUIFrameworkOptions {
GENERIC_TABS(
FrameworkOptions.GENERIC_TABS,
true,
Group.BETA_FEATURES,
Group.ADVANCED,
"List of classes which implement jsystem.treeui.interfaces.JSystemTab (under JSystemApp)\n" +
"Use this property to add custom tabs. \n" +
"Once you update this field, The JSystem will restart and add the new tabs." +
Expand All @@ -817,7 +828,7 @@ public enum GUIFrameworkOptions {
DATA_PROVIDER_CLASSES(
FrameworkOptions.DATA_PROVIDER_CLASSES,
true,
Group.BETA_FEATURES,
Group.ADVANCED,
"Allow users to implement different data providers for the data driven building block.\n"+
"For example, database data provider, Excel data provider, etc..\n" +
"To create a new data provider one need to create a new Maven project and add JSystemAnt project "+
Expand Down Expand Up @@ -924,9 +935,8 @@ public enum Group {
MAIL(3, "Mail"),
DISTRIBUTED_EXECUTION(4, "Distributed Execution"),
ADVANCED(5, "Advanced"),
BETA_FEATURES(6, "New Features"),
SOURCE_CONTROL(7, "Source Control"),
REPORTS_PUBLISHER(8,"Reports Publisher");
SOURCE_CONTROL(6, "Source Control"),
REPORTS_PUBLISHER(7,"Reports Publisher");

private int index;
private String value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import jsystem.utils.beans.AsmUtils;
import jsystem.utils.beans.MethodElement;
import junit.framework.SystemTestCase;
import junit.framework.SystemTestCase4;
import junit.framework.TestCase;

import org.apache.xpath.XPathAPI;
Expand Down Expand Up @@ -234,7 +235,7 @@ protected void initChildren(Object[] child) throws Exception {
Class testClass = LoadersManager.getInstance()
.getLoader().loadClass(className);

if (SystemTestCase.class.isAssignableFrom(testClass)) {
if (SystemTestCase4.class.isAssignableFrom(testClass)) {
children.add(new TestCaseNode(this, testClass));
}
} catch (Throwable ignore) {
Expand Down Expand Up @@ -293,7 +294,7 @@ private boolean isJar(File file) {
}

private boolean exludedJar(File f) {
return true;
return false;
}

public Enumeration<Object> getAllChildren() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package jsystem.treeui.tree;

import java.io.File;
import java.io.FilenameFilter;
import java.util.StringTokenizer;
import java.util.Vector;

Expand Down Expand Up @@ -58,10 +59,50 @@ public RootNode() throws Exception {
add(root);
}

initChildren(fPathItems.toArray());
initChildren(addJarsFromLibFolderToArray(fPathItems.toArray()));
markChildrenAsClassPath();
}

/**
*
* @param array
* @return
* @author Itai Agmon
*/
private Object[] addJarsFromLibFolderToArray(Object[] array) {
String libFolderName = JSystemProperties.getTestsLibFolder();
if (libFolderName == null) {
return array;
}
File libFolder = new File(libFolderName);
if (!libFolder.isDirectory()){
return array;
}
final String soPrefix = JSystemProperties.getInstance().getPreferenceOrDefault(FrameworkOptions.TESTS_JAR_NAME_PREFIX);
if (null == soPrefix) {
return array;
}
File[] jarFiles = libFolder.listFiles(new FilenameFilter(){

@Override
public boolean accept(File dir, String name) {
if (name.startsWith(soPrefix) && name.endsWith(".jar")){
return true;
}
return false;
}

});
if (jarFiles == null || jarFiles.length == 0){
return array;
}

Object[] newArr = new Object[array.length + jarFiles.length];
System.arraycopy(array, 0, newArr, 0, array.length);
System.arraycopy(jarFiles, 0, newArr, array.length, jarFiles.length);
return newArr;
}

private void scanPath(String classPath) {
String separator = System.getProperty("path.separator");
fPathItems = new Vector<File>(10);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -860,7 +860,15 @@ public enum FrameworkOptions {
"",
false
),


TESTS_JAR_NAME_PREFIX(
"tests.jar.name.prefix",
"The name prefix of jar files that will be scanned for building blocks",
DataType.TEXT,
"so-",
true
),

SORT_ASSETS_TREE(
"sort.tests.tree",
"",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -321,10 +321,8 @@ private void initLogger() {
if (!isReporterVm()) {
String remoteLogConf = "logger=true\n"
+ "handlers=java.util.logging.FileHandler java.util.logging.ConsoleHandler\n"
+ "java.util.logging.FileHandler.limit=10000000\n"
+ "java.util.logging.FileHandler.count=4\n"
+ "jsystem.level= FINER\n"
+ "java.util.logging.FileHandler.append=true\n"
+ "java.util.logging.FileHandler.limit=10000000\n" + "java.util.logging.FileHandler.count=4\n"
+ "jsystem.level= FINER\n" + "java.util.logging.FileHandler.append=true\n"
+ "java.util.logging.FileHandler.formatter=java.util.logging.SimpleFormatter\n"
// +
// "java.util.logging.FileHandler.formatter=jsystem.utils.BasicFormatter\n"
Expand Down Expand Up @@ -373,7 +371,8 @@ public static String getCurrentTestsPath() {
}

if (!JSystemProperties.getInstance().isJsystemRunner()) {
StringTokenizer st = new StringTokenizer(System.getProperty("java.class.path"), System.getProperty("path.separator"));
StringTokenizer st = new StringTokenizer(System.getProperty("java.class.path"),
System.getProperty("path.separator"));
while (st.hasMoreTokens()) {
File f = new File(st.nextToken());
if (f.isDirectory() && f.exists()) {
Expand All @@ -387,12 +386,12 @@ public static String getCurrentTestsPath() {
if (path != null && getInstance().getPreference(FrameworkOptions.TESTS_SOURCE_FOLDER) == null) {
File pathFile = new File(path);
File testSrc = new File(pathFile.getParent(), "tests");
if (testSrc.exists()){
//Ant project structure
if (testSrc.exists()) {
// Ant project structure
getInstance().setPreference(FrameworkOptions.TESTS_SOURCE_FOLDER, testSrc.getPath());
getInstance().setPreference(FrameworkOptions.RESOURCES_SOURCE_FOLDER, testSrc.getPath());
}else {
//Maven project structure
getInstance().setPreference(FrameworkOptions.RESOURCES_SOURCE_FOLDER, testSrc.getPath());
} else {
// Maven project structure
testSrc = new File(pathFile.getParentFile().getParentFile(), "src/main/java");
getInstance().setPreference(FrameworkOptions.TESTS_SOURCE_FOLDER, testSrc.getPath());
File resourcesSrc = new File(pathFile.getParentFile().getParentFile(), "src/main/resources");
Expand All @@ -404,6 +403,24 @@ public static String getCurrentTestsPath() {
return path;
}

/**
* Finds the lib folder of the tests project
*
* @return return the lib folder of the tests project or null if not exists
* @author Itai Agmon
*/
public static String getTestsLibFolder() {
String testPath = getCurrentTestsPath();
if (testPath == null) {
return null;
}
File libFolder = new File(new File(testPath).getParentFile().getParentFile(), "lib");
if (!libFolder.exists() || !libFolder.isDirectory()) {
return null;
}
return libFolder.getAbsolutePath().toString();
}

public void removePreference(FrameworkOptions option) {
removePreference(option.toString());
}
Expand Down Expand Up @@ -490,7 +507,8 @@ public void loadPropertiesToCache() {
/**
*
* @return True - if called from the Reporter VM<br>
* (for JRunner execution - True only if called from the JRunner VM, <br>
* (for JRunner execution - True only if called from the JRunner VM,
* <br>
* for Ant\IDE execution - True always)
*/
public boolean isReporterVm() {
Expand Down

0 comments on commit a203d91

Please sign in to comment.