Skip to content

Commit 5bf1c6f

Browse files
committed
working eclipse compiler;
0 parents  commit 5bf1c6f

18 files changed

+362
-0
lines changed

.classpath

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry kind="src" path="src"/>
4+
<classpathentry kind="src" path="gen"/>
5+
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
6+
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
7+
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.DEPENDENCIES"/>
8+
<classpathentry kind="output" path="bin/classes"/>
9+
</classpath>

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
bin/
2+
gen/

.project

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>SelfCompileApp</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
<buildCommand>
14+
<name>com.android.ide.eclipse.adt.PreCompilerBuilder</name>
15+
<arguments>
16+
</arguments>
17+
</buildCommand>
18+
<buildCommand>
19+
<name>org.eclipse.jdt.core.javabuilder</name>
20+
<arguments>
21+
</arguments>
22+
</buildCommand>
23+
<buildCommand>
24+
<name>com.android.ide.eclipse.adt.ApkBuilder</name>
25+
<arguments>
26+
</arguments>
27+
</buildCommand>
28+
</buildSpec>
29+
<natures>
30+
<nature>com.android.ide.eclipse.adt.AndroidNature</nature>
31+
<nature>org.eclipse.jdt.core.javanature</nature>
32+
</natures>
33+
</projectDescription>

AndroidManifest.xml

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="nl.tudelft.selfcompileapp"
4+
android:installLocation="preferExternal"
5+
android:versionCode="1"
6+
android:versionName="1.0" >
7+
8+
<uses-sdk
9+
android:minSdkVersion="18"
10+
android:targetSdkVersion="22" />
11+
12+
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
13+
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
14+
<uses-permission android:name="android.permission.NFC" />
15+
16+
<application
17+
android:allowBackup="true"
18+
android:icon="@drawable/ic_launcher"
19+
android:label="@string/app_name"
20+
android:theme="@style/AppTheme" >
21+
<activity
22+
android:name=".MainActivity"
23+
android:label="@string/app_name" >
24+
<intent-filter>
25+
<action android:name="android.intent.action.MAIN" />
26+
27+
<category android:name="android.intent.category.LAUNCHER" />
28+
</intent-filter>
29+
</activity>
30+
</application>
31+
32+
</manifest>

ic_launcher-web.png

16.4 KB
Loading

proguard-project.txt

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# To enable ProGuard in your project, edit project.properties
2+
# to define the proguard.config property as described in that file.
3+
#
4+
# Add project specific ProGuard rules here.
5+
# By default, the flags in this file are appended to flags specified
6+
# in ${sdk.dir}/tools/proguard/proguard-android.txt
7+
# You can edit the include path and order by changing the ProGuard
8+
# include property in project.properties.
9+
#
10+
# For more details, see
11+
# http://developer.android.com/guide/developing/tools/proguard.html
12+
13+
# Add any project specific keep options here:
14+
15+
# If your project uses WebView with JS, uncomment the following
16+
# and specify the fully qualified class name to the JavaScript interface
17+
# class:
18+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
19+
# public *;
20+
#}

project.properties

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# This file is automatically generated by Android Tools.
2+
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
3+
#
4+
# This file must be checked in Version Control Systems.
5+
#
6+
# To customize properties used by the Ant build system edit
7+
# "ant.properties", and override values to adapt the script to your
8+
# project structure.
9+
#
10+
# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
11+
#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
12+
13+
# Project target.
14+
target=android-22

res/drawable-hdpi/ic_launcher.png

1.51 KB
Loading

res/drawable-mdpi/ic_launcher.png

1.01 KB
Loading

res/drawable-xhdpi/ic_launcher.png

1.97 KB
Loading

res/drawable-xxhdpi/ic_launcher.png

3.13 KB
Loading

res/layout/activity_main.xml

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
2+
xmlns:tools="http://schemas.android.com/tools"
3+
android:layout_width="match_parent"
4+
android:layout_height="match_parent"
5+
tools:context="${relativePackage}.${activityClass}" >
6+
7+
<Button
8+
android:id="@+id/btnCompile"
9+
android:layout_width="wrap_content"
10+
android:layout_height="wrap_content"
11+
android:layout_centerHorizontal="true"
12+
android:layout_centerVertical="true"
13+
android:onClick="selfCompile"
14+
android:text="@string/btnCompile" />
15+
16+
</RelativeLayout>

res/values-v11/styles.xml

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<resources>
2+
3+
<!--
4+
Base application theme for API 11+. This theme completely replaces
5+
AppBaseTheme from res/values/styles.xml on API 11+ devices.
6+
-->
7+
<style name="AppBaseTheme" parent="android:Theme.Holo.Light">
8+
<!-- API 11 theme customizations can go here. -->
9+
</style>
10+
11+
</resources>

res/values-v14/styles.xml

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<resources>
2+
3+
<!--
4+
Base application theme for API 14+. This theme completely replaces
5+
AppBaseTheme from BOTH res/values/styles.xml and
6+
res/values-v11/styles.xml on API 14+ devices.
7+
-->
8+
<style name="AppBaseTheme" parent="android:Theme.Holo.Light.DarkActionBar">
9+
<!-- API 14 theme customizations can go here. -->
10+
</style>
11+
12+
</resources>

res/values/strings.xml

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<resources>
3+
4+
<string name="app_name">SelfCompileApp</string>
5+
<string name="btnCompile">Compile</string>
6+
7+
</resources>

res/values/styles.xml

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<resources>
2+
3+
<!--
4+
Base application theme, dependent on API level. This theme is replaced
5+
by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
6+
-->
7+
<style name="AppBaseTheme" parent="android:Theme.Light">
8+
<!--
9+
Theme customizations available in newer API levels can go in
10+
res/values-vXX/styles.xml, while customizations related to
11+
backward-compatibility can go here.
12+
-->
13+
</style>
14+
15+
<!-- Application theme. -->
16+
<style name="AppTheme" parent="AppBaseTheme">
17+
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
18+
</style>
19+
20+
</resources>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
package nl.tudelft.selfcompileapp;
2+
3+
import java.io.File;
4+
import java.io.IOException;
5+
import java.io.InputStream;
6+
import java.io.PrintWriter;
7+
8+
import org.eclipse.jdt.core.compiler.batch.BatchCompiler;
9+
import org.eclipse.jdt.internal.compiler.tool.EclipseCompiler;
10+
11+
import android.app.Activity;
12+
import android.os.AsyncTask;
13+
import android.os.Bundle;
14+
import android.os.Environment;
15+
import android.view.View;
16+
import android.widget.Button;
17+
18+
public class MainActivity extends Activity {
19+
20+
@Override
21+
protected void onCreate(Bundle savedInstanceState) {
22+
super.onCreate(savedInstanceState);
23+
setContentView(R.layout.activity_main);
24+
}
25+
26+
void toggleBtnCompile(boolean enabled) {
27+
28+
}
29+
30+
public void selfCompile(View btnCompile) {
31+
btnCompile.setEnabled(false);
32+
new CompilePrjSrc().execute();
33+
}
34+
35+
private class CompilePrjSrc extends AsyncTask<Object, Object, Object> {
36+
37+
@Override
38+
protected void onPostExecute(Object result) {
39+
Button btnCompile = (Button) findViewById(R.id.btnCompile);
40+
btnCompile.setEnabled(true);
41+
}
42+
43+
@Override
44+
protected Object doInBackground(Object... params) {
45+
try {
46+
System.out.println("// CLEAR OUTPUT FOLDER");
47+
File dirDownloads = Environment
48+
.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
49+
File dirProject = new File(dirDownloads, "demo_android");
50+
Util.deleteRecursive(dirProject);
51+
52+
System.out.println("// COPY PROJECT SOURCE");
53+
InputStream zipPrjSrc = getAssets().open("demo_android.zip");
54+
Util.unZip(zipPrjSrc, dirDownloads);
55+
56+
System.out.println("// COPY ANDROID PLATFORM");
57+
InputStream zipAndroidPlatform = getAssets().open(
58+
"android-22.zip");
59+
Util.unZip(zipAndroidPlatform, dirDownloads);
60+
61+
// TODO REMOVE R.JAVA
62+
63+
// TODO RUN AAPT & CREATE R.JAVA
64+
File dirGen = new File(dirProject, "gen");
65+
dirGen.mkdir();
66+
67+
System.out.println("// COMPILE SOURCE RECURSIVE");
68+
69+
// -verbose
70+
// -deprecation
71+
// -extdirs \"\"
72+
// -1.5
73+
// -bootclasspath
74+
// {AndroidJarPath}:
75+
// {root}libs/ecj.jar:
76+
// {root}libs/dx_ta.jar:
77+
// {root}libs/bsh.jar:
78+
// {root}libs/sdklib_ta.jar:
79+
// {root}libs/androidprefs.jar:
80+
// {root}libs/zipsigner-lib_all.jar
81+
// -classpath
82+
// {root}src:
83+
// {root}gen
84+
// -d {stScriptPath}bin
85+
// {root}src/com/t_arn/MainActivity.java
86+
87+
String strRoot = dirDownloads.getAbsolutePath();
88+
String strProj = dirProject.getAbsolutePath();
89+
String strArgs = " -verbose -1.5";
90+
strArgs += " -bootclasspath \"" + strRoot + "/android-22.jar:"
91+
+ strRoot + "/android-support-v13.jar:" + strRoot
92+
+ "/android-support-annotations.jar\"";
93+
strArgs += " -cp \"" + strProj + "/libs/demolib.jar:" + strProj
94+
+ "/src:" + strProj + "/gen\"";
95+
strArgs += " -d \"" + strProj + "/build/classes\""; // output
96+
strArgs += " \"" + strProj
97+
+ "/src/org/me/androiddemo/MainActivity.java\"";
98+
99+
BatchCompiler.compile(strArgs, new PrintWriter(System.out),
100+
new PrintWriter(System.err), null);
101+
102+
} catch (IOException e) {
103+
// TODO Auto-generated catch block
104+
e.printStackTrace();
105+
}
106+
return null;
107+
}
108+
109+
}
110+
}
+76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
package nl.tudelft.selfcompileapp;
2+
3+
import java.io.BufferedInputStream;
4+
import java.io.File;
5+
import java.io.FileNotFoundException;
6+
import java.io.FileOutputStream;
7+
import java.io.IOException;
8+
import java.io.InputStream;
9+
import java.io.PrintWriter;
10+
import java.util.zip.ZipEntry;
11+
import java.util.zip.ZipInputStream;
12+
13+
import org.eclipse.jdt.core.compiler.batch.BatchCompiler;
14+
15+
public class Util {
16+
17+
/**
18+
* @source http://stackoverflow.com/a/27050680
19+
*/
20+
public static void unZip(InputStream zipFile, File targetDir)
21+
throws IOException {
22+
ZipInputStream in = new ZipInputStream(new BufferedInputStream(zipFile));
23+
try {
24+
ZipEntry entry;
25+
int count;
26+
byte[] buffer = new byte[8192];
27+
while ((entry = in.getNextEntry()) != null) {
28+
29+
File file = new File(targetDir, entry.getName());
30+
File dir = entry.isDirectory() ? file : file.getParentFile();
31+
32+
if (!dir.isDirectory() && !dir.mkdirs()) {
33+
throw new FileNotFoundException(
34+
"Failed to ensure directory: "
35+
+ dir.getAbsolutePath());
36+
}
37+
if (entry.isDirectory()) {
38+
continue;
39+
}
40+
FileOutputStream out = new FileOutputStream(file);
41+
try {
42+
while ((count = in.read(buffer)) != -1) {
43+
out.write(buffer, 0, count);
44+
}
45+
} catch (Exception e) {
46+
// TODO Auto-generated catch block
47+
e.printStackTrace();
48+
} finally {
49+
out.close();
50+
}
51+
/*
52+
* if time should be restored as well long time = ze.getTime();
53+
* if (time > 0) file.setLastModified(time);
54+
*/
55+
}
56+
} catch (Exception e) {
57+
// TODO Auto-generated catch block
58+
e.printStackTrace();
59+
} finally {
60+
in.close();
61+
}
62+
}
63+
64+
/**
65+
* @source http://stackoverflow.com/a/6425744
66+
*/
67+
public static void deleteRecursive(File path) {
68+
if (path.isDirectory()) {
69+
for (File child : path.listFiles()) {
70+
deleteRecursive(child);
71+
}
72+
}
73+
path.delete();
74+
}
75+
76+
}

0 commit comments

Comments
 (0)