Force UTF-8 on all sources to hopefully avoid compile issues on Windows

This commit is contained in:
James Agnew 2015-08-28 11:35:12 -04:00
parent 5e0a8c476b
commit 4032a2674d
8 changed files with 26 additions and 168 deletions

View File

@ -3,8 +3,10 @@ package ca.uhn.fhir.tinder;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.net.URL;
import java.util.Collection;
@ -120,9 +122,11 @@ public class ResourceMinimizerMojo extends AbstractMojo {
if (!inputString.equals(outputString)) {
ourLog.info("Trimming contents of resource: {} - From {} to {}", nextFile, FileUtils.byteCountToDisplaySize(inputString.length()), FileUtils.byteCountToDisplaySize(outputString.length()));
try {
BufferedWriter writer = new BufferedWriter(new FileWriter(nextFile.getAbsolutePath(), false));
writer.append(outputString);
writer.close();
String f = nextFile.getAbsolutePath();
Writer w = new OutputStreamWriter(new FileOutputStream(f, false), "UTF-8");
w = new BufferedWriter(w);
w.append(outputString);
w.close();
} catch (IOException e) {
throw new MojoFailureException("Failed to write " + nextFile, e);
}

View File

@ -1,10 +1,11 @@
package ca.uhn.fhir.tinder;
import java.io.File;
import java.io.FileWriter;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.ArrayList;
import java.util.List;
@ -154,7 +155,8 @@ public class TinderClientMojo extends AbstractMojo {
private void write() throws IOException {
File file = new File(myDirectoryBase, myClientClassSimpleName + ".java");
FileWriter w = new FileWriter(file, false);
OutputStreamWriter w = new OutputStreamWriter(new FileOutputStream(file, false), "UTF-8");
ourLog.debug("Writing file: {}", file.getAbsolutePath());

View File

@ -1,10 +1,11 @@
package ca.uhn.fhir.tinder;
import java.io.File;
import java.io.FileWriter;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
@ -157,7 +158,8 @@ public class TinderJpaRestServerMojo extends AbstractMojo {
InputStreamReader templateReader = new InputStreamReader(templateIs);
targetResourceDirectory.mkdirs();
FileWriter w = new FileWriter(new File(targetResourceDirectory, targetResourceSpringBeansFile));
File f = new File(targetResourceDirectory, targetResourceSpringBeansFile);
OutputStreamWriter w = new OutputStreamWriter(new FileOutputStream(f, false), "UTF-8");
v.evaluate(ctx, w, "", templateReader);
w.close();

View File

@ -2,11 +2,12 @@ package ca.uhn.fhir.tinder;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
@ -287,7 +288,7 @@ public class ValueSetGenerator {
}
File f = new File(theOutputDirectory, theValueSetTm.getClassName() + ".java");
FileWriter w = new FileWriter(f, false);
OutputStreamWriter w = new OutputStreamWriter(new FileOutputStream(f, false), "UTF-8");
ourLog.debug("Writing file: {}", f.getAbsolutePath());
@ -302,7 +303,7 @@ public class ValueSetGenerator {
v.setProperty("runtime.references.strict", Boolean.TRUE);
InputStream templateIs = ResourceGeneratorUsingSpreadsheet.class.getResourceAsStream("/vm/valueset.vm");
InputStreamReader templateReader = new InputStreamReader(templateIs);
InputStreamReader templateReader = new InputStreamReader(templateIs, "UTF-8");
v.evaluate(ctx, w, "", templateReader);
w.close();

View File

@ -5,7 +5,6 @@ import static org.apache.commons.lang.StringUtils.isNotBlank;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
@ -522,7 +521,7 @@ public abstract class BaseStructureParser {
try {
File versionFile = new File(theResourceOutputDirectory, "fhirversion.properties");
FileWriter w = new FileWriter(versionFile, false);
OutputStreamWriter w = new OutputStreamWriter(new FileOutputStream(versionFile, false), "UTF-8");
ourLog.debug("Writing file: {}", versionFile.getAbsolutePath());

View File

@ -1,9 +1,9 @@
package ca.uhn.fhir.tinder.util;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.OutputStreamWriter;
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.model.dstu2.composite.NarrativeDt;
@ -24,7 +24,8 @@ private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger
nextRes.setText(new NarrativeDt());
}
FileWriter fw = new FileWriter(new File(fileName), false);
File f = new File(fileName);
OutputStreamWriter fw = new OutputStreamWriter(new FileOutputStream(f, false), "UTF-8");
ctx.newXmlParser().encodeResourceToWriter(b, fw);
fw.close();

View File

@ -1,151 +0,0 @@
package ca.uhn.fhir.util;
import static org.apache.commons.lang3.StringUtils.isBlank;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
import java.util.TreeSet;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import org.ini4j.Ini;
import org.ini4j.Profile.Section;
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.model.dstu2.composite.NarrativeDt;
import ca.uhn.fhir.model.dstu2.resource.BaseResource;
import ca.uhn.fhir.model.dstu2.resource.Bundle;
import ca.uhn.fhir.model.dstu2.resource.Bundle.Entry;
public class VersionSynchronizer {
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(VersionSynchronizer.class);
public static void main(String[] args) throws Exception {
Set<String> resources = new TreeSet<String>();
{
String str = IOUtils.toString(new FileReader("../hapi-fhir-structures-dstu2/pom.xml"));
Matcher m = Pattern.compile("baseResourceName.([a-zA-Z]+)..baseResourceName").matcher(str);
while (m.find()) {
String name = m.group(1).toLowerCase();
resources.add(name);
}
}
ourLog.info("POM resource names: " + resources);
String buildDir = "/Users/t3903uhn/workspace/fhirbuild/trunk/build";
ArrayList<String> lines = new ArrayList<String>(Arrays.asList(IOUtils.toString(new FileReader(new File(buildDir + "/source", "fhir.ini"))).split("\\r?\\n")));
for (int i = 0; i < lines.size(); i++) {
String next = lines.get(i);
if (next.startsWith("=") || next.startsWith(" ")) {
lines.remove(i);
i--;
continue;
}
if (isBlank(next)) {
continue;
}
if (Character.isAlphabetic(next.charAt(0)) && next.indexOf('=') == -1) {
lines.set(i, next + '=');
continue;
}
}
Ini ini = new Ini(new StringReader(StringUtils.join(lines, '\n')));
Section resourceSects = ini.get("resources");
ourLog.info("Copying resource spreadsheets");
TreeSet<String> resourceNames = new TreeSet<String>(resourceSects.keySet());
resourceNames.add("parameters");
for (String nextResource : new ArrayList<String>(resourceNames)) {
nextResource = nextResource.toLowerCase();
ourLog.info(" * Resource: {}", nextResource);
File spreadsheetFile = new File(buildDir + "/source/" + nextResource + "/" + nextResource + "-spreadsheet.xml");
if (!spreadsheetFile.exists()) {
throw new Exception("Unknown file: " + spreadsheetFile);
}
FileUtils.copyFile(spreadsheetFile, new File("src/main/resources/res/dstu2/" + nextResource + "-spreadsheet.xml"));
if (!resources.contains(nextResource)) {
throw new Exception("POM needs:\n<baseResourceName>" + nextResource+"</baseResourceName>");
}
resources.remove(nextResource);
}
if (resources.size() > 0) {
throw new Exception("POM has unneeded resources: " + resources);
}
ourLog.info("Copying datatypes");
Collection<File> dtFiles = FileUtils.listFiles(new File(buildDir+"/source/datatypes"), new String[] {"xml"}, false);
for (File file : dtFiles) {
if (file.getName().contains("-")) {
continue;
}
ourLog.info("Datatype: {}", file.getName());
File destFile = new File("src/main/resources/dt/dstu2/" + file.getName());
FileUtils.copyFile(file, destFile);
// ourLog.info("Copied to {}", destFile.getAbsolutePath());
}
ourLog.info("Copying ValueSets");
FileUtils.copyFile(new File(buildDir + "/publish/valuesets.xml"), new File("src/main/resources/vs/dstu2/all-valuesets-bundle.xml"));
{
ourLog.info("Shrinking valueset file");
String fileName = "src/main/resources/vs/dstu2/all-valuesets-bundle.xml";
FileReader fr = new FileReader(fileName);
FhirContext ctx = FhirContext.forDstu2();
Bundle b = ctx.newXmlParser().parseResource(Bundle.class, fr);
for (Entry nextEntry : b.getEntry()) {
BaseResource nextRes = (BaseResource) nextEntry.getResource();
nextRes.setText(new NarrativeDt());
}
FileWriter fw = new FileWriter(new File(fileName), false);
ctx.newXmlParser().encodeResourceToWriter(b, fw);
fw.close();
ourLog.info("Fixed {} valuesets", b.getEntry().size());
}
ourLog.info("Copying Schematron files");
Collection<File> schFiles = FileUtils.listFiles(new File(buildDir+"/publish"), new String[] {"sch"}, false);
for (File file : schFiles) {
ourLog.info("Schematron: {}", file.getName());
File destFile = new File("../hapi-fhir-structures-dstu2/src/main/resources/ca/uhn/fhir/model/dstu2/schema/" + file.getName());
FileUtils.copyFile(file, destFile);
// ourLog.info("Copied to {}", destFile.getAbsolutePath());
}
ourLog.info("Copying XSD");
FileUtils.copyFile(new File(buildDir + "/publish/fhir-single.xsd"), new File("../hapi-fhir-structures-dstu2/src/main/resources/ca/uhn/fhir/model/dstu2/schema/fhir-single.xsd"));
FileUtils.copyFile(new File(buildDir + "/publish/xml.xsd"), new File("../hapi-fhir-structures-dstu2/src/main/resources/ca/uhn/fhir/model/dstu2/schema/xml.xsd"));
FileUtils.copyFile(new File(buildDir + "/publish/fhir-xhtml.xsd"), new File("../hapi-fhir-structures-dstu2/src/main/resources/ca/uhn/fhir/model/dstu2/schema/fhir-xhtml.xsd"));
}
}

View File

@ -231,7 +231,6 @@
<mitreid-connect-version>1.1.8</mitreid-connect-version>
<phloc_schematron_version>2.7.1</phloc_schematron_version>
<phloc_commons_version>4.3.6</phloc_commons_version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<slf4j_version>1.7.10</slf4j_version>
<spring_version>4.1.5.RELEASE</spring_version>
<spring_security_version>3.2.4.RELEASE</spring_security_version>
@ -400,6 +399,7 @@
<target>1.6</target>
<compilerId>javac-with-errorprone</compilerId>
<forceJavacCompilerUse>true</forceJavacCompilerUse>
<encoding>UTF-8</encoding>
</configuration>
<dependencies>
<dependency>