mirror of
https://bitbucket.org/projectswg/lightspeed.git
synced 2026-09-28 14:12:57 -04:00
Changed build system to ant
This commit is contained in:
@@ -22,5 +22,7 @@
|
||||
</classpathentry>
|
||||
<classpathentry kind="lib" path="lib/HolocoreAdminPackets.jar"/>
|
||||
<classpathentry kind="lib" path="lib/lz4-1.3.0.jar"/>
|
||||
<classpathentry kind="lib" path="lib/ant/ant-launcher.jar"/>
|
||||
<classpathentry kind="lib" path="lib/ant/ant.jar"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
||||
|
||||
@@ -0,0 +1,88 @@
|
||||
<project name="Lightspeed" default="jar" basedir=".">
|
||||
<description>
|
||||
Standard Lightspeed Build File
|
||||
</description>
|
||||
<!-- set global properties for this build -->
|
||||
<property name="src" location="${opdir}/src"/>
|
||||
<property name="test" location="${opdir}/test"/>
|
||||
<property name="bin" location="${opdir}/bin"/>
|
||||
<property name="lib" location="${opdir}/lib"/>
|
||||
<property name="dist" location="${bin}/dist"/>
|
||||
<property name="jar" location="${dist}/ProjectSWG.jar"/>
|
||||
|
||||
<path id="ant.path">
|
||||
<fileset dir="lib/ant/">
|
||||
<include name="*.jar" />
|
||||
</fileset>
|
||||
<pathelement location="junit-4.12.jar"/>
|
||||
</path>
|
||||
<taskdef name="junit" classname="org.apache.tools.ant.taskdefs.optional.junit.JUnitTask" classpathref="ant.path" />
|
||||
|
||||
<target name="init">
|
||||
<!-- Create the bin directory structure used by compile -->
|
||||
<mkdir dir="${bin}"/>
|
||||
</target>
|
||||
|
||||
<target name="compile" depends="init" description="Compile the sources">
|
||||
<path id="classpath">
|
||||
<pathelement path="${classpath}"/>
|
||||
<fileset dir="${lib}">
|
||||
<include name="**/*.jar"/>
|
||||
</fileset>
|
||||
</path>
|
||||
<!-- Compile sources -->
|
||||
<javac srcdir="${src}" destdir="${bin}" includeantruntime="true" fork="true" debug="true">
|
||||
<classpath refid="classpath" />
|
||||
</javac>
|
||||
<!-- Compile tests -->
|
||||
<javac srcdir="${test}" destdir="${bin}" includeantruntime="true" fork="true" debug="true">
|
||||
<classpath refid="classpath" />
|
||||
</javac>
|
||||
</target>
|
||||
|
||||
<target name="test" depends="compile" description="Test">
|
||||
<junit printsummary="yes" haltonfailure="no" includeantruntime="true" fork="true" dir="${opdir}">
|
||||
<classpath>
|
||||
<pathelement location="${bin}" />
|
||||
<pathelement location="hamcrest-core-1.3.jar" />
|
||||
<pathelement location="junit-4.12.jar" />
|
||||
<fileset dir="${lib}">
|
||||
<include name="**/*.jar"/>
|
||||
</fileset>
|
||||
</classpath>
|
||||
<test name="main.TestAll" haltonfailure="no">
|
||||
</test>
|
||||
</junit>
|
||||
</target>
|
||||
|
||||
<target name="jar" depends="compile" description="Create the JAR">
|
||||
<!-- Create the distribution directory -->
|
||||
<delete dir="${dist}" />
|
||||
<mkdir dir="${dist}"/>
|
||||
<!-- Create the classpath -->
|
||||
<path id="classpath">
|
||||
<pathelement location="${bin}" />
|
||||
<fileset dir="${lib}">
|
||||
<include name="**/*.jar"/>
|
||||
</fileset>
|
||||
</path>
|
||||
<!-- Create the JAR -->
|
||||
<manifestclasspath property="manifest.classpath" jarfile="${jar}">
|
||||
<classpath refid="classpath" />
|
||||
</manifestclasspath>
|
||||
<jar jarfile="${jar}">
|
||||
<fileset dir="${bin}" includes="**/*.class" />
|
||||
<manifest>
|
||||
<attribute name="Main-Class" value="main.ProjectSWG"/>
|
||||
<attribute name="Class-Path" value="${manifest.classpath}"/>
|
||||
</manifest>
|
||||
</jar>
|
||||
</target>
|
||||
|
||||
<target name="clean" description="Clean up">
|
||||
<!-- Delete the ${bin} directory -->
|
||||
<delete dir="${dist}"/>
|
||||
<delete dir="${bin}"/>
|
||||
</target>
|
||||
</project>
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -66,7 +66,6 @@ public class JavaBuildMethod {
|
||||
|
||||
private void createJar(String repo, ServerBuildData buildData, InstallationCallback callback) {
|
||||
try {
|
||||
Log.i("Creating jar...");
|
||||
RepoInstaller installer = new RepoInstaller(new File(repo), jdk);
|
||||
buildData.setTime(TimeUtilities.getTime());
|
||||
if (!build(installer, buildData, callback)) {
|
||||
@@ -91,7 +90,7 @@ public class JavaBuildMethod {
|
||||
private boolean build(RepoInstaller installer, ServerBuildData buildData, InstallationCallback callback) {
|
||||
updateState(buildData, callback, InstallationState.BUILDING);
|
||||
CustomJavaBuild build = new CustomJavaBuild(installer);
|
||||
if (!build.compile(buildData, "main.ProjectSWG"))
|
||||
if (!build.compile(buildData))
|
||||
return false;
|
||||
if (detectCancelled(buildData, callback))
|
||||
return false;
|
||||
|
||||
@@ -27,10 +27,6 @@
|
||||
***********************************************************************************/
|
||||
package com.projectswg.lightspeed.build.java_builder;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.projectswg.common.info.Log;
|
||||
import com.projectswg.lightspeed.build.ServerBuildData;
|
||||
|
||||
@@ -42,37 +38,15 @@ public class CustomJavaBuild {
|
||||
this.installer = installer;
|
||||
}
|
||||
|
||||
public boolean compile(ServerBuildData buildData, String file) {
|
||||
String repo = buildData.getServer().getDirectory();
|
||||
file = file.replace('.', File.separatorChar);
|
||||
installer.getBin().mkdirs();
|
||||
String [] command = {
|
||||
installer.getJdkJavac().getAbsolutePath(),
|
||||
"-d", installer.getBin().getAbsolutePath(),
|
||||
"-classpath", installer.getFilesRelative(installer.getLib(), ".jar", File.pathSeparatorChar)+File.pathSeparator+".",
|
||||
"-sourcepath", installer.getSrc().getAbsolutePath()
|
||||
};
|
||||
StringBuilder builder = new StringBuilder();
|
||||
public boolean compile(ServerBuildData buildData) {
|
||||
long start = System.nanoTime();
|
||||
Log.i("Starting build...");
|
||||
int ret = CustomJavaCommon.execute(getFullCommand(command), new File(repo), builder, false);
|
||||
buildData.setCompileTime((System.nanoTime()-start)/1E9);
|
||||
buildData.setBuildString(builder.toString());
|
||||
buildData.setBuildSuccess(ret == 0);
|
||||
Log.i("Build return value: %d", ret);
|
||||
return ret == 0;
|
||||
}
|
||||
|
||||
private String [] getFullCommand(String [] header) {
|
||||
List<File> files = new ArrayList<>();
|
||||
files.addAll(installer.getFileList(installer.getSrc(), ".java"));
|
||||
files.addAll(installer.getFileList(installer.getTest(), ".java"));
|
||||
String [] command = new String[header.length + files.size()];
|
||||
System.arraycopy(header, 0, command, 0, header.length);
|
||||
for (int i = 0; i < files.size(); i++) {
|
||||
command[header.length + i] = files.get(i).getAbsolutePath();
|
||||
}
|
||||
return command;
|
||||
StringBuilder output = new StringBuilder("");
|
||||
boolean success = installer.executeAnt("compile", output);
|
||||
buildData.setBuildSuccess(success);
|
||||
buildData.setBuildString(output.toString());
|
||||
buildData.setCompileTime((System.nanoTime() - start) / 1E6);
|
||||
Log.i("Output: %s", output.toString());
|
||||
return success;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -27,20 +27,6 @@
|
||||
***********************************************************************************/
|
||||
package com.projectswg.lightspeed.build.java_builder;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.FileVisitResult;
|
||||
import java.nio.file.FileVisitor;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.attribute.BasicFileAttributes;
|
||||
import java.util.List;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipInputStream;
|
||||
|
||||
import com.projectswg.lightspeed.build.ServerBuildData;
|
||||
|
||||
public class CustomJavaInstall {
|
||||
@@ -52,110 +38,8 @@ public class CustomJavaInstall {
|
||||
}
|
||||
|
||||
public void createRawJar(ServerBuildData buildData, String file) throws CustomJavaException {
|
||||
String repo = buildData.getServer().getDirectory();
|
||||
File manifestFile = createManifest(repo, file);
|
||||
installer.execute(getCommandLineArgs(manifestFile));
|
||||
manifestFile.delete();
|
||||
installLoader();
|
||||
installer.executeAnt("jar", new StringBuilder(""));
|
||||
buildData.setJar(installer.getJar());
|
||||
}
|
||||
|
||||
private File createManifest(String repo, String file) throws CustomJavaException {
|
||||
String manifest = "Rsrc-Main-Class: " + file + "\n";
|
||||
manifest += "Rsrc-Class-Path: ./ " + installer.getFiles(installer.getLib(), ".jar", ' ') + "\n";
|
||||
manifest += "Main-Class: com.projectswg.lightspeed.build.jar_loader.LightspeedJarLoader\n";
|
||||
manifest += "Class-Path: .\n";
|
||||
try {
|
||||
File manifestFile = File.createTempFile("manifest", ".txt");
|
||||
try (FileWriter fw = new FileWriter(manifestFile)) {
|
||||
fw.write(manifest);
|
||||
}
|
||||
return manifestFile;
|
||||
} catch (IOException e) {
|
||||
throw new CustomJavaException("Install: Failed to create manifest. " + e.getClass().getSimpleName() + " " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private String [] getCommandLineArgs(File manifest) {
|
||||
List<File> classFiles = installer.getFileList(installer.getBin(), ".class");
|
||||
List<File> libFiles = installer.getFileList(installer.getLib(), ".jar");
|
||||
String [] command = new String[4 + classFiles.size()*3 + libFiles.size()];
|
||||
int i = 0;
|
||||
command[i++] = installer.getJdkJar().getAbsolutePath();
|
||||
command[i++] = "cvfm";
|
||||
command[i++] = installer.getJar().getAbsolutePath();
|
||||
command[i++] = manifest.getAbsolutePath();
|
||||
for (File f : classFiles) {
|
||||
command[i++] = "-C";
|
||||
command[i++] = installer.getBin().getAbsolutePath();
|
||||
command[i++] = f.getAbsolutePath();
|
||||
}
|
||||
for (File f : libFiles) {
|
||||
command[i++] = f.getAbsolutePath();
|
||||
}
|
||||
return command;
|
||||
}
|
||||
|
||||
private boolean installLoader() throws CustomJavaException {
|
||||
File dir = createTempDirectory();
|
||||
unzip("LightspeedJarLoader.zip", dir.getAbsolutePath());
|
||||
installer.execute(new String[]{installer.getJdkJar().getAbsolutePath(), "uvf", installer.getJar().getAbsolutePath(), "-C", dir.getAbsolutePath(), "."});
|
||||
deleteDirectory(dir);
|
||||
return true;
|
||||
}
|
||||
|
||||
private File createTempDirectory() throws CustomJavaException {
|
||||
try {
|
||||
return Files.createTempDirectory("LightspeedInstall").toFile();
|
||||
} catch (IOException e) {
|
||||
throw new CustomJavaException("Install: Failed to create temp directory");
|
||||
}
|
||||
}
|
||||
|
||||
private void unzip(String zipFilePath, String destDir) throws CustomJavaException {
|
||||
byte[] buffer = new byte[4*1024];
|
||||
try (FileInputStream fis = new FileInputStream(zipFilePath)) {
|
||||
try (ZipInputStream zis = new ZipInputStream(fis)) {
|
||||
ZipEntry ze = zis.getNextEntry();
|
||||
while (ze != null) {
|
||||
File newFile = new File(destDir + File.separator + ze.getName());
|
||||
if (ze.isDirectory()) {
|
||||
newFile.mkdirs();
|
||||
} else {
|
||||
new File(newFile.getParent()).mkdirs();
|
||||
try (FileOutputStream fos = new FileOutputStream(newFile)) {
|
||||
int len;
|
||||
while ((len = zis.read(buffer)) > 0) {
|
||||
fos.write(buffer, 0, len);
|
||||
}
|
||||
}
|
||||
}
|
||||
zis.closeEntry();
|
||||
ze = zis.getNextEntry();
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new CustomJavaException("Install: Failed to unzip jar loader. " + e.getClass().getSimpleName() + " " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private void deleteDirectory(File dir) {
|
||||
try {
|
||||
Files.walkFileTree(dir.toPath(), new FileVisitor<Path>() {
|
||||
public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException { return FileVisitResult.CONTINUE; }
|
||||
public FileVisitResult visitFileFailed(Path file, IOException exc) throws IOException { return FileVisitResult.CONTINUE; }
|
||||
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
|
||||
file.toFile().delete();
|
||||
return FileVisitResult.CONTINUE;
|
||||
}
|
||||
public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
|
||||
dir.toFile().delete();
|
||||
return FileVisitResult.CONTINUE;
|
||||
}
|
||||
});
|
||||
} catch (IOException e) {
|
||||
// Ignore - this is a minor issue as the files will be deleted on system reboot
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -27,7 +27,6 @@
|
||||
***********************************************************************************/
|
||||
package com.projectswg.lightspeed.build.java_builder;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@@ -37,8 +36,7 @@ import com.projectswg.lightspeed.build.ServerBuildData;
|
||||
|
||||
public class CustomJavaTest {
|
||||
|
||||
private static final Pattern JUNIT_OK_PATTERN = Pattern.compile("OK \\((\\d+) tests\\)");
|
||||
private static final Pattern JUNIT_FAIL_PATTERN = Pattern.compile("Tests run: (\\d+), Failures: (\\d+)");
|
||||
private static final Pattern JUNIT_PATTERN = Pattern.compile("Tests run: (\\d+), Failures: (\\d+), Errors: (\\d+).*$");
|
||||
|
||||
private final RepoInstaller installer;
|
||||
|
||||
@@ -47,61 +45,24 @@ public class CustomJavaTest {
|
||||
}
|
||||
|
||||
public TestDetails test(ServerBuildData buildData) {
|
||||
Log.i("Testing...");
|
||||
StringBuilder outBuilder = new StringBuilder();
|
||||
int ret = executeTest(outBuilder);
|
||||
String out = outBuilder.toString();
|
||||
TestDetails details = parseOutput(ret, out);
|
||||
StringBuilder output = new StringBuilder("");
|
||||
boolean success = installer.executeAnt("test", output);
|
||||
TestDetails details = parseFail(output.toString());
|
||||
buildData.setTestSuccess(success);
|
||||
buildData.setTestString(output.toString());
|
||||
buildData.setTestDetails(details);
|
||||
buildData.setTestString(out);
|
||||
buildData.setTestSuccess(ret == 0);
|
||||
Log.i("Test Result: %d", ret);
|
||||
Log.i("Output: %s", output.toString());
|
||||
return details;
|
||||
}
|
||||
|
||||
private int executeTest(StringBuilder oldBuilder) {
|
||||
String libs = installer.getBin().getAbsolutePath();
|
||||
libs += File.pathSeparatorChar + installer.getFilesRelative(installer.getLib(), ".jar", File.pathSeparatorChar);
|
||||
libs += File.pathSeparatorChar + new File("hamcrest-core-1.3.jar").getAbsolutePath();
|
||||
libs += File.pathSeparatorChar + new File("junit-4.12.jar").getAbsolutePath();
|
||||
String [] command = {
|
||||
installer.getJdkJava().getAbsolutePath(),
|
||||
"-cp", libs,
|
||||
"org.junit.runner.JUnitCore",
|
||||
"main.TestAll"
|
||||
};
|
||||
return installer.execute(command, oldBuilder);
|
||||
}
|
||||
|
||||
private TestDetails parseOutput(int ret, String out) {
|
||||
if (ret == 0) {
|
||||
return parseOK(out);
|
||||
} else if (out.contains("Tests run")) {
|
||||
return parseFail(out);
|
||||
} else {
|
||||
System.out.println(out);
|
||||
}
|
||||
return new TestDetails(-1, 0);
|
||||
}
|
||||
|
||||
private TestDetails parseOK(String out) {
|
||||
String line = out.substring(out.indexOf("OK"), out.indexOf('\n', out.indexOf("OK")));
|
||||
Matcher m = JUNIT_OK_PATTERN.matcher(line);
|
||||
if (!m.matches()) {
|
||||
System.err.println("Failed to match OK pattern: " + line);
|
||||
return new TestDetails(-1, 0);
|
||||
}
|
||||
return new TestDetails(Integer.parseInt(m.group(1)), 0);
|
||||
}
|
||||
|
||||
private TestDetails parseFail(String out) {
|
||||
String line = out.substring(out.indexOf("Tests run"), out.indexOf('\n', out.indexOf("Tests run")));
|
||||
Matcher m = JUNIT_FAIL_PATTERN.matcher(line);
|
||||
Matcher m = JUNIT_PATTERN.matcher(line);
|
||||
if (!m.matches()) {
|
||||
System.err.println("Failed to match FAIL pattern: " + line);
|
||||
return new TestDetails(-1, 0);
|
||||
}
|
||||
return new TestDetails(Integer.parseInt(m.group(1)), Integer.parseInt(m.group(2)));
|
||||
return new TestDetails(Integer.parseInt(m.group(1)), Integer.parseInt(m.group(2)) + Integer.parseInt(m.group(3)));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -31,6 +31,13 @@ import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.tools.ant.BuildEvent;
|
||||
import org.apache.tools.ant.BuildListener;
|
||||
import org.apache.tools.ant.Project;
|
||||
import org.apache.tools.ant.ProjectHelper;
|
||||
|
||||
import com.projectswg.common.info.Log;
|
||||
|
||||
public class RepoInstaller {
|
||||
|
||||
private static final String SEP = File.separator;
|
||||
@@ -53,7 +60,7 @@ public class RepoInstaller {
|
||||
this.src = new File(repo, "src");
|
||||
this.lib = new File(repo, "lib");
|
||||
this.test= new File(repo, "test");
|
||||
this.jar = new File(bin, "ProjectSWG.jar");
|
||||
this.jar = new File(bin, "dist" + SEP + "ProjectSWG.jar");
|
||||
this.jdk = jdk;
|
||||
String ext = "";
|
||||
if (System.getProperty("os.name").toLowerCase().indexOf("win") >= 0)
|
||||
@@ -63,6 +70,12 @@ public class RepoInstaller {
|
||||
this.jdkJar = new File(jdk, "bin" + SEP + "jar" + ext);
|
||||
}
|
||||
|
||||
public String getExtension() {
|
||||
if (System.getProperty("os.name").toLowerCase().indexOf("win") >= 0)
|
||||
return ".exe";
|
||||
return "";
|
||||
}
|
||||
|
||||
public File getRepo() {
|
||||
return repo;
|
||||
}
|
||||
@@ -108,10 +121,18 @@ public class RepoInstaller {
|
||||
}
|
||||
|
||||
public int execute(String [] command, StringBuilder output) {
|
||||
String opDirectory = repo.getAbsolutePath() + File.separatorChar;
|
||||
for (int i = 0; i < command.length; i++) {
|
||||
command[i] = command[i].replace(opDirectory, "");
|
||||
}
|
||||
return CustomJavaCommon.execute(command, repo, output, false);
|
||||
}
|
||||
|
||||
public int execute(String [] command, boolean output) {
|
||||
String opDirectory = repo.getAbsolutePath() + File.separatorChar;
|
||||
for (int i = 0; i < command.length; i++) {
|
||||
command[i] = command[i].replace(opDirectory, "");
|
||||
}
|
||||
return CustomJavaCommon.execute(command, repo, null, output);
|
||||
}
|
||||
|
||||
@@ -144,4 +165,36 @@ public class RepoInstaller {
|
||||
return files;
|
||||
}
|
||||
|
||||
public boolean executeAnt(String target, StringBuilder output) {
|
||||
File buildFile = new File("build.xml");
|
||||
Project p = new Project();
|
||||
ProjectHelper helper = ProjectHelper.getProjectHelper();
|
||||
p.setProperty("java.home", getJdk().getAbsolutePath());
|
||||
p.setUserProperty("ant.file", buildFile.getAbsolutePath());
|
||||
p.setUserProperty("opdir", getRepo().getAbsolutePath());
|
||||
p.init();
|
||||
p.addReference("ant.projectHelper", helper);
|
||||
helper.parse(p, buildFile);
|
||||
p.addBuildListener(new BuildListener() {
|
||||
public void taskStarted(BuildEvent arg0) { }
|
||||
public void taskFinished(BuildEvent arg0) { }
|
||||
public void targetStarted(BuildEvent arg0) { }
|
||||
public void targetFinished(BuildEvent arg0) { }
|
||||
public void buildStarted(BuildEvent arg0) { }
|
||||
public void buildFinished(BuildEvent arg0) { }
|
||||
@Override
|
||||
public void messageLogged(BuildEvent arg0) {
|
||||
if (arg0.getPriority() <= 2)
|
||||
output.append(arg0.getMessage() + '\n');
|
||||
}
|
||||
});
|
||||
try {
|
||||
p.executeTarget(target);
|
||||
return true;
|
||||
} catch (Throwable t) {
|
||||
Log.e(t);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user