Skip to content

Commit

Permalink
Migration to Jena 3.1.1, enabling other file types types.
Browse files Browse the repository at this point in the history
  • Loading branch information
Yev Bronshteyn committed Jan 29, 2017
1 parent d220009 commit 3e44047
Show file tree
Hide file tree
Showing 9 changed files with 322 additions and 150 deletions.
226 changes: 131 additions & 95 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,102 +1,138 @@
<?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>
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
<build>
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>
<repositories>
<repository>
<!-- Some jena component releases missing from maven central -->
<id>jena-releases</id>
<name>Apache Jena Releases</name>
<url>https://repository.apache.org/content/repositories/releases</url>
</repository>
<repository>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>bintray-yevster-spdx-tools-fork</id>
<name>bintray</name>
<url>https://dl.bintray.com/yevster/spdx-tools-fork</url>
</repository>
<repository>
<id>rdfa-bintray</id>
<url>https://dl.bintray.com/yevster/maven</url>
</repository>
</repositories>
<build>

<sourceDirectory>src/main/java</sourceDirectory>
<testSourceDirectory>test/main/java</testSourceDirectory>
<testResources>
<testResource>
<directory>test/main/resources</directory>
</testResource>
</testResources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.7</version>
<configuration>
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>spdxedit.Main</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<!-- this is used for inheritance merges -->
<phase>package</phase>
<!-- bind to the packaging phase -->
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<groupId>groupId</groupId>
<artifactId>spdx-edit</artifactId>
<version>1.0.1</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.12</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.12</version>
</dependency>
<dependency>
<groupId>com.hp.hpl.jena</groupId>
<artifactId>arq</artifactId>
<version>2.8.8</version>
</dependency>
<!-- <dependency> <groupId>org.spdx</groupId> <artifactId>spdx-tools</artifactId>
<version>2.1.0</version> </dependency> -->
<sourceDirectory>src/main/java</sourceDirectory>
<testSourceDirectory>test/main/java</testSourceDirectory>
<testResources>
<testResource>
<directory>test/main/resources</directory>
</testResource>
</testResources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.7</version>
<configuration>
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>spdxedit.Main</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<!-- this is used for inheritance merges -->
<phase>package</phase>
<!-- bind to the packaging phase -->
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<groupId>groupId</groupId>
<artifactId>spdx-edit</artifactId>
<version>1.0.1</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.12</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.12</version>
</dependency>
<dependency> <!--Temporary, pending release of SPDX tools 2.2-->
<groupId>org.spdx</groupId>
<artifactId>spdx-tools</artifactId>
<version>2.2.0</version>
</dependency>
<dependency>
<groupId>org.antlr</groupId>
<artifactId>antlr</artifactId>
<version>3.4</version>
</dependency>
<dependency>
<groupId>org.controlsfx</groupId>
<artifactId>controlsfx</artifactId>
<version>8.40.12</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.5</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>16.0.1</version>
</dependency>
<dependency>
<groupId>org.apache.jena</groupId>
<artifactId>apache-jena-libs</artifactId>
<version>3.1.1</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>


<dependency>
<groupId>com.github.spdx</groupId>
<artifactId>tools</artifactId>
<version>01f8d0d4da</version>
</dependency>
<dependency>
<groupId>org.controlsfx</groupId>
<artifactId>controlsfx</artifactId>
<version>8.40.12</version>
</dependency>

</dependencies>

</dependencies>

</project>
23 changes: 23 additions & 0 deletions src/main/java/spdxedit/IoFileTypeSelectionDialog.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package spdxedit;

import javafx.scene.control.ChoiceDialog;
import spdxedit.io.FileDataType;

import java.util.Optional;

/**
* A dialog that obtains a data type
*/
public final class IoFileTypeSelectionDialog{

public static Optional<FileDataType> getDataType(String title){
ChoiceDialog<FileDataType> dialog = new ChoiceDialog<>();
dialog.setTitle(title);
dialog.setHeaderText("Select data file type:");
dialog.getItems().addAll(FileDataType.values());

return dialog.showAndWait();

}

}
68 changes: 21 additions & 47 deletions src/main/java/spdxedit/MainSceneController.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.spdx.rdfparser.model.SpdxPackage;
import org.spdx.tag.CommonCode;
import org.spdx.tools.TagToRDF;
import spdxedit.io.FileDataType;
import spdxedit.util.UiUtils;

import java.io.*;
Expand All @@ -46,9 +47,6 @@ public class MainSceneController {
@FXML
private Button saveSpdx;

@FXML
private Button saveSpdxTag;

@FXML
private Button validateSpdx;

Expand Down Expand Up @@ -86,16 +84,20 @@ protected void updateItem(SpdxPackage item, boolean empty) {
}


private FileChooser getSpdxFileChooser(String... extensions) {
private FileChooser getSpdxFileChooser(Iterable<String> extenions) {
FileChooser chooser = new FileChooser();

for (int i = 0; i < extensions.length; ++i) {
FileChooser.ExtensionFilter spdxExtensionFilter = new FileChooser.ExtensionFilter(extensions[i], "*." + extensions[i]);
boolean first = true;
for (String extension : extenions) {
FileChooser.ExtensionFilter spdxExtensionFilter = new FileChooser.ExtensionFilter(extension, "*." + extension);
chooser.getExtensionFilters().add(spdxExtensionFilter);
if (i == 0) {
if (first){
chooser.setSelectedExtensionFilter(spdxExtensionFilter);
first = false;
}

}

return chooser;
}

Expand All @@ -106,7 +108,6 @@ void initialize() {
assert btnAddPackage != null : "fx:id=\"btnAddPackage\" was not injected: check your FXML file 'MainScene.fxml'.";
assert btnNewDocument != null : "fx:id=\"btnNewDocument\" was not injected: check your FXML file 'MainScene.fxml'.";
assert saveSpdx != null : "fx:id=\"saveSpdx\" was not injected: check your FXML file 'MainScene.fxml'.";
assert saveSpdxTag != null : "fx:id=\"saveSpdxTag\" was not injected: check your FXML file 'MainScene.fxml'.";
assert validateSpdx != null : "fx:id=\"validateSpdx\" was not injected: check your FXML file 'MainScene.fxml'.";
assert txtDocumentName != null : "fx:id=\"txtDocumentName\" was not injected: check your FXML file 'MainScene.fxml'.";
assert addedPackagesUiList != null : "fx:id=\"addedPackagesUiList\" was not injected: check your FXML file 'MainScene.fxml'.";
Expand All @@ -122,7 +123,6 @@ private void enableAllButtons(){
this.chooseDir.setDisable(false);
this.txtDocumentName.setDisable(false);
this.saveSpdx.setDisable(false);
this.saveSpdxTag.setDisable(false);
}

private static Optional<Path> selectDirectory(Window parentWindow) {
Expand Down Expand Up @@ -183,33 +183,21 @@ public void handleChooseDirectoryClicked(MouseEvent event) {
}



public void handleSaveSpdxClicked(MouseEvent event) {
File targetFile = getSpdxFileChooser("rdf", "spdx").showSaveDialog(saveSpdx.getScene().getWindow());
Optional<FileDataType> outputType = IoFileTypeSelectionDialog.getDataType("Save SPDX");
if (!outputType.isPresent()) return;

File targetFile = getSpdxFileChooser( outputType.get().getExtensions()).showSaveDialog(saveSpdx.getScene().getWindow());
if (targetFile == null) //Dialog cancelled
return;
try (FileWriter writer = new FileWriter(targetFile)) {
this.documentToEdit.getDocumentContainer().getModel().write(writer);
try {
outputType.get().writeToFile(targetFile, documentToEdit);
} catch (IOException e) {
logger.error("Unable to write SPDX file", e);
}
}

public void handleSaveTagClicked(MouseEvent event) {
File targetFile = getSpdxFileChooser("spdx", "tag").showSaveDialog(saveSpdx.getScene().getWindow());
if (targetFile == null) //Dialog cancelled
return;
try (PrintWriter out = new PrintWriter(targetFile)) {
// read the tag-value constants from a file
Properties constants = CommonCode
.getTextFromProperties("org/spdx/tag/SpdxTagValueConstants.properties");
// print document to a file using tag-value format
CommonCode.printDoc(documentToEdit, out, constants);
} catch (IOException | InvalidSPDXAnalysisException e) {
new Alert(Alert.AlertType.ERROR, "Unable to write tag file: " + e.getMessage(), ButtonType.OK);
}

}

public void handleAddPackageClicked(MouseEvent event) {
List<TreeItem<Path>> selectedNodes = dirTree.getSelectionModel().getSelectedItems();
assert (selectedNodes.size() <= 1);
Expand All @@ -231,10 +219,13 @@ private void loadSpdxDocument(SpdxDocument loadedDocument) {
}

public void handleLoadSpdxClicked(MouseEvent event) {
File targetFile = getSpdxFileChooser("rdf", "spdx").showOpenDialog(saveSpdx.getScene().getWindow());
Optional<FileDataType> inputType = IoFileTypeSelectionDialog.getDataType("Load SPDX");
if (!inputType.isPresent())return;

File targetFile = getSpdxFileChooser(inputType.get().getExtensions()).showOpenDialog(saveSpdx.getScene().getWindow());
if (targetFile == null) return; //Cancelled
try {
SpdxDocument loadedDocument = SPDXDocumentFactory.createSpdxDocument(targetFile.getPath());
SpdxDocument loadedDocument = inputType.get().readFromFile(targetFile);
loadSpdxDocument(loadedDocument);
} catch (InvalidSPDXAnalysisException isae) {
logger.error("Invalid SPDX load attempt", isae);
Expand All @@ -248,24 +239,7 @@ public void handleLoadSpdxClicked(MouseEvent event) {
}
}

public void handleLoadSpdxTagClicked(MouseEvent event) {
File targetFile = getSpdxFileChooser("spdx", "tag").showOpenDialog(saveSpdx.getScene().getWindow());
try (FileInputStream in = new FileInputStream(targetFile)) {
List<String> warnings = new LinkedList<>();
SpdxDocumentContainer container = TagToRDF.convertTagFileToRdf(in, "RDF/XML", warnings);
if (warnings.size() > 0) {
Alert warningsAlert = new Alert(Alert.AlertType.WARNING, "Warnings occured in parsing Tag document", ButtonType.OK);
TextArea warningList = new TextArea();
warningList.setText(Joiner.on("\n").join(warnings));
warningsAlert.getDialogPane().setExpandableContent(warningList);
warningsAlert.showAndWait();
}
loadSpdxDocument(container.getSpdxDocument());
} catch (Exception e) {
new Alert(Alert.AlertType.ERROR, "Error loading SPDX file " + targetFile.getAbsolutePath()).showAndWait();
}

}

public void handlePackageListClicked(MouseEvent event) {
if (event.getClickCount() == 2) {
Expand Down
Loading

0 comments on commit 3e44047

Please sign in to comment.