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

Smaller improvements (mainly related to generated comments)



Change-Id: Iabade18e9c5a729708a339719ac0898564007c5b
Signed-off-by: default avatarAdam Knapp <adam.knapp@sigmatechnology.se>
parent a3c57ba5
/******************************************************************************
* 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.common.utils;
import java.net.InetAddress;
import java.text.MessageFormat;
/**
* Util class for providing comments for different kinds of generated files,
* e.g. Java source files, bash files, XML files etc.
* @author Adam Knapp
* */
public final class CommentUtils {
private static final String HEADER_COMMENT_TEXT =
"{0}This Java file was generated by the TITAN Designer Eclipse plug-in version {1}\n"
+ "{0}for ({2}@{3})\n";
public static final String COPYRIGHT_TEXT = "Copyright (c) 2000-2021 Ericsson Telecom AB";
public static final String DO_NOT_EDIT_TEXT = "Do not edit this file unless you know what you are doing!";
/**
* Returns the header comment using the specified comment char
* @param commentChar Character indicating the start of comment
* @param versionString Version of Titan
* @return The header comment
*/
public static String getHeaderComments(final char commentChar, final String versionString) {
return getHeaderComments(String.valueOf(commentChar) + " ", versionString);
}
/**
* Returns the header comment using the specified comment string
* @param commentChar String indicating the start of comment
* @param versionString Version of Titan
* @return The header comment
*/
public static String getHeaderComments(final String commentString, final String versionString) {
String userName;
String hostName;
try {
userName = System.getProperty("user.name");
} catch (Exception e) {
userName = "unknown";
}
try {
hostName = InetAddress.getLocalHost().getHostName();
} catch (Exception e) {
hostName = "unknown";
}
return MessageFormat.format(HEADER_COMMENT_TEXT, commentString,
versionString, userName, hostName);
}
/**
* Returns the header comment using the specified comment string. It is extended with the copyright text.
* @param commentChar String indicating the start of comment
* @param versionString Version of Titan
* @return The header comment
*/
public static String getHeaderCommentsWithCopyright(final String commentString, final String versionString) {
return getHeaderComments(commentString, versionString) + commentString + COPYRIGHT_TEXT + "\n\n";
}
/**
* Returns the header comment using the specified comment string.
* It is extended with the copyright and do not edit texts.
* @param commentChar String indicating the start of comment
* @param versionString Version of Titan
* @return The header comment
*/
public static String getHeaderCommentsWithCopyrightAndDoNotEdit(final String commentString, final String versionString) {
return getHeaderCommentsWithCopyright(commentString, versionString) + commentString + DO_NOT_EDIT_TEXT + "\n";
}
}
......@@ -53,7 +53,6 @@ public final class GeneralConstants {
public static final String NUMBER_DEFAULT = "1";
public static final String VERSION_STRING = ON_THE_FLY_ANALYZER_VERSION.toString();
public static final String COPYRIGHT_STRING = "Copyright (c) 2000-2021 Ericsson Telecom AB";
public static final String PROJECT_PROPERTY_PAGE = "org.eclipse.titan.designer.properties.pages.ProjectBuildPropertyPage";
......@@ -66,6 +65,8 @@ public final class GeneralConstants {
FolderBuildPropertyData.EXCLUDE_FROM_BUILD_PROPERTY);
public static final String ACTIVITY_DEBUG = "org.eclipse.titan.designer.activities.debug";
public final static String JAVA_BUILD_DIR = "java_bin";
/** private constructor to disable instantiation */
private GeneralConstants() {
......
......@@ -11,8 +11,6 @@ import java.io.BufferedInputStream;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.text.MessageFormat;
import java.util.Set;
......@@ -22,6 +20,7 @@ import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.titan.common.utils.CommentUtils;
import org.eclipse.titan.common.utils.FileUtils;
import org.eclipse.titan.designer.GeneralConstants;
import org.eclipse.titan.designer.AST.MarkerHandler;
......@@ -33,6 +32,7 @@ import org.eclipse.titan.designer.parsers.ProjectSourceParser;
/**
* This is project level root of all java compiler related activities.
* @author Arpad Lovassy
* @author Adam Knapp
*/
public final class ProjectSourceCompiler {
private final static String PACKAGE_RUNTIME_ROOT = "org.eclipse.titan.runtime.core";
......@@ -178,7 +178,7 @@ public final class ProjectSourceCompiler {
generated = true;
}
}
/**
* Generates the common header comments: what generated the file, copyright
* <pre>
......@@ -194,21 +194,7 @@ public final class ProjectSourceCompiler {
public static void generateCommonHeaderComments(StringBuilder contentBuilder) {
if (contentBuilder == null)
return;
contentBuilder.append("// This Java file was generated by the TITAN Designer eclipse plug-in\n");
contentBuilder.append("// of the TTCN-3 Test Executor version " ).append(GeneralConstants.VERSION_STRING).append('\n');
contentBuilder.append("// for (").append(System.getProperty("user.name")).append('@');
try {
contentBuilder.append(InetAddress.getLocalHost().getHostName());
} catch (UnknownHostException e) {
contentBuilder.append("unknown");
}
contentBuilder.append(")\n");
contentBuilder.append('\n' );
contentBuilder.append("// ").append(GeneralConstants.COPYRIGHT_STRING).append('\n');
contentBuilder.append('\n' );
contentBuilder.append(CommentUtils.getHeaderCommentsWithCopyright("// ", GeneralConstants.VERSION_STRING));
}
/**
......@@ -229,9 +215,9 @@ public final class ProjectSourceCompiler {
contentBuilder.append("/**\n");
contentBuilder.append(MessageFormat.format(" * <code>{0}</code> package contains classes\n", getPackageGeneratedRoot(project)));
contentBuilder.append(MessageFormat.format(" * that were generated by Titan''s Java code generator, from the TTCN-3 and ASN.1 source codes in the project {0}.\n", project.getName()));
contentBuilder.append(MessageFormat.format(" * that were generated by Titan's Java code generator, from the TTCN-3 and ASN.1 source codes in the project {0}.\n", project.getName()));
contentBuilder.append(" *<p>\n");
contentBuilder.append(" * Do not edit this file unless you know what you are doing!\n");
contentBuilder.append(" * ").append(CommentUtils.DO_NOT_EDIT_TEXT).append("\n");
contentBuilder.append(" */\n");
contentBuilder.append( "package " );
contentBuilder.append( getPackageGeneratedRoot(project) );
......@@ -269,7 +255,7 @@ public final class ProjectSourceCompiler {
contentBuilder.append(MessageFormat.format(" * <code>{0}</code> package contains classes\n", getPackageUserProvidedRoot(project)));
contentBuilder.append(MessageFormat.format(" * that were written by the user, and contain the implementations of test ports and external functions, in the project {0}.\n", project.getName()));
contentBuilder.append(" *<p>\n");
contentBuilder.append(" * Do not edit this file unless you know what you are doing!\n");
contentBuilder.append(" * ").append(CommentUtils.DO_NOT_EDIT_TEXT).append("\n");
contentBuilder.append(" */\n");
contentBuilder.append( "package " );
contentBuilder.append( getPackageUserProvidedRoot(project) );
......@@ -304,7 +290,7 @@ public final class ProjectSourceCompiler {
generateCommonHeaderComments(contentBuilder);
contentBuilder.append( "// Do not edit this file unless you know what you are doing.\n" );
contentBuilder.append( "// "+ CommentUtils.DO_NOT_EDIT_TEXT + "\n" );
contentBuilder.append( '\n' );
contentBuilder.append( "package " );
contentBuilder.append( getPackageGeneratedRoot(project) );
......@@ -366,7 +352,7 @@ public final class ProjectSourceCompiler {
generateCommonHeaderComments(contentBuilder);
contentBuilder.append( "// Do not edit this file unless you know what you are doing.\n" );
contentBuilder.append( "// " + CommentUtils.DO_NOT_EDIT_TEXT + "\n" );
contentBuilder.append( '\n' );
contentBuilder.append( "package " );
contentBuilder.append( getPackageGeneratedRoot(project) );
......
......@@ -44,6 +44,7 @@ import org.eclipse.titan.common.path.PathConverter;
import org.eclipse.titan.common.path.PathUtil;
import org.eclipse.titan.common.path.TITANPathUtilities;
import org.eclipse.titan.common.product.ProductIdentity;
import org.eclipse.titan.common.utils.CommentUtils;
import org.eclipse.titan.common.utils.Cygwin;
import org.eclipse.titan.common.utils.IOUtils;
import org.eclipse.titan.common.utils.ResourceUtils;
......@@ -738,7 +739,7 @@ public final class InternalMakefileGenerator {
final String date = simpleDateFormat.format(new Date());
contents.append(") on ").append(date).append("\n\n");
contents.append("# ").append(GeneralConstants.COPYRIGHT_STRING).append('\n');
contents.append("# ").append(CommentUtils.COPYRIGHT_TEXT).append('\n');
contents.append('\n');
contents.append("# The following make commands are available:\n");
contents.append("# - make, make all ");
......
......@@ -129,7 +129,8 @@ public final class MakefileCreationData {
public static String[][] getDisplayNamesAndValues() {
return new String[][] { { "Class files", DefaultJavaTarget.CLASS.toString() },
{ "Executable JAR", DefaultJavaTarget.EXECUTABLE.toString() },
{ "JAR", DefaultJavaTarget.JAR.toString() } };
// TODO: exporting to simple JAR is not implemented yet, users have to do it manually
/*{ "JAR", DefaultJavaTarget.JAR.toString() }*/ };
}
}
......
......@@ -64,7 +64,7 @@ public class InternalJavaCreationTab {
protected TabItem createContents(final TabFolder tabFolder) {
newBuildPropertiesTabItem = new TabItem(tabFolder, SWT.BORDER);
newBuildPropertiesTabItem.setText("Internal makefile creation attributes");
newBuildPropertiesTabItem.setText("Internal build attributes");
newBuildPropertiesTabItem.setToolTipText("Settings controlling the new generation of the makefile.");
newBuildPropertiesComposite = new Composite(tabFolder, SWT.MULTI);
......
......@@ -16,6 +16,7 @@ import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.QualifiedName;
import org.eclipse.titan.common.logging.ErrorReporter;
import org.eclipse.titan.common.utils.CommentUtils;
import org.eclipse.titan.common.utils.StringUtils;
import org.eclipse.titan.designer.GeneralConstants;
import org.eclipse.titan.designer.properties.data.ProjectBuildPropertyData;
......@@ -97,7 +98,7 @@ public class HelloWorldSample extends SampleProject {
+ "// TTCN-3 Compiler of the TTCN-3 Test Executor version " + GeneralConstants.VERSION_STRING + NEWLINE
+ "// for (" + System.getProperty("user.name") + "@" + HOSTNAME + ")" + NEWLINE
+ NEWLINE
+ "// " + GeneralConstants.COPYRIGHT_STRING + NEWLINE
+ "// " + CommentUtils.COPYRIGHT_TEXT + NEWLINE
+ NEWLINE
+ "// You may modify this file. Add your attributes and prototypes of your" + NEWLINE
+ "// member functions here." + NEWLINE
......@@ -148,7 +149,7 @@ public class HelloWorldSample extends SampleProject {
+ "// TTCN-3 Compiler of the TTCN-3 Test Executor version " + GeneralConstants.VERSION_STRING + NEWLINE
+ "// for (" + System.getProperty("user.name") + "@" + HOSTNAME + ")" + NEWLINE
+ NEWLINE
+ "// " + GeneralConstants.COPYRIGHT_STRING + NEWLINE
+ "// " + CommentUtils.COPYRIGHT_TEXT + NEWLINE
+ NEWLINE
+ "// You may modify this file. Complete the body of empty functions and" + NEWLINE
+ "// add your member functions here." + NEWLINE
......
......@@ -41,6 +41,7 @@ import org.eclipse.titan.designer.compiler.ProjectSourceCompiler;
import org.eclipse.titan.designer.core.TITANJavaBuilder;
import org.eclipse.titan.designer.core.TITANNature;
import org.eclipse.titan.designer.properties.data.MakeAttributesData;
import org.eclipse.titan.designer.properties.data.MakefileCreationData;
import org.eclipse.titan.designer.properties.data.ProjectBuildPropertyData;
import org.eclipse.titan.designer.properties.data.ProjectDocumentHandlingUtility;
import org.eclipse.titan.designer.properties.data.ProjectFileHandler;
......@@ -277,6 +278,9 @@ public class NewTITANJavaProjectWizard extends BasicNewResourceWizard implements
try {
newProject.setPersistentProperty(new QualifiedName(ProjectBuildPropertyData.QUALIFIER,
MakeAttributesData.TEMPORAL_WORKINGDIRECTORY_PROPERTY), "java_src");
final String executableJar = MakefileCreationData.getDefaultJavaTargetName(newProject, false);
newProject.setPersistentProperty(new QualifiedName(ProjectBuildPropertyData.QUALIFIER,
MakefileCreationData.TARGET_EXECUTABLE_PROPERTY), executableJar);
final IJavaProject javaProject = JavaCore.create(newProject);
final List<IClasspathEntry> classpathEntries = new ArrayList<IClasspathEntry>();
......
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