~ubuntu-branches/debian/sid/eclipse-cdt/sid

« back to all changes in this revision

Viewing changes to core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/index/export/ExternalExportProjectProvider.java

  • Committer: Package Import Robot
  • Author(s): Jakub Adam
  • Date: 2011-10-06 21:15:04 UTC
  • mfrom: (1.1.4)
  • Revision ID: package-import@ubuntu.com-20111006211504-8dutmljjih0zikfv
Tags: 8.0.1-1
* New upstream release.
* Split the JNI packages into a separate architecture dependent
  package and made eclipse-cdt architecture independent.
* Install JNI libraries into multiarch aware location
* Bumped Standards-Version to 3.9.2.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*******************************************************************************
 
2
 * Copyright (c) 2007, 2009 Symbian Software Systems 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
 *    Andrew Ferguson (Symbian) - Initial implementation
 
10
 *******************************************************************************/
 
11
package org.eclipse.cdt.core.index.export;
 
12
 
 
13
import java.io.File;
 
14
import java.util.ArrayList;
 
15
import java.util.Arrays;
 
16
import java.util.Calendar;
 
17
import java.util.Date;
 
18
import java.util.HashMap;
 
19
import java.util.List;
 
20
import java.util.Map;
 
21
 
 
22
import com.ibm.icu.text.DateFormat;
 
23
import com.ibm.icu.text.MessageFormat;
 
24
 
 
25
import org.eclipse.cdt.core.CCorePlugin;
 
26
import org.eclipse.cdt.core.dom.IPDOMManager;
 
27
import org.eclipse.cdt.core.index.IIndexLocationConverter;
 
28
import org.eclipse.cdt.core.index.ResourceContainerRelativeLocationConverter;
 
29
import org.eclipse.cdt.core.model.CoreModel;
 
30
import org.eclipse.cdt.core.model.ICProject;
 
31
import org.eclipse.cdt.core.model.IPathEntry;
 
32
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
 
33
import org.eclipse.cdt.core.settings.model.ICProjectDescription;
 
34
import org.eclipse.cdt.core.settings.model.extension.impl.CDefaultConfigurationData;
 
35
import org.eclipse.cdt.internal.core.index.IIndexFragment;
 
36
import org.eclipse.cdt.internal.core.pdom.indexer.IndexerPreferences;
 
37
import org.eclipse.core.resources.IFolder;
 
38
import org.eclipse.core.resources.IProject;
 
39
import org.eclipse.core.resources.IProjectDescription;
 
40
import org.eclipse.core.resources.IResource;
 
41
import org.eclipse.core.resources.IWorkspace;
 
42
import org.eclipse.core.resources.IWorkspaceRunnable;
 
43
import org.eclipse.core.resources.ResourcesPlugin;
 
44
import org.eclipse.core.runtime.CoreException;
 
45
import org.eclipse.core.runtime.IProgressMonitor;
 
46
import org.eclipse.core.runtime.NullProgressMonitor;
 
47
import org.eclipse.core.runtime.Path;
 
48
 
 
49
/**
 
50
 * An IExportProjectProvider suitable for indexing an external folder. The arguments understood by this provider
 
51
 * are
 
52
 * <ul>
 
53
 * <li>-source what will become the root of the indexed content
 
54
 * <li>-include any preinclude files to configure the parser with
 
55
 * <li>-id the id to write to the produce fragment
 
56
 * </ul>
 
57
 */
 
58
public class ExternalExportProjectProvider extends AbstractExportProjectProvider {
 
59
        private static final String PREBUILT_PROJECT_OWNER = "org.eclipse.cdt.core.index.export.prebuiltOwner"; //$NON-NLS-1$
 
60
        private static final String ORG_ECLIPSE_CDT_CORE_INDEX_EXPORT_DATESTAMP = "org.eclipse.cdt.core.index.export.datestamp"; //$NON-NLS-1$
 
61
        private static final String CONTENT = "content"; //$NON-NLS-1$
 
62
        public static final String OPT_SOURCE = "-source"; //$NON-NLS-1$
 
63
        public static final String OPT_INCLUDE = "-include"; //$NON-NLS-1$
 
64
        public static final String OPT_FRAGMENT_ID = "-id"; //$NON-NLS-1$
 
65
 
 
66
        private IFolder content;
 
67
        private String fragmentId;
 
68
 
 
69
        public ExternalExportProjectProvider() {
 
70
                super();
 
71
        }
 
72
 
 
73
        /*
 
74
         * (non-Javadoc)
 
75
         * @see org.eclipse.cdt.core.index.export.IProjectForExportManager#createProject(java.util.Map)
 
76
         */
 
77
        public ICProject createProject() throws CoreException {
 
78
                // -source
 
79
                File source= new File(getSingleString(OPT_SOURCE));
 
80
                if(!source.exists()) {
 
81
                        fail(MessageFormat.format(Messages.ExternalContentPEM_LocationToIndexNonExistent, new Object[] {source}));
 
82
                }
 
83
 
 
84
                // -include
 
85
                List<String> includeFiles= new ArrayList<String>();
 
86
                if(isPresent(OPT_INCLUDE)) {
 
87
                        includeFiles.addAll(getParameters(OPT_INCLUDE));                                
 
88
                }
 
89
 
 
90
                // -id
 
91
                fragmentId= getSingleString(OPT_FRAGMENT_ID);
 
92
 
 
93
                return createCCProject("__" + System.currentTimeMillis(), source, includeFiles); //$NON-NLS-1$
 
94
        }
 
95
 
 
96
        /**
 
97
         * Returns the project folder the external content is stored in
 
98
         * @return the project folder the external content is stored in
 
99
         */
 
100
        protected IFolder getContentFolder() {
 
101
                return content;
 
102
        }
 
103
 
 
104
        /**
 
105
         * Convenience method for creating a cproject
 
106
         * @param projectName the name for the new project
 
107
         * @param location the absolute path of some external content
 
108
         * @param includeFiles a list of include paths to add to the project scanner
 
109
         * @return a new project
 
110
         * @throws CoreException
 
111
         */
 
112
        private ICProject createCCProject(final String projectName, final File location,
 
113
                        final List<String> includeFiles) throws CoreException {
 
114
                final IWorkspace ws = ResourcesPlugin.getWorkspace();
 
115
                final ICProject newProject[] = new ICProject[1];
 
116
 
 
117
                ws.run(new IWorkspaceRunnable() {
 
118
                        public void run(IProgressMonitor monitor) throws CoreException {
 
119
                                IWorkspace workspace= ResourcesPlugin.getWorkspace();
 
120
                                IProject project= workspace.getRoot().getProject("__prebuilt_index_temp__" + System.currentTimeMillis()); //$NON-NLS-1$
 
121
                                IProjectDescription description = workspace.newProjectDescription(project.getName());
 
122
                                CCorePlugin.getDefault().createCProject(description, project, NPM, PREBUILT_PROJECT_OWNER);
 
123
                                CCorePlugin.getDefault().convertProjectFromCtoCC(project, NPM);
 
124
                                ICProjectDescription pd= CCorePlugin.getDefault().getProjectDescription(project, true); 
 
125
                                newCfg(pd, project.getName(), "config"); //$NON-NLS-1$
 
126
                                                                
 
127
                                CoreModel.getDefault().setProjectDescription(project, pd, true, new NullProgressMonitor());
 
128
                                
 
129
                                ICProject cproject= CCorePlugin.getDefault().getCoreModel().create(project);
 
130
                                
 
131
                                // External content appears under a linked folder
 
132
                                content= cproject.getProject().getFolder(CONTENT);
 
133
                                content.createLink(new Path(location.getAbsolutePath()), IResource.NONE, null);
 
134
 
 
135
                                // Setup path entries
 
136
                                List<IPathEntry> entries= new ArrayList<IPathEntry>(Arrays.asList(CoreModel.getRawPathEntries(cproject)));
 
137
 
 
138
                                // pre-include files
 
139
                                for(String path : includeFiles) {
 
140
                                        entries.add(CoreModel.newIncludeFileEntry(project.getFullPath(), new Path(path)));
 
141
                                }
 
142
                                
 
143
                                // content directory is a source root
 
144
                                entries.add(CoreModel.newSourceEntry(content.getProjectRelativePath()));
 
145
                                
 
146
                                // any additional entries
 
147
                                entries.addAll(getAdditionalRawEntries());
 
148
                                
 
149
                                cproject.setRawPathEntries(entries.toArray(new IPathEntry[entries.size()]),
 
150
                                                new NullProgressMonitor()
 
151
                                );
 
152
                        
 
153
                                newProject[0]= cproject;
 
154
                                
 
155
                                IndexerPreferences.set(newProject[0].getProject(), IndexerPreferences.KEY_INDEXER_ID, IPDOMManager.ID_NO_INDEXER);
 
156
                                IndexerPreferences.set(newProject[0].getProject(), IndexerPreferences.KEY_INDEX_ALL_FILES, Boolean.TRUE.toString());
 
157
                                IndexerPreferences.set(newProject[0].getProject(), IndexerPreferences.KEY_INDEX_UNUSED_HEADERS_WITH_DEFAULT_LANG, Boolean.TRUE.toString());
 
158
                        }
 
159
                }, null);
 
160
 
 
161
                return newProject[0];
 
162
        }
 
163
        
 
164
        /**
 
165
         * Get additional raw entries (above those added as part of the ExternalExportProjectProvider functionality)
 
166
         * @return a list of additional entries to add to the project
 
167
         */
 
168
        protected List<IPathEntry> getAdditionalRawEntries() {
 
169
                List<IPathEntry> entries= new ArrayList<IPathEntry>();
 
170
                entries.add(CoreModel.newIncludeEntry(content.getProjectRelativePath(), null, content.getLocation(), true));
 
171
                return entries;
 
172
        }
 
173
 
 
174
        private ICConfigurationDescription newCfg(ICProjectDescription des, String project, String config) throws CoreException {
 
175
                CDefaultConfigurationData data= new CDefaultConfigurationData(project + "." + config, //$NON-NLS-1$
 
176
                                project + " " + config + " name", null); //$NON-NLS-1$ //$NON-NLS-2$
 
177
                data.initEmptyData();
 
178
                return des.createConfiguration(CCorePlugin.DEFAULT_PROVIDER_ID, data);          
 
179
        }
 
180
 
 
181
        /*
 
182
         * @see org.eclipse.cdt.core.index.export.IExportProjectProvider#getLocationConverter(org.eclipse.cdt.core.model.ICProject)
 
183
         */
 
184
        public IIndexLocationConverter getLocationConverter(final ICProject cproject) {
 
185
                return new ResourceContainerRelativeLocationConverter(content);
 
186
        }
 
187
 
 
188
        /*
 
189
         * @see org.eclipse.cdt.core.index.export.IExportProjectProvider#getExportProperties()
 
190
         */
 
191
        public Map<String, String> getExportProperties() {
 
192
                Map<String, String> properties= new HashMap<String, String>();
 
193
                Date now= Calendar.getInstance().getTime();
 
194
                properties.put(ORG_ECLIPSE_CDT_CORE_INDEX_EXPORT_DATESTAMP,
 
195
                                DateFormat.getDateInstance().format(now)
 
196
                                + " " + DateFormat.getTimeInstance().format(now)); //$NON-NLS-1$
 
197
                properties.put(IIndexFragment.PROPERTY_FRAGMENT_ID, fragmentId);
 
198
                return properties;
 
199
        }
 
200
}