use of org.gradle.gradleplugin.foundation.settings.SettingsNode in project gradle by gradle.
the class MainGradlePanel method setupUI.
private void setupUI() {
setLayout(new BorderLayout());
tabbedPane = new JTabbedPane();
add(tabbedPane, BorderLayout.CENTER);
addTabs();
restoreLastTab();
//add a listener so we can store the current tab when it changes.
tabbedPane.addChangeListener(new ChangeListener() {
public void stateChanged(ChangeEvent e) {
int selection = tabbedPane.getSelectedIndex();
if (selection >= 0 && selection < gradleTabs.size()) {
SettingsNode rootNode = settings.addChildIfNotPresent(MAIN_PANEL);
rootNode.setValueOfChild(CURRENT_TAB, gradleTabs.get(selection).getName());
}
}
});
}
use of org.gradle.gradleplugin.foundation.settings.SettingsNode in project gradle by gradle.
the class DOM4JSettingsNodeTest method testGetValueOfChildAsBoolean.
/**
* This tests getValueOfChildAsBoolean. We're interested in that it gets the child value correctly, but also that it
* returns the default value if either the node, its value isn't present, or the valid isn't illegal as a boolean.
* Because we're dealing with just true and false, I'll test several of these twice; once with a default of true and
* again with a default of false. This is just to be paranoid.
*/
public void testGetValueOfChildAsBoolean() {
//make sure we have no children first
List<SettingsNode> children = rootNode.getChildNodes();
assertEquals(0, children.size());
//set the value of a child
rootNode.setValueOfChild(SAMPLE_NAME_1, "true");
rootNode.setValueOfChild(SAMPLE_NAME_2, "false");
rootNode.setValueOfChild(SAMPLE_NAME_3, "true");
assertEquals(false, rootNode.getValueOfChildAsBoolean(SAMPLE_NAME_2, true));
assertEquals(true, rootNode.getValueOfChildAsBoolean(SAMPLE_NAME_1, false));
assertEquals(true, rootNode.getValueOfChildAsBoolean(SAMPLE_NAME_3, false));
//now try it with one that doesn't exist. We should get the default value
assertEquals(true, rootNode.getValueOfChildAsBoolean("nonexistent", true));
//see header
assertEquals(false, rootNode.getValueOfChildAsBoolean("nonexistent2", false));
//now add a single node but don't give it a value (which means its null)
SettingsNode valuelessNode = rootNode.addChild("valueless");
assertNull(valuelessNode.getValue());
//now try to get its value. We should get the default value
assertEquals(true, rootNode.getValueOfChildAsBoolean("valueless", true));
//see header
assertEquals(false, rootNode.getValueOfChildAsBoolean("valueless", false));
//now add a single node that has an illegal value
SettingsNode illegalNode = rootNode.addChild("illegal");
illegalNode.setValue("abcdefg");
//now try to get its value. We should get the default value
assertEquals(true, rootNode.getValueOfChildAsBoolean("illegal", true));
//see header
assertEquals(false, rootNode.getValueOfChildAsBoolean("illegal", false));
}
use of org.gradle.gradleplugin.foundation.settings.SettingsNode in project gradle by gradle.
the class DOM4JSettingsNodeTest method testGetChildNodesByName.
/**
* This tests getChildNodes that takes a sought node name. We'll make sure it returns all the child nodes. First
* we'll make sure it returns nothing when no children are present. Then we'll add some nodes and make sure it
* returns the correct ones. Lastly, we'll add some more again to make sure they're appropriately included in the
* list.
*/
public void testGetChildNodesByName() {
//try it with no nodes
List<SettingsNode> children = rootNode.getChildNodes();
assertEquals(0, children.size());
//add some test nodes
SettingsNode childNode1 = rootNode.addChild(SAMPLE_NAME_1);
SettingsNode childNode2 = rootNode.addChild(SAMPLE_NAME_2);
SettingsNode childNode3 = rootNode.addChild(SAMPLE_NAME_3);
//this is a duplicate of childNode2
SettingsNode childNode4 = rootNode.addChild(SAMPLE_NAME_2);
//only 2 and 4 match
children = rootNode.getChildNodes(SAMPLE_NAME_2);
TestUtility.assertListContents(children, childNode2, childNode4);
//add some more nodes. Only 1 is a match
SettingsNode childNode5 = rootNode.addChild(SAMPLE_NAME_1);
SettingsNode childNode6 = rootNode.addChild(SAMPLE_NAME_2);
//node 6 should also returned now
children = rootNode.getChildNodes(SAMPLE_NAME_2);
TestUtility.assertListContents(children, childNode2, childNode4, childNode6);
}
use of org.gradle.gradleplugin.foundation.settings.SettingsNode in project gradle by gradle.
the class DOM4JSettingsNodeTest method testRemoveAllChildren.
/**
* This tests removeAllChildren. We'll add some nodes and call removeAllChildren and then make sure they're no
* longer present.
*/
public void testRemoveAllChildren() {
//make sure we have no children first
List<SettingsNode> children = rootNode.getChildNodes();
assertEquals(0, children.size());
//add some sample nodes.
SettingsNode childNode1 = rootNode.addChild(SAMPLE_NAME_1);
SettingsNode childNode2 = rootNode.addChild(SAMPLE_NAME_2);
SettingsNode childNode3 = rootNode.addChild(SAMPLE_NAME_3);
SettingsNode childNode4 = rootNode.addChild(SAMPLE_NAME_2);
//make sure they're all present as expected
children = rootNode.getChildNodes();
TestUtility.assertListContents(children, childNode1, childNode2, childNode3, childNode4);
//now remove all children
rootNode.removeAllChildren();
//and make sure they're gone
children = rootNode.getChildNodes();
assertEquals(0, children.size());
//just to be paranoid, verify they're gone using getChildNode. Each of these should return nothing.
assertNull(rootNode.getChildNode(SAMPLE_NAME_1));
assertNull(rootNode.getChildNode(SAMPLE_NAME_2));
assertNull(rootNode.getChildNode(SAMPLE_NAME_3));
//make sure the nodes are gone from a DOM4J standpoint.
assertEquals(0, rootElement.elements().size());
}
use of org.gradle.gradleplugin.foundation.settings.SettingsNode in project gradle by gradle.
the class DOM4JSettingsNodeTest method testSetValueOfChildAsLong.
/**
* This tests setValueOfChildAsLong. We're going to make sure the value is set as well as that repeated calls to
* this don't add child nodes.
*/
public void testSetValueOfChildAsLong() {
//make sure we have no children first
List<SettingsNode> children = rootNode.getChildNodes();
assertEquals(0, children.size());
//set the value of a child
rootNode.setValueOfChildAsLong(SAMPLE_NAME_1, 8000000000l);
//verify it was set properly
SettingsNode childNode1 = rootNode.getChildNode(SAMPLE_NAME_1);
assertNotNull(childNode1);
assertEquals("8000000000", childNode1.getValue());
//make sure there's only 1 child.
children = rootNode.getChildNodes();
assertEquals(1, children.size());
//set the value again. This should set the value and NOT add an additional node
rootNode.setValueOfChildAsLong(SAMPLE_NAME_1, 3900000000l);
childNode1 = rootNode.getChildNode(SAMPLE_NAME_1);
assertNotNull(childNode1);
assertEquals("3900000000", childNode1.getValue());
//make sure there's still only 1 child.
children = rootNode.getChildNodes();
assertEquals(1, children.size());
}
Aggregations