Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[automation] Corrected issue where scripts were not starting when OH restarted #1367

Merged
merged 3 commits into from
Feb 17, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.file.Path;
import java.nio.file.Paths;
Expand Down Expand Up @@ -155,7 +156,7 @@ private void removeFile(URL url) {
}

private synchronized void importFile(URL url) {
String fileName = getFileName(url);
String fileName = url.getFile();
if (loaded.contains(url)) {
this.removeFile(url); // if already loaded, remove first
}
Expand Down Expand Up @@ -184,22 +185,12 @@ private synchronized void importFile(URL url) {
}
} else {
enqueueUrl(url, scriptType);

logger.info("ScriptEngine for {} not available", scriptType);
}
}
}
}

private String getFileName(URL url) {
String fileName = url.getFile();
String parentPath = FILE_DIRECTORY.replace('\\', '/');
if (fileName.contains(parentPath)) {
fileName = fileName.substring(fileName.lastIndexOf(parentPath) + parentPath.length() + 1);
}
return fileName;
}

private void enqueueUrl(URL url, String scriptType) {
synchronized (urlsByScriptExtension) {
Set<URL> set = urlsByScriptExtension.get(scriptType);
Expand Down Expand Up @@ -252,16 +243,26 @@ private void checkFiles() {
SortedSet<URL> reimportUrls = new TreeSet<URL>(new Comparator<URL>() {
@Override
public int compare(URL o1, URL o2) {
Path path1 = Paths.get(o1.getPath());
Path path2 = Paths.get(o2.getPath());
String name1 = path1.getFileName().toString();
String name2 = path2.getFileName().toString();
int nameCompare = name1.compareToIgnoreCase(name2);
if (nameCompare != 0) {
return nameCompare;
} else {
int pathCompare = path1.getParent().toString().compareToIgnoreCase(path2.getParent().toString());
return pathCompare;
try {
Path path1 = Paths.get(o1.toURI());
String name1 = path1.getFileName().toString();
logger.trace("o1 [{}], path1 [{}], name1 [{}]", o1, path1, name1);

Path path2 = Paths.get(o2.toURI());
String name2 = path2.getFileName().toString();
logger.trace("o2 [{}], path2 [{}], name2 [{}]", o2, path2, name2);

int nameCompare = name1.compareToIgnoreCase(name2);
if (nameCompare != 0) {
return nameCompare;
} else {
int pathCompare = path1.getParent().toString()
.compareToIgnoreCase(path2.getParent().toString());
return pathCompare;
}
} catch (URISyntaxException e) {
logger.error("URI syntax exception", e);
return 0;
}
}
});
Expand Down