From 8fd0a504c58d0d6f2fae644e205d4f141b5a6542 Mon Sep 17 00:00:00 2001 From: Vitalii Chepeliuk Date: Thu, 15 Feb 2018 12:20:35 +0100 Subject: [PATCH] Add constants to packages and cleanup code --- .../plugin/intellij/mobile/api/CLIRunner.java | 1 - .../intellij/mobile/api/CLIRunnerImpl.java | 58 ++++++++++--------- .../plugin/intellij/mobile/api/MobileAPI.java | 5 +- .../mobile/models/MobileClientSpec.java | 24 +++----- .../mobile/models/MobileServices.java | 4 +- .../services/sdkconfig/OpenFileRunnable.java | 9 +-- .../services/sdkconfig/SDKConfigManager.java | 28 +++++---- .../sdkconfig/WriteToFileRunnable.java | 15 ++--- .../mobile/ui/MobileToolWindowFactory.java | 10 ++-- .../mobile/ui/actions/ClientCreatedCheck.java | 11 +--- .../ui/actions/ClientCreatedCheckAction.java | 15 ++--- .../intellij/mobile/ui/actions/Constants.java | 7 +++ .../mobile/ui/actions/DisplayToolWindow.java | 4 +- .../mobile/ui/actions/ViewClientConfig.java | 6 +- .../ui/createclientpopup/Constants.java | 7 ++- .../createclientpopup/CreateClientForm.java | 8 +-- .../CreateClientFormInputs.java | 14 +---- .../mobile/ui/sdkconfig/Constants.java | 8 +++ .../ui/sdkconfig/CreateConfigDialog.java | 9 ++- .../mobile/ui/sdkconfig/NewFileForm.java | 2 +- .../ServiceDeployedNotification.java | 42 +++++++------- .../ui/sdkconfig/ViewSDKConfigDialog.java | 5 +- .../ui/sdkconfig/ViewSDKConfigPanel.java | 4 +- .../servicecatalog/DeployServiceDialog.java | 50 ++++++++-------- .../ui/servicecatalog/ServiceListPane.java | 7 ++- .../ui/servicecatalog/ServicePanel.java | 10 ++-- .../identity/IdentityConfigurationPanel.java | 24 +++----- .../identity/IdentityDeployment.java | 4 +- .../settings/AeroGearMobileConfigurable.java | 7 +-- .../mobile/ui/settings/SettingsPanel.java | 2 +- .../mobile/utils/WriteToFileRunnable.java | 16 ++--- src/test/java/MobileAPITest.java | 8 +-- 32 files changed, 211 insertions(+), 213 deletions(-) create mode 100644 src/main/java/org/aerogear/plugin/intellij/mobile/ui/actions/Constants.java create mode 100644 src/main/java/org/aerogear/plugin/intellij/mobile/ui/sdkconfig/Constants.java diff --git a/src/main/java/org/aerogear/plugin/intellij/mobile/api/CLIRunner.java b/src/main/java/org/aerogear/plugin/intellij/mobile/api/CLIRunner.java index 2abd51c..cc26af3 100644 --- a/src/main/java/org/aerogear/plugin/intellij/mobile/api/CLIRunner.java +++ b/src/main/java/org/aerogear/plugin/intellij/mobile/api/CLIRunner.java @@ -4,6 +4,5 @@ public interface CLIRunner { String executeSync(List command) throws CLIException; - void executeAsync(List command, Watcher w); } diff --git a/src/main/java/org/aerogear/plugin/intellij/mobile/api/CLIRunnerImpl.java b/src/main/java/org/aerogear/plugin/intellij/mobile/api/CLIRunnerImpl.java index cec1690..d84dca4 100644 --- a/src/main/java/org/aerogear/plugin/intellij/mobile/api/CLIRunnerImpl.java +++ b/src/main/java/org/aerogear/plugin/intellij/mobile/api/CLIRunnerImpl.java @@ -12,17 +12,22 @@ import java.util.concurrent.*; public class CLIRunnerImpl implements CLIRunner { - - MobileNotificationsService notificationsService; - + + private static final String OUTPUT_TYPE_ERROR = "error"; + private static final String OUTPUT_TYPE_STD = "std"; + + private static final int CMD_TIMEOUT_SECONDS = 10; + private static final int EXECUTOR_NUM_THREADS = 3; + + private final MobileNotificationsService notificationsService; + private final ExecutorService executorService; + + private static final CLIRunner instance = CLIRunnerImpl.getInstance(); + public CLIRunnerImpl() { this.notificationsService = new MobileNotificationsService(); + this.executorService = Executors.newFixedThreadPool(EXECUTOR_NUM_THREADS); } - - private final String OUTPUT_TYPE_ERROR = "error"; - private final String OUTPUT_TYPE_STD = "std"; - - private static int CMD_TIMEOUT_SECONDS = 10; @Override public String executeSync(List args) throws CLIException { @@ -66,24 +71,15 @@ private List prepareCmd(@NotNull List args) { } public void executeAsync(List args, Watcher w) { - final ExecutorService ex = Executors.newFixedThreadPool(3); - List cmd = prepareCmd(args); - ex.execute(() -> { + executorService.execute(() -> { + List cmd = prepareCmd(args); ProcessBuilder pb = new ProcessBuilder(cmd); - + try { final Process p = pb.start(); - Callable inputRead = new Callable() { - @Override public String call() throws Exception { - return readOutput(OUTPUT_TYPE_STD,p.getInputStream(), true); - } - }; - Callable errorRead = new Callable() { - @Override public String call() throws Exception { - return readOutput(OUTPUT_TYPE_ERROR,p.getErrorStream(),true); - } - } ; - Future cmdInput = ex.submit(inputRead); + Callable inputRead = () -> readOutput(OUTPUT_TYPE_STD,p.getInputStream(), true); + Callable errorRead = () -> readOutput(OUTPUT_TYPE_ERROR,p.getErrorStream(),true); + Future cmdInput = executorService.submit(inputRead); Future cmdErr = Executors.newSingleThreadExecutor().submit(errorRead); String input = cmdInput.get(); String error = cmdErr.get(); @@ -107,14 +103,20 @@ private String readOutput(String outputType,InputStream in, Boolean shouldNotify try (BufferedReader bf = new BufferedReader(new InputStreamReader(in))) { String line; while ((line = bf.readLine()) != null) { - if (outputType.equals("error") && shouldNotify){ - this.notificationsService.notifyError("cli error",line); - } else if (shouldNotify) { - this.notificationsService.notifyInformation("cli output", line); + if (shouldNotify) { + if (outputType.equals(OUTPUT_TYPE_ERROR)) { + this.notificationsService.notifyError("cli error", line); + } else { + this.notificationsService.notifyInformation("cli output", line); + } } - sb.append(line + "\n"); + sb.append(line).append(System.lineSeparator()); } } return sb.toString(); } + + public static CLIRunner getInstance() { + return instance; + } } diff --git a/src/main/java/org/aerogear/plugin/intellij/mobile/api/MobileAPI.java b/src/main/java/org/aerogear/plugin/intellij/mobile/api/MobileAPI.java index 7b4c0a8..45770af 100644 --- a/src/main/java/org/aerogear/plugin/intellij/mobile/api/MobileAPI.java +++ b/src/main/java/org/aerogear/plugin/intellij/mobile/api/MobileAPI.java @@ -13,7 +13,7 @@ public class MobileAPI { - private CLIRunner cliRunner; + private final CLIRunner cliRunner; public MobileAPI(CLIRunner cliRunner) { this.cliRunner = cliRunner; @@ -23,8 +23,7 @@ public MobileServices getServices() throws CLIException { String outPut = cliRunner.executeSync(Arrays.asList("get", "services", "--", "-o=json")); Gson gson = new Gson(); try { - MobileServices services = gson.fromJson(outPut, MobileServices.class); - return services; + return gson.fromJson(outPut, MobileServices.class); } catch (JsonSyntaxException e) { throw new CLIException("unexpected response from CLI: " + outPut); } diff --git a/src/main/java/org/aerogear/plugin/intellij/mobile/models/MobileClientSpec.java b/src/main/java/org/aerogear/plugin/intellij/mobile/models/MobileClientSpec.java index fc6330e..980c7c6 100644 --- a/src/main/java/org/aerogear/plugin/intellij/mobile/models/MobileClientSpec.java +++ b/src/main/java/org/aerogear/plugin/intellij/mobile/models/MobileClientSpec.java @@ -47,16 +47,13 @@ public void setAppIdentifier(String appIdentifier) { return true; if (o == null || getClass() != o.getClass()) return false; - + MobileClientSpec that = (MobileClientSpec) o; - - if (name != null ? !name.equals(that.name) : that.name != null) - return false; - if (apiKey != null ? !apiKey.equals(that.apiKey) : that.apiKey != null) - return false; - if (clientType != null ? !clientType.equals(that.clientType) : that.clientType != null) - return false; - return appIdentifier != null ? appIdentifier.equals(that.appIdentifier) : that.appIdentifier == null; + + return (name != null ? name.equals(that.name) : that.name == null) + && (apiKey != null ? apiKey.equals(that.apiKey) : that.apiKey == null) + && (clientType != null ? clientType.equals(that.clientType) : that.clientType == null) + && (appIdentifier != null ? appIdentifier.equals(that.appIdentifier) : that.appIdentifier == null); } public String toJsonPrettyPrint(){ @@ -74,11 +71,8 @@ public String toJsonPrettyPrint(){ @Override public String toString() { - return "{\n" + - " name: " + name + ",\n" + - " apiKey: " + apiKey +",\n" + - " clientType: " + clientType +",\n" + - " appIdentifier: " + appIdentifier +"\n" + - '}'; + + Gson gson = new GsonBuilder().setPrettyPrinting().create(); + return gson.toJson(this); } } diff --git a/src/main/java/org/aerogear/plugin/intellij/mobile/models/MobileServices.java b/src/main/java/org/aerogear/plugin/intellij/mobile/models/MobileServices.java index 85f8938..fcaa29a 100644 --- a/src/main/java/org/aerogear/plugin/intellij/mobile/models/MobileServices.java +++ b/src/main/java/org/aerogear/plugin/intellij/mobile/models/MobileServices.java @@ -1,5 +1,7 @@ package org.aerogear.plugin.intellij.mobile.models; +import java.util.Arrays; + public class MobileServices { private ServiceClass[] items = new ServiceClass[0]; @@ -17,6 +19,6 @@ public void setItems (ServiceClass[] items) @Override public String toString() { - return "items = " + items; + return "items = " + Arrays.toString(items); } } diff --git a/src/main/java/org/aerogear/plugin/intellij/mobile/services/sdkconfig/OpenFileRunnable.java b/src/main/java/org/aerogear/plugin/intellij/mobile/services/sdkconfig/OpenFileRunnable.java index 6dcafc6..e4e8657 100644 --- a/src/main/java/org/aerogear/plugin/intellij/mobile/services/sdkconfig/OpenFileRunnable.java +++ b/src/main/java/org/aerogear/plugin/intellij/mobile/services/sdkconfig/OpenFileRunnable.java @@ -6,11 +6,12 @@ import com.intellij.openapi.vfs.VirtualFile; import java.io.File; +import java.util.Objects; -public class OpenFileRunnable implements Runnable { +class OpenFileRunnable implements Runnable { - private Project project; - private String path; + private final Project project; + private final String path; public OpenFileRunnable(Project project, String path) { @@ -22,6 +23,6 @@ public OpenFileRunnable(Project project, String path) { public void run() { File file = new File(this.path); VirtualFile vConfig = LocalFileSystem.getInstance().findFileByIoFile(file); - new OpenFileDescriptor(project, vConfig).navigate(true); + new OpenFileDescriptor(project, Objects.requireNonNull(vConfig)).navigate(true); } } diff --git a/src/main/java/org/aerogear/plugin/intellij/mobile/services/sdkconfig/SDKConfigManager.java b/src/main/java/org/aerogear/plugin/intellij/mobile/services/sdkconfig/SDKConfigManager.java index e5f8e16..7f182cd 100644 --- a/src/main/java/org/aerogear/plugin/intellij/mobile/services/sdkconfig/SDKConfigManager.java +++ b/src/main/java/org/aerogear/plugin/intellij/mobile/services/sdkconfig/SDKConfigManager.java @@ -12,24 +12,28 @@ import java.io.File; import java.io.IOException; +import java.util.Objects; public class SDKConfigManager { public void createAndOpenFile(Project project, String path) throws CLIException, IOException { File configFile = new File(path); - configFile.createNewFile(); + boolean fileCreated = configFile.createNewFile(); + if (fileCreated){ + Runnable updateConfigRunner = new WriteToFileRunnable(project, path, getClientConfig(project)); + Runnable openConfigRunner = new OpenFileRunnable(project, path); - Runnable updateConfigRunner = new WriteToFileRunnable(project, path, getClientConfig(project)); - Runnable openConfigRunner = new OpenFileRunnable(project, path); - - this.asyncRefreshFiles(() -> { - WriteCommandAction.runWriteCommandAction(project, updateConfigRunner); - ApplicationManager.getApplication().runReadAction(openConfigRunner); - AeroGearMobileConfiguration.getInstance(project).setConfigPath(path); - }); + this.asyncRefreshFiles(() -> { + WriteCommandAction.runWriteCommandAction(project, updateConfigRunner); + ApplicationManager.getApplication().runReadAction(openConfigRunner); + Objects.requireNonNull(AeroGearMobileConfiguration.getInstance(project)).setConfigPath(path); + }); + } else { + Objects.requireNonNull(AeroGearMobileConfiguration.getInstance(project)).setConfigPath(path); + } } public void updateSDKConfig(Project project) throws CLIException { - String sdkConfigPath = AeroGearMobileConfiguration.getInstance(project).getConfigPath(); + String sdkConfigPath = Objects.requireNonNull(AeroGearMobileConfiguration.getInstance(project)).getConfigPath(); if (sdkConfigPath != null && !sdkConfigPath.isEmpty()) { this.asyncRefreshFiles(() -> { Runnable updateConfigRunner = new WriteToFileRunnable(project, sdkConfigPath, getClientConfig(project)); @@ -39,7 +43,7 @@ public void updateSDKConfig(Project project) throws CLIException { } private String getClientName(Project project) { - return AeroGearMobileConfiguration.getInstance(project).getClientName(); + return Objects.requireNonNull(AeroGearMobileConfiguration.getInstance(project)).getClientName(); } private void asyncRefreshFiles(Runnable r) { @@ -48,7 +52,7 @@ private void asyncRefreshFiles(Runnable r) { private CharSequence getClientConfig(Project project) throws CLIException { String clientName = this.getClientName(project); - return new MobileAPI(new CLIRunnerImpl()).getClientConfig(clientName); + return new MobileAPI(CLIRunnerImpl.getInstance()).getClientConfig(clientName); } public static SDKConfigManager getInstance(Project project) { diff --git a/src/main/java/org/aerogear/plugin/intellij/mobile/services/sdkconfig/WriteToFileRunnable.java b/src/main/java/org/aerogear/plugin/intellij/mobile/services/sdkconfig/WriteToFileRunnable.java index 27d405e..8d4f83e 100644 --- a/src/main/java/org/aerogear/plugin/intellij/mobile/services/sdkconfig/WriteToFileRunnable.java +++ b/src/main/java/org/aerogear/plugin/intellij/mobile/services/sdkconfig/WriteToFileRunnable.java @@ -8,12 +8,13 @@ import com.intellij.psi.PsiFile; import com.intellij.psi.PsiManager; import java.io.File; +import java.util.Objects; -public class WriteToFileRunnable implements Runnable { +class WriteToFileRunnable implements Runnable { - private Project project; - private String path; - private CharSequence cs; + private final Project project; + private final String path; + private final CharSequence cs; public WriteToFileRunnable(Project project, String path, CharSequence cs) { @@ -26,8 +27,8 @@ public WriteToFileRunnable(Project project, String path, CharSequence cs) { public void run() { File configFile = new File(this.path); VirtualFile vConfig = LocalFileSystem.getInstance().findFileByIoFile(configFile); - PsiFile psiConfig = PsiManager.getInstance(this.project).findFile(vConfig); - Document d = PsiDocumentManager.getInstance(this.project).getDocument(psiConfig); - d.setText(this.cs); + PsiFile psiConfig = PsiManager.getInstance(this.project).findFile(Objects.requireNonNull(vConfig)); + Document d = PsiDocumentManager.getInstance(this.project).getDocument(Objects.requireNonNull(psiConfig)); + Objects.requireNonNull(d).setText(this.cs); } } diff --git a/src/main/java/org/aerogear/plugin/intellij/mobile/ui/MobileToolWindowFactory.java b/src/main/java/org/aerogear/plugin/intellij/mobile/ui/MobileToolWindowFactory.java index 31c809c..f43d40a 100644 --- a/src/main/java/org/aerogear/plugin/intellij/mobile/ui/MobileToolWindowFactory.java +++ b/src/main/java/org/aerogear/plugin/intellij/mobile/ui/MobileToolWindowFactory.java @@ -12,13 +12,13 @@ import org.aerogear.plugin.intellij.mobile.api.CLIRunner; import org.aerogear.plugin.intellij.mobile.api.CLIRunnerImpl; import org.aerogear.plugin.intellij.mobile.api.MobileAPI; +import org.jetbrains.annotations.NotNull; import java.awt.*; public class MobileToolWindowFactory implements ToolWindowFactory { - private JBPanel mobileToolWindowContent; - MobileNotificationsService notifier; - private CLIRunner cliRunner = new CLIRunnerImpl(); + private final MobileNotificationsService notifier; + private final CLIRunner cliRunner = CLIRunnerImpl.getInstance(); public MobileToolWindowFactory() { @@ -26,8 +26,8 @@ public MobileToolWindowFactory() { } @Override - public void createToolWindowContent(Project project, ToolWindow toolWindow){ - mobileToolWindowContent = new JBPanel(); + public void createToolWindowContent(@NotNull Project project, @NotNull ToolWindow toolWindow){ + JBPanel mobileToolWindowContent = new JBPanel(); mobileToolWindowContent.setLayout(new GridLayout(0, 1)); ContentFactory contentFactory = ContentFactory.SERVICE.getInstance(); diff --git a/src/main/java/org/aerogear/plugin/intellij/mobile/ui/actions/ClientCreatedCheck.java b/src/main/java/org/aerogear/plugin/intellij/mobile/ui/actions/ClientCreatedCheck.java index eeabaf6..11f9f16 100644 --- a/src/main/java/org/aerogear/plugin/intellij/mobile/ui/actions/ClientCreatedCheck.java +++ b/src/main/java/org/aerogear/plugin/intellij/mobile/ui/actions/ClientCreatedCheck.java @@ -9,7 +9,6 @@ import org.aerogear.plugin.intellij.mobile.api.MobileAPI; import org.aerogear.plugin.intellij.mobile.services.MobileNotificationsService; import org.aerogear.plugin.intellij.mobile.ui.MobileIcons; -import org.aerogear.plugin.intellij.mobile.ui.createclientpopup.Constants; import org.jetbrains.annotations.NotNull; public class ClientCreatedCheck implements StartupActivity { @@ -20,17 +19,13 @@ public void runActivity(@NotNull Project project) { checkFile(projectPath + '/' + Constants.DOT_FILENAME, project); } - public void checkFile(String filePath, @NotNull Project project) { + private void checkFile(String filePath, @NotNull Project project) { VirtualFile file = LocalFileSystem.getInstance().refreshAndFindFileByPath(filePath); if (file == null) { - MobileAPI mobileAPI = new MobileAPI(new CLIRunnerImpl()); + MobileAPI mobileAPI = new MobileAPI(CLIRunnerImpl.getInstance()); - NotificationListener notificationListener = (notification, event) -> { - { - new ClientCreatedCheckAction().showCreateClientForm(project, mobileAPI, filePath); - } - }; + NotificationListener notificationListener = (notification, event) -> new ClientCreatedCheckAction().showCreateClientForm(project, mobileAPI, filePath); new MobileNotificationsService().notifyWarning( MobileIcons.AEROGEAR, diff --git a/src/main/java/org/aerogear/plugin/intellij/mobile/ui/actions/ClientCreatedCheckAction.java b/src/main/java/org/aerogear/plugin/intellij/mobile/ui/actions/ClientCreatedCheckAction.java index 8a4d0c9..ed64110 100644 --- a/src/main/java/org/aerogear/plugin/intellij/mobile/ui/actions/ClientCreatedCheckAction.java +++ b/src/main/java/org/aerogear/plugin/intellij/mobile/ui/actions/ClientCreatedCheckAction.java @@ -10,21 +10,22 @@ import org.aerogear.plugin.intellij.mobile.models.MobileClient; import org.aerogear.plugin.intellij.mobile.services.AeroGearMobileConfiguration; import org.aerogear.plugin.intellij.mobile.services.MobileNotificationsService; -import org.aerogear.plugin.intellij.mobile.ui.createclientpopup.Constants; import org.aerogear.plugin.intellij.mobile.ui.createclientpopup.CreateClientForm; import org.aerogear.plugin.intellij.mobile.utils.WriteToFileRunnable; +import java.util.Objects; + public class ClientCreatedCheckAction extends AnAction { - MobileNotificationsService notificationsService; - + private final MobileNotificationsService notificationsService; + public ClientCreatedCheckAction() { this.notificationsService = new MobileNotificationsService(); } @Override public void actionPerformed(AnActionEvent e) { - MobileAPI mobileAPI = new MobileAPI(new CLIRunnerImpl()); - String filePath = e.getProject().getBasePath() + "/" + Constants.DOT_FILENAME; + MobileAPI mobileAPI = new MobileAPI(CLIRunnerImpl.getInstance()); + String filePath = Objects.requireNonNull(e.getProject()).getBasePath() + "/" + Constants.DOT_FILENAME; showCreateClientForm(e.getProject(), mobileAPI, filePath); } @@ -34,12 +35,12 @@ public void showCreateClientForm(Project project, MobileAPI mobileAPI, String fi if (CreateClientForm.OK_EXIT_CODE == clientForm.getExitCode()) { MobileClient mobileClient = mobileAPI.createClient(clientForm.getName(), clientForm.getClientType(), clientForm.getAppId()); - AeroGearMobileConfiguration.getInstance(project).setClientName(mobileClient.getSpec().getName() + "-" + mobileClient.getSpec().getClientType()); + Objects.requireNonNull(AeroGearMobileConfiguration.getInstance(project)).setClientName(mobileClient.getSpec().getName() + "-" + mobileClient.getSpec().getClientType()); CharSequence charSeq = mobileClient.getSpec().toJsonPrettyPrint(); WriteToFileRunnable writeToFile = new WriteToFileRunnable(project, filePath, charSeq, Constants.DOT_FILENAME, JsonFileType.INSTANCE); WriteCommandAction.runWriteCommandAction(project, writeToFile); - this.notificationsService.notifyInformation("Mobile Client", "successfully created a mobile client "); + this.notificationsService.notifyInformation(Constants.MOBILE_CLIENT, "successfully created a mobile client "); } } } diff --git a/src/main/java/org/aerogear/plugin/intellij/mobile/ui/actions/Constants.java b/src/main/java/org/aerogear/plugin/intellij/mobile/ui/actions/Constants.java new file mode 100644 index 0000000..54a2c75 --- /dev/null +++ b/src/main/java/org/aerogear/plugin/intellij/mobile/ui/actions/Constants.java @@ -0,0 +1,7 @@ +package org.aerogear.plugin.intellij.mobile.ui.actions; + +class Constants { + public static final String AEROGEAR_MOBILE = "Aerogear Mobile"; + public static final String MOBILE_CLIENT = "Mobile Client"; + public static final String DOT_FILENAME = ".aerogear.json"; +} diff --git a/src/main/java/org/aerogear/plugin/intellij/mobile/ui/actions/DisplayToolWindow.java b/src/main/java/org/aerogear/plugin/intellij/mobile/ui/actions/DisplayToolWindow.java index 2f06369..aff83ac 100644 --- a/src/main/java/org/aerogear/plugin/intellij/mobile/ui/actions/DisplayToolWindow.java +++ b/src/main/java/org/aerogear/plugin/intellij/mobile/ui/actions/DisplayToolWindow.java @@ -5,11 +5,13 @@ import com.intellij.openapi.wm.ToolWindow; import com.intellij.openapi.wm.ToolWindowManager; +import java.util.Objects; + public class DisplayToolWindow extends AnAction { @Override public void actionPerformed(AnActionEvent e) { - ToolWindow toolWindow = ToolWindowManager.getInstance(e.getProject()).getToolWindow("Aerogear Mobile"); + ToolWindow toolWindow = ToolWindowManager.getInstance(Objects.requireNonNull(e.getProject())).getToolWindow(Constants.AEROGEAR_MOBILE); toolWindow.activate(null); } } diff --git a/src/main/java/org/aerogear/plugin/intellij/mobile/ui/actions/ViewClientConfig.java b/src/main/java/org/aerogear/plugin/intellij/mobile/ui/actions/ViewClientConfig.java index 470811e..8d0b5bb 100644 --- a/src/main/java/org/aerogear/plugin/intellij/mobile/ui/actions/ViewClientConfig.java +++ b/src/main/java/org/aerogear/plugin/intellij/mobile/ui/actions/ViewClientConfig.java @@ -9,17 +9,17 @@ import org.aerogear.plugin.intellij.mobile.services.MobileNotificationsService; import org.aerogear.plugin.intellij.mobile.ui.sdkconfig.ViewSDKConfigDialog; -; +import java.util.Objects; public class ViewClientConfig extends AnAction { @Override public void actionPerformed(AnActionEvent e) { try { - String clientName = AeroGearMobileConfiguration.getInstance(e.getProject()).getClientName(); + String clientName = Objects.requireNonNull(AeroGearMobileConfiguration.getInstance(e.getProject())).getClientName(); if (null == clientName){ throw new CLIException("cannot get config as no mobile client created"); } - String clientSdkConfig = new MobileAPI(new CLIRunnerImpl()).getClientConfig(clientName); + String clientSdkConfig = new MobileAPI(CLIRunnerImpl.getInstance()).getClientConfig(clientName); new ViewSDKConfigDialog(clientSdkConfig).show(); } catch (CLIException ex) { MobileNotificationsService.getInstance().notifyError("Error from mobile plugin: " + ex.toString()); diff --git a/src/main/java/org/aerogear/plugin/intellij/mobile/ui/createclientpopup/Constants.java b/src/main/java/org/aerogear/plugin/intellij/mobile/ui/createclientpopup/Constants.java index 93e007d..b6f0897 100644 --- a/src/main/java/org/aerogear/plugin/intellij/mobile/ui/createclientpopup/Constants.java +++ b/src/main/java/org/aerogear/plugin/intellij/mobile/ui/createclientpopup/Constants.java @@ -1,7 +1,8 @@ package org.aerogear.plugin.intellij.mobile.ui.createclientpopup; -public class Constants { +class Constants { public static final String[] CLIENT_TYPES = new String[]{"android", "cordova", "iOS"}; - - public static String DOT_FILENAME = ".aerogear.json"; + public static final String CLIENT_APP_NAME_IS_REQUIRED = "Client app name is required"; + public static final String APP_IDENTIFIER_BUNDLE_ID_PACKAGE_NAME_IS_REQUIRED = "appIdentifier bundleID|packageName is required"; + public static final String CREATE_CLIENT = "Create Client"; } \ No newline at end of file diff --git a/src/main/java/org/aerogear/plugin/intellij/mobile/ui/createclientpopup/CreateClientForm.java b/src/main/java/org/aerogear/plugin/intellij/mobile/ui/createclientpopup/CreateClientForm.java index aa30d06..903a1db 100644 --- a/src/main/java/org/aerogear/plugin/intellij/mobile/ui/createclientpopup/CreateClientForm.java +++ b/src/main/java/org/aerogear/plugin/intellij/mobile/ui/createclientpopup/CreateClientForm.java @@ -30,13 +30,13 @@ public class CreateClientForm extends DialogWrapper { private JLabel errorMessage; private Border defaultClientNameBorder; private CreateClientFormInputs formInputs; - private MobileAPI mobileAPI; + private final MobileAPI mobileAPI; public CreateClientForm(@Nullable Project project, MobileAPI mobileAPI) { super(project); this.mobileAPI = mobileAPI; init(); - setTitle("Create Client"); + setTitle(Constants.CREATE_CLIENT); } private void createUIComponents() { @@ -58,12 +58,12 @@ protected ValidationInfo doValidate() { getInputs(); //TODO duplicate client name validation if (formInputs.isInvalidName()) { - return new ValidationInfo(formInputs.invalidNameMessage(), clientNameTxtField); + return new ValidationInfo(Constants.CLIENT_APP_NAME_IS_REQUIRED, clientNameTxtField); } if (formInputs.isInvalidAppIdentifier()) { - return new ValidationInfo(formInputs.getInvalidAppIdentifierMessage(), clientAppIdTxtField); + return new ValidationInfo(Constants.APP_IDENTIFIER_BUNDLE_ID_PACKAGE_NAME_IS_REQUIRED, clientAppIdTxtField); } String clientId = (formInputs.getName() + "-" + formInputs.getClientType()).toLowerCase(); diff --git a/src/main/java/org/aerogear/plugin/intellij/mobile/ui/createclientpopup/CreateClientFormInputs.java b/src/main/java/org/aerogear/plugin/intellij/mobile/ui/createclientpopup/CreateClientFormInputs.java index eb5888b..0565d49 100644 --- a/src/main/java/org/aerogear/plugin/intellij/mobile/ui/createclientpopup/CreateClientFormInputs.java +++ b/src/main/java/org/aerogear/plugin/intellij/mobile/ui/createclientpopup/CreateClientFormInputs.java @@ -3,15 +3,11 @@ /** * Store of data inputs in the create client form */ -public class CreateClientFormInputs { +class CreateClientFormInputs { private String name; private String clientType; private String appIdentifier; - - CreateClientFormInputs() { - } - public String getName() { return name; } @@ -45,10 +41,6 @@ public boolean isInvalidName() { return name.isEmpty(); } - public String invalidNameMessage() { - return "Client app name is required"; - } - /** * validates app id * @@ -58,8 +50,4 @@ public boolean isInvalidAppIdentifier() { return appIdentifier.isEmpty(); } - public String getInvalidAppIdentifierMessage() { - return "appIdentifier bundleID|packageName is required"; - } - } \ No newline at end of file diff --git a/src/main/java/org/aerogear/plugin/intellij/mobile/ui/sdkconfig/Constants.java b/src/main/java/org/aerogear/plugin/intellij/mobile/ui/sdkconfig/Constants.java new file mode 100644 index 0000000..5af09db --- /dev/null +++ b/src/main/java/org/aerogear/plugin/intellij/mobile/ui/sdkconfig/Constants.java @@ -0,0 +1,8 @@ +package org.aerogear.plugin.intellij.mobile.ui.sdkconfig; + +class Constants { + public static final String CREATE_CONFIG = "create-config"; + public static final String OPEN_SETTINGS = "open-settings"; + public static final String UPDATE_CONFIG = "update-config"; + public static final String SDK_CONFIG = "SDK config"; +} diff --git a/src/main/java/org/aerogear/plugin/intellij/mobile/ui/sdkconfig/CreateConfigDialog.java b/src/main/java/org/aerogear/plugin/intellij/mobile/ui/sdkconfig/CreateConfigDialog.java index c9888ee..caff510 100644 --- a/src/main/java/org/aerogear/plugin/intellij/mobile/ui/sdkconfig/CreateConfigDialog.java +++ b/src/main/java/org/aerogear/plugin/intellij/mobile/ui/sdkconfig/CreateConfigDialog.java @@ -14,21 +14,20 @@ import java.io.File; import java.io.IOException; -public class CreateConfigDialog extends DialogWrapper { +class CreateConfigDialog extends DialogWrapper { - private Project project; + private final Project project; private TextFieldWithBrowseButton destination; private JTextField fileName; - protected CreateConfigDialog(@Nullable Project project) { + CreateConfigDialog(@Nullable Project project) { super(project); this.project = project; init(); - setTitle("SDK config"); + setTitle(Constants.SDK_CONFIG); } - @Nullable @Override protected JComponent createCenterPanel() { diff --git a/src/main/java/org/aerogear/plugin/intellij/mobile/ui/sdkconfig/NewFileForm.java b/src/main/java/org/aerogear/plugin/intellij/mobile/ui/sdkconfig/NewFileForm.java index 1d87000..91ac3dd 100644 --- a/src/main/java/org/aerogear/plugin/intellij/mobile/ui/sdkconfig/NewFileForm.java +++ b/src/main/java/org/aerogear/plugin/intellij/mobile/ui/sdkconfig/NewFileForm.java @@ -3,7 +3,7 @@ import javax.swing.JTextField; import com.intellij.openapi.ui.TextFieldWithBrowseButton; -public class NewFileForm extends javax.swing.JPanel { +class NewFileForm extends javax.swing.JPanel { public NewFileForm() { initComponents(); diff --git a/src/main/java/org/aerogear/plugin/intellij/mobile/ui/sdkconfig/ServiceDeployedNotification.java b/src/main/java/org/aerogear/plugin/intellij/mobile/ui/sdkconfig/ServiceDeployedNotification.java index f82b396..c1c2e7d 100644 --- a/src/main/java/org/aerogear/plugin/intellij/mobile/ui/sdkconfig/ServiceDeployedNotification.java +++ b/src/main/java/org/aerogear/plugin/intellij/mobile/ui/sdkconfig/ServiceDeployedNotification.java @@ -10,19 +10,16 @@ import org.aerogear.plugin.intellij.mobile.services.AeroGearMobileConfiguration; import org.aerogear.plugin.intellij.mobile.services.MobileNotificationsService; import org.aerogear.plugin.intellij.mobile.services.sdkconfig.SDKConfigManager; -import org.jetbrains.annotations.NotNull; -import javax.swing.event.HyperlinkEvent; +import java.util.Objects; public class ServiceDeployedNotification extends Notification { - private Project project; - private ServiceClass sc; + private final Project project; public ServiceDeployedNotification(Project project, ServiceClass sc) { super(MobileNotificationsService.AEROGEAR_NOTIFICATION_GROUP,sc.getDisplayName() + " deployment complete", "deployment", NotificationType.INFORMATION); this.project = project; - this.sc = sc; String content = this.createContent(); @@ -31,38 +28,39 @@ public ServiceDeployedNotification(Project project, ServiceClass sc) { } private String createContent() { - String sdkConfigPath = AeroGearMobileConfiguration.getInstance(this.project).getConfigPath(); - String content = ""; + String sdkConfigPath = Objects.requireNonNull(AeroGearMobileConfiguration.getInstance(this.project)).getConfigPath(); + StringBuilder content = new StringBuilder(); // TODO ADD template files if notification is redundant if (sdkConfigPath == null || sdkConfigPath.isEmpty()) { - content += "

SDK config settings are not set.

"; - content += "

If you haven't already, add sdk config file

"; - content += "

or

"; - content += "

if SDK config file exists set SDK config path setting

"; - content += "

then Update SDK config

"; + content.append("

SDK config settings are not set.

"); + content.append("

If you haven't already, add sdk config file

"); + content.append("

or

") ; + content.append("

if SDK config file exists set SDK config path setting

"); + content.append("

then Update SDK config

"); } else { - content += "Update SDK config"; + content.append("Update SDK config"); } - return content; + return content.toString(); } private NotificationListener getNotificationListener() { Project project = this.project; - return new NotificationListener() { - @Override - public void hyperlinkUpdate(@NotNull Notification notification, @NotNull HyperlinkEvent event) { - if (event.getDescription().equals("create-config")) { + return (notification, event) -> { + switch (event.getDescription()) { + case Constants.CREATE_CONFIG: new CreateConfigDialog(project).show(); - } else if (event.getDescription().equals("open-settings")) { + break; + case Constants.OPEN_SETTINGS: ShowSettingsUtil.getInstance().showSettingsDialog(project, "AeroGear Mobile"); - } else if (event.getDescription().equals("update-config")) { + break; + case Constants.UPDATE_CONFIG: try { SDKConfigManager.getInstance(project).updateSDKConfig(project); - } catch(CLIException ex) { + } catch (CLIException ex) { MobileNotificationsService.getInstance().notifyError("Error from mobile plugin: " + ex.toString()); } - } + break; } }; } diff --git a/src/main/java/org/aerogear/plugin/intellij/mobile/ui/sdkconfig/ViewSDKConfigDialog.java b/src/main/java/org/aerogear/plugin/intellij/mobile/ui/sdkconfig/ViewSDKConfigDialog.java index 9b3fc73..bce0f74 100644 --- a/src/main/java/org/aerogear/plugin/intellij/mobile/ui/sdkconfig/ViewSDKConfigDialog.java +++ b/src/main/java/org/aerogear/plugin/intellij/mobile/ui/sdkconfig/ViewSDKConfigDialog.java @@ -4,17 +4,16 @@ import org.jetbrains.annotations.Nullable; import javax.swing.*; -import java.awt.*; public class ViewSDKConfigDialog extends DialogWrapper { - private String sdkConfig; + private final String sdkConfig; public ViewSDKConfigDialog(String sdkConfig) { super(null); this.sdkConfig = sdkConfig; init(); - setTitle("SDK config"); + setTitle(Constants.SDK_CONFIG); } @Nullable diff --git a/src/main/java/org/aerogear/plugin/intellij/mobile/ui/sdkconfig/ViewSDKConfigPanel.java b/src/main/java/org/aerogear/plugin/intellij/mobile/ui/sdkconfig/ViewSDKConfigPanel.java index f105fe9..d25801f 100644 --- a/src/main/java/org/aerogear/plugin/intellij/mobile/ui/sdkconfig/ViewSDKConfigPanel.java +++ b/src/main/java/org/aerogear/plugin/intellij/mobile/ui/sdkconfig/ViewSDKConfigPanel.java @@ -2,7 +2,7 @@ import javax.swing.*; -public class ViewSDKConfigPanel extends javax.swing.JPanel { +class ViewSDKConfigPanel extends javax.swing.JPanel { public ViewSDKConfigPanel() { initComponents(); @@ -10,7 +10,7 @@ public ViewSDKConfigPanel() { private void initComponents() { - scrollPane = new javax.swing.JScrollPane(); + scrollPane = new com.intellij.ui.components.JBScrollPane(); sdkConfigDisplay = new javax.swing.JTextArea(); setLayout(new java.awt.GridLayout()); diff --git a/src/main/java/org/aerogear/plugin/intellij/mobile/ui/servicecatalog/DeployServiceDialog.java b/src/main/java/org/aerogear/plugin/intellij/mobile/ui/servicecatalog/DeployServiceDialog.java index 9c3015c..8a8d474 100644 --- a/src/main/java/org/aerogear/plugin/intellij/mobile/ui/servicecatalog/DeployServiceDialog.java +++ b/src/main/java/org/aerogear/plugin/intellij/mobile/ui/servicecatalog/DeployServiceDialog.java @@ -3,6 +3,7 @@ import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.DialogWrapper; +import com.intellij.ui.JBColor; import org.aerogear.plugin.intellij.mobile.api.CLIRunner; import org.aerogear.plugin.intellij.mobile.api.CLIRunnerImpl; import org.aerogear.plugin.intellij.mobile.api.MobileAPI; @@ -17,30 +18,31 @@ import java.awt.*; import java.util.List; -public class DeployServiceDialog extends DialogWrapper { - private Project project; - private ServiceClass sc; - private IdentityDeployment centerPanel; - private CLIRunner cliRunner = new CLIRunnerImpl(); - private MobileAPI mobileAPI = new MobileAPI(cliRunner); - private MobileNotificationsService notifier = MobileNotificationsService.getInstance(); +class DeployServiceDialog extends DialogWrapper { + private final Project project; + private final ServiceClass sc; + private final IdentityDeployment centerPanel; + private final MobileAPI mobileAPI; + private final MobileNotificationsService notifier = MobileNotificationsService.getInstance(); - protected DeployServiceDialog(Project project, ServiceClass sc) { + DeployServiceDialog(Project project, ServiceClass sc) { super(project); this.project = project; this.sc = sc; + CLIRunner cliRunner = CLIRunnerImpl.getInstance(); + mobileAPI = new MobileAPI(cliRunner); init(); setTitle(sc.getDisplayName()); + centerPanel = new IdentityDeployment(); } @Nullable @Override protected JComponent createCenterPanel() { - centerPanel = new IdentityDeployment(); - centerPanel.setBackground(Color.WHITE); - getContentPane().setBackground(Color.WHITE); + centerPanel.setBackground(JBColor.WHITE); + getContentPane().setBackground(JBColor.WHITE); getContentPanel().setBorder(BorderFactory.createEmptyBorder(0, 0, 10, 0)); return centerPanel; @@ -49,8 +51,8 @@ protected JComponent createCenterPanel() { @Override protected JComponent createSouthPanel() { JComponent sp = super.createSouthPanel(); - sp.setBorder(BorderFactory.createMatteBorder(2, 0, 0, 0, new Color(232, 232, 231))); - sp.setBackground(Color.WHITE); + sp.setBorder(BorderFactory.createMatteBorder(2, 0, 0, 0, new JBColor(new Color(232, 232, 231), JBColor.DARK_GRAY))); + sp.setBackground(JBColor.WHITE); return sp; } @@ -61,18 +63,16 @@ protected void doOKAction() { List params = this.centerPanel.getConfig(); Project project = this.project; ServiceClass sc = this.sc; - ApplicationManager.getApplication().invokeLater(() -> { - mobileAPI.createService(sc, params, new Watcher() { - @Override - public void onError(Exception e) { - notifier.notifyError("", "Error while " + sc.getServiceName() + " deployed: " + e.toString()); - } + ApplicationManager.getApplication().invokeLater(() -> mobileAPI.createService(sc, params, new Watcher() { + @Override + public void onError(Exception e) { + notifier.notifyError("", "Error while " + sc.getServiceName() + " deployed: " + e.toString()); + } - @Override - public void onSuccess(Object obj) { - notifier.notify(new ServiceDeployedNotification(project, sc)); - } - }); - }); + @Override + public void onSuccess(Object obj) { + notifier.notify(new ServiceDeployedNotification(project, sc)); + } + })); } } diff --git a/src/main/java/org/aerogear/plugin/intellij/mobile/ui/servicecatalog/ServiceListPane.java b/src/main/java/org/aerogear/plugin/intellij/mobile/ui/servicecatalog/ServiceListPane.java index 3329a21..e9a36a8 100644 --- a/src/main/java/org/aerogear/plugin/intellij/mobile/ui/servicecatalog/ServiceListPane.java +++ b/src/main/java/org/aerogear/plugin/intellij/mobile/ui/servicecatalog/ServiceListPane.java @@ -1,6 +1,7 @@ package org.aerogear.plugin.intellij.mobile.ui.servicecatalog; import com.intellij.openapi.project.Project; +import com.intellij.ui.JBColor; import com.intellij.ui.components.JBPanel; import com.intellij.ui.components.JBScrollPane; import org.aerogear.plugin.intellij.mobile.api.CLIException; @@ -12,7 +13,7 @@ import java.net.URL; public class ServiceListPane extends JBScrollPane { - private Project project; + private final Project project; public ServiceListPane(Project project, ServiceClass[] scl) throws CLIException { this.project = project; @@ -20,14 +21,14 @@ public ServiceListPane(Project project, ServiceClass[] scl) throws CLIException JBPanel view = new JBPanel(); view.setLayout(new BoxLayout(view, BoxLayout.PAGE_AXIS)); setViewportView(view); - view.withBackground(Color.WHITE); + view.withBackground(JBColor.WHITE); for (ServiceClass sc : scl) { view.add(createServicePanel(sc)); } } - public JPanel createServicePanel(ServiceClass sc) throws CLIException { + private JPanel createServicePanel(ServiceClass sc) throws CLIException { ServicePanel svcPanel = new ServicePanel(); JLabel serviceInfo = svcPanel.getServiceInfo(); URL imgSrc = null; diff --git a/src/main/java/org/aerogear/plugin/intellij/mobile/ui/servicecatalog/ServicePanel.java b/src/main/java/org/aerogear/plugin/intellij/mobile/ui/servicecatalog/ServicePanel.java index 8981b09..46cff0e 100644 --- a/src/main/java/org/aerogear/plugin/intellij/mobile/ui/servicecatalog/ServicePanel.java +++ b/src/main/java/org/aerogear/plugin/intellij/mobile/ui/servicecatalog/ServicePanel.java @@ -1,7 +1,9 @@ package org.aerogear.plugin.intellij.mobile.ui.servicecatalog; -import javax.swing.JButton; -import javax.swing.JLabel; +import com.intellij.ui.Gray; +import com.intellij.ui.JBColor; + +import javax.swing.*; /* * To change this license header, choose License Headers in Project Properties. @@ -14,7 +16,7 @@ * To edit this file, open the ServicePanel.form file in the NetBeans GUI Builder. * To view the generated source code, choose Source within the Netbeans GUI Builder. */ -public class ServicePanel extends javax.swing.JPanel { +class ServicePanel extends javax.swing.JPanel { /** * Creates new form ServicePanel @@ -35,7 +37,7 @@ private void initComponents() { serviceInfo = new javax.swing.JLabel(); deploy = new javax.swing.JButton(); - setBackground(new java.awt.Color(254, 254, 254)); + setBackground(new JBColor(Gray._254, JBColor.DARK_GRAY)); setMaximumSize(new java.awt.Dimension(32767, 70)); serviceInfo.setText("dssf"); diff --git a/src/main/java/org/aerogear/plugin/intellij/mobile/ui/servicecatalog/identity/IdentityConfigurationPanel.java b/src/main/java/org/aerogear/plugin/intellij/mobile/ui/servicecatalog/identity/IdentityConfigurationPanel.java index 3abb0b1..048c9d3 100644 --- a/src/main/java/org/aerogear/plugin/intellij/mobile/ui/servicecatalog/identity/IdentityConfigurationPanel.java +++ b/src/main/java/org/aerogear/plugin/intellij/mobile/ui/servicecatalog/identity/IdentityConfigurationPanel.java @@ -6,15 +6,17 @@ */ -import javax.swing.JComboBox; -import javax.swing.JTextField; +import com.intellij.ui.Gray; +import com.intellij.ui.JBColor; + +import javax.swing.*; /** * This class is generated by and can be edited using the Netbeans GUI Builder. * To edit this file, open the ServicePanel.form file in the NetBeans GUI Builder. * To view the generated source code, choose Source within the Netbeans GUI Builder. */ -public class IdentityConfigurationPanel extends javax.swing.JPanel { +class IdentityConfigurationPanel extends javax.swing.JPanel { /** * Creates new form KeycloakConfiguration @@ -33,31 +35,23 @@ public IdentityConfigurationPanel() { private void initComponents() { projectName = new javax.swing.JLabel(); - projectSelector = new javax.swing.JComboBox<>(); + projectSelector = new com.intellij.openapi.ui.ComboBox<>(); username = new javax.swing.JLabel(); usernameValue = new javax.swing.JTextField(); password = new javax.swing.JLabel(); passwordValue = new javax.swing.JTextField(); - setBackground(new java.awt.Color(254, 254, 254)); + setBackground(new JBColor(Gray._254, JBColor.DARK_GRAY)); setPreferredSize(new java.awt.Dimension(700, 400)); projectName.setText("* Add to Project"); projectSelector.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "myproject","mobile","myapp" })); - projectSelector.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - projectSelectorActionPerformed(evt); - } - }); + projectSelector.addActionListener(this::projectSelectorActionPerformed); username.setText("* Keycloak admin username"); - usernameValue.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - usernameValueActionPerformed(evt); - } - }); + usernameValue.addActionListener(this::usernameValueActionPerformed); password.setText("* Keycloak admin password"); diff --git a/src/main/java/org/aerogear/plugin/intellij/mobile/ui/servicecatalog/identity/IdentityDeployment.java b/src/main/java/org/aerogear/plugin/intellij/mobile/ui/servicecatalog/identity/IdentityDeployment.java index c9a4930..1225dcf 100644 --- a/src/main/java/org/aerogear/plugin/intellij/mobile/ui/servicecatalog/identity/IdentityDeployment.java +++ b/src/main/java/org/aerogear/plugin/intellij/mobile/ui/servicecatalog/identity/IdentityDeployment.java @@ -7,7 +7,7 @@ import java.util.List; public class IdentityDeployment extends JPanel implements Deployable { - private IdentityConfigurationPanel configPanel; + private final IdentityConfigurationPanel configPanel; public IdentityDeployment() { this.configPanel = new IdentityConfigurationPanel(); @@ -16,7 +16,7 @@ public IdentityDeployment() { @Override public List getConfig() { - List params = new ArrayList(); + List params = new ArrayList<>(); params.add("--namespace=" + this.configPanel.getProjectSelector().getSelectedItem()); params.add("-p ADMIN_NAME=" + this.configPanel.getUsernameValue().getText()); diff --git a/src/main/java/org/aerogear/plugin/intellij/mobile/ui/settings/AeroGearMobileConfigurable.java b/src/main/java/org/aerogear/plugin/intellij/mobile/ui/settings/AeroGearMobileConfigurable.java index 91e96ca..040d3a8 100644 --- a/src/main/java/org/aerogear/plugin/intellij/mobile/ui/settings/AeroGearMobileConfigurable.java +++ b/src/main/java/org/aerogear/plugin/intellij/mobile/ui/settings/AeroGearMobileConfigurable.java @@ -2,7 +2,6 @@ import com.intellij.openapi.fileChooser.FileChooserDescriptorFactory; import com.intellij.openapi.options.Configurable; -import com.intellij.openapi.options.ConfigurationException; import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.TextBrowseFolderListener; import com.intellij.openapi.ui.TextFieldWithBrowseButton; @@ -14,8 +13,8 @@ public class AeroGearMobileConfigurable implements Configurable { - private AeroGearMobileConfiguration config; - private Project project; + private final AeroGearMobileConfiguration config; + private final Project project; private TextFieldWithBrowseButton configPathValue; public AeroGearMobileConfigurable(Project project) { @@ -45,7 +44,7 @@ public boolean isModified() { } @Override - public void apply() throws ConfigurationException { + public void apply() { this.config.setConfigPath(this.configPathValue.getText()); } diff --git a/src/main/java/org/aerogear/plugin/intellij/mobile/ui/settings/SettingsPanel.java b/src/main/java/org/aerogear/plugin/intellij/mobile/ui/settings/SettingsPanel.java index b52cdb4..ccb85f1 100644 --- a/src/main/java/org/aerogear/plugin/intellij/mobile/ui/settings/SettingsPanel.java +++ b/src/main/java/org/aerogear/plugin/intellij/mobile/ui/settings/SettingsPanel.java @@ -4,7 +4,7 @@ import com.intellij.openapi.ui.TextFieldWithBrowseButton; -public class SettingsPanel extends javax.swing.JPanel { +class SettingsPanel extends javax.swing.JPanel { public SettingsPanel() { initComponents(); diff --git a/src/main/java/org/aerogear/plugin/intellij/mobile/utils/WriteToFileRunnable.java b/src/main/java/org/aerogear/plugin/intellij/mobile/utils/WriteToFileRunnable.java index 6e071c1..dd9d048 100644 --- a/src/main/java/org/aerogear/plugin/intellij/mobile/utils/WriteToFileRunnable.java +++ b/src/main/java/org/aerogear/plugin/intellij/mobile/utils/WriteToFileRunnable.java @@ -12,14 +12,16 @@ import com.intellij.psi.PsiManager; import com.intellij.psi.impl.file.PsiDirectoryFactory; +import java.util.Objects; + public class WriteToFileRunnable implements Runnable { - private CharSequence charSeq; - private String fileName; - private FileType fileType; - private String path; - private Project project; + private final CharSequence charSeq; + private final String fileName; + private final FileType fileType; + private final String path; + private final Project project; public WriteToFileRunnable(Project project, String path, CharSequence cs, String fileName, FileType fileType) { @@ -43,8 +45,8 @@ public void run() { } else { PsiFile psiFile = PsiManager.getInstance(this.project).findFile(existingFile); - Document document = PsiDocumentManager.getInstance(this.project).getDocument(psiFile); - document.setText(this.charSeq); + Document document = PsiDocumentManager.getInstance(this.project).getDocument(Objects.requireNonNull(psiFile)); + Objects.requireNonNull(document).setText(this.charSeq); } } diff --git a/src/test/java/MobileAPITest.java b/src/test/java/MobileAPITest.java index 985563b..b585037 100644 --- a/src/test/java/MobileAPITest.java +++ b/src/test/java/MobileAPITest.java @@ -10,9 +10,9 @@ public class MobileAPITest { @Test - public void testGetServices_ok() throws Exception { + public void testGetServices_ok() { CLIRunner runner = mock(CLIRunner.class); - when(runner.executeSync(anyList() )).thenReturn("{\n" + when(runner.executeSync(anyList() )).thenReturn("{\n" // TODO ADD testing assets here and NOT use strings + " \"metadata\": {},\n" + " \"items\": [\n" + " {\n" @@ -60,7 +60,7 @@ public void testGetServices_ok() throws Exception { } @Test(expectedExceptions = CLIException.class) - public void testGetServices_exception()throws Exception{ + public void testGetServices_exception() { CLIRunner runner = mock(CLIRunner.class); when(runner.executeSync(anyList())).thenThrow(new CLIException("failed to execute command")); MobileAPI api = new MobileAPI(runner); @@ -81,7 +81,7 @@ public void testGetServices_handles_bad_input()throws CLIException{ public void testCreateClient_ok()throws CLIException{ CLIRunner runner = mock(CLIRunner.class); MobileAPI api = new MobileAPI(runner); - when(runner.executeSync(anyList())).thenReturn("{\n" + when(runner.executeSync(anyList())).thenReturn("{\n" // TODO ADD testing assets here and NOT use strings + "\t\"kind\": \"MobileClient\",\n" + "\t\"apiVersion\": \"mobile.k8s.io/v1alpha1\",\n" + "\t\"metadata\": {\n"