trino-435版本windows下源码编译

2023-12-23 06:51:41

一、源码下载地址

https://github.com/trinodb/trino/tags

二、编译环境及工具准备

1、maven

(1)版本:3.6.3
(2)settings.xml配置

<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.2.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.2.0 http://maven.apache.org/xsd/settings-1.2.0.xsd">
  <localRepository>D:\maven\repo2</localRepository>  
  <mirrors>
	<mirror>
        <id>alimaven</id>
        <mirrorOf>central</mirrorOf>
        <name>aliyun maven</name>
        <url>https://maven.aliyun.com/repository/central/</url>
  </mirror>
   <mirror>
      <id>alimaven</id>
      <name>aliyun maven</name>
      <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
      <mirrorOf>central</mirrorOf>        
    </mirror>
  </mirrors>
 <profiles>
	<profile>
		<!-- maven使用jdk1.8 --> 
		<id>jdk-1.8</id>
			  <!-- 开启jdk --> 
		<activation>
			<activeByDefault>true</activeByDefault>
			<jdk>1.8</jdk>
		</activation>
			
		<properties>
			  <!-- 配置编译器信息 -->
			<maven.compiler.source>1.8</maven.compiler.source>
			<maven.compiler.target>1.8</maven.compiler.target>
			<maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>
		</properties>
	</profile>
  </profiles>
</settings>
2、jdk

版本:17.0.9

3、idea

版本:2023.2

三、源码编译配置

(1)取消插件:really-executable-jar-maven-plugin
在这里插入图片描述
(2)trino-root xml取消如下两个module
在这里插入图片描述
(3)trino-root xml取消scm
在这里插入图片描述
(4)trino-root xml取消如下配置

<!--                <plugin>-->
<!--                    <groupId>org.skife.maven</groupId>-->
<!--                    <artifactId>really-executable-jar-maven-plugin</artifactId>-->
<!--                    <version>2.1.1</version>-->
<!--                </plugin>-->
<!--                <plugin>-->
<!--                    <groupId>org.gaul</groupId>-->
<!--                    <artifactId>modernizer-maven-plugin</artifactId>-->
<!--                    <configuration>-->
<!--                        <violationsFiles>-->
<!--                            <violationsFile>${air.main.basedir}/.mvn/modernizer/violations.xml</violationsFile>-->
<!--                        </violationsFiles>-->
<!--                        <exclusionPatterns>-->
<!--                            <exclusionPattern>org/joda/time/.*</exclusionPattern>-->
<!--                        </exclusionPatterns>-->
<!--                        <exclusions>-->
<!--                            &lt;!&ndash; getOnlyElement is more readable than the stream analogue &ndash;&gt;-->
<!--                            <exclusion>com/google/common/collect/Iterables.getOnlyElement:(Ljava/lang/Iterable;)Ljava/lang/Object;</exclusion>-->
<!--                            &lt;!&ndash; getLast has lower complexity for array based lists than the stream analogue (O(1) vs O(log(N)) &ndash;&gt;-->
<!--                            <exclusion>com/google/common/collect/Iterables.getLast:(Ljava/lang/Iterable;)Ljava/lang/Object;</exclusion>-->
<!--                            <exclusion>com/google/common/collect/Iterables.getLast:(Ljava/lang/Iterable;Ljava/lang/Object;)Ljava/lang/Object;</exclusion>-->
<!--                            &lt;!&ndash; TODO: requires getting to common understanding which of those we want to enable &ndash;&gt;-->
<!--                            <exclusion>com/google/common/collect/Iterables.transform:(Ljava/lang/Iterable;Lcom/google/common/base/Function;)Ljava/lang/Iterable;</exclusion>-->
<!--                            <exclusion>com/google/common/collect/Lists.transform:(Ljava/util/List;Lcom/google/common/base/Function;)Ljava/util/List;</exclusion>-->
<!--                            <exclusion>com/google/common/collect/Iterables.isEmpty:(Ljava/lang/Iterable;)Z</exclusion>-->
<!--                            <exclusion>com/google/common/collect/Iterables.concat:(Ljava/lang/Iterable;Ljava/lang/Iterable;)Ljava/lang/Iterable;</exclusion>-->
<!--                            <exclusion>com/google/common/collect/Iterables.concat:(Ljava/lang/Iterable;Ljava/lang/Iterable;Ljava/lang/Iterable;)Ljava/lang/Iterable;</exclusion>-->
<!--                            <exclusion>com/google/common/collect/Iterables.concat:(Ljava/lang/Iterable;Ljava/lang/Iterable;Ljava/lang/Iterable;Ljava/lang/Iterable;)Ljava/lang/Iterable;</exclusion>-->
<!--                            <exclusion>com/google/common/collect/Iterables.concat:(Ljava/lang/Iterable;)Ljava/lang/Iterable;</exclusion>-->
<!--                            <exclusion>com/google/common/collect/Iterables.all:(Ljava/lang/Iterable;Lcom/google/common/base/Predicate;)Z</exclusion>-->
<!--                            <exclusion>com/google/common/collect/Iterables.any:(Ljava/lang/Iterable;Lcom/google/common/base/Predicate;)Z</exclusion>-->
<!--                            <exclusion>com/google/common/collect/Iterables.skip:(Ljava/lang/Iterable;I)Ljava/lang/Iterable;</exclusion>-->
<!--                            <exclusion>com/google/common/collect/Iterables.limit:(Ljava/lang/Iterable;I)Ljava/lang/Iterable;</exclusion>-->
<!--                            <exclusion>com/google/common/collect/Iterables.get:(Ljava/lang/Iterable;I)Ljava/lang/Object;</exclusion>-->
<!--                            <exclusion>com/google/common/collect/Iterables.getFirst:(Ljava/lang/Iterable;Ljava/lang/Object;)Ljava/lang/Object;</exclusion>-->
<!--                            <exclusion>com/google/common/collect/Iterables.getLast:(Ljava/lang/Iterable;)Ljava/lang/Object;</exclusion>-->
<!--                            <exclusion>com/google/common/collect/Iterables.cycle:(Ljava/lang/Iterable;)Ljava/lang/Iterable;</exclusion>-->
<!--                            <exclusion>com/google/common/collect/Iterables.cycle:([Ljava/lang/Object;)Ljava/lang/Iterable;</exclusion>-->
<!--                            <exclusion>com/google/common/collect/Iterables.getOnlyElement:(Ljava/lang/Iterable;Ljava/lang/Object;)Ljava/lang/Object;</exclusion>-->
<!--                            &lt;!&ndash; com.google.common.io.BaseEncoding.base64 provides more reach interfaces than java.util.Base64 &ndash;&gt;-->
<!--                            <exclusion>com/google/common/io/BaseEncoding.base64:()Lcom/google/common/io/BaseEncoding;</exclusion>-->

<!--                            &lt;!&ndash; disable default modernizer violation &ndash;&gt;-->
<!--                            <exclusion>com/google/inject/Provider</exclusion>-->
<!--                        </exclusions>-->
<!--                    </configuration>-->
<!--                </plugin>-->

(4)取消maven-enforcer-plugin配置
在这里插入图片描述
(5)配置maven插件
在这里插入图片描述

四、profiles配置

取消dependency-scope-check、duplicate-finder-check两个配置,防止maven install时因依赖冲突或jar依赖相关问题的出现在这里插入图片描述](https://img-blog.csdnimg.cn/direct/c4754f121fbb4d7a82b682390f7dae3c.png)
在这里插入图片描述
在这里插入图片描述

五、启动类配置

Trino comes with sample configuration that should work out-of-the-box for development. Use the following options to create a run configuration:

Main Class: io.trino.server.DevelopmentServer
VM Options: -ea -Dconfig=etc/config.properties -Dlog.levels-file=etc/log.properties -Djdk.attach.allowAttachSelf=true
Working directory: $MODULE_DIR$
Use classpath of module: trino-server-dev
The working directory should be the trino-server-dev subdirectory. In IntelliJ, using $MODULE_DIR$ accomplishes this automatically.

If VM options doesn’t exist in the dialog, you need to select Modify options and enable Add VM options
在这里插入图片描述

六、代码修改

由于trino源码支持的构建环境为Max OS X or Linux,因此需要适配windows环境,代码修改如下:
(1)修改方法: io.trino.server.TrinoSystemRequirements.verifyOsArchitecture,将failRequirement改为警告形式warnRequirement

 warnRequirement("Trino requires Linux or Mac OS X (found %s)", osName);

(2)修改方法: io.trino.server.TrinoSystemRequirements.verifyFileDescriptor,增加windows环境判断

private static void verifyFileDescriptor()
    {
        String osName = StandardSystemProperty.OS_NAME.value();
        OptionalLong maxFileDescriptorCount = getMaxFileDescriptorCount();
         if ("Windows 10".equals(osName)) {
            maxFileDescriptorCount=OptionalLong.of(100000);
        } 
        if (maxFileDescriptorCount.isEmpty()) {
            // This should never happen since we have verified the OS and JVM above
            failRequirement("Cannot read OS file descriptor limit");
        }
        if (maxFileDescriptorCount.getAsLong() < MIN_FILE_DESCRIPTORS) {
            failRequirement("Trino requires at least %s file descriptors (found %s)", MIN_FILE_DESCRIPTORS, maxFileDescriptorCount.getAsLong());
        }
        if (maxFileDescriptorCount.getAsLong() < RECOMMENDED_FILE_DESCRIPTORS) {
            warnRequirement("Current OS file descriptor limit is %s. Trino recommends at least %s", maxFileDescriptorCount.getAsLong(), RECOMMENDED_FILE_DESCRIPTORS);
        }
    }

(3)io.trino.server.PluginDiscovery#discoverPlugins 适配windows

 File file = artifact.getFile();
        if (!(file.getPath().endsWith("/target/classes")||file.getPath().endsWith("\\target\\classes"))) {
            throw new RuntimeException("Unexpected file for main artifact: " + file);
        }

(4)修改io.trino.server.PluginDiscovery#binaryName,适配windows系统

private static String binaryName(String javaName)
    {
        String property=System.getProperty("os.name");
        if(property.trim().toLowerCase().contains("windows")){
            return javaName.replace('.','\\');
        }
        return javaName.replace('.', '/');
    }

(5)修改io.trino.server.PluginDiscovery#javaName适配windows系统

private static String javaName(String binaryName)
    {
        return binaryName.replace('/', '.').replace("\\",".");
    }
``
`
(6)由于阿里云仓库使用得是https,io.trino.server.HttpsArtifactResolve代码中写死的使用http因此需要重写此代码,使用阿里云仓库,将HttpsArtifactResolve复制一份替换阿里云仓库,并修改resolveArtifacts方法,代码如下:

package io.trino.server;
public class ArtifactResolverX {
public static final String USER_LOCAL_REPO = “D:\maven\repo2”;
public static final String MAVEN_CENTRAL_URI = “https://repo1.maven.org/maven2/”;

    public static final String ALIYUN_MAVEN_CENTRAL_URI = "https://maven.aliyun.com/repository/public";
    public static final Set<String> DEPRECATED_MAVEN_CENTRAL_URIS = ImmutableSet.<String>builder()
            .add("http://repo1.maven.org/maven2")
            .add("http://repo1.maven.org/maven2/")
            .add("http://repo.maven.apache.org/maven2")
            .add("http://repo.maven.apache.org/maven2/")
            .build();

    private final RepositorySystem repositorySystem;
    private final MavenRepositorySystemSession repositorySystemSession;
    private final List<RemoteRepository> repositories;

public ArtifactResolverX(String localRepositoryDir, String...remoteRepositoryUris)
    {
        this(localRepositoryDir, Arrays.asList(remoteRepositoryUris));
    }

public ArtifactResolverX(String localRepositoryDir, List < String > remoteRepositoryUris)
    {
        MavenServiceLocator locator = new MavenServiceLocator();
        locator.addService(RepositoryConnectorFactory.class, FileRepositoryConnectorFactory.class);
        locator.addService(RepositoryConnectorFactory.class, AsyncRepositoryConnectorFactory.class);
        repositorySystem = locator.getService(RepositorySystem.class);

        repositorySystemSession = new MavenRepositorySystemSession();

        LocalRepositoryManager localRepositoryManager = new SimpleLocalRepositoryManager(localRepositoryDir);
        repositorySystemSession.setLocalRepositoryManager(localRepositoryManager);

        repositorySystemSession.setTransferListener(new ConsoleTransferListener());
        repositorySystemSession.setRepositoryListener(new ConsoleRepositoryListener());

        List<RemoteRepository> repositories = new ArrayList<>(remoteRepositoryUris.size());
        int index = 0;
        for (String repositoryUri : remoteRepositoryUris) {
            repositories.add(new RemoteRepository("repo-" + index++, "default", repositoryUri));
        }
        this.repositories = Collections.unmodifiableList(repositories);
    }

    public List<Artifact> resolveArtifacts (Artifact...sourceArtifacts)
    {
        return resolveArtifacts(Arrays.asList(sourceArtifacts));
    }

    public List<Artifact> resolveArtifacts (Iterable < ? extends Artifact > sourceArtifacts)
    {
        CollectRequest collectRequest = new CollectRequest();
        for (Artifact sourceArtifact : sourceArtifacts) {
            collectRequest.addDependency(new Dependency(sourceArtifact, JavaScopes.RUNTIME));
        }
        for (RemoteRepository repository : repositories) {
            // Hack: avoid using deprecated Maven Central URLs
            if (DEPRECATED_MAVEN_CENTRAL_URIS.contains(repository.getUrl())) {
                repository = new RemoteRepository(repository.getId(), repository.getContentType(), MAVEN_CENTRAL_URI);
            }
            collectRequest.addRepository(repository);
        }

        DependencyRequest dependencyRequest = new DependencyRequest(collectRequest, DependencyFilterUtils.classpathFilter(JavaScopes.RUNTIME));

        return resolveArtifacts(dependencyRequest);
    }

    public List<Artifact> resolvePom (File pomFile)
    {
        if (pomFile == null) {
            throw new RuntimeException("pomFile is null");
        }

        MavenProject pom = getMavenProject(pomFile);
        Artifact rootArtifact = getProjectArtifact(pom);

        CollectRequest collectRequest = new CollectRequest();
        for (org.apache.maven.model.Dependency dependency : pom.getDependencies()) {
            collectRequest.addDependency(toAetherDependency(dependency));
        }

        // Hack: avoid using deprecated Maven Central URLs. The Central Repository no longer supports insecure
        // communication over plain HTTP.
        ImmutableList.Builder<RemoteRepository> allRepositories = ImmutableList.builder();
        for (RemoteRepository repository : pom.getRemoteProjectRepositories()) {
            if (DEPRECATED_MAVEN_CENTRAL_URIS.contains(repository.getUrl())) {
                repository = new RemoteRepository(repository.getId(), repository.getContentType(), MAVEN_CENTRAL_URI);
            }
            allRepositories.add(repository);
        }
        for (RemoteRepository repository : repositories) {
            if (DEPRECATED_MAVEN_CENTRAL_URIS.contains(repository.getUrl())) {
                repository = new RemoteRepository(repository.getId(), repository.getContentType(), MAVEN_CENTRAL_URI);
            }
            allRepositories.add(repository);
        }
        collectRequest.setRepositories(allRepositories.build());

        // Make sure we account for managed dependencies
        if (pom.getDependencyManagement() != null) {
            for (org.apache.maven.model.Dependency managedDependency : pom.getDependencyManagement().getDependencies()) {
                collectRequest.addManagedDependency(toAetherDependency(managedDependency));
            }
        }

        DependencyRequest dependencyRequest = new DependencyRequest(collectRequest, DependencyFilterUtils.classpathFilter(JavaScopes.RUNTIME));
        List<Artifact> artifacts = resolveArtifacts(dependencyRequest);

        Map<String, Artifact> modules = getSiblingModules(pom).stream()
                .collect(toMap(ArtifactResolverX::getArtifactKey, identity()));

        return Stream.concat(
                        Stream.of(rootArtifact),
                        artifacts.stream()
                                .map(artifact -> modules.getOrDefault(getArtifactKey(artifact), artifact)))
                .collect(toImmutableList());
    }

    private MavenProject getMavenProject (File pomFile)
    {
        try {
            PlexusContainer container = container();
            org.apache.maven.repository.RepositorySystem lrs = container.lookup(org.apache.maven.repository.RepositorySystem.class);
            ProjectBuilder projectBuilder = container.lookup(ProjectBuilder.class);
            ProjectBuildingRequest request = new DefaultProjectBuildingRequest();
            request.setSystemProperties(requiredSystemProperties());
            request.setRepositorySession(repositorySystemSession);
            request.setProcessPlugins(false);
            ArtifactRepository defaultLocalRepository = lrs.createDefaultLocalRepository();
            defaultLocalRepository.setUrl(USER_LOCAL_REPO);
            request.setLocalRepository(defaultLocalRepository);
            ArtifactRepository defaultRemoteRepository = lrs.createDefaultRemoteRepository();
            defaultRemoteRepository.setUrl(ALIYUN_MAVEN_CENTRAL_URI);
            request.setRemoteRepositories(Arrays.asList(new ArtifactRepository[]{defaultRemoteRepository}.clone()));
            ProjectBuildingResult result = projectBuilder.build(pomFile, request);
            return result.getProject();
        } catch (Exception e) {
            throw new RuntimeException("Error loading pom: " + pomFile.getAbsolutePath(), e);
        }
    }

    private Artifact getProjectArtifact (MavenProject pom)
    {
        return new DefaultArtifact(
                pom.getArtifact().getGroupId(),
                pom.getArtifact().getArtifactId(),
                pom.getArtifact().getClassifier(),
                pom.getArtifact().getType(),
                pom.getArtifact().getVersion(),
                null,
                new File(pom.getModel().getBuild().getOutputDirectory()));
    }

    private List<Artifact> getSiblingModules (MavenProject module)
    {
        if (!module.hasParent() || module.getParentFile() == null) {
            return ImmutableList.of();
        }

        // Parent exists and is a project reactor
        MavenProject parent = module.getParent();
        String parentDir = module.getParentFile().getParent();

        return parent.getModules().stream()
                .map(moduleName -> new File(parentDir, moduleName + "/pom.xml"))
                .filter(File::isFile)
                .map(this::getMavenProject)
                .map(this::getProjectArtifact)
                .collect(toImmutableList());
    }

    /**
     * Returns a string identifying artifact by its maven coordinates.
     */
    private static String getArtifactKey (Artifact artifact)
    {
        return format("%s:%s:%s:%s", artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(), artifact.getClassifier());
    }

    private Properties requiredSystemProperties ()
    {
        Properties properties = new Properties();
        properties.setProperty("java.version", System.getProperty("java.version"));
        return properties;
    }

    private Dependency toAetherDependency (org.apache.maven.model.Dependency dependency)
    {
        Artifact artifact = new DefaultArtifact(dependency.getGroupId(), dependency.getArtifactId(), dependency.getClassifier(), dependency.getType(), dependency.getVersion());
        ImmutableList.Builder<Exclusion> exclusions = ImmutableList.builder();
        for (org.apache.maven.model.Exclusion exclusion : dependency.getExclusions()) {
            exclusions.add(new Exclusion(exclusion.getGroupId(), exclusion.getArtifactId(), null, "*"));
        }
        return new Dependency(artifact, dependency.getScope(), dependency.isOptional(), exclusions.build());
    }

    private List<Artifact> resolveArtifacts (DependencyRequest dependencyRequest)
    {
        DependencyResult dependencyResult;
        try {
            dependencyResult = repositorySystem.resolveDependencies(repositorySystemSession, dependencyRequest);
        } catch (DependencyResolutionException e) {
            dependencyResult = e.getResult();
        }
        List<ArtifactResult> artifactResults = dependencyResult.getArtifactResults();
        List<Artifact> artifacts = new ArrayList<>(artifactResults.size());
        for (ArtifactResult artifactResult : artifactResults) {
            if (artifactResult.isMissing()) {
                artifacts.add(artifactResult.getRequest().getArtifact());
            } else {
                artifacts.add(artifactResult.getArtifact());
            }
        }

        return Collections.unmodifiableList(artifacts);
    }

    private static PlexusContainer container ()
    {
        try {
            ClassWorld classWorld = new ClassWorld("plexus.core", Thread.currentThread().getContextClassLoader());

            ContainerConfiguration cc = new DefaultContainerConfiguration()
                    .setClassWorld(classWorld)
                    .setRealm(null)
                    .setName("maven");

            DefaultPlexusContainer container = new DefaultPlexusContainer(cc);

            // NOTE: To avoid inconsistencies, we'll use the Thread context class loader exclusively for lookups
            container.setLookupRealm(null);

            container.setLoggerManager(new Slf4jLoggerManager());
            container.getLoggerManager().setThresholds(Logger.LEVEL_INFO);

            return container;
        } catch (PlexusContainerException e) {
            throw new RuntimeException("Error loading Maven system", e);
        }
    }
}

``

此外还需要修改下面的两个类,将HttpsArtifactResolver替换为ArtifactResolverX :

  • io.trino.server.DevelopmentPluginsProvider
  • io.trino.server.DevelopmentLoaderConfig

七、本地启动测试

1、启动服务

在这里插入图片描述

2、客户端连接

使用client/trino-cli下的jar,启动方式:java -jar trino-cli-435-executable.jar --server http://localhost:8080

3、执行命令

4、ui展示

登录只需填写用户名trino
在这里插入图片描述

文章来源:https://blog.csdn.net/yuming226/article/details/135162186
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。