diff options
13 files changed, 316 insertions, 8 deletions
diff --git a/plugins/org.eclipse.emf.cdo.migrator/.classpath b/plugins/org.eclipse.emf.cdo.migrator/.classpath index 64c5e31b7a..c72f04c2a0 100644 --- a/plugins/org.eclipse.emf.cdo.migrator/.classpath +++ b/plugins/org.eclipse.emf.cdo.migrator/.classpath @@ -3,5 +3,6 @@ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/> <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> <classpathentry kind="src" path="src"/> + <classpathentry kind="src" output="bin.tasks" path="tasks"/> <classpathentry kind="output" path="bin"/> </classpath> diff --git a/plugins/org.eclipse.emf.cdo.migrator/.externalToolBuilders/org.eclipse.emf.cdo.migrator.build-ant-tasks.launch b/plugins/org.eclipse.emf.cdo.migrator/.externalToolBuilders/org.eclipse.emf.cdo.migrator.build-ant-tasks.launch new file mode 100644 index 0000000000..5200a489cc --- /dev/null +++ b/plugins/org.eclipse.emf.cdo.migrator/.externalToolBuilders/org.eclipse.emf.cdo.migrator.build-ant-tasks.launch @@ -0,0 +1,15 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<launchConfiguration type="org.eclipse.ant.AntBuilderLaunchConfigurationType"> +<stringAttribute key="org.eclipse.ant.ui.ATTR_ANT_CLEAN_TARGETS" value="clean.jars,"/> +<booleanAttribute key="org.eclipse.ant.ui.ATTR_TARGETS_UPDATED" value="true"/> +<booleanAttribute key="org.eclipse.ant.ui.DEFAULT_VM_INSTALL" value="false"/> +<stringAttribute key="org.eclipse.debug.core.ATTR_REFRESH_SCOPE" value="${working_set:<?xml version="1.0" encoding="UTF-8"?> <resources> <item path="/org.eclipse.emf.cdo.migrator" type="4"/> </resources>}"/> +<booleanAttribute key="org.eclipse.debug.ui.ATTR_LAUNCH_IN_BACKGROUND" value="false"/> +<stringAttribute key="org.eclipse.jdt.launching.CLASSPATH_PROVIDER" value="org.eclipse.ant.ui.AntClasspathProvider"/> +<booleanAttribute key="org.eclipse.jdt.launching.DEFAULT_CLASSPATH" value="true"/> +<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="org.eclipse.emf.cdo.migrator"/> +<stringAttribute key="org.eclipse.ui.externaltools.ATTR_BUILD_SCOPE" value="${working_set:<?xml version="1.0" encoding="UTF-8"?> <resources> <item path="/org.eclipse.emf.cdo.migrator" type="4"/> </resources>}"/> +<stringAttribute key="org.eclipse.ui.externaltools.ATTR_LOCATION" value="${workspace_loc:/org.eclipse.emf.cdo.migrator/build-ant-tasks.ant}"/> +<stringAttribute key="org.eclipse.ui.externaltools.ATTR_RUN_BUILD_KINDS" value="incremental,auto,clean"/> +<booleanAttribute key="org.eclipse.ui.externaltools.ATTR_TRIGGERS_CONFIGURED" value="true"/> +</launchConfiguration> diff --git a/plugins/org.eclipse.emf.cdo.migrator/.gitignore b/plugins/org.eclipse.emf.cdo.migrator/.gitignore new file mode 100644 index 0000000000..3472e076eb --- /dev/null +++ b/plugins/org.eclipse.emf.cdo.migrator/.gitignore @@ -0,0 +1 @@ +/bin.tasks/ diff --git a/plugins/org.eclipse.emf.cdo.migrator/.project b/plugins/org.eclipse.emf.cdo.migrator/.project index 290779ac72..d2cd2b05a8 100644 --- a/plugins/org.eclipse.emf.cdo.migrator/.project +++ b/plugins/org.eclipse.emf.cdo.migrator/.project @@ -37,6 +37,19 @@ </dictionary> </arguments> </buildCommand> + <buildCommand> + <name>org.eclipse.ui.externaltools.ExternalToolBuilder</name> + <arguments> + <dictionary> + <key>LaunchConfigHandle</key> + <value><project>/.externalToolBuilders/org.eclipse.emf.cdo.migrator.build-ant-tasks.launch</value> + </dictionary> + <dictionary> + <key>incclean</key> + <value>true</value> + </dictionary> + </arguments> + </buildCommand> </buildSpec> <natures> <nature>org.eclipse.pde.PluginNature</nature> diff --git a/plugins/org.eclipse.emf.cdo.migrator/.settings/org.eclipse.pde.prefs b/plugins/org.eclipse.emf.cdo.migrator/.settings/org.eclipse.pde.prefs index fe01bb701d..65c53e83db 100644 --- a/plugins/org.eclipse.emf.cdo.migrator/.settings/org.eclipse.pde.prefs +++ b/plugins/org.eclipse.emf.cdo.migrator/.settings/org.eclipse.pde.prefs @@ -1,13 +1,14 @@ -#Thu Feb 04 09:44:24 CET 2010 compilers.f.unresolved-features=1 compilers.f.unresolved-plugins=1 compilers.incompatible-environment=1 compilers.p.build=1 compilers.p.build.bin.includes=1 +compilers.p.build.encodings=2 +compilers.p.build.java.compiler=2 compilers.p.build.java.compliance=1 compilers.p.build.missing.output=2 -compilers.p.build.output.library=1 -compilers.p.build.source.library=1 +compilers.p.build.output.library=2 +compilers.p.build.source.library=2 compilers.p.build.src.includes=1 compilers.p.deprecated=2 compilers.p.discouraged-class=1 @@ -17,7 +18,9 @@ compilers.p.missing-version-export-package=1 compilers.p.missing-version-import-package=1 compilers.p.missing-version-require-bundle=1 compilers.p.no-required-att=0 +compilers.p.no.automatic.module=1 compilers.p.not-externalized-att=2 +compilers.p.service.component.without.lazyactivation=1 compilers.p.unknown-attribute=1 compilers.p.unknown-class=1 compilers.p.unknown-element=1 diff --git a/plugins/org.eclipse.emf.cdo.migrator/META-INF/MANIFEST.MF b/plugins/org.eclipse.emf.cdo.migrator/META-INF/MANIFEST.MF index f0f97a5a42..e48dcaeed8 100644 --- a/plugins/org.eclipse.emf.cdo.migrator/META-INF/MANIFEST.MF +++ b/plugins/org.eclipse.emf.cdo.migrator/META-INF/MANIFEST.MF @@ -12,7 +12,9 @@ Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.5.0,4.0.0)", org.eclipse.ui;bundle-version="[3.5.0,4.0.0)", org.eclipse.emf.ecore.xmi;bundle-version="[2.5.0,3.0.0)", org.eclipse.emf.importer;bundle-version="[2.5.0,3.0.0)", - org.eclipse.net4j.util.ui;bundle-version="[3.6.0,4.0.0)" + org.eclipse.net4j.util.ui;bundle-version="[3.6.0,4.0.0)", + org.eclipse.ant.core;bundle-version="[3.5.0,4.0.0)";resolution:=optional, + org.apache.ant;bundle-version="[1.0.0,2.0.0)";resolution:=optional Export-Package: org.eclipse.emf.cdo.internal.messages;version="3.0.200";x-internal:=true, org.eclipse.emf.cdo.internal.migrator;version="3.0.800";x-internal:=true, org.eclipse.emf.cdo.internal.migrator.actions;version="3.0.800";x-internal:=true, diff --git a/plugins/org.eclipse.emf.cdo.migrator/ant_tasks/.gitignore b/plugins/org.eclipse.emf.cdo.migrator/ant_tasks/.gitignore new file mode 100644 index 0000000000..947a3210ed --- /dev/null +++ b/plugins/org.eclipse.emf.cdo.migrator/ant_tasks/.gitignore @@ -0,0 +1 @@ +cdo.ant.tasks.jar diff --git a/plugins/org.eclipse.emf.cdo.migrator/build-ant-tasks.ant b/plugins/org.eclipse.emf.cdo.migrator/build-ant-tasks.ant new file mode 100644 index 0000000000..434d9e7e34 --- /dev/null +++ b/plugins/org.eclipse.emf.cdo.migrator/build-ant-tasks.ant @@ -0,0 +1,28 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + Copyright (c) 2018 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 +--> +<project name="build-ant-tasks" default="build-ant-tasks" basedir="."> + + <property name="jar.name" value="cdo.ant.tasks"/> + + <target name="build-ant-tasks"> + <jar destfile="ant_tasks/${jar.name}.jar"> + <fileset dir="bin.tasks"> + <include name="**/*.class"/> + </fileset> + </jar> + </target> + + <target name="clean.jars"> + <delete file="ant_tasks/${jar.name}.jar" failonerror="false"/> + </target> + +</project> diff --git a/plugins/org.eclipse.emf.cdo.migrator/build.properties b/plugins/org.eclipse.emf.cdo.migrator/build.properties index 54c0ae740c..c2d9dac0a3 100644 --- a/plugins/org.eclipse.emf.cdo.migrator/build.properties +++ b/plugins/org.eclipse.emf.cdo.migrator/build.properties @@ -18,11 +18,18 @@ bin.includes = .,\ about.ini,\ about.mappings,\ about.properties,\ - modeling32.png -jars.compile.order = . + modeling32.png,\ + ant_tasks/,\ + ant_tasks/cdo.ant.tasks.jar +src.includes = about.html,\ + pom.xml,\ + build-ant-tasks.ant +jars.compile.order = .,\ + ant_tasks/cdo.ant.tasks.jar source.. = src/ output.. = bin/ -src.includes = about.html,\ - pom.xml +source.ant_tasks/cdo.ant.tasks.jar = tasks/ +output.ant_tasks/cdo.ant.tasks.jar = bin.tasks/ generateSourceReferences = true +bin.excludes = ant_tasks/.gitignore diff --git a/plugins/org.eclipse.emf.cdo.migrator/plugin.xml b/plugins/org.eclipse.emf.cdo.migrator/plugin.xml index fb99b24448..80620a1aa0 100644 --- a/plugins/org.eclipse.emf.cdo.migrator/plugin.xml +++ b/plugins/org.eclipse.emf.cdo.migrator/plugin.xml @@ -54,4 +54,13 @@ </objectContribution> </extension> + <extension point="org.eclipse.ant.core.extraClasspathEntries"> + <extraClasspathEntry library="ant_tasks/cdo.ant.tasks.jar" /> + </extension> + + <extension point="org.eclipse.ant.core.antTasks"> + <antTask library="ant_tasks/cdo.ant.tasks.jar" name="cdo.ProjectImport" headless="true" class="org.eclipse.emf.cdo.migrator.tasks.ProjectImportTask" /> + <antTask library="ant_tasks/cdo.ant.tasks.jar" name="cdo.ProjectDelete" headless="true" class="org.eclipse.emf.cdo.migrator.tasks.ProjectDeleteTask" /> + </extension> + </plugin> diff --git a/plugins/org.eclipse.emf.cdo.migrator/tasks/org/eclipse/emf/cdo/migrator/tasks/CDOTask.java b/plugins/org.eclipse.emf.cdo.migrator/tasks/org/eclipse/emf/cdo/migrator/tasks/CDOTask.java new file mode 100644 index 0000000000..3eccd7943e --- /dev/null +++ b/plugins/org.eclipse.emf.cdo.migrator/tasks/org/eclipse/emf/cdo/migrator/tasks/CDOTask.java @@ -0,0 +1,93 @@ +/* + * Copyright (c) 2018 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 + */ +package org.eclipse.emf.cdo.migrator.tasks; + +import org.eclipse.ant.core.AntCorePlugin; +import org.eclipse.core.resources.IWorkspace; +import org.eclipse.core.resources.IWorkspaceRoot; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.NullProgressMonitor; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.Task; + +/** + * @author Eike Stepper + */ +public abstract class CDOTask extends Task +{ + protected IWorkspace workspace; + + protected IWorkspaceRoot root; + + @Override + public final void execute() throws BuildException + { + checkAttributes(); + + try + { + workspace = ResourcesPlugin.getWorkspace(); + root = workspace.getRoot(); + + doExecute(); + } + catch (Exception e) + { + if (e instanceof BuildException) + { + throw (BuildException)e; + } + + throw new BuildException(e); + } + } + + /** + * Subclasses may override. + */ + protected void checkAttributes() throws BuildException + { + // Do nothing. + } + + protected abstract void doExecute() throws Exception; + + protected final IProgressMonitor getProgressMonitor() + { + try + { + if (getProject() != null) + { + IProgressMonitor progressMonitor = (IProgressMonitor)getProject().getReferences().get(AntCorePlugin.ECLIPSE_PROGRESS_MONITOR); + if (progressMonitor != null) + { + return progressMonitor; + } + } + } + catch (Exception ex) + { + // Do nothing. + } + + return new NullProgressMonitor(); + } + + public static void assertTrue(String message, boolean expression) throws BuildException + { + if (!expression) + { + throw new BuildException(message); + } + } +} diff --git a/plugins/org.eclipse.emf.cdo.migrator/tasks/org/eclipse/emf/cdo/migrator/tasks/ProjectDeleteTask.java b/plugins/org.eclipse.emf.cdo.migrator/tasks/org/eclipse/emf/cdo/migrator/tasks/ProjectDeleteTask.java new file mode 100644 index 0000000000..b58e82fb47 --- /dev/null +++ b/plugins/org.eclipse.emf.cdo.migrator/tasks/org/eclipse/emf/cdo/migrator/tasks/ProjectDeleteTask.java @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2018 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 + */ +package org.eclipse.emf.cdo.migrator.tasks; + +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.NullProgressMonitor; + +import org.apache.tools.ant.BuildException; + +/** + * @author Eike Stepper + */ +public class ProjectDeleteTask extends CDOTask +{ + private String projectName; + + private boolean deleteContent; + + public void setProjectName(String projectName) + { + this.projectName = projectName; + } + + public void setDeleteContent(boolean deleteContent) + { + this.deleteContent = deleteContent; + } + + @Override + protected void checkAttributes() throws BuildException + { + assertTrue("'projectName' must be specified.", projectName != null && projectName.length() != 0); + } + + @Override + protected void doExecute() throws Exception + { + IProject project = root.getProject(projectName); + if (!project.exists()) + { + System.out.println("Project " + projectName + " does not exist."); + return; + } + + System.out.println("Deleting project " + projectName + " ..."); + project.delete(deleteContent, true, new NullProgressMonitor()); + } +} diff --git a/plugins/org.eclipse.emf.cdo.migrator/tasks/org/eclipse/emf/cdo/migrator/tasks/ProjectImportTask.java b/plugins/org.eclipse.emf.cdo.migrator/tasks/org/eclipse/emf/cdo/migrator/tasks/ProjectImportTask.java new file mode 100644 index 0000000000..36c57f25ea --- /dev/null +++ b/plugins/org.eclipse.emf.cdo.migrator/tasks/org/eclipse/emf/cdo/migrator/tasks/ProjectImportTask.java @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2018 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 + */ +package org.eclipse.emf.cdo.migrator.tasks; + +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IProjectDescription; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.core.runtime.Path; + +import org.apache.tools.ant.BuildException; + +import java.io.File; + +/** + * @author Eike Stepper + */ +public class ProjectImportTask extends CDOTask +{ + private String projectName; + + private File location; + + public void setProjectName(String projectName) + { + this.projectName = projectName; + } + + public void setLocation(File location) + { + this.location = location; + } + + @Override + protected void checkAttributes() throws BuildException + { + assertTrue("'projectName' must be specified.", projectName != null && projectName.length() != 0); + assertTrue("'location' must be specified.", location != null); + assertTrue("'location' must be point to an existing directory.", location.isDirectory()); + } + + @Override + protected void doExecute() throws Exception + { + IProject project = root.getProject(projectName); + if (project.exists()) + { + File existingLocation = new File(project.getLocation().toOSString()).getCanonicalFile(); + if (!existingLocation.equals(location)) + { + throw new BuildException("Project " + projectName + " exists in different location: " + existingLocation); + } + + System.out.println("Project " + location + " is already imported."); + return; + } + + System.out.println("Importing project " + location + " ..."); + IPath locationPath = new Path(location.getAbsolutePath()); + + IProjectDescription projectDescription = workspace.newProjectDescription(projectName); + projectDescription.setLocation(locationPath); + + project.create(projectDescription, new NullProgressMonitor()); + + if (!project.isOpen()) + { + project.open(new NullProgressMonitor()); + } + } +} |