From f619383971560105ccdb61b4f3bb1834d3fdf208 Mon Sep 17 00:00:00 2001 From: Anton Makeev Date: Tue, 1 Jun 2010 11:10:50 +0400 Subject: [PATCH] Maven: Add Library from Repository fixes --- build/scripts/layouts.gant | 10 ++- .../facade/MavenFacadeIndexerException.java | 2 +- .../idea/maven/facade/MavenFacadeUtil.java | 5 -- .../idea/maven/facade/RemoteObject.java | 35 ++++---- .../idea/maven/facade/MavenFacadeImpl.java | 58 +++++++++---- .../embedder/MavenFacadeEmbedderImpl.java | 84 +++++++++++-------- .../embedder/MavenFacadeIndexerImpl.java | 35 ++++---- .../facade/embedder/MavenModelConverter.java | 4 +- .../idea/maven/facade/nexus/ArtifactType.java | 11 --- .../idea/maven/facade/MavenFacadeManager.java | 19 ++--- .../maven/indices/MavenIndicesManager.java | 14 +--- .../maven/utils/RepositoryAttachDialog.java | 27 ++---- .../maven/utils/RepositoryAttachHandler.java | 45 ++++++---- .../src/main/resources/META-INF/plugin.xml | 18 ++-- .../maven/project/MavenProjectReaderTest.java | 11 +-- 15 files changed, 191 insertions(+), 187 deletions(-) diff --git a/build/scripts/layouts.gant b/build/scripts/layouts.gant index 0ef5893a72fc..cd56346c2752 100644 --- a/build/scripts/layouts.gant +++ b/build/scripts/layouts.gant @@ -174,10 +174,14 @@ def layoutFull(String home, String targetDirectory) { layoutPlugin("maven") { - jar("maven-facade.jar") { - module("maven-facade") + jar("maven-facade-api.jar") { + module("maven-facade-api") } - fileset(dir: "$home/plugins/maven/lib") + jar("maven-facade-impl.jar") { + module("maven-facade-impl") + } + fileset(dir: "$home/plugins/maven/facade-impl/lib") + fileset(dir: "$home/plugins/maven/facade-api/lib") } diff --git a/plugins/maven/facade-api/src/org/jetbrains/idea/maven/facade/MavenFacadeIndexerException.java b/plugins/maven/facade-api/src/org/jetbrains/idea/maven/facade/MavenFacadeIndexerException.java index 92ed5ad26499..a0cd581f5cee 100644 --- a/plugins/maven/facade-api/src/org/jetbrains/idea/maven/facade/MavenFacadeIndexerException.java +++ b/plugins/maven/facade-api/src/org/jetbrains/idea/maven/facade/MavenFacadeIndexerException.java @@ -20,7 +20,7 @@ public class MavenFacadeIndexerException extends Exception { super(message); } - public MavenFacadeIndexerException(Exception cause) { + public MavenFacadeIndexerException(Throwable cause) { super(null, cause); } } diff --git a/plugins/maven/facade-api/src/org/jetbrains/idea/maven/facade/MavenFacadeUtil.java b/plugins/maven/facade-api/src/org/jetbrains/idea/maven/facade/MavenFacadeUtil.java index 164bbe44aaa3..77964fbfb34d 100644 --- a/plugins/maven/facade-api/src/org/jetbrains/idea/maven/facade/MavenFacadeUtil.java +++ b/plugins/maven/facade-api/src/org/jetbrains/idea/maven/facade/MavenFacadeUtil.java @@ -24,7 +24,6 @@ public class MavenFacadeUtil { private static volatile Properties mySystemPropertiesCache; public static Properties collectSystemProperties() { - if (mySystemPropertiesCache == null) { Properties result = new Properties(); result.putAll(getSystemProperties()); @@ -39,10 +38,6 @@ public class MavenFacadeUtil { return mySystemPropertiesCache; } - public static void resetSystemPropertiesCache() { - mySystemPropertiesCache = null; - } - @SuppressWarnings({"unchecked"}) private static Properties getSystemProperties() { Properties result = (Properties)System.getProperties().clone(); diff --git a/plugins/maven/facade-api/src/org/jetbrains/idea/maven/facade/RemoteObject.java b/plugins/maven/facade-api/src/org/jetbrains/idea/maven/facade/RemoteObject.java index 9b9531ea6c72..753532d18cfa 100644 --- a/plugins/maven/facade-api/src/org/jetbrains/idea/maven/facade/RemoteObject.java +++ b/plugins/maven/facade-api/src/org/jetbrains/idea/maven/facade/RemoteObject.java @@ -53,31 +53,26 @@ public abstract class RemoteObject implements Remote, Unreferenced { } } - protected static void handleException(Exception e) { - Throwable cause = e; - while (cause.getCause() != null) { - cause = cause.getCause(); - } - cause = wrapException(cause); - throw cause instanceof RuntimeException ? (RuntimeException)cause : new RuntimeException(cause); - } - public static Throwable wrapException(Throwable ex) { - if (!ex.getClass().getName().startsWith("java")) { - final Throwable replaceWith = new RuntimeException(ex.toString()); - replaceWith.setStackTrace(ex.getStackTrace()); - ex = replaceWith; + boolean foreignException = false; + Throwable each = ex; + while(each != null) { + String name = each.getClass().getName(); + if (!name.startsWith("java") && !name.startsWith(RemoteObject.class.getPackage().getName())) { + foreignException = true; + break; + } + each = each.getCause(); + } + + if (foreignException) { + Throwable wrapper = new Throwable(ex.toString()); + wrapper.setStackTrace(ex.getStackTrace()); + ex = wrapper; } return ex; } - public Object wrapIfNeeded(Object o) throws RemoteException { - if (o == null) return o; - if (o.getClass().getClassLoader() == null || - o.getClass().getName().startsWith("com.intellij")) return o; - return o.toString(); - } - public void unreferenced() { if (myParent != null) { myParent.myChildren.remove(this); diff --git a/plugins/maven/facade-impl/src/org/jetbrains/idea/maven/facade/MavenFacadeImpl.java b/plugins/maven/facade-impl/src/org/jetbrains/idea/maven/facade/MavenFacadeImpl.java index 457628449ae7..a490b3cafbf2 100644 --- a/plugins/maven/facade-impl/src/org/jetbrains/idea/maven/facade/MavenFacadeImpl.java +++ b/plugins/maven/facade-impl/src/org/jetbrains/idea/maven/facade/MavenFacadeImpl.java @@ -38,34 +38,64 @@ import java.util.List; public class MavenFacadeImpl extends RemoteObject implements MavenFacade { public void setLogger(MavenFacadeLogger logger) throws RemoteException { - MavenFacadeLoggerManager.setLogger(logger); + try { + MavenFacadeLoggerManager.setLogger(logger); + } + catch (Exception e) { + throw new RuntimeException(wrapException(e)); + } } public MavenFacadeEmbedder createEmbedder(MavenFacadeSettings settings) throws RemoteException { - MavenFacadeEmbedderImpl result = MavenFacadeEmbedderImpl.create(settings); - UnicastRemoteObject.exportObject(result, 0); - return result; + try { + MavenFacadeEmbedderImpl result = MavenFacadeEmbedderImpl.create(settings); + UnicastRemoteObject.exportObject(result, 0); + return result; + } + catch (RemoteException e) { + throw new RuntimeException(wrapException(e)); + } } public MavenFacadeIndexer createIndexer() throws RemoteException { - MavenFacadeIndexerImpl result = new MavenFacadeIndexerImpl(); - UnicastRemoteObject.exportObject(result, 0); - return result; + try { + MavenFacadeIndexerImpl result = new MavenFacadeIndexerImpl(); + UnicastRemoteObject.exportObject(result, 0); + return result; + } + catch (RemoteException e) { + throw new RuntimeException(wrapException(e)); + } } public MavenModel interpolateAndAlignModel(MavenModel model, File basedir) { - return MavenFacadeEmbedderImpl.interpolateAndAlignModel(model, basedir); + try { + return MavenFacadeEmbedderImpl.interpolateAndAlignModel(model, basedir); + } + catch (Exception e) { + throw new RuntimeException(wrapException(e)); + } } public MavenModel assembleInheritance(MavenModel model, MavenModel parentModel) { - return MavenFacadeEmbedderImpl.assembleInheritance(model, parentModel); + try { + return MavenFacadeEmbedderImpl.assembleInheritance(model, parentModel); + } + catch (Exception e) { + throw new RuntimeException(wrapException(e)); + } } public ProfileApplicationResult applyProfiles(MavenModel model, File basedir, Collection explicitProfiles, Collection alwaysOnProfiles) { - return MavenFacadeEmbedderImpl.applyProfiles(model, basedir, explicitProfiles, alwaysOnProfiles); + try { + return MavenFacadeEmbedderImpl.applyProfiles(model, basedir, explicitProfiles, alwaysOnProfiles); + } + catch (Exception e) { + throw new RuntimeException(wrapException(e)); + } } public List getRepositories(String nexusUrl) throws RemoteException { @@ -79,8 +109,7 @@ public class MavenFacadeImpl extends RemoteObject implements MavenFacade { return result; } catch (Exception e) { - handleException(e); - throw new AssertionError(); + throw new RuntimeException(wrapException(e)); } } @@ -105,9 +134,8 @@ public class MavenFacadeImpl extends RemoteObject implements MavenFacade { } return result; } - catch (Exception ex) { - handleException(ex); - throw new AssertionError(); + catch (Exception e) { + throw new RuntimeException(wrapException(e)); } } } diff --git a/plugins/maven/facade-impl/src/org/jetbrains/idea/maven/facade/embedder/MavenFacadeEmbedderImpl.java b/plugins/maven/facade-impl/src/org/jetbrains/idea/maven/facade/embedder/MavenFacadeEmbedderImpl.java index c900a0a13d12..c4de158707c5 100644 --- a/plugins/maven/facade-impl/src/org/jetbrains/idea/maven/facade/embedder/MavenFacadeEmbedderImpl.java +++ b/plugins/maven/facade-impl/src/org/jetbrains/idea/maven/facade/embedder/MavenFacadeEmbedderImpl.java @@ -16,7 +16,6 @@ package org.jetbrains.idea.maven.facade.embedder; import com.intellij.openapi.progress.ProcessCanceledException; -import com.intellij.openapi.util.Pair; import com.intellij.openapi.util.Ref; import com.intellij.util.Function; import gnu.trove.THashMap; @@ -75,10 +74,12 @@ import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; +import static org.jetbrains.idea.maven.facade.RemoteObject.wrapException; + public class MavenFacadeEmbedderImpl extends RemoteObject implements MavenFacadeEmbedder { private final MavenEmbedder myImpl; private final MavenFacadeConsoleWrapper myConsoleWrapper; - private volatile MavenFacadeProgressIndicator myCurrentIndicator; + private volatile MavenFacadeProgressIndicatorWrapper myCurrentIndicatorWrapper; public static MavenFacadeEmbedderImpl create(MavenFacadeSettings facadeSettings) { MavenEmbedderSettings settings = new MavenEmbedderSettings(); @@ -184,15 +185,14 @@ public class MavenFacadeEmbedderImpl extends RemoteObject implements MavenFacade } @NotNull - public List resolveTransitively( - @NotNull final List artifacts, - @NotNull final List remoteRepositories) { - - Set toResolve = new LinkedHashSet(); - for (MavenArtifactInfo each : artifacts) { - toResolve.add(createArtifact(each)); - } + public List resolveTransitively(@NotNull final List artifacts, + @NotNull final List remoteRepositories) { try { + Set toResolve = new LinkedHashSet(); + for (MavenArtifactInfo each : artifacts) { + toResolve.add(createArtifact(each)); + } + return MavenModelConverter.convertArtifacts(myImpl.resolveTransitively(toResolve, convertRepositories(remoteRepositories)), new THashMap(), getLocalRepositoryFile()); } @@ -202,6 +202,10 @@ public class MavenFacadeEmbedderImpl extends RemoteObject implements MavenFacade catch (ArtifactNotFoundException e) { MavenFacadeLoggerManager.getLogger().info(e); } + catch (Exception e) { + throw new RuntimeException(wrapException(e)); + + } return Collections.emptyList(); } @@ -469,7 +473,6 @@ public class MavenFacadeEmbedderImpl extends RemoteObject implements MavenFacade private interface Executor { T execute() throws Exception; - } private T doExecute(final Executor executor) throws MavenFacadeProcessCanceledException { @@ -491,23 +494,17 @@ public class MavenFacadeEmbedderImpl extends RemoteObject implements MavenFacade } }); - MavenFacadeProgressIndicator indicator = myCurrentIndicator; + MavenFacadeProgressIndicatorWrapper indicator = myCurrentIndicatorWrapper; while (true) { - boolean canceled = false; - try { - canceled = indicator.isCanceled(); - } - catch (RemoteException e) { - throw new RuntimeException(e); - } - if (canceled) throw new MavenFacadeProcessCanceledException(); + if (indicator.isCanceled()) throw new MavenFacadeProcessCanceledException(); + try { future.get(50, TimeUnit.MILLISECONDS); } catch (TimeoutException ignore) { } catch (ExecutionException e) { - throw new RuntimeException(e.getCause()); + throw new RuntimeException(wrapException(e.getCause())); } catch (InterruptedException e) { throw new MavenFacadeProcessCanceledException(); @@ -526,8 +523,7 @@ public class MavenFacadeEmbedderImpl extends RemoteObject implements MavenFacade private RuntimeException getRethrowable(Throwable throwable) { if (throwable instanceof InvocationTargetException) throwable = throwable.getCause(); - if (throwable instanceof RuntimeException) return (RuntimeException)throwable; - return new RuntimeException(throwable); + return new RuntimeException(wrapException(throwable)); } private static void setupContainer(PlexusContainer c) { @@ -556,16 +552,21 @@ public class MavenFacadeEmbedderImpl extends RemoteObject implements MavenFacade boolean strict, MavenFacadeConsole logger, MavenFacadeProgressIndicator process) { - ((CustomArtifactFactory)getComponent(ArtifactFactory.class)).customize(); - ((CustomArtifactFactory)getComponent(ProjectArtifactFactory.class)).customize(); - ((CustomArtifactResolver)getComponent(ArtifactResolver.class)).customize(projectIdToFileMap, strict); - ((CustomWagonManager)getComponent(WagonManager.class)).customize(strict); + try { + ((CustomArtifactFactory)getComponent(ArtifactFactory.class)).customize(); + ((CustomArtifactFactory)getComponent(ProjectArtifactFactory.class)).customize(); + ((CustomArtifactResolver)getComponent(ArtifactResolver.class)).customize(projectIdToFileMap, strict); + ((CustomWagonManager)getComponent(WagonManager.class)).customize(strict); - setConsoleAndLogger(logger, process); + setConsoleAndLogger(logger, process); + } + catch (Exception e) { + throw new RuntimeException(wrapException(e)); + } } private void setConsoleAndLogger(MavenFacadeConsole logger, MavenFacadeProgressIndicator process) { - myCurrentIndicator = process; + myCurrentIndicatorWrapper = new MavenFacadeProgressIndicatorWrapper(process); myConsoleWrapper.setWrappee(logger); WagonManager wagon = getComponent(WagonManager.class); @@ -573,16 +574,26 @@ public class MavenFacadeEmbedderImpl extends RemoteObject implements MavenFacade } public void reset() { - setConsoleAndLogger(null, null); + try { + setConsoleAndLogger(null, null); - ((CustomArtifactFactory)getComponent(ProjectArtifactFactory.class)).reset(); - ((CustomArtifactFactory)getComponent(ArtifactFactory.class)).reset(); - ((CustomArtifactResolver)getComponent(ArtifactResolver.class)).reset(); - ((CustomWagonManager)getComponent(WagonManager.class)).reset(); + ((CustomArtifactFactory)getComponent(ProjectArtifactFactory.class)).reset(); + ((CustomArtifactFactory)getComponent(ArtifactFactory.class)).reset(); + ((CustomArtifactResolver)getComponent(ArtifactResolver.class)).reset(); + ((CustomWagonManager)getComponent(WagonManager.class)).reset(); + } + catch (Exception e) { + throw new RuntimeException(wrapException(e)); + } } public void release() { - myImpl.release(); + try { + myImpl.release(); + } + catch (Exception e) { + throw new RuntimeException(wrapException(e)); + } } public void clearCaches() { @@ -621,6 +632,9 @@ public class MavenFacadeEmbedderImpl extends RemoteObject implements MavenFacade catch (IllegalAccessException e) { MavenFacadeLoggerManager.getLogger().info(e); } + catch(Exception e) { + throw new RuntimeException(wrapException(e)); + } } } diff --git a/plugins/maven/facade-impl/src/org/jetbrains/idea/maven/facade/embedder/MavenFacadeIndexerImpl.java b/plugins/maven/facade-impl/src/org/jetbrains/idea/maven/facade/embedder/MavenFacadeIndexerImpl.java index a67c97653f1a..4fb55e106bf8 100644 --- a/plugins/maven/facade-impl/src/org/jetbrains/idea/maven/facade/embedder/MavenFacadeIndexerImpl.java +++ b/plugins/maven/facade-impl/src/org/jetbrains/idea/maven/facade/embedder/MavenFacadeIndexerImpl.java @@ -80,11 +80,8 @@ public class MavenFacadeIndexerImpl extends RemoteObject implements MavenFacadeI myIndices.put(id, context); return id; } - catch (IOException e) { - throw new MavenFacadeIndexerException(e); - } - catch (UnsupportedExistingLuceneIndexException e) { - throw new MavenFacadeIndexerException(e.getMessage()); + catch (Exception e) { + throw new MavenFacadeIndexerException(wrapException(e)); } } @@ -92,8 +89,8 @@ public class MavenFacadeIndexerImpl extends RemoteObject implements MavenFacadeI try { myIndexer.removeIndexingContext(getIndex(id), false); } - catch (IOException e) { - throw new MavenFacadeIndexerException(e); + catch (Exception e) { + throw new MavenFacadeIndexerException(wrapException(e)); } } @@ -163,8 +160,8 @@ public class MavenFacadeIndexerImpl extends RemoteObject implements MavenFacadeI catch (MavenFacadeProgressIndicatorWrapper.RuntimeCanceledException e) { throw new MavenFacadeProcessCanceledException(); } - catch (IOException e) { - throw new MavenFacadeIndexerException(e); + catch (Exception e) { + throw new MavenFacadeIndexerException(wrapException(e)); } } @@ -189,8 +186,8 @@ public class MavenFacadeIndexerImpl extends RemoteObject implements MavenFacadeI } return result; } - catch (IOException e) { - throw new MavenFacadeIndexerException(e); + catch (Exception e) { + throw new MavenFacadeIndexerException(wrapException(e)); } } @@ -205,8 +202,8 @@ public class MavenFacadeIndexerImpl extends RemoteObject implements MavenFacadeI org.sonatype.nexus.index.ArtifactInfo a = artifactContext.getArtifactInfo(); return new MavenId(a.groupId, a.artifactId, a.version); } - catch (IOException e) { - throw new MavenFacadeIndexerException(e); + catch (Exception e) { + throw new MavenFacadeIndexerException(wrapException(e)); } } @@ -238,8 +235,8 @@ public class MavenFacadeIndexerImpl extends RemoteObject implements MavenFacadeI } return result; } - catch (IOException e) { - throw new MavenFacadeIndexerException(e); + catch (Exception e) { + throw new MavenFacadeIndexerException(wrapException(e)); } } @@ -265,10 +262,14 @@ public class MavenFacadeIndexerImpl extends RemoteObject implements MavenFacadeI } public void release() { - myEmbedder.release(); + try { + myEmbedder.release(); + } + catch (Exception e) { + throw new RuntimeException(wrapException(e)); + } } - private static class MyScanningListener implements ArtifactScanningListener { private final MavenFacadeProgressIndicatorWrapper p; diff --git a/plugins/maven/facade-impl/src/org/jetbrains/idea/maven/facade/embedder/MavenModelConverter.java b/plugins/maven/facade-impl/src/org/jetbrains/idea/maven/facade/embedder/MavenModelConverter.java index 65557c7a7101..709df7b09d10 100644 --- a/plugins/maven/facade-impl/src/org/jetbrains/idea/maven/facade/embedder/MavenModelConverter.java +++ b/plugins/maven/facade-impl/src/org/jetbrains/idea/maven/facade/embedder/MavenModelConverter.java @@ -488,7 +488,7 @@ public class MavenModelConverter { result.setId(r.getId()); result.setName(r.getName()); result.setUrl(r.getUrl()); - result.setLayout(r.getLayout()); + result.setLayout(r.getLayout() == null ? "default" : r.getLayout()); if (r.getReleasesPolicy() != null) result.setReleases(toNativePolicy(r.getReleasesPolicy())); if (r.getSnapshotsPolicy() != null) result.setSnapshots(toNativePolicy(r.getSnapshotsPolicy())); @@ -514,7 +514,7 @@ public class MavenModelConverter { t.getVersion(), t.getPackaging(), t.getClassifier(), - t.getClassNames(), + null, t.getRepoId()); } diff --git a/plugins/maven/facade-impl/src/org/jetbrains/idea/maven/facade/nexus/ArtifactType.java b/plugins/maven/facade-impl/src/org/jetbrains/idea/maven/facade/nexus/ArtifactType.java index ca9fc8a040c7..545cc617fb2f 100644 --- a/plugins/maven/facade-impl/src/org/jetbrains/idea/maven/facade/nexus/ArtifactType.java +++ b/plugins/maven/facade-impl/src/org/jetbrains/idea/maven/facade/nexus/ArtifactType.java @@ -90,8 +90,6 @@ public class ArtifactType implements Serializable { @XmlElement(required = true) protected String artifactLink; - protected String classNames; - public ArtifactType() { } @@ -322,15 +320,6 @@ public class ArtifactType implements Serializable { this.artifactLink = value; } - @Nullable - public String getClassNames() { - return classNames; - } - - public void setClassNames(@Nullable String classNames) { - this.classNames = classNames; - } - @Override public String toString() { return groupId + ":" + artifactId + ":" + version; diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/facade/MavenFacadeManager.java b/plugins/maven/src/main/java/org/jetbrains/idea/maven/facade/MavenFacadeManager.java index 9a7cab28c6d9..e16d96c71154 100644 --- a/plugins/maven/src/main/java/org/jetbrains/idea/maven/facade/MavenFacadeManager.java +++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/facade/MavenFacadeManager.java @@ -29,10 +29,8 @@ import com.intellij.execution.process.ProcessTerminatedListener; import com.intellij.execution.rmi.RemoteProcessSupport; import com.intellij.execution.runners.ProgramRunner; import com.intellij.ide.DataManager; -import com.intellij.openapi.Disposable; import com.intellij.openapi.actionSystem.AnAction; import com.intellij.openapi.actionSystem.PlatformDataKeys; -import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.application.PathManager; import com.intellij.openapi.components.ServiceManager; import com.intellij.openapi.project.Project; @@ -40,9 +38,8 @@ import com.intellij.openapi.projectRoots.JavaSdkType; import com.intellij.openapi.projectRoots.JdkUtil; import com.intellij.openapi.projectRoots.Sdk; import com.intellij.openapi.projectRoots.SimpleJavaSdkType; -import com.intellij.openapi.util.Disposer; +import com.intellij.openapi.util.ShutDownTracker; import com.intellij.openapi.util.text.StringUtil; -import com.intellij.psi.CommonClassNames; import com.intellij.util.PathUtil; import com.intellij.util.PathsList; import com.intellij.util.SystemProperties; @@ -96,8 +93,8 @@ public class MavenFacadeManager { } }; - Disposer.register(ApplicationManager.getApplication(), new Disposable() { - public void dispose() { + ShutDownTracker.getInstance().registerShutdownTask(new Runnable() { + public void run() { mySupport.stopAll(); if (myLogger != null) { @@ -149,7 +146,7 @@ public class MavenFacadeManager { addPluginLibraries(params.getClassPath()); params.setMainClass(MAIN_CLASS); - params.getVMParametersList().add("-Xmx512m -agentlib:yjpagent=disablej2ee"); + params.getVMParametersList().addParametersString("-d32 -Xmx512m"); return params; } @@ -176,7 +173,6 @@ public class MavenFacadeManager { ProcessTerminatedListener.attach(processHandler); return processHandler; } - }; } @@ -192,7 +188,7 @@ public class MavenFacadeManager { libDir = new File(luceneLib.getParentFile().getParentFile().getParentFile(), "facade-impl/lib"); } else { - libDir = pluginFileOrDir; + libDir = pluginFileOrDir.getParentFile(); } MavenLog.LOG.assertTrue(libDir.exists() && libDir.isDirectory(), "Maven Facade libraries dir not found: " + libDir); @@ -204,11 +200,6 @@ public class MavenFacadeManager { } } - public static String getJarPath(@NotNull final Class context, @NotNull final String mainClassName) { - final String s = PathManager.getResourceRoot(context, "/" + mainClassName.replace('.', '/') + CommonClassNames.CLASS_FILE_EXTENSION); - return new File(s).getAbsoluteFile().getAbsolutePath(); - } - public MavenEmbedderWrapper createEmbedder(Project project) { MavenFacade facade = getFacade(); MavenGeneralSettings settings = MavenProjectsManager.getInstance(project).getGeneralSettings(); diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/indices/MavenIndicesManager.java b/plugins/maven/src/main/java/org/jetbrains/idea/maven/indices/MavenIndicesManager.java index 272ae3852f30..df4ff90b3d8d 100644 --- a/plugins/maven/src/main/java/org/jetbrains/idea/maven/indices/MavenIndicesManager.java +++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/indices/MavenIndicesManager.java @@ -17,6 +17,7 @@ package org.jetbrains.idea.maven.indices; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.components.ApplicationComponent; +import com.intellij.openapi.components.ServiceManager; import com.intellij.openapi.extensions.Extensions; import com.intellij.openapi.progress.BackgroundTaskQueue; import com.intellij.openapi.progress.ProcessCanceledException; @@ -47,7 +48,7 @@ import java.io.File; import java.io.IOException; import java.util.*; -public class MavenIndicesManager implements ApplicationComponent { +public class MavenIndicesManager { private static final String ELEMENT_ARCHETYPES = "archetypes"; private static final String ELEMENT_ARCHETYPE = "archetype"; private static final String ELEMENT_GROUP_ID = "groupId"; @@ -75,15 +76,7 @@ public class MavenIndicesManager implements ApplicationComponent { private volatile List myUserArchetypes = new ArrayList(); public static MavenIndicesManager getInstance() { - return ApplicationManager.getApplication().getComponent(MavenIndicesManager.class); - } - - @NotNull - public String getComponentName() { - return getClass().getSimpleName(); - } - - public void initComponent() { + return ServiceManager.getService(MavenIndicesManager.class); } @TestOnly @@ -99,7 +92,6 @@ public class MavenIndicesManager implements ApplicationComponent { private synchronized void ensureInitialized() { if (myIndices != null) return; - // todo remove defaultProject myIndexer = MavenFacadeManager.getInstance().createIndexer(); myIndices = new MavenIndices(myIndexer, getIndicesDir(), new MavenIndex.IndexListener() { public void indexIsBroken(MavenIndex index) { diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/utils/RepositoryAttachDialog.java b/plugins/maven/src/main/java/org/jetbrains/idea/maven/utils/RepositoryAttachDialog.java index 5760713137b4..4362c507b2db 100644 --- a/plugins/maven/src/main/java/org/jetbrains/idea/maven/utils/RepositoryAttachDialog.java +++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/utils/RepositoryAttachDialog.java @@ -25,6 +25,7 @@ import com.intellij.openapi.ui.popup.JBPopupFactory; import com.intellij.openapi.util.Comparing; import com.intellij.openapi.util.Condition; import com.intellij.openapi.util.Disposer; +import com.intellij.openapi.util.Pair; import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.vfs.VirtualFile; @@ -62,7 +63,8 @@ public class RepositoryAttachDialog extends DialogWrapper { private final Project myProject; private final boolean myManaged; private final AsyncProcessIcon myProgressIcon; - private final THashMap myCoordinates = new THashMap(); + private final THashMap> myCoordinates + = new THashMap>(); private final Map myRepositories = new TreeMap(); private final ArrayList myShownItems = new ArrayList(); private final JComboBox myCombobox = new JComboBox(new CollectionComboBoxModel(myShownItems, null)); @@ -170,14 +172,14 @@ public class RepositoryAttachDialog extends DialogWrapper { if (myProgressIcon.isVisible()) return false; myProgressIcon.setVisible(true); myProgressIcon.resume(); - RepositoryAttachHandler.searchArtifacts(myProject, text, new PairProcessor, Boolean>() { - public boolean process(Collection artifacts, Boolean tooMany) { + RepositoryAttachHandler.searchArtifacts(myProject, text, new PairProcessor>, Boolean>() { + public boolean process(Collection> artifacts, Boolean tooMany) { if (myProgressIcon.isDisposed()) return true; myProgressIcon.suspend(); myProgressIcon.setVisible(false); final int prevSize = myCoordinates.size(); - for (MavenArtifactInfo each : artifacts) { - myCoordinates.put(each.getGroupId() + ":" + each.getArtifactId() + ":" + each.getVersion(), each); + for (Pair each : artifacts) { + myCoordinates.put(each.first.getGroupId() + ":" + each.first.getArtifactId() + ":" + each.first.getVersion(), each); } myRepositoryUrl.setModel(new CollectionComboBoxModel(new ArrayList(myRepositories.keySet()), myRepositoryUrl.getEditor().getItem())); @@ -328,23 +330,12 @@ public class RepositoryAttachDialog extends DialogWrapper { return Collections.singletonList(new MavenRepositoryInfo("custom", null, selectedRepository)); } else { - final MavenArtifactInfo artifact = myCoordinates.get(getCoordinateText()); - final MavenRepositoryInfo repository = - artifact != null ? findRepositoryFor(artifact) : null; + final Pair artifactAndRepo = myCoordinates.get(getCoordinateText()); + final MavenRepositoryInfo repository = artifactAndRepo.second; return repository != null? Collections.singletonList(repository) : ContainerUtil.findAll(myRepositories.values(), Condition.NOT_NULL); } } - private MavenRepositoryInfo findRepositoryFor(MavenArtifactInfo artifact) { - String soughtFor = artifact.getRepositoryId(); - if (soughtFor == null) return null; - - for (MavenRepositoryInfo each : myRepositories.values()) { - if (each.getId().equals(soughtFor)) return each; - } - return null; - } - private boolean isValidCoordinateSelected() { final String text = getCoordinateText(); if (myCombobox.getModel().getSelectedItem() == null) return false; diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/utils/RepositoryAttachHandler.java b/plugins/maven/src/main/java/org/jetbrains/idea/maven/utils/RepositoryAttachHandler.java index 4d4fd0a55239..20d95c1d4a0e 100644 --- a/plugins/maven/src/main/java/org/jetbrains/idea/maven/utils/RepositoryAttachHandler.java +++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/utils/RepositoryAttachHandler.java @@ -32,14 +32,13 @@ import com.intellij.openapi.roots.libraries.Library; import com.intellij.openapi.roots.ui.configuration.libraryEditor.LibraryTableAttachHandler; import com.intellij.openapi.ui.DialogWrapper; import com.intellij.openapi.ui.Messages; -import com.intellij.openapi.util.ActionCallback; -import com.intellij.openapi.util.NullableComputable; -import com.intellij.openapi.util.Ref; +import com.intellij.openapi.util.*; import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.vfs.VfsUtil; import com.intellij.util.PairProcessor; import com.intellij.util.Processor; import com.intellij.util.SmartList; +import com.intellij.util.containers.ContainerUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.idea.maven.dom.converters.repositories.MavenRepositoriesProvider; import org.jetbrains.idea.maven.execution.SoutMavenConsole; @@ -192,21 +191,23 @@ public class RepositoryAttachHandler implements LibraryTableAttachHandler { } public static void searchArtifacts(final Project project, String coord, - final PairProcessor, Boolean> resultProcessor, + final PairProcessor>, Boolean> resultProcessor, final Processor> repoProcessor) { if (coord == null) return; final MavenArtifactInfo template = createTemplate(coord, null); ProgressManager.getInstance().run(new Task.Backgroundable(project, "Maven", false) { public void run(@NotNull ProgressIndicator indicator) { - final Ref> result = Ref.create(Collections.emptyList()); + final Ref>> result + = Ref.create(Collections.>emptyList()); final Ref> result2 = Ref.create(Collections.emptyList()); final Ref tooManyRef = Ref.create(Boolean.FALSE); try { MavenFacadeManager facade = MavenFacadeManager.getInstance(); final String[] nexusUrls = getDefaultNexusUrls(); - final List resultList = new ArrayList(); + final List> resultList + = new ArrayList>(); final List result2List = new ArrayList(); for (String nexusUrl : nexusUrls) { final List artifacts; @@ -221,8 +222,15 @@ public class RepositoryAttachHandler implements LibraryTableAttachHandler { tooManyRef.set(Boolean.TRUE); } else if (!artifacts.isEmpty()) { - result2List.addAll(facade.getRepositories(nexusUrl)); - resultList.addAll(artifacts); + final List repositories = facade.getRepositories(nexusUrl); + final HashMap map = new HashMap(); + for (MavenRepositoryInfo repository : repositories) { + map.put(repository.getId(), repository); + } + result2List.addAll(repositories); + for (MavenArtifactInfo artifact : artifacts) { + resultList.add(Pair.create(artifact, map.get(artifact.getRepositoryId()))); + } } } result.set(resultList); @@ -288,7 +296,7 @@ public class RepositoryAttachHandler implements LibraryTableAttachHandler { return new MavenArtifactInfo(parts.length > 0 ? parts[0] : null, parts.length > 1 ? parts[1] : null, parts.length > 2 ? parts[2] : null, - null, + packaging, null); } } @@ -299,21 +307,21 @@ public class RepositoryAttachHandler implements LibraryTableAttachHandler { public static void resolveLibrary(final Project project, final String libName, - Collection repositories, + final Collection repositories, boolean modal, final Processor> resultProcessor) { Task task; if (modal) { task = new Task.Modal(project, "Maven", false) { public void run(@NotNull ProgressIndicator indicator) { - doResolveInner(project, Collections.singletonList(createTemplate(libName, "jar")), resultProcessor, indicator); + doResolveInner(project, createTemplate(libName, "jar"), repositories, resultProcessor, indicator); } }; } else { task = new Task.Backgroundable(project, "Maven", false, PerformInBackgroundOption.DEAF) { public void run(@NotNull ProgressIndicator indicator) { - doResolveInner(project, Collections.singletonList(createTemplate(libName, "jar")), resultProcessor, indicator); + doResolveInner(project, createTemplate(libName, "jar"), repositories, resultProcessor, indicator); } @Override @@ -327,7 +335,8 @@ public class RepositoryAttachHandler implements LibraryTableAttachHandler { } private static void doResolveInner(Project project, - List artifacts, + MavenArtifactInfo artifact, + Collection repositories, final Processor> resultProcessor, ProgressIndicator indicator) { final Ref> result = new Ref>(); @@ -336,7 +345,13 @@ public class RepositoryAttachHandler implements LibraryTableAttachHandler { MavenEmbedderWrapper embedder = manager.getEmbedder(MavenEmbeddersManager.FOR_DOWNLOAD); try { embedder.customizeForResolve(new SoutMavenConsole(), new MavenProgressIndicator(indicator)); - result.set(embedder.resolveTransitively(artifacts, convertRepositories(getDefaultRepositories()))); + List resolved = embedder.resolveTransitively(Collections.singletonList(artifact), + convertRepositories(repositories)); + result.set(ContainerUtil.findAll(resolved, new Condition() { + public boolean value(MavenArtifact mavenArtifact) { + return mavenArtifact.isResolved(); + } + })); } catch (MavenProcessCanceledException e) { return; @@ -351,7 +366,7 @@ public class RepositoryAttachHandler implements LibraryTableAttachHandler { } } - private static List convertRepositories(List infos) { + private static List convertRepositories(Collection infos) { List result = new ArrayList(infos.size()); for (MavenRepositoryInfo each : infos) { result.add(new MavenRemoteRepository(each.getId(), each.getName(), each.getUrl(), null, null, null)); diff --git a/plugins/maven/src/main/resources/META-INF/plugin.xml b/plugins/maven/src/main/resources/META-INF/plugin.xml index 13f14ad673c2..e5ee12fc523f 100644 --- a/plugins/maven/src/main/resources/META-INF/plugin.xml +++ b/plugins/maven/src/main/resources/META-INF/plugin.xml @@ -20,8 +20,8 @@ - + + @@ -73,14 +73,9 @@ - - - - - + + + @@ -103,9 +98,6 @@ - - org.jetbrains.idea.maven.indices.MavenIndicesManager - org.jetbrains.idea.maven.utils.MavenEnvironmentRegistrar diff --git a/plugins/maven/src/test/java/org/jetbrains/idea/maven/project/MavenProjectReaderTest.java b/plugins/maven/src/test/java/org/jetbrains/idea/maven/project/MavenProjectReaderTest.java index 1bb850520a86..639a61f6926e 100644 --- a/plugins/maven/src/test/java/org/jetbrains/idea/maven/project/MavenProjectReaderTest.java +++ b/plugins/maven/src/test/java/org/jetbrains/idea/maven/project/MavenProjectReaderTest.java @@ -1132,16 +1132,13 @@ public class MavenProjectReaderTest extends MavenTestCase { } public void testActivatingProfilesByProperty() throws Exception { - System.setProperty("maven.test.property", "foo"); - MavenFacadeUtil.resetSystemPropertiesCache(); - createProjectPom("" + " " + " one" + " " + " " + - " maven.test.property" + - " foo" + + " os.name" + + " " + System.getProperty("os.name") + "" + " " + " " + " " + @@ -1149,8 +1146,8 @@ public class MavenProjectReaderTest extends MavenTestCase { " two" + " " + " " + - " maven.test.property" + - " bar" + + " os.name" + + " xxx" + " " + " " + " " +