Commit d994b486 authored by Adam Knapp's avatar Adam Knapp
Browse files

UI elements for exporting JAR



Change-Id: I58f7fb132af1732f55f2e1ed3c1e51264288523b
Signed-off-by: default avatarAdam Knapp <adam.knapp@sigmatechnology.se>
parent aa96aa29
......@@ -44,6 +44,9 @@ public final class MakefileCreationData {
public static final String TARGET_EXECUTABLE_PROPERTY = "targetExecutable";
public static final String CODE_SPLITTING_PROPERTY = "codeSplitting";
public static final String DEFAULT_TARGET_PROPERTY = "defaultTarget";
public static final String DEFAULT_JAVA_TARGET_PROPERTY = "defaultJavaTarget";
public static final String GENERATE_START_SH_SCRIPT_PROPERTY = "generateStartShScript";
public static final String GENERATE_START_BAT_SCRIPT_PROPERTY = "generateStartBatScript";
public static final boolean USE_ABSOLUTEPATH_DEFAULT_VALUE = false;
public static final boolean GNU_MAKE_DEFAULT_VALUE = false;
......@@ -53,20 +56,27 @@ public final class MakefileCreationData {
public static final boolean SINGLEMODE_DEFAULT_VALUE = false;
public static final String CODE_SPLITTING_DEFAULT_VALUE = GeneralConstants.NONE;
public static final String DEFAULT_TARGET_DEFAULT_VALUE = DefaultTarget.getDefault().toString();
public static final String DEFAULT_JAVA_TARGET_DEFAULT_VALUE = DefaultJavaTarget.getDefault().toString();
public static final boolean GENERATE_START_SH_SCRIPT_DEFAULT = false;
public static final boolean GENERATE_START_BAT_SCRIPT_DEFAULT = false;
// makefile properties to be saved into the XML
public static final String[] MAKEFILE_PROPERTIES = new String[] { USE_ABSOLUTEPATH_PROPERTY, GNU_MAKE_PROPERTY,
INCREMENTAL_DEPENDENCY_PROPERTY, DYNAMIC_LINKING_PROPERTY, FUNCTIONTESTRUNTIME_PROPERTY, SINGLEMODE_PROPERTY,
CODE_SPLITTING_PROPERTY, DEFAULT_TARGET_PROPERTY };
CODE_SPLITTING_PROPERTY, DEFAULT_TARGET_PROPERTY, DEFAULT_JAVA_TARGET_PROPERTY,
GENERATE_START_SH_SCRIPT_PROPERTY, GENERATE_START_BAT_SCRIPT_PROPERTY};
// XML tag names corresponding to the makefile properties
public static final String[] MAKEFILE_TAGS = new String[] { "useAbsolutePath", "GNUMake", "incrementalDependencyRefresh", "dynamicLinking",
"functiontestRuntime", "singleMode", "codeSplitting", "defaultTarget" };
"functiontestRuntime", "singleMode", "codeSplitting", "defaultTarget", "defaultJavaTarget",
"generateStartShScript", "generateStartBatScript"};
private static final String[] DEFAULT_VALUES = new String[] { String.valueOf(USE_ABSOLUTEPATH_DEFAULT_VALUE),
String.valueOf(GNU_MAKE_DEFAULT_VALUE), String.valueOf(INCREMENTAL_DEPENDENCY_DEFAULT_VALUE),
String.valueOf(DYNAMIC_LINKING_DEFAULT_VALUE), String.valueOf(FUNCTIONTESTRUNTIME_DEFAULT_VALUE),
String.valueOf(SINGLEMODE_DEFAULT_VALUE), CODE_SPLITTING_DEFAULT_VALUE, DEFAULT_TARGET_DEFAULT_VALUE };
String.valueOf(SINGLEMODE_DEFAULT_VALUE), CODE_SPLITTING_DEFAULT_VALUE, DEFAULT_TARGET_DEFAULT_VALUE,
DEFAULT_JAVA_TARGET_DEFAULT_VALUE, String.valueOf(GENERATE_START_SH_SCRIPT_DEFAULT),
String.valueOf(GENERATE_START_BAT_SCRIPT_DEFAULT)};
public enum DefaultTarget {
EXECUTABLE, LIBRARY;
......@@ -94,6 +104,34 @@ public final class MakefileCreationData {
{ "Library", DefaultTarget.LIBRARY.toString() } };
}
}
public enum DefaultJavaTarget {
CLASS, EXECUTABLE, JAR;
public static DefaultJavaTarget getDefault() {
return CLASS;
}
@Override
public String toString() {
return name().toLowerCase(Locale.ENGLISH);
}
/**
* This works like {@link #valueOf(String)} except it is case
* insensitive. This and {@link #toString()} should be kept
* consistent.
*/
public static DefaultJavaTarget createInstance(final String str) {
return DefaultJavaTarget.valueOf(str.toUpperCase());
}
public static String[][] getDisplayNamesAndValues() {
return new String[][] { { "Class files", DefaultJavaTarget.CLASS.toString() },
{ "Executable JAR", DefaultJavaTarget.EXECUTABLE.toString() },
{ "JAR", DefaultJavaTarget.JAR.toString() } };
}
}
private MakefileCreationData() {
// Do nothing
......@@ -110,6 +148,9 @@ public final class MakefileCreationData {
project.setPersistentProperty(new QualifiedName(ProjectBuildPropertyData.QUALIFIER, CODE_SPLITTING_PROPERTY), null);
project.setPersistentProperty(new QualifiedName(ProjectBuildPropertyData.QUALIFIER, DEFAULT_TARGET_PROPERTY), null);
project.setPersistentProperty(new QualifiedName(ProjectBuildPropertyData.QUALIFIER, TARGET_EXECUTABLE_PROPERTY), null);
project.setPersistentProperty(new QualifiedName(ProjectBuildPropertyData.QUALIFIER, DEFAULT_JAVA_TARGET_PROPERTY), null);
project.setPersistentProperty(new QualifiedName(ProjectBuildPropertyData.QUALIFIER, GENERATE_START_SH_SCRIPT_PROPERTY), null);
project.setPersistentProperty(new QualifiedName(ProjectBuildPropertyData.QUALIFIER, GENERATE_START_BAT_SCRIPT_PROPERTY), null);
} catch (CoreException e) {
ErrorReporter.logExceptionStackTrace("While removing attributes of `" + project.getName() + "'", e);
}
......@@ -334,4 +375,9 @@ public final class MakefileCreationData {
}
return name.toString();
}
public static String getDefaultJavaTargetName(final IProject project, final boolean isAbsolute) {
String name = getDefaultTargetExecutableName(project, isAbsolute);
return "java_bin" + File.separator + name.replace("bin" + File.separator, "").replace(".exe", "") + ".jar";
}
}
/******************************************************************************
* Copyright (c) 2000-2021 Ericsson Telecom AB
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.html
******************************************************************************/
package org.eclipse.titan.designer.properties.pages;
import java.net.URI;
import org.eclipse.core.filesystem.URIUtil;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.QualifiedName;
import org.eclipse.jface.util.IPropertyChangeListener;
import org.eclipse.jface.util.PropertyChangeEvent;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.TabFolder;
import org.eclipse.swt.widgets.TabItem;
import org.eclipse.titan.common.fieldeditors.TITANResourceLocatorFieldEditor;
import org.eclipse.titan.common.logging.ErrorReporter;
import org.eclipse.titan.common.path.PathUtil;
import org.eclipse.titan.common.path.TITANPathUtilities;
import org.eclipse.titan.common.utils.StringUtils;
import org.eclipse.titan.designer.preferences.pages.ComboFieldEditor;
import org.eclipse.titan.designer.productUtilities.ProductConstants;
import org.eclipse.titan.designer.properties.data.MakefileCreationData;
import org.eclipse.titan.designer.properties.data.ProjectBuildPropertyData;
import org.eclipse.ui.dialogs.PropertyPage;
public class JavaCreationTab {
private static final String JAVA_CREATION_TAB_TITLE = "Java target creation attributes";
private final IProject project;
private final PropertyPage page;
private Composite automaticBuildPropertiesComposite;
private Composite defaultJavaTargetComposite;
private Composite javaTargetComposite;
private ComboFieldEditor defaultJavaTarget;
private TabItem creationAttributesTabItem;
private TITANResourceLocatorFieldEditor temporalJavaTargetFileFieldEditor;
public static final String TEMPORAL_JAVA_TARGET = ProductConstants.PRODUCT_ID_DESIGNER + ".temporalJavaTarget";
private Button generateStartShScript;
private Button generateStartBatScript;
public JavaCreationTab(final IProject project, final PropertyPage page) {
this.project = project;
this.page = page;
}
public JavaCreationTab(final IProject project) {
this.project = project;
this.page = null;
}
/**
* Disposes the SWT resources allocated by this tab page.
*/
public void dispose() {
}
/**
* Creates and returns the SWT control for the customized body of this
* TabItem under the given parent TabFolder.
* <p>
*
* @param tabFolder
* the parent TabFolder
* @return the new TabItem
*/
protected TabItem createContents(final TabFolder tabFolder) {
creationAttributesTabItem = new TabItem(tabFolder, SWT.BORDER);
creationAttributesTabItem.setText(JAVA_CREATION_TAB_TITLE);
creationAttributesTabItem.setToolTipText("Settings controlling the generation of Java binaries.");
automaticBuildPropertiesComposite = new Composite(tabFolder, SWT.MULTI);
automaticBuildPropertiesComposite.setEnabled(true);
automaticBuildPropertiesComposite.setLayout(new GridLayout());
//defaultTarget
defaultJavaTargetComposite = new Composite(automaticBuildPropertiesComposite, SWT.NONE);
defaultJavaTarget = new ComboFieldEditor(MakefileCreationData.DEFAULT_TARGET_PROPERTY, "Default target:",
MakefileCreationData.DefaultJavaTarget.getDisplayNamesAndValues(), defaultJavaTargetComposite);
defaultJavaTarget.setPropertyChangeListener (new IPropertyChangeListener() {
@Override
public void propertyChange(final PropertyChangeEvent event) {
updateDefaultJavaTarget();
}
});
//target exe
javaTargetComposite = new Composite(automaticBuildPropertiesComposite, SWT.NONE);
final GridLayout targetExecutableLayout = new GridLayout();
javaTargetComposite.setLayout(targetExecutableLayout);
final GridData targetExecutableData = new GridData(GridData.FILL);
targetExecutableData.grabExcessHorizontalSpace = true;
targetExecutableData.horizontalAlignment = SWT.FILL;
javaTargetComposite.setLayoutData(targetExecutableData);
temporalJavaTargetFileFieldEditor = new TITANResourceLocatorFieldEditor(TEMPORAL_JAVA_TARGET,
"Java target:", javaTargetComposite, IResource.FILE, project.getLocation().toOSString());
temporalJavaTargetFileFieldEditor
.getLabelControl(javaTargetComposite)
.setToolTipText("The target of the Java build process.\n"
+ "This field is optional.\n"
+ "If it is not set, only Java class files will be generated into the working directory.");
final String[] extensions = new String[] {"*.jar;*.zip", "*.*"};
temporalJavaTargetFileFieldEditor.setFilterExtensions(extensions);
if (page != null) {
temporalJavaTargetFileFieldEditor.setPage(page);
}
generateStartShScript = new Button(automaticBuildPropertiesComposite, SWT.CHECK);
generateStartShScript.setText("Generate ttcn3_start shell script for starting the JAR (Linux)");
generateStartShScript.setEnabled(false);
generateStartShScript
.setToolTipText("If this option is set, also a shell script will be generated to start the JAR");
generateStartBatScript = new Button(automaticBuildPropertiesComposite, SWT.CHECK);
generateStartBatScript.setText("Generate ttcn3_start.bat script for starting the JAR (WIN)");
generateStartBatScript.setEnabled(false);
generateStartBatScript
.setToolTipText("If this option is set, also a .bat script will be generated to start the JAR");
creationAttributesTabItem.setControl(automaticBuildPropertiesComposite);
return creationAttributesTabItem;
}
/**
* Checks the properties of this page for errors.
*
* @param page
* the property page to report the errors to.
* @return true if no error was found, false otherwise.
* */
public boolean checkProperties(final ProjectJavaBuildPropertyPage page) {
if ((temporalJavaTargetFileFieldEditor.getStringValue().isEmpty() || !temporalJavaTargetFileFieldEditor.isValid())
&& !isClassSelected()) {
String errorMessage = temporalJavaTargetFileFieldEditor.getErrorMessage();
if (errorMessage == null) {
errorMessage = "The Java target is not set";
}
page.setErrorMessage(errorMessage);
return false;
}
return true;
}
/**
* Loads the properties from the property storage, into the user
* interface elements.
*
* @param project
* the project to load the properties from.
* */
public void loadProperties(final IProject project) {
String temp;
final boolean useAbsolutePath = false;
try {
temp = project.getPersistentProperty(new QualifiedName(ProjectBuildPropertyData.QUALIFIER,
MakefileCreationData.DEFAULT_JAVA_TARGET_PROPERTY));
if (StringUtils.isNullOrEmpty(temp)) {
defaultJavaTarget.setSelectedValue(MakefileCreationData.DefaultJavaTarget.getDefault().toString());
} else {
try {
defaultJavaTarget.setSelectedValue(MakefileCreationData.DefaultJavaTarget.createInstance(temp).toString());
} catch (final IllegalArgumentException e) {
ErrorReporter.INTERNAL_ERROR("Unknown default target in makefile creation tab: " + temp);
}
}
temp = project.getPersistentProperty(new QualifiedName(ProjectBuildPropertyData.QUALIFIER,
MakefileCreationData.TARGET_EXECUTABLE_PROPERTY));
if (temp == null) {
temporalJavaTargetFileFieldEditor.setStringValue(MakefileCreationData.getDefaultJavaTargetName(project, useAbsolutePath));
} else {
temporalJavaTargetFileFieldEditor.setStringValue(temp);
}
temp = project.getPersistentProperty(new QualifiedName(ProjectBuildPropertyData.QUALIFIER,
MakefileCreationData.GENERATE_START_SH_SCRIPT_PROPERTY));
generateStartShScript.setSelection(ProjectBuildPropertyData.TRUE_STRING.equals(temp) ? true : false);
temp = project.getPersistentProperty(new QualifiedName(ProjectBuildPropertyData.QUALIFIER,
MakefileCreationData.GENERATE_START_BAT_SCRIPT_PROPERTY));
generateStartBatScript.setSelection(ProjectBuildPropertyData.TRUE_STRING.equals(temp) ? true : false);
updateDefaultJavaTarget();
} catch (CoreException e) {
performDefaults(project);
}
}
/**
* Saves the properties to the property storage, from the user interface
* elements.
*
* @param project
* the project to save the properties to.
* @return true if the save was successful, false otherwise.
* */
public boolean saveProperties(final IProject project) {
try {
setProperty(project, MakefileCreationData.DEFAULT_JAVA_TARGET_PROPERTY, defaultJavaTarget.getActualValue());
setProperty(project, MakefileCreationData.GENERATE_START_SH_SCRIPT_PROPERTY,
String.valueOf(generateStartShScript.getSelection()));
setProperty(project, MakefileCreationData.GENERATE_START_BAT_SCRIPT_PROPERTY,
String.valueOf(generateStartBatScript.getSelection()));
String temp = temporalJavaTargetFileFieldEditor.getStringValue();
final URI path = URIUtil.toURI(temp);
final URI resolvedPath = TITANPathUtilities.resolvePathURI(temp, project.getLocation().toOSString());
if (path.equals(resolvedPath)) {
temp = PathUtil.getRelativePath(project.getLocation().toOSString(), temp);
}
setProperty(project, MakefileCreationData.TARGET_EXECUTABLE_PROPERTY, temp);
} catch (CoreException e) {
ErrorReporter.logExceptionStackTrace(e);
return false;
}
return true;
}
public void performDefaults(final IProject project) {
defaultJavaTarget.setSelectedValue(MakefileCreationData.DefaultJavaTarget.getDefault().toString());
temporalJavaTargetFileFieldEditor.setStringValue(MakefileCreationData.getDefaultJavaTargetName(project, false));
generateStartShScript.setSelection(MakefileCreationData.GENERATE_START_SH_SCRIPT_DEFAULT);
generateStartBatScript.setSelection(MakefileCreationData.GENERATE_START_BAT_SCRIPT_DEFAULT);
updateDefaultJavaTarget();
}
/**
* Sets the provided value, on the provided project, for the provided
* property.
*
* @param project
* the project to work on.
* @param name
* the name of the property to change.
* @param value
* the value to set.
*
* @exception CoreException
* if this method fails. Reasons include:
* <ul>
* <li>This project does not exist.</li>
* <li>This project is not local.</li>
* <li>This project is a project that is not open.</li>
* <li>Resource changes are disallowed during certain
* types of resource change event notification. See
* <code>IResourceChangeEvent</code> for more
* details.</li>
* </ul>
* */
private void setProperty(final IProject project, final String name, final String value) throws CoreException {
final QualifiedName qualifiedName = new QualifiedName(ProjectBuildPropertyData.QUALIFIER, name);
final String oldValue = project.getPersistentProperty(qualifiedName);
if (value != null && !value.equals(oldValue)) {
project.setPersistentProperty(qualifiedName, value);
}
}
/**
* Enables or disables the textbox of Java target and the checkboxes according to the selected value.
* If Class is selected, the textbox is disabled.
* If Executable is selected, the checkboxes are enabled.
*/
private void updateDefaultJavaTarget() {
temporalJavaTargetFileFieldEditor.setEnabled(true, javaTargetComposite);
generateStartShScript.setEnabled(false);
generateStartBatScript.setEnabled(false);
if (isClassSelected()) {
temporalJavaTargetFileFieldEditor.setEnabled(false, javaTargetComposite);
return;
}
if (isExecutableSelected()) {
generateStartShScript.setEnabled(true);
generateStartBatScript.setEnabled(true);
}
}
private boolean isClassSelected() {
return defaultJavaTarget.getActualValue().equals(MakefileCreationData.DefaultJavaTarget.CLASS.toString());
}
private boolean isExecutableSelected() {
return defaultJavaTarget.getActualValue().equals(MakefileCreationData.DefaultJavaTarget.EXECUTABLE.toString());
}
}
......@@ -43,6 +43,7 @@ public class ProjectJavaBuildPropertyPage extends PropertyPage {
private TabFolder makefileOperationsTabFolder;
private InternalJavaCreationTab internalMakefileCreationTab;
private JavaCreationTab javaCreationTab;
private final PreferenceStore tempStorage;
private IProject projectResource;
......@@ -58,6 +59,7 @@ public class ProjectJavaBuildPropertyPage extends PropertyPage {
@Override
public void dispose() {
headLabel.dispose();
javaCreationTab.dispose();
internalMakefileCreationTab.dispose();
makefileOperationsTabFolder.dispose();
pageComposite.dispose();
......@@ -190,7 +192,7 @@ public class ProjectJavaBuildPropertyPage extends PropertyPage {
firstConfiguration = configurationManager.getActualSelection();
makefileOperationsTabFolder = new TabFolder(pageComposite, SWT.BORDER);
final GridData makefileOperationsTabFolderGridData = new GridData();
makefileOperationsTabFolderGridData.horizontalAlignment = GridData.FILL;
makefileOperationsTabFolderGridData.verticalAlignment = GridData.FILL;
......@@ -198,6 +200,8 @@ public class ProjectJavaBuildPropertyPage extends PropertyPage {
makefileOperationsTabFolderGridData.grabExcessVerticalSpace = true;
makefileOperationsTabFolder.setLayoutData(makefileOperationsTabFolderGridData);
javaCreationTab = new JavaCreationTab(projectResource);
javaCreationTab.createContents(makefileOperationsTabFolder);
internalMakefileCreationTab = new InternalJavaCreationTab(projectResource);
internalMakefileCreationTab.createContents(makefileOperationsTabFolder);
......@@ -209,16 +213,14 @@ public class ProjectJavaBuildPropertyPage extends PropertyPage {
return pageComposite;
}
protected void updateContents() {
}
@Override
protected void performDefaults() {
javaCreationTab.performDefaults(projectResource);
internalMakefileCreationTab.performDefaults();
configurationManager.saveActualConfiguration();
}
......@@ -246,6 +248,9 @@ public class ProjectJavaBuildPropertyPage extends PropertyPage {
if (!pluginPreferenceStore.isDefault(MakeAttributesTab.TEMPORAL_WORKINGDIRECTORY)) {
pluginPreferenceStore.setToDefault(MakeAttributesTab.TEMPORAL_WORKINGDIRECTORY);
}
if (!pluginPreferenceStore.isDefault(JavaCreationTab.TEMPORAL_JAVA_TARGET)) {
pluginPreferenceStore.setToDefault(JavaCreationTab.TEMPORAL_JAVA_TARGET);
}
configurationManager.saveActualConfiguration();
ProjectDocumentHandlingUtility.saveDocument(projectResource);
......@@ -276,6 +281,7 @@ public class ProjectJavaBuildPropertyPage extends PropertyPage {
}
public void loadProperties() {
javaCreationTab.loadProperties(projectResource);
internalMakefileCreationTab.loadProperties(projectResource);
}
......@@ -306,6 +312,7 @@ public class ProjectJavaBuildPropertyPage extends PropertyPage {
* */
public boolean checkProperties() {
boolean result = true;
result &= javaCreationTab.checkProperties(this);
result &= internalMakefileCreationTab.checkProperties(this);
return result;
......@@ -314,6 +321,7 @@ public class ProjectJavaBuildPropertyPage extends PropertyPage {
public boolean saveProperties() {
boolean success = true;
// saving properties if checking was successful
success &= javaCreationTab.saveProperties(projectResource);
success &= internalMakefileCreationTab.saveProperties(projectResource);
setErrorMessage(null);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment