Skip to content

Commit

Permalink
refactor: manual YAML Cleanup (iBotPeaches#3229)
Browse files Browse the repository at this point in the history
* refactor: add missing license headers

* fix: remove unused exceptions

* refactor: remove unused single quote / slash param
  • Loading branch information
iBotPeaches authored Jul 29, 2023
1 parent 6e5d49b commit fe93fd2
Show file tree
Hide file tree
Showing 11 changed files with 122 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -146,15 +146,13 @@ public void save(File file) throws AndrolibException {
}

public static ApkInfo load(InputStream is) throws AndrolibException {
// return getYaml().loadAs(is, ApkInfo.class);
YamlReader reader = new YamlReader(is);
ApkInfo apkInfo = new ApkInfo();
reader.readRoot(apkInfo);
return apkInfo;
}

public static ApkInfo load(File appDir)
throws AndrolibException {
public static ApkInfo load(File appDir) throws AndrolibException {
try(
InputStream in = new FileDirectory(appDir).getFileInput("apktool.yml");
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,12 @@
*/
package brut.androlib.apk;

import brut.androlib.exceptions.AndrolibException;

public class PackageInfo implements YamlSerializable {
public String forcedPackageId;
public String renameManifestPackage;

@Override
public void readItem(YamlReader reader) throws AndrolibException {
public void readItem(YamlReader reader) {
YamlLine line = reader.getLine();
switch (line.getKey()) {
case "forcedPackageId": {
Expand All @@ -42,5 +40,4 @@ public void write(YamlWriter writer) {
writer.writeString("forcedPackageId", forcedPackageId);
writer.writeString("renameManifestPackage", renameManifestPackage);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,12 @@
*/
package brut.androlib.apk;

import brut.androlib.exceptions.AndrolibException;

public class VersionInfo implements YamlSerializable {
public String versionCode;
public String versionName;

@Override
public void readItem(YamlReader reader) throws AndrolibException {
public void readItem(YamlReader reader) {
YamlLine line = reader.getLine();
switch (line.getKey()) {
case "versionCode": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* Copyright (C) 2010 Ryszard Wiśniewski <[email protected]>
* Copyright (C) 2010 Connor Tumbleson <[email protected]>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package brut.androlib.apk;

import java.util.Objects;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* Copyright (C) 2010 Ryszard Wiśniewski <[email protected]>
* Copyright (C) 2010 Connor Tumbleson <[email protected]>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package brut.androlib.apk;

import brut.androlib.exceptions.AndrolibException;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* Copyright (C) 2010 Ryszard Wiśniewski <[email protected]>
* Copyright (C) 2010 Connor Tumbleson <[email protected]>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package brut.androlib.apk;

import brut.androlib.exceptions.AndrolibException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,20 @@
public class YamlStringEscapeUtils {

public static String escapeString(String str) {
return escapeJavaStyleString(str, false, false);
return escapeJavaStyleString(str);
}

/**
* @param str String to escape values in, may be null
* @param escapeSingleQuotes escapes single quotes if <code>true</code>
* @param escapeForwardSlash TODO
* @return the escaped string
*/
private static String escapeJavaStyleString(String str, boolean escapeSingleQuotes, boolean escapeForwardSlash) {
private static String escapeJavaStyleString(String str) {
if (str == null) {
return null;
}
try {
StringWriter writer = new StringWriter(str.length() * 2);
escapeJavaStyleString(writer, str, escapeSingleQuotes, escapeForwardSlash);
escapeJavaStyleString(writer, str);
return writer.toString();
} catch (IOException ioe) {
// this should never ever happen while writing to a StringWriter
Expand All @@ -50,14 +48,11 @@ private static String escapeJavaStyleString(String str, boolean escapeSingleQuot
}

/**
* @param out write to receieve the escaped string
* @param out write to receive the escaped string
* @param str String to escape values in, may be null
* @param escapeSingleQuote escapes single quotes if <code>true</code>
* @param escapeForwardSlash TODO
* @throws IOException if an IOException occurs
*/
private static void escapeJavaStyleString(Writer out, String str, boolean escapeSingleQuote,
boolean escapeForwardSlash) throws IOException {
private static void escapeJavaStyleString(Writer out, String str) throws IOException {
if (out == null) {
throw new IllegalArgumentException("The Writer must not be null");
}
Expand Down Expand Up @@ -101,7 +96,7 @@ private static void escapeJavaStyleString(Writer out, String str, boolean escape
} else {
switch (ch) {
case '\'' :
if (escapeSingleQuote) {
if (false) {
out.write('\\');
}
out.write('\'');
Expand All @@ -115,7 +110,7 @@ private static void escapeJavaStyleString(Writer out, String str, boolean escape
out.write('\\');
break;
case '/' :
if (escapeForwardSlash) {
if (false) {
out.write('\\');
}
out.write('/');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* Copyright (C) 2010 Ryszard Wiśniewski <[email protected]>
* Copyright (C) 2010 Connor Tumbleson <[email protected]>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package brut.androlib.apk;

import java.io.*;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* Copyright (C) 2010 Ryszard Wiśniewski <[email protected]>
* Copyright (C) 2010 Connor Tumbleson <[email protected]>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package brut.androlib.apk;

import brut.androlib.exceptions.AndrolibException;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* Copyright (C) 2010 Ryszard Wiśniewski <[email protected]>
* Copyright (C) 2010 Connor Tumbleson <[email protected]>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package brut.androlib.apk;

import brut.androlib.exceptions.AndrolibException;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* Copyright (C) 2010 Ryszard Wiśniewski <[email protected]>
* Copyright (C) 2010 Connor Tumbleson <[email protected]>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package brut.androlib.apk;

import org.junit.Test;
Expand Down

0 comments on commit fe93fd2

Please sign in to comment.