Commit 0e0ec75f authored by Adam Knapp's avatar Adam Knapp
Browse files

Replacing local literals with global constants



Change-Id: I66e52ae33c9f7b0fd4ad537597d2d0ffd4b85307
Signed-off-by: default avatarAdam Knapp <adam.knapp@sigmatechnology.se>
parent 87f1c9b1
......@@ -13,7 +13,7 @@ import java.io.IOException;
import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.titan.common.logging.ErrorReporter;
public final class FileUtils {
......@@ -50,7 +50,7 @@ public final class FileUtils {
private static boolean deleteIfExists(final File file) {
return file.exists() && !file.delete();
}
/**
* RECURSIVE
* Creates full directory path
......@@ -58,12 +58,23 @@ public final class FileUtils {
* @throws CoreException
*/
public static void createDir( final IFolder aFolder ) throws CoreException {
createDir(aFolder, null);
}
/**
* RECURSIVE
* Creates full directory path
* @param aFolder directory to create
* @param monitor a progress monitor, or {@code null} if progress reporting is not desired
* @throws CoreException
*/
public static void createDir( final IFolder aFolder, final IProgressMonitor monitor ) throws CoreException {
if (!aFolder.exists()) {
final IContainer parent = aFolder.getParent();
if (parent instanceof IFolder) {
createDir( (IFolder) parent );
}
aFolder.create( true, true, new NullProgressMonitor() );
aFolder.create( true, true, monitor );
}
}
}
......@@ -66,7 +66,10 @@ public final class GeneralConstants {
public static final String ACTIVITY_DEBUG = "org.eclipse.titan.designer.activities.debug";
public final static String JAVA_BUILD_DIR = "java_bin";
public static final String JAVA_BUILD_DIR = "java_bin";
public static final String JAVA_SOURCE_DIR = "java_src";
public static final String JAVA_TEMP_DIR = "temp";
public static final String JAVA_USER_PROVIDED = "user_provided";
/** private constructor to disable instantiation */
private GeneralConstants() {
......
......@@ -72,7 +72,7 @@ public final class ProjectSourceCompiler {
public static String getPackageUserProvidedRoot(final IProject project) {
final String projectName = project.getName().replaceAll("[^\\p{IsAlphabetic}^\\p{IsDigit}]", "_");
return MessageFormat.format("org.eclipse.titan.{0}.user_provided", projectName);
return MessageFormat.format("org.eclipse.titan.{0}." + GeneralConstants.JAVA_USER_PROVIDED, projectName);
}
/**
......@@ -83,7 +83,7 @@ public final class ProjectSourceCompiler {
public static String getGeneratedRoot(final IProject project) {
final String projectName = project.getName().replaceAll("[^\\p{IsAlphabetic}^\\p{IsDigit}]", "_");
return MessageFormat.format("java_src/org/eclipse/titan/{0}/generated", projectName);
return MessageFormat.format(GeneralConstants.JAVA_SOURCE_DIR + "/org/eclipse/titan/{0}/generated", projectName);
}
/**
......@@ -94,7 +94,7 @@ public final class ProjectSourceCompiler {
public static String getUserProvidedRoot(final IProject project) {
final String projectName = project.getName().replaceAll("[^\\p{IsAlphabetic}^\\p{IsDigit}]", "_");
return MessageFormat.format("user_provided/org/eclipse/titan/{0}/user_provided", projectName);
return MessageFormat.format(GeneralConstants.JAVA_USER_PROVIDED + "/org/eclipse/titan/{0}/" + GeneralConstants.JAVA_USER_PROVIDED, projectName);
}
public static void generateSourceFolder(final IProject project) throws CoreException {
......
......@@ -138,7 +138,7 @@ public final class ProjectBasedBuilder {
* */
public IContainer[] getWorkingDirectoryResources(final boolean reportError) {
if (TITANJavaBuilder.isBuilderEnabled(project)) {
final IFolder folder = project.getFolder("java_bin");
final IFolder folder = project.getFolder(GeneralConstants.JAVA_BUILD_DIR);
final IContainer containers[] = new IContainer[1];
containers[0] = folder;
return containers;
......
......@@ -22,6 +22,7 @@ import org.eclipse.core.runtime.SubMonitor;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.titan.common.logging.ErrorReporter;
import org.eclipse.titan.designer.Activator;
import org.eclipse.titan.designer.GeneralConstants;
import org.eclipse.titan.designer.AST.Module;
import org.eclipse.titan.designer.compiler.BuildTimestamp;
import org.eclipse.titan.designer.compiler.ProjectSourceCompiler;
......@@ -110,25 +111,35 @@ public class TITANJavaBuilder extends IncrementalProjectBuilder {
super.clean(monitor);
final SubMonitor progress = SubMonitor.convert(monitor, 100);
progress.subTask("Deleting java_src/org");
progress.subTask("Deleting " + GeneralConstants.JAVA_SOURCE_DIR + "/org");
final IProject project = getProject();
IFolder folder = project.getFolder( "java_src/org");
IFolder folder = project.getFolder(GeneralConstants.JAVA_SOURCE_DIR + "/org");
if( folder.exists() ) {
try {
folder.delete(true, progress.newChild(50));
folder.delete(true, progress.newChild(40));
} catch (CoreException e) {
ErrorReporter.logExceptionStackTrace("While cleaning generated code in java_src", e);
ErrorReporter.logExceptionStackTrace("While cleaning generated code in " + GeneralConstants.JAVA_SOURCE_DIR, e);
}
}
progress.subTask("Deleting java_bin");
folder = project.getFolder("java_bin");
progress.subTask("Deleting " + GeneralConstants.JAVA_BUILD_DIR);
folder = project.getFolder(GeneralConstants.JAVA_BUILD_DIR);
if( folder.exists() ) {
try {
folder.delete(true, progress.newChild(50));
} catch (CoreException e) {
ErrorReporter.logExceptionStackTrace("While cleaning generated code in java_bin ", e);
ErrorReporter.logExceptionStackTrace("While cleaning generated code in " + GeneralConstants.JAVA_BUILD_DIR, e);
}
}
progress.subTask("Deleting " + GeneralConstants.JAVA_TEMP_DIR);
folder = project.getFolder(GeneralConstants.JAVA_TEMP_DIR);
if( folder.exists() ) {
try {
folder.delete(true, progress.newChild(10));
} catch (CoreException e) {
ErrorReporter.logExceptionStackTrace("While cleaning files in " + GeneralConstants.JAVA_TEMP_DIR, e);
}
}
......
......@@ -379,6 +379,6 @@ public final class MakefileCreationData {
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";
return GeneralConstants.JAVA_BUILD_DIR + File.separator + name.replace("bin" + File.separator, "").replace(".exe", "") + ".jar";
}
}
......@@ -37,6 +37,7 @@ import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.titan.common.logging.ErrorReporter;
import org.eclipse.titan.designer.Activator;
import org.eclipse.titan.designer.GeneralConstants;
import org.eclipse.titan.designer.compiler.ProjectSourceCompiler;
import org.eclipse.titan.designer.core.TITANJavaBuilder;
import org.eclipse.titan.designer.core.TITANNature;
......@@ -124,7 +125,7 @@ public class NewTITANJavaProjectWizard extends BasicNewResourceWizard implements
protected void execute(final IProgressMonitor monitor) throws CoreException {
createProject(description, newProjectHandle, monitor);
IFolder folder = newProjectHandle.getFolder("java_src");
IFolder folder = newProjectHandle.getFolder(GeneralConstants.JAVA_SOURCE_DIR);
if (!folder.exists()) {
try {
folder.create(true, true, null);
......@@ -132,7 +133,7 @@ public class NewTITANJavaProjectWizard extends BasicNewResourceWizard implements
ErrorReporter.logExceptionStackTrace(e);
}
}
folder = newProjectHandle.getFolder("user_provided");
folder = newProjectHandle.getFolder(GeneralConstants.JAVA_USER_PROVIDED);
if (!folder.exists()) {
try {
folder.create(true, true, null);
......@@ -140,7 +141,7 @@ public class NewTITANJavaProjectWizard extends BasicNewResourceWizard implements
ErrorReporter.logExceptionStackTrace(e);
}
}
folder = newProjectHandle.getFolder("java_bin");
folder = newProjectHandle.getFolder(GeneralConstants.JAVA_BUILD_DIR);
if (!folder.exists()) {
try {
folder.create(true, true, null);
......@@ -218,9 +219,9 @@ public class NewTITANJavaProjectWizard extends BasicNewResourceWizard implements
private void createBuildProperties() throws CoreException {
final StringBuilder content = new StringBuilder();
content.append("source.. = java_src/,\\\n");
content.append(" user_provided/\n");
content.append("output.. = java_bin/\n");
content.append("source.. = " + GeneralConstants.JAVA_SOURCE_DIR + "/,\\\n");
content.append(" " + GeneralConstants.JAVA_USER_PROVIDED + "/\n");
content.append("output.. = " + GeneralConstants.JAVA_BUILD_DIR + "/\n");
content.append("bin.includes = META-INF/,\\\n");
content.append(" .\n");
......@@ -234,8 +235,6 @@ public class NewTITANJavaProjectWizard extends BasicNewResourceWizard implements
}
private void createManifest() throws CoreException {
final String projectJavaName = newProject.getName().replaceAll("[^\\p{IsAlphabetic}^\\p{IsDigit}]", "_");
final StringBuilder content = new StringBuilder("Manifest-Version: 1.0\n");
content.append("Bundle-ManifestVersion: 2\n");
content.append("Bundle-Name: " + newProject.getName() + "\n");
......@@ -245,8 +244,8 @@ public class NewTITANJavaProjectWizard extends BasicNewResourceWizard implements
content.append(" org.antlr.runtime;bundle-version=\"4.3.0\"\n");
content.append("Bundle-RequiredExecutionEnvironment: JavaSE-1.6\n");
content.append("Bundle-ActivationPolicy: lazy\n");
content.append("Export-Package: org.eclipse.titan." + projectJavaName + ".generated,\n");
content.append(" org.eclipse.titan." + projectJavaName + ".user_provided\n");
content.append("Export-Package: " + ProjectSourceCompiler.getPackageGeneratedRoot(newProject) + ",\n");
content.append(" " + ProjectSourceCompiler.getPackageUserProvidedRoot(newProject) + "\n");
final IFolder metaInf = newProject.getFolder("META-INF");
if (!metaInf.exists()) {
......@@ -277,7 +276,7 @@ public class NewTITANJavaProjectWizard extends BasicNewResourceWizard implements
try {
newProject.setPersistentProperty(new QualifiedName(ProjectBuildPropertyData.QUALIFIER,
MakeAttributesData.TEMPORAL_WORKINGDIRECTORY_PROPERTY), "java_src");
MakeAttributesData.TEMPORAL_WORKINGDIRECTORY_PROPERTY), GeneralConstants.JAVA_SOURCE_DIR);
final String executableJar = MakefileCreationData.getDefaultJavaTargetName(newProject, false);
newProject.setPersistentProperty(new QualifiedName(ProjectBuildPropertyData.QUALIFIER,
MakefileCreationData.TARGET_EXECUTABLE_PROPERTY), executableJar);
......@@ -286,10 +285,10 @@ public class NewTITANJavaProjectWizard extends BasicNewResourceWizard implements
final List<IClasspathEntry> classpathEntries = new ArrayList<IClasspathEntry>();
classpathEntries.add(JavaCore.newContainerEntry(new Path("org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5")));
classpathEntries.add(JavaCore.newContainerEntry(new Path("org.eclipse.pde.core.requiredPlugins")));
classpathEntries.add(JavaCore.newSourceEntry(new Path("/" + newProject.getName() +"/java_src")));
classpathEntries.add(JavaCore.newSourceEntry(new Path("/" + newProject.getName() +"/user_provided")));
classpathEntries.add(JavaCore.newSourceEntry(new Path("/" + newProject.getName() + "/" + GeneralConstants.JAVA_SOURCE_DIR)));
classpathEntries.add(JavaCore.newSourceEntry(new Path("/" + newProject.getName() +"/" + GeneralConstants.JAVA_USER_PROVIDED)));
javaProject.setRawClasspath(classpathEntries.toArray(new IClasspathEntry[classpathEntries.size()]), null);
javaProject.setOutputLocation(new Path("/" + newProject.getName() + "/java_bin"), null);
javaProject.setOutputLocation(new Path("/" + newProject.getName() + "/" + GeneralConstants.JAVA_BUILD_DIR), null);
createBuildProperties();
createManifest();
......@@ -334,11 +333,9 @@ public class NewTITANJavaProjectWizard extends BasicNewResourceWizard implements
ErrorReporter.logExceptionStackTrace(e);
}
BasicNewProjectResourceWizard.updatePerspective(config);
selectAndReveal(newProject);
return true;
}
}
......@@ -33,6 +33,7 @@ import org.eclipse.debug.ui.IDebugUIConstants;
import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
import org.eclipse.titan.common.logging.ErrorReporter;
import org.eclipse.titan.common.parsers.cfg.ConfigFileHandler;
import org.eclipse.titan.designer.GeneralConstants;
import org.eclipse.titan.designer.consoles.TITANConsole;
import org.eclipse.titan.executor.designerconnection.DynamicLinkingHelper;
import org.eclipse.titan.executor.views.executormonitor.ExecutorMonitorView;
......@@ -46,7 +47,7 @@ public final class LaunchConfigurationUtil {
private static final String MAIN_SINGLE = "org.eclipse.titan.{0}.generated.Single_main";
private static final String MAIN_PARALLEL = "org.eclipse.titan.{0}.generated.Parallel_main";
private static final String PATH_PREFIX = "java_src";
private static final String PATH_PREFIX = GeneralConstants.JAVA_SOURCE_DIR;
private static final String GROUP_LAUNCH_CONFIGURATION_ID = "org.eclipse.debug.core.groups.GroupLaunchConfigurationType";
private static final String LAUNCH_CONFIGURATION_LIST_ATTR = PLUGIN_ID + ".linkedLaunchConfigurations";
......
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