-
Notifications
You must be signed in to change notification settings - Fork 0
pull request #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Fame513
wants to merge
8
commits into
review
Choose a base branch
from
master
base: review
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
pull request #1
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
c3f026d
remove all
Fame513 c8e22d5
Yieir
Fame513 08b8a24
Add annotations
Fame513 23244bb
clean code
Fame513 3bda027
I want to sleep
Fame513 2ad127c
Made Spring injection in JSF managed bean, but as singleton
Fame513 39e7346
Js class no more singleton
Fame513 cf2b695
console added
Fame513 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| package pp.ua.fame.config; | ||
|
|
||
| import jdk.nashorn.api.scripting.NashornScriptEngineFactory; | ||
| import org.springframework.context.annotation.Bean; | ||
| import org.springframework.context.annotation.ComponentScan; | ||
| import org.springframework.context.annotation.Configuration; | ||
| import org.springframework.context.annotation.Scope; | ||
|
|
||
| import javax.persistence.EntityManager; | ||
| import javax.persistence.Persistence; | ||
| import javax.script.ScriptEngine; | ||
| import javax.script.ScriptEngineManager; | ||
|
|
||
| @Configuration | ||
| @ComponentScan(basePackages = "pp.ua.fame") | ||
| public class SpringConfig { | ||
| @Bean | ||
| public EntityManager entityManager(){ | ||
| return Persistence.createEntityManagerFactory("TesterDB").createEntityManager(); | ||
| } | ||
|
|
||
| public ScriptEngine nashorn(){ | ||
| return new NashornScriptEngineFactory().getScriptEngine("--no-java"); | ||
| } | ||
|
|
||
| public ScriptEngine rhino(){ | ||
| return new ScriptEngineManager().getEngineByName("rhino"); | ||
| } | ||
|
|
||
| @Bean | ||
| @Scope("prototype") | ||
| public ScriptEngine scriptEngine(){ | ||
| return nashorn(); | ||
| } | ||
|
|
||
| } |
19 changes: 16 additions & 3 deletions
19
src/main/java/pp/ua/fame/controllers/SpringController.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,15 +1,28 @@ | ||
| package pp.ua.fame.controllers; | ||
|
|
||
| import org.springframework.beans.factory.annotation.Autowired; | ||
| import org.springframework.stereotype.Controller; | ||
| import org.springframework.ui.ModelMap; | ||
| import org.springframework.web.bind.annotation.PathVariable; | ||
| import org.springframework.web.bind.annotation.RequestMapping; | ||
| import org.springframework.web.bind.annotation.RequestMethod; | ||
| import pp.ua.fame.dao.impl.TaskDaoImp; | ||
| import pp.ua.fame.model.Task; | ||
|
|
||
| import javax.servlet.http.HttpServletRequest; | ||
|
|
||
| @Controller | ||
| public class SpringController { | ||
|
|
||
| @Autowired | ||
| private TaskDaoImp taskDao; | ||
|
|
||
| @RequestMapping(value = "/main/{id}", method = RequestMethod.GET) | ||
| public String Task(ModelMap model, @PathVariable("id") Integer id){ | ||
| return "/main.xhtml?id="+id; | ||
| public String Task(@PathVariable("id") Integer id, HttpServletRequest req){ | ||
| Task task = taskDao.getTask(id); | ||
| if (task == null) { | ||
| return ("404page.xhtml"); | ||
| } | ||
| req.setAttribute("task", task); | ||
| return "/main.xhtml"; | ||
| } | ||
| } |
4 changes: 2 additions & 2 deletions
4
src/main/java/pp/ua/fame/DAO/TaskDao.java → src/main/java/pp/ua/fame/dao/TaskDao.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| package pp.ua.fame.dao.impl; | ||
|
|
||
| import org.springframework.beans.factory.annotation.Autowired; | ||
| import org.springframework.stereotype.Component; | ||
| import pp.ua.fame.dao.TaskDao; | ||
| import pp.ua.fame.model.Task; | ||
| import sun.reflect.generics.reflectiveObjects.NotImplementedException; | ||
|
|
||
| import javax.persistence.EntityManager; | ||
|
|
||
| @Component() | ||
| public class TaskDaoImp implements TaskDao { | ||
| @Autowired | ||
| private EntityManager entityManager; | ||
|
|
||
| @Override | ||
| public Task getTask(long id) { | ||
| return entityManager.find(Task.class, id); | ||
| } | ||
|
|
||
| @Override | ||
| public void addTask(String description, String source) { | ||
| throw new NotImplementedException(); | ||
| } | ||
|
|
||
| @Override | ||
| public void deleteTask(long id) { | ||
| throw new NotImplementedException(); | ||
| } | ||
|
|
||
| @Override | ||
| public void addTest(String test, String answer) { | ||
| throw new NotImplementedException(); | ||
| } | ||
|
|
||
| @Override | ||
| public void deleteTest(long id) { | ||
| throw new NotImplementedException(); | ||
| } | ||
| } |
2 changes: 1 addition & 1 deletion
2
...p/ua/fame/exceptions/TesterException.java → ...pp/ua/fame/exception/TesterException.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
.../ua/fame/exceptions/TimeoutException.java → ...p/ua/fame/exception/TimeoutException.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ame/exceptions/TypeMismatchException.java → ...fame/exception/TypeMismatchException.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 19 additions & 24 deletions
43
src/main/java/pp/ua/fame/JSRuner/JS.java → src/main/java/pp/ua/fame/jsRuner/Js.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,49 +1,44 @@ | ||
| package pp.ua.fame.JSRuner; | ||
| package pp.ua.fame.jsRuner; | ||
|
|
||
| import org.springframework.context.ApplicationContext; | ||
| import org.springframework.context.support.ClassPathXmlApplicationContext; | ||
| import pp.ua.fame.exceptions.TimeoutException; | ||
| import org.springframework.beans.factory.annotation.Autowired; | ||
| import org.springframework.context.annotation.Scope; | ||
| import org.springframework.stereotype.Component; | ||
| import pp.ua.fame.exception.TimeoutException; | ||
|
|
||
| import javax.faces.context.FacesContext; | ||
| import javax.script.ScriptEngine; | ||
| import javax.script.ScriptException; | ||
| import java.io.ByteArrayOutputStream; | ||
| import java.io.OutputStreamWriter; | ||
|
|
||
| enum Status{CREATE, RUN, ERROR, FINISH, TIMEOUT} | ||
|
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. CaMeL cAsE |
||
| public class JS { | ||
| @Component() | ||
| @Scope("prototype") | ||
| public class Js { | ||
|
|
||
| private final int TIMEOUT = 5000; | ||
|
|
||
| private Status status; | ||
| private static final int TIMEOUT = 5000; | ||
|
|
||
| @Autowired | ||
| private ScriptEngine engine; | ||
|
|
||
| private Status status = Status.CREATE; | ||
|
|
||
| private String source; | ||
|
|
||
| private ScriptException ex; | ||
|
|
||
| Result result; | ||
| private Result result; | ||
|
|
||
| private static ApplicationContext appContext; | ||
|
|
||
| public JS(String source) { | ||
| if (appContext == null) { | ||
| FacesContext ctx = FacesContext.getCurrentInstance(); | ||
| String configLocation = | ||
| ctx.getExternalContext().getInitParameter("contextConfigLocation"); | ||
| appContext = new ClassPathXmlApplicationContext(configLocation); | ||
| } | ||
| engine = (ScriptEngine)appContext.getBean("nashorn"); | ||
| // engine.getContext().setWriter(new OutputStreamWriter(System.err)); | ||
| public Js(String source) { | ||
| this.source = source; | ||
| status = Status.CREATE; | ||
| } | ||
|
|
||
| public Result eval() throws ScriptException, TimeoutException { | ||
| status = Status.RUN; | ||
| Thread calculatingThread = new Thread(() ->{ | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not needed line |
||
| try { | ||
| result = new Result(engine.eval(source)); | ||
| ByteArrayOutputStream myConsole = new ByteArrayOutputStream(); | ||
| engine.getContext().setWriter(new OutputStreamWriter(myConsole)); | ||
| result = new Result(engine.eval(source), new String(myConsole.toByteArray())); | ||
| status = Status.FINISH; | ||
| } catch (ScriptException e) { | ||
| ex = e; | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| package pp.ua.fame.jsRuner; | ||
|
|
||
| public enum Status{ | ||
| CREATE, RUN, ERROR, FINISH, TIMEOUT | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why enum in one file with class?