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 88147 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.
[patch]
Metadata Caching v02
patch-metadataCaching_v03.txt (text/plain), 12.20 KB, created by
Tim Mok
on 2008-01-29 10:41:57 EST
(
hide
)
Description:
Metadata Caching v02
Filename:
MIME Type:
Creator:
Tim Mok
Created:
2008-01-29 10:41:57 EST
Size:
12.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/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 15:39:11 -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/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 15:39:11 -0000 >@@ -15,8 +15,10 @@ > import java.util.jar.JarEntry; > import java.util.jar.JarInputStream; > import org.eclipse.core.runtime.*; >+import org.eclipse.equinox.internal.p2.core.helpers.ServiceHelper; > import org.eclipse.equinox.internal.p2.core.helpers.Tracing; > 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; >@@ -34,64 +36,103 @@ > } > > public IMetadataRepository load(URL location, IProgressMonitor monitor) throws ProvisionException { >+ final String PROTOCOL_FILE = "file"; //$NON-NLS-1$ > long time = 0; > boolean compress = true; >+ boolean local = false; > final String debugMsg = "Restoring metadata repository "; //$NON-NLS-1$ >- File temp = null; >+ AgentLocation agentLocation = (AgentLocation) ServiceHelper.getService(Activator.getContext(), AgentLocation.class.getName()); >+ long timestamp, cacheTimestamp; >+ URL actualFile, dataArea; >+ File localFile = null; > if (Tracing.DEBUG_METADATA_PARSING) { > Tracing.debug(debugMsg + location); > time = -System.currentTimeMillis(); > } > try { >- temp = File.createTempFile(CONTENT_FILENAME, JAR_EXTENSION); >+ IStatus status = Status.OK_STATUS; >+ OutputStream metadata = null; > 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(); >+ String fileLocation = URLMetadataRepository.getActualLocation(location, JAR_EXTENSION).toExternalForm(); >+ int hashCode = location.hashCode(); >+ timestamp = getTransport().getLastModified(fileLocation); >+ cacheTimestamp = 0; >+ actualFile = URLMetadataRepository.getActualLocation(location); >+ // check if the file is from a local repository >+ if (PROTOCOL_FILE.equals(actualFile.getProtocol())) { >+ local = true; >+ localFile = new File(URLMetadataRepository.getActualLocation(location, JAR_EXTENSION).getPath()); >+ if (!localFile.exists()) { >+ localFile = new File(actualFile.getPath()); >+ compress = false; >+ if (!localFile.exists()) { >+ String msg = NLS.bind(Messages.io_failedRead, location); >+ throw new ProvisionException(new Status(IStatus.ERROR, Activator.ID, ProvisionException.REPOSITORY_NOT_FOUND, msg, null)); >+ } >+ } > } >- 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 (!local) { >+ dataArea = agentLocation.getDataArea(Activator.ID + "/cache/"); //$NON-NLS-1$ >+ String localPath = dataArea.getPath(); >+ if (timestamp != 0) { >+ localFile = new File(localPath + CONTENT_FILENAME + hashCode + JAR_EXTENSION); >+ cacheTimestamp = localFile.lastModified(); >+ } else { >+ fileLocation = URLMetadataRepository.getActualLocation(location, XML_EXTENSION).toExternalForm(); >+ timestamp = getTransport().getLastModified(fileLocation); >+ if (timestamp != 0) { >+ compress = false; >+ localFile = new File(localPath, CONTENT_FILENAME + hashCode + XML_EXTENSION); >+ cacheTimestamp = localFile.lastModified(); >+ } else { >+ String msg = NLS.bind(Messages.io_failedRead, location); >+ throw new ProvisionException(new Status(IStatus.ERROR, Activator.ID, ProvisionException.REPOSITORY_NOT_FOUND, msg, null)); >+ } > } >- if (jarEntry == null) { >- throw new FileNotFoundException(actualFile.getPath().toString()); >+ if (timestamp < cacheTimestamp) { >+ // retrieve the newer index file >+ File parentFile = localFile.getParentFile(); >+ if (!parentFile.exists()) { >+ parentFile.mkdirs(); >+ } >+ localFile.createNewFile(); >+ metadata = new BufferedOutputStream(new FileOutputStream(localFile)); >+ status = getTransport().download(fileLocation, metadata, sub); > } >- inStream = jInStream; > } >- InputStream descriptorStream = new BufferedInputStream(inStream); >- try { >- IMetadataRepository result = new MetadataRepositoryIO().read(temp.toURL(), descriptorStream, sub.newChild(100)); >- if (result instanceof LocalMetadataRepository) >- ((LocalMetadataRepository) result).initializeAfterLoad(location); >- if (result instanceof URLMetadataRepository) >- ((URLMetadataRepository) result).initializeAfterLoad(location); >- if (Tracing.DEBUG_METADATA_PARSING) { >- time += System.currentTimeMillis(); >- Tracing.debug(debugMsg + "time (ms): " + time); //$NON-NLS-1$ >- } >- return result; >- } finally { >- if (descriptorStream != null) >- descriptorStream.close(); >+ if (status.isOK()) { >+ if (metadata != null) { >+ metadata.close(); >+ } >+ InputStream inStream = new BufferedInputStream(new FileInputStream(localFile)); >+ 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("Repository not found in compressed file."); //$NON-NLS-1$ >+ } >+ inStream = jInStream; >+ } >+ InputStream descriptorStream = new BufferedInputStream(inStream); >+ try { >+ IMetadataRepository result = new MetadataRepositoryIO().read(localFile.toURL(), descriptorStream, sub.newChild(100)); >+ if (result instanceof LocalMetadataRepository) >+ ((LocalMetadataRepository) result).initializeAfterLoad(location); >+ if (result instanceof URLMetadataRepository) >+ ((URLMetadataRepository) result).initializeAfterLoad(location); >+ if (Tracing.DEBUG_METADATA_PARSING) { >+ time += System.currentTimeMillis(); >+ Tracing.debug(debugMsg + "time (ms): " + time); //$NON-NLS-1$ >+ } >+ return result; >+ } finally { >+ if (descriptorStream != null) >+ descriptorStream.close(); >+ } > } > } catch (FileNotFoundException e) { > String msg = NLS.bind(Messages.io_failedRead, location); >@@ -99,11 +140,12 @@ > } catch (IOException e) { > 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(); >- } > } >+ if (localFile != null) { >+ localFile.deleteOnExit(); >+ } >+ return null; >+ > } > > private ECFMetadataTransport getTransport() {
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 Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 214816
:
87517
|
87772
|
88147
|
88162