diff options
author | Adrian Dudau <adrian.dudau@enea.com> | 2013-12-12 13:36:50 +0100 |
---|---|---|
committer | Adrian Dudau <adrian.dudau@enea.com> | 2013-12-12 15:25:03 +0100 |
commit | 41ac47d732eed8392d60d0f6773e5a279d49b999 (patch) | |
tree | cf19d099db9cfdb8d73aa21c31e7aa1cc86ff860 /plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/filesystem/Policy.java | |
download | eclipse-poky-juno-41ac47d732eed8392d60d0f6773e5a279d49b999.tar.gz |
Migrated from the internal git server on the dora-enea branch
Signed-off-by: Adrian Dudau <adrian.dudau@enea.com>
Diffstat (limited to 'plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/filesystem/Policy.java')
-rw-r--r-- | plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/filesystem/Policy.java | 108 |
1 files changed, 108 insertions, 0 deletions
diff --git a/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/filesystem/Policy.java b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/filesystem/Policy.java new file mode 100644 index 0000000..84c0f32 --- /dev/null +++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/filesystem/Policy.java | |||
@@ -0,0 +1,108 @@ | |||
1 | /******************************************************************************* | ||
2 | * Copyright (c) 2000, 2007 IBM Corporation and others. | ||
3 | * All rights reserved. This program and the accompanying materials | ||
4 | * are made available under the terms of the Eclipse Public License v1.0 | ||
5 | * which accompanies this distribution, and is available at | ||
6 | * http://www.eclipse.org/legal/epl-v10.html | ||
7 | * | ||
8 | * Contributors: | ||
9 | * IBM Corporation - initial API and implementation | ||
10 | *******************************************************************************/ | ||
11 | package org.yocto.bc.ui.filesystem; | ||
12 | |||
13 | import java.io.IOException; | ||
14 | import java.io.InputStream; | ||
15 | import java.io.OutputStream; | ||
16 | import java.util.Date; | ||
17 | |||
18 | import org.eclipse.core.runtime.CoreException; | ||
19 | import org.eclipse.core.runtime.IProgressMonitor; | ||
20 | import org.eclipse.core.runtime.NullProgressMonitor; | ||
21 | import org.eclipse.core.runtime.OperationCanceledException; | ||
22 | import org.eclipse.core.runtime.Status; | ||
23 | import org.eclipse.core.runtime.SubProgressMonitor; | ||
24 | |||
25 | import org.yocto.bc.ui.Activator; | ||
26 | |||
27 | /** | ||
28 | * Grab bag of utility methods for the file system plugin | ||
29 | */ | ||
30 | public class Policy { | ||
31 | |||
32 | /** | ||
33 | * General debug flag for the plugin | ||
34 | */ | ||
35 | public static boolean DEBUG = false; | ||
36 | |||
37 | public static final String PI_FILE_SYSTEM = "org.eclipse.core.filesystem"; //$NON-NLS-1$ | ||
38 | |||
39 | public static void checkCanceled(IProgressMonitor monitor) { | ||
40 | if (monitor.isCanceled()) | ||
41 | throw new OperationCanceledException(); | ||
42 | } | ||
43 | |||
44 | /** | ||
45 | * Print a debug message to the console. | ||
46 | * Pre-pend the message with the current date and the name of the current thread. | ||
47 | */ | ||
48 | public static void debug(String message) { | ||
49 | StringBuffer buffer = new StringBuffer(); | ||
50 | buffer.append(new Date(System.currentTimeMillis())); | ||
51 | buffer.append(" - ["); //$NON-NLS-1$ | ||
52 | buffer.append(Thread.currentThread().getName()); | ||
53 | buffer.append("] "); //$NON-NLS-1$ | ||
54 | buffer.append(message); | ||
55 | System.out.println(buffer.toString()); | ||
56 | } | ||
57 | |||
58 | public static void error(int code, String message) throws CoreException { | ||
59 | error(code, message, null); | ||
60 | } | ||
61 | |||
62 | public static void error(int code, String message, Throwable exception) throws CoreException { | ||
63 | int severity = code == 0 ? 0 : 1 << (code % 100 / 33); | ||
64 | throw new CoreException(new Status(severity, PI_FILE_SYSTEM, code, message, exception)); | ||
65 | } | ||
66 | |||
67 | public static void log(int severity, String message, Throwable t) { | ||
68 | if (message == null) | ||
69 | message = ""; //$NON-NLS-1$ | ||
70 | Activator.getDefault().getLog().log(new Status(severity, PI_FILE_SYSTEM, 1, message, t)); | ||
71 | } | ||
72 | |||
73 | public static IProgressMonitor monitorFor(IProgressMonitor monitor) { | ||
74 | return monitor == null ? new NullProgressMonitor() : monitor; | ||
75 | } | ||
76 | |||
77 | /** | ||
78 | * Closes a stream and ignores any resulting exception. | ||
79 | */ | ||
80 | public static void safeClose(InputStream in) { | ||
81 | try { | ||
82 | if (in != null) | ||
83 | in.close(); | ||
84 | } catch (IOException e) { | ||
85 | //ignore | ||
86 | } | ||
87 | } | ||
88 | |||
89 | /** | ||
90 | * Closes a stream and ignores any resulting exception. | ||
91 | */ | ||
92 | public static void safeClose(OutputStream out) { | ||
93 | try { | ||
94 | if (out != null) | ||
95 | out.close(); | ||
96 | } catch (IOException e) { | ||
97 | //ignore | ||
98 | } | ||
99 | } | ||
100 | |||
101 | public static IProgressMonitor subMonitorFor(IProgressMonitor monitor, int ticks) { | ||
102 | if (monitor == null) | ||
103 | return new NullProgressMonitor(); | ||
104 | if (monitor instanceof NullProgressMonitor) | ||
105 | return monitor; | ||
106 | return new SubProgressMonitor(monitor, ticks); | ||
107 | } | ||
108 | } | ||