Maven: Add Library from Repository fixes

This commit is contained in:
Anton Makeev
2010-06-01 11:11:16 +04:00
parent 31ce0fe762
commit f619383971
15 changed files with 191 additions and 187 deletions
+7 -3
View File
@@ -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")
}
@@ -20,7 +20,7 @@ public class MavenFacadeIndexerException extends Exception {
super(message);
}
public MavenFacadeIndexerException(Exception cause) {
public MavenFacadeIndexerException(Throwable cause) {
super(null, cause);
}
}
@@ -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();
@@ -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);
@@ -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<String> explicitProfiles,
Collection<String> 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<MavenRepositoryInfo> 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));
}
}
}
@@ -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<MavenArtifact> resolveTransitively(
@NotNull final List<MavenArtifactInfo> artifacts,
@NotNull final List<MavenRemoteRepository> remoteRepositories) {
Set<Artifact> toResolve = new LinkedHashSet<Artifact>();
for (MavenArtifactInfo each : artifacts) {
toResolve.add(createArtifact(each));
}
public List<MavenArtifact> resolveTransitively(@NotNull final List<MavenArtifactInfo> artifacts,
@NotNull final List<MavenRemoteRepository> remoteRepositories) {
try {
Set<Artifact> toResolve = new LinkedHashSet<Artifact>();
for (MavenArtifactInfo each : artifacts) {
toResolve.add(createArtifact(each));
}
return MavenModelConverter.convertArtifacts(myImpl.resolveTransitively(toResolve, convertRepositories(remoteRepositories)),
new THashMap<Artifact, MavenArtifact>(), 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> {
T execute() throws Exception;
}
private <T> T doExecute(final Executor<T> 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));
}
}
}
@@ -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;
@@ -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());
}
@@ -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;
@@ -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();
@@ -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<MavenArchetype> myUserArchetypes = new ArrayList<MavenArchetype>();
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) {
@@ -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<String, MavenArtifactInfo> myCoordinates = new THashMap<String, MavenArtifactInfo>();
private final THashMap<String, Pair<MavenArtifactInfo, MavenRepositoryInfo>> myCoordinates
= new THashMap<String, Pair<MavenArtifactInfo, MavenRepositoryInfo>>();
private final Map<String, MavenRepositoryInfo> myRepositories = new TreeMap<String, MavenRepositoryInfo>();
private final ArrayList<String> myShownItems = new ArrayList<String>();
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<Collection<MavenArtifactInfo>, Boolean>() {
public boolean process(Collection<MavenArtifactInfo> artifacts, Boolean tooMany) {
RepositoryAttachHandler.searchArtifacts(myProject, text, new PairProcessor<Collection<Pair<MavenArtifactInfo, MavenRepositoryInfo>>, Boolean>() {
public boolean process(Collection<Pair<MavenArtifactInfo, MavenRepositoryInfo>> 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<MavenArtifactInfo, MavenRepositoryInfo> each : artifacts) {
myCoordinates.put(each.first.getGroupId() + ":" + each.first.getArtifactId() + ":" + each.first.getVersion(), each);
}
myRepositoryUrl.setModel(new CollectionComboBoxModel(new ArrayList<String>(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<MavenArtifactInfo, MavenRepositoryInfo> 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;
@@ -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<Collection<MavenArtifactInfo>, Boolean> resultProcessor,
final PairProcessor<Collection<Pair<MavenArtifactInfo, MavenRepositoryInfo>>, Boolean> resultProcessor,
final Processor<Collection<MavenRepositoryInfo>> 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<List<MavenArtifactInfo>> result = Ref.create(Collections.<MavenArtifactInfo>emptyList());
final Ref<List<Pair<MavenArtifactInfo, MavenRepositoryInfo>>> result
= Ref.create(Collections.<Pair<MavenArtifactInfo, MavenRepositoryInfo>>emptyList());
final Ref<List<MavenRepositoryInfo>> result2 = Ref.create(Collections.<MavenRepositoryInfo>emptyList());
final Ref<Boolean> tooManyRef = Ref.create(Boolean.FALSE);
try {
MavenFacadeManager facade = MavenFacadeManager.getInstance();
final String[] nexusUrls = getDefaultNexusUrls();
final List<MavenArtifactInfo> resultList = new ArrayList<MavenArtifactInfo>();
final List<Pair<MavenArtifactInfo, MavenRepositoryInfo>> resultList
= new ArrayList<Pair<MavenArtifactInfo, MavenRepositoryInfo>>();
final List<MavenRepositoryInfo> result2List = new ArrayList<MavenRepositoryInfo>();
for (String nexusUrl : nexusUrls) {
final List<MavenArtifactInfo> 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<MavenRepositoryInfo> repositories = facade.getRepositories(nexusUrl);
final HashMap<String, MavenRepositoryInfo> map = new HashMap<String, MavenRepositoryInfo>();
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<MavenRepositoryInfo> repositories,
final Collection<MavenRepositoryInfo> repositories,
boolean modal,
final Processor<List<MavenArtifact>> 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<MavenArtifactInfo> artifacts,
MavenArtifactInfo artifact,
Collection<MavenRepositoryInfo> repositories,
final Processor<List<MavenArtifact>> resultProcessor,
ProgressIndicator indicator) {
final Ref<List<MavenArtifact>> result = new Ref<List<MavenArtifact>>();
@@ -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<MavenArtifact> resolved = embedder.resolveTransitively(Collections.singletonList(artifact),
convertRepositories(repositories));
result.set(ContainerUtil.findAll(resolved, new Condition<MavenArtifact>() {
public boolean value(MavenArtifact mavenArtifact) {
return mavenArtifact.isResolved();
}
}));
}
catch (MavenProcessCanceledException e) {
return;
@@ -351,7 +366,7 @@ public class RepositoryAttachHandler implements LibraryTableAttachHandler {
}
}
private static List<MavenRemoteRepository> convertRepositories(List<MavenRepositoryInfo> infos) {
private static List<MavenRemoteRepository> convertRepositories(Collection<MavenRepositoryInfo> infos) {
List<MavenRemoteRepository> result = new ArrayList<MavenRemoteRepository>(infos.size());
for (MavenRepositoryInfo each : infos) {
result.add(new MavenRemoteRepository(each.getId(), each.getName(), each.getUrl(), null, null, null));
@@ -20,8 +20,8 @@
<moduleBuilder builderClass="org.jetbrains.idea.maven.wizards.MavenModuleBuilder"/>
<frameworkSupport implementation="org.jetbrains.idea.maven.wizards.MavenFrameworkSupportProvider"/>
<applicationService serviceInterface="org.jetbrains.idea.maven.facade.MavenFacadeManager"
serviceImplementation="org.jetbrains.idea.maven.facade.MavenFacadeManager"/>
<applicationService serviceImplementation="org.jetbrains.idea.maven.facade.MavenFacadeManager"/>
<applicationService serviceImplementation="org.jetbrains.idea.maven.indices.MavenIndicesManager"/>
<projectConfigurable implementation="org.jetbrains.idea.maven.utils.MavenSettings" order="last"/>
@@ -73,14 +73,9 @@
<standardResourceProvider implementation="org.jetbrains.idea.maven.dom.MavenSchemaProvider"/>
<projectService serviceInterface="org.jetbrains.idea.maven.dom.MavenDomElementDescriptorHolder"
serviceImplementation="org.jetbrains.idea.maven.dom.MavenDomElementDescriptorHolder"/>
<applicationService serviceInterface="org.jetbrains.idea.maven.dom.converters.MavenDomConvertersRegistry"
serviceImplementation="org.jetbrains.idea.maven.dom.converters.MavenDomConvertersRegistry"/>
<applicationService serviceInterface="org.jetbrains.idea.maven.dom.converters.repositories.MavenRepositoriesProvider"
serviceImplementation="org.jetbrains.idea.maven.dom.converters.repositories.MavenRepositoriesProvider"/>
<projectService serviceImplementation="org.jetbrains.idea.maven.dom.MavenDomElementDescriptorHolder"/>
<applicationService serviceImplementation="org.jetbrains.idea.maven.dom.converters.MavenDomConvertersRegistry"/>
<applicationService serviceImplementation="org.jetbrains.idea.maven.dom.converters.repositories.MavenRepositoriesProvider"/>
<typedHandler implementation="org.jetbrains.idea.maven.dom.code.MavenTypedHandlerDelegate"/>
<libraryTable.attachHandler implementation="org.jetbrains.idea.maven.utils.RepositoryAttachHandler"/>
@@ -103,9 +98,6 @@
</extensions>
<application-components>
<component>
<implementation-class>org.jetbrains.idea.maven.indices.MavenIndicesManager</implementation-class>
</component>
<component>
<implementation-class>org.jetbrains.idea.maven.utils.MavenEnvironmentRegistrar</implementation-class>
</component>
@@ -1132,16 +1132,13 @@ public class MavenProjectReaderTest extends MavenTestCase {
}
public void testActivatingProfilesByProperty() throws Exception {
System.setProperty("maven.test.property", "foo");
MavenFacadeUtil.resetSystemPropertiesCache();
createProjectPom("<profiles>" +
" <profile>" +
" <id>one</id>" +
" <activation>" +
" <property>" +
" <name>maven.test.property</name>" +
" <value>foo</value>" +
" <name>os.name</name>" +
" <value>" + System.getProperty("os.name") + "</value>" +
" </property>" +
" </activation>" +
" </profile>" +
@@ -1149,8 +1146,8 @@ public class MavenProjectReaderTest extends MavenTestCase {
" <id>two</id>" +
" <activation>" +
" <property>" +
" <name>maven.test.property</name>" +
" <value>bar</value>" +
" <name>os.name</name>" +
" <value>xxx</value>" +
" </property>" +
" </activation>" +
" </profile>" +