Permalink
Browse files

JDK 1.7 (#214)

  • Loading branch information...
gquerret committed Mar 15, 2017
1 parent e157ef1 commit f45d28491dcced6d0be160491a24b9ff5edee452
View
@@ -1,4 +1,5 @@
/.sonar/
/.sonarlint/
/build/
/dist/
/testbox/
View
@@ -0,0 +1,4 @@
{
"serverId": "RSSW",
"projectKey": "eu.rssw.pct:PCT"
}
@@ -26,7 +26,9 @@
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Iterator;
@@ -117,7 +119,8 @@ public void setInactiveIndexes(boolean inactive) {
*
* @throws BuildException Something went wrong
*/
public void execute() throws BuildException {
@Override
public void execute() {
if (runAttributes.getAllDbConnections().size() == 0) {
cleanup();
throw new BuildException(Messages.getString("PCTLoadSchema.0")); //$NON-NLS-1$
@@ -168,10 +171,7 @@ public void execute() throws BuildException {
}
private void writeFileList() throws BuildException {
try {
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(
fsList), getCharset()));
try (OutputStream os = new FileOutputStream(fsList); Writer w = new OutputStreamWriter(os); BufferedWriter bw = new BufferedWriter(w)) {
if (srcFile != null) {
bw.write(srcFile.getAbsolutePath());
bw.newLine();
@@ -189,8 +189,6 @@ private void writeFileList() throws BuildException {
}
}
}
bw.close();
} catch (IOException ioe) {
throw new BuildException(Messages.getString("PCTCompile.2"), ioe); //$NON-NLS-1$
}
@@ -201,6 +199,7 @@ private void writeFileList() throws BuildException {
*
* @see PCTRun#cleanup
*/
@Override
protected void cleanup() {
super.cleanup();
@@ -30,6 +30,7 @@
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.Reader;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Iterator;
@@ -116,7 +117,8 @@ public void add(ResourceCollection rc) {
*
* @throws BuildException Something went wrong
*/
public void execute() throws BuildException {
@Override
public void execute() {
// Verify resource collections
for (ResourceCollection rc : resources) {
if (!rc.isFilesystemOnly())
@@ -183,7 +185,7 @@ public void execute() throws BuildException {
}
private void executeProxygen(File pxgFile) throws BuildException {
private void executeProxygen(File pxgFile) {
Java pxgTask = null;
log(MessageFormat.format(Messages.getString("PCTProxygen.3"), pxgFile.getAbsolutePath()), Project.MSG_INFO); //$NON-NLS-1$
@@ -216,9 +218,7 @@ private void executeProxygen(File pxgFile) throws BuildException {
}
// Parse output of proxygen task
BufferedReader reader = null;
try {
reader = new BufferedReader(new FileReader(logFile));
try (Reader r = new FileReader(logFile); BufferedReader reader = new BufferedReader(r)) {
String str = null;
while ((str = reader.readLine()) != null) {
if (str.contains("Warnings")) {
@@ -236,20 +236,12 @@ private void executeProxygen(File pxgFile) throws BuildException {
} catch (IOException caught) {
cleanup();
throw new BuildException("Unable to parse output", caught);
} finally {
if (reader != null) {
try {
reader.close();
} catch (IOException uncaught) {
}
}
}
cleanup();
// Parse log file of proxygen itself, if file is available
if ((pxgLogFile != null) && pxgLogFile.exists()) {
try {
reader = new BufferedReader(new FileReader(pxgLogFile));
try (Reader r = new FileReader(pxgLogFile); BufferedReader reader = new BufferedReader(r)) {
String str = null;
while ((str = reader.readLine()) != null) {
if (str.trim().startsWith(">>WARN")) {
@@ -263,16 +255,9 @@ private void executeProxygen(File pxgFile) throws BuildException {
} catch (IOException caught) {
cleanup();
throw new BuildException("Unable to parse log file", caught);
} finally {
if (reader != null) {
try {
reader.close();
} catch (IOException uncaught) {
}
}
}
} else {
log("Unable to read log file : " + pxgLogFile.getAbsolutePath(), Project.MSG_WARN);
log("Unable to read log file", Project.MSG_WARN);
}
if (fail) {
@@ -29,12 +29,15 @@
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.Reader;
import java.io.Writer;
import java.nio.charset.Charset;
import java.text.MessageFormat;
@@ -367,8 +370,8 @@ public void setOutput(File output) {
*
* @throws BuildException Something went wrong
*/
public void execute() throws BuildException {
BufferedReader br = null;
@Override
public void execute() {
checkDlcHome();
if ((runAttributes.getProcedure() == null) || (runAttributes.getProcedure().length() == 0))
@@ -414,13 +417,11 @@ public void execute() throws BuildException {
if (getProgressProcedures().needRedirector()) {
String s = null;
try {
BufferedReader br2 = new BufferedReader(new FileReader(outputStream));
try (Reader r = new FileReader(outputStream); BufferedReader br2 = new BufferedReader(r)) {
while ((s = br2.readLine()) != null) {
log(s, Project.MSG_INFO);
}
br2.close();
} catch (Exception e) {
} catch (IOException e) {
System.out.println(e);
}
}
@@ -429,22 +430,12 @@ public void execute() throws BuildException {
if (runAttributes.getOutputParameters() != null) {
for (OutputParameter param : runAttributes.getOutputParameters()) {
File f = param.getTempFileName();
try {
br = new BufferedReader(new InputStreamReader(new FileInputStream(f),
Charset.forName("utf-8")));
try (InputStream fis = new FileInputStream(f);
Reader r = new InputStreamReader(fis, Charset.forName("utf-8"));
BufferedReader br = new BufferedReader(r)) {
String s = br.readLine();
br.close();
getProject().setNewProperty(param.getName(), s);
} catch (FileNotFoundException fnfe) {
log(MessageFormat.format(
Messages.getString("PCTRun.10"), param.getName(), f.getAbsolutePath()), Project.MSG_ERR); //$NON-NLS-1$
cleanup();
throw new BuildException(fnfe);
} catch (IOException ioe) {
try {
br.close();
} catch (IOException ioe2) {
}
log(MessageFormat.format(
Messages.getString("PCTRun.10"), param.getName(), f.getAbsolutePath()), Project.MSG_ERR); //$NON-NLS-1$
cleanup();
@@ -454,40 +445,25 @@ public void execute() throws BuildException {
}
// Now read status file
try {
br = new BufferedReader(new FileReader(status));
try (Reader r = new FileReader(status); BufferedReader br = new BufferedReader(r)) {
String s = br.readLine();
br.close();
this.cleanup();
int ret = Integer.parseInt(s);
if (ret != 0 && runAttributes.isFailOnError()) {
throw new BuildException(MessageFormat.format(Messages.getString("PCTRun.6"), ret)); //$NON-NLS-1$
}
maybeSetResultPropertyValue(ret);
} catch (FileNotFoundException fnfe) {
// No need to clean BufferedReader as it's null in this case
this.cleanup();
throw new BuildException(Messages.getString("PCTRun.1"), fnfe); //$NON-NLS-1$
} catch (IOException ioe) {
try {
br.close();
} catch (IOException ioe2) {
}
this.cleanup();
throw new BuildException(Messages.getString("PCTRun.2"), ioe); //$NON-NLS-1$
} catch (NumberFormatException nfe) {
this.cleanup(); // Ce truc là ne serait pas manquant ??
throw new BuildException(Messages.getString("PCTRun.3"), nfe); //$NON-NLS-1$
} catch (IOException caught) {
throw new BuildException(Messages.getString("PCTRun.2"), caught); //$NON-NLS-1$
} catch (NumberFormatException caught) {
throw new BuildException(Messages.getString("PCTRun.3"), caught); //$NON-NLS-1$
} finally {
cleanup();
}
}
// In order to know if Progress session has to use verbose logging
private boolean isVerbose() {
return (getAntLoggerLever() > 2);
return getAntLoggerLever() > 2;
}
// Helper method to set result property to the passed in value if appropriate.
@@ -614,8 +590,8 @@ private String readCharset() {
// If paramFile is defined, then read it and check for cpStream or cpInternal
if (runAttributes.getParamFile() != null) {
try {
PFReader reader = new PFReader(new FileInputStream(runAttributes.getParamFile()));
try (InputStream is = new FileInputStream(runAttributes.getParamFile()); ) {
PFReader reader = new PFReader(is);
pfCpInt = reader.getCpInternal();
pfCpStream = reader.getCpStream();
} catch (IOException uncaught) {
@@ -635,12 +611,11 @@ else if (pfCpInt != null)
return null;
}
private void createProfilerFile() throws BuildException {
private void createProfilerFile() {
if ((runAttributes.getProfiler() != null) && runAttributes.getProfiler().isEnabled()) {
BufferedWriter bw = null;
try {
bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(
profilerParamFile)));
try (OutputStream os = new FileOutputStream(profilerParamFile);
Writer w = new OutputStreamWriter(os);
BufferedWriter bw = new BufferedWriter(w)) {
if (runAttributes.getProfiler().getOutputFile() != null) {
bw.write("-FILENAME " + runAttributes.getProfiler().getOutputFile().getAbsolutePath());
bw.newLine();
@@ -665,24 +640,16 @@ private void createProfilerFile() throws BuildException {
}
bw.write("-DESCRIPTION \"" + runAttributes.getProfiler().getDescription() + "\"");
bw.newLine();
bw.close();
} catch (IOException caught) {
throw new BuildException(caught);
} finally {
try {
bw.close();
} catch (IOException uncaught) {
}
}
}
}
private void createInitProcedure() throws BuildException {
BufferedWriter bw = null;
try {
bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(
initProc), getCharset()));
private void createInitProcedure() {
try (OutputStream os = new FileOutputStream(initProc);
Writer w = new OutputStreamWriter(os, getCharset());
BufferedWriter bw = new BufferedWriter(w)) {
// Progress v8 is unable to write to standard output, so output is redirected in a file,
// which is parsed in a later stage
if (this.getProgressProcedures().needRedirector()) {
@@ -786,7 +753,7 @@ private void createInitProcedure() throws BuildException {
// Creates a StringBuffer containing output parameters when calling the progress
// procedure
StringBuffer sb = new StringBuffer();
StringBuilder sb = new StringBuilder();
if ((runAttributes.getOutputParameters() != null) && (runAttributes.getOutputParameters().size() > 0)) {
sb.append('(');
int zz = 0;
@@ -832,14 +799,6 @@ private void createInitProcedure() throws BuildException {
bw.close();
} catch (IOException ioe) {
throw new BuildException(ioe);
} finally {
if (bw != null) {
try {
bw.close();
} catch (IOException uncaught) {
}
}
}
}
@@ -902,7 +861,6 @@ protected boolean getDebugPCT() {
/**
* Delete temporary files if debug not activated
*
*/
protected void cleanup() {
if (!runAttributes.isDebugPCT()) {
@@ -20,6 +20,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
public class PFReader {
private String cpInternal;
@@ -38,21 +39,21 @@ public String getCpStream() {
}
private void readPFStream(InputStream stream) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(stream));
try (Reader r = new InputStreamReader(stream);
BufferedReader reader = new BufferedReader(r)) {
String line = reader.readLine();
while (line != null) {
int end = line.indexOf('#');
if (end > -1) {
line = line.substring(0, end);
}
if (line.length() > 0) {
parseLine(line);
}
String line = reader.readLine();
while (line != null) {
int end = line.indexOf('#');
if (end > -1) {
line = line.substring(0, end);
line = reader.readLine();
}
if (line.length() > 0) {
parseLine(line);
}
line = reader.readLine();
}
reader.close();
}
private void parseLine(String line) {
@@ -81,4 +82,5 @@ private String stripQuotes(String quotedString) {
return s;
}
}

0 comments on commit f45d284

Please sign in to comment.