Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package com.jfrog.ide.eclipse.configuration;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import org.eclipse.jface.dialogs.ErrorDialog;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;

import com.jfrog.ide.common.configuration.JfrogCliDriver;
import com.jfrog.ide.eclipse.log.Logger;

public class CliDriverWrapper {

private static CliDriverWrapper instance;

public static final String CLIENT_ID_SERVER = "eclipse";
public static final String CLI_VERSION = "2.74.1";
public static final Path HOME_PATH = Paths.get(System.getProperty("user.home"), ".jfrog-eclipse-plugin");

private JfrogCliDriver cliDriver;

private CliDriverWrapper() {
try {
Files.createDirectories(HOME_PATH);
} catch (Exception e) {
showCliError("An error occurred while creating the JFrog Eclipse plugin directory:",e);
}
// Initialize the cliDriver and download CLI if needed
this.cliDriver = new JfrogCliDriver(null, Logger.getInstance());
try {
this.cliDriver.downloadCliIfNeeded(HOME_PATH.toString(), CLI_VERSION);
} catch (IOException e) {
showCliError("An error occurred while downloading the JFrog cli:",e);
}
}

public static CliDriverWrapper getInstance() {
if (instance == null) {
synchronized (CliDriverWrapper.class) {
if (instance == null) {
instance = new CliDriverWrapper();
}
}
}
return instance;
}

public JfrogCliDriver getCliDriver() {
return cliDriver;
}

public void showCliError(String errorTitle,Exception e) {
Logger.getInstance().error(e.getMessage(), e);
IStatus status = new Status(IStatus.ERROR, "jfrog-eclipse-plugin",e.getMessage(), e);

// Run UI-related code on the main UI thread
Display.getDefault().asyncExec(() -> {
Shell shell = Display.getDefault().getActiveShell();
if (shell != null) {
ErrorDialog.openError(shell, "Error", errorTitle, status);
}
});
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.jfrog.ide.eclipse.configuration;

import java.nio.file.Path;
import java.nio.file.Paths;
import org.eclipse.core.runtime.preferences.ConfigurationScope;
import org.eclipse.jface.preference.FieldEditorPreferencePage;
import org.eclipse.jface.preference.PreferenceDialog;
Expand All @@ -17,7 +19,7 @@

/**
* Panel for configuring Xray URL, username and password.
*
*
* @author yahavi
*/
public class XrayGlobalConfiguration extends FieldEditorPreferencePage implements IWorkbenchPreferencePage {
Expand Down Expand Up @@ -48,6 +50,20 @@ public boolean performOk() {
if (!XrayServerConfigImpl.getInstance().areCredentialsSet()) {
return true;
}
try{
CliDriverWrapper.getInstance();
CliDriverWrapper.getInstance().getCliDriver().addCliServerConfig(
XrayServerConfigImpl.getInstance().getXrayUrl(),
XrayServerConfigImpl.getInstance().getArtifactoryUrl(),
CliDriverWrapper.CLIENT_ID_SERVER,
XrayServerConfigImpl.getInstance().getUsername(),
XrayServerConfigImpl.getInstance().getPassword(),
CliDriverWrapper.HOME_PATH.toFile()
);
}
catch (Exception e){
CliDriverWrapper.getInstance().showCliError("An error occurred while Setting up the server connection:",e);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can maybe save all the error texts in a const and call to it.
i dont really care but we can do that if you want

}
boolean doQuickScan = false;
ComponentDetails[] componentsDetails = { ComponentIssueDetails.getInstance(), ComponentLicenseDetails.getInstance() };
for (ComponentDetails componentsDetail : componentsDetails) {
Expand Down