diff options
Diffstat (limited to 'plugins/org.eclipse.emf.cdo.dawn.codegen/src/org/eclipse')
10 files changed, 1082 insertions, 1082 deletions
diff --git a/plugins/org.eclipse.emf.cdo.dawn.codegen/src/org/eclipse/emf/cdo/dawn/codegen/DawnCodeGenPlugin.java b/plugins/org.eclipse.emf.cdo.dawn.codegen/src/org/eclipse/emf/cdo/dawn/codegen/DawnCodeGenPlugin.java index 90df14cf5d..0fe6e1a767 100644 --- a/plugins/org.eclipse.emf.cdo.dawn.codegen/src/org/eclipse/emf/cdo/dawn/codegen/DawnCodeGenPlugin.java +++ b/plugins/org.eclipse.emf.cdo.dawn.codegen/src/org/eclipse/emf/cdo/dawn/codegen/DawnCodeGenPlugin.java @@ -1,53 +1,53 @@ -/*
- * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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
- *
- * Contributors:
- * Martin Fluegge - initial API and implementation
- */
-package org.eclipse.emf.cdo.dawn.codegen;
-
-import org.eclipse.core.runtime.Plugin;
-
-import org.osgi.framework.BundleContext;
-
-/**
- * @author Martin Fluegge
- */
-public class DawnCodeGenPlugin extends Plugin
-{
- public static final String PLUGIN_ID = "org.eclipse.emf.cdo.dawn.codegen"; //$NON-NLS-1$
-
- private static DawnCodeGenPlugin plugin;
-
- public DawnCodeGenPlugin()
- {
- }
-
- @Override
- public void start(BundleContext context) throws Exception
- {
- super.start(context);
- plugin = this;
- }
-
- @Override
- public void stop(BundleContext context) throws Exception
- {
- plugin = null;
- super.stop(context);
- }
-
- /**
- * Returns the shared instance
- *
- * @return the shared instance
- */
- public static DawnCodeGenPlugin getDefault()
- {
- return plugin;
- }
-}
+/* + * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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 + * + * Contributors: + * Martin Fluegge - initial API and implementation + */ +package org.eclipse.emf.cdo.dawn.codegen; + +import org.eclipse.core.runtime.Plugin; + +import org.osgi.framework.BundleContext; + +/** + * @author Martin Fluegge + */ +public class DawnCodeGenPlugin extends Plugin +{ + public static final String PLUGIN_ID = "org.eclipse.emf.cdo.dawn.codegen"; //$NON-NLS-1$ + + private static DawnCodeGenPlugin plugin; + + public DawnCodeGenPlugin() + { + } + + @Override + public void start(BundleContext context) throws Exception + { + super.start(context); + plugin = this; + } + + @Override + public void stop(BundleContext context) throws Exception + { + plugin = null; + super.stop(context); + } + + /** + * Returns the shared instance + * + * @return the shared instance + */ + public static DawnCodeGenPlugin getDefault() + { + return plugin; + } +} diff --git a/plugins/org.eclipse.emf.cdo.dawn.codegen/src/org/eclipse/emf/cdo/dawn/codegen/actions/GenerateDawnGenModelAction.java b/plugins/org.eclipse.emf.cdo.dawn.codegen/src/org/eclipse/emf/cdo/dawn/codegen/actions/GenerateDawnGenModelAction.java index f582e79dd2..822ed29cf0 100644 --- a/plugins/org.eclipse.emf.cdo.dawn.codegen/src/org/eclipse/emf/cdo/dawn/codegen/actions/GenerateDawnGenModelAction.java +++ b/plugins/org.eclipse.emf.cdo.dawn.codegen/src/org/eclipse/emf/cdo/dawn/codegen/actions/GenerateDawnGenModelAction.java @@ -1,193 +1,193 @@ -/*
- * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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
- *
- * Contributors:
- * Martin Fluegge - initial API and implementation
- */
-package org.eclipse.emf.cdo.dawn.codegen.actions;
-
-import org.eclipse.emf.cdo.dawn.codegen.dawngenmodel.DawnFragmentGenerator;
-import org.eclipse.emf.cdo.dawn.codegen.dawngenmodel.DawnGenerator;
-import org.eclipse.emf.cdo.dawn.codegen.dawngenmodel.DawngenmodelFactory;
-import org.eclipse.emf.cdo.dawn.codegen.util.ProjectCreationHelper;
-
-import org.eclipse.emf.common.util.URI;
-import org.eclipse.emf.ecore.resource.Resource;
-import org.eclipse.emf.ecore.resource.ResourceSet;
-import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
-import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl;
-
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IResource;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.jface.action.IAction;
-import org.eclipse.jface.operation.IRunnableWithProgress;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.ui.IObjectActionDelegate;
-import org.eclipse.ui.IWorkbenchPart;
-import org.eclipse.ui.IWorkbenchWindow;
-import org.eclipse.ui.PlatformUI;
-
-import java.io.IOException;
-import java.lang.reflect.InvocationTargetException;
-import java.util.Collections;
-
-/**
- * @author Martin Fluegge
- */
-public abstract class GenerateDawnGenModelAction implements IObjectActionDelegate
-{
- /**
- * @since 1.0
- */
- protected IResource selectedElement;
-
- public final static String dawngenmodelFileExtension = "dawngenmodel";
-
- /**
- * @since 1.0
- */
- protected final String generalPrefix = "Dawn";
-
- public void setActivePart(IAction action, IWorkbenchPart targetPart)
- {
- }
-
- public void run(IAction action)
- {
- IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
- try
- {
- window.run(true, true, new IRunnableWithProgress()
- {
- public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException
- {
- monitor.beginTask("Generate Dawn Code", 1000);
- IFile genFile = (IFile)selectedElement;
-
- String genModelFile = genFile.getRawLocationURI().toString();
- String path = genModelFile.replace(genFile.getName(), "");
-
- ResourceSet resourceSet = createResourceSet();
- String modelname = "default";
- modelname = getModelName(genFile);
-
- Resource dawnGenModelResource = getResource(path, modelname, resourceSet, dawngenmodelFileExtension);
- Resource dawnFragmentModelResource = getDawnFragmentModelResource(path, modelname, resourceSet);
-
- DawnGenerator dawnGenerator = getDawngenerator(dawnGenModelResource);
-
- DawnFragmentGenerator fragmentGenerator = getDawnFragmentGenerator(genFile, resourceSet);
- fragmentGenerator.setDawnGenerator(dawnGenerator);
-
- dawnGenModelResource.getContents().add(dawnGenerator);
- dawnFragmentModelResource.getContents().add(fragmentGenerator);
-
- try
- {
- dawnGenModelResource.save(Collections.EMPTY_MAP);
- dawnFragmentModelResource.save(Collections.EMPTY_MAP);
- }
- catch (IOException ex)
- {
- throw new RuntimeException(ex);
- }
-
- ProjectCreationHelper.refreshProject(null, monitor);
- }
-
- private DawnGenerator getDawngenerator(Resource dawnGenModelResource)
- {
- DawnGenerator dawnGenerator;
-
- if (dawnGenModelResource.getContents().size() != 0)
- {
- dawnGenerator = (DawnGenerator)dawnGenModelResource.getContents().get(0);
- }
- else
- {
- dawnGenerator = DawngenmodelFactory.eINSTANCE.createDawnGenerator();
- }
- return dawnGenerator;
- }
-
- });
- }
- catch (InvocationTargetException ex)
- {
- throw new RuntimeException(ex);
- }
- catch (InterruptedException ex)
- {
- throw new RuntimeException(ex);
- }
- }
-
- /**
- * @since 1.0
- */
- protected abstract Resource getDawnFragmentModelResource(String path, String modelname, ResourceSet resourceSet);
-
- /**
- * @since 1.0
- */
- protected abstract DawnFragmentGenerator getDawnFragmentGenerator(IFile genFile, ResourceSet resourceSet);
-
- private String getModelName(IFile genFile)
- {
- int lastIndexOf = genFile.getName().lastIndexOf(".");
- return genFile.getName().substring(0, lastIndexOf);
- }
-
- /**
- * @since 1.0
- */
- protected Resource getResource(String path, String modelname, ResourceSet resourceSet, String extension)
- {
- String resourcePath = path + "" + modelname + "." + extension;
- URI uri = URI.createURI(resourcePath);
- Resource resource = null;
- try
- {
- resource = resourceSet.getResource(uri, true);
- }
- catch (Exception ignore)
- {
- // ignore
- }
-
- if (resource == null)
- {
- resource = resourceSet.createResource(uri);
- }
- return resource;
- }
-
- /**
- * @since 1.0
- */
- protected ResourceSet createResourceSet()
- {
- ResourceSet resourceSet = new ResourceSetImpl();
- resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap()
- .put(dawngenmodelFileExtension, new XMIResourceFactoryImpl());
- return resourceSet;
- }
-
- public void selectionChanged(IAction action, ISelection selection)
- {
- if (selection instanceof IStructuredSelection)
- {
- Object sel = ((IStructuredSelection)selection).getFirstElement();
- if (sel instanceof IResource)
- {
- selectedElement = (IResource)sel;
- }
- }
- }
-}
+/* + * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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 + * + * Contributors: + * Martin Fluegge - initial API and implementation + */ +package org.eclipse.emf.cdo.dawn.codegen.actions; + +import org.eclipse.emf.cdo.dawn.codegen.dawngenmodel.DawnFragmentGenerator; +import org.eclipse.emf.cdo.dawn.codegen.dawngenmodel.DawnGenerator; +import org.eclipse.emf.cdo.dawn.codegen.dawngenmodel.DawngenmodelFactory; +import org.eclipse.emf.cdo.dawn.codegen.util.ProjectCreationHelper; + +import org.eclipse.emf.common.util.URI; +import org.eclipse.emf.ecore.resource.Resource; +import org.eclipse.emf.ecore.resource.ResourceSet; +import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl; +import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl; + +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.jface.action.IAction; +import org.eclipse.jface.operation.IRunnableWithProgress; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.ui.IObjectActionDelegate; +import org.eclipse.ui.IWorkbenchPart; +import org.eclipse.ui.IWorkbenchWindow; +import org.eclipse.ui.PlatformUI; + +import java.io.IOException; +import java.lang.reflect.InvocationTargetException; +import java.util.Collections; + +/** + * @author Martin Fluegge + */ +public abstract class GenerateDawnGenModelAction implements IObjectActionDelegate +{ + /** + * @since 1.0 + */ + protected IResource selectedElement; + + public final static String dawngenmodelFileExtension = "dawngenmodel"; + + /** + * @since 1.0 + */ + protected final String generalPrefix = "Dawn"; + + public void setActivePart(IAction action, IWorkbenchPart targetPart) + { + } + + public void run(IAction action) + { + IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); + try + { + window.run(true, true, new IRunnableWithProgress() + { + public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException + { + monitor.beginTask("Generate Dawn Code", 1000); + IFile genFile = (IFile)selectedElement; + + String genModelFile = genFile.getRawLocationURI().toString(); + String path = genModelFile.replace(genFile.getName(), ""); + + ResourceSet resourceSet = createResourceSet(); + String modelname = "default"; + modelname = getModelName(genFile); + + Resource dawnGenModelResource = getResource(path, modelname, resourceSet, dawngenmodelFileExtension); + Resource dawnFragmentModelResource = getDawnFragmentModelResource(path, modelname, resourceSet); + + DawnGenerator dawnGenerator = getDawngenerator(dawnGenModelResource); + + DawnFragmentGenerator fragmentGenerator = getDawnFragmentGenerator(genFile, resourceSet); + fragmentGenerator.setDawnGenerator(dawnGenerator); + + dawnGenModelResource.getContents().add(dawnGenerator); + dawnFragmentModelResource.getContents().add(fragmentGenerator); + + try + { + dawnGenModelResource.save(Collections.EMPTY_MAP); + dawnFragmentModelResource.save(Collections.EMPTY_MAP); + } + catch (IOException ex) + { + throw new RuntimeException(ex); + } + + ProjectCreationHelper.refreshProject(null, monitor); + } + + private DawnGenerator getDawngenerator(Resource dawnGenModelResource) + { + DawnGenerator dawnGenerator; + + if (dawnGenModelResource.getContents().size() != 0) + { + dawnGenerator = (DawnGenerator)dawnGenModelResource.getContents().get(0); + } + else + { + dawnGenerator = DawngenmodelFactory.eINSTANCE.createDawnGenerator(); + } + return dawnGenerator; + } + + }); + } + catch (InvocationTargetException ex) + { + throw new RuntimeException(ex); + } + catch (InterruptedException ex) + { + throw new RuntimeException(ex); + } + } + + /** + * @since 1.0 + */ + protected abstract Resource getDawnFragmentModelResource(String path, String modelname, ResourceSet resourceSet); + + /** + * @since 1.0 + */ + protected abstract DawnFragmentGenerator getDawnFragmentGenerator(IFile genFile, ResourceSet resourceSet); + + private String getModelName(IFile genFile) + { + int lastIndexOf = genFile.getName().lastIndexOf("."); + return genFile.getName().substring(0, lastIndexOf); + } + + /** + * @since 1.0 + */ + protected Resource getResource(String path, String modelname, ResourceSet resourceSet, String extension) + { + String resourcePath = path + "" + modelname + "." + extension; + URI uri = URI.createURI(resourcePath); + Resource resource = null; + try + { + resource = resourceSet.getResource(uri, true); + } + catch (Exception ignore) + { + // ignore + } + + if (resource == null) + { + resource = resourceSet.createResource(uri); + } + return resource; + } + + /** + * @since 1.0 + */ + protected ResourceSet createResourceSet() + { + ResourceSet resourceSet = new ResourceSetImpl(); + resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap() + .put(dawngenmodelFileExtension, new XMIResourceFactoryImpl()); + return resourceSet; + } + + public void selectionChanged(IAction action, ISelection selection) + { + if (selection instanceof IStructuredSelection) + { + Object sel = ((IStructuredSelection)selection).getFirstElement(); + if (sel instanceof IResource) + { + selectedElement = (IResource)sel; + } + } + } +} diff --git a/plugins/org.eclipse.emf.cdo.dawn.codegen/src/org/eclipse/emf/cdo/dawn/codegen/creators/Creator.java b/plugins/org.eclipse.emf.cdo.dawn.codegen/src/org/eclipse/emf/cdo/dawn/codegen/creators/Creator.java index 81a492ed1e..23d06c77c9 100644 --- a/plugins/org.eclipse.emf.cdo.dawn.codegen/src/org/eclipse/emf/cdo/dawn/codegen/creators/Creator.java +++ b/plugins/org.eclipse.emf.cdo.dawn.codegen/src/org/eclipse/emf/cdo/dawn/codegen/creators/Creator.java @@ -1,21 +1,21 @@ -/*
- * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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
- *
- * Contributors:
- * Martin Fluegge - initial API and implementation
- */
-package org.eclipse.emf.cdo.dawn.codegen.creators;
-
-import org.eclipse.core.runtime.IProgressMonitor;
-
-/**
- * @author Martin Fluegge
- */
-public interface Creator
-{
- public void create(IProgressMonitor monitor);
-}
+/* + * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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 + * + * Contributors: + * Martin Fluegge - initial API and implementation + */ +package org.eclipse.emf.cdo.dawn.codegen.creators; + +import org.eclipse.core.runtime.IProgressMonitor; + +/** + * @author Martin Fluegge + */ +public interface Creator +{ + public void create(IProgressMonitor monitor); +} diff --git a/plugins/org.eclipse.emf.cdo.dawn.codegen/src/org/eclipse/emf/cdo/dawn/codegen/creators/impl/AbstractFragmentCreator.java b/plugins/org.eclipse.emf.cdo.dawn.codegen/src/org/eclipse/emf/cdo/dawn/codegen/creators/impl/AbstractFragmentCreator.java index 6e33de0a4e..276fddea87 100644 --- a/plugins/org.eclipse.emf.cdo.dawn.codegen/src/org/eclipse/emf/cdo/dawn/codegen/creators/impl/AbstractFragmentCreator.java +++ b/plugins/org.eclipse.emf.cdo.dawn.codegen/src/org/eclipse/emf/cdo/dawn/codegen/creators/impl/AbstractFragmentCreator.java @@ -1,158 +1,158 @@ -/*
- * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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
- *
- * Contributors:
- * Martin Fluegge - initial API and implementation
- */
-package org.eclipse.emf.cdo.dawn.codegen.creators.impl;
-
-import org.eclipse.emf.cdo.dawn.codegen.actions.GenerateDawnGenModelAction;
-import org.eclipse.emf.cdo.dawn.codegen.creators.Creator;
-import org.eclipse.emf.cdo.dawn.codegen.dawngenmodel.DawnFragmentGenerator;
-import org.eclipse.emf.cdo.dawn.codegen.util.ProjectCreationHelper;
-import org.eclipse.emf.cdo.dawn.codegen.util.Utils;
-
-import org.eclipse.emf.common.util.URI;
-import org.eclipse.emf.ecore.resource.Resource;
-import org.eclipse.emf.ecore.resource.ResourceSet;
-import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
-import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl;
-import org.eclipse.emf.mwe.core.WorkflowEngine;
-import org.eclipse.emf.mwe.core.monitor.NullProgressMonitor;
-
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.IResource;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.FileLocator;
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.jdt.core.JavaCore;
-
-import java.io.IOException;
-import java.lang.reflect.InvocationTargetException;
-import java.net.URL;
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * @author Martin Fluegge
- * @since 1.0
- */
-public abstract class AbstractFragmentCreator implements Creator
-{
- protected final IResource selectedElement;
-
- protected final String PLUGIN_NATURE = "org.eclipse.pde.PluginNature";
-
- protected final String JAVA_NATURE = JavaCore.NATURE_ID;
-
- public AbstractFragmentCreator(IResource selectedElement)
- {
- this.selectedElement = selectedElement;
- }
-
- public void create(IProgressMonitor monitor)
- {
- IFile dawnGenModelFile = (IFile)selectedElement;
-
- ResourceSet resourceSet = new ResourceSetImpl();
- resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap()
- .put(GenerateDawnGenModelAction.dawngenmodelFileExtension, new XMIResourceFactoryImpl());
-
- Resource dawnGenModelResource = resourceSet.getResource(
- URI.createURI(dawnGenModelFile.getRawLocationURI().toString()), true);
-
- DawnFragmentGenerator dawnFragmentGenerator = (DawnFragmentGenerator)dawnGenModelResource.getContents().get(0);
- // DawnGenerator dawnGenerator = dawnFragmentGenerator.getDawnGenerator();
-
- if (dawnFragmentGenerator != null)
- {
- monitor.subTask("Create client fragment's basic structure");
-
- // String[] natures = new String[] { JavaCore.NATURE_ID, PDE.PLUGIN_NATURE };
- String[] natures = new String[] { JAVA_NATURE, PLUGIN_NATURE };
-
- ProjectCreationHelper projectCreationHelper = new ProjectCreationHelper();
- projectCreationHelper.setName(dawnFragmentGenerator.getFragmentName());
- projectCreationHelper.setNatures(natures);
- IProject project;
- try
- {
- project = projectCreationHelper.createProject();
- projectCreationHelper.createJavaProject(project);
-
- monitor.worked(100);
-
- monitor.subTask("Creating folder structure...");
- projectCreationHelper.createFolder("lib", project);
- projectCreationHelper.createFolder("META-INF", project);
- projectCreationHelper.createFolder("icons", project);
-
- monitor.worked(100);
-
- monitor.subTask("Creating generic content...");
- createGenericContent(monitor, project.getLocation());
- ProjectCreationHelper.refreshProject(project, monitor);
- }
- catch (CoreException ex)
- {
- throw new RuntimeException(ex);
- }
- catch (InvocationTargetException ex)
- {
- throw new RuntimeException(ex);
- }
- catch (InterruptedException ex)
- {
- throw new RuntimeException(ex);
- }
- }
- else
- {
- throw new RuntimeException("Could not find DawnFragmentGenerator for " + selectedElement);
- }
-
- monitor.worked(100);
- }
-
- protected abstract URL getWorkflowURL();
-
- protected void createGenericContent(IProgressMonitor monitor, IPath location)
- {
- IFile file = (IFile)selectedElement;
- Map<String, String> properties = new HashMap<String, String>();
-
- Map<String, ?> slotMap = new HashMap<String, Object>();
- try
- {
- String dawnGenFile = file.getRawLocationURI().toString();// ;file.getLocation().toFile().getAbsoluteFile().toURI().toURL().toString();
-
- IFile dawnGen = (IFile)selectedElement;
- IProject hostProject = dawnGen.getProject();
-
- Utils.setPackage(hostProject.getName());
-
- String ouputFolder = location.toFile().getAbsoluteFile().toString();// + "/" + hostProject.getName()+".diagram";
-
- properties.put("model", dawnGenFile);
- properties.put("src-gen", ouputFolder);
-
- URL workFlowURL = getWorkflowURL();
- // WorkflowRunner workflowRunner = new WorkflowRunner();
- String workflow = FileLocator.toFileURL(workFlowURL).getFile();
-
- // workflowRunner.run(workflow, , properties, slotMap);
-
- new WorkflowEngine().run(workflow, new NullProgressMonitor(), properties, slotMap);
- }
- catch (IOException ex)
- {
- throw new RuntimeException(ex);
- }
- }
-}
+/* + * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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 + * + * Contributors: + * Martin Fluegge - initial API and implementation + */ +package org.eclipse.emf.cdo.dawn.codegen.creators.impl; + +import org.eclipse.emf.cdo.dawn.codegen.actions.GenerateDawnGenModelAction; +import org.eclipse.emf.cdo.dawn.codegen.creators.Creator; +import org.eclipse.emf.cdo.dawn.codegen.dawngenmodel.DawnFragmentGenerator; +import org.eclipse.emf.cdo.dawn.codegen.util.ProjectCreationHelper; +import org.eclipse.emf.cdo.dawn.codegen.util.Utils; + +import org.eclipse.emf.common.util.URI; +import org.eclipse.emf.ecore.resource.Resource; +import org.eclipse.emf.ecore.resource.ResourceSet; +import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl; +import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl; +import org.eclipse.emf.mwe.core.WorkflowEngine; +import org.eclipse.emf.mwe.core.monitor.NullProgressMonitor; + +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.FileLocator; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.jdt.core.JavaCore; + +import java.io.IOException; +import java.lang.reflect.InvocationTargetException; +import java.net.URL; +import java.util.HashMap; +import java.util.Map; + +/** + * @author Martin Fluegge + * @since 1.0 + */ +public abstract class AbstractFragmentCreator implements Creator +{ + protected final IResource selectedElement; + + protected final String PLUGIN_NATURE = "org.eclipse.pde.PluginNature"; + + protected final String JAVA_NATURE = JavaCore.NATURE_ID; + + public AbstractFragmentCreator(IResource selectedElement) + { + this.selectedElement = selectedElement; + } + + public void create(IProgressMonitor monitor) + { + IFile dawnGenModelFile = (IFile)selectedElement; + + ResourceSet resourceSet = new ResourceSetImpl(); + resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap() + .put(GenerateDawnGenModelAction.dawngenmodelFileExtension, new XMIResourceFactoryImpl()); + + Resource dawnGenModelResource = resourceSet.getResource( + URI.createURI(dawnGenModelFile.getRawLocationURI().toString()), true); + + DawnFragmentGenerator dawnFragmentGenerator = (DawnFragmentGenerator)dawnGenModelResource.getContents().get(0); + // DawnGenerator dawnGenerator = dawnFragmentGenerator.getDawnGenerator(); + + if (dawnFragmentGenerator != null) + { + monitor.subTask("Create client fragment's basic structure"); + + // String[] natures = new String[] { JavaCore.NATURE_ID, PDE.PLUGIN_NATURE }; + String[] natures = new String[] { JAVA_NATURE, PLUGIN_NATURE }; + + ProjectCreationHelper projectCreationHelper = new ProjectCreationHelper(); + projectCreationHelper.setName(dawnFragmentGenerator.getFragmentName()); + projectCreationHelper.setNatures(natures); + IProject project; + try + { + project = projectCreationHelper.createProject(); + projectCreationHelper.createJavaProject(project); + + monitor.worked(100); + + monitor.subTask("Creating folder structure..."); + projectCreationHelper.createFolder("lib", project); + projectCreationHelper.createFolder("META-INF", project); + projectCreationHelper.createFolder("icons", project); + + monitor.worked(100); + + monitor.subTask("Creating generic content..."); + createGenericContent(monitor, project.getLocation()); + ProjectCreationHelper.refreshProject(project, monitor); + } + catch (CoreException ex) + { + throw new RuntimeException(ex); + } + catch (InvocationTargetException ex) + { + throw new RuntimeException(ex); + } + catch (InterruptedException ex) + { + throw new RuntimeException(ex); + } + } + else + { + throw new RuntimeException("Could not find DawnFragmentGenerator for " + selectedElement); + } + + monitor.worked(100); + } + + protected abstract URL getWorkflowURL(); + + protected void createGenericContent(IProgressMonitor monitor, IPath location) + { + IFile file = (IFile)selectedElement; + Map<String, String> properties = new HashMap<String, String>(); + + Map<String, ?> slotMap = new HashMap<String, Object>(); + try + { + String dawnGenFile = file.getRawLocationURI().toString();// ;file.getLocation().toFile().getAbsoluteFile().toURI().toURL().toString(); + + IFile dawnGen = (IFile)selectedElement; + IProject hostProject = dawnGen.getProject(); + + Utils.setPackage(hostProject.getName()); + + String ouputFolder = location.toFile().getAbsoluteFile().toString();// + "/" + hostProject.getName()+".diagram"; + + properties.put("model", dawnGenFile); + properties.put("src-gen", ouputFolder); + + URL workFlowURL = getWorkflowURL(); + // WorkflowRunner workflowRunner = new WorkflowRunner(); + String workflow = FileLocator.toFileURL(workFlowURL).getFile(); + + // workflowRunner.run(workflow, , properties, slotMap); + + new WorkflowEngine().run(workflow, new NullProgressMonitor(), properties, slotMap); + } + catch (IOException ex) + { + throw new RuntimeException(ex); + } + } +} diff --git a/plugins/org.eclipse.emf.cdo.dawn.codegen/src/org/eclipse/emf/cdo/dawn/codegen/messages/Messages.java b/plugins/org.eclipse.emf.cdo.dawn.codegen/src/org/eclipse/emf/cdo/dawn/codegen/messages/Messages.java index 529f91032e..57cc7cd7bb 100644 --- a/plugins/org.eclipse.emf.cdo.dawn.codegen/src/org/eclipse/emf/cdo/dawn/codegen/messages/Messages.java +++ b/plugins/org.eclipse.emf.cdo.dawn.codegen/src/org/eclipse/emf/cdo/dawn/codegen/messages/Messages.java @@ -1,35 +1,35 @@ -/*
- * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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
- *
- * Contributors:
- * Martin Fluegge - initial API and implementation
- */
-package org.eclipse.emf.cdo.dawn.codegen.messages;
-
-import org.eclipse.osgi.util.NLS;
-
-/**
- * @author Martin Fluegge
- * @since 1.0
- */
-public class Messages extends NLS
-{
- private static final String BUNDLE_NAME = "org.eclipse.emf.cdo.dawn.codegen.messages"; //$NON-NLS-1$
-
- public static String GenerateClientCodeAction_0;
-
- public static String GenerateEMFFragmentAction_0;
- static
- {
- // initialize resource bundle
- NLS.initializeMessages(BUNDLE_NAME, Messages.class);
- }
-
- private Messages()
- {
- }
-}
+/* + * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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 + * + * Contributors: + * Martin Fluegge - initial API and implementation + */ +package org.eclipse.emf.cdo.dawn.codegen.messages; + +import org.eclipse.osgi.util.NLS; + +/** + * @author Martin Fluegge + * @since 1.0 + */ +public class Messages extends NLS +{ + private static final String BUNDLE_NAME = "org.eclipse.emf.cdo.dawn.codegen.messages"; //$NON-NLS-1$ + + public static String GenerateClientCodeAction_0; + + public static String GenerateEMFFragmentAction_0; + static + { + // initialize resource bundle + NLS.initializeMessages(BUNDLE_NAME, Messages.class); + } + + private Messages() + { + } +} diff --git a/plugins/org.eclipse.emf.cdo.dawn.codegen/src/org/eclipse/emf/cdo/dawn/codegen/messages/messages.properties b/plugins/org.eclipse.emf.cdo.dawn.codegen/src/org/eclipse/emf/cdo/dawn/codegen/messages/messages.properties index 8dfe1732e7..27814be3db 100644 --- a/plugins/org.eclipse.emf.cdo.dawn.codegen/src/org/eclipse/emf/cdo/dawn/codegen/messages/messages.properties +++ b/plugins/org.eclipse.emf.cdo.dawn.codegen/src/org/eclipse/emf/cdo/dawn/codegen/messages/messages.properties @@ -1,11 +1,11 @@ -# Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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
-#
-# Contributors:
-# Eike Stepper - initial API and implementation
-
-GenerateEMFFragmentAction_0=Generating Dawn EMF fragment...
-GenerateClientCodeAction_0=Generating Dawn GMF fragment...
+# Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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 +# +# Contributors: +# Eike Stepper - initial API and implementation + +GenerateEMFFragmentAction_0=Generating Dawn EMF fragment... +GenerateClientCodeAction_0=Generating Dawn GMF fragment... diff --git a/plugins/org.eclipse.emf.cdo.dawn.codegen/src/org/eclipse/emf/cdo/dawn/codegen/util/DawnWorkflowUtil.java b/plugins/org.eclipse.emf.cdo.dawn.codegen/src/org/eclipse/emf/cdo/dawn/codegen/util/DawnWorkflowUtil.java index 149da16831..eebd428ef1 100644 --- a/plugins/org.eclipse.emf.cdo.dawn.codegen/src/org/eclipse/emf/cdo/dawn/codegen/util/DawnWorkflowUtil.java +++ b/plugins/org.eclipse.emf.cdo.dawn.codegen/src/org/eclipse/emf/cdo/dawn/codegen/util/DawnWorkflowUtil.java @@ -1,22 +1,22 @@ -/*
- * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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
- *
- * Contributors:
- * Martin Fluegge - initial API and implementation
- */
-package org.eclipse.emf.cdo.dawn.codegen.util;
-
-import java.net.URL;
-
-/**
- * @author Martin Fluegge
- * @since 1.0
- */
-public interface DawnWorkflowUtil
-{
- public URL getWorkFlow();
-}
+/* + * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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 + * + * Contributors: + * Martin Fluegge - initial API and implementation + */ +package org.eclipse.emf.cdo.dawn.codegen.util; + +import java.net.URL; + +/** + * @author Martin Fluegge + * @since 1.0 + */ +public interface DawnWorkflowUtil +{ + public URL getWorkFlow(); +} diff --git a/plugins/org.eclipse.emf.cdo.dawn.codegen/src/org/eclipse/emf/cdo/dawn/codegen/util/ProjectCreationHelper.java b/plugins/org.eclipse.emf.cdo.dawn.codegen/src/org/eclipse/emf/cdo/dawn/codegen/util/ProjectCreationHelper.java index d4b5cc5f96..735b11860e 100644 --- a/plugins/org.eclipse.emf.cdo.dawn.codegen/src/org/eclipse/emf/cdo/dawn/codegen/util/ProjectCreationHelper.java +++ b/plugins/org.eclipse.emf.cdo.dawn.codegen/src/org/eclipse/emf/cdo/dawn/codegen/util/ProjectCreationHelper.java @@ -1,424 +1,424 @@ -/*
- * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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
- *
- * Contributors:
- * Martin Fluegge - initial API and implementation
- */
-package org.eclipse.emf.cdo.dawn.codegen.util;
-
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IFolder;
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.IProjectDescription;
-import org.eclipse.core.resources.IResource;
-import org.eclipse.core.resources.IWorkspaceRoot;
-import org.eclipse.core.resources.ResourcesPlugin;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.NullProgressMonitor;
-import org.eclipse.core.runtime.Path;
-import org.eclipse.jdt.core.IClasspathEntry;
-import org.eclipse.jdt.core.IJavaProject;
-import org.eclipse.jdt.core.JavaCore;
-import org.eclipse.jdt.core.JavaModelException;
-import org.eclipse.jdt.launching.JavaRuntime;
-import org.eclipse.jface.operation.IRunnableWithProgress;
-import org.eclipse.ui.actions.WorkspaceModifyOperation;
-
-import java.io.ByteArrayInputStream;
-import java.io.InputStream;
-import java.lang.reflect.InvocationTargetException;
-import java.util.ArrayList;
-
-/**
- * @author Martin Fluegge
- */
-public class ProjectCreationHelper
-{
-
- private String name;
-
- private String[] natures;
-
- public String getName()
- {
- return name;
- }
-
- public IProject getProject()
- {
- return ResourcesPlugin.getWorkspace().getRoot().getProject(name);
- }
-
- public IProject createProject() throws CoreException
- {
- IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(name);
-
- if (!project.exists())
- {
- project.create(null);
- }
-
- if (!project.isOpen())
- {
- project.open(null);
- }
-
- IProjectDescription description = project.getDescription();
- description.setNatureIds(natures);
- project.setDescription(description, null);
-
- return project;
- }
-
- /**
- * @param path
- * @param javaProject
- * @throws JavaModelException
- */
- public static void addJarToBuildPath(String path, IJavaProject javaProject) throws JavaModelException
- {
- IClasspathEntry newLibraryEntry = JavaCore.newLibraryEntry(new Path(path), null, null);
- ProjectCreationHelper.addToClasspath(javaProject, newLibraryEntry);
- }
-
- public static void addJarToBuildPath(IPath path, IJavaProject javaProject) throws JavaModelException
- {
- IClasspathEntry newLibraryEntry = JavaCore.newLibraryEntry(path, null, null);
- ProjectCreationHelper.addToClasspath(javaProject, newLibraryEntry);
- }
-
- public static void addVariableEntryToBuildPath(IPath path, IJavaProject javaProject) throws JavaModelException
- {
- IClasspathEntry newLibraryEntry = JavaCore.newVariableEntry(path, null, null);
- ProjectCreationHelper.addToClasspath(javaProject, newLibraryEntry);
- }
-
- /**
- * adds all jar files in this folder to the build path. Searches only on level 1
- *
- * @param folder
- * the folder which contains the jar files
- * @param javaProject
- * @throws CoreException
- */
- public static void addAllJarsToBuildPath(IFolder folder, IJavaProject javaProject) throws CoreException
- {
- try
- {
- folder.refreshLocal(100, new NullProgressMonitor());
- for (IResource resource : folder.members())
- {
-
- if (resource instanceof IFile && resource.getRawLocation().toString().endsWith(".jar"))
- {
- addJarToBuildPath(resource.getRawLocation(), javaProject);
- }
- }
- }
- catch (Exception e)
- {
- e.printStackTrace();
- }
- }
-
- /**
- * @param javaProject
- * @param newEntry
- * @throws JavaModelException
- */
- public final static void addToClasspath(IJavaProject javaProject, IClasspathEntry newEntry) throws JavaModelException
- {
- if (newEntry == null)
- {
- return;
- }
- IClasspathEntry[] oldEntries = javaProject.getRawClasspath();
- IClasspathEntry[] newEntries = new IClasspathEntry[oldEntries.length + 1];
- System.arraycopy(oldEntries, 0, newEntries, 0, oldEntries.length);
-
- newEntries[oldEntries.length] = newEntry;
- javaProject.setRawClasspath(newEntries, null);
- }
-
- /**
- * @param javaProject
- * @param toBeRemoved
- * @throws JavaModelException
- */
- public final static void removeFromClasspath(IJavaProject javaProject, IPath toBeRemoved) throws JavaModelException
- {
- IClasspathEntry[] oldEntries = javaProject.getRawClasspath();
- ArrayList<IClasspathEntry> newEntries = new ArrayList<IClasspathEntry>();
-
- for (IClasspathEntry classpathEntry : oldEntries)
- {
- if (!classpathEntry.getPath().equals(toBeRemoved))
- {
- newEntries.add(classpathEntry);
- }
- }
-
- IClasspathEntry[] newEntriesArray = new IClasspathEntry[newEntries.size()];
- javaProject.setRawClasspath(newEntries.toArray(newEntriesArray), null);
- }
-
- /**
- * @return the newly created java project
- * @throws CoreException
- */
- public IJavaProject createJavaProject() throws CoreException
- {
- IProject project = createProject();
- return createJavaProject(project);
- }
-
- /**
- * Creates a JavaProject prom the given project
- *
- * @param project
- * @return the created JavaProject
- */
- public IJavaProject createJavaProject(IProject project)
- {
- try
- {
- // addJavaNature(project);
- IJavaProject javaProject = JavaCore.create(project);
- if (!javaProject.isOpen())
- {
- javaProject.open(null);
- }
- createBinFolder(project, javaProject);
- clearSourcePath(javaProject);
-
- IClasspathEntry sourceFolder = createSourceFolder("src", project);
-
- addToClasspath(javaProject, sourceFolder);
- addJREContainerToProject(javaProject);
- return javaProject;
- }
- catch (CoreException e)
- {
- e.printStackTrace();
- }
- return null;
-
- }
-
- /**
- * @param javaProject
- * @throws JavaModelException
- */
- private void addJREContainerToProject(IJavaProject javaProject) throws JavaModelException
- {
- addToClasspath(javaProject, JavaRuntime.getDefaultJREContainerEntry());
- }
-
- /**
- * @param javaProject
- * @throws JavaModelException
- */
- private void clearSourcePath(IJavaProject javaProject) throws JavaModelException
- {
- javaProject.setRawClasspath(new IClasspathEntry[] {}, new NullProgressMonitor()); // clean classpath, means remove
- // Project root from classpath
- }
-
- /**
- * @param project
- * @throws CoreException
- */
- public void addJavaNature(IProject project) throws CoreException
- {
- IProjectDescription description = project.getDescription();
- String[] natures = description.getNatureIds();
- String[] newNatures = new String[natures.length + 1];
- System.arraycopy(natures, 0, newNatures, 0, natures.length);
- newNatures[natures.length] = JavaCore.NATURE_ID;
- description.setNatureIds(newNatures);
- project.setDescription(description, new NullProgressMonitor());
- }
-
- /**
- * @param path
- * @param project
- * @return
- * @throws CoreException
- */
- private IClasspathEntry createSourceFolder(String path, IProject project) throws CoreException
- {
- IFolder srcFolder = project.getFolder(new Path(path));
- if (!srcFolder.exists())
- {
- srcFolder.create(false, true, null);
- IPath sourceFolderPath = srcFolder.getFullPath();
- IClasspathEntry entry = JavaCore.newSourceEntry(sourceFolderPath);
-
- return entry;
- }
- return null;
- }
-
- /**
- * @param path
- * @param project
- * @param javaProject
- * @return the created source folder
- * @throws CoreException
- */
- public IFolder createSourceFolder(String path, IProject project, IJavaProject javaProject) throws CoreException
- {
- IFolder srcFolder = project.getFolder(new Path(path));
- if (!srcFolder.exists())
- {
- srcFolder.create(false, true, null);
- IPath sourceFolderPath = srcFolder.getFullPath();
- IClasspathEntry entry = JavaCore.newSourceEntry(sourceFolderPath);
- addToClasspath(javaProject, entry);
- return srcFolder;
- }
- return null;
- }
-
- /**
- * @param project
- * @param javaProject
- * @throws CoreException
- * @throws JavaModelException
- */
- private void createBinFolder(IProject project, IJavaProject javaProject) throws CoreException, JavaModelException
- {
- createOutputFolder("bin", project, javaProject);
- }
-
- /**
- * @param project
- * @param javaProject
- * @throws CoreException
- * @throws JavaModelException
- */
- private void createOutputFolder(String path, IProject project, IJavaProject javaProject) throws CoreException,
- JavaModelException
- {
- try
- {
- IFolder binFolder = project.getFolder(new Path(path));
- if (!binFolder.exists())
- {
- binFolder.create(true, true, null);
- javaProject.setOutputLocation(binFolder.getFullPath(), null);
- }
- }
- catch (Exception e)
- {
- e.printStackTrace();
- }
- }
-
- /**
- * @param name
- * @param project
- * @return the created folder
- */
- public IFolder createFolder(String name, IProject project)
- {
- IFolder folder = project.getFolder(name);
-
- if (!folder.exists())
- {
- try
- {
- folder.create(IResource.NONE, true, null);
- }
- catch (CoreException e)
- {
- e.printStackTrace();
- }
- }
- return folder;
- }
-
- public IFolder getFolder(String name, IProject project)
- {
- IFolder folder = project.getFolder(name);
-
- return folder;
- }
-
- /**
- * @param name
- * @param folder
- * @param content
- * @return the created file
- */
- public IFile createFile(String name, IFolder folder, String content)
- {
- IFile file = folder.getFile("web.xml");
-
- try
- {
-
- if (!file.exists())
- {
- byte[] bytes = content.getBytes();
- InputStream source = new ByteArrayInputStream(bytes);
- file.create(source, IResource.NONE, null);
-
- }
- }
- catch (CoreException e)
- {
- e.printStackTrace();
- }
- return file;
- }
-
- public void setName(String name)
- {
- this.name = name;
- }
-
- public String[] getNatures()
- {
- return natures;
- }
-
- public void setNatures(String[] natures)
- {
- this.natures = natures;
- }
-
- public ProjectCreationHelper()
- {
- }
-
- public static void refreshProject(IResource resource, IProgressMonitor monitor) throws InvocationTargetException,
- InterruptedException
- {
- IRunnableWithProgress op = new WorkspaceModifyOperation(null)
- {
- @Override
- protected void execute(IProgressMonitor monitor) throws CoreException, InterruptedException
- {
- try
- {
- IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
- root.refreshLocal(IResource.DEPTH_INFINITE, monitor);
-
- }
- catch (CoreException e)
- {
-
- e.printStackTrace();
- }
- }
- };
- op.run(monitor);
- }
-}
+/* + * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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 + * + * Contributors: + * Martin Fluegge - initial API and implementation + */ +package org.eclipse.emf.cdo.dawn.codegen.util; + +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IFolder; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IProjectDescription; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.IWorkspaceRoot; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.core.runtime.Path; +import org.eclipse.jdt.core.IClasspathEntry; +import org.eclipse.jdt.core.IJavaProject; +import org.eclipse.jdt.core.JavaCore; +import org.eclipse.jdt.core.JavaModelException; +import org.eclipse.jdt.launching.JavaRuntime; +import org.eclipse.jface.operation.IRunnableWithProgress; +import org.eclipse.ui.actions.WorkspaceModifyOperation; + +import java.io.ByteArrayInputStream; +import java.io.InputStream; +import java.lang.reflect.InvocationTargetException; +import java.util.ArrayList; + +/** + * @author Martin Fluegge + */ +public class ProjectCreationHelper +{ + + private String name; + + private String[] natures; + + public String getName() + { + return name; + } + + public IProject getProject() + { + return ResourcesPlugin.getWorkspace().getRoot().getProject(name); + } + + public IProject createProject() throws CoreException + { + IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(name); + + if (!project.exists()) + { + project.create(null); + } + + if (!project.isOpen()) + { + project.open(null); + } + + IProjectDescription description = project.getDescription(); + description.setNatureIds(natures); + project.setDescription(description, null); + + return project; + } + + /** + * @param path + * @param javaProject + * @throws JavaModelException + */ + public static void addJarToBuildPath(String path, IJavaProject javaProject) throws JavaModelException + { + IClasspathEntry newLibraryEntry = JavaCore.newLibraryEntry(new Path(path), null, null); + ProjectCreationHelper.addToClasspath(javaProject, newLibraryEntry); + } + + public static void addJarToBuildPath(IPath path, IJavaProject javaProject) throws JavaModelException + { + IClasspathEntry newLibraryEntry = JavaCore.newLibraryEntry(path, null, null); + ProjectCreationHelper.addToClasspath(javaProject, newLibraryEntry); + } + + public static void addVariableEntryToBuildPath(IPath path, IJavaProject javaProject) throws JavaModelException + { + IClasspathEntry newLibraryEntry = JavaCore.newVariableEntry(path, null, null); + ProjectCreationHelper.addToClasspath(javaProject, newLibraryEntry); + } + + /** + * adds all jar files in this folder to the build path. Searches only on level 1 + * + * @param folder + * the folder which contains the jar files + * @param javaProject + * @throws CoreException + */ + public static void addAllJarsToBuildPath(IFolder folder, IJavaProject javaProject) throws CoreException + { + try + { + folder.refreshLocal(100, new NullProgressMonitor()); + for (IResource resource : folder.members()) + { + + if (resource instanceof IFile && resource.getRawLocation().toString().endsWith(".jar")) + { + addJarToBuildPath(resource.getRawLocation(), javaProject); + } + } + } + catch (Exception e) + { + e.printStackTrace(); + } + } + + /** + * @param javaProject + * @param newEntry + * @throws JavaModelException + */ + public final static void addToClasspath(IJavaProject javaProject, IClasspathEntry newEntry) throws JavaModelException + { + if (newEntry == null) + { + return; + } + IClasspathEntry[] oldEntries = javaProject.getRawClasspath(); + IClasspathEntry[] newEntries = new IClasspathEntry[oldEntries.length + 1]; + System.arraycopy(oldEntries, 0, newEntries, 0, oldEntries.length); + + newEntries[oldEntries.length] = newEntry; + javaProject.setRawClasspath(newEntries, null); + } + + /** + * @param javaProject + * @param toBeRemoved + * @throws JavaModelException + */ + public final static void removeFromClasspath(IJavaProject javaProject, IPath toBeRemoved) throws JavaModelException + { + IClasspathEntry[] oldEntries = javaProject.getRawClasspath(); + ArrayList<IClasspathEntry> newEntries = new ArrayList<IClasspathEntry>(); + + for (IClasspathEntry classpathEntry : oldEntries) + { + if (!classpathEntry.getPath().equals(toBeRemoved)) + { + newEntries.add(classpathEntry); + } + } + + IClasspathEntry[] newEntriesArray = new IClasspathEntry[newEntries.size()]; + javaProject.setRawClasspath(newEntries.toArray(newEntriesArray), null); + } + + /** + * @return the newly created java project + * @throws CoreException + */ + public IJavaProject createJavaProject() throws CoreException + { + IProject project = createProject(); + return createJavaProject(project); + } + + /** + * Creates a JavaProject prom the given project + * + * @param project + * @return the created JavaProject + */ + public IJavaProject createJavaProject(IProject project) + { + try + { + // addJavaNature(project); + IJavaProject javaProject = JavaCore.create(project); + if (!javaProject.isOpen()) + { + javaProject.open(null); + } + createBinFolder(project, javaProject); + clearSourcePath(javaProject); + + IClasspathEntry sourceFolder = createSourceFolder("src", project); + + addToClasspath(javaProject, sourceFolder); + addJREContainerToProject(javaProject); + return javaProject; + } + catch (CoreException e) + { + e.printStackTrace(); + } + return null; + + } + + /** + * @param javaProject + * @throws JavaModelException + */ + private void addJREContainerToProject(IJavaProject javaProject) throws JavaModelException + { + addToClasspath(javaProject, JavaRuntime.getDefaultJREContainerEntry()); + } + + /** + * @param javaProject + * @throws JavaModelException + */ + private void clearSourcePath(IJavaProject javaProject) throws JavaModelException + { + javaProject.setRawClasspath(new IClasspathEntry[] {}, new NullProgressMonitor()); // clean classpath, means remove + // Project root from classpath + } + + /** + * @param project + * @throws CoreException + */ + public void addJavaNature(IProject project) throws CoreException + { + IProjectDescription description = project.getDescription(); + String[] natures = description.getNatureIds(); + String[] newNatures = new String[natures.length + 1]; + System.arraycopy(natures, 0, newNatures, 0, natures.length); + newNatures[natures.length] = JavaCore.NATURE_ID; + description.setNatureIds(newNatures); + project.setDescription(description, new NullProgressMonitor()); + } + + /** + * @param path + * @param project + * @return + * @throws CoreException + */ + private IClasspathEntry createSourceFolder(String path, IProject project) throws CoreException + { + IFolder srcFolder = project.getFolder(new Path(path)); + if (!srcFolder.exists()) + { + srcFolder.create(false, true, null); + IPath sourceFolderPath = srcFolder.getFullPath(); + IClasspathEntry entry = JavaCore.newSourceEntry(sourceFolderPath); + + return entry; + } + return null; + } + + /** + * @param path + * @param project + * @param javaProject + * @return the created source folder + * @throws CoreException + */ + public IFolder createSourceFolder(String path, IProject project, IJavaProject javaProject) throws CoreException + { + IFolder srcFolder = project.getFolder(new Path(path)); + if (!srcFolder.exists()) + { + srcFolder.create(false, true, null); + IPath sourceFolderPath = srcFolder.getFullPath(); + IClasspathEntry entry = JavaCore.newSourceEntry(sourceFolderPath); + addToClasspath(javaProject, entry); + return srcFolder; + } + return null; + } + + /** + * @param project + * @param javaProject + * @throws CoreException + * @throws JavaModelException + */ + private void createBinFolder(IProject project, IJavaProject javaProject) throws CoreException, JavaModelException + { + createOutputFolder("bin", project, javaProject); + } + + /** + * @param project + * @param javaProject + * @throws CoreException + * @throws JavaModelException + */ + private void createOutputFolder(String path, IProject project, IJavaProject javaProject) throws CoreException, + JavaModelException + { + try + { + IFolder binFolder = project.getFolder(new Path(path)); + if (!binFolder.exists()) + { + binFolder.create(true, true, null); + javaProject.setOutputLocation(binFolder.getFullPath(), null); + } + } + catch (Exception e) + { + e.printStackTrace(); + } + } + + /** + * @param name + * @param project + * @return the created folder + */ + public IFolder createFolder(String name, IProject project) + { + IFolder folder = project.getFolder(name); + + if (!folder.exists()) + { + try + { + folder.create(IResource.NONE, true, null); + } + catch (CoreException e) + { + e.printStackTrace(); + } + } + return folder; + } + + public IFolder getFolder(String name, IProject project) + { + IFolder folder = project.getFolder(name); + + return folder; + } + + /** + * @param name + * @param folder + * @param content + * @return the created file + */ + public IFile createFile(String name, IFolder folder, String content) + { + IFile file = folder.getFile("web.xml"); + + try + { + + if (!file.exists()) + { + byte[] bytes = content.getBytes(); + InputStream source = new ByteArrayInputStream(bytes); + file.create(source, IResource.NONE, null); + + } + } + catch (CoreException e) + { + e.printStackTrace(); + } + return file; + } + + public void setName(String name) + { + this.name = name; + } + + public String[] getNatures() + { + return natures; + } + + public void setNatures(String[] natures) + { + this.natures = natures; + } + + public ProjectCreationHelper() + { + } + + public static void refreshProject(IResource resource, IProgressMonitor monitor) throws InvocationTargetException, + InterruptedException + { + IRunnableWithProgress op = new WorkspaceModifyOperation(null) + { + @Override + protected void execute(IProgressMonitor monitor) throws CoreException, InterruptedException + { + try + { + IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); + root.refreshLocal(IResource.DEPTH_INFINITE, monitor); + + } + catch (CoreException e) + { + + e.printStackTrace(); + } + } + }; + op.run(monitor); + } +} diff --git a/plugins/org.eclipse.emf.cdo.dawn.codegen/src/org/eclipse/emf/cdo/dawn/codegen/util/Utils.ext b/plugins/org.eclipse.emf.cdo.dawn.codegen/src/org/eclipse/emf/cdo/dawn/codegen/util/Utils.ext index f264141018..b031dd704f 100644 --- a/plugins/org.eclipse.emf.cdo.dawn.codegen/src/org/eclipse/emf/cdo/dawn/codegen/util/Utils.ext +++ b/plugins/org.eclipse.emf.cdo.dawn.codegen/src/org/eclipse/emf/cdo/dawn/codegen/util/Utils.ext @@ -1,51 +1,51 @@ -/**
- * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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
- *
- * Contributors:
- * Martin Fluegge - initial API and implementation
- */
-import emf;
-import genmodel;
-import ecore;
-
-String timestamp() :
- JAVA org.eclipse.emf.cdo.dawn.codegen.util.Utils.timestamp();
-
- String getPackagePath() :
- JAVA org.eclipse.emf.cdo.dawn.codegen.util.Utils.getPackagePath();
-
- String getPackageName() :
- JAVA org.eclipse.emf.cdo.dawn.codegen.util.Utils.getPackageName();
-
- String getDiagramPluginID() :
- JAVA org.eclipse.emf.cdo.dawn.codegen.util.Utils.getDiagramPluginID();
-
- String setDiagramPackage(String s) :
- JAVA org.eclipse.emf.cdo.dawn.codegen.util.Utils.setDiagramPackage(java.lang.String);
-
- String getDiagramPackage() :
- JAVA org.eclipse.emf.cdo.dawn.codegen.util.Utils.getDiagramPackage();
-
- String getDiagramPackagePath() :
- JAVA org.eclipse.emf.cdo.dawn.codegen.util.Utils.getDiagramPackagePath();
-
- String getRootPackage() :
- JAVA org.eclipse.emf.cdo.dawn.codegen.util.Utils.getRootPackage();
-
- String getUniqueIdentifierName(String s ) :
- JAVA org.eclipse.emf.cdo.dawn.codegen.util.Utils.getUniqueIdentifierName(java.lang.String);
-
- String toModelName(String s ) :
- JAVA org.eclipse.emf.cdo.dawn.codegen.util.Utils.toModelName(java.lang.String);
-
- String toModelNameFromGetterName(String s ) :
- JAVA org.eclipse.emf.cdo.dawn.codegen.util.Utils.toModelNameFromGetterName(java.lang.String);
-
- String getEMFFileName(List genPackages) :
- JAVA org.eclipse.emf.cdo.dawn.codegen.util.Utils.getEMFFileName(java.util.List);
-
+/** + * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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 + * + * Contributors: + * Martin Fluegge - initial API and implementation + */ +import emf; +import genmodel; +import ecore; + +String timestamp() : + JAVA org.eclipse.emf.cdo.dawn.codegen.util.Utils.timestamp(); + + String getPackagePath() : + JAVA org.eclipse.emf.cdo.dawn.codegen.util.Utils.getPackagePath(); + + String getPackageName() : + JAVA org.eclipse.emf.cdo.dawn.codegen.util.Utils.getPackageName(); + + String getDiagramPluginID() : + JAVA org.eclipse.emf.cdo.dawn.codegen.util.Utils.getDiagramPluginID(); + + String setDiagramPackage(String s) : + JAVA org.eclipse.emf.cdo.dawn.codegen.util.Utils.setDiagramPackage(java.lang.String); + + String getDiagramPackage() : + JAVA org.eclipse.emf.cdo.dawn.codegen.util.Utils.getDiagramPackage(); + + String getDiagramPackagePath() : + JAVA org.eclipse.emf.cdo.dawn.codegen.util.Utils.getDiagramPackagePath(); + + String getRootPackage() : + JAVA org.eclipse.emf.cdo.dawn.codegen.util.Utils.getRootPackage(); + + String getUniqueIdentifierName(String s ) : + JAVA org.eclipse.emf.cdo.dawn.codegen.util.Utils.getUniqueIdentifierName(java.lang.String); + + String toModelName(String s ) : + JAVA org.eclipse.emf.cdo.dawn.codegen.util.Utils.toModelName(java.lang.String); + + String toModelNameFromGetterName(String s ) : + JAVA org.eclipse.emf.cdo.dawn.codegen.util.Utils.toModelNameFromGetterName(java.lang.String); + + String getEMFFileName(List genPackages) : + JAVA org.eclipse.emf.cdo.dawn.codegen.util.Utils.getEMFFileName(java.util.List); +
\ No newline at end of file diff --git a/plugins/org.eclipse.emf.cdo.dawn.codegen/src/org/eclipse/emf/cdo/dawn/codegen/util/Utils.java b/plugins/org.eclipse.emf.cdo.dawn.codegen/src/org/eclipse/emf/cdo/dawn/codegen/util/Utils.java index 11d4d9c967..73097da65c 100644 --- a/plugins/org.eclipse.emf.cdo.dawn.codegen/src/org/eclipse/emf/cdo/dawn/codegen/util/Utils.java +++ b/plugins/org.eclipse.emf.cdo.dawn.codegen/src/org/eclipse/emf/cdo/dawn/codegen/util/Utils.java @@ -1,115 +1,115 @@ -/*
- * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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
- *
- * Contributors:
- * Martin Fluegge - initial API and implementation
- */
-package org.eclipse.emf.cdo.dawn.codegen.util;
-
-import org.eclipse.emf.codegen.ecore.genmodel.GenPackage;
-
-import org.eclipse.swt.widgets.Canvas;
-
-import java.util.List;
-
-/**
- * @author Martin Fluegge
- */
-public class Utils
-{
- public static String packagePath = "";
-
- public static String packageName = "";
-
- public static String diagramPluginID = "";
-
- public static String diagramPackage = "";
-
- public static String timestamp()
- {
- return String.valueOf(System.currentTimeMillis());
- }
-
- public static String getPackagePath()
- {
- return packagePath;
- }
-
- public static String getPackageName()
- {
- return packageName;
- }
-
- public static String getDiagramPluginID()
- {
- return diagramPluginID;
- }
-
- public static String setGlobals(Canvas e)
- {
- // packageName=e.getName();
- // packagePath=e.getName().replace(".", "/");
- return "";
- }
-
- public static String setPackage(String pName)
- {
- diagramPluginID = pName + ".diagram";
- packageName = pName.replace("class", "clazz");
- packagePath = pName.replace(".", "/");
- return "";
- }
-
- public static String setDiagramPackage(String pName)
- {
- diagramPackage = pName;
- return "";
- }
-
- public static String getDiagramPackage()
- {
- return diagramPackage;
- }
-
- public static String getRootPackage()
- {
- String ret = diagramPackage.replace(".diagram", "");
- return ret;
- }
-
- public static String getDiagramPackagePath()
- {
- return diagramPackage.replace(".", "/");
- }
-
- public static String getUniqueIdentifierName(String uniqueIdentifier)
- {
- String ret = uniqueIdentifier.substring(uniqueIdentifier.lastIndexOf(".") + 1, uniqueIdentifier.length());
- return ret;
- }
-
- public static String toModelName(String uniqueIdentifier)
- {
- String ret = uniqueIdentifier.substring(uniqueIdentifier.lastIndexOf(".") + 1, uniqueIdentifier.length());
- ret = ret.substring(0, ret.lastIndexOf("_"));
- return ret;
- }
-
- public static String toModelNameFromGetterName(String uniqueIdentifier)
- {
- String ret = uniqueIdentifier.replace("getFigure", "");
- return ret;
- }
-
- /**
- * @since 1.0
- */
- public static String getEMFFileName(List<GenPackage> genPackages)
- {
- return genPackages.get(0).getFileExtension();
- }
-}
+/* + * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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 + * + * Contributors: + * Martin Fluegge - initial API and implementation + */ +package org.eclipse.emf.cdo.dawn.codegen.util; + +import org.eclipse.emf.codegen.ecore.genmodel.GenPackage; + +import org.eclipse.swt.widgets.Canvas; + +import java.util.List; + +/** + * @author Martin Fluegge + */ +public class Utils +{ + public static String packagePath = ""; + + public static String packageName = ""; + + public static String diagramPluginID = ""; + + public static String diagramPackage = ""; + + public static String timestamp() + { + return String.valueOf(System.currentTimeMillis()); + } + + public static String getPackagePath() + { + return packagePath; + } + + public static String getPackageName() + { + return packageName; + } + + public static String getDiagramPluginID() + { + return diagramPluginID; + } + + public static String setGlobals(Canvas e) + { + // packageName=e.getName(); + // packagePath=e.getName().replace(".", "/"); + return ""; + } + + public static String setPackage(String pName) + { + diagramPluginID = pName + ".diagram"; + packageName = pName.replace("class", "clazz"); + packagePath = pName.replace(".", "/"); + return ""; + } + + public static String setDiagramPackage(String pName) + { + diagramPackage = pName; + return ""; + } + + public static String getDiagramPackage() + { + return diagramPackage; + } + + public static String getRootPackage() + { + String ret = diagramPackage.replace(".diagram", ""); + return ret; + } + + public static String getDiagramPackagePath() + { + return diagramPackage.replace(".", "/"); + } + + public static String getUniqueIdentifierName(String uniqueIdentifier) + { + String ret = uniqueIdentifier.substring(uniqueIdentifier.lastIndexOf(".") + 1, uniqueIdentifier.length()); + return ret; + } + + public static String toModelName(String uniqueIdentifier) + { + String ret = uniqueIdentifier.substring(uniqueIdentifier.lastIndexOf(".") + 1, uniqueIdentifier.length()); + ret = ret.substring(0, ret.lastIndexOf("_")); + return ret; + } + + public static String toModelNameFromGetterName(String uniqueIdentifier) + { + String ret = uniqueIdentifier.replace("getFigure", ""); + return ret; + } + + /** + * @since 1.0 + */ + public static String getEMFFileName(List<GenPackage> genPackages) + { + return genPackages.get(0).getFileExtension(); + } +} |