private AgentProjectInfo processProject(MavenProject project) { long startTime = System.currentTimeMillis(); log.info(WssUtils.logMsg(LOG_COMPONENT, "processing Maven project " + project.getId())); AgentProjectInfo projectInfo = new AgentProjectInfo(); // project token if (project.equals(mavenParser.getMavenProject())) { projectInfo.setProjectToken(projectToken); } else { projectInfo.setProjectToken(moduleTokens.get(project.getArtifactId())); } // project coordinates projectInfo.setCoordinates(extractCoordinates(project)); Parent parent = project.getModel().getParent(); // parent coordinates if (parent != null) { projectInfo.setParentCoordinates(extractParentCoordinates(parent)); } // dependencies Map<Dependency, Artifact> lut = createLookupTable(project); for (Dependency dependency : mavenParser.getDependencies(project)) { DependencyInfo dependencyInfo = getDependencyInfo(dependency); Artifact artifact = lut.get(dependency); if (artifact != null) { File artifactFile = artifact.getFile(); if (artifactFile != null && artifactFile.exists()) { try { dependencyInfo.setSha1(ChecksumUtils.calculateSHA1(artifactFile)); } catch (IOException e) { log.warn(WssUtils.logMsg(LOG_COMPONENT, ERROR_SHA1 + " for " + artifact.getId())); } } } projectInfo.getDependencies().add(dependencyInfo); } log.info( WssUtils.logMsg( LOG_COMPONENT, "Total Maven project processing time is " + (System.currentTimeMillis() - startTime) + " [msec]")); return projectInfo; }
private MavenParser configureMavenParser(File workingDirectory) { MavenParser mavenParser = new MavenParser(); File pom = new File(workingDirectory, MavenParser.DEFAULT_MAVEN_POM); log.info(WssUtils.logMsg(LOG_COMPONENT, "Parsing Maven POM " + pom.getPath())); mavenParser.parseProject(pom); return mavenParser; }
@Override public Collection<AgentProjectInfo> extract() { log.info(WssUtils.logMsg(LOG_COMPONENT, "Collection started")); mavenParser = configureMavenParser(checkoutDirectory); Collection<MavenProject> projects = new ArrayList<MavenProject>(); MavenProject mavenProject = mavenParser.getMavenProject(); projects.add(mavenProject); projects.addAll(mavenParser.getModules(mavenProject)); Collection<AgentProjectInfo> projectInfos = new ArrayList<AgentProjectInfo>(); // Collect OSS usage information for (MavenProject project : projects) { if (shouldProcess(project)) { projectInfos.add(processProject(project)); } else { log.info(WssUtils.logMsg(LOG_COMPONENT, "skipping " + project.getId())); } } logAgentProjectInfos(projectInfos); return projectInfos; }