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 org.jetbrains.idea.eclipse.importWizard.EclipseProjectFinder;
import org.jetbrains.idea.eclipse.util.ErrorLog;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-import java.util.Set;
+import java.io.*;
+import java.util.*;
+import java.util.jar.Manifest;
import java.util.regex.PatternSyntaxException;
-import static org.jetbrains.idea.eclipse.conversion.EPathUtil.*;
+import static org.jetbrains.idea.eclipse.conversion.EPathUtil.expandEclipsePath2Url;
public class EclipseClasspathReader {
private final String myRootPath;
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);
myProject = project;
myCurrentRoots = currentRoots;
+ myModuleNames = moduleNames;
}
public void init(ModifiableRootModel model) {
}
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)) {
}
}
+ 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) {
+ }
+ }
+ }
+ }
+
private static int rearrangeOrderEntryOfType(ModifiableRootModel rootModel, Class<? extends OrderEntry> orderEntryClass) {
OrderEntry[] orderEntries = rootModel.getOrderEntries();
int moduleSourcesIdx = 0;
import com.intellij.packaging.artifacts.ModifiableArtifactModel;
import com.intellij.projectImport.ProjectImportBuilder;
import com.intellij.util.Function;
+import gnu.trove.THashSet;
import org.jdom.Element;
import org.jdom.JDOMException;
import org.jetbrains.annotations.NotNull;
final ModifiableModuleModel moduleModel = model != null ? model : ModuleManager.getInstance(project).getModifiableModel();
final ModifiableRootModel[] rootModels = new ModifiableRootModel[getParameters().projectsToConvert.size()];
final Set<File> files = new HashSet<File>();
+ final Set<String> moduleNames = new THashSet<String>(getParameters().projectsToConvert.size());
for (String path : getParameters().projectsToConvert) {
String modulesDirectory = getParameters().converterOptions.commonModulesDirectory;
if (modulesDirectory == null) {
modulesDirectory = path;
}
final String moduleName = EclipseProjectFinder.findProjectName(path);
+ moduleNames.add(moduleName);
final File imlFile = new File(modulesDirectory + File.separator + moduleName + IdeaXml.IML_EXT);
if (imlFile.isFile()) {
files.add(imlFile);
rootModels[idx++] = rootModel;
final File classpathFile = new File(path, EclipseXml.DOT_CLASSPATH_EXT);
- final EclipseClasspathReader classpathReader = new EclipseClasspathReader(path, project, getParameters().projectsToConvert);
+ final EclipseClasspathReader classpathReader = new EclipseClasspathReader(path, project, getParameters().projectsToConvert, moduleNames);
classpathReader.init(rootModel);
if (classpathFile.exists()) {
final Element classpathElement = JDOMUtil.loadDocument(classpathFile).getRootElement();