TMF: Change API for synchronization files' folder
authorGeneviève Bastien <gbastien+lttng@versatic.net>
Tue, 9 Sep 2014 16:50:19 +0000 (12:50 -0400)
committerGenevieve Bastien <gbastien+lttng@versatic.net>
Wed, 8 Oct 2014 14:16:29 +0000 (10:16 -0400)
Some clients of experiment need a relative path, others need the absolute
path, the getSynchronizationFolder method is unified and the constant becomes
private.

Change-Id: I02688b55ec047820fbe756a269cf4bde3721a9b7
Signed-off-by: Geneviève Bastien <gbastien+lttng@versatic.net>
Reviewed-on: https://git.eclipse.org/r/33133
Reviewed-by: Alexandre Montplaisir <alexmonthy@voxpopuli.im>
Tested-by: Hudson CI
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/TmfExperiment.java
org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/SynchronizeTracesHandler.java

index 6a6b73ff8cb0d585cbe2b709171ab1cda027f583..3eeee30c3411f311d50966e52d774d39ad4330e4 100644 (file)
@@ -66,22 +66,21 @@ public class TmfExperiment extends TmfTrace implements ITmfEventParser, ITmfPers
      * The file name of the Synchronization
      *
      * @since 3.0
-     * @deprecated This file name shouldn't be used directly anymore. Instead,
-     *             all synchronization files have been moved to the
-     *             {@link #SYNCHRONIZATION_DIRECTORY} folder.
+     * @deprecated This file name shouldn't be used directly anymore. All
+     *             synchronization files have been moved to a folder and you
+     *             should use the {@link #getSynchronizationFolder(boolean)}
+     *             method to return the path to this folder.
      */
     @Deprecated
-    public final static String SYNCHRONIZATION_FILE_NAME = "synchronization.bin"; //$NON-NLS-1$
+    public static final String SYNCHRONIZATION_FILE_NAME = "synchronization.bin"; //$NON-NLS-1$
 
     /**
      * The name of the directory containing trace synchronization data. This
      * directory typically will be preserved when traces are synchronized.
      * Analysis involved in synchronization can put their supplementary files in
      * there so they are not deleted when synchronized traces are copied.
-     *
-     * @since 3.2
      */
-    public final static String SYNCHRONIZATION_DIRECTORY = "sync_data"; //$NON-NLS-1$
+    private static final String SYNCHRONIZATION_DIRECTORY = "sync_data"; //$NON-NLS-1$
 
     /**
      * The default index page size
@@ -346,7 +345,8 @@ public class TmfExperiment extends TmfTrace implements ITmfEventParser, ITmfPers
             final ITmfContext traceContext = fTraces[i].seekEvent(locations[i]);
             context.setContext(i, traceContext);
             traceContext.setRank(ranks[i]);
-            locations[i] = traceContext.getLocation(); // update location after seek
+            // update location after seek
+            locations[i] = traceContext.getLocation();
             context.setEvent(i, fTraces[i].getNext(traceContext));
             rank += ranks[i];
         }
@@ -490,16 +490,24 @@ public class TmfExperiment extends TmfTrace implements ITmfEventParser, ITmfPers
     /**
      * Get the path to the folder in the supplementary file where
      * synchronization-related data can be kept so they are not deleted when the
-     * experiment is synchronized. If the directory does not exist, it will be
-     * created. A return value of <code>null</code> means either the trace
-     * resource does not exist or supplementary resources cannot be kept.
+     * experiment is synchronized. Analysis involved in synchronization can put
+     * their supplementary files in there so they are preserved after
+     * synchronization.
      *
+     * If the directory does not exist, it will be created. A return value of
+     * <code>null</code> means either the trace resource does not exist or
+     * supplementary resources cannot be kept.
+     *
+     * @param absolute
+     *            If <code>true</code>, it returns the absolute path in the file
+     *            system, including the supplementary file path. Otherwise, it
+     *            returns only the directory name.
      * @return The path to the folder where synchronization-related
      *         supplementary files can be kept or <code>null</code> if not
      *         available.
      * @since 3.2
      */
-    public String getSynchronizationFolder() {
+    public String getSynchronizationFolder(boolean absolute) {
         /* Set up the path to the synchronization file we'll use */
         IResource resource = this.getResource();
         String syncDirectory = null;
@@ -507,13 +515,18 @@ public class TmfExperiment extends TmfTrace implements ITmfEventParser, ITmfPers
         try {
             /* get the directory where the file will be stored. */
             if (resource != null) {
-                syncDirectory = resource.getPersistentProperty(TmfCommonConstants.TRACE_SUPPLEMENTARY_FOLDER);
+                String fullDirectory = resource.getPersistentProperty(TmfCommonConstants.TRACE_SUPPLEMENTARY_FOLDER);
                 /* Create the synchronization data directory if not present */
-                if (syncDirectory != null) {
-                    syncDirectory = syncDirectory + File.separator + SYNCHRONIZATION_DIRECTORY;
-                    File syncDir = new File(syncDirectory);
+                if (fullDirectory != null) {
+                    fullDirectory = fullDirectory + File.separator + SYNCHRONIZATION_DIRECTORY;
+                    File syncDir = new File(fullDirectory);
                     syncDir.mkdirs();
                 }
+                if (absolute) {
+                    syncDirectory = fullDirectory;
+                } else {
+                    syncDirectory = SYNCHRONIZATION_DIRECTORY;
+                }
             }
         } catch (CoreException e) {
             return null;
@@ -544,7 +557,7 @@ public class TmfExperiment extends TmfTrace implements ITmfEventParser, ITmfPers
      */
     public synchronized SynchronizationAlgorithm synchronizeTraces(boolean doSync) {
 
-        String syncDirectory = getSynchronizationFolder();
+        String syncDirectory = getSynchronizationFolder(true);
 
         final File syncFile = (syncDirectory != null) ? new File(syncDirectory + File.separator + SYNCHRONIZATION_FILE_NAME) : null;
 
@@ -691,7 +704,9 @@ public class TmfExperiment extends TmfTrace implements ITmfEventParser, ITmfPers
                         return 0;
                     }
                     totalCheckpointSize += currentTraceCheckpointSize;
-                    totalCheckpointSize += 8; // each entry in the TmfLocationArray has a rank in addition of the location
+                    // each entry in the TmfLocationArray has a rank in addition
+                    // of the location
+                    totalCheckpointSize += 8;
                 }
             }
         } catch (UnsupportedOperationException e) {
index e25c87fc7828dff5b2afdc8afd5fdc7d66e585bc..e7f18dbca63abd7452b18ffb94d0eca87c346062 100644 (file)
@@ -233,10 +233,10 @@ public class SynchronizeTracesHandler extends AbstractHandler {
 
                         // Move synchronization file temporarily so that
                         // it doesn't get deleted by the experiment change
-                        IFolder tmpFolder = exp.getTraceSupplementaryFolder(exp.getName() + '.' + TmfExperiment.SYNCHRONIZATION_DIRECTORY);
+                        IFolder tmpFolder = exp.getTraceSupplementaryFolder(exp.getName() + '.' + experiment.getSynchronizationFolder(false));
                         IResource syncFile = null;
                         for (IResource resource : exp.getSupplementaryResources()) {
-                            if (resource.getName().equals(TmfExperiment.SYNCHRONIZATION_DIRECTORY)) {
+                            if (resource.getName().equals(experiment.getSynchronizationFolder(false))) {
                                 try {
                                     resource.move(tmpFolder.getFullPath(), false, null);
                                     syncFile = resource;
This page took 0.030495 seconds and 5 git commands to generate.