| /** |
| * |
| * 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.application; |
| |
| import java.lang.reflect.InvocationTargetException; |
| import java.util.Arrays; |
| import java.util.LinkedHashSet; |
| import java.util.List; |
| import java.util.Set; |
| |
| 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.m2e.core.internal.IMavenConstants; |
| import org.eclipse.osbp.preferences.ProductConfiguration; |
| import org.eclipse.osbp.wizard.ui.basic.BasicProjectCreator; |
| import org.eclipse.osbp.wizard.ui.basic.BasicProjectFactory; |
| import org.eclipse.osbp.wizard.ui.basic.BasicProjectInfo; |
| import org.eclipse.xtext.ui.util.PluginProjectFactory; |
| import org.eclipse.xtext.ui.util.ProjectFactory; |
| import org.eclipse.xtext.ui.wizard.IProjectInfo; |
| |
| import com.google.common.collect.ImmutableList; |
| import com.google.common.collect.Lists; |
| |
| /** |
| * Creator for a new Application Project. |
| */ |
| public class ApplicationProjectCreator extends BasicProjectCreator { |
| |
| /** |
| * Execute one model project for each existing project post fixes. |
| * |
| * @param projectInfo |
| * the project info |
| * @param monitor |
| * the monitor |
| * @throws InvocationTargetException |
| * the invocation target exception |
| * @throws CoreException |
| * the core exception |
| * @throws InterruptedException |
| * the interrupted exception |
| */ |
| public static void execute(BasicProjectInfo projectInfo, IProgressMonitor monitor) throws InvocationTargetException, CoreException, InterruptedException { |
| // generate a new application project |
| projectInfo.useForApplicationFactory(); |
| ApplicationProjectCreator instance = new ApplicationProjectCreator(projectInfo); |
| instance.execute(monitor); |
| // return to the product project factory |
| projectInfo.useForProductFactory(); |
| } |
| |
| /** |
| * Instantiates a new application project creator. |
| * |
| * @param projectInfo |
| * the project info |
| */ |
| private ApplicationProjectCreator(BasicProjectInfo projectInfo) { |
| super(); |
| super.setProjectInfo(projectInfo); |
| } |
| |
| @Override |
| protected BasicProjectInfo getProjectInfo() { |
| return (BasicProjectInfo) super.getProjectInfo(); |
| } |
| |
| /** |
| * Do not use this method! |
| */ |
| @Deprecated |
| @Override |
| public void setProjectInfo(IProjectInfo projectInfo) { |
| System.err.println(); |
| } |
| |
| @Override |
| protected String getModelFolderName() { |
| return "src"; |
| } |
| |
| @Override |
| protected List<String> getAllFolders() { |
| return ImmutableList.of("src"); |
| } |
| |
| @Override |
| protected List<String> getRequiredBundles() { |
| // No need to use the super required bundles! |
| return Lists.newArrayList(); // super.getRequiredBundles()); |
| } |
| |
| @Override |
| protected List<String> getImportedPackages() { |
| return Lists.newArrayList(super.getImportedPackages()); |
| } |
| |
| @Override |
| protected List<String> getExportedPackages() { |
| List<String> result = Lists.newArrayList(super.getExportedPackages()); |
| return addFromMultiLine(result, ManifestAttribute.EXPORTED_PACKAGE, ""); |
| } |
| |
| @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(getProjectInfo()); |
| ((BasicProjectFactory) result).setRule(getRule()); |
| return result; |
| } |
| |
| /** |
| * @return a specific model project factory |
| */ |
| @Override |
| protected PluginProjectFactory createProjectFactory() { |
| return new ApplicationProjectFactory(); // super.createProjectFactory(); |
| } |
| |
| @Override |
| protected String getEncoding() throws CoreException { |
| return super.getEncoding(); |
| } |
| |
| /** |
| * Enhance the model 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, "application"); |
| } |
| |
| @SuppressWarnings("restriction") |
| @Override |
| protected String[] getProjectNatures() { |
| Set<String> projectNatures = new LinkedHashSet<String>(); |
| projectNatures.addAll(Arrays.asList(super.getProjectNatures())); |
| if (ProductConfiguration.isMavenActivated()) { |
| projectNatures.add(IMavenConstants.NATURE_ID); |
| } |
| return projectNatures.toArray(new String[0]); |
| } |
| |
| @SuppressWarnings("restriction") |
| @Override |
| protected String[] getBuilders() { |
| Set<String> projectBuilders = new LinkedHashSet<String>(); |
| projectBuilders.addAll(Arrays.asList(super.getBuilders())); |
| if (ProductConfiguration.isMavenActivated()) { |
| projectBuilders.add(IMavenConstants.BUILDER_ID); |
| } |
| return projectBuilders.toArray(new String[0]); |
| } |
| |
| } |