private Dependency resolveDependency(Collection parents, Dependency dependency, Stack<Dependency> parentStack) throws MissingDependencyException { Artifact artifact = dependency.getArtifact(); // if it is already resolved we are done if (artifact.isResolved()) { return dependency; } // we need an artifact resolver at this point if (artifactResolver == null) { throw new MissingDependencyException("Artifact is not resolved and there no artifact resolver available: " + artifact); } // resolve the artifact try { artifact = artifactResolver.resolveInClassLoader(artifact, parents); } catch (MissingDependencyException e) { // I'm throwing away the original error as the new message is lost on the stack as // most folks will drill down to the message on the bottom of the stack. StringBuffer sb = new StringBuffer(); sb.append(e.getMessage().trim()+"\n"+" Parent stack:\n"); boolean first = true; for (Dependency d : parentStack) { sb.append(" "+d.getArtifact().toString().trim()+(first?" (top)":"")+"\n"); first = false; } throw new MissingDependencyException(sb.toString()); } // build a new dependency object to contain the resolved artifact Dependency resolvedDependency = new Dependency(artifact, dependency.getImportType()); return resolvedDependency; }
private boolean matches(Dependency defaultDependency, Dependency actualDependency) { if (defaultDependency.getArtifact().matches(actualDependency.getArtifact()) || actualDependency.getArtifact().matches(defaultDependency.getArtifact())) { return defaultDependency.getImportType() == actualDependency.getImportType() || actualDependency.getImportType() == ImportType.ALL; } return false; }
private ArrayList getChildDependencies(Dependency dependency) { ArrayList childDependencies = new ArrayList(); for (Iterator repositoryIterator = repositories.iterator(); repositoryIterator.hasNext();) { Repository repository = (Repository) repositoryIterator.next(); if (repository.contains(dependency.getArtifact())) { // get the child artifacts LinkedHashSet childArtifacts = repository.getDependencies(dependency.getArtifact()); for (Iterator artifactIterator = childArtifacts.iterator(); artifactIterator.hasNext();) { Artifact artifact = (Artifact) artifactIterator.next(); // add each child as a classes-only dependency childDependencies.add(new Dependency(artifact, ImportType.CLASSES)); } } } return childDependencies; } }
private void verifyPrerequisites(PluginType plugin) throws MissingDependencyException { List<Dependency> missingPrereqs = getMissingPrerequisites(plugin); if (!missingPrereqs.isEmpty()) { PluginArtifactType metadata = plugin.getPluginArtifact().get(0); Artifact moduleId = toArtifact(metadata.getModuleId()); StringBuilder buf = new StringBuilder(); buf.append(moduleId.toString()).append(" requires "); Iterator<Dependency> iter = missingPrereqs.iterator(); while (iter.hasNext()) { buf.append(iter.next().getArtifact().toString()); if (iter.hasNext()) { buf.append(", "); } } buf.append(" to be installed"); throw new MissingDependencyException(buf.toString(), null, (Artifact) null); } }
public void addDependency(Artifact artifact, ImportType importType) { this.dependencies.add(new Dependency(artifact, importType)); }
private static DependencyType toDependencyType(Dependency dependency) { DependencyType dependencyType = DependencyType.Factory.newInstance(); fillArtifactType(dependency.getArtifact(), dependencyType); org.apache.geronimo.kernel.repository.ImportType importType = dependency.getImportType(); if (importType == org.apache.geronimo.kernel.repository.ImportType.CLASSES) { dependencyType.setImport(ImportType.CLASSES); } else if (importType == org.apache.geronimo.kernel.repository.ImportType.SERVICES) { dependencyType.setImport(ImportType.SERVICES); } return dependencyType; }
private boolean hasHardDependency(Artifact configurationId, ConfigurationData configurationData) { for (Iterator iterator = configurationData.getEnvironment().getDependencies().iterator(); iterator.hasNext();) { Dependency dependency = (Dependency) iterator.next(); Artifact artifact = dependency.getArtifact(); if (artifact.getVersion() != null && artifact.matches(configurationId)) { return true; } } for (Iterator iterator = configurationData.getChildConfigurations().values().iterator(); iterator.hasNext();) { ConfigurationData childConfigurationData = (ConfigurationData) iterator.next(); if (hasHardDependency(configurationId, childConfigurationData)) { return true; } } return false; }
private static Dependency toDependency(DependencyType dependencyType) { Artifact artifact = toArtifact(dependencyType, null); if (ImportType.CLASSES.equals(dependencyType.getImport())) { return new Dependency(artifact, org.apache.geronimo.kernel.repository.ImportType.CLASSES); } else if (ImportType.SERVICES.equals(dependencyType.getImport())) { return new Dependency(artifact, org.apache.geronimo.kernel.repository.ImportType.SERVICES); } else if (dependencyType.getImport() == null) { return new Dependency(artifact, org.apache.geronimo.kernel.repository.ImportType.ALL); } else { throw new IllegalArgumentException("Unknown import type: " + dependencyType.getImport()); } }
private LinkedHashSet<Artifact> resolveParentIds(ConfigurationData configurationData) throws MissingDependencyException, InvalidConfigException { Environment environment = configurationData.getEnvironment(); LinkedHashSet<Artifact> parentIds = new LinkedHashSet<Artifact>(); List<Dependency> dependencies = new ArrayList<Dependency>(environment.getDependencies()); for (ListIterator<Dependency> iterator = dependencies.listIterator(); iterator.hasNext();) { Dependency dependency = iterator.next(); Artifact resolvedArtifact = artifactResolver.resolveInClassLoader(dependency.getArtifact()); if (isConfiguration(resolvedArtifact)) { parentIds.add(resolvedArtifact); // update the dependency list to contain the resolved artifact dependency = new Dependency(resolvedArtifact, dependency.getImportType()); iterator.set(dependency); } else if (dependency.getImportType() == ImportType.SERVICES) { // Service depdendencies require that the depdencency be a configuration throw new InvalidConfigException("Dependency does not have services: " + resolvedArtifact); } } for (Iterator iterator = configurationData.getChildConfigurations().values().iterator(); iterator.hasNext();) { ConfigurationData childConfigurationData = (ConfigurationData) iterator.next(); LinkedHashSet<Artifact> childParentIds = resolveParentIds(childConfigurationData); // remove this configuration's id from the parent Ids since it will cause an infinite loop childParentIds.remove(configurationData.getId()); parentIds.addAll(childParentIds); } return parentIds; }
Artifact artifact = dependency.getArtifact(); if (parentsById.containsKey(artifact)) { Configuration parent = parentsById.get(artifact); if (dependency.getImportType() == ImportType.CLASSES || dependency.getImportType() == ImportType.ALL) { classParents.add(parent); if (dependency.getImportType() == ImportType.SERVICES || dependency.getImportType() == ImportType.ALL) { serviceParents.add(parent); } else if (dependency.getImportType() == ImportType.SERVICES) { throw new IllegalStateException("Could not find parent " + artifact + " in the parents collection"); } else {
DependencyManager dependencyManager = context.getDependencyManager(); for (Dependency dependency : context.getEnvironment().getDependencies()) { Artifact resolvedArtifact = context.resolveArtifact(dependency.getArtifact()); if(resolvedArtifact == null) { logger.warn("Dependency " + dependency.getArtifact() + " could not be resolved, its export packages are ignored"); continue; logger.warn("Fail to resolve the bundle corresponding to the artifact " + dependency.getArtifact() + ", its export packages are ignored"); continue;
private static Dependency toDependency(DependencyType dependencyType) { Artifact artifact = toArtifact(dependencyType, null); if (ImportType.CLASSES.equals(dependencyType.getImport())) { return new Dependency(artifact, org.apache.geronimo.kernel.repository.ImportType.CLASSES); } else if (ImportType.SERVICES.equals(dependencyType.getImport())) { return new Dependency(artifact, org.apache.geronimo.kernel.repository.ImportType.SERVICES); } else if (dependencyType.getImport() == null) { return new Dependency(artifact, org.apache.geronimo.kernel.repository.ImportType.ALL); } else { throw new IllegalArgumentException("Unknown import type: " + dependencyType.getImport()); } }
public static void addDependencies(TreeEntry curr, Configuration conf) { if (curr == null || conf == null) return; TreeEntry dep = new TreeEntry("dependencies", NOT_LEAF_TYPE); curr.addChild(dep); for (Iterator<Dependency> iterator = conf.getEnvironment().getDependencies().iterator(); iterator.hasNext();) { dep.addChild(new TreeEntry(iterator.next().getArtifact().toString(), NORMAL_TYPE)); } for (Iterator<Artifact> iterator = conf.getDependencyNode().getServiceParents().iterator(); iterator.hasNext();) { Artifact artifact = iterator.next(); dep.addChild(new TreeEntry(artifact.toString(), NORMAL_TYPE)); } }
private List<Dependency> getMissingPrerequisites(PluginType plugin) { if (plugin.getPluginArtifact().size() != 1) { throw new IllegalArgumentException("A plugin configuration must include one plugin artifact, not " + plugin.getPluginArtifact().size()); } PluginArtifactType metadata = plugin.getPluginArtifact().get(0); List<PrerequisiteType> prereqs = metadata.getPrerequisite(); ArrayList<Dependency> missingPrereqs = new ArrayList<Dependency>(); for (PrerequisiteType prereq : prereqs) { Artifact artifact = toArtifact(prereq.getId()); try { if (getServerInstance("default", servers).getArtifactResolver().queryArtifacts(artifact).length == 0) { missingPrereqs.add(new Dependency(artifact, ImportType.ALL)); } } catch (NoServerInstanceException e) { throw new RuntimeException("Invalid setup, no default server instance registered"); } } return missingPrereqs; }
public static DependencyType toDependencyType(Dependency dep, boolean includeVersion) { Artifact id = dep.getArtifact(); DependencyType dependency = new DependencyType(); dependency.setGroupId(id.getGroupId()); dependency.setArtifactId(id.getArtifactId()); if (includeVersion) { dependency.setVersion(id.getVersion() == null ? null : id.getVersion().toString()); } dependency.setType(id.getType()); return dependency; }
configurationData.getEnvironment().addDependency(new Dependency(ACTIVEMQ_ARTIFACT, ImportType.ALL));
Artifact artifact = dep.getArtifact(); log.debug("Attempting to download dependency={} for configuration={}", artifact, configID); downloadArtifact(artifact, metadata, repos, username, password, monitor, soFar, parentStack, true, servers, loadOverride);