Commit c1350468 authored by Florian Hölzl's avatar Florian Hölzl
Browse files

some extensions to tools and equivalence test

refs 727
parent 7961ae52
......@@ -22,6 +22,7 @@ import static org.eclipse.core.runtime.Assert.isTrue;
import java.io.File;
import java.io.IOException;
import java.util.List;
import org.fortiss.tooling.kernel.model.INamedElement;
......@@ -30,24 +31,23 @@ import org.fortiss.tooling.kernel.model.INamedElement;
* Instead of generating the input file(s) for the external tool this runner uses an existing file
* (or folder) as its source.
*
* @param <T>
* the result type
* The result type of the runner is its console output, i.e., a list of strings.
*
* @author hoelzl
* @author $Author$
* @version $Rev$
* @ConQAT.Rating RED Hash:
*/
public abstract class SimpleToolRunnerBase<T> extends ToolRunnerBase<INamedElement, T> {
public abstract class SimpleToolRunnerBase extends ToolRunnerBase<INamedElement, List<String>> {
/** The file or location used by this tool runner. */
/** The file used by this tool runner. */
protected final File physicalFile;
/** Constructor. */
public SimpleToolRunnerBase(File physicalFileOrLocation) {
isNotNull(physicalFileOrLocation);
isTrue(physicalFileOrLocation.exists());
this.physicalFile = physicalFileOrLocation;
public SimpleToolRunnerBase(File physicalFile) {
isNotNull(physicalFile);
isTrue(physicalFile.exists());
this.physicalFile = physicalFile;
}
/** Constructor. */
......@@ -62,33 +62,36 @@ public abstract class SimpleToolRunnerBase<T> extends ToolRunnerBase<INamedEleme
return physicalFile;
}
/** A lazy result of GCC. */
protected class SimpleLazyResult extends LazyResultBase {
/** Constructor. */
public SimpleLazyResult(File physicalFile) {
super(new SimpleToolRunningTask(physicalFile));
}
/** {@inheritDoc} */
@Override
public ILazyResult<List<String>> runTool() {
return new LazyResultBase(new SimpleToolRunningTask());
}
/** A simple tool runner task. */
private class SimpleToolRunningTask extends ToolRunningTask {
/** Constructor. */
SimpleToolRunningTask(File physicalFile) {
super(physicalFile, getResultBuilder(), getCommandList());
SimpleToolRunningTask() {
super(SimpleToolRunnerBase.this.physicalFile, new SimpleResultBuilder(),
getCommandList());
}
/** {@inheritDoc} */
@Override
protected T doProcessRunResults(StreamReader errorStreamReader,
protected List<String> doProcessRunResults(StreamReader errorStreamReader,
StreamReader inputStreamReader) throws IOException, Exception {
return resultBuilder.buildResult(inputStreamReader.getReadLines());
}
}
/** The result builder for this tool runner. */
public abstract IResultBuilder<T> getResultBuilder();
/** The simple result builder returning the console output. */
private class SimpleResultBuilder implements IResultBuilder<List<String>> {
/** {@inheritDoc} */
@Override
public List<String> buildResult(List<String> lines) {
return lines;
}
}
/** The command list for this tool runner. */
public abstract String[] getCommandList();
......
......@@ -45,8 +45,7 @@ import org.fortiss.af3.tools.ToolsActivator;
import org.fortiss.tooling.kernel.model.INamedElement;
/**
* The base class for tool-runners, the default implementation of
* {@link IToolRunner}.
* The base class for tool-runners, the default implementation of {@link IToolRunner}.
*
* @param <S>
* - the logical file type.
......@@ -58,8 +57,7 @@ import org.fortiss.tooling.kernel.model.INamedElement;
* @version $Rev: 18709 $
* @ConQAT.Rating GREEN Hash: 4CFB0DC725E695D473ADDB9B0349D804
*/
public abstract class ToolRunnerBase<S extends INamedElement, T> implements
IToolRunner<T> {
public abstract class ToolRunnerBase<S extends INamedElement, T> implements IToolRunner<T> {
/** Whether the tool should be debugged. */
public static boolean DEBUG = false;
......@@ -77,17 +75,16 @@ public abstract class ToolRunnerBase<S extends INamedElement, T> implements
protected abstract String getToolCommand();
/** Generates the physical file. */
protected File generatePhysicalFile(ITextGenerator<S> textGen,
String fileExtension) throws IOException,
UnknownLanguageFragmentException {
protected File generatePhysicalFile(ITextGenerator<S> textGen, String fileExtension)
throws IOException, UnknownLanguageFragmentException {
IPath location = plugin.getStateLocation();
Random randomGenerator = new Random();
String patchedPhysicalFileName = logicalFile.getName().replaceAll(
"[^A-Za-z0-9]", "");
File physicalFile = new File(location.toFile(), patchedPhysicalFileName
+ randomGenerator.nextLong() + fileExtension);
String patchedPhysicalFileName = logicalFile.getName().replaceAll("[^A-Za-z0-9]", "");
File physicalFile =
new File(location.toFile(), patchedPhysicalFileName + randomGenerator.nextLong() +
fileExtension);
BufferedWriter bw = new BufferedWriter(new FileWriter(physicalFile));
textGen.generateText(bw, logicalFile);
bw.close();
......@@ -99,19 +96,15 @@ public abstract class ToolRunnerBase<S extends INamedElement, T> implements
* Performs a smoke run of a tool and returns a pair of strings representing
* the normal and error outputs or null if an exception occurred.
*/
protected Pair<String, String> smokeToolRun(String toolName,
String showVersionOption) {
protected Pair<String, String> smokeToolRun(String toolName, String showVersionOption) {
try {
info(plugin, "Smoke tool run " + toolName + " with option: "
+ showVersionOption);
info(plugin, "Smoke tool run " + toolName + " with option: " + showVersionOption);
Process testProcess = Runtime.getRuntime().exec(
new String[] { toolName, showVersionOption }, null);
Process testProcess =
Runtime.getRuntime().exec(new String[] {toolName, showVersionOption}, null);
StreamReader errorStreamReader = new StreamReader(
testProcess.getErrorStream());
StreamReader inputStreamReader = new StreamReader(
testProcess.getInputStream());
StreamReader errorStreamReader = new StreamReader(testProcess.getErrorStream());
StreamReader inputStreamReader = new StreamReader(testProcess.getInputStream());
inputStreamReader.start();
errorStreamReader.start();
......@@ -125,9 +118,9 @@ public abstract class ToolRunnerBase<S extends INamedElement, T> implements
String errorMessage = errorStreamReader.getReadString();
return new Pair<String, String>(normalMessage, errorMessage);
} catch (IOException e) {
} catch(IOException e) {
e.printStackTrace();
} catch (InterruptedException e) {
} catch(InterruptedException e) {
e.printStackTrace();
}
return null;
......@@ -157,11 +150,11 @@ public abstract class ToolRunnerBase<S extends INamedElement, T> implements
InputStreamReader isr = new InputStreamReader(inputStream);
BufferedReader br = new BufferedReader(isr);
String line = null;
while ((line = br.readLine()) != null) {
while((line = br.readLine()) != null) {
result.add(line);
}
isr.close();
} catch (IOException ioe) {
} catch(IOException ioe) {
ioe.printStackTrace();
thrownException = ioe;
}
......@@ -172,7 +165,7 @@ public abstract class ToolRunnerBase<S extends INamedElement, T> implements
* the IOException that was thrown during {@link #run()}.
*/
public List<String> getReadLines() throws IOException {
if (thrownException != null) {
if(thrownException != null) {
throw thrownException;
}
return result;
......@@ -180,15 +173,14 @@ public abstract class ToolRunnerBase<S extends INamedElement, T> implements
/**
* Returns the read lines as a single string if the read was successful
* or further throws the IOException that was thrown during
* {@link #run()}.
* or further throws the IOException that was thrown during {@link #run()}.
*/
public String getReadString() throws IOException {
if (thrownException != null) {
if(thrownException != null) {
throw thrownException;
}
StringBuffer res = new StringBuffer();
for (String line : result) {
for(String line : result) {
res.append(line).append("\n");
}
return res.toString();
......@@ -208,8 +200,8 @@ public abstract class ToolRunnerBase<S extends INamedElement, T> implements
protected String[] cmdArray;
/** Constructor. */
protected ToolRunningTask(File physicalFile,
IResultBuilder<T> resultBuilder, String[] cmdArray) {
protected ToolRunningTask(File physicalFile, IResultBuilder<T> resultBuilder,
String[] cmdArray) {
this.physicalFile = physicalFile;
this.resultBuilder = resultBuilder;
this.cmdArray = cmdArray;
......@@ -219,19 +211,16 @@ public abstract class ToolRunnerBase<S extends INamedElement, T> implements
@Override
public T call() throws Exception {
info(plugin,
"Running " + getToolCommand() + " "
+ Arrays.toString(cmdArray) + " on file: "
+ physicalFile.getAbsolutePath());
"Running " + getToolCommand() + " " + Arrays.toString(cmdArray) + " on file " +
physicalFile.getName() + " in directory " + physicalFile.getParent());
long initialTimeStamp = System.currentTimeMillis();
toolRunnerProcess = Runtime.getRuntime().exec(cmdArray, null,
physicalFile.getParentFile());
toolRunnerProcess =
Runtime.getRuntime().exec(cmdArray, null, physicalFile.getParentFile());
StreamReader errorStreamReader = new StreamReader(
toolRunnerProcess.getErrorStream());
StreamReader inputStreamReader = new StreamReader(
toolRunnerProcess.getInputStream());
StreamReader errorStreamReader = new StreamReader(toolRunnerProcess.getErrorStream());
StreamReader inputStreamReader = new StreamReader(toolRunnerProcess.getInputStream());
inputStreamReader.start();
errorStreamReader.start();
......@@ -241,8 +230,9 @@ public abstract class ToolRunnerBase<S extends INamedElement, T> implements
inputStreamReader.join();
errorStreamReader.join();
String duration = new DecimalFormat("###.###").format((System
.currentTimeMillis() - initialTimeStamp) / 1000.0);
String duration =
new DecimalFormat("###.###")
.format((System.currentTimeMillis() - initialTimeStamp) / 1000.0);
info(plugin, "Run in " + duration + "s");
return doProcessRunResults(errorStreamReader, inputStreamReader);
......@@ -252,20 +242,19 @@ public abstract class ToolRunnerBase<S extends INamedElement, T> implements
protected T doProcessRunResults(StreamReader errorStreamReader,
StreamReader inputStreamReader) throws IOException, Exception {
String errorMessage = errorStreamReader.getReadString();
if (errorMessage.length() > 0) {
throw new Exception(getToolCommand() + " running errors\n"
+ errorMessage);
if(errorMessage.length() > 0) {
throw new Exception(getToolCommand() + " running errors\n" + errorMessage);
}
if (inputStreamReader.getReadLines().size() == 0) {
error(plugin, "Error on running " + getToolCommand()
+ " on file: " + physicalFile.getAbsolutePath()
+ " The file was not deleted and can be debugged! ");
throw new Exception("No result from running "
+ getToolCommand() + " :-( !!");
if(inputStreamReader.getReadLines().size() == 0) {
error(plugin,
"Error on running " + getToolCommand() + " on file: " +
physicalFile.getAbsolutePath() +
" The file was not deleted and can be debugged! ");
throw new Exception("No result from running " + getToolCommand() + " :-( !!");
}
if (!DEBUG) {
if(!DEBUG) {
physicalFile.delete();
}
......@@ -295,12 +284,11 @@ public abstract class ToolRunnerBase<S extends INamedElement, T> implements
futureResult = executorService.submit(toolRunningTask);
try {
return futureResult.get(timeoutInMilliseconds,
TimeUnit.MILLISECONDS);
} catch (TimeoutException to) {
return futureResult.get(timeoutInMilliseconds, TimeUnit.MILLISECONDS);
} catch(TimeoutException to) {
toolRunnerProcess.destroy();
throw to;
} catch (Exception e) {
} catch(Exception e) {
toolRunnerProcess.destroy();
e.printStackTrace();
error(plugin, "Unexpected error!", e);
......
......@@ -17,12 +17,14 @@ $Id$
+--------------------------------------------------------------------------*/
package org.fortiss.af3.tools.gcc;
import static org.conqat.lib.commons.filesystem.FileSystemUtils.readFile;
import static org.eclipse.core.runtime.Assert.isNotNull;
import static org.eclipse.core.runtime.Assert.isTrue;
import java.io.File;
import java.io.IOException;
import org.fortiss.af3.tools.base.ILazyResult;
import org.fortiss.af3.tools.base.IResultBuilder;
import org.fortiss.af3.tools.base.SimpleToolRunnerBase;
/**
* Tool runner class for running Shell scripts (e.g the configure script).
......@@ -32,55 +34,46 @@ import org.fortiss.af3.tools.base.IResultBuilder;
* @version $Rev$
* @ConQAT.Rating RED Hash:
*/
public class ConfigureRunner extends GCCToolChainRunnerBase {
public class ConfigureRunner extends SimpleToolRunnerBase {
/** The configure script file. */
private final File configureScript;
/** The arguments for the configure script. */
private final String[] arguments;
/** Constructor. */
public ConfigureRunner(File sourceDirectory) {
super(sourceDirectory);
isTrue(sourceDirectory.isDirectory());
this.configureScript = new File(sourceDirectory, "configure");
isTrue(configureScript.canExecute());
public ConfigureRunner(File targetDirectory, String[] arguments) {
super(new File(targetDirectory, "configure"));
isTrue(targetDirectory.isDirectory());
isNotNull(arguments);
this.arguments = arguments;
}
/** {@inheritDoc} */
@Override
public ILazyResult<File> runTool() throws Exception {
return null;
/** Constructor. */
public ConfigureRunner(File sourceDirectory) {
this(sourceDirectory, new String[0]);
}
/** {@inheritDoc} */
@Override
protected String getToolCommand() {
return configureScript.getAbsolutePath();
}
/** {@inheritDoc} */
@Override
public IResultBuilder<File> getResultBuilder() {
// FIXME: not gcc
return new GCCResultBuilder();
return "configure";
}
/** {@inheritDoc} */
@Override
public String[] getCommandList() {
// FIXME: -version
return new String[] {getVersionOption()};
}
/** {@inheritDoc} */
@Override
protected String getVersionOption() {
return "";
return arguments;
}
/** {@inheritDoc} */
/**
* {@inheritDoc} Returns the content of the configure script if it exists and can be read.
*/
@Override
protected String getVersionInfo(String helpMessage) {
int startOfVersioningInfo = helpMessage.indexOf("Success. ");
return helpMessage.substring(startOfVersioningInfo, startOfVersioningInfo + 8);
public String testToolAvailability() {
try {
return readFile(physicalFile);
} catch(IOException e) {
e.printStackTrace();
}
return null;
}
}
/*--------------------------------------------------------------------------+
$Id$
| |
| Copyright 2011 ForTISS GmbH |
| |
| Licensed under the Apache License, Version 2.0 (the "License"); |
| you may not use this file except in compliance with the License. |
| You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| See the License for the specific language governing permissions and |
| limitations under the License. |
+--------------------------------------------------------------------------*/
package org.fortiss.af3.tools.gcc;
import static org.fortiss.tooling.kernel.utils.LoggingUtils.info;
import java.io.File;
import java.util.List;
import org.fortiss.af3.tools.ToolsActivator;
import org.fortiss.af3.tools.base.IResultBuilder;
/**
* Builder for GCC result, i.e., an object file location.
*
* @author hoelzl
* @author $Author$
* @version $Rev$
* @ConQAT.Rating GREEN Hash: 194E8C06948F411A6EB17165BBC17CCF
*/
public class GCCResultBuilder implements IResultBuilder<File> {
/** {@inheritDoc} */
@Override
public File buildResult(List<String> lines) {
info(ToolsActivator.getDefault(), "Parsing GCC results!");
// FIXME: implement
return null;
}
}
......@@ -19,9 +19,6 @@ package org.fortiss.af3.tools.gcc;
import java.io.File;
import org.fortiss.af3.tools.base.ILazyResult;
import org.fortiss.af3.tools.base.IResultBuilder;
/**
* Tool runner class for running GCC.
*
......@@ -42,29 +39,16 @@ public class GCCRunner extends GCCToolChainRunnerBase {
super();
}
/** {@inheritDoc} */
@Override
public ILazyResult<File> runTool() throws Exception {
return null;
}
/** {@inheritDoc} */
@Override
protected String getToolCommand() {
return "gcc";
}
/** {@inheritDoc} */
@Override
public IResultBuilder<File> getResultBuilder() {
return new GCCResultBuilder();
}
/** {@inheritDoc} */
@Override
public String[] getCommandList() {
// FIXME: -v
return new String[] {"-v"};
return new String[] {physicalFile.getAbsolutePath()};
}
/** {@inheritDoc} */
......
......@@ -30,7 +30,7 @@ import org.fortiss.af3.tools.base.SimpleToolRunnerBase;
* @version $Rev$
* @ConQAT.Rating RED Hash:
*/
public abstract class GCCToolChainRunnerBase extends SimpleToolRunnerBase<File> {
public abstract class GCCToolChainRunnerBase extends SimpleToolRunnerBase {
/** Constructor. */
public GCCToolChainRunnerBase(File physicalFileOrLocation) {
......
......@@ -17,10 +17,9 @@ $Id$
+--------------------------------------------------------------------------*/
package org.fortiss.af3.tools.gcc;
import java.io.File;
import static org.eclipse.core.runtime.Assert.isTrue;
import org.fortiss.af3.tools.base.ILazyResult;
import org.fortiss.af3.tools.base.IResultBuilder;
import java.io.File;
/**
* Tool runner class for running Make.
......@@ -31,10 +30,10 @@ import org.fortiss.af3.tools.base.IResultBuilder;
* @ConQAT.Rating RED Hash:
*/
public class MakeRunner extends GCCToolChainRunnerBase {
/** Constructor. */
public MakeRunner(File sourceFile) {
super(sourceFile);
public MakeRunner(File makeFile) {
super(makeFile);
isTrue("Makefile".equals(makeFile.getName()));
}
/** Constructor. */
......@@ -42,30 +41,16 @@ public class MakeRunner extends GCCToolChainRunnerBase {
super();
}
/** {@inheritDoc} */
@Override
public ILazyResult<File> runTool() throws Exception {
return null;
}
/** {@inheritDoc} */
@Override
protected String getToolCommand() {
return "make";
}
/** {@inheritDoc} */
@Override
public IResultBuilder<File> getResultBuilder() {
// FIXME: not gcc
return new GCCResultBuilder();
}
/** {@inheritDoc} */
@Override
public String[] getCommandList() {
// FIXME: -v
return new String[] {"-v"};
return new String[0];
}
/** {@inheritDoc} */
......
......@@ -19,11 +19,9 @@ package org.fortiss.af3.tools.gcc;
import java.io.File;
import org.fortiss.af3.tools.base.ILazyResult;
import org.fortiss.af3.tools.base.IResultBuilder;
/**
* Tool runner class for running Shell scripts (e.g the configure script).
* Tool runner class for running Shell scripts (e.g the configure script) using the system shell
* {@code sh}.
*
* @author hoelzl
* @author $Author$
......@@ -33,8 +31,8 @@ import org.fortiss.af3.tools.base.IResultBuilder;
public class ShellRunner extends GCCToolChainRunnerBase {
/** Constructor. */
public ShellRunner(File sourceFile) {
super(sourceFile);
public ShellRunner(File scriptFile) {
super(scriptFile);
}
/** Constructor. */
......@@ -42,30 +40,16 @@ public class ShellRunner extends GCCToolChainRunnerBase {
super();
}