|
55 | 55 | import org.eclipse.core.resources.IFile;
|
56 | 56 | import org.eclipse.core.resources.IFolder;
|
57 | 57 | import org.eclipse.core.runtime.IPath;
|
| 58 | +import org.eclipse.jface.dialogs.MessageDialog; |
| 59 | +import org.eclipse.swt.widgets.Display; |
58 | 60 | import org.libreoffice.ide.eclipse.core.PluginLogger;
|
59 | 61 | import org.libreoffice.ide.eclipse.core.model.IUnoidlProject;
|
60 | 62 | import org.libreoffice.ide.eclipse.java.utils.TemplatesHelper;
|
@@ -228,4 +230,41 @@ private static IFile getClassesListFile(IUnoidlProject pProject) {
|
228 | 230 |
|
229 | 231 | return dest.getFile("RegistrationHandler.classes"); //$NON-NLS-1$
|
230 | 232 | }
|
| 233 | + |
| 234 | + /** |
| 235 | + * Check if the RegistrationHandler.classes file is empty |
| 236 | + * <code>org.libreoffice.ide.eclipse.java.JavaResourceDeltaVisitor</code> |
| 237 | + * |
| 238 | + * @param pProject the project where to check empty file |
| 239 | + */ |
| 240 | + public static void isFileEmpty(IUnoidlProject pProject) { |
| 241 | + IFile list = getClassesListFile(pProject); |
| 242 | + File file = list.getLocation().toFile(); |
| 243 | + boolean checkFileEmpty = true; |
| 244 | + FileInputStream in = null; |
| 245 | + BufferedReader reader = null; |
| 246 | + try { |
| 247 | + in = new FileInputStream(file); |
| 248 | + reader = new BufferedReader(new InputStreamReader(in)); |
| 249 | + if (reader.readLine() == null) { |
| 250 | + checkFileEmpty = true; |
| 251 | + } else { |
| 252 | + checkFileEmpty = false; |
| 253 | + } |
| 254 | + } catch (Exception e) { |
| 255 | + checkFileEmpty = true; |
| 256 | + |
| 257 | + } finally { |
| 258 | + try { |
| 259 | + reader.close(); |
| 260 | + in.close(); |
| 261 | + } catch (Exception e) { |
| 262 | + } |
| 263 | + } |
| 264 | + if (checkFileEmpty) { |
| 265 | + PluginLogger.error(Messages.getString("RegistrationHelper.RegistrationHandlerEmptyClassError")); |
| 266 | + MessageDialog.openError(Display.getDefault().getActiveShell(), "Error", |
| 267 | + Messages.getString("RegistrationHelper.RegistrationHandlerEmptyClassError")); |
| 268 | + } |
| 269 | + } |
231 | 270 | }
|
0 commit comments