Skip to content

The Unified and Autonomous Development Platform

Do not consider performance for now!

robin shine8729120cd603
diff --git a/commons.lang/src/main/java/com/pmease/commons/lang/AnalyzeResult.java b/commons.lang/src/main/java/com/pmease/commons/lang/AnalyzeResult.java
index 9e4fe61ce3..ad98570837 100644
--- a/commons.lang/src/main/java/com/pmease/commons/lang/AnalyzeResult.java
+++ b/commons.lang/src/main/java/com/pmease/commons/lang/AnalyzeResult.java
@@ -1,6 +1,5 @@
package com.pmease.commons.lang;
-import java.util.Collection;
import java.util.List;
import javax.annotation.Nullable;
diff --git a/commons.lang/src/main/java/com/pmease/commons/lang/LangToken.java b/commons.lang/src/main/java/com/pmease/commons/lang/LangToken.java
index d56aa2435a..2015e8d533 100644
--- a/commons.lang/src/main/java/com/pmease/commons/lang/LangToken.java
+++ b/commons.lang/src/main/java/com/pmease/commons/lang/LangToken.java
@@ -1,10 +1,14 @@
package com.pmease.commons.lang;
+import java.io.Serializable;
+
import org.antlr.v4.runtime.Token;
import com.google.common.base.Objects;
-public class LangToken {
+public class LangToken implements Serializable {
+
+ private static final long serialVersionUID = 1L;
public static final LangToken EOF = new LangToken(Token.EOF, "", -1, -1);
diff --git a/commons.lang/src/main/java/com/pmease/commons/lang/Outline.java b/commons.lang/src/main/java/com/pmease/commons/lang/Outline.java
index b319236a6d..b5dd2f0200 100644
--- a/commons.lang/src/main/java/com/pmease/commons/lang/Outline.java
+++ b/commons.lang/src/main/java/com/pmease/commons/lang/Outline.java
@@ -1,8 +1,8 @@
package com.pmease.commons.lang;
-import java.util.Collection;
+import java.io.Serializable;
import java.util.List;
-public interface Outline {
+public interface Outline extends Serializable {
List<LangToken> getSymbols();
}
diff --git a/commons.lang/src/main/java/com/pmease/commons/lang/java/FieldDef.java b/commons.lang/src/main/java/com/pmease/commons/lang/java/FieldDef.java
index 908d15ea0e..f94b221849 100644
--- a/commons.lang/src/main/java/com/pmease/commons/lang/java/FieldDef.java
+++ b/commons.lang/src/main/java/com/pmease/commons/lang/java/FieldDef.java
@@ -1,5 +1,6 @@
package com.pmease.commons.lang.java;
+import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
@@ -7,8 +8,10 @@ import javax.annotation.Nullable;
import com.pmease.commons.lang.LangToken;
-public class FieldDef {
+public class FieldDef implements Serializable {
+ private static final long serialVersionUID = 1L;
+
public LangToken name;
/**
diff --git a/commons.lang/src/main/java/com/pmease/commons/lang/java/JavaAnalyzer.java b/commons.lang/src/main/java/com/pmease/commons/lang/java/JavaAnalyzer.java
index c29ecdbe9f..2a1aad788e 100644
--- a/commons.lang/src/main/java/com/pmease/commons/lang/java/JavaAnalyzer.java
+++ b/commons.lang/src/main/java/com/pmease/commons/lang/java/JavaAnalyzer.java
@@ -105,7 +105,7 @@ public class JavaAnalyzer extends AbstractAnalyzer {
} else {
skipModifiers(stream); // skip annotations applied to method return type
token = stream.current();
- if (token.getText().equals(typeDef.name) && stream.lookAhead(1).is(LPAREN)) {
+ if (token.getText().equals(typeDef.name.getText()) && stream.lookAhead(1).is(LPAREN)) {
// this is a constructor
typeDef.methodDefs.add(defineMethod(stream, modifiers, null));
} else {
diff --git a/commons.lang/src/main/java/com/pmease/commons/lang/java/JavaOutline.java b/commons.lang/src/main/java/com/pmease/commons/lang/java/JavaOutline.java
index d0cc97ce59..66177c6ca8 100644
--- a/commons.lang/src/main/java/com/pmease/commons/lang/java/JavaOutline.java
+++ b/commons.lang/src/main/java/com/pmease/commons/lang/java/JavaOutline.java
@@ -11,6 +11,8 @@ import com.pmease.commons.lang.Outline;
public class JavaOutline implements Outline {
+ private static final long serialVersionUID = 1L;
+
@Nullable
public String packageName;
diff --git a/commons.lang/src/main/java/com/pmease/commons/lang/java/MethodDef.java b/commons.lang/src/main/java/com/pmease/commons/lang/java/MethodDef.java
index 4dc1c7f8a7..26db4b4374 100644
--- a/commons.lang/src/main/java/com/pmease/commons/lang/java/MethodDef.java
+++ b/commons.lang/src/main/java/com/pmease/commons/lang/java/MethodDef.java
@@ -1,5 +1,6 @@
package com.pmease.commons.lang.java;
+import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
@@ -7,7 +8,9 @@ import javax.annotation.Nullable;
import com.pmease.commons.lang.LangToken;
-public class MethodDef {
+public class MethodDef implements Serializable {
+
+ private static final long serialVersionUID = 1L;
public LangToken name;
diff --git a/commons.lang/src/main/java/com/pmease/commons/lang/java/TypeDef.java b/commons.lang/src/main/java/com/pmease/commons/lang/java/TypeDef.java
index 88ac89b01f..83d2123345 100644
--- a/commons.lang/src/main/java/com/pmease/commons/lang/java/TypeDef.java
+++ b/commons.lang/src/main/java/com/pmease/commons/lang/java/TypeDef.java
@@ -1,5 +1,6 @@
package com.pmease.commons.lang.java;
+import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
@@ -7,7 +8,9 @@ import com.google.common.base.Joiner;
import com.google.common.base.Splitter;
import com.pmease.commons.lang.LangToken;
-public class TypeDef {
+public class TypeDef implements Serializable {
+
+ private static final long serialVersionUID = 1L;
public enum Kind {
CLASS,
diff --git a/commons.lang/src/test/java/com/pmease/commons/lang/java/JavaAnalyzerTest.java b/commons.lang/src/test/java/com/pmease/commons/lang/java/JavaAnalyzerTest.java
index 40dee3e4ab..fa2944903a 100644
--- a/commons.lang/src/test/java/com/pmease/commons/lang/java/JavaAnalyzerTest.java
+++ b/commons.lang/src/test/java/com/pmease/commons/lang/java/JavaAnalyzerTest.java
@@ -1,8 +1,12 @@
package com.pmease.commons.lang.java;
+import java.io.File;
+import java.io.IOException;
+
import org.junit.Test;
import com.pmease.commons.lang.AnalyzerTest;
+import com.pmease.commons.util.FileUtils;
public class JavaAnalyzerTest extends AnalyzerTest {
@@ -29,5 +33,12 @@ public class JavaAnalyzerTest extends AnalyzerTest {
assertOutline(readFile("Resource.outline"),
new JavaAnalyzer().analyze(readFile("Resource.source")));
}
-
+
+ @Test
+ public void testMine() throws IOException {
+ for (File file: FileUtils.listFiles(new File("w:\\temp\\commons"), "**/*.java")) {
+ System.out.println(file);
+ new JavaAnalyzer().analyze(FileUtils.readFileToString(file));
+ }
+ }
}
diff --git a/gitplex.product/src/test/java/gitplex/product/Test.java b/gitplex.product/src/test/java/gitplex/product/Test.java
index f493b417d1..b0c5ec4ae4 100644
--- a/gitplex.product/src/test/java/gitplex/product/Test.java
+++ b/gitplex.product/src/test/java/gitplex/product/Test.java
@@ -2,199 +2,39 @@ package gitplex.product;
import java.io.File;
import java.io.IOException;
-import java.nio.charset.Charset;
-import java.util.concurrent.atomic.AtomicInteger;
-import org.apache.lucene.analysis.Analyzer;
-import org.apache.lucene.analysis.standard.StandardAnalyzer;
-import org.apache.lucene.document.Document;
-import org.apache.lucene.document.Field.Store;
-import org.apache.lucene.document.StringField;
-import org.apache.lucene.document.TextField;
-import org.apache.lucene.index.AtomicReaderContext;
-import org.apache.lucene.index.DirectoryReader;
-import org.apache.lucene.index.IndexReader;
-import org.apache.lucene.index.IndexWriter;
-import org.apache.lucene.index.IndexWriterConfig;
-import org.apache.lucene.index.IndexWriterConfig.OpenMode;
-import org.apache.lucene.index.Term;
-import org.apache.lucene.search.BooleanClause.Occur;
-import org.apache.lucene.search.BooleanQuery;
-import org.apache.lucene.search.Collector;
-import org.apache.lucene.search.IndexSearcher;
-import org.apache.lucene.search.Scorer;
-import org.apache.lucene.search.TermQuery;
-import org.apache.lucene.search.TopDocs;
-import org.apache.lucene.store.Directory;
-import org.apache.lucene.store.FSDirectory;
-import org.apache.lucene.util.Version;
-import org.eclipse.jgit.api.Git;
-import org.eclipse.jgit.lib.AnyObjectId;
-import org.eclipse.jgit.lib.FileMode;
-import org.eclipse.jgit.lib.ObjectId;
-import org.eclipse.jgit.lib.ObjectLoader;
-import org.eclipse.jgit.revwalk.RevCommit;
-import org.eclipse.jgit.revwalk.RevTree;
-import org.eclipse.jgit.revwalk.RevWalk;
-import org.eclipse.jgit.treewalk.TreeWalk;
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.lang3.SerializationUtils;
-import com.google.common.base.Throwables;
-import com.pmease.commons.util.Charsets;
+import com.pmease.commons.lang.Outline;
+import com.pmease.commons.lang.java.JavaAnalyzer;
public class Test {
- @org.junit.Test
- public void test3() throws IOException {
- Git jgit = Git.open(new File("w:\\mozilla\\.git"));
- AnyObjectId id = jgit.getRepository().resolve("6f5121bd65873a784b61f6b8959ec5197ecb5d23");
- System.out.println(jgit.getRepository().hasObject(id));
- jgit.close();
- }
-
- @org.junit.Test
- public void test2() throws IOException {
- Git jgit = Git.open(new File("w:\\mozilla\\.git"));
- try {
- org.eclipse.jgit.lib.Repository jgitRepo = jgit.getRepository();
- RevWalk revWalk = new RevWalk(jgitRepo);
- RevCommit commit = revWalk.parseCommit(jgitRepo.resolve("master"));
-
- long time = System.currentTimeMillis();
- File dir = new File("W:\\mozilla");
- for (File file: new File("W:\\mozilla\\content\\html\\content\\src").listFiles()) {
- String path = file.getAbsolutePath().substring(dir.getAbsolutePath().length()+1).replace('\\', '/');
- TreeWalk treeWalk = TreeWalk.forPath(jgitRepo, path, commit.getTree());
- jgitRepo.open(treeWalk.getObjectId(0)).getCachedBytes();
- }
- System.out.println(System.currentTimeMillis()-time);
- } catch (Exception e) {
- Throwables.propagate(e);
- } finally {
- jgit.close();
- }
- }
-
@org.junit.Test
public void test() throws IOException {
- Directory directory = FSDirectory.open(new File("w:\\temp\\index"));
- Analyzer analyzer = new StandardAnalyzer();
- IndexWriterConfig iwc = new IndexWriterConfig(Version.LATEST, analyzer);
- iwc.setOpenMode(OpenMode.CREATE_OR_APPEND);
+ String text = FileUtils.readFileToString(new File("w:\\temp\\RequestDetailPage.java"));
- try (IndexReader indexReader = DirectoryReader.open(directory); IndexWriter writer = new IndexWriter(directory, iwc)) {
- Git jgit = Git.open(new File("w:\\linux\\.git"));
- try {
- org.eclipse.jgit.lib.Repository jgitRepo = jgit.getRepository();
-
- ObjectId commitId = jgitRepo.resolve("master");
- RevWalk revWalk = new RevWalk(jgitRepo);
- RevCommit commit = revWalk.parseCommit(commitId);
- RevTree revTree = commit.getTree();
- TreeWalk treeWalk = new TreeWalk(jgitRepo);
- treeWalk.addTree(revTree);
- treeWalk.setRecursive(true);
-
- while (treeWalk.next()) {
- if ((treeWalk.getRawMode(0) & FileMode.TYPE_MASK) == FileMode.TYPE_FILE) {
- ObjectLoader loader = jgitRepo.open(treeWalk.getObjectId(0));
- if (loader.getSize() <= 1000000) {
- byte[] bytes = loader.getCachedBytes();
- Charset charset = Charsets.detectFrom(bytes);
- if (charset != null) {
- String content = new String(bytes, charset);
- Document doc = new Document();
-
- doc.add(new StringField("blobId", treeWalk.getObjectId(0).getName(), Store.YES));
- doc.add(new StringField("path", treeWalk.getPathString(), Store.YES));
- doc.add(new TextField("content", content, Store.NO));
-
- IndexSearcher searcher = new IndexSearcher(indexReader);
- BooleanQuery query = new BooleanQuery();
- query.add(new TermQuery(new Term("blobId", treeWalk.getObjectId(0).getName())), Occur.MUST);
- query.add(new TermQuery(new Term("path", treeWalk.getPathString())), Occur.MUST);
-
- TopDocs docs = searcher.search(query, 1);
- if (docs.totalHits == 0) {
- writer.addDocument(doc);
- }
- }
- }
- }
- }
- writer.commit();
- } catch (Exception e) {
- writer.rollback();
- Throwables.propagate(e);
- } finally {
- jgit.close();
- }
+ Outline outline = new JavaAnalyzer().analyze(text).getOutline();
+ String defs = outline.toString();
+ byte[] defBytes = SerializationUtils.serialize(defs);
+
+ System.out.println("defs size: " + defs.length()*2);
+ System.out.println("defBytes size: " + defBytes.length);
+
+ long time = System.currentTimeMillis();
+ for (int i=0; i<100; i++) {
+ SerializationUtils.deserialize(defBytes);
}
- }
-
- @org.junit.Test
- public void test4() throws IOException {
- Directory directory = FSDirectory.open(new File("w:\\temp\\index"));
- Analyzer analyzer = new StandardAnalyzer();
- IndexWriterConfig iwc = new IndexWriterConfig(Version.LATEST, analyzer);
- iwc.setOpenMode(OpenMode.CREATE_OR_APPEND);
+ System.out.println(System.currentTimeMillis()-time);
- try (IndexWriter writer = new IndexWriter(directory, iwc)) {
- Document doc1 = new Document();
- doc1.add(new TextField("animals", "tiger lion", Store.YES));
- doc1.add(new TextField("fruits", "apple pear", Store.YES));
- writer.addDocument(doc1);
-
- Document doc2 = new Document();
- doc2.add(new TextField("animals", "lion tiger", Store.YES));
- doc2.add(new TextField("fruits", "apple pear", Store.YES));
- writer.addDocument(doc2);
-
- writer.commit();
+ JavaAnalyzer analyzer = new JavaAnalyzer();
+ time = System.currentTimeMillis();
+ for (int i=0; i<100; i++) {
+ analyzer.analyze(defs);
}
+ System.out.println(System.currentTimeMillis()-time);
+
}
- @org.junit.Test
- public void test5() throws IOException {
- Directory directory = FSDirectory.open(new File("w:\\temp\\index"));
-
- try (IndexReader reader = DirectoryReader.open(directory)) {
- final IndexSearcher searcher = new IndexSearcher(reader);
- final AtomicInteger count = new AtomicInteger(0);
-
- for (int i=0; i<10; i++) {
- long time = System.currentTimeMillis();
- searcher.search(new TermQuery(new Term("content", "void")), new Collector() {
-
- @Override
- public void setScorer(Scorer scorer) throws IOException {
- // TODO Auto-generated method stub
-
- }
-
- @Override
- public void collect(int doc) throws IOException {
- Document docu = searcher.doc(doc);
- docu.get("blobId");
- docu.get("path");
- count.incrementAndGet();
- }
-
- @Override
- public void setNextReader(AtomicReaderContext context)
- throws IOException {
-
- }
-
- @Override
- public boolean acceptsDocsOutOfOrder() {
- // TODO Auto-generated method stub
- return false;
- }
-
- });
- System.out.println("count: " + count.get());
- System.out.println("time: " + (System.currentTimeMillis()-time));
- }
- }
- }
}
\ No newline at end of file
diff --git a/gitplex.search/src/main/java/com/pmease/gitplex/search/DefaultSearchManager.java b/gitplex.search/src/main/java/com/pmease/gitplex/search/DefaultSearchManager.java
index afe6bdbb27..3aea1e61a1 100644
--- a/gitplex.search/src/main/java/com/pmease/gitplex/search/DefaultSearchManager.java
+++ b/gitplex.search/src/main/java/com/pmease/gitplex/search/DefaultSearchManager.java
@@ -28,7 +28,6 @@ import org.eclipse.jgit.treewalk.TreeWalk;
import com.google.common.base.Preconditions;
import com.google.common.base.Throwables;
-import com.google.common.eventbus.EventBus;
import com.pmease.commons.git.GitUtils;
import com.pmease.commons.lang.Analyzers;
import com.pmease.commons.util.Charsets;
@@ -43,8 +42,7 @@ public class DefaultSearchManager implements SearchManager {
private final Analyzers analyzers;
@Inject
- public DefaultSearchManager(EventBus eventBus, StorageManager storageManager, Analyzers analyzers) {
- eventBus.register(this);
+ public DefaultSearchManager(StorageManager storageManager, Analyzers analyzers) {
this.storageManager = storageManager;
this.analyzers = analyzers;
}
diff --git a/gitplex.search/src/test/java/com/pmease/gitplex/search/DefaultIndexManagerTest.java b/gitplex.search/src/test/java/com/pmease/gitplex/search/DefaultIndexManagerTest.java
index 0322b6b16b..90cfb3df02 100644
--- a/gitplex.search/src/test/java/com/pmease/gitplex/search/DefaultIndexManagerTest.java
+++ b/gitplex.search/src/test/java/com/pmease/gitplex/search/DefaultIndexManagerTest.java
@@ -150,6 +150,8 @@ public class DefaultIndexManagerTest extends AbstractGitTest {
symbols.add(new LangToken(0, "tiger", 0, 0));
AnalyzeResult analyzeResult = new AnalyzeResult(symbols, new Outline() {
+ private static final long serialVersionUID = 1L;
+
@Override
public List<LangToken> getSymbols() {
return symbols;
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/TestPage.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/TestPage.java
index eeb0a008c8..7909b69d42 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/TestPage.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/TestPage.java
@@ -44,7 +44,7 @@ public class TestPage extends CommonPage {
long time = System.currentTimeMillis();
System.out.println(searchManager.search(repo, repo.git().parseRevision("master", true),
- FieldConstants.BLOB_SYMBOLS.query("ext2_acl_from_disk"), null, 0).size());
+ FieldConstants.BLOB_SYMBOLS.query("string"), null, 0).size());
System.out.println("time: " + (System.currentTimeMillis()-time));
}