2 * Copyright 2000-2009 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package com
.intellij
.ide
.macro
;
18 import com
.intellij
.ide
.IdeBundle
;
19 import com
.intellij
.openapi
.actionSystem
.DataContext
;
20 import com
.intellij
.openapi
.actionSystem
.PlatformDataKeys
;
21 import com
.intellij
.openapi
.compiler
.ex
.CompilerPathsEx
;
22 import com
.intellij
.openapi
.module
.Module
;
23 import com
.intellij
.openapi
.module
.ModuleManager
;
24 import com
.intellij
.openapi
.project
.Project
;
25 import com
.intellij
.openapi
.roots
.CompilerModuleExtension
;
26 import com
.intellij
.openapi
.roots
.ProjectFileIndex
;
27 import com
.intellij
.openapi
.roots
.ProjectRootManager
;
28 import com
.intellij
.openapi
.vfs
.VirtualFile
;
29 import com
.intellij
.openapi
.vfs
.VirtualFileManager
;
33 public final class OutputPathMacro
extends Macro
{
34 public String
getName() {
38 public String
getDescription() {
39 return IdeBundle
.message("macro.output.path");
42 public String
expand(DataContext dataContext
) {
43 Project project
= PlatformDataKeys
.PROJECT
.getData(dataContext
);
44 if (project
== null) {
48 VirtualFile file
= PlatformDataKeys
.VIRTUAL_FILE
.getData(dataContext
);
50 ProjectFileIndex projectFileIndex
= ProjectRootManager
.getInstance(project
).getFileIndex();
51 Module module
= projectFileIndex
.getModuleForFile(file
);
53 boolean isTest
= projectFileIndex
.isInTestSourceContent(file
);
54 String outputPathUrl
= isTest ? CompilerModuleExtension
.getInstance(module
).getCompilerOutputUrlForTests()
55 : CompilerModuleExtension
.getInstance(module
).getCompilerOutputUrl();
56 if (outputPathUrl
== null) return null;
57 return VirtualFileManager
.extractPath(outputPathUrl
).replace('/', File
.separatorChar
);
61 Module
[] allModules
= ModuleManager
.getInstance(project
).getSortedModules();
62 if (allModules
.length
== 0) {
65 String
[] paths
= CompilerPathsEx
.getOutputPaths(allModules
);
66 final StringBuffer outputPath
= new StringBuffer();
67 for (int idx
= 0; idx
< paths
.length
; idx
++) {
68 String path
= paths
[idx
];
70 outputPath
.append(File
.pathSeparator
);
72 outputPath
.append(path
);
74 return outputPath
.toString();