Skip to content

Commit

Permalink
Merge pull request #100 from rtgdk/patch2
Browse files Browse the repository at this point in the history
Showing line no. of error in tag value by throwing expections.
  • Loading branch information
goneall authored Jul 18, 2017
2 parents 7088082 + 0611d1b commit ebbb752
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/org/spdx/tag/HandBuiltParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public void data() throws Exception {
nextLine = textInput.readLine();
}
if (inTextBlock) {
throw(new RecognitionException("Unterminated text block. Expecting "+END_TEXT));
throw(new RecognitionException("Unterminated text block at line " + (textInput.getCurrentLineNo()) + " Expecting "+END_TEXT ));
}
this.buildDocument.exit();
} finally {
Expand Down
18 changes: 13 additions & 5 deletions src/org/spdx/tools/CompareSpdxDocs.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@

import com.google.common.base.Joiner;

import antlr.RecognitionException;

/**
* Command line application to compare two SPDX documents
* Usage: CompareSpdxDoc doc1 doc2 [output]
Expand Down Expand Up @@ -1145,20 +1147,21 @@ protected static SpdxDocument openRdfOrTagDoc(String spdxDocFileName, List<Strin
logger.info("Document identified as SPDX tag/value.");
} catch (SpdxCompareException e) {
// Ignore - assume this is an RDF/XML file.
errorDetails = e.getMessage();
}
if (retval == null) {
try {
// Now try to open the file as an RDF/XML file.
retval = SPDXDocumentFactory.createSpdxDocument(spdxDocFileName);
logger.info("Document identified as SPDX RDF/XML.");
} catch (IOException e) {
errorDetails = e.getMessage();
errorDetails += e.getMessage();
// Ignore - unrecognized files are handled below.
} catch (InvalidSPDXAnalysisException e) {
errorDetails = e.getMessage();
errorDetails += e.getMessage();
// Ignore - unrecognized files are handled below.
} catch (Exception e) {
errorDetails = e.getMessage();
errorDetails += e.getMessage();
// Ignore - unrecognized files are handled below.
}
}
Expand All @@ -1177,8 +1180,13 @@ private static SpdxDocument convertTagValueToRdf(File tagValueFile, List<String>
FileInputStream in = null;
try {
in = new FileInputStream(tagValueFile);
return TagToRDF.convertTagFileToRdf(in, TagToRDF.DEFAULT_OUTPUT_FORMAT, warnings).getSpdxDocument();
} catch (Exception e) {
SpdxDocument result = TagToRDF.convertTagFileToRdf(in, TagToRDF.DEFAULT_OUTPUT_FORMAT, warnings).getSpdxDocument();
return result;
}
catch (RecognitionException e){
throw(new SpdxCompareException(e.getMessage(),e));
}
catch (Exception e) {
throw(new SpdxCompareException("Error converting tag/value to RDF/XML format: "+e.getMessage(),e));
} finally {
if (in != null) {
Expand Down
19 changes: 12 additions & 7 deletions src/org/spdx/tools/TagToRDF.java
Original file line number Diff line number Diff line change
Expand Up @@ -206,14 +206,19 @@ public static SpdxDocumentContainer convertTagFileToRdf(
NoCommentInputStream nci = new NoCommentInputStream(spdxTagFile);
// TagValueLexer lexer = new TagValueLexer(new DataInputStream(nci));
// TagValueParser parser = new TagValueParser(lexer);
HandBuiltParser parser = new HandBuiltParser(nci);
SpdxDocumentContainer[] result = new SpdxDocumentContainer[1];
parser.setBehavior(new BuildDocument(result, constants, warnings));
parser.data();
if (result[0] == null) {
throw(new RuntimeException("Unexpected error parsing SPDX tag document - the result is null."));
try{
HandBuiltParser parser = new HandBuiltParser(nci);
SpdxDocumentContainer[] result = new SpdxDocumentContainer[1];
parser.setBehavior(new BuildDocument(result, constants, warnings));
parser.data();
if (result[0] == null) {
throw(new RuntimeException("Unexpected error parsing SPDX tag document - the result is null."));
}
return result[0];
}
catch (RecognitionException e) {
throw(new RecognitionException(e.getMessage()));
}
return result[0];
}


Expand Down

0 comments on commit ebbb752

Please sign in to comment.