-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: configure settings to exhort api
- Loading branch information
Showing
5 changed files
with
312 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
152 changes: 152 additions & 0 deletions
152
src/main/java/org/jboss/tools/intellij/settings/ApiSettingsComponent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,152 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2023 Red Hat, Inc. | ||
* Distributed under license by Red Hat, Inc. All rights reserved. | ||
* This program is made available under the terms of the | ||
* Eclipse Public License v2.0 which accompanies this distribution, | ||
* and is available at http://www.eclipse.org/legal/epl-v20.html | ||
* | ||
* Contributors: | ||
* Red Hat, Inc. - initial API and implementation | ||
******************************************************************************/ | ||
|
||
package org.jboss.tools.intellij.settings; | ||
|
||
import com.intellij.openapi.fileChooser.FileChooserDescriptorFactory; | ||
import com.intellij.openapi.ui.TextComponentAccessor; | ||
import com.intellij.openapi.ui.TextFieldWithBrowseButton; | ||
import com.intellij.ui.components.JBLabel; | ||
import com.intellij.ui.components.JBTextField; | ||
import com.intellij.util.ui.FormBuilder; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import javax.swing.*; | ||
|
||
public class ApiSettingsComponent { | ||
|
||
private final static String mvnPathLabel = "<html>Maven > Executable: <b>Path</b>" | ||
+ "<br>Specifies absolute path of <b>mvn</b> executable.</html>"; | ||
private final static String javaPathLabel = "<html>Maven > JAVA_HOME: <b>Path</b>" | ||
+ "<br>Specifies absolute path of Java installation directory.</html>"; | ||
private final static String npmPathLabel = "<html>Npm > Executable: <b>Path</b>" | ||
+ "<br>Specifies absolute path of <b>npm</b> executable.</html>"; | ||
private final static String nodePathLabel = "<html>Node > Executable: <b>Path</b>" | ||
+ "<br>Specifies absolute path of the <i>directory</i> containing <b>node</b> executable.</html>"; | ||
private final static String snykTokenLabel = "<html>Red Hat Dependency Analytics: <b>Exhort Snyk Token</b>" | ||
+ "<br>Red Hat Dependency Analytics sever authentication token for Snky.</html>"; | ||
|
||
private final JPanel mainPanel; | ||
|
||
private final TextFieldWithBrowseButton mvnPathText; | ||
private final TextFieldWithBrowseButton javaPathText; | ||
private final TextFieldWithBrowseButton npmPathText; | ||
private final TextFieldWithBrowseButton nodePathText; | ||
private final JBTextField snykTokenText; | ||
|
||
public ApiSettingsComponent() { | ||
mvnPathText = new TextFieldWithBrowseButton(); | ||
mvnPathText.addBrowseFolderListener( | ||
null, | ||
null, | ||
null, | ||
FileChooserDescriptorFactory.createSingleFileDescriptor(), | ||
TextComponentAccessor.TEXT_FIELD_WHOLE_TEXT | ||
); | ||
|
||
javaPathText= new TextFieldWithBrowseButton(); | ||
javaPathText.addBrowseFolderListener( | ||
null, | ||
null, | ||
null, | ||
FileChooserDescriptorFactory.createSingleFolderDescriptor(), | ||
TextComponentAccessor.TEXT_FIELD_WHOLE_TEXT | ||
); | ||
|
||
npmPathText = new TextFieldWithBrowseButton(); | ||
npmPathText.addBrowseFolderListener( | ||
null, | ||
null, | ||
null, | ||
FileChooserDescriptorFactory.createSingleFileDescriptor(), | ||
TextComponentAccessor.TEXT_FIELD_WHOLE_TEXT | ||
); | ||
|
||
nodePathText = new TextFieldWithBrowseButton(); | ||
nodePathText.addBrowseFolderListener( | ||
null, | ||
null, | ||
null, | ||
FileChooserDescriptorFactory.createSingleFolderDescriptor(), | ||
TextComponentAccessor.TEXT_FIELD_WHOLE_TEXT | ||
); | ||
|
||
snykTokenText = new JBTextField(); | ||
|
||
mainPanel = FormBuilder.createFormBuilder() | ||
.addLabeledComponent(new JBLabel(mvnPathLabel), mvnPathText, 1, true) | ||
.addVerticalGap(10) | ||
.addLabeledComponent(new JBLabel(javaPathLabel), javaPathText, 1, true) | ||
.addSeparator(10) | ||
.addVerticalGap(10) | ||
.addLabeledComponent(new JBLabel(npmPathLabel), npmPathText, 1, true) | ||
.addVerticalGap(10) | ||
.addLabeledComponent(new JBLabel(nodePathLabel), nodePathText, 1, true) | ||
.addSeparator(10) | ||
.addVerticalGap(10) | ||
.addLabeledComponent(new JBLabel(snykTokenLabel), snykTokenText, 1, true) | ||
.addComponentFillVertically(new JPanel(), 0) | ||
.getPanel(); | ||
} | ||
|
||
public JPanel getPanel() { | ||
return mainPanel; | ||
} | ||
|
||
public JComponent getPreferredFocusedComponent() { | ||
return mvnPathText; | ||
} | ||
|
||
@NotNull | ||
public String getMvnPathText() { | ||
return mvnPathText.getText(); | ||
} | ||
|
||
public void setMvnPathText(@NotNull String text) { | ||
mvnPathText.setText(text); | ||
} | ||
|
||
@NotNull | ||
public String getJavaPathText() { | ||
return javaPathText.getText(); | ||
} | ||
|
||
public void setJavaPathText(@NotNull String text) { | ||
javaPathText.setText(text); | ||
} | ||
|
||
@NotNull | ||
public String getNpmPathText() { | ||
return npmPathText.getText(); | ||
} | ||
|
||
public void setNpmPathText(@NotNull String text) { | ||
npmPathText.setText(text); | ||
} | ||
|
||
@NotNull | ||
public String getNodePathText() { | ||
return nodePathText.getText(); | ||
} | ||
|
||
public void setNodePathText(@NotNull String text) { | ||
nodePathText.setText(text); | ||
} | ||
|
||
@NotNull | ||
public String getSnykTokenText() { | ||
return snykTokenText.getText(); | ||
} | ||
|
||
public void setSnykTokenText(@NotNull String text) { | ||
snykTokenText.setText(text); | ||
} | ||
} |
74 changes: 74 additions & 0 deletions
74
src/main/java/org/jboss/tools/intellij/settings/ApiSettingsConfigurable.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2023 Red Hat, Inc. | ||
* Distributed under license by Red Hat, Inc. All rights reserved. | ||
* This program is made available under the terms of the | ||
* Eclipse Public License v2.0 which accompanies this distribution, | ||
* and is available at http://www.eclipse.org/legal/epl-v20.html | ||
* | ||
* Contributors: | ||
* Red Hat, Inc. - initial API and implementation | ||
******************************************************************************/ | ||
|
||
package org.jboss.tools.intellij.settings; | ||
|
||
import com.intellij.openapi.util.NlsContexts; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import javax.swing.*; | ||
|
||
public class ApiSettingsConfigurable implements com.intellij.openapi.options.Configurable { | ||
|
||
private ApiSettingsComponent settingsComponent; | ||
|
||
@Override | ||
public @NlsContexts.ConfigurableName String getDisplayName() { | ||
return "Red Hat Dependency Analytics"; | ||
} | ||
|
||
@Override | ||
public @Nullable JComponent createComponent() { | ||
settingsComponent = new ApiSettingsComponent(); | ||
return settingsComponent.getPanel(); | ||
} | ||
|
||
@Override | ||
public JComponent getPreferredFocusedComponent() { | ||
return settingsComponent.getPreferredFocusedComponent(); | ||
} | ||
|
||
@Override | ||
public boolean isModified() { | ||
ApiSettingsState settings = ApiSettingsState.getInstance(); | ||
boolean modified = !settingsComponent.getMvnPathText().equals(settings.mvnPath); | ||
modified |= !settingsComponent.getJavaPathText().equals(settings.javaPath); | ||
modified |= !settingsComponent.getNpmPathText().equals(settings.npmPath); | ||
modified |= !settingsComponent.getNodePathText().equals(settings.nodePath); | ||
modified |= !settingsComponent.getSnykTokenText().equals(settings.snykToken); | ||
return modified; | ||
} | ||
|
||
@Override | ||
public void apply() { | ||
ApiSettingsState settings = ApiSettingsState.getInstance(); | ||
settings.mvnPath = settingsComponent.getMvnPathText(); | ||
settings.javaPath = settingsComponent.getJavaPathText(); | ||
settings.npmPath = settingsComponent.getNpmPathText(); | ||
settings.nodePath = settingsComponent.getNodePathText(); | ||
settings.snykToken = settingsComponent.getSnykTokenText(); | ||
} | ||
|
||
@Override | ||
public void reset() { | ||
ApiSettingsState settings = ApiSettingsState.getInstance(); | ||
settingsComponent.setMvnPathText(settings.mvnPath); | ||
settingsComponent.setJavaPathText(settings.javaPath); | ||
settingsComponent.setNpmPathText(settings.npmPath); | ||
settingsComponent.setNodePathText(settings.nodePath); | ||
settingsComponent.setSnykTokenText(settings.snykToken); | ||
} | ||
|
||
@Override | ||
public void disposeUIResources() { | ||
settingsComponent = null; | ||
} | ||
} |
77 changes: 77 additions & 0 deletions
77
src/main/java/org/jboss/tools/intellij/settings/ApiSettingsState.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2023 Red Hat, Inc. | ||
* Distributed under license by Red Hat, Inc. All rights reserved. | ||
* This program is made available under the terms of the | ||
* Eclipse Public License v2.0 which accompanies this distribution, | ||
* and is available at http://www.eclipse.org/legal/epl-v20.html | ||
* | ||
* Contributors: | ||
* Red Hat, Inc. - initial API and implementation | ||
******************************************************************************/ | ||
|
||
package org.jboss.tools.intellij.settings; | ||
|
||
import com.intellij.openapi.application.ApplicationManager; | ||
import com.intellij.openapi.components.*; | ||
import com.intellij.util.xmlb.XmlSerializerUtil; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
@State( | ||
name = "org.jboss.tools.intellij.settings.ApiSettingsState", | ||
storages = @Storage( | ||
value = "rhda.exhort.xml", | ||
roamingType = RoamingType.DISABLED | ||
) | ||
) | ||
@Service(Service.Level.APP) | ||
public final class ApiSettingsState implements PersistentStateComponent<ApiSettingsState> { | ||
|
||
public static ApiSettingsState getInstance() { | ||
return ApplicationManager.getApplication().getService(ApiSettingsState.class); | ||
} | ||
|
||
public String mvnPath; | ||
public String javaPath; | ||
public String npmPath; | ||
public String nodePath; | ||
public String snykToken; | ||
|
||
@Override | ||
public @Nullable ApiSettingsState getState() { | ||
return this; | ||
} | ||
|
||
@Override | ||
public void loadState(@NotNull ApiSettingsState state) { | ||
XmlSerializerUtil.copyBean(state, this); | ||
} | ||
|
||
public void setApiOptions() { | ||
if (mvnPath != null && !mvnPath.isBlank()) { | ||
System.setProperty("EXHORT_MVN_PATH", mvnPath); | ||
} else { | ||
System.clearProperty("EXHORT_MVN_PATH"); | ||
} | ||
if (javaPath != null && !javaPath.isBlank()) { | ||
System.setProperty("JAVA_HOME", javaPath); | ||
} else { | ||
System.clearProperty("JAVA_HOME"); | ||
} | ||
if (npmPath != null && !npmPath.isBlank()) { | ||
System.setProperty("EXHORT_NPM_PATH", npmPath); | ||
} else { | ||
System.clearProperty("EXHORT_NPM_PATH"); | ||
} | ||
if (nodePath != null && !nodePath.isBlank()) { | ||
System.setProperty("NODE_HOME", nodePath); | ||
} else { | ||
System.clearProperty("NODE_HOME"); | ||
} | ||
if (snykToken != null && !snykToken.isBlank()) { | ||
System.setProperty("EXHORT_SNYK_TOKEN", snykToken); | ||
} else { | ||
System.clearProperty("EXHORT_SNYK_TOKEN"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters