Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
appinventor-sources
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
xpstem
appinventor-sources
Commits
bec5507f
Commit
bec5507f
authored
Mar 22, 2019
by
Evan W. Patton
Committed by
Susan Rati Lane
Mar 22, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make FormPropertiesAnalyzer handle Windows line endings (#1556)
Change-Id: Id58ad71b23a4132db983e8a2c9d8dce6919c4433
parent
5fe7669e
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
64 additions
and
2 deletions
+64
-2
appinventor/appengine/src/com/google/appinventor/shared/youngandroid/YoungAndroidSourceAnalyzer.java
...entor/shared/youngandroid/YoungAndroidSourceAnalyzer.java
+2
-1
appinventor/buildserver/src/com/google/appinventor/buildserver/FormPropertiesAnalyzer.java
...oogle/appinventor/buildserver/FormPropertiesAnalyzer.java
+2
-1
appinventor/buildserver/tests/com/google/appinventor/buildserver/FormPropertiesAnalyzerTest.java
...e/appinventor/buildserver/FormPropertiesAnalyzerTest.java
+60
-0
No files found.
appinventor/appengine/src/com/google/appinventor/shared/youngandroid/YoungAndroidSourceAnalyzer.java
View file @
bec5507f
// -*- mode: java; c-basic-offset: 2; -*-
// -*- mode: java; c-basic-offset: 2; -*-
// Copyright 2009-2011 Google, All Rights reserved
// Copyright 2009-2011 Google, All Rights reserved
// Copyright 2011-201
2
MIT, All rights reserved
// Copyright 2011-201
9
MIT, All rights reserved
// Released under the Apache License, Version 2.0
// Released under the Apache License, Version 2.0
// http://www.apache.org/licenses/LICENSE-2.0
// http://www.apache.org/licenses/LICENSE-2.0
...
@@ -57,6 +57,7 @@ public class YoungAndroidSourceAnalyzer {
...
@@ -57,6 +57,7 @@ public class YoungAndroidSourceAnalyzer {
* @return the properties as a JSONObject
* @return the properties as a JSONObject
*/
*/
public
static
JSONObject
parseSourceFile
(
String
source
,
JSONParser
jsonParser
)
{
public
static
JSONObject
parseSourceFile
(
String
source
,
JSONParser
jsonParser
)
{
source
=
source
.
replaceAll
(
"\r\n"
,
"\n"
);
// First, locate the beginning of the $JSON section.
// First, locate the beginning of the $JSON section.
// Older files have a $Properties before the $JSON section and we need to make sure we skip
// Older files have a $Properties before the $JSON section and we need to make sure we skip
// that.
// that.
...
...
appinventor/buildserver/src/com/google/appinventor/buildserver/FormPropertiesAnalyzer.java
View file @
bec5507f
...
@@ -53,6 +53,7 @@ public class FormPropertiesAnalyzer {
...
@@ -53,6 +53,7 @@ public class FormPropertiesAnalyzer {
* @return the properties as a JSONObject
* @return the properties as a JSONObject
*/
*/
public
static
JSONObject
parseSourceFile
(
String
source
)
{
public
static
JSONObject
parseSourceFile
(
String
source
)
{
source
=
source
.
replaceAll
(
"\r\n"
,
"\n"
);
// First, locate the beginning of the $JSON section.
// First, locate the beginning of the $JSON section.
// Older files have a $Properties before the $JSON section and we need to make sure we skip
// Older files have a $Properties before the $JSON section and we need to make sure we skip
// that.
// that.
...
@@ -64,7 +65,7 @@ public class FormPropertiesAnalyzer {
...
@@ -64,7 +65,7 @@ public class FormPropertiesAnalyzer {
}
}
beginningOfJsonSection
+=
jsonSectionPrefix
.
length
();
beginningOfJsonSection
+=
jsonSectionPrefix
.
length
();
// Then, locate the end of the $JSON section
;
// Then, locate the end of the $JSON section
String
jsonSectionSuffix
=
FORM_PROPERTIES_SUFFIX
;
String
jsonSectionSuffix
=
FORM_PROPERTIES_SUFFIX
;
int
endOfJsonSection
=
source
.
lastIndexOf
(
jsonSectionSuffix
);
int
endOfJsonSection
=
source
.
lastIndexOf
(
jsonSectionSuffix
);
if
(
endOfJsonSection
==
-
1
)
{
if
(
endOfJsonSection
==
-
1
)
{
...
...
appinventor/buildserver/tests/com/google/appinventor/buildserver/FormPropertiesAnalyzerTest.java
0 → 100644
View file @
bec5507f
// -*- mode: java; c-basic-offset: 2; -*-
// Copyright © 2019 Massachusetts Institute of Technology, All rights reserved.
// Released under the Apache License, Version 2.0
// http://www.apache.org/licenses/LICENSE-2.0
package
com.google.appinventor.buildserver
;
import
org.codehaus.jettison.json.JSONObject
;
import
org.junit.Test
;
import
java.util.Set
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertNotNull
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
public
class
FormPropertiesAnalyzerTest
{
private
static
final
String
TEST_DATA
=
"#|\n$JSON\n{\"Properties\":{\"$Type\":\"Form\",\"$Components\":[]}}\n|#\n"
;
@Test
public
void
testParseSourceFileValid
()
{
JSONObject
data
=
FormPropertiesAnalyzer
.
parseSourceFile
(
TEST_DATA
);
assertNotNull
(
data
.
optJSONObject
(
"Properties"
));
}
@Test
(
expected
=
IllegalArgumentException
.
class
)
public
void
testParseSourceFileMissingHeader
()
{
FormPropertiesAnalyzer
.
parseSourceFile
(
"\n|#\n"
);
}
@Test
(
expected
=
IllegalArgumentException
.
class
)
public
void
testParseSourceFileMissingFooter
()
{
FormPropertiesAnalyzer
.
parseSourceFile
(
"#|\n$JSON\n"
);
}
@Test
(
expected
=
IllegalArgumentException
.
class
)
public
void
testParseSourceFileInvalidJSON
()
{
FormPropertiesAnalyzer
.
parseSourceFile
(
"#|\n$JSON\n{]\n|#\n"
);
}
@Test
public
void
testParseSourceFileWindowsLineEndings
()
{
JSONObject
data
=
FormPropertiesAnalyzer
.
parseSourceFile
(
TEST_DATA
.
replaceAll
(
"\n"
,
"\r\n"
));
assertNotNull
(
data
.
optJSONObject
(
"Properties"
));
}
@Test
public
void
testGetComponentTypesFromFormFile
()
{
Set
<
String
>
result
=
FormPropertiesAnalyzer
.
getComponentTypesFromFormFile
(
TEST_DATA
);
assertEquals
(
1
,
result
.
size
());
assertTrue
(
result
.
contains
(
"Form"
));
}
@Test
(
expected
=
IllegalArgumentException
.
class
)
public
void
testGetComponentTypesFromFormFileThrows
()
{
FormPropertiesAnalyzer
.
getComponentTypesFromFormFile
(
"#|\n$JSON\n{}\n|$\n"
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment