use of org.eclipse.wst.common.project.facet.core.IActionDefinition in project mdw-designer by CenturyLinkCloud.
the class ProjectInflator method inflateCloudProject.
public void inflateCloudProject(final IRunnableContext container) {
getProject().setCloudProject(true);
// get a project handle
final IProject newProjectHandle = ResourcesPlugin.getWorkspace().getRoot().getProject(workflowProject.getName());
// get a project descriptor
IWorkspace workspace = ResourcesPlugin.getWorkspace();
final IProjectDescription description = workspace.newProjectDescription(newProjectHandle.getName());
// create the new project operation
IRunnableWithProgress op = new IRunnableWithProgress() {
public void run(IProgressMonitor monitor) throws InvocationTargetException {
Repository newRepo = null;
try {
if (workflowProject.getPersistType() == PersistType.Git)
createGitRepository(monitor);
CreateProjectOperation op = new CreateProjectOperation(description, "MDW Cloud Project");
PlatformUI.getWorkbench().getOperationSupport().getOperationHistory().execute(op, monitor, WorkspaceUndoUtil.getUIInfoAdapter(shell));
} catch (Exception ex) {
throw new InvocationTargetException(ex);
} finally {
if (newRepo != null)
newRepo.close();
}
}
};
// run the new project creation operation
try {
container.run(false, false, op);
ProgressMonitorDialog pmDialog = new MdwProgressMonitorDialog(MdwPlugin.getShell());
pmDialog.run(true, false, new IRunnableWithProgress() {
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
monitor.beginTask("Inflating Workflow Project", 250);
monitor.worked(5);
// configure as Java project
ProjectConfigurator projConf = new ProjectConfigurator(getProject(), MdwPlugin.getSettings());
projConf.setJava(new SubProgressMonitor(monitor, 3));
ProjectUpdater updater = new ProjectUpdater(getProject(), MdwPlugin.getSettings());
// bootstrap
updater.updateMappingFiles(new SubProgressMonitor(monitor, 3));
// versions
// of
// the
// property
// files
updater.updateFrameworkJars(new SubProgressMonitor(monitor, 150));
updater.updateWebProjectJars(new SubProgressMonitor(monitor, 50));
try {
if (getProject().isOsgi())
projConf.addJavaProjectSourceFolder(getProject().getOsgiSettings().getSourceDir(), new SubProgressMonitor(monitor, 3));
else if (!getProject().isWar())
projConf.addJavaProjectSourceFolder("src", monitor);
projConf.setJavaBuildOutputPath("build/classes", new SubProgressMonitor(monitor, 5));
projConf.addFrameworkJarsToClasspath(monitor);
// add the workflow facet
// already
getProject().setSkipFacetPostInstallUpdates(true);
// did
// framework
// updates
IFacetedProject facetedProject = ProjectFacetsManager.create(getProject().getSourceProject(), true, new SubProgressMonitor(monitor, 3));
IProjectFacetVersion javaFacetVersion = ProjectFacetsManager.getProjectFacet("java").getDefaultVersion();
if (Float.parseFloat(javaFacetVersion.getVersionString()) < 1.6)
javaFacetVersion = ProjectFacetsManager.getProjectFacet("java").getVersion("1.6");
if (workflowProject.isCloudOnly())
javaFacetVersion = ProjectFacetsManager.getProjectFacet("java").getVersion("1.7");
facetedProject.installProjectFacet(javaFacetVersion, null, new SubProgressMonitor(monitor, 3));
IProjectFacetVersion mdwFacet = ProjectFacetsManager.getProjectFacet("mdw.workflow").getDefaultVersion();
facetedProject.installProjectFacet(mdwFacet, getProject(), new SubProgressMonitor(monitor, 3));
if (workflowProject.isOsgi()) {
IProjectFacet utilFacet = ProjectFacetsManager.getProjectFacet("jst.utility");
IProjectFacetVersion facetVer = utilFacet.getDefaultVersion();
IActionDefinition def = facetVer.getActionDefinition(null, IFacetedProject.Action.Type.INSTALL);
Object cfg = def.createConfigObject();
facetedProject.installProjectFacet(ProjectFacetsManager.getProjectFacet("jst.utility").getDefaultVersion(), cfg, new SubProgressMonitor(monitor, 3));
} else if (workflowProject.isWar()) {
// add the facet to the xml file
IFile facetsFile = workflowProject.getSourceProject().getFile(".settings/org.eclipse.wst.common.project.facet.core.xml");
if (facetsFile.exists()) {
String content = new String(PluginUtil.readFile(facetsFile));
int insert = content.indexOf("</faceted-project>");
content = content.substring(0, insert) + " <installed facet=\"jst.web\" version=\"3.0\"/>\n" + content.substring(insert);
PluginUtil.writeFile(facetsFile, content, new SubProgressMonitor(monitor, 3));
}
}
final ProjectConfigurator configurator = new ProjectConfigurator(getProject(), MdwPlugin.getSettings());
if (!workflowProject.isOsgi() && !workflowProject.isWar()) {
MdwPlugin.getDisplay().syncExec(new Runnable() {
public void run() {
try {
configurator.createFrameworkSourceCodeAssociations(MdwPlugin.getShell(), new NullProgressMonitor());
} catch (CoreException ex) {
PluginMessages.log(ex);
}
}
});
}
if (workflowProject.isOsgi()) {
generateOsgiArtifacts(new SubProgressMonitor(monitor, 10));
configurator.configureOsgiProject(shell, new SubProgressMonitor(monitor, 5));
} else if (workflowProject.isWar()) {
generateWarCloudArtifacts(new SubProgressMonitor(monitor, 10));
// force
configurator.addMavenNature(new SubProgressMonitor(monitor, 5));
// maven
// refresh
}
} catch (Exception ex) {
throw new InvocationTargetException(ex);
}
}
});
} catch (Exception ex) {
PluginMessages.uiError(ex, "Create Cloud Project", workflowProject);
}
}
Aggregations