Skip to content

Commit

Permalink
Option to configure an existing project for test support added to
Browse files Browse the repository at this point in the history
wizards (#7). The option is default Off; if selected it will add the
test file folder (enables testing) – doing this more than once has no
effect.
  • Loading branch information
offa committed Jul 1, 2016
1 parent f5a319c commit b45a9f9
Show file tree
Hide file tree
Showing 10 changed files with 132 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,14 @@ public Set<?> instantiate() throws IOException
DataObject createdTemplate = templateDO.createFromTemplate(targetFolderDF, targetName, args);
FileObject createdFile = createdTemplate.getPrimaryFile();

WizardUtils.createTestsRootFolder(Templates.getProject(wizard));

Boolean configureCustomProject = (Boolean) wizard.getProperty(AbstractWizardPanel.PROP_CONFIGURE_CUSTOM_PROJECT);

if( configureCustomProject == true )
{
WizardUtils.createTestsRootFolder(Templates.getProject(wizard));
}


return Collections.singleton(createdFile);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
*/
public abstract class AbstractWizardPanel implements WizardDescriptor.Panel<WizardDescriptor>, ChangeListener
{
protected static final String PROP_CONFIGURE_CUSTOM_PROJECT = "PROP_CONFIGURE_CUSTOM_PROJECT";
private final ChangeSupport changeSupport;


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@
<Component id="lSettings" min="-2" max="-2" attributes="0"/>
<EmptySpace type="separate" max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Component id="cbCustomProjectEnable" min="-2" max="-2" attributes="0"/>
<Component id="cbColoredOutput" min="-2" max="-2" attributes="0"/>
<Component id="cbVerboseOutput" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace pref="127" max="32767" attributes="0"/>
<EmptySpace pref="65" max="32767" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
Expand All @@ -38,7 +39,9 @@
</Group>
<EmptySpace max="-2" attributes="0"/>
<Component id="cbColoredOutput" min="-2" max="-2" attributes="0"/>
<EmptySpace pref="240" max="32767" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="cbCustomProjectEnable" min="-2" max="-2" attributes="0"/>
<EmptySpace pref="211" max="32767" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
Expand Down Expand Up @@ -68,5 +71,13 @@
</Property>
</Properties>
</Component>
<Component class="javax.swing.JCheckBox" name="cbCustomProjectEnable">
<Properties>
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<ResourceString bundle="bv/offa/netbeans/cnd/unittest/wizard/Bundle.properties" key="NewTestMainVisualPanel1.cbCustomProjectEnable.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
</Property>
<Property name="toolTipText" type="java.lang.String" value="&lt;html&gt;&lt;p&gt;Enables the &lt;b&gt;Test&lt;/b&gt; functionality for custom projects (eg. using CMake). This is required only &lt;i&gt;once&lt;/i&gt; per project (indeed enabling it repeatedly has no effect).&lt;/p&gt;&#xa;&#xa;&lt;p&gt;&lt;b&gt;Required make targets:&lt;/b&gt;&#xa;&lt;ul&gt;&#xa;&lt;li&gt;&lt;i&gt;build-tests&lt;/i&gt; &#x2013; Builds the tests&lt;/li&gt;&#xa;&lt;li&gt;&lt;i&gt;test&lt;/i&gt; &#x2013; Executes the tests&lt;/li&gt;&#xa;&lt;/ul&gt;&#xa;&lt;/p&gt;&#xa;&#xa;&lt;p&gt;See &lt;a href=&quot;https://github.com/offa/NBCndUnit&quot;&gt;https://github.com/offa/NBCndUnit&lt;/a&gt; for more information.&lt;/p&gt;&#xa;&lt;/html&gt;" noResource="true"/>
</Properties>
</Component>
</SubComponents>
</Form>
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,17 @@ public boolean getEnableColor()
{
return cbColoredOutput.isSelected();
}


/**
* Returns whether a existing project should be configured for test.
*
* @return Configure Setting
*/
public boolean getConfigureCustomProject()
{
return cbCustomProjectEnable.isSelected();
}


/**
Expand All @@ -75,6 +86,7 @@ private void initComponents()
lSettings = new javax.swing.JLabel();
cbVerboseOutput = new javax.swing.JCheckBox();
cbColoredOutput = new javax.swing.JCheckBox();
cbCustomProjectEnable = new javax.swing.JCheckBox();

org.openide.awt.Mnemonics.setLocalizedText(lSettings, org.openide.util.NbBundle.getMessage(NewTestMainVisualPanel1.class, "NewTestMainVisualPanel1.lSettings.text")); // NOI18N

Expand All @@ -85,6 +97,9 @@ private void initComponents()
cbColoredOutput.setSelected(true);
org.openide.awt.Mnemonics.setLocalizedText(cbColoredOutput, org.openide.util.NbBundle.getMessage(NewTestMainVisualPanel1.class, "NewTestMainVisualPanel1.cbColoredOutput.text")); // NOI18N

org.openide.awt.Mnemonics.setLocalizedText(cbCustomProjectEnable, org.openide.util.NbBundle.getMessage(NewTestMainVisualPanel1.class, "NewTestMainVisualPanel1.cbCustomProjectEnable.text")); // NOI18N
cbCustomProjectEnable.setToolTipText("<html><p>Enables the <b>Test</b> functionality for custom projects (eg. using CMake). This is required only <i>once</i> per project (indeed enabling it repeatedly has no effect).</p>\n\n<p><b>Required make targets:</b>\n<ul>\n<li><i>build-tests</i> – Builds the tests</li>\n<li><i>test</i> – Executes the tests</li>\n</ul>\n</p>\n\n<p>See <a href=\"https://github.com/offa/NBCndUnit\">https://github.com/offa/NBCndUnit</a> for more information.</p>\n</html>"); // NOI18N

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
Expand All @@ -94,9 +109,10 @@ private void initComponents()
.addComponent(lSettings)
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(cbCustomProjectEnable)
.addComponent(cbColoredOutput)
.addComponent(cbVerboseOutput))
.addContainerGap(127, Short.MAX_VALUE))
.addContainerGap(65, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
Expand All @@ -107,13 +123,16 @@ private void initComponents()
.addComponent(cbVerboseOutput))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(cbColoredOutput)
.addContainerGap(240, Short.MAX_VALUE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(cbCustomProjectEnable)
.addContainerGap(211, Short.MAX_VALUE))
);
}// </editor-fold>//GEN-END:initComponents


// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JCheckBox cbColoredOutput;
private javax.swing.JCheckBox cbCustomProjectEnable;
private javax.swing.JCheckBox cbVerboseOutput;
private javax.swing.JLabel lSettings;
// End of variables declaration//GEN-END:variables
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ public void storeSettings(WizardDescriptor wiz)
{
wiz.putProperty(PROP_MAIN_ENABLE_VERBOSE, getEnableVerboseOutputFromVisualPanel());
wiz.putProperty(PROP_MAIN_ENABLE_COLOR, getEnableColorOutputFromVisualPanel());
wiz.putProperty(PROP_CONFIGURE_CUSTOM_PROJECT, getConfigureCustomProjectFromVisualPanel());
}
}

Expand Down Expand Up @@ -143,5 +144,16 @@ private boolean getEnableColorOutputFromVisualPanel()
{
return getComponent().getEnableColor();
}


/**
* Returns whether to configure a custom project from the visual component.
*
* @return Configure Setting
*/
private boolean getConfigureCustomProjectFromVisualPanel()
{
return getComponent().getConfigureCustomProject();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,25 @@
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" attributes="0">
<Group type="102" alignment="0" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" max="-2" attributes="0">
<Component id="lSuiteName" max="32767" attributes="0"/>
<Component id="lGenerate" max="32767" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" max="-2" attributes="0">
<Component id="cbGenerateSetup" min="-2" max="-2" attributes="0"/>
<Component id="cbGenerateTeardown" alignment="0" min="-2" max="-2" attributes="0"/>
<Group type="102" alignment="0" attributes="0">
<Component id="cbGenerateTestCases" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="tfTestCaseName" max="32767" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Component id="cbCustomProjectEnable" min="-2" max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" max="-2" attributes="0">
<Component id="cbGenerateSetup" min="-2" max="-2" attributes="0"/>
<Component id="cbGenerateTeardown" alignment="0" min="-2" max="-2" attributes="0"/>
<Group type="102" alignment="0" attributes="0">
<Component id="cbGenerateTestCases" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="tfTestCaseName" max="32767" attributes="0"/>
</Group>
<Component id="tfTestSuiteName" alignment="0" min="-2" pref="245" max="-2" attributes="0"/>
</Group>
<Component id="tfTestSuiteName" alignment="0" min="-2" pref="245" max="-2" attributes="0"/>
</Group>
<EmptySpace pref="158" max="32767" attributes="0"/>
</Group>
Expand All @@ -57,7 +60,9 @@
<Component id="cbGenerateTestCases" alignment="3" min="-2" pref="26" max="-2" attributes="0"/>
<Component id="tfTestCaseName" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace pref="50" max="32767" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="cbCustomProjectEnable" min="-2" max="-2" attributes="0"/>
<EmptySpace pref="21" max="32767" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
Expand Down Expand Up @@ -117,5 +122,13 @@
</Property>
</Properties>
</Component>
<Component class="javax.swing.JCheckBox" name="cbCustomProjectEnable">
<Properties>
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<ResourceString bundle="bv/offa/netbeans/cnd/unittest/wizard/Bundle.properties" key="NewTestSuiteVisualPanel1.cbCustomProjectEnable.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
</Property>
<Property name="toolTipText" type="java.lang.String" value="&lt;html&gt;&lt;p&gt;Enables the &lt;b&gt;Test&lt;/b&gt; functionality for custom projects (eg. using CMake). This is required only &lt;i&gt;once&lt;/i&gt; per project (indeed enabling it repeatedly has no effect).&lt;/p&gt;&#xa;&#xa;&lt;p&gt;&lt;b&gt;Required make targets:&lt;/b&gt;&#xa;&lt;ul&gt;&#xa;&lt;li&gt;&lt;i&gt;build-tests&lt;/i&gt; &#x2013; Builds the tests&lt;/li&gt;&#xa;&lt;li&gt;&lt;i&gt;test&lt;/i&gt; &#x2013; Executes the tests&lt;/li&gt;&#xa;&lt;/ul&gt;&#xa;&lt;/p&gt;&#xa;&#xa;&lt;p&gt;See &lt;a href=&quot;https://github.com/offa/NBCndUnit&quot;&gt;https://github.com/offa/NBCndUnit&lt;/a&gt; for more information.&lt;/p&gt;&#xa;&lt;/html&gt;" noResource="true"/>
</Properties>
</Component>
</SubComponents>
</Form>
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,17 @@ public String getTestSuiteName()
{
return tfTestSuiteName.getText();
}


/**
* Returns whether a existing project should be configured for test.
*
* @return Configure Setting
*/
public boolean getConfigureCustomProject()
{
return cbCustomProjectEnable.isSelected();
}


/**
Expand Down Expand Up @@ -200,6 +211,7 @@ private void initComponents()
cbGenerateTestCases = new javax.swing.JCheckBox();
lSuiteName = new javax.swing.JLabel();
tfTestSuiteName = new javax.swing.JTextField();
cbCustomProjectEnable = new javax.swing.JCheckBox();

tfTestCaseName.setText(org.openide.util.NbBundle.getMessage(NewTestSuiteVisualPanel1.class, "NewTestSuiteVisualPanel1.tfTestCaseName.text")); // NOI18N

Expand All @@ -224,6 +236,9 @@ public void actionPerformed(java.awt.event.ActionEvent evt)

tfTestSuiteName.setText(org.openide.util.NbBundle.getMessage(NewTestSuiteVisualPanel1.class, "NewTestSuiteVisualPanel1.tfTestSuiteName.text")); // NOI18N

org.openide.awt.Mnemonics.setLocalizedText(cbCustomProjectEnable, org.openide.util.NbBundle.getMessage(NewTestSuiteVisualPanel1.class, "NewTestSuiteVisualPanel1.cbCustomProjectEnable.text")); // NOI18N
cbCustomProjectEnable.setToolTipText("<html><p>Enables the <b>Test</b> functionality for custom projects (eg. using CMake). This is required only <i>once</i> per project (indeed enabling it repeatedly has no effect).</p>\n\n<p><b>Required make targets:</b>\n<ul>\n<li><i>build-tests</i> – Builds the tests</li>\n<li><i>test</i> – Executes the tests</li>\n</ul>\n</p>\n\n<p>See <a href=\"https://github.com/offa/NBCndUnit\">https://github.com/offa/NBCndUnit</a> for more information.</p>\n</html>"); // NOI18N

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
Expand All @@ -234,14 +249,16 @@ public void actionPerformed(java.awt.event.ActionEvent evt)
.addComponent(lSuiteName, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(lGenerate, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(cbGenerateSetup)
.addComponent(cbGenerateTeardown)
.addGroup(layout.createSequentialGroup()
.addComponent(cbGenerateTestCases)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(tfTestCaseName))
.addComponent(tfTestSuiteName, javax.swing.GroupLayout.PREFERRED_SIZE, 245, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(cbCustomProjectEnable)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(cbGenerateSetup)
.addComponent(cbGenerateTeardown)
.addGroup(layout.createSequentialGroup()
.addComponent(cbGenerateTestCases)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(tfTestCaseName))
.addComponent(tfTestSuiteName, javax.swing.GroupLayout.PREFERRED_SIZE, 245, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addContainerGap(158, Short.MAX_VALUE))
);
layout.setVerticalGroup(
Expand All @@ -261,7 +278,9 @@ public void actionPerformed(java.awt.event.ActionEvent evt)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(cbGenerateTestCases, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(tfTestCaseName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap(50, Short.MAX_VALUE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(cbCustomProjectEnable)
.addContainerGap(21, Short.MAX_VALUE))
);
}// </editor-fold>//GEN-END:initComponents

Expand All @@ -277,6 +296,7 @@ private void cbGenerateTestCasesActionPerformed(java.awt.event.ActionEvent evt)/


// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JCheckBox cbCustomProjectEnable;
private javax.swing.JCheckBox cbGenerateSetup;
private javax.swing.JCheckBox cbGenerateTeardown;
private javax.swing.JCheckBox cbGenerateTestCases;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ public void storeSettings(WizardDescriptor wiz)
wiz.putProperty(PROP_TEST_GENERATE_TESTCASES, getGenerateTestCasesFromVisualComponent());
wiz.putProperty(PROP_TEST_TESTCASE_NAMES, getTestCaseNamesFromVisualComponent());
wiz.putProperty(PROP_TEST_TESTSUITE_NAME, getTestSuiteNameFromVisualComponent());
wiz.putProperty(PROP_CONFIGURE_CUSTOM_PROJECT, getConfigureCustomProjectFromVisualPanel());
}
}

Expand Down Expand Up @@ -200,6 +201,18 @@ private String getTestSuiteNameFromVisualComponent()
{
return getComponent().getTestSuiteName();
}



/**
* Returns whether to configure a custom project from the visual component.
*
* @return Configure Setting
*/
private boolean getConfigureCustomProjectFromVisualPanel()
{
return getComponent().getConfigureCustomProject();
}


/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

package bv.offa.netbeans.cnd.unittest.wizard;

import java.util.logging.Level;
import java.util.logging.Logger;
import org.netbeans.api.project.Project;
import org.netbeans.modules.cnd.makeproject.api.configurations.ConfigurationDescriptorProvider;
import org.netbeans.modules.cnd.makeproject.api.configurations.Folder;
Expand All @@ -33,6 +35,9 @@
*/
public final class WizardUtils
{
private static final Logger LOGGER = Logger.getLogger(WizardUtils.class.getName());


private WizardUtils()
{
/* Empty */
Expand Down Expand Up @@ -127,9 +132,14 @@ public static Folder createTestsRootFolder(Project project)

if( testFolder == null )
{
LOGGER.log(Level.INFO, "Enable Test Files Folder");
return rootFolder.addNewFolder(MakeConfigurationDescriptor.TEST_FILES_FOLDER,
NbBundle.getMessage(MakeConfigurationDescriptor.class, "TestsFilesTxt"), false, Folder.Kind.TEST_LOGICAL_FOLDER);
}
else
{
LOGGER.log(Level.INFO, "Test Files Folder already enabled");
}

return testFolder;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@ MSG_Err_Empty_TestCase_Name=The test case name can not be empty.
MSG_Err_Empty_TestSuite_Name=The test suite name can not be empty.
MSG_Err_Invalid_TestCase_Name=The test case name contains invalid characters.
MSG_Err_Invalid_TestSuite_Name=The test suite name contains invalid characters.
NewTestMainVisualPanel1.cbCustomProjectEnable.text=Configure custom Project (Experimental)
NewTestSuiteVisualPanel1.cbCustomProjectEnable.text=Configure custom Project (Experimental)

0 comments on commit b45a9f9

Please sign in to comment.