Skip to content

Commit

Permalink
Fixed bug that prevented JReader installing from .jar file
Browse files Browse the repository at this point in the history
  • Loading branch information
facetoe committed Jan 28, 2014
1 parent 40766cd commit 63c53a0
Show file tree
Hide file tree
Showing 7 changed files with 315 additions and 193 deletions.
11 changes: 6 additions & 5 deletions .idea/artifacts/JReader_jar.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

368 changes: 205 additions & 163 deletions .idea/workspace.xml

Large diffs are not rendered by default.

60 changes: 45 additions & 15 deletions build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,16 @@
<pathelement location="${basedir}/lib/forms_rt.jar"/>
</path>

<path id="library.gson-2.2.4.classpath">
<pathelement location="${basedir}/lib/gson-2.2.4.jar"/>
</path>

<path id="library.javaparser-1.0.11-snapshot.classpath">
<pathelement location="${basedir}/lib/javaparser-1.0.11-SNAPSHOT.jar"/>
</path>

<path id="library.jfxrt.classpath">
<pathelement location="${basedir}/../../../../usr/lib/jvm/java-7-oracle/jre/lib/jfxrt.jar"/>
<pathelement location="${basedir}/lib/jfxrt.jar"/>
</path>

<path id="library.jgoodies-forms.classpath">
Expand Down Expand Up @@ -151,10 +155,11 @@
<property name="module.jdk.bin.jreader" value="${project.jdk.bin}"/>
<property name="module.jdk.classpath.jreader" value="${project.jdk.classpath}"/>

<property name="compiler.args.jreader" value="${compiler.args}"/>
<property name="compiler.args.jreader" value="-encoding UTF-8 -source 1.6 ${compiler.args}"/>

<property name="jreader.output.dir" value="${module.jreader.basedir}/out/production/JReader"/>

<property name="jreader.testoutput.dir" value="${module.jreader.basedir}/out/test/JReader"/>

<path id="jreader.module.bootclasspath">
<!-- Paths to be included in compilation bootclasspath -->
</path>
Expand All @@ -169,8 +174,9 @@
<path refid="library.forms_rt.classpath"/>
<path refid="library.jgoodies-forms.classpath"/>
<path refid="library.swingx-all-1.6.4.classpath"/>
<path refid="library.jfxrt.classpath"/>
<pathelement location="${idea.home}/lib/junit-4.10.jar"/>
<path refid="library.gson-2.2.4.classpath"/>
<path refid="library.jfxrt.classpath"/>
</path>

<path id="jreader.runtime.production.module.classpath">
Expand All @@ -183,8 +189,9 @@
<path refid="library.forms_rt.classpath"/>
<path refid="library.jgoodies-forms.classpath"/>
<path refid="library.swingx-all-1.6.4.classpath"/>
<path refid="library.jfxrt.classpath"/>
<pathelement location="${idea.home}/lib/junit-4.10.jar"/>
<path refid="library.gson-2.2.4.classpath"/>
<path refid="library.jfxrt.classpath"/>
</path>

<path id="jreader.module.classpath">
Expand All @@ -198,11 +205,13 @@
<path refid="library.forms_rt.classpath"/>
<path refid="library.jgoodies-forms.classpath"/>
<path refid="library.swingx-all-1.6.4.classpath"/>
<path refid="library.jfxrt.classpath"/>
<pathelement location="${idea.home}/lib/junit-4.10.jar"/>
<path refid="library.gson-2.2.4.classpath"/>
<path refid="library.jfxrt.classpath"/>
</path>

<path id="jreader.runtime.module.classpath">
<pathelement location="${jreader.testoutput.dir}"/>
<pathelement location="${jreader.output.dir}"/>
<path refid="library.jsoup-1.7.2.classpath"/>
<path refid="library.rsyntaxtextarea.classpath"/>
Expand All @@ -212,8 +221,9 @@
<path refid="library.forms_rt.classpath"/>
<path refid="library.jgoodies-forms.classpath"/>
<path refid="library.swingx-all-1.6.4.classpath"/>
<path refid="library.jfxrt.classpath"/>
<pathelement location="${idea.home}/lib/junit-4.10.jar"/>
<path refid="library.gson-2.2.4.classpath"/>
<path refid="library.jfxrt.classpath"/>
</path>


Expand All @@ -234,11 +244,12 @@
<path id="jreader.module.test.sourcepath">
<dirset dir="${module.jreader.basedir}">
<include name="test"/>
<include name="testFiles"/>
</dirset>
</path>



<target name="compile.module.jreader" depends="compile.module.jreader.production,compile.module.jreader.tests" description="Compile module JReader"/>

<target name="compile.module.jreader.production" depends="register.custom.compilers" description="Compile module JReader; production classes">
<mkdir dir="${jreader.output.dir}"/>
<javac2 destdir="${jreader.output.dir}" debug="${compiler.debug}" nowarn="${compiler.generate.no.warnings}" memorymaximumsize="${compiler.max.memory}" fork="true" executable="${module.jdk.bin.jreader}/javac">
Expand All @@ -256,10 +267,28 @@
</fileset>
</copy>
</target>


<target name="compile.module.jreader.tests" depends="register.custom.compilers,compile.module.jreader.production" description="compile module JReader; test classes" unless="skip.tests">
<mkdir dir="${jreader.testoutput.dir}"/>
<javac2 destdir="${jreader.testoutput.dir}" debug="${compiler.debug}" nowarn="${compiler.generate.no.warnings}" memorymaximumsize="${compiler.max.memory}" fork="true" executable="${module.jdk.bin.jreader}/javac">
<compilerarg line="${compiler.args.jreader}"/>
<bootclasspath refid="jreader.module.bootclasspath"/>
<classpath refid="jreader.module.classpath"/>
<src refid="jreader.module.test.sourcepath"/>
<patternset refid="excluded.from.compilation.jreader"/>
</javac2>

<copy todir="${jreader.testoutput.dir}">
<fileset dir="${module.jreader.basedir}/test">
<patternset refid="compiler.resources"/>
<type type="file"/>
</fileset>
</copy>
</target>

<target name="clean.module.jreader" description="cleanup module">
<delete dir="${jreader.output.dir}"/>
<delete dir="${jreader.testoutput.dir}"/>
</target>

<target name="init" description="Build initialization">
Expand All @@ -282,15 +311,16 @@
<mkdir dir="${artifact.temp.output.jreader:jar}"/>
<jar destfile="${temp.jar.path.JReader.jar}" duplicate="preserve" filesetmanifest="mergewithoutmain">
<zipfileset dir="${jreader.output.dir}"/>
<zipfileset src="${basedir}/lib/jsoup-1.7.2.jar"/>
<zipfileset src="${basedir}/lib/forms_rt.jar"/>
<zipfileset src="${basedir}/lib/rsyntaxtextarea.jar"/>
<zipfileset src="${basedir}/lib/gson-2.2.4.jar"/>
<zipfileset src="${basedir}/lib/javaparser-1.0.11-SNAPSHOT.jar"/>
<zipfileset src="${basedir}/lib/jfxrt.jar"/>
<zipfileset src="${basedir}/lib/jgoodies-forms.jar"/>
<zipfileset src="${basedir}/lib/jsoup-1.7.2.jar"/>
<zipfileset src="${basedir}/lib/log4j-1.2.14.jar"/>
<zipfileset src="${basedir}/lib/rsyntaxtextarea.jar"/>
<zipfileset src="${basedir}/lib/swingx-all-1.6.4.jar"/>
<zipfileset src="${basedir}/lib/zip4j_1.3.1.jar"/>
<zipfileset src="${basedir}/lib/log4j-1.2.14.jar"/>
<zipfileset src="${basedir}/lib/javaparser-1.0.11-SNAPSHOT.jar"/>
<zipfileset src="${basedir}/../../../../usr/lib/jvm/java-7-oracle/jre/lib/jfxrt.jar"/>
</jar>
<copy file="${temp.jar.path.JReader.jar}" tofile="${artifact.temp.output.jreader:jar}/JReader.jar"/>
</target>
Expand Down
1 change: 1 addition & 0 deletions src/com/facetoe/jreader/helpers/UnZipper.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public void unzip(File sourceFile, String destinationPath) throws Exception {
return;

if (pm.getCurrentOperation() == ProgressMonitor.OPERATION_EXTRACT) {
System.out.println(pm.getFileName());
publishProgress(pm.getFileName());
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/com/facetoe/jreader/ui/Actions.java
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,6 @@ public QuitAction(JReader jReader) {

@Override
public void actionPerformed(ActionEvent e) {
jReader.saveProfiles();
jReader.saveAndQuit();
}
}
62 changes: 55 additions & 7 deletions src/com/facetoe/jreader/ui/InstallationWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.IOException;
import java.io.*;

/**
* Created by facetoe on 18/01/14.
Expand All @@ -34,6 +33,7 @@ public class InstallationWindow implements ZipProgressListener {
private JLabel lblStatus;
private static final String SOURCE_REFERENCE = "/com/facetoe/jreader/resources/zipfiles/src-jdk.zip";
private static final String DOCS_REFERENCE = "/com/facetoe/jreader/resources/zipfiles/jdk-7u51-apidocs.zip";
private static String TEMP_FILE_NAME;
private SwingWorker installWorker;
private UnZipper unZipper;

Expand Down Expand Up @@ -87,6 +87,7 @@ private void install() {
protected Object doInBackground() throws Exception {
lblStatus.setText("Initializing...");
JReaderSetup.createDirectoriesAndConfig();
TEMP_FILE_NAME = Config.getString(Config.DATA_DIR) + File.separator + "tmpfile";
if (isCancelled())
return null;
unzipSource();
Expand All @@ -108,6 +109,7 @@ protected Object doInBackground() throws Exception {
installWorker.execute();

} catch (Exception e) {
System.out.println("Error: " + e.getMessage());
log.error(e);
Util.showErrorDialog(dialog, e.getMessage(), "Error Installing JReader");
dialog.dispose();
Expand All @@ -129,16 +131,62 @@ private void createDefaultProfile() throws IOException {
Config.setBool(Config.HAS_DEFAULT_PROFILE, true);
}

private void unzipSource() throws Exception {
File zipFile = Util.getResourceAsFile(getClass(), SOURCE_REFERENCE);
String destinationPath = Util.constructPath(Config.getString(Config.DATA_DIR), Config.JAVA_LANG_ZIP_FILE_NAME);
unZipper.unzip(zipFile, destinationPath);
private void unzipSource() {
try {
InputStream in = getClass().getResourceAsStream(SOURCE_REFERENCE);
File zipFile = inputStreamToFile(in);
String destinationPath = Util.constructPath(Config.getString(Config.DATA_DIR), Config.JAVA_LANG_ZIP_FILE_NAME);
unZipper.unzip(zipFile, destinationPath);
new File(TEMP_FILE_NAME).delete();
} catch (Exception e) {
System.out.println(e);
}
}

private File inputStreamToFile(InputStream in) {
System.out.println(in);
FileOutputStream outputStream = null;
File outFile = new File(TEMP_FILE_NAME);
try {
outFile.createNewFile();
outputStream = new FileOutputStream(outFile);
int read = 0;
byte[] bytes = new byte[1024];

while ((read = in.read(bytes)) != -1) {
outputStream.write(bytes, 0, read);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (in != null) {
try {
in.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if (outputStream != null) {
try {
outputStream.flush();
outputStream.close();
} catch (IOException e) {
e.printStackTrace();
}

}
}
return new File(outFile.getAbsolutePath());
}

private void unzipDocs() throws Exception {
File zipFile = Util.getResourceAsFile(getClass(), DOCS_REFERENCE);
InputStream in = getClass().getResourceAsStream(DOCS_REFERENCE);
File zipFile = inputStreamToFile(in);
String destinationPath = Util.constructPath(Config.getString(Config.DATA_DIR), Config.JAVA_DOCS_ZIP_FILE_NAME);
unZipper.unzip(zipFile, destinationPath);
new File(TEMP_FILE_NAME).delete();
}


Expand Down
4 changes: 2 additions & 2 deletions src/com/facetoe/jreader/ui/JReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ private void initListeners() {
frame.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
saveProfiles();
saveAndQuit();
System.exit(0);
}
});
Expand Down Expand Up @@ -363,7 +363,7 @@ public void resetSearchBar() {
topPanel.resetSearchBar();
}

public void saveProfiles() {
public void saveAndQuit() {
try {
log.debug("Saving profiles..");
profileManager.saveProfiles();
Expand Down

0 comments on commit 63c53a0

Please sign in to comment.