try {
List<ClientLibraryDef> clientLibs = Lists.newArrayList();
CompileContext cc = new CompileContext(descriptor, clientLibs);
Definition def = compileDef(descriptor, cc);
DependencyEntry de;
String uid;
if (def == null) {
return null;
}
List<CompilingDef<?>> compiled = Lists.newArrayList(cc.compiled.values());
Collections.sort(compiled);
Set<DefDescriptor<? extends Definition>> deps = Sets.newLinkedHashSet();
//
// Now walk the sorted list, building up our dependencies, and uid
//
StringBuilder sb = new StringBuilder(256);
Hash.StringBuilder globalBuilder = new Hash.StringBuilder();
for (CompilingDef<?> cd : compiled) {
if (cd.def == null) {
// actually, this should never happen.
throw new DefinitionNotFoundException(cd.descriptor);
}
deps.add(cd.descriptor);
//
// Now update our hash.
//
sb.setLength(0);
sb.append(cd.descriptor.getQualifiedName().toLowerCase());
sb.append("|");
String hash = cd.def.getOwnHash();
if (hash != null) {
sb.append(hash);
}
sb.append(",");
globalBuilder.addString(sb.toString());
}
uid = globalBuilder.build().toString();
//
// Now try a re-lookup. This may catch existing cached
// entries where uid was null.
//
de = getDE(uid, descriptor);
if (de != null) {
return de;
}
de = new DependencyEntry(uid, Collections.unmodifiableSet(deps), clientLibs);
if (shouldCache(descriptor)) {
// put UID-qualified descriptor key for dependency
depsCache.put(makeGlobalKey(de.uid, descriptor), de);
// put unqualified descriptor key for dependency
if (cc.shouldCacheDependencies) {
depsCache.put(makeNonUidGlobalKey(descriptor), de);
}
}
// See localDependencies comment
localDependencies.put(de.uid, de);
localDependencies.put(key, de);
return de;
} catch (QuickFixException qfe) {
// See localDependencies comment
localDependencies.put(key, new DependencyEntry(qfe));
throw qfe;
}
}