Skip to content

Commit

Permalink
Add features to JRE preference page (fixes #2026)
Browse files Browse the repository at this point in the history
   - update eclipse orbit update site to 2019-09 M3
   - add setDefault configuration to JRERequirement
   - add java.target.version property to pom.xml as an option for compilation against different java version

Signed-off-by: Ondrej Dockal <odockal@redhat.com>
  • Loading branch information
odockal authored and jkopriva committed Aug 27, 2019
1 parent 2317165 commit 3bdfe6d
Show file tree
Hide file tree
Showing 6 changed files with 235 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import java.util.ArrayList;
import java.util.List;

import org.eclipse.reddeer.core.exception.CoreLayerException;
import org.eclipse.reddeer.core.reference.ReferencedComposite;
import org.eclipse.reddeer.eclipse.exception.EclipseLayerException;
import org.eclipse.reddeer.eclipse.jdt.ui.preferences.JREItem;
Expand All @@ -28,7 +29,7 @@
/**
* Class representing JRE Preference page (Java &gt; Installed JREs).
*
* @author rhopp
* @author rhopp, odockal
*
*/

Expand Down Expand Up @@ -123,11 +124,68 @@ public List<JREItem> getJREs() {
*/

public JREsPreferencePage deleteJRE(String name) {
DefaultTable table = new DefaultTable(this);
table.getItem(name, 0).select();
selectJRE(name);
new PushButton(referencedComposite, "Remove").click();
return this;
}

/**
* Set given JRE to default by toggling checkbox on.
* @return JREsPreferencePage object
*/
public JREsPreferencePage toggleJRE(String name, boolean toggle) {
getJRETableItem(name).setChecked(toggle);
// we need to check if at least one java is chosen, otherwise apply is disabled
// and error is shown
if (!(new PushButton(referencedComposite, "Apply").isEnabled())) {
throw new EclipseLayerException("At least one valid JRE must be chosen - expected default JRE for workspace");
}
return this;
}

/**
* Selects given JRE.
* @param name JRE name in string
* @return
*/
public JREsPreferencePage selectJRE(String name) {
getJRETableItem(name).select();
return this;
}

/**
* Return existing JRE.
* @param name jre's name
* @return existing JRE item object in table
*/
public TableItem getJRETableItem(String name) {
DefaultTable table = new DefaultTable(this);
try {
return table.getItem(name);
} catch (CoreLayerException exc) {
// if set to default, name is changed to "${name} (default)"
return table.getItem(name + " (default)");
}
}

/**
* Return existing JRE.
* @param name jre's name
* @return existing JRE item object in table
*/
public JREItem getJREItem(String name) {
TableItem item = getJRETableItem(name);
return new JREItem(item.getText(0), item.getText(1), item.getText(2), item.isChecked());
}

/**
* Toggle given JRE on and sets it to default.
* @param name JRE name to search for
* @return JREsPreferencePage object
*/
public JREsPreferencePage setDefaultJRE(String name) {
return toggleJRE(name, true);
}

private AddVMInstallWizard openAddJREWizard() {
new PushButton(this, "Add...").click();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public class JREItem {
private String name;
private String location;
private String type;
private boolean isDefault;

/**
* Instantiates a new JRE item.
Expand All @@ -36,6 +37,39 @@ public JREItem(String name, String location, String type) {
this.name = name;
this.location = location;
this.type = type;
this.isDefault = false;
}

/**
* Instantiates a new JRE item.
*
* @param name the name
* @param location the location
* @param type the type
* @param isDefault the default
*/
public JREItem(String name, String location, String type, boolean checked) {
this.name = name;
this.location = location;
this.type = type;
this.isDefault = checked;
}

/**
* Gets if is checked/default
* @return the checked
*/
public boolean isDefault() {
return isDefault;
}

/**
* Sets the default.
*
* @param isDefault if it is default setup
*/
public void setDefault(boolean isDefault) {
this.isDefault = isDefault;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ public class JRERequirement extends AbstractConfigurableRequirement<JREConfigura
* @return true, if successful
*/
boolean cleanup() default false;

/**
* Sets new JRE as default.
* @return
*/
boolean setDefault() default false;
}

/**
Expand All @@ -61,6 +67,9 @@ public void fulfill() {
JREsPreferencePage page = new JREsPreferencePage(dialog);
dialog.select(page);
page.addJRE(getPath(), configuration.getName());
if (annotation.setDefault()) {
page.setDefaultJRE(configuration.getName());
}
dialog.ok();
}

Expand Down
7 changes: 4 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@
<tychoExtrasVersion>${tycho-version}</tychoExtrasVersion>
<eclipse-target-site>http://download.eclipse.org/staging/2019-09/</eclipse-target-site>
<swtbot-update-site>http://download.eclipse.org/technology/swtbot/snapshots/</swtbot-update-site>
<eclipse-orbit-update-site>https://download.eclipse.org/tools/orbit/downloads/drops/S20190726194335/repository</eclipse-orbit-update-site>
<eclipse-orbit-update-site>https://download.eclipse.org/tools/orbit/downloads/drops/S20190819183153/repository</eclipse-orbit-update-site>
<download-plugin-version>1.2.1</download-plugin-version>
<java.target.version>1.8</java.target.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<!-- In the update site's site/pom.xml (that calls jbosstools-maven-plugins/tycho-plugins/repository-utils)
you can override this value to be Nightly Build, Development Milestone, or
Expand All @@ -34,8 +35,8 @@
<targetEclipseVersion>4.13 (2019-09)</targetEclipseVersion>
<BUILD_ALIAS></BUILD_ALIAS>
<BUILD_TIMESTAMP>yyyyMMdd-HHmm</BUILD_TIMESTAMP>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>${java.target.version}</maven.compiler.source>
<maven.compiler.target>${java.target.version}</maven.compiler.target>
<!-- Java Code Coverage -->
<jacoco-version>0.8.2</jacoco-version>
<!-- Sonar Properties -->
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
/*******************************************************************************
* Copyright (c) 2019 Red Hat, Inc and others.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Red Hat, Inc - initial API and implementation
*******************************************************************************/
package org.eclipse.reddeer.eclipse.test.jdt.debug.ui.jres;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

import java.util.stream.Collectors;

import org.eclipse.reddeer.core.exception.CoreLayerException;
import org.eclipse.reddeer.eclipse.exception.EclipseLayerException;
import org.eclipse.reddeer.eclipse.jdt.debug.ui.jres.JREsPreferencePage;
import org.eclipse.reddeer.eclipse.jdt.ui.preferences.JREItem;
import org.eclipse.reddeer.junit.runner.RedDeerSuite;
import org.eclipse.reddeer.requirements.property.RequirementPropertyExpandor;
import org.eclipse.reddeer.swt.api.TableItem;
import org.eclipse.reddeer.workbench.ui.dialogs.WorkbenchPreferenceDialog;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;

/**
* Tests preference page for manipulation of JREs.
* @author odockal
*
*/
@RunWith(RedDeerSuite.class)
public class JREsPreferencePageTest {

private WorkbenchPreferenceDialog dialog;
private JREsPreferencePage page;

@Before
public void setup() {
preferenceIsOpen();
}

@Test
public void testAddingJRE() {
addJRE(false);
TableItem jre = getJRETableItem();
assertFalse(jre.isChecked());
assertFalse(page.getJREItem(getName()).isDefault());
}

@Test
public void testAddingDefaultJRE() {
addJRE(true);
assertEquals(getName() + " (default)", page.getJREItem(getName()).getName());
assertTrue(page.getJRETableItem(getName()).isChecked());
}

@Test(expected=CoreLayerException.class)
public void testJRENotFound() {
page.getJREItem("RandomJRE");
}

@Test(expected=EclipseLayerException.class)
public void testOneDefaultJRE() {
for(JREItem item : page.getJREs()) {
page.toggleJRE(item.getName(), false);
}
}

@After
public void clean() {
preferenceIsOpen();
for (JREItem item : page.getJREs()) {
if (item.getName().equals(getName())) {
page.deleteJRE(getName());
}
}
dialog.cancel();
}

private TableItem getJRETableItem() {
try {
return page.getJRETableItem(getName());
} catch (CoreLayerException e) {
fail("Cannot select non existing JRE: " + getName() + ". Only existing JREs are: " +
page.getJREs().stream().map(item -> item.getName()).collect(Collectors.joining(", ")));
}
return null;
}

public static void addJRE(boolean setDefault) {
WorkbenchPreferenceDialog dialog = new WorkbenchPreferenceDialog();
dialog.open();
JREsPreferencePage page = new JREsPreferencePage(dialog);
dialog.select(page);
page.addJRE(getPath(), getName());
if (setDefault) {
page.setDefaultJRE(getName());
}
}

public static String getName() {
return "jre.test";
}

public static String getPath() {
return RequirementPropertyExpandor.getProperty("${java.home}");
}

private void preferenceIsOpen() {
if (dialog == null || !dialog.isOpen()) {
dialog = new WorkbenchPreferenceDialog();
dialog.open();
page = new JREsPreferencePage(dialog);
dialog.select(page);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
package org.eclipse.reddeer.requirements.test.jre;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import java.io.File;
Expand Down Expand Up @@ -51,10 +52,10 @@ public void testConfiguredValues(){
dialog.select(page);
List<JREItem> jres = page.getJREs();
assertTrue(matchJREs(jres, requirement.getConfiguration().getName(), requirement.getPath()));
assertFalse(page.getJREItem(requirement.getConfiguration().getName()).isDefault());
dialog.cancel();
}


/**
*
* @return returns true if any of items matches name and path.
Expand Down

0 comments on commit 3bdfe6d

Please sign in to comment.