Skip to content

Commit

Permalink
Create idea.properties unconditionally
Browse files Browse the repository at this point in the history
Signed-off-by: Sergey Opivalov <[email protected]>
  • Loading branch information
6hundreds committed Jul 19, 2023
1 parent 02badc1 commit 1ed7b13
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ private void logLauncherConfiguration(List<String> commandLine) {
System.out.println("* Additional JVM args:");
additionalJvmArgs.forEach(arg -> System.out.println(" " + arg));
System.out.println("* Additional JVM args can be found at: " + studioSandbox.getScenarioOptionsDir().resolve("idea.vmoptions"));
System.out.println("* IDEA properties:");
ideaProperties.forEach(property -> System.out.println(" " + property));
System.out.println("* IDEA properties can be found at: " + studioSandbox.getScenarioOptionsDir().resolve("idea.properties"));
System.out.println("* Android Studio logs can be found at: " + studioSandbox.getLogsDir().resolve("idea.log"));
System.out.printf("* Using command line: %s%n%n", String.join(" ", commandLine));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,17 @@ public static StudioSandbox createSandbox(@Nullable Path sandboxDir, String plug
Path path = newTempDir();
Path pluginsDir = createDir(new File(path.toFile(), pluginsDirName).toPath());
Path logsDir = createDir(new File(path.toFile(), "logs").toPath());
Path jvmArgsDir = createDir(new File(path.toFile(), "jvmArgs").toPath());
return StudioSandbox.partialSandbox(pluginsDir, logsDir, jvmArgsDir);
Path scenarioOptionsDir = createDir(new File(path.toFile(), "scenarioOptions").toPath());
return StudioSandbox.partialSandbox(pluginsDir, logsDir, scenarioOptionsDir);
}
File sandboxDirFile = sandboxDir.toFile();
Path configDir = createDir(new File(sandboxDirFile, "config").toPath());
Path systemDir = createDir(new File(sandboxDirFile, "system").toPath());
Path pluginsDir = createDir(new File(sandboxDirFile, pluginsDirName).toPath());
Path logDir = createDir(new File(sandboxDirFile, "logs").toPath());
Path jvmArgsDir = createDir(new File(sandboxDirFile, "jvmArgs").toPath());
Path scenarioOptionsDir = createDir(new File(sandboxDirFile, "scenarioOptions").toPath());
disableIdeUpdate(configDir);
return StudioSandbox.fullSandbox(configDir, systemDir, pluginsDir, logDir, jvmArgsDir);
return StudioSandbox.fullSandbox(configDir, systemDir, pluginsDir, logDir, scenarioOptionsDir);
}

private static boolean shouldCreatePartialSandbox(Path sandboxDir) {
Expand Down Expand Up @@ -122,12 +122,12 @@ public Path getPluginsDir() {
return pluginsDir;
}

public static StudioSandbox fullSandbox(Path configDir, Path systemDir, Path pluginsDir, Path logsDir, Path jvmArgsDir) {
return new StudioSandbox(configDir, systemDir, pluginsDir, logsDir, jvmArgsDir);
public static StudioSandbox fullSandbox(Path configDir, Path systemDir, Path pluginsDir, Path logsDir, Path scenarioOptionsDir) {
return new StudioSandbox(configDir, systemDir, pluginsDir, logsDir, scenarioOptionsDir);
}

public static StudioSandbox partialSandbox(Path pluginsDir, Path logsDir, Path jvmArgsDir) {
return new StudioSandbox(null, null, pluginsDir, logsDir, jvmArgsDir);
public static StudioSandbox partialSandbox(Path pluginsDir, Path logsDir, Path scenarioOptionsDir) {
return new StudioSandbox(null, null, pluginsDir, logsDir, scenarioOptionsDir);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ class AndroidStudioIntegrationTest extends AbstractProfilerIntegrationTest {
then:
logFile.find("Full sync has completed in").size() == 2
logFile.find("and it SUCCEEDED").size() == 2
def vmOptionsFile = new File(sandboxDir, "jvmArgs/idea.vmoptions")
def vmOptionsFile = new File(sandboxDir, "scenarioOptions/idea.vmoptions")
vmOptionsFile.exists()
def vmOptions = vmOptionsFile.readLines()
vmOptions.contains("-Xmx1024m")
Expand Down Expand Up @@ -347,7 +347,7 @@ class AndroidStudioIntegrationTest extends AbstractProfilerIntegrationTest {
then:
logFile.find("Full sync has completed in").size() == 2
logFile.find("and it SUCCEEDED").size() == 2
def ideaPropertiesFile = new File(sandboxDir, "config/idea.properties")
def ideaPropertiesFile = new File(sandboxDir, "scenarioOptions/idea.properties")
def ideaProperties = ideaPropertiesFile.readLines()
ideaProperties.contains("foo=true")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import com.intellij.openapi.externalSystem.settings.ExternalSystemSettingsListenerAdapter;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.startup.StartupActivity;
import com.intellij.openapi.util.registry.Registry;
import com.intellij.openapi.util.registry.RegistryValue;
import org.gradle.profiler.client.protocol.Client;
import org.gradle.profiler.client.protocol.messages.StudioRequest;
import org.gradle.profiler.studio.plugin.client.GradleProfilerClient;
Expand All @@ -17,9 +19,14 @@
import org.jetbrains.plugins.gradle.settings.GradleProjectSettings;
import org.jetbrains.plugins.gradle.settings.GradleSettings;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.util.Collection;
import java.util.List;
import java.util.Properties;
import java.util.stream.Collectors;

import static org.gradle.profiler.client.protocol.messages.StudioRequest.StudioRequestType.EXIT_IDE;

Expand All @@ -32,6 +39,7 @@ public class GradleProfilerStartupActivity implements StartupActivity.DumbAware
@Override
public void runActivity(@NotNull Project project) {
LOG.info("Project opened");
logModifiedRegistryEntries();
if (System.getProperty(PROFILER_PORT_PROPERTY) != null) {
// This solves the issue where Android Studio would run the Gradle sync automatically on the first import.
// Unfortunately it seems we can't always detect it because it happens very late and due to that there might
Expand All @@ -53,6 +61,25 @@ public void runActivity(@NotNull Project project) {
}
}

private void logModifiedRegistryEntries() {
String studioPropertiesPath = System.getenv("STUDIO_PROPERTIES");
if (studioPropertiesPath == null || !new File(studioPropertiesPath).exists()) {
return;
}
try {
Properties properties = new Properties();
properties.load(new FileInputStream(studioPropertiesPath));
List<String> modifiedValues = Registry.getAll().stream()
.filter(value -> properties.containsKey(value.getKey()))
.map(RegistryValue::toString)
.sorted()
.collect(Collectors.toList());
LOG.info("Modified registry entries: " + modifiedValues);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}

private void disableDownloadOfExternalAnnotations(Project project) {
GradleSettings gradleSettings = GradleSettings.getInstance(project);
gradleSettings.getLinkedProjectsSettings()
Expand Down

0 comments on commit 1ed7b13

Please sign in to comment.