Juan Hernandez has uploaded a new change for review.

Change subject: core: Script to generate Eclipse project files
......................................................................

core: Script to generate Eclipse project files

This patch adds a new eclipse.py script in the top level directory
intended to generate the Eclpise project files so that they work out of
the box witn Eclipse.

The way to use the script is to go to the directory where the repository
has been cloned and run it, without arguments:

  cd $HOME/ovirt-engine
  ./eclipse.py

This will create the .project and .classpath files for the projects and
will also create and configure the $HOME/workspace directory. After that
you can run Eclipse and just and import the projects. The will all
compile without further adjustments.

Change-Id: Ieaa012e5d0c7f254d28784660d9c3aa5b5b001d1
Signed-off-by: Juan Hernandez <[email protected]>
---
A eclipse.py
1 file changed, 132 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/56/9556/1

diff --git a/eclipse.py b/eclipse.py
new file mode 100755
index 0000000..d65cf83
--- /dev/null
+++ b/eclipse.py
@@ -0,0 +1,132 @@
+#!/usr/bin/python
+#
+# Copyright 2012 Red Hat
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+# implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import optparse
+import os
+import subprocess
+import sys
+import textwrap
+import traceback
+
+from xml.dom import minidom
+
+
+def runMaven(args):
+    # Prepare the command line:
+    mavenArgs = ["mvn"]
+    mavenArgs.extend(args)
+
+    # Start the process and wait for it to finish:
+    mavenProcess = subprocess.Popen(mavenArgs)
+    mavenRc = mavenProcess.wait()
+    if mavenRc != 0:
+        raise Exception("Maven execution failed with exit code %d." % mavenRc)
+
+
+def addExclusions(projectDir, exclusionPattern):
+    # Locate the .classpath file from the project directory:
+    classpathFile = os.path.join(projectDir, ".classpath")
+    if not os.path.exists(classpathFile):
+        raise Exception("Can't find classpath file \"%s\"." % classpathFile)
+
+    # Load the XML document and find the element corresponding to the main Java
+    # source:
+    classpathDoc = minidom.parse(classpathFile)
+    classpathEntries = classpathDoc.getElementsByTagName("classpathentry")
+    sourceEntry = None
+    for entry in classpathEntries:
+       kind = entry.attributes.get("kind")
+       if kind:
+           kind = kind.value
+       path = entry.attributes.get("path")
+       if path:
+           path = path.value
+       if kind == "src" and path == "src/main/java":
+           sourceEntry = entry
+           break
+    if not sourceEntry:
+        raise Exception("Can't find source entry in classpath file \"%s\"." % 
classpathFile)
+
+    # Add the exclusion pattern:
+    sourceEntry.attributes["excluding"] = exclusionPattern
+
+    # Save the modified document:
+    classpathText = classpathDoc
+    with open(classpathFile, "w") as classpathFd:
+        classpathDoc.writexml(classpathFd)
+
+
+def main():
+    # Create the command line parser:
+    usage = "Usage: %prog [OPTION]..."
+    parser = optparse.OptionParser(usage)
+    parser.description = "A simple script to create Eclipse project files."
+
+    # Help option:
+    help = parser.get_option("--help")
+    help.help = "Show this help message and exit."
+
+    # Option to specify the location of the workspace:
+    parser.add_option(
+        "-w", "--workspace",
+        dest="workspace",
+        help=
+            "Specify the location of the workspace directory. The "
+            "default is the \"workspace\" directory inside the "
+            "home directory of the user.")
+
+    # Parse the command line:
+    options, args = parser.parse_args()
+
+    # Use the eclipse plugin to create the .project and .classpth files for all
+    # the projects:
+    runMaven([
+        "-DdownloadSources=true",
+        "eclipse:eclipse",
+    ])
+
+    # The gwt-extension needs to exclude the directory containing the GWT
+    # overriden classes from the sources:
+    addExclusions("frontend/webadmin/modules/gwt-extension", 
"org/ovirt/engine/ui/uioverrides/")
+
+    # Decide where will be the workspace:
+    if options.workspace:
+        workspaceDir = options.workspace
+    else:
+        homeDir = os.path.expanduser("~")
+        workspaceDir = os.path.join(homeDir, "workspace")
+
+    # Create the workspace directory if doesn't exist:
+    if not os.path.exists(workspaceDir):
+        os.mkdir(workspaceDir)
+
+    # Add the M2_HOME variable to the workspace:
+    runMaven([
+        "-Declipse.workspace=" + workspaceDir,
+        "eclipse:add-maven-repo",
+    ])
+
+
+if __name__ == "__main__":
+    try:
+        main()
+    except SystemExit:
+        raise
+    except:
+        print(traceback.format_exc())
+        sys.exit(1)
+


--
To view, visit http://gerrit.ovirt.org/9556
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ieaa012e5d0c7f254d28784660d9c3aa5b5b001d1
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Juan Hernandez <[email protected]>
_______________________________________________
Engine-patches mailing list
[email protected]
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to