summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorThe Android Open Source Project <initial-contribution@android.com>2013-11-22 16:46:47 -0800
committerThe Android Open Source Project <initial-contribution@android.com>2013-11-22 16:46:47 -0800
commitc61dbe23a4f2f69af9c674af3dad3759b098eae2 (patch)
treeae9cfb2e0a5898ffb899b70807a4175de6fbd9bd /tools
parent7e0d5c29b33f3056aedcb44cb8cbae808c11c35d (diff)
parent8eccbd3b5d90b9f0557c9a01f49d45e98ac85a46 (diff)
Merge commit '8eccbd3b5d90b9f0557c9a01f49d45e98ac85a46' into HEAD
Diffstat (limited to 'tools')
-rw-r--r--tools/emulator/test-apps/ConnectivityTest/Android.mk2
-rw-r--r--tools/emulator/test-apps/GpsLocationTest/Android.mk2
-rw-r--r--tools/idegen/Android.mk3
-rwxr-xr-xtools/idegen/index-gen.sh24
-rwxr-xr-xtools/idegen/intellij-gen.sh30
-rw-r--r--tools/idegen/src/com/android/idegen/Constants.java46
-rw-r--r--tools/idegen/src/com/android/idegen/DirectorySearch.java43
-rw-r--r--tools/idegen/src/com/android/idegen/FrameworkModule.java8
-rw-r--r--tools/idegen/src/com/android/idegen/IntellijProject.java56
-rw-r--r--tools/idegen/src/com/android/idegen/Module.java20
-rw-r--r--tools/idegen/src/com/android/idegen/StandardModule.java18
11 files changed, 162 insertions, 90 deletions
diff --git a/tools/emulator/test-apps/ConnectivityTest/Android.mk b/tools/emulator/test-apps/ConnectivityTest/Android.mk
index 097d1189a..ca20d574a 100644
--- a/tools/emulator/test-apps/ConnectivityTest/Android.mk
+++ b/tools/emulator/test-apps/ConnectivityTest/Android.mk
@@ -24,6 +24,8 @@ LOCAL_PACKAGE_NAME := ConnectivityTest
LOCAL_SDK_VERSION := 4
+LOCAL_PROGUARD_ENABLED := disabled
+
include $(BUILD_PACKAGE)
# Use the following include to make our test apk.
diff --git a/tools/emulator/test-apps/GpsLocationTest/Android.mk b/tools/emulator/test-apps/GpsLocationTest/Android.mk
index 35c944393..5f90f3a5b 100644
--- a/tools/emulator/test-apps/GpsLocationTest/Android.mk
+++ b/tools/emulator/test-apps/GpsLocationTest/Android.mk
@@ -24,6 +24,8 @@ LOCAL_PACKAGE_NAME := GpsLocationTest
LOCAL_SDK_VERSION := 4
+LOCAL_PROGUARD_ENABLED := disabled
+
include $(BUILD_PACKAGE)
# Use the following include to make our test apk.
diff --git a/tools/idegen/Android.mk b/tools/idegen/Android.mk
index d424ab6be..8771160dd 100644
--- a/tools/idegen/Android.mk
+++ b/tools/idegen/Android.mk
@@ -2,8 +2,7 @@ LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
-LOCAL_STATIC_JAVA_LIBRARIES := \
- guavalib \
+LOCAL_STATIC_JAVA_LIBRARIES := guavalib
LOCAL_SRC_FILES := $(call all-subdir-java-files)
diff --git a/tools/idegen/index-gen.sh b/tools/idegen/index-gen.sh
index eadaa98e5..5b9e24bb1 100755
--- a/tools/idegen/index-gen.sh
+++ b/tools/idegen/index-gen.sh
@@ -14,12 +14,14 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
-# Generates a module index file by searching through android source tree for make files. The
-# intellij-gen.sh script automatically calls this script the first time or if you delete the
-# generated indexed file. The only time you need to run this manually is if modules are added or
-# deleted.
-#
-# To use:
+# Generates a module index file by searching through android source
+# tree for make files. The intellij-gen.sh script automatically calls
+# this script the first time or if you delete the generated indexed
+# file. The only time you need to run this manually is if modules are
+# added or deleted.
+#
+# To use, run the following command from either your repo root or
+# development/tools/idegen:
# index-gen.sh
#
# Only tested on linux. Should work for macs but have not tried.
@@ -27,7 +29,15 @@
set -e
script_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
-root_dir=`readlink -f -n $script_dir/../../..`
+#root_dir=`readlink -f -n $script_dir/../../..`
+root_dir=$PWD
+if [ ! -e $root_dir/.repo ]; then
+ root_dir=$PWD/../../..
+ if [ ! -e $root_dir/.repo ]; then
+ echo "Repo root not found. Run this script from your repo root or the idegen directory."
+ exit 1
+ fi
+fi
tmp_file=tmp.txt
dest_file=module-index.txt
diff --git a/tools/idegen/intellij-gen.sh b/tools/idegen/intellij-gen.sh
index 7f00eba06..d67c1f867 100755
--- a/tools/idegen/intellij-gen.sh
+++ b/tools/idegen/intellij-gen.sh
@@ -14,7 +14,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
-# To use:
+# To use, run the following command from either your repo root or
+# development/tools/idegen:
# intellij-gen.sh <module name>
#
# where module name is the LOCAL_PACKAGE_NAME in Android.mk for the project.
@@ -22,27 +23,38 @@
# For example, to generate a project for Contacts, use:
# intellij-gen.sh Contacts
#
-# The project directory (.idea) will be put in the root directory of the module. Sharable iml
-# files will be put into each respective module directory.
+# The project directory (.idea) will be put in the root directory of
+# the module. Sharable iml files will be put into each respective
+# module directory.
#
# Only tested on linux. Should work for macs but have not tried.
#
set -e
-script_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
-root_dir=`readlink -f -n $script_dir/../../..`
-index_file=$script_dir/module-index.txt
-idegenjar=$root_dir/out/host/common/obj/JAVA_LIBRARIES/idegen_intermediates/javalib.jar
-
progname=`basename $0`
if [ $# -ne 1 ]
then
echo "Usage: $progname <module_name>"
exit 1
fi
-
module_name=$1
+script_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
+root_dir=$PWD
+if [ ! -e $root_dir/.repo ]; then
+ root_dir=$PWD/../../..
+ if [ ! -e $root_dir/.repo ]; then
+ echo "Repo root not found. Run this script from your repo root or the idegen directory."
+ exit 1
+ fi
+fi
+index_file=$root_dir/module-index.txt
+idegenjar=$script_dir/idegen.jar
+if [ ! -e $idegenjar ]; then
+ # See if the jar is in the build directory.
+ idegenjar=$root_dir/out/host/linux-x86/framework/idegen.jar
+fi
+
if [ ! -e "$index_file" ]; then
echo "Module index file missing; generating this is only done the first time."
echo "If any dependencies change, you should generate a new index file by running index-gen.sh."
diff --git a/tools/idegen/src/com/android/idegen/Constants.java b/tools/idegen/src/com/android/idegen/Constants.java
deleted file mode 100644
index f541dd48d..000000000
--- a/tools/idegen/src/com/android/idegen/Constants.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * Copyright (C) 2012 The Android Open Source Project
- *
- * 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.
- */
-
-package com.android.idegen;
-
-import java.nio.charset.Charset;
-
-/**
- * Constants
- */
-public class Constants {
-
- public static final Charset CHARSET = Charset.forName("UTF-8");
-
- public static final String REL_TEMPLATE_DIR = "development/tools/idegen/templates";
- public static final String REL_MODULES_TEMPLATE = REL_TEMPLATE_DIR + "/idea/modules.xml";
- public static final String REL_VCS_TEMPLATE = REL_TEMPLATE_DIR + "/idea/vcs.xml";
- public static final String REL_IML_TEMPLATE = REL_TEMPLATE_DIR + "/module-template.iml";
-
- public static final String REL_OUT_APP_DIR = "out/target/common/obj/APPS";
-
- public static final String FRAMEWORK_MODULE = "framework";
- public static final String[] AUTO_DEPENDENCIES = new String[]{
- FRAMEWORK_MODULE, "libcore"
- };
- public static final String[] DIRS_WITH_AUTO_DEPENDENCIES = new String[] {
- "packages", "vendor", "frameworks/ex", "frameworks/opt", "frameworks/support"
- };
-
- // Framework needs a special constant for it's intermediates because it does not follow
- // normal conventions.
- public static final String FRAMEWORK_INTERMEDIATES = "framework-res_intermediates";
-}
diff --git a/tools/idegen/src/com/android/idegen/DirectorySearch.java b/tools/idegen/src/com/android/idegen/DirectorySearch.java
index 1bbf99ff8..2ff23e3de 100644
--- a/tools/idegen/src/com/android/idegen/DirectorySearch.java
+++ b/tools/idegen/src/com/android/idegen/DirectorySearch.java
@@ -21,8 +21,12 @@ import com.google.common.collect.ImmutableList;
import com.google.common.collect.Sets;
import java.io.File;
+import java.io.FileNotFoundException;
import java.io.FilenameFilter;
+import java.net.URISyntaxException;
import java.util.HashSet;
+import java.util.logging.Level;
+import java.util.logging.Logger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -31,6 +35,8 @@ import java.util.regex.Pattern;
*/
public class DirectorySearch {
+ private static final Logger logger = Logger.getLogger(DirectorySearch.class.getName());
+
private static final HashSet<String> SOURCE_DIRS = Sets.newHashSet();
static {
SOURCE_DIRS.add("src");
@@ -40,6 +46,9 @@ public class DirectorySearch {
private static final Pattern EXCLUDE_PATTERN = Pattern.compile("values-..(-.*)*");
private static File repoRoot = null;
+ public static final String REL_TEMPLATE_DIR = "templates";
+ public static final String REL_TEMPLATE_PATH_FROM_ROOT = "development/tools/idegen/"
+ + REL_TEMPLATE_DIR;
/**
* Find the repo root. This is the root branch directory of a full repo checkout.
@@ -138,4 +147,38 @@ public class DirectorySearch {
return builder.build();
}
+
+ private static File templateDirCurrent = null;
+ private static File templateDirRoot = null;
+
+ public static File findTemplateDir() throws FileNotFoundException {
+ // Cache optimization.
+ if (templateDirCurrent != null && templateDirCurrent.exists()) return templateDirCurrent;
+ if (templateDirRoot != null && templateDirRoot.exists()) return templateDirRoot;
+
+ File currentDir = null;
+ try {
+ currentDir = new File(IntellijProject.class.getProtectionDomain().getCodeSource()
+ .getLocation().toURI().getPath()).getParentFile();
+ } catch (URISyntaxException e) {
+ logger.log(Level.SEVERE, "Could not get jar location.", e);
+ return null;
+ }
+
+ // First check relative to current run directory.
+ templateDirCurrent = new File(currentDir, REL_TEMPLATE_DIR);
+ if (templateDirCurrent.exists()) {
+ return templateDirCurrent;
+ } else {
+ // Then check relative to root directory.
+ templateDirRoot = new File(repoRoot, REL_TEMPLATE_PATH_FROM_ROOT);
+ if (templateDirRoot.exists()) {
+ return templateDirRoot;
+ }
+ }
+ throw new FileNotFoundException(
+ "Unable to find template dir. Tried the following locations:\n" +
+ templateDirCurrent.getAbsolutePath() + "\n" +
+ templateDirRoot.getAbsolutePath());
+ }
}
diff --git a/tools/idegen/src/com/android/idegen/FrameworkModule.java b/tools/idegen/src/com/android/idegen/FrameworkModule.java
index bfcd1fab3..8743925e4 100644
--- a/tools/idegen/src/com/android/idegen/FrameworkModule.java
+++ b/tools/idegen/src/com/android/idegen/FrameworkModule.java
@@ -25,15 +25,19 @@ import java.io.File;
*/
public class FrameworkModule extends StandardModule {
+ // Framework needs a special constant for it's intermediates because it does not follow
+ // normal conventions.
+ private static final String FRAMEWORK_INTERMEDIATES = "framework-res_intermediates";
+
public FrameworkModule(String moduleName, String makeFile) {
- super(Constants.FRAMEWORK_MODULE, makeFile, true);
+ super(IntellijProject.FRAMEWORK_MODULE, makeFile, true);
}
@Override
protected String buildIntermediates() {
StringBuilder sb = new StringBuilder();
File intermediates = new File(repoRoot,
- Constants.REL_OUT_APP_DIR + File.separator + Constants.FRAMEWORK_INTERMEDIATES);
+ REL_OUT_APP_DIR + File.separator + FRAMEWORK_INTERMEDIATES);
ImmutableList<File> intermediateSrcDirs = DirectorySearch.findSourceDirs(intermediates);
sb.append(" <content url=\"file://").append(intermediates).append("\">\n");
for (File src : intermediateSrcDirs) {
diff --git a/tools/idegen/src/com/android/idegen/IntellijProject.java b/tools/idegen/src/com/android/idegen/IntellijProject.java
index d5564d599..e49a12b72 100644
--- a/tools/idegen/src/com/android/idegen/IntellijProject.java
+++ b/tools/idegen/src/com/android/idegen/IntellijProject.java
@@ -22,6 +22,7 @@ import com.google.common.io.Files;
import java.io.File;
import java.io.IOException;
+import java.nio.charset.Charset;
import java.util.Arrays;
import java.util.Set;
import java.util.logging.Logger;
@@ -31,9 +32,16 @@ import java.util.logging.Logger;
*/
public class IntellijProject {
+ public static final String FRAMEWORK_MODULE = "framework";
+ public static final Charset CHARSET = Charset.forName("UTF-8");
+
private static final Logger logger = Logger.getLogger(IntellijProject.class.getName());
+ private static final String MODULES_TEMPLATE_FILE_NAME = "modules.xml";
+ private static final String VCS_TEMPLATE_FILE_NAME = "vcs.xml";
+
ModuleCache cache = ModuleCache.getInstance();
+
File indexFile;
File repoRoot;
File projectIdeaDir;
@@ -55,6 +63,11 @@ public class IntellijProject {
// First pass, find all dependencies and cache them.
Module module = cache.getAndCache(moduleName);
+ if (module == null) {
+ logger.info("Module '" + moduleName + "' not found." +
+ " Module names are case senstive.");
+ return;
+ }
projectIdeaDir = new File(module.getDir(), ".idea");
projectIdeaDir.mkdir();
copyTemplates();
@@ -104,19 +117,27 @@ public class IntellijProject {
/**
* Framework module needs special handling due to one off resource path:
- * frameworks/base/Android.mk
+ * frameworks/base/Android.mk
*/
private void buildFrameWorkModule() throws IOException {
- String makeFile = cache.getMakeFile(Constants.FRAMEWORK_MODULE);
- logger.info("makefile: " + makeFile);
- StandardModule frameworkModule = new FrameworkModule(Constants.FRAMEWORK_MODULE, makeFile);
- frameworkModule.build();
- cache.put(frameworkModule);
+ String makeFile = cache.getMakeFile(FRAMEWORK_MODULE);
+ if (makeFile == null) {
+ logger.warning("Unable to find framework module: " + FRAMEWORK_MODULE +
+ ". Skipping.");
+ } else {
+ logger.info("makefile: " + makeFile);
+ StandardModule frameworkModule = new FrameworkModule(FRAMEWORK_MODULE,
+ makeFile);
+ frameworkModule.build();
+ cache.put(frameworkModule);
+ }
}
private void createModulesFile(Module module) throws IOException {
- String modulesContent = Files.toString(new File(repoRoot, Constants.REL_MODULES_TEMPLATE),
- Constants.CHARSET);
+ String modulesContent = Files.toString(
+ new File(DirectorySearch.findTemplateDir(),
+ "idea" + File.separator + MODULES_TEMPLATE_FILE_NAME),
+ CHARSET);
StringBuilder sb = new StringBuilder();
File moduleIml = module.getImlFile();
sb.append(" <module fileurl=\"file://").append(moduleIml.getAbsolutePath())
@@ -131,12 +152,14 @@ public class IntellijProject {
File out = new File(projectIdeaDir, "modules.xml");
logger.info("Creating " + out.getAbsolutePath());
- Files.write(modulesContent, out, Constants.CHARSET);
+ Files.write(modulesContent, out, CHARSET);
}
private void createVcsFile(Module module) throws IOException {
- String vcsTemplate = Files.toString(new File(module.getRepoRoot(),
- Constants.REL_VCS_TEMPLATE), Constants.CHARSET);
+ String vcsTemplate = Files.toString(
+ new File(DirectorySearch.findTemplateDir(),
+ "idea" + File.separator + VCS_TEMPLATE_FILE_NAME),
+ CHARSET);
StringBuilder sb = new StringBuilder();
for (String name : module.getAllDependencies()) {
@@ -149,18 +172,17 @@ public class IntellijProject {
}
}
vcsTemplate = vcsTemplate.replace("@VCS@", sb.toString());
- Files.write(vcsTemplate, new File(projectIdeaDir, "vcs.xml"), Constants.CHARSET);
+ Files.write(vcsTemplate, new File(projectIdeaDir, "vcs.xml"), CHARSET);
}
private void createNameFile(String name) throws IOException {
- File out = new File(projectIdeaDir, ".name");
- Files.write(name, out, Constants.CHARSET);
+ File out = new File(projectIdeaDir, ".name");
+ Files.write(name, out, CHARSET);
}
private void copyTemplates() throws IOException {
- File templateDir = new File(repoRoot,
- Constants.REL_TEMPLATE_DIR + File.separatorChar + "idea");
- copyTemplates(templateDir, projectIdeaDir);
+ File templateDir = DirectorySearch.findTemplateDir();
+ copyTemplates(new File(templateDir, "idea"), projectIdeaDir);
}
private void copyTemplates(File fromDir, File toDir) throws IOException {
diff --git a/tools/idegen/src/com/android/idegen/Module.java b/tools/idegen/src/com/android/idegen/Module.java
index 7ba42a3f4..deb22811f 100644
--- a/tools/idegen/src/com/android/idegen/Module.java
+++ b/tools/idegen/src/com/android/idegen/Module.java
@@ -34,6 +34,8 @@ public abstract class Module {
private static final Logger logger = Logger.getLogger(Module.class.getName());
+ private static final String IML_TEMPLATE_FILE_NAME = "module-template.iml";
+
/**
* All possible attributes for the make file.
*/
@@ -44,23 +46,35 @@ public abstract class Module {
}
ModuleCache moduleCache = ModuleCache.getInstance();
+
private File imlFile;
+
private Set<String> allDependencies = Sets.newHashSet(); // direct + indirect
+
private Set<File> allDependentImlFiles = Sets.newHashSet();
protected abstract void build() throws IOException;
+
protected abstract String getName();
+
protected abstract File getDir();
+
protected abstract boolean isAndroidModule();
+
protected abstract List<File> getIntermediatesDirs();
+
public abstract Set<String> getDirectDependencies();
+
protected abstract ImmutableList<File> getSourceDirs();
+
protected abstract ImmutableList<File> getExcludeDirs();
+
public abstract File getRepoRoot();
public void buildImlFile() throws IOException {
- String imlTemplate = Files.toString(new File(getRepoRoot(), Constants.REL_IML_TEMPLATE),
- Constants.CHARSET);
+ String imlTemplate = Files.toString(
+ new File(DirectorySearch.findTemplateDir(), IML_TEMPLATE_FILE_NAME),
+ IntellijProject.CHARSET);
String facetXml = "";
if (isAndroidModule()) {
@@ -100,7 +114,7 @@ public abstract class Module {
imlFile = new File(moduleDir, getName() + ".iml");
logger.info("Creating " + imlFile.getAbsolutePath());
- Files.write(imlTemplate, imlFile, Constants.CHARSET);
+ Files.write(imlTemplate, imlFile, IntellijProject.CHARSET);
}
protected String buildIntermediates() {
diff --git a/tools/idegen/src/com/android/idegen/StandardModule.java b/tools/idegen/src/com/android/idegen/StandardModule.java
index dffb95e01..f7b24b085 100644
--- a/tools/idegen/src/com/android/idegen/StandardModule.java
+++ b/tools/idegen/src/com/android/idegen/StandardModule.java
@@ -17,6 +17,7 @@
package com.android.idegen;
import com.google.common.base.Objects;
+import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
@@ -45,10 +46,18 @@ import java.util.regex.Pattern;
*/
public class StandardModule extends Module {
+ static final String REL_OUT_APP_DIR = "out/target/common/obj/APPS";
+
private static final Logger logger = Logger.getLogger(StandardModule.class.getName());
private static final Pattern SRC_PATTERN = Pattern.compile(
".*\\(call all-java-files-under, (.*)\\)");
+ private static final String[] AUTO_DEPENDENCIES = new String[]{
+ IntellijProject.FRAMEWORK_MODULE, "libcore"
+ };
+ private static final String[] DIRS_WITH_AUTO_DEPENDENCIES = new String[]{
+ "packages", "vendor", "frameworks/ex", "frameworks/opt", "frameworks/support"
+ };
String moduleName;
File makeFile;
@@ -66,7 +75,8 @@ public class StandardModule extends Module {
}
public StandardModule(String moduleName, String makeFile, boolean searchForSrc) {
- this(moduleName, new File(makeFile), searchForSrc);
+ this(Preconditions.checkNotNull(moduleName), new File(Preconditions.checkNotNull(makeFile)),
+ searchForSrc);
}
public StandardModule(String moduleName, File makeFile, boolean searchForSrc) {
@@ -75,16 +85,16 @@ public class StandardModule extends Module {
this.moduleRoot = makeFile.getParentFile();
this.repoRoot = DirectorySearch.findRepoRoot(makeFile);
this.intermediatesDir = new File(repoRoot.getAbsolutePath() + File.separator +
- Constants.REL_OUT_APP_DIR + File.separator + getName() + "_intermediates" +
+ REL_OUT_APP_DIR + File.separator + getName() + "_intermediates" +
File.separator + "src");
this.searchForSrc = searchForSrc;
// TODO: auto-detect when framework dependency is needed instead of using coded list.
- for (String dir : Constants.DIRS_WITH_AUTO_DEPENDENCIES) {
+ for (String dir : DIRS_WITH_AUTO_DEPENDENCIES) {
// length + 2 to account for slash
boolean isDir = makeFile.getAbsolutePath().startsWith(repoRoot + "/" + dir);
if (isDir) {
- for (String dependency : Constants.AUTO_DEPENDENCIES) {
+ for (String dependency : AUTO_DEPENDENCIES) {
this.directDependencies.add(dependency);
}
}