From b59a3400b0a0e50a4bca203789341eebce3c671b Mon Sep 17 00:00:00 2001 From: nik Date: Thu, 20 Sep 2012 15:13:34 +0400 Subject: [PATCH] external compiler: fixed directory names for caches --- .../storage/BuildTargetsState.java | 3 +- .../src/com/intellij/util/PathUtil.java | 45 ++-------- .../src/com/intellij/util/PathUtilRt.java | 82 +++++++++++++++++++ 3 files changed, 89 insertions(+), 41 deletions(-) create mode 100644 platform/util-rt/src/com/intellij/util/PathUtilRt.java diff --git a/jps/jps-builders/src/org/jetbrains/jps/incremental/storage/BuildTargetsState.java b/jps/jps-builders/src/org/jetbrains/jps/incremental/storage/BuildTargetsState.java index 0b250ff41788..ab098b9cbab9 100644 --- a/jps/jps-builders/src/org/jetbrains/jps/incremental/storage/BuildTargetsState.java +++ b/jps/jps-builders/src/org/jetbrains/jps/incremental/storage/BuildTargetsState.java @@ -2,6 +2,7 @@ package org.jetbrains.jps.incremental.storage; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.util.io.FileUtil; +import com.intellij.util.PathUtilRt; import com.intellij.util.containers.ConcurrentHashMap; import org.jetbrains.annotations.NotNull; import org.jetbrains.jps.builders.BuildTarget; @@ -121,7 +122,7 @@ public class BuildTargetsState { } public File getTargetDataRoot(BuildTarget target) { - return new File(getTargetTypeDataRoot(target.getTargetType()), target.getId()); + return new File(getTargetTypeDataRoot(target.getTargetType()), PathUtilRt.suggestFileName(target.getId(), true, true)); } public void clean() { diff --git a/platform/core-api/src/com/intellij/util/PathUtil.java b/platform/core-api/src/com/intellij/util/PathUtil.java index 4073fd88ce2f..1c1973986d00 100644 --- a/platform/core-api/src/com/intellij/util/PathUtil.java +++ b/platform/core-api/src/com/intellij/util/PathUtil.java @@ -77,61 +77,26 @@ public class PathUtil { @NotNull public static String getFileName(@NotNull String path) { - if (path.length() == 0) { - return ""; - } - final char c = path.charAt(path.length() - 1); - int end = c == '/' || c == '\\' ? path.length() - 1 : path.length(); - int start = Math.max(path.lastIndexOf('/', end - 1), path.lastIndexOf('\\', end - 1)) + 1; - return path.substring(start, end); + return PathUtilRt.getFileName(path); } @NotNull public static String getParentPath(@NotNull String path) { - if (path.length() == 0) { - return ""; - } - int end = Math.max(path.lastIndexOf('/'), path.lastIndexOf('\\')); - if (end == path.length() - 1) { - end = Math.max(path.lastIndexOf('/', end - 1), path.lastIndexOf('\\', end - 1)); - } - return end == -1 ? "" : path.substring(0, end); + return PathUtilRt.getParentPath(path); } @NotNull public static String suggestFileName(@NotNull String text) { - return suggestFileName(text, false, false); + return PathUtilRt.suggestFileName(text); } @NotNull public static String suggestFileName(@NotNull String text, final boolean allowDots, final boolean allowSpaces) { - StringBuilder result = new StringBuilder(); - for (int i = 0; i < text.length(); i++) { - char c = text.charAt(i); - if (!isValidFileNameChar(c) || (!allowDots && c == '.') || (!allowSpaces && Character.isWhitespace(c))) { - result.append('_'); - } - else { - result.append(c); - } - } - return result.toString(); + return PathUtilRt.suggestFileName(text, allowDots, allowSpaces); } public static boolean isValidFileName(@NotNull String fileName) { - if (fileName.length() == 0) { - return false; - } - for (int i = 0; i < fileName.length(); i++) { - if (!isValidFileNameChar(fileName.charAt(i))) { - return false; - } - } - return true; + return PathUtilRt.isValidFileName(fileName); } - private static boolean isValidFileNameChar(char c) { - return c != '/' && c != '\\' && c != '\t' && c != '\n' && c != '\r' && c != ':' && c != ';' && c != '*' && c != '?' && - c != '"' && c != '\'' && c != '<' && c != '>'; - } } diff --git a/platform/util-rt/src/com/intellij/util/PathUtilRt.java b/platform/util-rt/src/com/intellij/util/PathUtilRt.java new file mode 100644 index 000000000000..75e038fe01ec --- /dev/null +++ b/platform/util-rt/src/com/intellij/util/PathUtilRt.java @@ -0,0 +1,82 @@ +/* + * 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 com.intellij.util; + +import org.jetbrains.annotations.NotNull; + +/** + * @author nik + */ +public class PathUtilRt { + @NotNull + public static String getFileName(@NotNull String path) { + if (path.length() == 0) { + return ""; + } + final char c = path.charAt(path.length() - 1); + int end = c == '/' || c == '\\' ? path.length() - 1 : path.length(); + int start = Math.max(path.lastIndexOf('/', end - 1), path.lastIndexOf('\\', end - 1)) + 1; + return path.substring(start, end); + } + + @NotNull + public static String getParentPath(@NotNull String path) { + if (path.length() == 0) { + return ""; + } + int end = Math.max(path.lastIndexOf('/'), path.lastIndexOf('\\')); + if (end == path.length() - 1) { + end = Math.max(path.lastIndexOf('/', end - 1), path.lastIndexOf('\\', end - 1)); + } + return end == -1 ? "" : path.substring(0, end); + } + + @NotNull + public static String suggestFileName(@NotNull String text) { + return suggestFileName(text, false, false); + } + + @NotNull + public static String suggestFileName(@NotNull String text, final boolean allowDots, final boolean allowSpaces) { + StringBuilder result = new StringBuilder(); + for (int i = 0; i < text.length(); i++) { + char c = text.charAt(i); + if (!isValidFileNameChar(c) || (!allowDots && c == '.') || (!allowSpaces && Character.isWhitespace(c))) { + result.append('_'); + } + else { + result.append(c); + } + } + return result.toString(); + } + + public static boolean isValidFileName(@NotNull String fileName) { + if (fileName.length() == 0) { + return false; + } + for (int i = 0; i < fileName.length(); i++) { + if (!isValidFileNameChar(fileName.charAt(i))) { + return false; + } + } + return true; + } + private static boolean isValidFileNameChar(char c) { + return c != '/' && c != '\\' && c != '\t' && c != '\n' && c != '\r' && c != ':' && c != ';' && c != '*' && c != '?' && + c != '"' && c != '\'' && c != '<' && c != '>'; + } +}