use of org.apache.ivy.plugins.repository.file.FileResource in project ant-ivy by apache.
the class BasicResolver method getArtifactRef.
protected ResolvedResource getArtifactRef(Artifact artifact, Date date) {
IvyContext.getContext().set(getName() + ".artifact", artifact);
try {
ResolvedResource ret = findArtifactRef(artifact, date);
if (ret == null && artifact.getUrl() != null) {
URL url = artifact.getUrl();
Message.verbose("\tusing url for " + artifact + ": " + url);
logArtifactAttempt(artifact, url.toExternalForm());
Resource resource;
if ("file".equals(url.getProtocol())) {
File f;
try {
f = new File(new URI(url.toExternalForm()));
} catch (URISyntaxException e) {
// unexpected, try to get the best of it
f = new File(url.getPath());
}
resource = new FileResource(new FileRepository(), f);
} else {
resource = new URLResource(url, this.getTimeoutConstraint());
}
ret = new ResolvedResource(resource, artifact.getModuleRevisionId().getRevision());
}
return ret;
} finally {
IvyContext.getContext().set(getName() + ".artifact", null);
}
}
use of org.apache.ivy.plugins.repository.file.FileResource in project ant-ivy by apache.
the class CacheResolver method download.
@Override
public DownloadReport download(Artifact[] artifacts, DownloadOptions options) {
ensureConfigured();
clearArtifactAttempts();
DownloadReport dr = new DownloadReport();
for (Artifact artifact : artifacts) {
final ArtifactDownloadReport adr = new ArtifactDownloadReport(artifact);
dr.addArtifactReport(adr);
ResolvedResource artifactRef = getArtifactRef(artifact, null);
if (artifactRef != null) {
Message.verbose("\t[NOT REQUIRED] " + artifact);
ArtifactOrigin origin = new ArtifactOrigin(artifact, true, artifactRef.getResource().getName());
File archiveFile = ((FileResource) artifactRef.getResource()).getFile();
adr.setDownloadStatus(DownloadStatus.NO);
adr.setSize(archiveFile.length());
adr.setArtifactOrigin(origin);
adr.setLocalFile(archiveFile);
} else {
adr.setDownloadStatus(DownloadStatus.FAILED);
}
}
return dr;
}
use of org.apache.ivy.plugins.repository.file.FileResource in project ant-ivy by apache.
the class OSGiManifestParserTest method testFileResource.
/**
* Tests that the
* {@link OSGiManifestParser#parseDescriptor(ParserSettings, URL, Resource, boolean)}
* works fine for descriptors that are backed by {@link FileResource}
*
* @throws Exception if something goes wrong
*/
@Test
public void testFileResource() throws Exception {
final File manifestFile = new File("test/repositories/osgi/module1/META-INF/MANIFEST.MF");
assertTrue("Manifest file is either missing or not a file at " + manifestFile.getAbsolutePath(), manifestFile.isFile());
final Resource manifestFileResource = new FileResource(null, manifestFile);
final ModuleDescriptor md = OSGiManifestParser.getInstance().parseDescriptor(settings, manifestFile.toURI().toURL(), manifestFileResource, true);
assertNotNull("Module descriptor created through a OSGi parser was null", md);
assertEquals("Unexpected organization name in module descriptor created through a OSGi parser", "bundle", md.getModuleRevisionId().getOrganisation());
assertEquals("Unexpected module name in module descriptor created through a OSGi parser", "module1", md.getModuleRevisionId().getName());
assertEquals("Unexpected version in module descriptor created through a OSGi parser", "1.2.3", md.getModuleRevisionId().getRevision());
}
use of org.apache.ivy.plugins.repository.file.FileResource 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