Skip to content

Commit 80191ad

Browse files
ADFA-1639 Rename .androidide/ to .cg/ in multiple locations (#1161)
* Rename .androidide/ to .cg/ in multiple locations * Add error handling for migrating legacy .androidide/ to modern .cg/ * Reduce complexity of LegacyIdeDataDirMigration()
1 parent 0975600 commit 80191ad

File tree

21 files changed

+110
-36
lines changed

21 files changed

+110
-36
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ sentry.properties
105105

106106
# Generated files for tooling API
107107
tests/test-home
108-
/tests/**/.androidide/init/model.jar
108+
/tests/**/.cg/init/model.jar
109109

110110
/composite-builds/build-deps-common/constants/build/
111111
/composite-builds/build-deps/build/

common/src/main/java/com/itsaky/androidide/utils/Environment.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,9 @@ public static String getArchitecture() {
127127
}
128128

129129
public static File getProjectCacheDir(File projectDir) {
130-
return new File(projectDir, ANDROIDIDE_PROJECT_CACHE_DIR);
130+
File current = new File(projectDir, ANDROIDIDE_PROJECT_CACHE_DIR);
131+
File legacy = new File(projectDir, SharedEnvironment.LEGACY_PROJECT_CACHE_DIR_NAME);
132+
return LegacyIdeDataDirMigration.migrateLegacyIdeDataDirIfNeeded(legacy, current);
131133
}
132134

133135
public static void init(Context context) {
@@ -142,7 +144,11 @@ public static void init(Context context) {
142144
ROOT = mkdirIfNotExists(new File(DEFAULT_ROOT));
143145
PREFIX = mkdirIfNotExists(new File(ROOT, "usr"));
144146
HOME = mkdirIfNotExists(new File(ROOT, "home"));
145-
ANDROIDIDE_HOME = mkdirIfNotExists(new File(HOME, ".androidide"));
147+
File ideHomeCandidate = new File(HOME, SharedEnvironment.PROJECT_CACHE_DIR_NAME);
148+
File legacyIdeHome = new File(HOME, SharedEnvironment.LEGACY_PROJECT_CACHE_DIR_NAME);
149+
File ideHomeResolved =
150+
LegacyIdeDataDirMigration.migrateLegacyIdeDataDirIfNeeded(legacyIdeHome, ideHomeCandidate);
151+
ANDROIDIDE_HOME = mkdirIfNotExists(ideHomeResolved);
146152
TMP_DIR = mkdirIfNotExists(new File(PREFIX, "tmp"));
147153
BIN_DIR = mkdirIfNotExists(new File(PREFIX, "bin"));
148154
OPT_DIR = mkdirIfNotExists(new File(PREFIX, "opt"));
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
* This file is part of AndroidIDE.
3+
*
4+
* AndroidIDE is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* AndroidIDE is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with AndroidIDE. If not, see <https://www.gnu.org/licenses/>.
16+
*/
17+
package com.itsaky.androidide.utils;
18+
19+
import java.io.File;
20+
import org.slf4j.Logger;
21+
import org.slf4j.LoggerFactory;
22+
23+
/**
24+
* One-time rename of the fork-era {@code .androidide} directory to {@link
25+
* SharedEnvironment#PROJECT_CACHE_DIR_NAME}.
26+
*/
27+
public final class LegacyIdeDataDirMigration {
28+
29+
private static final Logger LOG = LoggerFactory.getLogger(LegacyIdeDataDirMigration.class);
30+
31+
private LegacyIdeDataDirMigration() {}
32+
33+
/**
34+
* Resolves which IDE data directory path is in use: prefers {@code current} after a successful
35+
* rename from {@code legacy}. If {@code current} already exists, it wins (both-existing case is
36+
* logged). If only {@code legacy} exists and {@code legacy.renameTo(current)} fails, returns
37+
* {@code legacy} so callers keep using the existing tree. If neither exists, returns {@code
38+
* current} for the caller to create.
39+
*/
40+
public static File migrateLegacyIdeDataDirIfNeeded(File legacy, File current) {
41+
if (current.exists() && legacy.exists()) {
42+
LOG.warn(
43+
"Both {} and {} exist; using {} only",
44+
legacy.getAbsolutePath(),
45+
current.getAbsolutePath(),
46+
current.getAbsolutePath());
47+
return current;
48+
}
49+
if (legacy.exists()) {
50+
if (legacy.renameTo(current)) {
51+
return current;
52+
}
53+
LOG.warn("Failed to rename legacy IDE data dir {} to {}", legacy, current);
54+
return legacy;
55+
}
56+
return current;
57+
}
58+
}

composite-builds/build-deps-common/constants/src/main/java/org/adfa/constants/constants.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,12 @@ const val ANDROID_SDK_ZIP = "android-sdk.zip"
3434
const val GRADLE_DISTRIBUTION_NAME = "gradle-$GRADLE_DISTRIBUTION_VERSION"
3535
const val GRADLE_DISTRIBUTION_ARCHIVE_NAME = "$GRADLE_DISTRIBUTION_NAME-bin.zip"
3636

37-
// .androidide folder
37+
// App-internal IDE data under files/home/ (matches SharedEnvironment.PROJECT_CACHE_DIR_NAME)
3838
@Suppress("SdCardPath")
39-
const val ANDROIDIDE_HOME = "/data/data/com.itsaky.androidide/files/home/.androidide"
39+
const val IDE_DATA_DIR_NAME = ".cg"
40+
41+
@Suppress("SdCardPath")
42+
const val ANDROIDIDE_HOME = "/data/data/com.itsaky.androidide/files/home/$IDE_DATA_DIR_NAME"
4043

4144
// Code On the Go gradle plugin
4245
const val COGO_GRADLE_PLUGIN_NAME = "cogo-plugin"

gradle-plugin/src/test/java/com/itsaky/androidide/gradle/utils.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package com.itsaky.androidide.gradle
1919

2020
import com.itsaky.androidide.buildinfo.BuildInfo
2121
import com.itsaky.androidide.utils.FileProvider
22+
import com.itsaky.androidide.utils.SharedEnvironment
2223
import org.gradle.testkit.runner.BuildResult
2324
import org.gradle.testkit.runner.GradleRunner
2425
import org.gradle.testkit.runner.internal.PluginUnderTestMetadataReading
@@ -35,7 +36,8 @@ internal fun buildProject(
3536
vararg plugins: String
3637
): BuildResult {
3738
val projectRoot = openProject(agpVersion, useApplyPluginGroovySyntax, *plugins)
38-
val initScript = FileProvider.testHomeDir().resolve(".androidide/init/androidide.init.gradle")
39+
val initScript = FileProvider.testHomeDir()
40+
.resolve("${SharedEnvironment.PROJECT_CACHE_DIR_NAME}/init/androidide.init.gradle")
3941
val mavenLocal = FileProvider.projectRoot().resolve("gradle-plugin/build/maven-local/repos.txt").toFile()
4042

4143
if (!(mavenLocal.exists() && mavenLocal.isFile)) {

layouteditor/.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,4 +85,4 @@ lint/tmp/
8585
# lint/reports/
8686

8787

88-
.androidide/
88+
.cg/

resources/src/main/res/values-ar-rSA/strings.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@
282282
<string name="xml_formatting_options">خيارات تنسيق XML</string>
283283
<string name="xml_formatting_options_summary">تهيئة تنسيق XML</string>
284284
<string name="idepref_customFont_title">استخدام خط مخصص</string>
285-
<string name="idepref_customFont_summary">في حالة التمكين، سيتم استخدام الملف الموجود على \"/data/com.itsaky.androidide/files/home/.androidide/ui/font.ttf\" كخط محرر.</string>
285+
<string name="idepref_customFont_summary">في حالة التمكين، سيتم استخدام الملف الموجود على \"/data/data/com.itsaky.androidide/files/home/.cg/ui/font.ttf\" كخط محرر.</string>
286286
<string name="msg_installing_apk">تثبيت APK...</string>
287287
<string name="msg_action_open_application">هل تريد فتح التطبيق؟</string>
288288
<string name="title_gradle_service_notification_channel">خدمة بناء Code on the Go</string>
@@ -399,7 +399,7 @@
399399
<string name="idepref_devOptions_summary">خيارات تجريبية/تصحيح أخطاء Code on the Go</string>
400400
<string name="idepref_group_debugging">تصحيح الأخطاء</string>
401401
<string name="idepref_devOptions_dumpLogs_title">تفريغ السجلات</string>
402-
<string name="idepref_devOptions_dumpLogs_summary">تفريغ سجلات Code on the Go إلى $HOME/.androidide/logs</string>
402+
<string name="idepref_devOptions_dumpLogs_summary">تفريغ سجلات Code on the Go إلى $HOME/.cg/logs</string>
403403
<string name="msg_emptyview_applogs">قم بتشغيل النسخة التصحيحية (debug) من تطبيقك لعرض السجلات هنا.</string>
404404
<string name="msg_logsender_disabled">تم تعطيل إرسال السجل. يمكنك تمكينه في الخيارات.</string>
405405
<string name="msg_emptyview_idelogs">تظهر سجلات من بيئة التطوير المتكاملة هنا.</string>

resources/src/main/res/values-bn-rIN/strings.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@
282282
<string name="xml_formatting_options">XML ফর্ম্যাটিং অপশনগুলি</string>
283283
<string name="xml_formatting_options_summary">XML ফর্ম্যাটার কনফিগার করুন</string>
284284
<string name="idepref_customFont_title">কাস্টম ফন্ট ব্যবহার করুন</string>
285-
<string name="idepref_customFont_summary">সক্রিয় থাকলে, \"/data/data/com.itsaky.androidide/files/home/.androidide/ui/font.ttf\" ফাইলটিকে এডিটর-এর ফন্ট হিসেবে ব্যবহার করা হবে।</string>
285+
<string name="idepref_customFont_summary">সক্রিয় থাকলে, \"/data/data/com.itsaky.androidide/files/home/.cg/ui/font.ttf\" ফাইলটিকে এডিটর-এর ফন্ট হিসেবে ব্যবহার করা হবে।</string>
286286
<string name="msg_installing_apk">APK ইনস্টল করা হচ্ছে...</string>
287287
<string name="msg_action_open_application">তুমি কি অ্যাপ্লিকেশনটি খুলতে চাও?</string>
288288
<string name="title_gradle_service_notification_channel">Code on the Go Gradle build পরিষেবা</string>
@@ -399,7 +399,7 @@
399399
<string name="idepref_devOptions_summary">Code on the Go-এর জন্য পরীক্ষামূলক/ডিবাগিং অপশনগুলি</string>
400400
<string name="idepref_group_debugging">ডিবাগিং</string>
401401
<string name="idepref_devOptions_dumpLogs_title">ডাম্প লগ</string>
402-
<string name="idepref_devOptions_dumpLogs_summary">Code on the Go লগ ডাম্প করুন $HOME/.androidide/logs এ</string>
402+
<string name="idepref_devOptions_dumpLogs_summary">Code on the Go লগ ডাম্প করুন $HOME/.cg/logs এ</string>
403403
<string name="msg_emptyview_applogs">এখানে লগগুলি দেখার জন্য আপনার অ্যাপ্লিকেশনটির ডিবাগ ভ্যারিয়েন্ট টি রান করুন৷</string>
404404
<string name="msg_logsender_disabled">LogSender নিষ্ক্রিয় করা হয়েছে। আপনি Preferences-এ গিয়ে এটিকে সক্রিয় করতে পারেন।</string>
405405
<string name="msg_emptyview_idelogs">IDE লগস্ এখানে দেখানো হয়.</string>

resources/src/main/res/values-de-rDE/strings.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@
281281
<string name="xml_formatting_options">XML-Formatierungsoptionen</string>
282282
<string name="xml_formatting_options_summary">XML-Formatierer konfigurieren</string>
283283
<string name="idepref_customFont_title">Eigene Schriftart verwenden</string>
284-
<string name="idepref_customFont_summary">Wenn aktiviert, wird die Datei unter \"/data/data/com.itsaky.androidide/files/home/.androidide/ui/font.ttf\" als Editor Schriftart verwendet.</string>
284+
<string name="idepref_customFont_summary">Wenn aktiviert, wird die Datei unter \"/data/data/com.itsaky.androidide/files/home/.cg/ui/font.ttf\" als Editor Schriftart verwendet.</string>
285285
<string name="msg_installing_apk">Installiere APK...</string>
286286
<string name="msg_action_open_application">Möchtest du die Applikation öffnen?</string>
287287
<string name="title_gradle_service_notification_channel">Code on the Go Gradle-Build-Service</string>
@@ -398,7 +398,7 @@
398398
<string name="idepref_devOptions_summary">Experimentelle/Debugging Optionen für Code on the Go</string>
399399
<string name="idepref_group_debugging">Debugging</string>
400400
<string name="idepref_devOptions_dumpLogs_title">Protokolle ausgeben</string>
401-
<string name="idepref_devOptions_dumpLogs_summary">Code on the Go-Logs in $HOME/.androidide/logs ausgeben</string>
401+
<string name="idepref_devOptions_dumpLogs_summary">Code on the Go-Logs in $HOME/.cg/logs ausgeben</string>
402402
<string name="msg_emptyview_applogs">Run the debug variant of your application to view its logs here.</string>
403403
<string name="msg_logsender_disabled">LogSender is disabled. You can enable it in preferences.</string>
404404
<string name="msg_emptyview_idelogs">Protokolle der IDE werden hier angezeigt.</string>

resources/src/main/res/values-es-rES/strings.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@
282282
<string name="xml_formatting_options">Opciones de formato XML</string>
283283
<string name="xml_formatting_options_summary">Configura el formato XML</string>
284284
<string name="idepref_customFont_title">Añadir fuente personalizada</string>
285-
<string name="idepref_customFont_summary">Si está habilitado, el archivo en\"/data/data/com.itsaky.androidide/files/home/.androidide/ui/font.ttf\" se utilizará como fuente del editor.</string>
285+
<string name="idepref_customFont_summary">Si está habilitado, el archivo en\"/data/data/com.itsaky.androidide/files/home/.cg/ui/font.ttf\" se utilizará como fuente del editor.</string>
286286
<string name="msg_installing_apk">Instalando APK...</string>
287287
<string name="msg_action_open_application">¿Quieres abrir la aplicación?</string>
288288
<string name="title_gradle_service_notification_channel">Servicio de compilación de Gradle de Code on the Go</string>
@@ -399,7 +399,7 @@
399399
<string name="idepref_devOptions_summary">Experimental/debugging options for Code on the Go</string>
400400
<string name="idepref_group_debugging">Debugging</string>
401401
<string name="idepref_devOptions_dumpLogs_title">Dump logs</string>
402-
<string name="idepref_devOptions_dumpLogs_summary">Dump Code on the Go logs to $HOME/.androidide/logs</string>
402+
<string name="idepref_devOptions_dumpLogs_summary">Dump Code on the Go logs to $HOME/.cg/logs</string>
403403
<string name="msg_emptyview_applogs">Run the debug variant of your application to view its logs here.</string>
404404
<string name="msg_logsender_disabled">LogSender is disabled. You can enable it in preferences.</string>
405405
<string name="msg_emptyview_idelogs">Logs from the IDE are shown here.</string>

0 commit comments

Comments
 (0)