Package de.hsh.graja.modules.junit
Class JunitBroker
- java.lang.Object
-
- de.hsh.graja.modules.junit.JunitBroker
-
public class JunitBroker extends Object
This class serves requests from assignment grader instances, that are create by JUnit. It stores comments from graders and delivers information to graders such as the current workspace.
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Class<?>
getClassForName(String name)
Graders must call this method to load classes from student submissions, since this method guarantees that student code is loaded into the appropriate protection domain.ArrayList<Map.Entry<String,Sequence>>
getCommentsFromGrader()
Delivers all comments from graders.Path
getCurrentWorkspace()
WorkspaceCVVp
getCVVp()
Class<?>
getInterfaceForName(String name)
Graders must call this method to load interfaces from student submissions, since this method guarantees that student code is loaded into the appropriate protection domain.Sequence
getOrRegisterCommentsFromGrader(String testMethodKey)
Class<?>
getPublicClassForName(String name)
Graders must call this method to load classes from student submissions, since this method guarantees that student code is loaded into the appropriate protection domain.Class<?>
getPublicInterfaceForName(String name)
Graders must call this method to load interfaces from student submissions, since this method guarantees that student code is loaded into the appropriate protection domain.<Base> Class<? extends Base>
getPublicSubclassForName(String fqn, Class<Base> baseClass)
Returns the class as a subclass of Base.<Base> Class<? extends Base>
getSubclassForName(String fqn, Class<Base> baseClass)
Returns the class as a subclass of Base.long
getTimeoutAt()
Class<?>
readClassIntoGraderProtectionDomain(String code, String fullyQualifiedClassname, Class<?> graderClass, StringBuilder errorLog)
Sometimes a grader wants to compile code that is generated on the fly.Class<?>
readClassIntoSubmissionProtectionDomain(String code, String fullyQualifiedClassname, StringBuilder errorLog)
Sometimes a grader wants to compile code that is generated on the fly.void
registerCommentsFromGrader(String testMethodKey, Sequence commentsFromCallingGrader)
A grader can register it's own comments using this method.Sequence
retrieveCommentsFromSingleTestMethod(String testMethodKey)
Detaches and returns the comments collected from a single test method
-
-
-
Method Detail
-
readClassIntoGraderProtectionDomain
public Class<?> readClassIntoGraderProtectionDomain(String code, String fullyQualifiedClassname, Class<?> graderClass, StringBuilder errorLog) throws IOException, ClassNotFoundException
Sometimes a grader wants to compile code that is generated on the fly. This method compiles that generated code and loads the resulting bytecode using the class loader that loaded the grader. For an elaborate example seeCompileString
.- Parameters:
code
- program source code that must specify a single classfullyQualifiedClassname
- the name of the class- Returns:
- the compiled byte code
- Throws:
IOException
- in case of I/O errors when generating / reading filesClassNotFoundException
- if the source code does not specify a single class
-
readClassIntoSubmissionProtectionDomain
public Class<?> readClassIntoSubmissionProtectionDomain(String code, String fullyQualifiedClassname, StringBuilder errorLog) throws IOException, ClassNotFoundException
Sometimes a grader wants to compile code that is generated on the fly. This method compiles that generated code and loads the resulting bytecode using the class loader that loaded the grader. For an elaborate example seeCompileString
.- Parameters:
code
- program source code that must specify a single classfullyQualifiedClassname
- the name of the class- Returns:
- the compiled byte code
- Throws:
IOException
- in case of I/O errors when generating / reading filesClassNotFoundException
- if the source code does not specify a single class
-
getCurrentWorkspace
public Path getCurrentWorkspace()
Workspace- Returns:
- workspace
-
getTimeoutAt
public long getTimeoutAt()
- Returns:
- the current grader should not run after the return value of this method interpreted as milliseconds like System.currentTimeMillis()
-
getCVVp
public CVVp getCVVp()
- Returns:
- the variation resolution, if there is any; null, if there is none.
-
registerCommentsFromGrader
public void registerCommentsFromGrader(String testMethodKey, Sequence commentsFromCallingGrader)
A grader can register it's own comments using this method. Then when a test finishes, the corresponding comments are automatically put near the test method name in the comment output.- Parameters:
testMethodKey
-commentsFromCallingGrader
-
-
getCommentsFromGrader
public ArrayList<Map.Entry<String,Sequence>> getCommentsFromGrader()
Delivers all comments from graders. Key of the returned Map.Entry objects is the test method key as delivered by JUnitModuleConfiguration.getTestMethodKey.
-
getOrRegisterCommentsFromGrader
public Sequence getOrRegisterCommentsFromGrader(String testMethodKey)
-
retrieveCommentsFromSingleTestMethod
public Sequence retrieveCommentsFromSingleTestMethod(String testMethodKey)
Detaches and returns the comments collected from a single test method- Parameters:
testMethodKey
-- Returns:
- comments collected from a single test method
-
getClassForName
public Class<?> getClassForName(String name)
Graders must call this method to load classes from student submissions, since this method guarantees that student code is loaded into the appropriate protection domain. If the class cannot be found, this method fails with a org.junit.Assert.fail.- Parameters:
name
-- Returns:
- the class object
-
getInterfaceForName
public Class<?> getInterfaceForName(String name)
Graders must call this method to load interfaces from student submissions, since this method guarantees that student code is loaded into the appropriate protection domain. If the interface cannot be found, this method fails with a org.junit.Assert.fail.- Parameters:
name
-- Returns:
- the interface as a class object
-
getPublicClassForName
public Class<?> getPublicClassForName(String name)
Graders must call this method to load classes from student submissions, since this method guarantees that student code is loaded into the appropriate protection domain. If the class cannot be found or is not public, this method fails with a org.junit.Assert.fail.- Parameters:
name
-- Returns:
- the class object
-
getPublicInterfaceForName
public Class<?> getPublicInterfaceForName(String name)
Graders must call this method to load interfaces from student submissions, since this method guarantees that student code is loaded into the appropriate protection domain. If the interface cannot be found or is not public, this method fails with a org.junit.Assert.fail.- Parameters:
name
-- Returns:
- the class object
-
getSubclassForName
public <Base> Class<? extends Base> getSubclassForName(String fqn, Class<Base> baseClass)
Returns the class as a subclass of Base. fails, if the class is not found or it is not a subclass of Base. Subclass here means including Base itself.- Parameters:
fqn
-baseClass
-- Returns:
- the class object
-
getPublicSubclassForName
public <Base> Class<? extends Base> getPublicSubclassForName(String fqn, Class<Base> baseClass)
Returns the class as a subclass of Base. fails, if the class is not found or it is not public or it is not a subclass of Base. Subclass here means including Base itself.- Parameters:
fqn
-baseClass
-- Returns:
- the class object
-
-