mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Merge branch 'master' of git@git.labs.intellij.net:idea/community
This commit is contained in:
Binary file not shown.
|
After Width: | Height: | Size: 655 B |
@@ -65,7 +65,9 @@ public class AndroidPrecompileTask implements CompileTask {
|
||||
}
|
||||
}
|
||||
|
||||
CompilerManager.getInstance(project).addCompilationStatusListener(new MyCompilationStatusListener(project, addedEntries), project);
|
||||
if (addedEntries.size() > 0) {
|
||||
CompilerManager.getInstance(project).addCompilationStatusListener(new MyCompilationStatusListener(project, addedEntries), project);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -483,7 +483,9 @@ public class AndroidFacet extends Facet<AndroidFacetConfiguration> {
|
||||
propertiesFile.addProperty(AndroidUtils.ANDROID_TARGET_PROPERTY, targetPropertyValue);
|
||||
}
|
||||
else {
|
||||
property.setValue(targetPropertyValue);
|
||||
if (!Comparing.equal(property.getValue(), targetPropertyValue)) {
|
||||
property.setValue(targetPropertyValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
+1
-1
@@ -103,7 +103,7 @@ public class LocalResourceManager extends ResourceManager {
|
||||
|
||||
private static void collectResourceDirs(Module module, Set<VirtualFile> result) {
|
||||
VirtualFile resDir = AndroidRootUtil.getResourceDir(module);
|
||||
if (resDir == null || !result.add(resDir)) {
|
||||
if (resDir != null && !result.add(resDir)) {
|
||||
return;
|
||||
}
|
||||
for (AndroidFacet depFacet : AndroidUtils.getAllAndroidDependencies(module, false)) {
|
||||
|
||||
+35
-1
@@ -14,6 +14,7 @@ import com.android.sdklib.SdkConstants;
|
||||
import com.intellij.ide.ui.ListCellRendererWrapper;
|
||||
import com.intellij.openapi.Disposable;
|
||||
import com.intellij.openapi.actionSystem.*;
|
||||
import com.intellij.openapi.actionSystem.ex.CheckboxAction;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.module.ModuleUtil;
|
||||
@@ -60,6 +61,7 @@ class AndroidLayoutPreviewToolWindowForm implements Disposable {
|
||||
private static final Icon ZOOM_IN_ICON = IconLoader.getIcon("/icons/zoomIn.png");
|
||||
private static final Icon ZOOM_OUT_ICON = IconLoader.getIcon("/icons/zoomOut.png");
|
||||
private static final Icon ZOOM_ACTUAL_ICON = IconLoader.getIcon("/icons/zoomActual.png");
|
||||
private static final Icon REFRESH_ICON = IconLoader.getIcon("/icons/refreshPreview.png");
|
||||
|
||||
private static final String CUSTOM_DEVICE_STRING = "Edit...";
|
||||
|
||||
@@ -239,9 +241,26 @@ class AndroidLayoutPreviewToolWindowForm implements Disposable {
|
||||
actionGroup.add(new MyZoomActualAction());
|
||||
actionGroup.add(new MyZoomInAction());
|
||||
actionGroup.add(new MyZoomOutAction());
|
||||
actionGroup.add(new MyRefreshAction());
|
||||
myActionToolBar = ActionManager.getInstance().createActionToolbar(ActionPlaces.UNKNOWN, actionGroup, true);
|
||||
myActionToolBar.setReservePlaceAutoPopupIcon(false);
|
||||
|
||||
final DefaultActionGroup optionsGroup = new DefaultActionGroup();
|
||||
final ActionToolbar optionsToolBar = ActionManager.getInstance().createActionToolbar(ActionPlaces.UNKNOWN, optionsGroup, true);
|
||||
optionsToolBar.setReservePlaceAutoPopupIcon(false);
|
||||
optionsToolBar.setSecondaryActionsTooltip("Options");
|
||||
optionsGroup.addAction(new CheckboxAction("Hide for non-layout files") {
|
||||
@Override
|
||||
public boolean isSelected(AnActionEvent e) {
|
||||
return mySettings.getState().isHideForNonLayoutFiles();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSelected(AnActionEvent e, boolean state) {
|
||||
mySettings.getState().setHideForNonLayoutFiles(state);
|
||||
}
|
||||
}).setAsSecondary(true);
|
||||
|
||||
gb.gridx = 0;
|
||||
gb.gridy++;
|
||||
final JComponent toolbar = myActionToolBar.getComponent();
|
||||
@@ -249,7 +268,11 @@ class AndroidLayoutPreviewToolWindowForm implements Disposable {
|
||||
toolBarWrapper.add(toolbar, BorderLayout.CENTER);
|
||||
toolBarWrapper.setPreferredSize(new Dimension(10, toolbar.getMinimumSize().height));
|
||||
toolBarWrapper.setMinimumSize(new Dimension(10, toolbar.getMinimumSize().height));
|
||||
myComboPanel.add(toolBarWrapper, gb);
|
||||
|
||||
final JPanel fullToolbarComponent = new JPanel(new BorderLayout());
|
||||
fullToolbarComponent.add(toolBarWrapper, BorderLayout.CENTER);
|
||||
fullToolbarComponent.add(optionsToolBar.getComponent(), BorderLayout.EAST);
|
||||
myComboPanel.add(fullToolbarComponent, gb);
|
||||
|
||||
gb.fill = GridBagConstraints.HORIZONTAL;
|
||||
myThemeCombo = new ComboBox();
|
||||
@@ -1199,4 +1222,15 @@ class AndroidLayoutPreviewToolWindowForm implements Disposable {
|
||||
myActionToolBar.updateActionsImmediately();
|
||||
}
|
||||
}
|
||||
|
||||
private class MyRefreshAction extends AnAction {
|
||||
MyRefreshAction() {
|
||||
super(AndroidBundle.message("android.layout.preview.zoom.actual.action.text"), null, REFRESH_ICON);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(AnActionEvent e) {
|
||||
myToolWindowManager.render();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+7
-4
@@ -175,7 +175,7 @@ public class AndroidLayoutPreviewToolWindowManager implements ProjectComponent {
|
||||
|
||||
((ToolWindowManagerEx)ToolWindowManager.getInstance(myProject)).addToolWindowManagerListener(new ToolWindowManagerAdapter() {
|
||||
private boolean myVisible = false;
|
||||
|
||||
|
||||
@Override
|
||||
public void stateChanged() {
|
||||
if (myProject.isDisposed()) {
|
||||
@@ -186,7 +186,7 @@ public class AndroidLayoutPreviewToolWindowManager implements ProjectComponent {
|
||||
if (window != null && window.isAvailable()) {
|
||||
final boolean visible = window.isVisible();
|
||||
AndroidLayoutPreviewToolWindowSettings.getInstance(myProject).getState().setVisible(visible);
|
||||
|
||||
|
||||
if (visible && !myVisible) {
|
||||
render();
|
||||
}
|
||||
@@ -243,16 +243,19 @@ public class AndroidLayoutPreviewToolWindowManager implements ProjectComponent {
|
||||
initToolWindow();
|
||||
}
|
||||
|
||||
final AndroidLayoutPreviewToolWindowSettings settings = AndroidLayoutPreviewToolWindowSettings.getInstance(myProject);
|
||||
final boolean hideForNonLayoutFiles = settings.getState().isHideForNonLayoutFiles();
|
||||
|
||||
if (activeEditor == null) {
|
||||
myToolWindowForm.setFile(null);
|
||||
myToolWindow.setAvailable(false, null);
|
||||
myToolWindow.setAvailable(!hideForNonLayoutFiles, null);
|
||||
return;
|
||||
}
|
||||
|
||||
final PsiFile psiFile = PsiDocumentManager.getInstance(myProject).getPsiFile(activeEditor.getDocument());
|
||||
if (psiFile == null) {
|
||||
myToolWindowForm.setFile(null);
|
||||
myToolWindow.setAvailable(false, null);
|
||||
myToolWindow.setAvailable(!hideForNonLayoutFiles, null);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
+9
@@ -43,6 +43,7 @@ public class AndroidLayoutPreviewToolWindowSettings implements PersistentStateCo
|
||||
private String myLocaleLanguage;
|
||||
private String myLocaleRegion;
|
||||
private boolean myVisible = true;
|
||||
private boolean myHideForNonLayoutFiles = true;
|
||||
|
||||
public String getDevice() {
|
||||
return myDevice;
|
||||
@@ -115,5 +116,13 @@ public class AndroidLayoutPreviewToolWindowSettings implements PersistentStateCo
|
||||
public void setVisible(boolean visible) {
|
||||
myVisible = visible;
|
||||
}
|
||||
|
||||
public boolean isHideForNonLayoutFiles() {
|
||||
return myHideForNonLayoutFiles;
|
||||
}
|
||||
|
||||
public void setHideForNonLayoutFiles(boolean hideForNonLayoutFiles) {
|
||||
myHideForNonLayoutFiles = hideForNonLayoutFiles;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<Button android:id="@+id/ok"
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content">
|
||||
<Button android:id="@+id/ok" android:layout_width="wrap_content" android:layout_height="wrap_content"
|
||||
android:text="@string/myLibResource" />
|
||||
</LinearLayout>
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content">
|
||||
<Button android:id="@+id/ok" android:layout_width="wrap_content" android:layout_height="wrap_content"
|
||||
android:text="<error>@string/myLibResource123</error>" />
|
||||
</LinearLayout>
|
||||
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="p1.p2">
|
||||
<application android:label="@string/myLibResource">
|
||||
</application>
|
||||
</manifest>
|
||||
@@ -24,9 +24,11 @@ import org.jetbrains.android.AndroidResourcesLineMarkerProvider;
|
||||
import org.jetbrains.android.AndroidResourcesLineMarkerTest;
|
||||
import org.jetbrains.android.AndroidTestCase;
|
||||
import org.jetbrains.android.facet.AndroidFacet;
|
||||
import org.jetbrains.android.inspections.AndroidDomInspection;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
@@ -55,6 +57,7 @@ public class AndroidLibraryProjectTest extends UsefulTestCase {
|
||||
super.setUp();
|
||||
final TestFixtureBuilder<IdeaProjectTestFixture> projectBuilder = IdeaTestFixtureFactory.getFixtureFactory().createFixtureBuilder();
|
||||
myFixture = JavaTestFixtureFactory.getFixtureFactory().createCodeInsightFixture(projectBuilder.getFixture());
|
||||
myFixture.enableInspections(AndroidDomInspection.class);
|
||||
|
||||
final JavaModuleFixtureBuilder appModuleBuilder = projectBuilder.addModule(JavaModuleFixtureBuilder.class);
|
||||
String appModuleDir = myFixture.getTempDirPath() + "/app";
|
||||
@@ -101,7 +104,9 @@ public class AndroidLibraryProjectTest extends UsefulTestCase {
|
||||
model2.commit();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void createInitialStructure() {
|
||||
myFixture.copyFileToProject(SdkConstants.FN_ANDROID_MANIFEST_XML, "app/" + SdkConstants.FN_ANDROID_MANIFEST_XML);
|
||||
myFixture.copyFileToProject(BASE_PATH + "LibAndroidManifest.xml", "lib/" + SdkConstants.FN_ANDROID_MANIFEST_XML);
|
||||
|
||||
@@ -129,12 +134,47 @@ public class AndroidLibraryProjectTest extends UsefulTestCase {
|
||||
}
|
||||
|
||||
public void testHighlighting() {
|
||||
createInitialStructure();
|
||||
String to = "app/res/layout/" + getTestName(true) + ".xml";
|
||||
VirtualFile file = myFixture.copyFileToProject(BASE_PATH + getTestName(true) + ".xml", to);
|
||||
myFixture.configureFromExistingVirtualFile(file);
|
||||
myFixture.doHighlighting();
|
||||
myFixture.checkHighlighting(true, true, true);
|
||||
}
|
||||
|
||||
public void testHighlighting1() {
|
||||
createInitialStructure();
|
||||
String to = "app/res/layout/" + getTestName(true) + ".xml";
|
||||
VirtualFile file = myFixture.copyFileToProject(BASE_PATH + getTestName(true) + ".xml", to);
|
||||
myFixture.configureFromExistingVirtualFile(file);
|
||||
myFixture.doHighlighting();
|
||||
myFixture.checkHighlighting(true, true, true);
|
||||
}
|
||||
|
||||
public void testHighlighting2() {
|
||||
myFixture.copyFileToProject(BASE_PATH + "LibAndroidManifest.xml", "lib/" + SdkConstants.FN_ANDROID_MANIFEST_XML);
|
||||
final VirtualFile manifestFile =
|
||||
myFixture.copyFileToProject(BASE_PATH + getTestName(true) + ".xml", "app/" + SdkConstants.FN_ANDROID_MANIFEST_XML);
|
||||
myFixture.copyDirectoryToProject(BASE_PATH + "res", "lib/res");
|
||||
myFixture.configureFromExistingVirtualFile(manifestFile);
|
||||
myFixture.doHighlighting();
|
||||
myFixture.checkHighlighting(true, true, true);
|
||||
}
|
||||
|
||||
private void doRename(final VirtualFile file, final String newName) {
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
file.rename(myFixture.getProject(), newName);
|
||||
}
|
||||
catch (IOException e) {
|
||||
new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void testCompletion() {
|
||||
doTestCompletion();
|
||||
}
|
||||
@@ -144,6 +184,7 @@ public class AndroidLibraryProjectTest extends UsefulTestCase {
|
||||
}
|
||||
|
||||
private void doTestCompletion() {
|
||||
createInitialStructure();
|
||||
String to = "app/res/layout/" + getTestName(true) + ".xml";
|
||||
VirtualFile file = myFixture.copyFileToProject(BASE_PATH + getTestName(true) + ".xml", to);
|
||||
myFixture.configureFromExistingVirtualFile(file);
|
||||
@@ -167,6 +208,7 @@ public class AndroidLibraryProjectTest extends UsefulTestCase {
|
||||
}
|
||||
|
||||
private void doTestRJavaFilesMarkers(String destPath) {
|
||||
createInitialStructure();
|
||||
List<LineMarkerInfo> markers =
|
||||
AndroidResourcesLineMarkerTest.collectMarkers(myFixture, BASE_PATH + getTestName(false) + ".java", destPath);
|
||||
assertEquals(3, markers.size());
|
||||
@@ -180,22 +222,15 @@ public class AndroidLibraryProjectTest extends UsefulTestCase {
|
||||
}
|
||||
|
||||
public void testJavaFileMarkers() throws Exception {
|
||||
createInitialStructure();
|
||||
myFixture.copyFileToProject(BASE_PATH + "RJavaFileMarkers.java", "app/src/p1/p2/R.java");
|
||||
List<LineMarkerInfo> markers =
|
||||
AndroidResourcesLineMarkerTest.collectMarkers(myFixture, BASE_PATH + getTestName(false) + ".java", "/app/src/p1/p2/Java.java");
|
||||
assertEquals(0, markers.size());
|
||||
/*for (LineMarkerInfo marker : markers) {
|
||||
PsiReferenceExpression expression = (PsiReferenceExpression)marker.getElement();
|
||||
PsiField field = (PsiField)expression.resolve();
|
||||
GutterIconNavigationHandler handler = marker.getNavigationHandler();
|
||||
assertInstanceOf(handler, AndroidResourcesLineMarkerProvider.MyLazyNavigationHandler.class);
|
||||
Computable<PsiElement[]> targetProvider = ((AndroidResourcesLineMarkerProvider.MyLazyNavigationHandler)handler).getTargetProvider();
|
||||
PsiElement[] targets = targetProvider.compute();
|
||||
checkTargets(field, targets);
|
||||
}*/
|
||||
}
|
||||
|
||||
public void testJavaNavigation() throws Exception {
|
||||
createInitialStructure();
|
||||
myFixture.copyFileToProject(BASE_PATH + "RJavaFileMarkers.java", "app/src/p1/p2/R.java");
|
||||
VirtualFile file = myFixture.copyFileToProject(BASE_PATH + getTestName(false) + ".java", "/app/src/p1/p2/Java.java");
|
||||
myFixture.configureFromExistingVirtualFile(file);
|
||||
@@ -210,6 +245,7 @@ public class AndroidLibraryProjectTest extends UsefulTestCase {
|
||||
}
|
||||
|
||||
public void testLayoutFileMarkers() throws Exception {
|
||||
createInitialStructure();
|
||||
myFixture.copyFileToProject(BASE_PATH + "RJavaFileMarkers.java", "app/src/p1/p2/R.java");
|
||||
myFixture.copyFileToProject(BASE_PATH + "RJavaFileMarkers.java", "app/src/p1/p2/lib/R.java");
|
||||
myFixture.copyFileToProject(BASE_PATH + "RJavaFileMarkers.java", "lib/src/p1/p2/lib/R.java");
|
||||
@@ -285,6 +321,7 @@ public class AndroidLibraryProjectTest extends UsefulTestCase {
|
||||
}
|
||||
|
||||
private void doFindUsagesTest(String extension, String dir) throws Throwable {
|
||||
createInitialStructure();
|
||||
myFixture.copyFileToProject(BASE_PATH + "FindUsagesClass.java", "app/src/p1/p2/Class.java");
|
||||
myFixture.copyFileToProject(BASE_PATH + "FindUsagesClass1.java", "app/src/p1/p2/lib/Class.java");
|
||||
myFixture.copyFileToProject(BASE_PATH + "FindUsagesClass1.java", "lib/src/p1/p2/lib/Class.java");
|
||||
|
||||
+1
-2
@@ -26,7 +26,6 @@ import java.io.File;
|
||||
import java.rmi.Remote;
|
||||
import java.rmi.RemoteException;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public interface MavenServerIndexer extends Remote {
|
||||
@@ -47,7 +46,7 @@ public interface MavenServerIndexer extends Remote {
|
||||
MavenServerIndexerException,
|
||||
MavenServerProcessCanceledException;
|
||||
|
||||
List<MavenId> getAllArtifacts(int indexId) throws RemoteException, MavenServerIndexerException;
|
||||
void processArtifacts(int indexId, MavenServerIndicesProcessor processor) throws RemoteException, MavenServerIndexerException;
|
||||
|
||||
MavenId addArtifact(int indexId, File artifactFile) throws RemoteException, MavenServerIndexerException;
|
||||
|
||||
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* Copyright 2000-2011 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jetbrains.idea.maven.server;
|
||||
|
||||
import org.jetbrains.idea.maven.model.MavenId;
|
||||
|
||||
import java.rmi.Remote;
|
||||
import java.rmi.RemoteException;
|
||||
import java.util.Collection;
|
||||
|
||||
public interface MavenServerIndicesProcessor extends Remote {
|
||||
void processArtifacts(Collection<MavenId> artifacts) throws RemoteException;
|
||||
}
|
||||
+14
-3
@@ -186,11 +186,14 @@ public class Maven2ServerIndexerImpl extends MavenRemoteObject implements MavenS
|
||||
}
|
||||
}
|
||||
|
||||
public List<MavenId> getAllArtifacts(int indexId) throws MavenServerIndexerException {
|
||||
public void processArtifacts(int indexId, MavenServerIndicesProcessor processor) throws MavenServerIndexerException {
|
||||
try {
|
||||
List<MavenId> result = new ArrayList<MavenId>();
|
||||
final int CHUNK_SIZE = 10000;
|
||||
|
||||
IndexReader r = getIndex(indexId).getIndexReader();
|
||||
int total = r.numDocs();
|
||||
|
||||
List<MavenId> result = new ArrayList<MavenId>(Math.min(CHUNK_SIZE, total));
|
||||
for (int i = 0; i < total; i++) {
|
||||
if (r.isDeleted(i)) continue;
|
||||
|
||||
@@ -204,8 +207,16 @@ public class Maven2ServerIndexerImpl extends MavenRemoteObject implements MavenS
|
||||
if (groupId == null || artifactId == null || version == null) continue;
|
||||
|
||||
result.add(new MavenId(groupId, artifactId, version));
|
||||
|
||||
if (result.size() == CHUNK_SIZE) {
|
||||
processor.processArtifacts(result);
|
||||
result.clear();
|
||||
}
|
||||
}
|
||||
|
||||
if (!result.isEmpty()) {
|
||||
processor.processArtifacts(result);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new MavenServerIndexerException(wrapException(e));
|
||||
|
||||
+1
-2
@@ -25,7 +25,6 @@ import org.jetbrains.idea.maven.model.MavenId;
|
||||
import java.io.File;
|
||||
import java.rmi.RemoteException;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class Maven3FacadeIndexerImpl extends MavenRemoteObject implements MavenServerIndexer {
|
||||
@@ -55,7 +54,7 @@ public class Maven3FacadeIndexerImpl extends MavenRemoteObject implements MavenS
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<MavenId> getAllArtifacts(int indexId) throws RemoteException, MavenServerIndexerException {
|
||||
public void processArtifacts(int indexId, MavenServerIndicesProcessor processor) throws RemoteException, MavenServerIndexerException {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@ import org.jetbrains.idea.maven.model.MavenArtifactInfo;
|
||||
import org.jetbrains.idea.maven.model.MavenId;
|
||||
import org.jetbrains.idea.maven.project.MavenGeneralSettings;
|
||||
import org.jetbrains.idea.maven.server.MavenIndexerWrapper;
|
||||
import org.jetbrains.idea.maven.server.MavenIndicesProcessor;
|
||||
import org.jetbrains.idea.maven.server.MavenServerIndexerException;
|
||||
import org.jetbrains.idea.maven.utils.MavenLog;
|
||||
import org.jetbrains.idea.maven.utils.MavenProcessCanceledException;
|
||||
@@ -357,37 +358,55 @@ public class MavenIndex {
|
||||
|
||||
private void doUpdateIndexData(IndexData data,
|
||||
MavenProgressIndicator progress) throws IOException, MavenServerIndexerException {
|
||||
Set<String> groups = new THashSet<String>();
|
||||
Set<String> groupsWithArtifacts = new THashSet<String>();
|
||||
Set<String> groupsWithArtifactsWithVersions = new THashSet<String>();
|
||||
final Set<String> groups = new THashSet<String>();
|
||||
final Set<String> groupsWithArtifacts = new THashSet<String>();
|
||||
final Set<String> groupsWithArtifactsWithVersions = new THashSet<String>();
|
||||
|
||||
Map<String, Set<String>> groupToArtifactMap = new THashMap<String, Set<String>>();
|
||||
Map<String, Set<String>> groupWithArtifactToVersionMap = new THashMap<String, Set<String>>();
|
||||
final Map<String, Set<String>> groupToArtifactMap = new THashMap<String, Set<String>>();
|
||||
final Map<String, Set<String>> groupWithArtifactToVersionMap = new THashMap<String, Set<String>>();
|
||||
|
||||
List<MavenId> artifacts = data.getAllArtifacts();
|
||||
int total = artifacts.size();
|
||||
for (int i = 0; i < total; i++) {
|
||||
progress.setFraction(i / total);
|
||||
MavenId each = artifacts.get(i);
|
||||
final StringBuilder builder = new StringBuilder();
|
||||
|
||||
String groupId = each.getGroupId();
|
||||
String artifactId = each.getArtifactId();
|
||||
String version = each.getVersion();
|
||||
progress.pushState();
|
||||
progress.setIndeterminate(true);
|
||||
|
||||
groups.add(groupId);
|
||||
groupsWithArtifacts.add(groupId + ":" + artifactId);
|
||||
groupsWithArtifactsWithVersions.add(groupId + ":" + artifactId + ":" + version);
|
||||
try {
|
||||
data.processArtifacts(new MavenIndicesProcessor() {
|
||||
@Override
|
||||
public void processArtifacts(Collection<MavenId> artifacts) {
|
||||
for (MavenId each : artifacts) {
|
||||
String groupId = each.getGroupId();
|
||||
String artifactId = each.getArtifactId();
|
||||
String version = each.getVersion();
|
||||
|
||||
getOrCreate(groupToArtifactMap, groupId).add(artifactId);
|
||||
getOrCreate(groupWithArtifactToVersionMap, groupId + ":" + artifactId).add(version);
|
||||
builder.setLength(0);
|
||||
|
||||
builder.append(groupId).append(":").append(artifactId);
|
||||
String ga = builder.toString();
|
||||
|
||||
builder.append(":").append(version);
|
||||
String gav = builder.toString();
|
||||
|
||||
groups.add(groupId);
|
||||
groupsWithArtifacts.add(ga);
|
||||
groupsWithArtifactsWithVersions.add(gav);
|
||||
|
||||
getOrCreate(groupToArtifactMap, groupId).add(artifactId);
|
||||
getOrCreate(groupWithArtifactToVersionMap, ga).add(version);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
persist(groups, data.groups);
|
||||
persist(groupsWithArtifacts, data.groupsWithArtifacts);
|
||||
persist(groupsWithArtifactsWithVersions, data.groupsWithArtifactsWithVersions);
|
||||
|
||||
persist(groupToArtifactMap, data.groupToArtifactMap);
|
||||
persist(groupWithArtifactToVersionMap, data.groupWithArtifactToVersionMap);
|
||||
}
|
||||
finally {
|
||||
progress.popState();
|
||||
}
|
||||
|
||||
persist(groups, data.groups);
|
||||
persist(groupsWithArtifacts, data.groupsWithArtifacts);
|
||||
persist(groupsWithArtifactsWithVersions, data.groupsWithArtifactsWithVersions);
|
||||
|
||||
persist(groupToArtifactMap, data.groupToArtifactMap);
|
||||
persist(groupWithArtifactToVersionMap, data.groupWithArtifactToVersionMap);
|
||||
}
|
||||
|
||||
private <T> Set<T> getOrCreate(Map<String, Set<T>> map, String key) {
|
||||
@@ -451,32 +470,32 @@ public class MavenIndex {
|
||||
|
||||
public synchronized void addArtifact(final File artifactFile) {
|
||||
doIndexTask(new IndexTask<Object>() {
|
||||
public Object doTask() throws Exception {
|
||||
MavenId id = myData.addArtifact(artifactFile);
|
||||
public Object doTask() throws Exception {
|
||||
MavenId id = myData.addArtifact(artifactFile);
|
||||
|
||||
String groupId = id.getGroupId();
|
||||
String artifactId = id.getArtifactId();
|
||||
String version = id.getVersion();
|
||||
String groupId = id.getGroupId();
|
||||
String artifactId = id.getArtifactId();
|
||||
String version = id.getVersion();
|
||||
|
||||
myData.groups.enumerate(groupId);
|
||||
myData.hasGroupCache.put(groupId, true);
|
||||
myData.groups.enumerate(groupId);
|
||||
myData.hasGroupCache.put(groupId, true);
|
||||
|
||||
String groupWithArtifact = groupId + ":" + artifactId;
|
||||
String groupWithArtifact = groupId + ":" + artifactId;
|
||||
|
||||
myData.groupsWithArtifacts.enumerate(groupWithArtifact);
|
||||
myData.hasArtifactCache.put(groupWithArtifact, true);
|
||||
addToCache(myData.groupToArtifactMap, groupId, artifactId);
|
||||
myData.groupsWithArtifacts.enumerate(groupWithArtifact);
|
||||
myData.hasArtifactCache.put(groupWithArtifact, true);
|
||||
addToCache(myData.groupToArtifactMap, groupId, artifactId);
|
||||
|
||||
String groupWithArtifactWithVersion = groupWithArtifact + ":" + version;
|
||||
String groupWithArtifactWithVersion = groupWithArtifact + ":" + version;
|
||||
|
||||
myData.groupsWithArtifactsWithVersions.enumerate(groupWithArtifactWithVersion);
|
||||
myData.hasVersionCache.put(groupWithArtifactWithVersion, true);
|
||||
addToCache(myData.groupWithArtifactToVersionMap, groupWithArtifact, version);
|
||||
myData.flush();
|
||||
myData.groupsWithArtifactsWithVersions.enumerate(groupWithArtifactWithVersion);
|
||||
myData.hasVersionCache.put(groupWithArtifactWithVersion, true);
|
||||
addToCache(myData.groupWithArtifactToVersionMap, groupWithArtifact, version);
|
||||
myData.flush();
|
||||
|
||||
return null;
|
||||
}
|
||||
}, null);
|
||||
return null;
|
||||
}
|
||||
}, null);
|
||||
}
|
||||
|
||||
private void addToCache(PersistentHashMap<String, Set<String>> cache, String key, String value) throws IOException {
|
||||
@@ -488,35 +507,35 @@ public class MavenIndex {
|
||||
|
||||
public synchronized Set<String> getGroupIds() {
|
||||
return doIndexTask(new IndexTask<Set<String>>() {
|
||||
public Set<String> doTask() throws Exception {
|
||||
final Set<String> result = new THashSet<String>();
|
||||
myData.groups.traverseAllRecords(new PersistentEnumerator.RecordsProcessor() {
|
||||
public boolean process(int record) throws IOException {
|
||||
result.add(myData.groups.valueOf(record));
|
||||
return true;
|
||||
}
|
||||
});
|
||||
return result;
|
||||
}
|
||||
}, Collections.<String>emptySet());
|
||||
public Set<String> doTask() throws Exception {
|
||||
final Set<String> result = new THashSet<String>();
|
||||
myData.groups.traverseAllRecords(new PersistentEnumerator.RecordsProcessor() {
|
||||
public boolean process(int record) throws IOException {
|
||||
result.add(myData.groups.valueOf(record));
|
||||
return true;
|
||||
}
|
||||
});
|
||||
return result;
|
||||
}
|
||||
}, Collections.<String>emptySet());
|
||||
}
|
||||
|
||||
public synchronized Set<String> getArtifactIds(final String groupId) {
|
||||
return doIndexTask(new IndexTask<Set<String>>() {
|
||||
public Set<String> doTask() throws Exception {
|
||||
Set<String> result = myData.groupToArtifactMap.get(groupId);
|
||||
return result == null ? Collections.<String>emptySet() : result;
|
||||
}
|
||||
}, Collections.<String>emptySet());
|
||||
public Set<String> doTask() throws Exception {
|
||||
Set<String> result = myData.groupToArtifactMap.get(groupId);
|
||||
return result == null ? Collections.<String>emptySet() : result;
|
||||
}
|
||||
}, Collections.<String>emptySet());
|
||||
}
|
||||
|
||||
public synchronized Set<String> getVersions(final String groupId, final String artifactId) {
|
||||
return doIndexTask(new IndexTask<Set<String>>() {
|
||||
public Set<String> doTask() throws Exception {
|
||||
Set<String> result = myData.groupWithArtifactToVersionMap.get(groupId + ":" + artifactId);
|
||||
return result == null ? Collections.<String>emptySet() : result;
|
||||
}
|
||||
}, Collections.<String>emptySet());
|
||||
public Set<String> doTask() throws Exception {
|
||||
Set<String> result = myData.groupWithArtifactToVersionMap.get(groupId + ":" + artifactId);
|
||||
return result == null ? Collections.<String>emptySet() : result;
|
||||
}
|
||||
}, Collections.<String>emptySet());
|
||||
}
|
||||
|
||||
public synchronized boolean hasGroupId(String groupId) {
|
||||
@@ -540,15 +559,15 @@ public class MavenIndex {
|
||||
if (cached != null) return cached;
|
||||
|
||||
boolean result = doIndexTask(new IndexTask<Boolean>() {
|
||||
public Boolean doTask() throws Exception {
|
||||
return !set.traverseAllRecords(new PersistentEnumerator.RecordsProcessor() {
|
||||
public boolean process(int record) throws IOException {
|
||||
if (value.equals(set.valueOf(record))) return false;
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
}, false).booleanValue();
|
||||
public Boolean doTask() throws Exception {
|
||||
return !set.traverseAllRecords(new PersistentEnumerator.RecordsProcessor() {
|
||||
public boolean process(int record) throws IOException {
|
||||
if (value.equals(set.valueOf(record))) return false;
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
}, false).booleanValue();
|
||||
|
||||
cache.put(value, result);
|
||||
return result;
|
||||
@@ -556,10 +575,10 @@ public class MavenIndex {
|
||||
|
||||
public synchronized Set<MavenArtifactInfo> search(final Query query, final int maxResult) {
|
||||
return doIndexTask(new IndexTask<Set<MavenArtifactInfo>>() {
|
||||
public Set<MavenArtifactInfo> doTask() throws Exception {
|
||||
return myData.search(query, maxResult);
|
||||
}
|
||||
}, Collections.<MavenArtifactInfo>emptySet());
|
||||
public Set<MavenArtifactInfo> doTask() throws Exception {
|
||||
return myData.search(query, maxResult);
|
||||
}
|
||||
}, Collections.<MavenArtifactInfo>emptySet());
|
||||
}
|
||||
|
||||
private <T> T doIndexTask(IndexTask<T> task, T defaultValue) {
|
||||
@@ -675,8 +694,8 @@ public class MavenIndex {
|
||||
groupWithArtifactToVersionMap.force();
|
||||
}
|
||||
|
||||
public List<MavenId> getAllArtifacts() throws MavenServerIndexerException {
|
||||
return myIndexer.getAllArtifacts(indexId);
|
||||
public void processArtifacts(MavenIndicesProcessor processor) throws MavenServerIndexerException {
|
||||
myIndexer.processArtifacts(indexId, processor);
|
||||
}
|
||||
|
||||
public MavenId addArtifact(File artifactFile) throws MavenServerIndexerException {
|
||||
|
||||
+11
-5
@@ -32,7 +32,6 @@ import java.io.File;
|
||||
import java.rmi.RemoteException;
|
||||
import java.rmi.server.UnicastRemoteObject;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public abstract class MavenIndexerWrapper extends RemoteObjectWrapper<MavenServerIndexer> {
|
||||
@@ -118,11 +117,18 @@ public abstract class MavenIndexerWrapper extends RemoteObjectWrapper<MavenServe
|
||||
});
|
||||
}
|
||||
|
||||
public List<MavenId> getAllArtifacts(final int indexId) throws MavenServerIndexerException {
|
||||
return perform(new IndexRetriable<List<MavenId>>() {
|
||||
public void processArtifacts(final int indexId, final MavenIndicesProcessor processor) throws MavenServerIndexerException {
|
||||
perform(new IndexRetriable<Object>() {
|
||||
@Override
|
||||
public List<MavenId> execute() throws RemoteException, MavenServerIndexerException {
|
||||
return getOrCreateWrappee().getAllArtifacts(getRemoteId(indexId));
|
||||
public Object execute() throws RemoteException, MavenServerIndexerException {
|
||||
MavenServerIndicesProcessor processorWrapper = MavenServerManager.wrapAndExport(processor);
|
||||
try {
|
||||
getOrCreateWrappee().processArtifacts(getRemoteId(indexId), processorWrapper);
|
||||
}
|
||||
finally {
|
||||
UnicastRemoteObject.unexportObject(processorWrapper, true);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* Copyright 2000-2011 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jetbrains.idea.maven.server;
|
||||
|
||||
import org.jetbrains.idea.maven.model.MavenId;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
public interface MavenIndicesProcessor {
|
||||
void processArtifacts(Collection<MavenId> artifacts);
|
||||
}
|
||||
@@ -50,6 +50,7 @@ import org.apache.lucene.search.Query;
|
||||
import org.jdom.Element;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.idea.maven.model.MavenId;
|
||||
import org.jetbrains.idea.maven.model.MavenModel;
|
||||
import org.jetbrains.idea.maven.project.MavenConsole;
|
||||
import org.jetbrains.idea.maven.project.MavenGeneralSettings;
|
||||
@@ -339,6 +340,17 @@ public class MavenServerManager extends RemoteObjectWrapper<MavenServer> {
|
||||
}
|
||||
}
|
||||
|
||||
public static MavenServerIndicesProcessor wrapAndExport(final MavenIndicesProcessor processor) {
|
||||
try {
|
||||
RemoteMavenServerIndicesProcessor result = new RemoteMavenServerIndicesProcessor(processor);
|
||||
UnicastRemoteObject.exportObject(result, 0);
|
||||
return result;
|
||||
}
|
||||
catch (RemoteException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private static class RemoteMavenServerLogger extends MavenRemoteObject implements MavenServerLogger {
|
||||
public void info(Throwable e) {
|
||||
MavenLog.LOG.info(e);
|
||||
@@ -407,4 +419,17 @@ public class MavenServerManager extends RemoteObjectWrapper<MavenServer> {
|
||||
myConsole.printMessage(level, message, throwable);
|
||||
}
|
||||
}
|
||||
|
||||
private static class RemoteMavenServerIndicesProcessor extends MavenRemoteObject implements MavenServerIndicesProcessor {
|
||||
private final MavenIndicesProcessor myProcessor;
|
||||
|
||||
private RemoteMavenServerIndicesProcessor(MavenIndicesProcessor processor) {
|
||||
myProcessor = processor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processArtifacts(Collection<MavenId> artifacts) {
|
||||
myProcessor.processArtifacts(artifacts);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+12
@@ -59,6 +59,18 @@ public class MavenProgressIndicator {
|
||||
myIndicator.setFraction(fraction);
|
||||
}
|
||||
|
||||
public synchronized void setIndeterminate(boolean indeterminate) {
|
||||
myIndicator.setIndeterminate(indeterminate);
|
||||
}
|
||||
|
||||
public synchronized void pushState() {
|
||||
myIndicator.pushState();
|
||||
}
|
||||
|
||||
public synchronized void popState() {
|
||||
myIndicator.popState();
|
||||
}
|
||||
|
||||
public synchronized void cancel() {
|
||||
myIndicator.cancel();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user