add azure-toolkit-common-lib 0.0.1-SNAPSHOT (#1204)

* add azure-toolkit-common-lib 0.0.1-SNAPSHOT

Co-authored-by: Andy Xu(devdiv) <andxu@microsoft>
This commit is contained in:
Andy Xu(devdiv) 2020-12-31 16:17:15 +08:00 коммит произвёл GitHub
Родитель 56c3c0fd35
Коммит 3c56e1d1f1
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
7 изменённых файлов: 319 добавлений и 6 удалений

Просмотреть файл

@ -0,0 +1,71 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>azure-toolkit-libs</artifactId>
<groupId>com.microsoft.azure</groupId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>azure-toolkit-auth-lib</artifactId>
<dependencies>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>
<dependency>
<groupId>org.fusesource.jansi</groupId>
<artifactId>jansi</artifactId>
</dependency>
<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>jsr305</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-client-runtime</artifactId>
</dependency>
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-identity</artifactId>
</dependency>
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-toolkit-common-lib</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>

Просмотреть файл

@ -0,0 +1,55 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>azure-toolkit-libs</artifactId>
<groupId>com.microsoft.azure</groupId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>azure-toolkit-common-lib</artifactId>
<dependencies>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>
<dependency>
<groupId>org.fusesource.jansi</groupId>
<artifactId>jansi</artifactId>
</dependency>
<!-- javax annotations e.g. @Nonnull -->
<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>jsr305</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>

Просмотреть файл

@ -0,0 +1,9 @@
package com.microsoft.azure.tools.common.exception;
public class CommandExecuteException extends RuntimeException {
private static final long serialVersionUID = 4582230448665092548L;
public CommandExecuteException(String message) {
super(message);
}
}

Просмотреть файл

@ -0,0 +1,31 @@
/**
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for
* license information.
*/
package com.microsoft.azure.tools.common.util;
import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import org.apache.commons.io.IOUtils;
import com.microsoft.azure.tools.common.exception.CommandExecuteException;
public class CommandUtil {
private static final boolean isWindows = System.getProperty("os.name").contains("Windows");
public static String executeCommandAndGetOutput(final String cmd, File cwd)
throws IOException, InterruptedException {
final String[] cmds = new String[]{isWindows ? "cmd.exe" : "bash", "/c", cmd};
final Process p = Runtime.getRuntime().exec(cmds, null, cwd);
final int exitCode = p.waitFor();
if (exitCode != 0) {
String errorLog = IOUtils.toString(p.getErrorStream(), StandardCharsets.UTF_8);
throw new CommandExecuteException(String.format("Cannot execute '%s' due to error: %s", cmd, errorLog));
}
return IOUtils.toString(p.getInputStream(), StandardCharsets.UTF_8);
}
}

Просмотреть файл

@ -0,0 +1,30 @@
/**
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for
* license information.
*/
package com.microsoft.azure.tools.common.util;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonSyntaxException;
public class JsonUtils {
private static final Gson GSON = new GsonBuilder().setPrettyPrinting().disableHtmlEscaping().create();
public static <T> T fromJson(String json, Class<T> classOfT) throws JsonSyntaxException {
return GSON.fromJson(json, classOfT);
}
public static String toJson(Object src) {
return GSON.toJson(src);
}
public static Gson getGson() {
return GSON;
}
private JsonUtils() {
}
}

Просмотреть файл

@ -0,0 +1,47 @@
/**
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for
* license information.
*/
package com.microsoft.azure.tools.common.util;
import com.google.common.base.Preconditions;
import org.apache.commons.lang3.StringUtils;
import org.fusesource.jansi.Ansi;
import org.fusesource.jansi.Ansi.Color;
public class TextUtils {
public static String applyColorToText(String text, Color colorCode) {
if (StringUtils.isBlank(text)) {
return text;
}
return Ansi.ansi().fg(colorCode).a(text).reset().toString();
}
public static String yellow(String message) {
return applyColorToText(message, Color.YELLOW);
}
public static String green(String message) {
return applyColorToText(message, Color.GREEN);
}
public static String blue(String message) {
return applyColorToText(message, Color.BLUE);
}
public static String red(String message) {
return applyColorToText(message, Color.RED);
}
public static String[] splitLines(String text) {
Preconditions.checkNotNull(text, "The parameter 'text' cannot be null");
return text.split("\\r?\\n");
}
private TextUtils() {
}
}

Просмотреть файл

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-toolkit-libs</artifactId>
@ -11,6 +11,8 @@
<description>Wrapped libs for Microsoft Azure Toolkits</description>
<modules>
<module>azure-toolkit-common-lib</module>
<module>azure-toolkit-auth-lib</module>
<module>azure-toolkit-springcloud-lib</module>
</modules>
@ -30,12 +32,10 @@
<azure.ai.version>2.6.1</azure.ai.version>
<azure.applicationinsights-web.version>[2.0,)</azure.applicationinsights-web.version>
<azure.appplatform-sdk.version>1.0.0-beta</azure.appplatform-sdk.version>
<azure.client.version>1.7.8</azure.client.version>
<azure.auth-helper.version>0.7.0-SNAPSHOT</azure.auth-helper.version>
<azure.client.version>1.7.9</azure.client.version>
<azure.eventhubs.version>1.2.0</azure.eventhubs.version>
<azure.eventhubs-eph.version>2.0.1</azure.eventhubs-eph.version>
<azure.function.version>1.4.0</azure.function.version>
<azure.maven-plugin-lib.version>1.5.0-SNAPSHOT</azure.maven-plugin-lib.version>
<azure.mgmt-insights.version>1.0.0-beta</azure.mgmt-insights.version>
<azure.storage-blob.version>11.0.1</azure.storage-blob.version>
<azure.tools-common.version>0.10.0</azure.tools-common.version>
@ -74,6 +74,7 @@
<spring-test.version>4.1.6.RELEASE</spring-test.version>
<zt.zip.version>1.14</zt.zip.version>
<gson.version>2.8.6</gson.version>
<maven.clean-plugin.version>3.1.0</maven.clean-plugin.version>
<maven.resources-plugin.version>3.0.2</maven.resources-plugin.version>
<maven.source-plugin.version>2.2.1</maven.source-plugin.version>
@ -89,6 +90,10 @@
<google.jsr305.version>3.0.0</google.jsr305.version>
<azure.azure-mgmt-appplatform.version>1.0.0-beta</azure.azure-mgmt-appplatform.version>
<azure.toolkit.common.lib.version>0.0.1-SNAPSHOT</azure.toolkit.common.lib.version>
<azure-identity.version>1.2.1</azure-identity.version>
<azure.version>1.36.3</azure.version>
<lombok.version>1.18.8</lombok.version>
</properties>
<dependencyManagement>
@ -98,7 +103,7 @@
<artifactId>azure-tools-common</artifactId>
<version>${azure.tools-common.version}</version>
</dependency>
<!-- azure lib for spring cloud-->
<!-- azure lib for spring cloud -->
<dependency>
<groupId>com.microsoft.azure.appplatform.v2020_07_01</groupId>
<artifactId>azure-mgmt-appplatform</artifactId>
@ -129,6 +134,33 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>${guava.version}</version>
<exclusions>
<exclusion>
<groupId>com.google.errorprone</groupId>
<artifactId>error_prone_annotations</artifactId>
</exclusion>
<exclusion>
<groupId>com.google.code.findbugs</groupId>
<artifactId>jsr305</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>${gson.version}</version>
</dependency>
<dependency>
<groupId>org.fusesource.jansi</groupId>
<artifactId>jansi</artifactId>
<version>${jansi.version}</version>
</dependency>
<!-- javax annotations e.g. @Nonnull -->
<dependency>
@ -142,6 +174,44 @@
<artifactId>commons-lang3</artifactId>
<version>${commons.lang3.version}</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>${commons.io.version}</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
<scope>provided</scope>
</dependency>
<!-- azure sdk -->
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-client-runtime</artifactId>
<version>{azure.client.version}</version>
</dependency>
<dependency>
<groupId>com.azure.resourcemanager</groupId>
<artifactId>azure-resourcemanager</artifactId>
<version>${azure.version}</version>
</dependency>
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-identity</artifactId>
<version>${azure-identity.version}</version>
</dependency>
<!-- azure toolkit libs -->
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-toolkit-common-lib</artifactId>
<version>${azure.toolkit.common.lib.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
<build>