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

Adding JAR building feature to CLI-based building



&17
Signed-off-by: Adam Knapp's avatarAdam Knapp <adam.knapp@ericsson.com>
parent 6b685bc3
...@@ -7,6 +7,9 @@ ...@@ -7,6 +7,9 @@
******************************************************************************/ ******************************************************************************/
package org.eclipse.titan.designer.application; package org.eclipse.titan.designer.application;
import java.net.URI;
import org.eclipse.core.filesystem.URIUtil;
import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IncrementalProjectBuilder; import org.eclipse.core.resources.IncrementalProjectBuilder;
...@@ -14,9 +17,19 @@ import org.eclipse.core.resources.ResourcesPlugin; ...@@ -14,9 +17,19 @@ import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.QualifiedName;
import org.eclipse.equinox.app.IApplication; import org.eclipse.equinox.app.IApplication;
import org.eclipse.equinox.app.IApplicationContext; import org.eclipse.equinox.app.IApplicationContext;
import org.eclipse.titan.common.logging.ErrorReporter; 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.core.TITANJavaBuilder;
import org.eclipse.titan.designer.core.ant.AntLaunchConfigGenerator;
import org.eclipse.titan.designer.core.ant.AntScriptGenerator;
import org.eclipse.titan.designer.core.ant.CliScriptGenerator;
import org.eclipse.titan.designer.properties.data.MakefileCreationData;
import org.eclipse.titan.designer.properties.data.ProjectBuildPropertyData;
/** /**
* Externally callable application, that takes exactly one argument: the name of the project it should build. * Externally callable application, that takes exactly one argument: the name of the project it should build.
...@@ -25,44 +38,92 @@ import org.eclipse.titan.common.logging.ErrorReporter; ...@@ -25,44 +38,92 @@ import org.eclipse.titan.common.logging.ErrorReporter;
* */ * */
public final class InvokeBuild implements IApplication { public final class InvokeBuild implements IApplication {
/**
* Turns on the automatic JAR export feature on the specified project
* @param project
*/
public void addJarBuilder(final IProject project, final String pathToJar) throws CoreException {
String temp = pathToJar;
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);
}
project.setPersistentProperty(new QualifiedName(ProjectBuildPropertyData.QUALIFIER,
MakefileCreationData.TARGET_EXECUTABLE_PROPERTY), temp);
project.setPersistentProperty(new QualifiedName(ProjectBuildPropertyData.QUALIFIER,
MakefileCreationData.DEFAULT_JAVA_TARGET_PROPERTY), MakefileCreationData.DefaultJavaTarget.EXECUTABLE.toString());
project.setPersistentProperty(new QualifiedName(ProjectBuildPropertyData.QUALIFIER,
MakefileCreationData.GENERATE_START_SH_SCRIPT_PROPERTY), String.valueOf(true));
if (AntScriptGenerator.generateAndStoreBuildXML(project, true)) {
AntLaunchConfigGenerator.createAntLaunchConfiguration(project);
AntLaunchConfigGenerator.addAntBuilder(project);
project.refreshLocal(IResource.DEPTH_ONE, null);
}
CliScriptGenerator.generateAndStoreScripts(project);
AntLaunchConfigGenerator.setAntBuilderEnabled(project, true);
}
private Integer closeWorkspace() {
try {
ResourcesPlugin.getWorkspace().save(true, null);
return EXIT_OK;
} catch (CoreException e) {
ErrorReporter.logExceptionStackTrace("Error while closing workspace", e);
return Integer.valueOf(-1);
}
}
@Override @Override
/** {@inheritDoc} */ /** {@inheritDoc} */
public Object start(final IApplicationContext context) throws Exception { public Object start(final IApplicationContext context) throws Exception {
Platform.getBundle("org.eclipse.titan.designer").start(); Platform.getBundle("org.eclipse.titan.designer").start();
final String[] projectNames = (String[]) context.getArguments().get(IApplicationContext.APPLICATION_ARGS); final String[] args = (String[]) context.getArguments().get(IApplicationContext.APPLICATION_ARGS);
if (projectNames.length != 1) { if (args.length % 2 != 1) {
System.out.println("This application takes as parameter the name of the project it should build."); System.out.println("This application takes as parameter the name of the project it should build.\n"
return Integer.valueOf(-1); + "Optionally JAR output can be specified by the `-jar path_to_jar' option.");
return closeWorkspace();
} }
String projectName = null, pathToJar = null;
for (int i = 0; i < args.length; ++i) {
if (args[i].equals("-jar") && i < args.length-1) {
pathToJar = args[++i];
continue;
}
projectName = args[i];
}
if (!PathUtil.isValidFilePath(pathToJar)) {
System.out.println("The path `" + pathToJar + "' is not valid.");
return closeWorkspace();
}
final IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects(); final IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
for (final IProject project : projects) { for (final IProject project : projects) {
if (project != null && project.getName().equals(projectNames[0])) { if (project != null && project.getName().equals(projectName)) {
try { try {
project.refreshLocal(IResource.DEPTH_INFINITE, null); project.refreshLocal(IResource.DEPTH_INFINITE, null);
if (!StringUtils.isNullOrEmpty(pathToJar) && TITANJavaBuilder.isBuilderEnabled(project)) {
addJarBuilder(project, pathToJar);
}
project.build(IncrementalProjectBuilder.FULL_BUILD, new NullProgressMonitor());
} catch (CoreException e) { } catch (CoreException e) {
ErrorReporter.logExceptionStackTrace(e); ErrorReporter.logExceptionStackTrace(e);
} catch (Exception e) {
ErrorReporter.logExceptionStackTrace("Unknown error", e);
} }
project.build(IncrementalProjectBuilder.FULL_BUILD, new NullProgressMonitor()); return closeWorkspace();
try {
ResourcesPlugin.getWorkspace().save(true, null);
} catch (CoreException e) {
ErrorReporter.logExceptionStackTrace("Error while closing workspace",e);
}
return EXIT_OK;
} }
} }
System.out.println("The project with name `" + projectNames[0] + "' could not be found.");
return Integer.valueOf(-1); System.out.println("The project with name `" + projectName + "' could not be found.");
return closeWorkspace();
} }
@Override @Override
/** {@inheritDoc} */ /** {@inheritDoc} */
public void stop() { public void stop() {
// nothing to be done // nothing to be done
} }
} }
...@@ -224,9 +224,12 @@ public final class AntScriptGenerator { ...@@ -224,9 +224,12 @@ public final class AntScriptGenerator {
return null; return null;
} }
final File jarFile = new File(jarPathString); final File jarFile = new File(jarPathString);
final String jarFolder = jarFile.getParent(); String jarFolder = jarFile.getParent();
if (StringUtils.isNullOrEmpty(jarFolder)) {
jarFolder = ".";
}
final String jarFileName = jarFile.getName(); final String jarFileName = jarFile.getName();
if (StringUtils.isNullOrEmpty(jarFolder) || StringUtils.isNullOrEmpty(jarFileName)) { if (StringUtils.isNullOrEmpty(jarFileName)) {
ErrorReporter.INTERNAL_ERROR("Jar file is null or empty"); ErrorReporter.INTERNAL_ERROR("Jar file is null or empty");
return null; return 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