mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Phing initial commit
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
* Copyright 2000-2011 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.
|
||||
@@ -103,10 +103,13 @@ public abstract class ActionPlaces {
|
||||
public static final String TFS_TREE_POPUP = "TfsTreePopup";
|
||||
public static final String ACTION_PLACE_VCS_QUICK_LIST_POPUP_ACTION = "ActionPlace.VcsQuickListPopupAction";
|
||||
|
||||
public static final String PHING_EXPLORER_POPUP = "PhingExplorerPopup";
|
||||
public static final String PHING_EXPLORER_TOOLBAR = "PhingExplorerToolbar";
|
||||
|
||||
private static final String[] ourToolbarPlaces = new String[]{EDITOR_TOOLBAR, PROJECT_VIEW_TOOLBAR, TESTTREE_VIEW_TOOLBAR, MAIN_TOOLBAR,
|
||||
ANT_EXPLORER_TOOLBAR, ANT_MESSAGES_TOOLBAR, COMPILER_MESSAGES_TOOLBAR, TODO_VIEW_TOOLBAR, STRUCTURE_VIEW_TOOLBAR, USAGE_VIEW_TOOLBAR,
|
||||
DEBUGGER_TOOLBAR, CALL_HIERARCHY_VIEW_TOOLBAR, METHOD_HIERARCHY_VIEW_TOOLBAR, TYPE_HIERARCHY_VIEW_TOOLBAR, JAVADOC_TOOLBAR,
|
||||
FILE_HISTORY_TOOLBAR, FILEHISTORY_VIEW_TOOLBAR, LVCS_DIRECTORY_HISTORY_TOOLBAR, CHANGES_VIEW_TOOLBAR, };
|
||||
FILE_HISTORY_TOOLBAR, FILEHISTORY_VIEW_TOOLBAR, LVCS_DIRECTORY_HISTORY_TOOLBAR, CHANGES_VIEW_TOOLBAR, PHING_EXPLORER_TOOLBAR };
|
||||
|
||||
public static boolean isToolbarPlace(@NotNull String place) {
|
||||
return ArrayUtil.find(ourToolbarPlaces, place) != -1;
|
||||
@@ -118,7 +121,7 @@ public abstract class ActionPlaces {
|
||||
STRUCTURE_VIEW_POPUP, TODO_VIEW_POPUP, COMPILER_MESSAGES_POPUP, ANT_MESSAGES_POPUP, ANT_EXPLORER_POPUP, UPDATE_POPUP,
|
||||
FILEVIEW_POPUP, CHECKOUT_POPUP, LVCS_DIRECTORY_HISTORY_POPUP, GUI_DESIGNER_EDITOR_POPUP, GUI_DESIGNER_COMPONENT_TREE_POPUP, GUI_DESIGNER_PROPERTY_INSPECTOR_POPUP,
|
||||
CREATE_EJB_POPUP, CHANGES_VIEW_POPUP, REMOTE_HOST_VIEW_POPUP, REMOTE_HOST_DIALOG_POPUP, TFS_TREE_POPUP,
|
||||
ACTION_PLACE_VCS_QUICK_LIST_POPUP_ACTION
|
||||
ACTION_PLACE_VCS_QUICK_LIST_POPUP_ACTION , PHING_EXPLORER_POPUP
|
||||
};
|
||||
|
||||
public static boolean isPopupPlace(@NotNull String place) {
|
||||
|
||||
@@ -0,0 +1,107 @@
|
||||
/*
|
||||
* Copyright 2000-2011 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.buildfiles;
|
||||
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.util.Key;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.openapi.vfs.newvfs.FileAttribute;
|
||||
import com.intellij.openapi.vfs.newvfs.NewVirtualFile;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Created by IntelliJ IDEA.
|
||||
* User: lene
|
||||
* Date: 04.04.11
|
||||
* Time: 17:40
|
||||
*/
|
||||
public class ForcedBuildFileAttribute {
|
||||
private static final Logger LOG = Logger.getInstance("#" + ForcedBuildFileAttribute.class.getName());
|
||||
|
||||
private static final FileAttribute FRAMEWORK_FILE_ATTRIBUTE = new FileAttribute("forcedBuildFileFrameworkAttribute", 1, false);
|
||||
private static final Key<String> FRAMEWORK_FILE_MARKER = Key.create("forcedBuildFileFrameworkAttribute");
|
||||
|
||||
|
||||
private ForcedBuildFileAttribute() {
|
||||
}
|
||||
|
||||
public static boolean belongsToFramework(VirtualFile file, @NotNull String frameworkId) {
|
||||
return frameworkId.equals(getFrameworkIdOfBuildFile(file));
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static String getFrameworkIdOfBuildFile(VirtualFile file) {
|
||||
if (file instanceof NewVirtualFile) {
|
||||
final DataInputStream is = FRAMEWORK_FILE_ATTRIBUTE.readAttribute(file);
|
||||
if (is != null) {
|
||||
try {
|
||||
try {
|
||||
/*
|
||||
//todo[lene] IOUtil throws java.io.EOFException
|
||||
at java.io.DataInputStream.readFully(DataInputStream.java:180)
|
||||
at java.io.DataInputStream.readFully(DataInputStream.java:152)
|
||||
at com.intellij.util.io.IOUtil.readString(IOUtil.java:40)
|
||||
at com.intellij.buildfiles.ForcedBuildFileAttribute.getFrameworkIdOfBuildFile(ForcedBuildFileAttribute.java:59)
|
||||
*/
|
||||
return is.readUTF();
|
||||
}
|
||||
finally {
|
||||
is.close();
|
||||
}
|
||||
}
|
||||
catch (IOException e) {
|
||||
LOG.error(e);
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
return file.getUserData(FRAMEWORK_FILE_MARKER);
|
||||
}
|
||||
|
||||
|
||||
public static void forceFileToFramework(VirtualFile file, String frameworkId, boolean value) {
|
||||
if (!value && !frameworkId.equals(getFrameworkIdOfBuildFile(file))) {//belongs to other framework
|
||||
return;
|
||||
}
|
||||
forceBuildFile(file, frameworkId);
|
||||
}
|
||||
|
||||
|
||||
private static void forceBuildFile(VirtualFile file, String value) {
|
||||
if (file instanceof NewVirtualFile) {
|
||||
final DataOutputStream os = FRAMEWORK_FILE_ATTRIBUTE.writeAttribute(file);
|
||||
try {
|
||||
try {
|
||||
os.writeUTF(value);
|
||||
}
|
||||
finally {
|
||||
os.close();
|
||||
}
|
||||
}
|
||||
catch (IOException e) {
|
||||
LOG.error(e);
|
||||
}
|
||||
}
|
||||
else {
|
||||
file.putUserData(FRAMEWORK_FILE_MARKER, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
* Copyright 2000-2011 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.
|
||||
@@ -120,7 +120,7 @@ public class FileUtil {
|
||||
* @param strict if {@code false} then this method returns {@code true} if {@code ancestor}
|
||||
* and {@code file} are equal
|
||||
* @return {@code true} if {@code ancestor} is parent of {@code file}; {@code false} otherwise
|
||||
* @throws IOException this exception is never thrown and left here for backward compatibilty
|
||||
* @throws IOException this exception is never thrown and left here for backward compatibilty
|
||||
*/
|
||||
public static boolean isAncestor(@NotNull File ancestor, @NotNull File file, boolean strict) throws IOException {
|
||||
File parent = strict ? getParentFile(file) : file;
|
||||
@@ -902,7 +902,7 @@ public class FileUtil {
|
||||
|
||||
/**
|
||||
* Has duplicate: {@link com.intellij.coverage.listeners.CoverageListener#sanitize(java.lang.String, java.lang.String)}
|
||||
* as FileUtil is not available in client's vm
|
||||
* as FileUtil is not available in client's vm
|
||||
*/
|
||||
@NotNull
|
||||
public static String sanitizeFileName(@NotNull String name) {
|
||||
@@ -1016,4 +1016,51 @@ public class FileUtil {
|
||||
}
|
||||
return found;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns empty string for empty path.
|
||||
* First checks whether provided path is a path of a file with sought-for name.
|
||||
* Unless found, checks if provided file was a directory. In this case checks existance
|
||||
* of child files with given names in order "as provided". Finally checks filename among
|
||||
* brother-files of provided. Returns null if nothing found.
|
||||
*
|
||||
* @return path of the first of found files or empty string or null.
|
||||
*/
|
||||
@Nullable
|
||||
public static String findFileInProvidedPath(String providedPath, String... fileNames) {
|
||||
if (StringUtil.isEmpty(providedPath)) {
|
||||
return "";
|
||||
}
|
||||
|
||||
File providedFile = new File(providedPath);
|
||||
if (providedFile.exists()) {
|
||||
String name = providedFile.getName();
|
||||
for (String fileName : fileNames) {
|
||||
if (name.equals(fileName)) {
|
||||
return toSystemDependentName(providedFile.getPath());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (providedFile.isDirectory()) { //user chose folder with file
|
||||
for (String fileName : fileNames) {
|
||||
File file = new File(providedFile, fileName);
|
||||
if (fileName.equals(file.getName()) && file.exists()) {
|
||||
return toSystemDependentName(file.getPath());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
providedFile = providedFile.getParentFile(); //users chose wrong file in same directory
|
||||
if (providedFile != null && providedFile.exists()) {
|
||||
for (String fileName : fileNames) {
|
||||
File file = new File(providedFile, fileName);
|
||||
if (fileName.equals(file.getName()) && file.exists()) {
|
||||
return toSystemDependentName(file.getPath());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,89 @@
|
||||
/*
|
||||
* Copyright 2000-2011 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.openapi.util.io;
|
||||
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Created by IntelliJ IDEA.
|
||||
* User: lene
|
||||
* Date: 29.03.11
|
||||
* Time: 17:16
|
||||
*/
|
||||
public class FileUtilFindFileTest extends TestCase {
|
||||
private final File myTempFile;
|
||||
private final File myFirstFile;
|
||||
private final File mySecondFile;
|
||||
|
||||
@SuppressWarnings({"JUnitTestCaseWithNonTrivialConstructors"})
|
||||
public FileUtilFindFileTest() throws IOException {
|
||||
myTempFile = FileUtil.createTempDirectory("tEF", ""); //NON-NLS
|
||||
myFirstFile = new File(myTempFile, "first");
|
||||
mySecondFile = new File(myTempFile, "second"); //NON-NLS
|
||||
assertTrue(myFirstFile.createNewFile());
|
||||
assertTrue(mySecondFile.createNewFile());
|
||||
}
|
||||
|
||||
public void testNonExistingFileInNonExistentDirectory() throws Exception {
|
||||
String path = FileUtil.findFileInProvidedPath("123", "zero");//NON-NLS
|
||||
assertTrue(StringUtil.isEmpty(path));
|
||||
}
|
||||
|
||||
public void testNonExistingFileInDirectory() throws Exception {
|
||||
String path = FileUtil.findFileInProvidedPath(myTempFile.getAbsolutePath(), "zero");//NON-NLS
|
||||
assertTrue(StringUtil.isEmpty(path));
|
||||
}
|
||||
|
||||
public void testNonExistingFile() throws Exception {
|
||||
String path =
|
||||
FileUtil.findFileInProvidedPath(myFirstFile.getAbsolutePath() + "123", myFirstFile.getName() + "123");
|
||||
assertTrue(StringUtil.isEmpty(path));
|
||||
}
|
||||
|
||||
public void testExistingFileInDirectory() throws Exception {
|
||||
String path = FileUtil.findFileInProvidedPath(myTempFile.getAbsolutePath(), "first");
|
||||
assertEquals(path, myFirstFile.getAbsolutePath());
|
||||
}
|
||||
|
||||
public void testExistingFile() throws Exception {
|
||||
String path = FileUtil.findFileInProvidedPath(myFirstFile.getAbsolutePath(), "first");
|
||||
assertEquals(path, myFirstFile.getAbsolutePath());
|
||||
}
|
||||
|
||||
public void testTwoFilesOrderInDirectory() throws Exception {
|
||||
String path = FileUtil.findFileInProvidedPath(myTempFile.getAbsolutePath(), "first", "second"); //NON-NLS
|
||||
assertEquals(path, myFirstFile.getAbsolutePath());
|
||||
}
|
||||
|
||||
public void testTwoFilesOrderInDirectory2() throws Exception {
|
||||
String path = FileUtil.findFileInProvidedPath(myTempFile.getAbsolutePath(), "second", "first"); //NON-NLS
|
||||
assertEquals(path, mySecondFile.getAbsolutePath());
|
||||
}
|
||||
|
||||
public void testTwoFilesOrder() throws Exception {
|
||||
String path = FileUtil.findFileInProvidedPath(myFirstFile.getAbsolutePath(), "first", "second");//NON-NLS
|
||||
assertEquals(path, myFirstFile.getAbsolutePath());
|
||||
}
|
||||
|
||||
public void testTwoFilesOrder2() throws Exception {
|
||||
String path = FileUtil.findFileInProvidedPath(myFirstFile.getAbsolutePath(), "second", "first"); //NON-NLS
|
||||
assertEquals(path, myFirstFile.getAbsolutePath());
|
||||
}
|
||||
}
|
||||
+3
-2
@@ -9,8 +9,8 @@
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="module" module-name="openapi" />
|
||||
<orderEntry type="module" module-name="testFramework-java" scope="TEST" />
|
||||
<orderEntry type="library" scope="TEST" name="JUnit4" level="project" />
|
||||
<orderEntry type="module" module-name="testFramework-java" />
|
||||
<orderEntry type="library" name="JUnit4" level="project" />
|
||||
<orderEntry type="library" exported="" name="Ant" level="project" />
|
||||
<orderEntry type="module" module-name="compiler-impl" />
|
||||
<orderEntry type="module" module-name="java-runtime" />
|
||||
@@ -23,6 +23,7 @@
|
||||
<orderEntry type="module" module-name="xml-openapi" />
|
||||
<orderEntry type="module" module-name="util" />
|
||||
<orderEntry type="module" module-name="lang-impl" />
|
||||
<orderEntry type="module" module-name="platform-impl" />
|
||||
</component>
|
||||
<component name="copyright">
|
||||
<Base>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
* Copyright 2000-2011 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.
|
||||
@@ -15,14 +15,15 @@
|
||||
*/
|
||||
package com.intellij.lang.ant;
|
||||
|
||||
import com.intellij.buildfiles.ForcedBuildFileAttribute;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.util.Key;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.openapi.vfs.newvfs.FileAttribute;
|
||||
import com.intellij.openapi.vfs.newvfs.NewVirtualFile;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
@@ -31,15 +32,27 @@ import java.io.IOException;
|
||||
*/
|
||||
public class ForcedAntFileAttribute extends FileAttribute {
|
||||
private static final Logger LOG = Logger.getInstance("#com.intellij.lang.ant.ForcedAntFileAttribute");
|
||||
|
||||
|
||||
private static final String ANT_ID = "ant";
|
||||
|
||||
private static final ForcedAntFileAttribute ourAttribute = new ForcedAntFileAttribute();
|
||||
private static final Key<Boolean> ourAntFileMarker = Key.create("_forced_ant_attribute_");
|
||||
|
||||
|
||||
public ForcedAntFileAttribute() {
|
||||
super("_forced_ant_attribute_", 1, true);
|
||||
}
|
||||
|
||||
|
||||
public static boolean isAntFile(VirtualFile file) {
|
||||
String id = ForcedBuildFileAttribute.getFrameworkIdOfBuildFile(file);
|
||||
return ANT_ID.equals(id) || (StringUtil.isEmpty(id) && isAntFileOld(file));
|
||||
}
|
||||
|
||||
public static boolean mayBeAntFile(VirtualFile file) {
|
||||
String id = ForcedBuildFileAttribute.getFrameworkIdOfBuildFile(file);
|
||||
return StringUtil.isEmpty(id) || ANT_ID.equals(id);
|
||||
}
|
||||
|
||||
private static boolean isAntFileOld(VirtualFile file) {
|
||||
if (file instanceof NewVirtualFile) {
|
||||
final DataInputStream is = ourAttribute.readAttribute(file);
|
||||
if (is != null) {
|
||||
@@ -59,24 +72,8 @@ public class ForcedAntFileAttribute extends FileAttribute {
|
||||
}
|
||||
return Boolean.TRUE.equals(file.getUserData(ourAntFileMarker));
|
||||
}
|
||||
|
||||
|
||||
public static void forceAntFile(VirtualFile file, boolean value) {
|
||||
if (file instanceof NewVirtualFile) {
|
||||
final DataOutputStream os = ourAttribute.writeAttribute(file);
|
||||
try {
|
||||
try {
|
||||
os.writeBoolean(value);
|
||||
}
|
||||
finally {
|
||||
os.close();
|
||||
}
|
||||
}
|
||||
catch (IOException e) {
|
||||
LOG.error(e);
|
||||
}
|
||||
}
|
||||
else {
|
||||
file.putUserData(ourAntFileMarker, Boolean.valueOf(value));
|
||||
}
|
||||
ForcedBuildFileAttribute.forceFileToFramework(file, ANT_ID, value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2010 JetBrains s.r.o.
|
||||
* Copyright 2000-2011 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.
|
||||
@@ -43,12 +43,13 @@ public class AntDomFileDescription extends AntFileDescription<AntDomProject> {
|
||||
final XmlDocument document = xmlFile.getDocument();
|
||||
if (document != null) {
|
||||
final XmlTag tag = document.getRootTag();
|
||||
final VirtualFile vFile = xmlFile.getOriginalFile().getVirtualFile();
|
||||
if (tag != null && ROOT_TAG_NAME.equals(tag.getName()) && tag.getContext() instanceof XmlDocument) {
|
||||
if (tag.getAttributeValue("name") != null && tag.getAttributeValue("default") != null) {
|
||||
if (tag.getAttributeValue("name") != null && tag.getAttributeValue("default") != null
|
||||
&& vFile != null && ForcedAntFileAttribute.mayBeAntFile(vFile)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
final VirtualFile vFile = xmlFile.getOriginalFile().getVirtualFile();
|
||||
if (vFile != null && ForcedAntFileAttribute.isAntFile(vFile)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user