|
|
|
|
@@ -1,6 +1,6 @@
|
|
|
|
|
#!/usr/bin/python
|
|
|
|
|
#
|
|
|
|
|
# Copyright 2016 Google Inc. All Rights Reserved.
|
|
|
|
|
# Copyright 2016 The Domain Registry Authors. All Rights Reserved.
|
|
|
|
|
#
|
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
# you may not use this file except in compliance with the License.
|
|
|
|
|
@@ -14,7 +14,7 @@
|
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
|
# limitations under the License.
|
|
|
|
|
|
|
|
|
|
"Script for generating eclipse .project and .classpath files."
|
|
|
|
|
"""Script for generating eclipse .project and .classpath files."""
|
|
|
|
|
|
|
|
|
|
import os
|
|
|
|
|
import subprocess
|
|
|
|
|
@@ -34,17 +34,14 @@ def bazel_info(key):
|
|
|
|
|
The output of the bazel info invocation as a string. If multiple lines
|
|
|
|
|
are returned by bazel info, only the first line is returned.
|
|
|
|
|
"""
|
|
|
|
|
bazel_process = subprocess.Popen(
|
|
|
|
|
["bazel", "info", key],
|
|
|
|
|
stdout=subprocess.PIPE,
|
|
|
|
|
)
|
|
|
|
|
bazel_process = subprocess.Popen(["bazel", "info", key],
|
|
|
|
|
stdout=subprocess.PIPE)
|
|
|
|
|
result = [line.strip() for line in iter(bazel_process.stdout.readline, "")]
|
|
|
|
|
return result[0]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def classpath_entry_xml(kind, path):
|
|
|
|
|
"""
|
|
|
|
|
Generates an eclipse xml classpath entry.
|
|
|
|
|
"""Generates an eclipse xml classpath entry.
|
|
|
|
|
|
|
|
|
|
Args:
|
|
|
|
|
kind: Kind of classpath entry.
|
|
|
|
|
@@ -56,13 +53,11 @@ def classpath_entry_xml(kind, path):
|
|
|
|
|
xml classpath entry element with the specified kind and path.
|
|
|
|
|
"""
|
|
|
|
|
return "<classpathentry kind=\"{kind}\" path=\"{path}\"/>".format(
|
|
|
|
|
kind=kind, path=path,
|
|
|
|
|
)
|
|
|
|
|
kind=kind, path=path)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def classpath_xml(entries):
|
|
|
|
|
"""
|
|
|
|
|
Produces the xml for an eclipse classpath file.
|
|
|
|
|
"""Produces the xml for an eclipse classpath file.
|
|
|
|
|
|
|
|
|
|
Args:
|
|
|
|
|
entries: list of dictionaries in the form of:
|
|
|
|
|
@@ -74,8 +69,8 @@ def classpath_xml(entries):
|
|
|
|
|
Returns:
|
|
|
|
|
Contents of the eclipse .classpath file.
|
|
|
|
|
"""
|
|
|
|
|
entries_xml = "\n".join([
|
|
|
|
|
" " + classpath_entry_xml(**entry) for entry in entries])
|
|
|
|
|
entries_xml = "\n".join(
|
|
|
|
|
[" " + classpath_entry_xml(**entry) for entry in entries])
|
|
|
|
|
return ('<?xml version="1.0" encoding="UTF-8"?>\n'
|
|
|
|
|
"<classpath>\n"
|
|
|
|
|
"{entries}"
|
|
|
|
|
@@ -83,8 +78,7 @@ def classpath_xml(entries):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def build_classpath():
|
|
|
|
|
"""
|
|
|
|
|
Builds eclipse classpath file
|
|
|
|
|
"""Builds eclipse classpath file.
|
|
|
|
|
|
|
|
|
|
Generates an eclipse .classpath file that has references to all of the
|
|
|
|
|
project source folders, autogenerated source code, and external binary
|
|
|
|
|
@@ -108,13 +102,11 @@ def build_classpath():
|
|
|
|
|
},
|
|
|
|
|
{"kind": "output", "path": "bin"},
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
return classpath_xml(classpath_entries)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def build_project(project_name):
|
|
|
|
|
"""
|
|
|
|
|
Builds eclipse project file
|
|
|
|
|
"""Builds eclipse project file.
|
|
|
|
|
|
|
|
|
|
Uses a very simple template to generate an eclipse .project file
|
|
|
|
|
with a configurable project name.
|
|
|
|
|
@@ -153,8 +145,7 @@ def build_project(project_name):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def factorypath_entry_xml(kind, entry_id):
|
|
|
|
|
"""
|
|
|
|
|
Generates an eclipse xml factorypath entry.
|
|
|
|
|
"""Generates an eclipse xml factorypath entry.
|
|
|
|
|
|
|
|
|
|
Args:
|
|
|
|
|
kind: Kind of factorypath entry.
|
|
|
|
|
@@ -168,9 +159,9 @@ def factorypath_entry_xml(kind, entry_id):
|
|
|
|
|
"enabled=\"true\" runInBatchMode=\"false\"/>").format(
|
|
|
|
|
kind=kind, entry_id=entry_id)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def factorypath_xml(entries):
|
|
|
|
|
"""
|
|
|
|
|
Produces the xml for an eclipse factorypath file.
|
|
|
|
|
"""Produces the xml for an eclipse factorypath file.
|
|
|
|
|
|
|
|
|
|
Args:
|
|
|
|
|
entries: list of dictionaries in the form of:
|
|
|
|
|
@@ -182,16 +173,15 @@ def factorypath_xml(entries):
|
|
|
|
|
Returns:
|
|
|
|
|
Contents of the eclipse .factorypath file.
|
|
|
|
|
"""
|
|
|
|
|
entries_xml = "\n".join([
|
|
|
|
|
" " + factorypath_entry_xml(**entry) for entry in entries])
|
|
|
|
|
entries_xml = "\n".join(
|
|
|
|
|
[" " + factorypath_entry_xml(**entry) for entry in entries])
|
|
|
|
|
return ("<factorypath>\n"
|
|
|
|
|
"{entries}"
|
|
|
|
|
"\n</factorypath>").format(entries=entries_xml)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def build_factorypath():
|
|
|
|
|
"""
|
|
|
|
|
Builds eclipse factorypath file
|
|
|
|
|
"""Builds eclipse factorypath file.
|
|
|
|
|
|
|
|
|
|
Generates an eclipse .factorypath file that links to the jar containing
|
|
|
|
|
all required annotation processors for the project.
|
|
|
|
|
@@ -203,8 +193,7 @@ def build_factorypath():
|
|
|
|
|
annotations_jar = os.path.join(
|
|
|
|
|
bazel_bin,
|
|
|
|
|
"java/google/registry/eclipse"
|
|
|
|
|
"/annotation_processors_ide_deploy.jar",
|
|
|
|
|
)
|
|
|
|
|
"/annotation_processors_ide_deploy.jar")
|
|
|
|
|
factorypath_entries = [
|
|
|
|
|
{
|
|
|
|
|
"kind": "PLUGIN",
|
|
|
|
|
@@ -219,8 +208,7 @@ def build_factorypath():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def build_dependencies():
|
|
|
|
|
"""
|
|
|
|
|
Builds dependencies for producing eclipse project files
|
|
|
|
|
"""Builds dependencies for producing eclipse project files.
|
|
|
|
|
|
|
|
|
|
Runs bazel build for the entire project and builds a single jar with all
|
|
|
|
|
binary dependencies for eclipse to compile the project.
|
|
|
|
|
@@ -233,7 +221,8 @@ def build_dependencies():
|
|
|
|
|
"bazel",
|
|
|
|
|
"build",
|
|
|
|
|
"//java/google/registry/...",
|
|
|
|
|
"//javatests/google/registry/..."])
|
|
|
|
|
"//javatests/google/registry/...",
|
|
|
|
|
])
|
|
|
|
|
|
|
|
|
|
# Builds a giant jar of all compile-time dependencies of the project
|
|
|
|
|
subprocess.check_call([
|
|
|
|
|
@@ -247,12 +236,12 @@ def build_dependencies():
|
|
|
|
|
"bazel",
|
|
|
|
|
"build",
|
|
|
|
|
"//java/google/registry/eclipse"
|
|
|
|
|
":annotation_processors_ide_deploy.jar"
|
|
|
|
|
":annotation_processors_ide_deploy.jar",
|
|
|
|
|
])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
|
"""
|
|
|
|
|
Builds eclipse project files
|
|
|
|
|
"""Builds eclipse project files.
|
|
|
|
|
|
|
|
|
|
Before building the eclipse files, a working bazel build is required.
|
|
|
|
|
After building the eclipse dependencies jar and the tests, eclipse
|
|
|
|
|
@@ -261,8 +250,8 @@ def main():
|
|
|
|
|
build_dependencies()
|
|
|
|
|
workspace_directory = bazel_info("workspace")
|
|
|
|
|
classpath = build_classpath()
|
|
|
|
|
with open(os.path.join(
|
|
|
|
|
workspace_directory, ".classpath"), "w") as classpath_file:
|
|
|
|
|
with open(os.path.join(workspace_directory, ".classpath"),
|
|
|
|
|
"w") as classpath_file:
|
|
|
|
|
classpath_file.write(classpath)
|
|
|
|
|
if len(sys.argv) > 1:
|
|
|
|
|
project_name = sys.argv[1]
|
|
|
|
|
@@ -279,18 +268,17 @@ def main():
|
|
|
|
|
if not os.path.exists(".settings"):
|
|
|
|
|
os.makedirs(".settings")
|
|
|
|
|
# XXX: Avoid wiping out existing settings from org.eclipse.jdt.core.prefs
|
|
|
|
|
with open(os.path.join(
|
|
|
|
|
workspace_directory,
|
|
|
|
|
".settings",
|
|
|
|
|
"org.eclipse.jdt.core.prefs"), "w") as prefs_file:
|
|
|
|
|
with open(os.path.join(workspace_directory,
|
|
|
|
|
".settings",
|
|
|
|
|
"org.eclipse.jdt.core.prefs"), "w") as prefs_file:
|
|
|
|
|
prefs_file.write("\n".join([
|
|
|
|
|
"eclipse.preferences.version=1",
|
|
|
|
|
"org.eclipse.jdt.core.compiler.processAnnotations=enabled",
|
|
|
|
|
]))
|
|
|
|
|
with open(os.path.join(
|
|
|
|
|
workspace_directory,
|
|
|
|
|
".settings",
|
|
|
|
|
"org.eclipse.jdt.apt.core.prefs"), "w") as prefs_file:
|
|
|
|
|
with open(os.path.join(workspace_directory,
|
|
|
|
|
".settings",
|
|
|
|
|
"org.eclipse.jdt.apt.core.prefs"),
|
|
|
|
|
"w") as prefs_file:
|
|
|
|
|
prefs_file.write("\n".join([
|
|
|
|
|
"eclipse.preferences.version=1",
|
|
|
|
|
"org.eclipse.jdt.apt.aptEnabled=true",
|
|
|
|
|
|