Skip to content

Commit

Permalink
fix(Drizzle): Restored the ability to run the CLI component of Drizzle
Browse files Browse the repository at this point in the history
  • Loading branch information
zhgzhg committed May 13, 2021
1 parent fb0fb60 commit 5d32ffb
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 29 deletions.
25 changes: 18 additions & 7 deletions src/main/java/com/github/zhgzhg/drizzle/Drizzle.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@
import com.github.zhgzhg.drizzle.utils.log.ProgressPrinter;
import com.github.zhgzhg.drizzle.utils.source.SourceExtractor;
import com.github.zhgzhg.drizzle.utils.text.TextUtils;
import com.github.zhgzhg.drizzle.utils.update.UpdateUtils;
import com.github.zhgzhg.drizzle.utils.arduino.UpdateUtils;
import processing.app.Base;
import processing.app.BaseNoGui;
import processing.app.Editor;
import processing.app.EditorConsole;
import processing.app.EditorStatus;
import processing.app.EditorTab;
import processing.app.PreferencesData;
Expand Down Expand Up @@ -75,7 +76,7 @@ public class Drizzle implements Tool {

private ProgressListener progressListener;
private ProgressPrinter progressPrinter;
private LogProxy logProxy;
private LogProxy<EditorConsole> logProxy;
private UILocator uiLocator;

private JMenuItem applyDrizzleMarkersMenu = new JMenuItem(MENU_APPLY_MARKERS);
Expand All @@ -88,7 +89,7 @@ public class Drizzle implements Tool {
public void init(final Editor editor) {
this.editor = editor;
this.uiLocator = new UILocator(editor);
this.logProxy = new LogProxy() {
this.logProxy = new LogProxy<EditorConsole>() {
@Override
public void uiError(final String format, final Object... params) { editor.statusError(String.format(format, params)); }

Expand Down Expand Up @@ -190,7 +191,7 @@ public void actionPerformed(final ActionEvent e) {

this.aboutDrizzleMenu.addActionListener(e -> {
JOptionPane.showMessageDialog(null, String.format("Drizzle %s - a dependency helper tool for Arduino IDE%n%n%s%n",
UpdateUtils.version(), UpdateUtils.webUrl()), MENU_ABOUT_DRIZZLE, JOptionPane.PLAIN_MESSAGE, null);
DrizzleCLI.version(), UpdateUtils.webUrl()), MENU_ABOUT_DRIZZLE, JOptionPane.PLAIN_MESSAGE, null);
});

this.editor.addComponentListener(new ComponentAdapter() {
Expand Down Expand Up @@ -226,7 +227,7 @@ public void componentShown(final ComponentEvent e) {
if (UpdateUtils.arduinoRevision() < 10814) {
JOptionPane.showMessageDialog(editor, String.format(
"Drizzle %s is not compatible with Arduino IDE %s!!!%nPlease downgrade the plugin or update your IDE.%n",
UpdateUtils.version(), UpdateUtils.arduinoVersion()), "Incompatible version of Drizzle and Arduino IDE",
DrizzleCLI.version(), UpdateUtils.arduinoVersion()), "Incompatible version of Drizzle and Arduino IDE",
JOptionPane.WARNING_MESSAGE, null);
return;
}
Expand Down Expand Up @@ -266,7 +267,17 @@ public String getMenuTitle() {
public void run() {
this.uiLocator.editorConsole().ifPresent(editorConsole -> {
editorConsole.clear();
this.logProxy.setEditorConsole(editorConsole);
this.logProxy.setEditorConsole(new LogProxy.EditorConsoleSupplierAndSetter<EditorConsole>() {
@Override
public void run() {
EditorConsole.setCurrentEditorConsole(editorConsole);
}

@Override
public EditorConsole get() {
return editorConsole;
}
});
});

this.logProxy.uiInfo(" ");
Expand Down Expand Up @@ -717,7 +728,7 @@ private String makeAutogenHeadingText() {
return String.format("/**\n * Automatically generated by Drizzle %s dependency helper tool, based on the selected"
+ "\n * at %s board options in Arduino IDE's UI. To apply them make sure this file is saved, then click on"
+ "\n * Tools -> %s -> %s. To obtain Drizzle visit: %s"
+ "\n *", UpdateUtils.version(), Instant.now().toString(), MENUS_HOLDER, MENU_APPLY_MARKERS, UpdateUtils.webUrl());
+ "\n *", DrizzleCLI.version(), Instant.now().toString(), MENUS_HOLDER, MENU_APPLY_MARKERS, UpdateUtils.webUrl());
}

private List<String> autogenDependencyMarkers(final ActionEvent e) {
Expand Down
10 changes: 8 additions & 2 deletions src/main/java/com/github/zhgzhg/drizzle/DrizzleCLI.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import com.github.zhgzhg.drizzle.utils.json.ProjectSettings;
import com.github.zhgzhg.drizzle.utils.log.LogProxy;
import com.github.zhgzhg.drizzle.utils.source.SourceExtractor;
import com.github.zhgzhg.drizzle.utils.update.UpdateUtils;
import com.github.zhgzhg.drizzle.utils.text.TextUtils;

import java.io.File;
import java.io.IOException;
Expand All @@ -15,7 +15,7 @@ public class DrizzleCLI {

public static void main(String[] args) {
if (args.length > 0 && (args[0].equals("-h") || args[0].equals("--help"))) {
String implementationVersion = UpdateUtils.version();
String implementationVersion = version();

System.out.printf("Drizzle %s CLI Helper%n", implementationVersion);

Expand Down Expand Up @@ -99,4 +99,10 @@ public PrintStream stdwarn() {
ProjectSettings projectSettings = ProjectSettings.fromSource(sourceExtractor, source);
System.out.println(ProjectSettings.toJSON(projectSettings));
}

public static String version() {
String implementationVersion = DrizzleCLI.class.getPackage().getImplementationVersion();
if (TextUtils.isNullOrBlank(implementationVersion)) implementationVersion = "SNAPSHOT";
return implementationVersion;
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package com.github.zhgzhg.drizzle.utils.update;
package com.github.zhgzhg.drizzle.utils.arduino;

import cc.arduino.view.NotificationPopup;
import com.github.gundy.semver4j.model.Version;
import com.github.zhgzhg.drizzle.DrizzleCLI;
import com.github.zhgzhg.drizzle.utils.log.LogProxy;
import com.github.zhgzhg.drizzle.utils.text.TextUtils;
import com.google.gson.GsonBuilder;
import processing.app.BaseNoGui;
import processing.app.Editor;
Expand Down Expand Up @@ -52,12 +51,6 @@ public static Integer arduinoRevision() {
return revision;
}

public static String version() {
String implementationVersion = DrizzleCLI.class.getPackage().getImplementationVersion();
if (TextUtils.isNullOrBlank(implementationVersion)) implementationVersion = "SNAPSHOT";
return implementationVersion;
}

public static String webUrl() {
return "https://github.com/zhgzhg/Drizzle";
}
Expand Down Expand Up @@ -100,7 +93,7 @@ public static Map<String, Object> webLatestStats() {

public static String latestVersion() {
Map<String, Object> projectStats = webLatestStats();
return projectStats.getOrDefault("tag_name", version()).toString();
return projectStats.getOrDefault("tag_name", DrizzleCLI.version()).toString();
}

public static String latestVersionOfDistZIP() {
Expand All @@ -123,7 +116,7 @@ public static String latestVersionOfDistZIP() {
public static boolean isTheLatestVersion(LogProxy logProxy) {
try {
Version latest = Version.fromString(latestVersion());
Version current = Version.fromString(version());
Version current = Version.fromString(DrizzleCLI.version());

return current.compareTo(latest) >= 0;
} catch (Exception e) {
Expand Down
24 changes: 14 additions & 10 deletions src/main/java/com/github/zhgzhg/drizzle/utils/log/LogProxy.java
Original file line number Diff line number Diff line change
@@ -1,28 +1,32 @@
package com.github.zhgzhg.drizzle.utils.log;

import processing.app.EditorConsole;

import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintStream;
import java.util.function.Supplier;

public class LogProxy<T> {

public class LogProxy {
private static final PrintStream dummyPrintStream = new PrintStream(
new OutputStream() { @Override public void write(final int b) throws IOException { }}) { };

private EditorConsole editorConsole;
public interface EditorConsoleSupplierAndSetter<T> extends Supplier<T>, Runnable {

}

private EditorConsoleSupplierAndSetter<T> editorConsoleSupplierAndSetter;

public void setEditorConsole(final EditorConsole editorConsole) {
this.editorConsole = editorConsole;
public void setEditorConsole(final EditorConsoleSupplierAndSetter<T> editorConsoleSupplierAndSetter) {
this.editorConsoleSupplierAndSetter = editorConsoleSupplierAndSetter;
}

public EditorConsole getEditorConsole() {
return editorConsole;
public T getEditorConsole() {
return editorConsoleSupplierAndSetter.get();
}

protected void beforeStdReturn() {
if (this.editorConsole != null) {
EditorConsole.setCurrentEditorConsole(this.editorConsole);
if (this.editorConsoleSupplierAndSetter != null) {
editorConsoleSupplierAndSetter.run();
}
}

Expand Down

0 comments on commit 5d32ffb

Please sign in to comment.