Search in sources :

Example 1 with StdLogger

use of com.android.utils.StdLogger in project bazel by bazelbuild.

the class AarGeneratorAction method main.

public static void main(String[] args) {
    Stopwatch timer = Stopwatch.createStarted();
    OptionsParser optionsParser = OptionsParser.newOptionsParser(Options.class);
    optionsParser.parseAndExitUponError(args);
    Options options = optionsParser.getOptions(Options.class);
    checkFlags(options);
    AndroidResourceProcessor resourceProcessor = new AndroidResourceProcessor(new StdLogger(com.android.utils.StdLogger.Level.VERBOSE));
    try (ScopedTemporaryDirectory scopedTmp = new ScopedTemporaryDirectory("aar_gen_tmp")) {
        Path tmp = scopedTmp.getPath();
        Path resourcesOut = tmp.resolve("merged_resources");
        Files.createDirectories(resourcesOut);
        Path assetsOut = tmp.resolve("merged_assets");
        Files.createDirectories(assetsOut);
        logger.fine(String.format("Setup finished at %dms", timer.elapsed(TimeUnit.MILLISECONDS)));
        // There aren't any dependencies, but we merge to combine primary resources from different
        // res/assets directories into a single res and single assets directory.
        MergedAndroidData mergedData = AndroidResourceMerger.mergeData(options.mainData, ImmutableList.<DependencyAndroidData>of(), ImmutableList.<DependencyAndroidData>of(), resourcesOut, assetsOut, null, VariantType.LIBRARY, null);
        logger.fine(String.format("Merging finished at %dms", timer.elapsed(TimeUnit.MILLISECONDS)));
        writeAar(options.aarOutput, mergedData, options.manifest, options.rtxt, options.classes);
        logger.fine(String.format("Packaging finished at %dms", timer.elapsed(TimeUnit.MILLISECONDS)));
    } catch (IOException | MergingException e) {
        logger.log(Level.SEVERE, "Error during merging resources", e);
        System.exit(1);
    }
    System.exit(0);
}
Also used : Path(java.nio.file.Path) MergingException(com.android.ide.common.res2.MergingException) StdLogger(com.android.utils.StdLogger) Stopwatch(com.google.common.base.Stopwatch) IOException(java.io.IOException) OptionsParser(com.google.devtools.common.options.OptionsParser)

Example 2 with StdLogger

use of com.android.utils.StdLogger in project android by JetBrains.

the class KeystoreUtils method getOrCreateDefaultDebugKeystore.

public static File getOrCreateDefaultDebugKeystore() throws Exception {
    try {
        File debugLocation = new File(KeystoreHelper.defaultDebugKeystoreLocation());
        if (!debugLocation.exists()) {
            File keystoreDirectory = new File(AndroidLocation.getFolder());
            if (!keystoreDirectory.canWrite()) {
                throw new AndroidLocationException("Could not create debug keystore because \"" + keystoreDirectory + "\" is not writable");
            }
            ILogger logger = new StdLogger(StdLogger.Level.ERROR);
            // Default values taken from http://developer.android.com/tools/publishing/app-signing.html
            // Keystore name: "debug.keystore"
            // Keystore password: "android"
            // Keystore alias: "androiddebugkey"
            // Key password: "android"
            KeystoreHelper.createDebugStore(null, debugLocation, "android", "android", "AndroidDebugKey", logger);
        }
        if (!debugLocation.exists()) {
            throw new AndroidLocationException("Could not create debug keystore");
        }
        return debugLocation;
    } catch (AndroidLocationException exception) {
        throw new Exception("Failed to get debug keystore path", exception);
    }
}
Also used : StdLogger(com.android.utils.StdLogger) ILogger(com.android.utils.ILogger) AndroidLocationException(com.android.prefs.AndroidLocation.AndroidLocationException) GradleBuildFile(com.android.tools.idea.gradle.parser.GradleBuildFile) File(java.io.File) GradleSettingsFile(com.android.tools.idea.gradle.parser.GradleSettingsFile) KeyStoreException(java.security.KeyStoreException) AndroidLocationException(com.android.prefs.AndroidLocation.AndroidLocationException) IOException(java.io.IOException) CertificateException(java.security.cert.CertificateException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException)

Example 3 with StdLogger

use of com.android.utils.StdLogger in project bazel by bazelbuild.

the class RClassGeneratorTest method setUp.

@Before
public void setUp() throws Exception {
    temp = Files.createTempDirectory(toString());
    stdLogger = new StdLogger(StdLogger.Level.VERBOSE);
}
Also used : StdLogger(com.android.utils.StdLogger) Before(org.junit.Before)

Example 4 with StdLogger

use of com.android.utils.StdLogger in project android by JetBrains.

the class RecipeMergeUtils method mergeManifest.

/**
   * Merges the given manifest fragment into the given manifest file
   */
@Nullable
private static String mergeManifest(@NotNull File moduleRoot, @NotNull final File targetManifest, @NotNull final String targetXml, @NotNull final String mergeText) {
    try {
        boolean isMasterManifest = FileUtil.filesEqual(moduleRoot, targetManifest.getParentFile());
        //noinspection SpellCheckingInspection
        final File tempFile2 = new File(targetManifest.getParentFile(), "nevercreated.xml");
        StdLogger logger = new StdLogger(StdLogger.Level.INFO);
        MergingReport mergeReport = ManifestMerger2.newMerger(targetManifest, logger, ManifestMerger2.MergeType.APPLICATION).withFeatures(ManifestMerger2.Invoker.Feature.EXTRACT_FQCNS, ManifestMerger2.Invoker.Feature.NO_PLACEHOLDER_REPLACEMENT).addLibraryManifest(tempFile2).asType(isMasterManifest ? XmlDocument.Type.MAIN : XmlDocument.Type.OVERLAY).withFileStreamProvider(new ManifestMerger2.FileStreamProvider() {

            @Override
            protected InputStream getInputStream(@NotNull File file) throws FileNotFoundException {
                String text = FileUtil.filesEqual(file, targetManifest) ? targetXml : mergeText;
                return new ByteArrayInputStream(text.getBytes(Charsets.UTF_8));
            }
        }).merge();
        if (mergeReport.getResult().isSuccess()) {
            return mergeReport.getMergedDocument(MergingReport.MergedManifestKind.MERGED);
        }
        return null;
    } catch (ManifestMerger2.MergeFailureException e) {
        LOG.warn(e);
        return null;
    }
}
Also used : StdLogger(com.android.utils.StdLogger) NotNull(org.jetbrains.annotations.NotNull) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

StdLogger (com.android.utils.StdLogger)4 IOException (java.io.IOException)2 MergingException (com.android.ide.common.res2.MergingException)1 AndroidLocationException (com.android.prefs.AndroidLocation.AndroidLocationException)1 GradleBuildFile (com.android.tools.idea.gradle.parser.GradleBuildFile)1 GradleSettingsFile (com.android.tools.idea.gradle.parser.GradleSettingsFile)1 ILogger (com.android.utils.ILogger)1 Stopwatch (com.google.common.base.Stopwatch)1 OptionsParser (com.google.devtools.common.options.OptionsParser)1 File (java.io.File)1 Path (java.nio.file.Path)1 KeyStoreException (java.security.KeyStoreException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 CertificateException (java.security.cert.CertificateException)1 NotNull (org.jetbrains.annotations.NotNull)1 Nullable (org.jetbrains.annotations.Nullable)1 Before (org.junit.Before)1