Skip to content

Commit

Permalink
Merge pull request #13 from romeara/dev/romeara/enhancement/print-sea…
Browse files Browse the repository at this point in the history
…rch-location-comment

ISSUE #3 Changed string search row to include lines and comments
  • Loading branch information
romeara committed Jan 22, 2016
2 parents 3d7c024 + c0fb32d commit fb74ff3
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import com.blackducksoftware.sdk.protex.project.codetree.identification.Identification;
import com.blackducksoftware.sdk.protex.project.codetree.identification.IdentificationApi;
import com.blackducksoftware.sdk.protex.project.codetree.identification.IdentificationType;
import com.blackducksoftware.sdk.protex.project.codetree.identification.IdentifiedStringSearchMatchLocation;
import com.blackducksoftware.sdk.protex.project.codetree.identification.StringSearchIdentification;
import com.blackducksoftware.sdk.protex.util.CodeTreeUtilities;

Expand Down Expand Up @@ -144,22 +145,26 @@ public void doWork(String projectId, String parentPath, List<CodeTreeNode> thisL
""));
} else if (IdentificationType.STRING_SEARCH.equals(id.getType())) {
StringSearchIdentification ssId = (StringSearchIdentification) id;
StringBuilder fileLines = new StringBuilder();
StringBuilder comments = new StringBuilder();

for (IdentifiedStringSearchMatchLocation hit : ssId.getMatchLocations()) {
if (fileLines.length() > 0) {
fileLines.append(',');
}
if (comments.length() > 0) {
comments.append(',');
}
fileLines.append(hit.getFirstLine() != null ? hit.getFirstLine().toString() : "");
comments.append(hit.getIdentificationComment() != null ? hit.getIdentificationComment() : "");
}

System.out.println(String.format(
rowFormat,
"",
ssId.getType(),
filePath,
thisNodeFileInfo.getLength(),
"",
"<?>",
componentInfo.getComponentName(),
versionName,
id.getIdentifiedLicenseInfo() == null ? "" : id.getIdentifiedLicenseInfo()
.getName(),
id.getIdentifiedUsageLevel(),
"", "",
"Matched File Line", "Comment",
ssId.getStringSearchId()));
"", ssId.getType(), filePath, thisNodeFileInfo.getLength(), "", "<?>",
componentInfo.getComponentName(), versionName,
id.getIdentifiedLicenseInfo() == null ? "" : id.getIdentifiedLicenseInfo().getName(),
id.getIdentifiedUsageLevel(), "", "", fileLines.toString(), comments.toString(), ssId.getStringSearchId()));
} else if (IdentificationType.DEPENDENCY.equals(id.getType())) {
DependencyIdentification dpId = (DependencyIdentification) id;
System.out.println(String.format(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package com.blackducksoftware.sdk.protex.client.examples.test.report;

import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

import com.blackducksoftware.sdk.protex.client.examples.report.SampleReportDataIdentifiedFiles;
import com.blackducksoftware.sdk.protex.client.examples.test.type.AbstractSdkSampleTest;
import com.blackducksoftware.sdk.protex.client.examples.test.type.TestSources;
import com.blackducksoftware.sdk.protex.client.examples.test.type.Tests;
import com.blackducksoftware.sdk.protex.common.BomRefreshMode;
import com.blackducksoftware.sdk.protex.common.UsageLevel;
import com.blackducksoftware.sdk.protex.component.Component;
import com.blackducksoftware.sdk.protex.license.License;
import com.blackducksoftware.sdk.protex.license.LicenseCategory;
import com.blackducksoftware.sdk.protex.license.LicenseInfo;
import com.blackducksoftware.sdk.protex.project.AnalysisSourceLocation;
import com.blackducksoftware.sdk.protex.project.ProjectRequest;
import com.blackducksoftware.sdk.protex.project.codetree.identification.IdentificationRequest;

public class SampleReportDataIdentifiedFilesTest extends AbstractSdkSampleTest {

private String projectId;

@BeforeClass
protected void createProject() throws Exception {
ProjectRequest projectRequest = new ProjectRequest();
projectRequest.setName("SampleReportDataIdentifiedFilesTest Project");

AnalysisSourceLocation sourceLocation = TestSources.getAnalysisSourceLocation(getProxy());

projectRequest.setAnalysisSourceLocation(sourceLocation);

projectId = getProxy().getProjectApi().createProject(projectRequest, LicenseCategory.PROPRIETARY);

TestSources.synchronousSourceScan(getProxy(), projectId, 1000);

Component component = getProxy().getComponentApi().getComponentsByName("Cyclos", "3.0.7").get(0);
License license = getProxy().getLicenseApi().getLicenseById("gpl20");
LicenseInfo licenseInfo = new LicenseInfo();
licenseInfo.setLicenseId(license.getLicenseId());
licenseInfo.setName(license.getName());

// Identify stuff to GPL
IdentificationRequest toGpl = new IdentificationRequest();
toGpl.setIdentifiedComponentKey(component.getComponentKey());
toGpl.setIdentifiedLicenseInfo(licenseInfo);
toGpl.setIdentifiedUsageLevel(UsageLevel.COMPONENT);

getProxy().getIdentificationApi().addDeclaredIdentification(projectId, "/", toGpl, BomRefreshMode.SYNCHRONOUS);
}

@Test(groups = { Tests.SOURCE_DEPENDENT_TEST })
public void runSample() throws Exception {
String[] args = new String[4];
args[0] = Tests.getServerUrl();
args[1] = Tests.getServerUsername();
args[2] = Tests.getServerPassword();
args[3] = projectId;

SampleReportDataIdentifiedFiles.main(args);
}

@AfterClass(alwaysRun = true)
protected void deleteProject() throws Exception {
if (projectId != null) {
getProxy().getProjectApi().deleteProject(projectId);
}
}

}

0 comments on commit fb74ff3

Please sign in to comment.