Skip to content

Commit 3e845f7

Browse files
committed
Remove eclipse plugin configuration
1 parent 2e4f5fe commit 3e845f7

File tree

3 files changed

+8
-85
lines changed

3 files changed

+8
-85
lines changed

src/main/groovy/com/google/protobuf/gradle/ProtobufPlugin.groovy

+6-5
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,12 @@ class ProtobufPlugin implements Plugin<Project> {
263263
}
264264

265265
postConfigure.add {
266+
// This is required because the intellij/eclipse plugin does not allow adding source directories
267+
// that do not exist. The intellij/eclipse config files should be valid from the start.
268+
generateProtoTask.get().getOutputSourceDirectories().each { File outputDir ->
269+
outputDir.mkdirs()
270+
}
271+
266272
boolean isTest = Utils.isTest(sourceSet.name)
267273
project.plugins.withId("idea") {
268274
protoSrcDirSet.srcDirs.each { File protoDir ->
@@ -274,11 +280,6 @@ class ProtobufPlugin implements Plugin<Project> {
274280
Utils.addToIdeSources(project, isTest, outputDir, true)
275281
}
276282
}
277-
project.plugins.withId("eclipse") {
278-
generateProtoTask.get().getOutputSourceDirectories().each { File outputDir ->
279-
Utils.addToEclipseSources(project, isTest, sourceSet.name, outputDir)
280-
}
281-
}
282283
}
283284
}
284285

src/main/groovy/com/google/protobuf/gradle/Utils.groovy

-78
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,6 @@ import groovy.transform.CompileStatic
3333
import org.apache.commons.lang.StringUtils
3434
import org.gradle.api.Project
3535
import org.gradle.api.tasks.SourceSet
36-
import org.gradle.plugins.ide.eclipse.model.Classpath
37-
import org.gradle.plugins.ide.eclipse.model.ClasspathEntry
38-
import org.gradle.plugins.ide.eclipse.model.EclipseModel
39-
import org.gradle.plugins.ide.eclipse.model.SourceFolder
4036
import org.gradle.plugins.ide.idea.GenerateIdeaModule
4137
import org.gradle.plugins.ide.idea.model.IdeaModel
4238
import org.gradle.util.GUtil
@@ -133,78 +129,4 @@ class Utils {
133129
}
134130
}
135131
}
136-
137-
/**
138-
* Add the the folder of generated source to Eclipse .classpath file.
139-
*/
140-
static void addToEclipseSources(Project project, boolean isTest, String sourceSetName, File f) {
141-
project.plugins.withId("eclipse") {
142-
File projectDir = project.getProjectDir()
143-
144-
EclipseModel model = project.getExtensions().findByType(EclipseModel)
145-
model.classpath.file.whenMerged { Classpath cp ->
146-
// buildship requires the folder exists on disk, otherwise
147-
// it will be ignored when updating classpath file, see:
148-
// https://github.com/eclipse/buildship/issues/1196
149-
f.mkdirs()
150-
151-
String relativePath = projectDir.toURI().relativize(f.toURI()).getPath()
152-
// remove trailing slash
153-
if (relativePath.endsWith("/")) {
154-
relativePath = relativePath[0..(relativePath.length() - 2)]
155-
}
156-
SourceFolder entry = new SourceFolder(relativePath, getOutputPath(cp, sourceSetName))
157-
entry.entryAttributes.put("optional", "true")
158-
entry.entryAttributes.put("ignore_optional_problems", "true")
159-
160-
// this attribute is optional, but it could be useful for IDEs to recognize that it is
161-
// generated source folder from protobuf, thus providing some support for that.
162-
// e.g. Hint user to run generate tasks if the folder is empty or does not exist.
163-
entry.entryAttributes.put("protobuf_generated_source", "true")
164-
165-
// check if output is not null here because test source folder
166-
// must have a separate output folder in Eclipse
167-
if (entry.output != null && isTest) {
168-
entry.entryAttributes.put("test", "true")
169-
}
170-
cp.entries.add(entry)
171-
}
172-
}
173-
}
174-
175-
/**
176-
* Get the output path according to the source set name, if no valid path can be
177-
* found, <code>null</code> will return.
178-
*/
179-
private static String getOutputPath(Classpath classpath, String sourceSetName) {
180-
String path = "bin/" + sourceSetName
181-
if (isValidOutput(classpath, path)) {
182-
return path
183-
}
184-
// fallback to default output
185-
return null
186-
}
187-
188-
/**
189-
* Check if the output path is valid or not.
190-
* See: org.eclipse.jdt.internal.core.ClasspathEntry#validateClasspath()
191-
*/
192-
private static boolean isValidOutput(Classpath classpath, String path) {
193-
Set<String> outputs = []
194-
for (ClasspathEntry cpe : classpath.getEntries()) {
195-
if (cpe instanceof SourceFolder) {
196-
outputs.add(((SourceFolder) cpe).getOutput())
197-
}
198-
}
199-
for (String output : outputs) {
200-
if (Objects.equals(output, path)) {
201-
continue
202-
}
203-
// Eclipse does not allow nested output path
204-
if (output.startsWith(path) || path.startsWith(output)) {
205-
return false
206-
}
207-
}
208-
return true
209-
}
210132
}

src/test/groovy/com/google/protobuf/gradle/IDESupportTest.groovy

+2-2
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,9 @@ class IDESupportTest extends Specification {
119119
if (path.startsWith("build/generated/source/proto")) {
120120
if (path.contains("test")) {
121121
// test source path has one more attribute: ["test"="true"]
122-
assert it.attributes.attribute.size() == 4
123-
} else {
124122
assert it.attributes.attribute.size() == 3
123+
} else {
124+
assert it.attributes.attribute.size() == 2
125125
}
126126
}
127127
}

0 commit comments

Comments
 (0)