Skip to content
Merged
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
@@ -1,5 +1,7 @@
package com.jfrog.ide.eclipse.configuration;

import java.util.HashMap;
import java.util.Map;
/**
* Constant definitions for plug-in preferences
*
Expand All @@ -12,6 +14,7 @@ public class PreferenceConstants {
public static final String XRAY_URL = "URL";
public static final String XRAY_USERNAME = "Username";
public static final String XRAY_PASSWORD = "Password";
public static final String DEBUG_LOGS = "DebugLogs";

// Connection constants
public static final int CONNECTION_TIMEOUT_MILLISECONDS = 300 * 1000;
Expand All @@ -20,4 +23,13 @@ public class PreferenceConstants {
// Eclipse Buildship plugins
public static final String GRADLE_PLUGIN_QUALIFIER = "org.eclipse.buildship.core";
public static final String GRADLE_DISTRIBUTION = "gradle.distribution";


public static Map<String, String> getCliDebugLogsEnvVars(){
Map<String, String> envVars = new HashMap<>();
envVars.put("JFROG_CLI_LOG_LEVEL", "DEBUG");
envVars.put("CI", "true");

return envVars;
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package com.jfrog.ide.eclipse.configuration;

import java.util.HashMap;
import java.util.Map;

import org.eclipse.core.runtime.ICoreRunnable;
import org.eclipse.core.runtime.preferences.ConfigurationScope;
import org.eclipse.jface.preference.BooleanFieldEditor;
import org.eclipse.jface.preference.FieldEditorPreferencePage;
import org.eclipse.jface.preference.PreferenceDialog;
import org.eclipse.jface.preference.StringFieldEditor;
Expand All @@ -11,10 +15,10 @@
import org.eclipse.ui.dialogs.PreferencesUtil;
import org.eclipse.ui.preferences.ScopedPreferenceStore;

import com.jfrog.ide.eclipse.log.Logger;
import com.jfrog.ide.eclipse.scheduling.CliJob;
import com.jfrog.ide.eclipse.ui.ComponentDetails;
import com.jfrog.ide.eclipse.ui.issues.ComponentIssueDetails;

/**
* Panel for configuring Xray URL, username and password.
*
Expand All @@ -40,6 +44,7 @@ public void createFieldEditors() {
addField(usernameEditor);
addField(passwordEditor);
addField(new TestConnectionButton(urlEditor, usernameEditor, passwordEditor, getFieldEditorParent()));
addField(new BooleanFieldEditor(PreferenceConstants.DEBUG_LOGS, "Generate Debug Logs", getFieldEditorParent()));
}

@Override
Expand All @@ -48,9 +53,20 @@ public boolean performOk() {
if (!XrayServerConfigImpl.getInstance().areCredentialsSet()) {
return true;
}

final Map<String, String> configEnv;

// define log level
if (XrayServerConfigImpl.getInstance().getIsDebugLogs()) {
Logger.getInstance().setLogLevel(Logger.DEBUG);
configEnv = PreferenceConstants.getCliDebugLogsEnvVars();
} else {
Logger.getInstance().setLogLevel(Logger.INFO);
configEnv = new HashMap<>();
}

// Define the runnable to execute the CLI config command
ICoreRunnable runnable = monitor -> {
ICoreRunnable runnableServerConfig = monitor -> {
try {
CliDriverWrapper.getInstance().getCliDriver().addCliServerConfig(
XrayServerConfigImpl.getInstance().getXrayUrl(),
Expand All @@ -60,27 +76,22 @@ public boolean performOk() {
XrayServerConfigImpl.getInstance().getPassword(),
XrayServerConfigImpl.getInstance().getAccessToken(),
CliDriverWrapper.HOME_PATH.toFile(),
System.getenv()
configEnv
);
} catch (Exception e) {
CliDriverWrapper.getInstance().showCliError("An error occurred while setting up the server connection:", e);
}
};

// Schedule the CliJob to execute the runnable
CliJob.doSchedule("Setup Server Configuration", runnable);

boolean doQuickScan = false;
CliJob.doSchedule("Setup Server Configuration", runnableServerConfig);

ComponentDetails[] componentsDetails = { ComponentIssueDetails.getInstance()};
for (ComponentDetails componentsDetail : componentsDetails) {
if (componentsDetail != null) {
componentsDetail.credentialsSet();
doQuickScan = true;
}
}
if (doQuickScan) {
// TODO: run a scan using the ScanManager
}
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
*/
@SuppressWarnings("restriction")
public class XrayServerConfigImpl implements ServerConfig {
// TODO: adjust implementation for configuring server using JfrogCliDriver

private static XrayServerConfigImpl instance;
private IPreferencesService service = Platform.getPreferencesService();

Expand All @@ -48,6 +46,10 @@ public String getUsername() {
public String getPassword() {
return getValue(PreferenceConstants.XRAY_PASSWORD);
}

public boolean getIsDebugLogs() {
return getValue(PreferenceConstants.DEBUG_LOGS) == "true";
}

private String getValue(String key) {
return trim(service.getString(PreferenceConstants.XRAY_QUALIFIER, key, "", null));
Expand Down Expand Up @@ -110,32 +112,32 @@ public boolean isInsecureTls() {

@Override
public String getAccessToken() {
// TODO Auto-generated method stub
// This functionality is not yet implemented by the plug-in.
return null;
}

@Override
public String getExternalResourcesRepo() {
// TODO Auto-generated method stub
// This functionality is not yet implemented by the plug-in.
return null;
}

@Override
public PolicyType getPolicyType() {
// TODO Auto-generated method stub
// This functionality is not yet implemented by the plug-in.
return null;
}

@Override
public String getProject() {
// TODO Auto-generated method stub
// This functionality is not yet implemented by the plug-in.
return null;
}

@Override
public String getWatches() {
// TODO Auto-generated method stub
// This functionality is not yet implemented by the plug-in.
return null;
}

}
}
36 changes: 30 additions & 6 deletions bundle/src/main/java/com/jfrog/ide/eclipse/log/Logger.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ public class Logger implements Log {
private static Logger instance;
private static ProblemsLogger viewLogger;
private final String ID = "jfrog-eclipse-plugin";

public static final int DEBUG = 1;
public static final int INFO = 2;
public static final int WARN = 3;
public static final int ERROR = 4;

//set default log level as INFO
private int minLogLevel = INFO;

private Logger() {
ilog = ResourcesPlugin.getPlugin().getLog();
Expand All @@ -23,16 +31,23 @@ public static Logger getInstance() {
}
return instance;
}

public void setLogLevel(int logLevel) {
this.minLogLevel = logLevel;
}

public int getLogLevel() {
return minLogLevel;
}

@Override
public void debug(String message) {
ilog.log(new Status(Status.OK, ID, "[OK] " + message));
log(DEBUG, Status.OK, "[DEBUG] ", message);
}

@Override
public void error(String message) {
ilog.log(new Status(Status.ERROR, ID, "[ERROR] " + message));
logToProblemsLogger(message, Status.ERROR);
log(ERROR, Status.ERROR, "[ERROR] ", message);
}

@Override
Expand All @@ -43,14 +58,23 @@ public void error(String message, Throwable t) {

@Override
public void info(String message) {
ilog.log(new Status(Status.INFO, ID, "[INFO] " + message));
log(INFO, Status.INFO, "[INFO] ", message);
}

@Override
public void warn(String message) {
ilog.log(new Status(Status.WARNING, ID, "[WARN] " + message));
logToProblemsLogger(message, Status.WARNING);
log(WARN, Status.WARNING, "[WARN] ", message);
}

private void log(int level, int status, String prefix, String message) {
if (minLogLevel > level) {
return;
}
ilog.log(new Status(status, ID, prefix + message));
if (status == Status.WARNING || status == Status.ERROR) {
logToProblemsLogger(message, status);
}
}

private void logToProblemsLogger(String message, int status) {
if (viewLogger == null) {
Expand Down
41 changes: 41 additions & 0 deletions bundle/src/main/java/com/jfrog/ide/eclipse/scan/ScanCache.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.jfrog.ide.eclipse.scan;

import java.util.ArrayList;
import java.util.List;

import com.jfrog.ide.common.nodes.FileTreeNode;

public class ScanCache {
private List<FileTreeNode> scanResults;

private static ScanCache instance;

private ScanCache() {
scanResults = new ArrayList<FileTreeNode>();
}

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

public List<FileTreeNode> getScanResults() {
return scanResults;
}

public void updateScanResults(List<FileTreeNode> results) {
if (results != null) {
scanResults.addAll(results);
}
}

public void resetCache() {
scanResults = new ArrayList<FileTreeNode>();
}
}
Loading