This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 228318
Collapse All | Expand All

(-)a/o.n.bootstrap/arch.xml (+17 lines)
Lines 1110-1115 Link Here
1110
            <a href="#java.io.File-installation.cache">purposes of installer</a>.
1110
            <a href="#java.io.File-installation.cache">purposes of installer</a>.
1111
            </p>
1111
            </p>
1112
        </api>
1112
        </api>
1113
        <api category="friend" group="java.io.File" name="all-clusters.dat" type="export">
1114
            <p>
1115
                Lists relative paths of clusters (those defined by
1116
                <a href="#systemproperty-netbeans.home">netbeans.home</a> and
1117
                <a href="#systemproperty-netbeans.dirs">netbeans.dirs</a>)
1118
                for which the cache has been created. This is an important file
1119
                in the 
1120
                <a href="#java.io.File-installation.cache">shared cache</a> as
1121
                it helps to ensure the set of clusters has not changed since
1122
                the cache has been generated.
1123
            </p>
1124
            <p>
1125
                The file is binary and its format is <em>private</em>. The location
1126
                is however well known for 
1127
                <a href="#java.io.File-installation.cache">purposes of installer</a>.
1128
            </p>
1129
        </api>
1113
        <api category="friend" group="java.io.File" name="all-installer.dat" type="export">
1130
        <api category="friend" group="java.io.File" name="all-installer.dat" type="export">
1114
            <p>
1131
            <p>
1115
                Additional information about modules (like <em>deprecation message</em>, etc.)
1132
                Additional information about modules (like <em>deprecation message</em>, etc.)
(-)7d779ce00a82 (+165 lines)
Added Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2013 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * If you wish your version of this file to be governed by only the CDDL
28
 * or only the GPL Version 2, indicate your decision by adding
29
 * "[Contributor] elects to include this software in this distribution
30
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
31
 * single choice of license, a recipient has the option to distribute
32
 * your version of this file under either the CDDL, the GPL Version 2 or
33
 * to extend the choice of license to its licensees as provided above.
34
 * However, if you add GPL Version 2 code and therefore, elected the GPL
35
 * Version 2 license, then the option applies only if the new code is
36
 * made subject to such option by the copyright holder.
37
 *
38
 * Contributor(s):
39
 *
40
 * Portions Copyrighted 2013 Sun Microsystems, Inc.
41
 */
42
43
package org.netbeans;
44
45
import java.io.DataInputStream;
46
import java.io.DataOutputStream;
47
import java.io.File;
48
import java.io.IOException;
49
import java.util.ArrayList;
50
import java.util.List;
51
import java.util.StringTokenizer;
52
53
/**
54
 *
55
 * @author Jaroslav Tulach <jtulach@netbeans.org>
56
 */
57
final class Clusters implements Stamps.Updater {
58
    private static String[] dirs;
59
    private static String dirPrefix;
60
    private static final Clusters INSTANCE = new Clusters();
61
    
62
    private Clusters() {
63
    }
64
    
65
    static void scheduleSave(Stamps s) {
66
        s.scheduleSaveImpl(INSTANCE, "all-clusters.dat", false); // NOI18N
67
    }
68
    
69
    static boolean compareDirs(DataInputStream is) throws IOException {
70
        int cnt = is.readInt();
71
        String[] arr = relativeDirsWithHome();
72
        if (cnt != arr.length) {
73
            return false;
74
        }
75
        for (int i = 0; i < arr.length; i++) {
76
            String cluster = is.readUTF();
77
            if (!cluster.equals(arr[i])) {
78
                return false;
79
            }
80
        }
81
        return true;
82
    }
83
84
    static synchronized String[] dirs() {
85
        if (dirs == null) {
86
            List<String> tmp = new ArrayList<String>();
87
            String nbdirs = System.getProperty("netbeans.dirs");
88
            if (nbdirs != null) {
89
                StringTokenizer tok = new StringTokenizer(nbdirs, File.pathSeparator);
90
                while (tok.hasMoreTokens()) {
91
                    tmp.add(tok.nextToken());
92
                }
93
            }
94
            dirs = tmp.toArray(new String[tmp.size()]);
95
        }
96
        return dirs;
97
    }
98
99
    static int findCommonPrefix(String s1, String s2) {
100
        int len = Math.min(s1.length(), s2.length());
101
        int max = 0;
102
        for (int i = 0; i < len; i++) {
103
            final char ch = s1.charAt(i);
104
            if (ch != s2.charAt(i)) {
105
                return max;
106
            }
107
            if (ch == '/' || ch == File.separatorChar) {
108
                max = i + 1;
109
            }
110
        }
111
        return len;
112
    }
113
114
    static synchronized String dirPrefix() {
115
        if (dirPrefix == null) {
116
            String p = System.getProperty("netbeans.home");
117
            for (String d : dirs()) {
118
                if (p == null) {
119
                    p = d;
120
                } else {
121
                    int len = findCommonPrefix(p, d);
122
                    if (len <= 3) {
123
                        p = "";
124
                        break;
125
                    }
126
                    p = p.substring(0, len);
127
                }
128
            }
129
            dirPrefix = p == null ? "" : p;
130
        }
131
        return dirPrefix;
132
    }
133
134
    static String[] relativeDirsWithHome() {
135
        String[] arr = dirs();
136
        String[] tmp = new String[arr.length + 1];
137
        tmp[0] = System.getProperty("netbeans.home", ""); // NOI18N
138
        if (tmp[0].length() >= dirPrefix().length()) {
139
            tmp[0] = tmp[0].substring(dirPrefix().length());
140
        }
141
        for (int i = 0; i < arr.length; i++) {
142
            tmp[i + 1] = arr[i].substring(dirPrefix().length()).replace(File.separatorChar, '/');
143
        }
144
        return tmp;
145
    }
146
147
    static synchronized void clear() {
148
        dirs = null;
149
        dirPrefix = null;
150
    }
151
152
    @Override
153
    public void flushCaches(DataOutputStream os) throws IOException {
154
        String[] arr = relativeDirsWithHome();
155
        os.writeInt(arr.length);
156
        for (int i = 0; i < arr.length; i++) {
157
            os.writeUTF(arr[i]);
158
        }
159
    }
160
161
    @Override
162
    public void cacheReady() {
163
    }
164
    
165
}
(-)a/o.n.bootstrap/src/org/netbeans/Stamps.java (-59 / +94 lines)
Lines 45-50 Link Here
45
import java.io.BufferedOutputStream;
45
import java.io.BufferedOutputStream;
46
import java.io.ByteArrayInputStream;
46
import java.io.ByteArrayInputStream;
47
import java.io.DataInput;
47
import java.io.DataInput;
48
import java.io.DataInputStream;
48
import java.io.DataOutput;
49
import java.io.DataOutput;
49
import java.io.DataOutputStream;
50
import java.io.DataOutputStream;
50
import java.io.File;
51
import java.io.File;
Lines 68-74 Link Here
68
import java.util.Locale;
69
import java.util.Locale;
69
import java.util.Random;
70
import java.util.Random;
70
import java.util.Set;
71
import java.util.Set;
71
import java.util.StringTokenizer;
72
import java.util.concurrent.atomic.AtomicInteger;
72
import java.util.concurrent.atomic.AtomicInteger;
73
import java.util.concurrent.atomic.AtomicLong;
73
import java.util.concurrent.atomic.AtomicLong;
74
import java.util.concurrent.atomic.AtomicReference;
74
import java.util.concurrent.atomic.AtomicReference;
Lines 91-99 Link Here
91
    private static final Logger LOG = Logger.getLogger(Stamps.class.getName());
91
    private static final Logger LOG = Logger.getLogger(Stamps.class.getName());
92
    private static AtomicLong moduleJARs;
92
    private static AtomicLong moduleJARs;
93
    private static File moduleNewestFile;
93
    private static File moduleNewestFile;
94
    private static String[] dirs;
95
    private static File[] fallbackCache;
94
    private static File[] fallbackCache;
96
    private static boolean populated;
95
    private static boolean populated;
96
    private static Boolean clustersChanged;
97
97
98
    private Worker worker = new Worker();
98
    private Worker worker = new Worker();
99
99
Lines 107-127 Link Here
107
    static void main(String... args) {
107
    static void main(String... args) {
108
        if (args.length == 1 && "reset".equals(args[0])) { // NOI18N
108
        if (args.length == 1 && "reset".equals(args[0])) { // NOI18N
109
            moduleJARs = null;
109
            moduleJARs = null;
110
            dirs = null;
110
            Clusters.clear();
111
            clustersChanged = null;
111
            fallbackCache = null;
112
            fallbackCache = null;
112
            stamp(false);
113
            stamp(false);
113
            return;
114
            return;
114
        }
115
        }
115
        if (args.length == 1 && "init".equals(args[0])) { // NOI18N
116
        if (args.length == 1 && "init".equals(args[0])) { // NOI18N
116
            moduleJARs = null;
117
            moduleJARs = null;
117
            dirs = null;
118
            Clusters.clear();
119
            clustersChanged = null;
118
            fallbackCache = null;
120
            fallbackCache = null;
119
            stamp(true);
121
            stamp(true);
120
            return;
122
            return;
121
        }
123
        }
122
        if (args.length == 1 && "clear".equals(args[0])) { // NOI18N
124
        if (args.length == 1 && "clear".equals(args[0])) { // NOI18N
123
            moduleJARs = null;
125
            moduleJARs = null;
124
            dirs = null;
126
            Clusters.clear();
127
            clustersChanged = null;
125
            fallbackCache = null;
128
            fallbackCache = null;
126
            return;
129
            return;
127
        }
130
        }
Lines 183-188 Link Here
183
        return asByteBuffer(cache, true, false);
186
        return asByteBuffer(cache, true, false);
184
    }
187
    }
185
    final File file(String cache, int[] len) {
188
    final File file(String cache, int[] len) {
189
        if (clustersChanged()) {
190
            return null;
191
        }
192
        
186
        checkPopulateCache();
193
        checkPopulateCache();
187
        
194
        
188
        synchronized (this) {
195
        synchronized (this) {
Lines 191-224 Link Here
191
                return null;
198
                return null;
192
            }
199
            }
193
        }
200
        }
194
201
        return fileImpl(cache, len, moduleJARs());
195
        File cacheFile = Places.getCacheSubfile(cache);
196
        long last = cacheFile.lastModified();
197
        if (last <= 0) {
198
            LOG.log(Level.FINE, "Cache does not exist when asking for {0}", cache); // NOI18N
199
            cacheFile = findFallbackCache(cache);
200
            if (cacheFile == null || (last = cacheFile.lastModified()) <= 0) {
201
                return null;
202
            }
203
            LOG.log(Level.FINE, "Found fallback cache at {0}", cacheFile);
204
        }
205
206
        if (moduleJARs() > last) {
207
            LOG.log(Level.FINE, "Timestamp does not pass when asking for {0}. Newest file {1}", new Object[] { cache, moduleNewestFile }); // NOI18N
208
            return null;
209
        }
210
211
        long longLen = cacheFile.length();
212
        if (longLen > Integer.MAX_VALUE) {
213
            LOG.warning("Cache file is too big: " + longLen + " bytes for " + cacheFile); // NOI18N
214
            return null;
215
        }
216
        if (len != null) {
217
            len[0] = (int)longLen;
218
        }
219
        
220
        LOG.log(Level.FINE, "Cache found: {0}", cache); // NOI18N
221
        return cacheFile;
222
    }
202
    }
223
    
203
    
224
    private ByteBuffer asByteBuffer(String cache, boolean direct, boolean mmap) {
204
    private ByteBuffer asByteBuffer(String cache, boolean direct, boolean mmap) {
Lines 260-271 Link Here
260
     */
240
     */
261
    public void scheduleSave(Updater updater, String cache, boolean append) {
241
    public void scheduleSave(Updater updater, String cache, boolean append) {
262
        boolean firstAdd;
242
        boolean firstAdd;
263
        synchronized (worker) {
243
        firstAdd = scheduleSaveImpl(updater, cache, append);
264
            firstAdd = worker.addStorage(new Store(updater, cache, append));
265
        }
266
        LOG.log(firstAdd ? Level.FINE : Level.FINER, 
244
        LOG.log(firstAdd ? Level.FINE : Level.FINER, 
267
            "Scheduling save for {0} cache", cache
245
            "Scheduling save for {0} cache", cache
268
        );
246
        );
247
        Clusters.scheduleSave(this);
248
    }
249
    
250
    final boolean scheduleSaveImpl(Updater updater, String cache, boolean append) {
251
        synchronized (worker) {
252
            return worker.addStorage(new Store(updater, cache, append));
253
        }
269
    }
254
    }
270
    
255
    
271
    /** Flushes all caches.
256
    /** Flushes all caches.
Lines 345-380 Link Here
345
        stamp(checkStampFile, result, newestFile);
330
        stamp(checkStampFile, result, newestFile);
346
        return result;
331
        return result;
347
    }
332
    }
348
    
349
    private static synchronized String[] dirs() {
350
        if (dirs == null) {
351
            List<String> tmp = new ArrayList<String>();
352
            String nbdirs = System.getProperty("netbeans.dirs"); // NOI18N
353
            if (nbdirs != null) {
354
                StringTokenizer tok = new StringTokenizer(nbdirs, File.pathSeparator);
355
                while (tok.hasMoreTokens()) {
356
                    tmp.add(tok.nextToken());
357
                }
358
            }
359
            dirs = tmp.toArray(new String[tmp.size()]);
360
        }
361
        return dirs;
362
    }
363
333
364
    private static void stamp(boolean checkStampFile, AtomicLong result, AtomicReference<File> newestFile) {
334
    private static void stamp(boolean checkStampFile, AtomicLong result, AtomicReference<File> newestFile) {
365
        StringBuilder sb = new StringBuilder();
335
        StringBuilder sb = new StringBuilder();
366
        
336
        
367
        Set<File> processedDirs = new HashSet<File>();
337
        Set<File> processedDirs = new HashSet<File>();
338
        String[] relativeDirs = Clusters.relativeDirsWithHome();
368
        String home = System.getProperty ("netbeans.home"); // NOI18N
339
        String home = System.getProperty ("netbeans.home"); // NOI18N
369
        if (home != null) {
340
        if (home != null) {
370
            long stamp = stampForCluster (new File (home), result, newestFile, processedDirs, checkStampFile, true, null);
341
            long stamp = stampForCluster (new File (home), result, newestFile, processedDirs, checkStampFile, true, null);
371
            sb.append("home=").append(stamp).append('\n');
342
            sb.append(relativeDirs[0]).append('=').append(stamp).append('\n');
372
        }
343
        }
373
        for (String t : dirs()) {
344
        String[] drs = Clusters.dirs();
374
            final File clusterDir = new File(t);
345
        for (int i = 0; i < drs.length; i++) {
346
            final File clusterDir = new File(drs[i]);
375
            long stamp = stampForCluster(clusterDir, result, newestFile, processedDirs, checkStampFile, true, null);
347
            long stamp = stampForCluster(clusterDir, result, newestFile, processedDirs, checkStampFile, true, null);
376
            if (stamp != -1) {
348
            if (stamp != -1) {
377
                sb.append(clusterDir.getName()).append('=').append(stamp).append('\n');
349
                sb.append("cluster.").append(relativeDirs[i + 1]).append('=').append(stamp).append('\n');
378
            }
350
            }
379
        }
351
        }
380
        File user = Places.getUserDirectory();
352
        File user = Places.getUserDirectory();
Lines 561-568 Link Here
561
    private static File findFallbackCache(String cache) {
533
    private static File findFallbackCache(String cache) {
562
        if (fallbackCache == null) {
534
        if (fallbackCache == null) {
563
            fallbackCache = new File[0];
535
            fallbackCache = new File[0];
564
            if (dirs().length >= 1) {
536
            if (Clusters.dirs().length >= 1) {
565
                File fallback = new File(new File(new File(dirs()[0]), "var"), "cache"); // NOI18N
537
                File fallback = new File(new File(new File(Clusters.dirs()[0]), "var"), "cache"); // NOI18N
566
                if (fallback.isDirectory()) {
538
                if (fallback.isDirectory()) {
567
                    fallbackCache = new File[]{ fallback };
539
                    fallbackCache = new File[]{ fallback };
568
                }
540
                }
Lines 620-625 Link Here
620
            LOG.log(Level.INFO, "Failed to populate {0}", cache);
592
            LOG.log(Level.INFO, "Failed to populate {0}", cache);
621
        }
593
        }
622
    }
594
    }
595
    
596
    private static boolean clustersChanged() {
597
        if (clustersChanged != null) {
598
            return clustersChanged;
599
        }
600
        
601
        final String clustersCache = "all-clusters.dat"; // NOI18N
602
        File f = fileImpl(clustersCache, null, -1); // no timestamp check
603
        if (f != null) {
604
            DataInputStream dis = null;
605
            try {
606
                dis = new DataInputStream(new FileInputStream(f));
607
                if (Clusters.compareDirs(dis)) {
608
                    return false;
609
                }
610
            } catch (IOException ex) {
611
                return clustersChanged = true;
612
            } finally {
613
                if (dis != null) {
614
                    try {
615
                        dis.close();
616
                    } catch (IOException ex) {
617
                        LOG.log(Level.INFO, null, ex);
618
                    }
619
                }
620
            }
621
        } else {
622
            // missing cluster file signals caches are OK, for 
623
            // backward compatibility
624
            return clustersChanged = false;
625
        }
626
        return clustersChanged = true;
627
    }
628
629
    private static File fileImpl(String cache, int[] len, long moduleJARs) {
630
        File cacheFile = Places.getCacheSubfile(cache);
631
        long last = cacheFile.lastModified();
632
        if (last <= 0) {
633
            LOG.log(Level.FINE, "Cache does not exist when asking for {0}", cache); // NOI18N
634
            cacheFile = findFallbackCache(cache);
635
            if (cacheFile == null || (last = cacheFile.lastModified()) <= 0) {
636
                return null;
637
            }
638
            LOG.log(Level.FINE, "Found fallback cache at {0}", cacheFile);
639
        }
640
641
        if (moduleJARs > last) {
642
            LOG.log(Level.FINE, "Timestamp does not pass when asking for {0}. Newest file {1}", new Object[] { cache, moduleNewestFile }); // NOI18N
643
            return null;
644
        }
645
646
        long longLen = cacheFile.length();
647
        if (longLen > Integer.MAX_VALUE) {
648
            LOG.log(Level.WARNING, "Cache file is too big: {0} bytes for {1}", new Object[]{longLen, cacheFile}); // NOI18N
649
            return null;
650
        }
651
        if (len != null) {
652
            len[0] = (int)longLen;
653
        }
654
        
655
        LOG.log(Level.FINE, "Cache found: {0}", cache); // NOI18N
656
        return cacheFile;
657
    }
623
658
624
    /** A callback interface to flush content of some cache at a suitable
659
    /** A callback interface to flush content of some cache at a suitable
625
     * point in time.
660
     * point in time.
Lines 908-914 Link Here
908
            return relative;
943
            return relative;
909
        }
944
        }
910
        int indx = Integer.parseInt(index);
945
        int indx = Integer.parseInt(index);
911
        String[] _dirs = dirs();
946
        String[] _dirs = Clusters.dirs();
912
        if (indx < 0 || indx >= _dirs.length) {
947
        if (indx < 0 || indx >= _dirs.length) {
913
            throw new IOException("Bad index " + indx + " for " + Arrays.toString(_dirs));
948
            throw new IOException("Bad index " + indx + " for " + Arrays.toString(_dirs));
914
        }
949
        }
Lines 931-937 Link Here
931
            return;
966
            return;
932
        }
967
        }
933
        int cnt = 0;
968
        int cnt = 0;
934
        for (String p : dirs()) {
969
        for (String p : Clusters.dirs()) {
935
            if (testWritePath(path, p, "" + cnt, out)) {
970
            if (testWritePath(path, p, "" + cnt, out)) {
936
                return;
971
                return;
937
            }
972
            }
(-)a/o.n.bootstrap/test/unit/src/org/netbeans/ModuleManagerPersistanceTest.java (-1 / +3 lines)
Lines 72-78 Link Here
72
        clearWorkDir();
72
        clearWorkDir();
73
        
73
        
74
        File home = new File(getWorkDir(), "home");
74
        File home = new File(getWorkDir(), "home");
75
        new File(new File(home, "config"), "Modules").mkdirs();
75
        final File configModules = new File(new File(home, "config"), "Modules");
76
        configModules.mkdirs();
77
        new File(configModules, "a-b-c.xml").createNewFile();
76
        File moduleDir = new File(home, "modules");
78
        File moduleDir = new File(home, "modules");
77
        moduleDir.mkdirs();
79
        moduleDir.mkdirs();
78
        System.setProperty("netbeans.home", home.getPath());
80
        System.setProperty("netbeans.home", home.getPath());
(-)7d779ce00a82 (+187 lines)
Added Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 1997-2010 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 * 
27
 * If you wish your version of this file to be governed by only the CDDL
28
 * or only the GPL Version 2, indicate your decision by adding
29
 * "[Contributor] elects to include this software in this distribution
30
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
31
 * single choice of license, a recipient has the option to distribute
32
 * your version of this file under either the CDDL, the GPL Version 2 or
33
 * to extend the choice of license to its licensees as provided above.
34
 * However, if you add GPL Version 2 code and therefore, elected the GPL
35
 * Version 2 license, then the option applies only if the new code is
36
 * made subject to such option by the copyright holder.
37
 * 
38
 * Contributor(s):
39
 * 
40
 * Portions Copyrighted 2008 Sun Microsystems, Inc.
41
 */
42
43
package org.netbeans;
44
45
import java.io.DataOutputStream;
46
import java.io.File;
47
import java.io.IOException;
48
import java.util.Arrays;
49
import org.netbeans.junit.NbTestCase;
50
51
/**
52
 *
53
 * @author Jaroslav Tulach <jaroslav.tulach@netbeans.org>
54
 */
55
public class StampsClusterMovedTest extends NbTestCase implements Stamps.Updater{
56
    private File userdir;
57
    private File ide;
58
    private File platform;
59
    private File install;
60
    private File mainCluster;
61
    
62
    public StampsClusterMovedTest(String testName) {
63
        super(testName);
64
    }            
65
66
    public void testMoveOfAClusterIsDetected() throws Exception {
67
        clearWorkDir();
68
        
69
        install = new File(getWorkDir(), "install");
70
        platform = new File(install, "platform");
71
        platform.mkdirs();
72
        new File(platform, ".lastModified").createNewFile();
73
        ide = new File(install, "ide");
74
        ide.mkdirs();
75
        new File(ide, ".lastModified").createNewFile();
76
        mainCluster = new File(install, "extra");
77
        mainCluster.mkdirs();
78
        assertTrue("Extra cluster exists", mainCluster.isDirectory());
79
        new File(mainCluster, ".lastModified").createNewFile();
80
        userdir = new File(getWorkDir(), "tmp");
81
        
82
        System.setProperty("netbeans.home", platform.getPath());
83
        System.setProperty("netbeans.dirs", ide.getPath() + File.pathSeparator + mainCluster.getPath());
84
        System.setProperty("netbeans.user", userdir.getPath());
85
86
87
        Thread.sleep(500);
88
        long between = System.currentTimeMillis();
89
        Thread.sleep(500);
90
91
        
92
        Stamps.main("init");
93
        
94
        Stamps.getModulesJARs().scheduleSave(this, "test-cache", false);
95
        Stamps.getModulesJARs().waitFor(true);
96
        int[] arr = { 0 };
97
        File f = Stamps.getModulesJARs().file("test-cache", arr);
98
        assertNotNull("Cache found", f);
99
        assertEquals("Stamps of caches shall be the same as stamps of .lastModified",
100
            f.lastModified(), Stamps.moduleJARs()
101
        );
102
103
104
        Thread.sleep(500);
105
106
        File subDir = new File(getWorkDir(), "subdir");
107
        subDir.mkdirs();
108
        final File newExtra = new File(subDir, mainCluster.getName());
109
        boolean renRes = mainCluster.renameTo(newExtra);
110
        assertTrue("Rename succeeded", renRes);
111
        assertTrue("Extra renamed: " + newExtra, newExtra.isDirectory());
112
        
113
        System.setProperty("netbeans.dirs", ide.getPath() + File.pathSeparator + newExtra.getPath());
114
        
115
        Stamps.main("init");
116
        
117
        assertNull("Cache invalidated as relative location of clusters changed", 
118
            Stamps.getModulesJARs().asByteBuffer("test-cache")
119
        );
120
    }
121
    
122
    public void testChangeOfClustersIsDetectedInSharedConfig() throws Exception {
123
        clearWorkDir();
124
        
125
        install = new File(getWorkDir(), "install");
126
        platform = new File(install, "platform");
127
        platform.mkdirs();
128
        new File(platform, ".lastModified").createNewFile();
129
        ide = new File(install, "ide");
130
        ide.mkdirs();
131
        new File(ide, ".lastModified").createNewFile();
132
        mainCluster = new File(install, "extra");
133
        mainCluster.mkdirs();
134
        assertTrue("Extra cluster exists", mainCluster.isDirectory());
135
        new File(mainCluster, ".lastModified").createNewFile();
136
        userdir = new File(getWorkDir(), "tmp");
137
        userdir.mkdirs();
138
        
139
        System.setProperty("netbeans.home", platform.getPath());
140
        System.setProperty("netbeans.dirs", ide.getPath());
141
        // generate the cache to mainCluster directory
142
        System.setProperty("netbeans.user", mainCluster.getPath());
143
144
145
        Thread.sleep(500);
146
        long between = System.currentTimeMillis();
147
        Thread.sleep(500);
148
149
        
150
        Stamps.main("init");
151
        
152
        Stamps.getModulesJARs().scheduleSave(this, "test-cache", false);
153
        Stamps.getModulesJARs().waitFor(true);
154
        int[] arr = { 0 };
155
        File f = Stamps.getModulesJARs().file("test-cache", arr);
156
        assertNotNull("Cache found", f);
157
        assertEquals("Stamps of caches shall be the same as stamps of .lastModified",
158
            f.lastModified(), Stamps.moduleJARs()
159
        );
160
        
161
        File lmdir = new File(new File(new File(mainCluster, "var"), "cache"), "lastModified");
162
        assertTrue(lmdir + " is dir", lmdir.isDirectory());
163
        lmdir.renameTo(new File(lmdir.getParentFile(), "ignore"));
164
        assertFalse(lmdir + " is no longer dir", lmdir.isDirectory());
165
166
        Thread.sleep(500);
167
168
        System.setProperty("netbeans.user", userdir.getPath());
169
        // use mainCluster as cluster
170
        System.setProperty("netbeans.dirs", mainCluster.getPath() + File.pathSeparator + ide.getPath());
171
        
172
        Stamps.main("init");
173
        
174
        assertNull("Cache invalidated set of clusters changed", 
175
            Stamps.getModulesJARs().asByteBuffer("test-cache")
176
        );
177
    }
178
179
    @Override
180
    public void flushCaches(DataOutputStream os) throws IOException {
181
        os.write(1);
182
    }
183
184
    @Override
185
    public void cacheReady() {
186
    }
187
}
(-)a/o.n.bootstrap/test/unit/src/org/netbeans/StampsIdeLessThanPlatformTest.java (-1 / +1 lines)
Lines 132-138 Link Here
132
            String[] seg = line.split("=");
132
            String[] seg = line.split("=");
133
            assertEquals("There should be one = in the: " + line, 2, seg.length);
133
            assertEquals("There should be one = in the: " + line, 2, seg.length);
134
            String s = seg[0];
134
            String s = seg[0];
135
            if (s.endsWith("home")) {
135
            if (s.endsWith("platform")) {
136
                assertEquals("Correct for platform: " + line, "60000", seg[1]);
136
                assertEquals("Correct for platform: " + line, "60000", seg[1]);
137
                check ++;
137
                check ++;
138
            }
138
            }

Return to bug 228318