load from .classpath for external compiler (initial)

This commit is contained in:
anna
2012-10-30 12:52:34 +01:00
parent cec377a370
commit bc2e19604a
34 changed files with 1071 additions and 410 deletions
+1
View File
@@ -40,6 +40,7 @@
<module fileurl="file://$PROJECT_DIR$/platform/dvcs/dvcs.iml" filepath="$PROJECT_DIR$/platform/dvcs/dvcs.iml" group="platform" />
<module fileurl="file://$PROJECT_DIR$/plugins/eclipse/eclipse.iml" filepath="$PROJECT_DIR$/plugins/eclipse/eclipse.iml" group="plugins" />
<module fileurl="file://$PROJECT_DIR$/plugins/eclipse/jps-plugin/eclipse-jps-plugin.iml" filepath="$PROJECT_DIR$/plugins/eclipse/jps-plugin/eclipse-jps-plugin.iml" group="plugins" />
<module fileurl="file://$PROJECT_DIR$/plugins/eclipse/common-eclipse-util/common-eclipse-util.iml" filepath="$PROJECT_DIR$/plugins/eclipse/common-eclipse-util/common-eclipse-util.iml" group="plugins" />
<module fileurl="file://$PROJECT_DIR$/java/execution/impl/execution-impl.iml" filepath="$PROJECT_DIR$/java/execution/impl/execution-impl.iml" group="java" />
<module fileurl="file://$PROJECT_DIR$/java/execution/openapi/execution-openapi.iml" filepath="$PROJECT_DIR$/java/execution/openapi/execution-openapi.iml" group="java" />
<module fileurl="file://$PROJECT_DIR$/platform/extensions/extensions.iml" filepath="$PROJECT_DIR$/platform/extensions/extensions.iml" group="platform" />
+3
View File
@@ -398,6 +398,9 @@ public def layoutCommunityPlugins(String home) {
jar("eclipse-jps-plugin.jar") {
module("eclipse-jps-plugin")
}
jar("common-eclipse-util.jar") {
module("common-eclipse-util")
}
}
layoutPlugin("android") {
@@ -47,4 +47,12 @@ public class JpsMacroExpander {
public void substitute(Element element, boolean caseSensitive) {
myExpandMacroMap.substitute(element, caseSensitive);
}
public ExpandMacroToPathMap getExpandMacroMap() {
return myExpandMacroMap;
}
public String substitute(String element, boolean caseSensitive) {
return myExpandMacroMap.substitute(element, caseSensitive);
}
}
@@ -197,12 +197,16 @@ public class JpsProjectLoader extends JpsLoaderBase {
if (componentRoot == null) return;
final Element modules = componentRoot.getChild("modules");
List<Future<JpsModule>> futures = new ArrayList<Future<JpsModule>>();
final List<String> paths = new ArrayList<String>();
for (Element moduleElement : JDOMUtil.getChildren(modules, "module")) {
final String path = moduleElement.getAttributeValue("filepath");
paths.add(path);
}
for (final String path : paths) {
futures.add(ourThreadPool.submit(new Callable<JpsModule>() {
@Override
public JpsModule call() throws Exception {
return loadModule(path, projectSdkType);
return loadModule(path, paths, projectSdkType);
}
}));
}
@@ -220,7 +224,7 @@ public class JpsProjectLoader extends JpsLoaderBase {
}
@Nullable
private JpsModule loadModule(@NotNull String path, @Nullable JpsSdkType<?> projectSdkType) {
private JpsModule loadModule(@NotNull String path, List<String> paths, @Nullable JpsSdkType<?> projectSdkType) {
final File file = new File(path);
String name = FileUtil.getNameWithoutExtension(file);
if (!file.exists()) {
@@ -251,7 +255,7 @@ public class JpsProjectLoader extends JpsLoaderBase {
JpsModuleClasspathSerializer classpathSerializer = extension.getClasspathSerializer();
if (classpathSerializer != null && classpathSerializer.getClasspathId().equals(classpath)) {
String classpathDir = moduleRoot.getAttributeValue(CLASSPATH_DIR_ATTRIBUTE);
classpathSerializer.loadClasspath(module, classpathDir, baseModulePath);
classpathSerializer.loadClasspath(module, classpathDir, baseModulePath, expander, paths);
}
}
}
@@ -3,6 +3,9 @@ package org.jetbrains.jps.model.serialization.module;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jps.model.module.JpsModule;
import org.jetbrains.jps.model.serialization.JpsMacroExpander;
import java.util.List;
/**
* @author nik
@@ -18,5 +21,8 @@ public abstract class JpsModuleClasspathSerializer {
return myClasspathId;
}
public abstract void loadClasspath(@NotNull JpsModule module, @Nullable String classpathDir, @NotNull String baseModulePath);
public abstract void loadClasspath(@NotNull JpsModule module,
@Nullable String classpathDir,
@NotNull String baseModulePath,
JpsMacroExpander expander, List<String> paths);
}
@@ -76,7 +76,7 @@ public class BasePathMacroManager extends PathMacroManager {
return VirtualFileManager.getInstance().getFileSystem(StandardFileSystems.FILE_PROTOCOL);
}
protected ExpandMacroToPathMap getExpandMacroMap() {
public ExpandMacroToPathMap getExpandMacroMap() {
ExpandMacroToPathMap result = new ExpandMacroToPathMap();
for (Map.Entry<String, String> entry : PathMacrosImpl.getGlobalSystemMacros().entrySet()) {
result.addMacroExpand(entry.getKey(), entry.getValue());
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" packagePrefix="org.jetbrains.idea.eclipse" />
</content>
<orderEntry type="jdk" jdkName="IDEA jdk" jdkType="JavaSDK" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module" module-name="util" />
<orderEntry type="library" name="JDOM" level="project" />
<orderEntry type="module" module-name="jps-model-serialization" />
</component>
</module>
@@ -0,0 +1,340 @@
/*
* Copyright 2000-2012 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.idea.eclipse;
import com.intellij.openapi.components.ExpandMacroToPathMap;
import com.intellij.openapi.util.SystemInfo;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.util.text.StringUtil;
import org.jdom.Element;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.io.*;
import java.util.*;
import java.util.jar.Manifest;
import java.util.regex.PatternSyntaxException;
/**
* User: anna
* Date: 10/29/12
*/
public abstract class AbstractEclipseClasspathReader<T> {
protected final String myRootPath;
@Nullable protected final List<String> myCurrentRoots;
@Nullable protected final Set<String> myModuleNames;
public AbstractEclipseClasspathReader(final String rootPath,
@Nullable List<String> currentRoots, @Nullable Set<String> moduleNames) {
myRootPath = FileUtil.toSystemIndependentName(rootPath);
myCurrentRoots = currentRoots;
myModuleNames = moduleNames;
}
protected abstract String prepareValidUrlInsideJar(String url);
protected abstract void addNamedLibrary(T rootModel,
Collection<String> unknownLibraries,
boolean exported,
String name,
boolean applicationLevel);
protected abstract void addInvalidModuleEntry(T rootModel, boolean exported, String moduleName);
protected abstract void setUpModuleJdk(T rootModel,
Collection<String> unknownJdks,
EclipseModuleManager eclipseModuleManager,
String jdkName);
public abstract void setupOutput(T rootModel, String path);
protected abstract void addSourceFolder(T rootModel, String srcUrl, boolean testFolder);
protected abstract void addSourceFolderToCurrentContentRoot(T rootModel, String srcUrl, boolean testFolder);
protected abstract void addJUnitDefaultLib(T rootModel, String junitName);
protected abstract void addModuleLibrary(T rootModel,
Element element,
boolean exported,
String libName,
String url,
String srcUrl, ExpandMacroToPathMap macroMap);
protected abstract String expandEclipsePath2Url(T rootModel, String path);
protected abstract int rearrange(T rootModel);
protected void readClasspathEntry(T rootModel,
final Collection<String> unknownLibraries,
Collection<String> unknownJdks,
final Set<String> usedVariables,
Set<String> refsToModules,
final String testPattern,
Element element, int idx,
final EclipseModuleManager eclipseModuleManager,
final ExpandMacroToPathMap macroMap) throws ConversionException {
String kind = element.getAttributeValue(EclipseXml.KIND_ATTR);
if (kind == null) {
throw new ConversionException("Missing classpathentry/@kind");
}
String path = element.getAttributeValue(EclipseXml.PATH_ATTR);
if (path == null) {
throw new ConversionException("Missing classpathentry/@path");
}
final boolean exported = EclipseXml.TRUE_VALUE.equals(element.getAttributeValue(EclipseXml.EXPORTED_ATTR));
if (kind.equals(EclipseXml.SRC_KIND)) {
if (path.startsWith("/")) {
final String moduleName = path.substring(1);
refsToModules.add(moduleName);
addInvalidModuleEntry(rootModel, exported, moduleName);
}
else {
String srcUrl = pathToUrl(myRootPath + "/" + path);
boolean isTestFolder = false;
try {
isTestFolder = testPattern != null && testPattern.length() > 0 && path.matches(testPattern);
}
catch (PatternSyntaxException e) {
isTestFolder = false;
}
final String linked = expandLinkedResourcesPath(macroMap, usedVariables, path);
if (linked != null) {
srcUrl = pathToUrl(linked);
eclipseModuleManager.registerEclipseLinkedSrcVarPath(srcUrl, path);
addSourceFolder(rootModel, srcUrl, isTestFolder);
}
else {
addSourceFolderToCurrentContentRoot(rootModel, srcUrl, isTestFolder);
}
eclipseModuleManager.setExpectedModuleSourcePlace(rearrange(rootModel));
eclipseModuleManager.registerSrcPlace(srcUrl, idx);
}
}
else if (kind.equals(EclipseXml.OUTPUT_KIND)) {
String output = myRootPath + "/" + path;
final String linked = expandLinkedResourcesPath(macroMap, usedVariables, path);
if (linked != null) {
output = linked;
eclipseModuleManager.registerEclipseLinkedVarPath(pathToUrl(output), path);
}
setupOutput(rootModel, output);
}
else if (kind.equals(EclipseXml.LIB_KIND)) {
final String libName = getPresentableName(path);
final String linked = expandLinkedResourcesPath(macroMap, usedVariables, path);
final String url;
if (linked != null) {
url = pathToUrl(linked);
eclipseModuleManager.registerEclipseLinkedVarPath(url, path);
}
else {
url = expandEclipsePath2Url(rootModel, path);
}
eclipseModuleManager.registerEclipseLibUrl(url);
final String sourcePath = element.getAttributeValue(EclipseXml.SOURCEPATH_ATTR);
String srcUrl = null;
if (sourcePath != null) {
final String linkedSrc = expandLinkedResourcesPath(macroMap, usedVariables, sourcePath);
if (linkedSrc != null) {
srcUrl = pathToUrl(linkedSrc);
eclipseModuleManager.registerEclipseLinkedSrcVarPath(srcUrl, sourcePath);
}
else {
srcUrl = expandEclipsePath2Url(rootModel, sourcePath);
}
}
addModuleLibrary(rootModel, element, exported, libName, url, srcUrl, macroMap);
}
else if (kind.equals(EclipseXml.VAR_KIND)) {
int slash = path.indexOf("/");
if (slash == 0) {
throw new ConversionException("Incorrect 'classpathentry/var@path' format");
}
final String libName = getPresentableName(path);
final String url = eclipseVariabledPath2Url(macroMap, usedVariables, path, 0);
eclipseModuleManager.registerEclipseVariablePath(url, path);
final String srcPathAttr = element.getAttributeValue(EclipseXml.SOURCEPATH_ATTR);
String srcUrl = null;
if (srcPathAttr != null) {
srcUrl = eclipseVariabledPath2Url(macroMap, usedVariables, srcPathAttr, srcVarStart(srcPathAttr));
eclipseModuleManager.registerEclipseSrcVariablePath(srcUrl, srcPathAttr);
}
addModuleLibrary(rootModel, element, exported, libName, url, srcUrl, macroMap);
}
else if (kind.equals(EclipseXml.CON_KIND)) {
if (path.equals(EclipseXml.ECLIPSE_PLATFORM)) {
readRequiredBundles(rootModel, refsToModules);
addNamedLibrary(rootModel, unknownLibraries, exported, IdeaXml.ECLIPSE_LIBRARY, true);
}
else if (path.startsWith(EclipseXml.JRE_CONTAINER)) {
final String jdkName = getLastPathComponent(path);
setUpModuleJdk(rootModel, unknownJdks, eclipseModuleManager, jdkName);
}
else if (path.startsWith(EclipseXml.USER_LIBRARY)) {
addNamedLibrary(rootModel, unknownLibraries, exported, getPresentableName(path), false);
}
else if (path.startsWith(EclipseXml.JUNIT_CONTAINER)) {
final String junitName = IdeaXml.JUNIT + getPresentableName(path);
addJUnitDefaultLib(rootModel, junitName);
}
else if (path.equals(EclipseXml.GROOVY_DSL_CONTAINER)) {
eclipseModuleManager.setGroovyDslSupport();
eclipseModuleManager.registerSrcPlace(EclipseXml.GROOVY_DSL_CONTAINER, idx);
}
else {
eclipseModuleManager.registerUnknownCons(path);
addNamedLibrary(rootModel, new ArrayList<String>(), exported, path, true);
}
}
else {
throw new ConversionException("Unknown classpathentry/@kind: " + kind);
}
}
protected static int srcVarStart(String srcPath) {
return srcPath.startsWith("/") ? 1 : 0;
}
@NotNull
protected static String getPresentableName(@NotNull String path) {
final String pathComponent = getLastPathComponent(path);
return pathComponent != null ? pathComponent : path;
}
@Nullable
public static String getLastPathComponent(final String path) {
final int idx = path.lastIndexOf('/');
return idx < 0 || idx == path.length() - 1 ? null : path.substring(idx + 1);
}
protected static String getVariableRelatedPath(String var, String path) {
return var == null ? null : ("$" + var + "$" + (path == null ? "" : ("/" + path)));
}
protected static String pathToUrl(String path) {
return "file://" + path;
}
protected static EPathVariable createEPathVariable(final Set<String> usedVariables, final String pathAttr, final int varStart) {
final EPathVariable var;
int slash = pathAttr.indexOf("/", varStart);
if (slash > 0) {
var = new EPathVariable(usedVariables, pathAttr.substring(varStart, slash), pathAttr.substring(slash + 1));
}
else {
var = new EPathVariable(usedVariables, pathAttr.substring(varStart), null);
}
return var;
}
protected String eclipseVariabledPath2Url(ExpandMacroToPathMap pathMap, Set<String> usedVariables, String path, int varStart) {
final EPathVariable var = createEPathVariable(usedVariables, path, varStart);
final String url = pathMap.substitute(var.toIdeaVariabledUrl(), SystemInfo.isFileSystemCaseSensitive);
return prepareValidUrlInsideJar(url);
}
@Nullable
protected String expandLinkedResourcesPath(final ExpandMacroToPathMap macroMap,
final Set<String> usedVariables,
final String path) {
final EclipseProjectFinder.LinkedResource linkedResource = EclipseProjectFinder.findLinkedResource(myRootPath, path);
if (linkedResource != null) {
if (linkedResource.containsPathVariable()) {
usedVariables.add(linkedResource.getVariableName());
}
if (linkedResource.containsPathVariable()) {
final String toPathVariableFormat =
getVariableRelatedPath(linkedResource.getVariableName(), linkedResource.getRelativeToVariablePath());
return macroMap.substitute(toPathVariableFormat, SystemInfo.isFileSystemCaseSensitive);
}
return linkedResource.getLocation();
}
return null;
}
protected void readRequiredBundles(T rootModel, Set<String> refsToModules) throws ConversionException {
if (myModuleNames == null) {
return;
}
final File manifestFile = new File(myRootPath, "META-INF/MANIFEST.MF");
if (!manifestFile.exists()) {
return;
}
InputStream in = null;
try {
in = new BufferedInputStream(new FileInputStream(manifestFile));
final Manifest manifest = new Manifest(in);
final String attributes = manifest.getMainAttributes().getValue("Require-Bundle");
if (!StringUtil.isEmpty(attributes)) {
final StringTokenizer tokenizer = new StringTokenizer(attributes, ",");
while (tokenizer.hasMoreTokens()) {
String bundle = tokenizer.nextToken().trim();
if (!bundle.isEmpty()) {
final int constraintIndex = bundle.indexOf(';');
if (constraintIndex != -1) {
bundle = bundle.substring(0, constraintIndex).trim();
}
if (myModuleNames.contains(bundle)) {
refsToModules.add(bundle);
addInvalidModuleEntry(rootModel, false, bundle);
}
}
}
}
}
catch (IOException e) {
throw new ConversionException(e.getMessage());
}
finally {
if (in != null) {
try {
in.close();
}
catch (IOException ignored) {
}
}
}
}
protected static class EPathVariable {
private final String myVariable;
private final String myRelatedPath;
protected EPathVariable(final Set<String> usedVariables, final String variable, final String relatedPath) {
myVariable = variable;
myRelatedPath = relatedPath;
usedVariables.add(myVariable);
}
public String toIdeaVariabledUrl() {
return pathToUrl(getVariableRelatedPath(myVariable, myRelatedPath));
}
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* Copyright 2000-2012 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.
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.idea.eclipse.conversion;
package org.jetbrains.idea.eclipse;
import java.text.MessageFormat;
@@ -0,0 +1,72 @@
/*
* Copyright 2000-2012 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.idea.eclipse;
import com.intellij.openapi.util.Comparing;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.io.File;
import java.util.List;
/**
* User: anna
* Date: 10/29/12
*/
public class EPathCommonUtil {
/**
* @param path path in format /module_root/relative_path
* @return module_root
*/
@NotNull
public static String getRelativeModuleName(String path) {
int secondSlIdx = path.indexOf('/', 1);
return secondSlIdx > 1 ? path.substring(1, secondSlIdx) : path.substring(1);
}
/**
* @param path path in format /module_root/relative_path
* @return relative_path or null if /module_root
*/
@Nullable
public static String getRelativeToModulePath(String path) {
final int secondSlIdx = path.indexOf('/', 1);
return secondSlIdx != -1 && secondSlIdx + 1 < path.length() ? path.substring(secondSlIdx + 1) : null;
}
@Nullable
public static String expandEclipseRelative2ContentRoots(final @NotNull List<String> currentRoots,
final @NotNull String rootPath,
final @Nullable String relativeToRootPath) {
for (String currentRoot : currentRoots) {
if (currentRoot.endsWith(rootPath)
|| Comparing.strEqual(rootPath, EclipseProjectFinder.findProjectName(currentRoot))) { //rootPath = content_root <=> applicable root: abs_path/content_root
if (relativeToRootPath == null) {
return pathToUrl(currentRoot);
}
final File relativeToOtherModuleFile = new File(currentRoot, relativeToRootPath);
if (relativeToOtherModuleFile.exists()) {
return pathToUrl(relativeToOtherModuleFile.getPath());
}
}
}
return null;
}
public static String pathToUrl(String path) {
return "file://" + path;
}
}
@@ -0,0 +1,177 @@
/*
* Copyright 2000-2012 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.idea.eclipse;
import org.jetbrains.annotations.Nullable;
import java.util.Set;
/**
* User: anna
* Date: 10/29/12
*/
public interface EclipseModuleManager {
void setInvalidJdk(String invalidJdk);
@Nullable
String getInvalidJdk();
void setGroovyDslSupport();
boolean isGroovyDslSupport();
void registerEclipseVariablePath(String path, String var);
void registerEclipseSrcVariablePath(String path, String var);
void registerEclipseLinkedSrcVarPath(String path, String var);
@Nullable
String getEclipseLinkedSrcVariablePath(String path);
void registerEclipseLinkedVarPath(String path, String var);
@Nullable
String getEclipseLinkedVarPath(String path);
@Nullable
String getEclipseVariablePath(String path);
@Nullable
String getEclipseSrcVariablePath(String path);
void registerUnknownCons(String con);
@Nullable
Set<String> getUnknownCons();
boolean isForceConfigureJDK();
void setForceConfigureJDK();
void registerEclipseLibUrl(String url);
boolean isEclipseLibUrl(String url);
void setExpectedModuleSourcePlace(int expectedModuleSourcePlace);
boolean isExpectedModuleSourcePlace(int expectedPlace);
void registerSrcPlace(String srcUrl, int placeIdx);
@Nullable
Integer getSrcPlace(String srcUtl);
EclipseModuleManager EMPTY = new EclipseModuleManager() {
@Override
public void setInvalidJdk(String invalidJdk) {}
@Nullable
@Override
public String getInvalidJdk() {
return null;
}
@Override
public void setGroovyDslSupport() {}
@Override
public boolean isGroovyDslSupport() {
return false;
}
@Override
public void registerEclipseVariablePath(String path, String var) {}
@Override
public void registerEclipseSrcVariablePath(String path, String var) {}
@Override
public void registerEclipseLinkedSrcVarPath(String path, String var) {}
@Nullable
@Override
public String getEclipseLinkedSrcVariablePath(String path) {
return null;
}
@Override
public void registerEclipseLinkedVarPath(String path, String var) {
}
@Nullable
@Override
public String getEclipseLinkedVarPath(String path) {
return null;
}
@Nullable
@Override
public String getEclipseVariablePath(String path) {
return null;
}
@Nullable
@Override
public String getEclipseSrcVariablePath(String path) {
return null;
}
@Override
public void registerUnknownCons(String con) {}
@Nullable
@Override
public Set<String> getUnknownCons() {
return null;
}
@Override
public boolean isForceConfigureJDK() {
return false;
}
@Override
public void setForceConfigureJDK() {}
@Override
public void registerEclipseLibUrl(String url) {}
@Override
public boolean isEclipseLibUrl(String url) {
return false;
}
@Override
public void setExpectedModuleSourcePlace(int expectedModuleSourcePlace) {
}
@Override
public boolean isExpectedModuleSourcePlace(int expectedPlace) {
return false;
}
@Override
public void registerSrcPlace(String srcUrl, int placeIdx) {
}
@Nullable
@Override
public Integer getSrcPlace(String srcUtl) {
return null;
}
};
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* Copyright 2000-2012 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.
@@ -18,29 +18,25 @@
* User: anna
* Date: 11-Nov-2008
*/
package org.jetbrains.idea.eclipse.importWizard;
package org.jetbrains.idea.eclipse;
import com.intellij.openapi.progress.ProgressIndicator;
import com.intellij.openapi.progress.ProgressManager;
import com.intellij.openapi.util.Comparing;
import com.intellij.openapi.util.JDOMUtil;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.util.Processor;
import org.jdom.Element;
import org.jdom.JDOMException;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.idea.eclipse.EclipseXml;
import java.io.File;
import java.io.IOException;
import java.util.List;
public class EclipseProjectFinder implements EclipseXml {
public static void findModuleRoots(final List<String> paths, final String rootPath) {
final ProgressIndicator progressIndicator = ProgressManager.getInstance().getProgressIndicator();
if (progressIndicator != null) {
if (progressIndicator.isCanceled()) return;
progressIndicator.setText2(rootPath);
public static void findModuleRoots(final List<String> paths, final String rootPath, @Nullable Processor<String> progressUpdater) {
if (progressUpdater != null) {
progressUpdater.process(rootPath);
}
final String project = findProjectName(rootPath);
@@ -53,7 +49,7 @@ public class EclipseProjectFinder implements EclipseXml {
final File[] files = root.listFiles();
if (files != null) {
for (File file : files) {
findModuleRoots(paths, file.getPath());
findModuleRoots(paths, file.getPath(), progressUpdater);
}
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* Copyright 2000-2012 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.
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* Copyright 2000-2012 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.
+1
View File
@@ -20,6 +20,7 @@
<orderEntry type="module" module-name="annotations" />
<orderEntry type="module" module-name="java-impl" />
<orderEntry type="module" module-name="eclipse-jps-plugin" />
<orderEntry type="module" module-name="common-eclipse-util" />
</component>
</module>
@@ -10,6 +10,7 @@
<orderEntry type="module" module-name="util" />
<orderEntry type="module" module-name="jps-model-api" />
<orderEntry type="module" module-name="jps-model-serialization" />
<orderEntry type="module" module-name="common-eclipse-util" />
</component>
</module>
@@ -0,0 +1,230 @@
/*
* Copyright 2000-2012 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.jps.eclipse.model;
import com.intellij.openapi.components.ExpandMacroToPathMap;
import com.intellij.openapi.util.SystemInfo;
import com.intellij.util.containers.HashSet;
import org.jdom.Element;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.idea.eclipse.*;
import org.jetbrains.jps.model.JpsElementFactory;
import org.jetbrains.jps.model.JpsModel;
import org.jetbrains.jps.model.JpsProject;
import org.jetbrains.jps.model.java.*;
import org.jetbrains.jps.model.library.JpsLibrary;
import org.jetbrains.jps.model.library.JpsOrderRootType;
import org.jetbrains.jps.model.module.*;
import org.jetbrains.jps.model.serialization.JpsMacroExpander;
import org.jetbrains.jps.model.serialization.library.JpsSdkTableSerializer;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Set;
/**
* User: anna
* Date: 10/29/12
*/
class JpsEclipseClasspathReader extends AbstractEclipseClasspathReader<JpsModule> {
public JpsEclipseClasspathReader(String rootPath, @Nullable List<String> currentRoots, @Nullable Set<String> moduleNames) {
super(rootPath, currentRoots, moduleNames);
}
@Override
protected String prepareValidUrlInsideJar(String url) {
if (url.contains("!")) {
return url.substring(0, url.indexOf("!"));//todo
}
return url;
}
@Override
protected void addNamedLibrary(JpsModule rootModel,
Collection<String> unknownLibraries,
boolean exported,
String name,
boolean applicationLevel) {
JpsLibrary lib = findLibraryByName(rootModel.getProject(), name);
if (lib != null) {
final JpsLibraryDependency dependency = rootModel.getDependenciesList().addLibraryDependency(lib);
setLibraryEntryExported(exported, dependency);
}
}
@Override
protected void addInvalidModuleEntry(JpsModule rootModel, boolean exported, String moduleName) {
final JpsElementFactory elementFactory = JpsElementFactory.getInstance();
final JpsDependenciesList dependenciesList = rootModel.getDependenciesList();
final JpsModuleDependency dependency = dependenciesList.addModuleDependency(elementFactory.createModuleReference(moduleName));
final JpsJavaDependencyExtension extension = getService().getOrCreateDependencyExtension(dependency);
extension.setExported(exported);
}
@Override
protected void setUpModuleJdk(JpsModule rootModel,
Collection<String> unknownJdks,
EclipseModuleManager eclipseModuleManager,
String jdkName) {
if (jdkName == null) {
final JpsDependenciesList dependenciesList = rootModel.getDependenciesList();
dependenciesList.addSdkDependency(JpsJavaSdkType.INSTANCE);
}
else {
JpsSdkTableSerializer.setSdkReference(rootModel.getSdkReferencesTable(), jdkName, JpsJavaSdkType.INSTANCE);
}
}
@Override
protected void addSourceFolder(JpsModule rootModel, String srcUrl, boolean testFolder) {
rootModel.addSourceRoot(srcUrl, testFolder ? JavaSourceRootType.TEST_SOURCE : JavaSourceRootType.SOURCE);
}
@Override
protected void addSourceFolderToCurrentContentRoot(JpsModule rootModel, String srcUrl, boolean testFolder) {
rootModel.addSourceRoot(srcUrl, testFolder ? JavaSourceRootType.TEST_SOURCE : JavaSourceRootType.SOURCE);
}
@Override
protected void addJUnitDefaultLib(JpsModule rootModel, String junitName) {
//To change body of implemented methods use File | Settings | File Templates.
}
@Override
protected void addModuleLibrary(JpsModule rootModel,
Element element,
boolean exported,
String libName,
String url,
String srcUrl,
ExpandMacroToPathMap macroMap) {
final JpsLibrary jpsLibrary = rootModel.addModuleLibrary(libName, JpsJavaLibraryType.INSTANCE);
final JpsDependenciesList dependenciesList = rootModel.getDependenciesList();
final JpsLibraryDependency dependency = dependenciesList.addLibraryDependency(jpsLibrary);
final String linked = expandLinkedResourcesPath(url, macroMap);
if (linked != null) {
url = pathToUrl(linked);
}
else {
url = expandEclipsePath2Url(rootModel, url);
}
jpsLibrary.addRoot(url, JpsOrderRootType.COMPILED);
setLibraryEntryExported(exported, dependency);
}
@Override
protected String expandEclipsePath2Url(JpsModule rootModel, String path) {
String url = null;
if (new File(path).exists()) { //absolute path
url = pathToUrl(path);
}
else {
final String relativePath = new File(myRootPath, path).getPath(); //inside current project
final File file = new File(relativePath);
if (file.exists()) {
url = pathToUrl(relativePath);
}
else if (path.startsWith("/")) { //relative to other project
final String moduleName = EPathCommonUtil.getRelativeModuleName(path);
final String relativeToRootPath = EPathCommonUtil.getRelativeToModulePath(path);
url = EPathCommonUtil.expandEclipseRelative2ContentRoots(myCurrentRoots, moduleName, relativeToRootPath);
}
}
if (url == null) {
url = pathToUrl(path);
}
return prepareValidUrlInsideJar(url);
}
@Override
protected int rearrange(JpsModule rootModel) {
return 0;
}
public void readClasspath(JpsModule model,
final String testPattern,
Element classpathElement, JpsMacroExpander expander) throws IOException {
for (Object o : classpathElement.getChildren(EclipseXml.CLASSPATHENTRY_TAG)) {
try {
readClasspathEntry(model, new ArrayList<String>(), new ArrayList<String>(), new HashSet<String>(), new HashSet<String>(),
testPattern, (Element)o, 0, EclipseModuleManager.EMPTY, expander.getExpandMacroMap());
}
catch (ConversionException e) {
throw new IOException(e);
}
}
boolean foundSdkDependency = false;
for (JpsDependencyElement element : model.getDependenciesList().getDependencies()) {
if (element instanceof JpsSdkDependency) {
foundSdkDependency = true;
break;
}
}
if (!foundSdkDependency) {
model.getDependenciesList().addSdkDependency(JpsJavaSdkType.INSTANCE);
}
}
@Nullable
private String expandLinkedResourcesPath(final String path, ExpandMacroToPathMap expander) {
final EclipseProjectFinder.LinkedResource linkedResource = EclipseProjectFinder.findLinkedResource(myRootPath, path);
if (linkedResource != null) {
if (linkedResource.containsPathVariable()) {
final String toPathVariableFormat =
getVariableRelatedPath(linkedResource.getVariableName(), linkedResource.getRelativeToVariablePath());
return expander.substitute(toPathVariableFormat, SystemInfo.isFileSystemCaseSensitive);
}
return linkedResource.getLocation();
}
return null;
}
public void setupOutput(JpsModule rootModel, final String path) {
final JpsJavaModuleExtension extension = getService().getOrCreateModuleExtension(rootModel);
extension.setOutputUrl(pathToUrl(path));
extension.setInheritOutput(false);
}
private static void setLibraryEntryExported(boolean exported,
final JpsDependencyElement dependency) {
final JpsJavaDependencyExtension extension = getService().getOrCreateDependencyExtension(dependency);
extension.setExported(exported);
}
public static JpsLibrary findLibraryByName(JpsProject project, String name) {
JpsLibrary lib = project.getLibraryCollection().findLibrary(name);
if (lib == null) {
final JpsModel model = JpsElementFactory.getInstance().createModel();
lib = model.getGlobal().getLibraryCollection().findLibrary(name);
}
return lib;
}
private static JpsJavaExtensionService getService() {
return JpsJavaExtensionService.getInstance();
}
}
@@ -1,11 +1,19 @@
package org.jetbrains.jps.eclipse.model;
import com.intellij.openapi.util.JDOMUtil;
import com.intellij.util.containers.HashSet;
import org.jdom.Document;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.idea.eclipse.EclipseXml;
import org.jetbrains.jps.model.module.JpsModule;
import org.jetbrains.jps.model.serialization.JpsMacroExpander;
import org.jetbrains.jps.model.serialization.module.JpsModuleClasspathSerializer;
import java.io.File;
import java.util.List;
/**
* @author nik
*/
@@ -17,6 +25,17 @@ public class JpsEclipseClasspathSerializer extends JpsModuleClasspathSerializer
}
@Override
public void loadClasspath(@NotNull JpsModule module, @Nullable String classpathDir, @NotNull String baseModulePath) {
public void loadClasspath(@NotNull JpsModule module,
@Nullable String classpathDir,
@NotNull String baseModulePath,
JpsMacroExpander expander, List<String> paths) {
try {
final Document document = JDOMUtil.loadDocument(new File(classpathDir, EclipseXml.DOT_CLASSPATH_EXT));
final JpsEclipseClasspathReader reader = new JpsEclipseClasspathReader(baseModulePath, paths, new HashSet<String>());
reader.readClasspath(module, null, document.getRootElement(), expander);//todo
}
catch (Exception e) {
e.printStackTrace();
}
}
}
@@ -7,6 +7,7 @@
<extensions defaultExtensionNs="com.intellij">
<classpathStorageProvider implementation="org.jetbrains.idea.eclipse.config.EclipseClasspathStorageProvider"/>
<compileServer.plugin classpath="eclipse-jps-plugin.jar"/>
<compileServer.plugin classpath="common-eclipse-util.jar"/>
<projectImportProvider implementation="org.jetbrains.idea.eclipse.importWizard.EclipseProjectImportProvider"/>
<projectOpenProcessor id="EclipseProjectOpenProcessor" implementation="org.jetbrains.idea.eclipse.importWizard.EclipseProjectOpenProcessor"/>
<projectImportBuilder implementation="org.jetbrains.idea.eclipse.importWizard.EclipseImportBuilder"/>
@@ -16,7 +17,7 @@
</extensions>
<module-components>
<component>
<implementation-class>org.jetbrains.idea.eclipse.config.EclipseModuleManager</implementation-class>
<implementation-class>org.jetbrains.idea.eclipse.config.EclipseModuleManagerImpl</implementation-class>
</component>
</module-components>
<actions>
@@ -35,9 +35,7 @@ import org.jdom.Element;
import org.jdom.JDOMException;
import org.jetbrains.annotations.Nls;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.idea.eclipse.EclipseBundle;
import org.jetbrains.idea.eclipse.EclipseXml;
import org.jetbrains.idea.eclipse.IdeaXml;
import org.jetbrains.idea.eclipse.*;
import org.jetbrains.idea.eclipse.conversion.*;
import org.jetbrains.jps.eclipse.model.JpsEclipseClasspathSerializer;
@@ -98,7 +96,7 @@ public class EclipseClasspathStorageProvider implements ClasspathStorageProvider
}
public void detach(Module module) {
EclipseModuleManager.getInstance(module).setDocumentSet(null);
EclipseModuleManagerImpl.getInstance(module).setDocumentSet(null);
}
public ClasspathConverter createConverter(Module module) {
@@ -113,7 +111,7 @@ public class EclipseClasspathStorageProvider implements ClasspathStorageProvider
@Override
public void modulePathChanged(Module module, String path) {
final EclipseModuleManager moduleManager = EclipseModuleManager.getInstance(module);
final EclipseModuleManagerImpl moduleManager = EclipseModuleManagerImpl.getInstance(module);
if (moduleManager != null) {
moduleManager.setDocumentSet(null);
}
@@ -130,7 +128,7 @@ public class EclipseClasspathStorageProvider implements ClasspathStorageProvider
}
static CachedXmlDocumentSet getFileCache(final Module module) {
final EclipseModuleManager moduleManager = EclipseModuleManager.getInstance(module);
final EclipseModuleManagerImpl moduleManager = EclipseModuleManagerImpl.getInstance(module);
CachedXmlDocumentSet fileCache = moduleManager != null ? moduleManager.getDocumentSet() : null;
if (fileCache == null) {
fileCache = new CachedXmlDocumentSet(module.getProject());
@@ -198,7 +196,7 @@ public class EclipseClasspathStorageProvider implements ClasspathStorageProvider
documentSet.read(EclipseXml.CLASSPATH_FILE).getRootElement());
}
else {
EclipseClasspathReader.setupOutput(model, path + "/bin");
EclipseClasspathReader.setOutputUrl(model, path + "/bin");
}
final String eml = model.getModule().getName() + EclipseXml.IDEA_SETTINGS_POSTFIX;
if (documentSet.exists(eml)) {
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2010 JetBrains s.r.o.
* Copyright 2000-2012 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.
@@ -25,6 +25,7 @@ import com.intellij.openapi.roots.impl.storage.ClasspathStorage;
import com.intellij.openapi.util.text.StringUtil;
import org.jdom.Element;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.idea.eclipse.EclipseModuleManager;
import org.jetbrains.jps.eclipse.model.JpsEclipseClasspathSerializer;
import java.util.LinkedHashMap;
@@ -40,7 +41,7 @@ import java.util.Set;
)
}
)
public class EclipseModuleManager implements PersistentStateComponent<Element>{
public class EclipseModuleManagerImpl implements EclipseModuleManager, PersistentStateComponent<Element> {
@NonNls private static final String VALUE_ATTR = "value";
@NonNls private static final String VARELEMENT = "varelement";
@NonNls private static final String VAR_ATTRIBUTE = "var";
@@ -65,28 +66,32 @@ public class EclipseModuleManager implements PersistentStateComponent<Element>{
private String myInvalidJdk;
private boolean myGroovyDslSupport = false;
public EclipseModuleManager(Module module) {
public EclipseModuleManagerImpl(Module module) {
myModule = module;
}
@Override
public void setInvalidJdk(String invalidJdk) {
myInvalidJdk = invalidJdk;
}
@Override
public String getInvalidJdk() {
return myInvalidJdk;
}
@Override
public void setGroovyDslSupport() {
myGroovyDslSupport = true;
}
@Override
public boolean isGroovyDslSupport() {
return myGroovyDslSupport;
}
public static EclipseModuleManager getInstance(Module module) {
return ModuleServiceManager.getService(module, EclipseModuleManager.class);
public static EclipseModuleManagerImpl getInstance(Module module) {
return ModuleServiceManager.getService(module, EclipseModuleManagerImpl.class);
}
public CachedXmlDocumentSet getDocumentSet() {
@@ -97,63 +102,78 @@ public class EclipseModuleManager implements PersistentStateComponent<Element>{
myDocumentSet = documentSet;
}
@Override
public void registerEclipseVariablePath(String path, String var) {
myEclipseVariablePaths.put(path, var);
}
@Override
public void registerEclipseSrcVariablePath(String path, String var) {
myEclipseVariablePaths.put(SRC_PREFIX + path, var);
}
@Override
public void registerEclipseLinkedSrcVarPath(String path, String var) {
myEclipseVariablePaths.put(SRC_LINK_PREFIX + path, var);
}
@Override
public String getEclipseLinkedSrcVariablePath(String path) {
return myEclipseVariablePaths.get(SRC_LINK_PREFIX + path);
}
@Override
public void registerEclipseLinkedVarPath(String path, String var) {
myEclipseVariablePaths.put(LINK_PREFIX + path, var);
}
@Override
public String getEclipseLinkedVarPath(String path) {
return myEclipseVariablePaths.get(LINK_PREFIX + path);
}
@Override
public String getEclipseVariablePath(String path) {
return myEclipseVariablePaths.get(path);
}
@Override
public String getEclipseSrcVariablePath(String path) {
return myEclipseVariablePaths.get(SRC_PREFIX + path);
}
@Override
public void registerUnknownCons(String con) {
myUnknownCons.add(con);
}
@Override
public Set<String> getUnknownCons() {
return myUnknownCons;
}
@Override
public boolean isForceConfigureJDK() {
return myForceConfigureJDK;
}
@Override
public void setForceConfigureJDK() {
myForceConfigureJDK = true;
myExpectedModuleSourcePlace++;
}
@Override
public void registerEclipseLibUrl(String url) {
myEclipseUrls.add(url);
}
@Override
public boolean isEclipseLibUrl(String url) {
return myEclipseUrls.contains(url);
}
@Override
public Element getState() {
if (!ClasspathStorage.getStorageType(myModule).equals(JpsEclipseClasspathSerializer.CLASSPATH_STORAGE_ID)) {
if (!myEclipseUrls.isEmpty() || !myEclipseVariablePaths.isEmpty() || myForceConfigureJDK || !myUnknownCons.isEmpty()) {
@@ -207,6 +227,7 @@ public class EclipseModuleManager implements PersistentStateComponent<Element>{
return null;
}
@Override
public void loadState(Element state) {
clear();
@@ -242,18 +263,22 @@ public class EclipseModuleManager implements PersistentStateComponent<Element>{
mySrcPlace.clear();
}
@Override
public void setExpectedModuleSourcePlace(int expectedModuleSourcePlace) {
myExpectedModuleSourcePlace = expectedModuleSourcePlace;
}
@Override
public boolean isExpectedModuleSourcePlace(int expectedPlace) {
return myExpectedModuleSourcePlace == expectedPlace;
}
@Override
public void registerSrcPlace(String srcUrl, int placeIdx) {
mySrcPlace.put(srcUrl, placeIdx);
}
@Override
public Integer getSrcPlace(String srcUtl) {
return mySrcPlace.get(srcUtl);
}
@@ -36,6 +36,7 @@ import com.intellij.openapi.vfs.*;
import com.intellij.openapi.vfs.ex.http.HttpFileSystem;
import org.jdom.Element;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.idea.eclipse.EPathCommonUtil;
import java.io.File;
import java.util.ArrayList;
@@ -99,8 +100,8 @@ public class EJavadocUtil {
return VirtualFileManager.constructUrl(JarFileSystem.PROTOCOL, currentModulePath);
}
else {
final String moduleName = getRelativeModuleName(relativeToPlatform);
final String relativeToModulePathWithJarSuffix = getRelativeToModulePath(relativeToPlatform);
final String moduleName = EPathCommonUtil.getRelativeModuleName(relativeToPlatform);
final String relativeToModulePathWithJarSuffix = EPathCommonUtil.getRelativeToModulePath(relativeToPlatform);
final String relativeToModulePath = stripPathInsideJar(relativeToModulePathWithJarSuffix);
final Module otherModule = ModuleManager.getInstance(model.getModule().getProject()).findModuleByName(moduleName);
String url = null;
@@ -108,7 +109,7 @@ public class EJavadocUtil {
url = expandEclipseRelative2OtherModule(otherModule, relativeToModulePath);
}
else if (currentRoots != null) {
url = expandEclipseRelative2ContentRoots(currentRoots, moduleName, relativeToModulePath);
url = EPathCommonUtil.expandEclipseRelative2ContentRoots(currentRoots, moduleName, relativeToModulePath);
}
if (url != null) {
@@ -34,8 +34,9 @@ import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.vfs.*;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.idea.eclipse.EPathCommonUtil;
import org.jetbrains.idea.eclipse.EclipseXml;
import org.jetbrains.idea.eclipse.importWizard.EclipseProjectFinder;
import org.jetbrains.idea.eclipse.EclipseProjectFinder;
import java.io.File;
import java.util.List;
@@ -47,37 +48,17 @@ public class EPathUtil {
private EPathUtil() {
}
/**
* @param path path in format /module_root/relative_path
* @return module_root
*/
@NotNull
public static String getRelativeModuleName(String path) {
int secondSlIdx = path.indexOf('/', 1);
return secondSlIdx > 1 ? path.substring(1, secondSlIdx) : path.substring(1);
}
/**
* @param path path in format /module_root/relative_path
* @return relative_path or null if /module_root
*/
@Nullable
public static String getRelativeToModulePath(String path) {
final int secondSlIdx = path.indexOf('/', 1);
return secondSlIdx != -1 && secondSlIdx + 1 < path.length() ? path.substring(secondSlIdx + 1) : null;
}
public static boolean areUrlsPointTheSame(String ideaUrl, String eclipseUrl) {
final String path = VfsUtil.urlToPath(eclipseUrl);
final String path = VfsUtilCore.urlToPath(eclipseUrl);
if (ideaUrl.contains(path)) {
return true;
}
else {
final String relativeToModulePath = getRelativeToModulePath(path);
final String relativeToModulePath = EPathCommonUtil.getRelativeToModulePath(path);
final int relativeIdx = ideaUrl.indexOf(relativeToModulePath);
if (relativeIdx != -1) {
final String pathToProjectFile = VfsUtil.urlToPath(ideaUrl.substring(0, relativeIdx));
if (Comparing.strEqual(getRelativeModuleName(path),
final String pathToProjectFile = VfsUtilCore.urlToPath(ideaUrl.substring(0, relativeIdx));
if (Comparing.strEqual(EPathCommonUtil.getRelativeModuleName(path),
EclipseProjectFinder.findProjectName(pathToProjectFile))) {
return true;
}
@@ -86,25 +67,6 @@ public class EPathUtil {
return false;
}
@Nullable
static String expandEclipseRelative2ContentRoots(final @NotNull List<String> currentRoots,
final @NotNull String rootPath,
final @Nullable String relativeToRootPath) {
for (String currentRoot : currentRoots) {
if (currentRoot.endsWith(rootPath)
|| Comparing.strEqual(rootPath, EclipseProjectFinder.findProjectName(currentRoot))) { //rootPath = content_root <=> applicable root: abs_path/content_root
if (relativeToRootPath == null) {
return VfsUtil.pathToUrl(currentRoot);
}
final File relativeToOtherModuleFile = new File(currentRoot, relativeToRootPath);
if (relativeToOtherModuleFile.exists()) {
return VfsUtil.pathToUrl(relativeToOtherModuleFile.getPath());
}
}
}
return null;
}
/**
* @param otherModule check file relative to module content root
* @param relativeToOtherModule local path (paths inside jars are rejected)
@@ -134,28 +96,28 @@ public class EPathUtil {
final String rootPath = contentRoot.getPath();
String url = null;
if (new File(path).exists()) { //absolute path
url = VfsUtil.pathToUrl(path);
url = EPathCommonUtil.pathToUrl(path);
}
else {
final String relativePath = new File(rootPath, path).getPath(); //inside current project
final File file = new File(relativePath);
if (file.exists()) {
url = VfsUtil.pathToUrl(relativePath);
url = EPathCommonUtil.pathToUrl(relativePath);
} else if (path.startsWith("/")) { //relative to other project
final String moduleName = getRelativeModuleName(path);
final String relativeToRootPath = getRelativeToModulePath(path);
final String moduleName = EPathCommonUtil.getRelativeModuleName(path);
final String relativeToRootPath = EPathCommonUtil.getRelativeToModulePath(path);
final Module otherModule = ModuleManager.getInstance(model.getModule().getProject()).findModuleByName(moduleName);
if (otherModule != null && otherModule != model.getModule()) {
url = expandEclipseRelative2OtherModule(otherModule, relativeToRootPath);
}
else if (currentRoots != null) {
url = expandEclipseRelative2ContentRoots(currentRoots, moduleName, relativeToRootPath);
url = EPathCommonUtil.expandEclipseRelative2ContentRoots(currentRoots, moduleName, relativeToRootPath);
}
}
}
if (url == null) {
url = VfsUtil.pathToUrl(path);
url = EPathCommonUtil.pathToUrl(path);
}
final VirtualFile localFile = VirtualFileManager.getInstance().findFileByUrl(url);
@@ -191,7 +153,7 @@ public class EPathUtil {
private static String collapse2eclipsePathRelative2Module(VirtualFile file, Module module) {
final VirtualFile[] contentRoots = ModuleRootManager.getInstance(module).getContentRoots();
for (VirtualFile otherRoot : contentRoots) {
if (VfsUtil.isAncestor(otherRoot, file, false)) {
if (VfsUtilCore.isAncestor(otherRoot, file, false)) {
return "/" + module.getName() + "/" + VfsUtilCore.getRelativePath(file, otherRoot, '/');
}
}
@@ -265,7 +227,7 @@ public class EPathUtil {
final Project project = libraryOrderEntry.getOwnerModule().getProject();
final VirtualFile baseDir = project.getBaseDir();
final String filePath = jarFile.getPath();
if (baseDir != null && !VfsUtil.isAncestor(baseDir, jarFile, false)) {
if (baseDir != null && !VfsUtilCore.isAncestor(baseDir, jarFile, false)) {
final String ideaCollapsed = PathMacroManager.getInstance(project).collapsePath(filePath);
if (ideaCollapsed.contains("..")) return null;
final int index = ideaCollapsed.indexOf('$');
@@ -20,7 +20,9 @@
*/
package org.jetbrains.idea.eclipse.conversion;
import com.intellij.openapi.components.ExpandMacroToPathMap;
import com.intellij.openapi.components.PathMacroManager;
import com.intellij.openapi.components.impl.BasePathMacroManager;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.projectRoots.ProjectJdkTable;
import com.intellij.openapi.projectRoots.Sdk;
@@ -30,49 +32,36 @@ import com.intellij.openapi.roots.libraries.Library;
import com.intellij.openapi.roots.libraries.LibraryTable;
import com.intellij.openapi.roots.libraries.LibraryTablesRegistrar;
import com.intellij.openapi.util.Comparing;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.vfs.JarFileSystem;
import com.intellij.openapi.vfs.VfsUtil;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.openapi.vfs.VirtualFileManager;
import com.intellij.util.ArrayUtil;
import org.jdom.Element;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.idea.eclipse.EclipseXml;
import org.jetbrains.idea.eclipse.IdeaXml;
import org.jetbrains.idea.eclipse.config.EclipseModuleManager;
import org.jetbrains.idea.eclipse.importWizard.EclipseProjectFinder;
import org.jetbrains.idea.eclipse.*;
import org.jetbrains.idea.eclipse.config.EclipseModuleManagerImpl;
import org.jetbrains.idea.eclipse.util.ErrorLog;
import java.io.*;
import java.util.*;
import java.util.jar.Manifest;
import java.util.regex.PatternSyntaxException;
import java.io.IOException;
import java.util.Collection;
import java.util.List;
import java.util.Set;
import static org.jetbrains.idea.eclipse.conversion.EPathUtil.expandEclipsePath2Url;
public class EclipseClasspathReader {
private final String myRootPath;
public class EclipseClasspathReader extends AbstractEclipseClasspathReader<ModifiableRootModel> {
private final Project myProject;
@Nullable private final List<String> myCurrentRoots;
private ContentEntry myContentEntry;
@Nullable private final Set<String> myModuleNames;
public EclipseClasspathReader(final String rootPath, final Project project, @Nullable List<String> currentRoots) {
this(rootPath, project, currentRoots, null);
}
public EclipseClasspathReader(final String rootPath, final Project project, @Nullable List<String> currentRoots, @Nullable Set<String> moduleNames) {
myRootPath = FileUtil.toSystemIndependentName(rootPath);
super(rootPath, currentRoots, moduleNames);
myProject = project;
myCurrentRoots = currentRoots;
myModuleNames = moduleNames;
}
public void init(ModifiableRootModel model) {
myContentEntry = model.addContentEntry(VfsUtil.pathToUrl(myRootPath));
myContentEntry = model.addContentEntry(pathToUrl(myRootPath));
}
public static void collectVariables(Set<String> usedVariables, Element classpathElement, final String rootPath) {
@@ -96,10 +85,6 @@ public class EclipseClasspathReader {
}
}
private static int srcVarStart(String srcPath) {
return srcPath.startsWith("/") ? 1 : 0;
}
public void readClasspath(ModifiableRootModel model,
final Collection<String> unknownLibraries,
Collection<String> unknownJdks,
@@ -115,252 +100,94 @@ public class EclipseClasspathReader {
int idx = 0;
for (Object o : classpathElement.getChildren(EclipseXml.CLASSPATHENTRY_TAG)) {
try {
readClasspathEntry(model, unknownLibraries, unknownJdks, usedVariables, refsToModules, testPattern, (Element)o, idx++);
readClasspathEntry(model, unknownLibraries, unknownJdks, usedVariables, refsToModules, testPattern, (Element)o, idx++,
EclipseModuleManagerImpl.getInstance(model.getModule()),
((BasePathMacroManager)PathMacroManager.getInstance(model.getModule())).getExpandMacroMap());
}
catch (ConversionException e) {
ErrorLog.rethrow(ErrorLog.Level.Warning, null, EclipseXml.CLASSPATH_FILE, e);
}
}
if (!model.isSdkInherited() && model.getSdkName() == null) {
EclipseModuleManager.getInstance(model.getModule()).setForceConfigureJDK();
EclipseModuleManagerImpl.getInstance(model.getModule()).setForceConfigureJDK();
model.inheritSdk();
}
}
private void readClasspathEntry(ModifiableRootModel rootModel,
final Collection<String> unknownLibraries,
Collection<String> unknownJdks,
final Set<String> usedVariables,
Set<String> refsToModules,
final String testPattern,
Element element, int idx) throws ConversionException {
String kind = element.getAttributeValue(EclipseXml.KIND_ATTR);
if (kind == null) {
throw new ConversionException("Missing classpathentry/@kind");
@Override
protected int rearrange(ModifiableRootModel rootModel) {
return rearrangeOrderEntryOfType(rootModel, ModuleSourceOrderEntry.class);
}
@Override
protected String expandEclipsePath2Url(ModifiableRootModel rootModel, String path) {
return EPathUtil.expandEclipsePath2Url(path, rootModel, myCurrentRoots);
}
@Override
protected void addModuleLibrary(ModifiableRootModel rootModel,
Element element,
boolean exported,
String libName,
String url,
String srcUrl, ExpandMacroToPathMap macroMap) {
final Library library = rootModel.getModuleLibraryTable().getModifiableModel().createLibrary(libName);
final Library.ModifiableModel modifiableModel = library.getModifiableModel();
modifiableModel.addRoot(url, OrderRootType.CLASSES);
if (srcUrl != null) {
modifiableModel.addRoot(srcUrl, OrderRootType.SOURCES);
}
EJavadocUtil.appendJavadocRoots(element, rootModel, myCurrentRoots, modifiableModel);
modifiableModel.commit();
setLibraryEntryExported(rootModel, exported, library);
}
String path = element.getAttributeValue(EclipseXml.PATH_ATTR);
if (path == null) {
throw new ConversionException("Missing classpathentry/@path");
}
@Override
protected void addJUnitDefaultLib(ModifiableRootModel rootModel, String junitName) {
final Library library = rootModel.getModuleLibraryTable().getModifiableModel().createLibrary(junitName);
final Library.ModifiableModel modifiableModel = library.getModifiableModel();
modifiableModel.addRoot(getJunitClsUrl(junitName.contains("4")), OrderRootType.CLASSES);
modifiableModel.commit();
}
final boolean exported = EclipseXml.TRUE_VALUE.equals(element.getAttributeValue(EclipseXml.EXPORTED_ATTR));
@Override
protected void addSourceFolderToCurrentContentRoot(ModifiableRootModel rootModel,
String srcUrl,
boolean testFolder) {
myContentEntry.addSourceFolder(srcUrl, testFolder);
}
final EclipseModuleManager eclipseModuleManager = EclipseModuleManager.getInstance(rootModel.getModule());
if (kind.equals(EclipseXml.SRC_KIND)) {
if (path.startsWith("/")) {
final String moduleName = path.substring(1);
refsToModules.add(moduleName);
rootModel.addInvalidModuleEntry(moduleName).setExported(exported);
}
else {
String srcUrl = VfsUtil.pathToUrl(myRootPath + "/" + path);
boolean isTestFolder = false;
try {
isTestFolder = testPattern != null && testPattern.length() > 0 && path.matches(testPattern);
}
catch (PatternSyntaxException e) {
isTestFolder = false;
}
final String linked = expandLinkedResourcesPath(rootModel, usedVariables, path);
if (linked != null) {
srcUrl = VfsUtil.pathToUrl(linked);
eclipseModuleManager.registerEclipseLinkedSrcVarPath(srcUrl, path);
rootModel.addContentEntry(srcUrl).addSourceFolder(srcUrl, isTestFolder);
}
else {
myContentEntry.addSourceFolder(srcUrl, isTestFolder);
}
eclipseModuleManager.setExpectedModuleSourcePlace(rearrangeOrderEntryOfType(rootModel, ModuleSourceOrderEntry.class));
eclipseModuleManager.registerSrcPlace(srcUrl, idx);
}
}
@Override
protected void addSourceFolder(ModifiableRootModel rootModel, String srcUrl, boolean testFolder) {
rootModel.addContentEntry(srcUrl).addSourceFolder(srcUrl, testFolder);
}
else if (kind.equals(EclipseXml.OUTPUT_KIND)) {
String output = myRootPath + "/" + path;
final String linked = expandLinkedResourcesPath(rootModel, usedVariables, path);
if (linked != null) {
output = linked;
eclipseModuleManager.registerEclipseLinkedVarPath(VfsUtil.pathToUrl(output), path);
}
setupOutput(rootModel, output);
}
else if (kind.equals(EclipseXml.LIB_KIND)) {
final String libName = getPresentableName(path);
final Library library = rootModel.getModuleLibraryTable().getModifiableModel().createLibrary(libName);
final Library.ModifiableModel modifiableModel = library.getModifiableModel();
final String linked = expandLinkedResourcesPath(rootModel, usedVariables, path);
final String url;
if (linked != null) {
url = VfsUtil.pathToUrl(linked);
eclipseModuleManager.registerEclipseLinkedVarPath(url, path);
} else {
url = expandEclipsePath2Url(path, rootModel, myCurrentRoots);
}
modifiableModel.addRoot(url, OrderRootType.CLASSES);
eclipseModuleManager.registerEclipseLibUrl(url);
final String sourcePath = element.getAttributeValue(EclipseXml.SOURCEPATH_ATTR);
if (sourcePath != null) {
final String linkedSrc = expandLinkedResourcesPath(rootModel, usedVariables, sourcePath);
final String srcUrl;
if (linkedSrc != null) {
srcUrl = VfsUtil.pathToUrl(linkedSrc);
eclipseModuleManager.registerEclipseLinkedSrcVarPath(srcUrl, sourcePath);
}
else {
srcUrl = expandEclipsePath2Url(sourcePath, rootModel, myCurrentRoots);
}
modifiableModel.addRoot(srcUrl, OrderRootType.SOURCES);
}
EJavadocUtil.appendJavadocRoots(element, rootModel, myCurrentRoots, modifiableModel);
modifiableModel.commit();
setLibraryEntryExported(rootModel, exported, library);
}
else if (kind.equals(EclipseXml.VAR_KIND)) {
int slash = path.indexOf("/");
if (slash == 0) {
throw new ConversionException("Incorrect 'classpathentry/var@path' format");
}
final String libName = getPresentableName(path);
final Library library = rootModel.getModuleLibraryTable().getModifiableModel().createLibrary(libName);
final Library.ModifiableModel modifiableModel = library.getModifiableModel();
final String url = eclipseVariabledPath2Url(rootModel, usedVariables, path, 0);
modifiableModel.addRoot(url, OrderRootType.CLASSES);
eclipseModuleManager.registerEclipseVariablePath(url, path);
final String srcPathAttr = element.getAttributeValue(EclipseXml.SOURCEPATH_ATTR);
if (srcPathAttr != null) {
final String srcUrl = eclipseVariabledPath2Url(rootModel, usedVariables, srcPathAttr, srcVarStart(srcPathAttr));
modifiableModel.addRoot(srcUrl, OrderRootType.SOURCES);
eclipseModuleManager.registerEclipseSrcVariablePath(srcUrl, srcPathAttr);
}
EJavadocUtil.appendJavadocRoots(element, rootModel, myCurrentRoots, modifiableModel);
modifiableModel.commit();
setLibraryEntryExported(rootModel, exported, library);
}
else if (kind.equals(EclipseXml.CON_KIND)) {
if (path.equals(EclipseXml.ECLIPSE_PLATFORM)) {
readRequiredBundles(rootModel, refsToModules);
addNamedLibrary(rootModel, unknownLibraries, exported, IdeaXml.ECLIPSE_LIBRARY, LibraryTablesRegistrar.APPLICATION_LEVEL);
}
else if (path.startsWith(EclipseXml.JRE_CONTAINER)) {
final String jdkName = getLastPathComponent(path);
if (jdkName == null) {
rootModel.inheritSdk();
}
else {
final Sdk moduleJdk = ProjectJdkTable.getInstance().findJdk(jdkName);
if (moduleJdk != null) {
rootModel.setSdk(moduleJdk);
}
else {
rootModel.setInvalidSdk(jdkName, IdeaXml.JAVA_SDK_TYPE);
eclipseModuleManager.setInvalidJdk(jdkName);
unknownJdks.add(jdkName);
}
}
rearrangeOrderEntryOfType(rootModel, JdkOrderEntry.class);
}
else if (path.startsWith(EclipseXml.USER_LIBRARY)) {
addNamedLibrary(rootModel, unknownLibraries, exported, getPresentableName(path), LibraryTablesRegistrar.PROJECT_LEVEL);
}
else if (path.startsWith(EclipseXml.JUNIT_CONTAINER)) {
final String junitName = IdeaXml.JUNIT + getPresentableName(path);
final Library library = rootModel.getModuleLibraryTable().getModifiableModel().createLibrary(junitName);
final Library.ModifiableModel modifiableModel = library.getModifiableModel();
modifiableModel.addRoot(getJunitClsUrl(junitName.contains("4")), OrderRootType.CLASSES);
modifiableModel.commit();
}
else if (path.equals(EclipseXml.GROOVY_DSL_CONTAINER)) {
eclipseModuleManager.setGroovyDslSupport();
eclipseModuleManager.registerSrcPlace(EclipseXml.GROOVY_DSL_CONTAINER, idx);
}
else {
eclipseModuleManager.registerUnknownCons(path);
addNamedLibrary(rootModel, new ArrayList<String>(), exported, path, LibraryTablesRegistrar.APPLICATION_LEVEL);
}
@Override
protected void setUpModuleJdk(ModifiableRootModel rootModel,
Collection<String> unknownJdks,
EclipseModuleManager eclipseModuleManager,
String jdkName) {
if (jdkName == null) {
rootModel.inheritSdk();
}
else {
throw new ConversionException("Unknown classpathentry/@kind: " + kind);
final Sdk moduleJdk = ProjectJdkTable.getInstance().findJdk(jdkName);
if (moduleJdk != null) {
rootModel.setSdk(moduleJdk);
}
else {
rootModel.setInvalidSdk(jdkName, IdeaXml.JAVA_SDK_TYPE);
eclipseModuleManager.setInvalidJdk(jdkName);
unknownJdks.add(jdkName);
}
}
rearrangeOrderEntryOfType(rootModel, JdkOrderEntry.class);
}
@Nullable
private String expandLinkedResourcesPath(final ModifiableRootModel rootModel,
final Set<String> usedVariables,
final String path) {
final EclipseProjectFinder.LinkedResource linkedResource = EclipseProjectFinder.findLinkedResource(myRootPath, path);
if (linkedResource != null) {
if (linkedResource.containsPathVariable()) {
usedVariables.add(linkedResource.getVariableName());
}
if (linkedResource.containsPathVariable()) {
final String toPathVariableFormat =
getVariableRelatedPath(linkedResource.getVariableName(), linkedResource.getRelativeToVariablePath());
return PathMacroManager.getInstance(rootModel.getModule()).expandPath(toPathVariableFormat);
}
return linkedResource.getLocation();
}
return null;
}
private void readRequiredBundles(ModifiableRootModel rootModel, Set<String> refsToModules) throws ConversionException {
if (myModuleNames == null) {
return;
}
final File manifestFile = new File(myRootPath, "META-INF/MANIFEST.MF");
if (!manifestFile.exists()) {
return;
}
InputStream in = null;
try {
in = new BufferedInputStream(new FileInputStream(manifestFile));
final Manifest manifest = new Manifest(in);
final String attributes = manifest.getMainAttributes().getValue("Require-Bundle");
if (!StringUtil.isEmpty(attributes)) {
final StringTokenizer tokenizer = new StringTokenizer(attributes, ",");
while (tokenizer.hasMoreTokens()) {
String bundle = tokenizer.nextToken().trim();
if (!bundle.isEmpty()) {
final int constraintIndex = bundle.indexOf(';');
if (constraintIndex != -1) {
bundle = bundle.substring(0, constraintIndex).trim();
}
if (myModuleNames.contains(bundle)) {
refsToModules.add(bundle);
rootModel.addInvalidModuleEntry(bundle);
}
}
}
}
}
catch (IOException e) {
throw new ConversionException(e.getMessage());
}
finally {
if (in != null) {
try {
in.close();
}
catch (IOException ignored) {
}
}
}
@Override
protected void addInvalidModuleEntry(ModifiableRootModel rootModel, boolean exported, String moduleName) {
rootModel.addInvalidModuleEntry(moduleName).setExported(exported);
}
private static int rearrangeOrderEntryOfType(ModifiableRootModel rootModel, Class<? extends OrderEntry> orderEntryClass) {
@@ -378,9 +205,14 @@ public class EclipseClasspathReader {
return orderEntries.length - 1;
}
public static void setupOutput(ModifiableRootModel rootModel, final String path) {
@Override
public void setupOutput(ModifiableRootModel rootModel, final String path) {
setOutputUrl(rootModel, path);
}
public static void setOutputUrl(ModifiableRootModel rootModel, String path) {
final CompilerModuleExtension compilerModuleExtension = rootModel.getModuleExtension(CompilerModuleExtension.class);
compilerModuleExtension.setCompilerOutputPath(VfsUtil.pathToUrl(path));
compilerModuleExtension.setCompilerOutputPath(pathToUrl(path));
compilerModuleExtension.inheritCompilerOutputPath(false);
}
@@ -395,18 +227,19 @@ public class EclipseClasspathReader {
}
}
private void addNamedLibrary(final ModifiableRootModel rootModel,
final Collection<String> unknownLibraries,
final boolean exported,
final String name,
final String notFoundLibraryLevel) {
@Override
protected void addNamedLibrary(final ModifiableRootModel rootModel,
final Collection<String> unknownLibraries,
final boolean exported,
final String name,
final boolean applicationLevel) {
Library lib = findLibraryByName(myProject, name);
if (lib != null) {
rootModel.addLibraryEntry(lib).setExported(exported);
}
else {
unknownLibraries.add(name);
rootModel.addInvalidLibrary(name, notFoundLibraryLevel).setExported(exported);
rootModel.addInvalidLibrary(name, applicationLevel ? LibraryTablesRegistrar.APPLICATION_LEVEL : LibraryTablesRegistrar.PROJECT_LEVEL).setExported(exported);
}
}
@@ -427,37 +260,19 @@ public class EclipseClasspathReader {
return lib;
}
@NotNull
private static String getPresentableName(@NotNull String path) {
final String pathComponent = getLastPathComponent(path);
return pathComponent != null ? pathComponent : path;
}
@Nullable
public static String getLastPathComponent(final String path) {
final int idx = path.lastIndexOf('/');
return idx < 0 || idx == path.length() - 1 ? null : path.substring(idx + 1);
}
private static String getVariableRelatedPath(String var, String path) {
return var == null ? null : ("$" + var + "$" + (path == null ? "" : ("/" + path)));
}
static String getJunitClsUrl(final boolean version4) {
String url = version4 ? JavaSdkUtil.getJunit4JarPath() : JavaSdkUtil.getJunit3JarPath();
final VirtualFile localFile = VirtualFileManager.getInstance().findFileByUrl(VfsUtil.pathToUrl(url));
final VirtualFile localFile = VirtualFileManager.getInstance().findFileByUrl(pathToUrl(url));
if (localFile != null) {
final VirtualFile jarFile = JarFileSystem.getInstance().getJarRootForLocalFile(localFile);
url = jarFile != null ? jarFile.getUrl() : localFile.getUrl();
}
return url;
}
private static String eclipseVariabledPath2Url(ModifiableRootModel rootModel, Set<String> usedVariables, String path, int varStart) {
final EPathVariable var = createEPathVariable(usedVariables, path, varStart);
final String url = PathMacroManager.getInstance(rootModel.getModule()).expandPath(var.toIdeaVariabledUrl());
protected String prepareValidUrlInsideJar(String url) {
final VirtualFile localFile = VirtualFileManager.getInstance().findFileByUrl(url);
if (localFile != null) {
final VirtualFile jarFile = JarFileSystem.getInstance().getJarRootForLocalFile(localFile);
@@ -468,31 +283,4 @@ public class EclipseClasspathReader {
return url;
}
private static EPathVariable createEPathVariable(final Set<String> usedVariables, final String pathAttr, final int varStart) {
final EPathVariable var;
int slash = pathAttr.indexOf("/", varStart);
if (slash > 0) {
var = new EPathVariable(usedVariables, pathAttr.substring(varStart, slash), pathAttr.substring(slash + 1));
}
else {
var = new EPathVariable(usedVariables, pathAttr.substring(varStart), null);
}
return var;
}
private static class EPathVariable {
private final String myVariable;
private final String myRelatedPath;
private EPathVariable(final Set<String> usedVariables, final String variable, final String relatedPath) {
myVariable = variable;
myRelatedPath = relatedPath;
usedVariables.add(myVariable);
}
public String toIdeaVariabledUrl() {
return VfsUtil.pathToUrl(getVariableRelatedPath(myVariable, myRelatedPath));
}
}
}
@@ -31,9 +31,11 @@ import com.intellij.openapi.vfs.VirtualFile;
import org.jdom.Element;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.idea.eclipse.ConversionException;
import org.jetbrains.idea.eclipse.EclipseXml;
import org.jetbrains.idea.eclipse.IdeaXml;
import org.jetbrains.idea.eclipse.config.EclipseModuleManager;
import org.jetbrains.idea.eclipse.EclipseModuleManager;
import org.jetbrains.idea.eclipse.config.EclipseModuleManagerImpl;
import java.util.Arrays;
import java.util.HashMap;
@@ -64,7 +66,7 @@ public class EclipseClasspathWriter {
@NonNls String outputPath = "bin";
final String compilerOutputUrl = myModel.getModuleExtension(CompilerModuleExtension.class).getCompilerOutputUrl();
final EclipseModuleManager eclipseModuleManager = EclipseModuleManager.getInstance(myModel.getModule());
final EclipseModuleManager eclipseModuleManager = EclipseModuleManagerImpl.getInstance(myModel.getModule());
final String linkedPath = eclipseModuleManager.getEclipseLinkedVarPath(compilerOutputUrl);
if (linkedPath != null) {
outputPath = linkedPath;
@@ -87,7 +89,7 @@ public class EclipseClasspathWriter {
}
private void createClasspathEntry(OrderEntry entry, Element classpathRoot) throws ConversionException {
final EclipseModuleManager eclipseModuleManager = EclipseModuleManager.getInstance(entry.getOwnerModule());
final EclipseModuleManager eclipseModuleManager = EclipseModuleManagerImpl.getInstance(entry.getOwnerModule());
if (entry instanceof ModuleSourceOrderEntry) {
final boolean shouldPlaceSeparately =
eclipseModuleManager.isExpectedModuleSourcePlace(Arrays.binarySearch(myModel.getOrderEntries(), entry));
@@ -98,7 +100,7 @@ public class EclipseClasspathWriter {
final String srcUrl = sourceFolder.getUrl();
String relativePath = EPathUtil.collapse2EclipsePath(srcUrl, myModel);
if (!Comparing.equal(contentRoot, EPathUtil.getContentRoot(myModel))) {
final String linkedPath = EclipseModuleManager.getInstance(entry.getOwnerModule()).getEclipseLinkedSrcVariablePath(srcUrl);
final String linkedPath = EclipseModuleManagerImpl.getInstance(entry.getOwnerModule()).getEclipseLinkedSrcVariablePath(srcUrl);
if (linkedPath != null) {
relativePath = linkedPath;
}
@@ -205,7 +207,7 @@ public class EclipseClasspathWriter {
}
else if (entry instanceof JdkOrderEntry) {
if (entry instanceof InheritedJdkOrderEntry) {
if (!EclipseModuleManager.getInstance(entry.getOwnerModule()).isForceConfigureJDK()) {
if (!EclipseModuleManagerImpl.getInstance(entry.getOwnerModule()).isForceConfigureJDK()) {
addOrderEntry(EclipseXml.CON_KIND, EclipseXml.JRE_CONTAINER, classpathRoot);
}
}
@@ -43,7 +43,7 @@ import com.intellij.pom.java.LanguageLevel;
import org.jdom.Element;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.idea.eclipse.IdeaXml;
import org.jetbrains.idea.eclipse.config.EclipseModuleManager;
import org.jetbrains.idea.eclipse.config.EclipseModuleManagerImpl;
import java.io.File;
import java.util.ArrayList;
@@ -278,7 +278,7 @@ public class IdeaSpecificSettings {
isModified = true;
}
}
if (entry instanceof InheritedJdkOrderEntry && EclipseModuleManager.getInstance(entry.getOwnerModule()).getInvalidJdk() != null) {
if (entry instanceof InheritedJdkOrderEntry && EclipseModuleManagerImpl.getInstance(entry.getOwnerModule()).getInvalidJdk() != null) {
root.setAttribute(INHERIT_JDK, "true");
isModified = true;
}
@@ -37,6 +37,7 @@ import com.intellij.util.Function;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.output.EclipseJDOMUtil;
import org.jetbrains.idea.eclipse.ConversionException;
import org.jetbrains.idea.eclipse.EclipseBundle;
import org.jetbrains.idea.eclipse.EclipseXml;
import org.jetbrains.idea.eclipse.IdeaXml;
@@ -49,6 +49,7 @@ import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.packaging.artifacts.ModifiableArtifactModel;
import com.intellij.projectImport.ProjectImportBuilder;
import com.intellij.util.Function;
import com.intellij.util.Processor;
import gnu.trove.THashSet;
import icons.EclipseIcons;
import org.jdom.Element;
@@ -56,6 +57,7 @@ import org.jdom.JDOMException;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.idea.eclipse.EclipseBundle;
import org.jetbrains.idea.eclipse.EclipseProjectFinder;
import org.jetbrains.idea.eclipse.EclipseXml;
import org.jetbrains.idea.eclipse.IdeaXml;
import org.jetbrains.idea.eclipse.conversion.EclipseClasspathReader;
@@ -100,7 +102,17 @@ public class EclipseImportBuilder extends ProjectImportBuilder<String> implement
ProgressManager.getInstance().run(new Task.Modal(getCurrentProject(), EclipseBundle.message("eclipse.import.scanning"), true) {
public void run(@NotNull ProgressIndicator indicator) {
final ArrayList<String> roots = new ArrayList<String>();
EclipseProjectFinder.findModuleRoots(roots, path);
EclipseProjectFinder.findModuleRoots(roots, path, new Processor<String>() {
@Override
public boolean process(String path) {
final ProgressIndicator progressIndicator = ProgressManager.getInstance().getProgressIndicator();
if (progressIndicator != null) {
if (progressIndicator.isCanceled()) return false;
progressIndicator.setText2(path);
}
return true;
}
});
Collections.sort(roots, new Comparator<String>() {
@Override
public int compare(String path1, String path2) {
@@ -276,7 +288,7 @@ public class EclipseImportBuilder extends ProjectImportBuilder<String> implement
classpathReader.readClasspath(rootModel, unknownLibraries, unknownJdks, usedVariables, refsToModules,
getParameters().converterOptions.testPattern, classpathElement);
} else {
EclipseClasspathReader.setupOutput(rootModel, path + "/bin");
EclipseClasspathReader.setOutputUrl(rootModel, path + "/bin");
}
ClasspathStorage.setStorageType(rootModel,
getParameters().linkConverted ? JpsEclipseClasspathSerializer.CLASSPATH_STORAGE_ID : ClasspathStorage.DEFAULT_STORAGE);
@@ -25,6 +25,7 @@ import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.projectImport.ProjectOpenProcessorBase;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.idea.eclipse.EclipseProjectFinder;
import org.jetbrains.idea.eclipse.EclipseXml;
import java.util.List;
@@ -29,6 +29,7 @@ import com.intellij.projectImport.SelectImportedProjectsStep;
import com.intellij.util.ArrayUtil;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.idea.eclipse.EclipseProjectFinder;
import org.jetbrains.idea.eclipse.util.PathUtil;
import javax.swing.*;
@@ -17,7 +17,7 @@ package org.jetbrains.idea.eclipse.util;
import com.intellij.openapi.util.io.FileUtil;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.idea.eclipse.conversion.ConversionException;
import org.jetbrains.idea.eclipse.ConversionException;
import java.io.IOException;
@@ -42,10 +42,8 @@ import org.jdom.Element;
import org.jdom.JDOMException;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.idea.eclipse.config.EclipseClasspathStorageProvider;
import org.jetbrains.idea.eclipse.conversion.ConversionException;
import org.jetbrains.idea.eclipse.conversion.EclipseClasspathReader;
import org.jetbrains.idea.eclipse.conversion.EclipseClasspathWriter;
import org.jetbrains.idea.eclipse.importWizard.EclipseProjectFinder;
import java.io.File;
import java.io.IOException;
@@ -40,7 +40,6 @@ import org.jdom.Element;
import org.jdom.JDOMException;
import org.jetbrains.idea.eclipse.config.EclipseClasspathStorageProvider;
import org.jetbrains.idea.eclipse.conversion.IdeaSpecificSettings;
import org.jetbrains.idea.eclipse.importWizard.EclipseProjectFinder;
import java.io.File;
import java.io.IOException;
@@ -42,7 +42,6 @@ import org.jdom.Document;
import org.jdom.Element;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.idea.eclipse.conversion.EclipseClasspathReader;
import org.jetbrains.idea.eclipse.importWizard.EclipseProjectFinder;
import java.io.File;
import java.util.ArrayList;