Skip to content
Open
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
15 changes: 15 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
group 'com.github.nizshee'
version '1.0-SNAPSHOT'

apply plugin: 'java'

sourceCompatibility = 1.8

repositories {
mavenCentral()
}

dependencies {
compile group: 'berkeleydb', name: 'je', version: '3.2.76'
testCompile group: 'junit', name: 'junit', version: '4.11'
}
6 changes: 6 additions & 0 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#Fri Sep 16 16:31:37 MSK 2016
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.13-bin.zip
164 changes: 164 additions & 0 deletions gradlew

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

90 changes: 90 additions & 0 deletions gradlew.bat

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
rootProject.name = 'lazy-factory'
rootProject.name = 'hw11'

73 changes: 73 additions & 0 deletions src/main/java/com/github/nizshee/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package com.github.nizshee;


import com.github.nizshee.cvs.CVS;
import com.github.nizshee.exception.StateException;
import com.github.nizshee.exception.WorkspaceException;
import com.github.nizshee.frontend.Frontend;
import com.github.nizshee.index.InMemoryIndex;
import com.github.nizshee.tags.InMemoryTags;
import com.github.nizshee.tags.Tags;
import com.github.nizshee.workspace.FileWorkspace;

import java.io.*;
import java.nio.file.Paths;
import java.util.*;

public class Main {

private final static String CVS = ".cvs";
private final static String TAGS = ".tags";
private final static String WORKDIR = "workdir";

@SuppressWarnings("ResultOfMethodCallIgnored")
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

зачем подавлять для всего метода?

public static void main(String args[]) throws Exception {

Paths.get(WORKDIR).toFile().mkdirs();

Tags tags = restoreTags();
CVS cvs = restoreCVS();


Frontend frontend = new Frontend(tags, cvs);
frontend.eval(args);

if (cvs.current() != null) {
dumpTags(tags);
dumpCVS(cvs);
}
}

private static CVS restoreCVS() throws IOException, ClassNotFoundException, WorkspaceException, StateException {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

см restoreTags

try (FileInputStream fis = new FileInputStream(WORKDIR + "/" + CVS)) {
ObjectInputStream ois = new ObjectInputStream(fis);
return (CVS) ois.readObject();
} catch (FileNotFoundException ignore) {
return new CVS(new FileWorkspace(WORKDIR), new InMemoryIndex(new HashMap<>()),
Arrays.asList(CVS, TAGS));
}
}

private static void dumpCVS(CVS cvs) throws IOException {
FileOutputStream fos = new FileOutputStream(WORKDIR + "/" + CVS);
ObjectOutputStream oos = new ObjectOutputStream(fos);
oos.writeObject(cvs);
fos.close();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

см dumpTags

}

private static Tags restoreTags() throws IOException, ClassNotFoundException {
try (FileInputStream fis = new FileInputStream(WORKDIR + "/" + TAGS)) {
ObjectInputStream ois = new ObjectInputStream(fis);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

без fis можно обойтись

return (Tags) ois.readObject();
} catch (FileNotFoundException ignore) {
return new InMemoryTags();
}
}

private static void dumpTags(Tags tags) throws IOException {
FileOutputStream fos = new FileOutputStream(WORKDIR + "/" + TAGS);
ObjectOutputStream oos = new ObjectOutputStream(fos);
oos.writeObject(tags);
fos.close();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

не всегда исполнение дойдет до сюда

-0.5

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oos нужно как минимум флашить в такой реализации

и лучше переменную fos не заводить, можно oos обойтись

}
}
Loading