Skip to content

Commit 9cad2ca

Browse files
authored
Merge pull request #90 from ortus-boxlang/development
v1.0.0-Beta8
2 parents 3c69454 + 52f5612 commit 9cad2ca

Some content is hidden

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

51 files changed

+1240
-220
lines changed

gradle.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#Fri Jul 19 14:27:23 UTC 2024
1+
#Fri Jul 26 19:21:16 UTC 2024
22
antlrVersion=4.13.1
33
jdkVersion=21
4-
version=1.0.0-beta7
4+
version=1.0.0-beta8

src/main/java/ortus/boxlang/compiler/parser/BoxScriptLexerCustom.java

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,30 +48,39 @@ public boolean hasUnpoppedModes() {
4848

4949
/**
5050
* Get the unpopped modes on the Lexer's mode stack
51-
*
51+
*
5252
* @return list of unpopped modes
5353
*/
54-
public List<String> getUnpoppedModes() {
55-
List<String> results = new ArrayList<String>();
56-
results.add( modeNames[ _mode ] );
54+
public List<Integer> getUnpoppedModesInts() {
55+
List<Integer> results = new ArrayList<Integer>();
56+
results.add( _mode );
5757
for ( int mode : _modeStack.toArray() ) {
58-
results.add( modeNames[ mode ] );
58+
results.add( mode );
5959
}
6060
return results;
6161
}
6262

63+
/**
64+
* Get the unpopped modes on the Lexer's mode stack
65+
*
66+
* @return list of unpopped modes
67+
*/
68+
public List<String> getUnpoppedModes() {
69+
return getUnpoppedModesInts().stream().map( mode -> modeNames[ mode ] ).toList();
70+
}
71+
6372
/**
6473
* Check if the last mode was a specific mode
65-
*
74+
*
6675
* @param mode mode to check
67-
*
76+
*
6877
* @return true if the last mode was the specified mode
6978
*/
7079
public boolean lastModeWas( int mode ) {
7180
if ( !hasUnpoppedModes() ) {
7281
return false;
7382
}
74-
return _modeStack.peek() == mode;
83+
return getUnpoppedModesInts().get( 0 ) == mode;
7584
}
7685

7786
/**

src/main/java/ortus/boxlang/compiler/parser/BoxTemplateLexerCustom.java

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,24 @@ public boolean hasUnpoppedModes() {
5151
*
5252
* @return list of unpopped modes
5353
*/
54-
public List<String> getUnpoppedModes() {
55-
List<String> results = new ArrayList<String>();
56-
results.add( modeNames[ _mode ] );
54+
public List<Integer> getUnpoppedModesInts() {
55+
List<Integer> results = new ArrayList<Integer>();
56+
results.add( _mode );
5757
for ( int mode : _modeStack.toArray() ) {
58-
results.add( modeNames[ mode ] );
58+
results.add( mode );
5959
}
6060
return results;
6161
}
6262

63+
/**
64+
* Get the unpopped modes on the Lexer's mode stack
65+
*
66+
* @return list of unpopped modes
67+
*/
68+
public List<String> getUnpoppedModes() {
69+
return getUnpoppedModesInts().stream().map( mode -> modeNames[ mode ] ).toList();
70+
}
71+
6372
/**
6473
* Check if the last mode was a specific mode
6574
*
@@ -71,7 +80,7 @@ public boolean lastModeWas( int mode ) {
7180
if ( !hasUnpoppedModes() ) {
7281
return false;
7382
}
74-
return _modeStack.peek() == mode;
83+
return getUnpoppedModesInts().get( 0 ) == mode;
7584
}
7685

7786
/**

src/main/java/ortus/boxlang/compiler/parser/BoxTemplateParser.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,15 @@ private void validateParse( BoxTemplateLexerCustom lexer ) {
198198
}
199199
message += " on line " + position.getStart().getLine();
200200
issues.add( new Issue( message, position ) );
201+
} else if ( lexer.lastModeWas( BoxTemplateLexerCustom.COMMENT_MODE ) ) {
202+
String message = "Unclosed tag comment";
203+
Token outputStartToken = lexer.findPreviousToken( BoxTemplateLexerCustom.COMMENT_START );
204+
if ( outputStartToken != null ) {
205+
position = createOffsetPosition( outputStartToken.getLine(), outputStartToken.getCharPositionInLine(), outputStartToken.getLine(),
206+
outputStartToken.getCharPositionInLine() + outputStartToken.getText().length() );
207+
}
208+
message += " on line " + position.getStart().getLine();
209+
issues.add( new Issue( message, position ) );
201210
} else if ( lexer.lastModeWas( BoxTemplateLexerCustom.COMPONENT_MODE ) ) {
202211
String message = "Unclosed tag";
203212
Token startToken = lexer.findPreviousToken( BoxTemplateLexerCustom.COMPONENT_OPEN );

src/main/java/ortus/boxlang/compiler/parser/CFScriptLexerCustom.java

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,30 +54,39 @@ public boolean hasUnpoppedModes() {
5454

5555
/**
5656
* Get the unpopped modes on the Lexer's mode stack
57-
*
57+
*
5858
* @return list of unpopped modes
5959
*/
60-
public List<String> getUnpoppedModes() {
61-
List<String> results = new ArrayList<String>();
62-
results.add( modeNames[ _mode ] );
60+
public List<Integer> getUnpoppedModesInts() {
61+
List<Integer> results = new ArrayList<Integer>();
62+
results.add( _mode );
6363
for ( int mode : _modeStack.toArray() ) {
64-
results.add( modeNames[ mode ] );
64+
results.add( mode );
6565
}
6666
return results;
6767
}
6868

69+
/**
70+
* Get the unpopped modes on the Lexer's mode stack
71+
*
72+
* @return list of unpopped modes
73+
*/
74+
public List<String> getUnpoppedModes() {
75+
return getUnpoppedModesInts().stream().map( mode -> modeNames[ mode ] ).toList();
76+
}
77+
6978
/**
7079
* Check if the last mode was a specific mode
71-
*
80+
*
7281
* @param mode mode to check
73-
*
82+
*
7483
* @return true if the last mode was the specified mode
7584
*/
7685
public boolean lastModeWas( int mode ) {
7786
if ( !hasUnpoppedModes() ) {
7887
return false;
7988
}
80-
return _modeStack.peek() == mode;
89+
return getUnpoppedModesInts().get( 0 ) == mode;
8190
}
8291

8392
/**

src/main/java/ortus/boxlang/compiler/parser/CFTemplateLexerCustom.java

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,30 +49,39 @@ public boolean hasUnpoppedModes() {
4949

5050
/**
5151
* Get the unpopped modes on the Lexer's mode stack
52-
*
52+
*
5353
* @return list of unpopped modes
5454
*/
55-
public List<String> getUnpoppedModes() {
56-
List<String> results = new ArrayList<String>();
57-
results.add( modeNames[ _mode ] );
55+
public List<Integer> getUnpoppedModesInts() {
56+
List<Integer> results = new ArrayList<Integer>();
57+
results.add( _mode );
5858
for ( int mode : _modeStack.toArray() ) {
59-
results.add( modeNames[ mode ] );
59+
results.add( mode );
6060
}
6161
return results;
6262
}
6363

64+
/**
65+
* Get the unpopped modes on the Lexer's mode stack
66+
*
67+
* @return list of unpopped modes
68+
*/
69+
public List<String> getUnpoppedModes() {
70+
return getUnpoppedModesInts().stream().map( mode -> modeNames[ mode ] ).toList();
71+
}
72+
6473
/**
6574
* Check if the last mode was a specific mode
66-
*
75+
*
6776
* @param mode mode to check
68-
*
77+
*
6978
* @return true if the last mode was the specified mode
7079
*/
7180
public boolean lastModeWas( int mode ) {
7281
if ( !hasUnpoppedModes() ) {
7382
return false;
7483
}
75-
return _modeStack.peek() == mode;
84+
return getUnpoppedModesInts().get( 0 ) == mode;
7685
}
7786

7887
/**

src/main/java/ortus/boxlang/compiler/parser/CFTemplateParser.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,15 @@ private void validateParse( CFTemplateLexerCustom lexer ) {
213213
}
214214
message += " on line " + position.getStart().getLine();
215215
issues.add( new Issue( message, position ) );
216+
} else if ( lexer.lastModeWas( CFTemplateLexerCustom.COMMENT_MODE ) ) {
217+
String message = "Unclosed tag comment";
218+
Token outputStartToken = lexer.findPreviousToken( CFTemplateLexerCustom.COMMENT_START );
219+
if ( outputStartToken != null ) {
220+
position = createOffsetPosition( outputStartToken.getLine(), outputStartToken.getCharPositionInLine(), outputStartToken.getLine(),
221+
outputStartToken.getCharPositionInLine() + outputStartToken.getText().length() );
222+
}
223+
message += " on line " + position.getStart().getLine();
224+
issues.add( new Issue( message, position ) );
216225
} else if ( lexer.lastModeWas( CFTemplateLexerCustom.COMPONENT_MODE ) ) {
217226
String message = "Unclosed tag";
218227
Token startToken = lexer.findPreviousToken( CFTemplateLexerCustom.COMPONENT_OPEN );

src/main/java/ortus/boxlang/runtime/application/Session.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,11 +216,13 @@ public void shutdown( BaseApplicationListener listener ) {
216216
// Any buffer output in this context will be discarded
217217
listener.onSessionEnd(
218218
new ScriptingRequestBoxContext( BoxRuntime.getInstance().getRuntimeContext() ),
219-
new Object[] { sessionScope, listener.getApplication().getApplicationScope() }
219+
new Object[] { sessionScope != null ? sessionScope : Struct.of(), listener.getApplication().getApplicationScope() }
220220
);
221221

222222
// Clear the session scope
223-
this.sessionScope.clear();
223+
if ( this.sessionScope != null ) {
224+
this.sessionScope.clear();
225+
}
224226
this.sessionScope = null;
225227
}
226228

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/**
2+
* [BoxLang]
3+
*
4+
* Copyright [2023] [Ortus Solutions, Corp]
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the
7+
* License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS"
12+
* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language
13+
* governing permissions and limitations under the License.
14+
*/
15+
16+
package ortus.boxlang.runtime.bifs.global.io;
17+
18+
import ortus.boxlang.runtime.bifs.BIF;
19+
import ortus.boxlang.runtime.bifs.BoxBIF;
20+
import ortus.boxlang.runtime.context.IBoxContext;
21+
import ortus.boxlang.runtime.scopes.ArgumentsScope;
22+
import ortus.boxlang.runtime.scopes.Key;
23+
import ortus.boxlang.runtime.types.Argument;
24+
import ortus.boxlang.runtime.util.FileSystemUtil;
25+
26+
@BoxBIF
27+
public class ContractPath extends BIF {
28+
29+
/**
30+
* Constructor
31+
*/
32+
public ContractPath() {
33+
super();
34+
declaredArguments = new Argument[] {
35+
new Argument( true, "string", Key.path )
36+
};
37+
}
38+
39+
/**
40+
* Does the opposite of expandPath. Tries to match a given absolute path to mappings in the environment and will return a path that is contracted by the shortest matched mapping. If there are no matches, returns the absolute path it was given.
41+
*
42+
* @param context The context in which the BIF is being invoked.
43+
* @param arguments Argument scope for the BIF.
44+
*
45+
* @argument.path The absolute path to contract.
46+
*/
47+
public Object _invoke( IBoxContext context, ArgumentsScope arguments ) {
48+
String path = arguments.getAsString( Key.path );
49+
return FileSystemUtil.contractPath( context, path ).relativePath();
50+
}
51+
52+
}

src/main/java/ortus/boxlang/runtime/bifs/global/io/FileGetMimeType.java

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import ortus.boxlang.runtime.types.Argument;
2828
import ortus.boxlang.runtime.types.exceptions.BoxIOException;
2929
import ortus.boxlang.runtime.types.exceptions.BoxRuntimeException;
30+
import ortus.boxlang.runtime.util.FileSystemUtil;
3031

3132
@BoxBIF
3233

@@ -54,20 +55,31 @@ public FileGetMimeType() {
5455
* @argument.strict If true, throws an exception if the file does not exist or is empty. If false, returns "application/octet-stream" for non-existent or empty files.
5556
*/
5657
public Object _invoke( IBoxContext context, ArgumentsScope arguments ) {
57-
Path filePath = Path.of( arguments.getAsString( Key.file ) );
58+
String filePath = arguments.getAsString( Key.file );
5859
Boolean strict = arguments.getAsBoolean( Key.strict );
5960

60-
String mimeType = null;
61+
if ( !filePath.substring( 0, 4 ).equalsIgnoreCase( "http" ) ) {
62+
filePath = FileSystemUtil.expandPath( context, filePath ).absolutePath().toString();
63+
} else if ( strict ) {
64+
throw new BoxRuntimeException(
65+
"The file ["
66+
+ arguments.getAsString( Key.file )
67+
+ "] is a URL. To retrieve the mimetype of a URL set the strict argument to false."
68+
);
69+
}
70+
71+
String mimeType = null;
6172

6273
if ( strict ) {
74+
Path filePathObject = Path.of( filePath );
6375
try {
64-
if ( !Files.exists( filePath ) ) {
76+
if ( !Files.exists( filePathObject ) ) {
6577
throw new BoxRuntimeException(
6678
"The file ["
6779
+ arguments.getAsString( Key.file )
6880
+ "] does not exist. To retrieve the mimetype of a non-existent file set the strict argument to false."
6981
);
70-
} else if ( Files.size( filePath ) == 0 ) {
82+
} else if ( Files.size( filePathObject ) == 0 ) {
7183
throw new BoxRuntimeException(
7284
"The file ["
7385
+ arguments.getAsString( Key.file )
@@ -77,16 +89,11 @@ public Object _invoke( IBoxContext context, ArgumentsScope arguments ) {
7789
} catch ( IOException e ) {
7890
throw new BoxIOException( e );
7991
}
80-
8192
}
8293

83-
try {
84-
mimeType = Files.probeContentType( filePath );
85-
if ( mimeType == null ) {
86-
mimeType = "application/octet-stream";
87-
}
88-
} catch ( IOException e ) {
89-
throw new BoxIOException( e );
94+
mimeType = FileSystemUtil.getMimeType( filePath );
95+
if ( mimeType == null ) {
96+
mimeType = "application/octet-stream";
9097
}
9198

9299
return mimeType;

0 commit comments

Comments
 (0)