use of org.apache.ivy.plugins.repository.url.URLResource in project ant-ivy by apache.
the class UpdateSiteLoader method readJarOrXml.
private boolean readJarOrXml(URI repoUri, String baseName, XMLInputParser reader) throws IOException, ParseException, SAXException {
// the input stream from which the xml should be read
InputStream readIn = null;
URL contentUrl = repoUri.resolve(baseName + ".jar").toURL();
URLResource res = new URLResource(contentUrl, this.timeoutConstraint);
ArtifactDownloadReport report = repositoryCacheManager.downloadRepositoryResource(res, baseName, baseName, "jar", options, urlRepository);
if (report.getDownloadStatus() == DownloadStatus.FAILED) {
// no jar file, try the xml one
contentUrl = repoUri.resolve(baseName + ".xml").toURL();
res = new URLResource(contentUrl, this.timeoutConstraint);
report = repositoryCacheManager.downloadRepositoryResource(res, baseName, baseName, "xml", options, urlRepository);
if (report.getDownloadStatus() == DownloadStatus.FAILED) {
// no xml either
return false;
}
readIn = new FileInputStream(report.getLocalFile());
} else {
InputStream in = new FileInputStream(report.getLocalFile());
try {
// compressed, let's get the pointer on the actual xml
readIn = findEntry(in, baseName + ".xml");
if (readIn == null) {
in.close();
return false;
}
} catch (IOException e) {
in.close();
throw e;
}
}
try {
reader.parse(readIn);
} finally {
readIn.close();
}
return true;
}
use of org.apache.ivy.plugins.repository.url.URLResource in project ant-ivy by apache.
the class RelativeURLRepository method getResource.
public Resource getResource(String source) throws IOException {
source = encode(source);
Resource res = resourcesCache.get(source);
if (res == null) {
URI uri;
try {
uri = new URI(source);
} catch (URISyntaxException e) {
// very weird URL, let's assume it is absolute
uri = null;
}
if (uri == null || uri.isAbsolute()) {
res = new URLResource(new URL(source), getTimeoutConstraint());
} else {
res = new URLResource(new URL(baseUrl + source), getTimeoutConstraint());
}
resourcesCache.put(source, res);
}
return res;
}
use of org.apache.ivy.plugins.repository.url.URLResource in project ant-ivy by apache.
the class IvyConvertPom method doExecute.
public void doExecute() throws BuildException {
try {
if (pomFile == null) {
throw new BuildException("source pom file is required for convertpom task");
}
if (ivyFile == null) {
throw new BuildException("destination ivy file is required for convertpom task");
}
ModuleDescriptor md = PomModuleDescriptorParser.getInstance().parseDescriptor(getSettings(), pomFile.toURI().toURL(), false);
PomModuleDescriptorParser.getInstance().toIvyFile(pomFile.toURI().toURL().openStream(), new URLResource(pomFile.toURI().toURL()), getIvyFile(), md);
} catch (MalformedURLException e) {
throw new BuildException("unable to convert given pom file to url: " + pomFile + ": " + e, e);
} catch (ParseException e) {
log(e.getMessage(), Project.MSG_ERR);
throw new BuildException("syntax errors in pom file " + pomFile + ": " + e, e);
} catch (Exception e) {
throw new BuildException("impossible convert given pom file to ivy file: " + e + " from=" + pomFile + " to=" + ivyFile, e);
}
}
use of org.apache.ivy.plugins.repository.url.URLResource in project ant-ivy by apache.
the class PomModuleDescriptorParserTest method testDependenciesWithClassifier.
@Test
public void testDependenciesWithClassifier() throws Exception {
ModuleDescriptor md = PomModuleDescriptorParser.getInstance().parseDescriptor(settings, getClass().getResource("test-dependencies-with-classifier.pom"), true);
assertNotNull(md);
assertEquals(ModuleRevisionId.newInstance("org.apache", "test", "1.0"), md.getModuleRevisionId());
DependencyDescriptor[] dds = md.getDependencies();
assertNotNull(dds);
assertEquals(1, dds.length);
assertEquals(ModuleRevisionId.newInstance("commons-logging", "commons-logging", "1.0.4"), dds[0].getDependencyRevisionId());
Map<String, String> extraAtt = Collections.singletonMap("classifier", "asl");
assertEquals(1, dds[0].getAllDependencyArtifacts().length);
assertEquals(extraAtt, dds[0].getAllDependencyArtifacts()[0].getExtraAttributes());
// now we verify the conversion to an Ivy file
PomModuleDescriptorParser.getInstance().toIvyFile(getClass().getResource("test-dependencies-with-classifier.pom").openStream(), new URLResource(getClass().getResource("test-dependencies-with-classifier.pom")), dest, md);
assertTrue(dest.exists());
// the converted Ivy file should be parsable with validate=true
ModuleDescriptor md2 = XmlModuleDescriptorParser.getInstance().parseDescriptor(new IvySettings(), dest.toURI().toURL(), true);
// and the parsed module descriptor should be similar to the original
assertNotNull(md2);
assertEquals(md.getModuleRevisionId(), md2.getModuleRevisionId());
dds = md2.getDependencies();
assertEquals(1, dds[0].getAllDependencyArtifacts().length);
assertEquals(extraAtt, dds[0].getAllDependencyArtifacts()[0].getExtraAttributes());
}
use of org.apache.ivy.plugins.repository.url.URLResource in project ant-ivy by apache.
the class XmlModuleDescriptorUpdater method update.
public static void update(InputStream in, Resource res, File destFile, UpdateOptions options) throws IOException, SAXException {
if (destFile.getParentFile() != null) {
destFile.getParentFile().mkdirs();
}
OutputStream fos = new FileOutputStream(destFile);
try {
// TODO: use resource as input stream context?
URL inputStreamContext = null;
if (res instanceof URLResource) {
inputStreamContext = ((URLResource) res).getURL();
} else if (res instanceof FileResource) {
inputStreamContext = ((FileResource) res).getFile().toURI().toURL();
}
update(inputStreamContext, in, fos, options);
} finally {
try {
in.close();
} catch (IOException e) {
Message.warn("failed to close a stream : " + e.toString());
}
try {
fos.close();
} catch (IOException e) {
Message.warn("failed to close a stream : " + e.toString());
}
}
}
Aggregations