Skip to content

Commit 20294f0

Browse files
committed
fixed bug where addons wouldn't redeploy in some cases
1 parent a720a63 commit 20294f0

File tree

4 files changed

+38
-7
lines changed

4 files changed

+38
-7
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ WebCTRL is a trademark of Automated Logic Corporation. Any other trademarks ment
66

77
This WebCTRL add-on [(download link)](https://github.com/automatic-controls/addon-dev-refresh/releases/latest/download/AddonDevRefresher.addon) streamlines the development of other add-ons. Every 3 seconds, it checks for `*.update` files in the `./addons` folder of your WebCTRL server. If an `.update` file is found, it is renamed with extension `.addon`, replacing any existing `.addon` file. Add-ons are automatically disabled and re-enabled during updates.
88

9-
It is recommended to use this add-on in your local development WebCTRL server. Then have your build script copy in-development add-ons to the `./addons` folder with an `.update` extension whenever your `deploy` task runs.
9+
It is recommended to use this add-on in your local development WebCTRL server. Then have your build script copy in-development add-ons to the `./addons` folder with an `.update` extension whenever your `deploy` task runs. To detect if deployment is successful, your build script should wait for the `.update` file to disappear.
1010

1111
See [./deploy.bat](./deploy.bat) for an extension you can use with <https://github.com/automatic-controls/addon-dev-script>. If your WebCTRL server requires signed add-ons, download [*ACES.cer*](https://github.com/automatic-controls/addon-dev-script/blob/main/ACES.cer?raw=true) for authentication.

root/info.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<extension version="1">
22
<name>AddonDevRefresher</name>
33
<description>Streamlines add-on development by automatically removing and adding add-ons from a local WebCTRL server as they are developed.</description>
4-
<version>1.0.0</version>
4+
<version>1.0.1</version>
55
<vendor>Automatic Controls Equipment Systems, Inc.</vendor>
6-
</extension>
6+
</extension>

src/aces/webctrl/dev/HelperAPI.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
Contributors: Cameron Vogt (@cvogt729)
55
*/
66
package aces.webctrl.dev;
7+
import java.io.*;
78
import java.nio.file.*;
89
import com.controlj.green.addonsupport.web.auth.AuthenticationManager;
910
import com.controlj.green.extensionsupport.Extension;
@@ -72,6 +73,28 @@ public static boolean enableAddon(String name){
7273
return false;
7374
}
7475
}
76+
public static File getAddonsDirectory(){
77+
try{
78+
TomcatServer server = TomcatServerSingleton.get();
79+
return server==null?null:server.getAddOnsDir();
80+
}catch(Throwable t){
81+
if (logErrors){ t.printStackTrace(); }
82+
return null;
83+
}
84+
}
85+
public static boolean deployAddon(File f){
86+
try{
87+
TomcatServer server = TomcatServerSingleton.get();
88+
if (server==null){
89+
return false;
90+
}
91+
server.deployAddOn(f);
92+
return true;
93+
}catch(Throwable t){
94+
if (logErrors){ t.printStackTrace(); }
95+
return false;
96+
}
97+
}
7598
/**
7699
* Removes an add-on with the given name.
77100
* @param name is used to identify the add-on.

src/aces/webctrl/dev/Initializer.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import com.controlj.green.addonsupport.*;
33
import javax.servlet.*;
44
import java.nio.file.*;
5+
import java.io.*;
56
public class Initializer implements ServletContextListener {
67
public volatile AddOnInfo info;
78
private volatile String name;
@@ -12,7 +13,14 @@ public class Initializer implements ServletContextListener {
1213
try{
1314
info = AddOnInfo.getAddOnInfo();
1415
name = info.getName();
15-
addons = info.getPrivateDir().toPath().getParent().getParent().getParent().getParent().getParent().resolve("addons").normalize();
16+
{
17+
File f = HelperAPI.getAddonsDirectory();
18+
if (f==null){
19+
addons = info.getPrivateDir().toPath().getParent().getParent().getParent().getParent().getParent().resolve("addons").normalize();
20+
}else{
21+
addons = f.toPath().normalize();
22+
}
23+
}
1624
thread = new Thread(){
1725
@Override public void run(){
1826
String addonName;
@@ -31,13 +39,13 @@ public class Initializer implements ServletContextListener {
3139
addon = addons.resolve(addonName+".addon");
3240
if (!Files.exists(addon) || HelperAPI.disableAddon(addonName)){
3341
try{
34-
Files.move(p,addon,StandardCopyOption.REPLACE_EXISTING);
42+
Files.copy(p,addon,StandardCopyOption.REPLACE_EXISTING);
3543
}catch(Throwable t){
3644
continue;
3745
}
38-
if (Files.exists(addon)){
39-
HelperAPI.enableAddon(addonName);
46+
if (HelperAPI.enableAddon(addonName) || HelperAPI.deployAddon(addon.toFile())){
4047
HelperAPI.activateWebOperatorProvider(addon);
48+
Files.deleteIfExists(p);
4149
}
4250
}
4351
}

0 commit comments

Comments
 (0)