IDEA-125174 Linking gradle project fails: java.lang.String is not an interface

This commit is contained in:
Vladislav.Soroka
2016-02-15 16:30:24 +03:00
parent f970df54b3
commit ef6041f120
4 changed files with 145 additions and 13 deletions
@@ -31,6 +31,9 @@ import org.jetbrains.plugins.gradle.tooling.internal.scala.ScalaCompileOptionsIm
import org.jetbrains.plugins.gradle.tooling.internal.scala.ScalaForkOptionsImpl;
import org.jetbrains.plugins.gradle.tooling.internal.scala.ScalaModelImpl;
import java.util.ArrayList;
import java.util.List;
/**
* @author Vladislav.Soroka
* @since 1/31/14
@@ -80,7 +83,7 @@ public class ScalaModelBuilderImpl implements ModelBuilderService {
if (options == null) return null;
ScalaCompileOptionsImpl result = new ScalaCompileOptionsImpl();
result.setAdditionalParameters(options.getAdditionalParameters());
result.setAdditionalParameters(wrapStringList(options.getAdditionalParameters()));
result.setDaemonServer(options.getDaemonServer());
result.setDebugLevel(options.getDebugLevel());
result.setDeprecation(options.isDeprecation());
@@ -92,7 +95,7 @@ public class ScalaModelBuilderImpl implements ModelBuilderService {
result.setListFiles(options.isListFiles());
result.setLoggingLevel(options.getLoggingLevel());
result.setDebugLevel(options.getDebugLevel());
result.setLoggingPhases(options.getLoggingPhases());
result.setLoggingPhases(wrapStringList(options.getLoggingPhases()));
result.setOptimize(options.isOptimize());
result.setUnchecked(options.isUnchecked());
result.setUseAnt(options.isUseAnt());
@@ -101,13 +104,24 @@ public class ScalaModelBuilderImpl implements ModelBuilderService {
return result;
}
@Nullable
private static List<String> wrapStringList(@Nullable List<String> list) {
if (list == null) return null;
List<String> strings = new ArrayList<String>();
for (CharSequence s : list) {
// fix serialization issue if 's' is an instance of groovy.lang.GString [IDEA-125174]
strings.add(s.toString());
}
return strings;
}
@Nullable
@Contract("null -> null")
private static ScalaForkOptionsImpl create(@Nullable ScalaForkOptions forkOptions) {
if (forkOptions == null) return null;
ScalaForkOptionsImpl result = new ScalaForkOptionsImpl();
result.setJvmArgs(forkOptions.getJvmArgs());
result.setJvmArgs(wrapStringList(forkOptions.getJvmArgs()));
result.setMemoryInitialSize(forkOptions.getMemoryInitialSize());
result.setMemoryMaximumSize(forkOptions.getMemoryMaximumSize());
return result;
@@ -0,0 +1,37 @@
/*
* Copyright 2000-2016 JetBrains s.r.o.
*
* 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
*
* http://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.
*/
//noinspection GrPackage
apply plugin: 'scala'
repositories {
maven {
url 'http://maven.labs.intellij.net/repo1'
}
}
Closure compilerPlugins = {
String parjar = "opt"
scalaCompileOptions.additionalParameters = [
"-opt:$parjar"
]
}
dependencies {
compile 'org.scala-lang:scala-library:2.11.0'
}
compileScala compilerPlugins
compileTestScala compilerPlugins
@@ -16,9 +16,9 @@
package org.jetbrains.plugins.gradle.tooling.builder;
import com.google.common.collect.Multimap;
import org.jetbrains.plugins.gradle.model.ExternalProject;
import com.intellij.openapi.util.Pair;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.util.io.StreamUtil;
import com.intellij.testFramework.IdeaTestUtil;
import com.intellij.testFramework.UsefulTestCase;
import com.intellij.util.Function;
@@ -32,11 +32,12 @@ import org.gradle.tooling.model.DomainObjectSet;
import org.gradle.tooling.model.idea.IdeaModule;
import org.gradle.util.GradleVersion;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.plugins.gradle.tooling.VersionMatcherRule;
import org.jetbrains.plugins.gradle.model.BuildScriptClasspathModel;
import org.jetbrains.plugins.gradle.model.ClasspathEntryModel;
import org.jetbrains.plugins.gradle.model.ExternalProject;
import org.jetbrains.plugins.gradle.model.ProjectImportAction;
import org.jetbrains.plugins.gradle.service.execution.GradleExecutionHelper;
import org.jetbrains.plugins.gradle.tooling.VersionMatcherRule;
import org.jetbrains.plugins.gradle.util.GradleConstants;
import org.junit.After;
import org.junit.Before;
@@ -47,6 +48,7 @@ import org.junit.runners.Parameterized;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.*;
@@ -108,15 +110,28 @@ public abstract class AbstractModelBuilderTest {
testDir = new File(ourTempDir, methodName);
FileUtil.ensureExists(testDir);
FileUtil.writeToFile(
new File(testDir, GradleConstants.DEFAULT_SCRIPT_NAME),
FileUtil.loadTextAndClose(getClass().getResourceAsStream("/" + methodName + "/" + GradleConstants.DEFAULT_SCRIPT_NAME))
);
final InputStream buildScriptStream = getClass().getResourceAsStream("/" + methodName + "/" + GradleConstants.DEFAULT_SCRIPT_NAME);
try {
FileUtil.writeToFile(
new File(testDir, GradleConstants.DEFAULT_SCRIPT_NAME),
FileUtil.loadTextAndClose(buildScriptStream)
);
}
finally {
StreamUtil.closeStream(buildScriptStream);
}
FileUtil.writeToFile(
new File(testDir, GradleConstants.SETTINGS_FILE_NAME),
FileUtil.loadTextAndClose(getClass().getResourceAsStream("/" + methodName + "/" + GradleConstants.SETTINGS_FILE_NAME))
);
final InputStream settingsStream = getClass().getResourceAsStream("/" + methodName + "/" + GradleConstants.SETTINGS_FILE_NAME);
try {
if(settingsStream != null) {
FileUtil.writeToFile(
new File(testDir, GradleConstants.SETTINGS_FILE_NAME),
FileUtil.loadTextAndClose(settingsStream)
);
}
} finally {
StreamUtil.closeStream(settingsStream);
}
GradleConnector connector = GradleConnector.newConnector();
@@ -0,0 +1,66 @@
/*
* Copyright 2000-2016 JetBrains s.r.o.
*
* 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
*
* http://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.
*/
package org.jetbrains.plugins.gradle.tooling.builder;
import com.intellij.util.Function;
import com.intellij.util.containers.ContainerUtil;
import org.gradle.tooling.model.DomainObjectSet;
import org.gradle.tooling.model.idea.IdeaModule;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.plugins.gradle.model.scala.ScalaCompileOptions;
import org.jetbrains.plugins.gradle.model.scala.ScalaModel;
import org.junit.Test;
import java.util.List;
import java.util.Set;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
/**
* @author Vladislav.Soroka
* @since 11/29/13
*/
public class ScalaModelBuilderImplTest extends AbstractModelBuilderTest {
public ScalaModelBuilderImplTest(@NotNull String gradleVersion) {
super(gradleVersion);
}
@Test
public void testScalaModel() throws Exception {
DomainObjectSet<? extends IdeaModule> ideaModules = allModels.getIdeaProject().getModules();
List<ScalaModel> scalaModels = ContainerUtil.mapNotNull(ideaModules, new Function<IdeaModule, ScalaModel>() {
@Override
public ScalaModel fun(IdeaModule module) {
return allModels.getExtraProject(module, ScalaModel.class);
}
});
assertEquals(1, scalaModels.size());
ScalaModel scalaModel = scalaModels.get(0);
ScalaCompileOptions scalaCompileOptions = scalaModel.getScalaCompileOptions();
assertNotNull(scalaCompileOptions);
assertEquals(1, scalaCompileOptions.getAdditionalParameters().size());
assertEquals("-opt:opt", scalaCompileOptions.getAdditionalParameters().iterator().next());
}
@Override
protected Set<Class> getModels() {
return ContainerUtil.<Class>set(ScalaModel.class);
}
}