REO progress

now with status!
This commit is contained in:
rusefi 2020-06-23 00:24:32 -04:00
parent 1554509dda
commit 667696a4a0
10 changed files with 92 additions and 18 deletions

View File

@ -111,6 +111,12 @@ public class AutoupdateUtil {
frame.setIconImage(icon.getImage());
}
public static void pack(Window window) {
trueLayout(window);
window.pack();
trueLayout(window);
}
public static class ConnectionAndMeta {
private String zipFileName;
private HttpURLConnection httpConnection;

View File

@ -26,7 +26,7 @@ public class XmlUtil {
System.out.println("Writing " + fileName);
marshaller.marshal(instance, new FileWriter(fileName));
System.out.println("Done " + fileName);
System.out.println("Marshalling finished " + fileName);
}
public static <T> T readModel(Class<?> modelClass, String fileName) throws Exception {

Binary file not shown.

View File

@ -4,12 +4,12 @@
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/resources" type="java-resource" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="annotations" level="project" />
<orderEntry type="module" module-name="inifile" />
<orderEntry type="library" name="httpclient" level="project" />
<orderEntry type="library" name="json-simple" level="project" />
</component>
</module>

View File

@ -6,11 +6,17 @@ import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.concurrent.BasicFuture;
import org.apache.http.concurrent.FutureCallback;
import org.apache.http.entity.mime.MultipartEntity;
import org.apache.http.entity.mime.content.FileBody;
import org.apache.http.entity.mime.content.StringBody;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
import javax.swing.*;
import javax.xml.bind.JAXBException;
@ -20,7 +26,7 @@ import java.io.IOException;
public class Online {
private static final String url = "https://rusefi.com/online/upload.php";
public static void upload(File fileName, String authTokenValue) throws IOException {
public static JSONArray upload(File fileName, String authTokenValue) throws IOException {
HttpClient httpclient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(url);
@ -32,28 +38,55 @@ public class Online {
httpPost.setEntity(reqEntity);
HttpResponse response = httpclient.execute(httpPost);
System.out.println(response);
System.out.println("response=" + response);
System.out.println("code " + response.getStatusLine().getStatusCode());
HttpEntity entity = response.getEntity();
String responseString = EntityUtils.toString(entity, "UTF-8");
System.out.println(responseString);
System.out.println("responseString=" + responseString);
JSONParser parser = new JSONParser();
try {
JSONObject object = (JSONObject) parser.parse(responseString);
System.out.println("object=" + object);
JSONArray info = (JSONArray) object.get("info");
JSONArray error = (JSONArray) object.get("error");
if (error != null) {
System.out.println("error " + error);
return error;
} else {
System.out.println("info " + info);
return info;
}
} catch (ParseException e) {
e.printStackTrace();
}
return null;
}
public static void uploadTune(Msq tune, AuthTokenPanel authTokenPanel, JComponent parent) {
public static BasicFuture<JSONArray> uploadTune(Msq tune, AuthTokenPanel authTokenPanel, JComponent parent, FutureCallback<JSONArray> callback) {
BasicFuture<JSONArray> result = new BasicFuture<>(callback);
String authToken = authTokenPanel.getToken();
if (!authTokenPanel.hasToken()) {
authTokenPanel.showError(parent);
return;
return null;
}
new Thread(() -> doUpload(authToken, tune)).start();
new Thread(new Runnable() {
@Override
public void run() {
JSONArray array = doUpload(authToken, tune);
result.completed(array);
}
}).start();
return result;
}
private static void doUpload(String authToken, Msq tune) {
private static JSONArray doUpload(String authToken, Msq tune) {
try {
tune.writeXmlFile(Msq.outputXmlFileName);
// todo: network upload should not happen on UI thread
upload(new File(Msq.outputXmlFileName), authToken);
return upload(new File(Msq.outputXmlFileName), authToken);
} catch (JAXBException | IOException ex) {
throw new IllegalStateException(ex);
}

View File

@ -13,7 +13,7 @@
<javac debug="yes"
destdir="build/classes"
classpath="${console_path}/lib/junit.jar:${console_path}/lib/annotations.jar:${launcher_path}/lib/TunerStudioPluginAPI.jar:${console_path}/lib/httpclient.jar:${console_path}/lib/httpmime.jar:${console_path}/lib/httpcore.jar"
classpath="${console_path}/lib/junit.jar:${console_path}/lib/json-simple-1.1.1.jar:${console_path}/lib/annotations.jar:${launcher_path}/lib/TunerStudioPluginAPI.jar:${console_path}/lib/httpclient.jar:${console_path}/lib/httpmime.jar:${console_path}/lib/httpcore.jar"
>
<src path="${console_path}/shared_ui/src"/>
<src path="${console_path}/autoupdate/src"/>
@ -51,6 +51,7 @@
<zipfileset src="../../java_console/lib/httpclient.jar" includes="**/*.class"/>
<zipfileset src="../../java_console/lib/httpcore.jar" includes="**/*.class"/>
<zipfileset src="../../java_console/lib/httpmime.jar" includes="**/*.class"/>
<zipfileset src="../../java_console/lib/json-simple-1.1.1.jar" includes="**/*.class"/>
<!-- <zipfileset src="lib/commons-logging.jar" includes="**/*.class"/>-->
</jar>

View File

@ -8,7 +8,9 @@ import com.rusefi.tune.xml.Msq;
import com.rusefi.ui.AuthTokenPanel;
import com.rusefi.ui.storage.PersistentConfiguration;
import com.rusefi.ui.util.URLLabel;
import org.apache.http.concurrent.FutureCallback;
import org.jetbrains.annotations.NotNull;
import org.json.simple.JSONArray;
import org.putgemin.VerticalFlowLayout;
import javax.swing.*;
@ -30,11 +32,12 @@ public class PluginEntry implements TsPluginBody {
public static final String REO = "https://rusefi.com/online/";
private final AuthTokenPanel tokenPanel = new AuthTokenPanel();
private final JComponent content = new JPanel(new VerticalFlowLayout());
private static final ImageIcon LOGO = AutoupdateUtil.loadIcon("/rusefi_online_color_300.png");
private final ImageIcon LOGO = AutoupdateUtil.loadIcon("/rusefi_online_color_300.png");
private final JButton upload = new JButton("Upload Current Tune");
private static final JLabel projectWarning = new JLabel("Please open project");
private static final JLabel tuneWarning = new JLabel();
private final JLabel uploadState = new JLabel();
private final JLabel projectWarning = new JLabel("Please open project");
private final JLabel tuneWarning = new JLabel();
private final Supplier<ControllerAccess> controllerAccessSupplier;
private String currentConfiguration;
@ -95,16 +98,38 @@ public class PluginEntry implements TsPluginBody {
}
Msq tune = TuneUploder.writeCurrentTune(ControllerAccess.getInstance(), configurationName);
Online.uploadTune(tune, tokenPanel, content);
Online.uploadTune(tune, tokenPanel, content, new FutureCallback<JSONArray>() {
@Override
public void completed(JSONArray array) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
uploadState.setText(array.toString());
uploadState.setVisible(true);
}
});
}
@Override
public void failed(Exception e) {
}
@Override
public void cancelled() {
}
});
}
});
content.add(new JLabel(getAttribute(BUILT_TIMESTAMP)));
// content.add(new JLabel("Active project: " + getConfigurationName()));
uploadState.setVisible(false);
content.add(projectWarning);
content.add(tuneWarning);
content.add(upload);
content.add(uploadState);
content.add(new JLabel(LOGO));
content.add(tokenPanel.getContent());
content.add(new URLLabel(REO));

View File

@ -12,5 +12,7 @@
<orderEntry type="library" name="TunerStudioPluginAPI" level="project" />
<orderEntry type="module" module-name="ts_plugin_launcher" />
<orderEntry type="library" name="org.mockito:mockito-all:1.10.19" level="project" />
<orderEntry type="library" name="json-simple" level="project" />
<orderEntry type="library" name="httpclient" level="project" />
</component>
</module>

View File

@ -0,0 +1,9 @@
<component name="libraryTable">
<library name="json-simple">
<CLASSES>
<root url="jar://$PROJECT_DIR$/../../java_console/lib/json-simple-1.1.1.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</component>

View File

@ -173,9 +173,7 @@ public class Updater {
content.add(instance.getContent());
AutoupdateUtil.trueLayout(content.getParent());
Window windowAncestor = SwingUtilities.getWindowAncestor(content);
AutoupdateUtil.trueLayout(windowAncestor);
windowAncestor.pack();
AutoupdateUtil.trueLayout(windowAncestor);
AutoupdateUtil.pack(windowAncestor);
}
public JPanel getContent() {