in taverna-beanshell-activity/src/main/java/org/apache/taverna/activities/dependencyactivity/AbstractAsynchronousDependencyActivity.java [240:344]
private HashSet<URL> findDependencies(String dependencyType, JsonNode json, String workflowRunID) {
ClassLoaderSharing classLoaderSharing;
if (json.has("classLoaderSharing")) {
classLoaderSharing = ClassLoaderSharing.fromString(json.get("classLoaderSharing").textValue());
} else {
classLoaderSharing = ClassLoaderSharing.workflow;
}
// Get the WorkflowInstanceFacade which contains the current workflow
WeakReference<WorkflowInstanceFacade> wfFacadeRef = WorkflowInstanceFacade.workflowRunFacades.get(workflowRunID);
WorkflowInstanceFacade wfFacade = null;
if (wfFacadeRef != null) {
wfFacade = wfFacadeRef.get();
}
Dataflow wf = null;
if (wfFacade != null) {
wf = wfFacade.getDataflow();
}
// Files of dependencies for all activities in the workflow that share the classloading policy
HashSet<File> dependencies = new HashSet<File>();
// Urls of all dependencies
HashSet<URL> dependenciesURLs = new HashSet<URL>();
if (wf != null){
// Merge in dependencies from all activities that have the same classloader-sharing
// as this activity
for (Processor proc : wf.getProcessors()) {
// Nested workflow case
if (!proc.getActivityList().isEmpty() && proc.getActivityList().get(0) instanceof NestedDataflow){
// Get the nested workflow
Dataflow nestedWorkflow = ((NestedDataflow) proc.getActivityList().get(0)).getNestedDataflow();
dependenciesURLs.addAll(findNestedDependencies(dependencyType, json, nestedWorkflow));
}
else{ // Not nested - go through all of the processor's activities
Activity<?> activity = proc.getActivityList().get(0);
if (activity instanceof AbstractAsynchronousDependencyActivity){
AbstractAsynchronousDependencyActivity dependencyActivity = (AbstractAsynchronousDependencyActivity) activity;
// if (dependencyType.equals(LOCAL_JARS)){
// Collect the files of all found local dependencies
if (dependencyActivity.getConfiguration().has("localDependency")) {
for (JsonNode jar : dependencyActivity.getConfiguration().get("localDependency")) {
try {
dependencies.add(new File(libDir, jar.textValue()));
} catch (Exception ex) {
logger.warn("Invalid URL for " + jar, ex);
continue;
}
}
}
// } else if (dependencyType.equals(ARTIFACTS) && this.getClass().getClassLoader() instanceof LocalArtifactClassLoader){
// LocalArtifactClassLoader cl = (LocalArtifactClassLoader) this.getClass().getClassLoader(); // this class is always loaded with LocalArtifactClassLoader
// // Get the LocalReposotpry capable of finding artifact jar files
// LocalRepository rep = (LocalRepository) cl.getRepository();
// for (BasicArtifact art : ((DependencyActivityConfigurationBean) activity
// .getConfiguration())
// .getArtifactDependencies()){
// dependencies.add(rep.jarFile(art));
// }
// }
}
}
}
} else { // Just add dependencies for this activity since we can't get hold of the whole workflow
// if (dependencyType.equals(LOCAL_JARS)){
if (json.has("localDependency")) {
for (JsonNode jar : json.get("localDependency")) {
try {
dependencies.add(new File(libDir, jar.textValue()));
} catch (Exception ex) {
logger.warn("Invalid URL for " + jar, ex);
continue;
}
}
}
// }
// else if (dependencyType.equals(ARTIFACTS)){
// if (this.getClass().getClassLoader() instanceof LocalArtifactClassLoader){ // This should normally be the case
// LocalArtifactClassLoader cl = (LocalArtifactClassLoader)this.getClass().getClassLoader();
// LocalRepository rep = (LocalRepository)cl.getRepository();
// if (rep != null){
// for (BasicArtifact art : configurationBean.getArtifactDependencies()){
// dependencies.add(rep.jarFile(art));
// }
// }
// }
// else{
// // Tests will not be loaded using the LocalArtifactClassLoader as athey are loaded
// // outside Raven so there is nothing we can do about this - some tests
// // with dependencies will probably fail
// }
// }
}
// Collect the URLs of all found dependencies
for (File file: dependencies){
try{
dependenciesURLs.add(file.toURI().toURL());
}
catch(Exception ex){
logger.warn("Invalid URL for " + file.getAbsolutePath(), ex);
continue;
}
}
return dependenciesURLs;
}