~ubuntu-branches/ubuntu/utopic/eclipse-linuxtools/utopic

« back to all changes in this revision

Viewing changes to rpmstubby/org.eclipse.linuxtools.rpmstubby/src/org/eclipse/linuxtools/internal/rpmstubby/AbstractGenerator.java

  • Committer: Package Import Robot
  • Author(s): Jakub Adam
  • Date: 2014-05-12 18:11:40 UTC
  • mfrom: (3.1.2 sid)
  • Revision ID: package-import@ubuntu.com-20140512181140-w237r3vsah1tmybz
Tags: 2.2.1-1
* New upstream release.
* Refreshed d/patches.
* Removed eclipse-cdt-valgrind-remote package, all its functionality
  is now provided by eclipse-cdt-profiling-framework-remote.
* Added remove-license-feature.patch.
* Bump Standards-Version to 3.9.5.
* Enable eclipse-changelog package.
* Enable eclipse-rpm-editor package.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*******************************************************************************
2
 
 * Copyright (c) 2012 Red Hat, Inc.
 
2
 * Copyright (c) 2012, 2013 Red Hat, Inc.
3
3
 * All rights reserved. This program and the accompanying materials
4
4
 * are made available under the terms of the Eclipse Public License v1.0
5
5
 * which accompanies this distribution, and is available at
7
7
 *
8
8
 * Contributors:
9
9
 *     Red Hat Incorporated - initial API and implementation
 
10
 *     Neil Guzman - stub specfile in proper dir (B#414589)
10
11
 *******************************************************************************/
11
12
package org.eclipse.linuxtools.internal.rpmstubby;
12
13
 
16
17
 
17
18
import org.eclipse.core.resources.IContainer;
18
19
import org.eclipse.core.resources.IFile;
 
20
import org.eclipse.core.resources.IFolder;
19
21
import org.eclipse.core.resources.IResource;
20
22
import org.eclipse.core.resources.IWorkspaceRoot;
21
23
import org.eclipse.core.resources.ResourcesPlugin;
23
25
import org.eclipse.core.runtime.IStatus;
24
26
import org.eclipse.core.runtime.Path;
25
27
import org.eclipse.core.runtime.Status;
 
28
import org.eclipse.swt.widgets.Display;
26
29
import org.eclipse.ui.IWorkbenchPage;
27
30
import org.eclipse.ui.PartInitException;
28
31
import org.eclipse.ui.PlatformUI;
30
33
 
31
34
/**
32
35
 * Abstract class holding the common part of generators.
33
 
 * 
 
36
 *
34
37
 */
35
38
public abstract class AbstractGenerator {
36
39
 
48
51
                IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
49
52
                IResource resource = root.findMember(new Path(projectName));
50
53
                if (!resource.exists() || !(resource instanceof IContainer)) {
51
 
                        logCoreException("Project \"" + projectName + "\" does not exist.");
 
54
                        IStatus status = new Status(IStatus.ERROR, StubbyPlugin.PLUGIN_ID,
 
55
                                        IStatus.OK, "Project \"" + projectName + "\" does not exist.", null);
 
56
                        StubbyLog.logError(new CoreException(status));
52
57
                }
53
58
                IContainer container = (IContainer) resource;
54
 
                final IFile file = container.getFile(new Path(specfileName));
 
59
                IResource specsFolder = container.getProject().findMember("SPECS"); //$NON-NLS-1$
 
60
                IFile file = container.getFile(new Path(specfileName));
 
61
                if (specsFolder != null) {
 
62
                        file = ((IFolder) specsFolder).getFile(new Path(specfileName));
 
63
                }
 
64
                final IFile openFile = file;
55
65
                try {
56
66
                        InputStream stream = contentInputStream;
57
67
                        if (file.exists()) {
65
75
                } catch (CoreException e) {
66
76
                        StubbyLog.logError(e);
67
77
                }
68
 
                StubbyPlugin.getActiveWorkbenchShell().getDisplay()
69
 
                                .asyncExec(new Runnable() {
 
78
                Display.getCurrent().asyncExec(new Runnable() {
 
79
                                        @Override
70
80
                                        public void run() {
71
81
                                                IWorkbenchPage page = PlatformUI.getWorkbench()
72
82
                                                                .getActiveWorkbenchWindow().getActivePage();
73
83
                                                try {
74
 
                                                        IDE.openEditor(page, file, true);
 
84
                                                        IDE.openEditor(page, openFile, true);
75
85
                                                } catch (PartInitException e) {
76
86
                                                        StubbyLog.logError(e);
77
87
                                                }
81
91
 
82
92
        /**
83
93
         * The method that returns the string representation of the spec file.
84
 
         * 
 
94
         *
85
95
         * @return The specfile.
86
96
         */
87
97
        public abstract String generateSpecfile();
88
98
 
89
 
        private void logCoreException(String message) {
90
 
                IStatus status = new Status(IStatus.ERROR, StubbyPlugin.PLUGIN_ID,
91
 
                                IStatus.OK, message, null);
92
 
                StubbyLog.logError(new CoreException(status));
 
99
        /**
 
100
         * Generate changelog
 
101
         *
 
102
         * @param buffer Buffer to write content to
 
103
         */
 
104
        protected static void generateChangelog(StringBuilder buffer) {
 
105
                buffer.append("%changelog\n");
 
106
                buffer.append("#FIXME\n");
93
107
        }
94
108
 
95
109
}