Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 88162 Details for
Bug 214816
[prov] Local caching of remote metadata repositories
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
Updated patch
patch.txt (text/plain), 14.20 KB, created by
John Arthorne
on 2008-01-29 12:38:54 EST
(
hide
)
Description:
Updated patch
Filename:
MIME Type:
Creator:
John Arthorne
Created:
2008-01-29 12:38:54 EST
Size:
14.20 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.equinox.p2.metadata.repository >Index: src/org/eclipse/equinox/internal/p2/metadata/repository/SimpleMetadataRepositoryFactory.java >=================================================================== >RCS file: /cvsroot/eclipse/equinox-incubator/provisioning/org.eclipse.equinox.p2.metadata.repository/src/org/eclipse/equinox/internal/p2/metadata/repository/SimpleMetadataRepositoryFactory.java,v >retrieving revision 1.19 >diff -u -r1.19 SimpleMetadataRepositoryFactory.java >--- src/org/eclipse/equinox/internal/p2/metadata/repository/SimpleMetadataRepositoryFactory.java 28 Jan 2008 14:20:13 -0000 1.19 >+++ src/org/eclipse/equinox/internal/p2/metadata/repository/SimpleMetadataRepositoryFactory.java 29 Jan 2008 17:35:05 -0000 >@@ -15,8 +15,9 @@ > import java.util.jar.JarEntry; > import java.util.jar.JarInputStream; > import org.eclipse.core.runtime.*; >-import org.eclipse.equinox.internal.p2.core.helpers.Tracing; >+import org.eclipse.equinox.internal.p2.core.helpers.*; > import org.eclipse.equinox.p2.core.ProvisionException; >+import org.eclipse.equinox.p2.core.location.AgentLocation; > import org.eclipse.equinox.p2.metadata.repository.IMetadataRepository; > import org.eclipse.equinox.spi.p2.metadata.repository.IMetadataRepositoryFactory; > import org.eclipse.osgi.util.NLS; >@@ -26,6 +27,7 @@ > private static final String JAR_EXTENSION = ".jar"; //$NON-NLS-1$ > private static final String XML_EXTENSION = ".xml"; //$NON-NLS-1$ > private static final String CONTENT_FILENAME = "content"; //$NON-NLS-1$ >+ private static final String PROTOCOL_FILE = "file"; //$NON-NLS-1$ > > public IMetadataRepository create(URL location, String name, String type) { > if (location.getProtocol().equals("file")) //$NON-NLS-1$ >@@ -33,53 +35,97 @@ > return new URLMetadataRepository(location, name); > } > >+ /** >+ * Returns a file in the local file system that contains the contents of the >+ * metadata repository at the given location. >+ */ >+ private File getLocalFile(URL location, IProgressMonitor monitor) throws IOException, ProvisionException { >+ File localFile = null; >+ URL jarLocation = URLMetadataRepository.getActualLocation(location, JAR_EXTENSION); >+ URL xmlLocation = URLMetadataRepository.getActualLocation(location, XML_EXTENSION); >+ // If the repository is local, we can return the repository file directly >+ if (PROTOCOL_FILE.equals(xmlLocation.getProtocol())) { >+ //look for a compressed local file >+ localFile = new File(jarLocation.getPath()); >+ if (localFile.exists()) >+ return localFile; >+ //look for an uncompressed local file >+ localFile = new File(xmlLocation.getPath()); >+ if (localFile.exists()) >+ return localFile; >+ String msg = NLS.bind(Messages.io_failedRead, location); >+ throw new ProvisionException(new Status(IStatus.ERROR, Activator.ID, ProvisionException.REPOSITORY_NOT_FOUND, msg, null)); >+ } >+ //file is not local, so we need to get a locally cached copy >+ AgentLocation agentLocation = (AgentLocation) ServiceHelper.getService(Activator.getContext(), AgentLocation.class.getName()); >+ URL dataArea = agentLocation.getDataArea(Activator.ID + "/cache/"); //$NON-NLS-1$ >+ File dataAreaFile = URLUtil.toFile(dataArea); >+ int hashCode = location.hashCode(); >+ URL remoteLocation; >+ long remoteTimestamp = getTransport().getLastModified(jarLocation.toExternalForm()); >+ if (remoteTimestamp != 0) { >+ //remote file is in jar form >+ remoteLocation = jarLocation; >+ localFile = new File(dataAreaFile, CONTENT_FILENAME + hashCode + JAR_EXTENSION); >+ } else { >+ //check for remote file in xml form >+ remoteTimestamp = getTransport().getLastModified(xmlLocation.toExternalForm()); >+ if (remoteTimestamp == 0) { >+ //there is no remote file in either form >+ String msg = NLS.bind(Messages.io_failedRead, location); >+ throw new ProvisionException(new Status(IStatus.ERROR, Activator.ID, ProvisionException.REPOSITORY_NOT_FOUND, msg, null)); >+ } >+ remoteLocation = xmlLocation; >+ localFile = new File(dataAreaFile, CONTENT_FILENAME + hashCode + XML_EXTENSION); >+ } >+ long cacheTimestamp = localFile.lastModified(); >+ //if the cache is out of date, refresh with latest contents >+ if (remoteTimestamp > cacheTimestamp) { >+ localFile.getParentFile().mkdirs(); >+ OutputStream metadata = new BufferedOutputStream(new FileOutputStream(localFile)); >+ try { >+ IStatus result = getTransport().download(remoteLocation.toExternalForm(), metadata, monitor); >+ if (!result.isOK()) >+ throw new ProvisionException(result); >+ } finally { >+ metadata.close(); >+ } >+ } >+ return localFile; >+ } >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.equinox.spi.p2.metadata.repository.IMetadataRepositoryFactory#load(java.net.URL, org.eclipse.core.runtime.IProgressMonitor) >+ */ > public IMetadataRepository load(URL location, IProgressMonitor monitor) throws ProvisionException { > long time = 0; >- boolean compress = true; > final String debugMsg = "Restoring metadata repository "; //$NON-NLS-1$ >- File temp = null; > if (Tracing.DEBUG_METADATA_PARSING) { > Tracing.debug(debugMsg + location); > time = -System.currentTimeMillis(); > } >+ SubMonitor sub = SubMonitor.convert(monitor, 400); > try { >- temp = File.createTempFile(CONTENT_FILENAME, JAR_EXTENSION); >- SubMonitor sub = SubMonitor.convert(monitor, 300); >- OutputStream metadata = new BufferedOutputStream(new FileOutputStream(temp)); >- IStatus status = getTransport().download(URLMetadataRepository.getActualLocation(location, JAR_EXTENSION).toExternalForm(), metadata, sub); >- URL actualFile = URLMetadataRepository.getActualLocation(location); >- if (!status.isOK()) { >- // retry uncompressed >- metadata.close(); >- if (!temp.delete()) { >- temp.deleteOnExit(); >- } >- temp = File.createTempFile(CONTENT_FILENAME, XML_EXTENSION); >- metadata = new BufferedOutputStream(new FileOutputStream(temp)); >- compress = false; >- status = getTransport().download(URLMetadataRepository.getActualLocation(location, XML_EXTENSION).toExternalForm(), metadata, sub); >- if (!status.isOK()) >- return null; >- } >- if (metadata != null) { >- metadata.close(); >- } >- InputStream inStream = new BufferedInputStream(new FileInputStream(temp)); >- if (compress) { >- JarInputStream jInStream = new JarInputStream(inStream); >- JarEntry jarEntry = jInStream.getNextJarEntry(); >- String entryName = new Path(actualFile.getPath()).lastSegment(); >- while (jarEntry != null && (!entryName.equals(jarEntry.getName()))) { >- jarEntry = jInStream.getNextJarEntry(); >- } >- if (jarEntry == null) { >- throw new FileNotFoundException(actualFile.getPath().toString()); >- } >- inStream = jInStream; >- } >- InputStream descriptorStream = new BufferedInputStream(inStream); >+ File localFile = getLocalFile(location, sub.newChild(300)); >+ InputStream inStream = new BufferedInputStream(new FileInputStream(localFile)); >+ JarInputStream jarStream = null; > try { >- IMetadataRepository result = new MetadataRepositoryIO().read(temp.toURL(), descriptorStream, sub.newChild(100)); >+ //if reading from a jar, obtain a stream on the entry with the actual contents >+ if (localFile.getAbsolutePath().endsWith(JAR_EXTENSION)) { >+ jarStream = new JarInputStream(inStream); >+ JarEntry jarEntry = jarStream.getNextJarEntry(); >+ String entryName = URLMetadataRepository.CONTENT_FILENAME + URLMetadataRepository.XML_EXTENSION; >+ while (jarEntry != null && (!entryName.equals(jarEntry.getName()))) { >+ jarEntry = jarStream.getNextJarEntry(); >+ } >+ if (jarEntry == null) { >+ throw new FileNotFoundException("Repository not found in compressed file."); //$NON-NLS-1$ >+ } >+ } >+ //parse the repository descriptor file >+ sub.setWorkRemaining(100); >+ InputStream descriptorStream = jarStream != null ? jarStream : inStream; >+ IMetadataRepository result = new MetadataRepositoryIO().read(localFile.toURL(), descriptorStream, sub.newChild(100)); > if (result instanceof LocalMetadataRepository) > ((LocalMetadataRepository) result).initializeAfterLoad(location); > if (result instanceof URLMetadataRepository) >@@ -90,8 +136,8 @@ > } > return result; > } finally { >- if (descriptorStream != null) >- descriptorStream.close(); >+ safeClose(jarStream); >+ safeClose(inStream); > } > } catch (FileNotFoundException e) { > String msg = NLS.bind(Messages.io_failedRead, location); >@@ -100,9 +146,20 @@ > String msg = NLS.bind(Messages.io_failedRead, location); > throw new ProvisionException(new Status(IStatus.ERROR, Activator.ID, ProvisionException.REPOSITORY_FAILED_READ, msg, e)); > } finally { >- if (temp != null && !temp.delete()) { >- temp.deleteOnExit(); >- } >+ monitor.done(); >+ } >+ } >+ >+ /** >+ * Closes a stream, ignoring any secondary exceptions >+ */ >+ private void safeClose(InputStream stream) { >+ if (stream == null) >+ return; >+ try { >+ stream.close(); >+ } catch (IOException e) { >+ //ignore > } > } > >Index: src/org/eclipse/equinox/internal/p2/metadata/repository/ECFMetadataTransport.java >=================================================================== >RCS file: /cvsroot/eclipse/equinox-incubator/provisioning/org.eclipse.equinox.p2.metadata.repository/src/org/eclipse/equinox/internal/p2/metadata/repository/ECFMetadataTransport.java,v >retrieving revision 1.2 >diff -u -r1.2 ECFMetadataTransport.java >--- src/org/eclipse/equinox/internal/p2/metadata/repository/ECFMetadataTransport.java 23 Jan 2008 02:17:58 -0000 1.2 >+++ src/org/eclipse/equinox/internal/p2/metadata/repository/ECFMetadataTransport.java 29 Jan 2008 17:35:05 -0000 >@@ -13,6 +13,7 @@ > import java.io.IOException; > import java.io.OutputStream; > import org.eclipse.core.runtime.*; >+import org.eclipse.ecf.core.*; > import org.eclipse.ecf.filetransfer.*; > import org.eclipse.ecf.filetransfer.events.*; > import org.eclipse.ecf.filetransfer.identity.FileCreateException; >@@ -50,6 +51,75 @@ > return transfer(factory.newInstance(), toDownload, target, monitor); > } > >+ /** >+ * Gets the last modified date for the specified file. >+ * @param location - The URL location of the file. >+ * @return A <code>long</code> representing the date. Returns <code>0</code> if the file is not found or an error occurred. >+ */ >+ public long getLastModified(String location) { >+ IContainer container; >+ try { >+ container = ContainerFactory.getDefault().createContainer(); >+ } catch (ContainerCreateException e) { >+ return 0; >+ } >+ IRemoteFileSystemBrowserContainerAdapter adapter = (IRemoteFileSystemBrowserContainerAdapter) container.getAdapter(IRemoteFileSystemBrowserContainerAdapter.class); >+ if (adapter == null) { >+ return 0; >+ } >+ IRemoteFile remoteFile = checkFile(adapter, location); >+ if (remoteFile == null) { >+ return 0; >+ } >+ return remoteFile.getInfo().getLastModified(); >+ } >+ >+ private IRemoteFile checkFile(final IRemoteFileSystemBrowserContainerAdapter retrievalContainer, final String location) { >+ final Object[] result = new Object[1]; >+ final Boolean[] done = new Boolean[1]; >+ done[0] = new Boolean(false); >+ IRemoteFileSystemListener listener = new IRemoteFileSystemListener() { >+ public void handleRemoteFileEvent(IRemoteFileSystemEvent event) { >+ if (event instanceof IRemoteFileSystemBrowseEvent) { >+ IRemoteFileSystemBrowseEvent fsbe = (IRemoteFileSystemBrowseEvent) event; >+ IRemoteFile[] remoteFiles = fsbe.getRemoteFiles(); >+ if (remoteFiles != null && remoteFiles.length > 0) { >+ synchronized (result) { >+ result[0] = remoteFiles[0]; >+ done[0] = new Boolean(true); >+ result.notify(); >+ } >+ } else { >+ synchronized (result) { >+ result[0] = null; >+ done[0] = new Boolean(true); >+ result.notify(); >+ } >+ } >+ } >+ } >+ }; >+ try { >+ retrievalContainer.sendBrowseRequest(FileIDFactory.getDefault().createFileID(retrievalContainer.getBrowseNamespace(), location), listener); >+ } catch (RemoteFileSystemException e) { >+ return null; >+ } catch (FileCreateException e) { >+ return null; >+ } >+ synchronized (result) { >+ while (!done[0].booleanValue()) { >+ boolean logged = false; >+ try { >+ result.wait(); >+ } catch (InterruptedException e) { >+ if (!logged) >+ LogHelper.log(new Status(IStatus.WARNING, Activator.ID, "Unexpected interrupt while waiting on ECF browse", e)); //$NON-NLS-1$ >+ } >+ } >+ } >+ return (IRemoteFile) result[0]; >+ } >+ > private IStatus transfer(final IRetrieveFileTransferContainerAdapter retrievalContainer, final String toDownload, final OutputStream target, final IProgressMonitor monitor) { > final IStatus[] result = new IStatus[1]; > IFileTransferListener listener = new IFileTransferListener() { >Index: src/org/eclipse/equinox/internal/p2/metadata/repository/URLMetadataRepository.java >=================================================================== >RCS file: /cvsroot/eclipse/equinox-incubator/provisioning/org.eclipse.equinox.p2.metadata.repository/src/org/eclipse/equinox/internal/p2/metadata/repository/URLMetadataRepository.java,v >retrieving revision 1.11 >diff -u -r1.11 URLMetadataRepository.java >--- src/org/eclipse/equinox/internal/p2/metadata/repository/URLMetadataRepository.java 11 Jan 2008 20:36:39 -0000 1.11 >+++ src/org/eclipse/equinox/internal/p2/metadata/repository/URLMetadataRepository.java 29 Jan 2008 17:35:05 -0000 >@@ -24,10 +24,10 @@ > */ > public class URLMetadataRepository extends AbstractMetadataRepository { > >- static final protected String CONTENT_FILENAME = "content"; //$NON-NLS-1$ >- static final private String XML_EXTENSION = ".xml"; //$NON-NLS-1$ >- static final private String REPOSITORY_TYPE = URLMetadataRepository.class.getName(); >- static final private Integer REPOSITORY_VERSION = new Integer(1); >+ protected static final String CONTENT_FILENAME = "content"; //$NON-NLS-1$ >+ protected static final String XML_EXTENSION = ".xml"; //$NON-NLS-1$ >+ private static final String REPOSITORY_TYPE = URLMetadataRepository.class.getName(); >+ private static final Integer REPOSITORY_VERSION = new Integer(1); > > transient protected URL content; > protected HashSet units = new LinkedHashSet();
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 214816
:
87517
|
87772
|
88147
| 88162