Skip to content

Commit

Permalink
[416] Improve textual import running process
Browse files Browse the repository at this point in the history
Bug: #416
Signed-off-by: Axel RICHARD <axel.richard@obeo.fr>
  • Loading branch information
AxelRICHARD committed Jun 18, 2024
1 parent 08dd6ec commit d7a6453
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 8 deletions.
5 changes: 3 additions & 2 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,9 @@ A reset of the database is needed.
- https://github.com/eclipse-syson/syson/issues/388[#388] [details] Add Transition source and target to Core properties in the Details view
- https://github.com/eclipse-syson/syson/issues/394[#394] [metamodel] All _redefines_ references have been implemented.
- https://github.com/eclipse-syson/syson/issues/416[#416] [import] Improve textual import running process.
End users don't have to copy _syside-cli.js_ near the _syson-application_ jar anymore.
_org.eclipse.syson.syside.path_ application option is not useful and has been removed.
By default, end users don't have to copy _syside-cli.js_ near the _syson-application_ jar anymore.
The embedded _syside-cli.js_ is copied in a system temp folder and executed from there (with node).
But, if you encounter execution rights problem, you can still copy _syside-cli.js_ in a place where you have the appropriate rights and use the _org.eclipse.syson.syside.path_ application option.

=== New features

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,16 @@ logging.level.org.eclipse.sirius.web.diagrams.layout.LayoutService=OFF
#
##################################################
org.eclipse.syson.customImages.pattern=classpath*:/sysonCustomImages/**

##################################################
#
# SYSIDE-CLI PATH (NEEDED FOR TEXTUAL IMPORT)
# By default, the embedded syside-cli.js is copied
# in a system temp folder and executed from there
# (with node).
# If you encountered acess rights problems, you
# can provide your own syside-cli.js located in a
# place where you have the appropriate execution
# rights.
##################################################
#org.eclipse.syson.syside.path=add_path_to_your_syside-cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.core.io.support.ResourcePatternResolver;
Expand All @@ -41,17 +42,27 @@ public class SysmlToAst {

private final Logger logger = LoggerFactory.getLogger(SysmlToAst.class);

private final String cliPath;

public SysmlToAst(@Value("${org.eclipse.syson.syside.path:}") String cliPath) {
this.cliPath = cliPath;
}

public InputStream convert(InputStream input, String fileExtension) {
InputStream output = null;

try {
Path sysmlInputPath = this.createTempFile(input, "syson", fileExtension);

PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
Resource resource = resolver.getResource(ResourcePatternResolver.CLASSPATH_URL_PREFIX + "syside-cli.js");
InputStream sysIdeInputStream = resource.getInputStream();

Path sysIdeInputPath = this.createTempFile(sysIdeInputStream, "syside-cli", "js");
Path sysIdeInputPath = null;
if (this.cliPath != null) {
sysIdeInputPath = Path.of(this.cliPath);
} else {
PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
Resource resource = resolver.getResource(ResourcePatternResolver.CLASSPATH_URL_PREFIX + "syside-cli.js");
InputStream sysIdeInputStream = resource.getInputStream();
sysIdeInputPath = this.createTempFile(sysIdeInputStream, "syside-cli", "js");
}

this.logger.info("Call syside application : node " + sysIdeInputPath.toString() + " dump " + sysmlInputPath.toString());
String[] args = { "node", sysIdeInputPath.toString(), "dump", sysmlInputPath.toString() };
Expand Down Expand Up @@ -82,7 +93,9 @@ public InputStream convert(InputStream input, String fileExtension) {
output = new ByteArrayInputStream(builder.toString().getBytes());

sysmlInputPath.toFile().delete();
sysIdeInputPath.toFile().delete();
if (this.cliPath == null) {
sysIdeInputPath.toFile().delete();
}

} catch (IOException e) {
this.logger.error(e.getMessage());
Expand Down

0 comments on commit d7a6453

Please sign in to comment.