Guest User

Untitled

a guest
Dec 4th, 2017
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.77 KB | None | 0 0
  1. package com.din.main;
  2.  
  3. import java.io.IOException;
  4. import java.util.Iterator;
  5. import java.util.List;
  6.  
  7. import javax.swing.JOptionPane;
  8.  
  9. import com.blackducksoftware.sdk.fault.SdkFault;
  10. import com.blackducksoftware.sdk.protex.client.util.ProtexServerProxy;
  11. import com.blackducksoftware.sdk.protex.component.ComponentApi;
  12. import com.blackducksoftware.sdk.protex.license.LicenseApi;
  13. import com.blackducksoftware.sdk.protex.project.bom.BomApi;
  14. import com.blackducksoftware.sdk.protex.project.codetree.CodeTreeApi;
  15. import com.blackducksoftware.sdk.protex.project.codetree.CodeTreeNode;
  16. import com.blackducksoftware.sdk.protex.project.codetree.CodeTreeNodeRequest;
  17. import com.blackducksoftware.sdk.protex.project.codetree.identification.CodeTreeIdentificationInfo;
  18. import com.blackducksoftware.sdk.protex.project.codetree.identification.Identification;
  19. import com.blackducksoftware.sdk.protex.project.codetree.identification.IdentificationApi;
  20. import com.blackducksoftware.sdk.protex.project.localcomponent.LocalComponentApi;
  21. import com.blackducksoftware.sdk.protex.util.CodeTreeUtilities;
  22.  
  23. public class MainTrigger {
  24.  
  25. public static void main(String[] args) {
  26.  
  27.  
  28. String serverUrl = args[0];
  29. String userName = args[1];
  30. String password = args[2];
  31. String projectName = args[3];
  32.  
  33. ProtexServerProxy protexServerProxy = new ProtexServerProxy(serverUrl, userName, password);
  34.  
  35. //validate credentials
  36. try {
  37. protexServerProxy.validateCredentials();
  38. } catch (Exception e) {
  39. JOptionPane.showMessageDialog(null, "Wrong Credentials", "Info", JOptionPane.INFORMATION_MESSAGE);
  40. }
  41.  
  42. String projectId = null;
  43. try {
  44. projectId = protexServerProxy.getProjectApi().getProjectByName(projectName).getProjectId();
  45. System.out.println(projectId);
  46. } catch (SdkFault e1) {
  47. JOptionPane.showMessageDialog(null, "Error in fetching the projectId", "Info", JOptionPane.INFORMATION_MESSAGE);
  48. }
  49.  
  50. CodeTreeNodeRequest codeTreeNodeRequest = new CodeTreeNodeRequest();
  51. codeTreeNodeRequest.getIncludedNodeTypes().addAll(CodeTreeUtilities.ALL_CODE_TREE_NODE_TYPES);
  52. codeTreeNodeRequest.setDepth(CodeTreeUtilities.INFINITE_DEPTH);
  53. codeTreeNodeRequest.setIncludeParentNode(false);
  54.  
  55.  
  56. try {
  57. CodeTreeApi codeTreeApi = protexServerProxy.getCodeTreeApi();
  58. IdentificationApi identificationApi = protexServerProxy.getIdentificationApi();
  59. ComponentApi componentApi = protexServerProxy.getComponentApi();
  60. LicenseApi licenseApi = protexServerProxy.getLicenseApi();
  61. LocalComponentApi localComponentApi = protexServerProxy.getLocalComponentApi();
  62. BomApi bomApi = protexServerProxy.getBomApi();
  63.  
  64. System.out.println(codeTreeNodeRequest.getDepth());
  65. List<CodeTreeNode> codeTreeNodes = codeTreeApi.getCodeTreeNodes(projectId, "/", codeTreeNodeRequest);
  66. //getCodeTreeNodes(String projectId, String parentPath, CodeTreeNodeRequest codeTreeNodeRequest)
  67.  
  68.  
  69. System.out.println("list created successfully");
  70. int fileCount = 0;
  71. /*for (Iterator iterator = codeTreeNodes.iterator(); iterator.hasNext();) {
  72. CodeTreeNode codeTreeNode = (CodeTreeNode) iterator.next();
  73. if(!codeTreeNode.getNodeType().equals(CodeTreeNodeType.FILE)) continue;//Skip the folder name and process only the exact files
  74. //System.out.println();
  75. System.out.println(++fileCount+"-"+codeTreeNode.getName()+" md5-"+codeTreeApi.getFileInfo(projectId, codeTreeNode.getName(), CodeTreeUtilities.DIRECT_CHILDREN, Boolean.valueOf(true), null).get(0).getExactChecksum());
  76.  
  77. //getFileInfo(String projectId, String parentPath, Integer depth, Boolean includeParentPathNode, CharEncoding charEncoding)
  78.  
  79.  
  80.  
  81. //getAppliedIdentifications(String projectId, List<CodeTreeNode> nodes)
  82.  
  83. }*/
  84.  
  85.  
  86. List<CodeTreeIdentificationInfo> identifications = identificationApi.getAppliedIdentifications(projectId, codeTreeNodes);
  87. //identificationApi.getEffectiveIdentifications(arg0, arg1)
  88.  
  89.  
  90. System.out.println("identifications instance created successfully");
  91. try{
  92. for (Iterator iterator = identifications.iterator(); iterator.hasNext();) {
  93. CodeTreeIdentificationInfo codeTreeIdentificationInfo = (CodeTreeIdentificationInfo) iterator.next();
  94. List<Identification> ids = codeTreeIdentificationInfo.getIdentifications();
  95. for (Iterator iterator2 = ids.iterator(); iterator2.hasNext();) {
  96. Identification identification = (Identification) iterator2.next();
  97.  
  98.  
  99. try {
  100. localComponentApi.getLocalComponentByKey(projectId, identification.getIdentifiedComponentKey());//check for local component
  101. System.out.println("------------local component--------------------");
  102. System.out.println(codeTreeApi.getFileInfo(projectId, identification.getAppliedToPath(), CodeTreeUtilities.DIRECT_CHILDREN, Boolean.valueOf(true), null).get(0).getExactChecksum());
  103. System.out.println(localComponentApi.getLocalComponentByKey(projectId,identification.getIdentifiedComponentKey()).getComponentName()+" *"+localComponentApi.getLocalComponentByKey(projectId,identification.getIdentifiedComponentKey()).getVersionName()+" *"+identification.getIdentifiedLicenseInfo().getName()+" *"+identification.getAppliedToPath());
  104. //c_79625613-3b0a-49fc-92e8-5f4c4cfec5e2 *null *Microsoft .NET Library License *Microsoft.AspNetCore.Authorization.1.0.0.dll
  105. System.out.println(identification.getIdentifiedUsageLevel()+" *"+identification.getMode()+" *"+localComponentApi.getLocalComponentByKey(projectId,identification.getIdentifiedComponentKey()).getComponentType()+" *"+localComponentApi.getLocalComponentByKey(projectId,identification.getIdentifiedComponentKey()).getHomePage());
  106. //localComponentApi.getLocalComponentByKey(projectId,identification.getIdentifiedComponentKey()).getComponentType()
  107. //COMPONENT_DYNAMIC_LIBRARY *MANUAL *DECLARATION
  108. //COMPONENT *MANUAL *CODE_MATCH
  109. System.out.println(bomApi.getComponentComment(projectId, identification.getIdentifiedComponentKey()));
  110. System.out.println("--------------------------------");
  111. } catch (Exception e) {
  112. System.out.println("------------standard component--------------------");
  113. //if(!identification.getAppliedToPath().getNodeType().equals(CodeTreeNodeType.FILE)) continue;//Skip the folder name and process only the exact files
  114. System.out.println(codeTreeApi.getFileInfo(projectId, identification.getAppliedToPath(), CodeTreeUtilities.INFINITE_DEPTH, Boolean.valueOf(true), null).get(0).getExactChecksum());
  115. System.out.println(componentApi.getComponentByKey(identification.getIdentifiedComponentKey()).getComponentName()+" *"+componentApi.getComponentByKey(identification.getIdentifiedComponentKey()).getVersionName()+" *"+identification.getIdentifiedLicenseInfo().getName()+" *"+identification.getAppliedToPath());
  116. //c_79625613-3b0a-49fc-92e8-5f4c4cfec5e2 *null *Microsoft .NET Library License *Microsoft.AspNetCore.Authorization.1.0.0.dll
  117. System.out.println(identification.getIdentifiedUsageLevel()+" *"+identification.getMode()+" *"+identification.getType()+" *"+componentApi.getComponentByKey(identification.getIdentifiedComponentKey()).getHomePage());
  118. //COMPONENT_DYNAMIC_LIBRARY *MANUAL *DECLARATION
  119. //COMPONENT *MANUAL *CODE_MATCH
  120. System.out.println(bomApi.getComponentComment(projectId, identification.getIdentifiedComponentKey()));
  121. System.out.println("--------------------------------");
  122. }
  123. }
  124.  
  125. }
  126. }
  127. catch (Exception e) {
  128. JOptionPane.showMessageDialog(null, "Problem in identification instance", "Info", JOptionPane.INFORMATION_MESSAGE);
  129.  
  130. }
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137.  
  138.  
  139. //close the instance
  140. try {
  141. protexServerProxy.close();
  142. //JOptionPane.showMessageDialog(null, "protexServerProxy Instance closed safely", "Info", JOptionPane.INFORMATION_MESSAGE);
  143. } catch (IOException e) {
  144. JOptionPane.showMessageDialog(null, "protexServerProxy Instance not closed", "Info", JOptionPane.INFORMATION_MESSAGE);
  145.  
  146. }
  147.  
  148.  
  149.  
  150. }catch(Exception e){
  151.  
  152. }
  153. }
  154. }
Add Comment
Please, Sign In to add comment