mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[platform] source providers reorganization
- Ivy source provider along with a base class moved to the platform - the base class reused to reduce duplication - NPE fixed (EA-80328)
This commit is contained in:
@@ -14,5 +14,6 @@
|
||||
<orderEntry type="library" name="OroMatcher" level="project" />
|
||||
<orderEntry type="module" module-name="vcs-impl" />
|
||||
<orderEntry type="library" name="Guava" level="project" />
|
||||
<orderEntry type="module" module-name="properties-psi-api" />
|
||||
</component>
|
||||
</module>
|
||||
+33
-19
@@ -1,4 +1,19 @@
|
||||
package org.jetbrains.plugins.groovy.ivy;
|
||||
/*
|
||||
* Copyright 2000-2016 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.jarFinder;
|
||||
|
||||
import com.intellij.codeInsight.AttachSourcesProvider;
|
||||
import com.intellij.notification.Notification;
|
||||
@@ -16,6 +31,7 @@ import com.intellij.openapi.roots.libraries.Library;
|
||||
import com.intellij.openapi.util.ActionCallback;
|
||||
import com.intellij.openapi.vfs.JarFileSystem;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.openapi.vfs.VirtualFileSystem;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.util.io.HttpRequests;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -29,19 +45,21 @@ import java.util.List;
|
||||
* @author Sergey Evdokimov
|
||||
*/
|
||||
public abstract class AbstractAttachSourceProvider implements AttachSourcesProvider {
|
||||
|
||||
private static final Logger LOG = Logger.getInstance("#org.jetbrains.plugins.groovy.ivy.AbstractAttachSourceProvider");
|
||||
private static final Logger LOG = Logger.getInstance(AbstractAttachSourceProvider.class);
|
||||
|
||||
@Nullable
|
||||
protected static VirtualFile getJarByPsiFile(PsiFile psiFile) {
|
||||
VirtualFile virtualFile = psiFile.getVirtualFile();
|
||||
if (virtualFile == null) return null;
|
||||
protected static VirtualFile getJarByPsiFile(@Nullable PsiFile psiFile) {
|
||||
if (psiFile != null) {
|
||||
VirtualFile entry = psiFile.getVirtualFile();
|
||||
if (entry != null) {
|
||||
VirtualFileSystem fs = entry.getFileSystem();
|
||||
if (fs instanceof JarFileSystem) {
|
||||
return ((JarFileSystem)fs).getLocalVirtualFileFor(entry);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
VirtualFile jar = JarFileSystem.getInstance().getVirtualFileForJar(psiFile.getVirtualFile());
|
||||
|
||||
if (jar == null || !jar.getName().endsWith(".jar")) return null;
|
||||
|
||||
return jar;
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@@ -114,7 +132,7 @@ public abstract class AbstractAttachSourceProvider implements AttachSourcesProvi
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract class DownloadSourcesAction implements AttachSourcesAction {
|
||||
protected abstract static class DownloadSourcesAction implements AttachSourcesAction {
|
||||
protected final Project myProject;
|
||||
protected final String myUrl;
|
||||
protected final String myMessageGroupId;
|
||||
@@ -154,12 +172,8 @@ public abstract class AbstractAttachSourceProvider implements AttachSourcesProvi
|
||||
ApplicationManager.getApplication().invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
new Notification(myMessageGroupId,
|
||||
"Downloading failed",
|
||||
"Failed to download sources: " + myUrl,
|
||||
NotificationType.ERROR)
|
||||
.notify(getProject());
|
||||
|
||||
String message = "Failed to download sources: " + myUrl;
|
||||
new Notification(myMessageGroupId, "Downloading failed", message, NotificationType.ERROR).notify(getProject());
|
||||
callback.setDone();
|
||||
}
|
||||
});
|
||||
@@ -192,4 +206,4 @@ public abstract class AbstractAttachSourceProvider implements AttachSourcesProvi
|
||||
return callback;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2015 JetBrains s.r.o.
|
||||
* Copyright 2000-2016 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,7 +15,6 @@
|
||||
*/
|
||||
package com.intellij.jarFinder;
|
||||
|
||||
import com.intellij.codeInsight.AttachSourcesProvider;
|
||||
import com.intellij.notification.Notification;
|
||||
import com.intellij.notification.NotificationType;
|
||||
import com.intellij.openapi.application.AccessToken;
|
||||
@@ -29,10 +28,7 @@ import com.intellij.openapi.roots.libraries.Library;
|
||||
import com.intellij.openapi.roots.ui.configuration.LibrarySourceRootDetectorUtil;
|
||||
import com.intellij.openapi.util.ActionCallback;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.vfs.JarFileSystem;
|
||||
import com.intellij.openapi.vfs.LocalFileSystem;
|
||||
import com.intellij.openapi.vfs.VfsUtilCore;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.openapi.vfs.*;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.util.SystemProperties;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
@@ -48,25 +44,13 @@ import java.util.regex.Pattern;
|
||||
/**
|
||||
* @author Sergey Evdokimov
|
||||
*/
|
||||
public class InternetAttachSourceProvider implements AttachSourcesProvider {
|
||||
public class InternetAttachSourceProvider extends AbstractAttachSourceProvider {
|
||||
private static final Logger LOG = Logger.getInstance(InternetAttachSourceProvider.class);
|
||||
private static final Pattern ARTIFACT_IDENTIFIER = Pattern.compile("[A-Za-z0-9\\.\\-_]+");
|
||||
|
||||
@Nullable
|
||||
protected static VirtualFile getJarByPsiFile(PsiFile psiFile) {
|
||||
VirtualFile virtualFile = psiFile.getVirtualFile();
|
||||
if (virtualFile == null) return null;
|
||||
|
||||
VirtualFile jar = JarFileSystem.getInstance().getVirtualFileForJar(psiFile.getVirtualFile());
|
||||
|
||||
if (jar == null || !jar.getName().endsWith(".jar")) return null;
|
||||
|
||||
return jar;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<AttachSourcesAction> getActions(List<LibraryOrderEntry> orderEntries, final PsiFile psiFile) {
|
||||
public Collection<AttachSourcesAction> getActions(List<LibraryOrderEntry> orderEntries, @Nullable PsiFile psiFile) {
|
||||
final VirtualFile jar = getJarByPsiFile(psiFile);
|
||||
if (jar == null) return Collections.emptyList();
|
||||
|
||||
@@ -105,7 +89,7 @@ public class InternetAttachSourceProvider implements AttachSourcesProvider {
|
||||
final File sourceFile = new File(libSourceDir, sourceFileName);
|
||||
|
||||
if (sourceFile.exists()) {
|
||||
return Collections.<AttachSourcesAction>singleton(new LightAttachSourcesAction() {
|
||||
return Collections.singleton(new LightAttachSourcesAction() {
|
||||
@Override
|
||||
public String getName() {
|
||||
return "Attach downloaded source";
|
||||
@@ -124,7 +108,7 @@ public class InternetAttachSourceProvider implements AttachSourcesProvider {
|
||||
});
|
||||
}
|
||||
|
||||
return Collections.<AttachSourcesAction>singleton(new LightAttachSourcesAction() {
|
||||
return Collections.singleton(new LightAttachSourcesAction() {
|
||||
@Override
|
||||
public String getName() {
|
||||
return "Download...";
|
||||
@@ -239,10 +223,6 @@ public class InternetAttachSourceProvider implements AttachSourcesProvider {
|
||||
|
||||
public static File getLibrarySourceDir() {
|
||||
String path = System.getProperty("idea.library.source.dir");
|
||||
if (path != null) {
|
||||
return new File(path);
|
||||
}
|
||||
|
||||
return new File(SystemProperties.getUserHome(), ".ideaLibSources");
|
||||
return path != null ? new File(path) : new File(SystemProperties.getUserHome(), ".ideaLibSources");
|
||||
}
|
||||
}
|
||||
}
|
||||
+21
-8
@@ -1,4 +1,19 @@
|
||||
package org.jetbrains.plugins.groovy.ivy;
|
||||
/*
|
||||
* Copyright 2000-2016 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.jarFinder;
|
||||
|
||||
import com.intellij.lang.properties.IProperty;
|
||||
import com.intellij.lang.properties.psi.PropertiesFile;
|
||||
@@ -25,8 +40,7 @@ import java.util.List;
|
||||
* @author Sergey Evdokimov
|
||||
*/
|
||||
public class IvyAttachSourceProvider extends AbstractAttachSourceProvider {
|
||||
|
||||
private static final Logger LOG = Logger.getInstance("#org.jetbrains.plugins.groovy.ivy.IvyAttachSourceProvider");
|
||||
private static final Logger LOG = Logger.getInstance(IvyAttachSourceProvider.class);
|
||||
|
||||
@Nullable
|
||||
private static String extractUrl(PropertiesFile properties, String artifactName) {
|
||||
@@ -79,11 +93,11 @@ public class IvyAttachSourceProvider extends AbstractAttachSourceProvider {
|
||||
if (srcFile != null) {
|
||||
// File already downloaded.
|
||||
VirtualFile jarRoot = JarFileSystem.getInstance().getJarRootForLocalFile(srcFile);
|
||||
if (jarRoot == null || ArrayUtil.contains(jarRoot, library.getFiles(OrderRootType.SOURCES))) {
|
||||
if (jarRoot == null || ArrayUtil.contains(jarRoot, (Object[])library.getFiles(OrderRootType.SOURCES))) {
|
||||
return Collections.emptyList(); // Sources already attached.
|
||||
}
|
||||
|
||||
return Collections.<AttachSourcesAction>singleton(new AttachExistingSourceAction(jarRoot, library, "Attache sources from Ivy repository") );
|
||||
return Collections.singleton(new AttachExistingSourceAction(jarRoot, library, "Attache sources from Ivy repository") );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -93,7 +107,7 @@ public class IvyAttachSourceProvider extends AbstractAttachSourceProvider {
|
||||
final String url = extractUrl((PropertiesFile)propertiesFileFile, artifactName);
|
||||
if (StringUtil.isEmptyOrSpaces(url)) return Collections.emptyList();
|
||||
|
||||
return Collections.<AttachSourcesAction>singleton(new DownloadSourcesAction(psiFile.getProject(), "Downloading Ivy Sources", url) {
|
||||
return Collections.singleton(new DownloadSourcesAction(psiFile.getProject(), "Downloading Ivy Sources", url) {
|
||||
@Override
|
||||
protected void storeFile(byte[] content) {
|
||||
try {
|
||||
@@ -118,5 +132,4 @@ public class IvyAttachSourceProvider extends AbstractAttachSourceProvider {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2010 JetBrains s.r.o.
|
||||
* Copyright 2000-2016 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.
|
||||
@@ -36,8 +36,5 @@ public interface AttachSourcesProvider {
|
||||
/**
|
||||
* This marker interface means what this action will be shown only if it is single action.
|
||||
*/
|
||||
interface LightAttachSourcesAction extends AttachSourcesAction {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
interface LightAttachSourcesAction extends AttachSourcesAction { }
|
||||
}
|
||||
@@ -533,8 +533,6 @@
|
||||
|
||||
<fileTemplateGroup implementation="org.jetbrains.plugins.groovy.actions.GroovyTemplatesFactory"/>
|
||||
|
||||
<attachSourcesProvider implementation="org.jetbrains.plugins.groovy.ivy.IvyAttachSourceProvider"/>
|
||||
|
||||
<projectConfigurable instance="org.jetbrains.plugins.groovy.compiler.GroovyCompilerConfigurable" id="Groovy compiler"
|
||||
displayName="Groovy Compiler" parentId="project.propCompiler"/>
|
||||
<java.compiler implementation="org.jetbrains.plugins.groovy.compiler.GreclipseIdeaCompiler"/>
|
||||
|
||||
@@ -271,6 +271,7 @@
|
||||
<editorNotificationProvider implementation="com.intellij.debugger.ui.AlternativeSourceNotificationProvider"/>
|
||||
|
||||
<attachSourcesProvider implementation="com.intellij.jarFinder.InternetAttachSourceProvider"/>
|
||||
<attachSourcesProvider implementation="com.intellij.jarFinder.IvyAttachSourceProvider"/>
|
||||
|
||||
<checkoutListener implementation="com.intellij.openapi.vcs.checkout.ProjectCheckoutListener"/>
|
||||
<checkoutListener implementation="com.intellij.openapi.vcs.checkout.ProjectDirCheckoutListener"/>
|
||||
|
||||
Reference in New Issue
Block a user