Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (c) 2008, 2010 VMware Inc. All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse Public License v1.0 which accompanies this distribution, and is available at http://www.eclipse.org/legal/epl-v10.html Contributors: VMware Inc. - initial contribution /
 
 
 package org.eclipse.virgo.nano.serviceability.dump.internal;
 
 import java.io.File;
 
 
Utility class that writes the current Equinox resolver org.eclipse.osgi.service.resolver.State to a ZIP file.

Concurrent Semantics
Threadsafe.

 
 final class ResolutionStateDumper {
 
     private static final String ENTRY_NAME_STATE = "state/";
 
     private final Logger logger = LoggerFactory.getLogger(this.getClass());
 
     private final SystemStateAccessor systemStateAccessor;
     
     private final StateWriter stateWriter;

    
Creates a new ResolutionStateDumper.

Parameters:
systemStateAccessor to access live system org.eclipse.osgi.service.resolver.State
stateWriter to write a org.eclipse.osgi.service.resolver.State to permanent storage
 
     public ResolutionStateDumper(SystemStateAccessor systemStateAccessorStateWriter stateWriter) {
         this. = systemStateAccessor;
         this. = stateWriter;
     }

    
Dump the global resolver org.eclipse.osgi.service.resolver.State into a ZIP file at the supplied location.

Parameters:
outputFile the location to create the ZIP file at.
 
     public void dump(File outputFile) {
         dump(outputFilethis..getSystemState());
     }

    
Dump a resolver org.eclipse.osgi.service.resolver.State into a ZIP file at the supplied location.

Parameters:
outputFile the location to create the ZIP file at.
state the state to dump
 
     public void dump(File outputFileState state) {        
         File outdir = new File(getTmpDir(), "resolve-" + System.currentTimeMillis());
         if (outdir.mkdirs()) {
             try {
                 this..writeState(stateoutdir);
             } catch (IOException e) {
                 this..error("Unable to write resolver state."e);
             }
         } else {
             throw new RuntimeException("Unable to create temporary directory '" + outdir.getAbsolutePath() + "'.");
         }
 
         try {
             zipStateDirectory(outputFileoutdir);
         } catch (IOException e) {
             this..error("Unable to create ZIP of state dump"e);
         } finally {
             if (!new PathReference(outdir).delete(true)) {
                 this..warn("Temporary state directory '%s' was not removed after use."outdir.getAbsolutePath());
             }            
         }
     }
 
     private void zipStateDirectory(File outputFileFile dumpDirthrows IOException {
         PathReference output = new PathReference(outputFile);
         PathReference toZip = new PathReference(dumpDir);
 
         ZipUtils.zipTo(toZipoutput);
     }
 
     private String getTmpDir() {
         String path = System.getProperty("java.io.tmpdir");
        return path;
    }
New to GrepCode? Check out our FAQ X