mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
jps: load path variables from config file
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -22,7 +22,6 @@ import org.jetbrains.jps.model.JpsModel;
|
||||
import org.jetbrains.jps.model.serialization.JpsSerializationManager;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author nik
|
||||
@@ -31,14 +30,11 @@ 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,
|
||||
@Nullable ParameterizedRunnable<JpsModel> initializer) {
|
||||
public JpsModelLoaderImpl(String projectPath, String globalOptionsPath, @Nullable ParameterizedRunnable<JpsModel> initializer) {
|
||||
myProjectPath = projectPath;
|
||||
myGlobalOptionsPath = globalOptionsPath;
|
||||
myPathVars = pathVars;
|
||||
myModelInitializer = initializer;
|
||||
}
|
||||
|
||||
@@ -46,7 +42,7 @@ public class JpsModelLoaderImpl implements JpsModelLoader {
|
||||
public JpsModel loadModel() throws IOException {
|
||||
final long start = System.currentTimeMillis();
|
||||
LOG.info("Loading model: project path = " + myProjectPath + ", global options path = " + myGlobalOptionsPath);
|
||||
final JpsModel model = JpsSerializationManager.getInstance().loadModel(myProjectPath, myGlobalOptionsPath, myPathVars);
|
||||
final JpsModel model = JpsSerializationManager.getInstance().loadModel(myProjectPath, myGlobalOptionsPath);
|
||||
if (myModelInitializer != null) {
|
||||
myModelInitializer.run(model);
|
||||
}
|
||||
|
||||
+1
-1
@@ -31,7 +31,7 @@ import java.io.IOException;
|
||||
*/
|
||||
public class JpsGlobalElementSaver {
|
||||
private static final JpsGlobalExtensionSerializer[] SERIALIZERS = {
|
||||
new JpsGlobalLoader.GlobalLibrariesSerializer(), new JpsGlobalLoader.SdkTableSerializer()
|
||||
new JpsGlobalLoader.PathVariablesSerializer(), new JpsGlobalLoader.GlobalLibrariesSerializer(), new JpsGlobalLoader.SdkTableSerializer()
|
||||
};
|
||||
private final JpsGlobal myGlobal;
|
||||
|
||||
|
||||
+45
-7
@@ -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,7 +40,7 @@ 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()
|
||||
};
|
||||
@@ -48,18 +50,19 @@ public class JpsGlobalLoader extends JpsLoaderBase {
|
||||
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,6 +81,41 @@ public class JpsGlobalLoader extends JpsLoaderBase {
|
||||
loadComponents(optionsDir, "other.xml", serializer, myGlobal);
|
||||
}
|
||||
|
||||
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");
|
||||
|
||||
+28
@@ -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) {
|
||||
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* 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 org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jps.model.JpsElement;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author nik
|
||||
*/
|
||||
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
-2
@@ -22,7 +22,6 @@ import org.jetbrains.jps.model.JpsModel;
|
||||
import org.jetbrains.jps.service.JpsServiceManager;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author nik
|
||||
@@ -33,7 +32,7 @@ public abstract class JpsSerializationManager {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public abstract JpsModel loadModel(@NotNull String projectPath, @Nullable String optionsPath, @NotNull Map<String, String> pathVariables)
|
||||
public abstract JpsModel loadModel(@NotNull String projectPath, @Nullable String optionsPath)
|
||||
throws IOException;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
+72
@@ -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);
|
||||
}
|
||||
}
|
||||
+4
-6
@@ -20,10 +20,7 @@ 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.JpsGlobalElementSaver;
|
||||
import org.jetbrains.jps.model.serialization.JpsGlobalLoader;
|
||||
import org.jetbrains.jps.model.serialization.JpsProjectLoader;
|
||||
import org.jetbrains.jps.model.serialization.JpsSerializationManager;
|
||||
import org.jetbrains.jps.model.serialization.*;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
@@ -34,12 +31,13 @@ import java.util.Map;
|
||||
public class JpsSerializationManagerImpl extends JpsSerializationManager {
|
||||
@NotNull
|
||||
@Override
|
||||
public JpsModel loadModel(@NotNull String projectPath, @Nullable String optionsPath, @NotNull Map<String, String> pathVariables)
|
||||
public JpsModel loadModel(@NotNull String projectPath, @Nullable String optionsPath)
|
||||
throws IOException {
|
||||
JpsModel model = JpsElementFactory.getInstance().createModel();
|
||||
if (optionsPath != null) {
|
||||
JpsGlobalLoader.loadGlobalSettings(model.getGlobal(), pathVariables, optionsPath);
|
||||
JpsGlobalLoader.loadGlobalSettings(model.getGlobal(), optionsPath);
|
||||
}
|
||||
Map<String, String> pathVariables = JpsModelSerializationDataService.getAllPathVariables(model.getGlobal());
|
||||
JpsProjectLoader.loadProject(model.getProject(), pathVariables, projectPath);
|
||||
return model;
|
||||
}
|
||||
|
||||
@@ -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>
|
||||
|
||||
+41
-10
@@ -18,7 +18,6 @@ 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;
|
||||
|
||||
@@ -43,21 +42,53 @@ public class JpsGlobalSerializationTest extends JpsSerializationTestCase {
|
||||
assertEquals("1.6", sdk2.getName());
|
||||
}
|
||||
|
||||
public void testSaveSdksAndGlobalLibraries() throws JDOMException, IOException {
|
||||
public void testSaveSdksAndGlobalLibraries() {
|
||||
loadGlobalSettings(OPTIONS_DIR);
|
||||
File targetOptionsDir = FileUtil.createTempDirectory("options" ,null);
|
||||
JpsSerializationManager.getInstance().saveGlobalSettings(myModel.getGlobal(), targetOptionsDir.getAbsolutePath());
|
||||
|
||||
File targetOptionsDir = saveGlobalSettings();
|
||||
File originalOptionsDir = new File(getTestDataFileAbsolutePath(OPTIONS_DIR));
|
||||
assertOptionsFilesEqual(originalOptionsDir, targetOptionsDir, "jdk.table.xml");
|
||||
assertOptionsFilesEqual(originalOptionsDir, targetOptionsDir, "applicationLibraries.xml");
|
||||
}
|
||||
|
||||
private void assertOptionsFilesEqual(File originalOptionsDir, File targetOptionsDir, final String fileName) throws IOException {
|
||||
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);
|
||||
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() {
|
||||
|
||||
+7
-2
@@ -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);
|
||||
|
||||
+5
-22
@@ -17,7 +17,6 @@ package com.intellij.application.options;
|
||||
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.application.PathMacros;
|
||||
import com.intellij.openapi.application.PathManager;
|
||||
import com.intellij.openapi.components.ApplicationComponent;
|
||||
import com.intellij.openapi.components.ExpandMacroToPathMap;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
@@ -25,15 +24,13 @@ import com.intellij.openapi.util.InvalidDataException;
|
||||
import com.intellij.openapi.util.NamedJDOMExternalizable;
|
||||
import com.intellij.openapi.util.RoamingTypeDisabled;
|
||||
import com.intellij.openapi.util.WriteExternalException;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.util.SystemProperties;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.containers.HashMap;
|
||||
import gnu.trove.THashSet;
|
||||
import org.jdom.Element;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jps.model.serialization.JpsGlobalLoader;
|
||||
import org.jetbrains.jps.model.serialization.PathMacroUtil;
|
||||
|
||||
import java.util.*;
|
||||
@@ -50,12 +47,9 @@ public class PathMacrosImpl extends PathMacros implements ApplicationComponent,
|
||||
private final ReentrantReadWriteLock myLock = new ReentrantReadWriteLock();
|
||||
private final List<String> myIgnoredMacros = ContainerUtil.createLockFreeCopyOnWriteList();
|
||||
|
||||
@NonNls
|
||||
public static final String MACRO_ELEMENT = "macro";
|
||||
@NonNls
|
||||
public static final String NAME_ATTR = "name";
|
||||
@NonNls
|
||||
public static final String VALUE_ATTR = "value";
|
||||
public static final String MACRO_ELEMENT = JpsGlobalLoader.PathVariablesSerializer.MACRO_TAG;
|
||||
public static final String NAME_ATTR = JpsGlobalLoader.PathVariablesSerializer.NAME_ATTRIBUTE;
|
||||
public static final String VALUE_ATTR = JpsGlobalLoader.PathVariablesSerializer.VALUE_ATTRIBUTE;
|
||||
|
||||
@NonNls
|
||||
public static final String IGNORED_MACRO_ELEMENT = "ignoredMacro";
|
||||
@@ -68,7 +62,7 @@ public class PathMacrosImpl extends PathMacros implements ApplicationComponent,
|
||||
@NonNls
|
||||
public static final String MODULE_DIR_MACRO_NAME = PathMacroUtil.MODULE_DIR_MACRO_NAME;
|
||||
@NonNls
|
||||
public static final String USER_HOME_MACRO_NAME = "USER_HOME";
|
||||
public static final String USER_HOME_MACRO_NAME = PathMacroUtil.USER_HOME_NAME;
|
||||
|
||||
private static final Set<String> SYSTEM_MACROS = new HashSet<String>();
|
||||
@NonNls public static final String EXT_FILE_NAME = "path.macros";
|
||||
@@ -207,13 +201,6 @@ public class PathMacrosImpl extends PathMacros implements ApplicationComponent,
|
||||
}
|
||||
}
|
||||
|
||||
public static Map<String, String> getGlobalSystemMacros() {
|
||||
final Map<String, String> map = new HashMap<String, String>();
|
||||
map.put(APPLICATION_HOME_MACRO_NAME, PathManager.getHomePath());
|
||||
map.put(USER_HOME_MACRO_NAME, getUserHome());
|
||||
return map;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isIgnoredMacroName(@NotNull String macro) {
|
||||
return myIgnoredMacros.contains(macro);
|
||||
@@ -393,8 +380,4 @@ public class PathMacrosImpl extends PathMacros implements ApplicationComponent,
|
||||
myLock.readLock().unlock();
|
||||
}
|
||||
}
|
||||
|
||||
public static String getUserHome() {
|
||||
return StringUtil.trimEnd(FileUtil.toSystemIndependentName(SystemProperties.getUserHome()), "/");
|
||||
}
|
||||
}
|
||||
|
||||
+3
-2
@@ -31,6 +31,7 @@ import com.intellij.openapi.vfs.VirtualFileSystem;
|
||||
import com.intellij.util.containers.FactoryMap;
|
||||
import org.jdom.Element;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jps.model.serialization.PathMacroUtil;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@@ -78,7 +79,7 @@ public class BasePathMacroManager extends PathMacroManager {
|
||||
|
||||
public ExpandMacroToPathMap getExpandMacroMap() {
|
||||
ExpandMacroToPathMap result = new ExpandMacroToPathMap();
|
||||
for (Map.Entry<String, String> entry : PathMacrosImpl.getGlobalSystemMacros().entrySet()) {
|
||||
for (Map.Entry<String, String> entry : PathMacroUtil.getGlobalSystemMacros().entrySet()) {
|
||||
result.addMacroExpand(entry.getKey(), entry.getValue());
|
||||
}
|
||||
getPathMacros().addMacroExpands(result);
|
||||
@@ -87,7 +88,7 @@ public class BasePathMacroManager extends PathMacroManager {
|
||||
|
||||
protected ReplacePathToMacroMap getReplacePathMap() {
|
||||
ReplacePathToMacroMap result = new ReplacePathToMacroMap();
|
||||
for (Map.Entry<String, String> entry : PathMacrosImpl.getGlobalSystemMacros().entrySet()) {
|
||||
for (Map.Entry<String, String> entry : PathMacroUtil.getGlobalSystemMacros().entrySet()) {
|
||||
result.addMacroReplacement(entry.getValue(), entry.getKey());
|
||||
}
|
||||
getPathMacros().addMacroReplacements(result);
|
||||
|
||||
+1
-1
@@ -50,7 +50,7 @@ public class ModulePathMacroManager extends BasePathMacroManager {
|
||||
|
||||
if (!myModule.isDisposed()) {
|
||||
final String modulePath = PathMacroUtil.getModuleDir(myModule.getModuleFilePath());
|
||||
addFileHierarchyReplacements(result, PathMacrosImpl.MODULE_DIR_MACRO_NAME, modulePath, PathMacrosImpl.getUserHome());
|
||||
addFileHierarchyReplacements(result, PathMacrosImpl.MODULE_DIR_MACRO_NAME, modulePath, PathMacroUtil.getUserHome());
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
+3
-3
@@ -21,11 +21,11 @@ import com.intellij.openapi.util.io.FileUtil;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jps.incremental.artifacts.ArtifactBuilderTestCase;
|
||||
import org.jetbrains.jps.model.serialization.JpsGlobalLoader;
|
||||
import org.jetbrains.jps.model.serialization.JpsModelSerializationDataService;
|
||||
import org.jetbrains.jps.model.serialization.PathMacroUtil;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
|
||||
import static com.intellij.util.io.TestFileSystemBuilder.fs;
|
||||
@@ -43,8 +43,8 @@ public class JpsAntArtifactBuilderTaskTest extends ArtifactBuilderTestCase {
|
||||
}
|
||||
|
||||
public void testSimple() throws IOException {
|
||||
Map<String, String> pathVariables = Collections.singletonMap(PathMacroUtil.APPLICATION_HOME_DIR, PathManager.getHomePath());
|
||||
JpsGlobalLoader.loadGlobalSettings(myModel.getGlobal(), pathVariables, getTestDataRootPath() + "/config/options");
|
||||
JpsModelSerializationDataService.getOrCreatePathVariablesConfiguration(myModel.getGlobal()).addPathVariable(PathMacroUtil.APPLICATION_HOME_DIR, PathManager.getHomePath());
|
||||
JpsGlobalLoader.loadGlobalSettings(myModel.getGlobal(), getTestDataRootPath() + "/config/options");
|
||||
addJdk("1.6");
|
||||
loadProject("ant-project");
|
||||
rebuildAll();
|
||||
|
||||
Reference in New Issue
Block a user