Skip to content

Commit 4392eab

Browse files
authored
Merge pull request #237 from bThink-BGU/develop
pre-0.14.0
2 parents 64040f1 + a70a0b2 commit 4392eab

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+560
-356
lines changed

README.md

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ If you use BPjs in an academic work, please consider citing it as:
3232
<dependency>
3333
<groupId>com.github.bthink-bgu</groupId>
3434
<artifactId>BPjs</artifactId>
35-
<version>0.13.0</version>
35+
<version>0.14.0</version>
3636
</dependency>
3737
...
3838
</dependencies>
@@ -52,6 +52,22 @@ If you use BPjs in an academic work, please consider citing it as:
5252

5353
## Change Log for the BPjs Library.
5454

55+
### 2025-12
56+
57+
> [!IMPORTANT]
58+
> This update breaks backward compatibility in some minor ways around logging and custom executor services, as some methods were
59+
> added and some classes were moved. See below for details. Updates should be pretty straightforward. Contact us if there's any
60+
> issue, we'll be happy to help.
61+
62+
* :arrow_up: Upgraded to Rhino 1.8.1.
63+
* :arrow_up: Upgraded build and test dependencies.
64+
* :bug: Fixed and issued which prevented executor sevices from being re-used. Users who use custom executor services in managed environments now need to use the new methods on `ExecutorService`: `borrow()`/`borrowWithName()` and `returnService()`. Most users will not be affected by this change.[#236](https://github.com/bThink-BGU/BPjs/issues/236)
65+
* :tada: BPLog moved to own package. BPjs now has a central static logger, and no prints should go to `Systen.(out|err)` if you don't want them to. This is still the default behavior, but now messages go through the logging system first, so they can be directed to other logging destinations as well. [#231](https://github.com/bThink-BGU/BPjs/issues/231)
66+
* :arrow_up: `BpLog` is now easier to subclass, as core functionality moved to the interface using `default` methods.
67+
* :sparkles: Added a new logging level: `Error`. Exposed via `bp.log.error("ouch!")`.
68+
* :arrow_up: When logger is in `Fine` level, sotrage modifications are printed to the b-program's logger. [#230](https://github.com/bThink-BGU/BPjs/issues/230)
69+
* :tada: Violations now have location and stack trace. [#224](https://github.com/bThink-BGU/BPjs/issues/224)
70+
5571
### 2025-02
5672
* :arrow_up: Upgraded to Rhino 1.8.0 with updated JavaScript version. See the many updates [here](https://github.com/mozilla/rhino/releases/tag/Rhino1_8_0_Release).
5773
* :arrow_up: ``DfsBProgramVerifier.ProgressListener` now supports default methods for easier implementation.
@@ -64,7 +80,7 @@ If you use BPjs in an academic work, please consider citing it as:
6480
* :bug: Fixed a crash when accessing a b-program's global scope before the program starts to run.
6581
* :arrow_up: Added method `BProgramRunner::getListeners` ([#190](https://github.com/bThink-BGU/BPjs/issues/190)).
6682
* :arrow_up: Setting a non-function interrupt handler (which you should never do anyway) now throws an exception with informative message, rather than being siletly ignored. ([#114](https://github.com/bThink-BGU/BPjs/issues/114)).
67-
* :part_altertion_mark: Stack traces now use standard V8 formatting ([#198](https://github.com/bThink-BGU/BPjs/issues/198)).
83+
* :part_alternation_mark: Stack traces now use standard V8 formatting ([#198](https://github.com/bThink-BGU/BPjs/issues/198)).
6884

6985
### 2023-09
7086
* :sparkles: EventSets now have an `except` method, that allows removal of events from the set. e.g. `allMotionEvents.except(moveDownEvent)`. ([#218](https://github.com/bThink-BGU/BPjs/issues/218))

docs/source/BPjsTutorial/code/logging.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,12 @@ bp.registerBThread( "event logging", function() {
1212
while (true) {
1313
var evt = bp.sync({waitFor:bp.all});
1414
bp.log.setLevel(LOG_LEVELS[idx]);
15+
bp.log.error( evt.name );
1516
bp.log.warn( evt.name );
1617
bp.log.info( evt.name );
1718
bp.log.fine( evt.name );
1819
idx++;
1920
}
20-
})
21+
});
2122

2223
bp.log.info("registering b-threads - done");

docs/source/BPjsTutorial/logging.rst

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,21 @@ The "event generator" creates four events, one for each logging level. The "even
1414

1515
.. code::
1616
17-
# [READ] /.../logging.js
18-
[JS][Info] registering b-threads - start
19-
-:BPjs Added event generator
20-
-:BPjs Added event logging
21-
[JS][Info] registering b-threads - done
22-
# [ OK ] logging.js
2317
---:BPjs Started
2418
--:BPjs Event [BEvent name:event 0]
25-
[JS][Warn] event 0
26-
[JS][Info] event 0
27-
[JS][Fine] event 0
19+
[BP][Error] event 0
20+
[BP][Warn] event 0
21+
[BP][Info] event 0
22+
[BP][Fine] event 0
2823
--:BPjs Event [BEvent name:event 1]
29-
[JS][Warn] event 1
30-
[JS][Info] event 1
24+
[BP][Error] event 1
25+
[BP][Warn] event 1
26+
[BP][Info] event 1
3127
--:BPjs Event [BEvent name:event 2]
32-
[JS][Warn] event 2
28+
[BP][Error] event 2
29+
[BP][Warn] event 2
3330
--:BPjs Event [BEvent name:event 3]
31+
-:BPjs Done event generator
3432
---:BPjs No Event Selected
3533
---:BPjs Ended
3634

pom.xml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
<dependency>
6565
<groupId>org.mozilla</groupId>
6666
<artifactId>rhino</artifactId>
67-
<version>1.8.0</version>
67+
<version>1.8.1</version>
6868
</dependency>
6969
<dependency>
7070
<groupId>junit</groupId>
@@ -113,7 +113,7 @@
113113
<plugin>
114114
<groupId>org.apache.maven.plugins</groupId>
115115
<artifactId>maven-javadoc-plugin</artifactId>
116-
<version>3.11.2</version>
116+
<version>3.12.0</version>
117117
<configuration>
118118
<source>11</source>
119119
</configuration>
@@ -186,7 +186,7 @@
186186
<plugin>
187187
<groupId>org.apache.maven.plugins</groupId>
188188
<artifactId>maven-shade-plugin</artifactId>
189-
<version>3.3.0</version>
189+
<version>3.6.1</version>
190190
<executions>
191191
<execution>
192192
<phase>package</phase>
@@ -239,7 +239,7 @@
239239
<plugin>
240240
<groupId>org.apache.maven.plugins</groupId>
241241
<artifactId>maven-javadoc-plugin</artifactId>
242-
<version>3.11.2</version>
242+
<version>3.12.0</version>
243243
<configuration>
244244
<source>8</source>
245245
</configuration>
@@ -255,7 +255,7 @@
255255
<plugin>
256256
<groupId>org.apache.maven.plugins</groupId>
257257
<artifactId>maven-gpg-plugin</artifactId>
258-
<version>3.2.7</version>
258+
<version>3.2.8</version>
259259
<executions>
260260
<execution>
261261
<id>sign-artifacts</id>

src/main/java/il/ac/bgu/cs/bp/bpjs/BPjs.java

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,12 @@
2323
*/
2424
package il.ac.bgu.cs.bp.bpjs;
2525

26-
import il.ac.bgu.cs.bp.bpjs.bprogramio.BPJSStubInputStream;
27-
import il.ac.bgu.cs.bp.bpjs.bprogramio.BPJSStubOutputStream;
2826
import il.ac.bgu.cs.bp.bpjs.bprogramio.BuiltInStubberFactory;
29-
import il.ac.bgu.cs.bp.bpjs.bprogramio.SerializationStubber;
3027
import il.ac.bgu.cs.bp.bpjs.bprogramio.SerializationStubberFactory;
28+
import il.ac.bgu.cs.bp.bpjs.bprogramio.log.BpLog;
29+
import il.ac.bgu.cs.bp.bpjs.bprogramio.log.PrintStreamBpLog;
3130
import il.ac.bgu.cs.bp.bpjs.internal.BPjsRhinoContextFactory;
3231
import il.ac.bgu.cs.bp.bpjs.internal.ExecutorServiceMaker;
33-
import il.ac.bgu.cs.bp.bpjs.model.BProgram;
34-
import java.io.IOException;
35-
import java.io.InputStream;
36-
import java.io.OutputStream;
3732
import java.util.HashSet;
3833
import java.util.Set;
3934
import java.util.function.Consumer;
@@ -62,16 +57,18 @@ public class BPjs {
6257
private static boolean logDuringVerification = false;
6358

6459
private static final Set<SerializationStubberFactory> STUBBER_FACTORIES = new HashSet<>();
65-
60+
61+
private static BpLog MAIN_LOGGER;
62+
6663
static {
67-
ContextFactory.initGlobal( new BPjsRhinoContextFactory()) ;
68-
try (Context cx = enterRhinoContext()) {
64+
ContextFactory.initGlobal(new BPjsRhinoContextFactory());
65+
try ( Context cx = enterRhinoContext() ) {
6966
ImporterTopLevel importer = new ImporterTopLevel(cx);
7067
BPJS_SCOPE = cx.initStandardObjects(importer, true); // create and seal
7168
// NOTE: global extensions to BPjs scopes would go here, if we decide to create them.
7269
}
7370
RhinoException.setStackStyle(StackStyle.V8);
74-
registerStubberFactory(new BuiltInStubberFactory() );
71+
registerStubberFactory(new BuiltInStubberFactory());
7572
}
7673

7774
/**
@@ -193,4 +190,22 @@ public static String getVersion(){
193190
return mainPackage != null ? mainPackage.getImplementationVersion() : null;
194191
}
195192

193+
public static BpLog log() {
194+
if ( MAIN_LOGGER==null ) {
195+
MAIN_LOGGER = new PrintStreamBpLog();
196+
}
197+
return MAIN_LOGGER;
198+
}
199+
200+
/**
201+
* Sets the global logger for BPjs.
202+
* @param <L> The exact type of the logger, fo fluent API calls.
203+
* @param aBpLogger The new logger to use
204+
* @return The new logger that is being used (for fluent API etc).
205+
*/
206+
public static <L extends BpLog> L setLogger(L aBpLogger) {
207+
BPjs.MAIN_LOGGER = aBpLogger;
208+
return aBpLogger;
209+
}
210+
196211
}

src/main/java/il/ac/bgu/cs/bp/bpjs/analysis/DfsBProgramVerifier.java

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,11 @@
2727
import il.ac.bgu.cs.bp.bpjs.analysis.violations.JsErrorViolation;
2828
import il.ac.bgu.cs.bp.bpjs.analysis.violations.Violation;
2929
import il.ac.bgu.cs.bp.bpjs.exceptions.BPjsRuntimeException;
30-
import il.ac.bgu.cs.bp.bpjs.exceptions.BPjsSyncOutsideBThreadException;
3130

3231
import java.util.ArrayList;
3332
import java.util.List;
3433

35-
import il.ac.bgu.cs.bp.bpjs.execution.jsproxy.BpLog;
34+
import il.ac.bgu.cs.bp.bpjs.bprogramio.log.BpLog;
3635
import il.ac.bgu.cs.bp.bpjs.model.BProgram;
3736
import il.ac.bgu.cs.bp.bpjs.model.BEvent;
3837
import il.ac.bgu.cs.bp.bpjs.model.BProgramSyncSnapshot;
@@ -171,7 +170,7 @@ public VerificationResult verify(BProgram aBp) throws Exception {
171170
inspections.addAll( ExecutionTraceInspections.DEFAULT_SET );
172171
}
173172

174-
ExecutorService execSvc = BPjs.getExecutorServiceMaker().makeWithName("DfsBProgramRunner-" + INSTANCE_COUNTER.incrementAndGet());
173+
ExecutorService execSvc = BPjs.getExecutorServiceMaker().borrowWithName("DfsBProgramRunner-" + INSTANCE_COUNTER.incrementAndGet());
175174

176175
BpLog.LogLevel prevLevel = currentBProgram.getLogLevel();
177176
if ( ! BPjs.isLogDuringVerification() ) {
@@ -196,7 +195,7 @@ public VerificationResult verify(BProgram aBp) throws Exception {
196195

197196
} finally {
198197
listener.done(this);
199-
execSvc.shutdown();
198+
BPjs.getExecutorServiceMaker().returnService(execSvc);
200199
if ( ! BPjs.isLogDuringVerification() ) {
201200
currentBProgram.setLogLevel(prevLevel);
202201
}
@@ -340,24 +339,24 @@ public BProgram getCurrentBProgram() {
340339
}
341340

342341
void printStatus(long iteration, List<DfsTraversalNode> path) {
343-
System.out.println("Iteration " + iteration);
344-
System.out.println(" visited: " + visited.getVisitedStateCount());
345-
path.forEach(n -> System.out.println(" " + n.getLastEvent()));
342+
BPjs.log().fine("Iteration " + iteration);
343+
BPjs.log().fine(" visited: " + visited.getVisitedStateCount());
344+
path.forEach(n -> BPjs.log().fine(" " + n.getLastEvent()));
346345
}
347346

348347
private Violation inspectCurrentTrace() {
349348
Set<Violation> res = inspections.stream()
350349
.map(v->v.inspectTrace(trace))
351350
.filter(o->o.isPresent()).map(Optional::get)
352351
.collect(toSet());
353-
if ( res.size() > 0 ) {
352+
if ( !res.isEmpty() ) {
354353
for ( Violation v : res ) {
355354
if ( ! listener.violationFound(v, this) ) {
356355
return v;
357356
}
358357
}
359358
if (isDebugMode()) {
360-
System.out.println("-pop! (violation)-");
359+
BPjs.log().fine("-pop! (violation)-");
361360
}
362361
pop();
363362
}
@@ -368,7 +367,7 @@ private void push(DfsTraversalNode n) {
368367
visited.store(n.getSystemState());
369368
currentPath.add(n);
370369
if (isDebugMode()) {
371-
System.out.println("-visiting: " + n);
370+
BPjs.log().fine("-visiting: " + n);
372371
}
373372
if ( trace.getStateCount() == 0 ) {
374373
trace.push( n.getSystemState() );
@@ -381,7 +380,7 @@ private DfsTraversalNode pop() {
381380
DfsTraversalNode popped = currentPath.remove(currentPath.size() - 1);
382381
trace.pop();
383382
if (isDebugMode()) {
384-
System.out.println("-pop!-");
383+
BPjs.log().fine("-pop!-");
385384
}
386385
return popped;
387386
}

src/main/java/il/ac/bgu/cs/bp/bpjs/bprogramio/BPJSStubOutputStream.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
*/
4343
public class BPJSStubOutputStream extends ScriptableOutputStream {
4444

45-
private Map<Class, SerializationStubber> stubbers = new HashMap<>();
45+
private final Map<Class, SerializationStubber> stubbers = new HashMap<>();
4646

4747
/**
4848
* Constructor
@@ -55,7 +55,7 @@ public BPJSStubOutputStream(OutputStream out, Set<SerializationStubber> someStub
5555
for ( var stb : someStubbers ) {
5656
for ( var clz : stb.getClasses() ) {
5757
if ( stubbers.containsKey(clz) ) {
58-
System.err.println("Warning: stubber " + stb.getId() + " overrides stubber for class " + clz.getCanonicalName() + ", previously set by " + stubbers.get(clz).getId() );
58+
BPjs.log().warn("Stubber " + stb.getId() + " overrides stubber for class " + clz.getCanonicalName() + ", previously set by " + stubbers.get(clz).getId() );
5959
}
6060
stubbers.put(clz, stb);
6161
}

0 commit comments

Comments
 (0)