10
10
*******************************************************************************/
11
11
package org .eclipse .thym .android .core .adt ;
12
12
13
- import java .io .BufferedReader ;
14
- import java .io .File ;
15
- import java .io .FileReader ;
16
- import java .io .IOException ;
17
- import java .net .URL ;
18
13
import java .util .HashMap ;
19
- import java .util .Iterator ;
20
14
21
15
import org .eclipse .core .runtime .Assert ;
22
- import org .eclipse .core .runtime .CoreException ;
23
- import org .eclipse .core .runtime .IPath ;
24
- import org .eclipse .core .runtime .IProgressMonitor ;
25
- import org .eclipse .core .runtime .IStatus ;
26
- import org .eclipse .core .runtime .Path ;
27
- import org .eclipse .core .runtime .Status ;
28
- import org .eclipse .osgi .util .NLS ;
29
- import org .eclipse .thym .android .core .AndroidCore ;
30
- import org .eclipse .thym .core .HybridCore ;
31
16
import org .eclipse .thym .core .engine .HybridMobileLibraryResolver ;
32
- import org .eclipse .thym .core .internal . util . FileUtils ;
17
+ import org .eclipse .thym .core .platform . PlatformConstants ;
33
18
34
- import com .github .zafarkhaja .semver .Version ;
35
-
36
- public class AndroidLibraryResolver extends
37
- HybridMobileLibraryResolver {
38
- private static final Version VERSION_4_0_0 = Version .valueOf ("4.0.0" );
39
-
40
- public static final String DIR_LIBS = "libs" ;
41
- public static final String DIR_RES = "res" ;
42
- public static final String DIR_SRC = "src" ;
19
+ public class AndroidLibraryResolver extends HybridMobileLibraryResolver {
43
20
44
- public static final String FILE_JAR_CORDOVA = "cordova.jar" ;
45
- private static final IPath KEY_PATH_CORDOVA_JAR = new Path (DIR_LIBS +"/" + FILE_JAR_CORDOVA );
46
- public static final String FILE_XML_ANDROIDMANIFEST = "AndroidManifest.xml" ;
21
+ public static final String PROPERTIES ="project.propeties" ;
47
22
48
- HashMap <IPath , URL > files = new HashMap <IPath , URL >();
23
+ HashMap <String , String > files = new HashMap <String , String >();
49
24
50
25
private void initFiles () {
51
- Assert .isNotNull (libraryRoot , "Library resolver is not initialized. Call init before accessing any other functions." );
52
- if (version == null ){
53
- return ;
54
- }
55
- Version ver = Version .valueOf (version );
56
-
57
- IPath templatePrjRoot = libraryRoot .append ("bin/templates/project" );
58
- IPath cordovaJar = libraryRoot .append ("framework" ).append (NLS .bind ("cordova-{0}.jar" ,version ));
59
- files .put (KEY_PATH_CORDOVA_JAR , getEngineFile (cordovaJar ));
60
- files .put (new Path (DIR_RES ),getEngineFile (templatePrjRoot .append (DIR_RES )));
61
- files .put (new Path (FILE_XML_ANDROIDMANIFEST ), getEngineFile (templatePrjRoot .append (FILE_XML_ANDROIDMANIFEST )));
62
- files .put (new Path (DIR_SRC ).append (VAR_PACKAGE_NAME .replace ('.' , '/' )).append (VAR_APP_NAME +".java" ),
63
- getEngineFile (templatePrjRoot .append ("Activity.java" )));
64
- if (ver .lessThan (VERSION_4_0_0 )){
65
- files .put (PATH_CORDOVA_JS , getEngineFile (libraryRoot .append ("framework/assets/www/cordova.js" )));
66
- }else {
67
- // version 4.0.0 places cordova.js to a new location
68
- files .put (PATH_CORDOVA_JS , getEngineFile (templatePrjRoot .append ("assets/www/cordova.js" )));
69
- }
70
- files .put (new Path ("framework/project.properties" ), getEngineFile (libraryRoot .append ("framework/project.properties" )));
71
- }
72
-
73
-
74
- @ Override
75
- public URL getTemplateFile (IPath destination ) {
76
- if (files .isEmpty ()) initFiles ();
77
- Assert .isNotNull (destination );
78
- Assert .isTrue (!destination .isAbsolute ());
79
- return files .get (destination );
80
- }
81
-
82
- @ Override
83
- public IStatus isLibraryConsistent () {
84
- if (version == null ){
85
- return new Status (IStatus .ERROR , HybridCore .PLUGIN_ID , "Library for Android platform is not compatible with this tool. File for path {0} is missing." );
86
- }
87
- if (files .isEmpty ()) initFiles ();
88
- Iterator <IPath > paths = files .keySet ().iterator ();
89
- while (paths .hasNext ()) {
90
- IPath key = paths .next ();
91
- URL url = files .get (key );
92
- if (url != null ){
93
- File file = new File (url .getFile ());
94
- if ( file .exists () || key .equals (KEY_PATH_CORDOVA_JAR )){
95
- // we skip cordova.jar because it is generated by precompilation
96
- continue ;
97
- }
98
- }
99
- return new Status (IStatus .ERROR , HybridCore .PLUGIN_ID , NLS .bind ("Library for Android platform is not compatible with this tool. File for path {0} is missing." ,key .toString ()));
100
- }
101
- return Status .OK_STATUS ;
102
- }
103
-
104
- public void preCompile (IProgressMonitor monitor ) throws CoreException {
105
- }
106
-
107
- public boolean needsPreCompilation (){
108
- IPath cordovaJar = libraryRoot .append ("framework" ).append (NLS .bind ("cordova-{0}.jar" ,version ));
109
- return !cordovaJar .toFile ().exists ();
110
- }
111
-
112
- private URL getEngineFile (IPath path ){
113
- File file = path .toFile ();
114
- if (!file .exists ()){
115
- AndroidCore .log (IStatus .WARNING , NLS .bind ( "Missing Android engine file {0}" , file .toString ()), null );
116
- }
117
- return FileUtils .toURL (file );
26
+ files .put (PROPERTIES , "android/project.properties" );
27
+ files .put (PlatformConstants .FILE_JS_CORDOVA , "android/assets/www/cordova.js" );
118
28
}
119
29
120
30
121
31
@ Override
122
- public String detectVersion () {
123
- File versionFile = this .libraryRoot .append ("VERSION" ).toFile ();
124
- if (versionFile .exists ()){
125
- BufferedReader reader = null ;
126
- try {
127
- try {
128
- reader = new BufferedReader (new FileReader (versionFile ));
129
- String version = reader .readLine ();
130
- return version ;
131
- }
132
- finally {
133
- if (reader != null ) reader .close ();
134
- }
135
- }catch (IOException e ) {
136
- AndroidCore .log (IStatus .WARNING , "Can not detect version on library" , e );
137
- }
138
- }else {
139
- AndroidCore .log (IStatus .WARNING , NLS .bind ("Can not detect version. VERSION file {0} is missing" ,versionFile .toString ()), null );
32
+ public String getTemplateFile (String key ) {
33
+ if (files .isEmpty ()){
34
+ initFiles ();
140
35
}
141
- return null ;
36
+ Assert .isNotNull (key );
37
+ return files .get (key );
142
38
}
143
39
144
- }
40
+ }
0 commit comments