Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 301606 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/xtext/ui/generator/projectWizard/ProjectCreator.xpt (-14 / +38 lines)
Lines 37-48 Link Here
37
import org.eclipse.xpand2.output.Outlet;
37
import org.eclipse.xpand2.output.Outlet;
38
import org.eclipse.xpand2.output.OutputImpl;
38
import org.eclipse.xpand2.output.OutputImpl;
39
import org.eclipse.xtext.ui.util.EclipseResourceUtil;
39
import org.eclipse.xtext.ui.util.EclipseResourceUtil;
40
import org.eclipse.xtext.ui.wizard.DefaultProjectCreator;
40
import org.eclipse.xtext.ui.util.JavaProjectConfigurator;
41
import org.eclipse.xtext.ui.wizard.AbstractProjectCreator;
42
import org.eclipse.xtext.ui.util.ProjectCreatorDescription;
41
43
42
import com.google.common.collect.Lists;
44
import com.google.common.collect.Lists;
43
import com.google.common.collect.Sets;
45
import com.google.common.collect.Sets;
46
import com.google.inject.Inject;
47
import com.google.inject.Provider;
44
48
45
public class «projectCreatorClassName().toSimpleName()» extends DefaultProjectCreator {
49
public class «projectCreatorClassName().toSimpleName()» extends AbstractProjectCreator {
46
50
47
	private static final String DSL_GENERATOR_PROJECT_NAME = "«generatorProjectName»";
51
	private static final String DSL_GENERATOR_PROJECT_NAME = "«generatorProjectName»";
48
52
Lines 51-56 Link Here
51
	private final List<String> SRC_FOLDER_LIST = Collections
55
	private final List<String> SRC_FOLDER_LIST = Collections
52
			.unmodifiableList(Arrays.asList(SRC_ROOT, SRC_GEN_ROOT));
56
			.unmodifiableList(Arrays.asList(SRC_ROOT, SRC_GEN_ROOT));
53
57
58
	@Inject
59
	private Provider<EclipseResourceUtil> eclipseResourceUtilProvider;
60
54
	@Override
61
	@Override
55
	protected «projectInfoClassName().toSimpleName()» getProjectInfo() {
62
	protected «projectInfoClassName().toSimpleName()» getProjectInfo() {
56
		return («projectInfoClassName().toSimpleName()») super.getProjectInfo();
63
		return («projectInfoClassName().toSimpleName()») super.getProjectInfo();
Lines 75-94 Link Here
75
	}
82
	}
76
83
77
	protected IProject createProject(IProgressMonitor monitor) {
84
	protected IProject createProject(IProgressMonitor monitor) {
78
		final IProject project = EclipseResourceUtil.createProject(
85
		ProjectCreatorDescription creatorDescription = new ProjectCreatorDescription();
79
				getProjectInfo().getProjectName(),
86
		creatorDescription.setProjectName(getProjectInfo().getProjectName());
80
				getSourceFolders(), 
87
		creatorDescription.setSourceFolders(getSourceFolders());
81
				getReferencedProjects(),
88
		creatorDescription.setReferencedProjects(getReferencedProjects());
82
				Sets.newLinkedHashSet(getRequiredBundles()), 
89
		creatorDescription.setRequiredBundles(Sets
83
				getExportedPackages(),
90
				.newLinkedHashSet(getRequiredBundles()));
84
				getImportedPackages(), 
91
		creatorDescription.setExportedPackages(getExportedPackages());
85
				getActivatorClassName(),
92
		creatorDescription.setImportedPackages(getImportedPackages());
86
				monitor,
93
		creatorDescription.setActivatorClassName(getActivatorClassName());
87
				null,
94
		creatorDescription.setProjectNatures(getProjectNatures());
88
				getProjectNatures()
95
		creatorDescription.setBuilders(getBuilders());
89
		);
96
		final IProject project = eclipseResourceUtilProvider.get().createProject(
97
				creatorDescription, monitor, null);
98
		configureProject(project, getSourceFolders(), monitor);
90
		return project;
99
		return project;
91
	}
100
	}
101
102
	@Override
103
	protected void configureProject(IProject project, List<String> srcFolders,
104
			IProgressMonitor monitor) {
105
		JavaProjectConfigurator.configureJavaProject(project, srcFolders,
106
				monitor);
107
	}
92
	
108
	
93
	protected List<String> getSourceFolders() {
109
	protected List<String> getSourceFolders() {
94
        return SRC_FOLDER_LIST;
110
        return SRC_FOLDER_LIST;
Lines 119-124 Link Here
119
		};
135
		};
120
    }
136
    }
121
    
137
    
138
    protected String[] getBuilders() {
139
    	return new String[]{
140
			"org.eclipse.jdt.core.javabuilder", 
141
			"org.eclipse.pde.ManifestBuilder", 
142
			"org.eclipse.pde.SchemaBuilder"
143
		};
144
	}
145
    
122
	protected List<String> getRequiredBundles() {
146
	protected List<String> getRequiredBundles() {
123
		return Lists.newArrayList(
147
		return Lists.newArrayList(
124
			"com.ibm.icu",
148
			"com.ibm.icu",
(-)src/org/eclipse/xtext/ui/DefaultUiModule.java (+12 lines)
Lines 44-49 Link Here
44
import org.eclipse.xtext.ui.editor.formatting.IContentFormatterFactory;
44
import org.eclipse.xtext.ui.editor.formatting.IContentFormatterFactory;
45
import org.eclipse.xtext.ui.editor.formatting.PreferenceStoreIndentationInformation;
45
import org.eclipse.xtext.ui.editor.formatting.PreferenceStoreIndentationInformation;
46
import org.eclipse.xtext.ui.editor.hyperlinking.DefaultHyperlinkDetector;
46
import org.eclipse.xtext.ui.editor.hyperlinking.DefaultHyperlinkDetector;
47
import org.eclipse.xtext.ui.editor.model.IResourceForEditorInputFactory;
48
import org.eclipse.xtext.ui.editor.model.JavaClassPathResourceForIEditorInputFactory;
47
import org.eclipse.xtext.ui.editor.outline.IContentOutlineNodeComparer;
49
import org.eclipse.xtext.ui.editor.outline.IContentOutlineNodeComparer;
48
import org.eclipse.xtext.ui.editor.outline.IOutlineTreeProvider;
50
import org.eclipse.xtext.ui.editor.outline.IOutlineTreeProvider;
49
import org.eclipse.xtext.ui.editor.outline.XtextContentOutlinePage;
51
import org.eclipse.xtext.ui.editor.outline.XtextContentOutlinePage;
Lines 65-70 Link Here
65
import org.eclipse.xtext.ui.label.DefaultDescriptionLabelProvider;
67
import org.eclipse.xtext.ui.label.DefaultDescriptionLabelProvider;
66
import org.eclipse.xtext.ui.label.DefaultEObjectLabelProvider;
68
import org.eclipse.xtext.ui.label.DefaultEObjectLabelProvider;
67
import org.eclipse.xtext.ui.label.InjectableAdapterFactoryLabelProvider;
69
import org.eclipse.xtext.ui.label.InjectableAdapterFactoryLabelProvider;
70
import org.eclipse.xtext.ui.resource.IResourceSetProvider;
71
import org.eclipse.xtext.ui.resource.XtextResourceSetProvider;
68
72
69
import com.google.inject.Binder;
73
import com.google.inject.Binder;
70
import com.google.inject.name.Names;
74
import com.google.inject.name.Names;
Lines 231-234 Link Here
231
	public Class<? extends IContentOutlineNodeComparer> bindIContentOutlineNodeComparer() {
235
	public Class<? extends IContentOutlineNodeComparer> bindIContentOutlineNodeComparer() {
232
		return IContentOutlineNodeComparer.Default.class;
236
		return IContentOutlineNodeComparer.Default.class;
233
	}
237
	}
238
	
239
	public Class<? extends IResourceForEditorInputFactory> bindIResourceForEditorInputFactory() {
240
		return JavaClassPathResourceForIEditorInputFactory.class;
241
	}
242
	
243
	public Class<? extends IResourceSetProvider> bindIResourceSetProvider() {
244
		return XtextResourceSetProvider.class;
245
	}
234
}
246
}
(-)src/org/eclipse/xtext/ui/editor/model/IResourceForEditorInputFactory.java (-3 lines)
Lines 10-21 Link Here
10
import org.eclipse.emf.ecore.resource.Resource;
10
import org.eclipse.emf.ecore.resource.Resource;
11
import org.eclipse.ui.IEditorInput;
11
import org.eclipse.ui.IEditorInput;
12
12
13
import com.google.inject.ImplementedBy;
14
15
/**
13
/**
16
 * @author Sven Efftinge - Initial contribution and API
14
 * @author Sven Efftinge - Initial contribution and API
17
 */
15
 */
18
@ImplementedBy(JavaClassPathResourceForIEditorInputFactory.class)
19
public interface IResourceForEditorInputFactory {
16
public interface IResourceForEditorInputFactory {
20
	Resource createResource(IEditorInput input);
17
	Resource createResource(IEditorInput input);
21
}
18
}
(-)src/org/eclipse/xtext/ui/editor/model/JavaClassPathResourceForIEditorInputFactory.java (-44 / +11 lines)
Lines 12-18 Link Here
12
import org.eclipse.core.runtime.CoreException;
12
import org.eclipse.core.runtime.CoreException;
13
import org.eclipse.emf.common.util.URI;
13
import org.eclipse.emf.common.util.URI;
14
import org.eclipse.emf.common.util.WrappedException;
14
import org.eclipse.emf.common.util.WrappedException;
15
import org.eclipse.emf.ecore.resource.ContentHandler;
16
import org.eclipse.emf.ecore.resource.Resource;
15
import org.eclipse.emf.ecore.resource.Resource;
17
import org.eclipse.emf.ecore.resource.ResourceSet;
16
import org.eclipse.emf.ecore.resource.ResourceSet;
18
import org.eclipse.jdt.core.IJarEntryResource;
17
import org.eclipse.jdt.core.IJarEntryResource;
Lines 20-29 Link Here
20
import org.eclipse.jdt.core.IPackageFragmentRoot;
19
import org.eclipse.jdt.core.IPackageFragmentRoot;
21
import org.eclipse.ui.IEditorInput;
20
import org.eclipse.ui.IEditorInput;
22
import org.eclipse.ui.IStorageEditorInput;
21
import org.eclipse.ui.IStorageEditorInput;
23
import org.eclipse.xtext.resource.IExternalContentSupport;
24
import org.eclipse.xtext.resource.XtextResource;
22
import org.eclipse.xtext.resource.XtextResource;
25
import org.eclipse.xtext.resource.IExternalContentSupport.IExternalContentProvider;
26
import org.eclipse.xtext.ui.resource.IResourceSetProvider;
27
import org.eclipse.xtext.ui.resource.IStorage2UriMapper;
23
import org.eclipse.xtext.ui.resource.IStorage2UriMapper;
28
24
29
import com.google.inject.Inject;
25
import com.google.inject.Inject;
Lines 32-59 Link Here
32
 * @author Michael Clay
28
 * @author Michael Clay
33
 * @author Jan Koehnlein
29
 * @author Jan Koehnlein
34
 */
30
 */
35
public class JavaClassPathResourceForIEditorInputFactory implements IResourceForEditorInputFactory {
31
public class JavaClassPathResourceForIEditorInputFactory extends ResourceForIEditorInputFactory {
36
32
37
	@Inject
33
	@Inject
38
	private IStorage2UriMapper storageToUriMapper;
34
	private IStorage2UriMapper storageToUriMapper;
39
35
40
	@Inject
36
	@Override
41
	private IResourceSetProvider resourceSetProvider;
42
43
	@Inject
44
	private IExternalContentSupport externalContentSupport;
45
46
	@Inject
47
	private IExternalContentProvider externalContentProvider;
48
49
	public Resource createResource(IEditorInput editorInput) {
37
	public Resource createResource(IEditorInput editorInput) {
50
		try {
38
		try {
51
			if (editorInput instanceof IStorageEditorInput) {
39
			if (editorInput instanceof IStorageEditorInput) {
52
				IStorage storage = ((IStorageEditorInput) editorInput).getStorage();
40
				IStorage storage = ((IStorageEditorInput) editorInput).getStorage();
53
				if (storage instanceof IFile) {
41
				if (storage instanceof IJarEntryResource) {
54
					return createResourceFor((IFile) storage);
55
				} else if (storage instanceof IJarEntryResource) {
56
					return createResourceFor((IJarEntryResource) storage);
42
					return createResourceFor((IJarEntryResource) storage);
43
				} else if (storage instanceof IFile) {
44
					return super.createResource(editorInput);
57
				}
45
				}
58
			}
46
			}
59
			throw new IllegalArgumentException("Couldn't create EMF Resource for input " + editorInput);
47
			throw new IllegalArgumentException("Couldn't create EMF Resource for input " + editorInput);
Lines 71-110 Link Here
71
		return resource;
59
		return resource;
72
	}
60
	}
73
61
74
	protected void configureResourceSet(ResourceSet resourceSet, URI primaryURI) {
62
	@Override
75
		// TODO: Filter external content - primary resource should not use dirty state
76
		externalContentSupport.configureResourceSet(resourceSet, externalContentProvider);
77
	}
78
79
	protected XtextResource createResource(ResourceSet resourceSet, URI uri) {
80
		Resource aResource = resourceSet.createResource(uri, ContentHandler.UNSPECIFIED_CONTENT_TYPE);
81
		if (!(aResource instanceof XtextResource))
82
			throw new IllegalStateException("The resource factory registered for " + uri
83
					+ " does not yield an XtextResource. Make sure the right resource factory has been registered.");
84
		return (XtextResource) aResource;
85
	}
86
87
	protected ResourceSet getResourceSet(IStorage storage) {
63
	protected ResourceSet getResourceSet(IStorage storage) {
88
		if (storage instanceof IFile) {
64
		if (storage instanceof IJarEntryResource) {
89
			return resourceSetProvider.get(((IFile) storage).getProject());
90
		} else if (storage instanceof IJarEntryResource){
91
			IPackageFragmentRoot root = ((IJarEntryResource) storage).getPackageFragmentRoot();
65
			IPackageFragmentRoot root = ((IJarEntryResource) storage).getPackageFragmentRoot();
92
			if (root != null) {
66
			if (root != null) {
93
				IJavaProject project = root.getJavaProject();
67
				IJavaProject project = root.getJavaProject();
94
				if (project != null)
68
				if (project != null)
95
					return resourceSetProvider.get(project.getProject());
69
					return getResourceSetProvider().get(project.getProject());
96
			}
70
			}
71
		} else if (storage instanceof IFile) {
72
			return super.getResourceSet(storage);
97
		}
73
		}
98
		return resourceSetProvider.get(null);
99
	}
100
74
101
	protected Resource createResourceFor(IFile storage) throws CoreException {
75
		return getResourceSetProvider().get(null);
102
		ResourceSet resourceSet = getResourceSet(storage);
103
		URI uri = URI.createPlatformResourceURI(storage.getFullPath().toString(), true);
104
		configureResourceSet(resourceSet, uri);
105
		XtextResource resource = createResource(resourceSet, uri);
106
		resource.setValidationDisabled(false);
107
		return resource;
108
	}
76
	}
109
110
}
77
}
(-)src/org/eclipse/xtext/ui/editor/model/ResourceForIEditorInputFactory.java (+101 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2010 itemis AG (http://www.itemis.eu) 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
package org.eclipse.xtext.ui.editor.model;
9
10
import org.eclipse.core.resources.IFile;
11
import org.eclipse.core.resources.IStorage;
12
import org.eclipse.core.runtime.CoreException;
13
import org.eclipse.emf.common.util.URI;
14
import org.eclipse.emf.common.util.WrappedException;
15
import org.eclipse.emf.ecore.resource.ContentHandler;
16
import org.eclipse.emf.ecore.resource.Resource;
17
import org.eclipse.emf.ecore.resource.ResourceSet;
18
import org.eclipse.ui.IEditorInput;
19
import org.eclipse.ui.IStorageEditorInput;
20
import org.eclipse.xtext.resource.IExternalContentSupport;
21
import org.eclipse.xtext.resource.IExternalContentSupport.IExternalContentProvider;
22
import org.eclipse.xtext.resource.XtextResource;
23
import org.eclipse.xtext.ui.resource.IResourceSetProvider;
24
25
import com.google.inject.Inject;
26
27
/**
28
 * @author schill - Initial contribution and API
29
 */
30
public class ResourceForIEditorInputFactory implements IResourceForEditorInputFactory {
31
32
	@Inject
33
	private IResourceSetProvider resourceSetProvider;
34
35
	@Inject
36
	private IExternalContentSupport externalContentSupport;
37
38
	@Inject
39
	private IExternalContentProvider externalContentProvider;
40
41
	public Resource createResource(IEditorInput editorInput) {
42
		try {
43
			if (editorInput instanceof IStorageEditorInput) {
44
				IStorage storage = ((IStorageEditorInput) editorInput).getStorage();
45
				if (storage instanceof IFile) 
46
					return createResourceFor((IFile) storage);
47
			}
48
			throw new IllegalArgumentException("Couldn't create EMF Resource for input " + editorInput);
49
		} catch (CoreException e) {
50
			throw new WrappedException(e);
51
		}
52
	}
53
54
55
	protected Resource createResourceFor(IFile storage) throws CoreException {
56
		ResourceSet resourceSet = getResourceSet(storage);
57
		URI uri = URI.createPlatformResourceURI(storage.getFullPath().toString(), true);
58
		configureResourceSet(resourceSet, uri);
59
		XtextResource resource = createResource(resourceSet, uri);
60
		resource.setValidationDisabled(false);
61
		return resource;
62
	}
63
	
64
	protected XtextResource createResource(ResourceSet resourceSet, URI uri) {
65
		Resource aResource = resourceSet.createResource(uri, ContentHandler.UNSPECIFIED_CONTENT_TYPE);
66
		if (!(aResource instanceof XtextResource))
67
			throw new IllegalStateException("The resource factory registered for " + uri
68
					+ " does not yield an XtextResource. Make sure the right resource factory has been registered.");
69
		return (XtextResource) aResource;
70
	}
71
72
	protected ResourceSet getResourceSet(IStorage storage) {
73
		if (storage instanceof IFile) {
74
			return resourceSetProvider.get(((IFile) storage).getProject());
75
		}
76
		return resourceSetProvider.get(null);
77
	}
78
79
	protected void configureResourceSet(ResourceSet resourceSet, URI primaryURI) {
80
		// TODO: Filter external content - primary resource should not use dirty state
81
		externalContentSupport.configureResourceSet(resourceSet, externalContentProvider);
82
	}
83
84
85
	protected IResourceSetProvider getResourceSetProvider() {
86
		return resourceSetProvider;
87
	}
88
89
90
	protected IExternalContentSupport getExternalContentSupport() {
91
		return externalContentSupport;
92
	}
93
94
95
	protected IExternalContentProvider getExternalContentProvider() {
96
		return externalContentProvider;
97
	}
98
	
99
	
100
101
}
(-)src/org/eclipse/xtext/ui/resource/IResourceSetProvider.java (-4 / +1 lines)
Lines 10-22 Link Here
10
import org.eclipse.core.resources.IProject;
10
import org.eclipse.core.resources.IProject;
11
import org.eclipse.emf.ecore.resource.ResourceSet;
11
import org.eclipse.emf.ecore.resource.ResourceSet;
12
12
13
import com.google.inject.ImplementedBy;
14
15
/**
13
/**
16
 * @author Sven Efftinge - Initial contribution and API
14
 * @author Sven Efftinge - Initial contribution and API
17
 */
15
 */
18
@ImplementedBy(XtextResourceSetProvider.class)
19
public interface IResourceSetProvider {
16
public interface IResourceSetProvider {
20
	
17
21
	ResourceSet get(IProject project);
18
	ResourceSet get(IProject project);
22
}
19
}
(-)src/org/eclipse/xtext/ui/resource/SimpleResourceSetProvider.java (+29 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2010 itemis AG (http://www.itemis.eu) 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
package org.eclipse.xtext.ui.resource;
9
10
import org.eclipse.core.resources.IProject;
11
import org.eclipse.emf.ecore.resource.ResourceSet;
12
import org.eclipse.xtext.resource.XtextResourceSet;
13
14
import com.google.inject.Inject;
15
import com.google.inject.Provider;
16
17
/**
18
 * @author schill - Initial contribution and API
19
 */
20
public class SimpleResourceSetProvider implements IResourceSetProvider {
21
22
	@Inject
23
	private Provider<XtextResourceSet> resourceSetProvider;
24
	
25
	public ResourceSet get(IProject project) {
26
		return resourceSetProvider.get();
27
	}
28
29
}
(-)src/org/eclipse/xtext/ui/util/EclipseResourceUtil.java (-151 / +27 lines)
Lines 9-24 Link Here
9
package org.eclipse.xtext.ui.util;
9
package org.eclipse.xtext.ui.util;
10
10
11
import java.io.ByteArrayInputStream;
11
import java.io.ByteArrayInputStream;
12
import java.io.IOException;
13
import java.io.InputStream;
12
import java.io.InputStream;
14
import java.net.URL;
15
import java.util.ArrayList;
16
import java.util.Iterator;
13
import java.util.Iterator;
17
import java.util.List;
14
import java.util.List;
18
import java.util.Set;
15
import java.util.Set;
19
16
20
import org.apache.log4j.Logger;
17
import org.apache.log4j.Logger;
21
import org.eclipse.core.resources.ICommand;
22
import org.eclipse.core.resources.IContainer;
18
import org.eclipse.core.resources.IContainer;
23
import org.eclipse.core.resources.IFile;
19
import org.eclipse.core.resources.IFile;
24
import org.eclipse.core.resources.IFolder;
20
import org.eclipse.core.resources.IFolder;
Lines 27-84 Link Here
27
import org.eclipse.core.resources.IWorkspace;
23
import org.eclipse.core.resources.IWorkspace;
28
import org.eclipse.core.resources.ResourcesPlugin;
24
import org.eclipse.core.resources.ResourcesPlugin;
29
import org.eclipse.core.runtime.CoreException;
25
import org.eclipse.core.runtime.CoreException;
30
import org.eclipse.core.runtime.IPath;
31
import org.eclipse.core.runtime.IProgressMonitor;
26
import org.eclipse.core.runtime.IProgressMonitor;
32
import org.eclipse.core.runtime.NullProgressMonitor;
27
import org.eclipse.core.runtime.NullProgressMonitor;
33
import org.eclipse.core.runtime.Path;
28
import org.eclipse.core.runtime.Path;
34
import org.eclipse.core.runtime.Platform;
35
import org.eclipse.core.runtime.SubMonitor;
29
import org.eclipse.core.runtime.SubMonitor;
36
import org.eclipse.jdt.core.IClasspathEntry;
37
import org.eclipse.jdt.core.IJavaProject;
38
import org.eclipse.jdt.core.JavaCore;
39
import org.eclipse.jface.dialogs.MessageDialog;
30
import org.eclipse.jface.dialogs.MessageDialog;
40
import org.eclipse.swt.widgets.Shell;
31
import org.eclipse.swt.widgets.Shell;
41
import org.eclipse.ui.IWorkbench;
42
import org.eclipse.ui.IWorkbenchPage;
32
import org.eclipse.ui.IWorkbenchPage;
43
import org.eclipse.ui.IWorkingSet;
44
import org.eclipse.ui.PartInitException;
33
import org.eclipse.ui.PartInitException;
45
import org.eclipse.ui.PlatformUI;
34
import org.eclipse.ui.PlatformUI;
46
import org.eclipse.ui.ide.IDE;
35
import org.eclipse.ui.ide.IDE;
47
36
48
/**
37
/**
49
 * Represents a helper/util class to work with eclipse core resource
38
 * Represents a helper/util class to work with eclipse core resource abstractions for workspace,project,files and
50
 * abstractions for workspace,project,files and directories. For the most part
39
 * directories. For the most part this code was copied from the last version (4.3.1) of openArchitectureWare.
51
 * this code was copied from the last version (4.3.1) of openArchitectureWare.
40
 * 
52
 *
53
 * @author Michael Clay
41
 * @author Michael Clay
54
 */
42
 */
55
public class EclipseResourceUtil {
43
public class EclipseResourceUtil {
56
44
57
	private static Logger logger = Logger.getLogger(EclipseResourceUtil.class);
45
	private static final Logger logger = Logger.getLogger(EclipseResourceUtil.class);
58
46
59
	public static final String ISO_8859_1 = "iso-8859-1";
47
	public IProject createProject(final ProjectCreatorDescription projectCreatorDescription,
60
48
			final IProgressMonitor monitor, final Shell theShell) {
61
	public static IProject createProject(final String projectName, final IPath location, final List<String> srcFolders,
62
			final List<IProject> referencedProjects, final Set<String> requiredBundles,
63
			final List<String> exportedPackages, final List<String> importedPackages, final String activatorClassName,
64
			final IProgressMonitor monitor, final Shell theShell, String[] projectNatures, IWorkingSet[] workingSets,
65
			IWorkbench workbench) {
66
49
67
		IProject project = null;
50
		IProject project = null;
68
		SubMonitor subMonitor = SubMonitor.convert(monitor, 10);
51
		SubMonitor subMonitor = SubMonitor.convert(monitor, 10);
69
		try {
52
		try {
70
			subMonitor.subTask("Creating project " + projectName);
53
			subMonitor.subTask("Creating project " + projectCreatorDescription.getProjectName());
71
			final IWorkspace workspace = ResourcesPlugin.getWorkspace();
54
			final IWorkspace workspace = ResourcesPlugin.getWorkspace();
72
			project = workspace.getRoot().getProject(projectName);
55
			project = workspace.getRoot().getProject(projectCreatorDescription.getProjectName());
73
74
			// Clean up any old project information.
56
			// Clean up any old project information.
75
			if (project.exists()) {
57
			if (project.exists()) {
76
				final boolean[] result = new boolean[1];
58
				final boolean[] result = new boolean[1];
77
				PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() {
59
				PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() {
78
					public void run() {
60
					public void run() {
79
						result[0] = MessageDialog.openQuestion(theShell, "Do you want to overwrite the project "
61
						result[0] = MessageDialog.openQuestion(theShell, "Do you want to overwrite the project "
80
								+ projectName, "Note that everything inside the project '" + projectName
62
								+ projectCreatorDescription.getProjectName(),
81
								+ "' will be deleted if you confirm this dialog.");
63
								"Note that everything inside the project '"
64
										+ projectCreatorDescription.getProjectName()
65
										+ "' will be deleted if you confirm this dialog.");
82
					}
66
					}
83
				});
67
				});
84
				if (result[0]) {
68
				if (result[0]) {
Lines 86-146 Link Here
86
				} else
70
				} else
87
					return null;
71
					return null;
88
			}
72
			}
89
73
			IProjectDescription projectDescription = projectCreatorDescription.createProjectDescription();
90
			final IJavaProject javaProject = JavaCore.create(project);
91
			final IProjectDescription projectDescription = ResourcesPlugin.getWorkspace().newProjectDescription(
92
					projectName);
93
			if (location!=null && !Platform.getLocation().equals(location.removeLastSegments(1))) {
94
				projectDescription.setLocation(location);
95
			}
96
			project.create(projectDescription, subMonitor.newChild(1));
74
			project.create(projectDescription, subMonitor.newChild(1));
97
			final List<IClasspathEntry> classpathEntries = new ArrayList<IClasspathEntry>();
98
			if (referencedProjects.size() != 0) {
99
				projectDescription.setReferencedProjects(referencedProjects.toArray(new IProject[referencedProjects
100
						.size()]));
101
				for (final IProject referencedProject : referencedProjects) {
102
					final IClasspathEntry referencedProjectClasspathEntry = JavaCore.newProjectEntry(referencedProject
103
							.getFullPath());
104
					classpathEntries.add(referencedProjectClasspathEntry);
105
				}
106
			}
107
			projectDescription.setNatureIds(projectNatures);
108
109
			final ICommand java = projectDescription.newCommand();
110
			java.setBuilderName(JavaCore.BUILDER_ID);
111
112
			final ICommand manifest = projectDescription.newCommand();
113
			manifest.setBuilderName("org.eclipse.pde.ManifestBuilder");
114
115
			final ICommand schema = projectDescription.newCommand();
116
			schema.setBuilderName("org.eclipse.pde.SchemaBuilder");
117
118
			projectDescription.setBuildSpec(new ICommand[] { java, manifest, schema });
119
120
			project.open(subMonitor.newChild(1));
75
			project.open(subMonitor.newChild(1));
121
			project.setDescription(projectDescription, subMonitor.newChild(1));
76
			project.setDescription(projectDescription, subMonitor.newChild(1));
122
77
			for (final String src : projectCreatorDescription.getSourceFolders()) {
123
			for (final String src : srcFolders) {
124
				final IFolder srcContainer = project.getFolder(src);
78
				final IFolder srcContainer = project.getFolder(src);
125
				if (!srcContainer.exists()) {
79
				if (!srcContainer.exists()) {
126
					srcContainer.create(false, true, subMonitor.newChild(1));
80
					srcContainer.create(false, true, subMonitor.newChild(1));
127
				}
81
				}
128
				final IClasspathEntry srcClasspathEntry = JavaCore.newSourceEntry(srcContainer.getFullPath());
129
				classpathEntries.add(srcClasspathEntry);
130
			}
82
			}
131
83
			createManifest(projectCreatorDescription.getProjectName(), projectCreatorDescription.getRequiredBundles(),
132
			classpathEntries.add(JavaCore.newContainerEntry(new Path("org.eclipse.jdt.launching.JRE_CONTAINER")));
84
					projectCreatorDescription.getExportedPackages(), projectCreatorDescription.getImportedPackages(),
133
			classpathEntries.add(JavaCore.newContainerEntry(new Path("org.eclipse.pde.core.requiredPlugins")));
85
					projectCreatorDescription.getActivatorClassName(), subMonitor.newChild(1), project);
134
86
			createBuildProps(subMonitor.newChild(1), project, projectCreatorDescription.getSourceFolders());
135
			javaProject.setRawClasspath(classpathEntries.toArray(new IClasspathEntry[classpathEntries.size()]),
87
			if (projectCreatorDescription.getWorkbench() != null && projectCreatorDescription.getWorkingSets() != null)
136
					subMonitor.newChild(1));
88
				projectCreatorDescription.getWorkbench().getWorkingSetManager().addToWorkingSets(project,
137
89
						projectCreatorDescription.getWorkingSets());
138
			javaProject.setOutputLocation(new Path("/" + projectName + "/bin"), subMonitor.newChild(1));
139
			createManifest(projectName, requiredBundles, exportedPackages, importedPackages, activatorClassName,
140
					subMonitor.newChild(1), project);
141
			createBuildProps(subMonitor.newChild(1), project, srcFolders);
142
			if (workbench != null && workingSets != null)
143
				workbench.getWorkingSetManager().addToWorkingSets(project, workingSets);
144
		} catch (final Exception exception) {
90
		} catch (final Exception exception) {
145
			exception.printStackTrace();
91
			exception.printStackTrace();
146
			logger.error(exception);
92
			logger.error(exception);
Lines 149-164 Link Here
149
		}
95
		}
150
		return project;
96
		return project;
151
	}
97
	}
152
	
153
	public static IProject createProject(final String projectName, final List<String> srcFolders,
154
			final List<IProject> referencedProjects, final Set<String> requiredBundles,
155
			final List<String> exportedPackages, final List<String> importedPackages, final String activatorClassName,
156
			final IProgressMonitor progressMonitor, final Shell theShell, String[] projectNatures) {
157
		return createProject(projectName, null, srcFolders, referencedProjects, requiredBundles, exportedPackages,
158
				importedPackages, activatorClassName, progressMonitor, theShell, projectNatures, null, null);
159
	}
160
98
161
	public static IFile createFile(final String name, final IContainer container, final String content,
99
	protected IFile createFile(final String name, final IContainer container, final String content,
162
			final IProgressMonitor progressMonitor) {
100
			final IProgressMonitor progressMonitor) {
163
		final IFile file = container.getFile(new Path(name));
101
		final IFile file = container.getFile(new Path(name));
164
		assertExist(file.getParent());
102
		assertExist(file.getParent());
Lines 179-185 Link Here
179
		return file;
117
		return file;
180
	}
118
	}
181
119
182
	public static IFile createFile(final String name, final IContainer container, final String content,
120
	protected IFile createFile(final String name, final IContainer container, final String content,
183
			final String charSet, final IProgressMonitor progressMonitor) throws CoreException {
121
			final String charSet, final IProgressMonitor progressMonitor) throws CoreException {
184
		final IFile file = createFile(name, container, content, progressMonitor);
122
		final IFile file = createFile(name, container, content, progressMonitor);
185
		if (file != null && charSet != null) {
123
		if (file != null && charSet != null) {
Lines 188-194 Link Here
188
		return file;
126
		return file;
189
	}
127
	}
190
128
191
	private static void createBuildProps(final IProgressMonitor progressMonitor, final IProject project,
129
	protected void createBuildProps(final IProgressMonitor progressMonitor, final IProject project,
192
			final List<String> srcFolders) {
130
			final List<String> srcFolders) {
193
		final StringBuilder bpContent = new StringBuilder("source.. = ");
131
		final StringBuilder bpContent = new StringBuilder("source.. = ");
194
		for (final Iterator<String> iterator = srcFolders.iterator(); iterator.hasNext();) {
132
		for (final Iterator<String> iterator = srcFolders.iterator(); iterator.hasNext();) {
Lines 205-211 Link Here
205
		createFile("build.properties", project, bpContent.toString(), progressMonitor);
143
		createFile("build.properties", project, bpContent.toString(), progressMonitor);
206
	}
144
	}
207
145
208
	private static void createManifest(final String projectName, final Set<String> requiredBundles,
146
	protected void createManifest(final String projectName, final Set<String> requiredBundles,
209
			final List<String> exportedPackages, final List<String> importedPackages, final String activatorClassName,
147
			final List<String> exportedPackages, final List<String> importedPackages, final String activatorClassName,
210
			final IProgressMonitor progressMonitor, final IProject project) throws CoreException {
148
			final IProgressMonitor progressMonitor, final IProject project) throws CoreException {
211
		final StringBuilder mainContent = new StringBuilder("Manifest-Version: 1.0\n");
149
		final StringBuilder mainContent = new StringBuilder("Manifest-Version: 1.0\n");
Lines 214-220 Link Here
214
		mainContent.append("Bundle-Vendor: My Company\n");
152
		mainContent.append("Bundle-Vendor: My Company\n");
215
		mainContent.append("Bundle-Version: 1.0.0\n");
153
		mainContent.append("Bundle-Version: 1.0.0\n");
216
		mainContent.append("Bundle-SymbolicName: " + projectName.toLowerCase() + "; singleton:=true\n");
154
		mainContent.append("Bundle-SymbolicName: " + projectName.toLowerCase() + "; singleton:=true\n");
217
//		mainContent.append("Bundle-RequiredExecutionEnvironment: J2SE-1.5\n");
218
		if (null != activatorClassName) {
155
		if (null != activatorClassName) {
219
			mainContent.append("Bundle-Activator: " + activatorClassName + "\n");
156
			mainContent.append("Bundle-Activator: " + activatorClassName + "\n");
220
		}
157
		}
Lines 261-310 Link Here
261
		}
198
		}
262
	}
199
	}
263
200
264
	/**
201
	protected void assertExist(final IContainer c) {
265
	 * @param name
266
	 *            of the destination file
267
	 * @param container
268
	 *            directory containing the the destination file
269
	 * @param contentUrl
270
	 *            Url pointing to the src of the content
271
	 * @param progressMonitor
272
	 *            used to interact with and show the user the current operation
273
	 *            status
274
	 * @return
275
	 */
276
	public static IFile createFile(final String name, final IContainer container, final URL contentUrl,
277
			final IProgressMonitor progressMonitor) {
278
		final IFile file = container.getFile(new Path(name));
279
		SubMonitor subMonitor = SubMonitor.convert(progressMonitor, 1);
280
		try {
281
			InputStream inputStream = null;
282
			try {
283
				inputStream = contentUrl.openStream();
284
				if (file.exists()) {
285
					file.setContents(inputStream, true, true, subMonitor.newChild(1));
286
				} else {
287
					file.create(inputStream, true, subMonitor.newChild(1));
288
				}
289
				inputStream.close();
290
			} catch (final Exception e) {
291
				logger.error(e);
292
			} finally {
293
				if (null != inputStream) {
294
					try {
295
						inputStream.close();
296
					} catch (final IOException e) {
297
						logger.error(e);
298
					}
299
				}
300
			}
301
		} finally {
302
			subMonitor.done();
303
		}
304
		return file;
305
	}
306
307
	private static void assertExist(final IContainer c) {
308
		if (!c.exists()) {
202
		if (!c.exists()) {
309
			if (!c.getParent().exists()) {
203
			if (!c.getParent().exists()) {
310
				assertExist(c.getParent());
204
				assertExist(c.getParent());
Lines 319-325 Link Here
319
		}
213
		}
320
	}
214
	}
321
215
322
	public static void openFileToEdit(final Shell s, final IFile file) {
216
	public void openFileToEdit(final Shell s, final IFile file) {
323
		s.getDisplay().asyncExec(new Runnable() {
217
		s.getDisplay().asyncExec(new Runnable() {
324
			public void run() {
218
			public void run() {
325
				final IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
219
				final IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
Lines 331-352 Link Here
331
			}
225
			}
332
		});
226
		});
333
	}
227
	}
334
335
	public static void createPackagesWithDummyClasses(IProject dslProject, String string, List<String> exportedPackages)
336
			throws CoreException {
337
		for (String string2 : exportedPackages) {
338
			IFolder folder = dslProject.getFolder(string + "/" + (string2.replace('.', '/')));
339
			create(folder);
340
			IFile file = folder.getFile("Foo.java");
341
			String contents = "package " + string2 + ";\nclass Foo {}";
342
			file.create(new ByteArrayInputStream(contents.getBytes()), true, null);
343
		}
344
	}
345
346
	private static void create(IFolder folder) throws CoreException {
347
		if (!folder.getParent().exists())
348
			create((IFolder) folder.getParent());
349
		folder.create(true, true, null);
350
	}
351
352
}
228
}
(-)src/org/eclipse/xtext/ui/util/JavaProjectConfigurator.java (+60 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2010 itemis AG (http://www.itemis.eu) 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
package org.eclipse.xtext.ui.util;
9
10
import java.util.ArrayList;
11
import java.util.List;
12
13
import org.apache.log4j.Logger;
14
import org.eclipse.core.resources.IFolder;
15
import org.eclipse.core.resources.IProject;
16
import org.eclipse.core.runtime.IProgressMonitor;
17
import org.eclipse.core.runtime.Path;
18
import org.eclipse.core.runtime.SubMonitor;
19
import org.eclipse.jdt.core.IClasspathEntry;
20
import org.eclipse.jdt.core.IJavaProject;
21
import org.eclipse.jdt.core.JavaCore;
22
import org.eclipse.jdt.core.JavaModelException;
23
24
/**
25
 * @author schill - Initial contribution and API
26
 */
27
public class JavaProjectConfigurator {
28
29
	private static final Logger logger = Logger.getLogger(JavaProjectConfigurator.class);
30
	
31
	public static void configureJavaProject(final IProject project, final List<String> srcFolders,
32
			final IProgressMonitor monitor) {
33
		SubMonitor subMonitor = SubMonitor.convert(monitor, 10);
34
		try {
35
			subMonitor.subTask("Configure javaProject " + project.getName());
36
			final IJavaProject javaProject = JavaCore.create(project);
37
			final List<IClasspathEntry> classpathEntries = new ArrayList<IClasspathEntry>();
38
			for (final IProject referencedProject : project.getReferencingProjects()) {
39
				final IClasspathEntry referencedProjectClasspathEntry = JavaCore.newProjectEntry(referencedProject
40
						.getFullPath());
41
				classpathEntries.add(referencedProjectClasspathEntry);
42
			}
43
			for (final String src : srcFolders) {
44
				final IFolder srcContainer = project.getFolder(src);
45
				final IClasspathEntry srcClasspathEntry = JavaCore.newSourceEntry(srcContainer.getFullPath());
46
				classpathEntries.add(srcClasspathEntry);
47
			}
48
49
			classpathEntries.add(JavaCore.newContainerEntry(new Path("org.eclipse.jdt.launching.JRE_CONTAINER")));
50
			classpathEntries.add(JavaCore.newContainerEntry(new Path("org.eclipse.pde.core.requiredPlugins")));
51
52
			javaProject.setRawClasspath(classpathEntries.toArray(new IClasspathEntry[classpathEntries.size()]),
53
					subMonitor.newChild(1));
54
			javaProject.setOutputLocation(new Path("/" + project.getName() + "/bin"), subMonitor.newChild(1));
55
		} catch (JavaModelException e) {
56
			e.printStackTrace();
57
			logger.error(e);
58
		}
59
	}
60
}
(-)src/org/eclipse/xtext/ui/util/ProjectCreatorDescription.java (+169 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2010 itemis AG (http://www.itemis.eu) 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
package org.eclipse.xtext.ui.util;
9
10
import java.util.List;
11
import java.util.Set;
12
13
import org.eclipse.core.resources.ICommand;
14
import org.eclipse.core.resources.IProject;
15
import org.eclipse.core.resources.IProjectDescription;
16
import org.eclipse.core.resources.ResourcesPlugin;
17
import org.eclipse.core.runtime.IPath;
18
import org.eclipse.core.runtime.Platform;
19
import org.eclipse.ui.IWorkbench;
20
import org.eclipse.ui.IWorkingSet;
21
22
import com.google.common.collect.Lists;
23
24
25
/**
26
 * @author schill - Initial contribution and API
27
 */
28
public class ProjectCreatorDescription {
29
30
	private String projectName;
31
	private IPath location;
32
	private List<String> sourceFolders;
33
	private List<IProject> referencedProjects;
34
	private Set<String> requiredBundles;
35
	private List<String> exportedPackages;
36
	private List<String> importedPackages;
37
	private String activatorClassName;
38
	private String[] projectNatures;
39
	private IWorkingSet[] workingSets;
40
	private IWorkbench workbench;
41
	private String[] builders;
42
43
	public String[] getBuilders() {
44
		return builders;
45
	}
46
47
	public void setBuilders(String[] builders) {
48
		this.builders = builders;
49
	}
50
51
	public String getProjectName() {
52
		return projectName;
53
	}
54
55
	public void setProjectName(String projectName) {
56
		this.projectName = projectName;
57
	}
58
59
	public IPath getLocation() {
60
		return location;
61
	}
62
63
	public void setLocation(IPath location) {
64
		this.location = location;
65
	}
66
67
	public List<String> getSourceFolders() {
68
		return sourceFolders;
69
	}
70
71
	public void setSourceFolders(List<String> sourceFolders) {
72
		this.sourceFolders = sourceFolders;
73
	}
74
75
	public List<IProject> getReferencedProjects() {
76
		return referencedProjects;
77
	}
78
79
	public void setReferencedProjects(List<IProject> referencedProjects) {
80
		this.referencedProjects = referencedProjects;
81
	}
82
83
	public Set<String> getRequiredBundles() {
84
		return requiredBundles;
85
	}
86
87
	public void setRequiredBundles(Set<String> requiredBundles) {
88
		this.requiredBundles = requiredBundles;
89
	}
90
91
	public List<String> getExportedPackages() {
92
		return exportedPackages;
93
	}
94
95
	public void setExportedPackages(List<String> exportedPackages) {
96
		this.exportedPackages = exportedPackages;
97
	}
98
99
	public List<String> getImportedPackages() {
100
		return importedPackages;
101
	}
102
103
	public void setImportedPackages(List<String> importedPackages) {
104
		this.importedPackages = importedPackages;
105
	}
106
107
	public String getActivatorClassName() {
108
		return activatorClassName;
109
	}
110
111
	public void setActivatorClassName(String activatorClassName) {
112
		this.activatorClassName = activatorClassName;
113
	}
114
115
	public String[] getProjectNatures() {
116
		return projectNatures;
117
	}
118
119
	public void setProjectNatures(String[] projectNatures) {
120
		this.projectNatures = projectNatures;
121
	}
122
123
	public IWorkingSet[] getWorkingSets() {
124
		return workingSets;
125
	}
126
127
	public void setWorkingSets(IWorkingSet[] workingSets) {
128
		this.workingSets = workingSets;
129
	}
130
131
	public IWorkbench getWorkbench() {
132
		return workbench;
133
	}
134
135
	public void setWorkbench(IWorkbench workbench) {
136
		this.workbench = workbench;
137
	}
138
139
	/**
140
	 * Creates an IProjectDescription out of the given informations
141
	 * 
142
	 * @return {@link IProjectDescription}
143
	 */
144
	public IProjectDescription createProjectDescription() {
145
		final IProjectDescription projectDescription = ResourcesPlugin.getWorkspace()
146
				.newProjectDescription(projectName);
147
		if (location != null && !Platform.getLocation().equals(location.removeLastSegments(1))) {
148
			projectDescription.setLocation(location);
149
		}
150
151
		if (referencedProjects.size() != 0) {
152
			projectDescription.setReferencedProjects(referencedProjects
153
					.toArray(new IProject[referencedProjects.size()]));
154
		}
155
		projectDescription.setNatureIds(projectNatures);
156
		setBuilder(projectDescription, builders);
157
		return projectDescription;
158
	}
159
160
	protected void setBuilder(final IProjectDescription projectDescription, final String[] builders) {
161
		List<ICommand> commands = Lists.newArrayList();
162
		for (int i = 0; i < builders.length; i++) {
163
			ICommand command = projectDescription.newCommand();
164
			command.setBuilderName(builders[i]);
165
			commands.add(command);
166
		}
167
		projectDescription.setBuildSpec(commands.toArray(new ICommand[commands.size()]));
168
	}
169
}
(-)src/org/eclipse/xtext/ui/wizard/AbstractProjectCreator.java (+61 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2009 itemis AG (http://www.itemis.eu) 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
 *******************************************************************************/
9
package org.eclipse.xtext.ui.wizard;
10
11
import java.lang.reflect.InvocationTargetException;
12
import java.util.List;
13
14
import org.eclipse.core.resources.IFile;
15
import org.eclipse.core.resources.IProject;
16
import org.eclipse.core.resources.ResourcesPlugin;
17
import org.eclipse.core.runtime.CoreException;
18
import org.eclipse.core.runtime.IProgressMonitor;
19
import org.eclipse.ui.actions.WorkspaceModifyOperation;
20
21
/**
22
 * @author Peter Friese - Initial contribution and API
23
 */
24
public abstract class AbstractProjectCreator extends WorkspaceModifyOperation implements IProjectCreator {
25
	
26
	private IFile result;
27
	private IProjectInfo projectInfo;
28
29
	public IFile getResult() {
30
		return result;
31
	}
32
	
33
	protected void setResult(IFile result) {
34
		this.result = result;
35
	}
36
	
37
	public void setProjectInfo(IProjectInfo projectInfo) {
38
		this.projectInfo = projectInfo;
39
	}
40
	
41
	protected IProjectInfo getProjectInfo() {
42
		return projectInfo;
43
	}
44
	
45
	@Override
46
	protected void execute(IProgressMonitor monitor) throws CoreException, InvocationTargetException,
47
			InterruptedException {
48
49
	}
50
51
	protected String getEncoding() throws CoreException {
52
		return ResourcesPlugin.getWorkspace().getRoot().getDefaultCharset();
53
	}
54
	/**
55
	 * Method to configure a project e.g. an IJavaProject's classpath
56
	 * @param project  IProject to configure
57
	 * @param srcFolders List of sourceFolders e.g. to configure the classpath of an IJavaProject
58
	 */
59
	protected abstract void configureProject(IProject project, List<String> srcFolders, IProgressMonitor monitor); 
60
61
}
(-)src/org/eclipse/xtext/ui/wizard/DefaultProjectCreator.java (-53 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2009 itemis AG (http://www.itemis.eu) 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
 *******************************************************************************/
9
package org.eclipse.xtext.ui.wizard;
10
11
import java.lang.reflect.InvocationTargetException;
12
13
import org.eclipse.core.resources.IFile;
14
import org.eclipse.core.resources.ResourcesPlugin;
15
import org.eclipse.core.runtime.CoreException;
16
import org.eclipse.core.runtime.IProgressMonitor;
17
import org.eclipse.ui.actions.WorkspaceModifyOperation;
18
19
/**
20
 * @author Peter Friese - Initial contribution and API
21
 */
22
public class DefaultProjectCreator extends WorkspaceModifyOperation implements IProjectCreator {
23
	
24
	private IFile result;
25
	private IProjectInfo projectInfo;
26
27
	public IFile getResult() {
28
		return result;
29
	}
30
	
31
	protected void setResult(IFile result) {
32
		this.result = result;
33
	}
34
	
35
	public void setProjectInfo(IProjectInfo projectInfo) {
36
		this.projectInfo = projectInfo;
37
	}
38
	
39
	protected IProjectInfo getProjectInfo() {
40
		return projectInfo;
41
	}
42
	
43
	@Override
44
	protected void execute(IProgressMonitor monitor) throws CoreException, InvocationTargetException,
45
			InterruptedException {
46
47
	}
48
49
	protected String getEncoding() throws CoreException {
50
		return ResourcesPlugin.getWorkspace().getRoot().getDefaultCharset();
51
	}
52
53
}
(-)src/org/eclipse/xtext/ui/wizard/XtextNewProjectWizard.java (-1 / +7 lines)
Lines 20-25 Link Here
20
import org.eclipse.ui.IWorkbench;
20
import org.eclipse.ui.IWorkbench;
21
import org.eclipse.xtext.ui.util.EclipseResourceUtil;
21
import org.eclipse.xtext.ui.util.EclipseResourceUtil;
22
22
23
import com.google.inject.Inject;
24
import com.google.inject.Provider;
25
23
/**
26
/**
24
 * @author Peter Friese - Initial contribution and API
27
 * @author Peter Friese - Initial contribution and API
25
 */
28
 */
Lines 29-34 Link Here
29
32
30
	protected IStructuredSelection selection;
33
	protected IStructuredSelection selection;
31
34
35
	@Inject
36
	private Provider<EclipseResourceUtil> eclipseResourceUtilProvider;
37
	
32
	public XtextNewProjectWizard(IProjectCreator creator) {
38
	public XtextNewProjectWizard(IProjectCreator creator) {
33
		this.creator = creator;
39
		this.creator = creator;
34
		setNeedsProgressMonitor(true);
40
		setNeedsProgressMonitor(true);
Lines 75-81 Link Here
75
		try {
81
		try {
76
			creator.setProjectInfo(projectInfo);
82
			creator.setProjectInfo(projectInfo);
77
			creator.run(monitor);
83
			creator.run(monitor);
78
			EclipseResourceUtil.openFileToEdit(getShell(), creator.getResult());
84
			eclipseResourceUtilProvider.get().openFileToEdit(getShell(), creator.getResult());
79
		}
85
		}
80
		catch (final InvocationTargetException e) {
86
		catch (final InvocationTargetException e) {
81
			logger.error(e.getMessage(), e);
87
			logger.error(e.getMessage(), e);
(-)src/org/eclipse/xtext/ui/shared/internal/SharedModule.java (+3 lines)
Lines 27-34 Link Here
27
import org.eclipse.xtext.ui.editor.IDirtyStateManager;
27
import org.eclipse.xtext.ui.editor.IDirtyStateManager;
28
import org.eclipse.xtext.ui.notification.IStateChangeEventBroker;
28
import org.eclipse.xtext.ui.notification.IStateChangeEventBroker;
29
import org.eclipse.xtext.ui.notification.StateChangeEventBroker;
29
import org.eclipse.xtext.ui.notification.StateChangeEventBroker;
30
import org.eclipse.xtext.ui.resource.IResourceSetProvider;
30
import org.eclipse.xtext.ui.resource.IStorage2UriMapper;
31
import org.eclipse.xtext.ui.resource.IStorage2UriMapper;
31
import org.eclipse.xtext.ui.resource.Storage2UriMapperImpl;
32
import org.eclipse.xtext.ui.resource.Storage2UriMapperImpl;
33
import org.eclipse.xtext.ui.resource.SimpleResourceSetProvider;
32
34
33
import com.google.inject.AbstractModule;
35
import com.google.inject.AbstractModule;
34
import com.google.inject.Provider;
36
import com.google.inject.Provider;
Lines 45-50 Link Here
45
		bind(IBuilderState.class).to(PersistableResourceDescriptionsImpl.class).in(Scopes.SINGLETON);
47
		bind(IBuilderState.class).to(PersistableResourceDescriptionsImpl.class).in(Scopes.SINGLETON);
46
		bind(IResourceDescriptions.class).to(DirtyStateAwareResourceDescriptions.class).in(Scopes.SINGLETON);
48
		bind(IResourceDescriptions.class).to(DirtyStateAwareResourceDescriptions.class).in(Scopes.SINGLETON);
47
		bind(IResourceServiceProvider.Registry.class).toInstance(IResourceServiceProvider.Registry.INSTANCE);
49
		bind(IResourceServiceProvider.Registry.class).toInstance(IResourceServiceProvider.Registry.INSTANCE);
50
		bind(IResourceSetProvider.class).to(SimpleResourceSetProvider.class);
48
		bind(IExtensionRegistry.class).toInstance(Platform.getExtensionRegistry());
51
		bind(IExtensionRegistry.class).toInstance(Platform.getExtensionRegistry());
49
		bind(IResourceChangeListener.class).annotatedWith(Names.named(ProjectOpenedOrClosedListener.class.getName())).to(ProjectOpenedOrClosedListener.class);
52
		bind(IResourceChangeListener.class).annotatedWith(Names.named(ProjectOpenedOrClosedListener.class.getName())).to(ProjectOpenedOrClosedListener.class);
50
		
53
		
(-)src/org/eclipse/xtext/ui/shared/internal/SharedModuleWithJdt.java (+3 lines)
Lines 10-17 Link Here
10
import org.eclipse.xtext.builder.impl.ToBeBuiltComputer;
10
import org.eclipse.xtext.builder.impl.ToBeBuiltComputer;
11
import org.eclipse.xtext.builder.impl.javasupport.ElementChangeListener;
11
import org.eclipse.xtext.builder.impl.javasupport.ElementChangeListener;
12
import org.eclipse.xtext.builder.impl.javasupport.JdtToBeBuiltComputer;
12
import org.eclipse.xtext.builder.impl.javasupport.JdtToBeBuiltComputer;
13
import org.eclipse.xtext.ui.resource.IResourceSetProvider;
13
import org.eclipse.xtext.ui.resource.IStorage2UriMapper;
14
import org.eclipse.xtext.ui.resource.IStorage2UriMapper;
14
import org.eclipse.xtext.ui.resource.Storage2UriMapperJavaImpl;
15
import org.eclipse.xtext.ui.resource.Storage2UriMapperJavaImpl;
16
import org.eclipse.xtext.ui.resource.XtextResourceSetProvider;
15
17
16
import com.google.inject.AbstractModule;
18
import com.google.inject.AbstractModule;
17
19
Lines 26-31 Link Here
26
		bind(ToBeBuiltComputer.class).to(JdtToBeBuiltComputer.class);
28
		bind(ToBeBuiltComputer.class).to(JdtToBeBuiltComputer.class);
27
		bind(ElementChangeListener.class).asEagerSingleton();
29
		bind(ElementChangeListener.class).asEagerSingleton();
28
		bind(IStorage2UriMapper.class).to(Storage2UriMapperJavaImpl.class);
30
		bind(IStorage2UriMapper.class).to(Storage2UriMapperJavaImpl.class);
31
		bind(IResourceSetProvider.class).to(XtextResourceSetProvider.class);
29
	}
32
	}
30
33
31
}
34
}
(-)src/org/eclipse/xtext/xtext/ui/wizard/project/XtextProjectCreator.java (-28 / +61 lines)
Lines 14-27 Link Here
14
import java.util.Collections;
14
import java.util.Collections;
15
import java.util.LinkedHashSet;
15
import java.util.LinkedHashSet;
16
import java.util.List;
16
import java.util.List;
17
import java.util.Set;
18
17
19
import org.eclipse.core.resources.IFile;
18
import org.eclipse.core.resources.IFile;
20
import org.eclipse.core.resources.IFolder;
19
import org.eclipse.core.resources.IFolder;
21
import org.eclipse.core.resources.IProject;
20
import org.eclipse.core.resources.IProject;
22
import org.eclipse.core.resources.IResource;
21
import org.eclipse.core.resources.IResource;
23
import org.eclipse.core.runtime.CoreException;
22
import org.eclipse.core.runtime.CoreException;
24
import org.eclipse.core.runtime.IPath;
25
import org.eclipse.core.runtime.IProgressMonitor;
23
import org.eclipse.core.runtime.IProgressMonitor;
26
import org.eclipse.core.runtime.Path;
24
import org.eclipse.core.runtime.Path;
27
import org.eclipse.core.runtime.SubMonitor;
25
import org.eclipse.core.runtime.SubMonitor;
Lines 35-49 Link Here
35
import org.eclipse.xtend.type.impl.java.JavaBeansMetaModel;
33
import org.eclipse.xtend.type.impl.java.JavaBeansMetaModel;
36
import org.eclipse.xtext.ui.XtextProjectHelper;
34
import org.eclipse.xtext.ui.XtextProjectHelper;
37
import org.eclipse.xtext.ui.util.EclipseResourceUtil;
35
import org.eclipse.xtext.ui.util.EclipseResourceUtil;
38
import org.eclipse.xtext.ui.wizard.DefaultProjectCreator;
36
import org.eclipse.xtext.ui.util.JavaProjectConfigurator;
37
import org.eclipse.xtext.ui.util.ProjectCreatorDescription;
38
import org.eclipse.xtext.ui.wizard.AbstractProjectCreator;
39
40
import com.google.inject.Inject;
41
import com.google.inject.Provider;
39
42
40
/**
43
/**
41
 * XtextProjectCreator handles the actual creation of the new Xtext project.
44
 * XtextProjectCreator handles the actual creation of the new Xtext project.
42
 * 
45
 * 
43
 * @author Michael Clay - Initial contribution and API
46
 * @author Michael Clay - Initial contribution and API
44
 */
47
 */
45
public class XtextProjectCreator extends DefaultProjectCreator {
48
public class XtextProjectCreator extends AbstractProjectCreator {
46
49
50
	@Inject
51
	private Provider<EclipseResourceUtil> eclipseResourceUtilProvider;
52
	
47
	private static final String[] DSL_PROJECT_NATURES = new String[] { 
53
	private static final String[] DSL_PROJECT_NATURES = new String[] { 
48
			JavaCore.NATURE_ID,
54
			JavaCore.NATURE_ID,
49
			"org.eclipse.pde.PluginNature", //$NON-NLS-1$
55
			"org.eclipse.pde.PluginNature", //$NON-NLS-1$
Lines 54-59 Link Here
54
			JavaCore.NATURE_ID,
60
			JavaCore.NATURE_ID,
55
			"org.eclipse.pde.PluginNature" //$NON-NLS-1$
61
			"org.eclipse.pde.PluginNature" //$NON-NLS-1$
56
	};
62
	};
63
	
64
	private static final String[] BUILDERS = new String[]{
65
		JavaCore.BUILDER_ID, "org.eclipse.pde.ManifestBuilder", "org.eclipse.pde.SchemaBuilder"
66
	};
57
67
58
	private static final String[] GENERATOR_PROJECT_NATURES = DSL_UI_PROJECT_NATURES;
68
	private static final String[] GENERATOR_PROJECT_NATURES = DSL_UI_PROJECT_NATURES;
59
69
Lines 88-98 Link Here
88
		BasicNewResourceWizard.selectAndReveal(dslGrammarFile, PlatformUI.getWorkbench().getActiveWorkbenchWindow());
98
		BasicNewResourceWizard.selectAndReveal(dslGrammarFile, PlatformUI.getWorkbench().getActiveWorkbenchWindow());
89
		setResult(dslGrammarFile);
99
		setResult(dslGrammarFile);
90
	}
100
	}
101
	
102
	@Override
103
	protected void configureProject(IProject project, List<String> srcFolders, IProgressMonitor monitor) {
104
		JavaProjectConfigurator.configureJavaProject(project, srcFolders, monitor);
105
	}
91
106
92
	private IProject createDslUiProject(final IProgressMonitor monitor) throws CoreException {
107
	private IProject createDslUiProject(final IProgressMonitor monitor) throws CoreException {
93
		
94
		String projectName = getXtextProjectInfo().getUiProjectName();
95
96
		LinkedHashSet<String> requiredBundles = new LinkedHashSet<String>(Arrays.asList(getXtextProjectInfo()
108
		LinkedHashSet<String> requiredBundles = new LinkedHashSet<String>(Arrays.asList(getXtextProjectInfo()
97
				.getProjectName().toLowerCase()
109
				.getProjectName().toLowerCase()
98
				+ ";visibility:=reexport", //$NON-NLS-1$
110
				+ ";visibility:=reexport", //$NON-NLS-1$
Lines 100-112 Link Here
100
				"org.eclipse.ui.editors;bundle-version=\"3.5.0\"", //$NON-NLS-1$
112
				"org.eclipse.ui.editors;bundle-version=\"3.5.0\"", //$NON-NLS-1$
101
				"org.eclipse.ui.ide;bundle-version=\"3.5.0\"")); //$NON-NLS-1$
113
				"org.eclipse.ui.ide;bundle-version=\"3.5.0\"")); //$NON-NLS-1$
102
114
103
		return createProject(getXtextProjectInfo(), getXtextProjectInfo().getUiProjectLocation(), projectName, DSL_UI_PROJECT_NATURES, requiredBundles, 
115
		ProjectCreatorDescription creatorDescription = new ProjectCreatorDescription();
104
				Collections.singletonList("org.apache.log4j"), SRC_FOLDER_LIST, getDslUiProjectTemplateName(), monitor);
116
		creatorDescription.setWorkbench(getXtextProjectInfo().getWorkbench());
117
		creatorDescription.setWorkingSets(getXtextProjectInfo().getWorkingSets());
118
		creatorDescription.setLocation(getXtextProjectInfo().getUiProjectLocation());
119
		creatorDescription.setProjectName(getXtextProjectInfo().getUiProjectName());
120
		creatorDescription.setProjectNatures(DSL_UI_PROJECT_NATURES);
121
		creatorDescription.setBuilders(BUILDERS);
122
		creatorDescription.setRequiredBundles(requiredBundles);
123
		creatorDescription.setImportedPackages(Collections.singletonList("org.apache.log4j"));//$NON-NLS-1$
124
		creatorDescription.setSourceFolders(SRC_FOLDER_LIST);
125
		
126
		return createProject(creatorDescription, getDslUiProjectTemplateName(), monitor);
105
	}
127
	}
106
128
107
	private IProject createDslProject(final IProgressMonitor monitor) throws CoreException {
129
	private IProject createDslProject(final IProgressMonitor monitor) throws CoreException {
108
		String projectName = getXtextProjectInfo().getProjectName();
109
110
		LinkedHashSet<String> requiredBundles = new LinkedHashSet<String>(Arrays.asList("org.eclipse.xtext", //$NON-NLS-1$
130
		LinkedHashSet<String> requiredBundles = new LinkedHashSet<String>(Arrays.asList("org.eclipse.xtext", //$NON-NLS-1$
111
				"org.eclipse.xtext.generator;resolution:=optional", //$NON-NLS-1$
131
				"org.eclipse.xtext.generator;resolution:=optional", //$NON-NLS-1$
112
				"de.itemis.xtext.antlr;resolution:=optional", //$NON-NLS-1$
132
				"de.itemis.xtext.antlr;resolution:=optional", //$NON-NLS-1$
Lines 124-137 Link Here
124
		for(String bundleId: getAdditionalRequiredBundles()) {
144
		for(String bundleId: getAdditionalRequiredBundles()) {
125
			requiredBundles.add(bundleId.trim());
145
			requiredBundles.add(bundleId.trim());
126
		}
146
		}
147
		
148
		ProjectCreatorDescription creatorDescription = new ProjectCreatorDescription();
149
		creatorDescription.setWorkbench(getXtextProjectInfo().getWorkbench());
150
		creatorDescription.setWorkingSets(getXtextProjectInfo().getWorkingSets());
151
		creatorDescription.setLocation(getXtextProjectInfo().getProjectLocation());
152
		creatorDescription.setProjectName(getXtextProjectInfo().getProjectName());
153
		creatorDescription.setProjectNatures(DSL_PROJECT_NATURES);
154
		creatorDescription.setBuilders(BUILDERS);
155
		creatorDescription.setRequiredBundles(requiredBundles);
156
		creatorDescription.setImportedPackages(Collections.singletonList("org.apache.log4j"));//$NON-NLS-1$
157
		creatorDescription.setSourceFolders(SRC_FOLDER_LIST);
127
158
128
		return createProject(getXtextProjectInfo(), getXtextProjectInfo().getProjectLocation(), projectName, DSL_PROJECT_NATURES, requiredBundles, 
159
		return createProject(creatorDescription, getDslProjectTemplateName(), monitor);
129
				Collections.singletonList("org.apache.log4j"), SRC_FOLDER_LIST, getDslProjectTemplateName(), monitor);
130
	}
160
	}
131
161
132
	private IProject createGeneratorProject(final IProgressMonitor monitor) throws CoreException {
162
	private IProject createGeneratorProject(final IProgressMonitor monitor) throws CoreException {
133
		String projectName = getXtextProjectInfo().getGeneratorProjectName();
134
135
		LinkedHashSet<String> requiredBundles = new LinkedHashSet<String>(Arrays.asList(getXtextProjectInfo()
163
		LinkedHashSet<String> requiredBundles = new LinkedHashSet<String>(Arrays.asList(getXtextProjectInfo()
136
				.getProjectName().toLowerCase()
164
				.getProjectName().toLowerCase()
137
				+ ";visibility:=reexport", "org.eclipse.xpand;visibility:=reexport", //$NON-NLS-1$
165
				+ ";visibility:=reexport", "org.eclipse.xpand;visibility:=reexport", //$NON-NLS-1$
Lines 140-163 Link Here
140
				"org.eclipse.emf.mwe2.launch;resolution:=optional", //$NON-NLS-1$
168
				"org.eclipse.emf.mwe2.launch;resolution:=optional", //$NON-NLS-1$
141
				"org.eclipse.emf.mwe.utils;visibility:=reexport",//$NON-NLS-1$
169
				"org.eclipse.emf.mwe.utils;visibility:=reexport",//$NON-NLS-1$
142
				"org.eclipse.xtend.typesystem.emf;visibility:=reexport")); //$NON-NLS-1$
170
				"org.eclipse.xtend.typesystem.emf;visibility:=reexport")); //$NON-NLS-1$
143
171
		ProjectCreatorDescription creatorDescription = new ProjectCreatorDescription();
144
		return createProject(getXtextProjectInfo(), getXtextProjectInfo().getGeneratorProjectLocation(), projectName, GENERATOR_PROJECT_NATURES, requiredBundles,
172
		creatorDescription.setWorkbench(getXtextProjectInfo().getWorkbench());
145
				Collections.singletonList("org.apache.log4j"), SRC_FOLDER_LIST, getGeneratorProjectTemplateName(), monitor);
173
		creatorDescription.setWorkingSets(getXtextProjectInfo().getWorkingSets());
174
		creatorDescription.setLocation(getXtextProjectInfo().getGeneratorProjectLocation());
175
		creatorDescription.setProjectName(getXtextProjectInfo().getGeneratorProjectName());
176
		creatorDescription.setProjectNatures(GENERATOR_PROJECT_NATURES);
177
		creatorDescription.setBuilders(BUILDERS);
178
		creatorDescription.setRequiredBundles(requiredBundles);
179
		creatorDescription.setImportedPackages(Collections.singletonList("org.apache.log4j"));//$NON-NLS-1$
180
		creatorDescription.setSourceFolders(SRC_FOLDER_LIST);
181
		return createProject(creatorDescription, getGeneratorProjectTemplateName(), monitor);
146
	}
182
	}
147
183
148
	private IProject createProject(XtextProjectInfo xtextProjectInfo, IPath projectLocation, String projectName, String[] projectNatures,
184
	private IProject createProject(ProjectCreatorDescription creatorDescription, String templateName,
149
			Set<String> requiredBundles, List<String> importPackages, List<String> srcFolderList, String templateName,
150
			final IProgressMonitor monitor) throws CoreException {
185
			final IProgressMonitor monitor) throws CoreException {
151
		monitor.beginTask(Messages.XtextProjectCreator_CreatingProjectsMessage + projectName, 3);
186
		monitor.beginTask(Messages.XtextProjectCreator_CreatingProjectsMessage + creatorDescription.getProjectName(), 3);
152
		final IProject dslProject = EclipseResourceUtil.createProject(projectName, projectLocation,
187
		creatorDescription.setReferencedProjects( Collections.<IProject> emptyList());
153
				srcFolderList, Collections.<IProject> emptyList(), requiredBundles, null, importPackages, null,
188
		final IProject dslProject = eclipseResourceUtilProvider.get().createProject(creatorDescription, monitor, null);
154
				monitor, null, projectNatures, xtextProjectInfo.getWorkingSets(), xtextProjectInfo.getWorkbench());
155
189
156
		if (dslProject == null) {
190
		if (dslProject == null) {
157
			return null;
191
			return null;
158
		}
192
		}
159
193
160
		IFolder srcFolder = (IFolder) dslProject.findMember(srcFolderList.get(0));
194
		IFolder srcFolder = (IFolder) dslProject.findMember(creatorDescription.getSourceFolders().get(0));
161
195
162
		OutputImpl output = new OutputImpl();
196
		OutputImpl output = new OutputImpl();
163
		output.addOutlet(new Outlet(false, getEncoding(), null, true, srcFolder.getLocation().makeAbsolute()
197
		output.addOutlet(new Outlet(false, getEncoding(), null, true, srcFolder.getLocation().makeAbsolute()
Lines 169-175 Link Here
169
203
170
		// generate generator and activator for dsl and dsl.ui project
204
		// generate generator and activator for dsl and dsl.ui project
171
		XpandFacade facade = XpandFacade.create(execCtx);
205
		XpandFacade facade = XpandFacade.create(execCtx);
172
		facade.evaluate(templateName, xtextProjectInfo);
206
		facade.evaluate(templateName, getXtextProjectInfo());
173
207
174
		monitor.worked(1);
208
		monitor.worked(1);
175
209
Lines 177-183 Link Here
177
		dslProject.refreshLocal(IResource.DEPTH_INFINITE, monitor);
211
		dslProject.refreshLocal(IResource.DEPTH_INFINITE, monitor);
178
212
179
		monitor.worked(1);
213
		monitor.worked(1);
180
214
		configureProject(dslProject, creatorDescription.getSourceFolders(), monitor);
181
		return dslProject;
215
		return dslProject;
182
	}
216
	}
183
217
Lines 200-204 Link Here
200
	protected Collection<String> getAdditionalRequiredBundles() {
234
	protected Collection<String> getAdditionalRequiredBundles() {
201
		return Collections.emptyList();
235
		return Collections.emptyList();
202
	}
236
	}
203
204
}
237
}

Return to bug 301606