Skip to content

Commit

Permalink
Cut dependence between android_builder_lib and android.databinding
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 683261577
Change-Id: I2e307125362e190025dd1c87db84f1fc0b2ad653
  • Loading branch information
ted-xie authored and copybara-github committed Oct 7, 2024
1 parent 07115c7 commit bbd13bb
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright 2024 The Bazel Authors. All rights reserved.
//
// 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
//
// http://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 com.google.devtools.build.android;

import android.databinding.AndroidDataBinding;
import android.databinding.cli.ProcessXmlOptions;

/**
* Wrapper around the AndroidDataBinding.main() method.
*
* <p>Used solely to decouple android_builder_lib from directly depending on android.databinding.*.
*/
final class AndroidDataBindingWrapper {

private AndroidDataBindingWrapper() {}

public static void main(String[] args) {
AndroidDataBinding.main(args);
}

public static void doRun(ProcessXmlOptionsWrapper options) {
AndroidDataBinding.doRun((ProcessXmlOptions) options);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
// limitations under the License.
package com.google.devtools.build.android;

import android.databinding.AndroidDataBinding;
import android.databinding.cli.ProcessXmlOptions;
import com.android.annotations.NonNull;
import com.android.annotations.Nullable;
import com.android.builder.core.DefaultManifestParser;
Expand Down Expand Up @@ -47,6 +45,7 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Executors;
Expand Down Expand Up @@ -202,7 +201,7 @@ private void runAapt(
@Nullable Path publicResourcesOut)
throws IOException {
try (JunctionCreator junctions =
System.getProperty("os.name").toLowerCase().startsWith("windows")
System.getProperty("os.name").toLowerCase(Locale.ROOT).startsWith("windows")
? new WindowsJunctionCreator(Files.createDirectories(tempRoot.resolve("juncts")))
: new NoopJunctionCreator()) {
sourceOut = junctions.create(sourceOut);
Expand Down Expand Up @@ -304,7 +303,7 @@ static Path processDataBindings(
? inputResourcesDir.getRoot().relativize(inputResourcesDir)
: inputResourcesDir));

ProcessXmlOptions options = new ProcessXmlOptions();
ProcessXmlOptionsWrapper options = new ProcessXmlOptionsWrapper();
options.setAppId(packagePath);
options.setResInput(inputResourcesDir.toFile());
options.setResOutput(processedResourceDir.toFile());
Expand All @@ -314,7 +313,7 @@ static Path processDataBindings(
options.setZipLayoutInfo(shouldZipDataBindingInfo);

try {
AndroidDataBinding.doRun(options);
AndroidDataBindingWrapper.doRun(options);
} catch (Throwable t) {
throw new RuntimeException(t);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

package com.google.devtools.build.android;

import android.databinding.AndroidDataBinding;
import com.beust.jcommander.JCommander;
import com.beust.jcommander.Parameter;
import com.beust.jcommander.Parameters;
Expand Down Expand Up @@ -115,7 +114,7 @@ public static void main(String[] args) throws Exception {
classInfo -> dbArgsBuilder.add("-dependencyClassInfoList").add(classInfo.toString()));

try {
AndroidDataBinding.main(
AndroidDataBindingWrapper.main(
Streams.mapWithIndex(
dbArgsBuilder.build().stream(), (arg, index) -> index == 0 ? arg : arg + " ")
.toArray(String[]::new));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright 2024 The Bazel Authors. All rights reserved.
//
// 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
//
// http://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 com.google.devtools.build.android;

import android.databinding.cli.ProcessXmlOptions;

/**
* Essentially empty wrapper around the ProcessXmlOptions class.
*
* <p>Used solely to decouple android_builder_lib from directly depending on android.databinding.*.
*/
public class ProcessXmlOptionsWrapper extends ProcessXmlOptions {}

0 comments on commit bbd13bb

Please sign in to comment.