old packaging compiler removed
[fedora-idea.git] / java / compiler / openapi / src / com / intellij / openapi / deployment / DeploymentUtil.java
blob7525b2f08fb0dd29e6755e53f82d803addead636
1 /*
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.openapi.deployment;
18 import com.intellij.openapi.compiler.CompileContext;
19 import com.intellij.openapi.compiler.make.BuildRecipe;
20 import com.intellij.openapi.components.ServiceManager;
21 import com.intellij.openapi.module.Module;
22 import com.intellij.openapi.util.text.StringUtil;
23 import com.intellij.util.StringBuilderSpinAllocator;
24 import com.intellij.util.descriptors.ConfigFile;
25 import org.jetbrains.annotations.NotNull;
26 import org.jetbrains.annotations.Nullable;
28 import java.io.File;
29 import java.io.FileFilter;
30 import java.io.IOException;
31 import java.util.Set;
33 public abstract class DeploymentUtil {
34 public static DeploymentUtil getInstance() {
35 return ServiceManager.getService(DeploymentUtil.class);
38 public abstract void copyFile(@NotNull File fromFile,
39 @NotNull File toFile,
40 @NotNull CompileContext context,
41 @Nullable Set<String> writtenPaths,
42 @Nullable FileFilter fileFilter) throws IOException;
44 public abstract boolean addItemsRecursively(@NotNull BuildRecipe items,
45 @NotNull File root,
46 Module module,
47 String outputRelativePath, @Nullable String possibleBaseOutputPath);
49 public static String trimForwardSlashes(@NotNull String path) {
50 while (path.length() != 0 && (path.charAt(0) == '/' || path.charAt(0) == File.separatorChar)) {
51 path = path.substring(1);
53 return path;
56 public abstract void reportDeploymentDescriptorDoesNotExists(ConfigFile descriptor, CompileContext context, Module module);
58 public static String concatPaths(String... paths) {
59 final StringBuilder builder = new StringBuilder();
60 for (String path : paths) {
61 if (path.length() == 0) continue;
63 final int len = builder.length();
64 if (len > 0 && builder.charAt(len - 1) != '/' && builder.charAt(len - 1) != File.separatorChar) {
65 builder.append('/');
67 builder.append(len != 0 ? trimForwardSlashes(path) : path);
69 return builder.toString();
72 public static String appendToPath(@NotNull String path, @NotNull String name) {
73 if (!StringUtil.endsWithChar(path, '/') && !path.endsWith(File.separator)) {
74 path += "/";
76 return path + trimForwardSlashes(name);
79 public abstract BuildRecipe createBuildRecipe();
81 @Nullable
82 public abstract String getConfigFileErrorMessage(ConfigFile configFile);
84 @Nullable
85 public static String getRelativePath(File baseDir, File file) {
86 if (baseDir == null || file == null) return null;
88 String basePath = baseDir.getAbsolutePath();
89 final String filePath = file.getAbsolutePath();
90 return getRelativePath(basePath, filePath);
93 @Nullable public static String getRelativePath(@NotNull String basePath, @NotNull final String filePath) {
94 if (basePath.equals(filePath)) return "";
95 if (!basePath.endsWith(File.separator)) basePath += File.separatorChar;
97 int len = 0;
98 int lastSeparatorIndex = 0; // need this for cases like this: base="/temp/abcde/baseDir" and file="/temp/ab"
99 while (len < filePath.length() && len < basePath.length() && filePath.charAt(len) == basePath.charAt(len)) {
100 if (basePath.charAt(len) == File.separatorChar) {
101 lastSeparatorIndex = len;
103 len++;
106 if (len == 0) {
107 return null;
109 final StringBuilder relativePath = StringBuilderSpinAllocator.alloc();
110 try {
111 for (int i=len; i < basePath.length(); i++) {
112 if (basePath.charAt(i) == File.separatorChar) {
113 relativePath.append("..");
114 relativePath.append(File.separatorChar);
117 relativePath.append(filePath.substring(lastSeparatorIndex + 1));
119 return relativePath.toString();
121 finally {
122 StringBuilderSpinAllocator.dispose(relativePath);
126 public abstract void checkConfigFile(final ConfigFile descriptor, final CompileContext compileContext, final Module module);