Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (c) 2010 itemis AG (http://www.itemis.eu) and others. All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse Public License v1.0 which accompanies this distribution, and is available at http://www.eclipse.org/legal/epl-v10.html /
  
  package org.eclipse.xtext.ui.util;
  
 import java.util.List;
 
 import  org.eclipse.core.resources.IFolder;
 import  org.eclipse.core.resources.IProject;
 import  org.eclipse.core.runtime.CoreException;
 import  org.eclipse.core.runtime.IPath;
 import  org.eclipse.core.runtime.IProgressMonitor;
 import  org.eclipse.core.runtime.Path;
 import  org.eclipse.core.runtime.SubMonitor;
 import  org.eclipse.jdt.core.IClasspathEntry;
 import  org.eclipse.jdt.core.JavaCore;
 import  org.eclipse.swt.widgets.Shell;
 import  org.eclipse.ui.IWorkingSet;
 

Author(s):
Sebastian Zarnekow - Initial contribution and API
 
 public class PluginProjectFactory extends JavaProjectFactory {
 
 	protected List<StringrequiredBundles;
 	protected List<StringexportedPackages;
 	protected List<StringimportedPackages;
 	protected String activatorClassName;

Since:
2.8
 
 	private String breeToUse;
 
 	public PluginProjectFactory addRequiredBundles(List<StringrequiredBundles) {
 		if (this. == null)
 			this. = Lists.newArrayList();
 		this..addAll(requiredBundles);
 		return this;
 	}
 
 	public PluginProjectFactory addExportedPackages(List<StringexportedPackages) {
 		if (this. == null)
 			this. = Lists.newArrayList();
 		this..addAll(exportedPackages);
 		return this;
 	}
 
 	public PluginProjectFactory addImportedPackages(List<StringimportedPackages) {
 		if (this. == null)
 			this. = Lists.newArrayList();
 		this..addAll(importedPackages);
 		return this;
 	}
 
 	public PluginProjectFactory setActivatorClassName(String activatorClassName) {
 		this. = activatorClassName;
 		return this;
 	}
 
 	protected void enhanceProject(IProject project, SubMonitor subMonitor, Shell shellthrows CoreException {
 		super.enhanceProject(projectsubMonitorshell);
 		if ( != null && .contains("org.eclipse.pde.PluginNature")) {
 			createManifest(projectsubMonitor.newChild(1));
 			createBuildProperties(projectsubMonitor.newChild(1));
 		}
 	}
 
 	protected void addMoreClasspathEntriesTo(List<IClasspathEntry> classpathEntries) {
 		super.addMoreClasspathEntriesTo(classpathEntries);
 		classpathEntries.add(JavaCore.newContainerEntry(new Path("org.eclipse.pde.core.requiredPlugins"))); //$NON-NLS-1$
 	}
 
 	protected void createBuildProperties(IProject project, IProgressMonitor progressMonitor) {
 		final StringBuilder content = new StringBuilder();
 		Iterable<StringfoldersTrailingSlash = Iterables.transform(new Function<StringString>() {
 			public String apply(String input) {
 				return input + "/";
 			}
 		});
 
 		addToBuildProperties(contentfoldersTrailingSlash"source..");
 		content.append("\n");
 		addToBuildProperties(content, Lists.newArrayList("META-INF/"".""plugin.xml"), "bin.includes");
 		content.append("\n");
 		addToBuildProperties(content"additional.bundles");
		createFile("build.properties"projectcontent.toString(), progressMonitor);
	}
	protected void createManifest(IProject project, IProgressMonitor progressMonitorthrows CoreException {
		final StringBuilder content = new StringBuilder("Manifest-Version: 1.0\n");
		content.append("Bundle-ManifestVersion: 2\n");
		content.append("Bundle-Name: " +  + "\n");
		content.append("Bundle-Vendor: My Company\n");
		content.append("Bundle-Version: 1.0.0.qualifier\n");
		content.append("Bundle-SymbolicName: " +  + "; singleton:=true\n");
		if (null != ) {
			content.append("Bundle-Activator: " +  + "\n");
		}
		content.append("Bundle-ActivationPolicy: lazy\n");
		addToContent(content"Require-Bundle");
		addToContent(content"Export-Package");
		addToContent(content"Import-Package");
		content.append("Bundle-RequiredExecutionEnvironment: ");
		content.append(getBreeToUse() + "\n");
		final IFolder metaInf = project.getFolder("META-INF");
		SubMonitor subMonitor = SubMonitor.convert(progressMonitor, 2);
		try {
			if (metaInf.exists())
				metaInf.delete(falseprogressMonitor);
			metaInf.create(falsetruesubMonitor.newChild(1));
			createFile("MANIFEST.MF"metaInfcontent.toString(), subMonitor.newChild(1));
finally {
			subMonitor.done();
		}
	}
	private String getBreeToUse() {
		if ( == null) {
			return JREContainerProvider.getDefaultBREE();
		}
		return ;
	}

Use this method to set the Bundle-RequiredExecutionEnvironment (BREE).
If not set, the compatible system default will be used.

Parameters:
breeToUse - BREE to use (e.g. JavaSE-1.6)
Since:
2.7
See also:
JREContainerProvider.getDefaultBREE()
	public void setBreeToUse(String breeToUse) {
		this. = breeToUse;
	}
	protected void addToContent(final StringBuilder contentList<StringentriesString prefix) {
		if (entries != null && !entries.isEmpty()) {
			content.append(prefix).append(": ").append(entries.get(0));
			for (int i = 1, x = entries.size(); i < xi++) {
				content.append(",\n ").append(entries.get(i));
			}
			content.append("\n");
		}
	}

Since:
2.8
	protected void addToBuildProperties(StringBuilder contentIterable<StringentriesString entryName) {
		if (entries != null && !Iterables.isEmpty(entries)) {
			String assigment = entryName + " = ";
			String indent = Strings.repeat(" "assigment.length());
			content.append(assigment);
			for (final Iterator<Stringiterator = entries.iterator(); iterator.hasNext();) {
				content.append(iterator.next());
				if (iterator.hasNext()) {
					content.append(",\\\n");
					content.append(indent);
				}
			}
		}
	}
	public PluginProjectFactory addBuilderIds(String... builderIds) {
		return (PluginProjectFactorysuper.addBuilderIds(builderIds);
	}
		return (PluginProjectFactorysuper.addFolders(folders);
	}
	public PluginProjectFactory setProjectName(String projectName) {
		return (PluginProjectFactorysuper.setProjectName(projectName);
	}
	public PluginProjectFactory addProjectNatures(String... projectNatures) {
		return (PluginProjectFactorysuper.addProjectNatures(projectNatures);
	}
	public PluginProjectFactory addReferencedProjects(List<IProject> referencedProjects) {
		return (PluginProjectFactorysuper.addReferencedProjects(referencedProjects);
	}
	public PluginProjectFactory setLocation(IPath location) {
		return (PluginProjectFactorysuper.setLocation(location);
	}
	public PluginProjectFactory addWorkingSets(List<IWorkingSet> workingSets) {
		return (PluginProjectFactorysuper.addWorkingSets(workingSets);
	}

Since:
2.8
		if (this. == null)
		this..addAll(devTimeBundles);
		return this;
	}
New to GrepCode? Check out our FAQ X