@Override public final String toString() { final StringBuilder builder = new StringBuilder(); builder.append("[").append(this.getMvnGroup()).append("|").append(this.getArtifact()).append("|").append(this.getVersion()).append("]"); return builder.toString(); }
/** * Returns the path of the directory where the artifact is stored, relative to the local M2 repository. * E.g, com/jolira/guice/3.0.0. * @return */ @JsonIgnore private Path getRelM2Dir() { final StringBuilder b = new StringBuilder(); b.append(this.getLibId().getMvnGroup().replace('.', '/')).append("/"); b.append(this.getLibId().getArtifact()).append("/"); b.append(this.getLibId().getVersion()); return Paths.get(b.toString()); }
/** * Returns the artifact's filename root, e.g., guice-3.0.0 * To be completed with one of the available postfix in this.ec * @return */ @JsonIgnore public String getM2Filename() { final StringBuilder b = new StringBuilder(); b.append(this.getLibId().getArtifact()).append("-").append(this.getLibId().getVersion()); if(this.classifier!=null && !this.classifier.equals("")) b.append("-").append(this.getClassifier()); if(this.lang!=null && this.lang==ProgrammingLanguage.PY){ if (this.getPackaging().equals("sdist")){ b.append(".tar.gz"); } else if (this.getPackaging().equals("bdist_wheel")){ b.append(".whl"); } } else { b.append(".").append(this.getPackaging()); } return b.toString(); }
private boolean isAmongAggregatedModules(LibraryId _libid) { for(Application prj: this.modules) { if(prj.getMvnGroup().equals(_libid.getMvnGroup()) && prj.getArtifact().equals(_libid.getArtifact()) && prj.getVersion().equals(_libid.getVersion())) return true; } return false; }
/** * Compares this library ID with the provided library ID using, in that order, * group, artifact, or version. */ @Override public int compareTo(Object _other) { if(_other instanceof LibraryId) { final LibraryId other_libid = (LibraryId)_other; int result = this.getMvnGroup().compareToIgnoreCase(other_libid.getMvnGroup()); if(result==0) result = this.getArtifact().compareToIgnoreCase(other_libid.getArtifact()); if(result==0){ Version v = new Version(this.getVersion()); result = v.compareTo(new Version(other_libid.getVersion())); } return result; } else { throw new IllegalArgumentException("Expected object of type LibraryId, got [" + _other.getClass().getName() + "]"); } }
@Override public Path downloadArtifact(Artifact _doc) throws Exception { final String url = MAVEN_CENTRAL_REPO; final StringBuilder b = new StringBuilder(); b.append(url); b.append(_doc.getLibId().getMvnGroup().replace('.', '/')).append("/"); b.append(_doc.getLibId().getArtifact()).append("/"); b.append(_doc.getLibId().getVersion()).append("/"); b.append(_doc.getM2Filename()); // Make the query final RestTemplate rest_template = new RestTemplate(); Path result = null; try{ rest_template.execute(b.toString(), HttpMethod.GET, new DefaultRequestCallback(), new FileResponseExtractor(_doc, _doc.getAbsM2Path())); result = _doc.getAbsM2Path(); } catch(HttpClientErrorException e) { MavenCentralWrapper.log.error(_doc + " not available at [" +b.toString()+ "]"); } return result; }
/** * Filter the given packages according to whether the artifact name is (or is not, depending on the boolean flag) contained in the given filter. * @param _packages * @param _filter * @param _include * @return */ public static Set<PipInstalledPackage> filterUsingArtifact(Set<PipInstalledPackage> _packages, StringList _filter, boolean _include) { final Set<PipInstalledPackage> r = new HashSet<PipInstalledPackage>(); for(PipInstalledPackage p: _packages) { try { if(_include) { if(_filter.contains(p.getLibrary().getLibraryId().getArtifact())) r.add(p); } else { if(!_filter.contains(p.getLibrary().getLibraryId().getArtifact())) r.add(p); } } catch (FileAnalysisException e) { log.error("Error getting library ID of package [" + p + "]: " + e.getMessage(), e); } } return r; }
public synchronized String getVulnAst(LibraryId l){ if(this.lidVulnBytecodeAST.get(l)==null){ String ast_lid = BackendConnector.getInstance().getAstForQnameInLib(l.getMvnGroup()+"/"+l.getArtifact()+"/"+l.getVersion()+"/"+ type.toString()+"/"+construct,false,ProgrammingLanguage.JAVA); // the file is found if (ast_lid != null) { this.lidVulnBytecodeAST.put(l,ast_lid); } else { // the file is not found and cannot be used as a comparison basis, we set it to BytecodeNotFound to avoid furthur requests this.lidVulnBytecodeAST.put (l,BYTECODE_NOT_FOUND); } } String res = this.lidVulnBytecodeAST.get(l); if(res==BYTECODE_NOT_FOUND){ return null; } else { return res; } }
public synchronized String getFixedAst(LibraryId l){ if(this.lidFixedBytecodeAST.get(l)==null){ String ast_lid = BackendConnector.getInstance().getAstForQnameInLib(l.getMvnGroup()+"/"+l.getArtifact()+"/"+l.getVersion()+"/"+ type.toString()+"/"+construct,false,ProgrammingLanguage.JAVA); // the file is found if (ast_lid != null) { this.lidFixedBytecodeAST.put(l,ast_lid); } else { // the file is not found and cannot be used as a comparison basis, we set it to BytecodeNotFound to avoid furthur requests this.lidFixedBytecodeAST.put (l,BYTECODE_NOT_FOUND); } } String res = this.lidFixedBytecodeAST.get(l); if(res==BYTECODE_NOT_FOUND){ return null; } else { return res; } }
final Path old_jar = r.downloadArtifact(artifacts[0]); final Path new_jar = r.downloadArtifact(artifacts[1]); final String label = artifacts[0].getLibId().getArtifact() + "-" + artifacts[0].getLibId().getVersion() + "--" + artifacts[1].getLibId().getArtifact() + "-" + artifacts[1].getLibId().getVersion(); final File diff_xml = File.createTempFile(label + "-", ".xml");
/** * [OUT-OF-DATE] * Returns true if group, artifact, version are specified, * classifier is one of 'sources', 'javadoc', 'test-sources', and 'tests', and * packaging is one of 'pom', 'jar' and 'war'. * Without all this information, a download is not possible. * @param _doc * @return */ public boolean isReadyForDownload() { return this.getLibId().getMvnGroup()!=null && !this.getLibId().getMvnGroup().equals("") && this.getLibId().getArtifact()!=null && !this.getLibId().getArtifact().equals("") && this.getLibId().getVersion()!=null && !this.getLibId().getVersion().equals("") && (this.getClassifier()==null || this.getClassifier().equals("javadoc") || this.getClassifier().equals("sources") || this.getClassifier().equals("test-sources") || this.getClassifier().equals("tests") || this.getClassifier().equals("site")|| this.getClassifier().equals("jar")) && this.getPackaging()!=null && (this.getPackaging().equalsIgnoreCase("pom") || this.getPackaging().equalsIgnoreCase("jar") || this.getPackaging().equalsIgnoreCase("war") || this.getPackaging().equalsIgnoreCase("xml") || this.getPackaging().equalsIgnoreCase("sdist") || this.getPackaging().equalsIgnoreCase("bdist_wheel")); } }
log.info("Determined compilation unit " + def_ctx + " for qname [" + qname + "]"); file = ClassDownloader.getInstance().getClass(doc.getLibId().getMvnGroup(), doc.getLibId().getArtifact(), doc.getLibId().getVersion(), def_ctx.getQualifiedName(), ClassDownloader.Format.JAVA);
def_ctx = this.getCompilationUnit(jid); log.debug("Determined compilation unit " + def_ctx + " for qname [" + qname + "]"); file = ClassDownloader.getInstance().getClass(doc.getLibId().getMvnGroup(), doc.getLibId().getArtifact(), doc.getLibId().getVersion(), def_ctx.getQualifiedName(), ClassDownloader.Format.JAVA);
final Map<String,String> params = new HashMap<String,String>(); params.put("g", a.getLibId().getMvnGroup()); params.put("a", a.getLibId().getArtifact()); params.put("v", a.getLibId().getVersion()); params.put("p", a.getPackaging());
@Override public int compareTo(Object _other) { if(_other instanceof Artifact) { final Artifact other_libid = (Artifact)_other; int result = this.getLibId().getMvnGroup().compareToIgnoreCase(other_libid.getLibId().getMvnGroup()); if(result==0) result = this.getLibId().getArtifact().compareToIgnoreCase(other_libid.getLibId().getArtifact()); if(result==0 && this.getTimestamp()!=null && other_libid.getTimestamp()!=null) result = this.getTimestamp().compareTo(other_libid.getTimestamp()); if(result==0){ Version v = new Version(this.getLibId().getVersion()); result = v.compareTo(new Version(other_libid.getLibId().getVersion())); } // result = this.getLibId().getVersion().compareToIgnoreCase(((Artifact) _other).getLibId().getVersion()); return result; } else { throw new IllegalArgumentException("Expected object of type Artifact, got [" + _other.getClass().getName() + "]"); } }
JsonObject libraryId = new JsonObject(); libraryId.addProperty("group", l.getMvnGroup()); libraryId.addProperty("artifact", l.getArtifact()); libraryId.addProperty("version", l.getVersion()); sameBytecodeArray.add(libraryId);
@Override public Set<Artifact> getGreaterArtifactVersions(String group, String artifact, String greaterThanVersion, String classifier, String packaging) throws Exception { Set<Artifact> all = this.getAllArtifactVersions(group, artifact, classifier, packaging); Set<Artifact> allWithTimestamp = new TreeSet<Artifact>(); Artifact toCompare = null; for(Artifact a : all){ if(a.getLibId().getVersion().equals(greaterThanVersion)) toCompare = this.getArtifactVersion(a.getLibId().getMvnGroup(), a.getLibId().getArtifact(), a.getLibId().getVersion(), null, null, null); else allWithTimestamp.add(this.getArtifactVersion(a.getLibId().getMvnGroup(), a.getLibId().getArtifact(), a.getLibId().getVersion(), null, null, null)); } // Return bad request if version is not found if(toCompare==null){ log.error("Version [" + greaterThanVersion + "] not found in Nexus for group [" + group + "] and artifact [" + artifact + "]"); return null; } Set<Artifact> greater = new TreeSet<Artifact>(); for (Artifact t: allWithTimestamp){ if (t.compareTo(toCompare)>0) greater.add(t); } return greater; }
Path result = null; try{ final PypiResponse response = this.searchInPypi(a.getLibId().getArtifact(),a.getLibId().getVersion());
return false; Artifact other = (Artifact) obj; if (libId.getArtifact() == null) { if (other.getLibId().getArtifact() != null) return false; } else if (!libId.getArtifact().equals(other.getLibId().getArtifact())) return false; if (libId.getMvnGroup() == null) {
protected void doProcessing() throws Exception { // Old JAR PackageMapper oldPackages = new PackageMapper(); ClassfileLoader oldJar = new AggregatingClassfileLoader(); oldJar.addLoadListener(oldPackages); List<String> old_files = new ArrayList<String>(); old_files.add(this.oldPath.toString()); oldJar.load(old_files); // New JAR PackageMapper newPackages = new PackageMapper(); ClassfileLoader newJar = new AggregatingClassfileLoader(); newJar.addLoadListener(newPackages); List<String> new_files = new ArrayList<String>(); new_files.add(this.newPath.toString()); newJar.load(new_files); String name = this.oldLib.getLibId().getMvnGroup() + ":" + this.oldLib.getLibId().getArtifact(); String oldLabel = name + ":" + oldLib.getLibId().getVersion(); String newLabel = name + ":" + newLib.getLibId().getVersion(); Differences differences = getDifferencesFactory().createProjectDifferences(name, oldLabel, oldPackages, newLabel, newPackages); //Report report = new Report(getCommandLine().getSingleSwitch("encoding"), getCommandLine().getSingleSwitch("dtd-prefix")); visitor = new JarDiffVisitor(this.oldLib, this.newLib); differences.accept(visitor); }