From 896e13d0cd988a157fe27fc221c04cec902997a4 Mon Sep 17 00:00:00 2001 From: nik Date: Mon, 6 Feb 2012 12:36:37 +0400 Subject: [PATCH] transfer artifact names to compile server --- .../compiler/CompileServerManager.java | 11 +-- .../intellij/compiler/impl/CompileDriver.java | 15 +++- jps/jps-builders/proto/gen_proto.sh | 2 + jps/jps-builders/proto/jps_remote_proto.proto | 1 + .../org/jetbrains/jps/api/JpsRemoteProto.java | 78 +++++++++++++++++++ .../src/org/jetbrains/jps/api/ProtoUtil.java | 23 ++++-- .../jps/client/CompileServerClient.java | 7 +- .../artifacts/ArtifactSourceFilesState.java | 32 +++++--- .../artifacts/ArtifactsBuildData.java | 7 +- .../jps/server/ServerMessageHandler.java | 4 +- 10 files changed, 145 insertions(+), 35 deletions(-) create mode 100755 jps/jps-builders/proto/gen_proto.sh diff --git a/java/compiler/impl/src/com/intellij/compiler/CompileServerManager.java b/java/compiler/impl/src/com/intellij/compiler/CompileServerManager.java index b207b8d4a5e2..f97ad79d2de0 100644 --- a/java/compiler/impl/src/com/intellij/compiler/CompileServerManager.java +++ b/java/compiler/impl/src/com/intellij/compiler/CompileServerManager.java @@ -271,9 +271,8 @@ public class CompileServerManager implements ApplicationComponent{ if (!config.useCompileServer() || !config.MAKE_PROJECT_ON_SAVE) { continue; } - final RequestFuture future = submitCompilationTask( - project, false, true, Collections.emptyList(), Collections.emptyList(), new AutoMakeResponseHandler(project) - ); + final RequestFuture future = submitCompilationTask(project, false, true, Collections.emptyList(), Collections.emptyList(), + Collections.emptyList(), new AutoMakeResponseHandler(project)); if (future != null) { futures.add(future); synchronized (myAutomakeFutures) { @@ -311,7 +310,9 @@ public class CompileServerManager implements ApplicationComponent{ } @Nullable - public RequestFuture submitCompilationTask(final Project project, final boolean isRebuild, final boolean isMake, final Collection modules, final Collection paths, final JpsServerResponseHandler handler) { + public RequestFuture submitCompilationTask(final Project project, final boolean isRebuild, final boolean isMake, + final Collection modules, final Collection artifacts, + final Collection paths, final JpsServerResponseHandler handler) { final String projectId = project.getLocation(); final Ref futureRef = new Ref(null); final RunnableFuture future = myTaskExecutor.submit(new Runnable() { @@ -321,7 +322,7 @@ public class CompileServerManager implements ApplicationComponent{ if (client != null) { final RequestFuture requestFuture = isRebuild ? client.sendRebuildRequest(projectId, handler) : - client.sendCompileRequest(isMake, projectId, modules, paths, handler); + client.sendCompileRequest(isMake, projectId, modules, artifacts, paths, handler); futureRef.set(requestFuture); } else { diff --git a/java/compiler/impl/src/com/intellij/compiler/impl/CompileDriver.java b/java/compiler/impl/src/com/intellij/compiler/impl/CompileDriver.java index 87198ba9d5e7..5751811c903b 100644 --- a/java/compiler/impl/src/com/intellij/compiler/impl/CompileDriver.java +++ b/java/compiler/impl/src/com/intellij/compiler/impl/CompileDriver.java @@ -414,19 +414,25 @@ public class CompileDriver { } @Nullable - private RequestFuture compileOnServer(final CompileContextImpl compileContext, Collection modules, final Collection paths, @Nullable final CompileStatusNotification callback) + private RequestFuture compileOnServer(final @NotNull CompileContextImpl compileContext, @NotNull Collection modules, @NotNull Collection artifacts, + final @NotNull Collection paths, @Nullable final CompileStatusNotification callback) throws Exception { Collection moduleNames = Collections.emptyList(); - if (modules != null && modules.size() > 0) { + if (modules.size() > 0) { moduleNames = new ArrayList(modules.size()); for (Module module : modules) { moduleNames.add(module.getName()); } } + List artifactNames = new ArrayList(); + for (Artifact artifact : artifacts) { + artifactNames.add(artifact.getName()); + } + final CompileServerManager csManager = CompileServerManager.getInstance(); final MessageBus messageBus = myProject.getMessageBus(); csManager.cancelAutoMakeTasks(myProject); - return csManager.submitCompilationTask(myProject, compileContext.isRebuild(), compileContext.isMake(), moduleNames, paths, new JpsServerResponseHandler() { + return csManager.submitCompilationTask(myProject, compileContext.isRebuild(), compileContext.isMake(), moduleNames, artifactNames, paths, new JpsServerResponseHandler() { @Override public void handleCompileMessage(JpsRemoteProto.Message.Response.CompileMessage compilerMessage) { @@ -584,7 +590,8 @@ public class CompileDriver { } final Collection paths = fetchFiles(compileContext); final List modules = paths.isEmpty()? Arrays.asList(compileContext.getCompileScope().getAffectedModules()) : Collections.emptyList(); - final RequestFuture future = compileOnServer(compileContext, modules, paths, callback); + final Set artifacts = ArtifactCompileScope.getArtifactsToBuild(myProject, compileContext.getCompileScope(), true); + final RequestFuture future = compileOnServer(compileContext, modules, artifacts, paths, callback); if (future != null) { try { startCancelWatcher(indicator, future); diff --git a/jps/jps-builders/proto/gen_proto.sh b/jps/jps-builders/proto/gen_proto.sh new file mode 100755 index 000000000000..0a2ba92d332e --- /dev/null +++ b/jps/jps-builders/proto/gen_proto.sh @@ -0,0 +1,2 @@ +protoc -I=. --java_out=../src javac_remote_proto.proto +protoc -I=. --java_out=../src jps_remote_proto.proto \ No newline at end of file diff --git a/jps/jps-builders/proto/jps_remote_proto.proto b/jps/jps-builders/proto/jps_remote_proto.proto index 4f9cbb27b579..2b9e0b9001aa 100644 --- a/jps/jps-builders/proto/jps_remote_proto.proto +++ b/jps/jps-builders/proto/jps_remote_proto.proto @@ -43,6 +43,7 @@ message Message { optional string project_id = 2; repeated string module_name = 3; repeated string file_path = 4; + repeated string artifact_name = 5; } message ShutdownCommand { diff --git a/jps/jps-builders/src/org/jetbrains/jps/api/JpsRemoteProto.java b/jps/jps-builders/src/org/jetbrains/jps/api/JpsRemoteProto.java index 42191910cc47..ebde9bb6ee3d 100644 --- a/jps/jps-builders/src/org/jetbrains/jps/api/JpsRemoteProto.java +++ b/jps/jps-builders/src/org/jetbrains/jps/api/JpsRemoteProto.java @@ -857,6 +857,18 @@ public final class JpsRemoteProto { return filePath_.get(index); } + // repeated string artifact_name = 5; + public static final int ARTIFACT_NAME_FIELD_NUMBER = 5; + private java.util.List artifactName_ = + java.util.Collections.emptyList(); + public java.util.List getArtifactNameList() { + return artifactName_; + } + public int getArtifactNameCount() { return artifactName_.size(); } + public java.lang.String getArtifactName(int index) { + return artifactName_.get(index); + } + private void initFields() { commandType_ = org.jetbrains.jps.api.JpsRemoteProto.Message.Request.CompilationRequest.Type.REBUILD; } @@ -880,6 +892,9 @@ public final class JpsRemoteProto { for (java.lang.String element : getFilePathList()) { output.writeString(4, element); } + for (java.lang.String element : getArtifactNameList()) { + output.writeString(5, element); + } } private int memoizedSerializedSize = -1; @@ -914,6 +929,15 @@ public final class JpsRemoteProto { size += dataSize; size += 1 * getFilePathList().size(); } + { + int dataSize = 0; + for (java.lang.String element : getArtifactNameList()) { + dataSize += com.google.protobuf.CodedOutputStream + .computeStringSizeNoTag(element); + } + size += dataSize; + size += 1 * getArtifactNameList().size(); + } memoizedSerializedSize = size; return size; } @@ -1059,6 +1083,10 @@ public final class JpsRemoteProto { result.filePath_ = java.util.Collections.unmodifiableList(result.filePath_); } + if (result.artifactName_ != java.util.Collections.EMPTY_LIST) { + result.artifactName_ = + java.util.Collections.unmodifiableList(result.artifactName_); + } org.jetbrains.jps.api.JpsRemoteProto.Message.Request.CompilationRequest returnMe = result; result = null; return returnMe; @@ -1084,6 +1112,12 @@ public final class JpsRemoteProto { } result.filePath_.addAll(other.filePath_); } + if (!other.artifactName_.isEmpty()) { + if (result.artifactName_.isEmpty()) { + result.artifactName_ = new java.util.ArrayList(); + } + result.artifactName_.addAll(other.artifactName_); + } return this; } @@ -1122,6 +1156,10 @@ public final class JpsRemoteProto { addFilePath(input.readString()); break; } + case 42: { + addArtifactName(input.readString()); + break; + } } } } @@ -1249,6 +1287,46 @@ public final class JpsRemoteProto { return this; } + // repeated string artifact_name = 5; + public java.util.List getArtifactNameList() { + return java.util.Collections.unmodifiableList(result.artifactName_); + } + public int getArtifactNameCount() { + return result.getArtifactNameCount(); + } + public java.lang.String getArtifactName(int index) { + return result.getArtifactName(index); + } + public Builder setArtifactName(int index, java.lang.String value) { + if (value == null) { + throw new NullPointerException(); + } + result.artifactName_.set(index, value); + return this; + } + public Builder addArtifactName(java.lang.String value) { + if (value == null) { + throw new NullPointerException(); + } + if (result.artifactName_.isEmpty()) { + result.artifactName_ = new java.util.ArrayList(); + } + result.artifactName_.add(value); + return this; + } + public Builder addAllArtifactName( + java.lang.Iterable values) { + if (result.artifactName_.isEmpty()) { + result.artifactName_ = new java.util.ArrayList(); + } + super.addAll(values, result.artifactName_); + return this; + } + public Builder clearArtifactName() { + result.artifactName_ = java.util.Collections.emptyList(); + return this; + } + // @@protoc_insertion_point(builder_scope:org.jetbrains.jpsservice.Message.Request.CompilationRequest) } diff --git a/jps/jps-builders/src/org/jetbrains/jps/api/ProtoUtil.java b/jps/jps-builders/src/org/jetbrains/jps/api/ProtoUtil.java index 681baf46a0d8..e2646765706d 100644 --- a/jps/jps-builders/src/org/jetbrains/jps/api/ProtoUtil.java +++ b/jps/jps-builders/src/org/jetbrains/jps/api/ProtoUtil.java @@ -28,20 +28,23 @@ public class ProtoUtil { return builder.build(); } - public static JpsRemoteProto.Message.Request createMakeRequest(String project, Collection modules) { - return createCompileRequest(JpsRemoteProto.Message.Request.CompilationRequest.Type.MAKE, project, modules, Collections.emptyList()); + public static JpsRemoteProto.Message.Request createMakeRequest(String project, Collection modules, Collection artifacts) { + return createCompileRequest(JpsRemoteProto.Message.Request.CompilationRequest.Type.MAKE, project, modules, artifacts, Collections.emptyList()); } - public static JpsRemoteProto.Message.Request createForceCompileRequest(String project, Collection modules, Collection paths) { - return createCompileRequest(JpsRemoteProto.Message.Request.CompilationRequest.Type.FORCED_COMPILATION, project, modules, paths); + public static JpsRemoteProto.Message.Request createForceCompileRequest(String project, + Collection modules, + Collection artifacts, Collection paths) { + return createCompileRequest(JpsRemoteProto.Message.Request.CompilationRequest.Type.FORCED_COMPILATION, project, modules, artifacts, paths); } public static JpsRemoteProto.Message.Request createRebuildRequest(String project) { - return createCompileRequest(JpsRemoteProto.Message.Request.CompilationRequest.Type.REBUILD, project, Collections.emptyList(), Collections.emptyList()); + return createCompileRequest(JpsRemoteProto.Message.Request.CompilationRequest.Type.REBUILD, project, Collections.emptyList(), + Collections.emptyList(), Collections.emptyList()); } - public static JpsRemoteProto.Message.Request createCleanRequest(String project, Collection modules) { - return createCompileRequest(JpsRemoteProto.Message.Request.CompilationRequest.Type.CLEAN, project, modules, Collections.emptyList()); + public static JpsRemoteProto.Message.Request createCleanRequest(String project, Collection modules, Collection artifacts) { + return createCompileRequest(JpsRemoteProto.Message.Request.CompilationRequest.Type.CLEAN, project, modules, artifacts, Collections.emptyList()); } public static JpsRemoteProto.Message.Request createCancelRequest(UUID compileSessionId) { @@ -50,13 +53,17 @@ public class ProtoUtil { return JpsRemoteProto.Message.Request.newBuilder().setRequestType(JpsRemoteProto.Message.Request.Type.CANCEL_BUILD_COMMAND).setCancelBuildCommand(builder.build()).build(); } - public static JpsRemoteProto.Message.Request createCompileRequest(final JpsRemoteProto.Message.Request.CompilationRequest.Type command, String project, Collection modules, Collection paths) { + public static JpsRemoteProto.Message.Request createCompileRequest(final JpsRemoteProto.Message.Request.CompilationRequest.Type command, String project, Collection modules, + Collection artifacts, Collection paths) { final JpsRemoteProto.Message.Request.CompilationRequest.Builder builder = JpsRemoteProto.Message.Request.CompilationRequest.newBuilder().setCommandType( command); builder.setProjectId(project); if (modules.size() > 0) { builder.addAllModuleName(modules); } + if (artifacts.size() > 0) { + builder.addAllArtifactName(artifacts); + } if (paths.size() > 0) { builder.addAllFilePath(paths); } diff --git a/jps/jps-builders/src/org/jetbrains/jps/client/CompileServerClient.java b/jps/jps-builders/src/org/jetbrains/jps/client/CompileServerClient.java index 474227367a40..139eaa703e74 100644 --- a/jps/jps-builders/src/org/jetbrains/jps/client/CompileServerClient.java +++ b/jps/jps-builders/src/org/jetbrains/jps/client/CompileServerClient.java @@ -27,11 +27,12 @@ public class CompileServerClient extends SimpleProtobufClient modules, Collection paths, JpsServerResponseHandler handler) throws Exception{ + public RequestFuture sendCompileRequest(boolean isMake, String projectId, Collection modules, final Collection artifacts, + Collection paths, JpsServerResponseHandler handler) throws Exception{ checkConnected(); final JpsRemoteProto.Message.Request request = isMake? - ProtoUtil.createMakeRequest(projectId, modules) : - ProtoUtil.createForceCompileRequest(projectId, modules, paths); + ProtoUtil.createMakeRequest(projectId, modules, artifacts) : + ProtoUtil.createForceCompileRequest(projectId, modules, artifacts, paths); return sendRequest(request, handler); } diff --git a/jps/jps-builders/src/org/jetbrains/jps/incremental/artifacts/ArtifactSourceFilesState.java b/jps/jps-builders/src/org/jetbrains/jps/incremental/artifacts/ArtifactSourceFilesState.java index 5adc718077ec..cd7e73175785 100644 --- a/jps/jps-builders/src/org/jetbrains/jps/incremental/artifacts/ArtifactSourceFilesState.java +++ b/jps/jps-builders/src/org/jetbrains/jps/incremental/artifacts/ArtifactSourceFilesState.java @@ -2,6 +2,7 @@ package org.jetbrains.jps.incremental.artifacts; import com.intellij.openapi.util.io.FileUtil; import com.intellij.util.ArrayUtil; +import org.jetbrains.annotations.NotNull; import org.jetbrains.jps.Project; import org.jetbrains.jps.ProjectPaths; import org.jetbrains.jps.artifacts.Artifact; @@ -37,13 +38,13 @@ public class ArtifactSourceFilesState { public ArtifactSourceFilesState(Artifact artifact, int artifactId, Project project, ModuleRootsIndex rootsIndex, ArtifactSourceTimestampStorage timestampStorage, - File artifactsDataDir) { + File mappingsDir) { myProject = project; myArtifact = artifact; myRootsIndex = rootsIndex; myTimestampStorage = timestampStorage; myArtifactId = artifactId; - myMappingsFile = new File(artifactsDataDir, "mappings" + File.separator + artifactId); + myMappingsFile = new File(mappingsDir, String.valueOf(artifactId)); } public ArtifactSourceToOutputMapping getOrCreateMapping() throws Exception { @@ -161,20 +162,29 @@ public class ArtifactSourceFilesState { } for (String filePath : changedFiles) { final ArtifactSourceTimestampStorage.PerArtifactTimestamp[] state = myTimestampStorage.getState(filePath); - if (state == null) continue; - for (int i = 0, length = state.length; i < length; i++) { - if (state[i].myArtifactId == myArtifactId) { - File file = new File(FileUtil.toSystemDependentName(filePath)); - state[i] = new ArtifactSourceTimestampStorage.PerArtifactTimestamp(myArtifactId, file.lastModified()); - myTimestampStorage.update(filePath, state); - break; - } - } + File file = new File(FileUtil.toSystemDependentName(filePath)); + final long timestamp = file.lastModified(); + myTimestampStorage.update(filePath, updateTimestamp(state, timestamp)); } myDeletedFiles.clear(); myChangedFiles.clear(); } + @NotNull + private ArtifactSourceTimestampStorage.PerArtifactTimestamp[] updateTimestamp(ArtifactSourceTimestampStorage.PerArtifactTimestamp[] oldState, long timestamp) { + final ArtifactSourceTimestampStorage.PerArtifactTimestamp newItem = new ArtifactSourceTimestampStorage.PerArtifactTimestamp(myArtifactId, timestamp); + if (oldState == null) { + return new ArtifactSourceTimestampStorage.PerArtifactTimestamp[]{newItem}; + } + for (int i = 0, length = oldState.length; i < length; i++) { + if (oldState[i].myArtifactId == myArtifactId) { + oldState[i] = newItem; + return oldState; + } + } + return ArrayUtil.append(oldState, newItem); + } + public void close() throws IOException { if (myMapping != null) { myMapping.close(); diff --git a/jps/jps-builders/src/org/jetbrains/jps/incremental/artifacts/ArtifactsBuildData.java b/jps/jps-builders/src/org/jetbrains/jps/incremental/artifacts/ArtifactsBuildData.java index 7722afe014be..00ac633bb22f 100644 --- a/jps/jps-builders/src/org/jetbrains/jps/incremental/artifacts/ArtifactsBuildData.java +++ b/jps/jps-builders/src/org/jetbrains/jps/incremental/artifacts/ArtifactsBuildData.java @@ -18,19 +18,21 @@ public class ArtifactsBuildData { private final ArtifactSourceTimestampStorage myTimestampStorage; private ArtifactCompilerPersistentData myPersistentData; private final File myArtifactsDataDir; + private final File myMappingsDir; public ArtifactsBuildData(File artifactsDataDir) throws Exception { myArtifactsDataDir = artifactsDataDir; myTimestampStorage = new ArtifactSourceTimestampStorage(new File(artifactsDataDir, "timestamps")); myArtifactState = new HashMap(); myPersistentData = new ArtifactCompilerPersistentData(artifactsDataDir); + myMappingsDir = new File(myArtifactsDataDir, "mappings"); } public ArtifactSourceFilesState getOrCreateState(Artifact artifact, Project project, ModuleRootsIndex index) { ArtifactSourceFilesState state = myArtifactState.get(artifact); if (state == null) { final int artifactId = myPersistentData.getId(artifact.getName()); - state = new ArtifactSourceFilesState(artifact, artifactId, project, index, myTimestampStorage, myArtifactsDataDir); + state = new ArtifactSourceFilesState(artifact, artifactId, project, index, myTimestampStorage, myMappingsDir); myArtifactState.put(artifact, state); } return state; @@ -42,7 +44,8 @@ public class ArtifactsBuildData { for (ArtifactSourceFilesState state : myArtifactState.values()) { state.clean(); } - FileUtil.delete(myArtifactsDataDir); + myArtifactState.clear(); + FileUtil.delete(myMappingsDir); } public void close() throws IOException { diff --git a/jps/jps-builders/src/org/jetbrains/jps/server/ServerMessageHandler.java b/jps/jps-builders/src/org/jetbrains/jps/server/ServerMessageHandler.java index cf00e51af4b0..d2aa631fc435 100644 --- a/jps/jps-builders/src/org/jetbrains/jps/server/ServerMessageHandler.java +++ b/jps/jps-builders/src/org/jetbrains/jps/server/ServerMessageHandler.java @@ -187,8 +187,8 @@ class ServerMessageHandler extends SimpleChannelHandler { case REBUILD: { channelContext.setAttachment(sessionId); final BuildType buildType = convertCompileType(compileType); - final CompilationTask task = new CompilationTask( - sessionId, channelContext, projectId, buildType, compileRequest.getModuleNameList(), Collections.emptySet(), compileRequest.getFilePathList()); + final CompilationTask task = new CompilationTask(sessionId, channelContext, projectId, buildType, compileRequest.getModuleNameList(), + compileRequest.getArtifactNameList(), compileRequest.getFilePathList()); final RunnableFuture future = getCompileTaskExecutor(projectId).submit(task); myBuildsInProgress.add(new Pair(future, task)); return null;