Skip to content

Commit f5885a4

Browse files
committed
Make install path more flexible
1 parent a2c19cd commit f5885a4

File tree

18 files changed

+211
-94
lines changed

18 files changed

+211
-94
lines changed

pom.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
<dependency>
4848
<groupId>io.github.classgraph</groupId>
4949
<artifactId>classgraph</artifactId>
50-
<version>4.8.4</version>
50+
<version>4.8.90</version>
5151
</dependency>
5252
<dependency>
5353
<groupId>ch.qos.logback</groupId>
@@ -71,7 +71,7 @@
7171
<version>2.3.1</version>
7272
<configuration>
7373
<encoding>ISO-8859-1</encoding>
74-
<compilerVersion>1.6</compilerVersion>
74+
<compilerVersion>1.8</compilerVersion>
7575
</configuration>
7676
</plugin>
7777
</plugins>

tern-studio-agent/pom.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
<groupId>org.apache.maven.plugins</groupId>
2525
<artifactId>maven-compiler-plugin</artifactId>
2626
<configuration>
27-
<source>1.6</source>
28-
<target>1.6</target>
27+
<source>1.8</source>
28+
<target>1.8</target>
2929
</configuration>
3030
<!-- configuration>
3131
<source>9</source>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package org.ternlang.studio.agent.local;
2+
3+
public class ScriptLauncher {
4+
5+
public static void main(String[] list) throws Exception {
6+
LocalProcess.launch(
7+
"--cp=C:\\Work\\development\\tern-lang\\tern-demo\\demo\\misc\\src",
8+
"--s=text_test2.tern",
9+
"--v=true",
10+
"foo",
11+
"blah");
12+
}
13+
}

tern-studio-build/pom.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
<version>1.4.6</version>
1111
</parent>
1212
<properties>
13-
<maven.compiler.source>1.6</maven.compiler.source>
14-
<maven.compiler.target>1.6</maven.compiler.target>
13+
<maven.compiler.source>1.8</maven.compiler.source>
14+
<maven.compiler.target>1.8</maven.compiler.target>
1515
<project.build.sourceEncoding>ISO-8859-1</project.build.sourceEncoding>
1616
</properties>
1717
<dependencies>

tern-studio-core/pom.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
<version>1.4.6</version>
1111
</parent>
1212
<properties>
13-
<maven.compiler.source>1.6</maven.compiler.source>
14-
<maven.compiler.target>1.6</maven.compiler.target>
13+
<maven.compiler.source>1.8</maven.compiler.source>
14+
<maven.compiler.target>1.8</maven.compiler.target>
1515
<project.build.sourceEncoding>ISO-8859-1</project.build.sourceEncoding>
1616
</properties>
1717
<dependencies>

tern-studio-core/src/main/java/org/ternlang/studio/core/StudioOption.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ public enum StudioOption implements CommandOption {
1818
AGENT_POOL("n", "agent-pool", "Number of agents in pool", "\\d+", Integer.class, 4),
1919
PORT("p", "port", "Port for HTTP connections", "\\d+", Integer.class, 0),
2020
MODE("m", "mode", "Mode to start on", "(DEVELOP|DEBUG)", ProjectMode.class, ProjectMode.DEVELOP),
21-
DIRECTORY("d", "directory", "Directory used for sources", ".*", File.class, "${user.home}/work"),
21+
DIRECTORY("d", "directory", "Directory used for sources", ".*", File.class, HomeDirectory.getPath("work")),
2222
LOG_LEVEL("l", "log-level", "Level of logging", "(TRACE|DEBUG|INFO)", String.class, LogLevel.INFO),
23-
LOG("f", "log-file", "Log file to use", ".+", File.class, "${user.home}/" + HomeDirectory.HOME_DIRECTORY + "/log/ternd.log"),
23+
LOG("f", "log-file", "Log file to use", ".+", File.class, HomeDirectory.getPath("log/ternd.log")),
2424
SCRIPT("s", "script", "Script to launch", ".*.tern", Path.class),
2525
SERVER_ONLY("o", "server-only", "Launch server only", "(true|false)", Boolean.class, false),
2626
CLIENT_DEBUG("i", "client-debug", "Enable client debugger", "(true|false)", String.class, false); // firebug

tern-studio-core/src/main/java/org/ternlang/studio/core/StudioStartListener.java

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.ternlang.studio.core;
22

3+
import java.io.File;
34
import java.net.InetSocketAddress;
45

56
import org.simpleframework.module.annotation.Component;
@@ -9,6 +10,7 @@
910
import org.ternlang.studio.common.ProgressManager;
1011

1112
import lombok.extern.slf4j.Slf4j;
13+
import org.ternlang.studio.project.HomeDirectory;
1214

1315
@Slf4j
1416
@Component

tern-studio-core/src/main/java/org/ternlang/studio/core/splash/SplashScreen.java

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import java.awt.Toolkit;
77
import java.awt.event.WindowEvent;
88
import java.awt.image.BufferedImage;
9+
import java.io.File;
910
import java.io.InputStream;
1011
import java.net.URL;
1112
import java.util.concurrent.ArrayBlockingQueue;
@@ -29,6 +30,7 @@
2930
import org.simpleframework.module.common.ClassPathReader;
3031
import org.simpleframework.module.common.ThreadBuilder;
3132
import org.ternlang.studio.common.ProgressManager;
33+
import org.ternlang.studio.project.HomeDirectory;
3234
import org.ternlang.ui.WindowIcon;
3335
import org.ternlang.ui.WindowIconLoader;
3436

tern-studio-core/src/main/java/org/ternlang/studio/core/terminal/TerminalProcess.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public void onTerminalReady() {
7070
}
7171

7272
private void initializeProcess() throws Exception {
73-
String userHome = System.getProperty("user.home");
73+
File installPath = HomeDirectory.getRootPath();
7474
File dataDir = HomeDirectory.getPath("terminalfx");
7575
String startPath = directory.getCanonicalPath();
7676

@@ -87,7 +87,7 @@ private void initializeProcess() throws Exception {
8787

8888
System.setProperty("PTY_LIB_FOLDER", dataDir.toPath().resolve("libpty").toString());
8989

90-
this.process = PtyProcess.exec(termCommand, envs, userHome);
90+
this.process = PtyProcess.exec(termCommand, envs, installPath.getCanonicalPath());
9191

9292
process.setWinSize(new WinSize(columns, rows));
9393
this.inputReader = new BufferedReader(new InputStreamReader(process.getInputStream()));

tern-studio-core/src/main/java/org/ternlang/studio/core/terminal/TerminalService.java

+8-8
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
import java.io.File;
44
import java.util.Map;
55

6+
import com.fasterxml.jackson.core.type.TypeReference;
7+
import com.fasterxml.jackson.databind.ObjectMapper;
8+
69
import org.simpleframework.http.Path;
710
import org.simpleframework.http.Request;
811
import org.simpleframework.http.socket.Frame;
@@ -14,11 +17,8 @@
1417
import org.simpleframework.http.socket.service.Service;
1518
import org.simpleframework.module.annotation.Component;
1619
import org.simpleframework.resource.annotation.Subscribe;
17-
import org.ternlang.studio.project.Project;
18-
import org.ternlang.studio.project.Workspace;
19-
20-
import com.fasterxml.jackson.core.type.TypeReference;
21-
import com.fasterxml.jackson.databind.ObjectMapper;
20+
import org.ternlang.studio.common.FileDirectory;
21+
import org.ternlang.studio.common.FileDirectorySource;
2222

2323
import lombok.extern.slf4j.Slf4j;
2424

@@ -27,10 +27,10 @@
2727
@Subscribe("/session/.*")
2828
public class TerminalService implements Service {
2929

30-
private final Workspace workspace;
30+
private final FileDirectorySource workspace;
3131
private final ObjectMapper mapper;
3232

33-
public TerminalService(Workspace workspace) {
33+
public TerminalService(FileDirectorySource workspace) {
3434
this.mapper = new ObjectMapper();
3535
this.workspace = workspace;
3636
}
@@ -40,7 +40,7 @@ public void connect(Session session) {
4040
FrameChannel channel = session.getChannel();
4141
Request request = session.getRequest();
4242
Path path = request.getPath();
43-
Project project = workspace.createProject(path);
43+
FileDirectory project = workspace.getByPath(path);
4444
String[] segments = path.getSegments();
4545
File root = project.getBasePath();
4646
String suffix = "/";

tern-studio-project/src/main/java/org/ternlang/studio/project/ArchiveBuilder.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ private void extractRuntime(File destDir) throws Exception{
176176
String pattern = path.getPattern();
177177
Iterator<ClassNode> resources = project.getWorkspace()
178178
.getClassPath()
179-
.getTypes()
179+
.findTypes()
180180
.stream()
181181
.filter(info -> info.getName().matches(pattern))
182182
.iterator();
Original file line numberDiff line numberDiff line change
@@ -1,102 +1,101 @@
11
package org.ternlang.studio.project;
22

3+
import org.simpleframework.http.Path;
4+
import org.ternlang.studio.common.FileDirectory;
5+
36
import java.io.File;
47
import java.util.ArrayList;
58
import java.util.Collections;
69
import java.util.List;
710

8-
import org.simpleframework.http.Path;
9-
import org.ternlang.studio.common.FileDirectory;
10-
1111
public class FileSystem {
1212

1313
private final FileDirectory directory;
14-
14+
1515
public FileSystem(FileDirectory directory) {
1616
this.directory = directory;
1717
}
18-
18+
1919
public File getFile(Path path) {
2020
String projectPath = path.getPath(2); // /<project-name>/<project-path> or /default/blah.tern
2121
File rootPath = directory.getBasePath();
2222
String realPath = projectPath.replace('/', File.separatorChar);
2323
return new File(rootPath, realPath);
2424
}
25-
25+
2626
public File getFile(String path) {
2727
File rootPath = directory.getBasePath();
2828
String realPath = path.replace('/', File.separatorChar);
2929
return new File(rootPath, realPath);
3030
}
31-
31+
3232
public void writeAsString(String path, String resource) throws Exception {
3333
byte[] octets = resource.getBytes("UTF-8");
3434
writeAsByteArray(path, octets);
3535
}
36-
36+
3737
public void writeAsByteArray(String path, byte[] resource) throws Exception {
3838
File rootPath = directory.getBasePath();
3939
FilePersister.writeAsByteArray(rootPath, path, resource);
4040
}
41-
41+
4242
public String readAsString(String path) throws Exception {
4343
File rootPath = directory.getBasePath();
4444
return FilePersister.readAsString(rootPath, path);
4545
}
46-
46+
4747
public byte[] readAsByteArray(String path) throws Exception {
4848
File rootPath = directory.getBasePath();
4949
return FilePersister.readAsByteArray(rootPath, path);
5050
}
51-
51+
5252
public FileData readFile(Path path) throws Exception {
5353
String projectPath = path.getPath(2); // /<project-name>/<project-path> or /default/blah.tern
5454
return readFile(projectPath);
5555
}
56-
56+
5757
public FileData readFile(String path) throws Exception {
5858
long time = System.currentTimeMillis();
5959
File rootPath = directory.getBasePath();
6060
String realPath = path.replace('/', File.separatorChar);
6161
File projectFile = new File(rootPath, realPath);
62-
63-
if(projectFile.exists()) {
62+
63+
if (projectFile.exists()) {
6464
String canonicalPath = projectFile.getCanonicalPath();
65-
66-
if(canonicalPath.endsWith(realPath)) {
65+
66+
if (canonicalPath.endsWith(realPath)) {
6767
return new FileData(this, path, projectFile, time);
6868
}
69-
}
69+
}
7070
return new FileData(this, path, null, time);
7171
}
72-
72+
7373
public FileData readFile(File file) throws Exception {
7474
long time = System.currentTimeMillis();
7575
File rootPath = directory.getBasePath();
7676
String basePath = rootPath.getCanonicalPath();
7777
String absolutePath = file.getCanonicalPath();
7878
String relativePath = absolutePath.replace(basePath, "").replace(File.separatorChar, '/');
79-
80-
if(file.exists()) {
79+
80+
if (file.exists()) {
8181
return new FileData(this, relativePath, file, time);
82-
}
82+
}
8383
return new FileData(this, relativePath, null, time);
8484
}
85-
85+
8686
public List<FileData> readFiles(File file) throws Exception {
8787
File[] list = file.listFiles();
88-
89-
if(list != null) {
88+
89+
if (list != null) {
9090
List<FileData> result = new ArrayList<FileData>(list.length);
91-
92-
for(int i = 0; i < list.length; i++) {
91+
92+
for (int i = 0; i < list.length; i++) {
9393
FileData fileData = readFile(list[i]);
9494
result.add(fileData);
9595
}
9696
return Collections.unmodifiableList(result);
97-
}
97+
}
9898
return Collections.emptyList();
99-
99+
100100
}
101-
102101
}

tern-studio-project/src/main/java/org/ternlang/studio/project/HomeDirectory.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package org.ternlang.studio.project;
22

3+
import org.ternlang.studio.project.config.OperatingSystem;
4+
35
import java.io.File;
46

57
public class HomeDirectory {
@@ -8,8 +10,8 @@ public class HomeDirectory {
810

911
public static File getRootPath() {
1012
try {
11-
String userDir = System.getProperty("user.home");
12-
File homeDir = new File(userDir, HOME_DIRECTORY);
13+
File installDir = OperatingSystem.resolveSystem().getInstallDirectory();
14+
File homeDir = new File(installDir, HOME_DIRECTORY);
1315

1416
if(!homeDir.exists()) {
1517
homeDir.mkdirs();

0 commit comments

Comments
 (0)