diff --git a/.classpath b/.classpath index 8fbe9ec..c19037e 100644 --- a/.classpath +++ b/.classpath @@ -22,5 +22,7 @@ + + diff --git a/build.xml b/build.xml new file mode 100644 index 0000000..c79a61d --- /dev/null +++ b/build.xml @@ -0,0 +1,88 @@ + + + Standard Lightspeed Build File + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/lib/ant/ant-antlr.jar b/lib/ant/ant-antlr.jar new file mode 100644 index 0000000..2b4a481 Binary files /dev/null and b/lib/ant/ant-antlr.jar differ diff --git a/lib/ant/ant-apache-bcel.jar b/lib/ant/ant-apache-bcel.jar new file mode 100644 index 0000000..ea12320 Binary files /dev/null and b/lib/ant/ant-apache-bcel.jar differ diff --git a/lib/ant/ant-apache-bsf.jar b/lib/ant/ant-apache-bsf.jar new file mode 100644 index 0000000..0e7163d Binary files /dev/null and b/lib/ant/ant-apache-bsf.jar differ diff --git a/lib/ant/ant-apache-log4j.jar b/lib/ant/ant-apache-log4j.jar new file mode 100644 index 0000000..288d992 Binary files /dev/null and b/lib/ant/ant-apache-log4j.jar differ diff --git a/lib/ant/ant-apache-oro.jar b/lib/ant/ant-apache-oro.jar new file mode 100644 index 0000000..eb3aaad Binary files /dev/null and b/lib/ant/ant-apache-oro.jar differ diff --git a/lib/ant/ant-apache-regexp.jar b/lib/ant/ant-apache-regexp.jar new file mode 100644 index 0000000..255ace9 Binary files /dev/null and b/lib/ant/ant-apache-regexp.jar differ diff --git a/lib/ant/ant-apache-resolver.jar b/lib/ant/ant-apache-resolver.jar new file mode 100644 index 0000000..dd5d6cf Binary files /dev/null and b/lib/ant/ant-apache-resolver.jar differ diff --git a/lib/ant/ant-apache-xalan2.jar b/lib/ant/ant-apache-xalan2.jar new file mode 100644 index 0000000..adc2078 Binary files /dev/null and b/lib/ant/ant-apache-xalan2.jar differ diff --git a/lib/ant/ant-commons-logging.jar b/lib/ant/ant-commons-logging.jar new file mode 100644 index 0000000..5f4c61f Binary files /dev/null and b/lib/ant/ant-commons-logging.jar differ diff --git a/lib/ant/ant-commons-net.jar b/lib/ant/ant-commons-net.jar new file mode 100644 index 0000000..d4f5ace Binary files /dev/null and b/lib/ant/ant-commons-net.jar differ diff --git a/lib/ant/ant-jai.jar b/lib/ant/ant-jai.jar new file mode 100644 index 0000000..e1a9c2b Binary files /dev/null and b/lib/ant/ant-jai.jar differ diff --git a/lib/ant/ant-javamail.jar b/lib/ant/ant-javamail.jar new file mode 100644 index 0000000..776462b Binary files /dev/null and b/lib/ant/ant-javamail.jar differ diff --git a/lib/ant/ant-jdepend.jar b/lib/ant/ant-jdepend.jar new file mode 100644 index 0000000..8a551cc Binary files /dev/null and b/lib/ant/ant-jdepend.jar differ diff --git a/lib/ant/ant-jmf.jar b/lib/ant/ant-jmf.jar new file mode 100644 index 0000000..aca1e95 Binary files /dev/null and b/lib/ant/ant-jmf.jar differ diff --git a/lib/ant/ant-jsch.jar b/lib/ant/ant-jsch.jar new file mode 100644 index 0000000..ad86f0b Binary files /dev/null and b/lib/ant/ant-jsch.jar differ diff --git a/lib/ant/ant-junit.jar b/lib/ant/ant-junit.jar new file mode 100644 index 0000000..fb01a9c Binary files /dev/null and b/lib/ant/ant-junit.jar differ diff --git a/lib/ant/ant-junit4.jar b/lib/ant/ant-junit4.jar new file mode 100644 index 0000000..29304a9 Binary files /dev/null and b/lib/ant/ant-junit4.jar differ diff --git a/lib/ant/ant-launcher.jar b/lib/ant/ant-launcher.jar new file mode 100644 index 0000000..5073d2f Binary files /dev/null and b/lib/ant/ant-launcher.jar differ diff --git a/lib/ant/ant-netrexx.jar b/lib/ant/ant-netrexx.jar new file mode 100644 index 0000000..56d2a85 Binary files /dev/null and b/lib/ant/ant-netrexx.jar differ diff --git a/lib/ant/ant-swing.jar b/lib/ant/ant-swing.jar new file mode 100644 index 0000000..d1acca2 Binary files /dev/null and b/lib/ant/ant-swing.jar differ diff --git a/lib/ant/ant-testutil.jar b/lib/ant/ant-testutil.jar new file mode 100644 index 0000000..c9c1877 Binary files /dev/null and b/lib/ant/ant-testutil.jar differ diff --git a/lib/ant/ant-xz.jar b/lib/ant/ant-xz.jar new file mode 100644 index 0000000..0d5c588 Binary files /dev/null and b/lib/ant/ant-xz.jar differ diff --git a/lib/ant/ant.jar b/lib/ant/ant.jar new file mode 100644 index 0000000..4a7f8ed Binary files /dev/null and b/lib/ant/ant.jar differ diff --git a/src/com/projectswg/lightspeed/build/JavaBuildMethod.java b/src/com/projectswg/lightspeed/build/JavaBuildMethod.java index 3d6561b..2130e9c 100644 --- a/src/com/projectswg/lightspeed/build/JavaBuildMethod.java +++ b/src/com/projectswg/lightspeed/build/JavaBuildMethod.java @@ -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; diff --git a/src/com/projectswg/lightspeed/build/java_builder/CustomJavaBuild.java b/src/com/projectswg/lightspeed/build/java_builder/CustomJavaBuild.java index 0859def..4331db5 100644 --- a/src/com/projectswg/lightspeed/build/java_builder/CustomJavaBuild.java +++ b/src/com/projectswg/lightspeed/build/java_builder/CustomJavaBuild.java @@ -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 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; } } diff --git a/src/com/projectswg/lightspeed/build/java_builder/CustomJavaInstall.java b/src/com/projectswg/lightspeed/build/java_builder/CustomJavaInstall.java index d6d60ed..278ddac 100644 --- a/src/com/projectswg/lightspeed/build/java_builder/CustomJavaInstall.java +++ b/src/com/projectswg/lightspeed/build/java_builder/CustomJavaInstall.java @@ -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 classFiles = installer.getFileList(installer.getBin(), ".class"); - List 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() { - 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 - } - } - } diff --git a/src/com/projectswg/lightspeed/build/java_builder/CustomJavaTest.java b/src/com/projectswg/lightspeed/build/java_builder/CustomJavaTest.java index 859e496..eb0104b 100644 --- a/src/com/projectswg/lightspeed/build/java_builder/CustomJavaTest.java +++ b/src/com/projectswg/lightspeed/build/java_builder/CustomJavaTest.java @@ -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))); } } diff --git a/src/com/projectswg/lightspeed/build/java_builder/RepoInstaller.java b/src/com/projectswg/lightspeed/build/java_builder/RepoInstaller.java index a4c844d..86ee2fa 100644 --- a/src/com/projectswg/lightspeed/build/java_builder/RepoInstaller.java +++ b/src/com/projectswg/lightspeed/build/java_builder/RepoInstaller.java @@ -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; + } + } + }