Merge branch 'idea90' of git.labs.intellij.net:idea/community into idea90

This commit is contained in:
irengrig
2009-12-19 18:21:26 +03:00
30 changed files with 785 additions and 340 deletions
@@ -16,14 +16,15 @@
package org.intellij.lang.regexp;
import com.intellij.extapi.psi.PsiFileBase;
import com.intellij.lang.Language;
import com.intellij.openapi.fileTypes.FileType;
import com.intellij.psi.FileViewProvider;
import org.jetbrains.annotations.NotNull;
public class RegExpFile extends PsiFileBase {
public RegExpFile(FileViewProvider viewProvider) {
super(viewProvider, RegExpLanguage.INSTANCE);
public RegExpFile(FileViewProvider viewProvider, final Language language) {
super(viewProvider, language);
}
@NotNull
@@ -17,12 +17,12 @@ package org.intellij.lang.regexp;
import com.intellij.lexer.FlexAdapter;
class RegExpLexer extends FlexAdapter {
public class RegExpLexer extends FlexAdapter {
private static final int COMMENT_MODE = 1 << 14;
public RegExpLexer(boolean xmlSchemaMode) {
super(new _RegExLexer(xmlSchemaMode));
public RegExpLexer(boolean xmlSchemaMode, boolean allowDanglingMetacharacters) {
super(new _RegExLexer(xmlSchemaMode, allowDanglingMetacharacters));
}
public void start(CharSequence buffer, int startOffset, int endOffset, int initialState) {
@@ -18,13 +18,19 @@ package org.intellij.lang.regexp;
import com.intellij.lang.ASTNode;
import com.intellij.lang.PsiBuilder;
import com.intellij.lang.PsiParser;
import com.intellij.psi.tree.IElementType;
import com.intellij.psi.StringEscapesTokenTypes;
import com.intellij.psi.tree.IElementType;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@SuppressWarnings({ "RedundantIfStatement" })
class RegExpParser implements PsiParser {
public class RegExpParser implements PsiParser {
private boolean myAllowDanglingMetacharacters;
public void setAllowDanglingMetacharacters(boolean allowDanglingMetacharacters) {
myAllowDanglingMetacharacters = allowDanglingMetacharacters;
}
@NotNull
public ASTNode parse(IElementType root, PsiBuilder builder) {
// builder.setDebugMode(true);
@@ -123,6 +129,10 @@ class RegExpParser implements PsiParser {
if (builder.getTokenType() == RegExpTT.LBRACE) {
builder.advanceLexer();
if (builder.getTokenType() != RegExpTT.NUMBER && myAllowDanglingMetacharacters) {
marker.done(RegExpTT.CHARACTER);
return true;
}
checkMatches(builder, RegExpTT.NUMBER, "Number expected");
if (builder.getTokenType() == RegExpTT.RBRACE) {
builder.advanceLexer();
@@ -157,7 +167,7 @@ class RegExpParser implements PsiParser {
return true;
}
private void parseQuantifierType(PsiBuilder builder) {
private static void parseQuantifierType(PsiBuilder builder) {
if (builder.getTokenType() == RegExpTT.PLUS) {
builder.advanceLexer();
} else if (builder.getTokenType() == RegExpTT.QUEST) {
@@ -344,14 +354,19 @@ class RegExpParser implements PsiParser {
} else if (type == RegExpTT.CLASS_BEGIN) {
marker.drop();
return parseClass(builder);
} else {
}
else if (type == RegExpTT.LBRACE && myAllowDanglingMetacharacters) {
builder.advanceLexer();
marker.done(RegExpElementTypes.CHAR);
}
else {
marker.drop();
return null;
}
return marker;
}
private void parseProperty(PsiBuilder builder) {
private static void parseProperty(PsiBuilder builder) {
checkMatches(builder, RegExpTT.PROPERTY, "'\\p' expected");
checkMatches(builder, RegExpTT.LBRACE, "Character category expected");
@@ -34,9 +34,9 @@ import org.jetbrains.annotations.NotNull;
public class RegExpParserDefinition implements ParserDefinition {
private static final TokenSet COMMENT_TOKENS = TokenSet.create(RegExpTT.COMMENT);
@NotNull
@NotNull
public Lexer createLexer(Project project) {
return new RegExpLexer(false);
return new RegExpLexer(false, false);
}
public PsiParser createParser(Project project) {
@@ -86,7 +86,7 @@ public class RegExpParserDefinition implements ParserDefinition {
return new RegExpSetOptionsImpl(node);
} else if (type == RegExpElementTypes.OPTIONS) {
return new RegExpOptionsImpl(node);
} else if (type == RegExpElementTypes.BACKREF) {
} else if (type == RegExpElementTypes.BACKREF) {
return new RegExpBackrefImpl(node);
} else if (type == RegExpElementTypes.CLOSURE) {
return new RegExpClosureImpl(node);
@@ -101,7 +101,7 @@ public class RegExpParserDefinition implements ParserDefinition {
}
public PsiFile createFile(FileViewProvider viewProvider) {
return new RegExpFile(viewProvider);
return new RegExpFile(viewProvider, RegExpLanguage.INSTANCE);
}
public SpaceRequirements spaceExistanceTypeBetweenTokens(ASTNode left, ASTNode right) {
@@ -1,26 +1,13 @@
/*
* Copyright 2000-2009 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.
*/
/* The following code was generated by JFlex 1.4.1 on 18.12.09 20:27 */
/* It's an automatically generated code. Do not modify it. */
package org.intellij.lang.regexp;
import com.intellij.lexer.FlexLexer;
import com.intellij.psi.tree.IElementType;
import java.util.LinkedList;
import com.intellij.psi.StringEscapesTokenTypes;
import com.intellij.psi.tree.IElementType;
import java.util.LinkedList;
// IDEADEV-11055
@SuppressWarnings({ "ALL", "SameParameterValue", "WeakerAccess", "SameReturnValue", "RedundantThrows", "UnusedDeclaration", "UnusedDeclaration" })
@@ -28,8 +15,8 @@ import com.intellij.psi.StringEscapesTokenTypes;
/**
* This class is a scanner generated by
* <a href="http://www.jflex.de/">JFlex</a> 1.4.1
* on 04.11.09 17:54 from the specification file
* <tt>RegExpSupport/src/org/intellij/lang/regexp/regexp-lexer.flex</tt>
* on 18.12.09 20:27 from the specification file
* <tt>C:/JetBrains/IDEA/tools/lexer/../../community/RegExpSupport/src/org/intellij/lang/regexp/regexp-lexer.flex</tt>
*/
class _RegExLexer implements FlexLexer {
/** initial size of the lookahead buffer */
@@ -352,9 +339,12 @@ class _RegExLexer implements FlexLexer {
// as well, but is currently unfinished as it requires to tweak more places than just the lexer.
private boolean xmlSchemaMode;
_RegExLexer(boolean xmlSchemaMode) {
private boolean allowDanglingMetacharacters;
_RegExLexer(boolean xmlSchemaMode, boolean allowDanglingMetacharacters) {
this((java.io.Reader)null);
this.xmlSchemaMode = xmlSchemaMode;
this.xmlSchemaMode = xmlSchemaMode;
this.allowDanglingMetacharacters = allowDanglingMetacharacters;
}
private void yypushstate(int state) {
@@ -431,7 +421,14 @@ class _RegExLexer implements FlexLexer {
// For Demetra compatibility
public void reset(CharSequence buffer, int initialState){
reset(buffer, 0, buffer.length(), initialState);
zzBuffer = buffer;
zzBufferArray = null;
zzCurrentPos = zzMarkedPos = zzStartRead = 0;
zzPushbackPos = 0;
zzAtEOF = false;
zzAtBOL = true;
zzEndRead = buffer.length();
yybegin(initialState);
}
/**
@@ -591,7 +588,7 @@ class _RegExLexer implements FlexLexer {
while (true) {
if (zzCurrentPosL < zzEndReadL)
zzInput = zzBufferL.charAt(zzCurrentPosL++);
zzInput = zzBufferArrayL != null ? zzBufferArrayL[zzCurrentPosL++]:zzBufferL.charAt(zzCurrentPosL++);
else if (zzAtEOF) {
zzInput = YYEOF;
break zzForAction;
@@ -613,7 +610,7 @@ class _RegExLexer implements FlexLexer {
break zzForAction;
}
else {
zzInput = zzBufferL.charAt(zzCurrentPosL++);
zzInput = zzBufferArrayL != null ? zzBufferArrayL[zzCurrentPosL++]:zzBufferL.charAt(zzCurrentPosL++);
}
}
int zzNext = zzTransL[ zzRowMapL[zzState] + zzCMapL[zzInput] ];
@@ -840,45 +837,49 @@ class _RegExLexer implements FlexLexer {
{ return RegExpTT.HEX_CHAR;
}
case 111: break;
case 20:
{ return RegExpTT.BAD_CHARACTER;
}
case 112: break;
case 5:
{ return RegExpTT.GROUP_BEGIN;
}
case 113: break;
case 112: break;
case 8:
{ yypushstate(CLASS2); return RegExpTT.CLASS_BEGIN;
}
case 114: break;
case 113: break;
case 52:
{ return RegExpTT.NON_CAPT_GROUP;
}
case 115: break;
case 114: break;
case 9:
{ return StringEscapesTokenTypes.INVALID_CHARACTER_ESCAPE_TOKEN;
}
case 116: break;
case 115: break;
case 48:
{ return RegExpTT.BAD_HEX_VALUE;
}
case 117: break;
case 116: break;
case 2:
{ yypopstate(); return RegExpTT.COMMENT;
}
case 118: break;
case 117: break;
case 47:
{ yypushstate(QUOTED); return RegExpTT.QUOTE_BEGIN;
}
case 119: break;
case 118: break;
case 26:
{ yybegin(CLASS2); return RegExpTT.CHARACTER;
}
case 120: break;
case 119: break;
case 15:
{ return RegExpTT.PLUS;
}
case 120: break;
case 20:
{ if (allowDanglingMetacharacters) {
yypopstate(); yypushback(1);
} else {
return RegExpTT.BAD_CHARACTER;
}
}
case 121: break;
case 31:
{ yybegin(YYINITIAL); return RegExpTT.BAD_CHARACTER;
@@ -26,9 +26,12 @@ import com.intellij.psi.StringEscapesTokenTypes;
// as well, but is currently unfinished as it requires to tweak more places than just the lexer.
private boolean xmlSchemaMode;
_RegExLexer(boolean xmlSchemaMode) {
private boolean allowDanglingMetacharacters;
_RegExLexer(boolean xmlSchemaMode, boolean allowDanglingMetacharacters) {
this((java.io.Reader)null);
this.xmlSchemaMode = xmlSchemaMode;
this.xmlSchemaMode = xmlSchemaMode;
this.allowDanglingMetacharacters = allowDanglingMetacharacters;
}
private void yypushstate(int state) {
@@ -157,7 +160,12 @@ HEX_CHAR=[0-9a-fA-F]
"," { return RegExpTT.COMMA; }
{RBRACE} { yypopstate(); return RegExpTT.RBRACE; }
{ANY} { return RegExpTT.BAD_CHARACTER; }
{ANY} { if (allowDanglingMetacharacters) {
yypopstate(); yypushback(1);
} else {
return RegExpTT.BAD_CHARACTER;
}
}
}
"-" { return RegExpTT.MINUS; }
@@ -27,9 +27,9 @@ import com.intellij.psi.search.scope.packageSet.lexer.ScopeTokenTypes;
public class PatternPackageSetParserExtension implements PackageSetParserExtension {
public PackageSet parsePackageSet(final Lexer lexer, final String scope, final String modulePattern) throws ParsingException {
if (scope == PatternPackageSet.SCOPE_ANY && modulePattern == null) {
/*if (scope == PatternPackageSet.SCOPE_ANY && modulePattern == null) {
error(AnalysisScopeBundle.message("error.packageset.common.expectations"), lexer);
}
}*/
if (scope != PatternPackageSet.SCOPE_ANY &&
scope != PatternPackageSet.SCOPE_LIBRARY &&
scope != PatternPackageSet.SCOPE_PROBLEM &&
@@ -33,10 +33,7 @@ import com.intellij.openapi.util.Comparing;
import com.intellij.openapi.util.Condition;
import com.intellij.openapi.util.IconLoader;
import com.intellij.packageDependencies.DependencyValidationManager;
import com.intellij.psi.search.scope.packageSet.NamedScope;
import com.intellij.psi.search.scope.packageSet.NamedScopeManager;
import com.intellij.psi.search.scope.packageSet.NamedScopesHolder;
import com.intellij.psi.search.scope.packageSet.PackageSet;
import com.intellij.psi.search.scope.packageSet.*;
import com.intellij.ui.TreeSpeedSearch;
import com.intellij.util.Icons;
import com.intellij.util.containers.Convertor;
@@ -126,6 +123,28 @@ public class ScopeChooserConfigurable extends MasterDetailsComponent implements
loadStateOrder();
}
@Override
protected void checkApply(Set<MyNode> rootNodes, String prefix, String title) throws ConfigurationException {
super.checkApply(rootNodes, prefix, title);
final Set<String> predefinedScopes = new HashSet<String>();
for (CustomScopesProvider scopesProvider : myProject.getExtensions(CustomScopesProvider.CUSTOM_SCOPES_PROVIDER)) {
for (NamedScope namedScope : scopesProvider.getCustomScopes()) {
predefinedScopes.add(namedScope.getName());
}
}
for (MyNode rootNode : rootNodes) {
for (int i = 0; i < rootNode.getChildCount(); i++) {
final MyNode node = (MyNode)rootNode.getChildAt(i);
final NamedConfigurable scopeConfigurable = node.getConfigurable();
final String name = scopeConfigurable.getDisplayName();
if (predefinedScopes.contains(name)) {
selectNodeInTree(node);
throw new ConfigurationException("Scope name equals to predefined one", ProjectBundle.message("rename.scope.title"));
}
}
}
}
@Override
protected PersistentStateComponent<?> getAdditionalSettings() {
return myScopesState;
@@ -57,7 +57,7 @@ public class NotificationComponent extends JLabel implements NotificationModelLi
@Override
public void mousePressed(final MouseEvent e) {
if (UIUtil.isActionClick(e)) {
showList();
toggleList();
}
}
});
@@ -97,16 +97,16 @@ public class NotificationComponent extends JLabel implements NotificationModelLi
getManager().addListener(this);
}
private void showList() {
private void toggleList() {
JBPopup popup = null;
if (myPopupRef != null) {
final JBPopup popup = myPopupRef.get();
if (popup != null && !popup.isVisible()) {
myPopupRef = null;
}
else if (popup == null) myPopupRef = null;
popup = myPopupRef.get();
myPopupRef = null;
}
if (myPopupRef == null) {
if (popup != null && popup.isVisible()) {
popup.cancel();
} else {
myPopupRef = new WeakReference<JBPopup>(NotificationsListPanel.show(getProject(), this));
}
}
@@ -29,7 +29,9 @@ import javax.swing.table.TableColumn;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;
import java.util.ArrayList;
import java.util.EventObject;
import java.util.Iterator;
import java.util.List;
@@ -111,6 +113,15 @@ public class NotificationsConfigurablePanel extends JPanel implements Disposable
});
displayTypeColumn.setCellEditor(new ComboBoxTableRenderer<NotificationDisplayType>(NotificationDisplayType.values()) {
@Override
public boolean isCellEditable(EventObject event) {
if (event instanceof MouseEvent) {
return ((MouseEvent)event).getClickCount() >= 1;
}
return false;
}
@Override
protected String getTextFor(@NotNull NotificationDisplayType value) {
return value.getTitle();
@@ -86,6 +86,8 @@ public class InfoAndProgressPanel extends JPanel implements StatusBarPatch {
public void mousePressed(MouseEvent e) {
if (!myPopup.isShowing()) {
openProcessPopup();
} else {
hideProcessPopup();
}
}
});
@@ -36,10 +36,7 @@ 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.conversion.ConversionException;
import org.jetbrains.idea.eclipse.conversion.DotProjectFileHelper;
import org.jetbrains.idea.eclipse.conversion.EclipseClasspathReader;
import org.jetbrains.idea.eclipse.conversion.EclipseClasspathWriter;
import org.jetbrains.idea.eclipse.conversion.*;
import java.io.File;
import java.io.IOException;
@@ -70,8 +67,6 @@ public class EclipseClasspathStorageProvider implements ClasspathStorageProvider
final Library library = ((LibraryOrderEntry)entry).getLibrary();
if (library == null ||
entry.getUrls(OrderRootType.CLASSES).length != 1 ||
entry.getUrls(OrderRootType.SOURCES).length > 1 ||
entry.getUrls(JavadocOrderRootType.getInstance()).length > 1 ||
library.isJarDirectory(library.getUrls(OrderRootType.CLASSES)[0])) {
throw new ConfigurationException(
"Library \'" + entry.getPresentableName() + "\' is incompatible with eclipse format which supports only one content root");
@@ -98,7 +93,7 @@ public class EclipseClasspathStorageProvider implements ClasspathStorageProvider
return new EclipseClasspathConverter(module);
}
static void registerFiles(final CachedXmlDocumentSet fileCache, final Module module, final String moduleRoot, final String storageRoot) {
public static void registerFiles(final CachedXmlDocumentSet fileCache, final Module module, final String moduleRoot, final String storageRoot) {
fileCache.register(EclipseXml.CLASSPATH_FILE, storageRoot);
fileCache.register(EclipseXml.PROJECT_FILE, storageRoot);
fileCache.register(EclipseXml.PLUGIN_XML_FILE, storageRoot);
@@ -171,15 +166,16 @@ public class EclipseClasspathStorageProvider implements ClasspathStorageProvider
final EclipseClasspathReader classpathReader = new EclipseClasspathReader(path, module.getProject(), null);
classpathReader.init(model);
if (documentSet.exists(EclipseXml.CLASSPATH_FILE)) {
classpathReader.readClasspath(model, new ArrayList<String>(), new ArrayList<String>(), usedVariables, new HashSet<String>(), null,
documentSet.read(EclipseXml.CLASSPATH_FILE).getRootElement());
final String eml = model.getModule().getName() + EclipseXml.IDEA_SETTINGS_POSTFIX;
if (documentSet.exists(eml)) {
EclipseClasspathReader.readIDEASpecific(documentSet.read(eml).getRootElement(), model);
} else {
model.getModuleExtension(CompilerModuleExtension.class).setExcludeOutput(false);
}
} else {
EclipseClasspathReader.setupOutput(model, path + "/bin");
}
final String eml = model.getModule().getName() + EclipseXml.IDEA_SETTINGS_POSTFIX;
if (documentSet.exists(eml)) {
IdeaSpecificSettings.readIDEASpecific(documentSet.read(eml).getRootElement(), model);
} else {
model.getModuleExtension(CompilerModuleExtension.class).setExcludeOutput(false);
}
((RootModelImpl)model).writeExternal(element);
@@ -224,7 +220,7 @@ public class EclipseClasspathStorageProvider implements ClasspathStorageProvider
final Element ideaSpecific = new Element(IdeaXml.COMPONENT_TAG);
final String emlFilename = model.getModule().getName() + EclipseXml.IDEA_SETTINGS_POSTFIX;
if (classpathWriter.writeIDEASpecificClasspath(ideaSpecific)) {
if (IdeaSpecificSettings.writeIDEASpecificClasspath(ideaSpecific, model)) {
fileSet.write(new Document(ideaSpecific), emlFilename);
}
else {
@@ -32,9 +32,7 @@ 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.InvalidDataException;
import com.intellij.openapi.util.SystemInfo;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.vfs.JarFileSystem;
import com.intellij.openapi.vfs.VfsUtil;
import com.intellij.openapi.vfs.VirtualFile;
@@ -153,9 +151,7 @@ public class EclipseClasspathReader {
}
else if (kind.equals(EclipseXml.OUTPUT_KIND)) {
final CompilerModuleExtension compilerModuleExtension = rootModel.getModuleExtension(CompilerModuleExtension.class);
compilerModuleExtension.setCompilerOutputPath(VfsUtil.pathToUrl(myRootPath + "/" + path));
compilerModuleExtension.inheritCompilerOutputPath(false);
setupOutput(rootModel, myRootPath + "/" + path);
}
else if (kind.equals(EclipseXml.LIB_KIND)) {
@@ -277,6 +273,12 @@ public class EclipseClasspathReader {
}
}
public static void setupOutput(ModifiableRootModel rootModel, final String path) {
final CompilerModuleExtension compilerModuleExtension = rootModel.getModuleExtension(CompilerModuleExtension.class);
compilerModuleExtension.setCompilerOutputPath(VfsUtil.pathToUrl(path));
compilerModuleExtension.inheritCompilerOutputPath(false);
}
private static void setLibraryEntryExported(ModifiableRootModel rootModel, boolean exported, Library library) {
for (OrderEntry orderEntry : rootModel.getOrderEntries()) {
if (orderEntry instanceof LibraryOrderEntry &&
@@ -485,109 +487,4 @@ public class EclipseClasspathReader {
return url;
}
public static void readIDEASpecific(final Element root, ModifiableRootModel model) throws InvalidDataException {
PathMacroManager.getInstance(model.getModule()).expandPaths(root);
model.getModuleExtension(LanguageLevelModuleExtension.class).readExternal(root);
final CompilerModuleExtension compilerModuleExtension = model.getModuleExtension(CompilerModuleExtension.class);
final Element testOutputElement = root.getChild(IdeaXml.OUTPUT_TEST_TAG);
if (testOutputElement != null) {
compilerModuleExtension.setCompilerOutputPathForTests(testOutputElement.getAttributeValue(IdeaXml.URL_ATTR));
}
final String inheritedOutput = root.getAttributeValue(IdeaXml.INHERIT_COMPILER_OUTPUT_ATTR);
if (inheritedOutput != null && Boolean.valueOf(inheritedOutput).booleanValue()) {
compilerModuleExtension.inheritCompilerOutputPath(true);
}
compilerModuleExtension.setExcludeOutput(root.getChild(IdeaXml.EXCLUDE_OUTPUT_TAG) != null);
final List entriesElements = root.getChildren(IdeaXml.CONTENT_ENTRY_TAG);
if (!entriesElements.isEmpty()) {
for (Object o : entriesElements) {
readContentEntry((Element)o, model.addContentEntry(((Element)o).getAttributeValue(IdeaXml.URL_ATTR)));
}
} else {
final ContentEntry[] entries = model.getContentEntries();
if (entries.length > 0) {
readContentEntry(root, entries[0]);
}
}
for (Object o : root.getChildren("lib")) {
Element libElement = (Element)o;
final String libName = libElement.getAttributeValue("name");
final Library libraryByName = model.getModuleLibraryTable().getLibraryByName(libName);
if (libraryByName != null) {
final LibraryOrderEntry libraryOrderEntry = model.findLibraryOrderEntry(libraryByName);
if (libraryOrderEntry != null) {
final String scopeAttribute = libElement.getAttributeValue("scope");
libraryOrderEntry.setScope(scopeAttribute == null ? DependencyScope.COMPILE : DependencyScope.valueOf(scopeAttribute));
}
final Library.ModifiableModel modifiableModel = libraryByName.getModifiableModel();
for (Object r : libElement.getChildren("srcroot")) {
modifiableModel.addRoot(((Element)r).getAttributeValue("url"), OrderRootType.SOURCES);
}
replaceModuleRelatedRoots(model.getProject(), modifiableModel, libElement, OrderRootType.SOURCES, "relative-module-src");
replaceModuleRelatedRoots(model.getProject(), modifiableModel, libElement, OrderRootType.CLASSES, "relative-module-cls");
modifiableModel.commit();
} else { //try to replace everywhere
final Library[] libraries = model.getModuleLibraryTable().getLibraries();
for (Library library : libraries) {
final Library.ModifiableModel modifiableModel = library.getModifiableModel();
replaceModuleRelatedRoots(model.getProject(), modifiableModel, libElement, OrderRootType.SOURCES, "relative-module-src");
replaceModuleRelatedRoots(model.getProject(), modifiableModel, libElement, OrderRootType.CLASSES, "relative-module-cls");
modifiableModel.commit();
}
}
}
}
private static void replaceModuleRelatedRoots(final Project project, final Library.ModifiableModel modifiableModel, final Element libElement,
final OrderRootType orderRootType, final String relativeModuleName) {
final List<String> urls = new ArrayList<String>(Arrays.asList(modifiableModel.getUrls(orderRootType)));
for (Object r : libElement.getChildren(relativeModuleName)) {
final String root = PathMacroManager.getInstance(project).expandPath(((Element)r).getAttributeValue("project-related"));
for (Iterator<String> iterator = urls.iterator(); iterator.hasNext();) {
String url = iterator.next();
if (root.contains(VfsUtil.urlToPath(url))) {
iterator.remove();
modifiableModel.removeRoot(url, orderRootType);
modifiableModel.addRoot(root, orderRootType);
break;
}
}
}
}
private static void readContentEntry(Element root, ContentEntry entry) {
for (Object o : root.getChildren(IdeaXml.TEST_FOLDER_TAG)) {
final String url = ((Element)o).getAttributeValue(IdeaXml.URL_ATTR);
SourceFolder folderToBeTest = null;
for (SourceFolder folder : entry.getSourceFolders()) {
if (Comparing.strEqual(folder.getUrl(), url)) {
folderToBeTest = folder;
break;
}
}
if (folderToBeTest != null) {
entry.removeSourceFolder(folderToBeTest);
}
entry.addSourceFolder(url, true);
}
final String url = entry.getUrl();
for (Object o : root.getChildren(IdeaXml.EXCLUDE_FOLDER_TAG)) {
final String excludeUrl = ((Element)o).getAttributeValue(IdeaXml.URL_ATTR);
try {
if (FileUtil.isAncestor(new File(url), new File(excludeUrl), false)) { //check if it is excluded manually
entry.addExcludeFolder(excludeUrl);
}
}
catch (IOException e) {
//ignore
}
}
}
}
@@ -30,7 +30,6 @@ import com.intellij.openapi.projectRoots.Sdk;
import com.intellij.openapi.roots.*;
import com.intellij.openapi.roots.impl.ProjectRootManagerImpl;
import com.intellij.openapi.util.Comparing;
import com.intellij.openapi.util.WriteExternalException;
import com.intellij.openapi.util.text.CharFilter;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.vfs.JarFileSystem;
@@ -38,7 +37,6 @@ import com.intellij.openapi.vfs.VfsUtil;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.openapi.vfs.VirtualFileManager;
import com.intellij.openapi.vfs.ex.http.HttpFileSystem;
import com.intellij.pom.java.LanguageLevel;
import org.jdom.Element;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.Nullable;
@@ -309,111 +307,6 @@ public class EclipseClasspathWriter {
return (leaveLeadingSlash ? "/" : "") + stripped;
}
public boolean writeIDEASpecificClasspath(final Element root) throws WriteExternalException {
boolean isModified = false;
final CompilerModuleExtension compilerModuleExtension = myModel.getModuleExtension(CompilerModuleExtension.class);
if (compilerModuleExtension.getCompilerOutputPathForTests() != null) {
final Element pathElement = new Element(IdeaXml.OUTPUT_TEST_TAG);
pathElement.setAttribute(IdeaXml.URL_ATTR, compilerModuleExtension.getCompilerOutputUrlForTests());
root.addContent(pathElement);
isModified = true;
}
if (compilerModuleExtension.isCompilerOutputPathInherited()) {
root.setAttribute(IdeaXml.INHERIT_COMPILER_OUTPUT_ATTR, String.valueOf(true));
isModified = true;
}
if (compilerModuleExtension.isExcludeOutput()) {
root.addContent(new Element(IdeaXml.EXCLUDE_OUTPUT_TAG));
isModified = true;
}
final LanguageLevelModuleExtension languageLevelModuleExtension = myModel.getModuleExtension(LanguageLevelModuleExtension.class);
final LanguageLevel languageLevel = languageLevelModuleExtension.getLanguageLevel();
if (languageLevel != null) {
languageLevelModuleExtension.writeExternal(root);
isModified = true;
}
for (ContentEntry entry : myModel.getContentEntries()) {
final Element contentEntryElement = new Element(IdeaXml.CONTENT_ENTRY_TAG);
contentEntryElement.setAttribute(IdeaXml.URL_ATTR, entry.getUrl());
root.addContent(contentEntryElement);
for (SourceFolder sourceFolder : entry.getSourceFolders()) {
if (sourceFolder.isTestSource()) {
Element element = new Element(IdeaXml.TEST_FOLDER_TAG);
contentEntryElement.addContent(element);
element.setAttribute(IdeaXml.URL_ATTR, sourceFolder.getUrl());
isModified = true;
}
}
final VirtualFile entryFile = entry.getFile();
for (ExcludeFolder excludeFolder : entry.getExcludeFolders()) {
final String exludeFolderUrl = excludeFolder.getUrl();
final VirtualFile excludeFile = excludeFolder.getFile();
if (entryFile == null || excludeFile == null || VfsUtil.isAncestor(entryFile, excludeFile, false)) {
Element element = new Element(IdeaXml.EXCLUDE_FOLDER_TAG);
contentEntryElement.addContent(element);
element.setAttribute(IdeaXml.URL_ATTR, exludeFolderUrl);
isModified = true;
}
}
}
for (OrderEntry entry : myModel.getOrderEntries()) {
if (entry instanceof LibraryOrderEntry && ((LibraryOrderEntry)entry).isModuleLevel()) {
final Element element = new Element("lib");
element.setAttribute("name", entry.getPresentableName());
final DependencyScope scope = ((LibraryOrderEntry)entry).getScope();
element.setAttribute("scope", scope.name());
final String[] urls = entry.getUrls(OrderRootType.SOURCES);
if (urls.length > 1) {
for (int i = 0; i < urls.length - 1; i++) {
Element srcElement = new Element("srcroot");
srcElement.setAttribute("url", urls[i]);
element.addContent(srcElement);
}
}
for (String srcUrl : entry.getUrls(OrderRootType.SOURCES)) {
appendModuleRelatedRoot(element, srcUrl, "relative-module-src");
}
for (String classesUrl : entry.getUrls(OrderRootType.CLASSES)) {
appendModuleRelatedRoot(element, classesUrl, "relative-module-cls");
}
if (!element.getChildren().isEmpty() || !scope.equals(DependencyScope.COMPILE)) root.addContent(element);
}
}
PathMacroManager.getInstance(myModel.getModule()).collapsePaths(root);
return isModified;
}
private boolean appendModuleRelatedRoot(Element element, String classesUrl, final String rootMame) {
VirtualFile file = VirtualFileManager.getInstance().findFileByUrl(classesUrl);
if (file != null) {
if (file.getFileSystem() instanceof JarFileSystem) {
file = JarFileSystem.getInstance().getVirtualFileForJar(file);
assert file != null;
}
final Module module = ModuleUtil.findModuleForFile(file, myModel.getProject());
if (module != null && module != myModel.getModule()) {
final VirtualFile[] contentRoots = ModuleRootManager.getInstance(module).getContentRoots();
if (contentRoots.length > 0 && VfsUtil.isAncestor(contentRoots[0], file, false)) {
final Element clsElement = new Element(rootMame);
clsElement.setAttribute("project-related", PathMacroManager.getInstance(module.getProject()).collapsePath(classesUrl));
element.addContent(clsElement);
return true;
}
}
}
return false;
}
private static Element addOrderEntry(String kind, String path, Element classpathRoot, Element oldRoot) {
if (oldRoot != null) {
@@ -0,0 +1,297 @@
/*
* Copyright 2000-2009 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.
*/
/*
* User: anna
* Date: 18-Dec-2009
*/
package org.jetbrains.idea.eclipse.conversion;
import com.intellij.openapi.components.PathMacroManager;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.module.ModuleUtil;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.roots.*;
import com.intellij.openapi.roots.libraries.Library;
import com.intellij.openapi.util.Comparing;
import com.intellij.openapi.util.InvalidDataException;
import com.intellij.openapi.util.WriteExternalException;
import com.intellij.openapi.util.io.FileUtil;
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.pom.java.LanguageLevel;
import org.jdom.Element;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.idea.eclipse.IdeaXml;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
/**
* Read/write .eml
*/
public class IdeaSpecificSettings {
@NonNls private static final String RELATIVE_MODULE_SRC = "relative-module-src";
@NonNls private static final String RELATIVE_MODULE_CLS = "relative-module-cls";
@NonNls private static final String PROJECT_RELATED = "project-related";
@NonNls private static final String SRCROOT_ATTR = "srcroot";
private static final Logger LOG = Logger.getInstance("#" + IdeaSpecificSettings.class.getName());
private IdeaSpecificSettings() {
}
public static void readIDEASpecific(final Element root, ModifiableRootModel model) throws InvalidDataException {
PathMacroManager.getInstance(model.getModule()).expandPaths(root);
model.getModuleExtension(LanguageLevelModuleExtension.class).readExternal(root);
final CompilerModuleExtension compilerModuleExtension = model.getModuleExtension(CompilerModuleExtension.class);
final Element testOutputElement = root.getChild(IdeaXml.OUTPUT_TEST_TAG);
if (testOutputElement != null) {
compilerModuleExtension.setCompilerOutputPathForTests(testOutputElement.getAttributeValue(IdeaXml.URL_ATTR));
}
final String inheritedOutput = root.getAttributeValue(IdeaXml.INHERIT_COMPILER_OUTPUT_ATTR);
if (inheritedOutput != null && Boolean.valueOf(inheritedOutput).booleanValue()) {
compilerModuleExtension.inheritCompilerOutputPath(true);
}
compilerModuleExtension.setExcludeOutput(root.getChild(IdeaXml.EXCLUDE_OUTPUT_TAG) != null);
final List entriesElements = root.getChildren(IdeaXml.CONTENT_ENTRY_TAG);
if (!entriesElements.isEmpty()) {
for (Object o : entriesElements) {
readContentEntry((Element)o, model.addContentEntry(((Element)o).getAttributeValue(IdeaXml.URL_ATTR)));
}
} else {
final ContentEntry[] entries = model.getContentEntries();
if (entries.length > 0) {
readContentEntry(root, entries[0]);
}
}
for (Object o : root.getChildren("lib")) {
Element libElement = (Element)o;
final String libName = libElement.getAttributeValue("name");
final Library libraryByName = model.getModuleLibraryTable().getLibraryByName(libName);
if (libraryByName != null) {
final LibraryOrderEntry libraryOrderEntry = model.findLibraryOrderEntry(libraryByName);
if (libraryOrderEntry != null) {
final String scopeAttribute = libElement.getAttributeValue("scope");
libraryOrderEntry.setScope(scopeAttribute == null ? DependencyScope.COMPILE : DependencyScope.valueOf(scopeAttribute));
}
final Library.ModifiableModel modifiableModel = libraryByName.getModifiableModel();
replaceCollapsedByEclipseSourceRoots(libElement, modifiableModel);
replaceModuleRelatedRoots(model.getProject(), modifiableModel, libElement, OrderRootType.SOURCES, RELATIVE_MODULE_SRC);
replaceModuleRelatedRoots(model.getProject(), modifiableModel, libElement, OrderRootType.CLASSES, RELATIVE_MODULE_CLS);
modifiableModel.commit();
} else { //try to replace everywhere
final Library[] libraries = model.getModuleLibraryTable().getLibraries();
for (Library library : libraries) {
final Library.ModifiableModel modifiableModel = library.getModifiableModel();
replaceModuleRelatedRoots(model.getProject(), modifiableModel, libElement, OrderRootType.SOURCES, RELATIVE_MODULE_SRC);
replaceModuleRelatedRoots(model.getProject(), modifiableModel, libElement, OrderRootType.CLASSES, RELATIVE_MODULE_CLS);
modifiableModel.commit();
}
}
}
}
/**
* Eclipse detect sources inside zip automatically while IDEA doesn't.
* So .eml contains expanded roots which should replace zip root read from .classpath
*/
private static void replaceCollapsedByEclipseSourceRoots(Element libElement, Library.ModifiableModel modifiableModel) {
String[] srcUrlsFromClasspath = modifiableModel.getUrls(OrderRootType.SOURCES);
LOG.assertTrue(srcUrlsFromClasspath.length <= 1);
for (Object r : libElement.getChildren(SRCROOT_ATTR)) {
final String url = ((Element)r).getAttributeValue("url");
modifiableModel.addRoot(url, OrderRootType.SOURCES);
if (srcUrlsFromClasspath != null && srcUrlsFromClasspath.length == 1 && url.contains(VfsUtil.urlToPath(srcUrlsFromClasspath[0]))) { //remove compound root
modifiableModel.removeRoot(srcUrlsFromClasspath[0], OrderRootType.SOURCES);
srcUrlsFromClasspath = null;
}
}
}
public static void replaceModuleRelatedRoots(final Project project,
final Library.ModifiableModel modifiableModel, final Element libElement,
final OrderRootType orderRootType, final String relativeModuleName) {
final List<String> urls = new ArrayList<String>(Arrays.asList(modifiableModel.getUrls(orderRootType)));
for (Object r : libElement.getChildren(relativeModuleName)) {
final String root = PathMacroManager.getInstance(project).expandPath(((Element)r).getAttributeValue(PROJECT_RELATED));
for (Iterator<String> iterator = urls.iterator(); iterator.hasNext();) {
String url = iterator.next();
if (root.contains(VfsUtil.urlToPath(url))) {
iterator.remove();
modifiableModel.removeRoot(url, orderRootType);
modifiableModel.addRoot(root, orderRootType);
break;
}
}
}
}
public static void readContentEntry(Element root, ContentEntry entry) {
for (Object o : root.getChildren(IdeaXml.TEST_FOLDER_TAG)) {
final String url = ((Element)o).getAttributeValue(IdeaXml.URL_ATTR);
SourceFolder folderToBeTest = null;
for (SourceFolder folder : entry.getSourceFolders()) {
if (Comparing.strEqual(folder.getUrl(), url)) {
folderToBeTest = folder;
break;
}
}
if (folderToBeTest != null) {
entry.removeSourceFolder(folderToBeTest);
}
entry.addSourceFolder(url, true);
}
final String url = entry.getUrl();
for (Object o : root.getChildren(IdeaXml.EXCLUDE_FOLDER_TAG)) {
final String excludeUrl = ((Element)o).getAttributeValue(IdeaXml.URL_ATTR);
try {
if (FileUtil.isAncestor(new File(url), new File(excludeUrl), false)) { //check if it is excluded manually
entry.addExcludeFolder(excludeUrl);
}
}
catch (IOException e) {
//ignore
}
}
}
public static boolean writeIDEASpecificClasspath(final Element root, ModifiableRootModel model) throws WriteExternalException {
boolean isModified = false;
final CompilerModuleExtension compilerModuleExtension = model.getModuleExtension(CompilerModuleExtension.class);
if (compilerModuleExtension.getCompilerOutputPathForTests() != null) {
final Element pathElement = new Element(IdeaXml.OUTPUT_TEST_TAG);
pathElement.setAttribute(IdeaXml.URL_ATTR, compilerModuleExtension.getCompilerOutputUrlForTests());
root.addContent(pathElement);
isModified = true;
}
if (compilerModuleExtension.isCompilerOutputPathInherited()) {
root.setAttribute(IdeaXml.INHERIT_COMPILER_OUTPUT_ATTR, String.valueOf(true));
isModified = true;
}
if (compilerModuleExtension.isExcludeOutput()) {
root.addContent(new Element(IdeaXml.EXCLUDE_OUTPUT_TAG));
isModified = true;
}
final LanguageLevelModuleExtension languageLevelModuleExtension = model.getModuleExtension(LanguageLevelModuleExtension.class);
final LanguageLevel languageLevel = languageLevelModuleExtension.getLanguageLevel();
if (languageLevel != null) {
languageLevelModuleExtension.writeExternal(root);
isModified = true;
}
for (ContentEntry entry : model.getContentEntries()) {
final Element contentEntryElement = new Element(IdeaXml.CONTENT_ENTRY_TAG);
contentEntryElement.setAttribute(IdeaXml.URL_ATTR, entry.getUrl());
root.addContent(contentEntryElement);
for (SourceFolder sourceFolder : entry.getSourceFolders()) {
if (sourceFolder.isTestSource()) {
Element element = new Element(IdeaXml.TEST_FOLDER_TAG);
contentEntryElement.addContent(element);
element.setAttribute(IdeaXml.URL_ATTR, sourceFolder.getUrl());
isModified = true;
}
}
final VirtualFile entryFile = entry.getFile();
for (ExcludeFolder excludeFolder : entry.getExcludeFolders()) {
final String exludeFolderUrl = excludeFolder.getUrl();
final VirtualFile excludeFile = excludeFolder.getFile();
if (entryFile == null || excludeFile == null || VfsUtil.isAncestor(entryFile, excludeFile, false)) {
Element element = new Element(IdeaXml.EXCLUDE_FOLDER_TAG);
contentEntryElement.addContent(element);
element.setAttribute(IdeaXml.URL_ATTR, exludeFolderUrl);
isModified = true;
}
}
}
for (OrderEntry entry : model.getOrderEntries()) {
if (entry instanceof LibraryOrderEntry && ((LibraryOrderEntry)entry).isModuleLevel()) {
final Element element = new Element("lib");
element.setAttribute("name", entry.getPresentableName());
final DependencyScope scope = ((LibraryOrderEntry)entry).getScope();
element.setAttribute("scope", scope.name());
final String[] urls = entry.getUrls(OrderRootType.SOURCES);
if (urls.length > 1) {
for (int i = 0; i < urls.length - 1; i++) {
Element srcElement = new Element(SRCROOT_ATTR);
srcElement.setAttribute("url", urls[i]);
element.addContent(srcElement);
}
}
else if (urls.length == 1 && urls[0].contains(JarFileSystem.JAR_SEPARATOR)) {
final VirtualFile virtualFile = JarFileSystem.getInstance().findFileByPath(VfsUtil.urlToPath(urls[0]));
if (virtualFile != null) {
Element srcElement = new Element(SRCROOT_ATTR);
srcElement.setAttribute("url", urls[0]);
element.addContent(srcElement);
}
}
for (String srcUrl : entry.getUrls(OrderRootType.SOURCES)) {
appendModuleRelatedRoot(element, srcUrl, RELATIVE_MODULE_SRC, model);
}
for (String classesUrl : entry.getUrls(OrderRootType.CLASSES)) {
appendModuleRelatedRoot(element, classesUrl, RELATIVE_MODULE_CLS, model);
}
if (!element.getChildren().isEmpty() || !scope.equals(DependencyScope.COMPILE)) root.addContent(element);
}
}
PathMacroManager.getInstance(model.getModule()).collapsePaths(root);
return isModified;
}
public static boolean appendModuleRelatedRoot(Element element, String classesUrl, final String rootMame, ModifiableRootModel model) {
VirtualFile file = VirtualFileManager.getInstance().findFileByUrl(classesUrl);
if (file != null) {
if (file.getFileSystem() instanceof JarFileSystem) {
file = JarFileSystem.getInstance().getVirtualFileForJar(file);
assert file != null;
}
final Module module = ModuleUtil.findModuleForFile(file, model.getProject());
if (module != null && module != model.getModule()) {
final VirtualFile[] contentRoots = ModuleRootManager.getInstance(module).getContentRoots();
if (contentRoots.length > 0 && VfsUtil.isAncestor(contentRoots[0], file, false)) {
final Element clsElement = new Element(rootMame);
clsElement.setAttribute(PROJECT_RELATED, PathMacroManager.getInstance(module.getProject()).collapsePath(classesUrl));
element.addContent(clsElement);
return true;
}
}
}
return false;
}
}
@@ -39,10 +39,7 @@ import org.jetbrains.idea.eclipse.EclipseBundle;
import org.jetbrains.idea.eclipse.EclipseXml;
import org.jetbrains.idea.eclipse.IdeaXml;
import org.jetbrains.idea.eclipse.config.EclipseClasspathStorageProvider;
import org.jetbrains.idea.eclipse.conversion.ConversionException;
import org.jetbrains.idea.eclipse.conversion.DotProjectFileHelper;
import org.jetbrains.idea.eclipse.conversion.EclipseClasspathWriter;
import org.jetbrains.idea.eclipse.conversion.EclipseUserLibrariesHelper;
import org.jetbrains.idea.eclipse.conversion.*;
import java.io.File;
import java.io.IOException;
@@ -115,7 +112,7 @@ public class ExportEclipseProjectsAction extends AnAction implements DumbAware {
EclipseJDOMUtil.output(new Document(classpathEleemnt), classpathFile, project);
final Element ideaSpecific = new Element(IdeaXml.COMPONENT_TAG);
if (classpathWriter.writeIDEASpecificClasspath(ideaSpecific)) {
if (IdeaSpecificSettings.writeIDEASpecificClasspath(ideaSpecific, model)) {
final File emlFile = new File(storageRoot, module.getName() + EclipseXml.IDEA_SETTINGS_POSTFIX);
if (!FileUtil.createIfDoesntExist(emlFile)) continue;
EclipseJDOMUtil.output(new Document(ideaSpecific), emlFile, project);
@@ -47,9 +47,9 @@ import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.vfs.LocalFileSystem;
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.packaging.artifacts.ModifiableArtifactModel;
import org.jdom.Element;
import org.jdom.JDOMException;
import org.jetbrains.annotations.NotNull;
@@ -264,6 +264,8 @@ public class EclipseImportBuilder extends ProjectImportBuilder<String> implement
final Element classpathElement = JDOMUtil.loadDocument(classpathFile).getRootElement();
classpathReader.readClasspath(rootModel, unknownLibraries, unknownJdks, usedVariables, refsToModules,
getParameters().converterOptions.testPattern, classpathElement);
} else {
EclipseClasspathReader.setupOutput(rootModel, path + "/bin");
}
ClasspathStorage.setStorageType(rootModel,
getParameters().linkConverted ? EclipseClasspathStorageProvider.ID : ClasspathStorage.DEFAULT_STORAGE);
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="lib" path="lib/jar-all-5.zip" sourcepath="$ROOT$/lib/jar-all-5.zip"/>
<classpathentry kind="output" path="bin"/>
</classpath>
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>srcInZip</name>
<comment />
<projects />
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments />
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<component>
<exclude-output/>
<contentEntry url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/bin"/>
<excludeFolder url="file://$MODULE_DIR$/bin"/>
</contentEntry>
<lib name="jar-all-5.zip" scope="COMPILE">
<srcroot url="jar://$ROOT$/lib/jar-all-5.zip!/doc/api"/>
</lib>
</component>
@@ -0,0 +1,118 @@
/*
* Copyright 2000-2009 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.
*/
/*
* User: anna
* Date: 28-Nov-2008
*/
package org.jetbrains.idea.eclipse;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.application.PluginPathManager;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.module.ModuleManager;
import com.intellij.openapi.module.StdModuleTypes;
import com.intellij.openapi.roots.ModifiableRootModel;
import com.intellij.openapi.roots.ModuleRootManager;
import com.intellij.openapi.util.Computable;
import com.intellij.openapi.util.JDOMUtil;
import com.intellij.openapi.util.SystemInfo;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.vfs.LocalFileSystem;
import com.intellij.testFramework.IdeaTestCase;
import com.intellij.testFramework.IdeaTestUtil;
import org.jdom.Element;
import org.jdom.JDOMException;
import org.jetbrains.idea.eclipse.config.CachedXmlDocumentSet;
import org.jetbrains.idea.eclipse.config.EclipseClasspathStorageProvider;
import org.jetbrains.idea.eclipse.config.EclipseModuleManager;
import org.jetbrains.idea.eclipse.importWizard.EclipseProjectFinder;
import java.io.File;
import java.io.IOException;
public class EclipseEmlTest extends IdeaTestCase {
@Override
protected void setUp() throws Exception {
super.setUp();
final File testRoot = new File(PluginPathManager.getPluginHomePath("eclipse") + "/testData", "eml");
assertTrue(testRoot.getAbsolutePath(), testRoot.isDirectory());
final File currentTestRoot = new File(testRoot, getTestName(true));
assertTrue(currentTestRoot.getAbsolutePath(), currentTestRoot.isDirectory());
FileUtil.copyDir(currentTestRoot, new File(getProject().getBaseDir().getPath()));
}
private void doTest(String relativePath) throws Exception {
final String path = getProject().getBaseDir().getPath() + relativePath;
final Module module = ApplicationManager.getApplication().runWriteAction(new Computable<Module>() {
public Module compute() {
return ModuleManager.getInstance(getProject())
.newModule(path + "/" + EclipseProjectFinder.findProjectName(path) + IdeaXml.IML_EXT, StdModuleTypes.JAVA);
}
});
replaceRoot(path, module.getName() + EclipseXml.IDEA_SETTINGS_POSTFIX);
replaceRoot(path, EclipseXml.DOT_CLASSPATH_EXT);
final EclipseClasspathStorageProvider.EclipseClasspathConverter converter =
new EclipseClasspathStorageProvider.EclipseClasspathConverter(module);
final ModifiableRootModel rootModel = ModuleRootManager.getInstance(module).getModifiableModel();
final Element classpathElement = JDOMUtil.loadDocument(new String(FileUtil.loadFileText(new File(path, EclipseXml.DOT_CLASSPATH_EXT)))).getRootElement();
converter.getClasspath(rootModel, classpathElement);
final File tempDirectory = FileUtil.createTempDirectory("", "");
tempDirectory.deleteOnExit();
FileUtil.copyDir(new File(path), tempDirectory);
new EclipseClasspathStorageProvider.EclipseClasspathConverter(module) {
@Override
public CachedXmlDocumentSet getFileSet() {
CachedXmlDocumentSet fileCache = new CachedXmlDocumentSet(module.getProject());
EclipseModuleManager.getInstance(module).setDocumentSet(fileCache);
EclipseClasspathStorageProvider
.registerFiles(fileCache, module, tempDirectory.getPath(), tempDirectory.getPath());
fileCache.preload();
return fileCache;
}
}.setClasspath(rootModel);
rootModel.dispose();
IdeaTestUtil.assertDirectoriesEqual(LocalFileSystem.getInstance().findFileByIoFile(new File(path, EclipseXml.DOT_CLASSPATH_EXT).getParentFile()),
LocalFileSystem.getInstance().findFileByIoFile(tempDirectory), null);
}
private void replaceRoot(String path, final String child) throws IOException, JDOMException {
final File emlFile = new File(path, child);
String fileText = new String(FileUtil.loadFileText(emlFile)).replaceAll("\\$ROOT\\$", getProject().getBaseDir().getPath());
if (!SystemInfo.isWindows) {
fileText = fileText.replaceAll(EclipseXml.FILE_PROTOCOL + "/", EclipseXml.FILE_PROTOCOL);
}
JDOMUtil.writeDocument(JDOMUtil.loadDocument(fileText), emlFile, "\n");
}
public void testSrcInZip() throws Exception {
doTest("/test");
}
}
@@ -147,7 +147,7 @@ public class MavenResourceCompiler implements ClassPostProcessingCompiler {
MavenProject mavenProject = mavenProjectManager.findProject(eachModule);
if (mavenProject == null) continue;
Properties properties = loadFilters(context, mavenProject);
Properties properties = loadPropertiesAndFilters(context, mavenProject);
List<String> nonFilteredExtensions = collectNonFilteredExtensions(mavenProject);
String escapeString = mavenProject.findPluginConfigurationValue("org.apache.maven.plugins",
@@ -202,8 +202,10 @@ public class MavenResourceCompiler implements ClassPostProcessingCompiler {
return sorted.hashCode();
}
private static Properties loadFilters(CompileContext context, MavenProject mavenProject) {
private static Properties loadPropertiesAndFilters(CompileContext context, MavenProject mavenProject) {
Properties properties = new Properties();
properties.putAll(mavenProject.getProperties());
for (String each : mavenProject.getFilters()) {
try {
FileInputStream in = new FileInputStream(each);
@@ -509,7 +511,7 @@ public class MavenResourceCompiler implements ClassPostProcessingCompiler {
private LightVirtualFile myFile;
private FakeProcessingItem() {
myFile = new LightVirtualFile("fooBar");
myFile = new LightVirtualFile(this.getClass().getName());
}
@NotNull
@@ -523,52 +525,50 @@ public class MavenResourceCompiler implements ClassPostProcessingCompiler {
}
private static class MyValididtyState implements ValidityState {
private final TimestampValidityState myTimestampState;
private final long mySourceFileTimestamp;
private volatile long myOutputFileTimestamp;
private final boolean myFiltered;
private final long myPropertiesHashCode;
private final String myEscapeString;
public static MyValididtyState load(DataInput in) throws IOException {
return new MyValididtyState(TimestampValidityState.load(in), in.readLong(), in.readBoolean(), in.readLong(), in.readUTF());
}
public MyValididtyState(long sourceFileTimestamp,
long outputFileTimestamp,
boolean isFiltered,
long propertiesHashCode,
String escapeString) {
this(new TimestampValidityState(sourceFileTimestamp), outputFileTimestamp, isFiltered, propertiesHashCode, escapeString);
return new MyValididtyState(in.readLong(), in.readLong(), in.readBoolean(), in.readLong(), in.readUTF());
}
public void setOutputFileTimestamp(long outputFileTimestamp) {
myOutputFileTimestamp = outputFileTimestamp;
}
private MyValididtyState(TimestampValidityState timestampState,
private MyValididtyState(long sourceFileTimestamp,
long outputFileTimestamp,
boolean isFiltered,
long propertiesHashCode,
String escapeString) {
myTimestampState = timestampState;
mySourceFileTimestamp = sourceFileTimestamp;
myOutputFileTimestamp = outputFileTimestamp;
myFiltered = isFiltered;
myPropertiesHashCode = propertiesHashCode;
myEscapeString = escapeString;
}
@Override
public String toString() {
return mySourceFileTimestamp + " " + myOutputFileTimestamp + " " + myFiltered + " " + myPropertiesHashCode + " " + myEscapeString;
}
public boolean equalsTo(ValidityState otherState) {
if (!(otherState instanceof MyValididtyState)) return false;
MyValididtyState state = (MyValididtyState)otherState;
return myTimestampState.equalsTo(state.myTimestampState)
&& myOutputFileTimestamp == state.myOutputFileTimestamp
&& myFiltered == state.myFiltered
&& myPropertiesHashCode == state.myPropertiesHashCode
&& Comparing.strEqual(myEscapeString, state.myEscapeString);
MyValididtyState that = (MyValididtyState)otherState;
return mySourceFileTimestamp == that.mySourceFileTimestamp
&& myOutputFileTimestamp == that.myOutputFileTimestamp
&& myFiltered == that.myFiltered
&& myPropertiesHashCode == that.myPropertiesHashCode
&& Comparing.strEqual(myEscapeString, that.myEscapeString);
}
public void save(DataOutput out) throws IOException {
myTimestampState.save(out);
out.writeLong(mySourceFileTimestamp);
out.writeLong(myOutputFileTimestamp);
out.writeBoolean(myFiltered);
out.writeLong(myPropertiesHashCode);
@@ -367,7 +367,7 @@ public abstract class MavenTestCase extends UsefulTestCase {
}
private void setFileContent(VirtualFile file, String content) throws IOException {
file.setBinaryContent(content.getBytes(), -1, file.getTimeStamp() + 1000);
file.setBinaryContent(content.getBytes(), file.getModificationStamp() + 4000, file.getTimeStamp() + 4000);
}
protected void assertPathEquals(String expected, String actual) {
@@ -15,13 +15,25 @@
*/
package org.jetbrains.idea.maven.compiler;
import com.intellij.compiler.CompilerManagerImpl;
import com.intellij.compiler.CompilerWorkspaceConfiguration;
import com.intellij.compiler.impl.ModuleCompileScope;
import com.intellij.compiler.impl.TranslatingCompilerFilesMonitor;
import com.intellij.openapi.compiler.*;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.roots.ProjectRootManager;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.vfs.VfsUtil;
import com.intellij.openapi.vfs.VirtualFile;
import org.jetbrains.idea.maven.MavenImportingTestCase;
import org.jetbrains.idea.maven.importing.MavenDefaultModifiableModelsProvider;
import org.jetbrains.idea.maven.importing.MavenRootModelAdapter;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class ResourceFilteringTest extends MavenImportingTestCase {
public void testBasic() throws Exception {
@@ -114,7 +126,7 @@ public class ResourceFilteringTest extends MavenImportingTestCase {
assertResult("target/classes/file.bmp", "value=${project.version}");
}
public void testCustomNonFilteredExtensions() throws Exception {
createProjectSubFile("resources/file.bmp", "value=${project.version}");
createProjectSubFile("resources/file.xxx", "value=${project.version}");
@@ -239,7 +251,7 @@ public class ResourceFilteringTest extends MavenImportingTestCase {
assertResult("target/classes/file1.properties", "value=project");
assertResult("target/classes/file2.properties", "value=${project.artifactId}");
}
public void testEscapingSpecialCharsInProperties() throws Exception {
createProjectSubFile("resources/file.txt", "value=${foo}");
@@ -414,7 +426,7 @@ public class ResourceFilteringTest extends MavenImportingTestCase {
assertResult("target/classes/file.properties", "value=${project.version}");
}
public void testUpdatingWhenPropertiesAreChanged() throws Exception {
public void testUpdatingWhenPropertiesInFiltersAreChanged() throws Exception {
VirtualFile filter = createProjectSubFile("filters/filter.properties", "xxx=1");
createProjectSubFile("resources/file.properties", "value=${xxx}");
@@ -441,6 +453,127 @@ public class ResourceFilteringTest extends MavenImportingTestCase {
assertResult("target/classes/file.properties", "value=2");
}
public void testUpdatingWhenPropertiesAreChanged() throws Exception {
createProjectSubFile("resources/file.properties", "value=${foo}");
importProject("<groupId>test</groupId>" +
"<artifactId>project</artifactId>" +
"<version>1</version>" +
"<properties>" +
" <foo>val1</foo>" +
"</properties>" +
"<build>" +
" <resources>" +
" <resource>" +
" <directory>resources</directory>" +
" <filtering>true</filtering>" +
" </resource>" +
" </resources>" +
"</build>");
compileModules("project");
assertResult("target/classes/file.properties", "value=val1");
importProject("<groupId>test</groupId>" +
"<artifactId>project</artifactId>" +
"<version>1</version>" +
"<properties>" +
" <foo>val2</foo>" +
"</properties>" +
"<build>" +
" <resources>" +
" <resource>" +
" <directory>resources</directory>" +
" <filtering>true</filtering>" +
" </resource>" +
" </resources>" +
"</build>");
compileModules("project");
assertResult("target/classes/file.properties", "value=val2");
}
public void testUpdatingWhenPropertiesInModelAreChanged() throws Exception {
createProjectSubFile("resources/file.properties", "value=${project.name}");
importProject("<groupId>test</groupId>" +
"<artifactId>project</artifactId>" +
"<version>1</version>" +
"<name>val1</name>" +
"<build>" +
" <resources>" +
" <resource>" +
" <directory>resources</directory>" +
" <filtering>true</filtering>" +
" </resource>" +
" </resources>" +
"</build>");
compileModules("project");
assertResult("target/classes/file.properties", "value=val1");
importProject("<groupId>test</groupId>" +
"<artifactId>project</artifactId>" +
"<version>1</version>" +
"<name>val2</name>" +
"<build>" +
" <resources>" +
" <resource>" +
" <directory>resources</directory>" +
" <filtering>true</filtering>" +
" </resource>" +
" </resources>" +
"</build>");
compileModules("project");
assertResult("target/classes/file.properties", "value=val2");
}
public void testUpdatingWhenProfilesAreChanged() throws Exception {
createProjectSubFile("resources/file.properties", "value=${foo}");
createProjectPom("<groupId>test</groupId>" +
"<artifactId>project</artifactId>" +
"<version>1</version>" +
"<profiles>" +
" <profile>" +
" <id>one</id>" +
" <properties>" +
" <foo>val1</foo>" +
" </properties>" +
" </profile>" +
" <profile>" +
" <id>two</id>" +
" <properties>" +
" <foo>val2</foo>" +
" </properties>" +
" </profile>" +
"</profiles>" +
"<build>" +
" <resources>" +
" <resource>" +
" <directory>resources</directory>" +
" <filtering>true</filtering>" +
" </resource>" +
" </resources>" +
"</build>");
importProjectWithProfiles("one");
compileModules("project");
assertResult("target/classes/file.properties", "value=val1");
myProjectsManager.setActiveProfiles(Arrays.asList("two"));
scheduleResolveAll();
resolveDependenciesAndImport();
compileModules("project");
assertResult("target/classes/file.properties", "value=val2");
}
public void testSameFileInSourcesAndTestSources() throws Exception {
createProjectSubFile("src/main/resources/file.properties", "foo=${foo.main}");
createProjectSubFile("src/test/resources/file.properties", "foo=${foo.test}");
@@ -629,7 +629,7 @@ public class StructureImportingTest extends MavenImportingTestCase {
"</build>");
assertModules("project");
assertEquals(LanguageLevel.JDK_1_4, getLanguageLevelForProject());
assertEquals(LanguageLevel.JDK_1_4, getLanguageLevelForModule());
}
public void testLanguageLevel6() throws Exception {
@@ -650,7 +650,7 @@ public class StructureImportingTest extends MavenImportingTestCase {
"</build>");
assertModules("project");
assertEquals(LanguageLevel.JDK_1_6, getLanguageLevelForProject());
assertEquals(LanguageLevel.JDK_1_6, getLanguageLevelForModule());
}
public void testLanguageLevelWhenCompilerPluginIsNotSpecified() throws Exception {
@@ -659,7 +659,7 @@ public class StructureImportingTest extends MavenImportingTestCase {
"<version>1</version>");
assertModules("project");
assertNull(getLanguageLevelForProject());
assertNull(getLanguageLevelForModule());
}
public void testLanguageLevelWhenConfigurationIsNotSpecified() throws Exception {
@@ -677,10 +677,10 @@ public class StructureImportingTest extends MavenImportingTestCase {
"</build>");
assertModules("project");
assertNull(getLanguageLevelForProject());
assertNull(getLanguageLevelForModule());
}
public void testLanguageLevelWhenSourseLanguageLevelIsNotSpecified() throws Exception {
public void testLanguageLevelWhenSourceLanguageLevelIsNotSpecified() throws Exception {
importProject("<groupId>test</groupId>" +
"<artifactId>project</artifactId>" +
"<version>1</version>" +
@@ -697,10 +697,10 @@ public class StructureImportingTest extends MavenImportingTestCase {
"</build>");
assertModules("project");
assertNull(getLanguageLevelForProject());
assertNull(getLanguageLevelForModule());
}
private LanguageLevel getLanguageLevelForProject() {
private LanguageLevel getLanguageLevelForModule() {
return LanguageLevelModuleExtension.getInstance(getModule("project")).getLanguageLevel();
}
@@ -282,6 +282,8 @@
<rowspec value="center:20px:noGrow"/>
<rowspec value="top:4dlu:noGrow"/>
<rowspec value="center:d:noGrow"/>
<rowspec value="top:4dlu:noGrow"/>
<rowspec value="center:max(d;4px):noGrow"/>
<colspec value="fill:d:grow"/>
<constraints>
<tabbedpane title="Listeners"/>
@@ -354,6 +356,15 @@
</vspacer>
</children>
</grid>
<component id="4fd4c" class="javax.swing.JCheckBox" binding="myUseDefaultReportersCheckBox" default-binding="true">
<constraints>
<grid row="4" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
<forms defaultalign-horz="false"/>
</constraints>
<properties>
<text value="Use default reporters"/>
</properties>
</component>
</children>
</grid>
</children>
@@ -96,6 +96,7 @@ public class TestNGConfigurationEditor extends SettingsEditor<TestNGConfiguratio
private JList listenersTable;
private JButton removeListener;
private LabeledComponent<JComboBox> annotationType;
private JCheckBox myUseDefaultReportersCheckBox;
private final CommonJavaParameters commonJavaParameters = new CommonJavaParameters();
private ArrayList<Map.Entry> propertiesList;
private TestNGListenersTableModel listenerModel;
@@ -230,6 +231,7 @@ public class TestNGConfigurationEditor extends SettingsEditor<TestNGConfiguratio
propertiesTableModel.setParameterList(propertiesList);
listenerModel.setListenerList(data.TEST_LISTENERS);
myUseDefaultReportersCheckBox.setSelected(data.USE_DEFAULT_REPORTERS);
annotationType.getComponent().setSelectedItem(data.ANNOTATION_TYPE);
@@ -262,6 +264,8 @@ public class TestNGConfigurationEditor extends SettingsEditor<TestNGConfiguratio
data.TEST_LISTENERS.clear();
data.TEST_LISTENERS.addAll(listenerModel.getListenerList());
data.USE_DEFAULT_REPORTERS = myUseDefaultReportersCheckBox.isSelected();
data.setEnvs(envVariablesComponent.getEnvs());
data.PASS_PARENT_ENVS = envVariablesComponent.isPassParentEnvs();
}
@@ -264,6 +264,8 @@ public class TestNGRunnableState extends JavaCommandLineState {
javaParameters.getProgramParametersList().add(TestNGCommandLineArgs.OUTDIR_COMMAND_OPT, data.getOutputDirectory());
}
javaParameters.getProgramParametersList().add(TestNGCommandLineArgs.USE_DEFAULT_LISTENERS, String.valueOf(data.USE_DEFAULT_REPORTERS));
@NonNls final StringBuilder buf = new StringBuilder();
if (data.TEST_LISTENERS != null && !data.TEST_LISTENERS.isEmpty()) {
buf.append(StringUtil.join(data.TEST_LISTENERS, ";"));
@@ -54,6 +54,7 @@ public class TestData implements Cloneable
public TestSearchScope.Wrapper TEST_SEARCH_SCOPE;
public Map<String, String> TEST_PROPERTIES = new HashMap<String, String>();
public List<String> TEST_LISTENERS = new ArrayList<String>();
public boolean USE_DEFAULT_REPORTERS = false;
public String PROPERTIES_FILE;
public TestData() {
@@ -111,7 +112,8 @@ public class TestData implements Cloneable
&& Comparing.equal(WORKING_DIRECTORY, data.WORKING_DIRECTORY)
&& Comparing.equal(OUTPUT_DIRECTORY, data.OUTPUT_DIRECTORY)
&& Comparing.equal(VM_PARAMETERS, data.VM_PARAMETERS)
&& Comparing.equal(PARAMETERS, data.PARAMETERS);
&& Comparing.equal(PARAMETERS, data.PARAMETERS)
&& USE_DEFAULT_REPORTERS == data.USE_DEFAULT_REPORTERS;
}
}
@@ -125,7 +127,8 @@ public class TestData implements Cloneable
Comparing.hashcode(WORKING_DIRECTORY) ^
Comparing.hashcode(OUTPUT_DIRECTORY) ^
Comparing.hashcode(VM_PARAMETERS) ^
Comparing.hashcode(PARAMETERS);
Comparing.hashcode(PARAMETERS) ^
Comparing.hashcode(USE_DEFAULT_REPORTERS);
}
@Override
@@ -139,6 +142,8 @@ public class TestData implements Cloneable
data.TEST_LISTENERS = new ArrayList<String>();
data.TEST_LISTENERS.addAll(TEST_LISTENERS);
data.USE_DEFAULT_REPORTERS = USE_DEFAULT_REPORTERS;
data.setScope(getScope());
return data;
}