use of org.apache.ivy.plugins.resolver.DependencyResolver in project ant-ivy by apache.
the class IvySettings method dumpSettings.
private void dumpSettings() {
Message.verbose("\tdefault cache: " + getDefaultCache());
Message.verbose("\tdefault resolver: " + getDefaultResolver());
Message.debug("\tdefault latest strategy: " + getDefaultLatestStrategy());
Message.debug("\tdefault conflict manager: " + getDefaultConflictManager());
Message.debug("\tcircular dependency strategy: " + getCircularDependencyStrategy());
Message.debug("\tvalidate: " + doValidate());
Message.debug("\tcheck up2date: " + isCheckUpToDate());
if (!classpathURLs.isEmpty()) {
Message.verbose("\t-- " + classpathURLs.size() + " custom classpath urls:");
for (URL url : classpathURLs) {
Message.debug("\t\t" + url);
}
}
Message.verbose("\t-- " + resolversMap.size() + " resolvers:");
for (DependencyResolver resolver : resolversMap.values()) {
resolver.dumpSettings();
}
Message.debug("\tmodule settings:");
moduleSettings.dump("\t\t");
}
use of org.apache.ivy.plugins.resolver.DependencyResolver in project ant-ivy by apache.
the class ResolveEngine method findModule.
public ResolvedModuleRevision findModule(ModuleRevisionId id, ResolveOptions options) {
DependencyResolver r = settings.getResolver(id);
if (r == null) {
throw new IllegalStateException("no resolver found for " + id.getModuleId());
}
DefaultModuleDescriptor md = DefaultModuleDescriptor.newCallerInstance(id, new String[] { "*" }, false, false);
if (options.getResolveId() == null) {
options.setResolveId(ResolveOptions.getDefaultResolveId(md));
}
try {
return r.getDependency(new DefaultDependencyDescriptor(id, true), new ResolveData(this, options, new ConfigurationResolveReport(this, md, "default", null, options)));
} catch (ParseException e) {
throw new RuntimeException("problem while parsing repository module descriptor for " + id + ": " + e, e);
}
}
use of org.apache.ivy.plugins.resolver.DependencyResolver in project ant-ivy by apache.
the class PublishEngine method publish.
/**
* Publishes a module to the repository. The publish can update the ivy file to publish if
* update is set to true. In this case it will use the given pubrevision, pubdate and status. If
* pubdate is null it will default to the current date. If status is null it will default to the
* current ivy file status (which itself defaults to integration if none is found). If update is
* false, then if the revision is not the same in the ivy file than the one expected (given as
* parameter), this method will fail with an IllegalArgumentException. pubdate and status are
* not used if update is false. extra artifacts can be used to publish more artifacts than
* actually declared in the ivy file. This can be useful to publish additional metadata or
* reports. The extra artifacts array can be null (= no extra artifacts), and if non null only
* the name, type, ext url and extra attributes of the artifacts are really used. Other methods
* can return null safely.
*
* @param mrid ModuleRevisionId
* @param srcArtifactPattern a Collection of String
* @param resolverName String
* @param options PublishOptions
* @return Collection<Artifact>
* @throws IOException if something goes wrong
*/
public Collection<Artifact> publish(ModuleRevisionId mrid, Collection<String> srcArtifactPattern, String resolverName, PublishOptions options) throws IOException {
Message.info(":: publishing :: " + mrid.getModuleId());
Message.verbose("\tvalidate = " + options.isValidate());
long start = System.currentTimeMillis();
options.setSrcIvyPattern(settings.substitute(options.getSrcIvyPattern()));
if (options.getPubBranch() == null) {
options.setPubbranch(mrid.getBranch());
}
if (options.getPubrevision() == null) {
options.setPubrevision(mrid.getRevision());
}
ModuleRevisionId pubmrid = ModuleRevisionId.newInstance(mrid, options.getPubBranch(), options.getPubrevision());
// let's find the resolved module descriptor
ModuleDescriptor md = null;
if (options.getSrcIvyPattern() != null) {
File ivyFile = settings.resolveFile(IvyPatternHelper.substitute(options.getSrcIvyPattern(), DefaultArtifact.newIvyArtifact(pubmrid, new Date())));
if (!ivyFile.exists()) {
throw new IllegalArgumentException("ivy file to publish not found for " + mrid + ": call deliver before (" + ivyFile + ")");
}
URL ivyFileURL = ivyFile.toURI().toURL();
try {
md = XmlModuleDescriptorParser.getInstance().parseDescriptor(settings, ivyFileURL, false);
if (options.isUpdate()) {
File tmp = File.createTempFile("ivy", ".xml");
tmp.deleteOnExit();
String[] confs = replaceWildcards(options.getConfs(), md);
Set<String> confsToRemove = new HashSet<>(Arrays.asList(md.getConfigurationsNames()));
confsToRemove.removeAll(Arrays.asList(confs));
try {
XmlModuleDescriptorUpdater.update(ivyFileURL, tmp, new UpdateOptions().setSettings(settings).setStatus(options.getStatus() == null ? md.getStatus() : options.getStatus()).setRevision(options.getPubrevision()).setBranch(options.getPubBranch()).setPubdate(options.getPubdate() == null ? new Date() : options.getPubdate()).setMerge(options.isMerge()).setMergedDescriptor(md).setConfsToExclude(confsToRemove.toArray(new String[confsToRemove.size()])));
ivyFile = tmp;
// we parse the new file to get updated module descriptor
md = XmlModuleDescriptorParser.getInstance().parseDescriptor(settings, ivyFile.toURI().toURL(), false);
options.setSrcIvyPattern(ivyFile.getAbsolutePath());
} catch (SAXException e) {
throw new IllegalStateException("bad ivy file for " + mrid + ": " + ivyFile + ": " + e);
}
} else if (!options.getPubrevision().equals(md.getModuleRevisionId().getRevision())) {
throw new IllegalArgumentException("cannot publish " + ivyFile + " as " + options.getPubrevision() + ": bad revision found in ivy file (Revision: " + md.getModuleRevisionId().getRevision() + "). Use forcedeliver or update.");
}
} catch (ParseException e) {
throw new IllegalStateException("bad ivy file for " + mrid + ": " + ivyFile + ": " + e);
}
} else {
ResolutionCacheManager cacheManager = settings.getResolutionCacheManager();
try {
md = cacheManager.getResolvedModuleDescriptor(mrid);
} catch (ParseException e) {
throw new IllegalStateException("bad ivy file in cache for " + mrid + ": " + e);
}
md.setResolvedModuleRevisionId(pubmrid);
}
DependencyResolver resolver = settings.getResolver(resolverName);
if (resolver == null) {
throw new IllegalArgumentException("unknown resolver " + resolverName);
}
// collect all declared artifacts of this module
Collection<Artifact> missing = publish(md, srcArtifactPattern, resolver, options);
Message.verbose("\tpublish done (" + (System.currentTimeMillis() - start) + "ms)");
return missing;
}
use of org.apache.ivy.plugins.resolver.DependencyResolver in project ant-ivy by apache.
the class PomModuleDescriptorParserTest method createIvySettingsForParentLicenseTesting.
private IvySettings createIvySettingsForParentLicenseTesting(final String parentPomFileName, final String parentOrgName, final String parentModuleName) throws Exception {
final URL parentPomURL = this.getClass().getResource(parentPomFileName);
assertNotNull("Could not find " + parentPomFileName, parentPomURL);
final PomReader parentPomReader = new PomReader(parentPomURL, new URLResource(parentPomURL));
final License[] parentLicenses = parentPomReader.getLicenses();
assertNotNull("Missing licenses in parent pom " + parentPomFileName, parentLicenses);
assertEquals("Unexpected number of licenses in parent pom " + parentPomFileName, 1, parentLicenses.length);
final DependencyResolver dependencyResolver = new MockedDependencyResolver() {
@Override
protected ModuleDescriptor getModuleDescriptor(DependencyDescriptor dependencyDescriptor) {
final String depOrg = dependencyDescriptor.getDependencyId().getOrganisation();
final String depModuleName = dependencyDescriptor.getDependencyId().getName();
if (depOrg.equals(parentOrgName) && depModuleName.equals(parentModuleName)) {
final DefaultModuleDescriptor moduleDescriptor = DefaultModuleDescriptor.newDefaultInstance(dependencyDescriptor.getDependencyRevisionId());
for (final License license : parentLicenses) {
moduleDescriptor.addLicense(license);
}
return moduleDescriptor;
} else {
return super.getModuleDescriptor(dependencyDescriptor);
}
}
};
final IvySettings ivySettings = new IvySettings();
ivySettings.setDictatorResolver(dependencyResolver);
return ivySettings;
}
use of org.apache.ivy.plugins.resolver.DependencyResolver in project ant-ivy by apache.
the class OnlineXmlSettingsParserTest method testIncludeHttpUrl.
// remote.test
@Test
public void testIncludeHttpUrl() throws Exception {
configureURLHandler();
IvySettings settings = new IvySettings();
XmlSettingsParser parser = new XmlSettingsParser(settings);
parser.parse(new URL("http://ant.apache.org/ivy/test/ivysettings-include-http-url.xml"));
DependencyResolver resolver = settings.getResolver("ivyrep");
assertNotNull(resolver);
assertTrue(resolver instanceof IvyRepResolver);
}
Aggregations