Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.din.main;
- import java.io.IOException;
- import java.util.Iterator;
- import java.util.List;
- import javax.swing.JOptionPane;
- import com.blackducksoftware.sdk.fault.SdkFault;
- import com.blackducksoftware.sdk.protex.client.util.ProtexServerProxy;
- import com.blackducksoftware.sdk.protex.component.ComponentApi;
- import com.blackducksoftware.sdk.protex.license.LicenseApi;
- import com.blackducksoftware.sdk.protex.project.bom.BomApi;
- import com.blackducksoftware.sdk.protex.project.codetree.CodeTreeApi;
- import com.blackducksoftware.sdk.protex.project.codetree.CodeTreeNode;
- import com.blackducksoftware.sdk.protex.project.codetree.CodeTreeNodeRequest;
- import com.blackducksoftware.sdk.protex.project.codetree.identification.CodeTreeIdentificationInfo;
- import com.blackducksoftware.sdk.protex.project.codetree.identification.Identification;
- import com.blackducksoftware.sdk.protex.project.codetree.identification.IdentificationApi;
- import com.blackducksoftware.sdk.protex.project.localcomponent.LocalComponentApi;
- import com.blackducksoftware.sdk.protex.util.CodeTreeUtilities;
- public class MainTrigger {
- public static void main(String[] args) {
- String serverUrl = args[0];
- String userName = args[1];
- String password = args[2];
- String projectName = args[3];
- ProtexServerProxy protexServerProxy = new ProtexServerProxy(serverUrl, userName, password);
- //validate credentials
- try {
- protexServerProxy.validateCredentials();
- } catch (Exception e) {
- JOptionPane.showMessageDialog(null, "Wrong Credentials", "Info", JOptionPane.INFORMATION_MESSAGE);
- }
- String projectId = null;
- try {
- projectId = protexServerProxy.getProjectApi().getProjectByName(projectName).getProjectId();
- System.out.println(projectId);
- } catch (SdkFault e1) {
- JOptionPane.showMessageDialog(null, "Error in fetching the projectId", "Info", JOptionPane.INFORMATION_MESSAGE);
- }
- CodeTreeNodeRequest codeTreeNodeRequest = new CodeTreeNodeRequest();
- codeTreeNodeRequest.getIncludedNodeTypes().addAll(CodeTreeUtilities.ALL_CODE_TREE_NODE_TYPES);
- codeTreeNodeRequest.setDepth(CodeTreeUtilities.INFINITE_DEPTH);
- codeTreeNodeRequest.setIncludeParentNode(false);
- try {
- CodeTreeApi codeTreeApi = protexServerProxy.getCodeTreeApi();
- IdentificationApi identificationApi = protexServerProxy.getIdentificationApi();
- ComponentApi componentApi = protexServerProxy.getComponentApi();
- LicenseApi licenseApi = protexServerProxy.getLicenseApi();
- LocalComponentApi localComponentApi = protexServerProxy.getLocalComponentApi();
- BomApi bomApi = protexServerProxy.getBomApi();
- System.out.println(codeTreeNodeRequest.getDepth());
- List<CodeTreeNode> codeTreeNodes = codeTreeApi.getCodeTreeNodes(projectId, "/", codeTreeNodeRequest);
- //getCodeTreeNodes(String projectId, String parentPath, CodeTreeNodeRequest codeTreeNodeRequest)
- System.out.println("list created successfully");
- int fileCount = 0;
- /*for (Iterator iterator = codeTreeNodes.iterator(); iterator.hasNext();) {
- CodeTreeNode codeTreeNode = (CodeTreeNode) iterator.next();
- if(!codeTreeNode.getNodeType().equals(CodeTreeNodeType.FILE)) continue;//Skip the folder name and process only the exact files
- //System.out.println();
- System.out.println(++fileCount+"-"+codeTreeNode.getName()+" md5-"+codeTreeApi.getFileInfo(projectId, codeTreeNode.getName(), CodeTreeUtilities.DIRECT_CHILDREN, Boolean.valueOf(true), null).get(0).getExactChecksum());
- //getFileInfo(String projectId, String parentPath, Integer depth, Boolean includeParentPathNode, CharEncoding charEncoding)
- //getAppliedIdentifications(String projectId, List<CodeTreeNode> nodes)
- }*/
- List<CodeTreeIdentificationInfo> identifications = identificationApi.getAppliedIdentifications(projectId, codeTreeNodes);
- //identificationApi.getEffectiveIdentifications(arg0, arg1)
- System.out.println("identifications instance created successfully");
- try{
- for (Iterator iterator = identifications.iterator(); iterator.hasNext();) {
- CodeTreeIdentificationInfo codeTreeIdentificationInfo = (CodeTreeIdentificationInfo) iterator.next();
- List<Identification> ids = codeTreeIdentificationInfo.getIdentifications();
- for (Iterator iterator2 = ids.iterator(); iterator2.hasNext();) {
- Identification identification = (Identification) iterator2.next();
- try {
- localComponentApi.getLocalComponentByKey(projectId, identification.getIdentifiedComponentKey());//check for local component
- System.out.println("------------local component--------------------");
- System.out.println(codeTreeApi.getFileInfo(projectId, identification.getAppliedToPath(), CodeTreeUtilities.DIRECT_CHILDREN, Boolean.valueOf(true), null).get(0).getExactChecksum());
- System.out.println(localComponentApi.getLocalComponentByKey(projectId,identification.getIdentifiedComponentKey()).getComponentName()+" *"+localComponentApi.getLocalComponentByKey(projectId,identification.getIdentifiedComponentKey()).getVersionName()+" *"+identification.getIdentifiedLicenseInfo().getName()+" *"+identification.getAppliedToPath());
- //c_79625613-3b0a-49fc-92e8-5f4c4cfec5e2 *null *Microsoft .NET Library License *Microsoft.AspNetCore.Authorization.1.0.0.dll
- System.out.println(identification.getIdentifiedUsageLevel()+" *"+identification.getMode()+" *"+localComponentApi.getLocalComponentByKey(projectId,identification.getIdentifiedComponentKey()).getComponentType()+" *"+localComponentApi.getLocalComponentByKey(projectId,identification.getIdentifiedComponentKey()).getHomePage());
- //localComponentApi.getLocalComponentByKey(projectId,identification.getIdentifiedComponentKey()).getComponentType()
- //COMPONENT_DYNAMIC_LIBRARY *MANUAL *DECLARATION
- //COMPONENT *MANUAL *CODE_MATCH
- System.out.println(bomApi.getComponentComment(projectId, identification.getIdentifiedComponentKey()));
- System.out.println("--------------------------------");
- } catch (Exception e) {
- System.out.println("------------standard component--------------------");
- //if(!identification.getAppliedToPath().getNodeType().equals(CodeTreeNodeType.FILE)) continue;//Skip the folder name and process only the exact files
- System.out.println(codeTreeApi.getFileInfo(projectId, identification.getAppliedToPath(), CodeTreeUtilities.INFINITE_DEPTH, Boolean.valueOf(true), null).get(0).getExactChecksum());
- System.out.println(componentApi.getComponentByKey(identification.getIdentifiedComponentKey()).getComponentName()+" *"+componentApi.getComponentByKey(identification.getIdentifiedComponentKey()).getVersionName()+" *"+identification.getIdentifiedLicenseInfo().getName()+" *"+identification.getAppliedToPath());
- //c_79625613-3b0a-49fc-92e8-5f4c4cfec5e2 *null *Microsoft .NET Library License *Microsoft.AspNetCore.Authorization.1.0.0.dll
- System.out.println(identification.getIdentifiedUsageLevel()+" *"+identification.getMode()+" *"+identification.getType()+" *"+componentApi.getComponentByKey(identification.getIdentifiedComponentKey()).getHomePage());
- //COMPONENT_DYNAMIC_LIBRARY *MANUAL *DECLARATION
- //COMPONENT *MANUAL *CODE_MATCH
- System.out.println(bomApi.getComponentComment(projectId, identification.getIdentifiedComponentKey()));
- System.out.println("--------------------------------");
- }
- }
- }
- }
- catch (Exception e) {
- JOptionPane.showMessageDialog(null, "Problem in identification instance", "Info", JOptionPane.INFORMATION_MESSAGE);
- }
- //close the instance
- try {
- protexServerProxy.close();
- //JOptionPane.showMessageDialog(null, "protexServerProxy Instance closed safely", "Info", JOptionPane.INFORMATION_MESSAGE);
- } catch (IOException e) {
- JOptionPane.showMessageDialog(null, "protexServerProxy Instance not closed", "Info", JOptionPane.INFORMATION_MESSAGE);
- }
- }catch(Exception e){
- }
- }
- }
Add Comment
Please, Sign In to add comment