}
contribution.setModelResolver(modelResolver);
contribution.setUnresolved(true);
// Create a contribution scanner
ContributionScanner scanner;
if ("file".equals(contributionURL.getProtocol()) && new File(contributionURL.getFile()).isDirectory()) {
scanner = new DirectoryContributionScanner();
} else {
scanner = new JarContributionScanner();
}
// Scan the contribution and list the artifacts contained in it
List<Artifact> artifacts = contribution.getArtifacts();
boolean contributionMetadata = false;
List<String> compositeURIs = new ArrayList<String>();
List<String> artifactURIs = scanner.getArtifacts(contributionURL);
for (String artifactURI: artifactURIs) {
if (artifactURI.endsWith(COMPOSITE_FILE_EXTN)) {
// TUSCANY-3561: need to process the composites last
compositeURIs.add(artifactURI);
} else {
URL artifactURL = scanner.getArtifactURL(contributionURL, artifactURI);
// Add the deployed artifact model to the contribution
Artifact artifact = this.contributionFactory.createArtifact();
artifact.setURI(artifactURI);
artifact.setLocation(artifactURL.toString());
artifacts.add(artifact);
modelResolver.addModel(artifact);
// Read each artifact
Object model = artifactProcessor.read(contributionURL, URI.create(artifactURI), artifactURL);
if (model != null) {
artifact.setModel(model);
// Add the loaded model to the model resolver
modelResolver.addModel(model);
// Add policy definitions to the list of policy definitions
if (policyDefinitionsResolver != null) {
addPolicyDefinitions(model);
}
// Merge contribution metadata into the contribution model
if (model instanceof ContributionMetadata) {
contributionMetadata = true;
ContributionMetadata c = (ContributionMetadata)model;
contribution.getImports().addAll(c.getImports());
contribution.getExports().addAll(c.getExports());
contribution.getDeployables().addAll(c.getDeployables());
contribution.getExtensions().addAll(c.getExtensions());
contribution.getAttributeExtensions().addAll(c.getAttributeExtensions());
}
}
}
}
// TUSCANY-3561: process the composites last
for (String artifactURI : compositeURIs) {
URL artifactURL = scanner.getArtifactURL(contributionURL, artifactURI);
// Add the deployed artifact model to the contribution
Artifact artifact = this.contributionFactory.createArtifact();
artifact.setURI(artifactURI);
artifact.setLocation(artifactURL.toString());