blob: 6fc49ea50cb4924fdd2aa334f2c0a5254019f711 [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.product;
import java.lang.reflect.InvocationTargetException;
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.Platform;
import org.eclipse.osbp.preferences.ProductConfiguration;
import org.eclipse.osbp.wizard.ui.aggregator.AggregatorProjectCreator;
import org.eclipse.osbp.wizard.ui.application.ApplicationProjectCreator;
import org.eclipse.osbp.wizard.ui.basic.AbstractNonPluginProjectCreator;
import org.eclipse.osbp.wizard.ui.basic.BasicProjectFactory;
import org.eclipse.osbp.wizard.ui.basic.BasicProjectInfo;
import org.eclipse.osbp.wizard.ui.feature.FeatureProjectCreator;
import org.eclipse.osbp.wizard.ui.model.ModelProjectCreator;
import org.eclipse.xtext.ui.util.PluginProjectFactory;
import org.eclipse.xtext.ui.util.ProjectFactory;
/**
* Creator for a new Product Project.
*/
public class ProductProjectCreator extends AbstractNonPluginProjectCreator {
public ProductProjectCreator() {
super();
}
@Override
protected BasicProjectInfo getProjectInfo() {
return (BasicProjectInfo) super.getProjectInfo();
}
@Override
protected void execute(IProgressMonitor monitor) throws CoreException, InvocationTargetException, InterruptedException {
getProjectInfo().startExecute();
Exception e = null;
// --- generate this product project ---
getProjectInfo().useForProductFactory();
try {
// --- primary generate a aggregator project ---
if (ProductConfiguration.isMavenActivated()){
AggregatorProjectCreator.execute(getProjectInfo(), monitor);
}
super.execute(monitor);
// --- additionally generate a application project ---
ApplicationProjectCreator.execute(getProjectInfo(), monitor);
// --- additionally generate a feature project ---
FeatureProjectCreator.execute(getProjectInfo(), monitor);
// --- additionally generate a model project ---
ModelProjectCreator.execute(getProjectInfo(), monitor);
} catch (Exception ce) {
e = ce;
}
// --- reset to generate this project ---
getProjectInfo().useForProductFactory();
// re-throw any exceptions caugth while creating model projects
if (e instanceof CoreException) {
throw (CoreException) e;
}
if (e instanceof InvocationTargetException) {
throw (InvocationTargetException) e;
}
if (e instanceof InterruptedException) {
throw (InterruptedException) e;
}
getProjectInfo().endExecute();
}
/**
* @return specific product project factory
*/
@Override
protected PluginProjectFactory createProjectFactory() {
return new ProductProjectFactory();
}
@Override
protected ProjectFactory configureProjectFactory(ProjectFactory factory) {
// ----------- !!!!DONĀ“T MOVE THIS!!!! --------------
// This path manipulation is mandatory to put the product plugin project as subfolder of the aggregator.
// The setting of this new location path to projectInfo has to be before the call of super.configureProjectFactory(factory).
IPath path = Platform.getLocation().append(getProjectInfo().getBasicProjectName()).append(getProjectInfo().getProjectName());
getProjectInfo().setLocationPath(path.makeAbsolute());
// ---------------------------------------------------
ProjectFactory result = super.configureProjectFactory(factory);
((BasicProjectFactory) result).configureFrom((BasicProjectInfo) getProjectInfo());
((BasicProjectFactory) result).setRule(getRule());
return result;
}
/**
* Enhance the product project and display the progress on the monitor.
*
* @param project
* @param monitor
*/
@Override
protected void enhanceProject(final IProject project, final IProgressMonitor monitor) throws CoreException {
enhanceProject(project, monitor, "product");
}
}