Permalink
Browse files

On-the-fly xcode of init procedure for runtime environments (#263)

  • Loading branch information...
gquerret committed Sep 13, 2017
1 parent 1688fb6 commit bc2073fe65bc4c13d9f5aff381e7135f94433457
@@ -471,6 +471,11 @@ public void setProcedure(String procedure) {
throw new BuildException("Can't set procedure attribute here");
}
@Override
public void setXCodeInit(boolean xcode) {
throw new BuildException("Can't set XCodeInit attribute here");
}
@Override
public void setParameter(String param) {
throw new BuildException("Can't set parameter attribute here");
@@ -75,6 +75,7 @@
private boolean noErrorOnQuit = false;
private boolean superInit = true;
private File output;
private boolean xCodeInit = false;
public GenericExecuteOptions(Task parent) {
this.parent = parent;
@@ -303,6 +304,11 @@ public void setProcedure(String procedure) {
this.procedure = procedure;
}
@Override
public void setXCodeInit(boolean xcode) {
this.xCodeInit = xcode;
}
@Override
public void setMainCallback(String mainCallback) {
this.mainCallback = mainCallback;
@@ -442,6 +448,10 @@ public String getProcedure() {
return procedure;
}
public boolean getXCodeInit() {
return xCodeInit;
}
public File getAssemblies() {
return assemblies;
}
@@ -205,6 +205,11 @@
*/
void setProcedure(String procedure);
/**
* XCode init procedure
*/
void setXCodeInit(boolean xcode);
/**
* Add a database alias
*/
@@ -16,33 +16,33 @@
*/
package com.phenix.pct;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.BuildListener;
import org.apache.tools.ant.DefaultLogger;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.Task;
import org.apache.tools.ant.types.Environment;
import org.apache.tools.ant.types.Environment.Variable;
import org.apache.tools.ant.types.FileSet;
import org.apache.tools.ant.types.Path;
import org.apache.tools.ant.types.PatternSet;
import com.phenix.pct.RCodeInfo.InvalidRCodeException;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.lang.reflect.Field;
import java.nio.file.Files;
import java.text.MessageFormat;
import java.util.Collection;
import java.util.List;
import java.util.Random;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.BuildListener;
import org.apache.tools.ant.DefaultLogger;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.Task;
import org.apache.tools.ant.types.Environment;
import org.apache.tools.ant.types.Environment.Variable;
import org.apache.tools.ant.types.FileSet;
import org.apache.tools.ant.types.Path;
import org.apache.tools.ant.types.PatternSet;
import com.phenix.pct.RCodeInfo.InvalidRCodeException;
/**
* Base class for creating tasks involving Progress. It does basic work on guessing where various
* bin/java/etc are located.
@@ -627,82 +627,35 @@ protected static final int nextRandomInt() {
* @param directory directory to delete
* @throws IOException in case deletion is unsuccessful
*/
protected static void deleteDirectory(File directory) throws IOException {
if (!directory.exists()) {
protected void deleteDirectory(File directory) {
if (directory == null)
return;
}
cleanDirectory(directory);
if (!directory.delete()) {
String message = "Unable to delete directory " + directory + ".";
throw new IOException(message);
}
}
/**
* Cleans a directory without deleting it.
*
* @param directory directory to clean
* @throws IOException in case cleaning is unsuccessful
*/
private static void cleanDirectory(File directory) throws IOException {
if (!directory.exists()) {
String message = directory + " does not exist";
throw new IllegalArgumentException(message);
}
if (!directory.isDirectory()) {
String message = directory + " is not a directory";
throw new IllegalArgumentException(message);
return;
}
File[] files = directory.listFiles();
if (files == null) { // null if security restricted
throw new IOException("Failed to list contents of " + directory);
}
IOException exception = null;
for (int zz = 0; zz < files.length; zz++) {
try {
forceDelete(files[zz]);
} catch (IOException ioe) {
exception = ioe;
}
for (File f : directory.listFiles()) {
deleteFile(f);
}
try {
Files.deleteIfExists(directory.toPath());
} catch (IOException caught) {
log(MessageFormat.format(Messages.getString("PCTRun.5"), directory.getAbsolutePath()),
Project.MSG_VERBOSE);
if (null != exception) {
throw exception;
}
}
/**
* Deletes a file. If file is a directory, delete it and all sub-directories.
* <p>
* The difference between File.delete() and this method are:
* <ul>
* <li>A directory to be deleted does not have to be empty.</li>
* <li>You get exceptions when a file or directory cannot be deleted. (java.io.File methods
* returns a boolean)</li>
* </ul>
*
* @param file file or directory to delete, must not be <code>null</code>
* @throws NullPointerException if the directory is <code>null</code>
* @throws FileNotFoundException if the file was not found
* @throws IOException in case deletion is unsuccessful
*/
private static void forceDelete(File file) throws IOException {
if (file.isDirectory()) {
protected void deleteFile(File file) {
if (file == null)
return;
if (file.isDirectory())
deleteDirectory(file);
} else {
boolean filePresent = file.exists();
if (!file.delete()) {
if (!filePresent) {
throw new FileNotFoundException("File does not exist: " + file);
}
String message = "Unable to delete file: " + file;
throw new IOException(message);
}
try {
Files.deleteIfExists(file.toPath());
} catch (IOException caught) {
log(MessageFormat.format(Messages.getString("PCTRun.5"), file.getAbsolutePath()),
Project.MSG_VERBOSE);
}
}
@@ -78,6 +78,11 @@ public void setProcedure(String procedure) {
throw new BuildException("Can't set procedure attribute");
}
@Override
public void setXCodeInit(boolean xcode) {
throw new BuildException("Can't set xCodeInit attribute");
}
/**
* Do the work
*
@@ -168,6 +168,11 @@ public void setDebugPCT(boolean debugPCT) {
options.setDebugPCT(debugPCT);
}
@Override
public void setXCodeInit(boolean xcode) {
options.setXCodeInit(xcode);
}
@Override
public void setCompileUnderscore(boolean compUnderscore) {
options.setCompileUnderscore(compUnderscore);
@@ -609,22 +614,16 @@ protected void preparePropath() {
}
protected void cleanup() {
if (!pctLib.isDirectory()) {
pctLib.delete();
} else {
try {
deleteDirectory(pctLib);
} catch (IOException uncaught) {
log(Messages.getString("PCTBgRun.4"), uncaught, Project.MSG_INFO);
}
// Always delete pct.pl, even in debugPCT mode
if (pctLib != null) {
deleteFile(pctLib);
}
initProc.delete();
for (File f : profilerParams) {
if (!f.delete()) {
log(MessageFormat
.format(Messages.getString("PCTRun.5"), f.getAbsolutePath()), Project.MSG_INFO); //$NON-NLS-1$
}
if (options.isDebugPCT())
return;
deleteFile(initProc);
for (File f : profilerParams) {
deleteFile(f);
}
}
Oops, something went wrong.

0 comments on commit bc2073f

Please sign in to comment.