-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Abraham Rubinstein
committed
Mar 13, 2019
0 parents
commit c665548
Showing
30 changed files
with
3,336 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
target/ | ||
pom.xml.tag | ||
pom.xml.releaseBackup | ||
pom.xml.versionsBackup | ||
pom.xml.next | ||
release.properties | ||
dependency-reduced-pom.xml | ||
buildNumber.properties | ||
.mvn/timing.properties | ||
|
||
# Avoid ignoring Maven wrapper jar file (.jar files are usually ignored) | ||
!/.mvn/wrapper/maven-wrapper.jar | ||
|
||
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm | ||
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 | ||
|
||
.idea | ||
*.iml | ||
|
||
workspace/ | ||
|
||
# User-specific stuff | ||
.idea/**/workspace.xml | ||
.idea/**/tasks.xml | ||
.idea/**/usage.statistics.xml | ||
.idea/**/dictionaries | ||
.idea/**/shelf | ||
|
||
# Generated files | ||
.idea/**/contentModel.xml | ||
|
||
# Sensitive or high-churn files | ||
.idea/**/dataSources/ | ||
.idea/**/dataSources.ids | ||
.idea/**/dataSources.local.xml | ||
.idea/**/sqlDataSources.xml | ||
.idea/**/dynamic.xml | ||
.idea/**/uiDesigner.xml | ||
.idea/**/dbnavigator.xml | ||
|
||
# Gradle | ||
.idea/**/gradle.xml | ||
.idea/**/libraries | ||
|
||
# Gradle and Maven with auto-import | ||
# When using Gradle or Maven with auto-import, you should exclude module files, | ||
# since they will be recreated, and may cause churn. Uncomment if using | ||
# auto-import. | ||
# .idea/modules.xml | ||
# .idea/*.iml | ||
# .idea/modules | ||
|
||
# CMake | ||
cmake-build-*/ | ||
|
||
# Mongo Explorer plugin | ||
.idea/**/mongoSettings.xml | ||
|
||
# File-based project format | ||
*.iws | ||
|
||
# IntelliJ | ||
out/ | ||
|
||
# mpeltonen/sbt-idea plugin | ||
.idea_modules/ | ||
|
||
# JIRA plugin | ||
atlassian-ide-plugin.xml | ||
|
||
# Cursive Clojure plugin | ||
.idea/replstate.xml | ||
|
||
# Crashlytics plugin (for Android Studio and IntelliJ) | ||
com_crashlytics_export_strings.xml | ||
crashlytics.properties | ||
crashlytics-build.properties | ||
fabric.properties | ||
|
||
# Editor-based Rest Client | ||
.idea/httpRequests | ||
|
||
# Android studio 3.1+ serialized cache file | ||
.idea/caches/build_file_checksums.ser | ||
|
||
# General | ||
.DS_Store | ||
.AppleDouble | ||
.LSOverride | ||
|
||
# Icon must end with two \r | ||
Icon | ||
|
||
|
||
# Thumbnails | ||
._* | ||
|
||
# Files that might appear in the root of a volume | ||
.DocumentRevisions-V100 | ||
.fseventsd | ||
.Spotlight-V100 | ||
.TemporaryItems | ||
.Trashes | ||
.VolumeIcon.icns | ||
.com.apple.timemachine.donotpresent | ||
|
||
# Directories potentially created on remote AFP share | ||
.AppleDB | ||
.AppleDesktop | ||
Network Trash Folder | ||
Temporary Items | ||
.apdisk |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
language: java | ||
|
||
cache: | ||
directories: | ||
- $HOME/.m2 | ||
|
||
script: | ||
- echo "RESBot at work... let's see if code compiles and tests pass!" | ||
- cd LabJavaIO | ||
- mvn clean package |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2018 Software Engineering @ HEIG-VD | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<groupId>ch.heigvd.res.io</groupId> | ||
<artifactId>lab-java-io</artifactId> | ||
<version>1.0-SNAPSHOT</version> | ||
<packaging>jar</packaging> | ||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<maven.compiler.source>1.8</maven.compiler.source> | ||
<maven.compiler.target>1.8</maven.compiler.target> | ||
</properties> | ||
<name>RES Lab Java IO</name> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<artifactId>maven-surefire-plugin</artifactId> | ||
<version>2.22.1</version> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-shade-plugin</artifactId> | ||
<version>2.3</version> | ||
<executions> | ||
<execution> | ||
<phase>package</phase> | ||
<goals> | ||
<goal>shade</goal> | ||
</goals> | ||
<configuration> | ||
<transformers> | ||
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"> | ||
<mainClass>ch.heigvd.res.labio.impl.Application</mainClass> | ||
</transformer> | ||
</transformers> | ||
<shadedArtifactAttached>true</shadedArtifactAttached> | ||
<shadedClassifierName>launcher</shadedClassifierName> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
<dependencies> | ||
<dependency> | ||
<groupId>javax.xml.bind</groupId> | ||
<artifactId>jaxb-api</artifactId> | ||
<version>2.3.1</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.sun.xml.bind</groupId> | ||
<artifactId>jaxb-core</artifactId> | ||
<version>2.3.0.1</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.sun.xml.bind</groupId> | ||
<artifactId>jaxb-impl</artifactId> | ||
<version>2.3.0.1</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>javax.activation</groupId> | ||
<artifactId>javax.activation-api</artifactId> | ||
<version>1.2.0</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.glassfish.jersey.core</groupId> | ||
<artifactId>jersey-client</artifactId> | ||
<version>2.15</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.glassfish.jersey.media</groupId> | ||
<artifactId>jersey-media-json-jackson</artifactId> | ||
<version>2.14</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>commons-io</groupId> | ||
<artifactId>commons-io</artifactId> | ||
<version>2.4</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.projectlombok</groupId> | ||
<artifactId>lombok</artifactId> | ||
<version>1.18.2</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.junit.jupiter</groupId> | ||
<artifactId>junit-jupiter-api</artifactId> | ||
<version>5.4.0</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.junit.jupiter</groupId> | ||
<artifactId>junit-jupiter-engine</artifactId> | ||
<version>5.4.0</version> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
</project> |
153 changes: 153 additions & 0 deletions
153
LabJavaIO/src/main/java/ch/heigvd/res/labio/impl/Application.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,153 @@ | ||
package ch.heigvd.res.labio.impl; | ||
|
||
import ch.heigvd.res.labio.impl.explorers.DFSFileExplorer; | ||
import ch.heigvd.res.labio.impl.transformers.CompleteFileTransformer; | ||
import ch.heigvd.res.labio.interfaces.IApplication; | ||
import ch.heigvd.res.labio.interfaces.IFileExplorer; | ||
import ch.heigvd.res.labio.interfaces.IFileVisitor; | ||
import ch.heigvd.res.labio.quotes.QuoteClient; | ||
import ch.heigvd.res.labio.quotes.Quote; | ||
import java.io.File; | ||
import java.io.IOException; | ||
import java.io.StringWriter; | ||
import java.io.Writer; | ||
import java.util.logging.Level; | ||
import java.util.logging.Logger; | ||
import org.apache.commons.io.FileUtils; | ||
|
||
/** | ||
* | ||
* @author Olivier Liechti | ||
*/ | ||
public class Application implements IApplication { | ||
|
||
/** | ||
* This constant defines where the quotes will be stored. The path is relative | ||
* to where the Java application is invoked. | ||
*/ | ||
public static String WORKSPACE_DIRECTORY = "./workspace/quotes"; | ||
|
||
private static final Logger LOG = Logger.getLogger(Application.class.getName()); | ||
|
||
public static void main(String[] args) { | ||
|
||
/* | ||
* I prefer to have LOG output on a single line, it's easier to read. Being able | ||
* to change the formatting of console outputs is one of the reasons why it is | ||
* better to use a Logger rather than using System.out.println | ||
*/ | ||
System.setProperty("java.util.logging.SimpleFormatter.format", "%4$s: %5$s%6$s%n"); | ||
|
||
|
||
int numberOfQuotes = 0; | ||
try { | ||
numberOfQuotes = Integer.parseInt(args[0]); | ||
} catch (Exception e) { | ||
System.err.println("The command accepts a single numeric argument (number of quotes to fetch)"); | ||
System.exit(-1); | ||
} | ||
|
||
Application app = new Application(); | ||
try { | ||
/* | ||
* Step 1 : clear the output directory | ||
*/ | ||
app.clearOutputDirectory(); | ||
|
||
/* | ||
* Step 2 : use the QuotesClient to fetch quotes; store each quote in a file | ||
*/ | ||
app.fetchAndStoreQuotes(numberOfQuotes); | ||
|
||
/* | ||
* Step 3 : use a file explorer to traverse the file system; print the name of each directory and file | ||
*/ | ||
Writer writer = new StringWriter(); // we create a special writer that will send characters into a string (memory) | ||
app.printFileNames(writer); // we hand over this writer to the printFileNames method | ||
LOG.info(writer.toString()); // we dump the whole result on the console | ||
|
||
/* | ||
* Step 4 : process the quote files, by applying 2 transformations to their content | ||
* (convert to uppercase and add line numbers) | ||
*/ | ||
app.processQuoteFiles(); | ||
|
||
} catch (IOException ex) { | ||
LOG.log(Level.SEVERE, "Could not fetch quotes. {0}", ex.getMessage()); | ||
ex.printStackTrace(); | ||
} | ||
} | ||
|
||
@Override | ||
public void fetchAndStoreQuotes(int numberOfQuotes) throws IOException { | ||
clearOutputDirectory(); | ||
QuoteClient client = new QuoteClient(); | ||
for (int i = 0; i < numberOfQuotes; i++) { | ||
Quote quote = client.fetchQuote(); | ||
/* There is a missing piece here! | ||
* As you can see, this method handles the first part of the lab. It uses the web service | ||
* client to fetch quotes. We have removed a single line from this method. It is a call to | ||
* one method provided by this class, which is responsible for storing the content of the | ||
* quote in a text file (and for generating the directories based on the tags). | ||
*/ | ||
LOG.info("Received a new joke with " + quote.getTags().size() + " tags."); | ||
for (String tag : quote.getTags()) { | ||
LOG.info("> " + tag); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* This method deletes the WORKSPACE_DIRECTORY and its content. It uses the | ||
* apache commons-io library. You should call this method in the main method. | ||
* | ||
* @throws IOException | ||
*/ | ||
void clearOutputDirectory() throws IOException { | ||
FileUtils.deleteDirectory(new File(WORKSPACE_DIRECTORY)); | ||
} | ||
|
||
/** | ||
* This method stores the content of a quote in the local file system. It has | ||
* 2 responsibilities: | ||
* | ||
* - with quote.getTags(), it gets a list of tags and uses | ||
* it to create sub-folders (for instance, if a quote has three tags "A", "B" and | ||
* "C", it will be stored in /quotes/A/B/C/quotes-n.utf8. | ||
* | ||
* - with quote.getQuote(), it has access to the text of the quote. It stores | ||
* this text in UTF-8 file. | ||
* | ||
* @param quote the quote object, with tags and text | ||
* @param filename the name of the file to create and where to store the quote text | ||
* @throws IOException | ||
*/ | ||
void storeQuote(Quote quote, String filename) throws IOException { | ||
throw new UnsupportedOperationException("The student has not implemented this method yet."); | ||
} | ||
|
||
/** | ||
* This method uses a IFileExplorer to explore the file system and prints the name of each | ||
* encountered file and directory. | ||
*/ | ||
void printFileNames(final Writer writer) { | ||
IFileExplorer explorer = new DFSFileExplorer(); | ||
explorer.explore(new File(WORKSPACE_DIRECTORY), new IFileVisitor() { | ||
@Override | ||
public void visit(File file) { | ||
/* | ||
* There is a missing piece here. Notice how we use an anonymous class here. We provide the implementation | ||
* of the the IFileVisitor interface inline. You just have to add the body of the visit method, which should | ||
* be pretty easy (we want to write the filename, including the path, to the writer passed in argument). | ||
*/ | ||
} | ||
}); | ||
} | ||
|
||
@Override | ||
public void processQuoteFiles() throws IOException { | ||
IFileExplorer explorer = new DFSFileExplorer(); | ||
explorer.explore(new File(WORKSPACE_DIRECTORY), new CompleteFileTransformer()); | ||
} | ||
|
||
} |
Oops, something went wrong.