use of org.apache.ivy.Ivy in project ant-ivy by apache.
the class IvyRepositoryReport method doExecute.
public void doExecute() throws BuildException {
Ivy ivy = getIvyInstance();
IvySettings settings = ivy.getSettings();
if (xsl && xslFile == null) {
throw new BuildException("xsl file is mandatory when using xsl generation");
}
if (module == null && PatternMatcher.EXACT.equals(matcher)) {
throw new BuildException("no module name provided for ivy repository graph task: " + "It can either be set explicitly via the attribute 'module' or " + "via 'ivy.module' property or a prior call to <resolve/>");
} else if (module == null && !PatternMatcher.EXACT.equals(matcher)) {
module = PatternMatcher.ANY_EXPRESSION;
}
ModuleRevisionId moduleRevisionId = ModuleRevisionId.newInstance(organisation, module, revision);
try {
ModuleRevisionId criteria = (revision == null) || settings.getVersionMatcher().isDynamic(moduleRevisionId) ? new ModuleRevisionId(new ModuleId(organisation, module), branch, "*") : new ModuleRevisionId(new ModuleId(organisation, module), branch, revision);
ModuleRevisionId[] mrids = ivy.listModules(criteria, settings.getMatcher(matcher));
// replace all found revisions with the original requested revision
Set<ModuleRevisionId> modules = new HashSet<>();
for (ModuleRevisionId mrid : mrids) {
modules.add(ModuleRevisionId.newInstance(mrid, revision));
}
mrids = modules.toArray(new ModuleRevisionId[modules.size()]);
ModuleDescriptor md = DefaultModuleDescriptor.newCallerInstance(mrids, true, false);
String resolveId = ResolveOptions.getDefaultResolveId(md);
ResolveReport report = ivy.resolve(md, new ResolveOptions().setResolveId(resolveId).setValidate(doValidate(settings)));
ResolutionCacheManager cacheMgr = getIvyInstance().getResolutionCacheManager();
new XmlReportOutputter().output(report, cacheMgr, new ResolveOptions());
if (graph) {
gengraph(cacheMgr, md.getModuleRevisionId().getOrganisation(), md.getModuleRevisionId().getName());
}
if (dot) {
gendot(cacheMgr, md.getModuleRevisionId().getOrganisation(), md.getModuleRevisionId().getName());
}
if (xml) {
FileUtil.copy(cacheMgr.getConfigurationResolveReportInCache(resolveId, "default"), new File(getTodir(), outputname + ".xml"), null);
}
if (xsl) {
genreport(cacheMgr, md.getModuleRevisionId().getOrganisation(), md.getModuleRevisionId().getName());
}
} catch (Exception e) {
throw new BuildException("impossible to generate graph for " + moduleRevisionId + ": " + e, e);
}
}
use of org.apache.ivy.Ivy in project ant-ivy by apache.
the class IvyTask method getIvyInstance.
protected Ivy getIvyInstance() {
Object antIvyEngine;
if (antIvyEngineRef == null) {
antIvyEngine = IvyAntSettings.getDefaultInstance(this);
} else {
antIvyEngine = antIvyEngineRef.getReferencedObject(getProject());
if (!antIvyEngine.getClass().getName().equals(IvyAntSettings.class.getName())) {
throw new BuildException(antIvyEngineRef.getRefId() + " doesn't reference an ivy:settings", getLocation());
}
if (!(antIvyEngine instanceof IvyAntSettings)) {
throw new BuildException(antIvyEngineRef.getRefId() + " has been defined in a different classloader. " + "Please use the same loader when defining your task, or " + "redeclare your ivy:settings in this classloader", getLocation());
}
}
Ivy ivy = ((IvyAntSettings) antIvyEngine).getConfiguredIvyInstance(this);
AntMessageLogger.register(this, ivy);
return ivy;
}
use of org.apache.ivy.Ivy in project ant-ivy by apache.
the class IvyVar method doExecute.
public void doExecute() throws BuildException {
Ivy ivy = getIvyInstance();
IvySettings settings = ivy.getSettings();
if (getName() != null) {
settings.setVariable(getVarName(getName()), getValue());
} else {
Properties props = new Properties();
InputStream is = null;
try {
if (getFile() != null) {
is = new FileInputStream(getFile());
} else if (getUrl() != null) {
is = new URL(getUrl()).openStream();
} else {
throw new BuildException("specify either name or file or url to ivy var task");
}
props.load(is);
} catch (Exception ex) {
throw new BuildException("impossible to load variables from file: " + ex, ex);
} finally {
if (is != null) {
try {
is.close();
} catch (Exception e) {
// ignore
}
}
}
for (Map.Entry<Object, Object> entry : props.entrySet()) {
settings.setVariable(getVarName((String) entry.getKey()), (String) entry.getValue());
}
}
}
use of org.apache.ivy.Ivy in project ant-ivy by apache.
the class IvyConfigureTest method testOverrideTrue.
@Test
public void testOverrideTrue() {
configure.setFile(new File("test/repositories/ivysettings.xml"));
configure.execute();
Ivy ivy = getIvyInstance();
assertNotNull(ivy);
configure = new IvyConfigure();
configure.setProject(project);
configure.setOverride("true");
configure.setFile(new File("test/repositories/ivysettings.xml"));
configure.execute();
assertNotNull(getIvyInstance());
assertNotSame(ivy, getIvyInstance());
}
use of org.apache.ivy.Ivy in project ant-ivy by apache.
the class BuildOBRTask method doExecute.
public void doExecute() throws BuildException {
if (file == null) {
throw new BuildException("No output file specified: use the attribute 'out'");
}
Iterable<ManifestAndLocation> it;
if (resolverName != null) {
if (baseDir != null) {
throw new BuildException("specify only one of 'resolver' or 'baseDir'");
}
if (cacheName != null) {
throw new BuildException("specify only one of 'resolver' or 'cache'");
}
Ivy ivy = getIvyInstance();
IvySettings settings = ivy.getSettings();
DependencyResolver resolver = settings.getResolver(resolverName);
if (resolver == null) {
throw new BuildException("the resolver '" + resolverName + "' was not found");
}
if (!(resolver instanceof BasicResolver)) {
throw new BuildException("the type of resolver '" + resolver.getClass().getName() + "' is not supported.");
}
it = new ResolverManifestIterable((BasicResolver) resolver);
} else if (baseDir != null) {
if (cacheName != null) {
throw new BuildException("specify only one of 'baseDir' or 'cache'");
}
if (!baseDir.isDirectory()) {
throw new BuildException(baseDir + " is not a directory");
}
it = new FSManifestIterable(baseDir);
} else if (cacheName != null) {
Ivy ivy = getIvyInstance();
RepositoryCacheManager cacheManager = ivy.getSettings().getRepositoryCacheManager(cacheName);
if (!(cacheManager instanceof DefaultRepositoryCacheManager)) {
throw new BuildException("the type of cache '" + cacheManager.getClass().getName() + "' is not supported.");
}
File basedir = ((DefaultRepositoryCacheManager) cacheManager).getBasedir();
it = new FSManifestIterable(basedir);
} else {
prepareAndCheck();
try {
it = new ArtifactReportManifestIterable(getArtifactReports(), sourceTypes);
} catch (ParseException e) {
throw new BuildException("Impossible to parse the artifact reports: " + e.getMessage(), e);
}
}
OutputStream out;
try {
out = new FileOutputStream(file);
} catch (FileNotFoundException e) {
throw new BuildException(file + " was not found", e);
}
ContentHandler hd;
try {
hd = OBRXMLWriter.newHandler(out, encoding, indent);
} catch (TransformerConfigurationException e) {
throw new BuildException("Sax configuration error: " + e.getMessage(), e);
}
class AntMessageLogger2 extends AntMessageLogger {
AntMessageLogger2() {
super(BuildOBRTask.this);
}
}
IvyContext.getContext().getMessageLogger();
Message.setDefaultLogger(new AntMessageLogger2());
try {
OBRXMLWriter.writeManifests(it, hd, quiet);
} catch (SAXException e) {
throw new BuildException("Sax serialisation error: " + e.getMessage(), e);
}
try {
out.flush();
out.close();
} catch (IOException e) {
// don't care
}
Message.sumupProblems();
}
Aggregations