Skip to content

Commit

Permalink
Merge pull request #560 from jolie/bug/getServiceDirectory
Browse files Browse the repository at this point in the history
getServiceDirectory does not return the proper service path
  • Loading branch information
fmontesi authored and mwallnoefer committed Jan 30, 2025
1 parent 7a78a17 commit 2afe6b6
Show file tree
Hide file tree
Showing 12 changed files with 268 additions and 193 deletions.
8 changes: 8 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
"-p",
"${workspaceFolder}/packages",
"${input:trace}",
"--responseTimeout",
"300000",
"${input:programName}"
],
"windows": {
Expand All @@ -27,6 +29,8 @@
"-p",
"${workspaceFolder}\\packages",
"${input:trace}",
"--responseTimeout",
"300000",
"${input:programName}"
]
}
Expand Down Expand Up @@ -74,6 +78,8 @@
"-p",
"${workspaceFolder}/packages",
"${input:trace}",
"--responseTimeout",
"300000",
"test.ol",
"${input:testName}"
],
Expand All @@ -86,6 +92,8 @@
"-p",
"${workspaceFolder}\\packages",
"${input:trace}",
"--responseTimeout",
"300000",
"test.ol",
"${input:programName}"
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ public InternalJolieServiceLoader( Expression channelDest, Interpreter currInter
new CommandLineParser( newArgs.toArray( new String[] {} ), currInterpreter.getClassLoader(), true );
interpreter = new Interpreter(
commandLineParser.getInterpreterConfiguration(),
currInterpreter.programDirectory(),
currInterpreter,
program );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ public JolieServiceLoader( Expression channelDest, Interpreter currInterpreter,
super( channelDest );
final String[] ss = SERVICE_PATH_SPLIT_PATTERN.split( servicePath );
final String[] options = currInterpreter.optionArgs();

final String[] newArgs = new String[ 2 + options.length + ss.length ];
newArgs[ 0 ] = "-i";
newArgs[ 1 ] = currInterpreter.programDirectory().getAbsolutePath();
Expand All @@ -60,36 +59,11 @@ public JolieServiceLoader( Expression channelDest, Interpreter currInterpreter,

Interpreter.Configuration cmdConfig = commandLineParser.getInterpreterConfiguration();
Interpreter.Configuration config = Interpreter.Configuration.create(
cmdConfig.connectionsLimit(),
cmdConfig.cellId(),
cmdConfig.correlationAlgorithm(),
cmdConfig.includePaths(),
cmdConfig.optionArgs(),
cmdConfig.libUrls(),
cmdConfig.inputStream(),
cmdConfig.charset(),
cmdConfig.programFilepath(),
cmdConfig.arguments(),
cmdConfig.constants(),
cmdConfig.jolieClassLoader(),
cmdConfig.isProgramCompiled(),
cmdConfig.typeCheck(),
cmdConfig.tracer(),
cmdConfig.tracerLevel(),
cmdConfig.tracerMode(),
cmdConfig.check(),
cmdConfig.printStackTraces(),
cmdConfig.responseTimeout(),
cmdConfig.logLevel(),
cmdConfig.programDirectory(),
cmdConfig.packagePaths(),
// difference:
serviceName.orElse( cmdConfig.executionTarget() ),
Optional.empty() );
cmdConfig,
serviceName.orElse( cmdConfig.executionTarget() ) );

interpreter = new Interpreter(
config,
currInterpreter.programDirectory(),
params,
Optional.of( currInterpreter.logPrefix() ) );
}
Expand All @@ -100,7 +74,7 @@ public JolieServiceLoader( String code, Expression channelDest, Interpreter curr
Interpreter.Configuration configuration =
Interpreter.Configuration.create( currInterpreter.configuration(), new File( "#native_code_" +
SERVICE_LOADER_COUNTER.getAndIncrement() ), new ByteArrayInputStream( code.getBytes() ) );
interpreter = new Interpreter( configuration, currInterpreter.programDirectory(),
interpreter = new Interpreter( configuration,
Optional.empty(), Optional.of( currInterpreter.logPrefix() ) );
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
import jolie.runtime.ValueVector;
import jolie.runtime.embedding.RequestResponse;
import jolie.runtime.typing.Type;
import jolie.util.UriUtils;

/**
*
Expand Down Expand Up @@ -452,7 +453,7 @@ public String getServiceDirectory()
throws FaultException {
String dir = null;
try {
dir = interpreter().programDirectory().getCanonicalPath();
dir = UriUtils.normalizeWindowsPath( interpreter().programDirectory().getCanonicalPath() );
} catch( IOException e ) {
throw new FaultException( "IOException", e );
}
Expand Down
2 changes: 1 addition & 1 deletion jolie-cli/src/main/java/jolie/Jolie.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public static void main( String[] args ) {
JsUtils.parseJsonIntoValue( fileReader, params.get(), true );
}
}
final Interpreter interpreter = new Interpreter( config, null, params, Optional.empty() );
final Interpreter interpreter = new Interpreter( config, params, Optional.empty() );
Thread.currentThread().setContextClassLoader( interpreter.getClassLoader() );
Runtime.getRuntime().addShutdownHook( new Thread( () -> interpreter.exit( TERMINATION_TIMEOUT ) ) );
interpreter.run();
Expand Down
18 changes: 1 addition & 17 deletions jolie-cli/src/main/java/jolie/cli/CommandLineParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@
import java.util.stream.Collectors;
import jolie.Interpreter;
import jolie.JolieClassLoader;
import jolie.jap.JapURLConnection;
import jolie.lang.Constants;
import jolie.lang.parse.Scanner;
import jolie.runtime.correlation.CorrelationEngine;
Expand Down Expand Up @@ -90,7 +89,6 @@ public class CommandLineParser implements AutoCloseable {
private final Level logLevel;
private final String executionTarget;
private final Optional< Path > parametersFilepath;
private File programDirectory = null;
private int cellId = 0;

/**
Expand Down Expand Up @@ -483,7 +481,6 @@ public CommandLineParser( String[] args, ClassLoader parentClassLoader, Argument
Collection< String > japOptions = parseJapManifestForOptions( manifest );
argsList.addAll( i + 1, japOptions );
japUrl = japFilename + "!";
programDirectory = new File( japFilename ).getParentFile();
}
break;
}
Expand Down Expand Up @@ -691,7 +688,6 @@ private GetOLStreamResult getOLStream( boolean ignoreFile, String olFilepath, De
if( f.exists() ) {
result.stream = new FileInputStream( f );
result.source = f.toURI().getSchemeSpecificPart();
programDirectory = f.getParentFile();
} else {
for( String includePath : includePaths ) {
if( includePath.startsWith( "jap:" ) ) {
Expand All @@ -712,7 +708,6 @@ private GetOLStreamResult getOLStream( boolean ignoreFile, String olFilepath, De
f = f.getAbsoluteFile();
result.stream = new FileInputStream( f );
result.source = f.toURI().getSchemeSpecificPart();
programDirectory = f.getParentFile();
break;
}
}
Expand All @@ -733,17 +728,6 @@ private GetOLStreamResult getOLStream( boolean ignoreFile, String olFilepath, De
result.source = olURL.toString();
}
}
if( programDirectory == null && olURL != null && olURL.getPath() != null ) {
// Try to extract the parent directory of the JAP/JAR library file
try {
File urlFile = new File( JapURLConnection.NESTING_SEPARATION_PATTERN
.split( new URI( olURL.getPath() ).getSchemeSpecificPart() )[ 0 ] ).getAbsoluteFile();
if( urlFile.exists() ) {
programDirectory = urlFile.getParentFile();
}
} catch( URISyntaxException e ) {
}
}
}
}
if( result.stream != null ) {
Expand Down Expand Up @@ -815,6 +799,7 @@ public Interpreter.Configuration getInterpreterConfiguration() throws CommandLin
programStream,
charset,
programFilepath,
programFilepath.getParentFile(),
arguments,
constants,
jolieClassLoader,
Expand All @@ -827,7 +812,6 @@ public Interpreter.Configuration getInterpreterConfiguration() throws CommandLin
printStackTraces,
responseTimeout,
logLevel,
programDirectory,
packagePaths,
executionTarget,
parametersFilepath );
Expand Down
Loading

0 comments on commit 2afe6b6

Please sign in to comment.