Moving sts-gradle-model plugin into headless services

Closer to original in main
This commit is contained in:
aboyko
2024-03-01 13:35:44 -05:00
committed by aboyko
parent fd10ee30af
commit 0c8644bbbe
38 changed files with 969 additions and 187 deletions

View File

@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-17"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src/"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>

View File

@@ -2,7 +2,6 @@
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry exported="true" kind="lib" path="gradle-plugin/sts-gradle-model-plugin.jar"/>
<classpathentry kind="src" path="src/"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>

View File

@@ -18,8 +18,7 @@ Require-Bundle: org.eclipse.core.runtime,
org.eclipse.ui.workbench,
com.google.guava,
org.springsource.ide.eclipse.commons.livexp,
org.springframework.ide.eclipse.boot;bundle-version="3.9.12"
org.springframework.ide.eclipse.boot;bundle-version="3.9.12",
org.springframework.tooling.gradle
Import-Package: org.apache.commons.io
Bundle-ClassPath: gradle-plugin/sts-gradle-model-plugin.jar,
.
Bundle-Activator: org.springframework.ide.eclipse.buildship30.Buildship30Plugin

View File

@@ -1,10 +1,6 @@
source.. = src/
output.. = bin/
bin.includes = META-INF/,\
.,\
plugin.properties,\
plugin.xml,\
about.html,\
gradle-plugin/sts-gradle-model-plugin.jar,\
gradle-plugin/init.gradle
about.html

View File

@@ -65,69 +65,6 @@
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-clean-plugin</artifactId>
<configuration>
<filesets>
<fileset>
<directory>${project.basedir}/gradle-plugin</directory>
<includes>
<include>*.jar</include>
</includes>
</fileset>
</filesets>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<executions>
<execution>
<id>sts-gradle-model-build</id>
<phase>generate-resources</phase>
<configuration>
<workingDirectory>${project.basedir}/../sts-gradle-model-plugin/sts-gradle-model-plugin</workingDirectory>
<executable>${gradle.executable}</executable>
<arguments>
<argument>clean</argument>
<argument>build</argument>
<argument>-S</argument>
</arguments>
</configuration>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<id>copy-sts-gradle-model-jars</id>
<phase>process-resources</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${project.basedir}/gradle-plugin</outputDirectory>
<resources>
<resource>
<directory>${project.basedir}/../sts-gradle-model-plugin/sts-gradle-model-plugin/build/libs/</directory>
<includes>
<include>${gradle.model-plugin.artifactId}.jar</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>target-platform-configuration</artifactId>

View File

@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2020 Pivotal, Inc.
* Copyright (c) 2020, 2024 Pivotal, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -11,9 +11,6 @@
package org.springframework.ide.eclipse.buildship30;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
@@ -25,7 +22,6 @@ import org.eclipse.buildship.core.internal.workspace.NewProjectHandler;
import org.eclipse.buildship.core.internal.workspace.SynchronizationJob;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.gradle.tooling.ModelBuilder;
@@ -39,6 +35,7 @@ import org.springframework.ide.eclipse.boot.core.initializr.InitializrService;
import org.springframework.ide.eclipse.boot.core.initializr.InitializrUrl;
import org.springframework.ide.eclipse.boot.core.internal.SpringBootProject;
import org.springframework.ide.eclipse.boot.util.DependencyDelta;
import org.springframework.tooling.gradle.StsGradleToolingModelBuilder;
import org.springsource.ide.eclipse.commons.livexp.util.Log;
import com.google.common.base.Supplier;
@@ -54,11 +51,6 @@ public class GradleSpringBootProject extends SpringBootProject {
private static final String WAR_PKG_NATURE = "org.eclipse.wst.common.project.facet.core.nature";
private static final Supplier<Path> cacheFolderSupplier = Suppliers.memoize(() -> {
IPath iPath = Buildship30Plugin.getDefault().getStateLocation().makeAbsolute();
return iPath.toFile().toPath().resolve("gradle-plugin");
});
private static class GradleModels {
EclipseProject eclipseProject;
StsToolingModel stsToolingModel;
@@ -117,13 +109,12 @@ public class GradleSpringBootProject extends SpringBootProject {
if (build.isPresent()) {
try {
return build.get().withConnection(connection -> {
ModelBuilder<StsToolingModel> stsModelBuilder = connection.model(StsToolingModel.class)
.withArguments("--init-script", getInitScript().toString());
ModelBuilder<StsToolingModel> stsModelBuilder = StsGradleToolingModelBuilder.getModelBuilder(connection, project.getLocation().toFile(), null);
return new GradleModels(connection.model(EclipseProject.class).get(),
stsModelBuilder.get());
}, new NullProgressMonitor());
} catch (Exception e) {
Log.log(e);
} catch (Throwable t) {
Log.log(t);
return null;
}
}
@@ -252,29 +243,4 @@ public class GradleSpringBootProject extends SpringBootProject {
throw new UnsupportedOperationException("Not implemented!");
}
private Path getInitScript() {
Path cacheFolder = cacheFolderSupplier.get();
Path initScript = cacheFolder.resolve("init.gradle");
Path jarPath = cacheFolder.resolve("sts-gradle-model-plugin.jar");
if (!Files.isDirectory(cacheFolder)) {
cacheFolder.toFile().mkdirs();
}
if (!Files.exists(initScript)) {
try {
Files.copy(getClass().getResourceAsStream("/gradle-plugin/init.gradle"), initScript);
} catch (IOException e) {
Log.log(e);
}
}
if (!Files.exists(jarPath)) {
try {
Files.copy(getClass().getResourceAsStream("/gradle-plugin/sts-gradle-model-plugin.jar"),
jarPath);
} catch (IOException e) {
Log.log(e);
}
}
return initScript;
}
}

View File

@@ -2,90 +2,92 @@
<site>
<category-def name="Spring Tools 4 Language Server Integrations for Eclipse" label="Spring Tools 4 Language Server Integrations for Eclipse"/>
<feature id="org.springframework.tooling.boot.ls.feature">
<category name="Spring Tools 4 Language Server Integrations for Eclipse"/>
</feature>
<feature id="org.springframework.tooling.boot.ls.feature">
<category name="Spring Tools 4 Language Server Integrations for Eclipse"/>
</feature>
<feature id="org.springframework.tooling.boot.ls.feature.source">
<category name="Spring Tools 4 Language Server Integrations for Eclipse"/>
</feature>
<feature id="org.springframework.tooling.boot.ls.feature.source">
<category name="Spring Tools 4 Language Server Integrations for Eclipse"/>
</feature>
<feature id="org.springframework.tooling.cloudfoundry.manifest.ls.integration.feature">
<category name="Spring Tools 4 Language Server Integrations for Eclipse"/>
</feature>
<feature id="org.springframework.tooling.cloudfoundry.manifest.ls.integration.feature">
<category name="Spring Tools 4 Language Server Integrations for Eclipse"/>
</feature>
<feature id="org.springframework.tooling.cloudfoundry.manifest.ls.integration.feature.source">
<category name="Spring Tools 4 Language Server Integrations for Eclipse"/>
</feature>
<feature id="org.springframework.tooling.cloudfoundry.manifest.ls.integration.feature.source">
<category name="Spring Tools 4 Language Server Integrations for Eclipse"/>
</feature>
<feature id="org.springframework.tooling.cloudfoundry.manifest.ls.feature">
<category name="Spring Tools 4 Language Server Integrations for Eclipse"/>
</feature>
<feature id="org.springframework.tooling.cloudfoundry.manifest.ls.feature">
<category name="Spring Tools 4 Language Server Integrations for Eclipse"/>
</feature>
<feature id="org.springframework.tooling.cloudfoundry.manifest.ls.feature.source">
<category name="Spring Tools 4 Language Server Integrations for Eclipse"/>
</feature>
<feature id="org.springframework.tooling.cloudfoundry.manifest.ls.feature.source">
<category name="Spring Tools 4 Language Server Integrations for Eclipse"/>
</feature>
<feature id="org.springframework.tooling.bosh.ls.feature">
<category name="Spring Tools 4 Language Server Integrations for Eclipse"/>
</feature>
<feature id="org.springframework.tooling.bosh.ls.feature">
<category name="Spring Tools 4 Language Server Integrations for Eclipse"/>
</feature>
<feature id="org.springframework.tooling.bosh.ls.feature.source">
<category name="Spring Tools 4 Language Server Integrations for Eclipse"/>
</feature>
<feature id="org.springframework.tooling.bosh.ls.feature.source">
<category name="Spring Tools 4 Language Server Integrations for Eclipse"/>
</feature>
<feature id="org.springframework.tooling.concourse.ls.feature">
<category name="Spring Tools 4 Language Server Integrations for Eclipse"/>
</feature>
<feature id="org.springframework.tooling.concourse.ls.feature">
<category name="Spring Tools 4 Language Server Integrations for Eclipse"/>
</feature>
<feature id="org.springframework.tooling.concourse.ls.feature.source">
<category name="Spring Tools 4 Language Server Integrations for Eclipse"/>
</feature>
<feature id="org.springframework.tooling.concourse.ls.feature.source">
<category name="Spring Tools 4 Language Server Integrations for Eclipse"/>
</feature>
<feature id="org.eclipse.mylyn.wikitext_feature"/>
<feature id="org.eclipse.tm4e.feature"/>
<feature id="org.eclipse.mylyn.wikitext_feature"/>
<feature id="org.eclipse.tm4e.feature"/>
<bundle id="org.springframework.tooling.ls.eclipse.commons"/>
<bundle id="org.springframework.tooling.ls.eclipse.commons.source"/>
<bundle id="org.springframework.tooling.jdt.ls.commons"/>
<bundle id="org.springframework.tooling.jdt.ls.commons.source"/>
<bundle id="org.springframework.tooling.ls.eclipse.gotosymbol"/>
<bundle id="org.springframework.tooling.ls.eclipse.gotosymbol.source"/>
<bundle id="org.springframework.ide.eclipse.editor.support"/>
<bundle id="org.springframework.ide.eclipse.editor.support.source"/>
<bundle id="org.springsource.ide.eclipse.commons.boot.ls"/>
<bundle id="org.springsource.ide.eclipse.commons.boot.ls.source"/>
<bundle id="org.springsource.ide.eclipse.commons.core"/>
<bundle id="org.springsource.ide.eclipse.commons.core.source"/>
<bundle id="org.springsource.ide.eclipse.commons.frameworks.core"/>
<bundle id="org.springsource.ide.eclipse.commons.frameworks.core.source"/>
<bundle id="org.springsource.ide.eclipse.commons.frameworks.test.util"/>
<bundle id="org.springsource.ide.eclipse.commons.frameworks.test.util.source"/>
<bundle id="org.springsource.ide.eclipse.commons.frameworks.ui"/>
<bundle id="org.springsource.ide.eclipse.commons.frameworks.ui.source"/>
<bundle id="org.springsource.ide.eclipse.commons.jdk_tools"/>
<bundle id="org.springsource.ide.eclipse.commons.jdk_tools.source"/>
<bundle id="org.springsource.ide.eclipse.commons.livexp"/>
<bundle id="org.springsource.ide.eclipse.commons.livexp.source"/>
<bundle id="org.springsource.ide.eclipse.commons.tests.util"/>
<bundle id="org.springsource.ide.eclipse.commons.tests.util.source"/>
<bundle id="org.springsource.ide.eclipse.commons.ui"/>
<bundle id="org.springsource.ide.eclipse.commons.ui.source"/>
<bundle id="org.springframework.tooling.ls.eclipse.commons"/>
<bundle id="org.springframework.tooling.ls.eclipse.commons.source"/>
<bundle id="org.springframework.tooling.jdt.ls.commons"/>
<bundle id="org.springframework.tooling.jdt.ls.commons.source"/>
<bundle id="org.springframework.tooling.gradle"/>
<bundle id="org.springframework.tooling.gradle.source"/>
<bundle id="org.springframework.tooling.ls.eclipse.gotosymbol"/>
<bundle id="org.springframework.tooling.ls.eclipse.gotosymbol.source"/>
<bundle id="io.projectreactor.reactor-core"/>
<bundle id="io.projectreactor.reactor-core.source"/>
<bundle id="org.reactivestreams.reactive-streams"/>
<bundle id="org.reactivestreams.reactive-streams.source"/>
<bundle id="org.springframework.ide.eclipse.editor.support"/>
<bundle id="org.springframework.ide.eclipse.editor.support.source"/>
<bundle id="org.eclipse.lsp4e"/>
<bundle id="org.eclipse.lsp4e.jdt"/>
<bundle id="org.eclipse.lsp4j"/>
<bundle id="org.eclipse.lsp4j.jsonrpc"/>
<bundle id="org.eclipse.xtext.xbase.lib"/>
<bundle id="org.jcodings"/>
<bundle id="org.joni"/>
<bundle id="org.apache.commons.lang3"/>
<bundle id="org.springsource.ide.eclipse.commons.boot.ls"/>
<bundle id="org.springsource.ide.eclipse.commons.boot.ls.source"/>
<bundle id="org.springsource.ide.eclipse.commons.core"/>
<bundle id="org.springsource.ide.eclipse.commons.core.source"/>
<bundle id="org.springsource.ide.eclipse.commons.frameworks.core"/>
<bundle id="org.springsource.ide.eclipse.commons.frameworks.core.source"/>
<bundle id="org.springsource.ide.eclipse.commons.frameworks.test.util"/>
<bundle id="org.springsource.ide.eclipse.commons.frameworks.test.util.source"/>
<bundle id="org.springsource.ide.eclipse.commons.frameworks.ui"/>
<bundle id="org.springsource.ide.eclipse.commons.frameworks.ui.source"/>
<bundle id="org.springsource.ide.eclipse.commons.jdk_tools"/>
<bundle id="org.springsource.ide.eclipse.commons.jdk_tools.source"/>
<bundle id="org.springsource.ide.eclipse.commons.livexp"/>
<bundle id="org.springsource.ide.eclipse.commons.livexp.source"/>
<bundle id="org.springsource.ide.eclipse.commons.tests.util"/>
<bundle id="org.springsource.ide.eclipse.commons.tests.util.source"/>
<bundle id="org.springsource.ide.eclipse.commons.ui"/>
<bundle id="org.springsource.ide.eclipse.commons.ui.source"/>
<bundle id="io.projectreactor.reactor-core"/>
<bundle id="io.projectreactor.reactor-core.source"/>
<bundle id="org.reactivestreams.reactive-streams"/>
<bundle id="org.reactivestreams.reactive-streams.source"/>
<bundle id="org.eclipse.lsp4e"/>
<bundle id="org.eclipse.lsp4e.jdt"/>
<bundle id="org.eclipse.lsp4j"/>
<bundle id="org.eclipse.lsp4j.jsonrpc"/>
<bundle id="org.eclipse.xtext.xbase.lib"/>
<bundle id="org.jcodings"/>
<bundle id="org.joni"/>
<bundle id="org.apache.commons.lang3"/>
</site>

View File

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry exported="true" kind="lib" path="gradle-plugin/sts-gradle-model-plugin.jar"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-17"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
</classpath>

View File

@@ -0,0 +1 @@
/gradle-plugin/*.jar

View File

@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>org.springframework.tooling.gradle</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.ManifestBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.SchemaBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

View File

@@ -0,0 +1,15 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: STS Gradle Model
Bundle-SymbolicName: org.springframework.tooling.gradle;singleton:=true
Bundle-Version: 4.22.0.qualifier
Export-Package: org.springframework.tooling.gradle,
sts.model.plugin
Require-Bundle: org.eclipse.core.runtime,
org.eclipse.buildship.core;bundle-version="3.0.0"
Automatic-Module-Name: org.springframework.tooling.gradle
Bundle-ActivationPolicy: lazy
Bundle-Activator: org.springframework.tooling.gradle.StsGradlePlugin
Bundle-ClassPath: .,
gradle-plugin/sts-gradle-model-plugin.jar
Bundle-RequiredExecutionEnvironment: JavaSE-17

View File

@@ -0,0 +1,7 @@
source.. = src/
output.. = bin/
bin.includes = META-INF/,\
.,\
gradle-plugin/sts-gradle-model-plugin.jar, \
gradle-plugin/init.gradle

View File

@@ -0,0 +1,74 @@
<project xmlns="https://maven.apache.org/POM/4.0.0"
xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://maven.apache.org/POM/4.0.0 https://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<packaging>eclipse-plugin</packaging>
<groupId>org.springframework.ide.vscode</groupId>
<artifactId>org.springframework.tooling.gradle</artifactId>
<version>4.22.0-SNAPSHOT</version>
<name>org.springframework.tooling.gradle</name>
<parent>
<groupId>org.springframework.tooling</groupId>
<artifactId>jdt-ls-extension-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.ide</groupId>
<artifactId>sts-gradle-model-plugin</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<!-- make sure lib dir is removed after clean to avoid "dirty" build -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-clean-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<filesets>
<fileset>
<directory>${project.basedir}/gradle-plugin</directory>
<includes>
<include>*.jar</include>
</includes>
</fileset>
</filesets>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.1.1</version>
<executions>
<execution>
<id>copy-sts-gradle-model-jars</id>
<phase>initialize</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>org.springframework.ide</groupId>
<artifactId>sts-gradle-model-plugin</artifactId>
<overWrite>true</overWrite>
<outputDirectory>${basedir}/gradle-plugin</outputDirectory>
</artifactItem>
</artifactItems>
<stripVersion>true</stripVersion>
<overWriteReleases>true</overWriteReleases>
<overWriteSnapshots>true</overWriteSnapshots>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@@ -0,0 +1,26 @@
package org.springframework.tooling.gradle;
import org.eclipse.core.runtime.Plugin;
import org.osgi.framework.BundleContext;
public class StsGradlePlugin extends Plugin {
private static StsGradlePlugin plugin;
static StsGradlePlugin getDefault() {
return plugin;
}
@Override
public void start(BundleContext context) throws Exception {
super.start(context);
plugin = this;
}
@Override
public void stop(BundleContext context) throws Exception {
plugin = null;
super.stop(context);
}
}

View File

@@ -0,0 +1,78 @@
/*******************************************************************************
* Copyright (c) 2024 Broadcom, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Broadcom, Inc. - initial API and implementation
*******************************************************************************/
package org.springframework.tooling.gradle;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.core.runtime.IPath;
import org.gradle.tooling.ModelBuilder;
import org.gradle.tooling.ProjectConnection;
import sts.model.plugin.StsToolingModel;
public class StsGradleToolingModelBuilder {
private static Path initScript = null;
private static Path getCacheFolder() {
IPath iPath = StsGradlePlugin.getDefault().getStateLocation().makeAbsolute();
return iPath.toFile().toPath().resolve("gradle-plugin");
};
private static Path getInitScript() {
if (initScript == null) {
Path cacheFolder = getCacheFolder();
initScript = cacheFolder.resolve("init.gradle");
Path jarPath = cacheFolder.resolve("sts-gradle-model-plugin.jar");
if (!Files.isDirectory(cacheFolder)) {
cacheFolder.toFile().mkdirs();
}
if (!Files.exists(initScript)) {
try {
Files.copy(StsGradleToolingModelBuilder.class.getResourceAsStream("/gradle-plugin/init.gradle"),
initScript, StandardCopyOption.REPLACE_EXISTING);
} catch (IOException e) {
StsGradlePlugin.getDefault().getLog().error("Failed to copy '/gradle-plugin/init.gradle'", e);
}
}
if (!Files.exists(jarPath)) {
try {
Files.copy(StsGradleToolingModelBuilder.class
.getResourceAsStream("/gradle-plugin/sts-gradle-model-plugin.jar"), jarPath, StandardCopyOption.REPLACE_EXISTING);
} catch (IOException e) {
StsGradlePlugin.getDefault().getLog()
.error("Failed to copy '/gradle-plugin/sts-gradle-model-plugin.jar'", e);
}
}
}
return initScript;
}
public static ModelBuilder<StsToolingModel> getModelBuilder(ProjectConnection connection, File projectDir, File buildFile) {
List<String> arguments = new ArrayList<>();
if (buildFile != null && buildFile.exists()) {
arguments.add("-b");
arguments.add(buildFile.getAbsolutePath());
}
arguments.add("--init-script");
arguments.add(getInitScript().toString());
ModelBuilder<StsToolingModel> modelBuilder = connection.model(StsToolingModel.class);
modelBuilder.withArguments(arguments);
return modelBuilder;
}
}

View File

@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2018, 2023 Pivotal, Inc.
* Copyright (c) 2018, 2024 Pivotal, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -225,7 +225,7 @@ public class ClasspathUtil {
}
}
public static ProjectBuild createProjectBuild(IJavaProject jp) {
public static ProjectBuild createProjectBuild(IJavaProject jp, Logger logger) {
// try {
boolean likelyGradle = false;
boolean likelyMaven = false;
@@ -239,7 +239,16 @@ public class ClasspathUtil {
if (!g.exists()) {
g = jp.getProject().getFile("build.gradle.kts");
}
return new ProjectBuild(ProjectBuild.GRADLE_PROJECT_TYPE, g.exists() ? g.getLocationURI().toASCIIString() : null, null);
// TODO: TestJars support requires GAV of a project. To be added properly later as it needs optimizations
// Optional<Gav> optGav = GradleCore.getWorkspace().getBuild(jp.getProject()).flatMap(build -> {
// try {
// return Optional.of(build.withConnection(conn -> StsGradleToolingModelBuilder.getModelBuilder(conn, jp.getProject().getLocation().toFile(), null).get(), new NullProgressMonitor()));
// } catch (Exception e) {
// logger.log(e);
// return Optional.empty();
// }
// }).map(m -> new Gav(m.group(), m.artifact(), m.version()));
return ProjectBuild.createGradleBuild(g.exists() ? g.getLocationURI().toASCIIString() : null, /*optGav.orElse(null)*/null);
} else {
try {
for (IClasspathEntry e : jp.getRawClasspath()) {

View File

@@ -143,7 +143,7 @@ public class SendClasspathNotificationsJob extends Job {
logger.log(e);
}
}
bufferMessage(projectLoc, deleted, projectName, classpath, ClasspathUtil.createProjectBuild(jp));
bufferMessage(projectLoc, deleted, projectName, classpath, ClasspathUtil.createProjectBuild(jp, logger));
}
}
flush();

View File

@@ -39,6 +39,7 @@
</ciManagement>
<modules>
<module>org.springframework.tooling.gradle</module>
<module>org.springframework.tooling.jdt.ls.extension</module>
<module>org.springframework.tooling.jdt.ls.commons</module>
<module>org.springframework.tooling.jdt.ls.commons.test</module>

View File

@@ -10,6 +10,7 @@
<name>aggregator</name>
<modules>
<module>sts-gradle-model-plugin</module>
<module>commons</module>
<module>manifest-yaml-language-server</module>
<module>concourse-language-server</module>

View File

@@ -0,0 +1,6 @@
/**/.gradle/
/**/.project
/**/.classpath
/**/.settings/
.DS_Store
/**/.DS_Store

View File

@@ -0,0 +1,19 @@
apply plugin: 'application'
repositories {
maven {
url "$projectDir/../repo"
}
maven {
url 'https://repo.gradle.org/gradle/libs-releases-local'
}
mavenCentral()
}
dependencies {
compile files('../sts-model-plugin/build/libs/sts-model-plugin-1.0.0-SNAPSHOT.jar')
compile "org.gradle:gradle-tooling-api:6.2.2"
runtime 'org.slf4j:slf4j-simple:1.7.5'
}
mainClassName = 'org.gradle.sample.toolingapi.ToolingApiRunner'

View File

@@ -0,0 +1,40 @@
/*******************************************************************************
* Copyright (c) 2020 Pivotal, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Pivotal, Inc. - initial API and implementation
*******************************************************************************/
package org.gradle.sample.toolingapi;
import java.io.File;
import org.gradle.tooling.GradleConnector;
import org.gradle.tooling.ModelBuilder;
import org.gradle.tooling.ProjectConnection;
import sts.model.plugin.StsToolingModel;
public class ToolingApiRunner {
public static void main(String[] args) {
GradleConnector connector = GradleConnector.newConnector();
connector.forProjectDirectory(new File("../sample"));
ProjectConnection connection = null;
try {
connection = connector.connect();
ModelBuilder<StsToolingModel> customModelBuilder = connection.model(StsToolingModel.class);
customModelBuilder.withArguments("--init-script", "/Users/aboyko/Documents/runtime-STS/.metadata/.plugins/org.springframework.ide.eclipse.buildship30/gradle-plugin/init.gradle");
StsToolingModel model = customModelBuilder.get();
System.out.println("Group=" + model.group() + " artifact=" + model.artifact() + " version=" + model.version());
assert model.version() != null;
} finally {
if(connection != null) {
connection.close();
}
}
}
}

View File

@@ -0,0 +1,54 @@
<project xmlns="https://maven.apache.org/POM/4.0.0" xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://maven.apache.org/POM/4.0.0
https://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.springframework.ide.vscode</groupId>
<artifactId>sts-gradle-model-plugin-wrapper</artifactId>
<packaging>pom</packaging>
<version>1.53.0-SNAPSHOT</version>
<name>sts-gradle-model-plugin-wrapper</name>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<executions>
<execution>
<id>test</id>
<phase>test</phase>
<configuration>
<workingDirectory>${project.basedir}/sts-gradle-model-plugin/</workingDirectory>
<executable>./gradlew</executable>
<arguments>
<argument>test</argument>
<argument>-i</argument>
</arguments>
</configuration>
<goals>
<goal>exec</goal>
</goals>
</execution>
<execution>
<id>install</id>
<phase>install</phase>
<configuration>
<workingDirectory>${project.basedir}/sts-gradle-model-plugin/</workingDirectory>
<executable>./gradlew</executable>
<arguments>
<argument>clean</argument>
<argument>build</argument>
<argument>publishToMavenLocal</argument>
</arguments>
</configuration>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@@ -0,0 +1,33 @@
plugins {
id 'org.springframework.boot' version '2.3.0.M2'
id 'io.spring.dependency-management' version '1.0.9.RELEASE'
id 'java'
}
group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '17'
configurations {
compileOnly {
extendsFrom annotationProcessor
}
}
repositories {
mavenCentral()
maven { url 'https://repo.spring.io/milestone' }
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-activemq'
implementation 'org.springframework.boot:spring-boot-starter-web'
annotationProcessor 'org.springframework.boot:spring-boot-configuration-processor'
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
}
test {
useJUnitPlatform()
}

View File

@@ -0,0 +1,9 @@
initscript {
dependencies {
classpath files('../sts-gradle-model-plugin/build/libs/sts-gradle-model-plugin-1.0.0-SNAPSHOT.jar')
}
}
allprojects {
apply plugin: sts.model.plugin.StsModelPlugin
}

View File

@@ -0,0 +1,14 @@
pluginManagement {
repositories {
maven { url 'https://repo.spring.io/milestone' }
gradlePluginPortal()
}
resolutionStrategy {
eachPlugin {
if (requested.id.id == 'org.springframework.boot') {
useModule("org.springframework.boot:spring-boot-gradle-plugin:${requested.version}")
}
}
}
}
rootProject.name = 'demo-gradle-jar'

View File

@@ -0,0 +1,5 @@
# Ignore Gradle project-specific cache directory
.gradle
# Ignore Gradle build output directory
build

View File

@@ -0,0 +1,24 @@
plugins {
id 'java-library'
id 'maven-publish'
}
dependencies {
implementation gradleApi()
}
publishing {
publications {
mavenJava(MavenPublication) {
from components.java
}
}
}
compileJava {
sourceCompatibility = '17'
targetCompatibility = '17'
}
group = "org.springframework.ide"
version = "1.0.0"

View File

@@ -0,0 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

View File

@@ -0,0 +1,183 @@
#!/usr/bin/env sh
#
# Copyright 2015 the original author or authors.
#
# 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
#
# https://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.
#
##############################################################################
##
## Gradle start up script for UN*X
##
##############################################################################
# Attempt to set APP_HOME
# Resolve links: $0 may be a link
PRG="$0"
# Need this for relative symlinks.
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG=`dirname "$PRG"`"/$link"
fi
done
SAVED="`pwd`"
cd "`dirname \"$PRG\"`/" >/dev/null
APP_HOME="`pwd -P`"
cd "$SAVED" >/dev/null
APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"`
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"
warn () {
echo "$*"
}
die () {
echo
echo "$*"
echo
exit 1
}
# OS specific support (must be 'true' or 'false').
cygwin=false
msys=false
darwin=false
nonstop=false
case "`uname`" in
CYGWIN* )
cygwin=true
;;
Darwin* )
darwin=true
;;
MINGW* )
msys=true
;;
NONSTOP* )
nonstop=true
;;
esac
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
# Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables
JAVACMD="$JAVA_HOME/jre/sh/java"
else
JAVACMD="$JAVA_HOME/bin/java"
fi
if [ ! -x "$JAVACMD" ] ; then
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
else
JAVACMD="java"
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
# Increase the maximum file descriptors if we can.
if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
MAX_FD_LIMIT=`ulimit -H -n`
if [ $? -eq 0 ] ; then
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
MAX_FD="$MAX_FD_LIMIT"
fi
ulimit -n $MAX_FD
if [ $? -ne 0 ] ; then
warn "Could not set maximum file descriptor limit: $MAX_FD"
fi
else
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
fi
fi
# For Darwin, add options to specify how the application appears in the dock
if $darwin; then
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
fi
# For Cygwin or MSYS, switch paths to Windows format before running java
if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
JAVACMD=`cygpath --unix "$JAVACMD"`
# We build the pattern for arguments to be converted via cygpath
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
SEP=""
for dir in $ROOTDIRSRAW ; do
ROOTDIRS="$ROOTDIRS$SEP$dir"
SEP="|"
done
OURCYGPATTERN="(^($ROOTDIRS))"
# Add a user-defined pattern to the cygpath arguments
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
fi
# Now convert the arguments - kludge to limit ourselves to /bin/sh
i=0
for arg in "$@" ; do
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
else
eval `echo args$i`="\"$arg\""
fi
i=`expr $i + 1`
done
case $i in
0) set -- ;;
1) set -- "$args0" ;;
2) set -- "$args0" "$args1" ;;
3) set -- "$args0" "$args1" "$args2" ;;
4) set -- "$args0" "$args1" "$args2" "$args3" ;;
5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
esac
fi
# Escape application args
save () {
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
echo " "
}
APP_ARGS=`save "$@"`
# Collect all arguments for the java command, following the shell quoting and substitution rules
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
exec "$JAVACMD" "$@"

View File

@@ -0,0 +1,100 @@
@rem
@rem Copyright 2015 the original author or authors.
@rem
@rem Licensed under the Apache License, Version 2.0 (the "License");
@rem you may not use this file except in compliance with the License.
@rem You may obtain a copy of the License at
@rem
@rem https://www.apache.org/licenses/LICENSE-2.0
@rem
@rem Unless required by applicable law or agreed to in writing, software
@rem distributed under the License is distributed on an "AS IS" BASIS,
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem
@if "%DEBUG%" == "" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
@rem
@rem ##########################################################################
@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal
set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome
set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto init
echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto init
echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:init
@rem Get command-line arguments, handling Windows variants
if not "%OS%" == "Windows_NT" goto win9xME_args
:win9xME_args
@rem Slurp the command line arguments.
set CMD_LINE_ARGS=
set _SKIP=2
:win9xME_args_slurp
if "x%~1" == "x" goto execute
set CMD_LINE_ARGS=%*
:execute
@rem Setup the command line
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
:end
@rem End local scope for the variables with windows NT shell
if "%ERRORLEVEL%"=="0" goto mainEnd
:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
exit /b 1
:mainEnd
if "%OS%"=="Windows_NT" endlocal
:omega

View File

@@ -0,0 +1,10 @@
/*
* This file was generated by the Gradle 'init' task.
*
* The settings file is used to specify which projects to include in your build.
*
* Detailed information about configuring a multi-project build in Gradle can be found
* in the user manual at https://docs.gradle.org/6.0/userguide/multi_project_builds.html
*/
rootProject.name = 'sts-gradle-model-plugin'

View File

@@ -0,0 +1,38 @@
/*******************************************************************************
* Copyright (c) 2020 Pivotal, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Pivotal, Inc. - initial API and implementation
*******************************************************************************/
package sts.model.plugin;
import java.io.Serializable;
class DefaultModel implements StsToolingModel, Serializable {
private static final long serialVersionUID = 725626813912256658L;
String version;
String group;
String artifact;
@Override
public String version() {
return version;
}
@Override
public String group() {
return group;
}
@Override
public String artifact() {
return artifact;
}
}

View File

@@ -0,0 +1,38 @@
/*******************************************************************************
* Copyright (c) 2020 Pivotal, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Pivotal, Inc. - initial API and implementation
*******************************************************************************/
package sts.model.plugin;
import org.gradle.api.Project;
import org.gradle.tooling.provider.model.ToolingModelBuilder;
public class StsModelBuilder implements ToolingModelBuilder {
@Override
public StsToolingModel buildAll(String modelName, Project project) {
DefaultModel model = new DefaultModel();
if (project.getVersion() != null) {
model.version = project.getVersion().toString();
}
if (project.getGroup() != null) {
model.group = project.getGroup().toString();
}
if (project.getName() != null) {
model.artifact = project.getName();
}
return model;
}
@Override
public boolean canBuild(String modelName) {
return StsToolingModel.class.getName().equals(modelName);
}
}

View File

@@ -0,0 +1,33 @@
/*******************************************************************************
* Copyright (c) 2020 Pivotal, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Pivotal, Inc. - initial API and implementation
*******************************************************************************/
package sts.model.plugin;
import javax.inject.Inject;
import org.gradle.api.Plugin;
import org.gradle.api.Project;
import org.gradle.tooling.provider.model.ToolingModelBuilderRegistry;
public class StsModelPlugin implements Plugin<Project> {
private final ToolingModelBuilderRegistry registry;
@Inject
public StsModelPlugin(ToolingModelBuilderRegistry registry) {
this.registry = registry;
}
@Override
public void apply(Project project) {
registry.register(new StsModelBuilder());
}
}

View File

@@ -0,0 +1,17 @@
/*******************************************************************************
* Copyright (c) 2020 Pivotal, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Pivotal, Inc. - initial API and implementation
*******************************************************************************/
package sts.model.plugin;
public interface StsToolingModel {
String version();
String group();
String artifact();
}