Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Refactor for History enumeration and ObjectStreamHandler #3271

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions dev/checkstyle/suppressions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ Portions Copyright (c) 2018-2020, Chris Fraire <[email protected]>.

<suppress checks="LineLength" files="CustomSloppyPhraseScorer\.java" />

<suppress checks="AnonInnerLength" files="Executor\.java" />

<suppress checks="EmptyBlock" files="JFlexNonXref\.java|JavaClassAnalyzer\.java|JFlexXref\.java|Util\.java|
|ClearCaseRepository\.java" />

Expand Down
18 changes: 18 additions & 0 deletions opengrok-indexer/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,26 @@ Portions Copyright (c) 2020-2020, Lubos Kosco <[email protected]>.
<artifactId>micrometer-registry-prometheus</artifactId>
<version>${micrometer.version}</version>
</dependency>
<dependency>
<groupId>com.oath.halodb</groupId>
<artifactId>halodb</artifactId>
<version>0.5.3</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-nop</artifactId>
<version>1.7.26</version>
</dependency>
</dependencies>

<repositories>
<repository>
<id>yahoo-bintray</id>
<name>yahoo-bintray</name>
<url>https://yahoo.bintray.com/maven</url>
</repository>
</repositories>

<build>
<plugins>
<!-- jflex:generate plugin HAS to be the first one which runs in generate-sources phase!!! -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

/*
* Copyright (c) 2008, 2019, Oracle and/or its affiliates. All rights reserved.
* Portions Copyright (c) 2019, Chris Fraire <[email protected]>.
*/
package org.opengrok.indexer.history;

Expand Down Expand Up @@ -49,9 +50,8 @@ public class AccuRevHistoryParser implements Executor.StreamHandler {
* @param file the file to parse history for
* @param repos Pointer to the {@code AccuRevRepository}
* @return object representing the file's history
* @throws HistoryException if a problem occurs while executing p4 command
*/
History parse(File file, Repository repos) throws HistoryException {
History parse(File file, Repository repos) {

repository = (AccuRevRepository) repos;

Expand All @@ -68,26 +68,19 @@ History parse(File file, Repository repos) throws HistoryException {

if (relPath.equals(rootRelativePath)) {

List<HistoryEntry> entries = new ArrayList<HistoryEntry>();
List<HistoryEntry> entries = new ArrayList<>();

entries.add(new HistoryEntry(
"", new Date(), "OpenGrok", null, "Workspace Root", true));

history = new History(entries);

} else {
try {
/*
* Errors will be logged, so not bothering to add to the output.
*/
Executor executor = repository.getHistoryLogExecutor(file);
executor.exec(true, this);

} catch (IOException e) {
throw new HistoryException(
"Failed to get history for: \""
+ file.getAbsolutePath() + "\"" + e);
}
/*
* Errors will be logged, so not bothering to add to the output.
*/
Executor executor = repository.getHistoryLogExecutor(file);
executor.exec(true, this);
}

return history;
Expand All @@ -96,7 +89,7 @@ History parse(File file, Repository repos) throws HistoryException {
public void processStream(InputStream input) throws IOException {

BufferedReader in = new BufferedReader(new InputStreamReader(input));
List<HistoryEntry> entries = new ArrayList<HistoryEntry>();
List<HistoryEntry> entries = new ArrayList<>();
String line;
String user;
Date date;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

/*
* Copyright (c) 2008, 2018, Oracle and/or its affiliates. All rights reserved.
* Portions Copyright (c) 2018, Chris Fraire <[email protected]>.
* Portions Copyright (c) 2018-2019, Chris Fraire <[email protected]>.
*/
package org.opengrok.indexer.history;

Expand Down Expand Up @@ -108,7 +108,7 @@ public AccuRevRepository() {
}

@Override
public Annotation annotate(File file, String rev) throws IOException {
public Annotation annotate(File file, String rev) {

ArrayList<String> cmd = new ArrayList<>();

Expand Down Expand Up @@ -141,7 +141,7 @@ public Annotation annotate(File file, String rev) throws IOException {
* @param file file for which history is to be retrieved.
* @return An Executor ready to be started
*/
Executor getHistoryLogExecutor(File file) throws IOException {
Executor getHistoryLogExecutor(File file) {

// Do not use absolute paths because symbolic links will cause havoc.
String path = getDepotRelativePath( file );
Expand Down Expand Up @@ -455,12 +455,12 @@ boolean hasHistoryForDirectories() {
}

@Override
History getHistory(File file) throws HistoryException {
return new AccuRevHistoryParser().parse(file, this);
HistoryEnumeration getHistory(File file) throws HistoryException {
return new SingleHistory(new AccuRevHistoryParser().parse(file, this));
}

@Override
String determineParent(CommandTimeoutType cmdType) throws IOException {
String determineParent(CommandTimeoutType cmdType) {
getAccuRevInfo(new File(getDirectoryName()), cmdType);
return parentInfo;
}
Expand All @@ -471,7 +471,7 @@ String determineBranch(CommandTimeoutType cmdType) {
}

@Override
String determineCurrentVersion(CommandTimeoutType cmdType) throws IOException {
String determineCurrentVersion(CommandTimeoutType cmdType) {
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

/*
* Copyright (c) 2008, 2020, Oracle and/or its affiliates. All rights reserved.
* Portions Copyright (c) 2017, Chris Fraire <[email protected]>.
* Portions Copyright (c) 2017, 2019, Chris Fraire <[email protected]>.
*/
package org.opengrok.indexer.history;

Expand Down Expand Up @@ -50,8 +50,8 @@ class BazaarHistoryParser implements Executor.StreamHandler {
private static final Logger LOGGER = LoggerFactory.getLogger(BazaarHistoryParser.class);

private String myDir;
private List<HistoryEntry> entries = new ArrayList<>(); //NOPMD
private BazaarRepository repository = new BazaarRepository(); //NOPMD
private final List<HistoryEntry> entries = new ArrayList<>(); //NOPMD
private final BazaarRepository repository;

BazaarHistoryParser(BazaarRepository repository) {
this.repository = repository;
Expand Down Expand Up @@ -93,12 +93,11 @@ History parse(File file, String sinceRevision) throws HistoryException {
@Override
public void processStream(InputStream input) throws IOException {
RuntimeEnvironment env = RuntimeEnvironment.getInstance();

BufferedReader in = new BufferedReader(new InputStreamReader(input));
String s;

HistoryEntry entry = null;
int state = 0;

String s;
while ((s = in.readLine()) != null) {
if ("------------------------------------------------------------".equals(s)) {
if (entry != null && state > 2) {
Expand Down Expand Up @@ -169,8 +168,8 @@ public void processStream(InputStream input) throws IOException {

File f = new File(myDir, s);
try {
String name = env.getPathRelativeToSourceRoot(f);
entry.addFile(name.intern());
String path = env.getPathRelativeToSourceRoot(f);
entry.addFile(path);
} catch (ForbiddenSymlinkException e) {
LOGGER.log(Level.FINER, e.getMessage());
// ignored
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

/*
* Copyright (c) 2008, 2019, Oracle and/or its affiliates. All rights reserved.
* Portions Copyright (c) 2017-2018, Chris Fraire <[email protected]>.
* Portions Copyright (c) 2017-2019, Chris Fraire <[email protected]>.
*/
package org.opengrok.indexer.history;

Expand Down Expand Up @@ -77,7 +77,7 @@ Executor getHistoryLogExecutor(final File file, final String sinceRevision)
throws IOException {
String filename = getRepoRelativePath(file);

List<String> cmd = new ArrayList<String>();
List<String> cmd = new ArrayList<>();
ensureCommand(CMD_PROPERTY_KEY, CMD_FALLBACK);
cmd.add(RepoCommand);
cmd.add("log");
Expand Down Expand Up @@ -202,19 +202,19 @@ boolean hasHistoryForDirectories() {
}

@Override
History getHistory(File file, String sinceRevision) throws HistoryException {
HistoryEnumeration getHistory(File file, String sinceRevision) throws HistoryException {
RuntimeEnvironment env = RuntimeEnvironment.getInstance();
History result = new BazaarHistoryParser(this).parse(file, sinceRevision);
// Assign tags to changesets they represent
// We don't need to check if this repository supports tags, because we know it:-)
if (env.isTagsEnabled()) {
assignTagsInHistory(result);
}
return result;
return new SingleHistory(result);
}

@Override
History getHistory(File file) throws HistoryException {
HistoryEnumeration getHistory(File file) throws HistoryException {
return getHistory(file, null);
}

Expand Down Expand Up @@ -271,7 +271,7 @@ String determineBranch(CommandTimeoutType cmdType) {
}

@Override
String determineCurrentVersion(CommandTimeoutType cmdType) throws IOException {
String determineCurrentVersion(CommandTimeoutType cmdType) {
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

/*
* Copyright (c) 2012, 2018, Oracle and/or its affiliates. All rights reserved.
* Portions Copyright (c) 2019, Chris Fraire <[email protected]>.
*/
package org.opengrok.indexer.history;

Expand All @@ -37,6 +38,6 @@ public BazaarTagEntry(int revision, String tag) {
@Override
public int compareTo(HistoryEntry that) {
assert this.revision != NOREV : "BazaarTagEntry created without tag specified.specified";
return ((Integer) this.revision).compareTo(Integer.parseInt(that.getRevision()));
return Integer.compare(this.revision, Integer.parseInt(that.getRevision()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
/*
* Author: James Service <[email protected]>
* Portions by: Oracle and/or its affiliates.
* Portions Copyright (c) 2018, Chris Fraire <[email protected]>.
* Portions Copyright (c) 2018-2019, Chris Fraire <[email protected]>.
*/

package org.opengrok.indexer.history;
Expand Down Expand Up @@ -168,7 +168,7 @@ public Version getVersion() {
* @return null
*/
@Override
String determineBranch(CommandTimeoutType cmdType) throws IOException {
String determineBranch(CommandTimeoutType cmdType) {
return null;
}

Expand All @@ -181,7 +181,7 @@ String determineBranch(CommandTimeoutType cmdType) throws IOException {
String determineParent(CommandTimeoutType cmdType) throws IOException {
final File directory = new File(getDirectoryName());

final ArrayList<String> argv = new ArrayList<String>();
final ArrayList<String> argv = new ArrayList<>();
ensureCommand(CMD_PROPERTY_KEY, CMD_FALLBACK);
argv.add(RepoCommand);
argv.add("parent");
Expand Down Expand Up @@ -232,7 +232,7 @@ public boolean fileHasHistory(File file) {
final File directory = absolute.getParentFile();
final String basename = absolute.getName();

final ArrayList<String> argv = new ArrayList<String>();
final ArrayList<String> argv = new ArrayList<>();
ensureCommand(CMD_PROPERTY_KEY, CMD_FALLBACK);
argv.add(RepoCommand);
argv.add("files");
Expand All @@ -251,10 +251,10 @@ public boolean fileHasHistory(File file) {
* Construct a History for a file in this repository.
*
* @param file a file in the repository
* @return history a history object
* @return history a history sequence
*/
@Override
History getHistory(File file) throws HistoryException {
HistoryEnumeration getHistory(File file) throws HistoryException {
return getHistory(file, null);
}

Expand All @@ -263,15 +263,15 @@ History getHistory(File file) throws HistoryException {
*
* @param file a file in the repository
* @param sinceRevision omit history from before, and including, this revision
* @return history a history object
* @return history a history sequence
*/
@Override
History getHistory(File file, String sinceRevision) throws HistoryException {
HistoryEnumeration getHistory(File file, String sinceRevision) throws HistoryException {
final File absolute = file.getAbsoluteFile();
final File directory = absolute.getParentFile();
final String basename = absolute.getName();

final ArrayList<String> argv = new ArrayList<String>();
final ArrayList<String> argv = new ArrayList<>();
ensureCommand(CMD_PROPERTY_KEY, CMD_FALLBACK);
argv.add(RepoCommand);
argv.add("log");
Expand All @@ -297,15 +297,15 @@ History getHistory(File file, String sinceRevision) throws HistoryException {
assignTagsInHistory(history);
}

return history;
return new SingleHistory(history);
}

@Override
boolean getHistoryGet(
BufferSink sink, String parent, String basename, String revision) {

final File directory = new File(parent).getAbsoluteFile();
final ArrayList<String> argv = new ArrayList<String>();
final ArrayList<String> argv = new ArrayList<>();
ensureCommand(CMD_PROPERTY_KEY, CMD_FALLBACK);
argv.add(RepoCommand);
argv.add("get");
Expand Down Expand Up @@ -436,7 +436,7 @@ public void buildTagList(File directory, CommandTimeoutType cmdType) {
}

@Override
String determineCurrentVersion(CommandTimeoutType cmdType) throws IOException {
String determineCurrentVersion(CommandTimeoutType cmdType) {
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

/*
* Copyright (c) 2008, 2019, Oracle and/or its affiliates. All rights reserved.
* Portions Copyright (c) 2017, 2020, Chris Fraire <[email protected]>.
* Portions Copyright (c) 2017, 2019-2020, Chris Fraire <[email protected]>.
*/
package org.opengrok.indexer.history;

Expand Down Expand Up @@ -144,7 +144,7 @@ public boolean isRepositoryFor(File file, CommandTimeoutType cmdType) {
}

@Override
String determineBranch(CommandTimeoutType cmdType) throws IOException {
String determineBranch(CommandTimeoutType cmdType) {
String branch = null;

File tagFile = new File(getDirectoryName(), "CVS/Tag");
Expand Down Expand Up @@ -250,12 +250,12 @@ public boolean fileHasHistory(File file) {
}

@Override
History getHistory(File file) throws HistoryException {
return new CVSHistoryParser().parse(file, this);
HistoryEnumeration getHistory(File file) throws HistoryException {
return new SingleHistory(new CVSHistoryParser().parse(file, this));
}

@Override
Annotation annotate(File file, String revision) throws IOException {
Annotation annotate(File file, String revision) {
ArrayList<String> cmd = new ArrayList<>();
ensureCommand(CMD_PROPERTY_KEY, CMD_FALLBACK);
cmd.add(RepoCommand);
Expand Down Expand Up @@ -284,7 +284,7 @@ Annotation annotate(File file, String revision) throws IOException {
}

@Override
String determineParent(CommandTimeoutType cmdType) throws IOException {
String determineParent(CommandTimeoutType cmdType) {
File rootFile = new File(getDirectoryName() + File.separator + "CVS"
+ File.separator + "Root");
String parent = null;
Expand Down
Loading