Merge remote branch 'origin/master'

This commit is contained in:
irengrig
2013-03-09 11:44:22 +04:00
351 changed files with 2139 additions and 1547 deletions
File diff suppressed because it is too large Load Diff
@@ -636,7 +636,9 @@ public class CompileDriver {
if (useExtProcessBuild) {
// ensure the project model seen by build process is up-to-date
myProject.save();
ApplicationManager.getApplication().saveSettings();
if (!ApplicationManager.getApplication().isUnitTestMode()) {
ApplicationManager.getApplication().saveSettings();
}
}
PsiDocumentManager.getInstance(myProject).commitAllDocuments();
FileDocumentManager.getInstance().saveAllDocuments();
@@ -16,7 +16,6 @@
package com.intellij.compiler.server;
import com.intellij.ProjectTopics;
import com.intellij.application.options.PathMacrosImpl;
import com.intellij.compiler.CompilerWorkspaceConfiguration;
import com.intellij.compiler.impl.javaCompiler.javac.JavacConfiguration;
import com.intellij.compiler.server.impl.CompileServerClasspathManager;
@@ -215,8 +214,6 @@ public class BuildManager implements ApplicationComponent{
private final ChannelGroup myAllOpenChannels = new DefaultChannelGroup("build-manager");
private final BuildMessageDispatcher myMessageDispatcher = new BuildMessageDispatcher();
private volatile int myListenPort = -1;
private volatile CmdlineRemoteProto.Message.ControllerMessage.GlobalSettings myGlobals;
private int myGlobalsStamp = -1;
@Nullable
private final Charset mySystemCharset;
@@ -376,7 +373,6 @@ public class BuildManager implements ApplicationComponent{
}
public void clearState(Project project) {
myGlobals = null;
final String projectPath = getProjectPath(project);
synchronized (myProjectDataMap) {
final ProjectData data = myProjectDataMap.get(projectPath);
@@ -539,7 +535,10 @@ public class BuildManager implements ApplicationComponent{
return;
}
final CmdlineRemoteProto.Message.ControllerMessage.GlobalSettings globals = buildGlobalSettings();
final CmdlineRemoteProto.Message.ControllerMessage.GlobalSettings globals =
CmdlineRemoteProto.Message.ControllerMessage.GlobalSettings.newBuilder()
.setGlobalOptionsPath(PathManager.getOptionsPath())
.build();
CmdlineRemoteProto.Message.ControllerMessage.FSEvent currentFSChanges;
final SequentialTaskExecutor projectTaskQueue;
synchronized (myProjectDataMap) {
@@ -688,47 +687,6 @@ public class BuildManager implements ApplicationComponent{
return "com.intellij.compiler.server.BuildManager";
}
private CmdlineRemoteProto.Message.ControllerMessage.GlobalSettings buildGlobalSettings() {
final PathMacrosImpl pathVars = PathMacrosImpl.getInstanceEx();
final CmdlineRemoteProto.Message.ControllerMessage.GlobalSettings cached = myGlobals;
if (cached != null && myGlobalsStamp == pathVars.getModificationStamp()) {
return cached;
}
myGlobals = null; // ensure the cache is cleared and stamp is current
myGlobalsStamp = pathVars.getModificationStamp();
final Map<String, String> data = new HashMap<String, String>();
for (Map.Entry<String, String> entry : PathMacrosImpl.getGlobalSystemMacros().entrySet()) {
data.put(entry.getKey(), FileUtil.toSystemIndependentName(entry.getValue()));
}
for (String name : pathVars.getAllMacroNames()) {
final String path = pathVars.getValue(name);
if (path != null) {
data.put(name, FileUtil.toSystemIndependentName(path));
}
}
final CmdlineRemoteProto.Message.ControllerMessage.GlobalSettings.Builder cmdBuilder =
CmdlineRemoteProto.Message.ControllerMessage.GlobalSettings.newBuilder();
cmdBuilder.setGlobalOptionsPath(PathManager.getOptionsPath());
if (!data.isEmpty()) {
for (Map.Entry<String, String> entry : data.entrySet()) {
final String var = entry.getKey();
final String value = entry.getValue();
if (var != null && value != null) {
cmdBuilder.addPathVariable(CmdlineProtoUtil.createPair(var, value));
}
}
}
return myGlobals = cmdBuilder.build();
}
private OSProcessHandler launchBuildProcess(Project project, final int port, final UUID sessionId) throws ExecutionException {
final String compilerPath;
final String vmExecutablePath;
@@ -28,6 +28,7 @@ import com.intellij.openapi.diagnostic.Logger;
import com.sun.jdi.*;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.*;
@@ -172,18 +173,23 @@ public class StackFrameProxyImpl extends JdiProxy implements StackFrameProxy {
}
}
@Nullable
public ObjectReference thisObject() throws EvaluateException {
DebuggerManagerThreadImpl.assertIsManagerThread();
checkValid();
try {
if(myThisReference == null) {
myThisReference = getStackFrame().thisObject();
for (int attempt = 0; attempt < 2; attempt++) {
try {
if(myThisReference == null) {
myThisReference = getStackFrame().thisObject();
}
break;
}
catch (InvalidStackFrameException e) {
clearCaches();
}
}
}
catch (InvalidStackFrameException e) {
clearCaches();
return thisObject();
}
catch (InternalException e) {
// supress some internal errors caused by bugs in specific JDI implementations
if(e.errorCode() != 23) {
@@ -707,7 +707,10 @@ public class HighlightVisitorImpl extends JavaElementVisitor implements Highligh
}
}
else {
myHolder.add(HighlightNamesUtil.highlightMethodName(method, element, false, colorsScheme));
final PsiElement referenceNameElement = element.getReferenceNameElement();
if(referenceNameElement != null) {
myHolder.add(HighlightNamesUtil.highlightMethodName(method, referenceNameElement, false, colorsScheme));
}
}
}
catch (IndexNotReadyException ignored) {
@@ -35,14 +35,9 @@ import com.intellij.util.containers.Stack;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.*;
import static com.intellij.psi.CommonClassNames.JAVA_LANG_ERROR;
import static com.intellij.psi.CommonClassNames.JAVA_LANG_RUNTIME_EXCEPTION;
import static com.intellij.psi.CommonClassNames.JAVA_LANG_THROWABLE;
import static com.intellij.psi.CommonClassNames.*;
class ControlFlowAnalyzer extends JavaElementVisitor {
private static final Logger LOG = Logger.getInstance("#com.intellij.codeInspection.dataFlow.ControlFlowAnalyzer");
@@ -91,7 +86,9 @@ class ControlFlowAnalyzer extends JavaElementVisitor {
pass2Flow.setFields(myFields.toArray(new DfaVariableValue[myFields.size()]));
LOG.assertTrue(myPass1Flow.getInstructionCount() == pass2Flow.getInstructionCount());
if (myPass1Flow.getInstructionCount() != pass2Flow.getInstructionCount()) {
LOG.error(Arrays.toString(myPass1Flow.getInstructions()) + "!=\n" + Arrays.toString(pass2Flow.getInstructions()));
}
addInstruction(new ReturnInstruction());
@@ -18,8 +18,6 @@ package com.intellij.openapi.options.colors.pages;
import com.intellij.application.options.colors.InspectionColorSettingsPage;
import com.intellij.ide.highlighter.JavaFileHighlighter;
import com.intellij.ide.highlighter.JavaHighlightingColors;
import com.intellij.openapi.editor.HighlighterColors;
import com.intellij.openapi.editor.SyntaxHighlighterColors;
import com.intellij.openapi.editor.colors.CodeInsightColors;
import com.intellij.openapi.editor.colors.TextAttributesKey;
import com.intellij.openapi.fileTypes.StdFileTypes;
@@ -181,7 +179,7 @@ public class JavaColorSettingsPage implements ColorSettingsPage, InspectionColor
" int <localVar>a</localVar> = <implicitAnonymousParameter>localVar</implicitAnonymousParameter>;\n" +
" }\n" +
" };\n" +
" <reassignedParameter>reassignedParam</reassignedParameter> = new int[2];\n" +
" <reassignedParameter>reassignedParam</reassignedParameter> = new <constructorCall>ArrayList</constructorCall><<class>String</class>>().toArray(new int[0]);\n" +
" }\n" +
"}\n" +
"enum <enum>AnEnum</enum> { <static_final>CONST1</static_final>, <static_final>CONST2</static_final> }\n"+
@@ -33,9 +33,11 @@ import org.jetbrains.annotations.Nullable;
public class PsiClassConverter extends Converter<PsiClass> implements CustomReferenceConverter<PsiClass> {
public PsiClass fromString(final String s, final ConvertContext context) {
if (StringUtil.isEmptyOrSpaces(s)) return null;
final DomElement element = context.getInvocationElement();
final GlobalSearchScope scope = element instanceof GenericDomValue ? getScope(context) : null;
return DomJavaUtil.findClass(s, context.getFile(), context.getModule(), scope);
return DomJavaUtil.findClass(s.trim(), context.getFile(), context.getModule(), scope);
}
@Nullable
@@ -32,11 +32,9 @@ import com.intellij.psi.impl.PsiManagerEx;
import com.intellij.psi.impl.file.PsiPackageImpl;
import com.intellij.psi.impl.java.stubs.index.JavaFullClassNameIndex;
import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.psi.util.PsiUtilCore;
import com.intellij.util.Query;
import com.intellij.util.containers.ConcurrentHashMap;
import com.intellij.util.containers.ContainerUtil;
import com.intellij.util.indexing.FileBasedIndex;
import com.intellij.util.messages.MessageBus;
import com.intellij.util.messages.MessageBusConnection;
import org.jetbrains.annotations.NonNls;
@@ -130,15 +128,13 @@ public abstract class JavaFileManagerBase implements JavaFileManager, Disposable
@Override
public PsiClass[] findClasses(@NotNull String qName, @NotNull final GlobalSearchScope scope) {
final Collection<? extends PsiElement> classes = JavaFullClassNameIndex.getInstance().get(qName.hashCode(), myManager.getProject(), scope);
final Collection<PsiClass> classes = JavaFullClassNameIndex.getInstance().get(qName.hashCode(), myManager.getProject(), scope);
if (classes.isEmpty()) return PsiClass.EMPTY_ARRAY;
List<PsiClass> result = new ArrayList<PsiClass>(classes.size());
int count = 0;
PsiClass aClass = null;
for (PsiElement found : classes) {
if (notClass(found)) continue;
aClass = (PsiClass)found;
for (PsiClass found : classes) {
aClass = found;
final String qualifiedName = aClass.getQualifiedName();
if (qualifiedName == null || !qualifiedName.equals(qName)) continue;
@@ -277,12 +273,9 @@ public abstract class JavaFileManagerBase implements JavaFileManager, Disposable
private PsiClass findClassInIndex(String qName, GlobalSearchScope scope) {
VirtualFile bestFile = null;
PsiClass bestClass = null;
final Collection<? extends PsiElement> classes = JavaFullClassNameIndex.getInstance().get(qName.hashCode(), myManager.getProject(), scope);
final Collection<PsiClass> classes = JavaFullClassNameIndex.getInstance().get(qName.hashCode(), myManager.getProject(), scope);
for (PsiElement found : classes) {
if (notClass(found)) continue;
PsiClass aClass = (PsiClass)found;
for (PsiClass aClass : classes) {
PsiFile file = aClass.getContainingFile();
if (file == null) {
LOG.error("aClass=" + aClass);
@@ -346,18 +339,6 @@ public abstract class JavaFileManagerBase implements JavaFileManager, Disposable
return myNontrivialPackagePrefixes;
}
private static boolean notClass(final PsiElement found) {
if (found instanceof PsiClass) return false;
VirtualFile faultyContainer = PsiUtilCore.getVirtualFile(found);
LOG.error("Non class in class list: " + faultyContainer + ". found: " + found);
if (faultyContainer != null && faultyContainer.isValid()) {
FileBasedIndex.getInstance().requestReindex(faultyContainer);
}
return true;
}
@Nullable
private static PsiClass findClassByName(PsiJavaFile scope, String name) {
PsiClass[] classes = scope.getClasses();
@@ -24,7 +24,9 @@ import com.intellij.psi.PsiAnnotation;
import com.intellij.psi.impl.search.JavaSourceFilterScope;
import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.psi.stubs.StringStubIndexExtension;
import com.intellij.psi.stubs.StubIndex;
import com.intellij.psi.stubs.StubIndexKey;
import com.intellij.psi.stubs.StubProcessingHelperBase;
import org.jetbrains.annotations.NotNull;
import java.util.Collection;
@@ -44,6 +46,6 @@ public class JavaAnnotationIndex extends StringStubIndexExtension<PsiAnnotation>
@Override
public Collection<PsiAnnotation> get(final String s, final Project project, @NotNull final GlobalSearchScope scope) {
return super.get(s, project, new JavaSourceFilterScope(scope));
return StubIndex.getInstance().safeGet(getKey(), s, project, new JavaSourceFilterScope(scope), PsiAnnotation.class);
}
}
@@ -24,6 +24,7 @@ import com.intellij.psi.PsiClass;
import com.intellij.psi.impl.search.JavaSourceFilterScope;
import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.psi.stubs.IntStubIndexExtension;
import com.intellij.psi.stubs.StubIndex;
import com.intellij.psi.stubs.StubIndexKey;
import org.jetbrains.annotations.NotNull;
@@ -44,6 +45,6 @@ public class JavaFullClassNameIndex extends IntStubIndexExtension<PsiClass> {
@Override
public Collection<PsiClass> get(final Integer integer, final Project project, @NotNull final GlobalSearchScope scope) {
return super.get(integer, project, new JavaSourceFilterScope(scope));
return StubIndex.getInstance().safeGet(getKey(), integer, project, new JavaSourceFilterScope(scope), PsiClass.class);
}
}
@@ -3,7 +3,6 @@ package com.intellij.psi.impl.search;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.util.Computable;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.*;
import com.intellij.psi.impl.PsiManagerImpl;
import com.intellij.psi.impl.java.stubs.index.JavaAnnotationIndex;
@@ -11,13 +10,12 @@ import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.psi.search.LocalSearchScope;
import com.intellij.psi.search.SearchScope;
import com.intellij.psi.search.searches.AnnotatedElementsSearch;
import com.intellij.psi.util.PsiUtilCore;
import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.util.Processor;
import com.intellij.util.QueryExecutor;
import com.intellij.util.indexing.FileBasedIndex;
import com.intellij.util.containers.ContainerUtil;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
@@ -43,46 +41,32 @@ public class AnnotatedElementsSearcher implements QueryExecutor<PsiModifierListO
final PsiManagerImpl psiManager = (PsiManagerImpl)annClass.getManager();
final SearchScope useScope = p.getScope();
Class<? extends PsiModifierListOwner>[] types = p.getTypes();
final Class<? extends PsiModifierListOwner>[] types = p.getTypes();
for (PsiElement elt : getAnnotationCandidates(annClass, useScope)) {
if (notAnnotation(elt)) continue;
final PsiAnnotation ann = (PsiAnnotation)elt;
final PsiJavaCodeReferenceElement ref = ApplicationManager.getApplication().runReadAction(new Computable<PsiJavaCodeReferenceElement>() {
for (final PsiAnnotation ann : getAnnotationCandidates(annClass, useScope)) {
final PsiModifierListOwner candidate = ApplicationManager.getApplication().runReadAction(new Computable<PsiModifierListOwner>() {
@Override
public PsiJavaCodeReferenceElement compute() {
return ann.getNameReferenceElement();
public PsiModifierListOwner compute() {
PsiElement parent = ann.getParent();
if (!(parent instanceof PsiModifierList)) {
return null; // Can be a PsiNameValuePair, if annotation is used to annotate annotation parameters
}
final PsiElement owner = parent.getParent();
if (!isInstanceof(owner, types)) {
return null;
}
final PsiJavaCodeReferenceElement ref = ann.getNameReferenceElement();
if (ref == null || !psiManager.areElementsEquivalent(ref.resolve(), annClass)) {
return null;
}
return (PsiModifierListOwner)owner;
}
});
if (ref == null) continue;
PsiElement parent = ann.getParent();
if (!(parent instanceof PsiModifierList)) continue; // Can be a PsiNameValuePair, if annotation is used to annotate annotation parameters
final PsiElement owner = parent.getParent();
if (!isInstanceof(owner, types)) continue;
final PsiModifierListOwner candidate = (PsiModifierListOwner)owner;
if (!ApplicationManager.getApplication().runReadAction(new Computable<Boolean>() {
@Override
public Boolean compute() {
if (!candidate.isValid()) {
return false;
}
if (!psiManager.areElementsEquivalent(ref.resolve(), annClass)) {
return false;
}
return !(useScope instanceof GlobalSearchScope) ||
((GlobalSearchScope)useScope).contains(candidate.getContainingFile().getVirtualFile());
}
})) {
continue;
}
if (!consumer.process(candidate)) {
if (candidate != null && !consumer.process(candidate)) {
return false;
}
}
@@ -90,23 +74,17 @@ public class AnnotatedElementsSearcher implements QueryExecutor<PsiModifierListO
return true;
}
private static Collection<? extends PsiElement> getAnnotationCandidates(final PsiClass annClass, final SearchScope useScope) {
return ApplicationManager.getApplication().runReadAction(new Computable<Collection<? extends PsiElement>>() {
private static Collection<PsiAnnotation> getAnnotationCandidates(final PsiClass annClass, final SearchScope useScope) {
return ApplicationManager.getApplication().runReadAction(new Computable<Collection<PsiAnnotation>>() {
@Override
public Collection<? extends PsiElement> compute() {
public Collection<PsiAnnotation> compute() {
if (useScope instanceof GlobalSearchScope) {
return JavaAnnotationIndex.getInstance().get(annClass.getName(), annClass.getProject(), (GlobalSearchScope)useScope);
}
final List<PsiElement> result = new ArrayList<PsiElement>();
final List<PsiAnnotation> result = ContainerUtil.newArrayList();
for (PsiElement element : ((LocalSearchScope)useScope).getScope()) {
element.accept(new PsiRecursiveElementWalkingVisitor() {
@Override
public void visitElement(PsiElement element) {
if (element instanceof PsiAnnotation) {
result.add(element);
}
}
});
result.addAll(PsiTreeUtil.findChildrenOfType(element, PsiAnnotation.class));
}
return result;
}
@@ -120,15 +98,4 @@ public class AnnotatedElementsSearcher implements QueryExecutor<PsiModifierListO
return false;
}
private static boolean notAnnotation(final PsiElement found) {
if (found instanceof PsiAnnotation) return false;
VirtualFile faultyContainer = PsiUtilCore.getVirtualFile(found);
LOG.error("Non annotation in annotations list: " + faultyContainer+"; element:"+found);
if (faultyContainer != null && faultyContainer.isValid()) {
FileBasedIndex.getInstance().requestReindex(faultyContainer);
}
return true;
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* Copyright 2000-2013 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.
@@ -32,29 +32,27 @@ import java.util.List;
*/
public class PsiClassReferenceType extends PsiClassType {
private static final Logger LOG = Logger.getInstance("#com.intellij.psi.impl.source.PsiClassReferenceType");
private final PsiJavaCodeReferenceElement myReference;
public PsiClassReferenceType(@NotNull PsiJavaCodeReferenceElement reference, LanguageLevel languageLevel) {
super(languageLevel, extractAnnosFromReference(reference));
public PsiClassReferenceType(@NotNull PsiJavaCodeReferenceElement reference, LanguageLevel langLevel) {
this(reference, langLevel, collectAnnotations(reference));
}
public PsiClassReferenceType(@NotNull PsiJavaCodeReferenceElement reference, LanguageLevel langLevel, @NotNull PsiAnnotation[] annotations) {
super(langLevel, annotations);
myReference = reference;
}
private static PsiAnnotation[] extractAnnosFromReference(PsiJavaCodeReferenceElement reference) {
private static PsiAnnotation[] collectAnnotations(PsiJavaCodeReferenceElement reference) {
List<PsiAnnotation> result = null;
for(PsiElement child = reference.getFirstChild(); child != null; child = child.getNextSibling()){
for (PsiElement child = reference.getFirstChild(); child != null; child = child.getNextSibling()) {
if (child instanceof PsiAnnotation) {
if (result == null) result = new SmartList<PsiAnnotation>();
result.add((PsiAnnotation)child);
}
}
if (result == null) return PsiAnnotation.EMPTY_ARRAY;
return result.toArray(new PsiAnnotation[result.size()]);
}
public PsiClassReferenceType(@NotNull PsiJavaCodeReferenceElement reference, LanguageLevel languageLevel, PsiAnnotation[] annotations) {
super(languageLevel,annotations);
myReference = reference;
return result == null ? PsiAnnotation.EMPTY_ARRAY : result.toArray(new PsiAnnotation[result.size()]);
}
@Override
@@ -84,7 +82,7 @@ public class PsiClassReferenceType extends PsiClassType {
@Override
public PsiClassType setLanguageLevel(@NotNull final LanguageLevel languageLevel) {
if (languageLevel.equals(myLanguageLevel)) return this;
return new PsiClassReferenceType(myReference,languageLevel,getAnnotations());
return new PsiClassReferenceType(myReference, languageLevel, getAnnotations());
}
@Override
@@ -158,9 +156,9 @@ public class PsiClassReferenceType extends PsiClassType {
}
String qualifiedName = myReference.getQualifiedName();
String name = myReference.getReferenceName();
if (name==null) name="";
if (name == null) name = "";
LightClassReference reference = new LightClassReference(myReference.getManager(), name, qualifiedName, myReference.getResolveScope());
return new PsiClassReferenceType(reference, null,getAnnotations());
return new PsiClassReferenceType(reference, null, getAnnotations());
}
@Override
@@ -175,9 +173,9 @@ public class PsiClassReferenceType extends PsiClassType {
}
public PsiClassType createImmediateCopy() {
final ClassResolveResult resolveResult = resolveGenerics();
if (resolveResult.getElement() == null) return this;
return new PsiImmediateClassType(resolveResult.getElement(), resolveResult.getSubstitutor());
ClassResolveResult resolveResult = resolveGenerics();
PsiClass element = resolveResult.getElement();
return element != null ? new PsiImmediateClassType(element, resolveResult.getSubstitutor()) : this;
}
@Override
@@ -42,7 +42,6 @@ message Message {
}
message GlobalSettings {
repeated KeyValuePair path_variable = 1;
required string global_options_path = 5;
}
@@ -1,19 +1,3 @@
/*
* 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.
*/
// Generated by the protocol buffer compiler. DO NOT EDIT!
// source: cmdline_remote_proto.proto
@@ -1966,12 +1950,6 @@ public final class CmdlineRemoteProto {
public interface GlobalSettingsOrBuilder
extends com.google.protobuf.MessageLiteOrBuilder {
// repeated .org.jetbrains.jpsservice.Message.KeyValuePair path_variable = 1;
java.util.List<org.jetbrains.jps.api.CmdlineRemoteProto.Message.KeyValuePair>
getPathVariableList();
org.jetbrains.jps.api.CmdlineRemoteProto.Message.KeyValuePair getPathVariable(int index);
int getPathVariableCount();
// required string global_options_path = 5;
boolean hasGlobalOptionsPath();
String getGlobalOptionsPath();
@@ -1995,27 +1973,6 @@ public final class CmdlineRemoteProto {
}
private int bitField0_;
// repeated .org.jetbrains.jpsservice.Message.KeyValuePair path_variable = 1;
public static final int PATH_VARIABLE_FIELD_NUMBER = 1;
private java.util.List<org.jetbrains.jps.api.CmdlineRemoteProto.Message.KeyValuePair> pathVariable_;
public java.util.List<org.jetbrains.jps.api.CmdlineRemoteProto.Message.KeyValuePair> getPathVariableList() {
return pathVariable_;
}
public java.util.List<? extends org.jetbrains.jps.api.CmdlineRemoteProto.Message.KeyValuePairOrBuilder>
getPathVariableOrBuilderList() {
return pathVariable_;
}
public int getPathVariableCount() {
return pathVariable_.size();
}
public org.jetbrains.jps.api.CmdlineRemoteProto.Message.KeyValuePair getPathVariable(int index) {
return pathVariable_.get(index);
}
public org.jetbrains.jps.api.CmdlineRemoteProto.Message.KeyValuePairOrBuilder getPathVariableOrBuilder(
int index) {
return pathVariable_.get(index);
}
// required string global_options_path = 5;
public static final int GLOBAL_OPTIONS_PATH_FIELD_NUMBER = 5;
private java.lang.Object globalOptionsPath_;
@@ -2049,7 +2006,6 @@ public final class CmdlineRemoteProto {
}
private void initFields() {
pathVariable_ = java.util.Collections.emptyList();
globalOptionsPath_ = "";
}
private byte memoizedIsInitialized = -1;
@@ -2061,12 +2017,6 @@ public final class CmdlineRemoteProto {
memoizedIsInitialized = 0;
return false;
}
for (int i = 0; i < getPathVariableCount(); i++) {
if (!getPathVariable(i).isInitialized()) {
memoizedIsInitialized = 0;
return false;
}
}
memoizedIsInitialized = 1;
return true;
}
@@ -2074,9 +2024,6 @@ public final class CmdlineRemoteProto {
public void writeTo(com.google.protobuf.CodedOutputStream output)
throws java.io.IOException {
getSerializedSize();
for (int i = 0; i < pathVariable_.size(); i++) {
output.writeMessage(1, pathVariable_.get(i));
}
if (((bitField0_ & 0x00000001) == 0x00000001)) {
output.writeBytes(5, getGlobalOptionsPathBytes());
}
@@ -2088,10 +2035,6 @@ public final class CmdlineRemoteProto {
if (size != -1) return size;
size = 0;
for (int i = 0; i < pathVariable_.size(); i++) {
size += com.google.protobuf.CodedOutputStream
.computeMessageSize(1, pathVariable_.get(i));
}
if (((bitField0_ & 0x00000001) == 0x00000001)) {
size += com.google.protobuf.CodedOutputStream
.computeBytesSize(5, getGlobalOptionsPathBytes());
@@ -2198,10 +2141,8 @@ public final class CmdlineRemoteProto {
public Builder clear() {
super.clear();
pathVariable_ = java.util.Collections.emptyList();
bitField0_ = (bitField0_ & ~0x00000001);
globalOptionsPath_ = "";
bitField0_ = (bitField0_ & ~0x00000002);
bitField0_ = (bitField0_ & ~0x00000001);
return this;
}
@@ -2235,12 +2176,7 @@ public final class CmdlineRemoteProto {
org.jetbrains.jps.api.CmdlineRemoteProto.Message.ControllerMessage.GlobalSettings result = new org.jetbrains.jps.api.CmdlineRemoteProto.Message.ControllerMessage.GlobalSettings(this);
int from_bitField0_ = bitField0_;
int to_bitField0_ = 0;
if (((bitField0_ & 0x00000001) == 0x00000001)) {
pathVariable_ = java.util.Collections.unmodifiableList(pathVariable_);
bitField0_ = (bitField0_ & ~0x00000001);
}
result.pathVariable_ = pathVariable_;
if (((from_bitField0_ & 0x00000002) == 0x00000002)) {
if (((from_bitField0_ & 0x00000001) == 0x00000001)) {
to_bitField0_ |= 0x00000001;
}
result.globalOptionsPath_ = globalOptionsPath_;
@@ -2250,16 +2186,6 @@ public final class CmdlineRemoteProto {
public Builder mergeFrom(org.jetbrains.jps.api.CmdlineRemoteProto.Message.ControllerMessage.GlobalSettings other) {
if (other == org.jetbrains.jps.api.CmdlineRemoteProto.Message.ControllerMessage.GlobalSettings.getDefaultInstance()) return this;
if (!other.pathVariable_.isEmpty()) {
if (pathVariable_.isEmpty()) {
pathVariable_ = other.pathVariable_;
bitField0_ = (bitField0_ & ~0x00000001);
} else {
ensurePathVariableIsMutable();
pathVariable_.addAll(other.pathVariable_);
}
}
if (other.hasGlobalOptionsPath()) {
setGlobalOptionsPath(other.getGlobalOptionsPath());
}
@@ -2271,12 +2197,6 @@ public final class CmdlineRemoteProto {
return false;
}
for (int i = 0; i < getPathVariableCount(); i++) {
if (!getPathVariable(i).isInitialized()) {
return false;
}
}
return true;
}
@@ -2297,14 +2217,8 @@ public final class CmdlineRemoteProto {
}
break;
}
case 10: {
org.jetbrains.jps.api.CmdlineRemoteProto.Message.KeyValuePair.Builder subBuilder = org.jetbrains.jps.api.CmdlineRemoteProto.Message.KeyValuePair.newBuilder();
input.readMessage(subBuilder, extensionRegistry);
addPathVariable(subBuilder.buildPartial());
break;
}
case 42: {
bitField0_ |= 0x00000002;
bitField0_ |= 0x00000001;
globalOptionsPath_ = input.readBytes();
break;
}
@@ -2314,99 +2228,10 @@ public final class CmdlineRemoteProto {
private int bitField0_;
// repeated .org.jetbrains.jpsservice.Message.KeyValuePair path_variable = 1;
private java.util.List<org.jetbrains.jps.api.CmdlineRemoteProto.Message.KeyValuePair> pathVariable_ =
java.util.Collections.emptyList();
private void ensurePathVariableIsMutable() {
if (!((bitField0_ & 0x00000001) == 0x00000001)) {
pathVariable_ = new java.util.ArrayList<org.jetbrains.jps.api.CmdlineRemoteProto.Message.KeyValuePair>(pathVariable_);
bitField0_ |= 0x00000001;
}
}
public java.util.List<org.jetbrains.jps.api.CmdlineRemoteProto.Message.KeyValuePair> getPathVariableList() {
return java.util.Collections.unmodifiableList(pathVariable_);
}
public int getPathVariableCount() {
return pathVariable_.size();
}
public org.jetbrains.jps.api.CmdlineRemoteProto.Message.KeyValuePair getPathVariable(int index) {
return pathVariable_.get(index);
}
public Builder setPathVariable(
int index, org.jetbrains.jps.api.CmdlineRemoteProto.Message.KeyValuePair value) {
if (value == null) {
throw new NullPointerException();
}
ensurePathVariableIsMutable();
pathVariable_.set(index, value);
return this;
}
public Builder setPathVariable(
int index, org.jetbrains.jps.api.CmdlineRemoteProto.Message.KeyValuePair.Builder builderForValue) {
ensurePathVariableIsMutable();
pathVariable_.set(index, builderForValue.build());
return this;
}
public Builder addPathVariable(org.jetbrains.jps.api.CmdlineRemoteProto.Message.KeyValuePair value) {
if (value == null) {
throw new NullPointerException();
}
ensurePathVariableIsMutable();
pathVariable_.add(value);
return this;
}
public Builder addPathVariable(
int index, org.jetbrains.jps.api.CmdlineRemoteProto.Message.KeyValuePair value) {
if (value == null) {
throw new NullPointerException();
}
ensurePathVariableIsMutable();
pathVariable_.add(index, value);
return this;
}
public Builder addPathVariable(
org.jetbrains.jps.api.CmdlineRemoteProto.Message.KeyValuePair.Builder builderForValue) {
ensurePathVariableIsMutable();
pathVariable_.add(builderForValue.build());
return this;
}
public Builder addPathVariable(
int index, org.jetbrains.jps.api.CmdlineRemoteProto.Message.KeyValuePair.Builder builderForValue) {
ensurePathVariableIsMutable();
pathVariable_.add(index, builderForValue.build());
return this;
}
public Builder addAllPathVariable(
java.lang.Iterable<? extends org.jetbrains.jps.api.CmdlineRemoteProto.Message.KeyValuePair> values) {
ensurePathVariableIsMutable();
super.addAll(values, pathVariable_);
return this;
}
public Builder clearPathVariable() {
pathVariable_ = java.util.Collections.emptyList();
bitField0_ = (bitField0_ & ~0x00000001);
return this;
}
public Builder removePathVariable(int index) {
ensurePathVariableIsMutable();
pathVariable_.remove(index);
return this;
}
// required string global_options_path = 5;
private java.lang.Object globalOptionsPath_ = "";
public boolean hasGlobalOptionsPath() {
return ((bitField0_ & 0x00000002) == 0x00000002);
return ((bitField0_ & 0x00000001) == 0x00000001);
}
public String getGlobalOptionsPath() {
java.lang.Object ref = globalOptionsPath_;
@@ -2422,19 +2247,19 @@ public final class CmdlineRemoteProto {
if (value == null) {
throw new NullPointerException();
}
bitField0_ |= 0x00000002;
bitField0_ |= 0x00000001;
globalOptionsPath_ = value;
return this;
}
public Builder clearGlobalOptionsPath() {
bitField0_ = (bitField0_ & ~0x00000002);
bitField0_ = (bitField0_ & ~0x00000001);
globalOptionsPath_ = getDefaultInstance().getGlobalOptionsPath();
return this;
}
void setGlobalOptionsPath(com.google.protobuf.ByteString value) {
bitField0_ |= 0x00000002;
bitField0_ |= 0x00000001;
globalOptionsPath_ = value;
}
@@ -104,7 +104,7 @@ public class BuildRunner {
targetsState = new BuildTargetsState(dataPaths, jpsModel, buildRootIndex);
projectTimestamps = new ProjectTimestamps(dataStorageRoot, targetsState);
dataManager = new BuildDataManager(dataPaths, targetsState, STORE_TEMP_CACHES_IN_MEMORY);
// second attempt succeded
// second attempt succeeded
msgHandler.processMessage(new CompilerMessage("build", BuildMessage.Kind.INFO, "Project rebuild forced: " + e.getMessage()));
}
@@ -61,11 +61,11 @@ final class BuildSession implements Runnable, CanceledStatus {
private final UUID mySessionId;
private final Channel myChannel;
private volatile boolean myCanceled = false;
private String myProjectPath;
private final String myProjectPath;
@Nullable
private CmdlineRemoteProto.Message.ControllerMessage.FSEvent myInitialFSDelta;
// state
private EventsProcessor myEventsProcessor = new EventsProcessor();
private final EventsProcessor myEventsProcessor = new EventsProcessor();
private volatile long myLastEventOrdinal;
private volatile ProjectDescriptor myProjectDescriptor;
private final Map<Pair<String, String>, ConstantSearchFuture> mySearchTasks = Collections.synchronizedMap(new HashMap<Pair<String, String>, ConstantSearchFuture>());
@@ -81,14 +81,7 @@ final class BuildSession implements Runnable, CanceledStatus {
mySessionId = sessionId;
myChannel = channel;
// globals
Map<String, String> pathVars = new HashMap<String, String>();
final CmdlineRemoteProto.Message.ControllerMessage.GlobalSettings globals = params.getGlobalSettings();
for (CmdlineRemoteProto.Message.KeyValuePair variable : globals.getPathVariableList()) {
pathVars.put(variable.getKey(), variable.getValue());
}
// session params
myProjectPath = FileUtil.toCanonicalPath(params.getProjectId());
String globalOptionsPath = FileUtil.toCanonicalPath(globals.getGlobalOptionsPath());
myBuildType = convertCompileType(params.getBuildType());
@@ -99,7 +92,7 @@ final class BuildSession implements Runnable, CanceledStatus {
builderParams.put(pair.getKey(), pair.getValue());
}
myInitialFSDelta = delta;
JpsModelLoaderImpl loader = new JpsModelLoaderImpl(myProjectPath, globalOptionsPath, pathVars, null);
JpsModelLoaderImpl loader = new JpsModelLoaderImpl(myProjectPath, globalOptionsPath, null);
myForceModelLoading = Boolean.parseBoolean(builderParams.get(BuildMain.FORCE_MODEL_LOADING_PARAMETER.toString()));
myBuildRunner = new BuildRunner(loader, scopes, filePaths, builderParams);
}
@@ -304,7 +297,8 @@ final class BuildSession implements Runnable, CanceledStatus {
}
}
private void applyFSEvent(ProjectDescriptor pd, @Nullable CmdlineRemoteProto.Message.ControllerMessage.FSEvent event, final boolean saveEventStamp) throws IOException {
private static void applyFSEvent(ProjectDescriptor pd, @Nullable CmdlineRemoteProto.Message.ControllerMessage.FSEvent event,
final boolean saveEventStamp) throws IOException {
if (event == null) {
return;
}
@@ -369,7 +363,7 @@ final class BuildSession implements Runnable, CanceledStatus {
}
}
private void updateFsStateOnDisk(File dataStorageRoot, DataInputStream original, final long ordinal) {
private static void updateFsStateOnDisk(File dataStorageRoot, DataInputStream original, final long ordinal) {
final File file = new File(dataStorageRoot, FS_STATE_FILE);
try {
final BufferExposingByteArrayOutputStream bytes = new BufferExposingByteArrayOutputStream();
@@ -462,8 +456,8 @@ final class BuildSession implements Runnable, CanceledStatus {
}
try {
final File file = new File(dataStorageRoot, FS_STATE_FILE);
final InputStream fs = new FileInputStream(file);
byte[] bytes;
final InputStream fs = new FileInputStream(file);
try {
bytes = FileUtil.loadBytes(fs, (int)file.length());
}
@@ -17,9 +17,11 @@ package org.jetbrains.jps.cmdline;
import org.jetbrains.jps.model.JpsModel;
import java.io.IOException;
/**
* @author nik
*/
public interface JpsModelLoader {
JpsModel loadModel();
JpsModel loadModel() throws IOException;
}
@@ -17,14 +17,11 @@ package org.jetbrains.jps.cmdline;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.util.ParameterizedRunnable;
import org.jetbrains.jps.model.JpsElementFactory;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jps.model.JpsModel;
import org.jetbrains.jps.model.serialization.JpsGlobalLoader;
import org.jetbrains.jps.model.serialization.JpsProjectLoader;
import org.jetbrains.jps.model.serialization.JpsSerializationManager;
import java.io.File;
import java.io.IOException;
import java.util.Map;
/**
* @author nik
@@ -33,44 +30,25 @@ public class JpsModelLoaderImpl implements JpsModelLoader {
private static final Logger LOG = Logger.getInstance("#org.jetbrains.jps.cmdline.JpsModelLoaderImpl");
private final String myProjectPath;
private final String myGlobalOptionsPath;
private final Map<String, String> myPathVars;
private final ParameterizedRunnable<JpsModel> myModelInitializer;
public JpsModelLoaderImpl(String projectPath, String globalOptionsPath, Map<String, String> pathVars,
ParameterizedRunnable<JpsModel> initializer) {
public JpsModelLoaderImpl(String projectPath, String globalOptionsPath, @Nullable ParameterizedRunnable<JpsModel> initializer) {
myProjectPath = projectPath;
myGlobalOptionsPath = globalOptionsPath;
myPathVars = pathVars;
myModelInitializer = initializer;
}
@Override
public JpsModel loadModel() {
public JpsModel loadModel() throws IOException {
final long start = System.currentTimeMillis();
try {
final JpsModel model = JpsElementFactory.getInstance().createModel();
try {
if (myGlobalOptionsPath != null) {
JpsGlobalLoader.loadGlobalSettings(model.getGlobal(), myPathVars, myGlobalOptionsPath);
}
JpsProjectLoader.loadProject(model.getProject(), myPathVars, myProjectPath);
if (myModelInitializer != null) {
myModelInitializer.run(model);
}
LOG.info("New JPS model: " + model.getProject().getModules().size() + " modules, " + model.getProject().getLibraryCollection().getLibraries().size() + " libraries");
}
catch (IOException e) {
LOG.info(e);
}
return model;
LOG.info("Loading model: project path = " + myProjectPath + ", global options path = " + myGlobalOptionsPath);
final JpsModel model = JpsSerializationManager.getInstance().loadModel(myProjectPath, myGlobalOptionsPath);
if (myModelInitializer != null) {
myModelInitializer.run(model);
}
finally {
final long loadTime = System.currentTimeMillis() - start;
LOG.info("New JPS model: project " + myProjectPath + " loaded in " + loadTime + " ms");
}
}
private static boolean isDirectoryBased(File projectFile) {
return !(projectFile.isFile() && projectFile.getName().endsWith(".ipr"));
final long loadTime = System.currentTimeMillis() - start;
LOG.info("Model loaded in " + loadTime + " ms");
LOG.info("Project has " + model.getProject().getModules().size() + " modules, " + model.getProject().getLibraryCollection().getLibraries().size() + " libraries");
return model;
}
}
@@ -1,26 +0,0 @@
/*
* 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.model.module;
import java.util.EventListener;
/**
* @author nik
*/
public interface JpsFacetListener extends EventListener {
void facetAdded(JpsFacet facet);
void facetRemoved(JpsFacet facet);
}
@@ -1,24 +0,0 @@
/*
* 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.model.module;
import org.jetbrains.jps.model.JpsElementReference;
/**
* @author nik
*/
public interface JpsFacetReference extends JpsElementReference<JpsFacet> {
}
@@ -54,13 +54,6 @@ public interface JpsModule extends JpsNamedElement, JpsReferenceableElement<JpsM
void removeSourceRoot(@NotNull String url, @NotNull JpsModuleSourceRootType rootType);
@NotNull
<P extends JpsElement>
JpsFacet addFacet(@NotNull String name, @NotNull JpsFacetType<P> type, @NotNull P properties);
@NotNull
List<JpsFacet> getFacets();
JpsDependenciesList getDependenciesList();
@NotNull
@@ -23,10 +23,10 @@ import org.jetbrains.jps.model.ex.JpsElementChildRoleBase;
* @author nik
*/
public class JpsArtifactRole extends JpsElementChildRoleBase<JpsArtifact> {
public static final JpsArtifactRole INSTANCE = new JpsArtifactRole();
private static final JpsArtifactRole INSTANCE = new JpsArtifactRole();
public static final JpsElementCollectionRole<JpsArtifact> ARTIFACT_COLLECTION_ROLE = JpsElementCollectionRole.create(INSTANCE);
public JpsArtifactRole() {
private JpsArtifactRole() {
super("artifact");
}
}
@@ -29,7 +29,7 @@ import java.util.Map;
* @author nik
*/
public abstract class JpsEventDispatcherBase implements JpsEventDispatcher {
private Map<Class<?>, EventDispatcher<?>> myDispatchers = new HashMap<Class<?>, EventDispatcher<?>>();
private final Map<Class<?>, EventDispatcher<?>> myDispatchers = new HashMap<Class<?>, EventDispatcher<?>>();
@NotNull
@Override
@@ -41,11 +41,11 @@ public class JpsCompilerExcludesImpl implements JpsCompilerExcludes {
addExcludedDirectory(JpsPathUtil.urlToFile(url), recursively);
}
public void addExcludedFile(File file) {
protected void addExcludedFile(File file) {
myFiles.add(file);
}
public void addExcludedDirectory(File dir, boolean recursively) {
protected void addExcludedDirectory(File dir, boolean recursively) {
(recursively ? myRecursivelyExcludedDirectories : myDirectories).add(dir);
}
@@ -36,13 +36,13 @@ public class JpsJavaCompilerConfigurationImpl extends JpsCompositeElementBase<Jp
public static final JpsElementChildRole<JpsJavaCompilerConfiguration> ROLE = JpsElementChildRoleBase.create("compiler configuration");
private boolean myAddNotNullAssertions = true;
private boolean myClearOutputDirectoryOnRebuild = true;
private JpsCompilerExcludes myCompilerExcludes = new JpsCompilerExcludesImpl();
private List<String> myResourcePatterns = new ArrayList<String>();
private List<ProcessorConfigProfile> myAnnotationProcessingProfiles = new ArrayList<ProcessorConfigProfile>();
private ProcessorConfigProfileImpl myDefaultAnnotationProcessingProfile = new ProcessorConfigProfileImpl("Default");
private final JpsCompilerExcludes myCompilerExcludes = new JpsCompilerExcludesImpl();
private final List<String> myResourcePatterns = new ArrayList<String>();
private final List<ProcessorConfigProfile> myAnnotationProcessingProfiles = new ArrayList<ProcessorConfigProfile>();
private final ProcessorConfigProfileImpl myDefaultAnnotationProcessingProfile = new ProcessorConfigProfileImpl("Default");
private String myProjectByteCodeTargetLevel;
private Map<String, String> myModulesByteCodeTargetLevels = new HashMap<String, String>();
private Map<String, JpsJavaCompilerOptions> myCompilerOptions = new HashMap<String, JpsJavaCompilerOptions>();
private final Map<String, String> myModulesByteCodeTargetLevels = new HashMap<String, String>();
private final Map<String, JpsJavaCompilerOptions> myCompilerOptions = new HashMap<String, JpsJavaCompilerOptions>();
private String myJavaCompilerId = "Javac";
private Map<JpsModule, ProcessorConfigProfile> myAnnotationProcessingProfileMap;
private ResourcePatterns myCompiledPatterns;
@@ -160,7 +160,7 @@ public class ResourcePatterns {
return wildcardPattern;
}
public static boolean isPatternNegated(String wildcardPattern) {
private static boolean isPatternNegated(String wildcardPattern) {
return wildcardPattern.length() > 1 && wildcardPattern.charAt(0) == '!';
}
@@ -26,7 +26,7 @@ import org.jetbrains.jps.model.library.JpsLibraryListener;
* @author nik
*/
public class JpsLibraryRole extends JpsElementChildRoleBase<JpsLibrary> {
public static final JpsLibraryRole INSTANCE = new JpsLibraryRole();
private static final JpsLibraryRole INSTANCE = new JpsLibraryRole();
public static final JpsElementCollectionRole<JpsLibrary> LIBRARIES_COLLECTION_ROLE = JpsElementCollectionRole.create(INSTANCE);
private JpsLibraryRole() {
@@ -1,88 +0,0 @@
/*
* 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.model.module.impl;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jps.model.JpsElement;
import org.jetbrains.jps.model.JpsElementChildRole;
import org.jetbrains.jps.model.JpsElementCollection;
import org.jetbrains.jps.model.ex.JpsElementChildRoleBase;
import org.jetbrains.jps.model.ex.JpsNamedCompositeElementBase;
import org.jetbrains.jps.model.module.JpsFacet;
import org.jetbrains.jps.model.module.JpsFacetReference;
import org.jetbrains.jps.model.module.JpsFacetType;
import org.jetbrains.jps.model.module.JpsModule;
/**
* @author nik
*/
public class JpsFacetImpl extends JpsNamedCompositeElementBase<JpsFacetImpl> implements JpsFacet {
private static final JpsElementChildRole<JpsFacetReference> PARENT_FACET_REFERENCE = JpsElementChildRoleBase.create("parent facet");
private final JpsFacetType<?> myFacetType;
public <P extends JpsElement>JpsFacetImpl(JpsFacetType<?> facetType, @NotNull String name, @NotNull P properties) {
super(name);
myFacetType = facetType;
myContainer.setChild(JpsFacetRole.COLLECTION_ROLE);
}
private JpsFacetImpl(JpsFacetImpl original) {
super(original);
myFacetType = original.myFacetType;
}
@NotNull
@Override
public JpsFacetImpl createCopy() {
return new JpsFacetImpl(this);
}
@Override
@NotNull
public JpsFacetType<?> getType() {
return myFacetType;
}
@Override
public void setParentFacet(@NotNull JpsFacet facet) {
myContainer.setChild(PARENT_FACET_REFERENCE, facet.createReference());
}
@Override
@Nullable
public JpsFacet getParentFacet() {
final JpsFacetReference reference = myContainer.getChild(PARENT_FACET_REFERENCE);
return reference != null ? reference.resolve() : null;
}
@Override
public JpsModule getModule() {
return myParent != null ? (JpsModule)myParent.getParent() : null;
}
@NotNull
@Override
public JpsFacetReference createReference() {
return new JpsFacetReferenceImpl(getName(), getModule().createReference());
}
@Override
public void delete() {
//noinspection unchecked
((JpsElementCollection<JpsFacet>)myParent).removeChild(this);
}
}
@@ -1,41 +0,0 @@
/*
* 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.model.module.impl;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jps.model.impl.JpsNamedElementReferenceImpl;
import org.jetbrains.jps.model.module.JpsFacet;
import org.jetbrains.jps.model.module.JpsFacetReference;
import org.jetbrains.jps.model.module.JpsModuleReference;
/**
* @author nik
*/
public class JpsFacetReferenceImpl extends JpsNamedElementReferenceImpl<JpsFacet, JpsFacetReferenceImpl> implements JpsFacetReference {
public JpsFacetReferenceImpl(String facetName, JpsModuleReference moduleReference) {
super(JpsFacetRole.COLLECTION_ROLE, facetName, moduleReference);
}
private JpsFacetReferenceImpl(JpsFacetReferenceImpl original) {
super(original);
}
@NotNull
@Override
public JpsFacetReferenceImpl createCopy() {
return new JpsFacetReferenceImpl(this);
}
}
@@ -1,45 +0,0 @@
/*
* 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.model.module.impl;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jps.model.JpsEventDispatcher;
import org.jetbrains.jps.model.ex.JpsElementCollectionRole;
import org.jetbrains.jps.model.ex.JpsElementChildRoleBase;
import org.jetbrains.jps.model.module.JpsFacet;
import org.jetbrains.jps.model.module.JpsFacetListener;
/**
* @author nik
*/
public class JpsFacetRole extends JpsElementChildRoleBase<JpsFacet> {
public static final JpsFacetRole INSTANCE = new JpsFacetRole();
public static final JpsElementCollectionRole<JpsFacet> COLLECTION_ROLE = JpsElementCollectionRole.create(INSTANCE);
public JpsFacetRole() {
super("facet");
}
@Override
public void fireElementAdded(@NotNull JpsEventDispatcher dispatcher, @NotNull JpsFacet element) {
dispatcher.getPublisher(JpsFacetListener.class).facetAdded(element);
}
@Override
public void fireElementRemoved(@NotNull JpsEventDispatcher dispatcher, @NotNull JpsFacet element) {
dispatcher.getPublisher(JpsFacetListener.class).facetRemoved(element);
}
}
@@ -40,7 +40,7 @@ import java.util.List;
public class JpsModuleImpl<P extends JpsElement> extends JpsNamedCompositeElementBase<JpsModuleImpl<P>> implements JpsTypedModule<P> {
private static final JpsUrlListRole CONTENT_ROOTS_ROLE = new JpsUrlListRole("content roots");
private static final JpsUrlListRole EXCLUDED_ROOTS_ROLE = new JpsUrlListRole("excluded roots");
public static final JpsElementChildRole<JpsDependenciesListImpl> DEPENDENCIES_LIST_CHILD_ROLE = JpsElementChildRoleBase.create("dependencies");
private static final JpsElementChildRole<JpsDependenciesListImpl> DEPENDENCIES_LIST_CHILD_ROLE = JpsElementChildRoleBase.create("dependencies");
private final JpsModuleType<P> myModuleType;
private final JpsLibraryCollection myLibraryCollection;
@@ -50,7 +50,6 @@ public class JpsModuleImpl<P extends JpsElement> extends JpsNamedCompositeElemen
myContainer.setChild(myModuleType.getPropertiesRole(), properties);
myContainer.setChild(CONTENT_ROOTS_ROLE);
myContainer.setChild(EXCLUDED_ROOTS_ROLE);
myContainer.setChild(JpsFacetRole.COLLECTION_ROLE);
myContainer.setChild(DEPENDENCIES_LIST_CHILD_ROLE, new JpsDependenciesListImpl());
getDependenciesList().addModuleSourceDependency();
myLibraryCollection = new JpsLibraryCollectionImpl(myContainer.setChild(JpsLibraryRole.LIBRARIES_COLLECTION_ROLE));
@@ -136,18 +135,6 @@ public class JpsModuleImpl<P extends JpsElement> extends JpsNamedCompositeElemen
}
}
@NotNull
@Override
public <P extends JpsElement> JpsFacet addFacet(@NotNull String name, @NotNull JpsFacetType<P> type, @NotNull P properties) {
return myContainer.getChild(JpsFacetRole.COLLECTION_ROLE).addChild(new JpsFacetImpl(type, name, properties));
}
@NotNull
@Override
public List<JpsFacet> getFacets() {
return myContainer.getChild(JpsFacetRole.COLLECTION_ROLE).getElements();
}
@NotNull
@Override
public JpsDependenciesList getDependenciesList() {
@@ -27,10 +27,10 @@ import org.jetbrains.jps.model.module.JpsModuleListener;
* @author nik
*/
public class JpsModuleRole extends JpsElementChildRoleBase<JpsModule> {
public static final JpsElementChildRole<JpsModule> INSTANCE = new JpsModuleRole();
private static final JpsElementChildRole<JpsModule> INSTANCE = new JpsModuleRole();
public static final JpsElementCollectionRole<JpsModule> MODULE_COLLECTION_ROLE = JpsElementCollectionRole.create(INSTANCE);
public JpsModuleRole() {
private JpsModuleRole() {
super("module");
}
@@ -26,10 +26,10 @@ import org.jetbrains.jps.model.module.JpsModuleSourceRootListener;
* @author nik
*/
public class JpsModuleSourceRootRole extends JpsElementChildRoleBase<JpsModuleSourceRoot> {
public static final JpsModuleSourceRootRole INSTANCE = new JpsModuleSourceRootRole();
private static final JpsModuleSourceRootRole INSTANCE = new JpsModuleSourceRootRole();
public static final JpsElementCollectionRole<JpsModuleSourceRoot> ROOT_COLLECTION_ROLE = JpsElementCollectionRole.create(INSTANCE);
public JpsModuleSourceRootRole() {
private JpsModuleSourceRootRole() {
super("module source root");
}
@@ -1,40 +0,0 @@
/*
* 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.model;
import org.jetbrains.jps.model.java.JpsJavaModuleType;
import org.jetbrains.jps.model.module.JpsFacet;
import org.jetbrains.jps.model.module.JpsFacetType;
import org.jetbrains.jps.model.module.JpsModule;
/**
* @author nik
*/
public class JpsFacetTest extends JpsModelTestCase {
public void testAddFacet() {
final JpsModule m = myProject.addModule("m", JpsJavaModuleType.INSTANCE);
m.addFacet("f", MY_FACET_TYPE, JpsElementFactory.getInstance().createDummyElement());
assertEquals("f", assertOneElement(m.getFacets()).getName());
}
public void testCreateReferenceByFacet() {
final JpsFacet facet = myProject.addModule("m", JpsJavaModuleType.INSTANCE).addFacet("f", MY_FACET_TYPE, JpsElementFactory.getInstance().createDummyElement());
final JpsElementReference<JpsFacet> reference = facet.createReference().asExternal(myModel);
assertSame(facet, reference.resolve());
}
private static final JpsFacetType<JpsDummyElement> MY_FACET_TYPE = new JpsFacetType<JpsDummyElement>() { };
}
@@ -0,0 +1 @@
org.jetbrains.jps.model.serialization.impl.JpsSerializationManagerImpl
@@ -24,8 +24,8 @@ import org.jetbrains.jps.model.JpsElement;
* @author nik
*/
public abstract class JpsElementExtensionSerializerBase<E extends JpsElement> {
protected final String myConfigFileName;
protected final String myComponentName;
private final String myConfigFileName;
private final String myComponentName;
protected JpsElementExtensionSerializerBase(@Nullable String configFileName, @NotNull String componentName) {
myComponentName = componentName;
@@ -0,0 +1,75 @@
/*
* Copyright 2000-2013 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.model.serialization;
import com.intellij.openapi.util.JDOMUtil;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.util.SystemProperties;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.JDOMException;
import org.jetbrains.jps.model.JpsGlobal;
import java.io.File;
import java.io.IOException;
/**
* @author nik
*/
public class JpsGlobalElementSaver {
private static final JpsGlobalExtensionSerializer[] SERIALIZERS = {
new JpsGlobalLoader.PathVariablesSerializer(), new JpsGlobalLoader.GlobalLibrariesSerializer(), new JpsGlobalLoader.SdkTableSerializer()
};
private final JpsGlobal myGlobal;
public JpsGlobalElementSaver(JpsGlobal global) {
myGlobal = global;
}
public static void saveGlobalElement(JpsGlobal global, String optionsPath) throws IOException {
File optionsDir = new File(FileUtil.toCanonicalPath(optionsPath));
new JpsGlobalElementSaver(global).save(optionsDir);
}
private void save(File optionsDir) throws IOException {
for (JpsGlobalExtensionSerializer serializer : SERIALIZERS) {
saveGlobalComponents(serializer, optionsDir);
}
}
private void saveGlobalComponents(JpsGlobalExtensionSerializer serializer, File optionsDir) throws IOException {
String fileName = serializer.getConfigFileName();
File configFile = new File(optionsDir, fileName != null ? fileName : "other.xml");
Element rootElement = loadOrCreateRootElement(configFile);
serializer.saveExtension(myGlobal, JDomSerializationUtil.findOrCreateComponentElement(rootElement, serializer.getComponentName()));
JDOMUtil.writeDocument(new Document(rootElement), configFile, SystemProperties.getLineSeparator());
}
private static Element loadOrCreateRootElement(File configFile) {
if (!configFile.exists()) {
return new Element("application");
}
try {
return JDOMUtil.loadDocument(configFile).getRootElement();
}
catch (JDOMException e) {
throw new RuntimeException(e);
}
catch (IOException e) {
throw new RuntimeException(e);
}
}
}
@@ -16,20 +16,22 @@
package org.jetbrains.jps.model.serialization;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.util.JDOMUtil;
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 org.jetbrains.jps.model.JpsElementChildRole;
import org.jetbrains.jps.model.JpsElementFactory;
import org.jetbrains.jps.model.JpsGlobal;
import org.jetbrains.jps.model.JpsSimpleElement;
import org.jetbrains.jps.model.ex.JpsElementChildRoleBase;
import org.jetbrains.jps.model.serialization.impl.JpsPathVariablesConfigurationImpl;
import org.jetbrains.jps.model.serialization.library.JpsLibraryTableSerializer;
import org.jetbrains.jps.model.serialization.library.JpsSdkTableSerializer;
import java.io.File;
import java.io.IOException;
import java.util.Collections;
import java.util.Map;
/**
@@ -38,28 +40,29 @@ import java.util.Map;
public class JpsGlobalLoader extends JpsLoaderBase {
private static final Logger LOG = Logger.getInstance(JpsGlobalLoader.class);
public static final String SDK_TABLE_COMPONENT_NAME = "ProjectJdkTable";
private static final JpsElementChildRole<JpsSimpleElement<Map<String, String>>> PATH_VARIABLES_ROLE = JpsElementChildRoleBase.create("path variables");
public static final JpsElementChildRole<JpsPathVariablesConfiguration> PATH_VARIABLES_ROLE = JpsElementChildRoleBase.create("path variables");
private static final JpsGlobalExtensionSerializer[] SERIALIZERS = {
new GlobalLibrariesSerializer(), new SdkTableSerializer(), new FileTypesSerializer()
};
public static final String FILE_TYPES_COMPONENT_NAME_KEY = "jps.file.types.component.name";
private final JpsGlobal myGlobal;
public JpsGlobalLoader(JpsGlobal global, Map<String, String> pathVariables) {
private JpsGlobalLoader(JpsGlobal global, Map<String, String> pathVariables) {
super(new JpsMacroExpander(pathVariables));
myGlobal = global;
global.getContainer().setChild(PATH_VARIABLES_ROLE, JpsElementFactory.getInstance().createSimpleElement(pathVariables));
}
public static void loadGlobalSettings(JpsGlobal global, Map<String, String> pathVariables, String optionsPath) throws IOException {
public static void loadGlobalSettings(JpsGlobal global, String optionsPath) throws IOException {
File optionsDir = new File(FileUtil.toCanonicalPath(optionsPath));
new JpsGlobalLoader(global, Collections.<String, String>emptyMap()).loadGlobalComponents(optionsDir, new PathVariablesSerializer());
Map<String, String> pathVariables = JpsModelSerializationDataService.getAllPathVariables(global);
new JpsGlobalLoader(global, pathVariables).load(optionsDir);
}
@Nullable
public static String getPathVariable(JpsGlobal global, String name) {
JpsSimpleElement<Map<String, String>> child = global.getContainer().getChild(PATH_VARIABLES_ROLE);
return child != null ? child.getData().get(name) : null;
JpsPathVariablesConfiguration configuration = JpsModelSerializationDataService.getPathVariablesConfiguration(global);
return configuration != null ? configuration.getPathVariable(name) : null;
}
private void load(File optionsDir) {
@@ -78,8 +81,43 @@ public class JpsGlobalLoader extends JpsLoaderBase {
loadComponents(optionsDir, "other.xml", serializer, myGlobal);
}
private static class GlobalLibrariesSerializer extends JpsGlobalExtensionSerializer {
private GlobalLibrariesSerializer() {
public static class PathVariablesSerializer extends JpsGlobalExtensionSerializer {
public static final String MACRO_TAG = "macro";
public static final String NAME_ATTRIBUTE = "name";
public static final String VALUE_ATTRIBUTE = "value";
public PathVariablesSerializer() {
super("path.macros.xml", "PathMacrosImpl");
}
@Override
public void loadExtension(@NotNull JpsGlobal global, @NotNull Element componentTag) {
JpsPathVariablesConfiguration configuration = global.getContainer().setChild(PATH_VARIABLES_ROLE, new JpsPathVariablesConfigurationImpl());
for (Element macroTag : JDOMUtil.getChildren(componentTag, MACRO_TAG)) {
String name = macroTag.getAttributeValue(NAME_ATTRIBUTE);
String value = macroTag.getAttributeValue(VALUE_ATTRIBUTE);
if (name != null && value != null) {
configuration.addPathVariable(name, StringUtil.trimEnd(FileUtil.toSystemIndependentName(value), "/"));
}
}
}
@Override
public void saveExtension(@NotNull JpsGlobal global, @NotNull Element componentTag) {
JpsPathVariablesConfiguration configuration = JpsModelSerializationDataService.getPathVariablesConfiguration(global);
if (configuration != null) {
for (Map.Entry<String, String> entry : configuration.getAllVariables().entrySet()) {
Element tag = new Element(MACRO_TAG);
tag.setAttribute(NAME_ATTRIBUTE, entry.getKey());
tag.setAttribute(VALUE_ATTRIBUTE, entry.getValue());
componentTag.addContent(tag);
}
}
}
}
public static class GlobalLibrariesSerializer extends JpsGlobalExtensionSerializer {
public GlobalLibrariesSerializer() {
super("applicationLibraries.xml", "libraryTable");
}
@@ -94,8 +132,8 @@ public class JpsGlobalLoader extends JpsLoaderBase {
}
}
private static class SdkTableSerializer extends JpsGlobalExtensionSerializer {
private SdkTableSerializer() {
public static class SdkTableSerializer extends JpsGlobalExtensionSerializer {
public SdkTableSerializer() {
super("jdk.table.xml", SDK_TABLE_COMPONENT_NAME);
}
@@ -15,10 +15,8 @@
*/
package org.jetbrains.jps.model.serialization;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.util.JDOMUtil;
import com.intellij.openapi.util.SystemInfo;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.util.io.FileUtilRt;
import org.jdom.Element;
import org.jdom.JDOMException;
@@ -31,7 +29,6 @@ import java.io.IOException;
* @author nik
*/
public abstract class JpsLoaderBase {
private static final Logger LOG = Logger.getInstance("#org.jetbrains.jps.model.serialization.JpsLoaderBase");
private final JpsMacroExpander myMacroExpander;
protected JpsLoaderBase(JpsMacroExpander macroExpander) {
@@ -17,18 +17,46 @@ package org.jetbrains.jps.model.serialization;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jps.model.JpsGlobal;
import org.jetbrains.jps.model.JpsProject;
import org.jetbrains.jps.model.module.JpsModule;
import org.jetbrains.jps.model.serialization.impl.JpsModuleSerializationDataExtensionImpl;
import org.jetbrains.jps.model.serialization.impl.JpsPathVariablesConfigurationImpl;
import org.jetbrains.jps.model.serialization.impl.JpsProjectSerializationDataExtensionImpl;
import org.jetbrains.jps.model.serialization.module.JpsModuleSerializationDataExtension;
import java.io.File;
import java.util.HashMap;
import java.util.Map;
/**
* @author nik
*/
public class JpsModelSerializationDataService {
@NotNull
public static Map<String, String> getAllPathVariables(JpsGlobal global) {
Map<String, String> pathVariables = new HashMap<String, String>(PathMacroUtil.getGlobalSystemMacros());
JpsPathVariablesConfiguration configuration = getPathVariablesConfiguration(global);
if (configuration != null) {
pathVariables.putAll(configuration.getAllVariables());
}
return pathVariables;
}
@Nullable
public static JpsPathVariablesConfiguration getPathVariablesConfiguration(JpsGlobal global) {
return global.getContainer().getChild(JpsGlobalLoader.PATH_VARIABLES_ROLE);
}
@NotNull
public static JpsPathVariablesConfiguration getOrCreatePathVariablesConfiguration(JpsGlobal global) {
JpsPathVariablesConfiguration child = global.getContainer().getChild(JpsGlobalLoader.PATH_VARIABLES_ROLE);
if (child == null) {
return global.getContainer().setChild(JpsGlobalLoader.PATH_VARIABLES_ROLE, new JpsPathVariablesConfigurationImpl());
}
return child;
}
@Nullable
public static JpsProjectSerializationDataExtension getProjectExtension(@NotNull JpsProject project) {
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2012 JetBrains s.r.o.
* Copyright 2000-2013 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,14 +13,25 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.jps.model.module;
package org.jetbrains.jps.model.serialization;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jps.model.JpsElement;
import java.util.Map;
/**
* @author nik
*/
//todo[nik] I'm not sure that we really need separate interface for facets in the project model.
//Perhaps facets should be replaced by extensions for module elements
public abstract class JpsFacetType<P extends JpsElement> {
public interface JpsPathVariablesConfiguration extends JpsElement {
void addPathVariable(@NotNull String name, @NotNull String value);
void removePathVariable(@NotNull String name);
@Nullable
String getPathVariable(@NotNull String name);
@NotNull
Map<String, String> getAllVariables();
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2012 JetBrains s.r.o.
* Copyright 2000-2013 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,33 +13,27 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.jps.model.module;
package org.jetbrains.jps.model.serialization;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jps.model.JpsNamedElement;
import org.jetbrains.jps.model.JpsReferenceableElement;
import org.jetbrains.jps.model.JpsGlobal;
import org.jetbrains.jps.model.JpsModel;
import org.jetbrains.jps.service.JpsServiceManager;
import java.io.IOException;
/**
* @author nik
*/
//todo[nik] I'm not sure that we really need separate interface for facets in the project model.
//Perhaps facets should be replaced by extensions for module elements
public interface JpsFacet extends JpsNamedElement, JpsReferenceableElement<JpsFacet> {
JpsModule getModule();
public abstract class JpsSerializationManager {
public static JpsSerializationManager getInstance() {
return JpsServiceManager.getInstance().getService(JpsSerializationManager.class);
}
@NotNull
JpsFacetType<?> getType();
public abstract JpsModel loadModel(@NotNull String projectPath, @Nullable String optionsPath)
throws IOException;
void delete();
@NotNull
@Override
JpsFacetReference createReference();
void setParentFacet(@NotNull JpsFacet facet);
@Nullable
JpsFacet getParentFacet();
public abstract void saveGlobalSettings(@NotNull JpsGlobal global, @NotNull String optionsPath) throws IOException;
}
@@ -15,10 +15,16 @@
*/
package org.jetbrains.jps.model.serialization;
import com.intellij.openapi.application.PathManager;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.util.SystemProperties;
import com.intellij.util.containers.HashMap;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.Nullable;
import java.io.File;
import java.util.Map;
/**
* @author nik
@@ -28,6 +34,7 @@ public class PathMacroUtil {
@NonNls public static final String MODULE_DIR_MACRO_NAME = "MODULE_DIR";
@NonNls public static final String DIRECTORY_STORE_NAME = ".idea";
@NonNls public static final String APPLICATION_HOME_DIR = "APPLICATION_HOME_DIR";
@NonNls public static final String USER_HOME_NAME = "USER_HOME";
@Nullable
public static String getModuleDir(String moduleFilePath) {
@@ -48,4 +55,15 @@ public class PathMacroUtil {
}
return moduleDir;
}
public static String getUserHome() {
return StringUtil.trimEnd(FileUtil.toSystemIndependentName(SystemProperties.getUserHome()), "/");
}
public static Map<String, String> getGlobalSystemMacros() {
final Map<String, String> map = new HashMap<String, String>();
map.put(APPLICATION_HOME_DIR, FileUtil.toSystemIndependentName(PathManager.getHomePath()));
map.put(USER_HOME_NAME, getUserHome());
return map;
}
}
@@ -0,0 +1,72 @@
/*
* Copyright 2000-2013 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.model.serialization.impl;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jps.model.ex.JpsElementBase;
import org.jetbrains.jps.model.serialization.JpsPathVariablesConfiguration;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Map;
/**
* @author nik
*/
public class JpsPathVariablesConfigurationImpl extends JpsElementBase<JpsPathVariablesConfigurationImpl> implements JpsPathVariablesConfiguration {
private Map<String, String> myPathVariables;
public JpsPathVariablesConfigurationImpl() {
myPathVariables = new LinkedHashMap<String, String>();
}
private JpsPathVariablesConfigurationImpl(Map<String, String> pathVariables) {
myPathVariables = new LinkedHashMap<String, String>(pathVariables);
}
@NotNull
@Override
public JpsPathVariablesConfigurationImpl createCopy() {
return new JpsPathVariablesConfigurationImpl(myPathVariables);
}
@Override
public void applyChanges(@NotNull JpsPathVariablesConfigurationImpl modified) {
}
@Override
public void addPathVariable(@NotNull String name, @NotNull String value) {
myPathVariables.put(name, value);
}
@Override
public void removePathVariable(@NotNull String name) {
myPathVariables.remove(name);
}
@Nullable
@Override
public String getPathVariable(@NotNull String name) {
return myPathVariables.get(name);
}
@NotNull
@Override
public Map<String, String> getAllVariables() {
return Collections.unmodifiableMap(myPathVariables);
}
}
@@ -0,0 +1,49 @@
/*
* Copyright 2000-2013 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.model.serialization.impl;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jps.model.JpsElementFactory;
import org.jetbrains.jps.model.JpsGlobal;
import org.jetbrains.jps.model.JpsModel;
import org.jetbrains.jps.model.serialization.*;
import java.io.IOException;
import java.util.Map;
/**
* @author nik
*/
public class JpsSerializationManagerImpl extends JpsSerializationManager {
@NotNull
@Override
public JpsModel loadModel(@NotNull String projectPath, @Nullable String optionsPath)
throws IOException {
JpsModel model = JpsElementFactory.getInstance().createModel();
if (optionsPath != null) {
JpsGlobalLoader.loadGlobalSettings(model.getGlobal(), optionsPath);
}
Map<String, String> pathVariables = JpsModelSerializationDataService.getAllPathVariables(model.getGlobal());
JpsProjectLoader.loadProject(model.getProject(), pathVariables, projectPath);
return model;
}
@Override
public void saveGlobalSettings(@NotNull JpsGlobal global, @NotNull String optionsPath) throws IOException {
JpsGlobalElementSaver.saveGlobalElement(global, optionsPath);
}
}
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<application>
<component name="PathMacrosImpl">
<macro name="MAVEN_REPOSITORY" value="/home/nik/.m2/repository" />
</component>
</application>
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<application>
<component name="PathMacrosImpl">
<macro name="MAVEN_REPOSITORY" value="/home/nik/.m2/repository" />
<macro name="TOMCAT_HOME" value="/home/nik/applications/tomcat" />
</component>
</application>
@@ -15,12 +15,11 @@
*/
package org.jetbrains.jps.model.serialization;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.testFramework.PlatformTestUtil;
import org.jdom.Element;
import org.jdom.JDOMException;
import org.jetbrains.jps.model.JpsEncodingConfigurationService;
import org.jetbrains.jps.model.library.JpsLibrary;
import org.jetbrains.jps.model.serialization.library.JpsSdkTableSerializer;
import java.io.File;
import java.io.IOException;
@@ -32,7 +31,7 @@ import java.util.List;
public class JpsGlobalSerializationTest extends JpsSerializationTestCase {
private static final String OPTIONS_DIR = "jps/model-serialization/testData/config/options";
public void testLoadSdks() {
public void testLoadSdksAndGlobalLibraries() {
loadGlobalSettings(OPTIONS_DIR);
final List<JpsLibrary> libraries = myModel.getGlobal().getLibraryCollection().getLibraries();
assertEquals(3, libraries.size());
@@ -43,14 +42,53 @@ public class JpsGlobalSerializationTest extends JpsSerializationTestCase {
assertEquals("1.6", sdk2.getName());
}
public void testSaveSdks() throws JDOMException, IOException {
public void testSaveSdksAndGlobalLibraries() {
loadGlobalSettings(OPTIONS_DIR);
Element actual = new Element("component").setAttribute("name", "ProjectJdkTable");
JpsSdkTableSerializer.saveSdks(myModel.getGlobal().getLibraryCollection(), actual);
File jdkTableFile = new File(getTestDataFileAbsolutePath(OPTIONS_DIR), "jdk.table.xml");
JpsMacroExpander expander = new JpsMacroExpander(getPathVariables());
Element expected = JDomSerializationUtil.findComponent(JpsLoaderBase.loadRootElement(jdkTableFile, expander), "ProjectJdkTable");
PlatformTestUtil.assertElementsEqual(expected, actual);
File targetOptionsDir = saveGlobalSettings();
File originalOptionsDir = new File(getTestDataFileAbsolutePath(OPTIONS_DIR));
assertOptionsFilesEqual(originalOptionsDir, targetOptionsDir, "jdk.table.xml");
assertOptionsFilesEqual(originalOptionsDir, targetOptionsDir, "applicationLibraries.xml");
}
private File saveGlobalSettings() {
try {
File targetOptionsDir = FileUtil.createTempDirectory("options", null);
JpsSerializationManager.getInstance().saveGlobalSettings(myModel.getGlobal(), targetOptionsDir.getAbsolutePath());
return targetOptionsDir;
}
catch (IOException e) {
throw new RuntimeException(e);
}
}
public void testLoadPathVariables() {
loadGlobalSettings(OPTIONS_DIR);
JpsPathVariablesConfiguration configuration = JpsModelSerializationDataService.getPathVariablesConfiguration(myModel.getGlobal());
assertNotNull(configuration);
assertEquals("/home/nik/.m2/repository", configuration.getPathVariable("MAVEN_REPOSITORY"));
assertEquals(1, configuration.getAllVariables().size());
}
public void testSavePathVariables() {
loadGlobalSettings(OPTIONS_DIR);
JpsPathVariablesConfiguration configuration = JpsModelSerializationDataService.getOrCreatePathVariablesConfiguration(myModel.getGlobal());
configuration.addPathVariable("TOMCAT_HOME", "/home/nik/applications/tomcat");
File targetOptionsDir = saveGlobalSettings();
File originalOptionsDir = new File(getTestDataFileAbsolutePath(OPTIONS_DIR + "AfterChange"));
assertOptionsFilesEqual(originalOptionsDir, targetOptionsDir, "path.macros.xml");
}
private void assertOptionsFilesEqual(File originalOptionsDir, File targetOptionsDir, final String fileName) {
try {
JpsMacroExpander expander = new JpsMacroExpander(getPathVariables());
Element expected = JpsLoaderBase.loadRootElement(new File(originalOptionsDir, fileName), expander);
Element actual = JpsLoaderBase.loadRootElement(new File(targetOptionsDir, fileName), expander);
PlatformTestUtil.assertElementsEqual(expected, actual);
}
catch (IOException e) {
throw new RuntimeException(e);
}
}
public void testLoadEncoding() {
@@ -16,6 +16,7 @@
package org.jetbrains.jps.model.serialization;
import com.intellij.application.options.PathMacrosImpl;
import com.intellij.openapi.application.PathManager;
import com.intellij.openapi.application.ex.PathManagerEx;
import com.intellij.openapi.util.io.FileUtilRt;
import com.intellij.openapi.vfs.VfsUtilCore;
@@ -65,7 +66,11 @@ public abstract class JpsSerializationTestCase extends JpsModelTestCase {
try {
String optionsPath = getTestDataFileAbsolutePath(optionsDir);
Map<String,String> pathVariables = getPathVariables();
JpsGlobalLoader.loadGlobalSettings(myModel.getGlobal(), pathVariables, optionsPath);
JpsPathVariablesConfiguration configuration = JpsModelSerializationDataService.getOrCreatePathVariablesConfiguration(myModel.getGlobal());
for (Map.Entry<String, String> entry : pathVariables.entrySet()) {
configuration.addPathVariable(entry.getKey(), entry.getValue());
}
JpsGlobalLoader.loadGlobalSettings(myModel.getGlobal(), optionsPath);
}
catch (IOException e) {
throw new RuntimeException(e);
@@ -74,7 +79,7 @@ public abstract class JpsSerializationTestCase extends JpsModelTestCase {
protected Map<String, String> getPathVariables() {
Map<String, String> variables = new HashMap<String, String>();
variables.put(PathMacrosImpl.APPLICATION_HOME_MACRO_NAME, PathManagerEx.getHomePath(getClass()));
variables.put(PathMacrosImpl.APPLICATION_HOME_MACRO_NAME, PathManager.getHomePath());
variables.put(PathMacrosImpl.USER_HOME_MACRO_NAME, SystemProperties.getUserHome());
return variables;
}
@@ -114,9 +114,7 @@ public class Standalone {
initializer = new GroovyModelInitializer(scriptFile);
}
Map<String, String> pathVars = new HashMap<String, String>();
pathVars.put("USER_HOME", System.getProperty("user.home"));
JpsModelLoaderImpl loader = new JpsModelLoaderImpl(projectPath, globalOptionsPath, pathVars, initializer);
JpsModelLoaderImpl loader = new JpsModelLoaderImpl(projectPath, globalOptionsPath, initializer);
BuildType buildType = incremental ? BuildType.MAKE : BuildType.PROJECT_REBUILD;
Set<String> modulesSet = new HashSet<String>(Arrays.asList(modules));
List<String> artifactsList = Arrays.asList(artifacts);
@@ -124,8 +124,8 @@ bool FindJVMInEnvVar(const char* envVarName, bool& result)
else
{
char buf[_MAX_PATH];
sprintf_s(buf, "The environment variable %s (with the value of %s) does not point to a valid JVM installation",
envVarValue, jvmPath);
sprintf_s(buf, "The environment variable %s (with the value of %s) does not point to a valid JVM installation.",
envVarName, envVarValue);
MessageBoxA(NULL, buf, "Error Launching IntelliJ Platform", MB_OK);
result = false;
}
@@ -553,7 +553,6 @@ bool CheckSingleInstance()
{
hFileMapping = CreateFileMappingA(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, FILE_MAPPING_SIZE,
mappingName.c_str());
hSingleInstanceWatcherThread = CreateThread(NULL, 0, SingleInstanceThread, NULL, 0, NULL);
return true;
}
else
@@ -704,6 +703,9 @@ int APIENTRY _tWinMain(HINSTANCE hInstance,
if (!LoadVMOptions()) return 1;
if (!LoadJVMLibrary()) return 1;
if (!CreateJVM()) return 1;
hSingleInstanceWatcherThread = CreateThread(NULL, 0, SingleInstanceThread, NULL, 0, NULL);
if (!RunMainClass()) return 1;
jvm->DestroyJavaVM();
@@ -716,3 +718,4 @@ int APIENTRY _tWinMain(HINSTANCE hInstance,
return 0;
}
@@ -64,7 +64,7 @@
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
<IncludePath>C:\Java\jdk1.6.0_41\include;C:\Java\jdk1.6.0_41\include\win32;$(IncludePath)</IncludePath>
<IncludePath>C:\Java\jdk1.6.0_43\include;C:\Java\jdk1.6.0_43\include\win32;$(IncludePath)</IncludePath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
@@ -72,7 +72,7 @@
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
<IncludePath>C:\Java\jdk1.6.0_41\include;C:\Java\jdk1.6.0_41\include\win32;$(IncludePath)</IncludePath>
<IncludePath>C:\Java\jdk1.6.0_43\include;C:\Java\jdk1.6.0_43\include\win32;$(IncludePath)</IncludePath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
@@ -317,7 +317,12 @@ public class CompositeElement extends TreeElement {
@NonNls String msg = "";
msg += ";\n changed=" + (startStamp != myModificationsCount);
msg += ";\n buffer=" + text;
msg += ";\n this=" + this;
try {
msg += ";\n this=" + this;
}
catch (StackOverflowError e) {
msg += ";\n this.toString produces SOE";
}
int shitStart = textMatches(text, 0);
msg += ";\n matches until " + shitStart;
LeafElement leaf = findLeafElementAt(Math.abs(shitStart));
Binary file not shown.

Before

Width:  |  Height:  |  Size: 309 B

After

Width:  |  Height:  |  Size: 309 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 659 B

After

Width:  |  Height:  |  Size: 653 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 217 B

After

Width:  |  Height:  |  Size: 423 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 763 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 779 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 430 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 389 B

After

Width:  |  Height:  |  Size: 388 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 809 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 811 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 399 B

After

Width:  |  Height:  |  Size: 402 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 712 B

After

Width:  |  Height:  |  Size: 711 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 731 B

After

Width:  |  Height:  |  Size: 771 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 512 B

After

Width:  |  Height:  |  Size: 506 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 489 B

After

Width:  |  Height:  |  Size: 508 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 982 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 478 B

After

Width:  |  Height:  |  Size: 481 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 475 B

After

Width:  |  Height:  |  Size: 458 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1007 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 984 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 451 B

After

Width:  |  Height:  |  Size: 452 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 946 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 993 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 455 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 461 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 343 B

After

Width:  |  Height:  |  Size: 334 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 355 B

After

Width:  |  Height:  |  Size: 466 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 425 B

After

Width:  |  Height:  |  Size: 449 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 347 B

After

Width:  |  Height:  |  Size: 349 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 553 B

After

Width:  |  Height:  |  Size: 578 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 429 B

After

Width:  |  Height:  |  Size: 436 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 365 B

After

Width:  |  Height:  |  Size: 356 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 352 B

After

Width:  |  Height:  |  Size: 358 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 471 B

After

Width:  |  Height:  |  Size: 463 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 393 B

After

Width:  |  Height:  |  Size: 396 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 844 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 128 B

After

Width:  |  Height:  |  Size: 196 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 296 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 297 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 197 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 508 B

After

Width:  |  Height:  |  Size: 489 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1001 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 406 B

After

Width:  |  Height:  |  Size: 411 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 712 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 821 B

Some files were not shown because too many files have changed in this diff Show More