blob: 4a2b2d2a0f24cd9906d6842c5febb43031e37db7 [file] [log] [blame]
/**
*
* Copyright (c) 2011, 2016 - Loetz GmbH&Co.KG (69115 Heidelberg, Germany)
*
* 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
*
* Contributors:
* Christophe Loetz (Loetz GmbH&Co.KG) - initial implementation
*/
package org.eclipse.osbp.wizard.ui.basic;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.SubMonitor;
import org.eclipse.core.runtime.jobs.ISchedulingRule;
import org.eclipse.xtext.ui.util.JREContainerProvider;
import org.eclipse.xtext.ui.util.PluginProjectFactory;
public abstract class BasicProjectFactory extends PluginProjectFactory {
private final String BREE_PREFIX = "JavaSE-";
public BasicProjectFactory() {
super();
setDefaultOutput("target/classes");
}
protected BasicProjectInfo projectInfo;
protected final String getBreeToUse() {
return BREE_PREFIX+projectInfo.bree_version; // JREContainerProvider.getDefaultBREE();
}
/**
* Use this method to set the Bundle-RequiredExecutionEnvironment (BREE).<br>
* If not set, the compatible system default will be used.
* @see JREContainerProvider#getDefaultBREE()
* @param breeToUse - BREE to use (e.g. JavaSE-1.6)
* @since 2.7
*/
public final void setBreeToUse(String breeToUse) {
double breeVersion = 0.0;
try {
breeVersion = Double.parseDouble(breeToUse.replace(BREE_PREFIX, ""));
}
catch (Exception e) {
}
if (breeVersion >= BasicProjectInfo.BREE_MINIMUM) {
projectInfo.bree_version = BasicProjectInfo.BREE_MINIMUM;
}
}
public final void configureFrom(BasicProjectInfo projectInfo) {
this.projectInfo = projectInfo;
}
protected String getBundleName() {
return projectInfo.getThisProjectName();
}
protected String getBundleSymbolicName() {
return projectInfo.getThisSymbolicName();
}
@Override
protected final void createManifest(IProject project, IProgressMonitor progressMonitor) throws CoreException {
final StringBuilder content = new StringBuilder("Manifest-Version: 1.0\n");
content.append("Bundle-ActivationPolicy: lazy\n");
if (null != activatorClassName) {
content.append("Bundle-Activator: " + activatorClassName + "\n");
}
content.append("Bundle-ManifestVersion: 2\n");
content.append("Bundle-Name: " + getBundleName() + "\n");
content.append("Bundle-RequiredExecutionEnvironment: "+getBreeToUse() + "\n");
content.append("Bundle-SymbolicName: " + getBundleSymbolicName() + ";singleton:=true\n");
content.append("Bundle-Vendor: " + projectInfo.getCopyrightVendor() + "\n");
content.append("Bundle-Version: " + projectInfo.getVersion() + ".qualifier\n");
addToContent(content, requiredBundles, "Require-Bundle");
addToContent(content, importedPackages, "Import-Package");
addToContent(content, exportedPackages, "Export-Package");
createManifestAppend(content);
final IFolder metaInf = project.getFolder("META-INF");
SubMonitor subMonitor = SubMonitor.convert(progressMonitor, 2);
try {
if (metaInf.exists())
metaInf.delete(false, progressMonitor);
metaInf.create(false, true, subMonitor.newChild(1));
createFile("MANIFEST.MF", metaInf, content.toString(), subMonitor.newChild(1));
} finally {
subMonitor.done();
}
}
/**
* Add specific MANIFEST.MF entries.
* @param project
* @param content MANIFEST.MF file content to far
*/
protected abstract void createManifestAppend(StringBuilder content);
public final void setRule(ISchedulingRule rule) {
if ((workspace == null) && (rule instanceof IResource)) {
workspace = ((IResource) rule).getWorkspace();
}
}
}