use of org.apache.ivy.osgi.repo.ManifestAndLocation 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();
}
use of org.apache.ivy.osgi.repo.ManifestAndLocation in project ant-ivy by apache.
the class OBRXMLWriter method writeManifests.
public static void writeManifests(Iterable<ManifestAndLocation> manifestAndLocations, ContentHandler handler, boolean quiet) throws SAXException {
int level = quiet ? Message.MSG_DEBUG : Message.MSG_WARN;
handler.startDocument();
AttributesImpl atts = new AttributesImpl();
handler.startElement("", RepositoryHandler.REPOSITORY, RepositoryHandler.REPOSITORY, atts);
int nbOk = 0;
int nbRejected = 0;
for (ManifestAndLocation manifestAndLocation : manifestAndLocations) {
BundleInfo bundleInfo;
try {
bundleInfo = ManifestParser.parseManifest(manifestAndLocation.getManifest());
bundleInfo.addArtifact(new BundleArtifact(false, manifestAndLocation.getUri(), null));
if (manifestAndLocation.getSourceURI() != null) {
bundleInfo.addArtifact(new BundleArtifact(true, manifestAndLocation.getSourceURI(), null));
}
nbOk++;
} catch (ParseException e) {
nbRejected++;
IvyContext.getContext().getMessageLogger().log("Rejected " + manifestAndLocation.getUri() + ": " + e.getMessage(), level);
continue;
}
saxBundleInfo(bundleInfo, handler);
}
handler.endElement("", RepositoryHandler.REPOSITORY, RepositoryHandler.REPOSITORY);
handler.endDocument();
Message.info(nbOk + " bundle" + (nbOk > 1 ? "s" : "") + " added, " + nbRejected + " bundle" + (nbRejected > 1 ? "s" : "") + " rejected.");
}
Aggregations