Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrading plugin dependencies to include 'Critical' severity #25

Merged
merged 24 commits into from
Dec 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
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
2 changes: 1 addition & 1 deletion bundle/.classpath
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@
<classpathentry kind="src" path="src/main/java"/>
<classpathentry exported="true" kind="lib" path="lib/ide-plugins-common.jar"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>
</classpath>
Binary file added bundle/icons/critical.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified bundle/icons/default.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified bundle/icons/high.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified bundle/icons/low.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified bundle/icons/medium.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified bundle/icons/normal.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified bundle/icons/unknown.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 5 additions & 1 deletion bundle/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,14 @@
<id>releases</id>
<url>https://releases.jfrog.io/artifactory/oss-releases</url>
</repository>
<repository>
<id>gradle</id>
<url>https://repo.gradle.org/gradle/libs-releases</url>
</repository>
</repositories>

<properties>
<ide-plugins-common-version>1.1.1</ide-plugins-common-version>
<ide-plugins-common-version>1.6.1</ide-plugins-common-version>
</properties>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@ public class PreferenceConstants {
public static final String XRAY_URL = "URL";
public static final String XRAY_USERNAME = "Username";
public static final String XRAY_PASSWORD = "Password";

// Connection constants
public static final int CONNECTION_TIMEOUT_MILLISECONDS = 300 * 1000;
public static final int CONNECTION_RETRIES = 5;

// Eclipse Buildship plugins
public static final String GRADLE_PLUGIN_QUALIFIER = "org.eclipse.buildship.core";
public static final String GRADLE_DISTRIBUTION = "gradle.distribution";

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.jfrog.client.http.model.ProxyConfig;
import org.osgi.framework.FrameworkUtil;

import com.jfrog.ide.common.utils.XrayConnectionUtils;
import com.jfrog.xray.client.Xray;
import com.jfrog.xray.client.impl.XrayClient;
import com.jfrog.xray.client.impl.XrayClientBuilder;
import com.jfrog.xray.client.services.system.Version;
import com.jfrog.ide.eclipse.log.Logger;

/**
* Button in the configuration panel for testing connection with Xray.
Expand Down Expand Up @@ -79,16 +79,28 @@ protected void doStore() {
public int getNumberOfControls() {
return 1;
}

private Xray createXrayClient() {
String url = urlEditor.getStringValue();
String xrayUrl = url.endsWith("/") ? url + "xray" : url + "/xray";
XrayServerConfigImpl serverConfig = XrayServerConfigImpl.getInstance();

return (Xray) new XrayClientBuilder()
.setUrl(xrayUrl)
.setUserName(usernameEditor.getStringValue())
.setPassword(passwordEditor.getStringValue())
.setUserAgent(USER_AGENT)
.setProxyConfiguration(serverConfig.getProxyConfForTargetUrl(xrayUrl))
.setLog(Logger.getInstance())
.build();
}

private class ButtonSelection extends SelectionAdapter {
@Override
public void widgetSelected(SelectionEvent e) {
try {
connectionResults.setText("Connecting to Xray...");
String url = urlEditor.getStringValue();
ProxyConfig proxyConfig = XrayServerConfigImpl.getInstance().getProxyConfForTargetUrl(url);
Xray xrayClient = XrayClient.create(url, usernameEditor.getStringValue(),
passwordEditor.getStringValue(), USER_AGENT, false, proxyConfig);
Xray xrayClient = createXrayClient();
Version xrayVersion = xrayClient.system().version();

if (!XrayConnectionUtils.isXrayVersionSupported(xrayVersion)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,24 @@

import java.net.URI;

import javax.net.ssl.SSLContext;

import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
import org.eclipse.core.internal.net.ProxyManager;
import org.eclipse.core.net.proxy.IProxyData;
import org.eclipse.core.net.proxy.IProxyService;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.preferences.IPreferencesService;
import org.jfrog.client.http.model.ProxyConfig;
import org.jfrog.build.client.ProxyConfiguration;

import com.jfrog.ide.common.configuration.XrayServerConfig;
import com.jfrog.ide.common.configuration.ServerConfig;

/**
* @author yahavi
*/
@SuppressWarnings("restriction")
public class XrayServerConfigImpl implements XrayServerConfig {
public class XrayServerConfigImpl implements ServerConfig {

private static XrayServerConfigImpl instance;
private IPreferencesService service = Platform.getPreferencesService();
Expand Down Expand Up @@ -51,21 +53,58 @@ private String getValue(String key) {
}

@Override
public ProxyConfig getProxyConfForTargetUrl(String xrayUrl) {
public ProxyConfiguration getProxyConfForTargetUrl(String xrayUrl) {
xrayUrl = StringUtils.defaultIfBlank(xrayUrl, getUrl());
IProxyService service = ProxyManager.getProxyManager();
IProxyData[] proxyData = service.select(URI.create(xrayUrl));
if (ArrayUtils.isEmpty(proxyData)) {
return null;
}

ProxyConfig proxyConfig = new ProxyConfig();
proxyConfig.setHost(trim(proxyData[0].getHost()));
proxyConfig.setPort(proxyData[0].getPort());
ProxyConfiguration proxyConfig = new ProxyConfiguration();
proxyConfig.host = trim(proxyData[0].getHost());
proxyConfig.port = proxyData[0].getPort();
if (proxyData[0].isRequiresAuthentication()) {
proxyConfig.setUsername(trim(proxyData[0].getUserId()));
proxyConfig.setPassword(proxyData[0].getPassword());
proxyConfig.username = trim(proxyData[0].getUserId());
proxyConfig.password = proxyData[0].getPassword();
}
return proxyConfig;
}

@Override
kerenr-jfrog marked this conversation as resolved.
Show resolved Hide resolved
public String getXrayUrl() {
String url = getUrl();
String xrayUrl = url.endsWith("/") ? url + "xray" : url + "/xray";
return xrayUrl;
}

@Override
public String getArtifactoryUrl() {
String url = getUrl();
String artifactoryUrl = url.endsWith("/") ? url + "artifactory" : url + "/artifactory";
return artifactoryUrl;
}

@Override
public int getConnectionRetries() {
return PreferenceConstants.CONNECTION_RETRIES;
}

@Override
public int getConnectionTimeout() {
return PreferenceConstants.CONNECTION_TIMEOUT_MILLISECONDS;
}

@Override
public SSLContext getSslContext() {
// This method is not used by the plug-in.
return null;
}

@Override
public boolean isInsecureTls() {
// This method is not used by the plug-in.
return false;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import java.util.Set;

import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
import org.eclipse.buildship.core.GradleDistribution;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
Expand All @@ -23,20 +22,23 @@
import org.gradle.tooling.ProgressEvent;
import org.gradle.tooling.ProgressListener;
import org.gradle.tooling.ProjectConnection;
import org.jfrog.build.extractor.scan.DependenciesTree;
import org.jfrog.build.extractor.scan.DependencyTree;
import org.jfrog.build.extractor.scan.GeneralInfo;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.collect.Sets;
import com.jfrog.ide.common.scan.ComponentPrefix;
import com.jfrog.ide.common.gradle.GradleTreeBuilder;
import com.jfrog.ide.eclipse.configuration.PreferenceConstants;
import com.jfrog.ide.eclipse.log.Logger;
import com.jfrog.ide.eclipse.utils.GradleArtifact;

public class GradleScanManager extends ScanManager {

private static final String TASK_NAME = "generateDependenciesGraphAsJson";
public static final String GRADLE_INIT_SCRIPT = "dependencies.gradle";
public static final String GRADLESCRIPTDIR = "gradleScript";
private final GradleTreeBuilder gradleTreeBuilder;

private static ObjectMapper objectMapper = new ObjectMapper();
private GradleArtifact gradleArtifact;
Expand All @@ -45,6 +47,7 @@ public class GradleScanManager extends ScanManager {
public GradleScanManager(IProject project) throws IOException {
super(project, ComponentPrefix.GAV);
getLog().info("Found Gradle project: " + getProjectName());
gradleTreeBuilder = new GradleTreeBuilder(project.getLocation().toFile().toPath(), System.getenv());
}

public static boolean isApplicable(IProject project) {
Expand All @@ -56,40 +59,14 @@ public static boolean isApplicable(IProject project) {
}

@Override
void refreshDependencies(IProgressMonitor monitor) throws IOException {
this.monitor = monitor;
String rootProjectDir = project.getLocation().toPortableString();
if (project.getLocation().toFile().isDirectory()) {
rootProjectDir = project.getLocation().addTrailingSeparator().toPortableString();
void buildTree() throws IOException {
try {
setScanResults(gradleTreeBuilder.buildTree(getLog()));
}
catch (IOException ex) {
Logger.getInstance().warn("Could not scan project: " + getProjectName() + ". Reason is: " + ex.getMessage());
}

String gradleFileNameFullPath = "/gradle/" + GRADLE_INIT_SCRIPT;
ClassLoader classLoader = GradleScanManager.class.getClassLoader();
// classLoader.getResourceAsStream(gradleFileNameFullPath) will work on all the
// OSes
try (InputStream res = classLoader.getResourceAsStream(gradleFileNameFullPath)) {
String gradleFile = createGradleFile(res);
if (StringUtils.isBlank(gradleFile)) {
getLog().warn("Gradle init script wasn't created.");
return;
}
generateDependenciesGraphAsJsonTask(rootProjectDir, gradleFile);
parseJsonResult();
}
}

@Override
void buildTree() {
DependenciesTree rootNode = new DependenciesTree(getProjectName());
GeneralInfo generalInfo = new GeneralInfo();
generalInfo.groupId(gradleArtifact.getGroupId()).artifactId(gradleArtifact.getArtifactId())
.version(gradleArtifact.getVersion());
rootNode.setGeneralInfo(generalInfo);
GradleArtifact[] dependencies = gradleArtifact.getDependencies();
if (ArrayUtils.isNotEmpty(dependencies)) {
populateDependenciesTree(rootNode, dependencies);
}
setScanResults(rootNode);
}

public GradleArtifact getGradleArtifact() {
Expand All @@ -108,14 +85,15 @@ private String getComponentId(GradleArtifact gradleArtifact) {
}

/**
* Populate root modules DependenciesTree with issues, licenses and general info
* Populate root modules DependencyTree with issues, licenses and general info
* from the scan cache.
*/
private void populateDependenciesTree(DependenciesTree scanTreeNode, GradleArtifact[] gradleArtifacts) {
@SuppressWarnings("unused")
private void populateDependenciesTree(DependencyTree scanTreeNode, GradleArtifact[] gradleArtifacts) {
for (GradleArtifact artifact : gradleArtifacts) {
String componentId = getComponentId(artifact);
DependenciesTree child = new DependenciesTree(componentId);
child.setGeneralInfo(new GeneralInfo(componentId, "", "", "Maven"));
DependencyTree child = new DependencyTree(componentId);
child.setGeneralInfo(new GeneralInfo(componentId, artifact.getArtifactId(), "", "Gradle"));
scanTreeNode.add(child);
populateDependenciesTree(child, artifact.getDependencies());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@
import org.eclipse.m2e.core.project.IMavenProjectFacade;
import org.eclipse.m2e.core.project.MavenProjectChangedEvent;
import org.eclipse.swt.widgets.Composite;
import org.jfrog.build.extractor.scan.DependenciesTree;
import org.jfrog.build.extractor.scan.DependencyTree;
import org.jfrog.build.extractor.scan.GeneralInfo;
import org.jfrog.build.extractor.scan.Scope;

import com.google.common.collect.Sets;
import com.jfrog.ide.common.scan.ComponentPrefix;
import com.jfrog.ide.eclipse.log.Logger;
import com.jfrog.ide.eclipse.scheduling.ScanJob;
Expand Down Expand Up @@ -48,7 +50,6 @@ public static boolean isApplicable(IProject project) {
}
}

@Override
void refreshDependencies(IProgressMonitor monitor) throws CoreException {
IMavenProjectFacade facade = MavenPlugin.getMavenProjectRegistry().getProject(project);
if (facade == null) {
Expand All @@ -64,26 +65,32 @@ void refreshDependencies(IProgressMonitor monitor) throws CoreException {

@Override
void buildTree() throws CoreException {
refreshDependencies(getMonitor());
if (mavenProject == null) {
return;
}
DependenciesTree rootNode = new DependenciesTree(mavenProject.getName());
DependencyTree rootNode = new DependencyTree(mavenProject.getName());
populateScanTreeNode(rootNode, mavenDependenciesRoot);
kerenr-jfrog marked this conversation as resolved.
Show resolved Hide resolved
GeneralInfo generalInfo = new GeneralInfo().groupId(mavenProject.getGroupId())
.artifactId(mavenProject.getArtifactId()).version(mavenProject.getVersion());
rootNode.setGeneralInfo(generalInfo);
populateScanTreeNode(rootNode, mavenDependenciesRoot);
setScanResults(rootNode);
setScanResults(rootNode);
}

/**
* Populate root modules DependenciesTree with issues, licenses and general info
* Populate root modules DependencyTree with issues, licenses and general info
* from the scan cache.
*/
private void populateScanTreeNode(DependenciesTree scanTreeNode, DependencyNode dependencyNode) {
private void populateScanTreeNode(DependencyTree scanTreeNode, DependencyNode dependencyNode) {
dependencyNode.getChildren().forEach(dependencyChild -> {
String componentId = getComponentId(dependencyChild);
DependenciesTree child = new DependenciesTree(componentId);
child.setGeneralInfo(new GeneralInfo(componentId, "", "", "Maven"));
DependencyTree child = new DependencyTree(componentId);
String componentName = dependencyChild.getArtifact().getArtifactId();
child.setGeneralInfo(new GeneralInfo(componentId, componentName, "", "Maven"));
// set dependency scope
String componentScope = dependencyChild.getDependency().getScope();
child.setScopes(Sets.newHashSet(new Scope(componentScope)));

scanTreeNode.add(child);
populateScanTreeNode(child, dependencyChild);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.jfrog.ide.common.npm.NpmTreeBuilder;
import com.jfrog.ide.common.scan.ComponentPrefix;
import com.jfrog.ide.eclipse.log.Logger;

/**
* @author yahavi
Expand All @@ -20,15 +20,16 @@ public class NpmScanManager extends ScanManager {
NpmScanManager(IProject project) throws IOException {
super(project, ComponentPrefix.NPM);
getLog().info("Found npm project: " + getProjectName());
npmTreeBuilder = new NpmTreeBuilder(project.getFullPath().toFile().toPath());
}

@Override
void refreshDependencies(IProgressMonitor monitor) throws IOException {
npmTreeBuilder = new NpmTreeBuilder(project.getFullPath().toFile().toPath(), System.getenv());
}

@Override
void buildTree() throws CoreException, JsonProcessingException, IOException {
setScanResults(npmTreeBuilder.buildTree(getLog()));
}
try {
setScanResults(npmTreeBuilder.buildTree(getLog(), false));
kerenr-jfrog marked this conversation as resolved.
Show resolved Hide resolved
}
catch (IOException ex) {
Logger.getInstance().error("Could not scan project: " + getProjectName() + ". Reason is: " + ex.getMessage());
kerenr-jfrog marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
Loading
Loading