Line 0
Link Here
|
|
|
1 |
package org.netbeans.modules.cnd.modelui.actions; |
2 |
|
3 |
import java.io.File; |
4 |
import java.io.IOException; |
5 |
import java.util.Collections; |
6 |
import java.util.Map; |
7 |
import java.util.Set; |
8 |
import org.netbeans.api.sendopts.CommandException; |
9 |
import org.netbeans.spi.sendopts.Env; |
10 |
import org.netbeans.spi.sendopts.Option; |
11 |
import org.netbeans.spi.sendopts.OptionProcessor; |
12 |
import org.openide.filesystems.FileUtil; |
13 |
import org.openide.modules.Places; |
14 |
import org.openide.util.Exceptions; |
15 |
|
16 |
/* |
17 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
18 |
* |
19 |
* Copyright (c) 2016 Oracle and/or its affiliates. All rights reserved. |
20 |
* |
21 |
* Oracle and Java are registered trademarks of Oracle and/or its affiliates. |
22 |
* Other names may be trademarks of their respective owners. |
23 |
* |
24 |
* The contents of this file are subject to the terms of either the GNU |
25 |
* General Public License Version 2 only ("GPL") or the Common |
26 |
* Development and Distribution License("CDDL") (collectively, the |
27 |
* "License"). You may not use this file except in compliance with the |
28 |
* License. You can obtain a copy of the License at |
29 |
* http://www.netbeans.org/cddl-gplv2.html |
30 |
* or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the |
31 |
* specific language governing permissions and limitations under the |
32 |
* License. When distributing the software, include this License Header |
33 |
* Notice in each file and include the License file at |
34 |
* nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this |
35 |
* particular file as subject to the "Classpath" exception as provided |
36 |
* by Oracle in the GPL Version 2 section of the License file that |
37 |
* accompanied this code. If applicable, add the following below the |
38 |
* License Header, with the fields enclosed by brackets [] replaced by |
39 |
* your own identifying information: |
40 |
* "Portions Copyrighted [year] [name of copyright owner]" |
41 |
* |
42 |
* If you wish your version of this file to be governed by only the CDDL |
43 |
* or only the GPL Version 2, indicate your decision by adding |
44 |
* "[Contributor] elects to include this software in this distribution |
45 |
* under the [CDDL or GPL Version 2] license." If you do not indicate a |
46 |
* single choice of license, a recipient has the option to distribute |
47 |
* your version of this file under either the CDDL, the GPL Version 2 or |
48 |
* to extend the choice of license to its licensees as provided above. |
49 |
* However, if you add GPL Version 2 code and therefore, elected the GPL |
50 |
* Version 2 license, then the option applies only if the new code is |
51 |
* made subject to such option by the copyright holder. |
52 |
* |
53 |
* Contributor(s): |
54 |
*/ |
55 |
|
56 |
/** |
57 |
* |
58 |
* @author Alexander Simon |
59 |
*/ |
60 |
@org.openide.util.lookup.ServiceProvider(service=org.netbeans.spi.sendopts.OptionProcessor.class) |
61 |
public class CeanupCache extends OptionProcessor { |
62 |
|
63 |
@Override |
64 |
protected Set<Option> getOptions() { |
65 |
cleanupCache("cnd"); // NOI18N |
66 |
cleanupCache("remote-files"); // NOI18N |
67 |
cleanupCache("index"); // NOI18N |
68 |
cleanupCache("svnremotecache"); // NOI18N |
69 |
return Collections.emptySet(); |
70 |
} |
71 |
|
72 |
static void markToCleanup() { |
73 |
markToCleanup("cnd"); // NOI18N |
74 |
markToCleanup("remote-files"); // NOI18N |
75 |
markToCleanup("index"); // NOI18N |
76 |
markToCleanup("svnremotecache"); // NOI18N |
77 |
|
78 |
} |
79 |
|
80 |
private static void markToCleanup(String cacheName) { |
81 |
File cache = Places.getCacheSubdirectory(cacheName); // NOI18N |
82 |
if (cache.exists()) { |
83 |
File cleanupFile = new File(cache,"cleanup"); // NOI18N |
84 |
if (!cleanupFile.exists()) { |
85 |
try { |
86 |
cleanupFile.createNewFile(); |
87 |
} catch (IOException x) { |
88 |
} |
89 |
} |
90 |
} |
91 |
} |
92 |
|
93 |
private static void cleanupCache(String cacheName) { |
94 |
File cache = Places.getCacheSubdirectory(cacheName); // NOI18N |
95 |
if (cache.exists()) { |
96 |
File cleanupFile = new File(cache, "cleanup"); // NOI18N |
97 |
if (cleanupFile.exists()) { |
98 |
deleteRecursively(cache); |
99 |
} |
100 |
} |
101 |
} |
102 |
|
103 |
public static void deleteRecursively(File file) { |
104 |
File [] files = file.listFiles(); |
105 |
if (files != null) { |
106 |
for (int i = 0; i < files.length; i++) { |
107 |
deleteRecursively(files[i]); |
108 |
} |
109 |
} |
110 |
file.delete(); |
111 |
} |
112 |
|
113 |
@Override |
114 |
protected void process(Env env, Map<Option, String[]> optionValues) throws CommandException { |
115 |
} |
116 |
} |