Skip to content

Commit

Permalink
Improved run script. Refactored build script.
Browse files Browse the repository at this point in the history
  • Loading branch information
dimi2 committed Jun 23, 2018
1 parent bcf2376 commit fe26bc0
Show file tree
Hide file tree
Showing 33 changed files with 86 additions and 44 deletions.
13 changes: 11 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ DyAnnotationExtractor -input "Getting Started with Ubuntu 16.04.pdf"

(this will create file with same name in the same directory, with added '.md' suffix)

Now you have extract of the book which is not 100 but 5-6 pages. You can skim just the exported text instead of re-reading entire book.
Now you have extract of the book which is not 100 but 5-6 pages. So, you can skim just the exported text instead of re-reading the entire book.

## Supported Input Formats ##

Expand All @@ -44,7 +44,16 @@ End users need to download only the distribution.
Extract the downloaded archive in some local directory.<br/>
Run the provided 'DyAnnotationExtractor' script to perform extraction.

## Build ##

To build the project from sources, you will need [Gradle](https://gradle.org/) build tool.
Go into the project home directory (PROJ_HOME) and executd command:
```
gradle
```
The result will appear in directory `PROJ_HOME/build/distributions`.

## Dependencies ##

- iTextPdf 7.0.2+ (PDF handling library)
- iTextPdf 7.1.2+ (PDF handling library)

79 changes: 54 additions & 25 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,18 @@ defaultTasks 'dist'

apply plugin: 'java'

// Define project specific directories (we do not use the default project structure
// (because it is contra-productive).
defaultTasks 'dist'
buildDir = 'build'
def workDir = 'work'
// Define project specific directories.
def workDir = "$projectDir/work"
def programDirName = 'program'
def programDir = "$workDir/$programDirName"
def testsDirName = 'tests'
def testsDir = "$workDir/$testsDirName"
def libraryDirName = 'library'
def libraryDir = "$workDir/$libraryDirName"
def distDir = "$buildDir/distributions"
def autoDocDir = "$distDir/autodoc"
def tempDirName = 'temp'
def tempDir = "$workDir/$tempDirName"
def minJavaVersion = 1.8
def minGradleVersion = 2.0

Expand All @@ -25,8 +30,8 @@ repositories {
}

dependencies {
compile "com.itextpdf:kernel:7.0.2"
compile "org.slf4j:slf4j-simple:1.7.13"
compile "com.itextpdf:kernel:7.1.2"
compile "org.slf4j:slf4j-simple:1.7.25"

testCompile "junit:junit:4.12"
}
Expand All @@ -40,16 +45,30 @@ dependencies {
sourceSets {
main {
java {
srcDir "sources/main/java"
srcDir "source/main/java"
outputDir = file(programDir)
}
output.classesDir = "$workDir/program"
}
test {
java {
srcDir "sources/test/java"
srcDir "source/test/java"
outputDir = file(testsDir)
}
output.classesDir = "$workDir/tests"
output.resourcesDir = "$workDir/testing/resource"
}
}

// Force IntelliJ IDEA development environment to use the same build directories as Gradle.
apply plugin: 'idea'
idea {
module {
//inheritOutputDirs = false
outputDir file(programDir)
testOutputDir file(testsDir)
// TODO: Check why this exclusion is ignored by Intellij.
excludeDirs -= file(workDir)
excludeDirs += [file(libraryDir), file(tempDir)]
downloadJavadoc = true
downloadSources = true
}
}

Expand All @@ -61,6 +80,9 @@ compileTestJava {
options.encoding = "UTF-8"
}

// Check the preconditions before attempting build.
build.dependsOn('checkEnv')

jar {
baseName = projectName
classifier = 'binary'
Expand All @@ -87,42 +109,49 @@ task checkEnv {
description = 'Check the build pre-conditions.'

// Check the Java version.
def javaVersion = (System.getProperty('java.version') =~ /^\d+(\.\d+)?/)[0][0] as double
if (javaVersion < minJavaVersion) {
throw new GradleException("Inappropriate Java version ($javaVersion). Needs ($minJavaVersion) or higher.")
def javaVersion = (System.getProperty('java.version') =~ /^\d+\.\d+/)[0] as double
if (javaVersion < minJavaVersion) {
throw new GradleException("Inappropriate Java version ($javaVersion). " +
"Needs ($minJavaVersion) or higher.")
}

// Check the Gradle version.
def gradleVersion = (gradle.gradleVersion =~ /^\d+(\.\d+)?/)[0][0] as double
if (gradleVersion < minGradleVersion) {
throw new GradleException("Inappropriate Gradle version ($gradleVersion). Needs ($minGradleVersion) or higher.")
def gradleVersion = (gradle.gradleVersion =~ /^\d+\.\d+/)[0] as double
if (gradleVersion < minGradleVersion) {
throw new GradleException("Inappropriate Gradle version ($gradleVersion). " +
"Needs ($minGradleVersion) or higher.")
}
}

javadoc {
destinationDir = file(autoDocDir)
}

task generateDocs {
task docs {
description = 'Generates project documentation.'
dependsOn javadoc
}

task dist(type: Zip, dependsOn: ['checkEnv', 'clean', 'build']) {
description = 'Create project distribution.'

// Ensure ordered execution of dependent tasks (this is workaround for Gradle design weakness).
def tasks = [clean, jar, test, docs]
for (int i = 0; i < tasks.size() - 1; i++) {
tasks[i + 1].mustRunAfter(tasks[i])
}
dependsOn(tasks)

classifier = 'dist'
destinationDir = file(distDir)
from (workDir) {
exclude(['temp', 'tests'])
exclude([tempDirName, testsDirName])
}
from (configurations.runtime) {
into 'library'
into libraryDirName
}
includeEmptyDirs = false
into projectName
}
clean.mustRunAfter checkEnv
build.mustRunAfter clean
generateDocs.mustRunAfter build
jar.mustRunAfter test


2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
projectName = DyAnnotationExtractor
projectVersion = 1.0.2
projectVersion = 1.0.3
group = dsk
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
* Base functionality for unit tests.
*/
public abstract class TestBase {
public static final String WORK_DIR = "work";
public static final String TEMP_DIR = "temp";
protected static File workDir;
protected static File tempDir;
protected static String resDir;
Expand All @@ -23,15 +25,15 @@ public abstract class TestBase {
public TestBase() {
super();
if (workDir == null) {
workDir = setupWorkDirectory("work");
tempDir = setupTempDirectory("temp");
resDir = workDir + "/../resources/test";
workDir = setupWorkDirectory(WORK_DIR);
tempDir = setupTempDirectory(TEMP_DIR);
resDir = workDir + "/testing";
}
}

/**
* Setup working directory to run the tests from.
* @param dir Work directory name (relative to project root directory). Null = to use default.
* @param dir Work directory name (relative to project root directory). Pass null to use default.
* @return The work directory.
*/
protected File setupWorkDirectory(String dir) {
Expand Down Expand Up @@ -62,7 +64,7 @@ protected File setupWorkDirectory(String dir) {
protected File setupTempDirectory(String dir) {
File tempDir;
if (dir == null) {
tempDir = new File(workDir, "temp").getAbsoluteFile();
tempDir = new File(workDir, TEMP_DIR).getAbsoluteFile();
}
else {
tempDir = new File(dir).getAbsoluteFile();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public void testCyrillicAnnotation() {
AnnotatedDocument document = importer.readAnnotations(resDir + "/Test_Pdf_1.pdf");
List<Annotation> annotations = document.getAnnotations();
Annotation annot = annotations.get(0);
assertEquals("\u041f\u0435\u0442", annot.getText()); // Пет (Cyrillic).
assertEquals("\u041f\u0435\u0442", annot.getText()); // Пет ("five" in Cyrillic).
assertEquals(1, annotations.size());
}

Expand Down
3 changes: 2 additions & 1 deletion work/DyAnnotationExtractor.sh
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
java java -cp program;library/* dsk.anotex.ConsoleRunner $1 $2 $3 $4
#!/bin/bash
java -cp "program:library/*" dsk.anotex.ConsoleRunner $1 "$2"
19 changes: 10 additions & 9 deletions work/documents/Manual.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ DyAnnotationExtractor -input "Getting Started with Ubuntu 16.04.pdf"

(this will create file with same name in the same directory, with added '.md' suffix)

Now you have extract of the book which is not 100 but 5-6 pages. You can skim just the exported text instead of re-reading entire book.
Now you have extract of the book which is not 100 but 5-6 pages. So, you can skim just the exported text instead of re-reading the entire book.

## Supported Input Formats ##

Expand All @@ -37,23 +37,24 @@ Now you have extract of the book which is not 100 but 5-6 pages. You can skim ju
Get the [latest release](https://github.com/dimi2/DyAnnotationExtractor/releases/latest).



There are separate files for: distribution, binary and sources.<br/>
End users need to download only the distribution.

## Installation ##







Extract the downloaded archive in some local directory.<br/>
Run the provided 'DyAnnotationExtractor' script to perform extraction.

## Build ##

To build the project from sources, you will need [Gradle](https://gradle.org/) build tool.
Go into the project home directory (PROJ_HOME) and executd command:
```
gradle
```
The result will appear in directory `PROJ_HOME/build/distributions`.

## Dependencies ##

- iTextPdf 7.0.2+ (PDF handling library)
- iTextPdf 7.1.2+ (PDF handling library)

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit fe26bc0

Please sign in to comment.