ModelResolver modelResolver = new ExtensibleModelResolver(contribution, modelResolvers, modelFactories);
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();
}
// Read generated and user sca-contribution.xml files
boolean contributionMetadata = false;
for (String path: new String[]{
Contribution.SCA_CONTRIBUTION_GENERATED_META,
Contribution.SCA_CONTRIBUTION_META}) {
URL url = scanner.getArtifactURL(contributionURL, path);
try {
// Check if the file actually exists before trying to read it
URLConnection connection = url.openConnection();
connection.setUseCaches(false);
InputStream is = connection.getInputStream();
is.close();
} catch (IOException e) {
continue;
}
contributionMetadata = true;
// Read the sca-contribution.xml file
ContributionMetadata c = (ContributionMetadata)artifactProcessor.read(contributionURL, URI.create(path), url);
contribution.getImports().addAll(c.getImports());
contribution.getExports().addAll(c.getExports());
contribution.getDeployables().addAll(c.getDeployables());
}
// If no sca-contribution.xml file was provided then consider
// all composites in the contribution as deployables, and also
// read any files that are explicitly asssigned artifact processors
// as they are likely to provide relevant metadata info
if (!contributionMetadata) {
List<String> artifactURIs;
try {
artifactURIs = scanner.getArtifacts(contributionURL);
} catch (ContributionReadException e) {
artifactURIs = null;
}
if (artifactURIs != null) {
for (String artifactURI: artifactURIs) {
boolean read = false;
if (artifactURI.endsWith(".composite")) {
read = true;
} else {
int s= artifactURI.lastIndexOf("/");
String fileName = artifactURI.substring(s + 1);
if (artifactProcessors.getProcessor(fileName) != null) {
read = true;
}
}
if (read) {
URL artifactURL = scanner.getArtifactURL(contributionURL, artifactURI);
// Read each artifact
Object model = artifactProcessor.read(contributionURL, URI.create(artifactURI), artifactURL);
// In the absence of more info, consider all composites as deployable