mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
native libraries (dll/so) supported in libraries (IDEA-28168)
This commit is contained in:
@@ -18,6 +18,7 @@ package com.intellij.execution.configurations;
|
||||
import com.intellij.execution.CantRunException;
|
||||
import com.intellij.execution.ExecutionBundle;
|
||||
import com.intellij.openapi.actionSystem.DataKey;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.projectRoots.Sdk;
|
||||
@@ -25,6 +26,7 @@ import com.intellij.openapi.roots.*;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.openapi.vfs.encoding.EncodingProjectManager;
|
||||
import com.intellij.util.NotNullFunction;
|
||||
import com.intellij.util.PathsList;
|
||||
import org.intellij.lang.annotations.MagicConstant;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -32,6 +34,8 @@ import org.jetbrains.annotations.Nullable;
|
||||
import java.nio.charset.Charset;
|
||||
|
||||
public class JavaParameters extends SimpleJavaParameters {
|
||||
private static final Logger LOG = Logger.getInstance(JavaParameters.class);
|
||||
private static final String JAVA_LIBRARY_PATH_PROPERTY = "java.library.path";
|
||||
public static final DataKey<JavaParameters> JAVA_PARAMETERS = DataKey.create("javaParameters");
|
||||
|
||||
public String getJdkPath() throws CantRunException {
|
||||
@@ -70,6 +74,21 @@ public class JavaParameters extends SimpleJavaParameters {
|
||||
|
||||
setDefaultCharset(module.getProject());
|
||||
configureEnumerator(OrderEnumerator.orderEntries(module).runtimeOnly().recursively(), classPathType, jdk).collectPaths(getClassPath());
|
||||
configureJavaLibraryPath(OrderEnumerator.orderEntries(module).recursively());
|
||||
}
|
||||
|
||||
private void configureJavaLibraryPath(OrderEnumerator enumerator) {
|
||||
PathsList pathsList = new PathsList();
|
||||
enumerator.runtimeOnly().withoutSdk().roots(NativeLibraryOrderRootType.getInstance()).collectPaths(pathsList);
|
||||
if (!pathsList.getPathList().isEmpty()) {
|
||||
ParametersList vmParameters = getVMParametersList();
|
||||
if (vmParameters.hasProperty(JAVA_LIBRARY_PATH_PROPERTY)) {
|
||||
LOG.info(JAVA_LIBRARY_PATH_PROPERTY + " property is already specified, native library paths from dependencies (" + pathsList.getPathsString() + ") won't be added");
|
||||
}
|
||||
else {
|
||||
vmParameters.addProperty(JAVA_LIBRARY_PATH_PROPERTY, pathsList.getPathsString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@@ -123,6 +142,7 @@ public class JavaParameters extends SimpleJavaParameters {
|
||||
}
|
||||
setDefaultCharset(project);
|
||||
configureEnumerator(OrderEnumerator.orderEntries(project).runtimeOnly(), classPathType, jdk).collectPaths(getClassPath());
|
||||
configureJavaLibraryPath(OrderEnumerator.orderEntries(project));
|
||||
}
|
||||
|
||||
private static OrderRootsEnumerator configureEnumerator(OrderEnumerator enumerator, @MagicConstant(valuesFromClass = JavaParameters.class) int classPathType, Sdk jdk) {
|
||||
|
||||
+34
-5
@@ -16,6 +16,7 @@
|
||||
package com.intellij.openapi.roots.ui.configuration.libraryEditor;
|
||||
|
||||
import com.intellij.codeInsight.ExternalAnnotationsManager;
|
||||
import com.intellij.openapi.fileChooser.FileChooserDescriptor;
|
||||
import com.intellij.openapi.fileTypes.StdFileTypes;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.progress.ProgressIndicator;
|
||||
@@ -23,22 +24,22 @@ import com.intellij.openapi.project.ProjectBundle;
|
||||
import com.intellij.openapi.projectRoots.ui.Util;
|
||||
import com.intellij.openapi.roots.AnnotationOrderRootType;
|
||||
import com.intellij.openapi.roots.JavadocOrderRootType;
|
||||
import com.intellij.openapi.roots.NativeLibraryOrderRootType;
|
||||
import com.intellij.openapi.roots.OrderRootType;
|
||||
import com.intellij.openapi.roots.libraries.ui.*;
|
||||
import com.intellij.openapi.roots.ui.OrderRootTypeUIFactory;
|
||||
import com.intellij.openapi.roots.ui.configuration.PathUIUtils;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.vfs.VfsUtilCore;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.openapi.vfs.VirtualFileVisitor;
|
||||
import com.intellij.util.IconUtil;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @author nik
|
||||
@@ -63,7 +64,15 @@ public class DefaultLibraryRootsComponentDescriptor extends LibraryRootsComponen
|
||||
PathUIUtils.JAVA_SOURCE_ROOT_DETECTOR,
|
||||
new FileTypeBasedRootFilter(OrderRootType.SOURCES, true, StdFileTypes.JAVA, "source archive directory"),
|
||||
new JavadocRootDetector(),
|
||||
new AnnotationsRootFilter());
|
||||
new AnnotationsRootFilter(), new NativeLibraryRootFilter());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public FileChooserDescriptor createAttachFilesChooserDescriptor(@Nullable String libraryName) {
|
||||
FileChooserDescriptor descriptor = super.createAttachFilesChooserDescriptor(libraryName);
|
||||
descriptor.setDescription(ProjectBundle.message("library.java.attach.files.description"));
|
||||
return descriptor;
|
||||
}
|
||||
|
||||
public static OrderRootTypePresentation getDefaultPresentation(OrderRootType type) {
|
||||
@@ -110,6 +119,26 @@ public class DefaultLibraryRootsComponentDescriptor extends LibraryRootsComponen
|
||||
}
|
||||
}
|
||||
|
||||
private static class NativeLibraryRootFilter extends RootFilter {
|
||||
private static final Set<String> NATIVE_LIBRARY_EXTENSIONS = ContainerUtil.newTroveSet(FileUtil.PATH_HASHING_STRATEGY, "dll", "so", "dylib");
|
||||
|
||||
private NativeLibraryRootFilter() {
|
||||
super(NativeLibraryOrderRootType.getInstance(), false, "external annotations");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAccepted(@NotNull VirtualFile rootCandidate, @NotNull ProgressIndicator progressIndicator) {
|
||||
if (rootCandidate.isDirectory()) {
|
||||
for (VirtualFile file : rootCandidate.getChildren()) {
|
||||
if (NATIVE_LIBRARY_EXTENSIONS.contains(file.getExtension())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static class AttachUrlJavadocDescriptor extends AttachRootButtonDescriptor {
|
||||
private AttachUrlJavadocDescriptor() {
|
||||
super(JavadocOrderRootType.getInstance(), IconUtil.getAddLinkIcon(), ProjectBundle.message("module.libraries.javadoc.url.button"));
|
||||
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright 2000-2014 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* User: anna
|
||||
* Date: 26-Dec-2007
|
||||
*/
|
||||
package com.intellij.openapi.roots.ui.configuration.libraryEditor;
|
||||
|
||||
import com.intellij.icons.AllIcons;
|
||||
import com.intellij.openapi.project.ProjectBundle;
|
||||
import com.intellij.openapi.projectRoots.Sdk;
|
||||
import com.intellij.openapi.projectRoots.ui.SdkPathEditor;
|
||||
import com.intellij.openapi.roots.ui.OrderRootTypeUIFactory;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
public class NativeLibraryOrderRootTypeUIFactory implements OrderRootTypeUIFactory {
|
||||
|
||||
@Override
|
||||
public Icon getIcon() {
|
||||
return AllIcons.Modules.Library;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getNodeText() {
|
||||
return ProjectBundle.message("project.roots.native.library.node.text");
|
||||
}
|
||||
|
||||
@Override
|
||||
public SdkPathEditor createPathEditor(Sdk sdk) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright 2000-2014 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.roots;
|
||||
|
||||
/**
|
||||
* @author nik
|
||||
*/
|
||||
public class NativeLibraryOrderRootType extends PersistentOrderRootType {
|
||||
public static OrderRootType getInstance() {
|
||||
return getOrderRootType(NativeLibraryOrderRootType.class);
|
||||
}
|
||||
|
||||
public NativeLibraryOrderRootType() {
|
||||
super("NATIVE", "native", null, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean skipWriteIfEmpty() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* Copyright 2000-2014 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 org.jetbrains.jps.model.java;
|
||||
|
||||
import org.jetbrains.jps.model.library.JpsOrderRootType;
|
||||
|
||||
/**
|
||||
* @author nik
|
||||
*/
|
||||
public class JpsNativeLibraryRootType extends JpsOrderRootType {
|
||||
public static final JpsNativeLibraryRootType INSTANCE = new JpsNativeLibraryRootType();
|
||||
|
||||
private JpsNativeLibraryRootType() {
|
||||
}
|
||||
}
|
||||
+2
-1
@@ -126,7 +126,8 @@ public class JpsJavaModelSerializerExtension extends JpsModelSerializerExtension
|
||||
@Override
|
||||
public List<JpsLibraryRootTypeSerializer> getLibraryRootTypeSerializers() {
|
||||
return Arrays.asList(new JpsLibraryRootTypeSerializer("JAVADOC", JpsOrderRootType.DOCUMENTATION, true),
|
||||
new JpsLibraryRootTypeSerializer("ANNOTATIONS", JpsAnnotationRootType.INSTANCE, false));
|
||||
new JpsLibraryRootTypeSerializer("ANNOTATIONS", JpsAnnotationRootType.INSTANCE, false),
|
||||
new JpsLibraryRootTypeSerializer("NATIVE", JpsNativeLibraryRootType.INSTANCE, false));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -23,6 +23,7 @@ import com.intellij.openapi.projectRoots.ui.SdkPathEditor;
|
||||
import com.intellij.openapi.roots.OrderRootType;
|
||||
import com.intellij.openapi.util.KeyedExtensionFactory;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
@@ -41,6 +42,7 @@ public interface OrderRootTypeUIFactory {
|
||||
}
|
||||
};
|
||||
|
||||
@Nullable
|
||||
SdkPathEditor createPathEditor(Sdk sdk);
|
||||
|
||||
Icon getIcon();
|
||||
|
||||
@@ -128,6 +128,7 @@ button.text.attach.files=Attach &Files or Directories...
|
||||
library.attach.files.action=Attach Files or Directories
|
||||
library.attach.files.to.library.action=Attach Files or Directories to Library ''{0}''
|
||||
library.attach.files.description=Select files or directories in which library classes, sources and documentation are located
|
||||
library.java.attach.files.description=Select files or directories in which library classes, sources, documentation or native libraries are located
|
||||
|
||||
library.sources.not.found=Sources not found
|
||||
library.sources.not.attached=Sources not attached
|
||||
@@ -318,6 +319,7 @@ external.annotations.root.chooser.description=External annotations would be save
|
||||
external.annotation.prompt=External annotation prompt
|
||||
external.annotations.suggestion.message=<html><body>If you do not want annotations in your code you may use external storage.<br> \
|
||||
To configure external annotations please specify root directory where files with annotations would be placed</body></html>
|
||||
project.roots.native.library.node.text=Native Library Locations
|
||||
sdk.configure.annotations.tab=Annotations
|
||||
project.roots.path.tab.title=Paths
|
||||
project.roots.external.annotations.tab.title=External Annotations
|
||||
|
||||
@@ -312,6 +312,8 @@
|
||||
implementationClass="com.intellij.openapi.roots.ui.configuration.libraryEditor.JavadocOrderRootTypeUIFactory"/>
|
||||
<OrderRootTypeUI key="ANNOTATIONS"
|
||||
implementationClass="com.intellij.openapi.roots.ui.configuration.libraryEditor.AnnotationsOrderRootTypeUIFactory"/>
|
||||
<OrderRootTypeUI key="NATIVE"
|
||||
implementationClass="com.intellij.openapi.roots.ui.configuration.libraryEditor.NativeLibraryOrderRootTypeUIFactory"/>
|
||||
<OrderRootTypeUI key="CLASSES"
|
||||
implementationClass="com.intellij.openapi.roots.ui.configuration.libraryEditor.ClassesOrderRootTypeUIFactory"/>
|
||||
<OrderRootTypeUI key="SOURCES"
|
||||
@@ -332,6 +334,7 @@
|
||||
<moduleExtension implementation="com.intellij.openapi.roots.impl.JavaModuleExternalPathsImpl"/>
|
||||
|
||||
<orderRootType implementation="com.intellij.openapi.roots.AnnotationOrderRootType"/>
|
||||
<orderRootType implementation="com.intellij.openapi.roots.NativeLibraryOrderRootType"/>
|
||||
<orderRootType implementation="com.intellij.openapi.roots.JavadocOrderRootType"/>
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user