Skip to content

Commit 4fffae4

Browse files
committed
Add FlutterUtils methods to handle path erasing
1 parent 6148e12 commit 4fffae4

File tree

3 files changed

+35
-17
lines changed

3 files changed

+35
-17
lines changed

src/io/flutter/FlutterUtils.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,36 @@ public static boolean isAndroidStudio() {
111111
}
112112
}
113113

114+
public static void info(@NotNull Logger logger, @NotNull Exception e) {
115+
info(logger, e, false);
116+
}
117+
118+
public static void info(@NotNull Logger logger, @NotNull Exception e, boolean sanitizePaths) {
119+
if (sanitizePaths && FlutterSettings.getInstance().isFilePathLoggingEnabled()) {
120+
logger.info(e);
121+
} else {
122+
logger.info(e.toString());
123+
}
124+
}
125+
126+
public static void warn(@NotNull Logger logger, @NotNull Exception e) {
127+
warn(logger, e, false);
128+
}
129+
130+
public static void warn(@NotNull Logger logger, @NotNull Exception e, boolean sanitizePaths) {
131+
if (sanitizePaths && FlutterSettings.getInstance().isFilePathLoggingEnabled()) {
132+
logger.warn(e);
133+
} else {
134+
logger.warn(e.toString());
135+
}
136+
}
137+
114138
/**
115139
* Write a warning message to the IntelliJ log.
116140
* <p>
117141
* This is separate from LOG.warn() to allow us to decorate the behavior.
142+
*
143+
* This method is deprecated (as we are not decorating this behavior anywhere).
118144
*/
119145
public static void warn(@NotNull Logger logger, @NotNull Throwable t) {
120146
logger.warn(t);
@@ -124,6 +150,8 @@ public static void warn(@NotNull Logger logger, @NotNull Throwable t) {
124150
* Write a warning message to the IntelliJ log.
125151
* <p>
126152
* This is separate from LOG.warn() to allow us to decorate the behavior.
153+
*
154+
* This method is deprecated (as we are not decorating this behavior anywhere).
127155
*/
128156
public static void warn(@NotNull Logger logger, @NotNull String message) {
129157
logger.warn(message);
@@ -133,6 +161,8 @@ public static void warn(@NotNull Logger logger, @NotNull String message) {
133161
* Write a warning message to the IntelliJ log.
134162
* <p>
135163
* This is separate from LOG.warn() to allow us to decorate the behavior.
164+
*
165+
* This method is deprecated (as we are not decorating this behavior anywhere).
136166
*/
137167
public static void warn(@NotNull Logger logger, @NotNull String message, @NotNull Throwable t) {
138168
logger.warn(message, t);

src/io/flutter/run/LaunchState.java

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@
5151
import io.flutter.run.daemon.DaemonConsoleView;
5252
import io.flutter.run.daemon.DeviceService;
5353
import io.flutter.run.daemon.FlutterApp;
54-
import io.flutter.settings.FlutterSettings;
5554
import io.flutter.toolwindow.ToolWindowBadgeUpdater;
5655
import org.jetbrains.annotations.NotNull;
5756
import org.jetbrains.annotations.Nullable;
@@ -173,7 +172,7 @@ protected RunContentDescriptor launch(@NotNull ExecutionEnvironment env) throws
173172

174173
try {
175174
// There is no public way to set display name so we resort to reflection.
176-
final Field f = descriptor.getClass().getDeclaredField("myDisplayNameView");
175+
final Field f = descriptor.getClass().getDeclaredField("myDisplayNameView_INVALID");
177176
f.setAccessible(true);
178177
Object viewInstance = f.get(descriptor);
179178
if (viewInstance != null) {
@@ -182,11 +181,7 @@ protected RunContentDescriptor launch(@NotNull ExecutionEnvironment env) throws
182181
}
183182
}
184183
catch (IllegalAccessException | InvocationTargetException | NoSuchFieldException | NoSuchMethodException e) {
185-
if (FlutterSettings.getInstance().isFilePathLoggingEnabled()) {
186-
LOG.info(e);
187-
} else {
188-
LOG.info(e.toString());
189-
}
184+
FlutterUtils.info(LOG, e, true);
190185
}
191186

192187
return descriptor;
@@ -407,11 +402,7 @@ protected RunContentDescriptor doExecute(@NotNull RunProfileState state, @NotNul
407402
app.shutdownAsync().get();
408403
}
409404
catch (InterruptedException | java.util.concurrent.ExecutionException e) {
410-
if (FlutterSettings.getInstance().isFilePathLoggingEnabled()) {
411-
LOG.warn(e);
412-
} else {
413-
LOG.warn(e.toString());
414-
}
405+
FlutterUtils.warn(LOG, e, true);
415406
}
416407
return launchState.launch(env);
417408
}

src/io/flutter/run/SdkFields.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import com.jetbrains.lang.dart.sdk.DartConfigurable;
2020
import com.jetbrains.lang.dart.sdk.DartSdk;
2121
import io.flutter.FlutterBundle;
22+
import io.flutter.FlutterUtils;
2223
import io.flutter.dart.DartPlugin;
2324
import io.flutter.logging.PluginLogger;
2425
import io.flutter.pub.PubRoot;
@@ -232,11 +233,7 @@ public GeneralCommandLine createFlutterSdkRunCommand(
232233
args = ArrayUtil.append(args, "--devtools-server-address=http://" + instance.host() + ":" + instance.port());
233234
}
234235
catch (Exception e) {
235-
if (FlutterSettings.getInstance().isFilePathLoggingEnabled()) {
236-
LOG.info(e);
237-
} else {
238-
LOG.info(e.toString());
239-
}
236+
FlutterUtils.warn(LOG, e, true);
240237
}
241238
command = flutterSdk.flutterRun(root, main.getFile(), device, runMode, flutterLaunchMode, project, args);
242239
final GeneralCommandLine commandLine = command.createGeneralCommandLine(project);

0 commit comments

Comments
 (0)