trino-435版本windows下源码编译

一、源码下载地址

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

二、编译环境及工具准备

1、maven

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



  D:\maven\repo2  
  
	
        alimaven
        central
        aliyun maven
        https://maven.aliyun.com/repository/central/
  
   
      alimaven
      aliyun maven
      http://maven.aliyun.com/nexus/content/groups/public/
      central        
    
  
 
	
		 
		jdk-1.8
			   
		
			true
			1.8
		
			
		
			  
			1.8
			1.8
			1.8
		
	
  

2、jdk

版本:17.0.9

3、idea

版本:2023.2

三、源码编译配置

(1)取消插件:really-executable-jar-maven-plugin
trino-435版本windows下源码编译_第1张图片
(2)trino-root xml取消如下两个module
trino-435版本windows下源码编译_第2张图片
(3)trino-root xml取消scm
trino-435版本windows下源码编译_第3张图片
(4)trino-root xml取消如下配置

















































(4)取消maven-enforcer-plugin配置
trino-435版本windows下源码编译_第4张图片
(5)配置maven插件
trino-435版本windows下源码编译_第5张图片

四、profiles配置

取消dependency-scope-check、duplicate-finder-check两个配置,防止maven install时因依赖冲突或jar依赖相关问题的出现在这里插入图片描述](https://img-blog.csdnimg.cn/direct/c4754f121fbb4d7a82b682390f7dae3c.png)
trino-435版本windows下源码编译_第6张图片
trino-435版本windows下源码编译_第7张图片

五、启动类配置

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-435版本windows下源码编译_第8张图片

六、代码修改

由于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 DEPRECATED_MAVEN_CENTRAL_URIS = ImmutableSet.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 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 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 resolveArtifacts (Artifact...sourceArtifacts)
    {
        return resolveArtifacts(Arrays.asList(sourceArtifacts));
    }

    public List 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 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 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 artifacts = resolveArtifacts(dependencyRequest);

        Map 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 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 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 resolveArtifacts (DependencyRequest dependencyRequest)
    {
        DependencyResult dependencyResult;
        try {
            dependencyResult = repositorySystem.resolveDependencies(repositorySystemSession, dependencyRequest);
        } catch (DependencyResolutionException e) {
            dependencyResult = e.getResult();
        }
        List artifactResults = dependencyResult.getArtifactResults();
        List 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、启动服务

trino-435版本windows下源码编译_第9张图片

2、客户端连接

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

3、执行命令

trino-435版本windows下源码编译_第10张图片

4、ui展示

登录只需填写用户名trino
trino-435版本windows下源码编译_第11张图片

你可能感兴趣的:(大数据,java,intellij,idea)