Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Workspace Composites WIP rebased to Master #1297

Open
wants to merge 22 commits into
base: kuzniarz-workspace-composites-rebased
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,242 @@
/*******************************************************************************
* Copyright (c) 2019 Gradle Inc.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
******************************************************************************/
package org.eclipse.buildship.core;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Properties;

import org.eclipse.buildship.core.internal.CorePlugin;
import org.eclipse.buildship.core.internal.configuration.CompositeConfiguration;

public class CompositeProperties {

private final List<File> projectList;
private final Boolean overwriteWorkspaceSettings;
private final GradleDistribution distribution;
private final File gradleUserHome;
private final File javaHome;
private final Boolean buildScansEnabled;
private final Boolean offlineMode;
private final Boolean autoSync;
private final List<String> arguments;
private final List<String> jvmArguments;
private final Boolean showConsoleView;
private final Boolean showExecutionsView;
private final Boolean useProjectAsRoot;
private final File rootProject;

private static final String KEY_COMPOSITE_PROJECTS = "composite.projects";
private static final String KEY_OVERWRITE_WORKSPACE_SETTINGS = "override.workspace.settings";
private static final String KEY_DISTRIBUTION = "connection.gradle.distribution";
private static final String KEY_GRADLE_USER_HOME = "gradle.user.home";
private static final String KEY_JAVA_HOME = "java.home";
private static final String KEY_BUILD_SCANS_ENABLED = "build.scans.enabled";
private static final String KEY_OFFLINE_MODE = "offline.mode";
private static final String KEY_AUTO_SYNC = "auto.sync";
private static final String KEY_ARGUMENTS = "arguments";
private static final String KEY_JVM_ARGUMENTS = "jvm.arguments";
private static final String KEY_SHOW_CONSOLE_VIEW = "show.console.view";
private static final String KEY_SHOW_EXECUTION_VIEW = "show.executions.view";
private static final String KEY_USE_PROJECT_AS_ROOT = "project.as.root";
private static final String KEY_ROOT_PROJECT = "root.project";

private CompositeProperties(CompositePropertiesBuilder builder) {
this.projectList = builder.projectList;
this.overwriteWorkspaceSettings = builder.overrideWorkspaceConfiguration;
this.distribution = builder.gradleDistribution == null ? GradleDistribution.fromBuild() : builder.gradleDistribution;
this.gradleUserHome = builder.gradleUserHome == null ? null: builder.gradleUserHome;
this.javaHome = builder.javaHome == null ? null : builder.javaHome;
this.buildScansEnabled = builder.buildScansEnabled;
this.offlineMode = builder.offlineMode;
this.autoSync = builder.autoSync;
this.arguments = builder.arguments == null ? Collections.emptyList() : builder.arguments;
this.jvmArguments = builder.jvmArguments == null ? Collections.emptyList() : builder.jvmArguments;
this.showConsoleView = builder.showConsoleView;
this.showExecutionsView = builder.showExecutionsView;
this.useProjectAsRoot = builder.projectAsCompositeRoot;
this.rootProject = builder.rootProject == null ? null: builder.rootProject;
}

public static CompositePropertiesReader getCompositeReaderForFile(String compositeName) {
return new CompositePropertiesReader(compositeName);
}

public static CompositePropertiesBuilder create() {
return new CompositePropertiesBuilder();
}

public static CompositePropertiesBuilder forCompositeConfiguration(CompositeConfiguration compositeConf) {
return new CompositePropertiesBuilder(compositeConf);
}

public Properties toProperties() {
Properties prop = new Properties();

prop.put(KEY_COMPOSITE_PROJECTS, this.projectList.toString());
prop.put(KEY_OVERWRITE_WORKSPACE_SETTINGS, this.overwriteWorkspaceSettings.toString());
prop.put(KEY_DISTRIBUTION, this.distribution == null ? GradleDistribution.fromBuild() : this.distribution.toString());
prop.put(KEY_GRADLE_USER_HOME, this.gradleUserHome == null ? "" : this.gradleUserHome.getAbsolutePath());
prop.put(KEY_JAVA_HOME, this.javaHome == null ? "" : this.javaHome.getAbsolutePath());
prop.put(KEY_BUILD_SCANS_ENABLED, this.buildScansEnabled.toString());
prop.put(KEY_OFFLINE_MODE, this.offlineMode.toString());
prop.put(KEY_AUTO_SYNC, this.autoSync.toString());
prop.put(KEY_ARGUMENTS, removeBrackets(this.arguments.toString()));
prop.put(KEY_JVM_ARGUMENTS, removeBrackets(this.jvmArguments.toString()));
prop.put(KEY_SHOW_CONSOLE_VIEW, this.showConsoleView.toString());
prop.put(KEY_SHOW_EXECUTION_VIEW, this.showExecutionsView.toString());
prop.put(KEY_USE_PROJECT_AS_ROOT, this.useProjectAsRoot.toString());
prop.put(KEY_ROOT_PROJECT, this.rootProject == null ? "" : this.rootProject.toString());
return prop;
}

private String removeBrackets(String arguments) {
return arguments.replace("[", "").replace("]", "").replace(",", "");
}

public static final class CompositePropertiesBuilder {

public List<File> projectList;
private boolean overrideWorkspaceConfiguration = false;
private GradleDistribution gradleDistribution;
private File gradleUserHome = null;
private File javaHome = null;
private boolean buildScansEnabled = false;
private boolean offlineMode = false;
private boolean autoSync = false;
private List<String> arguments = new ArrayList<>();
private List<String> jvmArguments = new ArrayList<>();
private boolean showConsoleView = true;
private boolean showExecutionsView = true;
private boolean projectAsCompositeRoot = false;
private File rootProject = null;

private CompositePropertiesBuilder() {
}

public CompositePropertiesBuilder(CompositeConfiguration compositeConf) {
this.projectList = compositeConf.getIncludedBuilds();
this.overrideWorkspaceConfiguration = compositeConf.getBuildConfiguration().isOverrideWorkspaceSettings();
this.gradleDistribution = compositeConf.getBuildConfiguration().getGradleDistribution();
this.gradleUserHome = compositeConf.getBuildConfiguration().getGradleUserHome();
this.javaHome = compositeConf.getBuildConfiguration().getJavaHome();
this.buildScansEnabled = compositeConf.getBuildConfiguration().isBuildScansEnabled();
this.offlineMode = compositeConf.getBuildConfiguration().isOfflineMode();
this.autoSync = compositeConf.getBuildConfiguration().isAutoSync();
this.arguments = compositeConf.getBuildConfiguration().getArguments();
this.jvmArguments = compositeConf.getBuildConfiguration().getJvmArguments();
this.showConsoleView = compositeConf.getBuildConfiguration().isShowConsoleView();
this.showExecutionsView = compositeConf.getBuildConfiguration().isShowExecutionsView();
this.projectAsCompositeRoot = compositeConf.projectAsCompositeRoot();
this.rootProject = compositeConf.getBuildConfiguration().getRootProjectDirectory();

}

public CompositePropertiesBuilder projectList(List<File> projectList) {
this.projectList = projectList;
return this;
}

public CompositePropertiesBuilder overrideWorkspaceConfiguration(boolean overrideWorkspaceConfiguration) {
this.overrideWorkspaceConfiguration = overrideWorkspaceConfiguration;
return this;
}

public CompositePropertiesBuilder gradleDistribution(GradleDistribution gradleDistribution) {
this.gradleDistribution = gradleDistribution;
return this;
}

public CompositePropertiesBuilder gradleUserHome(File gradleUserHome) {
this.gradleUserHome = gradleUserHome;
return this;
}

public CompositePropertiesBuilder javaHome(File javaHome) {
this.javaHome = javaHome;
return this;
}

public CompositePropertiesBuilder buildScansEnabled(boolean buildScansEnabled) {
this.buildScansEnabled = buildScansEnabled;
return this;
}

public CompositePropertiesBuilder offlineMode(boolean offlineMode) {
this.offlineMode = offlineMode;
return this;
}

public CompositePropertiesBuilder autoSync(boolean autoSync) {
this.autoSync = autoSync;
return this;
}

public CompositePropertiesBuilder arguments(List<String> arguments) {
this.arguments = arguments;
return this;
}

public CompositePropertiesBuilder jvmArguments(List<String> jvmArguments) {
this.jvmArguments = jvmArguments;
return this;
}

public CompositePropertiesBuilder showConsoleView(boolean showConsoleView) {
this.showConsoleView = showConsoleView;
return this;
}

public CompositePropertiesBuilder showExecutionsView(boolean showExecutionsView) {
this.showExecutionsView = showExecutionsView;
return this;
}

public CompositePropertiesBuilder projectAsCompositeRoot(boolean projectAsCompositeRoot) {
this.projectAsCompositeRoot = projectAsCompositeRoot;
return this;
}

public CompositePropertiesBuilder rootProject(File rootProject) {
this.rootProject = rootProject;
return this;
}

public CompositeProperties build() {
return new CompositeProperties(this);
}
}

public static final class CompositePropertiesReader {
private Properties compositeProperties = new Properties();

private CompositePropertiesReader(String compositeName) {
File compositeDirectory = CorePlugin.getInstance().getStateLocation().append("workspace-composites").append(compositeName).toFile();
try {
FileInputStream input= new FileInputStream(compositeDirectory);
this.compositeProperties = new Properties();
this.compositeProperties.load(input);
} catch (IOException e) {
e.printStackTrace();
}
}

public boolean getProjectAsCompositeRoot() {
return Boolean.valueOf(this.compositeProperties.get(KEY_USE_PROJECT_AS_ROOT).toString());
}

//If needed implement reader for other properties

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ final class BuildConfigurationPersistence {
private static final String PREF_KEY_JVM_ARGUMENTS = "jvm.arguments";
private static final String PREF_KEY_SHOW_CONSOLE_VIEW = "show.console.view";
private static final String PREF_KEY_SHOW_EXECUTIONS_VIEW = "show.executions.view";
private static final String PREF_KEY_USE_PROJECT_AS_ROOT = "project.as.root";
private static final String PREF_KEY_ROOT_PROJECT = "root.project";

public BuildConfigurationProperties readBuildConfiguratonProperties(IProject project) {
Preconditions.checkNotNull(project);
Expand All @@ -58,6 +60,12 @@ public BuildConfigurationProperties readBuildConfiguratonProperties(File project
return readPreferences(preferences, projectDir);
}

public DefaultBuildConfigurationProperties readCompositeBuildProperties(File compositeDir) {
Preconditions.checkNotNull(compositeDir);
PreferenceStore preferences = PreferenceStore.forPreferenceFile(compositeDir);
return readCompositePreferences(preferences, compositeDir);
}

public void saveBuildConfiguration(IProject project, BuildConfigurationProperties properties) {
Preconditions.checkNotNull(project);
Preconditions.checkNotNull(properties);
Expand Down Expand Up @@ -149,6 +157,74 @@ private static BuildConfigurationProperties readPreferences(PreferenceStore pref

return new BuildConfigurationProperties(rootDir, distribution, gradleUserHome, javaHome, overrideWorkspaceSettings, buildScansEnabled, offlineMode, autoSync, arguments, jvmArguments, showConsoleView, showExecutionsView);
}

private DefaultBuildConfigurationProperties readCompositePreferences(PreferenceStore preferences,
File compositePreferencesDir) {
boolean overrideWorkspaceSettings = preferences.readBoolean(PREF_KEY_OVERRIDE_WORKSPACE_SETTINGS, false);

String distributionString = preferences.readString(PREF_KEY_CONNECTION_GRADLE_DISTRIBUTION, null);
GradleDistribution distribution;
try {
distribution = GradleDistribution.fromString(distributionString);
} catch (RuntimeException ignore) {
distribution = GradleDistribution.fromBuild();
}

String gradleUserHomeString = preferences.readString(PREF_KEY_GRADLE_USER_HOME, "");
File gradleUserHome = gradleUserHomeString.isEmpty()
? null
: new File(gradleUserHomeString);
String javaHomeString = preferences.readString(PREF_KEY_JAVA_HOME, "");
File javaHome = javaHomeString.isEmpty()
? null
: new File(javaHomeString);

boolean buildScansEnabled = preferences.readBoolean(PREF_KEY_BUILD_SCANS_ENABLED, false);
boolean offlineMode = preferences.readBoolean(PREF_KEY_OFFLINE_MODE, false);
boolean autoSync = preferences.readBoolean(PREF_KEY_AUTO_SYNC, false);
List<String> arguments = Lists.newArrayList(Splitter.on(' ').omitEmptyStrings().split(preferences.readString(PREF_KEY_ARGUMENTS, "")));
List<String> jvmArguments = Lists.newArrayList(Splitter.on(' ').omitEmptyStrings().split(preferences.readString(PREF_KEY_JVM_ARGUMENTS, "")));
boolean showConsoleView = preferences.readBoolean(PREF_KEY_SHOW_CONSOLE_VIEW, false);
boolean showExecutionsView = preferences.readBoolean(PREF_KEY_SHOW_EXECUTIONS_VIEW, false);

File rootDir = new File(preferences.readString(PREF_KEY_ROOT_PROJECT, compositePreferencesDir.getAbsolutePath()));

return new DefaultBuildConfigurationProperties(rootDir, distribution, gradleUserHome, javaHome, overrideWorkspaceSettings, buildScansEnabled, offlineMode, autoSync, arguments, jvmArguments, showConsoleView, showExecutionsView);
}

private DefaultBuildConfigurationProperties readCompositePreferences(PreferenceStore preferences,
File compositePreferencesDir) {
boolean overrideWorkspaceSettings = preferences.readBoolean(PREF_KEY_OVERRIDE_WORKSPACE_SETTINGS, false);

String distributionString = preferences.readString(PREF_KEY_CONNECTION_GRADLE_DISTRIBUTION, null);
GradleDistribution distribution;
try {
distribution = GradleDistribution.fromString(distributionString);
} catch (RuntimeException ignore) {
distribution = GradleDistribution.fromBuild();
}

String gradleUserHomeString = preferences.readString(PREF_KEY_GRADLE_USER_HOME, "");
File gradleUserHome = gradleUserHomeString.isEmpty()
? null
: new File(gradleUserHomeString);
String javaHomeString = preferences.readString(PREF_KEY_JAVA_HOME, "");
File javaHome = javaHomeString.isEmpty()
? null
: new File(javaHomeString);

boolean buildScansEnabled = preferences.readBoolean(PREF_KEY_BUILD_SCANS_ENABLED, false);
boolean offlineMode = preferences.readBoolean(PREF_KEY_OFFLINE_MODE, false);
boolean autoSync = preferences.readBoolean(PREF_KEY_AUTO_SYNC, false);
List<String> arguments = Lists.newArrayList(Splitter.on(' ').omitEmptyStrings().split(preferences.readString(PREF_KEY_ARGUMENTS, "")));
List<String> jvmArguments = Lists.newArrayList(Splitter.on(' ').omitEmptyStrings().split(preferences.readString(PREF_KEY_JVM_ARGUMENTS, "")));
boolean showConsoleView = preferences.readBoolean(PREF_KEY_SHOW_CONSOLE_VIEW, false);
boolean showExecutionsView = preferences.readBoolean(PREF_KEY_SHOW_EXECUTIONS_VIEW, false);

File rootDir = new File(preferences.readString(PREF_KEY_ROOT_PROJECT, compositePreferencesDir.getAbsolutePath()));

return new DefaultBuildConfigurationProperties(rootDir, distribution, gradleUserHome, javaHome, overrideWorkspaceSettings, buildScansEnabled, offlineMode, autoSync, arguments, jvmArguments, showConsoleView, showExecutionsView);
}

private static void savePreferences(BuildConfigurationProperties properties, PreferenceStore preferences) {
GradleDistribution gradleDistribution = properties.getGradleDistribution();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*******************************************************************************
* Copyright (c) 2019 Gradle Inc.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
******************************************************************************/

package org.eclipse.buildship.core.internal.configuration;

import java.io.File;
import java.util.List;

/**
* Configuration for a workspace composite in a Gradle build.
*
* @author Sebastian Kuzniarz
*/
public interface CompositeConfiguration {

String getCompositeName();

List<File> getIncludedBuilds();

BuildConfiguration getBuildConfiguration();

Boolean projectAsCompositeRoot();
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,11 @@ BuildConfiguration createBuildConfiguration(File rootProjectDirectory, boolean o

void deleteProjectConfiguration(IProject project);

RunConfiguration loadRunConfiguration(ILaunchConfiguration configuration);
CompositeConfiguration loadCompositeConfiguration(String workingSetName);

void saveCompositeConfiguration(CompositeConfiguration compConf);

RunConfiguration loadRunConfiguration(ILaunchConfiguration launchConfiguration);

TestRunConfiguration loadTestRunConfiguration(ILaunchConfiguration configuration);

Expand Down
Loading
Loading